voxolith

bakePose()

Bake a posed voxel model from a rigged rest model and bone matrices. Each posed cell is inverse-mapped to rest space through its bone, so rotated limbs stay solid; a final pass closes the cracks on the outside of bending joints. yaw turns the result about the anchor at any angle, which resamples...

function bakePose(
   model: EntityModel, 
   rig: Rig, 
   matrices: Float32Array, 
   opts?: BakeOptions
): EntityModel;

Defined in: engine/src/animation/bake.ts:120

Bake a posed voxel model from a rigged rest model and bone matrices. Each posed cell is inverse-mapped to rest space through its bone, so rotated limbs stay solid; a final pass closes the cracks on the outside of bending joints. yaw turns the result about the anchor at any angle, which resamples (scenery sticks to 90-degree orientations for exactness).

The result is a new dense model cropped to the posed voxels, with bones and an anchor that sits at the same point as the rest anchor. Cost grows with each bone's posed bounding box, so bake once per pose and cache (see makePoseCache, makeCrowd).

Parameters

ParameterTypeDescription
modelEntityModelThe rest model; it must carry bones. Pass a wounded or severed rest model to pose damage.
rigRigThe entity's rig.
matricesFloat32ArrayBone matrices from poseMatrices, 12 floats per bone.
opts?BakeOptions-

Returns

EntityModel

The posed model.

Example

const pose = sampleClip(walk, anim.time(), rig.bones.length);
const posed = bakePose(rat.model, rig, poseMatrices(rig, pose), { yaw: Math.PI / 4 });
stamper.put(1, toSprite(posed), { x, y, z }, ratBase);

On this page