[Bf-blender-cvs] [39752eb] master: Fix for isect_tri_tri_epsilon_v3 w/ small faces

Campbell Barton noreply at git.blender.org
Fri Sep 4 14:34:54 CEST 2015


Commit: 39752eb912cd2eb606935dd41e4f2f3977190ea0
Author: Campbell Barton
Date:   Fri Sep 4 22:25:28 2015 +1000
Branches: master
https://developer.blender.org/rB39752eb912cd2eb606935dd41e4f2f3977190ea0

Fix for isect_tri_tri_epsilon_v3 w/ small faces

tris with ~1e-05 edge lengths would fail

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

M	source/blender/blenlib/intern/math_geom.c

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

diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index c644e04..548aed3 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -1668,7 +1668,9 @@ bool isect_tri_tri_epsilon_v3(
 	plane_a[3] = -dot_v3v3(plane_a, t_a0);
 	plane_b[3] = -dot_v3v3(plane_b, t_b0);
 
-	if (isect_plane_plane_v3(plane_a, plane_b, plane_co, plane_no)) {
+	if (isect_plane_plane_v3(plane_a, plane_b, plane_co, plane_no) &&
+	    (normalize_v3(plane_no) > epsilon))
+	{
 		/**
 		 * Implementation note: its simpler to project the triangles onto the intersection plane
 		 * before intersecting their edges with the ray, defined by 'isect_plane_plane_v3'.
@@ -1681,10 +1683,6 @@ bool isect_tri_tri_epsilon_v3(
 		int t;
 		float co_proj[3];
 
-		/* only for numeric stability
-		 * (and so we can call 'closest_to_plane3_normalized_v3' below) */
-		normalize_v3(plane_no);
-
 		closest_to_plane3_normalized_v3(co_proj, plane_no, plane_co);
 
 		/* For both triangles, find the overlap with the line defined by the ray [co_proj, plane_no].
@@ -1698,7 +1696,10 @@ bool isect_tri_tri_epsilon_v3(
 			closest_to_plane3_normalized_v3(tri_proj[2], plane_no, tri_pair[t][2]);
 
 			for (j = 0, j_prev = 2; j < 3; j_prev = j++) {
-				const float edge_fac = line_point_factor_v3_ex(co_proj, tri_proj[j_prev], tri_proj[j], epsilon, -1.0f);
+				/* note that its important to have a very small nonzero epsilon here
+				 * otherwise this fails for very small faces.
+				 * However if its too small, large adjacent faces will count as intersecting */
+				const float edge_fac = line_point_factor_v3_ex(co_proj, tri_proj[j_prev], tri_proj[j], 1e-10f, -1.0f);
 				/* ignore collinear lines, they are either an edge shared between 2 tri's
 				 * (which runs along [co_proj, plane_no], but can be safely ignored).
 				 *




More information about the Bf-blender-cvs mailing list