GLB + VAT Not working (merge needed?)


I’ve been trying to add VAT on thinInstances, but I realized I’m not even able to enable VAT on a simple clone of a loaded GLB. I’ve done some tests:

TEST 6 is uncommented: this is my first objective, using VAT on a simple clone (next, will be thinInstances).

Currently, the result is that the model is not animated.

I’ve read some forum posts and noticed that some people were merging their models before using VAT. Is that mandatory? The documentation does not speak about that. I tried to merge, but as you can see in the playground, the only successful merge is when I merge child meshes only (2 meshes) and keep the root mesh as parent.

If the merge is not possible in some use cases (how to know that?), do we have to create a VAT for each mesh? I also tried that in my TEST 7, but the model didn’t change at all. If yes, does it make sense to add the same skeleton to each mesh? From what I understand, a skeleton applies to vertices, so it might not work if some vertices are not part of the mesh…

If the goal is to have only one mesh, with one skeleton, and one VAT, I suppose I have to manage to merge and get rid of:
Cannot merge meshes with different overrideMaterialSideOrientation values.

Thank you for your help.

You can adapt what @Alexander_Sosnovskiy came up with in this thread:

I modified the original PG a bit to avoid merge meshes. Also, I set the total number of frames to bake to 500, because the animation is very long: it takes around 1mn to bake it all! You can set numFrames = -1 line 36, if you want to bake them all.

The PG is setup to merge several animations and not a single one which contains different animations. You will either have to update your .glb file to conform to this (and list the animations in the array line 41), or change the way the baking works.


Hi @Evgeni_Popov and thank you for answering so quickly!

There is something I do not understand in your playground. My model contains 3 meshes:

  • root
    • child1
    • child2

We initialize the baker with child 1:

[L78] const b = new BABYLON.VertexAnimationBaker(scene, modelMeshes[0]);

We then applied the same texture on both children. And we can switch to compute the texture by giving the other child; it still works. Could you explain this behavior please? I suppose this is specific to my model, but this is very surprising.

Also, maybe a Typescript signature should be updated, in Skeleton.d.ts :

 * Gets the list of transform matrices to send to shaders inside a texture (one matrix per bone)
 * @param mesh defines the mesh to use to get the root matrix (if needInitialSkinMatrix === true)
 * @returns a raw texture containing the data
getTransformMatrices(mesh: AbstractMesh): Float32Array;

should be :

getTransformMatrices(mesh: Nullable<AbstractMesh> = null): Float32Array;

VertexAnimationBaker only uses the mesh you pass as a parameter to get the skeleton from, and to stop all the animations (this._scene.stopAnimation(this._mesh)). In the PR below, I added the possibility to directly pass a skeleton instead of a mesh. Thus, it makes it clearer that the texture is computed for a skeleton and not a mesh and can be reused for multiple meshes, if they all use the same skeleton.

Done in the PR below.


Oh great! Indeed, I was in trouble, but I finally understood. I also managed to get something working with GLB + thin instance + VAT + Recast, thanks to the Babylon team! :heart_eyes:

I’ll share with you from time to time the progress of the game in the Demos and Projects section (being the only developer, it will take some time).

1 Like