Animation weighting issues

I’m having difficulty understanding how skeletal animations fit into babylon. I know that I can tell the scene to play a skeletal animation.

What I’d like to do is to take animations from two identical skeletons, apply one as additive and adjust the weighting.

From the documentation it looks like that weighting is an attribute of an AnimationGroup, and from the limited examples in the documentation it looks like animation groups can only contain simple procedural animations.

Is there a way to get a skeletal animation as an object and add it to an animation group?

I may be able to frame this question better as well. Let me start over.

I have a mesh with additional morph targets and an animation track.

The animation track goes like this:

Frame 0: T-pose
Frame 1-60: idle loop
Frame 61: enlarged skeleton

Then there’s an accompanying morph target to go with the enlarged skeleton. Frame 61 stretches the bones, and the morph target increases the bulk of the model.

When I import the mesh it begins playing the entire file automatically. If I tell the scene to play frames 1-60 it doesn’t work and the mesh import task stops executing, with no error output.

Additionally, when I inspect the mesh object, I can’t find the animations it’s playing anywhere, even in the bones. The mesh HAS a skeleton, but it seems like the skeleton is also imported separately to the scene. Are both skeletons the same reference?

I don’t think I can do any additive blending to apply the enlarged skeleton without a reference to the animation. It’s very frustrating.

Additional issues:

I’ve found the animationgroup for the mesh. I can stop the animation, but if I start it again I only have control over the rate, not the from/to. It just ignores from/to.

        importedData.loadedAnimationGroups[0].stop();
        importedData.loadedAnimationGroups[0].start(true, 3.0, 1, 60, false);

Okay! On the first loop it plays from To and finishes at From, but after that it just plays from start to end. That’s a bit useless.

More insight: I see in the AnimationGroup that each bone animation track is a child (a track for position, rotation, scale, etc.) That’s good, at least I know where they are now.

  • Setting _from and _to does nothing.
  • Using start() does not update_from or _to. Playing the animation does not use _from or _to.
  • And finally, I can’t even handle it in an observer because the docs do not specify what [target] is in Scene.BeginAnimation(). It’s not a mesh, skeleton or animationgroup because none of those things cause the animation to start playing if it’s stopped.

Finally, the issue appears to be (thanks Scene debug layer!) that GLTF animations in Babylon don’t respect the To and From times, whether they’re entered in frames or seconds.

Part of why I’m hung up on this is Cinema4D only exports a single animation group and I don’t want to learn to rig and animate in Blender.

What I may try to do is clone my file, do the animations individually and then import everything and just use the animation groups on the single visible mesh.

My biggest concern however is this: if GLTF doesn’t support any animation controls aside from start and stop with no arguments, how is additive blending supposed to work?

All right!:slight_smile:

To make sure we can help you as fast as possible, I would highly recommend to create a simple repro in the Playground. This will be far easier for everyone to provide guidance or even solution :slight_smile:

1 Like

I’ve abandoned the workflow I was using that was forcing me to select frame ranges and use different files. Now I just use Blender and get a single file out. That fixed a lot of issues.

What I’m stuck on now is getting additive animations to work. I’ll try doing a repro in the playground like you suggested and come back.

Okay, here we go: https://playground.babylonjs.com/#6I67BL#123

If you uncomment line 27 the mesh vanishes, presumably transformed offscreen. Is there a reason why?

@Evgeni_Popov do you mind having a look pretty please?

I noticed calling onBeforeAnimation make it work:

https://playground.babylonjs.com/#6I67BL#129

Let me know if it is the right fix.

Yes! Two things actually: in my working copy I was trying to make both animations additive, which caused the mesh to disappear as I guess there was no base animation. There’s also some stuff with magic numbers and single-frame GLTF animations.

Thanks everyone, made a lot of progress last night.

I’ve managed to move the progress into my working copy.

Now when I set the weight of the additive animation it’s pretty much binary. Any value over 0.0 applies it 100%, but I can see that the weight is between 0.0 and 1.0. I didn’t have this issue with the test mesh, so it’s probably a mesh problem.

My additive animation is designed to scale the limbs of the skeleton larger but it’s also based on the idle pose rather than a T-pose. Could that cause that behaviour?

Edit: okay it’s not the T-pose thing.

So it looks like that even though the animation is additive, it’s not behaving as if it’s additive. On top of that the weight is doing the above strange behaviour.

Here’s the mesh: https://github.com/antidamage/Filestore/raw/main/Hipster.glb

Edit: you can see it in the playground here: https://playground.babylonjs.com/#6I67BL#157

@Evgeni_Popov I am running out of idea on this one, would be amazing if you could have a look :slight_smile:

1 Like

Will have a look as soon as possible but I want to finish my current PR/doc first while it is fresh in my mind (else it will still take hours before I’m up to speed).

1 Like

I think a clue is that it’s definitely to do with the mesh as the XBot.glb file DOES animate smoothly.

I’ve been making a new mesh and have uploaded it.

I am very interested in why the playground fails to finish loading: https://playground.babylonjs.com/#6I67BL#157

The model is hidden behind the loader and is interactable if you drag the pane over.

In my app the model is present but never displays. It might be one of the animation groups, as bringing up the inspector and fiddling with the two animations can cause the model to appear and disappear in the playground.

Edit: left it alone and after a few minutes it loaded and I couldn’t replicate the earlier behaviour.

For whatever reason animation weights aren’t working with that file. Fair enough.

I’m now trying to goToFrame() and stop on that frame, and the height animation is an actual animation of the character growing.

Naturally, that also doesn’t work: https://playground.babylonjs.com/#6I67BL#177

It’s a complicated thing. If the animations are left to play, additives work. If the animations are paused, additives seem to not work. goToFrame() works but only if you don’t pause it right after. And the frame ranges are strange, it’s playing an extra frame in the idle loop if left to figure its own frame range out, which is the start of the grow animation, so it glitches.

See Additive animations behave very oddly - #3 by Evgeni_Popov for my findings on another PG having the same problem than you.

Your PG after the changes:

https://playground.babylonjs.com/#6I67BL#187

Note that setWeightForAllAnimatables(1.0) must be called after start to have an effect.

That did actually fix it, thank you! It’s a bit unintuitive to need to start the animation first, but the system seems to be working now.

The next problem is to do with pausing.

I’m able to start the animation to loop on a single timecode, but this isn’t flawless and various things will cause the animation to jump around (background switching, random CPU lag, etc.)

Even setting a timeout to pause the animation doesn’t work.

By the same token I’ve not been able to get goToFrame() to work.

You mean starting an animation with the same start and end frame does not work? Do you have a repro?

If the start and end frame is the same the animation should not jump around as it should always be the same.