Backed texture : limit?


Maybe I didn’t get something about baked textures

The vertexData.json tells the width is 264.
I don’t understand why my baked texture only has a width of 264, when my mesh has 15k vertices.
it has a height of 32, which is correct because the anim has a length of 32 frames.

I reused the code in the example.

let baker = null,
mesh = null;

const ranges = [{ from: 0, to: 32, name: "My animation" }];
SceneLoader.ImportMeshAsync("", "/path/", "untitled.glb", scene, undefined)
.then((importResult) => {
        mesh = importResult.meshes[1]; //<- offset 1 because 0 has no skeleton

        // create the baker helper, so we can generate the texture
        baker = new VertexAnimationBaker(scene, mesh);
        // you can slice the animation here with several animation ranges.
        return baker.bakeVertexData(ranges);
.then((vertexData) => {
        // we got the vertex data. let's serialize it:
        const vertexDataJSON = baker.serializeBakedVertexDataToJSON(vertexData);
        // and save it to a local JSON file
        let a = document.createElement("a");
        a.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(vertexDataJSON));
        a.setAttribute("download", "vertexData.json");;

So, I thought I should have a texture width of about 15k.
total size of the texture 15k * 3 (<=>3 points in vertex) * sizeof(float) * 32 lines

Not sure what I missed…

May you help? :upside_down_face: :slightly_smiling_face:

Reading this post it is not per vertex but a matrix per bone.

Quick question before I deal with it tomorrow: is each matrix local to the bone? So the value has to be considered relative to the root of the mesh and then, one can apply the translation as needed?
3x3 or 4x4 matrices?
The base of those matrices is the gltf’s bind pose of each bone?

cc @Evgeni_Popov

The baked matrices are the final matrices after all transformations have been done


for the size of it,
mesh._bonesTransformMatrices = new Float32Array(16 * (this.bones.length + 1));,

so a 4x4 matrix.

@Raggar : I currently roam in the code, but it should be the final transform of the local matrix? in comparison to the bind pose?

some food:

_computeTransformMatrices(targetMatrix, initialSkinMatrix) {
    for (let index = 0; index < this.bones.length; index++) {
      const bone = this.bones[index];
      const parentBone = bone.getParent();
      if (parentBone) {
        bone.getLocalMatrix().multiplyToRef(parentBone.getFinalMatrix(), bone.getFinalMatrix());
      } else {
        if (initialSkinMatrix) {
          bone.getLocalMatrix().multiplyToRef(initialSkinMatrix, bone.getFinalMatrix());
        } else {
      if (bone._index !== -1) {
        const mappedIndex = bone._index === null ? index : bone._index;
        bone.getAbsoluteInverseBindMatrix().multiplyToArray(bone.getFinalMatrix(), targetMatrix, mappedIndex * 16);
    this._identity.copyToArray(targetMatrix, this.bones.length * 16);

Yes, it is the final transformation of the local bone matrix, as bone.getLocalMatrix().multiplyToRef(parentBone.getFinalMatrix(), bone.getFinalMatrix()); shows.

Note that because it is skinning, we also remove the bind pose by multiplying by the inverse bind matrix (bone.getAbsoluteInverseBindMatrix().multiplyToArray(bone.getFinalMatrix(), targetMatrix, mappedIndex * 16);).


Thanks! Let’s get to work now :+1: