/** * {@link SkinnedSplatMesh}: a static splat skinned by a `THREE.Skeleton`, the * splat counterpart of `THREE.SkinnedMesh`. Whatever moves the bones moves the * splats: glTF clips under an `AnimationMixer` (with cross-fades and action * weights), IK, physics or plain code. * * The splats stay in the pool as captured (the bind pose). Each splat carries * up to four bone indices and weights in float channels; a small RGBA float * texture holds one 3×4 matrix per bone, from the bind pose to the current * one, refreshed in `update`. A `SplatModifier` blends a splat's bone * matrices and moves its center and shape (the linear part goes through the * covariance as `M·Σ·Mᵀ`); a position-only twin in `sortDisplacement` makes * the standalone WebGPU sort see the posed centers. */ import * as THREE from 'three/webgpu'; import { SplatMesh } from '../core/splat-mesh'; import type { SplatData } from '../core/splat-data'; import type { SplatModifier } from '../core/splat-modifier'; import type { SplatMeshOptions, SplatRange, SplatUpdateOptions } from '../core/splat-mesh-types'; /** * Most bones a skeleton bound to a {@link SkinnedSplatMesh} may have. * * @experimental */ export declare const SKINNED_SPLAT_MAX_BONES = 4096; /** * Per-splat skinning: which bones move each splat, and how much. * * @experimental */ export interface SplatSkinData { /** Bones per splat (the length of each splat's run in {@link indices} and {@link weights}). */ readonly bonesPerSplat: 1 | 2 | 4; /** `count · bonesPerSplat` indices into `skeleton.bones`. */ readonly indices: ArrayLike; /** * `count · bonesPerSplat` weights, normalized per splat (all zero means the * first bone alone). Stored in 8 bits each. */ readonly weights: ArrayLike; } /** * Options of {@link SkinnedSplatMesh}. * * @experimental */ export interface SkinnedSplatMeshOptions extends SplatMeshOptions { /** The splats' bone indices and weights, in the order of the data's splats. */ skin: SplatSkinData; } /** * A static splat skinned by a `THREE.Skeleton`: the splat counterpart of * `THREE.SkinnedMesh` (see the module comment for how it works). * * The splats' local space is the bind space: the frame the skeleton's * inverse bind matrices were made in. With a glTF, put the mesh where the * rig's `SkinnedMesh` is (for example as its child) and bind with that * mesh's skeleton and `bindMatrix`. The data keeps its own axes (no upright * correction is applied), so the skeleton must use the same ones. * * Bounds follow the pose: each `update` checks the posed reach against * `displacementBounds`, grows it when a limb (or root motion) leaves it, and * shrinks it back once it is far larger than the pose needs. A box the app * sets itself is only ever grown. * * Limits: view-dependent SH is evaluated in the bind pose, so strong SH on a * turned limb is stale. The WebGL2 worker sorter sorts bind-pose centers, and * the pooled unified draw rejects channel-reading modifiers. For rigid parts * alone (a vehicle's wheels and doors), `MergedSplatMesh` with one source per * part is exact on every path. * * @example * ```ts * import * as THREE from 'three/webgpu'; * import { SkinnedSplatMesh, computeSplatSkinWeights } from '@voluma/vlam/dynamic'; * * // A glTF with the rig: a low-poly SkinnedMesh in the splat's frame, and clips. * const proxy = gltf.scene.getObjectByProperty('isSkinnedMesh', true) as THREE.SkinnedMesh; * proxy.visible = false; * const mesh = new SkinnedSplatMesh(splats, { skin: computeSplatSkinWeights(splats, proxy) }); * proxy.add(mesh); // the proxy's frame is the bind space * mesh.bind(proxy.skeleton, proxy.bindMatrix); * scene.add(gltf.scene); * * const mixer = new THREE.AnimationMixer(gltf.scene); * const walk = mixer.clipAction(THREE.AnimationClip.findByName(gltf.animations, 'Walk')!); * walk.play(); * // Later: walk.crossFadeTo(run, 0.4, true). * * renderer.setAnimationLoop(() => { * mixer.update(timer.getDelta()); * mesh.update(camera, renderer); // refreshes the bone texture from the skeleton * renderer.render(scene, camera); * }); * ``` * * @experimental The API may change in a minor release. */ export declare class SkinnedSplatMesh extends SplatMesh { /** The splats' single range, for channels a host writes (a paint mask). */ readonly range: SplatRange; /** Bones per splat the mesh decodes. */ readonly bonesPerSplat: 1 | 2 | 4; /** The bound skeleton, or `null` before {@link bind} (the splats then rest in the bind pose). */ skeleton: THREE.Skeleton | null; /** As `THREE.SkinnedMesh.bindMode`: `'attached'` follows this mesh's world matrix. */ bindMode: 'attached' | 'detached'; /** The matrix the skeleton was bound with (bind space → the skeleton's world). */ readonly bindMatrix: THREE.Matrix4; /** Inverse of {@link bindMatrix}, or of the world matrix in `'attached'` mode. */ readonly bindMatrixInverse: THREE.Matrix4; private readonly source; private readonly weights; private readonly indices; /** Splat-center box of every bone's splats, in bind space (empty for an unused bone). */ private boneBoxes; private bones; /** One 3×4 row-major matrix per bone, bind pose → current pose; the texture's data. */ private matrices; private skin; private skinSort; /** The bounds {@link followPose} last set, to tell them from a box the app set. */ private ownedBounds; private readonly scratch; constructor(data: SplatData, options: SkinnedSplatMeshOptions); /** The skin modifier, once bound; on {@link modifiers}, exposed for hosts that restack. */ get skinModifier(): SplatModifier | null; /** * Binds a skeleton, as `THREE.SkinnedMesh.bind` does: with no `bindMatrix`, * the mesh's world matrix becomes the bind matrix and the skeleton's * current pose its bind pose (`skeleton.calculateInverses()`). */ bind(skeleton: THREE.Skeleton, bindMatrix?: THREE.Matrix4): void; /** * Refreshes the bone texture from the skeleton's current bone world * matrices (and this mesh's, in `'attached'` mode), and grows the bounds if * the pose left them. `update` calls it; call it yourself only to read * {@link posedSplatData} between updates. * * Bones are read through `updateWorldMatrix`, so a bone whose matrix is set * by hand (`matrixAutoUpdate = false`) needs `matrixWorldNeedsUpdate = true`, * as everywhere in three.js. */ refreshSkin(): void; /** * Keeps {@link displacementBounds} around the pose: grows them when the pose * leaves them, and shrinks bounds the mesh set itself once they are far * larger than the pose needs. A box the app set is never shrunk, only grown. */ private followPose; private setOwnedBounds; /** * The splats in the current pose, on the CPU, matching what the GPU draws * (same quantized weights): for picking against posed splats, CPU queries * and exports. A pass over every splat; call it per query, not per frame. */ posedSplatData(): SplatData; update(camera: THREE.PerspectiveCamera, renderer: THREE.WebGPURenderer, options?: SplatUpdateOptions): void; dispose(): void; /** Box of the bind-pose centers of every splat each bone moves at all. */ private measureBoneBoxes; }