[Bf-blender-cvs] [2b3f06d] bmesh-boolean-experiment: Fix error with concave ngons

Campbell Barton noreply at git.blender.org
Thu Nov 26 07:21:03 CET 2015


Commit: 2b3f06df89ea5ee895cb18be8b0fa171946d54e0
Author: Campbell Barton
Date:   Thu Nov 26 17:13:24 2015 +1100
Branches: bmesh-boolean-experiment
https://developer.blender.org/rB2b3f06df89ea5ee895cb18be8b0fa171946d54e0

Fix error with concave ngons

Failed when face-center wasn't inside the face.
copy-paste from knife tool, best make generic function eventually.

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

M	source/blender/bmesh/tools/bmesh_intersect.c

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

diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c
index 3a31d0d..dd551be 100644
--- a/source/blender/bmesh/tools/bmesh_intersect.c
+++ b/source/blender/bmesh/tools/bmesh_intersect.c
@@ -794,6 +794,46 @@ static void bm_isect_tri_tri(
 	}
 }
 
+/* copy of #edbm_mesh_knife_face_point. we could de-duplicate these */
+static void bm_face_calc_point_on_face(BMFace *f, float r_cent[3])
+{
+	if (f->len == 3) {
+		BM_face_calc_center_mean(f, r_cent);
+		return;
+	}
+
+	const int tottri = f->len - 2;
+	BMLoop **loops = BLI_array_alloca(loops, (unsigned int)f->len);
+	unsigned int  (*index)[3] = BLI_array_alloca(index, (unsigned int)tottri);
+	int j;
+	int j_best = 0;  /* use as fallback when unset */
+	float area_best  = -1.0f;
+
+	/* XXX, needed? (probably the one copied from the original face is close enough) */
+	BM_face_normal_update(f);
+
+	BM_face_calc_tessellation(f, loops, index);
+
+	for (j = 0; j < tottri; j++) {
+		const float *p1 = loops[index[j][0]]->v->co;
+		const float *p2 = loops[index[j][1]]->v->co;
+		const float *p3 = loops[index[j][2]]->v->co;
+		float area;
+
+		area = area_squared_tri_v3(p1, p2, p3);
+		if (area > area_best) {
+			j_best = j;
+			area_best = area;
+		}
+	}
+
+	mid_v3_v3v3v3(
+	        r_cent,
+	        loops[index[j_best][0]]->v->co,
+	        loops[index[j_best][1]]->v->co,
+	        loops[index[j_best][2]]->v->co);
+}
+
 #ifdef USE_BVH
 
 
@@ -1596,7 +1636,7 @@ bool BM_mesh_intersect(
 			/* TODO, find if islands are inside/outside,
 			 * for now remove alternate islands, as simple testcase */
 
-
+			printf("Found %d\n", group_tot);
 			for (i = 0; i < group_tot; i++) {
 				int fg     = group_index[i][0];
 				int fg_end = group_index[i][1] + fg;
@@ -1609,7 +1649,8 @@ bool BM_mesh_intersect(
 					int hits;
 					int side = test_fn(f, user_data) == 0;
 
-					BM_face_calc_center_mean(f, co);
+					// BM_face_calc_center_mean(f, co);
+					bm_face_calc_point_on_face(f, co);
 
 					hits = isect_bvhtree_point_v3(tree_pair[side], looptri_coords, co);
 
@@ -1633,7 +1674,7 @@ bool BM_mesh_intersect(
 						unsigned int colors[4] = {0x00000000, 0xffffffff, 0xff000000, 0x0000ff};
 						float co_other[3] = {UNPACK3(co)};
 						co_other[0] += 1000.0f;
-						bl_debug_color_set(hits < 3 ? colors[hits] : 0xAAAAAA);
+						bl_debug_color_set(colors[(hits & 1) == 1]);
 						bl_debug_draw_edge_add(co, co_other);
 					}
 #endif




More information about the Bf-blender-cvs mailing list