Loading character with animations to scene and cloning it with animation groups

Yeap, you are correct! I was suspicious of that part as well, but didn’t have time to test it yet :slight_smile:

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…

  1. You need to store the root mesh, the skeleton and the animation groups somewhere.
  2. 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.
  3. Clone the skeleton with the regular clone function.
  4. 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).
  5. Fetch all the descendants of the rootMesh with getDescendants (with false as option)
  6. Set the cloned skeleton as the skeleton of all the descendants.
  7. Link all the cloned skeleton bones with the new cloned root mesh. You need to use the stored links created in section 1.
  8. 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.
  9. Done! You can use your cloned animation groups to play animations separately :slight_smile:

Have to say that I really love Babylon community :heart: 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

7 Likes