From bb67d4c298ac071a2bb524af68985c5d25ad8b90 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 27 Mar 2023 14:38:47 -0300 Subject: [PATCH] Transform: expose hardcoded 'Rotate Normals' key "Rotate Normals" is a changeable operation like any other and does not need to be hardcoded. An advantage of exposing this modal is that the shortcut key now appears in the header when rotating an edited mesh. --- scripts/modules/bl_keymap_utils/versioning.py | 2 ++ .../keyconfig/keymap_data/blender_default.py | 1 + .../keymap_data/industry_compatible_data.py | 1 + source/blender/editors/transform/transform.c | 31 +++++++++---------- source/blender/editors/transform/transform.h | 1 + .../editors/transform/transform_mode.c | 3 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/scripts/modules/bl_keymap_utils/versioning.py b/scripts/modules/bl_keymap_utils/versioning.py index 6b794c52e29..0b1ae56a90d 100644 --- a/scripts/modules/bl_keymap_utils/versioning.py +++ b/scripts/modules/bl_keymap_utils/versioning.py @@ -76,6 +76,8 @@ def keyconfig_update(keyconfig_data, keyconfig_version): elif item_modal == 'ROTATE': km_items.append(('TRACKBALL', item_event, None)) + # The modal key for "Rotate Normals" also didn't exist until then. + km_items.append(('ROTATE_NORMALS', {"type": 'N', "value": 'PRESS'}, None)) break return keyconfig_data diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index 9b0e5f22ca0..c4ba8924173 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -5793,6 +5793,7 @@ def km_transform_modal_map(_params): ("ROTATE", {"type": 'R', "value": 'PRESS'}, None), ("TRACKBALL", {"type": 'R', "value": 'PRESS'}, None), ("RESIZE", {"type": 'S', "value": 'PRESS'}, None), + ("ROTATE_NORMALS", {"type": 'N', "value": 'PRESS'}, None), ("SNAP_TOGGLE", {"type": 'TAB', "value": 'PRESS', "shift": True}, None), ("SNAP_INV_ON", {"type": 'LEFT_CTRL', "value": 'PRESS', "any": True}, None), ("SNAP_INV_OFF", {"type": 'LEFT_CTRL', "value": 'RELEASE', "any": True}, None), diff --git a/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py index 90ab9e008a4..f141566e7cc 100644 --- a/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py +++ b/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py @@ -3975,6 +3975,7 @@ def km_transform_modal_map(_params): ("ROTATE", {"type": 'R', "value": 'PRESS'}, None), ("TRACKBALL", {"type": 'R', "value": 'PRESS'}, None), ("RESIZE", {"type": 'S', "value": 'PRESS'}, None), + ("ROTATE_NORMALS", {"type": 'N', "value": 'PRESS'}, None), ("SNAP_TOGGLE", {"type": 'TAB', "value": 'PRESS', "shift": True}, None), ("SNAP_INV_ON", {"type": 'LEFT_CTRL', "value": 'PRESS', "any": True}, None), ("SNAP_INV_OFF", {"type": 'LEFT_CTRL', "value": 'RELEASE', "any": True}, None), diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index c6eb7c4b504..78a42f1a3d8 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -620,7 +620,8 @@ static bool transform_modal_item_poll(const wmOperator *op, int value) case TFM_MODAL_ROTATE: case TFM_MODAL_RESIZE: case TFM_MODAL_VERT_EDGE_SLIDE: - case TFM_MODAL_TRACKBALL: { + case TFM_MODAL_TRACKBALL: + case TFM_MODAL_ROTATE_NORMALS: { if (!transform_mode_is_changeable(t->mode)) { return false; } @@ -662,6 +663,9 @@ static bool transform_modal_item_poll(const wmOperator *op, int value) t->mode != TFM_ROTATION) { return false; } + if (value == TFM_MODAL_ROTATE_NORMALS) { + return t->mode == TFM_ROTATION && t->data_type == &TransConvertType_Mesh; + } break; } } @@ -712,6 +716,7 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf) {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""}, {TFM_MODAL_TRACKBALL, "TRACKBALL", 0, "TrackBall", ""}, {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""}, + {TFM_MODAL_ROTATE_NORMALS, "ROTATE_NORMALS", 0, "Rotate Normals", ""}, {TFM_MODAL_AUTOCONSTRAINT, "AUTOCONSTRAIN", 0, "Automatic Constraint", ""}, {TFM_MODAL_AUTOCONSTRAINTPLANE, "AUTOCONSTRAINPLANE", 0, "Automatic Constraint Plane", ""}, {TFM_MODAL_PRECISION, "PRECISION", 0, "Precision Mode", ""}, @@ -957,6 +962,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) case TFM_MODAL_ROTATE: case TFM_MODAL_RESIZE: case TFM_MODAL_TRACKBALL: + case TFM_MODAL_ROTATE_NORMALS: case TFM_MODAL_VERT_EDGE_SLIDE: /* only switch when... */ if (!transform_mode_is_changeable(t->mode)) { @@ -977,11 +983,16 @@ int transformEvent(TransInfo *t, const wmEvent *event) if ((event->val == TFM_MODAL_ROTATE && t->mode == TFM_ROTATION) || (event->val == TFM_MODAL_TRACKBALL && t->mode == TFM_TRACKBALL) || + (event->val == TFM_MODAL_ROTATE_NORMALS && t->mode == TFM_NORMAL_ROTATION) || (event->val == TFM_MODAL_VERT_EDGE_SLIDE && ELEM(t->mode, TFM_VERT_SLIDE, TFM_EDGE_SLIDE))) { break; } + if (event->val == TFM_MODAL_ROTATE_NORMALS && t->data_type != &TransConvertType_Mesh) { + break; + } + restoreTransObjects(t); resetTransModal(t); resetTransRestrictions(t); @@ -995,6 +1006,9 @@ int transformEvent(TransInfo *t, const wmEvent *event) else if (event->val == TFM_MODAL_TRACKBALL) { transform_mode_init(t, NULL, TFM_TRACKBALL); } + else if (event->val == TFM_MODAL_ROTATE_NORMALS) { + transform_mode_init(t, NULL, TFM_NORMAL_ROTATION); + } else if (event->val == TFM_MODAL_RESIZE) { /* Scale isn't normally very useful after extrude along normals, see #39756 */ if ((t->con.mode & CON_APPLY) && (t->orient[t->orient_curr].type == V3D_ORIENT_NORMAL)) { @@ -1283,21 +1297,6 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; } break; - case EVT_NKEY: - if (event->flag & WM_EVENT_IS_REPEAT) { - break; - } - if (ELEM(t->mode, TFM_ROTATION)) { - if ((t->flag & T_EDIT) && t->obedit_type == OB_MESH) { - restoreTransObjects(t); - resetTransModal(t); - resetTransRestrictions(t); - transform_mode_init(t, NULL, TFM_NORMAL_ROTATION); - t->redraw = TREDRAW_HARD; - handled = true; - } - } - break; default: break; } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 55215f23426..ff1836145db 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -268,6 +268,7 @@ enum { TFM_MODAL_VERT_EDGE_SLIDE = 31, TFM_MODAL_TRACKBALL = 32, + TFM_MODAL_ROTATE_NORMALS = 33, }; /** \} */ diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c index e72ae622f93..1fa00aaed5b 100644 --- a/source/blender/editors/transform/transform_mode.c +++ b/source/blender/editors/transform/transform_mode.c @@ -72,7 +72,8 @@ bool transform_mode_is_changeable(const int mode) TFM_TRACKBALL, TFM_TRANSLATION, TFM_EDGE_SLIDE, - TFM_VERT_SLIDE); + TFM_VERT_SLIDE, + TFM_NORMAL_ROTATION); } /* -------------------------------------------------------------------- */