/** * Semantic Object Animation Video playback from exact UTSBM transforms. * * The runtime keeps only the decoded blocks needed for interpolation resident, reconstructs object-major * quantized matrices, and applies them to Object3D, InstancedMesh, or BatchedMesh targets. * * ```js * const animation = await ObjectAnimationVideo.load( '/assets/clip.oav/manifest.json' ); * const gltf = await gltfLoader.loadAsync( '/assets/clip.oav/scene.glb' ); * animation.bind( gltf.scene, { strict: true } ); * animation.play(); * animation.update( deltaSeconds ); * ``` * * @class ObjectAnimationVideo * @category OAV */ import * as THREE from 'three'; import type { MeshoptVertexDecoderLike } from '../MotionTracks/IndexedMeshoptTrack.js'; import type { TSLFloatNode } from '../types/tsl.js'; import { OAVMeshoptDecoder } from './OAVMeshoptBinary.js'; import type { OAVMeshoptDiagnostics } from './OAVMeshoptBinary.js'; import type { OAVManifest } from './OAVManifest.js'; /** A promise whose settlement functions are retained by the OAV runtime. */ export interface ObjectAnimationVideoDeferred extends Promise { resolve(value: TValue | PromiseLike): void; reject(reason?: unknown): void; } /** Fetch result surface required by {@link ObjectAnimationVideo.load}. */ export interface ObjectAnimationVideoFetchResponse { readonly ok: boolean; readonly status: number; json(): Promise; arrayBuffer?(): Promise; } /** Injectable fetch contract used by {@link ObjectAnimationVideo.load}. */ export type ObjectAnimationVideoFetch = (input: string, init?: RequestInit) => Promise; /** Shared playback options for fetched, in-memory, and directly constructed OAV clips. */ export interface ObjectAnimationVideoPlaybackOptions { loop?: boolean; playbackSpeed?: number; play?: boolean; /** * Meshopt vertex decoder for the UTSBM transform track — pass `MeshoptDecoder` from * `three/addons/libs/meshopt_decoder.module.js` (the same module `GLTFLoader` uses). */ meshoptDecoder?: MeshoptVertexDecoderLike; } /** Direct-construction options: how the UTSBM block assets referenced by the manifest load. */ export interface ObjectAnimationVideoOptions extends ObjectAnimationVideoPlaybackOptions { resolveFile?: (file: string) => string; fetchImpl?: ObjectAnimationVideoFetch; } type ObjectAnimationVideoInternalOptions = ObjectAnimationVideoOptions; /** Options for loading a manifest and its track over the network. */ export interface ObjectAnimationVideoLoadOptions extends ObjectAnimationVideoPlaybackOptions { /** Fetch implementation used for the manifest and UTSBM block assets. */ fetchImpl?: ObjectAnimationVideoFetch; } /** Accepted byte containers in an in-memory OAV folder. */ export type ObjectAnimationVideoFileValue = ArrayBuffer | ArrayBufferView; /** Manifest-relative in-memory files accepted by {@link ObjectAnimationVideo.loadFromFiles}. */ export type ObjectAnimationVideoFiles = Map | Record; /** A manifest object selector used by object and instance bindings. */ export type ObjectAnimationVideoObjectSelector = number | string; /** Result returned after binding same-named descendants beneath a root. */ export interface ObjectAnimationVideoBindResult { bound: number; missing: string[]; } /** Options controlling same-name descendant binding. */ export interface ObjectAnimationVideoBindOptions { strict?: boolean; } /** Options controlling removal of an OAV binding. */ export interface ObjectAnimationVideoUnbindOptions { restore?: boolean; } /** Binding record for a caller-owned Object3D. */ export interface ObjectAnimationVideoObjectBinding { readonly kind: 'object'; readonly target: THREE.Object3D; readonly matrix: THREE.Matrix4; readonly matrixAutoUpdate: boolean; } /** Minimal caller-owned instance target supported by the runtime. */ export interface ObjectAnimationVideoInstanceTarget { setMatrixAt(index: number, matrix: THREE.Matrix4): unknown; readonly instanceMatrix?: { needsUpdate: boolean; }; } /** Binding record for an instance in an InstancedMesh, BatchedMesh, or compatible target. */ export interface ObjectAnimationVideoInstanceBinding { readonly kind: 'instance'; readonly target: ObjectAnimationVideoInstanceTarget; readonly instanceIndex: number; } /** A removable object or instance binding. */ export type ObjectAnimationVideoBinding = ObjectAnimationVideoObjectBinding | ObjectAnimationVideoInstanceBinding; /** Optional named or indexed manifest-object side of an instance mapping. */ export interface ObjectAnimationVideoInstanceObjectMapping { objectIndex?: ObjectAnimationVideoObjectSelector; object?: ObjectAnimationVideoObjectSelector; } /** Named or indexed instance mapping accepted by {@link ObjectAnimationVideo.bindBatchedMesh}. */ export type ObjectAnimationVideoInstanceMapping = ObjectAnimationVideoInstanceObjectMapping & ({ instanceIndex: number; instance?: number; } | { instanceIndex?: never; instance: number; }); /** Compact positional or explicit instance mapping input. */ export type ObjectAnimationVideoInstanceMappingInput = number | ObjectAnimationVideoInstanceMapping; /** Runtime evidence for exact decoding and bounded numerical residency. */ export interface ObjectAnimationVideoDiagnostics { quantizedFrameSlots: number; quantizedFrameBytes: number; currentMatrixBytes: number; worldMatrixBytes: number; diagnosticBufferBytes: number; failure: string | null; decoder: Readonly | null; suspended: boolean; disposed: boolean; } /** Decoder error notification. */ export interface ObjectAnimationVideoErrorEvent { error: unknown; } /** Notification that an exact frame was decoded and cached. */ export interface ObjectAnimationVideoDecodeEvent { frame: number; } /** Notification that the interpolated object matrices were applied. */ export interface ObjectAnimationVideoFrameEvent { frame: number; lowerFrame: number; upperFrame: number; alpha: number; } /** Strongly typed Three.js event map for OAV playback. */ export interface ObjectAnimationVideoEventMap { error: ObjectAnimationVideoErrorEvent; decode: ObjectAnimationVideoDecodeEvent; frame: ObjectAnimationVideoFrameEvent; } export declare class ObjectAnimationVideo extends THREE.EventDispatcher { manifest: Readonly; loop: boolean; playbackSpeed: number; playing: boolean; time: number; duration: number; texture: THREE.DataTexture | null; textureNode: TSLFloatNode | null; ready: ObjectAnimationVideoDeferred; firstFrame: ObjectAnimationVideoDeferred; decoder: OAVMeshoptDecoder | null; private _frames; private _desired; private _requested; private _decoderReady; private _failure; private _disposed; private _suspended; private _resumePromise; private _lifecycleGeneration; private _bindings; private _current; private _world; private _parentIndices; private _matrix; private _worldMatrix; private _localMatrix; private _textureFrame; private _readySettled; private _disposedDiagnostics; /** Fetch a manifest and open its UTSBM transform track. */ static load(url: string, options?: ObjectAnimationVideoLoadOptions): Promise; /** Construct from an in-memory OAV folder map (keys are manifest-relative paths). */ static loadFromFiles(files: ObjectAnimationVideoFiles, options?: ObjectAnimationVideoPlaybackOptions): Promise; constructor(manifest: unknown, options: ObjectAnimationVideoOptions); constructor(manifest: unknown, options: ObjectAnimationVideoInternalOptions); private _createDecoder; private _recordFailure; private _onFrame; private _trimFrameCache; private _requestMissing; private _framePosition; private _syncDesired; private _applyCurrent; private _setTextureFrame; private _needsWorldMatrices; private _applyBinding; private _objectIndex; /** Bind one manifest object to a THREE.Object3D. */ bindObject(indexOrName: ObjectAnimationVideoObjectSelector, target: THREE.Object3D): ObjectAnimationVideoObjectBinding; /** Bind every manifest entry to a same-named descendant of `root`. */ bind(root: THREE.Object3D, { strict }?: ObjectAnimationVideoBindOptions): ObjectAnimationVideoBindResult; /** Bind object ids to instance ids on an InstancedMesh or BatchedMesh. */ bindBatchedMesh(target: ObjectAnimationVideoInstanceTarget, mapping?: readonly ObjectAnimationVideoInstanceMappingInput[] | null): ObjectAnimationVideoInstanceBinding[]; /** Remove one binding; Object3D bindings restore their authored transform by default. */ unbind(binding: ObjectAnimationVideoBinding, { restore }?: ObjectAnimationVideoUnbindOptions): boolean; play(): this; pause(): this; setTime(seconds: number): this; setFrame(frame: number): this; update(deltaSeconds: number): this; /** Release active fetch/decode work while retaining presented state. */ suspend(): void; /** Resume indexed reads without replacing retained matrices, bindings, or texture identity. */ resume(): Promise; /** Copy the currently interpolated matrix for custom integrations. */ getMatrixAt(indexOrName: ObjectAnimationVideoObjectSelector, target?: THREE.Matrix4): THREE.Matrix4; /** Exact decoder and bounded-residency evidence. */ getDiagnostics(): Readonly; private _buildDiagnostics; dispose(): void; } export {};