[Bf-blender-cvs] [505ff16dbf] master: Snap System: BVH: ignore AABBs behind ray

Germano Cavalcante noreply at git.blender.org
Mon Jan 30 06:49:52 CET 2017


Commit: 505ff16dbff03a90ddc9e2d53cd1694e38beb49c
Author: Germano Cavalcante
Date:   Mon Jan 30 02:49:41 2017 -0300
Branches: master
https://developer.blender.org/rB505ff16dbff03a90ddc9e2d53cd1694e38beb49c

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

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

M	source/blender/editors/transform/transform_snap_object.c

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

diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 43eb02889b..0624288f94 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];




More information about the Bf-blender-cvs mailing list