Accessing AnimationGroup directly from .glb instead of scene.AnimationGroups (mesh exported from Blender)

Hello, I’m trying to figure out how to access/play/stop an AnimationGroup directly from a .glb mesh object, rather than the scene.AnimationGroups object.

The end goal is to write something like scene.beginDirectAnimation(importedMesh, attackAnim1, 0, 25, false) and play the animation on that specific mesh. Later, I will need a different animation, so I would do scene.beginDirectAnimation(importedMesh, defendAnim1, 0, 25, false) and so on.

PG example using AnimationGroups so you can see what sort of mesh/mesh construction I’m referring to:

I have the following constraints:

  • The .glb is exported via Blender. Each animation is on a different NLA track in Blender.

  • In my final app, I will have multiple humanoid meshes, and they will have different animations. It is unlikely that any raw animation data will be shared across meshes. However, NLA tracks will have the same name on different humanoid meshes, so filtering AnimationGroups by name is probably a lost cause?

  • Since these are humanoid figures, each AnimationGroup contains numerous targetedAnimations that move individual parts of the parent mesh. I watched a tutorial here: Demystifying Animation Groups - YouTube about combining these, but for my use case it seems infeasible to collapse all targetedAnimations into one AnimationGroup, for the aforementioned reason that they need to play separately at different times. A humanoid mesh will sometimes attack, sometimes defend, etc. and there are several hundred targetedAnimations in a single group.

  • Assigning individual animations to the .glb with something like importedMesh.animations[0].setKeys(myKeyArray) also seems infeasible, as there are a lot of meshes+values manipulated for every animation, and I won’t really be able to keep track of the individual lengths/frames in a larger scale scene.

  • Animations will need to blend together smoothly, most likely accomplished with animation weights like shown here: https://playground.babylonjs.com/#IQN716#9 . However, with multiple humanoid meshes each with individual skeletons, it doesn’t appear it would be possible to tell them all apart. Skeletons will necessarily have generic/shared names.

Is there any strategy that allows for accessing these animations simply from the imported parent mesh? Perhaps I’m understanding something incorrectly in BabylonJS or even Blender, but I haven’t been able to find a solution. Thanks for your attention on this.

1 Like

I think you should use AssetContainers to load all your meshes and store them somewhere, then have a cloning function to get the character asset back from the store. Like so:

After you have cloned the mesh, you should be able to individually control the animations.

3 Likes

meshTask1 in your playground should contains the list of animationGroups related to this task only ???

Thanks @Panuchka I think this might be the answer to what I needed. I didn’t have much of a grasp of Asset Containers at all and this is very helpful.

@sebavan I am possibly/probably missing some basic Javascript knowledge around promises, but could not figure out how to properly return meshTask1 from the loadTestModel function. Since the asset task promise must be resolved and the promise returned, it’s possible to see the groups inside the function but not outside. In my app, I’ll load the model at some point in time and then start/stop various animations at a later point. But open to hearing your thoughts on it of course.

Thanks both for your time!

1 Like

Something like this should work https://playground.babylonjs.com/#6CEBPU#12

1 Like

You can also set assetContainers, to preload models and create instances if you need a model:

Thanks @Panuchka - I believe I’ve arrived at a working solution using the AssetContainer, drilling into the returned objects and combining everything into a CharacterModel class. This should work exactly the way I needed it to!

@sebavan accessing the animation from the scene object isn’t what I’d like to achieve, nor from the Asset Manager @Takemura. But thank you both for taking the time to look into this and answer. Much appreciated.

2 Likes