import type { SplatData } from '../core/splat-data'; import { type SplatDeviceProfile } from '../core/splat-budget'; import { type SplatCountPeekOptions } from './peek-splat-count'; /** Options for {@link SplatSceneBudget}. */ export interface SplatSceneBudgetOptions { /** * Total resident splats across every file loaded under the budget. It is a * ceiling on the device default, never a raise above it: a phone stays * within its tier however large the number. Default: the device's * `resolveSplatBudget()`. Either way the budget never exceeds 2²⁴, what one * unified draw can address. */ total?: number; /** * Device signals the default is resolved from. Defaults to detecting them; * `null` skips detection, so `total` (or the portable floor) applies as is. */ profile?: SplatDeviceProfile | null; } /** Options for {@link SplatSceneBudget.plan}. */ export type SplatSceneBudgetPlanOptions = SplatCountPeekOptions; /** * One file's claim on a {@link SplatSceneBudget}, taken while it decodes. * * The loaders take and settle these themselves; a host only meets one when it * drives a custom loader. */ export interface SplatBudgetReservation { /** The most splats the file may keep; the loader thins it to this. */ readonly maxSplats: number; /** * Confirms the decoded data. The budget then holds its splats until the mesh * built from it is disposed. Returns the data to use: `data` itself, or a * thinner copy when files decoding side by side over-committed the budget. */ commit(data: SplatData): SplatData; /** Gives the share back: the load failed or was cancelled. */ release(): void; } /** * One splat budget shared by every whole-file scene loaded under it, so a * scene made of several large files stays within what the device can hold. * * Pass the same budget as `sceneBudget` to each `loadSplatData` / * `loadSplatDataFile` (or `ChunkLoader`) call. Each file is decoded, then * thinned in the load worker to its share, keeping its most visible splats * (opacity × size) exactly as an oversized single file is. A file takes * whatever the budget has free. When that is less than its proportional share * of the scene, the meshes already built from earlier files shrink to theirs * first (keeping their most visible splats, and reallocating their pools so * the memory is really returned), so adding a file later needs no host * arithmetic. {@link plan} a known batch first to split the budget up front * instead. The budget never exceeds 2²⁴ splats, so the sum of its files always * fits one `UnifiedSplatMesh` work buffer. * * Pass the returned data to `new SplatMesh(data)` unchanged: the mesh reports * to the budget and gives its splats back on `dispose()`. Data that never * becomes a mesh stays counted until {@link discard}. * * Thinning is lossy. Disposing one mesh frees budget for the next load, but * the meshes that remain do not regain the splats they were thinned by; * reload a file to restore its detail. A re-balance happens when the late * file's count is known (after it decodes), so the earlier meshes stay * shrunk even if that load then fails. Only a plain `SplatMesh` built * directly from the budgeted data, with its own editable pool, can shrink; * any other consumer keeps its share. * * Streamed formats (`StreamedSplatMesh`) keep their own governors and are not * counted here. * * @example * import { SplatMesh } from '@voluma/vlam'; * import { loadSplatData, SplatSceneBudget } from '@voluma/vlam/loaders'; * const budget = new SplatSceneBudget(); * const urls = ['/a.sog', '/b.sog', '/c.sog']; * await budget.plan(urls); * const meshes = await Promise.all( * urls.map(async (url) => new SplatMesh(await loadSplatData(url, { sceneBudget: budget }))), * ); */ export declare class SplatSceneBudget { /** The ceiling, in splats; at most 2²⁴. */ readonly total: number; private readonly entries; private readonly byData; private readonly plannedByUrl; private readonly plannedByFile; /** * @throws {RangeError} if `options.total` is not a positive finite number. */ constructor(options?: SplatSceneBudgetOptions); /** Splats held by loaded scenes (decoded data or the meshes built from it). */ get resident(): number; /** Splats not yet promised to any load, decoded or in flight. */ get free(): number; /** * Splits the budget across a batch of files in proportion to their sizes, * before any of them loads: each gets `⌊total × count / Σ count⌋`, never more * than its own count. Later loads of these inputs take their planned share * instead of whatever is free. * * The counts come from each file's header (a few small range requests per * URL). A file whose count cannot be read cheaply - a server without `Range` * support, a legacy gzip `.spz`, a whole-file `.rad` - is left out of the * split and takes what is free when it loads. * * @param inputs - The URLs (resolved against `options.baseUrl`) or local * files about to load. A URL must later be loaded by the same absolute URL. * @throws Rejects only with an `AbortError` when `options.signal` fires. */ plan(inputs: readonly (string | URL | File)[], options?: SplatSceneBudgetPlanOptions): Promise; /** * Claims a share for a file about to be thinned. The loaders call this from * the load worker's request once the decoded count is known; a host does not * need to. * * A file gets what is free, and at least its proportional share of the * scene whenever the others can give that up: loaded meshes above their * shares shrink at once, and files still loading above theirs are thinned * when they commit. The budget can therefore be briefly over-committed * while several files decode at the same time, never once they are loaded. * * @param declared - The file's splat count, when known. * @param input - The absolute URL or the `File`, to find a planned share. */ reserve(declared?: number, input?: string | File): SplatBudgetReservation; /** Splats promised beyond the total (only while several files decode at once). */ private get overCommitted(); /** * Each file's proportional share of the scene - `total × sourceCount / Σ`, * by its *original* count, so a file thinned before is not penalised twice - * never above its own count. `extra` is a newcomer not yet registered. */ private fairShares; /** * Shrinks every loaded mesh holding more than its share to that share, * keeping its most visible splats. Runs once per added file, on the main * thread. */ private shrinkLoaded; /** * Returns the splats of loaded data that will not become a mesh. A no-op * for data already built into one (dispose the mesh instead). */ discard(data: SplatData): void; }