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).
This commit is contained in:
@@ -259,6 +259,10 @@
|
||||
Filter="h;hpp;hxx;hm;inl"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
|
||||
@@ -1206,6 +1206,10 @@
|
||||
RelativePath="..\..\..\source\blender\editors\mesh\editmesh_tools.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\source\blender\editors\mesh\loopcut.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\source\blender\editors\mesh\mesh_intern.h"
|
||||
>
|
||||
|
||||
@@ -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*));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *ob = CTX_data_edit_object(C);
|
||||
BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh;
|
||||
BMOperator bmop;
|
||||
|
||||
EditFace *efa;
|
||||
short change = 0;
|
||||
MTFace *tf;
|
||||
float u1, v1;
|
||||
int axis= RNA_enum_get(op->ptr, "axis");
|
||||
/* 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);
|
||||
|
||||
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;
|
||||
}
|
||||
/* execute the operator */
|
||||
BMO_Exec_Op(em->bm, &bmop);
|
||||
|
||||
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];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
BKE_mesh_end_editmesh(obedit->data, em);
|
||||
|
||||
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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user