From 94783ec04f186657698a573897a042bd9c258f37 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 30 Jan 2024 16:31:54 +0100 Subject: [PATCH 1/6] rough implementation --- scripts/startup/bl_ui/space_graph.py | 1 + source/blender/editors/transform/transform.cc | 23 +++++++++++++++++++ source/blender/makesdna/DNA_space_types.h | 3 ++- source/blender/makesrna/intern/rna_space.cc | 7 ++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index bba2e98706b..241e6438c44 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -158,6 +158,7 @@ class GRAPH_MT_view(Menu): layout.prop(st, "use_realtime_update") layout.prop(st, "show_sliders") layout.prop(st, "use_auto_merge_keyframes") + layout.prop(st, "autolock_translation_axis") layout.separator() if st.mode != 'DRIVERS': diff --git a/source/blender/editors/transform/transform.cc b/source/blender/editors/transform/transform.cc index 1412650859c..8d2a323674c 100644 --- a/source/blender/editors/transform/transform.cc +++ b/source/blender/editors/transform/transform.cc @@ -967,12 +967,35 @@ static bool transform_event_modal_constraint(TransInfo *t, short modal_type) return true; } +static bool editor_forces_constraints(TransInfo *t) +{ + switch (t->spacetype) { + case SPACE_GRAPH: { + if (t->mode != TFM_TRANSLATION) { + return false; + } + SpaceGraph *space_graph = (SpaceGraph *)t->area->spacedata.first; + return space_graph->flag & SIPO_AUTOLOCK_AXIS; + } + + default: + break; + } + return false; +} + int transformEvent(TransInfo *t, const wmEvent *event) { bool handled = false; bool is_navigating = t->vod ? ((RegionView3D *)t->region->regiondata)->rflag & RV3D_NAVIGATING : false; + /* Auto set constraints if the editor supports it. Don't do it if a constraint is already active + * or it would be impossible for the user to change it. */ + if (editor_forces_constraints(t) && (t->con.mode & CON_APPLY) == 0) { + initSelectConstraint(t); + } + /* Handle modal numinput events first, if already activated. */ if (!is_navigating && ((event->val == KM_PRESS) || (event->type == EVT_MODAL_MAP)) && hasNumInput(&t->num) && handleNumInput(t->context, &(t->num), event)) diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 727766faf39..1c592e90e4f 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -506,7 +506,8 @@ typedef enum eGraphEdit_Flag { SIPO_NOTRANSKEYCULL = (1 << 1), /* don't show any keyframe handles at all */ SIPO_NOHANDLES = (1 << 2), - /* SIPO_NODRAWCFRANUM = (1 << 3), DEPRECATED */ + /* Automatically lock the transform to whichever axis the cursor has moved the most. */ + SIPO_AUTOLOCK_AXIS = (1 << 3), /* show timing in seconds instead of frames */ SIPO_DRAWTIME = (1 << 4), /* draw names of F-Curves beside the respective curves */ diff --git a/source/blender/makesrna/intern/rna_space.cc b/source/blender/makesrna/intern/rna_space.cc index 92732bc9475..f39a1d4a484 100644 --- a/source/blender/makesrna/intern/rna_space.cc +++ b/source/blender/makesrna/intern/rna_space.cc @@ -6421,6 +6421,13 @@ static void rna_def_space_graph(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Show Handles", "Show handles of Bezier control points"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, nullptr); + prop = RNA_def_property(srna, "autolock_translation_axis", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", SIPO_AUTOLOCK_AXIS); + RNA_def_property_ui_text(prop, + "Auto-Lock Axis", + "Automatically locks the movement of keyframes to the dominant axis"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, nullptr); + prop = RNA_def_property(srna, "use_only_selected_keyframe_handles", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, nullptr, "flag", SIPO_SELVHANDLESONLY); RNA_def_property_ui_text( -- 2.30.2 From 46ca58fcd781cb74ec9b18807d1127ec9abdad16 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Fri, 2 Feb 2024 17:29:00 +0100 Subject: [PATCH 2/6] only lock keys --- source/blender/editors/transform/transform.cc | 23 ---------------- .../transform/transform_convert_graph.cc | 26 ++++++++++++++++++- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/source/blender/editors/transform/transform.cc b/source/blender/editors/transform/transform.cc index bbbef0ecc52..31700800f58 100644 --- a/source/blender/editors/transform/transform.cc +++ b/source/blender/editors/transform/transform.cc @@ -967,35 +967,12 @@ static bool transform_event_modal_constraint(TransInfo *t, short modal_type) return true; } -static bool editor_forces_constraints(TransInfo *t) -{ - switch (t->spacetype) { - case SPACE_GRAPH: { - if (t->mode != TFM_TRANSLATION) { - return false; - } - SpaceGraph *space_graph = (SpaceGraph *)t->area->spacedata.first; - return space_graph->flag & SIPO_AUTOLOCK_AXIS; - } - - default: - break; - } - return false; -} - int transformEvent(TransInfo *t, const wmEvent *event) { bool handled = false; bool is_navigating = t->vod ? ((RegionView3D *)t->region->regiondata)->rflag & RV3D_NAVIGATING : false; - /* Auto set constraints if the editor supports it. Don't do it if a constraint is already active - * or it would be impossible for the user to change it. */ - if (editor_forces_constraints(t) && (t->con.mode & CON_APPLY) == 0) { - initSelectConstraint(t); - } - /* Handle modal numinput events first, if already activated. */ if (!is_navigating && ((event->val == KM_PRESS) || (event->type == EVT_MODAL_MAP)) && hasNumInput(&t->num) && handleNumInput(t->context, &(t->num), event)) diff --git a/source/blender/editors/transform/transform_convert_graph.cc b/source/blender/editors/transform/transform_convert_graph.cc index 251f9f4b7f1..51c16e620e4 100644 --- a/source/blender/editors/transform/transform_convert_graph.cc +++ b/source/blender/editors/transform/transform_convert_graph.cc @@ -27,6 +27,7 @@ #include "UI_view2d.hh" #include "transform.hh" +#include "transform_constraints.hh" #include "transform_convert.hh" #include "transform_mode.hh" #include "transform_snap.hh" @@ -145,6 +146,22 @@ static bool graph_edit_use_local_center(TransInfo *t) return ((t->around == V3D_AROUND_LOCAL_ORIGINS) && (graph_edit_is_translation_mode(t) == false)); } +static void enable_autolock(TransInfo *t, SpaceGraph *space_graph) +{ + if (t->mode != TFM_TRANSLATION) { + return; + } + + /* Those flags are set when using tweak mode on handles. */ + if ((space_graph->runtime.flag & SIPO_RUNTIME_FLAG_TWEAK_HANDLES_LEFT) || + (space_graph->runtime.flag & SIPO_RUNTIME_FLAG_TWEAK_HANDLES_RIGHT)) + { + return; + } + + initSelectConstraint(t); +} + /** * Get the effective selection of a triple for transform, i.e. return if the left handle, right * handle and/or the center point should be affected by transform. @@ -367,6 +384,8 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } } + bool only_handles_selected = true; + /* loop 2: build transdata arrays */ LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); @@ -405,7 +424,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) TransDataCurveHandleFlags *hdata = nullptr; graph_bezt_get_transform_selection(t, bezt, use_handle, &sel_left, &sel_key, &sel_right); - + only_handles_selected &= !sel_key; if (is_prop_edit) { bool is_sel = (sel_key || sel_left || sel_right); /* we always select all handles for proportional editing if central handle is selected */ @@ -459,6 +478,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } } else { + /* only include handles if selected, irrespective of the interpolation modes. * also, only treat handles specially if the center point isn't selected. */ @@ -616,6 +636,10 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } } + if (sipo->flag & SIPO_AUTOLOCK_AXIS && !only_handles_selected) { + enable_autolock(t, sipo); + } + /* cleanup temp list */ ANIM_animdata_freelist(&anim_data); } -- 2.30.2 From 533d3d2bf21327d2d7dc42ad24ab697477417a44 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Fri, 2 Feb 2024 17:31:11 +0100 Subject: [PATCH 3/6] update description --- source/blender/makesrna/intern/rna_space.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/blender/makesrna/intern/rna_space.cc b/source/blender/makesrna/intern/rna_space.cc index 7b66bc66a38..cae6d6d9256 100644 --- a/source/blender/makesrna/intern/rna_space.cc +++ b/source/blender/makesrna/intern/rna_space.cc @@ -6425,8 +6425,9 @@ static void rna_def_space_graph(BlenderRNA *brna) prop = RNA_def_property(srna, "autolock_translation_axis", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, nullptr, "flag", SIPO_AUTOLOCK_AXIS); RNA_def_property_ui_text(prop, - "Auto-Lock Axis", - "Automatically locks the movement of keyframes to the dominant axis"); + "Auto-Lock Key Axis", + "Automatically locks the movement of keyframes to the dominant axis. " + "Ignores keyframe handles"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, nullptr); prop = RNA_def_property(srna, "use_only_selected_keyframe_handles", PROP_BOOLEAN, PROP_NONE); -- 2.30.2 From 4095a9fdba52ee84ff1306aeeec26964ee972c0c Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 6 Feb 2024 10:02:07 +0100 Subject: [PATCH 4/6] review comments --- source/blender/editors/transform/transform_convert_graph.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/transform/transform_convert_graph.cc b/source/blender/editors/transform/transform_convert_graph.cc index 51c16e620e4..1352a1ea285 100644 --- a/source/blender/editors/transform/transform_convert_graph.cc +++ b/source/blender/editors/transform/transform_convert_graph.cc @@ -148,11 +148,13 @@ static bool graph_edit_use_local_center(TransInfo *t) static void enable_autolock(TransInfo *t, SpaceGraph *space_graph) { + /* Locking the axis makes most sense for translation. We may want to enable it for scaling as + * well if artists require that. */ if (t->mode != TFM_TRANSLATION) { return; } - /* Those flags are set when using tweak mode on handles. */ + /* These flags are set when using tweak mode on handles. */ if ((space_graph->runtime.flag & SIPO_RUNTIME_FLAG_TWEAK_HANDLES_LEFT) || (space_graph->runtime.flag & SIPO_RUNTIME_FLAG_TWEAK_HANDLES_RIGHT)) { @@ -478,7 +480,6 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } } else { - /* only include handles if selected, irrespective of the interpolation modes. * also, only treat handles specially if the center point isn't selected. */ -- 2.30.2 From 0adfa275294522faed8deba14868f2ba77eddc53 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 6 Feb 2024 10:03:36 +0100 Subject: [PATCH 5/6] invert key selection check --- source/blender/editors/transform/transform_convert_graph.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/transform/transform_convert_graph.cc b/source/blender/editors/transform/transform_convert_graph.cc index 1352a1ea285..61c482b62eb 100644 --- a/source/blender/editors/transform/transform_convert_graph.cc +++ b/source/blender/editors/transform/transform_convert_graph.cc @@ -386,7 +386,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } } - bool only_handles_selected = true; + bool at_least_one_key_selected = false; /* loop 2: build transdata arrays */ LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { @@ -426,7 +426,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) TransDataCurveHandleFlags *hdata = nullptr; graph_bezt_get_transform_selection(t, bezt, use_handle, &sel_left, &sel_key, &sel_right); - only_handles_selected &= !sel_key; + at_least_one_key_selected |= sel_key; if (is_prop_edit) { bool is_sel = (sel_key || sel_left || sel_right); /* we always select all handles for proportional editing if central handle is selected */ @@ -637,7 +637,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } } - if (sipo->flag & SIPO_AUTOLOCK_AXIS && !only_handles_selected) { + if (sipo->flag & SIPO_AUTOLOCK_AXIS && at_least_one_key_selected) { enable_autolock(t, sipo); } -- 2.30.2 From f190b8d789e72ae53f36f4b50ac27a34883a0f16 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 6 Feb 2024 23:20:56 +0100 Subject: [PATCH 6/6] don't mention handles in the tooltip --- source/blender/makesrna/intern/rna_space.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/blender/makesrna/intern/rna_space.cc b/source/blender/makesrna/intern/rna_space.cc index ed7879c32e4..1152ab2f68e 100644 --- a/source/blender/makesrna/intern/rna_space.cc +++ b/source/blender/makesrna/intern/rna_space.cc @@ -6426,8 +6426,7 @@ static void rna_def_space_graph(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, nullptr, "flag", SIPO_AUTOLOCK_AXIS); RNA_def_property_ui_text(prop, "Auto-Lock Key Axis", - "Automatically locks the movement of keyframes to the dominant axis. " - "Ignores keyframe handles"); + "Automatically locks the movement of keyframes to the dominant axis"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, nullptr); prop = RNA_def_property(srna, "use_only_selected_keyframe_handles", PROP_BOOLEAN, PROP_NONE); -- 2.30.2