[Bf-blender-cvs] [9715f86] blender-v2.72-release: Fix T4199: Knife holes in concave ngons failed

Campbell Barton noreply at git.blender.org
Wed Oct 15 13:08:01 CEST 2014


Commit: 9715f86b0ccc2332c873c2e194671b1bf176e74b
Author: Campbell Barton
Date:   Tue Oct 7 10:07:06 2014 +0200
Branches: blender-v2.72-release
https://developer.blender.org/rB9715f86b0ccc2332c873c2e194671b1bf176e74b

Fix T4199: Knife holes in concave ngons failed

BM_face_point_inside_test assumed the face center was inside the face.

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

M	source/blender/bmesh/intern/bmesh_polygon.c

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

diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c
index 9a1914b..a8e1acd 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.c
+++ b/source/blender/bmesh/intern/bmesh_polygon.c
@@ -666,49 +666,25 @@ static bool line_crosses_v2f(const float v1[2], const float v2[2], const float v
  */
 bool BM_face_point_inside_test(BMFace *f, const float co[3])
 {
-	int ax, ay;
-	float co2[2], cent[2] = {0.0f, 0.0f}, out[2] = {FLT_MAX * 0.5f, FLT_MAX * 0.5f};
+	float axis_mat[3][3];
+	float (*projverts)[2] = BLI_array_alloca(projverts, f->len);
+
+	float co_2d[2];
 	BMLoop *l_iter;
-	BMLoop *l_first;
-	int crosses = 0;
-	float onepluseps = 1.0f + (float)FLT_EPSILON * 150.0f;
+	int i;
 	
 	if (is_zero_v3(f->no))
 		BM_face_normal_update(f);
-	
-	/* find best projection of face XY, XZ or YZ: barycentric weights of
-	 * the 2d projected coords are the same and faster to compute
-	 *
-	 * this probably isn't all that accurate, but it has the advantage of
-	 * being fast (especially compared to projecting into the face orientation)
-	 */
-	axis_dominant_v3(&ax, &ay, f->no);
-
-	co2[0] = co[ax];
-	co2[1] = co[ay];
-	
-	l_iter = l_first = BM_FACE_FIRST_LOOP(f);
-	do {
-		cent[0] += l_iter->v->co[ax];
-		cent[1] += l_iter->v->co[ay];
-	} while ((l_iter = l_iter->next) != l_first);
-	
-	mul_v2_fl(cent, 1.0f / (float)f->len);
-	
-	l_iter = l_first = BM_FACE_FIRST_LOOP(f);
-	do {
-		float v1[2], v2[2];
-		
-		v1[0] = (l_iter->prev->v->co[ax] - cent[0]) * onepluseps + cent[0];
-		v1[1] = (l_iter->prev->v->co[ay] - cent[1]) * onepluseps + cent[1];
-		
-		v2[0] = (l_iter->v->co[ax] - cent[0]) * onepluseps + cent[0];
-		v2[1] = (l_iter->v->co[ay] - cent[1]) * onepluseps + cent[1];
-		
-		crosses += line_crosses_v2f(v1, v2, co2, out) != 0;
-	} while ((l_iter = l_iter->next) != l_first);
-	
-	return crosses % 2 != 0;
+
+	axis_dominant_v3_to_m3(axis_mat, f->no);
+
+	mul_v2_m3v3(co_2d, axis_mat, co);
+
+	for (i = 0, l_iter = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l_iter = l_iter->next) {
+		mul_v2_m3v3(projverts[i], axis_mat, l_iter->v->co);
+	}
+
+	return isect_point_poly_v2(co_2d, (const float (*)[2])projverts, f->len, false);
 }
 
 /**




More information about the Bf-blender-cvs mailing list