Improve animation track optimizer #64132
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes the key removal algorithm of the animation track optimizer using the velocity ratio as I said in godotengine/godot-proposals#4997.
For example, if there is a value A that changes 0.6/s and a value B that changes 0.5/s, the ratio can be calculated as follows:
The closer the value is to 1, the closer the velocity of the prev and next keys.
This eliminates the old optimizer's
Max Angle
and unifies it into anMax Velocity Error
. For the same reason, theMax Linear Error
real value comparison is also eliminated. However, since real value comparison is still necessary for removing float point precision error, so anMax Precision Error
is added.Below is a video preview with #53864:
raw.mp4
As the value of
Max Velocity Error
increases, more keys are deleted certainly.The case of
Velocity Error: 0.05, Angular Error: 0.01
looks mostly correct, but a few frames produced a slightly worrisome error.Larger values of
Angular Error
will reduce more keys, but it corrupts animation larger:raw.3.mp4
As @Calinou said in godotengine/godot-proposals#4997, the default value must be lossless in look and feel. So far, the case that can be properly called lossless is
Velocity Error: 0.01, Angular Error: 0.01
. I decide to use it as default values.Comparison with the old Optimizer:
raw.2.mp4
The old Optimizer default values obviously remove too many keys, and the animation path is quite corrupted. I chose
Velocity Error: 0.25, Angular Error: 0.01
as settings where the deletion rate is close to that, but still an acceptable animation corruption.By the way, a comparison with the old Optimizer's minimum value setting is shown below.
The new Optimizer seems to have better results, keeping more important keys and a better deletion rate there.
This solves the #58968 problem as well:
raw.4.mp4
The Optimizer issues have been reported so frequently that I cannot keep track of all of them.
For now, I will only link to two issues for which there are sample project files and for which I can determine that the problem has been completely resolved.
Fixes godotengine/godot-proposals#4997.
Fixes #53864. Fixes #58968.