diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2016-02-11 10:22:19 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-02-11 10:23:58 +0300 |
commit | 5b2d0b0fb423d8cadbc992fbfaa0e3cfdfa7efbb (patch) | |
tree | 2df72effa1d75be35d6148d9e764fee9779e07e2 | |
parent | 86725667d49d2948e205aecbfd8123b1e6ba8939 (diff) |
BLI_kdopbvh: test root node before traversing
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdopbvh.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index b7a46085bc3..7bd2b50d3dc 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); + } } } |