Mirror in object mode. Works like Mirror in edit mode but only works on local axis...
authorMartin Poirier <theeth@yahoo.com>
Sat, 24 Apr 2004 21:09:06 +0000 (21:09 +0000)
committerMartin Poirier <theeth@yahoo.com>
Sat, 24 Apr 2004 21:09:06 +0000 (21:09 +0000)
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.

source/blender/blenlib/BLI_arithb.h
source/blender/blenlib/intern/arithb.c
source/blender/include/BDR_editobject.h
source/blender/include/BSE_headerbuttons.h
source/blender/src/editobject.c
source/blender/src/header_view3d.c
source/blender/src/space.c
source/blender/src/toolbox.c

index 78f662ce67c551cbe6532180e8099192f62d78ce..5941d421d1670cd087783f82fbebc92faf55d679 100644 (file)
@@ -468,6 +468,11 @@ saacos(
        float 
 sasqrt(
        float fac
+);
+       void
+printvecf(
+       char *str,
+       float v[3]
 );
        float 
 Inpf(
index 61fe4358fa466b43a7e9e3ec1e99f34bb1ff147c..b3419bd92501f8e7e79613be111ed2ffd125656c 100644 (file)
@@ -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);
index df5def7a7e91b9bd4c55210f3d584a3d18a53a41..f376161cb7a8d2fa6c6800cab38629793823e437 100644 (file)
@@ -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 */
 
index ab0d3139bc0d7478bb4bb55d93f6ceee9c2c8e91..446df3e76475d8c348e99ef3a8f6810ab4294e8f 100644 (file)
@@ -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);
index 1d68cdc881568983a5b47092b4d0a492936b70b5..eec31290391ec6f03f2dea5a30e7ee0b5a4b23d9 100644 (file)
@@ -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*/
+       }
 }
 
index 889204e7ba9fa1d6190108393af336c7c361072e..fb1fa9e3cc86edcc9b7925f4012873b83fec7757 100644 (file)
 
 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, "");
index af369e3d9370b10cab5b285daab28c89a4395148..399aeb6c94baf3ac070936d46018daf7571f28c9 100644 (file)
@@ -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;
index 738d575066b608235fd802154f4ecdfb3dadc17a..921319da9ba1e1a0fdcd901d6bb2b8fcb479a815 100644 (file)
@@ -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}};