[Bf-blender-cvs] [97d2f63bfe6] master: Object.raycast: Also test distance from BoundBox

Germano Cavalcante noreply at git.blender.org
Sat Apr 15 06:31:40 CEST 2017


Commit: 97d2f63bfe6d166eca12f7dec0e6525806990f49
Author: Germano Cavalcante
Date:   Sat Apr 15 01:31:24 2017 -0300
Branches: master
https://developer.blender.org/rB97d2f63bfe6d166eca12f7dec0e6525806990f49

Object.raycast: Also test distance from BoundBox

If `isect_ray_aabb_v3_simple` provides this information, why not take advantage of it?

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

M	source/blender/makesrna/intern/rna_object_api.c

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

diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 3b2e57a06e5..42d1b78784f 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -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};




More information about the Bf-blender-cvs mailing list