[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20363] branches/bmesh/blender/source/ blender: ngons are tesselated properly again, using scanfill, though need to get it to update on transform step still.

Joseph Eagar joeedh at gmail.com
Sat May 23 18:53:06 CEST 2009


Revision: 20363
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20363
Author:   joeedh
Date:     2009-05-23 18:53:03 +0200 (Sat, 23 May 2009)

Log Message:
-----------
ngons are tesselated properly again, using scanfill, though need to get it to update on transform step still.  also made normals for ngons sortof work, but it's still buggy and not looking right :-/

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c	2009-05-23 14:46:43 UTC (rev 20362)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c	2009-05-23 16:53:03 UTC (rev 20363)
@@ -58,6 +58,7 @@
 #include "BLI_edgehash.h"
 #include "BLI_linklist.h"
 #include "BLI_memarena.h"
+#include "BLI_scanfill.h"
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_customdata.h"
@@ -112,7 +113,9 @@
 	tm2->bm = BM_Copy_Mesh(tm->bm);
 	TM_RecalcTesselation(tm2);
 
-	tm2->vert_index = tm2->edge_index = tm2->face_index = NULL;
+	tm2->vert_index = NULL;
+	tm2->edge_index = NULL;
+	tm2->face_index = NULL;
 
 	return tm2;
 }
@@ -134,21 +137,59 @@
 		/*don't consider two-edged faces*/
 		if (f->len < 3) continue;
 		
-		/*for now, just do a triangle fan, in the future,
-		  use scanfill*/
-		l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
-		for (; l; l=BMIter_Step(&liter)) {
-			if (l == f->loopbase) continue;
-			if ((BMLoop*)l->head.next == f->loopbase) continue;
+		if (f->len <= 4) {
+			/*triangle fan for quads.  should be recoded to
+			  just add one tri for tris, and two for quads,
+			  but this code works for now too.*/
+			l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
+			for (; l; l=BMIter_Step(&liter)) {
+				if (l == f->loopbase) continue;
+				if ((BMLoop*)l->head.next == f->loopbase) continue;
 
-			V_GROW(looptris);
-			V_GROW(looptris);
-			V_GROW(looptris);
+				V_GROW(looptris);
+				V_GROW(looptris);
+				V_GROW(looptris);
 
-			looptris[i*3] = l;
-			looptris[i*3+1] = (BMLoop*)l->head.next;
-			looptris[i*3+2] = f->loopbase;
-			i += 1;
+				looptris[i*3] = l;
+				looptris[i*3+1] = (BMLoop*)l->head.next;
+				looptris[i*3+2] = f->loopbase;
+				i += 1;
+			}
+		} else {
+			/*scanfill time*/
+			EditVert *v, *lastv=NULL, *firstv=NULL;
+			EditEdge *e;
+			EditFace *efa;
+
+			l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
+			for (; l; l=BMIter_Step(&liter)) {
+				v = BLI_addfillvert(l->v->co);
+				v->tmp.p = l;
+				
+				if (lastv) {
+					e = BLI_addfilledge(lastv, v);
+				}
+
+				lastv = v;
+				if (firstv==NULL) firstv = v;
+			}
+
+			/*complete the loop*/
+			BLI_addfilledge(firstv, v);
+
+			BLI_edgefill(0, 0);
+			
+			for (efa = fillfacebase.first; efa; efa=efa->next) {
+				V_GROW(looptris);
+				V_GROW(looptris);
+				V_GROW(looptris);
+
+				looptris[i*3] = efa->v1->tmp.p;
+				looptris[i*3+1] = efa->v2->tmp.p;
+				looptris[i*3+2] = efa->v3->tmp.p;
+				i += 1;
+			}
+			BLI_end_edgefill();
 		}
 	}
 

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c	2009-05-23 14:46:43 UTC (rev 20362)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c	2009-05-23 16:53:03 UTC (rev 20363)
@@ -117,6 +117,15 @@
 	}
 	
 	l = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
+
+	if (l == 0.0) {
+		normal[0] = 0.0f;
+		normal[1] = 0.0f;
+		normal[2] = 1.0f;
+
+		return;
+	}
+
 	n[0] /= l;
 	n[1] /= l;
 	n[2] /= l;
@@ -396,6 +405,7 @@
 		do{
 			VECCOPY(projectverts[i], l->v->co);
 			l = (BMLoop*)(l->head.next);
+			i += 1;
 		}while(l!=f->loopbase);
 
 		compute_poly_plane(projectverts, f->len);





More information about the Bf-blender-cvs mailing list