use 'normal' orientation rather then 'local' with individual origins to use the per...
[blender-staging.git] / source / blender / editors / transform / transform_constraints.c
index 2752d76fbf00842e20ef1ace84b1f868a686564e..27b25a50eff77e6d95349b8df4651e6c8c38bddd 100644 (file)
@@ -393,7 +393,11 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, const float in
                        if (t->con.mode & CON_AXIS2) {
                                out[2] = in[i++];
                        }
+
                        mul_m3_v3(td->axismtx, out);
+                       if (t->flag & T_EDIT) {
+                               mul_m3_v3(t->obedit_mat, out);
+                       }
                }
        }
 }
@@ -445,6 +449,9 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3]
                }
 
                mul_m3_m3m3(tmat, smat, imat);
+               if (t->flag & T_EDIT) {
+                       mul_m3_m3m3(smat, t->obedit_mat, smat);
+               }
                mul_m3_m3m3(smat, td->axismtx, tmat);
        }
 }
@@ -509,24 +516,34 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3],
 {
        if (t->con.mode & CON_APPLY) {
                int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2);
+               float tmp_axismtx[3][3];
+               float (*axismtx)[3];
 
                /* on setup call, use first object */
                if (td == NULL) {
                        td = t->data;
                }
 
+               if (t->flag & T_EDIT) {
+                       mul_m3_m3m3(tmp_axismtx, t->obedit_mat, td->axismtx);
+                       axismtx = tmp_axismtx;
+               }
+               else {
+                       axismtx = td->axismtx;
+               }
+
                switch (mode) {
                        case CON_AXIS0:
                        case (CON_AXIS1 | CON_AXIS2):
-                               copy_v3_v3(vec, td->axismtx[0]);
+                               copy_v3_v3(vec, axismtx[0]);
                                break;
                        case CON_AXIS1:
                        case (CON_AXIS0 | CON_AXIS2):
-                               copy_v3_v3(vec, td->axismtx[1]);
+                               copy_v3_v3(vec, axismtx[1]);
                                break;
                        case CON_AXIS2:
                        case (CON_AXIS0 | CON_AXIS1):
-                               copy_v3_v3(vec, td->axismtx[2]);
+                               copy_v3_v3(vec, axismtx[2]);
                                break;
                }
                if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) {
@@ -555,36 +572,36 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
        t->redraw = 1;
 }
 
+/* applies individual td->axismtx constraints */
+void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[])
+{
+       if (t->total == 1) {
+               setConstraint(t, t->data->axismtx, mode, text);
+       }
+       else {
+               BLI_strncpy(t->con.text + 1, text, sizeof(t->con.text) - 1);
+               copy_m3_m3(t->con.mtx, t->data->axismtx);
+               t->con.mode = mode;
+               getConstraintMatrix(t);
+
+               startConstraint(t);
+
+               t->con.drawExtra = drawObjectConstraint;
+               t->con.applyVec = applyObjectConstraintVec;
+               t->con.applySize = applyObjectConstraintSize;
+               t->con.applyRot = applyObjectConstraintRot;
+               t->redraw = 1;
+       }
+}
+
 void setLocalConstraint(TransInfo *t, int mode, const char text[])
 {
        /* edit-mode now allows local transforms too */
-#if 0
        if (t->flag & T_EDIT) {
-               float obmat[3][3];
-               copy_m3_m4(obmat, t->scene->obedit->obmat);
-               normalize_m3(obmat);
-               setConstraint(t, obmat, mode, text);
+               setConstraint(t, t->obedit_mat, mode, text);
        }
-       else
-#endif
-       {
-               if (t->total == 1) {
-                       setConstraint(t, t->data->axismtx, mode, text);
-               }
-               else {
-                       BLI_strncpy(t->con.text + 1, text, sizeof(t->con.text) - 1);
-                       copy_m3_m3(t->con.mtx, t->data->axismtx);
-                       t->con.mode = mode;
-                       getConstraintMatrix(t);
-
-                       startConstraint(t);
-
-                       t->con.drawExtra = drawObjectConstraint;
-                       t->con.applyVec = applyObjectConstraintVec;
-                       t->con.applySize = applyObjectConstraintSize;
-                       t->con.applyRot = applyObjectConstraintRot;
-                       t->redraw = 1;
-               }
+       else {
+               setAxisMatrixConstraint(t, mode, text);
        }
 }
 
@@ -612,7 +629,12 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte
                        break;
                case V3D_MANIP_NORMAL:
                        BLI_snprintf(text, sizeof(text), ftext, IFACE_("normal"));
-                       setConstraint(t, t->spacemtx, mode, text);
+                       if (checkUseAxisMatrix(t)) {
+                               setAxisMatrixConstraint(t, mode, text);
+                       }
+                       else {
+                               setConstraint(t, t->spacemtx, mode, text);
+                       }
                        break;
                case V3D_MANIP_VIEW:
                        BLI_snprintf(text, sizeof(text), ftext, IFACE_("view"));
@@ -756,31 +778,39 @@ static void drawObjectConstraint(TransInfo *t)
        short options = DRAWLIGHT;
        TransData *td = t->data;
        int i;
+       float tmp_axismtx[3][3];
 
        for (i = 0; i < t->total; i++, td++) {
                float co[3];
+               float (*axismtx)[3];
 
                if (t->flag & T_OBJECT) {
                        copy_v3_v3(co, td->ob->obmat[3]);
+                       axismtx = td->axismtx;
                }
                else if (t->flag & T_EDIT) {
                        mul_v3_m4v3(co, t->obedit->obmat, td->center);
+
+                       mul_m3_m3m3(tmp_axismtx, t->obedit_mat, td->axismtx);
+                       axismtx = tmp_axismtx;
                }
                else if (t->flag & T_POSE) {
                        mul_v3_m4v3(co, t->poseobj->obmat, td->center);
+                       axismtx = td->axismtx;
                }
                else {
                        copy_v3_v3(co, td->center);
+                       axismtx = td->axismtx;
                }
 
                if (t->con.mode & CON_AXIS0) {
-                       drawLine(t, td->center, td->axismtx[0], 'X', options);
+                       drawLine(t, co, axismtx[0], 'X', options);
                }
                if (t->con.mode & CON_AXIS1) {
-                       drawLine(t, td->center, td->axismtx[1], 'Y', options);
+                       drawLine(t, co, axismtx[1], 'Y', options);
                }
                if (t->con.mode & CON_AXIS2) {
-                       drawLine(t, td->center, td->axismtx[2], 'Z', options);
+                       drawLine(t, co, axismtx[2], 'Z', options);
                }
                options &= ~DRAWLIGHT;
        }