Targeting multiple GLTF animations to a single rig

Hey there!

We have a base rig gltf which we’d like to apply animations to.

The animations are contained in separate gltf files, one animation per file, so we can add new animations into the scene on the fly without a client needing to re-download an entire monolithic gltf. The gist of what we want to do is, take the animations from one of the other rigs and run them on the base rig.

The closest we got was cloning the skeleton from the animation rig mesh and overwriting the skeleton of the base rig mesh (using simple assignment), then copying each AnimationGroup from the animation rig into the base rig, then calling play() on the correct AnimationGroup. However, things get tricky because there are multiple meshes in each rig, and the approach visually distorted the 3d object we were operating on.

Each rig (for now) has identical meshes, skeletons, etc. and we’ve tried a number of other things, including reassigning the target of each TargetedAnimation instance, using containers to load other rigs invisibly and moving just the AnimationGroup to the main rig, all to no avail.

The only examples we’ve seen on this forum are people using ranges of animation within the same file, but haven’t seen examples of combining that data of multiple animationGroups.

Are we over-complicating this? Would like to know if we’re at all going down the right path here. Thanks for reading!

Hello and welcome to the Babylon community! I’ll ping @PirateJC and @PatrickRyan who might have encountered this issue before :smiley:

1 Like

I’m targeting multiple GLTF animations to multiple rigs, and what I’ve done with babylon 4.2:

  1. Load GLTF and exporting the BABYLON.AnimationGroup to a json file.
  2. Load non-cached BABYLON.AnimationGroup by “BABYLON.AnimationGroup.Parse”

Tip: My experience is pre-loading the most used animations for a better user-experience.

2 Likes

@carolhmj thank you for having me, and I appreciate you pinging some other help.

@webgrid oh wow this is great, to know, going to give this a shot and report back with results.

@pasquale this type of retargeting animations from individual animation files is fairly common as it allows you to save file size by not needing to include duplicate animation data across every mesh that needs that animation. It also allows you to easily update animation clips in one place and have them updated across all meshes that use the animation. Typically I see the files that contain the individual animations using either a default mannequin mesh that uses as few triangles as possible to keep the file size down, or the file is exported with no mesh and is just a skeleton and animation data as the mesh in the animation file is not needed when retargeting.

The critical thing here is that the skeleton in the animation file and the skeleton in the mesh you are retargeting to are identical. There can be some exceptions like the base animation skeleton has a tail and animations to the tail but the skeleton you are retargeting to does not have a tail. If there are some joints toward the end of a joint chain that are missing in the retargeted mesh any animations passed to those missing joints will be ignored. But if you have a different structure in the middle of your joint chain, your animation will just break.

Hot swapping skeletons on a mesh is also problematic because the skinning data will not match up to a skeleton with a different hierarchy assigned to a mesh. In this case, if you radically have to change a skeleton on the fly with a mesh (maybe your character has Inspector Gadget-type robotic arm that extends from their hat but you don’t want to pay the cost of the extra joints and mesh when the arm is not in use) then it is better to swap the meshes entirely to a new mesh that has been skinned to the appropriate skeleton and then pass on the animation clip you need.

I also like the approach @webgrid mentions with exporting the animation group to a json file as that can be a nice consolidation of the most used animations. But you should be able to just assign any animation group to any mesh just like in this demo where the same animation is passed to two different meshes. Of course, these are simple cubes and the animations are authored in Babylon, but the general method should be the same. Create your animation groups from the animation data of any loaded files, and then be able to play those groups on any mesh in your scene.

3 Likes