[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43141] branches/bmesh/blender/source/ blender/modifiers/intern/MOD_screw.c: convert screw modifier to create MPolys rather then MFaces

Campbell Barton ideasman42 at gmail.com
Wed Jan 4 21:11:17 CET 2012


Revision: 43141
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43141
Author:   campbellbarton
Date:     2012-01-04 20:11:08 +0000 (Wed, 04 Jan 2012)
Log Message:
-----------
convert screw modifier to create MPolys rather then MFaces

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_screw.c

Modified: branches/bmesh/blender/source/blender/modifiers/intern/MOD_screw.c
===================================================================
--- branches/bmesh/blender/source/blender/modifiers/intern/MOD_screw.c	2012-01-04 19:18:11 UTC (rev 43140)
+++ branches/bmesh/blender/source/blender/modifiers/intern/MOD_screw.c	2012-01-04 20:11:08 UTC (rev 43141)
@@ -132,6 +132,23 @@
 	tltmd->iter= sltmd->iter;
 }
 
+#if 0
+static int findEd(MEdge *medge_new, int toted, int v1, int v2)
+{
+	int i;
+
+	for (i = 0; i < toted; i++) {
+		if ( (medge_new[i].v1 == v1 && medge_new[i].v2 == v2) ||
+		     (medge_new[i].v1 == v2 && medge_new[i].v2 == v1) )
+		{
+			return i;
+		}
+	}
+
+	return -1;
+}
+#endif
+
 static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 						DerivedMesh *derivedData,
 						int useRenderParams,
@@ -142,13 +159,13 @@
 	ScrewModifierData *ltmd= (ScrewModifierData*) md;
 	
 	int *origindex;
-	int mface_index=0;
+	int mpoly_index=0;
 	int step;
 	int i, j;
 	unsigned int i1, i2;
 	int step_tot= useRenderParams ? ltmd->render_steps : ltmd->steps;
 	const int do_flip = ltmd->flag & MOD_SCREW_NORMAL_FLIP ? 1 : 0;
-	int maxVerts=0, maxEdges=0, maxFaces=0;
+	int maxVerts=0, maxEdges=0, maxPolys=0;
 	const unsigned int totvert= dm->getNumVerts(dm);
 	const unsigned int totedge= dm->getNumEdges(dm);
 
@@ -166,7 +183,8 @@
 	short other_axis_1, other_axis_2;
 	float *tmpf1, *tmpf2;
 	
-	MFace *mface_new, *mf_new;
+	MPoly *mpoly_new, *mp_new;
+	MLoop *mloop_new, *ml_new;
 	MEdge *medge_orig, *med_orig, *med_new, *med_new_firstloop, *medge_new;
 	MVert *mvert_new, *mvert_orig, *mv_orig, *mv_new, *mv_new_base;
 
@@ -278,7 +296,7 @@
 		maxVerts =	totvert  * step_tot; /* -1 because we're joining back up */
 		maxEdges =	(totvert * step_tot) + /* these are the edges between new verts */
 					(totedge * step_tot); /* -1 because vert edges join */
-		maxFaces =	totedge * step_tot;
+		maxPolys =	totedge * step_tot;
 
 		screw_ofs= 0.0f;
 	}
@@ -289,21 +307,30 @@
 		maxVerts =	totvert  * step_tot; /* -1 because we're joining back up */
 		maxEdges =	(totvert * (step_tot-1)) + /* these are the edges between new verts */
 					(totedge * step_tot); /* -1 because vert edges join */
-		maxFaces =	totedge * (step_tot-1);
+		maxPolys =	totedge * (step_tot-1);
 	}
 	
-	result= CDDM_from_template(dm, maxVerts, maxEdges, maxFaces, 0, 0);
+	result= CDDM_from_template(dm, maxVerts, maxEdges, 0, maxPolys * 4, maxPolys);
 	
 	/* copy verts from mesh */
 	mvert_orig =	dm->getVertArray(dm);
 	medge_orig =	dm->getEdgeArray(dm);
 	
 	mvert_new =		result->getVertArray(result);
-	mface_new =		result->getTessFaceArray(result);
+	mpoly_new =		result->getPolyArray(result);
+	mloop_new =		result->getLoopArray(result);
 	medge_new =		result->getEdgeArray(result);
-	
-	origindex= result->getTessFaceDataArray(result, CD_ORIGINDEX);
 
+	if (!CustomData_has_layer(&result->polyData, CD_ORIGINDEX)) {
+		CustomData_add_layer(&result->polyData, CD_ORIGINDEX, CD_CALLOC, NULL, maxPolys);
+	}
+
+#if 0 // trunk
+	origindex = result->getPolyDataArray(result, CD_ORIGINDEX);
+#else // bmesh
+	origindex = CustomData_get_layer(&result->polyData, CD_ORIGINDEX);
+#endif
+
 	DM_copy_vert_data(dm, result, 0, 0, totvert); /* copy first otherwise this overwrites our own vertex normals */
 	
 	/* Set the locations of the first set of verts */
@@ -746,7 +773,8 @@
 		}
 	}
 	
-	mf_new= mface_new;
+	mp_new= mpoly_new;
+	ml_new= mloop_new;
 	med_new_firstloop= medge_new;
 	
 	for (i=0; i < totedge; i++, med_new_firstloop++) {
@@ -758,27 +786,37 @@
 			
 			/* new face */
 			if(do_flip) {
-				mf_new->v4= i1;
-				mf_new->v3= i2;
-				mf_new->v2= i2 + totvert;
-				mf_new->v1= i1 + totvert;
+				ml_new[3].v = i1;
+				ml_new[2].v = i2;
+				ml_new[1].v = i2 + totvert;
+				ml_new[0].v = i1 + totvert;
+
+				ml_new[2].e = step == 0 ? i : (totedge + (totvert * step_tot) + step + (i * (step_tot - 1))) - 1;
+				ml_new[1].e = totedge + i2;
+				ml_new[0].e = totedge + (totvert * step_tot) + step + (i * (step_tot - 1));
+				ml_new[3].e = totedge + i1;
 			}
 			else {
-				mf_new->v1= i1;
-				mf_new->v2= i2;
-				mf_new->v3= i2 + totvert;
-				mf_new->v4= i1 + totvert;
+				ml_new[0].v = i1;
+				ml_new[1].v = i2;
+				ml_new[2].v = i2 + totvert;
+				ml_new[3].v = i1 + totvert;
+
+				ml_new[0].e = step == 0 ? i : (totedge + (totvert * step_tot) + step + (i * (step_tot - 1))) - 1;
+				ml_new[1].e = totedge + i2;
+				ml_new[2].e = totedge + (totvert * step_tot) + step + (i * (step_tot - 1));
+				ml_new[3].e = totedge + i1;
 			}
+
+
+			mp_new->loopstart = mpoly_index * 4;
+			mp_new->totloop = 4;
+			mp_new->flag= ME_SMOOTH;
+			origindex[mpoly_index]= ORIGINDEX_NONE;
+			mp_new++;
+			ml_new += 4;
+			mpoly_index++;
 			
-			if( !mf_new->v3 || !mf_new->v4 ) {
-				SWAP(unsigned int, mf_new->v1, mf_new->v3);
-				SWAP(unsigned int, mf_new->v2, mf_new->v4);
-			}
-			mf_new->flag= ME_SMOOTH;
-			origindex[mface_index]= ORIGINDEX_NONE;
-			mf_new++;
-			mface_index++;
-			
 			/* new vertical edge */
 			if (step) { /* The first set is already dome */
 				med_new->v1= i1;
@@ -794,26 +832,35 @@
 		/* close the loop*/
 		if (close) { 
 			if(do_flip) {
-				mf_new->v4= i1;
-				mf_new->v3= i2;
-				mf_new->v2= med_new_firstloop->v2;
-				mf_new->v1= med_new_firstloop->v1;
+				ml_new[3].v = i1;
+				ml_new[2].v = i2;
+				ml_new[1].v = med_new_firstloop->v2;
+				ml_new[0].v = med_new_firstloop->v1;
+
+				ml_new[2].e = (totedge + (totvert * step_tot) + step + (i * (step_tot - 1))) - 1;
+				ml_new[1].e = totedge + i2;
+				ml_new[0].e = i;
+				ml_new[3].e = totedge + i1;
 			}
 			else {
-				mf_new->v1= i1;
-				mf_new->v2= i2;
-				mf_new->v3= med_new_firstloop->v2;
-				mf_new->v4= med_new_firstloop->v1;
+				ml_new[0].v = i1;
+				ml_new[1].v = i2;
+				ml_new[2].v = med_new_firstloop->v2;
+				ml_new[3].v = med_new_firstloop->v1;
+
+				ml_new[0].e = (totedge + (totvert * step_tot) + step + (i * (step_tot - 1))) - 1;
+				ml_new[1].e = totedge + i2;
+				ml_new[2].e = i;
+				ml_new[3].e = totedge + i1;
 			}
 
-			if( !mf_new->v3 || !mf_new->v4 ) {
-				SWAP(unsigned int, mf_new->v1, mf_new->v3);
-				SWAP(unsigned int, mf_new->v2, mf_new->v4);
-			}
-			mf_new->flag= ME_SMOOTH;
-			origindex[mface_index]= ORIGINDEX_NONE;
-			mf_new++;
-			mface_index++;
+			mp_new->loopstart = mpoly_index * 4;
+			mp_new->totloop = 4;
+			mp_new->flag= ME_SMOOTH;
+			origindex[mpoly_index]= ORIGINDEX_NONE;
+			mp_new++;
+			ml_new += 4;
+			mpoly_index++;
 		}
 		
 		/* new vertical edge */
@@ -824,10 +871,38 @@
 		med_new++;
 	}
 
-	/* BMesh implimentation info - need to calculate polys before recalculating
-	 * normals, since normal calc overwrites MFaces from Polys */
-	CDDM_tessfaces_to_faces(result);
+	/* validate */
+#if 0
+	{
+		i = 0;
+		printf("\n");
+		for ( ; i < maxPolys * 4; i += 4) {
+			int ii;
+			ml_new = mloop_new + i;
+			ii = findEd(medge_new, maxEdges, ml_new[0].v, ml_new[1].v);
+			printf("%d %d -- ", ii, ml_new[0].e);
+			ml_new[0].e = ii;
 
+			ii = findEd(medge_new, maxEdges, ml_new[1].v, ml_new[2].v);
+			printf("%d %d -- ", ii, ml_new[1].e);
+			ml_new[1].e = ii;
+
+			ii = findEd(medge_new, maxEdges, ml_new[2].v, ml_new[3].v);
+			printf("%d %d -- ", ii, ml_new[2].e);
+			ml_new[2].e = ii;
+
+			ii = findEd(medge_new, maxEdges, ml_new[3].v, ml_new[0].v);
+			printf("%d %d\n", ii, ml_new[3].e);
+			ml_new[3].e = ii;
+
+		}
+	}
+#endif
+
+
+	/* BMESH_TODO - remove this and make modifiers create their own tessfaces on demand */
+	CDDM_recalc_tesselation(result);
+
 	if((ltmd->flag & MOD_SCREW_NORMAL_CALC) == 0) {
 		CDDM_calc_normals(result);
 	}



More information about the Bf-blender-cvs mailing list