Animation frameRate and scene rendering frames per second

Hello, I am very confused about this function:
const myAnim = new BABYLON.Animation(name, property, frames_per_second, property_type, loop_mode);

https://playground.babylonjs.com/#MTCTS5

The question is: It seems that frames_per_second can be any value, whether it is a decimal or an integer, the effect of the animation will not change at all. This makes me full of doubts when using this function.

Hello :slight_smile:

Theorically, a decimal number for a framerate is not a problem. For example for a 24 fps video you can often see in its properties : 23.98 as a frame rate. Also, if a frame is played every 30ms, the frame rate is 1000/30 == 33.33, there is no particular reason why it should exactly match a number of frames within a second.

The reason is in your keyframes :wink:

const xSlide = new BABYLON.Animation("xSlide", "position.x", frameRate, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);

const keyFrames = []; 

keyFrames.push({
    frame: 0,
    value: 2
});

keyFrames.push({
    frame: frameRate,
    value: -2
});

keyFrames.push({
    frame: 2 * frameRate,
    value: 2
});

You are using frameRate and 2*frameRate as the timings for the keyframes, so there is no doubt it will be the exact same speed whatever the frameRate.


Just change it to for example 10 and 20 :

In this case :

  • frameRate = 20 → 1 second for a full loop
  • frameRate = 40 → 2 times faster
  • frameRate = 80 → 4 times faster

Etc, etc… :slight_smile:

3 Likes

Then the frame parameter actually ultimately affects time. In my example, from and to are both decimals. In fact, I don’t have to worry about why frames can be decimals. In fact, at the bottom level, from and to will be converted into time-related variables and then interpolated.

The above is the conclusion I came to after reading the relevant source code. In short, for novices, frameRate can be a decimal, but the fact that the frame parameter is a decimal is actually not easy to understand.