When/how to use scene.getAnimationRatio() in my animation?

I am having trouble smoothing out/optimizing my animations for a large mesh scene. I looked at the Optimizing your Scene doc and it mentioned using scene.getAnimationRatio() but that’s all it said, not how or where to use it.

I looked at some playground examples and I’m a bit confused as to when and where to use it, and also what it returns. I understands that it returns 1 for 60fps, but it then returns higher if you are running below 60fps? I also saw examples where the scene.getAnimationRatio() was multiplied by .003 and .001, for instance.

If I want to smooth out my animations, I’m a bit confused as to whether I should apply it to the frameRate in the Animation() constructor as such:
this.animCameraRotation = new Animation(
‘animCameraRotation’,
‘rotation’,
60 * this.scene.getAnimationRatio(),
Animation.ANIMATIONTYPE_VECTOR3,
Animation.ANIMATIONLOOPMODE_CONSTANT
);

or to the speedRatio as such (does speedRatio get multiplied with the frameRate to speed it up? Where does speed Ratio come in?):
this.scene.beginDirectAnimation(
this.arcCamera,
this.arcCamera.animations,
0,
100,
false,
2 * this.scene.getAnimationRatio(),
() => {
});

Or would I multiply the total frames by it

(ie frame: 0 → frame: 180 * this.scene.getAnimationRatio())

Or would I multiply it to a combination of both or all?

Basically, if I want to have my camera move from point A to point B, but have the animation be smoothed and optimized based on the current frame rate of the device, how should I set the Animation up?

I feel like I am taking up forum space with this simple question, but I’m having a difficult time searching the docs and examples to delineate between some of these attributes and how they affect the smoothness of the animation. Many examples do it differently.

Thanks in advance!

1 Like

If you are using the Animation object, the animation ratio is already built into the math. scene.getAnimationRatio is mostly useful for when you are animating something manually:

scene.onBeforeRender = function () {
    box.position.x += 0.01 * scene.getAnimationRatio();
}

The reason for this is that onBeforeRender or any of per frame callbacks are, err, per frame and the frame rate is not necessarily consistent depending on the load of the CPU/GPU. The animation ratio accounts for the frame rates drops so that the animated amount is consistent with the frame time.

1 Like

Gotcha. Thanks for clearing that up. So I’m still stuck with animation performance however. I have a lot of meshes in the scene, and when the model loads the animations are really choppy and laggy. they improve a bit after the first few animation calls. But there is still some left to be desired. I can work on compiling a PG, but in the meantime, are there any best practices that you know of to smooth out animations? I’ve scoured the docs and only found a couple things about animations, and most of which pointed towards getAnimationRatio(), which it seems is irrelevant to my case anyway, as you mentioned. Are the only factors just how you set it up in the Animation() constructor and how the function is parameterized in beginDirectAnimation, as denoted above? Thanks.

Are you saying there are animations running while you load a model? There are probably a few synchronous operations that happen on load which will cause frame hitches that will cause animations to not be smooth. I’m not sure these are easily fixable as some of these synchronous operations are browser API calls.

No, no. Sorry, what I meant in that is once I have the model initially loaded. the first few animations that are called are a lot more choppy than after I have called them several times.

Okay, that’s pretty odd. If you can repro this in a playground, we can try to see what is causing it.

1 Like

Okay, might be a little while to move code around, but I’ll try to have one built up by monday. Thanks!

1 Like