[Bf-blender-cvs] [58a394073fc] master: BMesh: utility functions for visible element access

Campbell Barton noreply at git.blender.org
Tue Feb 26 06:06:47 CET 2019


Commit: 58a394073fcd2cf009724514b483aa36b554c3cd
Author: Campbell Barton
Date:   Tue Feb 26 16:03:21 2019 +1100
Branches: master
https://developer.blender.org/rB58a394073fcd2cf009724514b483aa36b554c3cd

BMesh: utility functions for visible element access

Needed for drawing code which skips hidden elements.

===================================================================

M	source/blender/bmesh/intern/bmesh_query.c
M	source/blender/bmesh/intern/bmesh_query.h
M	source/blender/bmesh/intern/bmesh_structure.c
M	source/blender/bmesh/intern/bmesh_structure.h

===================================================================

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.
@@ -1999,6 +2006,24 @@ BMEdge *BM_edge_find_double(BMEdge *e)
 	return NULL;
 }
 
+/**
+ * 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
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 */



More information about the Bf-blender-cvs mailing list