Files
workinf_Blender_Wasm/web/protocol/nanovdb-progressive-redraw.ts
mes123456 0fe8d2bb56
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Advance M8-M11 parity workflows
2026-08-17 04:37:07 -04:00

38 lines
1.3 KiB
TypeScript

export const NANOVDB_PROGRESSIVE_REDRAW_MAX_FRAMES = 32;
export const NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE = "NANOVDB_PROGRESSIVE_REDRAW_LIMIT" as const;
export interface NanoVDBProgressiveRedrawBudgetResult {
allowed: boolean;
redrawCount: number;
capped: boolean;
errorCode: typeof NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE | null;
}
export function validateNanoVDBProgressiveRedrawLimit(value: number): number {
if (!Number.isSafeInteger(value) || value < 1 || value > 1024) {
throw new Error("NANOVDB_INVALID_ARGUMENT: progressive redraw limit must be an integer from 1 to 1024");
}
return value;
}
export function consumeNanoVDBProgressiveRedrawBudget(
redrawCount: number,
maxRedraws: number,
): NanoVDBProgressiveRedrawBudgetResult {
if (!Number.isSafeInteger(redrawCount) || redrawCount < 0) {
throw new Error("NANOVDB_INVALID_ARGUMENT: progressive redraw count must be a non-negative integer");
}
const limit = validateNanoVDBProgressiveRedrawLimit(maxRedraws);
if (redrawCount >= limit) {
return { allowed: false, redrawCount, capped: true, errorCode: NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE };
}
const nextCount = redrawCount + 1;
const capped = nextCount >= limit;
return {
allowed: true,
redrawCount: nextCount,
capped,
errorCode: capped ? NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE : null,
};
}