diff options
author | Martin Poirier <theeth@yahoo.com> | 2008-03-10 03:27:17 +0300 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2008-03-10 03:27:17 +0300 |
commit | cbfbe53ebe39ece9a0c0bf05e87d3f7241ebe006 (patch) | |
tree | 73805c5f627a0d58ef89f1ab4230c9c479b09fac | |
parent | 1a4f7a861ef6008b10a9e5ef65d4f4a34f5ca548 (diff) |
== Align to Transform Orientation ==
New rotation alignement fonction
Rotates objects/Pose bones to match the selected transform orientation.
Can be used to align to view, active object (normal) and custom transform orientations.
Accessible in the Object -> Transform submenu and through the hotkey Ctrl-Alt-A (which was previously a fall through for Apply but only Ctrl-A and Ctrl-Shift-A did anything special).
Can be eventually made to work in edit mode (not too hard).
-rw-r--r-- | source/blender/include/BIF_transform.h | 1 | ||||
-rw-r--r-- | source/blender/include/transform.h | 3 | ||||
-rw-r--r-- | source/blender/src/header_view3d.c | 5 | ||||
-rw-r--r-- | source/blender/src/space.c | 10 | ||||
-rw-r--r-- | source/blender/src/transform.c | 59 |
5 files changed, 77 insertions, 1 deletions
diff --git a/source/blender/include/BIF_transform.h b/source/blender/include/BIF_transform.h index deebe7c27cb..e5be25ae729 100644 --- a/source/blender/include/BIF_transform.h +++ b/source/blender/include/BIF_transform.h @@ -62,6 +62,7 @@ #define TFM_BAKE_TIME 23 #define TFM_BEVEL 24 #define TFM_BWEIGHT 25 +#define TFM_ALIGN 26 /* TRANSFORM CONTEXTS */ #define CTX_NONE 0 diff --git a/source/blender/include/transform.h b/source/blender/include/transform.h index 694cfece989..feaa2b4d762 100644 --- a/source/blender/include/transform.h +++ b/source/blender/include/transform.h @@ -373,6 +373,9 @@ int BakeTime(TransInfo *t, short mval[2]); void initMirror(TransInfo *t); int Mirror(TransInfo *t, short mval[2]); +void initAlign(TransInfo *t); +int Align(TransInfo *t, short mval[2]); + /*********************** transform_conversions.c ********** */ struct ListBase; void flushTransIpoData(TransInfo *t); diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c index 1ea9d43afd8..592b64227ee 100644 --- a/source/blender/src/header_view3d.c +++ b/source/blender/src/header_view3d.c @@ -1786,6 +1786,10 @@ static void do_view3d_transformmenu(void *arg, int event) case 20: G.scene->snap_target = SCE_SNAP_TARGET_ACTIVE; break; + case 21: + initTransform(TFM_ALIGN, CTX_NO_PET|CTX_AUTOCONFIRM); + Transform(); + break; } allqueue(REDRAWVIEW3D, 0); } @@ -1835,6 +1839,7 @@ static uiBlock *view3d_transformmenu(void *arg_unused) if (!G.obedit) { uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center New", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center Cursor", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align to Transform Orientation", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 21, ""); } if (BIF_snappingSupported()) diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 47a37a21ed9..89775f976ff 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -1743,7 +1743,15 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) break; case AKEY: - if(G.qual & LR_CTRLKEY) apply_object(); /* also with shift! */ + if (G.obedit == 0 && G.qual == (LR_CTRLKEY|LR_ALTKEY)) { + if(okee("Align to Transform Orientation")) { + initTransform(TFM_ALIGN, CTX_NO_PET|CTX_AUTOCONFIRM); + Transform(); + } + } + else if(G.qual & LR_CTRLKEY) { /* also with shift! */ + apply_object(); + } else if((G.qual==LR_SHIFTKEY)) { toolbox_n_add(); } diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c index b7bc6a2f027..5d4e110a75e 100644 --- a/source/blender/src/transform.c +++ b/source/blender/src/transform.c @@ -943,6 +943,7 @@ void initTransform(int mode, int context) { if(Trans.spacetype==SPACE_VIEW3D) { calc_manipulator_stats(curarea); Mat3CpyMat4(Trans.spacemtx, G.vd->twmat); + Mat3Ortho(Trans.spacemtx); } else Mat3One(Trans.spacemtx); @@ -1041,6 +1042,9 @@ void initTransform(int mode, int context) { case TFM_BWEIGHT: initBevelWeight(&Trans); break; + case TFM_ALIGN: + initAlign(&Trans); + break; } } @@ -4024,6 +4028,61 @@ int Mirror(TransInfo *t, short mval[2]) return 1; } +/* ************************** ALIGN *************************** */ + +void initAlign(TransInfo *t) +{ + t->flag |= T_NO_CONSTRAINT; + + t->transform = Align; +} + +int Align(TransInfo *t, short mval[2]) +{ + TransData *td = t->data; + float center[3]; + int i; + + /* saving original center */ + VECCOPY(center, t->center); + + for(i = 0 ; i < t->total; i++, td++) + { + float mat[3][3], invmat[3][3]; + + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + /* around local centers */ + if (t->flag & (T_OBJECT|T_POSE)) { + VECCOPY(t->center, td->center); + } + else { + if(G.scene->selectmode & SCE_SELECT_FACE) { + VECCOPY(t->center, td->center); + } + } + + Mat3Inv(invmat, td->axismtx); + + Mat3MulMat3(mat, t->spacemtx, invmat); + + ElementRotation(t, td, mat); + } + + /* restoring original center */ + VECCOPY(t->center, center); + + recalcData(t); + + headerprint("Align"); + + return 1; +} + /* ************************** ANIM EDITORS - TRANSFORM TOOLS *************************** */ /* ---------------- Special Helpers for Various Settings ------------- */ |