Trim imported gltf animation to any frame range

Hey community,

I am importing animation from a gltf file.
The gltf is exported from Blender. In blender the animation is created in frame range from frame 1001 to frame 1245. So it means the actual animation is only 245 frames.

but when I imported this gltf into babylon, the anim always starts from frame 0. In other words, in babylon the animation becomes 1245 frames long instead of 245. Also the first 1000 frames are completely empty with no animations at all.

Is there any aways I can trim the imported animation in Babylon to any range (trim to 1001 to 1045 in my case), also after, slide the animation on timeline to make it start at wherever frame I want?

Searched all related APIs but couldn’t find any ways to do so.

Many thanks,

The animationGroup has a function that sets the animation range.
It doesn’t change the animation, just the range of playback.

group.normalize(start, end)

If you want to change the animation, you can change the value of the key’s frame in the animationGroup.

Here’s an example of how to trim the animation group.
see line 13 and 14

1 Like

There are also static functions on AnimationGroup that can help you:

  • ClipKeys
  • ClipKeysInPlace
  • ClipFrames
  • ClipFramesInPlace
1 Like

Thanks for the response folks!

Cool! just tried, the clip functions works really well. Sorry didn’t find these funcs in the first place. I thought these functions were for other purposes.

Have a great weekend!

@Evgeni_Popov Hey sorry I have a follow up question:

After clipping/trimming the animation group. Are clipped the animation will start from frame 0 automatically?

For example, if the original animation group has animation from [0, 130], and I clip frames to [51, 100]. From my observation, the new animation will be in [0, 49] right? Looks after trimming, the new animation will be slide along timeline and start from 0 automatically?

Is there a way check what exactly the frame range on timeline of a given animation in general?

Many thanks,

Yes, the new animation group will start at frame 0.

You can retrieve the frame range thanks to anmGroup.from and

1 Like