[Bf-blender-cvs] [e0b7aa6ba70] temp-snap-base: Transform: New feature to set a custom 'Snap With'

Germano Cavalcante noreply at git.blender.org
Mon Nov 9 10:09:03 CET 2020


Commit: e0b7aa6ba70ad9479240fa4b773a20f9498eb174
Author: Germano Cavalcante
Date:   Mon Nov 9 10:08:23 2020 +0100
Branches: temp-snap-base
https://developer.blender.org/rBe0b7aa6ba70ad9479240fa4b773a20f9498eb174

Transform: New feature to set a custom 'Snap With'

Ref T66484

Basically the idea is to use a modal keymap to change the current Base Point
defined by `Snap With` by one that can be chosen through snapping.

{F9170047}

I prefer to avoid using any of the modifier buttons (Shift, Alt, Ctrl) as
they can be used in the future to allow navigation during transform operations.

So the shortcut chosen in this patch is the {key B}.

Note:
This feature is not enabled if the scene snap option is Incremental or grid.

Maniphest Tasks: T66484

Differential Revision: https://developer.blender.org/D9415

===================================================================

M	release/scripts/addons
M	release/scripts/addons_contrib
M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_snap.c
M	source/blender/editors/transform/transform_snap.h
M	source/blender/editors/transform/transform_snap_object.c

===================================================================

diff --git a/release/scripts/addons b/release/scripts/addons
index 33eae7da675..8ad9de7c1e1 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 33eae7da675d532bbb9c12b129c0e30228f5f000
+Subproject commit 8ad9de7c1e1022dee907ddce78f4c357111fc09e
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index eae381b6982..26a8b2eadc7 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit eae381b698248e70e4a3c62bdf239f9d5a0470a9
+Subproject commit 26a8b2eadc7abb2a30fac50eb5505aa24daf5785
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 467eb317905..51dba3c8054 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5022,6 +5022,7 @@ def km_transform_modal_map(_params):
         ("INSERTOFS_TOGGLE_DIR", {"type": 'T', "value": 'PRESS'}, None),
         ("AUTOCONSTRAIN", {"type": 'MIDDLEMOUSE', "value": 'PRESS'}, None),
         ("AUTOCONSTRAINPLANE", {"type": 'MIDDLEMOUSE', "value": 'PRESS'}, None),
+        ("EDIT_SNAPWITH", {"type": 'B', "value": 'PRESS', "repeat": True}, None),
     ])
 
     return keymap
diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
index c79a59145cf..337ee0b4fef 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -3944,6 +3944,7 @@ def km_transform_modal_map(_params):
         ("INSERTOFS_TOGGLE_DIR", {"type": 'T', "value": 'PRESS'}, None),
         ("AUTOCONSTRAIN", {"type": 'MIDDLEMOUSE', "value": 'PRESS'}, None),
         ("AUTOCONSTRAINPLANE", {"type": 'MIDDLEMOUSE', "value": 'PRESS', "shift": True}, None),
+        ("EDIT_SNAPWITH", {"type": 'B', "value": 'PRESS', "repeat": True}, None),
     ])
 
     return keymap
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 1b1740cd5bc..7940b2431f2 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -636,6 +636,15 @@ static bool transform_modal_item_poll(const wmOperator *op, int value)
       }
       break;
     }
+    case TFM_MODAL_EDIT_SNAPWITH: {
+      if (t->spacetype != SPACE_VIEW3D) {
+        return false;
+      }
+      if (!(t->tsnap.mode & ~(SCE_SNAP_MODE_GRID | SCE_SNAP_MODE_INCREMENT))) {
+        return false;
+      }
+      break;
+    }
   }
   return true;
 }
@@ -685,6 +694,7 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
       {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
       {TFM_MODAL_AUTOCONSTRAINT, "AUTOCONSTRAIN", 0, "Automatic Constraint", ""},
       {TFM_MODAL_AUTOCONSTRAINTPLANE, "AUTOCONSTRAINPLANE", 0, "Automatic Constraint", ""},
+      {TFM_MODAL_EDIT_SNAPWITH, "EDIT_SNAPWITH", 0, "Edit snap with", ""},
       {0, NULL, 0, NULL, NULL},
   };
 
@@ -1108,6 +1118,9 @@ int transformEvent(TransInfo *t, const wmEvent *event)
           handled = true;
         }
         break;
+      case TFM_MODAL_EDIT_SNAPWITH:
+        tranform_snap_snapwith_init(t);
+        break;
       /* Those two are only handled in transform's own handler, see T44634! */
       case TFM_MODAL_EDGESLIDE_UP:
       case TFM_MODAL_EDGESLIDE_DOWN:
@@ -1206,12 +1219,15 @@ int transformEvent(TransInfo *t, const wmEvent *event)
       default: {
         /* Disable modifiers. */
         int modifiers = t->modifiers;
-        modifiers &= ~MOD_CONSTRAINT_SELECT;
-        modifiers &= ~MOD_CONSTRAINT_PLANE;
+        modifiers &= ~(MOD_CONSTRAINT_SELECT | MOD_CONSTRAINT_PLANE | MOD_EDIT_SNAPWITH);
         if (modifiers != t->modifiers) {
           if (t->modifiers & (MOD_CONSTRAINT_SELECT | MOD_CONSTRAINT_PLANE)) {
             postSelectConstraint(t);
           }
+          else {
+            BLI_assert(t->modifiers & MOD_EDIT_SNAPWITH);
+            tranform_snap_snapwith_end(t);
+          }
           t->modifiers = modifiers;
           t->redraw |= TREDRAW_HARD;
           handled = true;
@@ -1915,14 +1931,18 @@ void transformApply(bContext *C, TransInfo *t)
 
   if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT))) {
     selectConstraint(t);
-    if (t->transform) {
+    if (t->modifiers & MOD_EDIT_SNAPWITH) {
+      tranform_snap_snapwith_update(t);
+    }
+    else if (t->transform) {
       t->transform(t, t->mval); /* calls recalcData() */
-      viewRedrawForce(C, t);
+      t->redraw |= TREDRAW_SOFT;
     }
-    t->redraw = TREDRAW_NOTHING;
   }
-  else if (t->redraw & TREDRAW_SOFT) {
+
+  if (t->redraw & TREDRAW_SOFT) {
     viewRedrawForce(C, t);
+    t->redraw = TREDRAW_NOTHING;
   }
 
   /* If auto confirm is on, break after one pass */
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 17ef9a3034f..092e91bd969 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -84,9 +84,9 @@ typedef struct TransSnap {
   /* Snapped Element Type (currently for objects only). */
   char snapElem;
   /** snapping from this point (in global-space). */
-  float snapPoint[3];
-  /** to this point (in global-space). */
   float snapTarget[3];
+  /** to this point (in global-space). */
+  float snapPoint[3];
   float snapNormal[3];
   char snapNodeBorder;
   ListBase points;
@@ -498,6 +498,7 @@ enum {
   MOD_SNAP = 1 << 2,
   MOD_SNAP_INVERT = 1 << 3,
   MOD_CONSTRAINT_PLANE = 1 << 4,
+  MOD_EDIT_SNAPWITH = 1 << 5,
 };
 
 /* use node center for transform instead of upper-left corner.
@@ -578,6 +579,8 @@ enum {
 
   TFM_MODAL_AUTOCONSTRAINT = 28,
   TFM_MODAL_AUTOCONSTRAINTPLANE = 29,
+
+  TFM_MODAL_EDIT_SNAPWITH = 30,
 };
 
 bool initTransform(struct bContext *C,
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index f1c4c243780..a2b10041e09 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -128,6 +128,9 @@ bool validSnap(const TransInfo *t)
 
 bool activeSnap(const TransInfo *t)
 {
+  if (t->modifiers & MOD_EDIT_SNAPWITH) {
+    return true;
+  }
   return ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP) ||
          ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP_INVERT);
 }
@@ -177,8 +180,9 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
   activeCol[3] = 192;
 
   if (t->spacetype == SPACE_VIEW3D) {
-    bool draw_target = (t->tsnap.status & TARGET_INIT) &&
-                       (t->scene->toolsettings->snap_mode & SCE_SNAP_MODE_EDGE_PERPENDICULAR);
+    bool draw_target = (t->modifiers & MOD_EDIT_SNAPWITH) ||
+                       (t->tsnap.status & TARGET_INIT) &&
+                           (t->scene->toolsettings->snap_mode & SCE_SNAP_MODE_EDGE_PERPENDICULAR);
 
     if (draw_target || validSnap(t)) {
       const float *loc_cur = NULL;
@@ -1115,6 +1119,11 @@ static void TargetSnapClosest(TransInfo *t)
   }
 }
 
+static void TargetSnapCustom(TransInfo *t)
+{
+  t->tsnap.status |= TARGET_INIT;
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -1130,7 +1139,7 @@ short snapObjectsTransform(
       t->depsgraph,
       t->settings->snap_mode,
       &(const struct SnapObjectParams){
-          .snap_select = t->tsnap.modeSelect,
+          .snap_select = t->modifiers & MOD_EDIT_SNAPWITH ? SNAP_ALL : t->tsnap.modeSelect,
           .use_object_edit_cage = (t->flag & T_EDIT) != 0,
           .use_occlusion_test = t->settings->snap_mode != SCE_SNAP_MODE_FACE,
           .use_backface_culling = t->tsnap.use_backface_culling,
@@ -1546,6 +1555,42 @@ bool transform_snap_increment(TransInfo *t, float *val)
   return true;
 }
 
+void tranform_snap_snapwith_init(TransInfo *t)
+{
+  t->modifiers |= MOD_EDIT_SNAPWITH;
+  t->tsnap.targetSnap = TargetSnapCustom;
+  t->tsnap.targetSnap(t);
+  restoreTransObjects(t);
+}
+
+void tranform_snap_snapwith_update(TransInfo *t)
+{
+  BLI_assert(t->modifiers & MOD_EDIT_SNAPWITH);
+  double current = PIL_check_seconds_timer();
+
+  /* Time base quirky code to go around findnearest slowness */
+  /* TODO: add exception for object mode, no need to slow it down then. */
+  if (current - t->tsnap.last >= 0.01) {
+    t->tsnap.calcSnap(t, NULL);
+    t->tsnap.last = current;
+  }
+
+  if (validSnap(t)) {
+    copy_v3_v3(t->tsnap.snapTarget, t->tsnap.snapPoint);
+    t->redraw |= TREDRAW_SOFT;
+  }
+}
+
+void tranform_snap_snapwith_end(TransInfo *t)
+{
+  BLI_assert(t->modifiers & MOD_EDIT_SNAPWITH);
+  t->modifiers &= ~MOD_EDIT_SNAPWITH;
+
+  /* Force a reinit with a current #t->mval. */
+  initMouseInput(t, &t->mouse, t->center2d, t->mval, false);
+  applyMouseInput(t, &t->mouse, t->mval, t->values);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/transform/transform_snap.h b/source/blender/editors/transform/transform_snap.h
index 5bee572c603..732c8ab8dbd 100644
--- a/source/blender/editors/transform/transform_snap.h
+++ b/source/blender/editors/transform/transform_snap.h
@@ -59,6 +59,10 @@ bool transformModeUseSnap(const TransInfo *t);
 bool transform_snap_increment(TransInfo *t, float *val);
 bool transform_snap_grid(TransInfo *t, float *val);
 
+void tranform_snap_snapwith_init(TransInfo *t);
+void tranform_snap_snapwith_update(TransInfo *t);
+void tranform_snap_snapwith_end(TransInfo *t);
+
 void snapSequenceBounds(TransInfo *t, const int mval[2]);
 
 bool activeSnap(const TransInfo *t);
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 50b7c6d147b..9603692770b 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -395,7 +395,7 @@ static void iter_snap_o

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list