transform: 2d option for proportional editmode,
authorCampbell Barton <ideasman42@gmail.com>
Thu, 20 Jun 2013 13:24:07 +0000 (13:24 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 20 Jun 2013 13:24:07 +0000 (13:24 +0000)
Uses for view orientation for distance calculation, can give nicer results when you dont want twisting caused by changes in depth.

source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c

index 7a8d4c6750e11aab372630f94fcef44546567a63..ca31a4a98de46ba23f554ce2826bc06e80bcc600 100644 (file)
@@ -1736,12 +1736,15 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        }
 
        /* convert flag to enum */
-       switch (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) {
+       switch (t->flag & T_PROP_EDIT_ALL) {
+               case T_PROP_EDIT:
+                       proportional = PROP_EDIT_ON;
+                       break;
                case (T_PROP_EDIT | T_PROP_CONNECTED):
                        proportional = PROP_EDIT_CONNECTED;
                        break;
-               case T_PROP_EDIT:
-                       proportional = PROP_EDIT_ON;
+               case (T_PROP_EDIT | T_PROP_PROJECTED):
+                       proportional = PROP_EDIT_PROJECTED;
                        break;
                default:
                        proportional = PROP_EDIT_OFF;
@@ -2945,7 +2948,7 @@ static void headerResize(TransInfo *t, float vec[3], char *str)
                }
        }
 
-       if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) {
+       if (t->flag & T_PROP_EDIT_ALL) {
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size);
        }
 }
@@ -3143,7 +3146,7 @@ int Resize(TransInfo *t, const int mval[2])
                /* vertices in the radius of the brush end */
                /* outside the clipping area               */
                /* XXX HACK - dg */
-               if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) {
+               if (t->flag & T_PROP_EDIT_ALL) {
                        clipUVData(t);
                }
        }
@@ -3663,7 +3666,7 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2]))
                                    RAD2DEGF(final), t->con.text, t->proptext);
        }
        
-       if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) {
+       if (t->flag & T_PROP_EDIT_ALL) {
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size);
        }
 
@@ -3764,7 +3767,7 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2]))
                                    RAD2DEGF(phi[0]), RAD2DEGF(phi[1]), t->proptext);
        }
 
-       if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) {
+       if (t->flag & T_PROP_EDIT_ALL) {
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size);
        }
 
@@ -3912,7 +3915,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str)
                }
        }
 
-       if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) {
+       if (t->flag & T_PROP_EDIT_ALL) {
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size);
        }
 }
@@ -4019,7 +4022,7 @@ int Translation(TransInfo *t, const int UNUSED(mval[2]))
                /* vertices in the radius of the brush end */
                /* outside the clipping area               */
                /* XXX HACK - dg */
-               if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) {
+               if (t->flag & T_PROP_EDIT_ALL) {
                        clipUVData(t);
                }
        }
index 2cef3209b4e0065cbc416d9c276a9a763eaf851f..53ecfe3a685f7a4aabbd5f1b065f3f066c84826b 100644 (file)
@@ -394,6 +394,8 @@ typedef struct TransInfo {
 
 #define T_PROP_EDIT                    (1 << 11)
 #define T_PROP_CONNECTED       (1 << 12)
+#define T_PROP_PROJECTED       (1 << 25)
+#define T_PROP_EDIT_ALL                (T_PROP_EDIT | T_PROP_CONNECTED | T_PROP_PROJECTED)
 
 #define T_V3D_ALIGN                    (1 << 14)
        /* for 2d views like uv or ipo */
index d1b57e2e40245413c9c25a73451f752100cac759..2a982517d3e7e326d15f6b06ef0579409f1e045b 100644 (file)
@@ -201,6 +201,17 @@ static void set_prop_dist(TransInfo *t, const bool with_dist)
        TransData *tob;
        int a;
 
+       float _proj_vec[3];
+       const float *proj_vec = NULL;
+
+       if (t->flag & T_PROP_PROJECTED) {
+               if (t->spacetype == SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
+                       RegionView3D *rv3d = t->ar->regiondata;
+                       normalize_v3_v3(_proj_vec, rv3d->viewinv[2]);
+                       proj_vec = _proj_vec;
+               }
+       }
+
        for (a = 0, tob = t->data; a < t->total; a++, tob++) {
 
                tob->rdist = 0.0f; // init, it was mallocced
@@ -216,6 +227,13 @@ static void set_prop_dist(TransInfo *t, const bool with_dist)
                                if (td->flag & TD_SELECTED) {
                                        sub_v3_v3v3(vec, tob->center, td->center);
                                        mul_m3_v3(tob->mtx, vec);
+
+                                       if (proj_vec) {
+                                               float vec_p[3];
+                                               project_v3_v3v3(vec_p, vec, proj_vec);
+                                               sub_v3_v3(vec, vec_p);
+                                       }
+
                                        dist = len_squared_v3(vec);
                                        if ((tob->rdist == -1.0f) || (dist < (tob->rdist * tob->rdist))) {
                                                tob->rdist = sqrtf(dist);
@@ -989,7 +1007,7 @@ static void createTransPose(TransInfo *t, Object *ob)
        t->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */
 
        /* disable PET, its not usable in pose mode yet [#32444] */
-       t->flag &= ~(T_PROP_EDIT | T_PROP_CONNECTED);
+       t->flag &= ~T_PROP_EDIT_ALL;
 
        /* init trans data */
        td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransPoseBone");
@@ -2013,7 +2031,7 @@ static void createTransEditVerts(TransInfo *t)
        float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL;
        float *dists = NULL;
        int count = 0, countsel = 0, a, totleft;
-       int propmode = (t->flag & T_PROP_EDIT) ? (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) : 0;
+       int propmode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0;
        int mirror = 0;
        char *selstate = NULL;
        short selectmode = ts->selectmode;
@@ -5827,7 +5845,7 @@ static void createTransNodeData(bContext *UNUSED(C), TransInfo *t)
        }
 
        /* nodes dont support PET and probably never will */
-       t->flag &= ~(T_PROP_EDIT | T_PROP_CONNECTED);
+       t->flag &= ~T_PROP_EDIT_ALL;
 
        /* set transform flags on nodes */
        for (node = snode->edittree->nodes.first; node; node = node->next) {
index 369b5a82a8482d9ee8f3b0143d0e87657bf2bfad..3e4316b1277e2aad3390d67d577677b5f591200a 100644 (file)
@@ -1023,6 +1023,20 @@ void resetTransRestrictions(TransInfo *t)
        t->flag &= ~T_ALL_RESTRICTIONS;
 }
 
+static int initTransInfo_edit_pet_to_flag(const int proportional)
+{
+       switch (proportional) {
+               case PROP_EDIT_ON:
+                       return T_PROP_EDIT;
+               case PROP_EDIT_CONNECTED:
+                       return T_PROP_EDIT | T_PROP_CONNECTED;
+               case PROP_EDIT_PROJECTED:
+                       return T_PROP_EDIT | T_PROP_PROJECTED;
+               default:
+                       return 0;
+       }
+}
+
 /* the *op can be NULL */
 int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event)
 {
@@ -1245,24 +1259,14 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
        /* setting PET flag only if property exist in operator. Otherwise, assume it's not supported */
        if (op && (prop = RNA_struct_find_property(op->ptr, "proportional"))) {
                if (RNA_property_is_set(op->ptr, prop)) {
-                       switch (RNA_property_enum_get(op->ptr, prop)) {
-                               case PROP_EDIT_CONNECTED:
-                                       t->flag |= T_PROP_CONNECTED;
-                               case PROP_EDIT_ON:
-                                       t->flag |= T_PROP_EDIT;
-                                       break;
-                       }
+                       t->flag |= initTransInfo_edit_pet_to_flag(RNA_property_enum_get(op->ptr, prop));
                }
                else {
                        /* use settings from scene only if modal */
                        if (t->flag & T_MODAL) {
                                if ((t->options & CTX_NO_PET) == 0) {
-                                       if (t->obedit && ts->proportional != PROP_EDIT_OFF) {
-                                               t->flag |= T_PROP_EDIT;
-
-                                               if (ts->proportional == PROP_EDIT_CONNECTED) {
-                                                       t->flag |= T_PROP_CONNECTED;
-                                               }
+                                       if (t->obedit) {
+                                               t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional);
                                        }
                                        else if (t->options & CTX_MASK) {
                                                if (ts->proportional_mask) {
index bc911f9addca972c1ec21f5350cb68bb38aefc97..e08ecf6dff8877e588bc08e078b045388698a281 100644 (file)
@@ -1501,7 +1501,8 @@ typedef struct Scene {
 /* toolsettings->proportional */
 #define PROP_EDIT_OFF                  0
 #define PROP_EDIT_ON                   1
-#define PROP_EDIT_CONNECTED    2
+#define PROP_EDIT_CONNECTED            2
+#define PROP_EDIT_PROJECTED            3
 
 /* toolsettings->weightuser */
 enum {
index 44eee64208145d9de03d35ee10d8d6374719456a..0c3f4aa073bf5f69de1de2c964d23bcb4bd2d1a3 100644 (file)
@@ -120,6 +120,8 @@ EnumPropertyItem proportional_falloff_curve_only_items[] = {
 EnumPropertyItem proportional_editing_items[] = {
        {PROP_EDIT_OFF, "DISABLED", ICON_PROP_OFF, "Disable", "Proportional Editing disabled"},
        {PROP_EDIT_ON, "ENABLED", ICON_PROP_ON, "Enable", "Proportional Editing enabled"},
+       {PROP_EDIT_PROJECTED, "PROJECTED", ICON_PROP_ON, "Projected (2D)",
+                             "Proportional Editing using screen space locations"},
        {PROP_EDIT_CONNECTED, "CONNECTED", ICON_PROP_CON, "Connected",
                              "Proportional Editing using connected geometry only"},
        {0, NULL, 0, NULL, NULL}