Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve animation track optimizer #64132

Merged
merged 1 commit into from
Aug 22, 2022

Conversation

TokageItLab
Copy link
Member

@TokageItLab TokageItLab commented Aug 8, 2022

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:

ratio = A < B ? A / B : B / A = 0.83

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 an Max Velocity Error. For the same reason, the Max Linear Error real value comparison is also eliminated. However, since real value comparison is still necessary for removing float point precision error, so an Max Precision Error is added.

image


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.

image
image

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.

def

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.

Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed that using acceleration or jerk is not necessary.

Also the unit of the 0.01 is not meters but something else.

From @TokageItLab

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:
ratio = A < B ? A / B : B / A = 0.83
The closer the value is to 1, the closer the speed of the prev and next keys.

@reduz
Copy link
Member

reduz commented Aug 18, 2022

This seems like a very interesting approach, I guess time will tell how well it works.

@timshannon
Copy link

FWIW, this absolutely fixes my issue with the attached project on v4.0.alpha.mono.custom_build [03dc8c5].

After importing the same model with this PR, I no longer have the overlap / escaping mesh issues that was seeing before, and the animations seem to better reflect the snappyness I'm seeing in blender.

Bug.zip

@akien-mga akien-mga merged commit 5bc8702 into godotengine:master Aug 22, 2022
@akien-mga
Copy link
Member

Thanks!

@TokageItLab TokageItLab deleted the fix-optimizer branch September 16, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improvement Track Optimizer in Importer Keyframe Missing from Animation (gltf) Problem with animation
5 participants