[Bf-blender-cvs] [c75a665c442] master: Transform: refactoring - unify constraint and default orientation

Germano Cavalcante noreply at git.blender.org
Fri May 22 17:40:40 CEST 2020


Commit: c75a665c442e9aa906703fa1f46ec2dc621e9263
Author: Germano Cavalcante
Date:   Fri May 22 12:34:29 2020 -0300
Branches: master
https://developer.blender.org/rBc75a665c442e9aa906703fa1f46ec2dc621e9263

Transform: refactoring - unify constraint and default orientation

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

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
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_gizmo_3d.c
M	source/blender/editors/transform/transform_mode_shear.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/editors/transform/transform_snap.c

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

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index bb4291555d0..5fc65522fe6 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -825,17 +825,17 @@ static void transform_event_xyz_constraint(TransInfo *t, short key_type, bool is
       }
     }
     else if (!edit_2d) {
-      if (t->orientation.index == 0 || ELEM(cmode, '\0', axis)) {
+      if (t->orient_curr == 0 || ELEM(cmode, '\0', axis)) {
         /* Successive presses on existing axis, cycle orientation modes. */
-        t->orientation.index = (t->orientation.index + 1) % ARRAY_SIZE(t->orientation.types);
-        initTransformOrientation(t->context, t, t->orientation.types[t->orientation.index]);
+        t->orient_curr = (short)((t->orient_curr + 1) % (int)ARRAY_SIZE(t->orient));
+        transform_orientations_current_set(t, t->orient_curr);
       }
 
-      if (t->orientation.index == 0) {
+      if (t->orient_curr == 0) {
         stopConstraint(t);
       }
       else {
-        const short orientation = t->orientation.types[t->orientation.index];
+        const short orientation = t->orient[t->orient_curr].type;
         if (is_plane == false) {
           setUserConstraint(t, orientation, constraint_axis, msg2);
         }
@@ -983,7 +983,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
         }
         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)) {
+          if ((t->con.mode & CON_APPLY) && (t->orient[t->orient_curr].type == V3D_ORIENT_NORMAL)) {
             stopConstraint(t);
           }
 
@@ -1601,8 +1601,8 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
     mul_m3_v3(t->spacemtx, t->values_final);
     unit_m3(t->spacemtx);
 
-    BLI_assert(t->orientation.index == 0);
-    t->orientation.types[0] = V3D_ORIENT_GLOBAL;
+    BLI_assert(t->orient_curr == 0);
+    t->orient[0].type = V3D_ORIENT_GLOBAL;
   }
 
   // Save back mode in case we're in the generic operator
@@ -1713,19 +1713,20 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
   }
 
   if ((prop = RNA_struct_find_property(op->ptr, "orient_type"))) {
-    short orient_set, orient_cur;
-    orient_set = RNA_property_is_set(op->ptr, prop) ? RNA_property_enum_get(op->ptr, prop) : -1;
-    orient_cur = t->orientation.types[t->orientation.index];
+    short orient_type_set, orient_type_curr;
+    orient_type_set = RNA_property_is_set(op->ptr, prop) ? RNA_property_enum_get(op->ptr, prop) :
+                                                           -1;
+    orient_type_curr = t->orient[t->orient_curr].type;
 
-    if (!ELEM(orient_cur, orient_set, V3D_ORIENT_CUSTOM_MATRIX)) {
-      RNA_property_enum_set(op->ptr, prop, orient_cur);
-      orient_set = orient_cur;
+    if (!ELEM(orient_type_curr, orient_type_set, V3D_ORIENT_CUSTOM_MATRIX)) {
+      RNA_property_enum_set(op->ptr, prop, orient_type_curr);
+      orient_type_set = orient_type_curr;
     }
 
     if (((prop = RNA_struct_find_property(op->ptr, "orient_matrix_type")) &&
          !RNA_property_is_set(op->ptr, prop))) {
       /* Set the first time to register on redo. */
-      RNA_property_enum_set(op->ptr, prop, orient_set);
+      RNA_property_enum_set(op->ptr, prop, orient_type_set);
       RNA_float_set_array(op->ptr, "orient_matrix", &t->spacemtx[0][0]);
     }
   }
@@ -1873,11 +1874,8 @@ 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 orientation = t->orientation.types[0] == V3D_ORIENT_CUSTOM_MATRIX ?
-                          V3D_ORIENT_CUSTOM_MATRIX :
-                          t->orientation.types[t->orientation.index];
-
-  initTransformOrientation(C, t, orientation);
+  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(
@@ -2033,7 +2031,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->orientation.types[t->orientation.index], t->con.mode, "%s");
+    setUserConstraint(t, t->orient[t->orient_curr].type, 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.h b/source/blender/editors/transform/transform.h
index 9f4b3773fd8..7720660e2e8 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -113,13 +113,8 @@ typedef struct TransSnap {
 } TransSnap;
 
 typedef struct TransCon {
-  short orientation;
   /** Description of the constraint for header_print. */
   char text[50];
-  /** Matrix of the constraint space. */
-  float mtx[3][3];
-  /** Inverse matrix of the constraint space. */
-  float imtx[3][3];
   /** Projection constraint matrix (same as #imtx with some axis == 0). */
   float pmtx[3][3];
   /** Initial mouse value for visual calculation
@@ -531,13 +526,11 @@ typedef struct TransInfo {
   bool is_launch_event_tweak;
 
   struct {
-    short index;
-    short types[3];
-    /* this gets used when orientation.type[x] is V3D_ORIENT_CUSTOM */
-    struct TransformOrientation *custom;
-    /* this gets used when orientation.type[0] is V3D_ORIENT_CUSTOM_MATRIX */
-    float custom_matrix[3][3];
-  } orientation;
+    short type;
+    float matrix[3][3];
+  } orient[3];
+  short orient_curr;
+
   /** backup from view3d, to restore on end. */
   short gizmo_flag;
 
@@ -911,8 +904,13 @@ void getViewVector(const TransInfo *t, const float coord[3], float vec[3]);
 void transform_data_ext_rotate(TransData *td, float mat[3][3], bool use_drot);
 
 /*********************** Transform Orientations ******************************/
-
-void initTransformOrientation(struct bContext *C, TransInfo *t, short orientation);
+short transform_orientation_matrix_get(struct bContext *C,
+                                       TransInfo *t,
+                                       const short orientation,
+                                       const float custom[3][3],
+                                       float r_spacemtx[3][3]);
+const char *transform_orientations_spacename_get(TransInfo *t, const short orient_type);
+void transform_orientations_current_set(struct TransInfo *t, const short orient_index);
 
 /* Those two fill in mat and return non-zero on success */
 bool createSpaceNormal(float mat[3][3], const float normal[3]);
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index b05b99d9601..d13fa6de7c5 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -42,6 +42,7 @@
 #include "BLI_utildefines.h"
 
 #include "BKE_context.h"
+#include "BKE_scene.h"
 
 #include "ED_view3d.h"
 
@@ -57,6 +58,27 @@
 
 static void drawObjectConstraint(TransInfo *t);
 
+static void projection_matrix_calc(const TransInfo *t, float r_pmtx[3][3])
+{
+  unit_m3(r_pmtx);
+
+  if (!(t->con.mode & CON_AXIS0)) {
+    zero_v3(r_pmtx[0]);
+  }
+
+  if (!(t->con.mode & CON_AXIS1)) {
+    zero_v3(r_pmtx[1]);
+  }
+
+  if (!(t->con.mode & CON_AXIS2)) {
+    zero_v3(r_pmtx[2]);
+  }
+
+  float mat[3][3];
+  mul_m3_m3m3(mat, r_pmtx, t->spacemtx_inv);
+  mul_m3_m3m3(r_pmtx, t->spacemtx, mat);
+}
+
 /* ************************** CONSTRAINTS ************************* */
 static void constraintValuesFinal(TransInfo *t, float vec[3])
 {
@@ -123,7 +145,7 @@ void constraintNumInput(TransInfo *t, float vec[3])
 
 static void postConstraintChecks(TransInfo *t, float vec[3])
 {
-  mul_m3_v3(t->con.imtx, vec);
+  mul_m3_v3(t->spacemtx_inv, vec);
 
   snapGridIncrement(t, vec);
 
@@ -153,7 +175,7 @@ static void postConstraintChecks(TransInfo *t, float vec[3])
     /* inverse transformation at the end */
   }
 
-  mul_m3_v3(t->con.mtx, vec);
+  mul_m3_v3(t->spacemtx, vec);
 }
 
 static void viewAxisCorrectCenter(const TransInfo *t, float t_con_center[3])
@@ -286,7 +308,7 @@ static bool isPlaneProjectionViewAligned(const TransInfo *t)
   int n = 0;
   for (int i = 0; i < 3; i++) {
     if (t->con.mode & (CON_AXIS0 << i)) {
-      constraint_vector[n++] = t->con.mtx[i];
+      constraint_vector[n++] = t->spacemtx[i];
       if (n == 2) {
         break;
       }
@@ -326,6 +348,39 @@ static void planeProjection(const TransInfo *t, const float in[3], float out[3])
   add_v3_v3v3(out, in, vec);
 }
 
+static void applyAxisConstraintVec_impl(
+    TransInfo *t, float space_mat[3][3], float proj_mat[3][3], const float in[3], float out[3])
+{
+  mul_m3_v3(proj_mat, out);
+
+  // With snap, a projection is alright, no need to correct for view alignment
+  if (!validSnap(t)) {
+    const int dims = getConstraintSpaceDimension(t);
+    if (dims == 2) {
+      if (!is_zero_v3(out)) {
+        if (!isPlaneProjectionViewAligned(t)) {
+          planeProjection(t, in, out);
+        }
+      }
+    }
+    else if (dims == 1) {
+      float c[3];
+
+      if (t->con.mode & CON_AXIS0) {
+        copy_v3_v3(c, space_mat[0]);
+      }
+      else if (t->con.mode & CON_AXIS1) {
+        copy_v3_v3(c, space_mat[1]);
+      }
+      else if (t->con.mode & CON_AXIS2) {
+        copy_v3_v3(c, space_mat[2]);
+      }
+      axisProjection(t, c, in, out);
+    }
+  }
+  postConstraintChecks(t, out);
+}
+
 /*
  * Generic callback for constant spatial constraints applied to linear motion
  *
@@ -339,41 +394,14 @@ static void applyAxisConstraintVec(
 {
   copy_v3_v3(out, in);
   if (!td && t->con.mode & CON_APPLY) {
-    mul_m3_v3(t->con.pmtx, out);
-
-    // With snap, a projection is alright, no need to correct for view alignment
-    if (!validSnap(t)) {
-      const int dims = getConstraintSpaceDimension

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list