[Bf-blender-cvs] [cb7796d] bmesh-boolean-experiment: Fix error using diced faces, doing bvh lookups

Campbell Barton noreply at git.blender.org
Wed Oct 28 11:12:34 CET 2015


Commit: cb7796dfd32aaffe60d3a050230a206f8bace814
Author: Campbell Barton
Date:   Wed Oct 28 20:26:57 2015 +1100
Branches: bmesh-boolean-experiment
https://developer.blender.org/rBcb7796dfd32aaffe60d3a050230a206f8bace814

Fix error using diced faces, doing bvh lookups

Was accessing face loops of faces which were already cut,
this made the coordinates mismatch with the original faces (and the BVH tree).

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

M	source/blender/bmesh/tools/bmesh_intersect.c
M	source/blender/modifiers/intern/MOD_boolean.c

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

diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c
index 90a1800..a136984 100644
--- a/source/blender/bmesh/tools/bmesh_intersect.c
+++ b/source/blender/bmesh/tools/bmesh_intersect.c
@@ -788,7 +788,7 @@ static void bm_isect_tri_tri(
 #ifdef USE_BVH
 
 typedef struct RaycastData {
-	/*const*/ BMLoop *(*looptris)[3];
+	const float **looptris;
 	BLI_Buffer z_buffer;
 	float z_buffer_storage[64];
 	int num_isect;
@@ -855,15 +855,16 @@ static void raycast_callback(void *userdata,
                              BVHTreeRayHit *hit)
 {
 	RaycastData *raycast_data = userdata;
-	/*const*/ BMLoop *(*looptris)[3] = raycast_data->looptris;
-	const float *v0 = looptris[index][0]->v->co;
-	const float *v1 = looptris[index][1]->v->co;
-	const float *v2 = looptris[index][2]->v->co;
+	const float **looptris = raycast_data->looptris;
+	const float *v0 = looptris[index * 3 + 0];
+	const float *v1 = looptris[index * 3 + 1];
+	const float *v2 = looptris[index * 3 + 2];
 	float dist, uv[2];
 	(void) hit;  /* Ignored. */
 	if (
 #ifdef USE_KDOPBVH_WATERTIGHT
-	    isect_ray_tri_watertight_v3(ray->origin, &isect_precalc_x, v0, v1, v2, &dist, uv))
+	    isect_ray_tri_watertight_v3_simple(ray->origin, ray->direction, v0, v1, v2, &dist, uv))
+//		isect_ray_tri_watertight_v3(ray->origin, &isect_precalc_x, v0, v1, v2, &dist, uv))
 #else
 	    isect_ray_tri_epsilon_v3(ray->origin, ray->direction, v0, v1, v2, &dist, uv, FLT_EPSILON))
 #endif
@@ -887,7 +888,7 @@ static void raycast_callback(void *userdata,
 
 static int isect_bvhtree_point_v3(
         BVHTree *tree,
-        BMLoop *(*looptris)[3],
+        const float **looptris,
         const float co[3])
 {
 	RaycastData raycast_data = {
@@ -947,6 +948,9 @@ bool BM_mesh_intersect(
 	bool has_isect;
 	const int totface_orig = bm->totface;
 
+	/* needed for boolean, since cutting up faces moves the loops within the face */
+	const float **looptri_coords = NULL;
+
 #ifdef USE_BVH
 	BVHTree *tree_a, *tree_b;
 	unsigned int tree_overlap_tot;
@@ -1007,6 +1011,20 @@ bool BM_mesh_intersect(
 	printf("data = [\n");
 #endif
 
+	if (boolean_mode != 0) {
+		/* keep original geometrty for raycast callbacks */
+		float **cos;
+		int i, j;
+
+		cos = MEM_mallocN((size_t)looptris_tot * sizeof(*looptri_coords) * 3, __func__);
+		for (i = 0, j = 0; i < looptris_tot; i++) {
+			cos[j++] = looptris[i][0]->v->co;
+			cos[j++] = looptris[i][1]->v->co;
+			cos[j++] = looptris[i][2]->v->co;
+		}
+		looptri_coords = (const float **)cos;
+	}
+
 #ifdef USE_BVH
 	{
 		int i;
@@ -1143,7 +1161,7 @@ bool BM_mesh_intersect(
 			}
 
 #ifdef USE_DUMP
-			printf("# SPLITTING EDGE: %d, %d\n", e_index, v_ls_base->list_len);
+			printf("# SPLITTING EDGE: %d, %d\n", BM_elem_index_get(e), v_ls_base->list_len);
 #endif
 			/* intersect */
 			is_wire = BLI_gset_haskey(s.wire_edges,  e);
@@ -1508,8 +1526,7 @@ bool BM_mesh_intersect(
 
 					BM_face_calc_center_mean(f, co);
 
-					hits = isect_bvhtree_point_v3(test_fn(f, user_data) == 1 ? tree_a : tree_b, looptris, co);
-
+					hits = isect_bvhtree_point_v3(test_fn(f, user_data) == 1 ? tree_a : tree_b, looptri_coords, co);
 					if ((hits & 1) == 1) {
 						is_inside = false;
 					}
@@ -1549,6 +1566,8 @@ bool BM_mesh_intersect(
 		}
 	}
 
+	MEM_freeN(looptri_coords);
+
 	if (boolean_mode != 0) {
 		/* no booleans, just free immediate */
 		BLI_bvhtree_free(tree_a);
diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c
index ede6f76..c74d147 100644
--- a/source/blender/modifiers/intern/MOD_boolean.c
+++ b/source/blender/modifiers/intern/MOD_boolean.c
@@ -157,6 +157,7 @@ static int bm_face_isect_pair(BMFace *f, void *user_data)
 {
 	struct BMIsectUserData *data = user_data;
 
+	// return (f->mat_nr == 0);  /* quick test */
 	return (BM_elem_index_get(f) < data->face_tot_first_mesh);
 }




More information about the Bf-blender-cvs mailing list