diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2017-01-30 08:49:41 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2017-01-30 08:49:41 +0300 |
commit | 505ff16dbff03a90ddc9e2d53cd1694e38beb49c (patch) | |
tree | bc6117cb1e7b9b53dddd872eeef8f0138d1436f6 /source | |
parent | 318ee2e8c108c7a6e03a78dd4877e2ce67f8f5e0 (diff) |
Snap System: BVH: ignore AABBs behind ray
This provides a slight improvement in performance in specific cases, such as when the observer is inside a high poly object and executes snap to edge or vertex
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 43eb02889bb..0624288f94f 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -542,12 +542,16 @@ static bool cb_walk_parent_snap_project(const BVHTreeAxisRange *bounds, void *us /* if rtmin < rtmax, ray intersect `AABB` */ if (rtmin <= rtmax) { +#define IGNORE_BEHIND_RAY #ifdef IGNORE_BEHIND_RAY /* `if rtmax < depth_min`, the hit is behind us */ if (rtmax < data->depth_range[0]) { - /* TODO: TODO: Check if the entire AABB is behind ray - * this will prevent unnecessary leaf testing */ - return false; + /* Test if the entire AABB is behind us */ + float dvec[3]; + sub_v3_v3v3(dvec, local_bvmax, data->ray_origin_local); + if (dot_v3v3(dvec, data->ray_direction_local) < (data->depth_range[0])) { + return false; + } } #endif const float proj = rtmin * data->ray_direction_local[main_axis]; @@ -557,10 +561,15 @@ static bool cb_walk_parent_snap_project(const BVHTreeAxisRange *bounds, void *us #ifdef IGNORE_BEHIND_RAY /* `if rtmin < depth_min`, the hit is behing us */ else if (rtmin < data->depth_range[0]) { - /* TODO: Test if the AABB is totally behind ray */ - return false; + /* Test if the entire AABB is behind us */ + float dvec[3]; + sub_v3_v3v3(dvec, local_bvmax, data->ray_origin_local); + if (dot_v3v3(dvec, data->ray_direction_local) < (data->depth_range[0])) { + return false; + } } #endif +#undef IGNORE_BEHIND_RAY if (data->sign[main_axis]) { va[main_axis] = local_bvmax[main_axis]; vb[main_axis] = local_bvmin[main_axis]; |