[Bf-blender-cvs] [231ee60] master: mathutils.BVHTree: support overlap self-intersect

Campbell Barton noreply at git.blender.org
Mon Aug 24 00:29:28 CEST 2015


Commit: 231ee60ab5373bb2e5676fc4f5c6dea476fc1d42
Author: Campbell Barton
Date:   Mon Aug 24 08:13:58 2015 +1000
Branches: master
https://developer.blender.org/rB231ee60ab5373bb2e5676fc4f5c6dea476fc1d42

mathutils.BVHTree: support overlap self-intersect

Use same logic as BKE_bmbvh_overlap

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

M	source/blender/python/mathutils/mathutils_bvhtree.c

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

diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c
index 4d18d7b..8a488fd 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -460,8 +460,27 @@ static bool py_bvhtree_overlap_cb(void *userdata, int index_a, int index_b, int
 	const unsigned int *tri_b = tree_b->tris[index_b];
 	const float *tri_a_co[3] = {tree_a->coords[tri_a[0]], tree_a->coords[tri_a[1]], tree_a->coords[tri_a[2]]};
 	const float *tri_b_co[3] = {tree_b->coords[tri_b[0]], tree_b->coords[tri_b[1]], tree_b->coords[tri_b[2]]};
+	float ix_pair[2][3];
+	int verts_shared = 0;
 
-	return isect_tri_tri_epsilon_v3(UNPACK3(tri_a_co), UNPACK3(tri_b_co), NULL, NULL, data->epsilon);
+	if (tree_a == tree_b) {
+		if (UNLIKELY(index_a == index_b)) {
+			return false;
+		}
+
+		verts_shared = (
+		        ELEM(tri_a_co[0], UNPACK3(tri_b_co)) +
+		        ELEM(tri_a_co[1], UNPACK3(tri_b_co)) +
+		        ELEM(tri_a_co[2], UNPACK3(tri_b_co)));
+
+		/* if 2 points are shared, bail out */
+		if (verts_shared >= 2) {
+			return false;
+		}
+	}
+
+	return (isect_tri_tri_epsilon_v3(UNPACK3(tri_a_co), UNPACK3(tri_b_co), ix_pair[0], ix_pair[1], data->epsilon) &&
+	        ((verts_shared == 0) || (len_squared_v3v3(ix_pair[0], ix_pair[1]) > data->epsilon)));
 }
 
 PyDoc_STRVAR(py_bvhtree_overlap_doc,




More information about the Bf-blender-cvs mailing list