Index: source/blender/bmesh/intern/bmesh_opdefines.c =================================================================== --- source/blender/bmesh/intern/bmesh_opdefines.c (revision 23139) +++ source/blender/bmesh/intern/bmesh_opdefines.c (working copy) @@ -747,6 +747,31 @@ 0 }; +/* +** color rotation +** cycle the colors +*/ +BMOpDefine def_meshrotatecolors = { + "meshrotatecolors", + {{BMOP_OPSLOT_ELEMENT_BUF, "faces"}, /* input faces */ + {BMOP_OPSLOT_INT, "dir"}, /* direction */ + {0} /*null-terminating sentinel*/}, + bmesh_rotatecolors_exec, + 0 +}; + +/* +** color reverse +** reverse the colors +*/ +BMOpDefine def_meshreversecolors = { + "meshreversecolors", + {{BMOP_OPSLOT_ELEMENT_BUF, "faces"}, /* input faces */ + {0} /*null-terminating sentinel*/}, + bmesh_reversecolors_exec, + 0 +}; + BMOpDefine *opdefines[] = { &def_splitop, &def_dupeop, @@ -796,6 +821,8 @@ &def_bmesh_to_mesh, &def_meshreverseuvs, &def_edgenet_prepare, + &def_meshrotatecolors, + &def_meshreversecolors, }; int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*)); Index: source/blender/bmesh/intern/bmesh_operators_private.h =================================================================== --- source/blender/bmesh/intern/bmesh_operators_private.h (revision 23139) +++ source/blender/bmesh/intern/bmesh_operators_private.h (working copy) @@ -55,5 +55,6 @@ void object_load_bmesh_exec(BMesh *bm, BMOperator *op); void bmesh_reverseuvs_exec(BMesh *bm, BMOperator *op); void bmesh_edgenet_prepare(BMesh *bm, BMOperator *op); - +void bmesh_rotatecolors_exec(BMesh *bm, BMOperator *op); +void bmesh_reversecolors_exec(BMesh *bm, BMOperator *op); #endif Index: source/blender/bmesh/operators/utils.c =================================================================== --- source/blender/bmesh/operators/utils.c (revision 23139) +++ source/blender/bmesh/operators/utils.c (working copy) @@ -1070,3 +1070,112 @@ V_FREE(uvs); } + +/****************************************************************************** +** Cycle colors for a face +******************************************************************************/ + +void bmesh_rotatecolors_exec(BMesh *bm, BMOperator *op) +{ + BMOIter fs_iter; /* selected faces iterator */ + BMFace *fs; /* current face */ + BMIter l_iter; /* iteration loop */ + int n; + + int dir = BMO_Get_Int(op, "dir"); + + BMO_ITER(fs, &fs_iter, bm, op, "faces", BM_FACE) { + if( CustomData_has_layer(&(bm->ldata), CD_MLOOPCOL) ) { + if( dir == DIRECTION_CW ) { /* same loops direction */ + BMLoop *lf; /* current face loops */ + MLoopCol *f_lcol; /* first face loop color */ + MLoopCol p_col; /* previous color */ + MLoopCol t_col; /* tmp color */ + + int n = 0; + BM_ITER(lf, &l_iter, bm, BM_LOOPS_OF_FACE, fs) { + /* current loop color is the previous loop color */ + MLoopCol *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL); + if( n == 0 ) { + f_lcol = luv; + p_col = *luv; + } else { + t_col = *luv; + *luv = p_col; + p_col = t_col; + } + n++; + } + + *f_lcol = p_col; + } else if( dir == DIRECTION_CCW ) { /* counter loop direction */ + BMLoop *lf; /* current face loops */ + MLoopCol *p_lcol; /*previous loop color */ + MLoopCol *lcol; + MLoopCol t_col; /* current color */ + + int n = 0; + BM_ITER(lf, &l_iter, bm, BM_LOOPS_OF_FACE, fs) { + /* previous loop color is the current loop color */ + lcol = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL); + if( n == 0 ) { + p_lcol = lcol; + t_col = *lcol; + } else { + *p_lcol = *lcol; + p_lcol = lcol; + } + n++; + } + + *lcol = t_col; + } + } + } +} + +/****************************************************************************** +** Reverse colors for a face +******************************************************************************/ + +void bmesh_reversecolors_exec(BMesh *bm, BMOperator *op) +{ + BMOIter fs_iter; /* selected faces iterator */ + BMFace *fs; /* current face */ + BMIter l_iter; /* iteration loop */ + V_DECLARE(cols); + MLoopCol *cols = NULL; + int max_vert_count = 0; + + + BMO_ITER(fs, &fs_iter, bm, op, "faces", BM_FACE) { + if( CustomData_has_layer(&(bm->ldata), CD_MLOOPCOL) ) { + BMLoop *lf; /* current face loops */ + MLoopCol *f_lcol; /* first face loop color */ + int num_verts = fs->len; + int i = 0; + + V_RESET(cols); + BM_ITER(lf, &l_iter, bm, BM_LOOPS_OF_FACE, fs) { + MLoopCol *lcol = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL); + + /* current loop uv is the previous loop color */ + V_GROW(cols); + cols[i] = *lcol; + 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 color */ + MLoopCol *lcol = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL); + *lcol = cols[(fs->len - i - 1)]; + i++; + } + } + } + + V_FREE(cols); +} + Index: source/blender/editors/mesh/mesh_ops.c =================================================================== --- source/blender/editors/mesh/mesh_ops.c (revision 23139) +++ source/blender/editors/mesh/mesh_ops.c (working copy) @@ -171,7 +171,8 @@ //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"); + //uiItemMenuEnumO(layout, NULL, 0, "MESH_OT_colors_mirror", "axis"); + uiItemO(layout, NULL, 0, "MESH_OT_colors_reverse"); uiPupMenuEnd(C, pup); @@ -291,7 +292,8 @@ //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); + //WM_operatortype_append(MESH_OT_colors_mirror); + WM_operatortype_append(MESH_OT_colors_reverse); WM_operatortype_append(MESH_OT_fill); WM_operatortype_append(MESH_OT_beauty_fill); @@ -441,7 +443,8 @@ //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); + //WM_keymap_add_item(keymap, "MESH_OT_colors_mirror",EIGHTKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "MESH_OT_colors_reverse",EIGHTKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "MESH_OT_rip_move",VKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MESH_OT_merge", MKEY, KM_PRESS, KM_ALT, 0); Index: source/blender/editors/mesh/bmesh_tools.c =================================================================== --- source/blender/editors/mesh/bmesh_tools.c (revision 23139) +++ source/blender/editors/mesh/bmesh_tools.c (working copy) @@ -2245,66 +2245,57 @@ static int mesh_rotate_colors(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; - MCol tmpcol, *mcol; - int dir= RNA_enum_get(op->ptr, "direction"); + /* get the direction from RNA */ + int dir = RNA_enum_get(op->ptr, "direction"); - if (!EM_vertColorCheck(em)) { - BKE_report(op->reports, RPT_ERROR, "Mesh has no color layers."); - BKE_mesh_end_editmesh(obedit->data, em); - return OPERATOR_CANCELLED; - } + /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ + EDBM_InitOpf(em, &bmop, op, "meshrotatecolors faces=%hf dir=%d", BM_SELECT, dir); - for(efa=em->faces.first; efa; efa=efa->next) { - if (efa->f & SELECT) { - mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL); - tmpcol= mcol[0]; + /* execute the operator */ + BMO_Exec_Op(em->bm, &bmop); - if (dir == DIRECTION_CCW) { - if(efa->v4) { - mcol[0]= mcol[3]; - mcol[3]= mcol[2]; - } else { - mcol[0]= mcol[2]; - } - mcol[2]= mcol[1]; - mcol[1]= tmpcol; - } else { - mcol[0]= mcol[1]; - mcol[1]= mcol[2]; - - if(efa->v4) { - mcol[2]= mcol[3]; - mcol[3]= tmpcol; - } - else - mcol[2]= tmpcol; - } - 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); + + /* we succeeded */ return OPERATOR_FINISHED; -#endif } -static int mesh_mirror_colors(bContext *C, wmOperator *op) +static int mesh_reverse_colors(bContext *C, wmOperator *op) { + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_edit_object(C); + BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh; + BMOperator bmop; + + /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ + EDBM_InitOpf(em, &bmop, op, "meshreversecolors faces=%hf", BM_SELECT); + + /* execute the operator */ + BMO_Exec_Op(em->bm, &bmop); + + /* finish the operator */ + if( !EDBM_FinishOp(em, &bmop, op, 1) ) + return OPERATOR_CANCELLED; + + /* 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); + + /* we succeeded */ + return OPERATOR_FINISHED; #if 0 Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); @@ -2413,21 +2404,21 @@ RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "Direction", "Direction to rotate edge around."); } -void MESH_OT_colors_mirror(wmOperatorType *ot) +void MESH_OT_colors_reverse(wmOperatorType *ot) { /* identifiers */ - ot->name= "Mirror Colors"; - ot->idname= "MESH_OT_colors_mirror"; + ot->name= "Reverse Colors"; + ot->idname= "MESH_OT_colors_reverse"; /* api callbacks */ - ot->exec= mesh_mirror_colors; + ot->exec= mesh_reverse_colors; 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 colors around."); + //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror colors around."); } Index: source/blender/editors/mesh/mesh_intern.h =================================================================== --- source/blender/editors/mesh/mesh_intern.h (revision 23139) +++ source/blender/editors/mesh/mesh_intern.h (working copy) @@ -281,8 +281,10 @@ //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); +//void MESH_OT_colors_mirror(struct wmOperatorType *ot); +void MESH_OT_colors_reverse(struct wmOperatorType *ot); + void MESH_OT_delete(struct wmOperatorType *ot); void MESH_OT_rip(struct wmOperatorType *ot);