diff options
author | Joseph Eagar <joeedh@gmail.com> | 2009-09-12 11:08:57 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2009-09-12 11:08:57 +0400 |
commit | 186603c2ff1e41b75d9b9eee33b88fa804c75207 (patch) | |
tree | 892928286dd3d23267f8114c556c82ab5d42d36c | |
parent | bc7fb6f962e5d3dad621c9945b9a127e94708f76 (diff) |
commit of patch #19287 by Wael S Oraiby, implementing a reverse face uvs feature, which replaces mirror uvs (which didn't make any sense outside of quads).
-rw-r--r-- | projectfiles_vc9/blender/blender.vcproj | 4 | ||||
-rw-r--r-- | projectfiles_vc9/blender/editors/ED_editors.vcproj | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 13 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators_private.h | 1 | ||||
-rw-r--r-- | source/blender/bmesh/operators/utils.c | 46 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_tools.c | 180 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_ops.c | 9 |
8 files changed, 97 insertions, 163 deletions
diff --git a/projectfiles_vc9/blender/blender.vcproj b/projectfiles_vc9/blender/blender.vcproj index dc8d663469b..e7cd980b294 100644 --- a/projectfiles_vc9/blender/blender.vcproj +++ b/projectfiles_vc9/blender/blender.vcproj @@ -259,6 +259,10 @@ Filter="h;hpp;hxx;hm;inl"
>
</Filter>
+ <Filter
+ Name="Source Files"
+ >
+ </Filter>
</Files>
<Globals>
</Globals>
diff --git a/projectfiles_vc9/blender/editors/ED_editors.vcproj b/projectfiles_vc9/blender/editors/ED_editors.vcproj index e008c3fd6d3..8e82a18aa60 100644 --- a/projectfiles_vc9/blender/editors/ED_editors.vcproj +++ b/projectfiles_vc9/blender/editors/ED_editors.vcproj @@ -1207,6 +1207,10 @@ >
</File>
<File
+ RelativePath="..\..\..\source\blender\editors\mesh\loopcut.c"
+ >
+ </File>
+ <File
RelativePath="..\..\..\source\blender\editors\mesh\mesh_intern.h"
>
</File>
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 57bf4759e02..d297a95799d 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -717,6 +717,18 @@ BMOpDefine def_meshrotateuvs = { 0 }; +/* +** uv reverse +** reverse the uvs +*/ +BMOpDefine def_meshreverseuvs = { + "meshreverseuvs", + {{BMOP_OPSLOT_ELEMENT_BUF, "faces"}, /* input faces */ + {0} /*null-terminating sentinel*/}, + bmesh_reverseuvs_exec, + 0 +}; + BMOpDefine *opdefines[] = { &def_splitop, &def_dupeop, @@ -764,6 +776,7 @@ BMOpDefine *opdefines[] = { &def_vert_average_facedata, &def_meshrotateuvs, &def_bmesh_to_mesh, + &def_meshreverseuvs, }; int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*)); diff --git a/source/blender/bmesh/intern/bmesh_operators_private.h b/source/blender/bmesh/intern/bmesh_operators_private.h index a69ba7a2dbe..efdf6a6602e 100644 --- a/source/blender/bmesh/intern/bmesh_operators_private.h +++ b/source/blender/bmesh/intern/bmesh_operators_private.h @@ -53,5 +53,6 @@ void bmesh_pointmerge_facedata_exec(BMesh *bm, BMOperator *op); void bmesh_vert_average_facedata_exec(BMesh *bm, BMOperator *op); void bmesh_rotateuvs_exec(BMesh *bm, BMOperator *op); void object_load_bmesh_exec(BMesh *bm, BMOperator *op); +void bmesh_reverseuvs_exec(BMesh *bm, BMOperator *op); #endif diff --git a/source/blender/bmesh/operators/utils.c b/source/blender/bmesh/operators/utils.c index 99c03e5a0bf..c8fb5a2907b 100644 --- a/source/blender/bmesh/operators/utils.c +++ b/source/blender/bmesh/operators/utils.c @@ -1024,3 +1024,49 @@ void bmesh_rotateuvs_exec(BMesh *bm, BMOperator *op) } } + +/****************************************************************************** +** Reverse UVs for a face +******************************************************************************/ + +void bmesh_reverseuvs_exec(BMesh *bm, BMOperator *op) +{ + BMOIter fs_iter; /* selected faces iterator */ + BMFace *fs; /* current face */ + BMIter l_iter; /* iteration loop */ + V_DECLARE(uvs); + float (*uvs)[2] = NULL; + int max_vert_count = 0; + + BMO_ITER(fs, &fs_iter, bm, op, "faces", BM_FACE) { + if( CustomData_has_layer(&(bm->ldata), CD_MLOOPUV) ) { + BMLoop *lf; /* current face loops */ + MLoopUV *f_luv; /* first face loop uv */ + int num_verts = fs->len; + int i = 0; + + V_RESET(uvs); + BM_ITER(lf, &l_iter, bm, BM_LOOPS_OF_FACE, fs) { + MLoopUV *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPUV); + + /* current loop uv is the previous loop uv */ + V_GROW(uvs); + uvs[i][0] = luv->uv[0]; + uvs[i][1] = luv->uv[1]; + i++; + } + + /* now that we have the uvs in the array, reverse! */ + i = 0; + BM_ITER(lf, &l_iter, bm, BM_LOOPS_OF_FACE, fs) { + /* current loop uv is the previous loop uv */ + MLoopUV *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPUV); + luv->uv[0] = uvs[(fs->len - i - 1)][0]; + luv->uv[1] = uvs[(fs->len - i - 1)][1]; + i++; + } + } + } + + V_FREE(uvs); +} diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index 780c65f921b..eb369531e03 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -2216,169 +2216,30 @@ static int mesh_rotate_uvs(bContext *C, wmOperator *op) /* we succeeded */ return OPERATOR_FINISHED; -#if 0 - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); - - EditFace *efa; - short change = 0; - MTFace *tf; - float u1, v1; - int dir= RNA_enum_get(op->ptr, "direction"); - - if (!EM_texFaceCheck(em)) { - BKE_report(op->reports, RPT_ERROR, "Mesh has no uv/image layers."); - BKE_mesh_end_editmesh(obedit->data, em); - return OPERATOR_CANCELLED; - } - - for(efa=em->faces.first; efa; efa=efa->next) { - if (efa->f & SELECT) { - tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - u1= tf->uv[0][0]; - v1= tf->uv[0][1]; - - if (dir == DIRECTION_CCW) { - if(efa->v4) { - tf->uv[0][0]= tf->uv[3][0]; - tf->uv[0][1]= tf->uv[3][1]; - - tf->uv[3][0]= tf->uv[2][0]; - tf->uv[3][1]= tf->uv[2][1]; - } else { - tf->uv[0][0]= tf->uv[2][0]; - tf->uv[0][1]= tf->uv[2][1]; - } - - tf->uv[2][0]= tf->uv[1][0]; - tf->uv[2][1]= tf->uv[1][1]; - - tf->uv[1][0]= u1; - tf->uv[1][1]= v1; - } else { - tf->uv[0][0]= tf->uv[1][0]; - tf->uv[0][1]= tf->uv[1][1]; - - tf->uv[1][0]= tf->uv[2][0]; - tf->uv[1][1]= tf->uv[2][1]; - - if(efa->v4) { - tf->uv[2][0]= tf->uv[3][0]; - tf->uv[2][1]= tf->uv[3][1]; - - tf->uv[3][0]= u1; - tf->uv[3][1]= v1; - } - else { - tf->uv[2][0]= u1; - tf->uv[2][1]= v1; - } - } - change = 1; - } - } - - BKE_mesh_end_editmesh(obedit->data, em); - - if(!change) - return OPERATOR_CANCELLED; - - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); -#endif - return OPERATOR_FINISHED; } -static int mesh_mirror_uvs(bContext *C, wmOperator *op) +static int mesh_reverse_uvs(bContext *C, wmOperator *op) { -#if 0 - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); - - EditFace *efa; - short change = 0; - MTFace *tf; - float u1, v1; - int axis= RNA_enum_get(op->ptr, "axis"); - - if (!EM_texFaceCheck(em)) { - BKE_report(op->reports, RPT_ERROR, "Mesh has no uv/image layers."); - BKE_mesh_end_editmesh(obedit->data, em); - return OPERATOR_CANCELLED; - } - - for(efa=em->faces.first; efa; efa=efa->next) { - if (efa->f & SELECT) { - tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - if (axis == AXIS_Y) { - u1= tf->uv[1][0]; - v1= tf->uv[1][1]; - if(efa->v4) { - - tf->uv[1][0]= tf->uv[2][0]; - tf->uv[1][1]= tf->uv[2][1]; - - tf->uv[2][0]= u1; - tf->uv[2][1]= v1; - - u1= tf->uv[3][0]; - v1= tf->uv[3][1]; - - tf->uv[3][0]= tf->uv[0][0]; - tf->uv[3][1]= tf->uv[0][1]; - - tf->uv[0][0]= u1; - tf->uv[0][1]= v1; - } - else { - tf->uv[1][0]= tf->uv[2][0]; - tf->uv[1][1]= tf->uv[2][1]; - tf->uv[2][0]= u1; - tf->uv[2][1]= v1; - } - - } else { - u1= tf->uv[0][0]; - v1= tf->uv[0][1]; - if(efa->v4) { - - tf->uv[0][0]= tf->uv[1][0]; - tf->uv[0][1]= tf->uv[1][1]; - - tf->uv[1][0]= u1; - tf->uv[1][1]= v1; - - u1= tf->uv[3][0]; - v1= tf->uv[3][1]; - - tf->uv[3][0]= tf->uv[2][0]; - tf->uv[3][1]= tf->uv[2][1]; + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMOperator bmop; - tf->uv[2][0]= u1; - tf->uv[2][1]= v1; - } - else { - tf->uv[0][0]= tf->uv[1][0]; - tf->uv[0][1]= tf->uv[1][1]; - tf->uv[1][0]= u1; - tf->uv[1][1]= v1; - } - } - change = 1; - } - } + /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ + EDBM_InitOpf(em, &bmop, op, "meshreverseuvs faces=%hf", BM_SELECT); - BKE_mesh_end_editmesh(obedit->data, em); + /* execute the operator */ + BMO_Exec_Op(em->bm, &bmop); - if(!change) + /* finish the operator */ + if( !EDBM_FinishOp(em, &bmop, op, 1) ) return OPERATOR_CANCELLED; - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + /* dependencies graph and notification stuff */ + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT | ND_GEOM_SELECT, ob); -#endif + /* we succeeded */ return OPERATOR_FINISHED; } @@ -2517,21 +2378,22 @@ void MESH_OT_uvs_rotate(wmOperatorType *ot) RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "Direction", "Direction to rotate UVs around."); } -void MESH_OT_uvs_mirror(wmOperatorType *ot) +//void MESH_OT_uvs_mirror(wmOperatorType *ot) +void MESH_OT_uvs_reverse(wmOperatorType *ot) { /* identifiers */ - ot->name= "Mirror UVs"; - ot->idname= "MESH_OT_uvs_mirror"; + ot->name= "Reverse UVs"; + ot->idname= "MESH_OT_uvs_reverse"; /* api callbacks */ - ot->exec= mesh_mirror_uvs; + ot->exec= mesh_reverse_uvs; ot->poll= ED_operator_editmesh; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ - RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror UVs around."); + //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror UVs around."); } void MESH_OT_colors_rotate(wmOperatorType *ot) diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 37803d4c00a..ec7383a9bd0 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -278,7 +278,8 @@ void MESH_OT_loop_to_region(struct wmOperatorType *ot); void MESH_OT_region_to_loop(struct wmOperatorType *ot); void MESH_OT_uvs_rotate(struct wmOperatorType *ot); -void MESH_OT_uvs_mirror(struct wmOperatorType *ot); +//void MESH_OT_uvs_mirror(struct wmOperatorType *ot); +void MESH_OT_uvs_reverse(struct wmOperatorType *ot); void MESH_OT_colors_rotate(struct wmOperatorType *ot); void MESH_OT_colors_mirror(struct wmOperatorType *ot); diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 9570ae16a4b..3d42b958d18 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -168,7 +168,8 @@ static int face_specials_invoke(bContext *C, wmOperator *op, wmEvent *event) // uiItemS(layout); uiItemMenuEnumO(layout, NULL, 0, "MESH_OT_uvs_rotate", "direction"); - uiItemMenuEnumO(layout, NULL, 0, "MESH_OT_uvs_mirror", "axis"); + //uiItemMenuEnumO(layout, NULL, 0, "MESH_OT_uvs_mirror", "axis"); + uiItemO(layout, NULL, 0, "MESH_OT_uvs_reverse"); uiItemMenuEnumO(layout, NULL, 0, "MESH_OT_colors_rotate", "direction"); uiItemMenuEnumO(layout, NULL, 0, "MESH_OT_colors_mirror", "axis"); @@ -287,7 +288,8 @@ void ED_operatortypes_mesh(void) WM_operatortype_append(MESH_OT_region_to_loop); WM_operatortype_append(MESH_OT_uvs_rotate); - WM_operatortype_append(MESH_OT_uvs_mirror); + //WM_operatortype_append(MESH_OT_uvs_mirror); + WM_operatortype_append(MESH_OT_uvs_reverse); WM_operatortype_append(MESH_OT_colors_rotate); WM_operatortype_append(MESH_OT_colors_mirror); @@ -436,7 +438,8 @@ void ED_keymap_mesh(wmWindowManager *wm) WM_keymap_add_item(keymap, "MESH_OT_region_to_loop",SIXKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "MESH_OT_uvs_rotate",SEVENKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "MESH_OT_uvs_mirror",SEVENKEY, KM_PRESS, KM_ALT, 0); + //WM_keymap_add_item(keymap, "MESH_OT_uvs_mirror",SEVENKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "MESH_OT_uvs_reverse",SEVENKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "MESH_OT_colors_rotate",EIGHTKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "MESH_OT_colors_mirror",EIGHTKEY, KM_PRESS, KM_ALT, 0); |