[Bf-blender-cvs] [388b9162469] master: Fix T80937: Changing the contrain axis does not return to the scene orientation

Germano Cavalcante noreply at git.blender.org
Fri Sep 25 15:24:30 CEST 2020


Commit: 388b9162469650c7b0523c2fb9c88bbe2dee1567
Author: Germano Cavalcante
Date:   Thu Sep 24 19:16:41 2020 -0300
Branches: master
https://developer.blender.org/rB388b9162469650c7b0523c2fb9c88bbe2dee1567

Fix T80937: Changing the contrain axis does not return to the scene orientation

This was the behavior in old versions of blender.

During a transformation operation, when pressing a contrain key, the chosen
orientation is that of the scene.

If you press the same key, the orientation changes to Global or Local.

However, if you choose another contrain axis with the orientation changed,
the orientation does not return to the set for the scene.

It remains Global or Local.

Now when changing a contrain axis, no matter what the current orientation is,
it always returns to the scene orientation.

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

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform_constraints.c
M	source/blender/editors/transform/transform_constraints.h
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_mode_rotate.c
M	source/blender/editors/transform/transform_orientations.c

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

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index bc08cb91c0d..ab24bbb35d4 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -755,27 +755,22 @@ static void transform_event_xyz_constraint(TransInfo *t, short key_type, bool is
         stopConstraint(t);
       }
       else {
-        setUserConstraint(t, V3D_ORIENT_GLOBAL, constraint_axis, msg1);
+        setUserConstraint(t, constraint_axis, msg1);
       }
     }
     else if (!edit_2d) {
+      short orient_index = 1;
       if (t->orient_curr == 0 || ELEM(cmode, '\0', axis)) {
         /* Successive presses on existing axis, cycle orientation modes. */
-        t->orient_curr = (short)((t->orient_curr + 1) % (int)ARRAY_SIZE(t->orient));
-        transform_orientations_current_set(t, t->orient_curr);
+        orient_index = (short)((t->orient_curr + 1) % (int)ARRAY_SIZE(t->orient));
       }
 
-      if (t->orient_curr == 0) {
+      transform_orientations_current_set(t, orient_index);
+      if (orient_index == 0) {
         stopConstraint(t);
       }
       else {
-        const short orientation = t->orient[t->orient_curr].type;
-        if (is_plane == false) {
-          setUserConstraint(t, orientation, constraint_axis, msg2);
-        }
-        else {
-          setUserConstraint(t, orientation, constraint_plane, msg3);
-        }
+        setUserConstraint(t, constraint_axis, is_plane ? msg3 : msg2);
       }
     }
     t->redraw |= TREDRAW_HARD;
@@ -1717,10 +1712,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 
   initTransInfo(C, t, op, event);
 
-  /* Use the custom orientation when it is set. */
-  short orient_index = t->orient[0].type == V3D_ORIENT_CUSTOM_MATRIX ? 0 : t->orient_curr;
-  transform_orientations_current_set(t, orient_index);
-
   if (t->spacetype == SPACE_VIEW3D) {
     t->draw_handle_apply = ED_region_draw_cb_activate(
         t->region->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
@@ -1868,7 +1859,7 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 
   /* Constraint init from operator */
   if (t->con.mode & CON_APPLY) {
-    setUserConstraint(t, t->orient[t->orient_curr].type, t->con.mode, "%s");
+    setUserConstraint(t, t->con.mode, "%s");
   }
 
   /* Don't write into the values when non-modal because they are already set from operator redo
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index 805411ffc20..27ece728276 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -686,9 +686,15 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[])
  * ftext is a format string passed to BLI_snprintf. It will add the name of
  * the orientation where %s is (logically).
  */
-void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[])
+void setUserConstraint(TransInfo *t, int mode, const char ftext[])
 {
   char text[256];
+  short orientation = t->orient[t->orient_curr].type;
+  if (orientation == V3D_ORIENT_CUSTOM_MATRIX) {
+    /* Use the real value of the "orient_type". */
+    orientation = t->orient[0].type;
+  }
+
   const char *spacename = transform_orientations_spacename_get(t, orientation);
   BLI_snprintf(text, sizeof(text), ftext, spacename);
 
@@ -943,12 +949,10 @@ void stopConstraint(TransInfo *t)
 void initSelectConstraint(TransInfo *t)
 {
   if (t->orient_curr == 0) {
-    t->orient_curr = 1;
-    transform_orientations_current_set(t, t->orient_curr);
+    transform_orientations_current_set(t, 1);
   }
 
-  short orientation = t->orient[t->orient_curr].type;
-  setUserConstraint(t, orientation, CON_APPLY | CON_SELECT, "%s");
+  setUserConstraint(t, CON_APPLY | CON_SELECT, "%s");
   setNearestAxis(t);
 }
 
diff --git a/source/blender/editors/transform/transform_constraints.h b/source/blender/editors/transform/transform_constraints.h
index 4c901842964..ac62c057f9d 100644
--- a/source/blender/editors/transform/transform_constraints.h
+++ b/source/blender/editors/transform/transform_constraints.h
@@ -35,7 +35,7 @@ void transform_constraint_snap_axis_to_face(const TransInfo *t,
 void setConstraint(TransInfo *t, int mode, const char text[]);
 void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[]);
 void setLocalConstraint(TransInfo *t, int mode, const char text[]);
-void setUserConstraint(TransInfo *t, short orientation, int mode, const char text[]);
+void setUserConstraint(TransInfo *t, int mode, const char text[]);
 void drawConstraint(TransInfo *t);
 void drawPropCircle(const struct bContext *C, TransInfo *t);
 void startConstraint(TransInfo *t);
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index a2e1c50e375..ba87f0bcc38 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -442,7 +442,10 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
   }
 
   BLI_assert(is_zero_v4(t->values_modal_offset));
+
+  bool use_orient_axis = false;
   bool t_values_set_is_array = false;
+
   if (op && (prop = RNA_struct_find_property(op->ptr, "value")) &&
       RNA_property_is_set(op->ptr, prop)) {
     float values[4] = {0}; /* in case value isn't length 4, avoid uninitialized memory  */
@@ -465,19 +468,28 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
     }
   }
 
+  if (op && (prop = RNA_struct_find_property(op->ptr, "orient_axis"))) {
+    t->orient_axis = RNA_property_enum_get(op->ptr, prop);
+    use_orient_axis = true;
+  }
+
   if (op && (prop = RNA_struct_find_property(op->ptr, "constraint_axis"))) {
     bool constraint_axis[3] = {false, false, false};
-    if (RNA_property_is_set(op->ptr, prop)) {
-      RNA_property_boolean_get_array(op->ptr, prop, constraint_axis);
-    }
-
-    if (t_values_set_is_array && t->flag & T_INPUT_IS_VALUES_FINAL) {
-      /* For operators whose `t->values` is array, set constraint so that the
-       * orientation is more intuitive in the Redo Panel. */
-      for (int i = 3; i--;) {
-        constraint_axis[i] |= t->values[i] != 0.0f;
+    if (t->flag & T_INPUT_IS_VALUES_FINAL) {
+      if (t_values_set_is_array) {
+        /* For operators whose `t->values` is array, set constraint so that the
+         * orientation is more intuitive in the Redo Panel. */
+        for (int i = 3; i--;) {
+          constraint_axis[i] |= t->values[i] != 0.0f;
+        }
+      }
+      else if (use_orient_axis) {
+        constraint_axis[t->orient_axis] = true;
       }
     }
+    else if (RNA_property_is_set(op->ptr, prop)) {
+      RNA_property_boolean_get_array(op->ptr, prop, constraint_axis);
+    }
 
     if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2]) {
       t->con.mode |= CON_APPLY;
@@ -495,9 +507,13 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
   }
 
   {
-    short orient_type_set = -1;
-    short orient_type_matrix_set = -1;
+    short orient_types[3];
+    float custom_matrix[3][3];
+
+    short orient_type_default = V3D_ORIENT_GLOBAL;
     short orient_type_scene = V3D_ORIENT_GLOBAL;
+    short orient_type_set = V3D_ORIENT_GLOBAL;
+    short orient_type_matrix_set = -1;
 
     if ((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW)) {
       TransformOrientationSlot *orient_slot = &t->scene->orientation_slots[SCE_ORIENT_DEFAULT];
@@ -508,14 +524,6 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
       }
     }
 
-    short orient_types[3];
-    float custom_matrix[3][3];
-    bool use_orient_axis = false;
-
-    if (op && (prop = RNA_struct_find_property(op->ptr, "orient_axis"))) {
-      t->orient_axis = RNA_property_enum_get(op->ptr, prop);
-      use_orient_axis = true;
-    }
     if (op && (prop = RNA_struct_find_property(op->ptr, "orient_axis_ortho"))) {
       t->orient_axis_ortho = RNA_property_enum_get(op->ptr, prop);
     }
@@ -530,21 +538,21 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
       }
 
       /* Change the default orientation to be used when redoing. */
-      orient_types[0] = orient_type_set;
-      orient_types[1] = orient_type_set;
-      orient_types[2] = orient_type_scene;
+      orient_type_default = orient_type_set;
+    }
+    else if (t->con.mode & CON_APPLY) {
+      orient_type_set = orient_type_default = orient_type_scene;
     }
     else {
+      if (orient_type_set == orient_type_scene) {
+        BLI_assert(orient_type_set == V3D_ORIENT_GLOBAL);
+        orient_type_set = V3D_ORIENT_LOCAL;
+      }
+
       if ((t->flag & T_MODAL) && (use_orient_axis || transform_mode_is_changeable(t->mode)) &&
           (t->mode != TFM_ALIGN)) {
-        orient_types[0] = V3D_ORIENT_VIEW;
+        orient_type_default = V3D_ORIENT_VIEW;
       }
-      else {
-        orient_types[0] = orient_type_scene;
-      }
-      orient_types[1] = orient_type_scene;
-      orient_types[2] = orient_type_scene != V3D_ORIENT_GLOBAL ? V3D_ORIENT_GLOBAL :
-                                                                 V3D_ORIENT_LOCAL;
     }
 
     if (op && ((prop = RNA_struct_find_property(op->ptr, "orient_matrix")) &&
@@ -555,39 +563,39 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
           RNA_property_is_set(op->ptr, prop)) {
         orient_type_matrix_set = RNA_property_enum_get(op->ptr, prop);
       }
-      else if (orient_type_set != -1) {
-        orient_type_matrix_set = orient_type_set;
-      }
       else {
-        orient_type_matrix_set = orient_type_set = V3D_ORIENT_GLOBAL;
+        orient_type_matrix_set = orient_type_set;
       }
 
       if (orient_type_matrix_set == orient_type_set) {
         /* Constraints are forced to use the custom matrix when redoing. */
-        orient_types[0] = V3D_ORIENT_CUSTOM_MATRIX;
+        orient_type_set = V3D_ORIENT_CUSTOM_MATRI

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list