iimachines / Maya2glTF

Maya to glTF 2.0 exporter
MIT License
324 stars 49 forks source link

Simplify sampled curves #141

Open ziriax opened 3 years ago

ziriax commented 3 years ago

When the animation is hand made, many of the curves are very smooth. Therefore, it should be possible to reduce the number of keyframes.

The exporter should fit a cubic spline to the curves, maybe using the keyframes from the artists as knob hint positions.

Maybe Maya's built-in key reducers could be used for this? See MEL's simplify command

The idea is as follows:

For other approaches, see also ACL, gltfPack

I wasn't able to find a viewer for the animation curves, so add one too.

fire commented 3 years ago

I was able to reuse this mit licensed code.

https://github.com/robertjoosten/maya-keyframe-reduction

It works very well.

fire commented 3 years ago

There's also state of the art research here:

C2 Continuity!!!

http://www.cemyuksel.com/research/interpolating_splines/

ziriax commented 3 years ago

Thanks! The problem is that glTF uses simple y=at³ + bt² + ct +d piecewise cubic polynomials.

Maya's curves and the one in the papers are real 2D curves, e.g. both X and Y are function of the curve parameter t... This allows the user to have a lot of freedom creating animation curves, but it is very expensive to interpolate, e.g. to find Y for a give time X value, you first need to find the curve parameter from that X, and that is slow. Too slow for games. Actually the glTF spec explicitly mentioned this.

Nevertheless the papers and code you provided look very very interesting, and I will certainly look into these.

BigRoy commented 1 year ago

@ziriax As far as I'm aware currently frames are always stored for every frame - even when e.g. a part of the animation is static for a few frames. If I were to implement logic to filter out those keys that are redundant (e.g. previous + next frame are not different than current frame) where should that logic roughly be implemented?

ziriax commented 1 year ago

I think NodeAnimation.cpp, finish method. It already has a TODO for this