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

Constant curve support for flipbooking #1043

Closed spiraloid closed 4 years ago

spiraloid commented 4 years ago

Is your feature request related to a problem? Please describe. I am baking effects like fluids into gltf. I bake the simulation down into a low resolution mesh per frame and then animate it's visibility/scale on and off per frame, like a childs flipbook animation or caymations.

each frame has three keyframes and uses constant, or stepped curve interpolation. i.e. image

the results look like this in blender: flipbook_constant_curve_test

however, in GLTF they look like this: strobe

The problem is that the animation playblack is variable and the gltf baked curves are crossfading using the linear interpolation from the animation resample on export. the result is strobing. if the curve interpolation were stepped/constant, the animation would playback fine.

here's the source blender file if you want a look. flipbook_constant_curve_test_blender.zip

Describe the solution you'd like keyframes that are using constant interpolation type in blender should export through to GLTF, and the gltf sampler channels should use interpolation as constant. e.g. they hold the same value until the next keyframe.

I think "flipbooked" mesh animations like this for various effects not possible with skinning or blendshapes is worthwhile to support. to support it, if the

Describe alternatives you've considered allembic support, but android hates allembic.

Additional context more animators are going to ask for this.
https://vimeo.com/channels/1522686/379550189

spiraloid commented 4 years ago

liner curve interpolation creates bad strobing artifacts because the render does not lineup with frames.

i.e. flipbook_constant_curve_test.glb.zip

another solution is to lock the animation playback to the gltf framerate so that the subframe cross scaling frames don't strobe.

scurest commented 4 years ago

I don't think this is related to flipbooking. You can turn off Animation > Always Sample Animations to get curves with constant interpolation and see the same problem.

I think this has to do with the fact that your animation is getting exported as multiple glTF animations. All the animations have different lengths and loop independently in the viewer. You want all your actions to be one animation that only loops when the whole thing is over.

The exporter uses NLA tracks to organize actions into animations by default, but if you turn off the Animation > NLA Strips option, it will put all the currently assigned actions into one glTF animation. If I do that and export (with or without Always Sample Animations), I get a glTF file that works like you expect.

When NLA Strips is on, the exporter puts any actions that aren't in NLA tracks each into its own glTF animation. It might instead make sense to have it put all of them into one glTF animation, since they are logically grouped in that they're playing together in Blender.


tl;dr turn off Animation > NLA Strips in the export options.

emackey commented 4 years ago

@spiraloid Can/did you retest this using last week's fixes from #1035?

Also, make sure every last keyframe on a track is "constant", and there's not even a single "linear" keyframe mixed anywhere in there. glTF sets interpolations on whole animations, not individual keys.

spiraloid commented 4 years ago

confirmed it's working! you guys are awesome! close the issue.

julienduroure commented 4 years ago

Thanks for your feedback! Closing