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

Clamp bezier handle length to half the length of animation #93930

Conversation

Arnklit
Copy link
Contributor

@Arnklit Arnklit commented Jul 4, 2024

Fixes #93807 by clamping the new handle length to half the length of the animation.

image

@Arnklit Arnklit force-pushed the short-animation-length-bezier-handle-fix branch from ae04ce9 to bbed82d Compare July 4, 2024 09:28
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@akien-mga akien-mga added the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Jul 4, 2024
@akien-mga akien-mga modified the milestones: 4.x, 4.3 Jul 4, 2024
@Arnklit
Copy link
Contributor Author

Arnklit commented Jul 4, 2024

@mihe pointed out to me that there was another code path that this didn't cover. Setting to draft while I fix that and refactor the code.

@Arnklit Arnklit marked this pull request as draft July 4, 2024 11:47
@Arnklit Arnklit force-pushed the short-animation-length-bezier-handle-fix branch from bbed82d to 2bd8154 Compare July 4, 2024 12:20
@Arnklit
Copy link
Contributor Author

Arnklit commented Jul 4, 2024

Moved make_default_bezier_key into animation on @mihe 's suggestion, which meant we can now call the same code from all three spots and remove the repeated code. @mihe if you have time to give it another look that would be great.

@Arnklit Arnklit marked this pull request as ready for review July 4, 2024 12:23
array[2] = 0;
array[3] = 0.25;
array[4] = 0;
array = animation->make_default_bezier_key(p_id.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Skip the intermediate array here and just assign straight to value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah of course. done

arr[3] = 0.25;
arr[4] = 0;

arr = animation->make_default_bezier_key(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Skip the intermediate arr here and just assign straight to id.value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -3189,6 +3189,20 @@ StringName Animation::method_track_get_name(int p_track, int p_key_idx) const {
return pm->methods[p_key_idx].method;
}

Array Animation::make_default_bezier_key(float p_value) {
const float max_width = length / 2.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that it really matters, but you might want to make this a const double instead, seeing as how length is double, as well as the 0.25 constants below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Arnklit Arnklit force-pushed the short-animation-length-bezier-handle-fix branch from 2bd8154 to 7c6f32d Compare July 4, 2024 12:41
Copy link
Member

@TokageItLab TokageItLab left a comment

Choose a reason for hiding this comment

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

The best approach is to share the calculation with the handle setting method in bezier_track_set_key_handle_mode(), which calculates a value that depends on the key interval. The default value is not defined for HANDLE_SET_MODE_AUTO when keying a newly created key, but in that case, I think the HANDLE_MODE_BALANCED or HANDLE_MODE_MIRRORED calculation should be applied. HANDLE_MODE_MIRRORED should be a concept closer to the current default in that it adopts a length that is x0.25 the interval-dependent length.

@Arnklit
Copy link
Contributor Author

Arnklit commented Jul 4, 2024

The best approach is to share the calculation with the handle setting method in bezier_track_set_key_handle_mode(), which calculates a value that depends on the key interval. The default value is not defined for HANDLE_SET_MODE_AUTO when keying a newly created key, but in that case, I think the HANDLE_MODE_BALANCED or HANDLE_MODE_MIRRORED calculation should be applied. HANDLE_MODE_MIRRORED should be a concept closer to the current default in that it adopts a length that is x0.25 the interval-dependent length.

Happy to add that in. I had thought it would make more sense as a editor setting where you could change the default behavior. But if it can work for everything by default that is easier.

Copy link
Member

@TokageItLab TokageItLab left a comment

Choose a reason for hiding this comment

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

Well, since follow up is possible later, I think it is enough as a stop gap for this inconvenient situation for now.

@akien-mga akien-mga merged commit 4d984b6 into godotengine:master Jul 4, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

@Arnklit Arnklit deleted the short-animation-length-bezier-handle-fix branch July 4, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release enhancement topic:animation topic:editor usability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bezier handles are too long on short animations
5 participants