[Bf-blender-cvs] [309cfbceaa5] master: Transform: default to median center instead of bounds

Campbell Barton noreply at git.blender.org
Tue Jun 23 10:36:35 CEST 2020


Commit: 309cfbceaa590828b61bfd72f12ef976f9808392
Author: Campbell Barton
Date:   Tue Jun 23 18:31:10 2020 +1000
Branches: master
https://developer.blender.org/rB309cfbceaa590828b61bfd72f12ef976f9808392

Transform: default to median center instead of bounds

When neither bounds or median is selected, snapping the cursor to
the selection was using bounds which often doesn't give useful results.

Resolves T78135

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

M	source/blender/editors/armature/armature_edit.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/object/object_transform.c
M	source/blender/editors/space_view3d/view3d_snap.c

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

diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c
index a7a705a6202..a010fbd5e81 100644
--- a/source/blender/editors/armature/armature_edit.c
+++ b/source/blender/editors/armature/armature_edit.c
@@ -140,7 +140,16 @@ void ED_armature_origin_set(
     mul_m4_v3(ob->imat, cent);
   }
   else {
-    if (around == V3D_AROUND_CENTER_MEDIAN) {
+    if (around == V3D_AROUND_CENTER_BOUNDS) {
+      float min[3], max[3];
+      INIT_MINMAX(min, max);
+      for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+        minmax_v3v3_v3(min, max, ebone->head);
+        minmax_v3v3_v3(min, max, ebone->tail);
+      }
+      mid_v3_v3v3(cent, min, max);
+    }
+    else { /* #V3D_AROUND_CENTER_MEDIAN. */
       int total = 0;
       zero_v3(cent);
       for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
@@ -152,15 +161,6 @@ void ED_armature_origin_set(
         mul_v3_fl(cent, 1.0f / (float)total);
       }
     }
-    else {
-      float min[3], max[3];
-      INIT_MINMAX(min, max);
-      for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
-        minmax_v3v3_v3(min, max, ebone->head);
-        minmax_v3v3_v3(min, max, ebone->tail);
-      }
-      mid_v3_v3v3(cent, min, max);
-    }
   }
 
   /* Do the adjustments */
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 18ffffb3782..54782ba683d 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2956,13 +2956,16 @@ static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op))
     }
   }
 
-  if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEDIAN && count) {
-    mul_v3_fl(centroid, 1.0f / (float)count);
-    copy_v3_v3(cursor, centroid);
-  }
-  else {
+  if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_BOUNDS) {
     mid_v3_v3v3(cursor, min, max);
   }
+  else { /* #V3D_AROUND_CENTER_MEDIAN. */
+    zero_v3(cursor);
+    if (count) {
+      mul_v3_fl(centroid, 1.0f / (float)count);
+      copy_v3_v3(cursor, centroid);
+    }
+  }
 
   DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
   WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index 132b530455e..161611d59c9 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -1098,15 +1098,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
         mul_m4_v3(obedit->imat, cent);
       }
       else {
-        if (around == V3D_AROUND_CENTER_MEDIAN) {
-          if (em->bm->totvert) {
-            const float total_div = 1.0f / (float)em->bm->totvert;
-            BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
-              madd_v3_v3fl(cent, eve->co, total_div);
-            }
-          }
-        }
-        else {
+        if (around == V3D_AROUND_CENTER_BOUNDS) {
           float min[3], max[3];
           INIT_MINMAX(min, max);
           BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
@@ -1114,6 +1106,14 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
           }
           mid_v3_v3v3(cent, min, max);
         }
+        else { /* #V3D_AROUND_CENTER_MEDIAN. */
+          if (em->bm->totvert) {
+            const float total_div = 1.0f / (float)em->bm->totvert;
+            BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
+              madd_v3_v3fl(cent, eve->co, total_div);
+            }
+          }
+        }
       }
 
       BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
@@ -1211,12 +1211,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
         else if (centermode == ORIGIN_TO_CENTER_OF_MASS_VOLUME) {
           BKE_mesh_center_of_volume(me, cent);
         }
-        else if (around == V3D_AROUND_CENTER_MEDIAN) {
-          BKE_mesh_center_median(me, cent);
-        }
-        else {
+        else if (around == V3D_AROUND_CENTER_BOUNDS) {
           BKE_mesh_center_bounds(me, cent);
         }
+        else { /* #V3D_AROUND_CENTER_MEDIAN. */
+          BKE_mesh_center_median(me, cent);
+        }
 
         negate_v3_v3(cent_neg, cent);
         BKE_mesh_translate(me, cent_neg, 1);
@@ -1231,12 +1231,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
         if (centermode == ORIGIN_TO_CURSOR) {
           /* done */
         }
-        else if (around == V3D_AROUND_CENTER_MEDIAN) {
-          BKE_curve_center_median(cu, cent);
-        }
-        else {
+        else if (around == V3D_AROUND_CENTER_BOUNDS) {
           BKE_curve_center_bounds(cu, cent);
         }
+        else { /* #V3D_AROUND_CENTER_MEDIAN. */
+          BKE_curve_center_median(cu, cent);
+        }
 
         /* don't allow Z change if curve is 2D */
         if ((ob->type == OB_CURVE) && !(cu->flag & CU_3D)) {
@@ -1324,12 +1324,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
         if (centermode == ORIGIN_TO_CURSOR) {
           /* done */
         }
-        else if (around == V3D_AROUND_CENTER_MEDIAN) {
-          BKE_mball_center_median(mb, cent);
-        }
-        else {
+        else if (around == V3D_AROUND_CENTER_BOUNDS) {
           BKE_mball_center_bounds(mb, cent);
         }
+        else { /* #V3D_AROUND_CENTER_MEDIAN. */
+          BKE_mball_center_median(mb, cent);
+        }
 
         negate_v3_v3(cent_neg, cent);
         BKE_mball_translate(mb, cent_neg);
@@ -1351,12 +1351,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
         if (centermode == ORIGIN_TO_CURSOR) {
           /* done */
         }
-        else if (around == V3D_AROUND_CENTER_MEDIAN) {
-          BKE_lattice_center_median(lt, cent);
-        }
-        else {
+        else if (around == V3D_AROUND_CENTER_BOUNDS) {
           BKE_lattice_center_bounds(lt, cent);
         }
+        else { /* #V3D_AROUND_CENTER_MEDIAN. */
+          BKE_lattice_center_median(lt, cent);
+        }
 
         negate_v3_v3(cent_neg, cent);
         BKE_lattice_translate(lt, cent_neg, 1);
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c
index 437c0dd4035..91b2971585d 100644
--- a/source/blender/editors/space_view3d/view3d_snap.c
+++ b/source/blender/editors/space_view3d/view3d_snap.c
@@ -850,12 +850,12 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3])
     return false;
   }
 
-  if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEDIAN) {
-    mul_v3_fl(centroid, 1.0f / (float)count);
-    copy_v3_v3(cursor, centroid);
+  if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_BOUNDS) {
+    mid_v3_v3v3(cursor, min, max);
   }
   else {
-    mid_v3_v3v3(cursor, min, max);
+    mul_v3_fl(centroid, 1.0f / (float)count);
+    copy_v3_v3(cursor, centroid);
   }
   return true;
 }



More information about the Bf-blender-cvs mailing list