Skip to content

Commit b21a969

Browse files
authored
Fix logic for mesh matrices in bakeVertexDataSync (#16775)
I hadn't fully validated this in the pipeline after making some adjustments for performance - the piece that was missing was grabbing the mesh matrices for each frame. Here is a prototype shim of the exact logic working in a PG: https://playground.babylonjs.com/?BabylonToolkit#CP2RN9#304
1 parent 868d657 commit b21a969

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

packages/dev/core/src/BakedVertexAnimation/vertexAnimationBaker.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,27 @@ export class VertexAnimationBaker {
5151

5252
const vertexData = halfFloat ? new Uint16Array(floatsPerFrame * totalFrames) : new Float32Array(floatsPerFrame * totalFrames);
5353

54-
let offset = 0;
55-
const matrices = this._skeleton.getTransformMatrices(this._mesh);
54+
let frameIdx = 0;
5655

5756
this._skeleton.returnToRest();
5857

59-
if (halfFloat) {
60-
for (const { from, to } of ranges) {
61-
for (let f = Math.floor(from); f <= Math.floor(to); ++f) {
62-
this._scene.beginAnimation(this._skeleton, f, f, false, 1.0);
63-
this._skeleton.computeAbsoluteMatrices(true);
64-
for (let i = 0; i < floatsPerFrame; ++i) {
65-
vertexData[offset + i] = ToHalfFloat(matrices[i]);
66-
}
67-
offset += floatsPerFrame;
68-
}
69-
}
70-
} else {
71-
for (const { from, to } of ranges) {
72-
for (let f = Math.floor(from); f <= Math.floor(to); ++f) {
73-
this._scene.beginAnimation(this._skeleton, f, f, false, 1.0);
74-
this._skeleton.computeAbsoluteMatrices(true);
75-
vertexData.set(matrices, offset);
76-
offset += floatsPerFrame;
58+
for (const range of ranges) {
59+
for (let f = Math.floor(range.from); f <= Math.floor(range.to); f++) {
60+
this._scene.beginAnimation(this._skeleton, f, f, false, 1.0);
61+
this._scene.render();
62+
this._skeleton.computeAbsoluteMatrices(true);
63+
const matrices = this._skeleton.getTransformMatrices(this._mesh);
64+
const base = frameIdx * floatsPerFrame;
65+
if (halfFloat) {
66+
matrices.forEach((val, i) => {
67+
vertexData[base + i] = ToHalfFloat(val);
68+
});
69+
} else {
70+
matrices.forEach((val, i) => {
71+
vertexData[base + i] = val;
72+
});
7773
}
74+
frameIdx++;
7875
}
7976
}
8077

0 commit comments

Comments
 (0)