From b8b56ee1722b7b55c4224b0bb3dbf06201c96946 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Tue, 18 Aug 2020 14:08:16 -0300 Subject: BLI_kdopbvh: Adjust epsilon according to the axis This corrects the overlap detection for cloths since in this case kdop26 is used and epsilon represents the distance. --- source/blender/blenlib/intern/BLI_kdopbvh.c | 39 +++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index f63a523ca60..f030a733752 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -201,6 +201,23 @@ const float bvhtree_kdop_axes[13][3] = { {0, 1.0, -1.0}, }; +/* Used to correct the epsilon and thus match the overlap distance. */ +const float bvhtree_kdop_axes_length[13] = { + 1.0f, + 1.0f, + 1.0f, + 1.7320508075688772f, + 1.7320508075688772f, + 1.7320508075688772f, + 1.7320508075688772f, + 1.4142135623730951f, + 1.4142135623730951f, + 1.4142135623730951f, + 1.4142135623730951f, + 1.4142135623730951f, + 1.4142135623730951f, +}; + /* -------------------------------------------------------------------- */ /** \name Utility Functions * \{ */ @@ -970,9 +987,18 @@ void BLI_bvhtree_balance(BVHTree *tree) #endif } -void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints) +static void bvhtree_node_inflate(const BVHTree *tree, BVHNode *node, const float dist) { axis_t axis_iter; + for (axis_iter = tree->start_axis; axis_iter < tree->stop_axis; axis_iter++) { + float dist_corrected = dist * bvhtree_kdop_axes_length[axis_iter]; + node->bv[(2 * axis_iter)] -= dist_corrected; /* minimum */ + node->bv[(2 * axis_iter) + 1] += dist_corrected; /* maximum */ + } +} + +void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints) +{ BVHNode *node = NULL; /* insert should only possible as long as tree->totbranch is 0 */ @@ -986,10 +1012,7 @@ void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoin node->index = index; /* inflate the bv with some epsilon */ - for (axis_iter = tree->start_axis; axis_iter < tree->stop_axis; axis_iter++) { - node->bv[(2 * axis_iter)] -= tree->epsilon; /* minimum */ - node->bv[(2 * axis_iter) + 1] += tree->epsilon; /* maximum */ - } + bvhtree_node_inflate(tree, node, tree->epsilon); } /* call before BLI_bvhtree_update_tree() */ @@ -997,7 +1020,6 @@ bool BLI_bvhtree_update_node( BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints) { BVHNode *node = NULL; - axis_t axis_iter; /* check if index exists */ if (index > tree->totleaf) { @@ -1013,10 +1035,7 @@ bool BLI_bvhtree_update_node( } /* inflate the bv with some epsilon */ - for (axis_iter = tree->start_axis; axis_iter < tree->stop_axis; axis_iter++) { - node->bv[(2 * axis_iter)] -= tree->epsilon; /* minimum */ - node->bv[(2 * axis_iter) + 1] += tree->epsilon; /* maximum */ - } + bvhtree_node_inflate(tree, node, tree->epsilon); return true; } -- cgit v1.2.3