[Bf-blender-cvs] [522bee3fc83] master: Refactoring: bvhutils: Use a function that gets the bvhtree through an identifier type.

Germano noreply at git.blender.org
Tue May 1 15:03:42 CEST 2018


Commit: 522bee3fc838c83b377d0e05fef8299a29ae5a16
Author: Germano
Date:   Tue May 1 10:03:28 2018 -0300
Branches: master
https://developer.blender.org/rB522bee3fc838c83b377d0e05fef8299a29ae5a16

Refactoring: bvhutils: Use a function that gets the bvhtree through an identifier type.

Reviewed By: @campbellbarton
Differential Revision: https://developer.blender.org/D3192

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

M	source/blender/blenkernel/BKE_bvhutils.h
M	source/blender/blenkernel/intern/bvhutils.c
M	source/blender/blenkernel/intern/constraint.c
M	source/blender/blenkernel/intern/mesh_remap.c
M	source/blender/blenkernel/intern/shrinkwrap.c
M	source/blender/editors/physics/particle_object.c
M	source/blender/editors/transform/transform_snap_object.c
M	source/blender/modifiers/intern/MOD_surface.c
M	source/blender/modifiers/intern/MOD_surfacedeform.c
M	source/blender/modifiers/intern/MOD_weightvgproximity.c
M	source/blender/render/intern/source/bake_api.c

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

diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index b3122f8adb9..33e88a6b8f8 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -113,8 +113,6 @@ BVHTree *bvhtree_from_editmesh_verts_ex(
         const BLI_bitmap *mask, int verts_num_active,
         float epsilon, int tree_type, int axis);
 
-BVHTree *bvhtree_from_mesh_verts(
-        struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
 BVHTree *bvhtree_from_mesh_verts_ex(
         struct BVHTreeFromMesh *data, const struct MVert *vert, const int numVerts,
         const bool vert_allocated, const BLI_bitmap *mask, int verts_num_active,
@@ -138,9 +136,6 @@ BVHTree *bvhtree_from_mesh_edges_ex(
         const BLI_bitmap *edges_mask, int edges_num_active,
         float epsilon, int tree_type, int axis);
 
-BVHTree *bvhtree_from_mesh_faces(
-        struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon,
-        int tree_type, int axis);
 BVHTree *bvhtree_from_mesh_faces_ex(
         struct BVHTreeFromMesh *data,
         const struct MVert *vert, const bool vert_allocated,
@@ -166,6 +161,8 @@ BVHTree *bvhtree_from_mesh_looptri_ex(
         const BLI_bitmap *mask, int looptri_num_active,
         float epsilon, int tree_type, int axis);
 
+BVHTree *bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type);
+
 /**
  * Frees data allocated by a call to bvhtree_from_mesh_*.
  */
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index cd2c7194237..90a75b8d3cc 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -501,7 +501,7 @@ BVHTree *bvhtree_from_editmesh_verts(
 
 /* Builds a bvh tree where nodes are the vertices of the given dm
  * and stores the BVHTree in dm->bvhCache */
-BVHTree *bvhtree_from_mesh_verts(
+static BVHTree *bvhtree_from_mesh_verts(
         BVHTreeFromMesh *data, DerivedMesh *dm,
         float epsilon, int tree_type, int axis)
 {
@@ -859,7 +859,7 @@ static void bvhtree_from_mesh_faces_setup_data(
 }
 
 /* Builds a bvh tree where nodes are the tesselated faces of the given dm */
-BVHTree *bvhtree_from_mesh_faces(
+static BVHTree *bvhtree_from_mesh_faces(
         BVHTreeFromMesh *data, DerivedMesh *dm,
         float epsilon, int tree_type, int axis)
 {
@@ -1225,6 +1225,25 @@ BVHTree *bvhtree_from_mesh_looptri_ex(
 	return tree;
 }
 
+/**
+ * Builds or queries a bvhcache for the cache bvhtree of the request type.
+ */
+BVHTree *bvhtree_from_mesh_get(
+        struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type)
+{
+	switch (type) {
+		case BVHTREE_FROM_VERTS:
+			return bvhtree_from_mesh_verts(data, mesh, 0.0f, 2, 6);
+		case BVHTREE_FROM_EDGES:
+			return bvhtree_from_mesh_edges(data, mesh, 0.0f, 2, 6);
+		case BVHTREE_FROM_FACES:
+			return bvhtree_from_mesh_faces(data, mesh, 0.0f, 2, 6);
+		case BVHTREE_FROM_LOOPTRI:
+			return bvhtree_from_mesh_looptri(data, mesh, 0.0f, 2, 6);
+	}
+	return NULL;
+}
+
 /** \} */
 
 
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 28e4af32a71..934cfbe9374 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3508,9 +3508,9 @@ static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra
 					nearest.dist_sq = FLT_MAX;
 
 					if (scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX)
-						bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6);
+						bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_VERTS);
 					else
-						bvhtree_from_mesh_looptri(&treeData, target, 0.0, 2, 6);
+						bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_LOOPTRI);
 					
 					if (treeData.tree == NULL) {
 						fail = true;
diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c
index 0af4dae4506..f99dd5574b2 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -131,7 +131,7 @@ float BKE_mesh_remap_calc_difference_from_dm(
 	float result = 0.0f;
 	int i;
 
-	bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6);
+	bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS);
 	nearest.index = -1;
 
 	for (i = 0; i < numverts_dst; i++) {
@@ -460,7 +460,7 @@ void BKE_mesh_remap_calc_verts_from_dm(
 		float tmp_co[3], tmp_no[3];
 
 		if (mode == MREMAP_MODE_VERT_NEAREST) {
-			bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6);
+			bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS);
 			nearest.index = -1;
 
 			for (i = 0; i < numverts_dst; i++) {
@@ -485,7 +485,7 @@ void BKE_mesh_remap_calc_verts_from_dm(
 			float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__);
 			dm_src->getVertCos(dm_src, vcos_src);
 
-			bvhtree_from_mesh_edges(&treedata, dm_src, 0.0f, 2, 6);
+			bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES);
 			nearest.index = -1;
 
 			for (i = 0; i < numverts_dst; i++) {
@@ -543,7 +543,13 @@ void BKE_mesh_remap_calc_verts_from_dm(
 			float *weights = MEM_mallocN(sizeof(*weights) * tmp_buff_size, __func__);
 
 			dm_src->getVertCos(dm_src, vcos_src);
-			bvhtree_from_mesh_looptri(&treedata, dm_src, (mode & MREMAP_USE_NORPROJ) ? ray_radius : 0.0f, 2, 6);
+			if (mode & MREMAP_USE_NORPROJ) {
+				bvhtree_from_mesh_looptri(
+				        &treedata, dm_src, ray_radius, 2, 6);
+			}
+			else {
+				bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI);
+			}
 
 			if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) {
 				for (i = 0; i < numverts_dst; i++) {
@@ -676,7 +682,7 @@ void BKE_mesh_remap_calc_edges_from_dm(
 
 			dm_src->getVertCos(dm_src, vcos_src);
 
-			bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6);
+			bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS);
 			nearest.index = -1;
 
 			for (i = 0; i < numedges_dst; i++) {
@@ -776,7 +782,7 @@ void BKE_mesh_remap_calc_edges_from_dm(
 			MEM_freeN(vert_to_edge_src_map_mem);
 		}
 		else if (mode == MREMAP_MODE_EDGE_NEAREST) {
-			bvhtree_from_mesh_edges(&treedata, dm_src, 0.0f, 2, 6);
+			bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES);
 			nearest.index = -1;
 
 			for (i = 0; i < numedges_dst; i++) {
@@ -803,7 +809,7 @@ void BKE_mesh_remap_calc_edges_from_dm(
 			float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__);
 
 			dm_src->getVertCos(dm_src, vcos_src);
-			bvhtree_from_mesh_looptri(&treedata, dm_src, 0.0f, 2, 6);
+			bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI);
 
 			for (i = 0; i < numedges_dst; i++) {
 				interp_v3_v3v3(tmp_co, verts_dst[edges_dst[i].v1].co, verts_dst[edges_dst[i].v2].co, 0.5f);
@@ -1360,7 +1366,7 @@ void BKE_mesh_remap_calc_loops_from_dm(
 			}
 			else {
 				BLI_assert(num_trees == 1);
-				bvhtree_from_mesh_verts(&treedata[0], dm_src, bvh_epsilon, 2, 6);
+				bvhtree_from_mesh_get(&treedata[0], dm_src, BVHTREE_FROM_VERTS);
 			}
 		}
 		else {  /* We use polygons. */
@@ -2007,10 +2013,13 @@ void BKE_mesh_remap_calc_polys_from_dm(
 		BVHTreeRayHit rayhit = {0};
 		float hit_dist;
 
-		bvhtree_from_mesh_looptri(
-		        &treedata, dm_src,
-		        (mode & MREMAP_USE_NORPROJ) ? MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius) : 0.0f,
-		        2, 6);
+		if (mode & MREMAP_USE_NORPROJ) {
+			bvhtree_from_mesh_looptri(
+			        &treedata, dm_src, MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius), 2, 6);
+		}
+		else {
+			bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI);
+		}
 
 		if (mode == MREMAP_MODE_POLY_NEAREST) {
 			nearest.index = -1;
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c
index 618f495dbf1..0d381248ef2 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -158,7 +158,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc)
 		return;
 	}
 
-	TIMEIT_BENCH(bvhtree_from_mesh_verts(&treeData, calc->target, 0.0, 2, 6), bvhtree_verts);
+	TIMEIT_BENCH(bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_VERTS), bvhtree_verts);
 	if (treeData.tree == NULL) {
 		OUT_OF_MEMORY();
 		return;
@@ -588,7 +588,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc)
 	}
 
 	/* Create a bvh-tree of the given target */
-	bvhtree_from_mesh_looptri(&treeData, calc->target, 0.0, 2, 6);
+	bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_LOOPTRI);
 	if (treeData.tree == NULL) {
 		OUT_OF_MEMORY();
 		return;
diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c
index 546fac6b7a3..f4334a2e872 100644
--- a/source/blender/editors/physics/particle_object.c
+++ b/source/blender/editors/physics/particle_object.c
@@ -692,11 +692,11 @@ static bool remap_hair_emitter(Scene *scene, Object *ob, ParticleSystem *psys,
 
 	if (dm->getNumTessFaces(dm) != 0) {
 		mface = dm->getTessFaceArray(dm);
-		bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6);
+		bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_FACES);
 	}
 	else if (dm->getNumEdges(dm) != 0) {
 		medge = dm->getEdgeArray(dm);
-		bvhtree_from_mesh_edges(&bvhtree, dm, 0.0, 2, 6);
+		bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_EDGES);
 	}
 	else {
 		dm->release(dm);
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index d248d0df4e3..569c662d31c 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -1687,10 +1687,10 @@ static bool snapDerivedMesh(
 		if (treedata->tree == NULL) {
 			switch (snapdata->snap_to) {
 				case SCE_SNAP_MODE_EDGE:
-					bvhtree_from_mesh_edges(treedata, dm, 0.0f, 2, 6);
+					bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_EDGES);
 					break;
 				case SCE_SNAP_MODE_VERTEX:
-					bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6);
+					bvh

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list