diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-11-06 13:38:00 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-11-06 13:38:00 +0300 |
commit | d4fe2595f7c350c90feba61ba8d520850648b06f (patch) | |
tree | 5740ccae324a64e4ab369fc07c01c22024a0d6ed /source/blender | |
parent | cc2476fde5f2ae4a3df625780b056580c7836712 (diff) |
bring back align to view to object
- 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).
Diffstat (limited to 'source/blender')
5 files changed, 138 insertions, 106 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index e76dc1aaa00..fa6267c4a5c 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -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[] = { diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 13324e61999..adda08202c0 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -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); diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index ae4b1f446da..f6f8d3e4aa2 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -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]); diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index a1d62f93568..dd94fef4059 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -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 */ diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 56160d66e25..8b4023a3352 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -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); + } +} |