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.
This commit is contained in:
parent
dead79a16a
commit
cf6ca226fa
|
@ -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];
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue