Commit: 82eecc6c0022426f8354ad38e1e42ad03e5004db
Author: Campbell Barton
Date:   Tue Nov 20 15:29:08 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB82eecc6c0022426f8354ad38e1e42ad03e5004db

Multi-Objects: Calc origin w/ all edit-objects

D3924 by @Leon95 w/ code de-duplication.

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

M       source/blender/editors/transform/transform_gizmo_3d.c

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

diff --git a/source/blender/editors/transform/transform_gizmo_3d.c 
b/source/blender/editors/transform/transform_gizmo_3d.c
index bf5500903a2..97f4018731b 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -461,6 +461,18 @@ static void calc_tw_center(struct TransformBounds 
*tbounds, const float co[3])
        }
 }
 
+static void calc_tw_center_with_matrix(
+        struct TransformBounds *tbounds, const float co[3],
+        const bool use_matrix, const float matrix[4][4])
+{
+       float co_world[3];
+       if (use_matrix) {
+               mul_v3_m4v3(co_world, matrix, co);
+               co = co_world;
+       }
+       calc_tw_center(tbounds, co);
+}
+
 static void protectflag_to_drawflags(short protectflag, short *drawflags)
 {
        if (protectflag & OB_LOCK_LOCX)
@@ -761,10 +773,9 @@ int ED_transform_calc_gizmo_stats(
 
        if (is_gp_edit) {
                float diff_mat[4][4];
-               float fpt[3];
-
                for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
                        /* only editable and visible layers are considered */
+                       const bool use_mat_local = gpl->parent != NULL;
                        if (gpencil_layer_is_editable(gpl) && (gpl->actframe != 
NULL)) {
 
                                /* calculate difference matrix */
@@ -784,15 +795,8 @@ int ED_transform_calc_gizmo_stats(
                                                /* Change selection status of 
all points, then make the stroke match */
                                                for (i = 0, pt = gps->points; i 
< gps->totpoints; i++, pt++) {
                                                        if (pt->flag & 
GP_SPOINT_SELECT) {
-                                                               if (gpl->parent 
== NULL) {
-                                                                       
calc_tw_center(tbounds, &pt->x);
-                                                                       
totsel++;
-                                                               }
-                                                               else {
-                                                                       
mul_v3_m4v3(fpt, diff_mat, &pt->x);
-                                                                       
calc_tw_center(tbounds, fpt);
-                                                                       
totsel++;
-                                                               }
+                                                               
calc_tw_center_with_matrix(tbounds, &pt->x, use_mat_local, diff_mat);
+                                                               totsel++;
                                                        }
                                                }
                                        }
@@ -807,6 +811,21 @@ int ED_transform_calc_gizmo_stats(
                }
        }
        else if (obedit) {
+
+#define FOREACH_EDIT_OBJECT_BEGIN(ob_iter, use_mat_local) \
+               { \
+                       invert_m4_m4(obedit->imat, obedit->obmat); \
+                       uint objects_len = 0; \
+                       Object **objects = 
BKE_view_layer_array_from_objects_in_edit_mode(view_layer, &objects_len); \
+                       for (uint ob_index = 0; ob_index < objects_len; 
ob_index++) { \
+                               Object *ob_iter = objects[ob_index]; \
+                               const bool use_mat_local = (ob_iter != obedit);
+
+#define FOREACH_EDIT_OBJECT_END() \
+                       } \
+                       MEM_freeN(objects); \
+               } ((void)0)
+
                ob = obedit;
                if (obedit->type == OB_MESH) {
                        BMEditMesh *em = BKE_editmesh_from_object(obedit);
@@ -820,14 +839,7 @@ int ED_transform_calc_gizmo_stats(
                                totsel = 1;
                        }
                        else {
-                               uint objects_len = 0;
-                               Object **objects = 
BKE_view_layer_array_from_objects_in_edit_mode(view_layer, &objects_len);
-
-                               float mat_local[4][4];
-                               invert_m4_m4(obedit->imat, obedit->obmat);
-
-                               for (uint ob_index = 0; ob_index < objects_len; 
ob_index++) {
-                                       Object *ob_iter = objects[ob_index];
+                               FOREACH_EDIT_OBJECT_BEGIN(ob_iter, 
use_mat_local) {
                                        BMEditMesh *em_iter = 
BKE_editmesh_from_object(ob_iter);
                                        BMesh *bm = em_iter->bm;
 
@@ -838,7 +850,7 @@ int ED_transform_calc_gizmo_stats(
                                        BMVert *eve;
                                        BMIter iter;
 
-                                       const bool use_mat_local = (ob_iter != 
obedit);
+                                       float mat_local[4][4];
                                        if (use_mat_local) {
                                                mul_m4_m4m4(mat_local, 
obedit->imat, ob_iter->obmat);
                                        }
@@ -846,20 +858,12 @@ int ED_transform_calc_gizmo_stats(
                                        BM_ITER_MESH (eve, &iter, bm, 
BM_VERTS_OF_MESH) {
                                                if (!BM_elem_flag_test(eve, 
BM_ELEM_HIDDEN)) {
                                                        if 
(BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-                                                               float co[3];
-                                                               if 
(use_mat_local) {
-                                                                       
mul_v3_m4v3(co, mat_local, eve->co);
-                                                               }
-                                                               else {
-                                                                       
copy_v3_v3(co, eve->co);
-                                                               }
-                                                               
calc_tw_center(tbounds, co);
+                                                               
calc_tw_center_with_matrix(tbounds, eve->co, use_mat_local, mat_local);
                                                                totsel++;
                                                        }
                                                }
                                        }
-                               }
-                               MEM_freeN(objects);
+                               } FOREACH_EDIT_OBJECT_END();
                        }
                } /* end editmesh */
                else if (obedit->type == OB_ARMATURE) {
@@ -881,28 +885,35 @@ int ED_transform_calc_gizmo_stats(
                                protectflag_to_drawflags_ebone(rv3d, ebo);
                        }
                        else {
-                               /* TODO: multi-object support. */
-                               for (ebo = arm->edbo->first; ebo; ebo = 
ebo->next) {
-                                       if (EBONE_VISIBLE(arm, ebo)) {
-                                               if (ebo->flag & BONE_TIPSEL) {
-                                                       calc_tw_center(tbounds, 
ebo->tail);
-                                                       totsel++;
-                                               }
-                                               if ((ebo->flag & BONE_ROOTSEL) 
&&
-                                                   /* don't include same point 
multiple times */
-                                                   ((ebo->flag & 
BONE_CONNECTED) &&
-                                                    (ebo->parent != NULL) &&
-                                                    (ebo->parent->flag & 
BONE_TIPSEL) &&
-                                                    EBONE_VISIBLE(arm, 
ebo->parent)) == 0)
-                                               {
-                                                       calc_tw_center(tbounds, 
ebo->head);
-                                                       totsel++;
-                                               }
-                                               if (ebo->flag & BONE_SELECTED) {
-                                                       
protectflag_to_drawflags_ebone(rv3d, ebo);
+                               FOREACH_EDIT_OBJECT_BEGIN(ob_iter, 
use_mat_local) {
+                                       arm = ob_iter->data;
+
+                                       float mat_local[4][4];
+                                       if (use_mat_local) {
+                                               mul_m4_m4m4(mat_local, 
obedit->imat, ob_iter->obmat);
+                                       }
+                                       for (ebo = arm->edbo->first; ebo; ebo = 
ebo->next) {
+                                               if (EBONE_VISIBLE(arm, ebo)) {
+                                                       if (ebo->flag & 
BONE_TIPSEL) {
+                                                               
calc_tw_center_with_matrix(tbounds, ebo->tail, use_mat_local, mat_local);
+                                                               totsel++;
+                                                       }
+                                                       if ((ebo->flag & 
BONE_ROOTSEL) &&
+                                                               /* don't 
include same point multiple times */
+                                                               ((ebo->flag & 
BONE_CONNECTED) &&
+                                                                (ebo->parent 
!= NULL) &&
+                                                                
(ebo->parent->flag & BONE_TIPSEL) &&
+                                                                
EBONE_VISIBLE(arm, ebo->parent)) == 0)
+                                                       {
+                                                               
calc_tw_center_with_matrix(tbounds, ebo->head, use_mat_local, mat_local);
+                                                               totsel++;
+                                                       }
+                                                       if (ebo->flag & 
BONE_SELECTED) {
+                                                               
protectflag_to_drawflags_ebone(rv3d, ebo);
+                                                       }
                                                }
                                        }
-                               }
+                               } FOREACH_EDIT_OBJECT_END();
                        }
                }
                else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
@@ -914,60 +925,67 @@ int ED_transform_calc_gizmo_stats(
                                totsel++;
                        }
                        else {
-                               /* TODO: multi-object support. */
-                               Nurb *nu;
-                               BezTriple *bezt;
-                               BPoint *bp;
-                               ListBase *nurbs = BKE_curve_editNurbs_get(cu);
-
-                               nu = nurbs->first;
-                               while (nu) {
-                                       if (nu->type == CU_BEZIER) {
-                                               bezt = nu->bezt;
-                                               a = nu->pntsu;
-                                               while (a--) {
-                                                       /* exceptions
-                                                        * if handles are 
hidden then only check the center points.
-                                                        * If the center knot 
is selected then only use this as the center point.
-                                                        */
-                                                       if 
((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_CU_HANDLES) == 0) {
-                                                               if (bezt->f2 & 
SELECT) {
-                                                                       
calc_tw_center(tbounds, bezt->vec[1]);
-                                                                       
totsel++;
+                               FOREACH_EDIT_OBJECT_BEGIN(ob_iter, 
use_mat_local) {
+                                       cu = ob_iter->data;
+                                       Nurb *nu;
+                                       BezTriple *bezt;
+                                       BPoint *bp;
+                                       ListBase *nurbs = 
BKE_curve_editNurbs_get(cu);
+
+                                       float mat_local[4][4];
+                                       if (use_mat_local) {
+                                               mul_m4_m4m4(mat_local, 
obedit->imat, ob_iter->obmat);
+                                       }
+
+                                       nu = nurbs->first;
+                                       while (nu) {
+                                               if (nu->type == CU_BEZIER) {
+                                                       bezt = nu->bezt;
+                                                       a = nu->pntsu;
+                                                       while (a--) {
+                                                               /* exceptions
+                                                                * if handles 
are hidden then only check the center points.
+                                                                * If the 
center knot is selected then only use this as the center point.
+                                                                */
+                                                               if 
((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_CU_HANDLES) == 0) {
+                                                                       if 
(bezt->f2 & SELECT) {
+                                                                               
calc_tw_center_with_matrix(tbounds, bezt->vec[1], use_mat_local, mat_local);
+                                                                               
totsel++;
+                                                                       }
                                                                }
-                                                       }
-                                                       else if (bezt->f2 & 
SELECT) {
-                                                               
calc_tw_center(tbounds, bezt->vec[1]);
-                                                               totsel++;
-                                                       }
-                                                       else {
-                                                               if (bezt->f1 & 
SELECT) {
-                                                                       
calc_tw_center(
-                                                                               
tbounds, bezt->vec[(pivot_point == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 0]);
+                                                               else if 
(bezt->f2 & SELECT) {
+                                                                       
calc_tw_center_with_matrix(tbounds, bezt->vec[1], use_mat_local, mat_local);
                                                                        
totsel++;
                                                                }
-                                                               if (bezt->f3 & 
SELECT) {
-                                                                       
calc_tw_center(
-                                                                               
tbounds, bezt->vec[(pivot_point == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 2]);
-                                                                       
totsel++;
+                                                               else {
+                                                                       if 
(bezt->f1 & SELECT) {
+                                                                               
const float *co = bezt->vec[(pivot_point == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 0];
+                                                                               
calc_tw_center_with_matrix(tbounds, co, use_mat_local, mat_local);
+                                                                               
totsel++;
+                                                                       }
+                                                                       if 
(bezt->f3 & SELECT) {
+                                                                               
const float *co = bezt->vec[(pivot_point == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 2];
+                                                                               
calc_tw_center_with_matrix(tbounds, co, use_mat_local, mat_local);
+                                                                               
totsel++;
+                                                                       }
                                                                }
+                                                               bezt++;
                                                        }
-                                                       bezt++;
                                                }
-                                       }
-                                       else {
-                                               bp = nu->bp;
-                                               a = nu->pntsu * nu->pntsv;
-                                               while (a--) {
-                                                       if (bp->f1 & SELECT) {
-                                                               
calc_tw_center(tbounds, bp->vec);
-                                                               totsel++;
+                                               else {
+                                                       bp = nu->bp;
+                                                       a = nu->pntsu * 
nu->pntsv;
+                                                       while (a--) {
+                                                               if (bp->f1 & 
SELECT) {
+                                                                       
calc_tw_center_with_matrix(tbounds, bp->vec, use_mat_local, mat_local);
+                                                                       
totsel++;
+                                                               }
+                                                               bp++;
                                                        }
-                                                       bp++;
                                                }
+                                               nu = nu->next;
                                        }
-                                       nu = nu->next;
-                               }
+                               } FOREACH_EDIT_OBJECT_END();
                        }
                }
                else if (obedit->type == OB_MBALL) {
@@ -979,13 +997,21 @@ int ED_transform_calc_gizmo_stats(
                                totsel++;
                        }
                        else {
-                               /* TODO: multi-object support. */
-                               for (ml = mb->editelems->first; ml; ml = 
ml->next) {
-                                       if (ml->flag & SELECT) {
-                                               calc_tw_center(tbounds, &ml->x);
-                                               totsel++;
+                               FOREACH_EDIT_OBJECT_BEGIN(ob_iter, 
use_mat_local) {
+                                       mb = (MetaBall *)ob_iter->data;
+
+                                       float mat_local[4][4];
+                                       if (use_mat_local) {
+                                               mul_m4_m4m4(mat_local, 
obedit->imat, ob_iter->obmat);
                                        }
-                               }
+
+                                       for (ml = mb->editelems->first; ml; ml 
= ml->next) {
+                                               if (ml->flag & SELECT) {
+                                                       
calc_tw_center_with_matrix(tbounds, &ml->x, use_mat_local, mat_local);
+                                                       totsel++;
+                                               }
+                                       }
+                               } FOREACH_EDIT_OBJECT_END();
                        }
                }
                else if (obedit->type == OB_LATTICE) {
@@ -997,19 +1023,30 @@ int ED_transform_calc_gizmo_stats(
                                totsel++

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to