I have a model with sequential frame animation, such as 0-100 frames.
Now when I play 50 frames with AnimationAction.play(), then it stop.
How to get 50 by attributes or methods?
This is my code with AnimationAction.

I have a model with sequential frame animation, such as 0-100 frames.
Now when I play 50 frames with AnimationAction.play(), then it stop.
How to get 50 by attributes or methods?
This is my code with AnimationAction.
frames aren’t really all that useful, because the animation system works with curves instead of frames. In other words, the animation system is not working in discrete time (frames) but in continuous time instead.
That being said - you can approximate the frame index from the current animation time.
Let’s say that your animation has 100 frames, and lets say that you exported your animations with 24FPS setting, this means that 1 second of animation would cover 24 frames. So when you play the animation in three.js, you can check the current time and derive the frame number from that, like so:
const FRAME_RATE = 24;
cosnt animationTime = animationMixer.time;
const frameIndex = Math.floor(animationTime*FRAME_RATE);
Thank you very much. It helps me a lot.
the answer is wrong, correct one is:
//frameCount is animation's total frame count, e.g. 100 means the animation has 100 frames
export let getFrameIndex = (action: AnimationAction, frameCount) => {
let animationTime = action.time
return Math.round(animationTime / action.getClip().duration * frameCount)
}
@yang_yuanchao
This assumes that you know the “total frame count”, which you don’t automatically know. so that’s not quite the whole story. The duration and frame timing is determined by the modelling software so there is no guarantee of a time correspondence.
In blender you can set a framerate for animation. It defaults to 24fps I believe. You can come up with a formula that works with your specific set of exports, or you can look at the time codes on the animation tracks themselves, but the animation system in threejs is time based, not keyframe based. Also the gltf exporter can/will resample animations, and potentially optimize/drop keyframes, so you can’t just use the keyframe count reliably.