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 option to auto tangent new bezier points in animation editor #95564

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Arnklit
Copy link
Contributor

@Arnklit Arnklit commented Aug 15, 2024

This adds an option to set the default behavior of new bezier keys in the editor settings
This would close godotengine/godot-proposals#10250

image

Example of behavior when the behavior is set to Mirrored Automatic

godot.windows.editor.dev.x86_64_qrJA6lPQOc.mp4
  • "Default Bezier Key Behavior" Editor setting added.
  • New keys inserted through the bezier or tracks editors are rebalanced based on the "Default Bezier Key Behavior" setting.
  • Ctrl + Click dragging to create a new key now works correctly. The key gets rebalanced upon mouse release.
  • Add folddown that mirrors the "Default Bezier Key Behavior" editor setting to the Bezier Track editor
  • Update the visual handle while dragging by splitting the auto balance function into a public function that can also be used in the draw function

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.

Need to fix docs line. You can use the command godot.exe --doctool to make document template.

@@ -1231,6 +1231,17 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Add Bezier Point"));
undo_redo->add_do_method(animation.ptr(), "bezier_track_insert_key", selected_track, time, new_point[0], Vector2(new_point[1], new_point[2]), Vector2(new_point[3], new_point[4]));
int k_idx = animation->track_find_key(selected_track, time) + 1;
switch (int(EDITOR_GET("editors/animation/default_bezier_key_behavior"))) {
Copy link
Member

@TokageItLab TokageItLab Aug 26, 2024

Choose a reason for hiding this comment

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

Retrieved value of the EDITOR_GET must be cached in AnimationBezierTrackEdit::_notification().

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. maybe you can check if I did it the right way.

@@ -1670,6 +1681,17 @@ void AnimationBezierTrackEdit::_menu_selected(int p_index) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Add Bezier Point"));
undo_redo->add_do_method(animation.ptr(), "track_insert_key", selected_track, time, new_point);
int k_idx = animation->track_find_key(selected_track, time) + 1;
switch (int(EDITOR_GET("editors/animation/default_bezier_key_behavior"))) {
Copy link
Member

Choose a reason for hiding this comment

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

Same above.

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. maybe you can check if I did it the right way.

scene/resources/animation.h Outdated Show resolved Hide resolved
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Tested locally (rebased on top of master 906a4e9), it mostly works as expected.

However, if you hold Ctrl and drag the mouse to create a new point, the tangents won't update automatically after the initial click (i.e. during the drag motion):

bezier_balanced.mp4
bezier_mirorred.mp4

This should probably be changed to perform tangent changes continuously during the initial dragging motion (but not after, unless we add new settings to use Auto Tangent as a default). Also, double-check that undo-redo works correctly in this case: pressing Ctrl + Z should undo the key addition, whereas it currently only works correctly if you haven't performed any dragging at all.

@Arnklit
Copy link
Contributor Author

Arnklit commented Sep 17, 2024

Rebased and tried to apply @TokageItLab and @Calinou 's comments. Still have to work on making sure that it works when you drag the keys as Calinou pointed out it in his last comment. Marking as draft until I solve that.

@Arnklit Arnklit marked this pull request as draft September 17, 2024 15:18
@Arnklit
Copy link
Contributor Author

Arnklit commented Sep 20, 2024

@Calinou outside this PR should the current behavior of adding and dragging a key with Ctrl be changed so it's registered as a single do action that can be undone with a single undo? That part of the behavior isn't from this PR.

Current Do/Undo history when Ctrl + Click dragging a point into the bezier editor and undoing it.
image

@Calinou
Copy link
Member

Calinou commented Nov 7, 2024

@Calinou outside this PR should the current behavior of adding and dragging a key with Ctrl be changed so it's registered as a single do action that can be undone with a single undo? That part of the behavior isn't from this PR.

I'd say yes, I expect those to be considered a single action.

@Arnklit Arnklit force-pushed the default-bezier-keys branch 4 times, most recently from 08c5220 to 45ee246 Compare January 24, 2025 10:47
@Arnklit Arnklit force-pushed the default-bezier-keys branch from 45ee246 to 4fb23e3 Compare January 24, 2025 13:12
@Arnklit
Copy link
Contributor Author

Arnklit commented Jan 24, 2025

It now works correctly to ctrl+click+drag insert keys (they re-balance after release if needed and it works to drag them into another order as well). Big thanks to @mihe for helping out with this.
And I added a drop-down to the animation track editor for setting the mode. I'm not sure about where this drop-down should be or if the label is the best, suggestions welcome.

godot.windows.editor.dev.x86_64_H3qq6WP20P.mp4

I still want to add making the key handles update while dragging in the draw function when you are in the auto modes.

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.

Add options to auto balance new bezier keys in animations
4 participants