Baking an animation

Is it possible in JavaScript to get the transformed vertex positions of a skinnedMesh after setting an animation pose? Or alternatively is there a way to update a vertex to an animation time in JavaScript.

Some pseudocode that I combined from the previous thread where you asked this question:

// simplified with boneTransform
let skinned = new THREE.Vector3();
let geometry = skinnedMesh.geometry;
let position = geometry.attributes.position;
for (let i = 0; i < position.count; i ++ ) {
  skinned.set(position.getX(i),position.getY(i),position.getZ(i));
  skinnedMesh.boneTransform(i, skinned);
  //skinned is now in model space... (probably what you're looking for..)
  
  //to get it in worldspace...
  skinned.applyMatrix4( skinnedMesh.matrixWorld );
}

Thanks. boneTransform is now applyBoneTransform. The source gltf.scene that the AnimationMixer is controlling needs adding to the scene while baking the animation for mixer.setTime to affect the bone transforms.

1 Like

Are you going to write these vertex positions to a texture?
If so, you can arrange them in rows, then use the bilinear filtering to tween the frames right in the texture read…
position = texture(frameTexture,vec2(gl_VertexID/vertexCount,frameTime));

Thanks for the advice. I’m just saving them to a StorageBuffer. Seems to work fine. I’ll try your suggestion in another example. TSL is amazing!

1 Like

Awesome work!! (looks like one of the terms in atan migth needs flipping)

1 Like