[Bf-blender-cvs] [a39ca327bc8] master: Fix T76935: Current orientation not taken in account when using "Align to transform orientation"

Germano Cavalcante noreply at git.blender.org
Thu May 21 16:01:15 CEST 2020


Commit: a39ca327bc8491129d9794d136b39a6ba8cd6ffa
Author: Germano Cavalcante
Date:   Thu May 21 10:57:35 2020 -0300
Branches: master
https://developer.blender.org/rBa39ca327bc8491129d9794d136b39a6ba8cd6ffa

Fix T76935: Current orientation not taken in account when using "Align to transform orientation"

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

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_mode.c
M	source/blender/editors/transform/transform_mode.h

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

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index f779a6dea39..bb4291555d0 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -896,74 +896,59 @@ int transformEvent(TransInfo *t, const wmEvent *event)
         break;
       case TFM_MODAL_TRANSLATE:
         /* only switch when... */
-        if (ELEM(t->mode,
-                 TFM_ROTATION,
-                 TFM_RESIZE,
-                 TFM_TRACKBALL,
-                 TFM_EDGE_SLIDE,
-                 TFM_VERT_SLIDE)) {
-          restoreTransObjects(t);
-          resetTransModal(t);
-          resetTransRestrictions(t);
-          transform_mode_init(t, NULL, TFM_TRANSLATION);
-          initSnapping(t, NULL);  // need to reinit after mode change
-          t->redraw |= TREDRAW_HARD;
-          handled = true;
-        }
-        else if (t->mode == TFM_SEQ_SLIDE) {
-          t->flag ^= T_ALT_TRANSFORM;
-          t->redraw |= TREDRAW_HARD;
-          handled = true;
-        }
-        else {
-          if (t->obedit_type == OB_MESH) {
-            if ((t->mode == TFM_TRANSLATION) && (t->spacetype == SPACE_VIEW3D)) {
-              restoreTransObjects(t);
+        if (t->mode == TFM_TRANSLATION) {
+          if ((t->obedit_type == OB_MESH) && (t->spacetype == SPACE_VIEW3D)) {
+            restoreTransObjects(t);
+            resetTransModal(t);
+            resetTransRestrictions(t);
+
+            /* first try edge slide */
+            transform_mode_init(t, NULL, TFM_EDGE_SLIDE);
+            /* if that fails, do vertex slide */
+            if (t->state == TRANS_CANCEL) {
+              resetTransModal(t);
+              t->state = TRANS_STARTING;
+              transform_mode_init(t, NULL, TFM_VERT_SLIDE);
+            }
+            /* vert slide can fail on unconnected vertices (rare but possible) */
+            if (t->state == TRANS_CANCEL) {
               resetTransModal(t);
+              t->state = TRANS_STARTING;
+              restoreTransObjects(t);
               resetTransRestrictions(t);
-
-              /* first try edge slide */
-              transform_mode_init(t, NULL, TFM_EDGE_SLIDE);
-              /* if that fails, do vertex slide */
-              if (t->state == TRANS_CANCEL) {
-                resetTransModal(t);
-                t->state = TRANS_STARTING;
-                transform_mode_init(t, NULL, TFM_VERT_SLIDE);
-              }
-              /* vert slide can fail on unconnected vertices (rare but possible) */
-              if (t->state == TRANS_CANCEL) {
-                resetTransModal(t);
-                t->state = TRANS_STARTING;
-                restoreTransObjects(t);
-                resetTransRestrictions(t);
-                transform_mode_init(t, NULL, TFM_TRANSLATION);
-              }
-              initSnapping(t, NULL);  // need to reinit after mode change
-              t->redraw |= TREDRAW_HARD;
-              handled = true;
+              transform_mode_init(t, NULL, TFM_TRANSLATION);
             }
+            initSnapping(t, NULL);  // need to reinit after mode change
+            t->redraw |= TREDRAW_HARD;
+            handled = true;
           }
           else if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
-            if (t->mode == TFM_TRANSLATION) {
-              restoreTransObjects(t);
+            restoreTransObjects(t);
 
-              t->flag ^= T_ALT_TRANSFORM;
-              t->redraw |= TREDRAW_HARD;
-              handled = true;
-            }
+            t->flag ^= T_ALT_TRANSFORM;
+            t->redraw |= TREDRAW_HARD;
+            handled = true;
           }
         }
+        else if (t->mode == TFM_SEQ_SLIDE) {
+          t->flag ^= T_ALT_TRANSFORM;
+          t->redraw |= TREDRAW_HARD;
+          handled = true;
+        }
+        else if (transform_mode_is_changeable(t->mode)) {
+          restoreTransObjects(t);
+          resetTransModal(t);
+          resetTransRestrictions(t);
+          transform_mode_init(t, NULL, TFM_TRANSLATION);
+          initSnapping(t, NULL);  // need to reinit after mode change
+          t->redraw |= TREDRAW_HARD;
+          handled = true;
+        }
         break;
       case TFM_MODAL_ROTATE:
         /* only switch when... */
         if (!(t->options & CTX_TEXTURE) && !(t->options & (CTX_MOVIECLIP | CTX_MASK))) {
-          if (ELEM(t->mode,
-                   TFM_ROTATION,
-                   TFM_RESIZE,
-                   TFM_TRACKBALL,
-                   TFM_TRANSLATION,
-                   TFM_EDGE_SLIDE,
-                   TFM_VERT_SLIDE)) {
+          if (transform_mode_is_changeable(t->mode)) {
             restoreTransObjects(t);
             resetTransModal(t);
             resetTransRestrictions(t);
@@ -982,13 +967,21 @@ int transformEvent(TransInfo *t, const wmEvent *event)
         break;
       case TFM_MODAL_RESIZE:
         /* only switch when... */
-        if (ELEM(t->mode,
-                 TFM_ROTATION,
-                 TFM_TRANSLATION,
-                 TFM_TRACKBALL,
-                 TFM_EDGE_SLIDE,
-                 TFM_VERT_SLIDE)) {
+        if (t->mode == TFM_RESIZE) {
+          if (t->options & CTX_MOVIECLIP) {
+            restoreTransObjects(t);
 
+            t->flag ^= T_ALT_TRANSFORM;
+            t->redraw |= TREDRAW_HARD;
+            handled = true;
+          }
+        }
+        else if (t->mode == TFM_SHRINKFATTEN) {
+          t->flag ^= T_ALT_TRANSFORM;
+          t->redraw |= TREDRAW_HARD;
+          handled = true;
+        }
+        else if (transform_mode_is_changeable(t->mode)) {
           /* Scale isn't normally very useful after extrude along normals, see T39756 */
           if ((t->con.mode & CON_APPLY) && (t->con.orientation == V3D_ORIENT_NORMAL)) {
             stopConstraint(t);
@@ -1002,20 +995,6 @@ int transformEvent(TransInfo *t, const wmEvent *event)
           t->redraw |= TREDRAW_HARD;
           handled = true;
         }
-        else if (t->mode == TFM_SHRINKFATTEN) {
-          t->flag ^= T_ALT_TRANSFORM;
-          t->redraw |= TREDRAW_HARD;
-          handled = true;
-        }
-        else if (t->mode == TFM_RESIZE) {
-          if (t->options & CTX_MOVIECLIP) {
-            restoreTransObjects(t);
-
-            t->flag ^= T_ALT_TRANSFORM;
-            t->redraw |= TREDRAW_HARD;
-            handled = true;
-          }
-        }
         break;
 
       case TFM_MODAL_SNAP_INV_ON:
@@ -1229,7 +1208,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
           break;
         }
         /* only switch when... */
-        if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL)) {
+        if (t->mode != TFM_TRANSLATION && transform_mode_is_changeable(t->mode)) {
           restoreTransObjects(t);
           resetTransModal(t);
           resetTransRestrictions(t);
@@ -1244,7 +1223,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
           break;
         }
         /* only switch when... */
-        if (ELEM(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL)) {
+        if (t->mode != TFM_RESIZE && transform_mode_is_changeable(t->mode)) {
           restoreTransObjects(t);
           resetTransModal(t);
           resetTransRestrictions(t);
@@ -1260,7 +1239,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
         }
         /* only switch when... */
         if (!(t->options & CTX_TEXTURE)) {
-          if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION)) {
+          if (transform_mode_is_changeable(t->mode)) {
             restoreTransObjects(t);
             resetTransModal(t);
             resetTransRestrictions(t);
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 36dc01fc9c6..2f3b50a7c1a 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1660,8 +1660,15 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
       orient_type_scene += index_custom;
     }
 
-    short orient_type_default = V3D_ORIENT_VIEW;
+    short orient_type_default;
     short orient_type_constraint[2];
+    if ((t->flag & T_MODAL) && transform_mode_is_changeable(t->mode)) {
+      /* During modal, rotation starts with the View orientation. */
+      orient_type_default = V3D_ORIENT_VIEW;
+    }
+    else {
+      orient_type_default = orient_type_scene;
+    }
 
     if (op && (prop = RNA_struct_find_property(op->ptr, "orient_axis"))) {
       t->orient_axis = RNA_property_enum_get(op->ptr, prop);
diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c
index 4c14c3aebd7..c2c880b03ff 100644
--- a/source/blender/editors/transform/transform_mode.c
+++ b/source/blender/editors/transform/transform_mode.c
@@ -61,6 +61,18 @@ bool transdata_check_local_center(TransInfo *t, short around)
            (t->options & (CTX_MOVIECLIP | CTX_MASK | CTX_PAINT_CURVE))));
 }
 
+/* Informs if the mode can be switched during modal. */
+bool transform_mode_is_changeable(const int mode)
+{
+  return ELEM(mode,
+              TFM_ROTATION,
+              TFM_RESIZE,
+              TFM_TRACKBALL,
+              TFM_TRANSLATION,
+              TFM_EDGE_SLIDE,
+              TFM_VERT_SLIDE);
+}
+
 /* -------------------------------------------------------------------- */
 /** \name Transform Locks
  * \{ */
diff --git a/source/blender/editors/transform/transform_mode.h b/source/blender/editors/transform/transform_mode.h
index 6180f6d3477..074e89390c2 100644
--- a/source/blender/editors/transform/transform_mode.h
+++ b/source/blender/editors/transform/transform_mode.h
@@ -41,6 +41,7 @@ typedef struct TransDataGenericSlideVert {
 
 /* transform_mode.c */
 bool transdata_check_local_center(TransInfo *t, short around);
+bool transform_mode_is_changeable(const int mode);
 void protectedTransBits(short protectflag, float vec[3]);
 void constraintTransLim(TransInfo *t, TransData *td);
 void postInputRotation(TransInfo *t, float values[3]);



More information about the Bf-blender-cvs mailing list