[Bf-blender-cvs] [5b2d0b0] master: BLI_kdopbvh: test root node before traversing

Germano Cavalcante noreply at git.blender.org
Thu Feb 11 08:33:57 CET 2016


Commit: 5b2d0b0fb423d8cadbc992fbfaa0e3cfdfa7efbb
Author: Germano Cavalcante
Date:   Thu Feb 11 18:22:19 2016 +1100
Branches: master
https://developer.blender.org/rB5b2d0b0fb423d8cadbc992fbfaa0e3cfdfa7efbb

BLI_kdopbvh: test root node before traversing

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

M	source/blender/blenlib/intern/BLI_kdopbvh.c

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

diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index b7a4608..7bd2b50 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1924,15 +1924,6 @@ static void dfs_find_nearest_to_ray_dfs(BVHNearestRayData *data, BVHNode *node)
 	}
 }
 
-static void dfs_find_nearest_to_ray_begin(BVHNearestRayData *data, BVHNode *node)
-{
-	float dist_sq = calc_dist_sq_to_ray(data, node);
-	if (dist_sq >= data->nearest.dist_sq) {
-		return;
-	}
-	dfs_find_nearest_to_ray_dfs(data, node);
-}
-
 int BLI_bvhtree_find_nearest_to_ray(
         BVHTree *tree, const float co[3], const float dir[3], BVHTreeNearest *nearest,
         BVHTree_NearestToRayCallback callback, void *userdata)
@@ -1940,8 +1931,6 @@ int BLI_bvhtree_find_nearest_to_ray(
 	BVHNearestRayData data;
 	BVHNode *root = tree->nodes[tree->totleaf];
 
-	BLI_ASSERT_UNIT_V3(dir);
-
 	data.tree = tree;
 
 	data.callback = callback;
@@ -1963,7 +1952,9 @@ int BLI_bvhtree_find_nearest_to_ray(
 
 	/* dfs search */
 	if (root) {
-		dfs_find_nearest_to_ray_begin(&data, root);
+		if (calc_dist_sq_to_ray(&data, root) < data.nearest.dist_sq) {
+			dfs_find_nearest_to_ray_dfs(&data, root);
+		}
 	}
 
 	/* copy back results */
@@ -2131,7 +2122,10 @@ void BLI_bvhtree_walk_dfs(
 {
 	const BVHNode *root = tree->nodes[tree->totleaf];
 	if (root != NULL) {
-		bvhtree_walk_dfs_recursive(walk_parent_cb, walk_leaf_cb, walk_order_cb, root, userdata);
+		/* first make sure the bv of root passes in the test too */
+		if (walk_parent_cb((const BVHTreeAxisRange *)root->bv, userdata)) {
+			bvhtree_walk_dfs_recursive(walk_parent_cb, walk_leaf_cb, walk_order_cb, root, userdata);
+		}
 	}
 }




More information about the Bf-blender-cvs mailing list