Yeap, you are correct! I was suspicious of that part as well, but didn’t have time to test it yet
Here is the final version, with added animation blending!
So what I gather, here is what needs to be done if you wish to clone a fully rigged and animated character “manually”. I also assume there might be some differences if the glb/gltf formats are not used…
- You need to store the root mesh, the skeleton and the animation groups somewhere.
- Clone the root mesh using instantiateHierarchy, with the doNotInstantiate -option. You also need to store the links between the original mesh parts with the cloned mesh parts.
- Clone the skeleton with the regular clone function.
- Set the cloned root mesh as skeletons overrideMesh if skeleton already has this pointing to somewhere (as in the original mesh, so it needs to be replaced).
- Fetch all the descendants of the rootMesh with getDescendants (with false as option)
- Set the cloned skeleton as the skeleton of all the descendants.
- Link all the cloned skeleton bones with the new cloned root mesh. You need to use the stored links created in section 1.
- Clone each animation group separately using the clone function. This works a bit differently than normal clone, since you need create a special conversion function to set the animation group to a new target, which is some part of the new cloned root mesh hierarchy. Here you need the stored links as well from section 1.
- Done! You can use your cloned animation groups to play animations separately
Have to say that I really love Babylon community Thank you all for helping me!
Update:
You can use asset containers to do the same thing easier! Check this playground: https://playground.babylonjs.com/#S7E00P#237