[Bf-blender-cvs] [480473f1f10] master: Object.raycast: Test the hit on the BoundBox first
Germano Cavalcante
noreply at git.blender.org
Sat Apr 15 05:44:25 CEST 2017
Commit: 480473f1f1008168e7784221b852a6d370a0f4f5
Author: Germano Cavalcante
Date: Sat Apr 15 00:44:05 2017 -0300
Branches: master
https://developer.blender.org/rB480473f1f1008168e7784221b852a6d370a0f4f5
Object.raycast: Test the hit on the BoundBox first
This avoids the unnecessary creation of bvhtree, which can be highly inefficient in some cases
(for example: in the `operator_modal_view3d_raycast.py` template)
===================================================================
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 c680abe71a4..3b2e57a06e5 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -321,13 +321,19 @@ static void rna_Object_ray_cast(
float origin[3], float direction[3], float distance,
int *r_success, float r_location[3], float r_normal[3], int *r_index)
{
- BVHTreeFromMesh treeData = {NULL};
-
if (ob->derivedFinal == NULL) {
BKE_reportf(reports, RPT_ERROR, "Object '%s' has no mesh data to be used for ray casting", ob->id.name + 2);
return;
}
+ /* Test BoundBox */
+ 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;
+ }
+
+ BVHTreeFromMesh treeData = {NULL};
+
/* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
bvhtree_from_mesh_looptri(&treeData, ob->derivedFinal, 0.0f, 4, 6);
More information about the Bf-blender-cvs
mailing list