# How to bind mesh to skeleton while preserving vertices size?

Binding a mesh to a skeleton will cause the mesh to transform according to the skeleton matrix

What’s the best way to force the mesh to maintain its vertex transforms before and after binding? I supposed I would need to somehow compute the vertices positions before binding, cache it and ‘restore’ it manually after binding?

Here is a PG: https://playground.babylonjs.com/#SYQW69#1035

Before binding
(notice the mesh box at the feet)

After binding
(The mesh box blows up due to the skeleton base matrix. Had to zoom out here)

Hello @mrlooi, how are you doing?

I believe you are having a problem because the mesh that you want to bind the skeleton with and the transforms node that are linked against the skeleton have different roots. This will make so that the bind matrix applies the inverse transformation between the root skeleton transform node and the box mesh to the box mesh vertices.

If they both have the same parent this issue will not happen. (As you can see in the image attached)

I have modified your playground by adding a setParent to the box mesh, and than set the position, rotation and scaling for the box back to the values they had before binding.

Examples: Load glTF model | Babylon.js Playground (babylonjs.com)

1 Like

Thanks a lot @srzerbetto , yea I know about that, but I was wondering if there was a way to bake the vertices without dealing with reparenting and setting scales etc

Maybe you can use bakeTransformIntoVertices using the relative transform between the box mesh and the skeleton parent?

Examples: Load glTF model | Babylon.js Playground (babylonjs.com)

1 Like

ah that’s a nice one, I’ll test it out, thank you!

Oh wait actually it doesn’t quite preserve all the transforms

For example, if box is initialized with box.position.x = 1, the box moves after binding

If you don’t multiply by the box inverse world matrix you can keep the relative transforms.

Examples: Load glTF model | Babylon.js Playground (babylonjs.com)

1 Like

EDIT: Ok yep it works, I guess this PG would be a bit less confusing
The one in the solution showed the box moving (due to the bake being called before the skeleton binding) which could be confusing to some new to the topic

Thanks!