Keyframes in Babylon.js are stored with array of objects. Some animations exported with millons of key frames, with the object mode, it would take more memory than stored with typed arrays, like Float32Array.
Without the object per frame, it would be much harder for features like per-frame interpolation and tangent to be implemented, so this could be an optional feature for those suffers too many keyframes without these advanced features.
See code in playground:
compact for gltf with 4-bytes alignment for each item
deleteRange recalculate keys if removed first or last key
AnimationCurveEditor (maybe convert it back to Animation)
For AnimationCurveEditor it is hard to fully adapt it to CompactAnimation, maybe the fast way it to convert CompactAnimation to Animation, for which a function named compactAnimationToAnimation can be found in my last posted playground link.
If working with AnimationGroup the Animation and the target of animation can be found at AnimationGroup#targetedAnimations, where animations inside the animations property can be replaced with converted one, and animation inside TargetedAnimation itself, and animations inside AnimationGroup.animatables[number]._runtimeAnimations._animation.
It is also possible that the inspector targets an IAnimatable, eg. one Mesh, in this case all the AnimationGroups in scene and all the _activeAnimatables and animations of the scene should be iterated to find all references to the animations.
Targeting one Animation is simlar to the case above, but all the meshes, transformNodes, cameras, particleSystems, materials, morphTargetManagers, skeletons in the same scene should be iterated to find all references to the animations.
Another simple method is to check for existance of CompactAnimation and disable or hide the Edit button which opens the curve editor.
The event callback for AnimationCurveEditor, where all the convertion should be done before:
Since replacing animation object in scene is complicated, maybe there could be another way by replacing [[Prototype]] of the animation object using Object.prototype.__proto__ or Object.setPrototypeOf or Reflect.setPrototypeOf.
That reply is related to the AnimationCurveEditor in inspector, which can edit animation’s key frames with advanced features like per-frame tangent and interpolation, which is hard to implement for typed-array-based CompactAnimation.
To make CompactAnimation work with AnimationCurveEditor, the most likely possible way is to convert CompactAnimation back to regular Animation, and replace usages of the CompactAnimation in scene with converted Animation, the replies here and here are different ways of replacing animation in scene, and the reply here is a demo of iterating all animations in scene and replace, which shoud be the prefered way since changing prototype is discouraged according to docs.
screenshots of advanced feature of AnimationCurveEditor and keys after using that
I would just like to say, i am grateful for your effort and enthusiasm you’ve put into this and other refactoring projects. I feel that sometimes, efforts like this can seem to be met with a bit of a cold response, but just know this is great and thank you.