diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2017-04-15 06:44:05 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2017-04-15 06:44:05 +0300 |
commit | 480473f1f1008168e7784221b852a6d370a0f4f5 (patch) | |
tree | efcd61745b252fe538b25cfa08f3fc5dbe28fa51 /source/blender/makesrna/intern | |
parent | 718fb3167d0ed293d6476807897dddf05b562523 (diff) |
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)
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_object_api.c | 10 |
1 files changed, 8 insertions, 2 deletions
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); |