Create AnimationGroup from blender exported animations

Hi all,

So I’ve got a couple of meshes exported from blender. I’d like to create an AnimationGroup using animations from these meshes. Is this possible?

So far, I’ve tried:

var animationGroup = new BABYLON.AnimationGroup(“my-animation-group”);

let firstAnimatable = firstSkeleton.beginAnimation(firstAnimationName);
firstAnimatable.pause();

And did the same thing for my secondSkeleton, thirdSkeleton, etc. And then, I tried the following:

// First try.
animationGroup.addTargetedAnimation(firstAnimatable.getAnimations()[0].animation, firstMesh)

// Second try. I noticed the “Target” on the animations was “_matrix”, so I tried getting the animations using getAnimationByTargetProperty("_matrix")
animationGroup.addTargetedAnimation(firstAnimatable.getAnimationByTargetProperty("_matrix"), firstMesh);

My third try was just like the first try, but instead of just adding firstAnimatable.getAnimations()[0].animation, I added all the animations to the group (i.e. firstAnimatable.getAnimations()[0].animation, firstAnimatable.getAnimations()[1].animation, firstAnimatable.getAnimations()[2].animation, etc…)

None of the approaches worked: every time I did animationGroup.play(), nothing happened. Any tips?

Hey! do you mind reproducing the issue in the PG?

You can use this doc to reference your files: Using External Assets - Babylon.js Documentation

I used the animation blending example to create a quick and dirty PG example.

https://www.babylonjs-playground.com/#IQN716#81

In that example I’m only using 1 mesh (in my project I have 3 meshes), but even with that 1 mesh I’m not able to get it to work. I feel like if I can get that example to work, I’ll be able to get my 3 meshes working as well.

I’m not sure what the target in addTargetedAnimation() is supposed to be, and how to convert the animatables into an animation I can pass to addTargetedAnimation().

Hello this is because the idleAnimation (for instance) contains 57 animations :slight_smile: (one per bone)

So technically you will need to call addTargetedAnimation 57 times to add the animation for each bone

1 Like

Thanks, I got it working here:

https://www.babylonjs-playground.com/#IQN716#84

However, now I’ve got a new problem - when the speedRatio of the animation group is slow, the animation looks choppy as hell. Is there a way to interpolate the animationGroup? I was kinda hoping animationGroup.normalize() would automatically interpolate the animations if I passed in say, beginFrame = 0 and endFrame = 1000. That unfortunately didn’t work :stuck_out_tongue:

Also, performance wise, is this approach much slower than just calling scene.beginAnimation()?

Nope this is quite the same :slight_smile:

For interpolation, you can set the animation loopMode to cycle (instead of constant):
https://www.babylonjs-playground.com/#IQN716#85

(check line #42)

1 Like

Thanks Del. You’re an absolute legend mate.

1 Like