import * as THREE from 'three/webgpu'; import type { LodRun } from '../../streaming/lod-scheduler'; import type { LodSource, LodSourceOptions, StreamedScene } from '../../streaming/lod-source'; import type { SplatData } from '../../core/splat-data'; import type { SplatDatasetSource } from '../../streaming/dataset-source'; import { type SplatRequestOptions } from '../../loaders/loading'; /** Controls for RAD bootstrap and LOD selection. */ export interface RadSceneOptions extends LodSourceOptions { /** Fetch settings for the header and bootstrap chunk. */ request?: SplatRequestOptions; /** Cancels bootstrap network and decode work. */ signal?: AbortSignal; /** Zero declines SH; nonzero retains all available bands. Default 3. */ maxShBands?: 0 | 1 | 2 | 3; /** Allow the existing finest-level budget lift. Default true. */ budgetLifts?: boolean; /** Force page-table selection, or retain the automatic policy. */ radStrategy?: 'auto' | 'page-table'; } /** * Builds a streamed scene from a single-file `.rad`. Fetches the header and * chunk table, then decodes chunk 0 (the coarsest whole-scene overview) to * establish scene bounds - the header carries none - and to seed the LOD * source with the root of the tree. * * `maxShBands` lets a caller **decline** the spherical harmonics the file * carries. Unlike SOG's opt-*in* `shBands` (whose manifest never declares * whether tiles have shN), a `.rad` names its own `maxSh`, so the question here * is only whether to keep it. It matters: every band costs 16 B/splat of GPU * pool plus as much again of CPU backing, and a texture fetch and coefficient * evaluation per splat per frame - exactly what the `smooth` performance profile * exists to decline on mobile. * * The choice is deliberately **all-or-nothing**: `0` drops SH, anything else * keeps every band the file has. A *partial* cap cannot be honoured, because the * `.rad` decoder emits the file's full band count and `SplatMesh.writePackedSh` * only copies packed words when the counts match exactly - a mismatch falls * through to neutral words, which would pay for the reduced bands' textures and * still render flat, view-independent color. Truncating the packed SH per splat * at decode would lift this restriction. */ export declare function buildRadScene(source: SplatDatasetSource, options: RadSceneOptions): Promise; /** * Selects a budget-bounded prefix of a `.rad` chunk sequence and renders its * frontier - the splats whose children are not yet resident, plus all leaves. * * The tree is discovered incrementally: {@link onChunkDecoded} records each * chunk's `child_count`/`child_start` columns, and `discoveredDepth` tracks the * longest contiguous decoded prefix. `computeDesiredRuns` emits the frontier of * the largest prefix whose drawn count fits the budget (cached - it does not * depend on the camera), plus fetch-intent runs that pull the next chunks in. * * Refinement is **uniform** over the scene, not camera-distance foveated. Chunk- * granular spatial foveation is impossible for this format: the chunk graph is a * deeply entangled DAG - every non-root chunk has ≥2 parent chunks - so no * ancestor-closed chunk subset larger than `{0}` exists, and a coarse ancestor * that is not resident would double-draw over any refined descendant. True near- * camera refinement therefore needs Spark-style per-splat GPU culling (see * `docs/formats/rad-notes.md`, ROADMAP M14.6). Two levers help meanwhile: a budget large * enough to load a moderate scene's full leaf set (blobs vanish once every chunk * is resident), and the `maxSplatScreenRadius` blob cull for what stays coarse. * * {@link RadLodSource} is exported for unit testing only; it is not part of the * public API and is reached in practice through {@link buildRadScene}. */ export declare class RadLodSource implements LodSource { budget: number; lodBaseDistance: number; lodMultiplier: number; private readonly total; private readonly chunkSize; private readonly chunkCounts; private readonly numChunks; /** * Decoded per-splat tree columns, by chunk index. * * Grows monotonically and is deliberately never evicted. That costs ~10 B per * splat of every chunk ever decoded (`childCount` u16 + `childStart` u32 + * `size` f32) and is invisible to the chunk cache's byte accounting, so it * reads like a leak - but it is not reclaimable. {@link discoveredDepth} is * the longest *contiguous* decoded prefix and every frontier walk at or below * it reads these columns, so dropping an entry would either corrupt the * traversal or force `discoveredDepth` back and visibly coarsen the scene. * * Bounded in practice by the mode that uses it: `.rad` defaults to * `foveationMode: 'page-table'`, where the frontier worker owns the traversal * and this source is never constructed. Only the `'band'` and `'frontier'` * A/B modes pay it. Reducing it means changing the tree encoding, not adding * an eviction pass here. */ private readonly decoded; /** Longest contiguous decoded prefix `{0 … discoveredDepth − 1}`. */ private discoveredDepth; /** Chunk-0-only frontier: the always-available coarse substitute coverage. */ private coarseRuns; /** Splats the coarse (chunk-0) coverage draws. */ coverageSplatCount: number; /** Cache of the last emitted frontier, keyed by the inputs that shape it. */ private cachedRuns; private cachedFrontierCount; /** Frontier splat count by prefix depth; see {@link countAtDepth}. */ private readonly depthCounts; /** Budget range over which {@link cachedRuns} stays the correct frontier. */ private cachedBudgetLo; private cachedBudgetHi; private cachedForDiscovered; constructor(total: number, chunkSize: number, chunkCounts: readonly number[], options: LodSourceOptions); onChunkDecoded(file: number, data: SplatData): void; computeDesiredRuns(_cameraLocal: THREE.Vector3, _frustum: THREE.Frustum, _now: number): LodRun[]; coarsestRunsFor(from: number, to: number): LodRun[]; /** * Recomputes the cached frontier when the budget or discovery has moved. * * The cache is keyed on the *range* of budgets that select the same prefix * depth, not on the budget itself. A camera-weighted governor rewrites the * budget every frame - it wanders by a few percent as the camera drifts - and * an exact-equality key therefore missed on roughly a third of all calls while * choosing the very same depth. Each of those misses re-walks `frontierRuns` * over the whole decoded prefix (millions of splats, several times over if it * steps down levels): measured at 33ms mean and 1.1s worst, it was 92% of all * frame CPU on a multi-mesh scene. Frontier count rises monotonically with * depth, so the selected depth is stable for any budget in * `[thisDepthCount, nextDepthCount)` and the walk can be skipped outright. */ private ensureFrontier; /** * Splats the frontier draws at `depth`, memoized. * * `discoveredDepth` is the longest *contiguous* decoded prefix, so for any * `depth <= discoveredDepth` every chunk the walk reads is already decoded and * the answer can never change afterwards - chunks are only ever added to * `decoded`. That makes this permanently cacheable, which is what lets the * depth search above run without rebuilding runs at each level it rejects. */ private countAtDepth; /** * The rendered runs for a resident prefix of `depth` chunks: within each * chunk, the contiguous ranges of splats that are leaves or whose children * fall beyond `residentCount` (the prefix's total splat count). The chunk's * splats are child-start-descending (leaves first), so each range coalesces * into one run. */ private frontierRuns; private fetchIntentRun; }