From 53d08ec50634e88eb67339333f9c13cfae03f85d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 2 May 2015 16:05:32 +1000 Subject: BMesh: BM_mesh_edgesplit Did quite a few checks not to tag bad splits (which wasn't working perfectly) Instead rely on BM_vert_separate not to create invalid geometry. --- source/blender/bmesh/operators/bmo_split_edges.c | 2 +- source/blender/bmesh/tools/bmesh_edgesplit.c | 117 ++--------------------- source/blender/bmesh/tools/bmesh_edgesplit.h | 2 +- source/blender/bmesh/tools/bmesh_intersect.c | 2 +- source/blender/editors/mesh/editmesh_rip.c | 2 +- source/blender/modifiers/intern/MOD_edgesplit.c | 2 +- 6 files changed, 13 insertions(+), 114 deletions(-) (limited to 'source') diff --git a/source/blender/bmesh/operators/bmo_split_edges.c b/source/blender/bmesh/operators/bmo_split_edges.c index ca2088339cf..eb7946caff0 100644 --- a/source/blender/bmesh/operators/bmo_split_edges.c +++ b/source/blender/bmesh/operators/bmo_split_edges.c @@ -48,7 +48,7 @@ void bmo_split_edges_exec(BMesh *bm, BMOperator *op) } /* this is where everything happens */ - BM_mesh_edgesplit(bm, use_verts, true, true, false); + BM_mesh_edgesplit(bm, use_verts, true, false); BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_INTERNAL_TAG); } diff --git a/source/blender/bmesh/tools/bmesh_edgesplit.c b/source/blender/bmesh/tools/bmesh_edgesplit.c index 50be4e21f24..74b1660080b 100644 --- a/source/blender/bmesh/tools/bmesh_edgesplit.c +++ b/source/blender/bmesh/tools/bmesh_edgesplit.c @@ -35,74 +35,6 @@ #include "bmesh_edgesplit.h" /* own include */ - -/** - * Remove the BM_ELEM_TAG flag for edges we cant split - * - * un-tag edges not connected to other tagged edges, - * unless they are on a boundary - */ -static void bm_edgesplit_validate_seams(BMesh *bm, const bool use_non_manifold) -{ - BMIter iter; - BMEdge *e; - - unsigned char *vtouch; - - BM_mesh_elem_index_ensure(bm, BM_VERT); - - vtouch = MEM_callocN(sizeof(char) * bm->totvert, __func__); - - /* tag all boundary verts so as not to untag an edge which is inbetween only 2 faces [] */ - BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - - /* unrelated to flag assignment in this function - since this is the - * only place we loop over all edges, disable tag */ - BM_elem_flag_disable(e, BM_ELEM_INTERNAL_TAG); - - if (e->l == NULL) { - BM_elem_flag_disable(e, BM_ELEM_TAG); - } - else if (BM_edge_is_boundary(e)) { - unsigned char *vt; - vt = &vtouch[BM_elem_index_get(e->v1)]; if (*vt < 2) (*vt)++; - vt = &vtouch[BM_elem_index_get(e->v2)]; if (*vt < 2) (*vt)++; - - /* while the boundary verts need to be tagged, - * the edge its self can't be split */ - BM_elem_flag_disable(e, BM_ELEM_TAG); - } - else if ((use_non_manifold == false) && - (BM_edge_is_manifold(e) == false)) - { - BM_elem_flag_disable(e, BM_ELEM_TAG); - } - } - - /* single marked edges unconnected to any other marked edges - * are illegal, go through and unmark them */ - BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_TAG)) { - /* lame, but we don't want the count to exceed 255, - * so just count to 2, its all we need */ - unsigned char *vt; - vt = &vtouch[BM_elem_index_get(e->v1)]; if (*vt < 2) (*vt)++; - vt = &vtouch[BM_elem_index_get(e->v2)]; if (*vt < 2) (*vt)++; - } - } - BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_TAG)) { - if (vtouch[BM_elem_index_get(e->v1)] == 1 && - vtouch[BM_elem_index_get(e->v2)] == 1) - { - BM_elem_flag_disable(e, BM_ELEM_TAG); - } - } - } - - MEM_freeN(vtouch); -} - /** * \param use_verts Use flagged verts instead of edges. * \param use_non_manifold Split non-manifold edges (a little slower, must check for doubles). @@ -111,7 +43,7 @@ static void bm_edgesplit_validate_seams(BMesh *bm, const bool use_non_manifold) */ void BM_mesh_edgesplit( BMesh *bm, - const bool use_verts, const bool use_non_manifold, + const bool use_verts, const bool tag_only, const bool copy_select) { BMIter iter; @@ -156,27 +88,8 @@ void BM_mesh_edgesplit( } } - bm_edgesplit_validate_seams(bm, use_non_manifold); - BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(e, BM_ELEM_TAG)) { - /* this flag gets copied so we can be sure duplicate edges get it too (important) */ - BM_elem_flag_enable(e, BM_ELEM_INTERNAL_TAG); - - /* keep splitting until each loop has its own edge */ - while (!BM_edge_is_boundary(e)) { - BMLoop *l_sep = e->l; - bmesh_edge_separate(bm, e, l_sep, copy_select); - BLI_assert(l_sep->e != e); - - if (use_ese) { - BMEditSelection *ese = BLI_ghash_lookup(ese_gh, e); - if (UNLIKELY(ese)) { - BM_select_history_store_after_notest(bm, ese, l_sep->e); - } - } - } - BM_elem_flag_enable(e->v1, BM_ELEM_TAG); BM_elem_flag_enable(e->v2, BM_ELEM_TAG); } @@ -194,7 +107,7 @@ void BM_mesh_edgesplit( BMVert **vtar; int vtar_len; - bmesh_vert_separate(bm, v, &vtar, &vtar_len, copy_select); + BM_vert_separate_hflag(bm, v, BM_ELEM_TAG, copy_select, &vtar, &vtar_len); /* first value is always in 'v' */ if (vtar_len > 1) { @@ -211,35 +124,21 @@ void BM_mesh_edgesplit( MEM_freeN(vtar); } else { - bmesh_vert_separate(bm, v, NULL, NULL, copy_select); + BM_vert_separate_hflag(bm, v, BM_ELEM_TAG, copy_select, NULL, NULL); } } } } } - if (use_non_manifold) { - /* if we split non-manifold, double edge may remain */ - BMEdge *e_next; - BM_ITER_MESH_MUTABLE (e, e_next, &iter, bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_TAG)) { - BMEdge *e_other; - if ((e_other = BM_edge_find_double(e))) { - BM_edge_splice(bm, e_other, e); - } - } - } - } - else { #ifndef NDEBUG - /* ensure we don't have any double edges! */ - BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_TAG)) { - BLI_assert(BM_edge_find_double(e) == NULL); - } + /* ensure we don't have any double edges! */ + BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(e, BM_ELEM_TAG)) { + BLI_assert(BM_edge_find_double(e) == NULL); } -#endif } +#endif if (use_ese) { BLI_ghash_free(ese_gh, NULL, NULL); diff --git a/source/blender/bmesh/tools/bmesh_edgesplit.h b/source/blender/bmesh/tools/bmesh_edgesplit.h index 531af964a99..26040077f43 100644 --- a/source/blender/bmesh/tools/bmesh_edgesplit.h +++ b/source/blender/bmesh/tools/bmesh_edgesplit.h @@ -29,7 +29,7 @@ void BM_mesh_edgesplit( BMesh *bm, - const bool use_verts, const bool use_non_manifold, + const bool use_verts, const bool tag_only, const bool copy_select); #endif /* __BMESH_EDGESPLIT_H__ */ diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c index 98ebd2e854b..fc12bce8563 100644 --- a/source/blender/bmesh/tools/bmesh_intersect.c +++ b/source/blender/bmesh/tools/bmesh_intersect.c @@ -1281,7 +1281,7 @@ bool BM_mesh_intersect( BM_elem_flag_enable(e, BM_ELEM_TAG); } - BM_mesh_edgesplit(bm, false, false, true, false); + BM_mesh_edgesplit(bm, false, true, false); } #else (void)use_separate; diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 05bd677ba6f..cc462bb75a8 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -941,7 +941,7 @@ static int edbm_rip_invoke__edge(bContext *C, wmOperator *op, const wmEvent *eve fill_uloop_pairs = edbm_tagged_loop_pairs_to_fill(bm); } - BM_mesh_edgesplit(em->bm, true, true, true, true); + BM_mesh_edgesplit(em->bm, true, true, true); /* note: the output of the bmesh operator is ignored, since we built * the contiguous loop pairs to split already, its possible that some diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c index 2e6360c3ded..fa29921b325 100644 --- a/source/blender/modifiers/intern/MOD_edgesplit.c +++ b/source/blender/modifiers/intern/MOD_edgesplit.c @@ -91,7 +91,7 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd) } } - BM_mesh_edgesplit(bm, false, false, true, false); + BM_mesh_edgesplit(bm, false, true, false); /* BM_mesh_validate(bm); */ /* for troubleshooting */ -- cgit v1.2.3