diff options
author | Martin Poirier <theeth@yahoo.com> | 2004-04-25 01:09:06 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2004-04-25 01:09:06 +0400 |
commit | 64fd636f0ced7ed164d5772df2d1d6b3c5b7b496 (patch) | |
tree | ae10dcbc8f43bd39e02a81e3ba5af86c2e732c64 /source/blender | |
parent | f860c88405e38373daeb680288eba2f535c68b42 (diff) |
Mirror in object mode. Works like Mirror in edit mode but only works on local axis (doing it differently would require a much more clever algorithm).
Mirror Object is assigned to Ctrl-M and I've add Ctrl-M to call Mirror Edit (on top of M alone) for practical reason. We should consider switching both to Ctrl-M for pratical reasons but I kept M for backward compatibility
Also added the menu and toolbox counterparts.
Minor addition to arithb.c: A function to print vectors to the console. Easier for debuging.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_arithb.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/arithb.c | 8 | ||||
-rw-r--r-- | source/blender/include/BDR_editobject.h | 3 | ||||
-rw-r--r-- | source/blender/include/BSE_headerbuttons.h | 3 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 76 | ||||
-rw-r--r-- | source/blender/src/header_view3d.c | 44 | ||||
-rw-r--r-- | source/blender/src/space.c | 7 | ||||
-rw-r--r-- | source/blender/src/toolbox.c | 18 |
8 files changed, 143 insertions, 21 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h index 78f662ce67c..5941d421d16 100644 --- a/source/blender/blenlib/BLI_arithb.h +++ b/source/blender/blenlib/BLI_arithb.h @@ -469,6 +469,11 @@ saacos( sasqrt( float fac ); + void +printvecf( + char *str, + float v[3] +); float Inpf( float *v1, diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index 61fe4358fa4..b3419bd9250 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -949,6 +949,14 @@ int FloatCompare( float *v1, float *v2, float limit) return 0; } +void printvecf( char *str, float v[3]) +{ + printf("%s\n", str); + printf("%f %f %f\n",v[0],v[1],v[2]); + printf("\n"); + +} + void printmatrix4( char *str, float m[][4]) { printf("%s\n", str); diff --git a/source/blender/include/BDR_editobject.h b/source/blender/include/BDR_editobject.h index df5def7a7e9..f376161cb7a 100644 --- a/source/blender/include/BDR_editobject.h +++ b/source/blender/include/BDR_editobject.h @@ -116,7 +116,8 @@ void first_base(void); void make_displists_by_obdata(void *obdata); void flip_subdivison(struct Object *ob, int); void mirrormenu(void); -void mirror(short mode); +void mirror_edit(short mode); +void mirror_object(short mode); #endif /* BDR_EDITOBJECT_H */ diff --git a/source/blender/include/BSE_headerbuttons.h b/source/blender/include/BSE_headerbuttons.h index ab0d3139bc0..446df3e7647 100644 --- a/source/blender/include/BSE_headerbuttons.h +++ b/source/blender/include/BSE_headerbuttons.h @@ -123,7 +123,8 @@ void do_view3d_select_object_typemenu(void *arg, int event); void do_view3d_select_meshmenu(void *arg, int event); void do_view3d_select_curvemenu(void *arg, int event); void do_view3d_edit_snapmenu(void *arg, int event); -void do_view3d_edit_mesh_mirrormenu(void *arg, int event); +void do_view3d_edit_mirrormenu(void *arg, int event); +void do_view3d_object_mirrormenu(void *arg, int event); void do_view3d_edit_mesh_normalsmenu(void *arg, int event); void do_view3d_edit_mesh_verticesmenu(void *arg, int event); void do_view3d_edit_mesh_edgesmenu(void *arg, int event); diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 1d68cdc8815..eec31290391 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -7253,7 +7253,7 @@ void make_displists_by_obdata(void *obdata) { /* ******************************************************************** */ /* Mirror function in Edit Mode */ -void mirror(short mode) { +void mirror_edit(short mode) { short axis, a; float mat[3][3], imat[3][3], min[3], max[3]; TransVert *tv; @@ -7383,15 +7383,81 @@ void mirror(short mode) { tottrans= 0; } +void mirror_object(short mode) { + TransOb *tob; + short a, axis; + float off[3], imat[3][3]; + + setbaseflags_for_editing('s'); + figure_pose_updating(); + make_trans_objects(); + + tob = transmain; + + // Taking care of all the centre modes + if(G.vd->around==V3D_CENTROID) { + VecCopyf(centre, centroid); + } + else if(G.vd->around==V3D_CURSOR) { + float *curs; + curs= give_cursor(); + VECCOPY(centre, curs); + } + else if(G.vd->around==V3D_LOCAL) { + centre[0] = centre[1] = centre[2] = 0.0; + } + // Boundbox centre is implicit + + if ( (mode == 1) || (mode == 2) || (mode == 3) ) { + axis = mode - 1; + for(a=0; a<tottrans; a++, tob++) { + Mat3Inv(imat, tob->obmat); + + VecSubf(off, tob->loc, centre); + + Mat3MulVecfl(imat, off); + + off[axis] *= -1; + + Mat3MulVecfl(tob->obmat, off); + + VecAddf(off, off, centre); + + tob->loc[0] = off[0]; + tob->loc[1] = off[1]; + tob->loc[2] = off[2]; + + tob->size[axis] *= -1; + } + } + + special_aftertrans_update('m', 1, 0, 0); + + allqueue(REDRAWVIEW3D, 0); + scrarea_queue_headredraw(curarea); + + clearbaseflags_for_editing(); + if(transmain) MEM_freeN(transmain); + transmain= 0; + + tottrans= 0; +} + void mirrormenu(void){ short mode = 0; - if (G.obedit==0) return; - mode=pupmenu("Mirror Axis %t|X Global%x1|Y Global%x2|Z Global%x3|%l|X Local%x4|Y local%x5|Z Local%x6|%l|X View%x7|Y View%x8|Z View%x9|"); + if (G.obedit==0) { + mode=pupmenu("Mirror Axis %t|X Local%x1|Y Local%x2|Z Local%x3|"); - if (mode==-1) return; /* return */ + if (mode==-1) return; /* return */ + mirror_object(mode); /* separating functionality from interface | call*/ + } + else { + mode=pupmenu("Mirror Axis %t|X Global%x1|Y Global%x2|Z Global%x3|%l|X Local%x4|Y local%x5|Z Local%x6|%l|X View%x7|Y View%x8|Z View%x9|"); - mirror(mode); /* separating functionality from interface | call*/ + if (mode==-1) return; /* return */ + mirror_edit(mode); /* separating functionality from interface | call*/ + } } diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c index 889204e7ba9..fb1fa9e3cc8 100644 --- a/source/blender/src/header_view3d.c +++ b/source/blender/src/header_view3d.c @@ -134,6 +134,35 @@ static int viewmovetemp = 0; +void do_view3d_object_mirrormenu(void *arg, int event) +{ + switch(event) { + case 1: + case 2: + case 3: + mirror_object(event); + break; + } + allqueue(REDRAWVIEW3D, 0); +} + +static uiBlock *view3d_object_mirrormenu(void *arg_unused) +{ + uiBlock *block; + short yco = 20, menuwidth = 120; + + block= uiNewBlock(&curarea->uiblocks, "view3d_object_mirrormenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); + uiBlockSetButmFunc(block, do_view3d_object_mirrormenu, NULL); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "X Local|M, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Y Local|M, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Z Local|M, 3", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); + + uiBlockSetDirection(block, UI_RIGHT); + uiTextBoundsBlock(block, 60); + return block; +} + void do_layer_buttons(short event) { static int oldlay= 1; @@ -1510,6 +1539,8 @@ static uiBlock *view3d_edit_objectmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Move to Layer...|M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, ""); + + uiDefIconTextBlockBut(block, view3d_object_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, menuwidth, 19, ""); if(curarea->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); @@ -1800,7 +1831,7 @@ static uiBlock *view3d_edit_mesh_normalsmenu(void *arg_unused) return block; } -void do_view3d_edit_mesh_mirrormenu(void *arg, int event) +void do_view3d_edit_mirrormenu(void *arg, int event) { switch(event) { case 1: @@ -1812,19 +1843,19 @@ void do_view3d_edit_mesh_mirrormenu(void *arg, int event) case 7: case 8: case 9: - mirror(event); + mirror_edit(event); break; } allqueue(REDRAWVIEW3D, 0); } -static uiBlock *view3d_edit_mesh_mirrormenu(void *arg_unused) +static uiBlock *view3d_edit_mirrormenu(void *arg_unused) { uiBlock *block; short yco = 20, menuwidth = 120; - block= uiNewBlock(&curarea->uiblocks, "view3d_edit_mesh_mirrormenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); - uiBlockSetButmFunc(block, do_view3d_edit_mesh_mirrormenu, NULL); + block= uiNewBlock(&curarea->uiblocks, "view3d_edit_mirrormenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); + uiBlockSetButmFunc(block, do_view3d_edit_mirrormenu, NULL); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "X Global|M, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Y Global|M, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); @@ -1847,7 +1878,6 @@ static uiBlock *view3d_edit_mesh_mirrormenu(void *arg_unused) return block; } - static void do_view3d_edit_mesh_showhidemenu(void *arg, int event) { @@ -1968,7 +1998,7 @@ static uiBlock *view3d_edit_meshmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); - uiDefIconTextBlockBut(block, view3d_edit_mesh_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 19, ""); + uiDefIconTextBlockBut(block, view3d_edit_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 19, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Shrink/Fatten Along Normals|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Shear|Ctrl S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Warp|Shift W", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, ""); diff --git a/source/blender/src/space.c b/source/blender/src/space.c index af369e3d937..399aeb6c94b 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -1162,14 +1162,17 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) makeDispList(G.obedit); } } - else if((G.qual==0)) { + else if((G.qual==0) || (G.qual==LR_CTRLKEY)) { mirrormenu(); } if(G.qual & (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY)) { if(G.obedit->type==OB_MESH) select_non_manifold(); } } - else if((G.qual==0)){ + else if(G.qual & LR_CTRLKEY) { + mirrormenu(); + } + else if(G.qual==0) { movetolayer(); } break; diff --git a/source/blender/src/toolbox.c b/source/blender/src/toolbox.c index 738d575066b..921319da9ba 100644 --- a/source/blender/src/toolbox.c +++ b/source/blender/src/toolbox.c @@ -2048,6 +2048,12 @@ static void tb_do_transform(void *arg, int event) } } +static TBitem tb_transform_object_mirror[]= { +{ 0, "X Local|M, 1", 1, NULL}, +{ 0, "Y Local|M, 2", 2, NULL}, +{ 0, "Z Local|M, 3", 3, NULL}, +{ -1, "", 0, do_view3d_object_mirrormenu}}; + static TBitem tb_transform[]= { { 0, "Grab/Move|G", 0, NULL}, { 0, "Grab/Move on Axis| ", 0, tb_transform_moveaxis}, @@ -2056,13 +2062,15 @@ static TBitem tb_transform[]= { { 0, "Scale|S", 2, NULL}, { 0, "Scale on Axis", 0, tb_transform_scaleaxis}, { 0, "SEPR", 0, NULL}, +{ 0, "Mirror", 0, tb_transform_object_mirror}, +{ 0, "SEPR", 0, NULL}, { ICON_MENU_PANEL, "Properties|N", 3, NULL}, { 0, "Snap", 0, tb_transform_snap}, { 0, "SEPR", 0, NULL}, { 0, "Clear/Apply", 0, tb_transform_clearapply}, { -1, "", 0, tb_do_transform}}; -static TBitem tb_transform_mirror[]= { +static TBitem tb_transform_edit_mirror[]= { { 0, "X Global|M, 1", 1, NULL}, { 0, "Y Global|M, 2", 2, NULL}, { 0, "Z Global|M, 3", 3, NULL}, @@ -2074,7 +2082,7 @@ static TBitem tb_transform_mirror[]= { { 0, "X View|M, 7", 7, NULL}, { 0, "Y View|M, 8", 8, NULL}, { 0, "Z View|M, 9", 9, NULL}, -{ -1, "", 0, do_view3d_edit_mesh_mirrormenu}}; +{ -1, "", 0, do_view3d_edit_mirrormenu}}; static TBitem tb_transform_editmode1[]= { { 0, "Grab/Move|G", 'g', NULL}, @@ -2084,12 +2092,12 @@ static TBitem tb_transform_editmode1[]= { { 0, "Scale|S", 's', NULL}, { 0, "Scale on Axis", 0, tb_transform_scaleaxis}, { 0, "SEPR", 0, NULL}, -{ 0, "Mirror", 0, tb_transform_mirror}, +{ 0, "Mirror", 0, tb_transform_edit_mirror}, { 0, "Shrink/Fatten|Alt S", TB_ALT|'s', NULL}, { 0, "Shear|Ctrl S", TB_CTRL|'s', NULL}, { 0, "Warp|Shift W", 'W', NULL}, { 0, "SEPR", 0, NULL}, -{ ICON_MENU_PANEL, "Properties|n", 'n', NULL}, +{ ICON_MENU_PANEL, "Properties|N", 'N', NULL}, { 0, "Snap", 0, tb_transform_snap}, { 0, "SEPR", 0, NULL}, { 0, "Proportional Edit|O", 'o', NULL}, @@ -2104,7 +2112,7 @@ static TBitem tb_transform_editmode2[]= { { 0, "Scale|S", 2, NULL}, { 0, "Scale on Axis", 0, tb_transform_scaleaxis}, { 0, "SEPR", 0, NULL}, -{ ICON_MENU_PANEL, "Properties|n", 'n', NULL}, +{ ICON_MENU_PANEL, "Properties|N", 'N', NULL}, { 0, "Snap", 0, tb_transform_snap}, { -1, "", 0, tb_do_transform}}; |