bring back align to view to object
authorCampbell Barton <ideasman42@gmail.com>
Fri, 6 Nov 2009 10:38:00 +0000 (10:38 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 6 Nov 2009 10:38:00 +0000 (10:38 +0000)
- In 2.4x this was numpad *, however that would only align on the Z axis.
- New behavior for VIEW3D_OT_viewnumpad, holding Shift with Numpad 1/3/7 sets the left/top/front etc on the normal axis.
- Uses active bone, face, edge, vert, curve handel & object (just like the view manipulator with 'Normal' selected).

source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_manipulator.c
source/blender/editors/transform/transform_orientations.c

index e76dc1aaa00c3f2efa376bbd7f91fd2ebd722f5a..fa6267c4a5cc80b1158a2355a86b4d1d7ce1f60c 100644 (file)
@@ -1498,27 +1498,56 @@ static EnumPropertyItem prop_view_items[] = {
        {RV3D_VIEW_CAMERA, "CAMERA", 0, "Camera", "View From the active amera"},
        {0, NULL, 0, NULL, NULL}};
 
-static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, short view, int perspo)
+
+/* would like to make this a generic function - outside of transform */
+extern void getTransformOrientationMatrix(const bContext *C, float twmat[][4], int activeOnly);
+
+static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, short view, int perspo, int align_active)
 {
        View3D *v3d = CTX_wm_view3d(C);
        RegionView3D *rv3d= CTX_wm_region_view3d(C);
        float new_quat[4];
 
-       if(rv3d->viewlock) {
-               /* only pass on if */
-               if(rv3d->view==RV3D_VIEW_FRONT && view==RV3D_VIEW_BACK);
-               else if(rv3d->view==RV3D_VIEW_BACK && view==RV3D_VIEW_FRONT);
-               else if(rv3d->view==RV3D_VIEW_RIGHT && view==RV3D_VIEW_LEFT);
-               else if(rv3d->view==RV3D_VIEW_LEFT && view==RV3D_VIEW_RIGHT);
-               else if(rv3d->view==RV3D_VIEW_BOTTOM && view==RV3D_VIEW_TOP);
-               else if(rv3d->view==RV3D_VIEW_TOP && view==RV3D_VIEW_BOTTOM);
-               else return;
-       }
-
        new_quat[0]= q1; new_quat[1]= q2;
        new_quat[2]= q3; new_quat[3]= q4;
 
-       rv3d->view= view;
+       if(align_active) {
+               /* align to active object */
+               Object *obact= CTX_data_active_object(C);
+               if (obact==NULL) {
+                       /* no active object, ignore this option */
+                       align_active= FALSE;
+               }
+               else {
+                       float obact_quat[4];
+                       float twmat[4][4];
+
+                       /* same as transform manipulator when normal is set */
+                       getTransformOrientationMatrix(C, twmat, TRUE);
+
+                       Mat4ToQuat(twmat, obact_quat);
+                       QuatInv(obact_quat);
+                       QuatMul(new_quat, new_quat, obact_quat);
+
+                       rv3d->view= view= 0;
+               }
+       }
+
+       if(align_active==FALSE) {
+               /* normal operation */
+               if(rv3d->viewlock) {
+                       /* only pass on if */
+                       if(rv3d->view==RV3D_VIEW_FRONT && view==RV3D_VIEW_BACK);
+                       else if(rv3d->view==RV3D_VIEW_BACK && view==RV3D_VIEW_FRONT);
+                       else if(rv3d->view==RV3D_VIEW_RIGHT && view==RV3D_VIEW_LEFT);
+                       else if(rv3d->view==RV3D_VIEW_LEFT && view==RV3D_VIEW_RIGHT);
+                       else if(rv3d->view==RV3D_VIEW_BOTTOM && view==RV3D_VIEW_TOP);
+                       else if(rv3d->view==RV3D_VIEW_TOP && view==RV3D_VIEW_BOTTOM);
+                       else return;
+               }
+
+               rv3d->view= view;
+       }
 
        if(rv3d->viewlock) {
                ED_region_tag_redraw(CTX_wm_region(C));
@@ -1548,35 +1577,36 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
        RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Scene *scene= CTX_data_scene(C);
        static int perspo=RV3D_PERSP;
-       int viewnum;
+       int viewnum, align_active;
 
        viewnum = RNA_enum_get(op->ptr, "type");
+       align_active = RNA_boolean_get(op->ptr, "align_active");
 
        /* Use this to test if we started out with a camera */
 
        switch (viewnum) {
                case RV3D_VIEW_BOTTOM :
-                       axis_set_view(C, 0.0, -1.0, 0.0, 0.0, viewnum, perspo);
+                       axis_set_view(C, 0.0, -1.0, 0.0, 0.0, viewnum, perspo, align_active);
                        break;
 
                case RV3D_VIEW_BACK:
-                       axis_set_view(C, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), viewnum, perspo);
+                       axis_set_view(C, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), viewnum, perspo, align_active);
                        break;
 
                case RV3D_VIEW_LEFT:
-                       axis_set_view(C, 0.5, -0.5, 0.5, 0.5, viewnum, perspo);
+                       axis_set_view(C, 0.5, -0.5, 0.5, 0.5, viewnum, perspo, align_active);
                        break;
 
                case RV3D_VIEW_TOP:
-                       axis_set_view(C, 1.0, 0.0, 0.0, 0.0, viewnum, perspo);
+                       axis_set_view(C, 1.0, 0.0, 0.0, 0.0, viewnum, perspo, align_active);
                        break;
 
                case RV3D_VIEW_FRONT:
-                       axis_set_view(C, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, viewnum, perspo);
+                       axis_set_view(C, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, viewnum, perspo, align_active);
                        break;
 
                case RV3D_VIEW_RIGHT:
-                       axis_set_view(C, 0.5, -0.5, -0.5, -0.5, viewnum, perspo);
+                       axis_set_view(C, 0.5, -0.5, -0.5, -0.5, viewnum, perspo, align_active);
                        break;
 
                case RV3D_VIEW_CAMERA:
@@ -1617,7 +1647,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                                else{
                                        /* return to settings of last view */
                                        /* does smooth_view too */
-                                       axis_set_view(C, rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3], rv3d->lview, rv3d->lpersp);
+                                       axis_set_view(C, rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3], rv3d->lview, rv3d->lpersp, 0);
                                }
                        }
                        break;
@@ -1645,6 +1675,7 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot)
        ot->flag= 0;
 
        RNA_def_enum(ot->srna, "type", prop_view_items, 0, "View", "The Type of view");
+       RNA_def_boolean(ot->srna, "align_active", 0, "Align Active", "Align to the active objects axis");
 }
 
 static EnumPropertyItem prop_view_orbit_items[] = {
index 13324e61999c76c1c36860cb294b5f1c8f7958f7..adda08202c0d1f10cd489e23cfa81a0d2d94cf7c 100644 (file)
@@ -155,6 +155,39 @@ void view3d_keymap(wmKeyConfig *keyconf)
        RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD6, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANRIGHT);
        RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANUP);
 
+    /* active aligned, replaces '*' key in 2.4x */
+    km= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT, 0);
+    RNA_enum_set(km->ptr, "type", RV3D_VIEW_FRONT);
+    RNA_boolean_set(km->ptr, "align_active", TRUE);
+    km= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT, 0);
+    RNA_enum_set(km->ptr, "type", RV3D_VIEW_RIGHT);
+    RNA_boolean_set(km->ptr, "align_active", TRUE);    
+    km= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT, 0);
+    RNA_enum_set(km->ptr, "type", RV3D_VIEW_TOP);
+    RNA_boolean_set(km->ptr, "align_active", TRUE);
+    km= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
+    RNA_enum_set(km->ptr, "type", RV3D_VIEW_BACK);
+    RNA_boolean_set(km->ptr, "align_active", TRUE);
+    km= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
+    RNA_enum_set(km->ptr, "type", RV3D_VIEW_LEFT);
+    RNA_boolean_set(km->ptr, "align_active", TRUE);
+    km= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
+    RNA_enum_set(km->ptr, "type", RV3D_VIEW_BOTTOM);
+    RNA_boolean_set(km->ptr, "align_active", TRUE);    
+    
+
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD2, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPDOWN);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD4, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
+       WM_keymap_add_item(keymap, "VIEW3D_OT_view_persportho", PAD5, KM_PRESS, 0, 0);
+       
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD6, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD8, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPUP);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BACK);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_LEFT);
+       RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BOTTOM);
+
        WM_keymap_add_item(keymap, "VIEW3D_OT_localview", PADSLASHKEY, KM_PRESS, 0, 0);
        
        WM_keymap_add_item(keymap, "VIEW3D_OT_game_start", PKEY, KM_PRESS, 0, 0);
index ae4b1f446dac6870c826f8a4fca46bdaaf2b44d7..f6f8d3e4aa2ec813519c246227126b966f49c10f 100644 (file)
@@ -697,6 +697,9 @@ void applyTransformOrientation(const struct bContext *C, float mat[3][3], char *
 #define ORIENTATION_FACE       4
 
 int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3], int activeOnly);
+
+/* also used in view3d_edit.c, todo - move outside of transform */
+void getTransformOrientationMatrix(const struct bContext *C, float twmat[][4], int use_active);
 int createSpaceNormal(float mat[3][3], float normal[3]);
 int createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]);
 
index a1d62f93568a9f95f2000ca28da16b5e31295c4e..dd94fef4059ba4a6f12fcdd3e479416938c2d82f 100644 (file)
@@ -259,8 +259,6 @@ int calc_manipulator_stats(const bContext *C)
        RegionView3D *rv3d= ar->regiondata;
        Base *base;
        Object *ob= OBACT;
-       float normal[3]={0.0, 0.0, 0.0};
-       float plane[3]={0.0, 0.0, 0.0};
        int a, totsel= 0;
 
        /* transform widget matrix */
@@ -498,47 +496,7 @@ int calc_manipulator_stats(const bContext *C)
                }
                case V3D_MANIP_NORMAL:
                        if(obedit || ob->mode & OB_MODE_POSE) {
-                               float mat[3][3];
-                               int type;
-
-                               type = getTransformOrientation(C, normal, plane, (v3d->around == V3D_ACTIVE));
-
-                               switch (type)
-                               {
-                                       case ORIENTATION_NORMAL:
-                                               if (createSpaceNormalTangent(mat, normal, plane) == 0)
-                                               {
-                                                       type = ORIENTATION_NONE;
-                                               }
-                                               break;
-                                       case ORIENTATION_VERT:
-                                               if (createSpaceNormal(mat, normal) == 0)
-                                               {
-                                                       type = ORIENTATION_NONE;
-                                               }
-                                               break;
-                                       case ORIENTATION_EDGE:
-                                               if (createSpaceNormalTangent(mat, normal, plane) == 0)
-                                               {
-                                                       type = ORIENTATION_NONE;
-                                               }
-                                               break;
-                                       case ORIENTATION_FACE:
-                                               if (createSpaceNormalTangent(mat, normal, plane) == 0)
-                                               {
-                                                       type = ORIENTATION_NONE;
-                                               }
-                                               break;
-                               }
-
-                               if (type == ORIENTATION_NONE)
-                               {
-                                       Mat4One(rv3d->twmat);
-                               }
-                               else
-                               {
-                                       Mat4CpyMat3(rv3d->twmat, mat);
-                               }
+                               getTransformOrientationMatrix(C, rv3d->twmat, (v3d->around == V3D_ACTIVE));
                                break;
                        }
                        /* no break we define 'normal' as 'local' in Object mode */
index 56160d66e258d8f32ac2cf680cb40424d5cdb57b..8b4023a33523c623aaa882634ec262371112228c 100644 (file)
@@ -531,49 +531,8 @@ void initTransformOrientation(bContext *C, TransInfo *t)
                break;
        case V3D_MANIP_NORMAL:
                if(obedit || (ob && ob->mode & OB_MODE_POSE)) {
-                       float mat[3][3];
-                       int type;
-                       
                        strcpy(t->spacename, "normal");
-                       
-                       type = getTransformOrientation(C, normal, plane, (v3d->around == V3D_ACTIVE));
-                       
-                       switch (type)
-                       {
-                               case ORIENTATION_NORMAL:
-                                       if (createSpaceNormalTangent(mat, normal, plane) == 0)
-                                       {
-                                               type = ORIENTATION_NONE;
-                                       }
-                                       break;
-                               case ORIENTATION_VERT:
-                                       if (createSpaceNormal(mat, normal) == 0)
-                                       {
-                                               type = ORIENTATION_NONE;
-                                       }
-                                       break;
-                               case ORIENTATION_EDGE:
-                                       if (createSpaceNormalTangent(mat, normal, plane) == 0)
-                                       {
-                                               type = ORIENTATION_NONE;
-                                       }
-                                       break;
-                               case ORIENTATION_FACE:
-                                       if (createSpaceNormalTangent(mat, normal, plane) == 0)
-                                       {
-                                               type = ORIENTATION_NONE;
-                                       }
-                                       break;
-                       }
-                       
-                       if (type == ORIENTATION_NONE)
-                       {
-                               Mat3One(t->spacemtx);
-                       }
-                       else
-                       {
-                               Mat3CpyMat3(t->spacemtx, mat);
-                       }
+                       getTransformOrientationMatrix(C, t->spacemtx, (v3d->around == V3D_ACTIVE));
                        break;
                }
                /* no break we define 'normal' as 'local' in Object mode */
@@ -967,3 +926,51 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
        
        return result;
 }
+
+void getTransformOrientationMatrix(const bContext *C, float twmat[][4], int activeOnly)
+{
+       float normal[3]={0.0, 0.0, 0.0};
+       float plane[3]={0.0, 0.0, 0.0};
+
+       float mat[3][3];
+       int type;
+
+       type = getTransformOrientation(C, normal, plane, activeOnly);
+
+       switch (type)
+       {
+               case ORIENTATION_NORMAL:
+                       if (createSpaceNormalTangent(mat, normal, plane) == 0)
+                       {
+                               type = ORIENTATION_NONE;
+                       }
+                       break;
+               case ORIENTATION_VERT:
+                       if (createSpaceNormal(mat, normal) == 0)
+                       {
+                               type = ORIENTATION_NONE;
+                       }
+                       break;
+               case ORIENTATION_EDGE:
+                       if (createSpaceNormalTangent(mat, normal, plane) == 0)
+                       {
+                               type = ORIENTATION_NONE;
+                       }
+                       break;
+               case ORIENTATION_FACE:
+                       if (createSpaceNormalTangent(mat, normal, plane) == 0)
+                       {
+                               type = ORIENTATION_NONE;
+                       }
+                       break;
+       }
+
+       if (type == ORIENTATION_NONE)
+       {
+               Mat4One(twmat);
+       }
+       else
+       {
+               Mat4CpyMat3(twmat, mat);
+       }
+}