[Bf-blender-cvs] [fa4f9292e16] master: Transform: avoid passing the context to extended orientation functions

Campbell Barton noreply at git.blender.org
Tue Aug 31 09:14:01 CEST 2021


Commit: fa4f9292e16ce6a9253164ea731870c6d0161848
Author: Campbell Barton
Date:   Tue Aug 31 16:29:59 2021 +1000
Branches: master
https://developer.blender.org/rBfa4f9292e16ce6a9253164ea731870c6d0161848

Transform: avoid passing the context to extended orientation functions

This makes it possible to calculate orientation from functions
that don't have the context.

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

M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/mesh/editmesh_select.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/editors/transform/transform_mode.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/editors/transform/transform_orientations.h

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

diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 69ac48d842f..bedd0e2fa35 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -109,7 +109,8 @@ bool BIF_createTransformOrientation(struct bContext *C,
                                     const bool overwrite);
 void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *target);
 
-void ED_getTransformOrientationMatrix(const struct bContext *C,
+void ED_getTransformOrientationMatrix(struct ViewLayer *view_layer,
+                                      const struct View3D *v3d,
                                       struct Object *ob,
                                       struct Object *obedit,
                                       const short around,
@@ -145,15 +146,15 @@ void Transform_Properties(struct wmOperatorType *ot, int flags);
 
 /* *** transform_orientations.c *** */
 void ED_transform_calc_orientation_from_type(const struct bContext *C, float r_mat[3][3]);
-short ED_transform_calc_orientation_from_type_ex(const struct bContext *C,
-                                                 float r_mat[3][3],
-                                                 /* extra args */
-                                                 struct Scene *scene,
-                                                 struct RegionView3D *rv3d,
+short ED_transform_calc_orientation_from_type_ex(const struct Scene *scene,
+                                                 struct ViewLayer *view_layer,
+                                                 const struct View3D *v3d,
+                                                 const struct RegionView3D *rv3d,
                                                  struct Object *ob,
                                                  struct Object *obedit,
                                                  const short orientation_index,
-                                                 const int pivot_point);
+                                                 const int pivot_point,
+                                                 float r_mat[3][3]);
 
 /* transform gizmos */
 
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 8e38d41f971..2fcf8fa6f8f 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -4871,8 +4871,15 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op)
   float axis_mat[3][3];
 
   /* 3D view variables may be NULL, (no need to check in poll function). */
-  ED_transform_calc_orientation_from_type_ex(
-      C, axis_mat, scene, CTX_wm_region_view3d(C), obedit, obedit, orientation, V3D_AROUND_ACTIVE);
+  ED_transform_calc_orientation_from_type_ex(scene,
+                                             view_layer,
+                                             CTX_wm_view3d(C),
+                                             CTX_wm_region_view3d(C),
+                                             obedit,
+                                             obedit,
+                                             orientation,
+                                             V3D_AROUND_ACTIVE,
+                                             axis_mat);
 
   const float *axis_vector = axis_mat[axis];
 
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 466820353b9..8ed134c7fd1 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -3961,9 +3961,10 @@ static int view_axis_exec(bContext *C, wmOperator *op)
     Object *obact = CTX_data_active_object(C);
     if (obact != NULL) {
       float twmat[3][3];
+      ViewLayer *view_layer = CTX_data_view_layer(C);
       Object *obedit = CTX_data_edit_object(C);
       /* same as transform gizmo when normal is set */
-      ED_getTransformOrientationMatrix(C, obact, obedit, V3D_AROUND_ACTIVE, twmat);
+      ED_getTransformOrientationMatrix(view_layer, v3d, obact, obedit, V3D_AROUND_ACTIVE, twmat);
       align_quat = align_quat_buf;
       mat3_to_quat(align_quat, twmat);
       invert_qt_normalized(align_quat);
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c
index 279dca9731d..8dc4f107837 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -674,7 +674,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C,
   if (ob) {
     float mat[3][3];
     ED_transform_calc_orientation_from_type_ex(
-        C, mat, scene, rv3d, ob, obedit, orient_index, pivot_point);
+        scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, mat);
     copy_m4_m3(rv3d->twmat, mat);
   }
 
diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c
index 8df95222fa1..b9fb8a86752 100644
--- a/source/blender/editors/transform/transform_mode.c
+++ b/source/blender/editors/transform/transform_mode.c
@@ -1232,14 +1232,24 @@ void transform_mode_default_modal_orientation_set(TransInfo *t, int type)
     return;
   }
 
+  View3D *v3d = NULL;
   RegionView3D *rv3d = NULL;
   if ((type == V3D_ORIENT_VIEW) && (t->spacetype == SPACE_VIEW3D) && t->region &&
       (t->region->regiontype == RGN_TYPE_WINDOW)) {
+    v3d = t->view;
     rv3d = t->region->regiondata;
   }
 
   t->orient[O_DEFAULT].type = ED_transform_calc_orientation_from_type_ex(
-      NULL, t->orient[O_DEFAULT].matrix, NULL, rv3d, NULL, NULL, type, 0);
+      t->scene,
+      t->view_layer,
+      v3d,
+      rv3d,
+      NULL,
+      NULL,
+      type,
+      V3D_AROUND_CENTER_BOUNDS,
+      t->orient[O_DEFAULT].matrix);
 
   if (t->orient_curr == O_DEFAULT) {
     /* Update Orientation. */
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index 33f4b06eb0e..1e3acdf1071 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -490,13 +490,14 @@ void ED_transform_calc_orientation_from_type(const bContext *C, float r_mat[3][3
   Scene *scene = CTX_data_scene(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
   Object *obedit = CTX_data_edit_object(C);
+  View3D *v3d = CTX_wm_view3d(C);
   RegionView3D *rv3d = region->regiondata;
   Object *ob = OBACT(view_layer);
   const short orient_index = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT);
   const int pivot_point = scene->toolsettings->transform_pivot_point;
 
   ED_transform_calc_orientation_from_type_ex(
-      C, r_mat, scene, rv3d, ob, obedit, orient_index, pivot_point);
+      scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, r_mat);
 }
 
 /**
@@ -508,15 +509,15 @@ void ED_transform_calc_orientation_from_type(const bContext *C, float r_mat[3][3
  * - #V3D_ORIENT_LOCAL may contain shear from non-uniform scale in parent/child relationships.
  * - #V3D_ORIENT_CUSTOM may have been created from #V3D_ORIENT_LOCAL.
  */
-short ED_transform_calc_orientation_from_type_ex(const bContext *C,
-                                                 float r_mat[3][3],
-                                                 /* extra args (can be accessed from context) */
-                                                 Scene *scene,
-                                                 RegionView3D *rv3d,
+short ED_transform_calc_orientation_from_type_ex(const Scene *scene,
+                                                 ViewLayer *view_layer,
+                                                 const View3D *v3d,
+                                                 const RegionView3D *rv3d,
                                                  Object *ob,
                                                  Object *obedit,
                                                  const short orientation_index,
-                                                 const int pivot_point)
+                                                 const int pivot_point,
+                                                 float r_mat[3][3])
 {
   switch (orientation_index) {
     case V3D_ORIENT_GIMBAL: {
@@ -528,7 +529,7 @@ short ED_transform_calc_orientation_from_type_ex(const bContext *C,
     }
     case V3D_ORIENT_NORMAL: {
       if (obedit || (ob && ob->mode & OB_MODE_POSE)) {
-        ED_getTransformOrientationMatrix(C, ob, obedit, pivot_point, r_mat);
+        ED_getTransformOrientationMatrix(view_layer, v3d, ob, obedit, pivot_point, r_mat);
         break;
       }
       /* No break we define 'normal' as 'local' in Object mode. */
@@ -541,7 +542,7 @@ short ED_transform_calc_orientation_from_type_ex(const bContext *C,
            * use the active pones axis for display T33575, this works as expected on a single
            * bone and users who select many bones will understand what's going on and what local
            * means when they start transforming. */
-          ED_getTransformOrientationMatrix(C, ob, obedit, pivot_point, r_mat);
+          ED_getTransformOrientationMatrix(view_layer, v3d, ob, obedit, pivot_point, r_mat);
         }
         else {
           transform_orientations_create_from_axis(r_mat, UNPACK3(ob->obmat));
@@ -604,9 +605,11 @@ short transform_orientation_matrix_get(bContext *C,
   Object *ob = CTX_data_active_object(C);
   Object *obedit = CTX_data_edit_object(C);
   Scene *scene = t->scene;
+  View3D *v3d = NULL;
   RegionView3D *rv3d = NULL;
 
   if ((t->spacetype == SPACE_VIEW3D) && t->region && (t->region->regiontype == RGN_TYPE_WINDOW)) {
+    v3d = t->view;
     rv3d = t->region->regiondata;
 
     if (ob && (ob->mode & OB_MODE_ALL_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) {
@@ -619,15 +622,7 @@ short transform_orientation_matrix_get(bContext *C,
   }
 
   short r_orient_index = ED_transform_calc_orientation_from_type_ex(
-      C,
-      r_spacemtx,
-      /* extra args (can be accessed from context) */
-      scene,
-      rv3d,
-      ob,
-      obe

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list