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

Add position track normalization to importer retarget #63138

Merged
merged 1 commit into from
Jul 27, 2022

Conversation

TokageItLab
Copy link
Member

@TokageItLab TokageItLab commented Jul 18, 2022

Section 4 and 5 (partialy) of godotengine/godot-proposals#4510.

Solves problems caused by the combination of body height differences and position tracks.

Desktop 2022 07 18 - 18 23 31

This should allow for sharing of animations among some models in most simple cases, except for the bone mapping hassle.


Add position track normalization to importer and add motion_scale to Skeleton3D

image

The importer retarget assumes the motion scale to be the height from the world origin of the bone specified as the bone of motion_scale_base in the profile. In most cases, the motion_scale will match the hips height.

As far as I know, most game engines and retargeting systems use hips height as the motion scale.

image

The key value of the imported position track is normalized by dividing by the motion_scale. The motion scale is then stored in the skeleton, and when the animation is played back, the position track is multiplied by the motion_scale of the skeleton to which it is applied.

Also, added _post_process_key_value() to AnimationPlayer and AnimationTree as a virtual function.

The motion_scale multiplication is done in it. In some cases, we can override this function in a custom module to implement real-time retargeting, etc.1

Add Track Organizer

image

Unimportant Positions

Remove unimportant position tracks (other than Root and motion_scale_base ≈ Hips) that have been mapped.

Unmapped Bones

Remove unmapped bone TRS3D tracks.

Other fixes


Test model

Blender Chan! / CC by SearKitchen
https://sketchfab.com/3d-models/blender-chan-6835f0d60e0c4813812c0247e3b73da7

Footnotes

  1. It might be better to use GDVIRTUAL, it is possible to override function while the game is running, but we could not function it on the editor.

@TokageItLab
Copy link
Member Author

TokageItLab commented Jul 18, 2022

I have one concern: skeletons with motion scale make it difficult to handle position tracks in inspector and somewhere. As noted in the documentation, the position of a skeleton with a non 1.0 motion scale does not match the value of the position track key. Although I made the normalization depend on the motion scale when inserting the key, it may still be confusing because the actual position and the key value are different.

The smarter way I can think of is to add a normalized property to Position3DTrack, or add track_add_meta("Normalized", true) or track_add_attribute("Normalized") methods to the AnimationTrack, so that only normalized tracks will be multiplied by motion scale. Besides, since normalized tracks are difficult to edit, it is better to make them readonly.

With the above implementation, non-normalized keys can be written and played. Then by adding a method for conversion, it can be converted to normalized track as needed.

However, in the past, I had a huge dispute with @reduz about adding attributes to tracks and creating 3D Skeleton animations on Godot, so for now, this is a simplified implementation as it is now. I will send additional PR later if really needed the additional track attribution.

editor/import/resource_importer_scene.cpp Outdated Show resolved Hide resolved
scene/3d/skeleton_3d.h Outdated Show resolved Hide resolved
@TokageItLab TokageItLab force-pushed the normalize-position-track branch 2 times, most recently from b23b130 to 014235f Compare July 26, 2022 09:40
@TokageItLab TokageItLab force-pushed the normalize-position-track branch from 014235f to dde235a Compare July 26, 2022 09:48
@TokageItLab TokageItLab requested a review from reduz July 26, 2022 09:49
@TokageItLab
Copy link
Member Author

@reduz I fixed the part pointed out.

@reduz
Copy link
Member

reduz commented Jul 27, 2022

Looks great!!

@akien-mga akien-mga merged commit ed61fb2 into godotengine:master Jul 27, 2022
@akien-mga
Copy link
Member

Thanks!

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.

Discrepancy between built-in animation and same animation saved to file from imported gltf
3 participants