Commit: f0083fc1d225298115c389c08e9c2f197cb3802e
Author: Campbell Barton
Date:   Tue Apr 10 08:10:59 2018 +0200
Branches: temp-object-multi-mode
https://developer.blender.org/rBf0083fc1d225298115c389c08e9c2f197cb3802e

TMP

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

M       source/blender/editors/transform/transform.c
M       source/blender/editors/transform/transform_generics.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 5d0db753977..2ed100eb57e 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -244,6 +244,7 @@ void setTransformViewMatrices(TransInfo *t)
                t->persp = RV3D_ORTHO;
        }
 
+       calculateCenterGlobal(t, t->center, t->center_global);
        calculateCenter2D(t);
 }
 
diff --git a/source/blender/editors/transform/transform_generics.c 
b/source/blender/editors/transform/transform_generics.c
index 59dbce2281f..a0933107c26 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1708,15 +1708,12 @@ void calculateCenter2D(TransInfo *t)
        BLI_assert(!is_zero_v3(t->aspect));
 
        if (t->flag & (T_EDIT | T_POSE)) {
-               FOREACH_THAND (t, th) {
-                       TransData *td = th->data;
-                       Object *ob = th->obedit ? th->obedit : t->poseobj;
-                       float vec[3];
+               Object *ob = THAND_FIRST_EVIL(t)->obedit ? 
THAND_FIRST_EVIL(t)->obedit : THAND_FIRST_EVIL(t)->poseobj;
+               float vec[3];
 
-                       copy_v3_v3(vec, t->center);
-                       mul_m4_v3(ob->obmat, vec);
-                       projectFloatView(t, vec, t->center2d);
-               }
+               copy_v3_v3(vec, t->center);
+               mul_m4_v3(ob->obmat, vec);
+               projectFloatView(t, vec, t->center2d);
        }
        else {
                projectFloatView(t, t->center, t->center2d);
@@ -1730,7 +1727,7 @@ void calculateCenterGlobal(
        /* setting constraint center */
        /* note, init functions may over-ride t->center */
        if (t->flag & (T_EDIT | T_POSE)) {
-               Object *ob = t->obedit ? t->obedit : t->poseobj;
+               Object *ob = THAND_FIRST_EVIL(t)->obedit ? 
THAND_FIRST_EVIL(t)->obedit : THAND_FIRST_EVIL(t)->poseobj;
                mul_v3_m4v3(r_center_global, ob->obmat, center_local);
        }
        else {
@@ -1747,7 +1744,7 @@ void calculateCenterCursor(TransInfo *t, float 
r_center[3])
        
        /* If edit or pose mode, move cursor in local space */
        if (t->flag & (T_EDIT | T_POSE)) {
-               Object *ob = t->obedit ? t->obedit : t->poseobj;
+               Object *ob = THAND_FIRST_EVIL(t)->obedit ? 
THAND_FIRST_EVIL(t)->obedit : THAND_FIRST_EVIL(t)->poseobj;
                float mat[3][3], imat[3][3];
                
                sub_v3_v3v3(r_center, r_center, ob->obmat[3]);
@@ -1831,10 +1828,10 @@ void calculateCenterMedian(TransInfo *t, float 
r_center[3])
        int total = 0;
        int i;
        
-       for (i = 0; i < t->total; i++) {
-               if (t->data[i].flag & TD_SELECTED) {
-                       if (!(t->data[i].flag & TD_NOCENTER)) {
-                               add_v3_v3(partial, t->data[i].center);
+       for (i = 0; i < THAND_FIRST_EVIL(t)->total; i++) {
+               if (THAND_FIRST_EVIL(t)->data[i].flag & TD_SELECTED) {
+                       if (!(THAND_FIRST_EVIL(t)->data[i].flag & TD_NOCENTER)) 
{
+                               add_v3_v3(partial, 
THAND_FIRST_EVIL(t)->data[i].center);
                                total++;
                        }
                }
@@ -1850,16 +1847,16 @@ void calculateCenterBound(TransInfo *t, float 
r_center[3])
        float max[3];
        float min[3];
        int i;
-       for (i = 0; i < t->total; i++) {
+       for (i = 0; i < THAND_FIRST_EVIL(t)->total; i++) {
                if (i) {
-                       if (t->data[i].flag & TD_SELECTED) {
-                               if (!(t->data[i].flag & TD_NOCENTER))
-                                       minmax_v3v3_v3(min, max, 
t->data[i].center);
+                       if (THAND_FIRST_EVIL(t)->data[i].flag & TD_SELECTED) {
+                               if (!(THAND_FIRST_EVIL(t)->data[i].flag & 
TD_NOCENTER))
+                                       minmax_v3v3_v3(min, max, 
THAND_FIRST_EVIL(t)->data[i].center);
                        }
                }
                else {
-                       copy_v3_v3(max, t->data[i].center);
-                       copy_v3_v3(min, t->data[i].center);
+                       copy_v3_v3(max, THAND_FIRST_EVIL(t)->data[i].center);
+                       copy_v3_v3(min, THAND_FIRST_EVIL(t)->data[i].center);
                }
        }
        mid_v3_v3v3(r_center, min, max);
@@ -1874,7 +1871,7 @@ bool calculateCenterActive(TransInfo *t, bool 
select_only, float r_center[3])
        TransHandle *th = &t->thand[0];
        bool ok = false;
 
-       if (t->obedit) {
+       if (th->obedit) {
                if (ED_object_editmode_calc_active_center(th->obedit, 
select_only, r_center)) {
                        ok = true;
                }
@@ -2037,7 +2034,7 @@ void calculatePropRatio(TransInfo *t)
                const char *pet_id = NULL;
                FOREACH_THAND (t, th) {
                TransData *td = th->data;
-               for (i = 0; i < t->total; i++, td++) {
+               for (i = 0; i < th->total; i++, td++) {
                        if (td->flag & TD_SELECTED) {
                                td->factor = 1.0f;
                        }
diff --git a/source/blender/editors/transform/transform_snap.c 
b/source/blender/editors/transform/transform_snap.c
index 0a44c4ab31a..501942a5cb0 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -275,7 +275,7 @@ void applyProject(TransInfo *t)
                float tvec[3];
                int i;
 
-               for (TransHandle *th = t->thand, *th_end = t->thand + 
t->thand_len; th != th_end; th++) {
+               FOREACH_THAND(t, th) {
                TransData *td = th->data;
 
                float imat[4][4];
@@ -370,7 +370,7 @@ void applyGridAbsolute(TransInfo *t)
        if (grid_size == 0.0f)
                return;
        
-       for (TransHandle *th = t->thand, *th_end = t->thand + t->thand_len; th 
!= th_end; th++) {
+       FOREACH_THAND(t, th) {
        TransData *td;
 
        if (t->flag & (T_EDIT | T_POSE)) {
@@ -993,7 +993,7 @@ static void CalcSnapGeometry(TransInfo *t, float 
*UNUSED(vec))
                
                UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], 
&co[0], &co[1]);
 
-               if (ED_uvedit_nearest_uv(t->scene, t->obedit, ima, co, 
t->tsnap.snapPoint)) {
+               if (ED_uvedit_nearest_uv(t->scene, THAND_FIRST_EVIL(t)->obedit, 
ima, co, t->tsnap.snapPoint)) {
                        t->tsnap.snapPoint[0] *= t->aspect[0];
                        t->tsnap.snapPoint[1] *= t->aspect[1];
 
@@ -1069,7 +1069,7 @@ static void TargetSnapActive(TransInfo *t)
        if ((t->tsnap.status & TARGET_INIT) == 0) {
                if (calculateCenterActive(t, true, t->tsnap.snapTarget)) {
                        if (t->flag & (T_EDIT | T_POSE)) {
-                               Object *ob = t->obedit ? t->obedit : t->poseobj;
+                               Object *ob = THAND_FIRST_EVIL(t)->obedit ? 
THAND_FIRST_EVIL(t)->obedit : THAND_FIRST_EVIL(t)->poseobj;
                                mul_m4_v3(ob->obmat, t->tsnap.snapTarget);
                        }
 
@@ -1090,23 +1090,34 @@ static void TargetSnapMedian(TransInfo *t)
 {
        // Only need to calculate once
        if ((t->tsnap.status & TARGET_INIT) == 0) {
-               TransData *td = NULL;
-               int i;
+               int i_accum = 0;
 
                t->tsnap.snapTarget[0] = 0;
                t->tsnap.snapTarget[1] = 0;
                t->tsnap.snapTarget[2] = 0;
-               
-               for (td = t->data, i = 0; i < t->total && td->flag & 
TD_SELECTED; i++, td++) {
-                       add_v3_v3(t->tsnap.snapTarget, td->center);
-               }
-               
-               mul_v3_fl(t->tsnap.snapTarget, 1.0 / i);
-               
-               if (t->flag & (T_EDIT | T_POSE)) {
-                       Object *ob = t->obedit ? t->obedit : t->poseobj;
-                       mul_m4_v3(ob->obmat, t->tsnap.snapTarget);
+
+               FOREACH_THAND (t, th) {
+                       Object *ob_xform = NULL;
+                       if (t->flag & (T_EDIT | T_POSE)) {
+                               ob_xform = th->obedit ? th->obedit : 
th->poseobj;
+                       }
+                       TransData *td = th->data;
+                       int i;
+                       for (i = 0; i < th->total && td->flag & TD_SELECTED; 
i++, td++) {
+                               /* TODO(campbell): perform the global 
transformation once per TransHandle */
+                               if (ob_xform) {
+                                       float v[3];
+                                       mul_v3_m4v3(v, ob_xform->obmat, 
td->center);
+                                       add_v3_v3(t->tsnap.snapTarget, v);
+                               }
+                               else {
+                                       add_v3_v3(t->tsnap.snapTarget, 
td->center);
+                               }
+                       }
+                       i_accum += i;
                }
+
+               mul_v3_fl(t->tsnap.snapTarget, 1.0 / i_accum);
                
                TargetSnapOffset(t, NULL);
                
@@ -1119,14 +1130,14 @@ static void TargetSnapClosest(TransInfo *t)
        // Only valid if a snap point has been selected
        if (t->tsnap.status & POINT_INIT) {
                float dist_closest = 0.0f;
-               TransData *closest = NULL, *td = NULL;
+               TransData *closest = NULL;
                
                /* Object mode */
                if (t->flag & T_OBJECT) {
                        int i;
-                       for (TransHandle *th = t->thand, *th_end = t->thand + 
t->thand_len; th != th_end; th++) {
+                       FOREACH_THAND(t, th) {
                        TransData *td = th->data;
-                       for (td = t->data, i = 0; i < t->total && td->flag & 
TD_SELECTED; i++, td++) {
+                       for (td = th->data, i = 0; i < th->total && td->flag & 
TD_SELECTED; i++, td++) {
                                struct BoundBox *bb = 
BKE_object_boundbox_get(td->ob);
                                
                                /* use boundbox if possible */
@@ -1171,15 +1182,17 @@ static void TargetSnapClosest(TransInfo *t)
                        } // FIXME(indent)
                }
                else {
+                       FOREACH_THAND(t, th) {
+                       TransData *td = th->data;
                        int i;
-                       for (td = t->data, i = 0; i < t->total && td->flag & 
TD_SELECTED; i++, td++) {
+                       for (i = 0; i < th->total && td->flag & TD_SELECTED; 
i++, td++) {
                                float loc[3];
                                float dist;
                                
                                copy_v3_v3(loc, td->center);
                                
                                if (t->flag & (T_EDIT | T_POSE)) {
-                                       Object *ob = t->obedit ? t->obedit : 
t->poseobj;
+                                       Object *ob = th->obedit ? th->obedit : 
th->poseobj;
                                        mul_m4_v3(ob->obmat, loc);
                                }
                                
@@ -1193,6 +1206,7 @@ static void TargetSnapClosest(TransInfo *t)
                                        dist_closest = dist;
                                }
                        }
+                       } // FIXME(indent)
                }
                
                TargetSnapOffset(t, closest);

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

Reply via email to