/** * {@link SplatClipMesh}: a dynamic-capacity `SplatMesh` that plays any * {@link SplatClip}, driven by a `time` property an `AnimationMixer` can * animate. The mesh owns the transport (time, the `AnimationClip`, waiting * for a frame, errors, the shared staging budget); how frames reach the GPU * is the clip format's business (`splat-clip-playback.ts`): * * - **A format's GPU path** where it has one (`.csgs` on WebGPU: * `csgs-gpu-playback.ts`), which evaluates the motion in a `SplatModifier`. * - **The frame path** otherwise (`frame-playback.ts`): whole frames are * evaluated one ahead of the shown one and swapped into the pool. */ import * as THREE from 'three/webgpu'; import { SplatMesh } from '../core/splat-mesh'; import type { SplatMeshOptions, SplatUpdateOptions } from '../core/splat-mesh-types'; import type { SplatClip } from './splat-clip'; import { SplatClipStagingBudget } from './splat-clip-staging-budget'; /** * Options of {@link SplatClipMesh}. * * @experimental */ export interface SplatClipMeshOptions extends SplatMeshOptions { /** * The renderer the mesh draws with, already initialized * (`await renderer.init()`): the playback path and the pool capacity * depend on its backend and are fixed in the constructor. */ renderer: THREE.WebGPURenderer; /** * `'auto'` (default): the clip format's GPU path where it has one and the * device can hold it (`.csgs`: WebGPU, every section `gpuEligible`, the knot * texture fits), else the frame path. `'gpu'` throws where the GPU path is * not possible; `'frames'` always plays the frame path. */ playback?: 'auto' | 'gpu' | 'frames'; /** * GPU path: sections kept on the GPU. `'all'` makes scrubbing free at the * cost of memory; 2 is the minimum (shown + next). Lowered to what the * device's `maxTextureDimension2D` allows, and to 8192 knot-texture rows * (~134 MB of knots) on any device. Default: `'all'` while the clip's * packed sections stay under 256 MB, else 2. */ residentSections?: number | 'all'; /** Shared staging budget (several clips); default: a private 4 MB-per-frame one. */ staging?: SplatClipStagingBudget; /** SH bands of the pool; defaults to the clip's {@link SplatClip.shBands}. */ shBands?: 0 | 1 | 2 | 3; } /** * Events of a {@link SplatClipMesh}, on top of `Object3D`'s. * * @experimental */ export interface SplatClipMeshEventMap extends THREE.Object3DEventMap { /** * A frame evaluation or a section upload failed; the last good frame keeps * showing. Without a listener the error is logged to the console. */ error: { error: unknown; }; } /** Clip frame of `time` seconds: wraps into `[0, totalFrames)`, but `duration` is the last frame. */ export declare function splatClipFrameAt(clip: SplatClip, time: number): number; /** * A dynamic-capacity `SplatMesh` that plays a {@link SplatClip}: set * {@link time} (seconds), or let an `AnimationMixer` drive it through * {@link animation}, and call `update` every frame. Works standalone and as a * `UnifiedSplatMesh` source (the unified draw calls `update` itself). * * Playing and scrubbing are one code path: whatever sets `time`, `update` * shows that frame as soon as it is available, and holds the last drawn * frame until then. Two captured clips are different sets of splats, so the * mixer's cross-fades and weights do not blend them; a transition is an * opacity fade between two meshes. (Rigged splats, whose motion is a * skeleton's, do blend: see `SkinnedSplatMesh`.) * * The mesh declares the clip's {@link SplatClip.bounds} as its * `displacementBounds`, so every pose sorts inside the quantized depth range. * * @example * ```ts * import * as THREE from 'three/webgpu'; * import { loadSplatClip, SplatClipMesh } from '@voluma/vlam/dynamic'; * * await renderer.init(); * const clip = await loadSplatClip(sceneUrl); * const mesh = new SplatClipMesh(clip, { renderer }); * scene.add(mesh); * * const mixer = new THREE.AnimationMixer(mesh); * const action = mixer.clipAction(mesh.animation); * action.play(); * * const timer = new THREE.Timer(); * renderer.setAnimationLoop(() => { * timer.update(); * mixer.update(timer.getDelta()); * mesh.update(camera, renderer); * renderer.render(scene, camera); * }); * * action.paused = true; // pause * action.time = 1.2; // scrub (seconds) * action.timeScale = -1; // play backwards * ``` * * @experimental The API may change in a minor release. */ export declare class SplatClipMesh extends SplatMesh { readonly clip: SplatClip; /** * An `AnimationClip` named after the clip, with one linear track driving * `.time` from 0 to `duration`, for an `AnimationMixer` rooted at this mesh. */ readonly animation: THREE.AnimationClip; /** The playback path the constructor picked: a format's GPU path, or frames. */ readonly playback: 'gpu' | 'frames'; private clipTime; private readonly strategy; private readonly staging; private lastFrame; /** Frames `time` moved between the last two updates (signed, the short way round). */ private lastDelta; private direction; private waiters; private lastError; private readonly errorListeners; private released; constructor(clip: SplatClip, options: SplatClipMeshOptions); /** * Clip time in seconds. Values outside `[0, duration)` wrap, except * `duration` itself, which shows the last frame (a clamped `LoopOnce`). * Animatable: {@link animation} drives it. */ get time(): number; set time(value: number); /** Fractional clip frame of {@link time}. */ get frame(): number; /** * Integer frame currently drawn, or -1 before the first. Trails * {@link frame} while the wanted frame is uploaded or evaluated. */ get shownFrame(): number; /** Splats alive in the drawn frame. */ get alive(): number; /** * Resolves once the drawn content is exactly {@link time}'s frame (for * tests, captures and thumbnails). Needs `update` calls to progress; a * later `time` change moves the goal. Rejects if the mesh is disposed * first, or if that frame failed to evaluate or upload. */ whenShown(): Promise; addEventListener>(type: T, listener: THREE.EventListener): void; removeEventListener>(type: T, listener: THREE.EventListener): void; /** * Shows {@link time}'s frame (or moves toward it), queues staging, then * runs the `SplatMesh` update. Call every frame before rendering; a * `UnifiedSplatMesh` calls it for its sources. */ update(camera: THREE.PerspectiveCamera, renderer: THREE.WebGPURenderer, options?: SplatUpdateOptions): void; dispose(): void; private fail; private failure; /** Resolves every waiter (`error === null`) or rejects them all. */ private settleWaiters; }