[Bf-blender-cvs] [50e5d13647b] blender2.8-snapping_with_occlusion: BKE: bvhutils: Adds support for bvhtrees from loose edges.

Germano noreply at git.blender.org
Mon May 7 01:09:00 CEST 2018


Commit: 50e5d13647bcfaf895c2d793be7e9a60494e79be
Author: Germano
Date:   Fri May 4 20:01:23 2018 -0300
Branches: blender2.8-snapping_with_occlusion
https://developer.blender.org/rB50e5d13647bcfaf895c2d793be7e9a60494e79be

BKE: bvhutils: Adds support for bvhtrees from loose edges.

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

M	source/blender/blenkernel/BKE_bvhutils.h
M	source/blender/blenkernel/intern/bvhutils.c

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

diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index ad7cd559f9e..9f6afcab6b3 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -183,8 +183,9 @@ enum {
 	BVHTREE_FROM_LOOPTRI         = 3,
 
 	BVHTREE_FROM_LOOSEVERTS      = 4,
+	BVHTREE_FROM_LOOSEEDGES      = 5,
 
-	BVHTREE_FROM_EM_LOOPTRI      = 5,
+	BVHTREE_FROM_EM_LOOPTRI      = 6,
 };
 
 
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index e4f2ae83372..20c5e08a3d1 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -1002,6 +1002,31 @@ static BLI_bitmap *loose_verts_map_get(
 	return loose_verts_mask;
 }
 
+static BLI_bitmap *loose_edges_map_get(
+        const MEdge *medge, const int edges_num,
+        const MVert *mvert, int *r_loose_edge_num)
+{
+	BLI_bitmap *loose_edges_mask = BLI_BITMAP_NEW(edges_num, __func__);
+
+	/* another option to get the `numLooseEdges` would be
+	* `dm->drawObject->tot_loose_edge_drawn` */
+	int num_loose_edges = 0;
+	const MEdge *e = medge;
+	for (int i = 0; i < edges_num; i++, e++) {
+		if (e->flag & ME_LOOSEEDGE) {
+			BLI_BITMAP_ENABLE(loose_edges_mask, i);
+			num_loose_edges++;
+		}
+		else {
+			BLI_BITMAP_DISABLE(loose_edges_mask, i);
+		}
+	}
+
+	*r_loose_edge_num = num_loose_edges;
+
+	return loose_edges_mask;
+}
+
 /**
  * Builds or queries a bvhcache for the cache bvhtree of the request type.
  */
@@ -1078,6 +1103,7 @@ BVHTree *bvhtree_from_mesh_get(
 			break;
 
 		case BVHTREE_FROM_EDGES:
+		case BVHTREE_FROM_LOOSEEDGES:
 			nearest_callback = mesh_edges_nearest_point;
 			raycast_callback = mesh_edges_spherecast;
 
@@ -1087,16 +1113,30 @@ BVHTree *bvhtree_from_mesh_get(
 			if (tree == NULL) {
 				/* Not in cache */
 				BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE);
-				tree = bvhcache_find(dm->bvhCache, BVHTREE_FROM_EDGES);
+				tree = bvhcache_find(dm->bvhCache, type);
+
 				if (tree == NULL) {
+					BLI_bitmap *loose_edges_mask = NULL;
+					int loose_edges_num = -1;
+					int edges_num = dm->getNumEdges(dm);
+
+					if (type == BVHTREE_FROM_LOOSEEDGES) {
+						loose_edges_mask = loose_edges_map_get(
+						        medge, edges_num, mvert, &loose_edges_num);
+					}
+
 					tree = bvhtree_from_mesh_edges_create_tree(
-					        mvert, medge, dm->getNumEdges(dm),
-					        NULL, -1, 0.0, tree_type, 6);
+					        mvert, medge, edges_num,
+					        loose_edges_mask, loose_edges_num, 0.0, tree_type, 6);
+
+					if (loose_edges_mask != NULL) {
+						MEM_freeN(loose_edges_mask);
+					}
 
 					if (tree) {
 						/* Save on cache for later use */
 						/* printf("BVHTree built and saved on cache\n"); */
-						bvhcache_insert(&dm->bvhCache, tree, BVHTREE_FROM_EDGES);
+						bvhcache_insert(&dm->bvhCache, tree, type);
 					}
 				}
 				BLI_rw_mutex_unlock(&cache_rwlock);



More information about the Bf-blender-cvs mailing list