diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-02-26 08:03:21 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-02-26 08:03:21 +0300 |
commit | 58a394073fcd2cf009724514b483aa36b554c3cd (patch) | |
tree | d596057d157b3b831ee43425ad8bc535f43fca61 /source/blender/bmesh | |
parent | 2986923f8c62ef78b783991ff5fbf9e8cadb209c (diff) |
BMesh: utility functions for visible element access
Needed for drawing code which skips hidden elements.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_query.c | 25 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_query.h | 3 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_structure.c | 22 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_structure.h | 1 |
4 files changed, 51 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_query.c b/source/blender/bmesh/intern/bmesh_query.c index 166712225bd..7a0d1c7ec5a 100644 --- a/source/blender/bmesh/intern/bmesh_query.c +++ b/source/blender/bmesh/intern/bmesh_query.c @@ -377,6 +377,13 @@ BMLoop *BM_vert_find_first_loop(BMVert *v) { return v->e ? bmesh_disk_faceloop_find_first(v->e, v) : NULL; } +/** + * A version of #BM_vert_find_first_loop that ignores hidden loops. + */ +BMLoop *BM_vert_find_first_loop_visible(BMVert *v) +{ + return v->e ? bmesh_disk_faceloop_find_first_visible(v->e, v) : NULL; +} /** * Returns true if the vertex is used in a given face. @@ -2000,6 +2007,24 @@ BMEdge *BM_edge_find_double(BMEdge *e) } /** + * Only #BMEdge.l access us needed, however when we want the first visible loop, + * a utility function is needed. + */ +BMLoop *BM_edge_find_first_loop_visible(BMEdge *e) +{ + if (e->l != NULL) { + BMLoop *l_iter, *l_first; + l_iter = l_first = e->l; + do { + if (!BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) { + return l_iter; + } + } while ((l_iter = l_iter->radial_next) != l_first); + } + return NULL; +} + +/** * Given a set of vertices (varr), find out if * there is a face with exactly those vertices * (and only those vertices). diff --git a/source/blender/bmesh/intern/bmesh_query.h b/source/blender/bmesh/intern/bmesh_query.h index 7d464453678..c04c7f5e97d 100644 --- a/source/blender/bmesh/intern/bmesh_query.h +++ b/source/blender/bmesh/intern/bmesh_query.h @@ -42,7 +42,10 @@ BMLoop *BM_loop_other_edge_loop(BMLoop *l, BMVert *v) ATTR_WARN_UNUSED_RESULT AT BMLoop *BM_face_other_vert_loop(BMFace *f, BMVert *v_prev, BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); BMLoop *BM_loop_other_vert_loop(BMLoop *l, BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); BMLoop *BM_vert_step_fan_loop(BMLoop *l, BMEdge **e_step) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + BMLoop *BM_vert_find_first_loop(BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +BMLoop *BM_vert_find_first_loop_visible(BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +BMLoop *BM_edge_find_first_loop_visible(BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); bool BM_vert_pair_share_face_check( BMVert *v_a, BMVert *v_b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index 420e3c511cf..e4bad715b29 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -347,6 +347,28 @@ BMLoop *bmesh_disk_faceloop_find_first(const BMEdge *e, const BMVert *v) return NULL; } +/** + * A version of #bmesh_disk_faceloop_find_first that ignores hidden faces. + */ +BMLoop *bmesh_disk_faceloop_find_first_visible(const BMEdge *e, const BMVert *v) +{ + const BMEdge *e_iter = e; + do { + if (!BM_elem_flag_test(e_iter, BM_ELEM_HIDDEN)) { + if (e_iter->l != NULL) { + BMLoop *l_iter, *l_first; + l_iter = l_first = e_iter->l; + do { + if (!BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) { + return (l_iter->v == v) ? l_iter : l_iter->next; + } + } while ((l_iter = l_iter->radial_next) != l_first); + } + } + } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e); + return NULL; +} + BMEdge *bmesh_disk_faceedge_find_next(const BMEdge *e, const BMVert *v) { BMEdge *e_find; diff --git a/source/blender/bmesh/intern/bmesh_structure.h b/source/blender/bmesh/intern/bmesh_structure.h index 3629b22dd34..8e3ba7b46c0 100644 --- a/source/blender/bmesh/intern/bmesh_structure.h +++ b/source/blender/bmesh/intern/bmesh_structure.h @@ -45,6 +45,7 @@ int bmesh_disk_facevert_count_at_most(const BMVert *v, const int count_max) int bmesh_disk_facevert_count(const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); BMEdge *bmesh_disk_faceedge_find_first(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); BMLoop *bmesh_disk_faceloop_find_first(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +BMLoop *bmesh_disk_faceloop_find_first_visible(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); BMEdge *bmesh_disk_faceedge_find_next(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /* RADIAL CYCLE MANAGMENT */ |