Manipulator: Use object bound-box for scale cage
authorCampbell Barton <ideasman42@gmail.com>
Tue, 24 Oct 2017 01:40:52 +0000 (12:40 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 26 Oct 2017 05:15:54 +0000 (16:15 +1100)
Without this, scaling single objects wasn't working usefully.

source/blender/editors/transform/transform_manipulator.c

index a540fe588779bdf937dcc33c1ca73cfdf73a5a63..1fa62556bd54e9b3624c7abb86973d1726cf480a 100644 (file)
@@ -584,7 +584,9 @@ bool gimbal_axis(Object *ob, float gmat[3][3])
 
 /* centroid, boundbox, of selection */
 /* returns total items selected */
-static int calc_manipulator_stats(const bContext *C, struct TransformBounds *tbounds)
+static int calc_manipulator_stats(
+        const bContext *C, bool use_only_center,
+        struct TransformBounds *tbounds)
 {
        ScrArea *sa = CTX_wm_area(C);
        ARegion *ar = CTX_wm_region(C);
@@ -1004,7 +1006,16 @@ static int calc_manipulator_stats(const bContext *C, struct TransformBounds *tbo
                        if (TESTBASELIB_NEW(base)) {
                                if (ob == NULL)
                                        ob = base->object;
-                               calc_tw_center(tbounds, base->object->obmat[3]);
+                               if (use_only_center || base->object->bb == NULL) {
+                                       calc_tw_center(tbounds, base->object->obmat[3]);
+                               }
+                               else {
+                                       for (uint j = 0; j < 8; j++) {
+                                               float co[3];
+                                               mul_v3_m4v3(co, base->object->obmat, base->object->bb->vec[j]);
+                                               calc_tw_center(tbounds, co);
+                                       }
+                               }
                                protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag);
                                totsel++;
                        }
@@ -1181,7 +1192,7 @@ static int manipulator_modal(
        struct TransformBounds tbounds;
 
 
-       if (calc_manipulator_stats(C, &tbounds)) {
+       if (calc_manipulator_stats(C, true, &tbounds)) {
                manipulator_prepare_mat(C, v3d, rv3d, &tbounds);
                WM_manipulator_set_matrix_location(widget, rv3d->twmat[3]);
        }
@@ -1317,7 +1328,7 @@ static void WIDGETGROUP_manipulator_refresh(const bContext *C, wmManipulatorGrou
        struct TransformBounds tbounds;
 
        /* skip, we don't draw anything anyway */
-       if ((man->all_hidden = (calc_manipulator_stats(C, &tbounds) == 0)))
+       if ((man->all_hidden = (calc_manipulator_stats(C, true, &tbounds) == 0)))
                return;
 
        manipulator_prepare_mat(C, v3d, rv3d, &tbounds);
@@ -1524,7 +1535,7 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmManipulatorGroup
 
        struct TransformBounds tbounds;
 
-       if ((calc_manipulator_stats(C, &tbounds) == 0) ||
+       if ((calc_manipulator_stats(C, false, &tbounds) == 0) ||
            equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max))
        {
                WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);