[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45701] trunk/blender/source/blender/ blenlib/intern/scanfill.c: improve scanfill for uneven ngons, previously scanfill would use the most angular corner, but this made non planer ngons rip frequently (often reported problem).

Campbell Barton ideasman42 at gmail.com
Mon Apr 16 18:24:55 CEST 2012


Revision: 45701
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45701
Author:   campbellbarton
Date:     2012-04-16 16:24:55 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
improve scanfill for uneven ngons, previously scanfill would use the most angular corner, but this made non planer ngons rip frequently (often reported problem).

now calculate the normal as with ngons.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/scanfill.c

Modified: trunk/blender/source/blender/blenlib/intern/scanfill.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/scanfill.c	2012-04-16 15:13:21 UTC (rev 45700)
+++ trunk/blender/source/blender/blenlib/intern/scanfill.c	2012-04-16 16:24:55 UTC (rev 45701)
@@ -786,7 +786,7 @@
 	ScanFillVert *eve;
 	ScanFillEdge *eed, *nexted;
 	PolyFill *pflist, *pf;
-	float limit, *min_xy_p, *max_xy_p, *v1, *v2, norm[3], len;
+	float *min_xy_p, *max_xy_p;
 	short a, c, poly = 0, ok = 0, toggle = 0;
 	int totfaces = 0; /* total faces added */
 	int co_x, co_y;
@@ -813,7 +813,7 @@
 
 		eve = sf_ctx->fillvertbase.first;
 		/* no need to check 'eve->next->next->next' is valid, already counted */
-		/*use shortest diagonal for quad*/
+		/* use shortest diagonal for quad */
 		sub_v3_v3v3(vec1, eve->co, eve->next->next->co);
 		sub_v3_v3v3(vec2, eve->next->co, eve->next->next->next->co);
 
@@ -848,42 +848,36 @@
 		eve = eve->next;
 	}
 
-	if (ok == 0) return 0;
+	if (ok == 0) {
+		return 0;
+	}
+	else {
+		/* define projection: with 'best' normal */
+		/* Newell's Method */
+		/* Similar code used elsewhere, but this checks for double ups
+		 * which historically this function supports so better not change */
+		float *v_prev;
+		float n[3] = {0.0f};
 
-	/* NEW NEW! define projection: with 'best' normal */
-	/* just use the first three different vertices */
-	
-	/* THIS PART STILL IS PRETTY WEAK! (ton) */
+		eve = sf_ctx->fillvertbase.last;
+		v_prev = eve->co;
 
-	eve = sf_ctx->fillvertbase.last;
-	len = 0.0;
-	v1 = eve->co;
-	v2 = 0;
-	eve = sf_ctx->fillvertbase.first;
-	limit = 1e-8f;
-
-	while (eve) {
-		if (v2) {
-			if (!compare_v3v3(v2, eve->co, COMPLIMIT)) {
-				float inner = angle_v3v3v3(v1, v2, eve->co);
-				inner = MIN2(fabsf(inner), fabsf(M_PI - inner));
-
-				if (inner > limit) {
-					limit = inner;
-					len = normal_tri_v3(norm, v1, v2, eve->co);
-				}
+		for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
+			if (!compare_v3v3(v_prev, eve->co, COMPLIMIT)) {
+				n[0] += (v_prev[1] - eve->co[1]) * (v_prev[2] + eve->co[2]);
+				n[1] += (v_prev[2] - eve->co[2]) * (v_prev[0] + eve->co[0]);
+				n[2] += (v_prev[0] - eve->co[0]) * (v_prev[1] + eve->co[1]);
 			}
 		}
-		else if (!compare_v3v3(v1, eve->co, COMPLIMIT))
-			v2 = eve->co;
 
-		eve = eve->next;
+		if (UNLIKELY(normalize_v3(n) == 0.0f)) {
+			n[2] = 1.0f; /* other axis set to 0.0 */
+		}
+
+		axis_dominant_v3(&co_x, &co_y, n);
 	}
 
-	if (len == 0.0f) return 0;  /* no fill possible */
 
-	axis_dominant_v3(&co_x, &co_y, norm);
-
 	/* STEP 1: COUNT POLYS */
 	eve = sf_ctx->fillvertbase.first;
 	while (eve) {




More information about the Bf-blender-cvs mailing list