Understanding Skeletons and Bones

I know that the usual way to deal with meshes with skeletons and animations is to produce them in something like Blender and import into Babylon.js. However I like to get right down to basics in order to learn and understand.

My expectations of how bones and skeletons work is completely wrong. I finally worked out how to rotate a bone but then expected the linked mesh to rotate with it.

In this PG from an already created skeleton animation I rotate a bone and the mesh rotates as well
https://www.babylonjs-playground.com/#QY1WYT#114

When I try to construct my own example the bone rotates but not the mesh, using either rotation or rotationQuaternion.

https://www.babylonjs-playground.com/#TAFTE5
https://www.babylonjs-playground.com/#TAFTE5#3

I would be grateful if anyone can offer advice on this issue and even more so if they could give further explanation of the working of skeletons and bones in Babylon.js:slightly_smiling_face:

1 Like

After a bit of digging in the source code of Bone / Skeleton, I find that you should call:

bone0.updateMatrix(BABYLON.Matrix.Identity());

after you change the position or quaternion of bone0, to trigger some internal recalculations:

https://www.babylonjs-playground.com/#TAFTE5#4

Also, you did:

    for (var i = 0; i < nbVertices; i++) {
        m.push(0.5, 0.15, 0.35, 0.25);
        mi.push(1, 0, 0, 1);
    }

mi holds the bone indices to use for each vertex. As you have a single bone, you should use index 0 for all 4 influences.

Regarding m (weights), the sum should equal to 1, but I think Babylon is doing a renormalization on its own.

5 Likes

@Evgeni_Popov thank you, that has taken me a step further forward.