diff options
-rw-r--r-- | source/blender/bmesh/intern/bmesh_delete.c | 224 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_delete.h | 6 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_dupe.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_removedoubles.c | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_skin.c | 15 |
5 files changed, 222 insertions, 27 deletions
diff --git a/source/blender/bmesh/intern/bmesh_delete.c b/source/blender/bmesh/intern/bmesh_delete.c index 195217cb03c..42b1c09b7ef 100644 --- a/source/blender/bmesh/intern/bmesh_delete.c +++ b/source/blender/bmesh/intern/bmesh_delete.c @@ -38,6 +38,13 @@ #include "bmesh.h" #include "intern/bmesh_private.h" + +/* -------------------------------------------------------------------- */ +/* BMO functions */ + +/** \name BMesh Operator Delete Functions + * \{ */ + /** * Called by operators to remove elements that they have marked for * removal. @@ -78,21 +85,40 @@ static void bmo_remove_tagged_verts(BMesh *bm, const short oflag) } } -#define DEL_WIREVERT (1 << 10) +static void bmo_remove_tagged_verts_loose(BMesh *bm, const short oflag) +{ + BMVert *v, *v_next; + BMIter iter; + + BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { + if (BMO_elem_flag_test(bm, v, oflag) && (v->e == NULL)) { + BM_vert_kill(bm, v); + } + } +} + +void BMO_mesh_delete_oflag_tagged(BMesh *bm, const short oflag, const char htype) +{ + if (htype & BM_FACE) { + bmo_remove_tagged_faces(bm, oflag); + } + if (htype & BM_EDGE) { + bmo_remove_tagged_edges(bm, oflag); + } + if (htype & BM_VERT) { + bmo_remove_tagged_verts(bm, oflag); + } +} /** * \warning oflag applies to different types in some contexts, * not just the type being removed. - * - * \warning take care, uses operator flag DEL_WIREVERT */ -void BMO_remove_tagged_context(BMesh *bm, const short oflag, const int type) +void BMO_mesh_delete_oflag_context(BMesh *bm, const short oflag, const int type) { - BMVert *v; BMEdge *e; BMFace *f; - BMIter viter; BMIter eiter; BMIter fiter; @@ -113,12 +139,7 @@ void BMO_remove_tagged_context(BMesh *bm, const short oflag, const int type) } } bmo_remove_tagged_edges(bm, oflag); - /* remove loose vertice */ - BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) { - if (BMO_elem_flag_test(bm, v, oflag) && (!(v->e))) - BMO_elem_flag_enable(bm, v, DEL_WIREVERT); - } - bmo_remove_tagged_verts(bm, DEL_WIREVERT); + bmo_remove_tagged_verts_loose(bm, oflag); break; } @@ -136,9 +157,7 @@ void BMO_remove_tagged_context(BMesh *bm, const short oflag, const int type) } case DEL_ONLYTAGGED: { - bmo_remove_tagged_faces(bm, oflag); - bmo_remove_tagged_edges(bm, oflag); - bmo_remove_tagged_verts(bm, oflag); + BMO_mesh_delete_oflag_tagged(bm, oflag, BM_ALL_NOLOOP); break; } @@ -188,3 +207,178 @@ void BMO_remove_tagged_context(BMesh *bm, const short oflag, const int type) } } } + +/** \} */ + + +/* -------------------------------------------------------------------- */ +/* BM functions + * + * note! this is just a duplicate of the code above (bad!) + * but for now keep in sync, its less hassle then having to create bmesh operator flags, + * each time we need to remove some geometry. + */ + +/** \name BMesh Delete Functions (no oflags) + * \{ */ + +static void bm_remove_tagged_faces(BMesh *bm, const char hflag) +{ + BMFace *f, *f_next; + BMIter iter; + + BM_ITER_MESH_MUTABLE (f, f_next, &iter, bm, BM_FACES_OF_MESH) { + if (BM_elem_flag_test(f, hflag)) { + BM_face_kill(bm, f); + } + } +} + +static void bm_remove_tagged_edges(BMesh *bm, const char hflag) +{ + BMEdge *e, *e_next; + BMIter iter; + + BM_ITER_MESH_MUTABLE (e, e_next, &iter, bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(e, hflag)) { + BM_edge_kill(bm, e); + } + } +} + +static void bm_remove_tagged_verts(BMesh *bm, const char hflag) +{ + BMVert *v, *v_next; + BMIter iter; + + BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { + if (BM_elem_flag_test(v, hflag)) { + BM_vert_kill(bm, v); + } + } +} + +static void bm_remove_tagged_verts_loose(BMesh *bm, const char hflag) +{ + BMVert *v, *v_next; + BMIter iter; + + BM_ITER_MESH_MUTABLE (v, v_next, &iter, bm, BM_VERTS_OF_MESH) { + if (BM_elem_flag_test(v, hflag) && (v->e == NULL)) { + BM_vert_kill(bm, v); + } + } +} + +void BM_mesh_delete_hflag_tagged(BMesh *bm, const char hflag, const char htype) +{ + if (htype & BM_FACE) { + bm_remove_tagged_faces(bm, hflag); + } + if (htype & BM_EDGE) { + bm_remove_tagged_edges(bm, hflag); + } + if (htype & BM_VERT) { + bm_remove_tagged_verts(bm, hflag); + } +} + +/** + * \warning oflag applies to different types in some contexts, + * not just the type being removed. + */ +void BM_mesh_delete_hflag_context(BMesh *bm, const char hflag, const int type) +{ + BMEdge *e; + BMFace *f; + + BMIter eiter; + BMIter fiter; + + switch (type) { + case DEL_VERTS: + { + bm_remove_tagged_verts(bm, hflag); + + break; + } + case DEL_EDGES: + { + /* flush down to vert */ + BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(e, hflag)) { + BM_elem_flag_enable(e->v1, hflag); + BM_elem_flag_enable(e->v2, hflag); + } + } + bm_remove_tagged_edges(bm, hflag); + bm_remove_tagged_verts_loose(bm, hflag); + + break; + } + case DEL_EDGESFACES: + { + bm_remove_tagged_edges(bm, hflag); + + break; + } + case DEL_ONLYFACES: + { + bm_remove_tagged_faces(bm, hflag); + + break; + } + case DEL_ONLYTAGGED: + { + BM_mesh_delete_hflag_tagged(bm, hflag, BM_ALL_NOLOOP); + + break; + } + case DEL_FACES: + { + /* go through and mark all edges and all verts of all faces for delete */ + BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { + if (BM_elem_flag_test(f, hflag)) { + BMLoop *l_first = BM_FACE_FIRST_LOOP(f); + BMLoop *l_iter; + + l_iter = l_first; + do { + BM_elem_flag_enable(l_iter->v, hflag); + BM_elem_flag_enable(l_iter->e, hflag); + } while ((l_iter = l_iter->next) != l_first); + } + } + /* now go through and mark all remaining faces all edges for keeping */ + BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { + if (!BM_elem_flag_test(f, hflag)) { + BMLoop *l_first = BM_FACE_FIRST_LOOP(f); + BMLoop *l_iter; + + l_iter = l_first; + do { + BM_elem_flag_disable(l_iter->v, hflag); + BM_elem_flag_disable(l_iter->e, hflag); + } while ((l_iter = l_iter->next) != l_first); + } + } + /* also mark all the vertices of remaining edges for keeping */ + BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { + if (!BM_elem_flag_test(e, hflag)) { + BM_elem_flag_disable(e->v1, hflag); + BM_elem_flag_disable(e->v2, hflag); + } + } + /* now delete marked face */ + bm_remove_tagged_faces(bm, hflag); + /* delete marked edge */ + bm_remove_tagged_edges(bm, hflag); + /* remove loose vertice */ + bm_remove_tagged_verts(bm, hflag); + + break; + } + } +} + +/** \} */ diff --git a/source/blender/bmesh/intern/bmesh_delete.h b/source/blender/bmesh/intern/bmesh_delete.h index de0162e7c3d..a876819dd40 100644 --- a/source/blender/bmesh/intern/bmesh_delete.h +++ b/source/blender/bmesh/intern/bmesh_delete.h @@ -27,6 +27,10 @@ * \ingroup bmesh */ -void BMO_remove_tagged_context(BMesh *bm, const short oflag, const int type); +void BMO_mesh_delete_oflag_tagged(BMesh *bm, const short oflag, const char htype); +void BM_mesh_delete_hflag_tagged(BMesh *bm, const char hflag, const char htype); + +void BMO_mesh_delete_oflag_context(BMesh *bm, const short oflag, const int type); +void BM_mesh_delete_hflag_context(BMesh *bm, const char hflag, const int type); #endif /* __BMESH_DELETE_H__ */ diff --git a/source/blender/bmesh/operators/bmo_dupe.c b/source/blender/bmesh/operators/bmo_dupe.c index a5c34f7623b..794c688b26b 100644 --- a/source/blender/bmesh/operators/bmo_dupe.c +++ b/source/blender/bmesh/operators/bmo_dupe.c @@ -451,7 +451,7 @@ void bmo_delete_exec(BMesh *bm, BMOperator *op) /* Mark Buffer */ BMO_slot_buffer_flag_enable(bm, delop->slots_in, "geom", BM_ALL_NOLOOP, DEL_INPUT); - BMO_remove_tagged_context(bm, DEL_INPUT, BMO_slot_int_get(op->slots_in, "context")); + BMO_mesh_delete_oflag_context(bm, DEL_INPUT, BMO_slot_int_get(op->slots_in, "context")); #undef DEL_INPUT } diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index a771e05acfc..beabca28276 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -208,7 +208,7 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) } } - BMO_op_callf(bm, op->flag, "delete geom=%fvef context=%i", ELE_DEL, DEL_ONLYTAGGED); + BMO_mesh_delete_oflag_context(bm, ELE_DEL, DEL_ONLYTAGGED); BLI_array_free(edges); BLI_array_free(loops); diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index a031cd10ca8..73297c00084 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -311,10 +311,10 @@ static int build_hull(SkinOutput *so, Frame **frames, int totframe) /* Check if removing triangles above will create wire triangles, * mark them too */ BMO_ITER (e, &oiter, op.slots_out, "geom.out", BM_EDGE) { - int is_wire = TRUE; + bool is_wire = true; BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) { if (!BM_elem_flag_test(f, BM_ELEM_TAG)) { - is_wire = FALSE; + is_wire = false; break; } } @@ -324,9 +324,7 @@ static int build_hull(SkinOutput *so, Frame **frames, int totframe) BMO_op_finish(bm, &op); - BMO_op_callf(bm, BMO_FLAG_DEFAULTS, - "delete geom=%hef context=%i", - BM_ELEM_TAG, DEL_ONLYTAGGED); + BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_ONLYTAGGED); return TRUE; } @@ -1426,11 +1424,10 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd) } } - BMO_op_callf(so->bm, BMO_FLAG_DEFAULTS, - "delete geom=%hef context=%i", - BM_ELEM_TAG, DEL_ONLYTAGGED); - BLI_heap_free(heap, NULL); + + BM_mesh_delete_hflag_context(so->bm, BM_ELEM_TAG, DEL_ONLYTAGGED); + } static void skin_merge_close_frame_verts(SkinNode *skin_nodes, int totvert, |