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

Automatically transform Skeleton2D calculations so pivots are not needed #72214

Merged
merged 1 commit into from
Jan 29, 2023

Conversation

clayjohn
Copy link
Member

Fixes: #71108

In the rewrite for Godot 4.0 we moved to calculating skeletons outside of the main draw loop. This is more efficient, but it disconnects the skeleton from the object that draws it. As a result, we were deforming skeletons without regard to where the Skeleton2D node is compared to the Polygon2D resulting in rotations being calculated in the wrong space.

The fix is to transform the bone transforms into local space to perform the rotation. This requires sending the CanvasItem's transform to MeshStorage class and caching the transform in the MeshInstance so it is available at Skeleton update time.

With this change Skeleton2Ds finally are back to working the same as they do in the Skeleton2D tutorial

@@ -164,10 +174,13 @@ void main() {
m += GET_BONE_MATRIX(bones.z, bones_a.z, in_weight_attrib.z);
m += GET_BONE_MATRIX(bones.w, bones_a.w, in_weight_attrib.w);

mat4 skeleton_matrix = mat4(vec4(skeleton_transform_x, 0.0, 0.0), vec4(skeleton_transform_y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(skeleton_transform_offset, 0.0, 1.0));
Copy link
Member

Choose a reason for hiding this comment

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

This is only for 2D right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that code is only included when calculating 2D skeletons

@akien-mga akien-mga merged commit 23d0873 into godotengine:master Jan 29, 2023
@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.

[4.0 beta10] Skeleton2D/Polygon2D moving/rotating issues when polygon is not on default position
3 participants