[Bf-blender-cvs] [6ec463a4b75] master: Cleanup/Refactor: Transform Orientation: Use 'orient_index' instead 'orient_type'

Germano Cavalcante noreply at git.blender.org
Thu Apr 1 16:25:34 CEST 2021


Commit: 6ec463a4b754bf69baf94ba6b3683655f6834ccd
Author: Germano Cavalcante
Date:   Thu Apr 1 11:19:31 2021 -0300
Branches: master
https://developer.blender.org/rB6ec463a4b754bf69baf94ba6b3683655f6834ccd

Cleanup/Refactor: Transform Orientation: Use 'orient_index' instead 'orient_type'

`orient_index` is a more comprehensive value as it reveals both the type and index.

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

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

M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/intern/scene.c
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/editors/transform/transform_gizmo_extrude_3d.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/editors/transform/transform_orientations.h

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

diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index b2726885593..66edb00e83c 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -140,6 +140,8 @@ struct TransformOrientationSlot *BKE_scene_orientation_slot_get(struct Scene *sc
 void BKE_scene_orientation_slot_set_index(struct TransformOrientationSlot *orient_slot,
                                           int orientation);
 int BKE_scene_orientation_slot_get_index(const struct TransformOrientationSlot *orient_slot);
+int BKE_scene_orientation_get_index(struct Scene *scene, int slot_index);
+int BKE_scene_orientation_get_index_from_flag(struct Scene *scene, int flag);
 
 /* **  Scene evaluation ** */
 
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index de3e1023b08..e0ff0b0268a 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -2517,6 +2517,18 @@ int BKE_scene_orientation_slot_get_index(const TransformOrientationSlot *orient_
              orient_slot->type;
 }
 
+int BKE_scene_orientation_get_index(Scene *scene, int slot_index)
+{
+  TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, slot_index);
+  return BKE_scene_orientation_slot_get_index(orient_slot);
+}
+
+int BKE_scene_orientation_get_index_from_flag(Scene *scene, int flag)
+{
+  TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get_from_flag(scene, flag);
+  return BKE_scene_orientation_slot_get_index(orient_slot);
+}
+
 /** \} */
 
 static bool check_rendered_viewport_visible(Main *bmain)
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 8f1be847e2b..cb6fb0dba60 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -151,8 +151,7 @@ short ED_transform_calc_orientation_from_type_ex(const struct bContext *C,
                                                  struct RegionView3D *rv3d,
                                                  struct Object *ob,
                                                  struct Object *obedit,
-                                                 const short orientation_type,
-                                                 int orientation_index_custom,
+                                                 const short orientation_index,
                                                  const int pivot_point);
 
 /* transform gizmos */
@@ -186,8 +185,7 @@ struct TransformCalcParams {
   uint use_only_center : 1;
   uint use_local_axis : 1;
   /* Use 'Scene.orientation_type' when zero, otherwise subtract one and use. */
-  ushort orientation_type;
-  ushort orientation_index_custom;
+  ushort orientation_index;
 };
 int ED_transform_calc_gizmo_stats(const struct bContext *C,
                                   const struct TransformCalcParams *params,
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c
index 3f258a0699a..ad91af73a71 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c
@@ -143,7 +143,7 @@ static void WIDGETGROUP_tool_generic_refresh(const bContext *C, wmGizmoGroup *gz
     const bool hide = ED_transform_calc_gizmo_stats(C,
                                                     &(struct TransformCalcParams){
                                                         .use_only_center = true,
-                                                        .orientation_type = orientation + 1,
+                                                        .orientation_index = orientation + 1,
                                                     },
                                                     &tbounds) == 0;
 
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c
index 27df29afd8d..7a780df0def 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -512,11 +512,11 @@ static void protectflag_to_drawflags(short protectflag, short *drawflags)
 /* for pose mode */
 static void protectflag_to_drawflags_pchan(RegionView3D *rv3d,
                                            const bPoseChannel *pchan,
-                                           short orientation_type)
+                                           short orientation_index)
 {
   /* Protect-flags apply to local space in pose mode, so only let them influence axis
    * visibility if we show the global orientation, otherwise it's confusing. */
-  if (orientation_type == V3D_ORIENT_LOCAL) {
+  if (orientation_index == V3D_ORIENT_LOCAL) {
     protectflag_to_drawflags(pchan->protectflag, &rv3d->twdrawflag);
   }
 }
@@ -657,12 +657,9 @@ int ED_transform_calc_gizmo_stats(const bContext *C,
   int a, totsel = 0;
 
   const int pivot_point = scene->toolsettings->transform_pivot_point;
-  const short orientation_type = params->orientation_type ?
-                                     (params->orientation_type - 1) :
-                                     scene->orientation_slots[SCE_ORIENT_DEFAULT].type;
-  const short orientation_index_custom =
-      params->orientation_type ? params->orientation_index_custom :
-                                 scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom;
+  const short orient_index = params->orientation_index ?
+                                 (params->orientation_index - 1) :
+                                 BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT);
 
   /* transform widget matrix */
   unit_m4(rv3d->twmat);
@@ -678,7 +675,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, orientation_type, orientation_index_custom, pivot_point);
+        C, mat, scene, rv3d, ob, obedit, orient_index, pivot_point);
     copy_m4_m3(rv3d->twmat, mat);
   }
 
@@ -976,7 +973,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C,
           Bone *bone = pchan->bone;
           if (bone && (bone->flag & BONE_TRANSFORM)) {
             calc_tw_center_with_matrix(tbounds, pchan->pose_head, use_mat_local, mat_local);
-            protectflag_to_drawflags_pchan(rv3d, pchan, orientation_type);
+            protectflag_to_drawflags_pchan(rv3d, pchan, orient_index);
           }
         }
         totsel += totsel_iter;
@@ -1063,7 +1060,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C,
 
       /* Protect-flags apply to world space in object mode, so only let them influence axis
        * visibility if we show the global orientation, otherwise it's confusing. */
-      if (orientation_type == V3D_ORIENT_GLOBAL) {
+      if (orient_index == V3D_ORIENT_GLOBAL) {
         protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag);
       }
       totsel++;
@@ -1689,18 +1686,15 @@ static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup)
     }
   }
 
-  const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get_from_flag(
-      scene, ggd->twtype_init);
+  const int orient_index = BKE_scene_orientation_get_index_from_flag(scene, ggd->twtype_init);
 
   /* skip, we don't draw anything anyway */
-  if ((ggd->all_hidden = (ED_transform_calc_gizmo_stats(
-                              C,
-                              &(struct TransformCalcParams){
-                                  .use_only_center = true,
-                                  .orientation_type = orient_slot->type + 1,
-                                  .orientation_index_custom = orient_slot->index_custom,
-                              },
-                              &tbounds) == 0))) {
+  if ((ggd->all_hidden = (ED_transform_calc_gizmo_stats(C,
+                                                        &(struct TransformCalcParams){
+                                                            .use_only_center = true,
+                                                            .orientation_index = orient_index + 1,
+                                                        },
+                                                        &tbounds) == 0))) {
     return;
   }
 
@@ -2119,14 +2113,12 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmGizmoGroup *gzgr
     gzgroup->use_fallback_keymap = false;
   }
 
-  const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene,
-                                                                               SCE_ORIENT_SCALE);
+  const int orient_index = BKE_scene_orientation_get_index_from_flag(scene, SCE_ORIENT_SCALE);
 
   if ((ED_transform_calc_gizmo_stats(C,
                                      &(struct TransformCalcParams){
                                          .use_local_axis = true,
-                                         .orientation_type = orient_slot->type + 1,
-                                         .orientation_index_custom = orient_slot->index_custom,
+                                         .orientation_index = orient_index + 1,
                                      },
                                      &tbounds) == 0) ||
       equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max)) {
@@ -2335,14 +2327,14 @@ static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzg
   /* Needed to test view orientation changes. */
   copy_m3_m4(xgzgroup->prev.viewinv_m3, rv3d->viewinv);
 
-  const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene,
-                                                                               SCE_ORIENT_ROTATE);
+  TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get_from_flag(
+      scene, SCE_ORIENT_ROTATE);
+  const int orient_index = BKE_scene_orientation_slot_get_index(orient_slot);
 
   if (ED_transform_calc_gizmo_stats(C,
                                     &(struct TransformCalcParams){
                     

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list