Playing Animation Groups Backward

Hi,

So I’ve been learning about animation groups today and I’ve been trying to understand how to play animations backward.

scene.animationGroups[i].start(false,playRatio,scene.animationGroups[i].animatables.masterFrame,this.scene.animationGroups[i].to);

I’ve tried this parsing 1 or -1 into the speed ratio argument, but the animation snaps back to the beginning when it ends and attempts to play backward from the end of the animation.

Is there a correct way to toggle animations backward and forward?

Thanks

Hey!

It should work:
https://www.babylonjs-playground.com/#8EH69Q

Can you repro your issue in the Playground?

That’s not quite what I’m after. Ideally the scaling of the green box should get to the end and then reverse back in the other direction once it’s at the end. Might have not explained it quite right.

like that ?
https://www.babylonjs-playground.com/#8EH69Q#1

That’s more like it. That said how could you link the current state say to a button that plays it forward and then when clicked again reverses it. That’s the bit that has stumped me.

This is closes thing I could find: https://www.babylonjs-playground.com/#41MBJZ#2 but couldn’t understand how the to/from arguments work.

In my example I’m animating “scaling.x” so mesh.scaling.x is always your current state. So in your button you can check mesh.scaling.x and define it as either from or to in your parameters :smiley:

Okay so how can I get the current play position of an animation group? I couldn’t see in the API a parameter that I could access. This what I assume I need to do in order to parse the to/from frame.

I think I should have explained a bit more in my initial post.

So I’ve got a GLTF file that contains a simple door opening and closing. I want the door to either be opened or closed. e.g. when opened, it plays the animation and gets to the open state. Now in theory you should be able to then set a negative playRatio to reverse the animation, however it pings back to the start frame of the closed state and doesn’t play backwards. So it seems that it’s resetting or something when being played again. Any ideas?

The problem is that animation groups contains multiple animations which can be at different stages. So you can get individual animations and get their current positions but not a global one

If you consider then all animations in a group are on the same timeline then pick the first animation and check the value, it should work

So just trying to understand how animations are stored.

From what I can see its

scene.animationGroups[i].targetedAnimations[0].animation

Is that correct? I’m very confused of where the animation data is being held.

An Animation is a template used to generate a animatable(which is currently animating a real target)

targetedAnimations are just Animations + a Target to animate :slight_smile:

you can get most of what you need from:

scene.animationGroups[i].animatables[0].masterFrame

I see, thanks. I’ll have to play around a bit. I think I’m also getting some conflicts with Vue when accessing that data as its coming back as undefined. That’s seems to be a separate issue.

1 Like