diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 389d65e05a0..b3f7399d791 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -503,6 +503,13 @@ The modulate color to use for "past" frames displayed in the animation editor's onion skinning feature. + + The default behavior for newly created Bezier keys in the animation editor. + - [b]Horizontal:[/b] Both tangents are fully horizontal regardless of the key's previous and next values. + - [b]Linear:[/b] Key is set to linear with no tangents. + - [b]Balanced Automatic:[/b] Both tangents are rotated to match the key's previous and next values. The tangents' length is adjusted according to the distance between the previous and next values. If the key that is being added has no previous or next value, only one of the two tangents will be defined. + - [b]Mirrored Automatic:[/b] Both tangents are rotated to match the key's previous and next values. The tangents' length is adjusted according to the distance between the previous and next values, but their length is forced to be equal. + diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 66ebd07c2a3..9c729eda54a 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -218,6 +218,9 @@ void AnimationBezierTrackEdit::_notification(int p_what) { if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/panning")) { panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/animation_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning"))); } + if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/animation")) { + _default_bezier_key_behavior = int(EDITOR_GET("editors/animation/default_bezier_key_behavior")); + } } break; case NOTIFICATION_ENTER_TREE: { @@ -1238,6 +1241,21 @@ void AnimationBezierTrackEdit::gui_input(const Ref &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 (_default_bezier_key_behavior) { + case Animation::HANDLE_MODE_LINEAR: { + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), selected_track, k_idx, Animation::HANDLE_MODE_LINEAR, Animation::HANDLE_SET_MODE_AUTO); + break; + } + case Animation::HANDLE_MODE_BALANCED: { + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), selected_track, k_idx, Animation::HANDLE_MODE_BALANCED, Animation::HANDLE_SET_MODE_AUTO); + break; + } + case Animation::HANDLE_MODE_MIRRORED: { + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), selected_track, k_idx, Animation::HANDLE_MODE_MIRRORED, Animation::HANDLE_SET_MODE_AUTO); + break; + } + } undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", selected_track, time); undo_redo->commit_action(); @@ -1682,6 +1700,21 @@ 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 (_default_bezier_key_behavior) { + case Animation::HANDLE_MODE_LINEAR: { + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), selected_track, k_idx, Animation::HANDLE_MODE_LINEAR, Animation::HANDLE_SET_MODE_AUTO); + break; + } + case Animation::HANDLE_MODE_BALANCED: { + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), selected_track, k_idx, Animation::HANDLE_MODE_BALANCED, Animation::HANDLE_SET_MODE_AUTO); + break; + } + case Animation::HANDLE_MODE_MIRRORED: { + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), selected_track, k_idx, Animation::HANDLE_MODE_MIRRORED, Animation::HANDLE_SET_MODE_AUTO); + break; + } + } undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation); undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", selected_track, time); AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton(); diff --git a/editor/animation_bezier_editor.h b/editor/animation_bezier_editor.h index dd7e8758f32..0a0661b30bb 100644 --- a/editor/animation_bezier_editor.h +++ b/editor/animation_bezier_editor.h @@ -193,6 +193,8 @@ class AnimationBezierTrackEdit : public Control { float _bezier_h_to_pixel(float p_h); void _zoom_vertically(real_t p_minimum_value, real_t p_maximum_value); + int _default_bezier_key_behavior; + protected: static void _bind_methods(); void _notification(int p_what); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 9373a45475f..212247b29e7 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -4532,6 +4532,23 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD } undo_redo->add_do_method(animation.ptr(), "track_insert_key", p_id.track_idx, time, value); + if (!created && p_id.type == Animation::TYPE_BEZIER) { + int k_idx = animation->track_find_key(p_id.track_idx, time) + 1; + switch (int(EDITOR_GET("editors/animation/default_bezier_key_behavior"))) { + case Animation::HANDLE_MODE_LINEAR: { + undo_redo->add_do_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), p_id.track_idx, k_idx, Animation::HANDLE_MODE_LINEAR, Animation::HANDLE_SET_MODE_AUTO); + break; + } + case Animation::HANDLE_MODE_BALANCED: { + undo_redo->add_do_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), p_id.track_idx, k_idx, Animation::HANDLE_MODE_BALANCED, Animation::HANDLE_SET_MODE_AUTO); + break; + } + case Animation::HANDLE_MODE_MIRRORED: { + undo_redo->add_do_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), p_id.track_idx, k_idx, Animation::HANDLE_MODE_MIRRORED, Animation::HANDLE_SET_MODE_AUTO); + break; + } + } + } if (created) { // Just remove the track. diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 96a7700c34a..298718c8561 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -867,6 +867,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("editors/animation/default_create_reset_tracks", true); _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0)); _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0)); + EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/animation/default_bezier_key_behavior", 0, "Horizontal,Linear,Balanced Automatic,Mirrored Automatic"); // Shader editor _initial_set("editors/shader_editor/behavior/files/restore_shaders_on_load", true);