I want to implement a feature that lets the user to subscribe to keyframes of any animation, whether 2D or 3D.
The goal is to invoke a callback everytime the animation reachs 1 or N keyframes appointed by the user.
In 2D animations I do it using timeouts.
What would be the proper way to subscribe to a keyframe in a mesh which is using an AnimationGroup imported from a .glb file?
So I want to add the events to the targeted animation of the animation group (I’d expect it would be just one targeted animation per animation group), but when I log the targeted animations of the Walking grouped animation, I find hundreds of them, all of them similar with 32 keyframes (some scale, some rotation, some position):
I don’t have idea how to use addEvent in that animationGroup, either why are there that amount of similar targeted animations. The same is happening for animatables array, same amount of elements.
I also looks like a big amount of memory usage per grouped animation. That’s not good in case the user spawns several actors. I’m using assetContainer.instantiateModelsToScene to spawn each new actor, this method clones all the grouped animations to allow individual animation per actor.
There is a lot on this topic already in the forum.
In a nutshell: normalize and cleanup your animations in Blender. Also have a look @labrisoptimizer! This will drastically reduce animation file size.
Blender uses a different timeline than Babylon. A marker on keyframe 3 in Blender, does not readily translate to Babylon getCurrentFrame(). I cannot quite remember whether GLTF supports animation events.
In terms of the amount of data. There ususally is 1 rotation per Mixamo bone (~70) per animation frame. That will be 2100 rotations for a 30 frames animation.