animationGroup play backwards issue

Hello
I would like to run an animationGroup forward and backward. If I understand it correctly, I can use speedRatio for that. Here is an example: https://playground.babylonjs.com/#CBGEQX#1779
If I press Play, the animation runs once till the end as expected .
If I press Reverse, the animation runs backwards as expected to Frame zero.
But if I press Pause during a running animation, and then press Reverse, then the animation starts looping.
There seems to have been a similar problem here (October 2019), which was then supposedly fixed.
speedRatio effect in animation? - #6 by Deltakosh
Is it still a bug or is it meant to be?

pause() <-> play()
I canā€™t seem to find a way to resolve the animationā€™s From-To relationship in this relationship.

From the first execution point animationGroup.play
from ~ to will have an initial value ex) 0~100

Since the value of pause() does not change, it stops maintaining the previous value.

If you do changing speedRatio = -1; Its from to will not change
For example, if you press reverse about 60 frames after starting,
The frame rate will continue to decrease from 60 and will never reach the target of 100.

Also, the value of the from to is not processed.

What I found out about the next PG is that if the value for the range of from to is exceeded, the frame is repeated.
frame
100 ā†’ 0 ā†’ 100 ->0
or
0 ā†’ 100 ā†’ 0 ā†’ 100

stop() <-> start()
In this relationship, it is possible for it to work even if you reverse it after the animation is completely finished.

If you donā€™t have logic that needs to be processed only with play pause, you can do it with this way

This way is just by adjusting from to frame without changing the speedRatio value

stop() <-> start() PG

As explained by @11128, the way to handle this is to use start/stop. However, you should save the current frame when hitting ā€œpauseā€, so that you can restart from the right frame afterwards:

See also:

Ok, I was able to fix it in the runtimeAnimation class, so after this PR is merged, your first PG will work as expected, as well as https://forum.babylonjs.com/t/gltf-animation-loops-when-i-click-how-to-stop-the-loop/38477:

3 Likes

Thank you, that sounds great.