[Bf-blender-cvs] [cf6ca226fa] master: New math_geom function `isect_ray_aabb_v3_simple`

Germano Cavalcante noreply at git.blender.org
Sun Jan 29 17:57:09 CET 2017


Commit: cf6ca226fa58d7a03be6cebb73a88eeb57497cf4
Author: Germano Cavalcante
Date:   Sun Jan 29 13:56:58 2017 -0300
Branches: master
https://developer.blender.org/rBcf6ca226fa58d7a03be6cebb73a88eeb57497cf4

New math_geom function `isect_ray_aabb_v3_simple`

The new `isect_ray_aabb_v3_simple` function replaces the `BKE_boundbox_ray_hit_check` and can be used in BVHTree Root (first AABB). So it is much more efficient.

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

M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/editors/transform/transform_snap_object.c

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

diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index e3635be671..4a85e859c1 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -293,6 +293,10 @@ void isect_ray_aabb_v3_precalc(
 bool isect_ray_aabb_v3(
         const struct IsectRayAABB_Precalc *data,
         const float bb_min[3], const float bb_max[3], float *tmin);
+bool isect_ray_aabb_v3_simple(
+        const float orig[3], const float dir[3],
+        const float bb_min[3], const float bb_max[3],
+        float *tmin, float *tmax);
 
 struct NearestRayToAABB_Precalc {
 	float ray_origin[3];
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 8f5d84dfa0..aeb6a550cd 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2309,6 +2309,34 @@ bool isect_ray_aabb_v3(
 	return true;
 }
 
+/*
+ * Test a bounding box (AABB) for ray intersection
+ * assumes the ray is already local to the boundbox space
+ */
+bool isect_ray_aabb_v3_simple(
+        const float orig[3], const float dir[3],
+        const float bb_min[3], const float bb_max[3],
+        float *tmin, float *tmax)
+{
+	double t[7];
+	float hit_dist[2];
+	t[1] = (double)(bb_min[0] - orig[0]) / dir[0];
+	t[2] = (double)(bb_max[0] - orig[0]) / dir[0];
+	t[3] = (double)(bb_min[1] - orig[1]) / dir[1];
+	t[4] = (double)(bb_max[1] - orig[1]) / dir[1];
+	t[5] = (double)(bb_min[2] - orig[2]) / dir[2];
+	t[6] = (double)(bb_max[2] - orig[2]) / dir[2];
+	hit_dist[0] = (float)fmax(fmax(fmin(t[1], t[2]), fmin(t[3], t[4])), fmin(t[5], t[6]));
+	hit_dist[1] = (float)fmin(fmin(fmax(t[1], t[2]), fmax(t[3], t[4])), fmax(t[5], t[6]));
+	if ((hit_dist[1] < 0 || hit_dist[0] > hit_dist[1]))
+		return false;
+	else {
+		if (tmin) *tmin = hit_dist[0];
+		if (tmax) *tmax = hit_dist[1];
+		return true;
+	}
+}
+
 void dist_squared_ray_to_aabb_v3_precalc(
         struct NearestRayToAABB_Precalc *data,
         const float ray_origin[3], const float ray_direction[3])
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 0f7b62d7ba..a562a66597 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -1087,13 +1087,16 @@ static bool snapDerivedMesh(
 					bb = &bb_temp;
 				}
 
-				/* was local_depth, see: T47838 */
-				len_diff = BVH_RAYCAST_DIST_MAX;
+				float tmin, tmax;
 
-				if (!BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, &len_diff)) {
+				/* was BKE_boundbox_ray_hit_check, see: T50486 */
+				if (!isect_ray_aabb_v3_simple(
+					ray_start_local, ray_normal_local, bb->vec[0], bb->vec[6], &tmin, &tmax))
+				{
 					return retval;
 				}
-				need_ray_start_correction_init = false;
+				/* was local_depth, see: T47838 */
+				len_diff = tmin > 0 ? tmin : tmax;
 			}
 		}




More information about the Bf-blender-cvs mailing list