KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 316 forks source link

Exporting bone animations ignore keys that are specified to be constant #1868

Closed blackears closed 1 year ago

blackears commented 1 year ago

Describe the bug Exported animations treat all animated keys as LINEAR, even when specified to be constant. This is causing an animation where I want to snap between two locations instantly to slide over several frames when I view it in most viewers.

To Reproduce Create a mesh and bind it to a bone in a rig.
Add an animation to the bone.
Open Blender's graph editor, select the control points, right click and set them to be constant. Play back the animation in Blender. The mesh bound to the bone will snap to the position you gave it. Export the animation as a gltf file. Open the animation in a viewer such as 3D viewer. Instead of snapping to the new location, the mesh will quickly slide to it. If you open the gltf file in a text editor, you will even see every animated frame marked as 'LINEAR' and none as 'STEP'.

Expected behavior Exported animation should respect constant keyframe indications. This is necessary for faking flipbook animations and hiding objects.

.blend file/ .gltf experiments.zip

Version

julienduroure commented 1 year ago

Confirmed. This is a know limitation for now: When baking, we bake every single frame, with LINEAR interpolation whatever the blender interpolation is. See https://github.com/KhronosGroup/glTF-Blender-IO/blob/832484f279a7bd37b71a7f693cfd818e81588deb/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py#L297 and https://github.com/KhronosGroup/glTF-Blender-IO/blob/405df21da3dac95a4514e24bc4ac30716b32295c/addons/io_scene_gltf2/blender/exp/animation/sampled/armature/gltf2_blender_gather_armature_sampler.py#L209 Setting at enhancement, as we can detect:

julienduroure commented 1 year ago

This should be fixed now. Note that glTF animation for Translation, Rotation or Scale are not animate each channel (X, Y, Z, ...). So in your case, you have to put each X, Y, Z to CONSTANT if you want to export to STEP, else it will still export to LINEAR, as we detect different interpolation mode inside an animated TRS.