[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43548] branches/bmesh/blender/source/ blender/modifiers/intern/MOD_build.c: improvements to build modifier

Campbell Barton ideasman42 at gmail.com
Fri Jan 20 01:26:39 CET 2012


Revision: 43548
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43548
Author:   campbellbarton
Date:     2012-01-20 00:26:25 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
improvements to build modifier
- dont make a copy of the source mesh before using it
- dont recalculate tessface's and normals

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

Modified: branches/bmesh/blender/source/blender/modifiers/intern/MOD_build.c
===================================================================
--- branches/bmesh/blender/source/blender/modifiers/intern/MOD_build.c	2012-01-20 00:02:48 UTC (rev 43547)
+++ branches/bmesh/blender/source/blender/modifiers/intern/MOD_build.c	2012-01-20 00:26:25 UTC (rev 43548)
@@ -84,11 +84,11 @@
 	DerivedMesh *result;
 	BuildModifierData *bmd = (BuildModifierData*) md;
 	int i, j, k;
-	int numFaces, numEdges, numLoops = 0;
+	int numFaces_dst, numEdges_dst, numLoops_dst = 0;
 	int *vertMap, *edgeMap, *faceMap;
 	float frac;
-	MPoly *mpolys, *mpolyd;
-	MLoop *mld, *mloops, *mls, *mloopd;
+	MPoly *mpoly_dst;
+	MLoop *ml_dst, *ml_src, *mloop_dst;
 	GHashIterator *hashIter;
 	/* maps vert indices in old mesh to indices in new mesh */
 	GHash *vertHash = BLI_ghash_new(BLI_ghashutil_inthash,
@@ -99,44 +99,44 @@
 	GHash *edgeHash2 = BLI_ghash_new(BLI_ghashutil_inthash,
 					BLI_ghashutil_intcmp, "build ed apply gh");
 
-	const int maxVerts= dm->getNumVerts(dm);
-	const int maxEdges= dm->getNumEdges(dm);
-	const int maxFaces= dm->getNumPolys(dm);
-	
-	if (!CDDM_Check(dm)) {
-		result = CDDM_copy(dm, 0);
-		dm = result;
-	}
-	
-	vertMap = MEM_callocN(sizeof(*vertMap) * maxVerts, "build modifier vertMap");
-	for(i = 0; i < maxVerts; ++i) vertMap[i] = i;
-	edgeMap = MEM_callocN(sizeof(*edgeMap) * maxEdges, "build modifier edgeMap");
-	for(i = 0; i < maxEdges; ++i) edgeMap[i] = i;
-	faceMap = MEM_callocN(sizeof(*faceMap) * maxFaces, "build modifier faceMap");
-	for(i = 0; i < maxFaces; ++i) faceMap[i] = i;
+	const int numVert_src = dm->getNumVerts(dm);
+	const int numEdge_src = dm->getNumEdges(dm);
+	const int numPoly_src = dm->getNumPolys(dm);
+	MPoly *mpoly_src = dm->getPolyArray(dm);
+	MLoop *mloop_src = dm->getLoopArray(dm);
+	MEdge *medge_src = dm->getEdgeArray(dm);
+	MVert *mvert_src = dm->getVertArray(dm);
 
+
+	vertMap = MEM_callocN(sizeof(*vertMap) * numVert_src, "build modifier vertMap");
+	for(i = 0; i < numVert_src; ++i) vertMap[i] = i;
+	edgeMap = MEM_callocN(sizeof(*edgeMap) * numEdge_src, "build modifier edgeMap");
+	for(i = 0; i < numEdge_src; ++i) edgeMap[i] = i;
+	faceMap = MEM_callocN(sizeof(*faceMap) * numPoly_src, "build modifier faceMap");
+	for(i = 0; i < numPoly_src; ++i) faceMap[i] = i;
+
 	frac = (BKE_curframe(md->scene) - bmd->start) / bmd->length;
 	CLAMP(frac, 0.0f, 1.0f);
 
-	numFaces = dm->getNumPolys(dm) * frac;
-	numEdges = dm->getNumEdges(dm) * frac;
+	numFaces_dst = numPoly_src * frac;
+	numEdges_dst = numEdge_src * frac;
 
 	/* if there's at least one face, build based on faces */
-	if(numFaces) {
+	if(numFaces_dst) {
 		MPoly *mpoly, *mp;
 		MLoop *ml, *mloop;
 		MEdge *medge;
 		
 		if(bmd->randomize)
 			BLI_array_randomize(faceMap, sizeof(*faceMap),
-						maxFaces, bmd->seed);
+						numPoly_src, bmd->seed);
 
 		/* get the set of all vert indices that will be in the final mesh,
 		* mapped to the new indices
 		*/
-		mpoly = CDDM_get_polys(dm);
-		mloop = CDDM_get_loops(dm);
-		for(i = 0; i < numFaces; ++i) {
+		mpoly = mpoly_src;
+		mloop = mloop_src;
+		for(i = 0; i < numFaces_dst; ++i) {
 			mp = mpoly + faceMap[i];
 			ml = mloop + mp->loopstart;
 
@@ -146,14 +146,14 @@
 						SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
 			}
 			
-			numLoops += mp->totloop;
+			numLoops_dst += mp->totloop;
 		}
 
 		/* get the set of edges that will be in the new mesh (i.e. all edges
 		* that have both verts in the new mesh)
 		*/
-		medge = CDDM_get_edges(dm);
-		for(i = 0; i < maxEdges; ++i) {
+		medge = medge_src;
+		for(i = 0; i < numEdge_src; ++i) {
 			MEdge *me = medge + i;
 
 			if(BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1))
@@ -165,18 +165,18 @@
 				BLI_ghash_insert(edgeHash2, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(j));
 			}
 		}
-	} else if(numEdges) {
+	} else if(numEdges_dst) {
 		MEdge *medge, *me;
 
 		if(bmd->randomize)
 			BLI_array_randomize(edgeMap, sizeof(*edgeMap),
-						maxEdges, bmd->seed);
+						numEdge_src, bmd->seed);
 
 		/* get the set of all vert indices that will be in the final mesh,
 		* mapped to the new indices
 		*/
-		medge = CDDM_get_edges(dm);
-		for(i = 0; i < numEdges; ++i) {
+		medge = medge_src;
+		for(i = 0; i < numEdges_dst; ++i) {
 			me = medge + edgeMap[i];
 
 			if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1)))
@@ -189,7 +189,7 @@
 
 		/* get the set of edges that will be in the new mesh
 		*/
-		for(i = 0; i < numEdges; ++i) {
+		for(i = 0; i < numEdges_dst; ++i) {
 			j = BLI_ghash_size(edgeHash);
 			
 			BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(j),
@@ -198,11 +198,11 @@
 							 SET_INT_IN_POINTER(j));
 		}
 	} else {
-		int numVerts = dm->getNumVerts(dm) * frac;
+		int numVerts = numVert_src * frac;
 
 		if(bmd->randomize)
 			BLI_array_randomize(vertMap, sizeof(*vertMap),
-						maxVerts, bmd->seed);
+						numVert_src, bmd->seed);
 
 		/* get the set of all vert indices that will be in the final mesh,
 		* mapped to the new indices
@@ -215,7 +215,7 @@
 	* the mesh
 	*/
 	result = CDDM_from_template(dm, BLI_ghash_size(vertHash),
-					BLI_ghash_size(edgeHash), 0, numLoops, numFaces);
+					BLI_ghash_size(edgeHash), 0, numLoops_dst, numFaces_dst);
 
 	/* copy the vertices across */
 	for(	hashIter = BLI_ghashIterator_new(vertHash);
@@ -227,7 +227,7 @@
 		int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter));
 		int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(hashIter));
 
-		dm->getVert(dm, oldIndex, &source);
+		source = mvert_src [oldIndex];
 		dest = CDDM_get_vert(result, newIndex);
 
 		DM_copy_vert_data(dm, result, oldIndex, newIndex, 1);
@@ -241,7 +241,7 @@
 		MEdge *dest;
 		int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i)));
 		
-		dm->getEdge(dm, oldIndex, &source);
+		source = medge_src[oldIndex];
 		dest = CDDM_get_edge(result, i);
 		
 		source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
@@ -251,19 +251,17 @@
 		*dest = source;
 	}
 
-	mpolys = CDDM_get_polys(dm);
-	mpolyd = CDDM_get_polys(result);
-	mloops = CDDM_get_loops(dm);
-	mloopd = mld = CDDM_get_loops(result);
+	mpoly_dst = CDDM_get_polys(result);
+	mloop_dst = ml_dst = CDDM_get_loops(result);
 	
 	/* copy the faces across, remapping indices */
 	k = 0;
-	for(i = 0; i < numFaces; ++i) {
+	for(i = 0; i < numFaces_dst; ++i) {
 		MPoly *source;
 		MPoly *dest;
 		
-		source = mpolys + faceMap[i];
-		dest = mpolyd + i;
+		source = mpoly_src + faceMap[i];
+		dest = mpoly_dst + i;
 		DM_copy_poly_data(dm, result, faceMap[i], i, 1);
 		
 		*dest = *source;
@@ -271,14 +269,12 @@
 		
 		DM_copy_loop_data(dm, result, source->loopstart, dest->loopstart, dest->totloop);
 
-		mls = mloops + source->loopstart;
-		for (j=0; j<source->totloop; j++, k++, mls++, mld++) {
-			mld->v = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(mls->v)));
-			mld->e = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash2, SET_INT_IN_POINTER(mls->e)));
+		ml_src = mloop_src + source->loopstart;
+		for (j=0; j<source->totloop; j++, k++, ml_src++, ml_dst++) {
+			ml_dst->v = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(ml_src->v)));
+			ml_dst->e = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash2, SET_INT_IN_POINTER(ml_src->e)));
 		}
 	}
-
-	CDDM_calc_normals_mapping(result);
 	
 	BLI_ghash_free(vertHash, NULL, NULL);
 	BLI_ghash_free(edgeHash, NULL, NULL);
@@ -287,12 +283,7 @@
 	MEM_freeN(vertMap);
 	MEM_freeN(edgeMap);
 	MEM_freeN(faceMap);
-	
-	if (dm != derivedData) {
-		dm->needsFree = 1;
-		dm->release(dm);
-	}
-	
+
 	return result;
 }
 



More information about the Bf-blender-cvs mailing list