From 2f32c8451cf3afb2fbac412a43e39a29054a3dc5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 11 Aug 2005 00:00:24 +0000 Subject: [PATCH] New "Mirror UVs" function in faceselect mode, to complement Rotate UVs. It mirrors the UVs or Vertex Colors of individual faces (on the red edge of the UV face). Patch provided by Martin Poirier, thanks! --- source/blender/include/BDR_editface.h | 1 + source/blender/src/editface.c | 73 +++++++++++++++++++++++++++ source/blender/src/header_view3d.c | 4 ++ source/blender/src/space.c | 4 +- 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/source/blender/include/BDR_editface.h b/source/blender/include/BDR_editface.h index 7eaf47d15d8..85ba851d6bb 100644 --- a/source/blender/include/BDR_editface.h +++ b/source/blender/include/BDR_editface.h @@ -47,6 +47,7 @@ void select_linked_tfaces(int mode); void deselectall_tface(void); void selectswap_tface(void); void rotate_uv_tface(void); +void mirror_uv_tface(void); void minmax_tface(float *min, float *max); int face_pick(struct Mesh *me, short x, short y, unsigned int *index); void face_select(void); diff --git a/source/blender/src/editface.c b/source/blender/src/editface.c index 845d371eec6..6a7a8bb4d73 100644 --- a/source/blender/src/editface.c +++ b/source/blender/src/editface.c @@ -892,6 +892,79 @@ void rotate_uv_tface() allqueue(REDRAWIMAGE, 0); } +void mirror_uv_tface() +{ + Mesh *me; + TFace *tface; + MFace *mface; + short mode; + int a; + + me= get_mesh(OBACT); + if(me==0 || me->tface==0) return; + + mode= pupmenu("Mirror %t|UV Co-ordinates %x1|Vertex Colors %x2"); + + if(mode<1) return; + + tface= me->tface; + mface= me->mface; + a= me->totface; + while(a--) { + if(tface->flag & TF_SELECT) { + if(mode==1) { + float u1= tface->uv[0][0]; + float v1= tface->uv[0][1]; + if(mface->v4) { + tface->uv[0][0]= tface->uv[3][0]; + tface->uv[0][1]= tface->uv[3][1]; + + tface->uv[3][0]= u1; + tface->uv[3][1]= v1; + + u1= tface->uv[1][0]; + v1= tface->uv[1][1]; + + tface->uv[1][0]= tface->uv[2][0]; + tface->uv[1][1]= tface->uv[2][1]; + + tface->uv[2][0]= u1; + tface->uv[2][1]= v1; + } + else { + tface->uv[0][0]= tface->uv[2][0]; + tface->uv[0][1]= tface->uv[2][1]; + tface->uv[2][0]= u1; + tface->uv[2][1]= v1; + } + } + else if(mode==2) { + unsigned int tcol= tface->col[0]; + if(mface->v4) { + tface->col[0]= tface->col[3]; + tface->col[3]= tcol; + + tcol = tface->col[1]; + tface->col[1]= tface->col[2]; + tface->col[2]= tcol; + } + else { + tface->col[0]= tface->col[2]; + tface->col[2]= tcol; + } + } + } + tface++; + mface++; + } + + BIF_undo_push("Mirror UV face"); + DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA); + + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWIMAGE, 0); +} + void minmax_tface(float *min, float *max) { Object *ob; diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c index 2a785ead481..ccf64b40452 100644 --- a/source/blender/src/header_view3d.c +++ b/source/blender/src/header_view3d.c @@ -3531,6 +3531,9 @@ static void do_view3d_faceselmenu(void *arg, int event) case 7: /* rotate UVs */ rotate_uv_tface(); break; + case 9: /* mirror UVs */ + mirror_uv_tface(); + break; } allqueue(REDRAWVIEW3D, 0); @@ -3554,6 +3557,7 @@ static uiBlock *view3d_faceselmenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unwrap UVs|U", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rotate UVs|R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Mirror UVs|M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, ""); uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 0757a1c1a73..d552a102ef3 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -1394,7 +1394,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) } break; case MKEY: - if(G.obedit){ + if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0)) + mirror_uv_tface(); + else if(G.obedit){ if(G.qual==LR_ALTKEY) { if(G.obedit->type==OB_MESH) { mergemenu();