1 #include "MEM_guardedalloc.h"
3 #include "BKE_utildefines.h"
6 #include "mesh_intern.h"
7 #include "bmesh_private.h"
8 #include "BLI_arithb.h"
16 void dissolvefaces_exec(BMesh *bm, BMOperator *op)
21 BMFace *f, *f2, *nf = NULL;
23 //BMO_Flag_Buffer(bm, op, BMOP_DISFACES_FACEIN, FACE_MARK);
25 /*TODO: need to discuss with Briggs how best to implement this, seems this would be
26 a great time to use the walker api, get it up to snuff. perhaps have a walker
27 that goes over inner vertices of a contiguously-flagged region? then you
28 could just use dissolve disk on them.*/
29 if (BMO_GetSlot(op, BMOP_DISFACES_FACEIN)->len != 2) return;
31 /*HACK: for debugging purposes, handle cases of two adjacent faces*/
32 f = BMO_IterNew(&iter, bm, op, BMOP_DISFACES_FACEIN);
33 f2 = BMO_IterStep(&iter);
35 for (l=BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);l;l=BMIter_Step(&liter)) {
36 if (!l->radial.next) continue;
37 if (((BMLoop*)l->radial.next->data)->f == f2) {
38 nf = BM_Join_Faces(bm, f, f2, l->e, 1, 0);
44 BMO_SetFlag(bm, nf, 1);
45 BMO_Flag_To_Slot(bm, op, BMOP_DISFACES_REGIONOUT, 1, BM_FACE);
50 /*returns 1 if any faces were dissolved*/
51 int BM_DissolveFaces(EditMesh *em, int flag) {
52 BMesh *bm = editmesh_to_bmesh(em);
56 BMO_Init_Op(&op, BMOP_DISSOLVE_FACES);
57 BMO_HeaderFlag_To_Slot(bm, &op, BMOP_DISFACES_FACEIN, flag, BM_FACE);
59 BMO_Finish_Op(bm, &op);
61 em2 = bmesh_to_editmesh(bm);
62 set_editMesh(em, em2);
65 return BMO_GetSlot(&op, BMOP_DISFACES_REGIONOUT)->len > 0;
68 void dissolveverts_exec(BMesh *bm, BMOperator *op)
71 BMIter iter, liter, fiter;
76 int found, found2, found3, len, oldlen=0;
78 vinput = BMO_GetSlot(op, BMOP_DISVERTS_VERTIN);
80 BMO_Flag_Buffer(bm, op, BMOP_DISVERTS_VERTIN, VERT_MARK);
86 for (v=BMIter_New(&iter, bm, BM_VERTS, NULL); v; v=BMIter_Step(&iter)) {
87 if (BMO_TestFlag(bm, v, VERT_MARK)) {
88 if (!BM_Dissolve_Vert(bm, v)) {
89 BMO_RaiseError(bm, op,
90 BMERR_DISSOLVEDISK_FAILED, NULL);
99 /*clean up two-edged faces*/
100 /*basic idea is to keep joining 2-edged faces until their
101 gone. this however relies on joining two 2-edged faces
102 together to work, which doesn't.*/
106 for (f=BMIter_New(&iter, bm, BM_FACES, NULL); f; f=BMIter_Step(&iter)){
107 if (BM_Validate_Face(bm, f, stderr)) {
112 //this design relies on join faces working
113 //with two-edged faces properly.
114 //commenting this line disables the
118 l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
120 for (; l; l=BMIter_Step(&liter)) {
121 f2 = BMIter_New(&fiter, bm,
122 BM_FACES_OF_EDGE, l->e);
123 for (; f2; f2=BMIter_Step(&fiter)) {
125 BM_Join_Faces(bm, f, f2, l->e,
138 } /*else if (f->len == 3) {
144 //check for duplicate edges
145 l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
146 for (; l; l=BMIter_Step(&liter)) {
151 if (vt[0] == vt[1] || vt[0] == vt[2]) {
157 if (oldlen == len) break;