From 19d3e230e6d0cc52ebd82a8b5d0efbbeb396a9cf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Aug 2013 11:44:51 +0000 Subject: improved BM_face_copy_shared to copy from more possible connected loops and add filter function (not used yet). --- source/blender/bmesh/intern/bmesh_construct.c | 46 +++++++++++++++++++++------ source/blender/bmesh/intern/bmesh_construct.h | 3 +- source/blender/bmesh/intern/bmesh_queries.h | 2 -- 3 files changed, 39 insertions(+), 12 deletions(-) (limited to 'source/blender/bmesh/intern') diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index f5856ee94b3..aa37a684519 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -127,33 +127,61 @@ BMFace *BM_face_create_quad_tri_v(BMesh *bm, BMVert **verts, int len, const BMFa /** * \brief copies face loop data from shared adjacent faces. + * + * \param filter_fn A function that filters the source loops before copying (don't always want to copy all) + * * \note when a matching edge is found, both loops of that edge are copied * this is done since the face may not be completely surrounded by faces, - * this way: a quad with 2 connected quads on either side will still get all 4 loops updated */ -void BM_face_copy_shared(BMesh *bm, BMFace *f) + * this way: a quad with 2 connected quads on either side will still get all 4 loops updated + */ +void BM_face_copy_shared(BMesh *bm, BMFace *f, + BMElemFilterFunc filter_fn, void *user_data) { BMLoop *l_first; BMLoop *l_iter; +#ifdef DEBUG + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + do { + BLI_assert(BM_ELEM_API_FLAG_TEST(l_iter, _FLAG_OVERLAP) == 0); + } while ((l_iter = l_iter->next) != l_first); +#endif + l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { BMLoop *l_other = l_iter->radial_next; if (l_other && l_other != l_iter) { + BMLoop *l_src[2]; + BMLoop *l_dst[2] = {l_iter, l_iter->next}; + unsigned int j; + if (l_other->v == l_iter->v) { - bm_loop_attrs_copy(bm, bm, l_other, l_iter); - bm_loop_attrs_copy(bm, bm, l_other->next, l_iter->next); + l_src[0] = l_other; + l_src[1] = l_other->next; } else { - bm_loop_attrs_copy(bm, bm, l_other->next, l_iter); - bm_loop_attrs_copy(bm, bm, l_other, l_iter->next); + l_src[0] = l_other->next; + l_src[1] = l_other; } - /* since we copy both loops of the shared edge, step over the next loop here */ - if ((l_iter = l_iter->next) == l_first) { - break; + + for (j = 0; j < 2; j++) { + BLI_assert(l_dst[j]->v == l_src[j]->v); + if (BM_ELEM_API_FLAG_TEST(l_dst[j], _FLAG_OVERLAP) == 0) { + if ((filter_fn == NULL) || filter_fn((BMElem *)l_src[j], user_data)) { + bm_loop_attrs_copy(bm, bm, l_src[j], l_dst[j]); + BM_ELEM_API_FLAG_ENABLE(l_dst[j], _FLAG_OVERLAP); + } + } } } } while ((l_iter = l_iter->next) != l_first); + + + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + do { + BM_ELEM_API_FLAG_DISABLE(l_iter, _FLAG_OVERLAP); + } while ((l_iter = l_iter->next) != l_first); } /** diff --git a/source/blender/bmesh/intern/bmesh_construct.h b/source/blender/bmesh/intern/bmesh_construct.h index f0bd7b316e9..92ed3307523 100644 --- a/source/blender/bmesh/intern/bmesh_construct.h +++ b/source/blender/bmesh/intern/bmesh_construct.h @@ -36,7 +36,8 @@ BMFace *BM_face_create_quad_tri_v(BMesh *bm, BMFace *BM_face_create_quad_tri(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, const BMFace *example, const bool no_double); -void BM_face_copy_shared(BMesh *bm, BMFace *f); +void BM_face_copy_shared(BMesh *bm, BMFace *f, + BMElemFilterFunc filter_fn, void *user_data); BMFace *BM_face_create_ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, const int len, const int create_flag); BMFace *BM_face_create_ngon_verts(BMesh *bm, BMVert **vert_arr, const int len, const int create_flag, diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index 38d30b2d005..e52e59102db 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -27,8 +27,6 @@ * \ingroup bmesh */ -typedef bool (*BMElemFilterFunc)(BMElem *, void *user_data); - bool BM_vert_in_face(BMFace *f, BMVert *v); int BM_verts_in_face_count(BMFace *f, BMVert **varr, int len); bool BM_verts_in_face(BMFace *f, BMVert **varr, int len); -- cgit v1.2.3