Object.raycast: Also test distance from BoundBox

If `isect_ray_aabb_v3_simple` provides this information, why not take advantage of it?
This commit is contained in:
Germano Cavalcante 2017-04-15 01:31:24 -03:00
parent 480473f1f1
commit 97d2f63bfe
1 changed files with 12 additions and 3 deletions

View File

@ -326,10 +326,19 @@ static void rna_Object_ray_cast(
return;
}
/* Test BoundBox */
/* Test BoundBox first (efficiency) */
BoundBox *bb = BKE_object_boundbox_get(ob);
if (bb && !isect_ray_aabb_v3_simple(origin, direction, bb->vec[0], bb->vec[6], NULL, NULL)) {
goto finally;
if (bb) {
float distmin, distmax;
if (isect_ray_aabb_v3_simple(origin, direction, bb->vec[0], bb->vec[6], &distmin, &distmax)) {
float dist = distmin >= 0 ? distmin : distmax;
if (dist > distance) {
goto finally;
}
}
else {
goto finally;
}
}
BVHTreeFromMesh treeData = {NULL};