Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-08-21 10:46:23 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-08-21 10:48:33 +0300
commit59e166c568a57315b78c5ab812837c95923c300e (patch)
tree3bb1f901f1f1209fbee7449aeaa672c3487c88c6 /source/blender/blenlib/intern/BLI_kdopbvh.c
parent71919efd78149a305bea4db18d80f9434abeca33 (diff)
BVH-raycast: Use watertight intersections
By default watertight intersections are used, For callbacks where its not needed, BLI_bvhtree_ray_cast_ex can be called without the BVH_RAYCAST_WATERTIGHT flag. Fixes T45286
Diffstat (limited to 'source/blender/blenlib/intern/BLI_kdopbvh.c')
-rw-r--r--source/blender/blenlib/intern/BLI_kdopbvh.c54
1 files changed, 46 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 1b9b6e38208..ddb61e415ac 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -139,6 +139,10 @@ typedef struct BVHRayCastData {
BVHTreeRay ray;
+#ifdef USE_KDOPBVH_WATERTIGHT
+ struct IsectRayPrecalc isect_precalc;
+#endif
+
/* initialized by bvhtree_ray_cast_data_precalc */
float ray_dot_axis[13];
float idot_axis[13];
@@ -1626,7 +1630,7 @@ static void iterative_raycast(BVHRayCastData *data, BVHNode *node)
}
#endif
-static void bvhtree_ray_cast_data_precalc(BVHRayCastData *data)
+static void bvhtree_ray_cast_data_precalc(BVHRayCastData *data, int flag)
{
int i;
@@ -1642,10 +1646,24 @@ static void bvhtree_ray_cast_data_precalc(BVHRayCastData *data)
data->index[2 * i] += 2 * i;
data->index[2 * i + 1] += 2 * i;
}
+
+#ifdef USE_KDOPBVH_WATERTIGHT
+ if (flag & BVH_RAYCAST_WATERTIGHT) {
+ isect_ray_tri_watertight_v3_precalc(&data->isect_precalc, data->ray.direction);
+ data->ray.isect_precalc = &data->isect_precalc;
+ }
+ else {
+ data->ray.isect_precalc = NULL;
+ }
+#else
+ UNUSED_VARS(flag);
+#endif
}
-int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit,
- BVHTree_RayCastCallback callback, void *userdata)
+int BLI_bvhtree_ray_cast_ex(
+ BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit,
+ BVHTree_RayCastCallback callback, void *userdata,
+ int flag)
{
BVHRayCastData data;
BVHNode *root = tree->nodes[tree->totleaf];
@@ -1661,10 +1679,11 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f
copy_v3_v3(data.ray.direction, dir);
data.ray.radius = radius;
- bvhtree_ray_cast_data_precalc(&data);
+ bvhtree_ray_cast_data_precalc(&data, flag);
- if (hit)
+ if (hit) {
memcpy(&data.hit, hit, sizeof(*hit));
+ }
else {
data.hit.index = -1;
data.hit.dist = FLT_MAX;
@@ -1682,6 +1701,13 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f
return data.hit.index;
}
+int BLI_bvhtree_ray_cast(
+ BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit,
+ BVHTree_RayCastCallback callback, void *userdata)
+{
+ return BLI_bvhtree_ray_cast_ex(tree, co, dir, radius, hit, callback, userdata, BVH_RAYCAST_DEFAULT);
+}
+
float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], const float light_end[3], float pos[3])
{
BVHRayCastData data;
@@ -1707,8 +1733,13 @@ float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], cons
}
-int BLI_bvhtree_ray_cast_all(BVHTree *tree, const float co[3], const float dir[3], float radius,
- BVHTree_RayCastCallback callback, void *userdata)
+/**
+ * Calls the callback for every ray intersection
+ */
+int BLI_bvhtree_ray_cast_all_ex(
+ BVHTree *tree, const float co[3], const float dir[3], float radius,
+ BVHTree_RayCastCallback callback, void *userdata,
+ int flag)
{
BVHRayCastData data;
BVHNode *root = tree->nodes[tree->totleaf];
@@ -1724,7 +1755,7 @@ int BLI_bvhtree_ray_cast_all(BVHTree *tree, const float co[3], const float dir[3
copy_v3_v3(data.ray.direction, dir);
data.ray.radius = radius;
- bvhtree_ray_cast_data_precalc(&data);
+ bvhtree_ray_cast_data_precalc(&data, flag);
data.hit.index = -1;
data.hit.dist = FLT_MAX;
@@ -1736,6 +1767,13 @@ int BLI_bvhtree_ray_cast_all(BVHTree *tree, const float co[3], const float dir[3
return data.hit.index;
}
+int BLI_bvhtree_ray_cast_all(
+ BVHTree *tree, const float co[3], const float dir[3], float radius,
+ BVHTree_RayCastCallback callback, void *userdata)
+{
+ return BLI_bvhtree_ray_cast_all_ex(tree, co, dir, radius, callback, userdata, BVH_RAYCAST_DEFAULT);
+}
+
/**
* Range Query - as request by broken :P
*