[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35214] branches/bmesh/blender: =bmesh=

Joseph Eagar joeedh at gmail.com
Sun Feb 27 08:49:37 CET 2011


Revision: 35214
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35214
Author:   joeedh
Date:     2011-02-27 07:49:36 +0000 (Sun, 27 Feb 2011)
Log Message:
-----------
=bmesh=

Mirror modifier no longer uses bmesh, but is now
100% CDDM.  This is faster; the sluggishness was
driving me crazy.  Still need to deal with UVs,
but that shouldn't be hard.

Modified Paths:
--------------
    branches/bmesh/blender/intern/ghost/intern/GHOST_EventManager.cpp
    branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_array.c
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_edgesplit.c
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c
    branches/bmesh/blender/source/blender/python/intern/bpy_interface.c
    branches/bmesh/blender/source/blender/python/intern/bpy_rna.c

Modified: branches/bmesh/blender/intern/ghost/intern/GHOST_EventManager.cpp
===================================================================
--- branches/bmesh/blender/intern/ghost/intern/GHOST_EventManager.cpp	2011-02-27 06:19:40 UTC (rev 35213)
+++ branches/bmesh/blender/intern/ghost/intern/GHOST_EventManager.cpp	2011-02-27 07:49:36 UTC (rev 35214)
@@ -156,7 +156,7 @@
 			
 			/*write modifier key states*/
 			sys->getModifierKeys(keys);
-			fprintf(m_recfile, "lshift: %d rshift: %d lalt: %d ralt: %d lctrl: %d rctrl: %d command: %d\n", 
+			fprintf(m_recfile, "lshift: %d rshift: %d lalt: %d ralt: %d lctrl: %d rctrl: %d", 
 				(int)keys.get(GHOST_kModifierKeyLeftShift),
 				(int)keys.get(GHOST_kModifierKeyRightShift), 
 				(int)keys.get(GHOST_kModifierKeyLeftAlt), 

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2011-02-27 06:19:40 UTC (rev 35213)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2011-02-27 07:49:36 UTC (rev 35214)
@@ -2225,9 +2225,6 @@
 	if (CustomData_has_layer(&dm->faceData, CD_NORMAL))
 		CustomData_free_layer(&dm->faceData, CD_NORMAL, dm->numFaceData, 0);
 
-	temp_nors = MEM_callocN(numVerts * sizeof(*temp_nors),
-							"CDDM_calc_normals temp_nors");
-
 	/*recalc tesselation to ensure we have valid origindex values
 	  for mface->mpoly lookups.*/
 	cdDM_recalcTesselation2(dm);
@@ -2283,12 +2280,14 @@
 		face_nors, dm->numFaceData);
 }
 
-#if 0
+#if 1
 /*merge verts
  
   vtargetmap is a table that maps vertices to target vertices.  a value of -1
   indicates a vertex is a target, and is to be kept.
   
+  this frees dm, and returns a new one.
+  
   this is a really horribly written function.  ger. - joeedh
 
  */
@@ -2304,96 +2303,20 @@
 	BLI_array_declare(mpoly);
 	MLoop *ml, *mloop = NULL;
 	BLI_array_declare(mloop);
-	SmallHash _hash, *hash=&_hash;
-	SmallHash _hash2, *hash2=&_hash2;
+	EdgeHash *ehash = BLI_edgehash_new();
 	int *newv = NULL, *newe = NULL, *newl = NULL;
 	int *oldv = NULL, *olde = NULL, *oldl = NULL, *oldp = NULL;
 	BLI_array_declare(oldv); BLI_array_declare(olde); BLI_array_declare(oldl); BLI_array_declare(oldp);
 	int i, j, c, totloop, totpoly;
 	
-	BLI_smallhash_init(hash);
-	BLI_smallhash_init(hash2);
-
-#if 0
-	/*split off ngon faces with merges in them*/
-	mp = cddm->mpoly;
-	for (i=0; i<dm->numPolyData; i++, mp++) {
-		ml = cddm->mloop + mp->loopstart;
-		for (j=0; j<mp->totloop; j++, ml++) {
-			MLoop *ml2 = NULL;
-			int k, k1, a;
-			
-			if (ml->v == -1)
-				continue;
-			
-			for (k1=0; k1<mp->totloop; k1++) {
-				k = (j + k1) % mp->totloop;
-				ml2 = cddm->mloop + mp->loopstart + k;
-				
-				if (ml == ml2 || ml2->v == -1)
-					continue;
-				
-				if (vtargetmap[ml->v] == ml2->v || vtargetmap[ml2->v] == ml->v) {
-					MLoop *ml3;
-					MPoly *mp2;
-					int s, e, l, tot;
-					
-					if (k < j) 
-						SWAP(int, k, j);
-					
-					s = j; e = k; tot = 0;
-					l = BLI_array_count(mloop);
-					ml3 = cddm->mloop + mp->loopstart + s;
-					for (a=s; a<e; a++, ml3++) {
-						if (ml3->v == -1)
-							continue;
-						
-						BLI_smallhash_insert(hash, dm->numLoopData + BLI_array_count(mloop), SET_INT_IN_POINTER(mp->loopstart + a - s));
-						BLI_array_append(mloop, *ml3);
-						
-						ml3->v = -1;
-						ml3->e = -1;
-						tot++;
-					}
-					
-					if (!tot)
-						continue;
-					
-					BLI_smallhash_insert(hash2, dm->numPolyData + BLI_array_count(mpoly), SET_INT_IN_POINTER(i));
-	
-					mp2 = BLI_array_append(mpoly, *mp);
-					mp2->loopstart = l + dm->numLoopData;
-					mp2->totloop = tot;
-				}
-			}
-		}
-	}
-
-	ml = MEM_callocN(sizeof(MLoop)*(dm->numLoopData + BLI_array_count(mloop)), "merge mloop");
-	mp = MEM_callocN(sizeof(MPoly)*(dm->numPolyData + BLI_array_count(mloop)), "merge mpoly");
-	
-	memcpy(ml, cddm->mloop, sizeof(MLoop)*dm->numLoopData);
-	memcpy(mp, cddm->mpoly, sizeof(MPoly)*dm->numPolyData);
-	
-	cddm->mloop = ml; cddm->mpoly = mp;
-	
-	memcpy(cddm->mloop+dm->numLoopData, mloop, sizeof(MLoop)*BLI_array_count(mloop));
-	memcpy(cddm->mpoly+dm->numPolyData, mpoly, sizeof(MPoly)*BLI_array_count(mpoly));
-	
-	totloop = dm->numLoopData + BLI_array_count(mloop);
-	totpoly = dm->numPolyData + BLI_array_count(mpoly);
-	
-	BLI_array_empty(mloop);
-	BLI_array_empty(mpoly);
-#else
 	totloop = dm->numLoopData;
 	totpoly = dm->numPolyData;
-#endif
 	
 	newv = MEM_callocN(sizeof(int)*dm->numVertData, "newv vtable CDDM_merge_verts");
 	newe = MEM_callocN(sizeof(int)*dm->numEdgeData, "newv etable CDDM_merge_verts");
 	newl = MEM_callocN(sizeof(int)*totloop, "newv ltable CDDM_merge_verts");
-		
+	
+	/*fill newl with destination vertex indices*/
 	mv = cddm->mvert;
 	c = 0;
 	for (i=0; i<dm->numVertData; i++, mv++) {
@@ -2404,6 +2327,13 @@
 		}
 	}
 	
+	/*now link target vertices to destination indices*/
+	for (i=0; i<dm->numVertData; i++) {
+		if (vtargetmap[i] != -1) {
+			newv[i] = newv[vtargetmap[i]];
+		}
+	}
+	
 	/*find-replace merged vertices with target vertices*/	
 	ml = cddm->mloop;
 	c = 0;
@@ -2426,12 +2356,32 @@
 	me = cddm->medge;
 	c = 0;
 	for (i=0; i<dm->numEdgeData; i++, me++) {
-		if (me->v1 == me->v2)
+		int v1, v2;
+		
+		if (me->v1 == me->v2) {
+			newe[i] = -1;
 			continue;
+		}
 		
-		BLI_array_append(olde, i);
-		newe[i] = c++;
-		BLI_array_append(medge, *me);
+		if (vtargetmap[me->v1] != -1)
+			v1 = vtargetmap[me->v1];
+		else
+			v1 = me->v1;
+		
+		if (vtargetmap[me->v2] != -1)
+			v2 = vtargetmap[me->v2];
+		else
+			v2 = me->v2;
+		
+		if (BLI_edgehash_haskey(ehash, v1, v2)) {
+			newe[i] = GET_INT_FROM_POINTER(BLI_edgehash_lookup(ehash, v1, v2));
+		} else {
+			BLI_array_append(olde, i);
+			newe[i] = c;
+			BLI_array_append(medge, *me);
+			BLI_edgehash_insert(ehash, v1, v2, SET_INT_IN_POINTER(c));
+			c++;
+		}
 	}
 	
 	mp = cddm->mpoly;
@@ -2447,9 +2397,9 @@
 			
 			me = cddm->medge + ml->e;
 			if (me->v1 != me->v2) {
-				BLI_array_append(oldl, j);
+				BLI_array_append(oldl, j+mp->loopstart);
 				BLI_array_append(mloop, *ml);
-				newl[c] = BLI_array_count(mloop)-1;
+				newl[j+mp->loopstart] = BLI_array_count(mloop)-1;
 				c++;
 			}
 		}
@@ -2467,69 +2417,48 @@
 	/*create new cddm*/	
 	cddm2 = (CDDerivedMesh*) CDDM_new(BLI_array_count(mvert), BLI_array_count(medge), 0, BLI_array_count(mloop), BLI_array_count(mpoly));
 	
-	/*copy over data.  CustomData_add_layer can do this, need to look it up.*/
-	memcpy(cddm2->mvert, mvert, sizeof(MVert)*BLI_array_count(mvert));
-	memcpy(cddm2->medge, medge, sizeof(MEdge)*BLI_array_count(medge));
-	memcpy(cddm2->mloop, mloop, sizeof(MLoop)*BLI_array_count(mloop));
-	memcpy(cddm2->mpoly, mpoly, sizeof(MPoly)*BLI_array_count(mpoly));
-	
-	BLI_array_free(mvert); BLI_array_free(medge); BLI_array_free(mloop); BLI_array_free(mpoly);
-	mvert = cddm2->mvert; medge = cddm2->medge; mloop = cddm2->mloop; mpoly = cddm2->mpoly;
-	
 	/*update edge indices and copy customdata*/
-	me = cddm2->medge;
+	me = medge;
 	for (i=0; i<cddm2->dm.numEdgeData; i++, me++) {
-		MEdge cpy;
+		if (newv[me->v1] != -1)
+			me->v1 = newv[me->v1];
+		if (newv[me->v2] != -1)
+			me->v2 = newv[me->v2];
 		
-		me->v1 = newv[me->v1];
-		me->v2 = newv[me->v2];
-		
-		cpy = *me;
 		CustomData_copy_data(&dm->edgeData, &cddm2->dm.edgeData, olde[i], i, 1);
-		*me = cpy;
 	}
 	
 	/*update loop indices and copy customdata*/
-	ml = cddm2->mloop;
+	ml = mloop;
 	for (i=0; i<cddm2->dm.numLoopData; i++, ml++) {
-		MLoop cpy;
-		
-		ml->e = newe[ml->e];
-		ml->v = newv[ml->v];
+		if (newe[ml->e] != -1)
+			ml->e = newe[ml->e];
+		if (newv[ml->v] != -1)
+			ml->v = newv[ml->v];
 			
-		cpy = *ml;
-		
-		if (oldl[i] >= dm->numLoopData)
-			oldl[i] = GET_INT_FROM_POINTER(BLI_smallhash_lookup(hash, (intptr_t)oldl[i]));
-
 		CustomData_copy_data(&dm->loopData, &cddm2->dm.loopData, oldl[i], i, 1);
-		*ml = cpy;
 	}
 	
 	/*copy vertex customdata*/	
-	mv = cddm2->mvert;
+	mv = mvert;
 	for (i=0; i<cddm2->dm.numVertData; i++, mv++) {
-		MVert cpy = *mv;
-		
 		CustomData_copy_data(&dm->vertData, &cddm2->dm.vertData, oldv[i], i, 1);
-		*mv = cpy;
 	}
 	
 	/*copy poly customdata*/
-	mp = cddm2->mpoly;
+	mp = mpoly;
 	for (i=0; i<cddm2->dm.numPolyData; i++, mp++) {
-		MPoly cpy = *mp;
-		
-		if (oldl[i] >= dm->numPolyData)
-			oldl[i] = GET_INT_FROM_POINTER(BLI_smallhash_lookup(hash, (intptr_t)oldl[i]));
-
 		CustomData_copy_data(&dm->polyData, &cddm2->dm.polyData, oldp[i], i, 1);
-		*mp = cpy;
 	}
 	
-	/*eek! not sure what to do with ORIGINDEX stuff here!!*/	
-	cddm2->dm.numFaceData = mesh_recalcTesselation(&cddm2->dm.faceData, &cddm2->dm.loopData, &cddm2->dm.polyData, cddm2->mvert, 0, cddm2->dm.numLoopData, cddm2->dm.numPolyData, 1, 0);
-	cddm2->mface = CustomData_get_layer(&cddm->dm.faceData, CD_MFACE);
+	/*copy over data.  CustomData_add_layer can do this, need to look it up.*/
+	memcpy(cddm2->mvert, mvert, sizeof(MVert)*BLI_array_count(mvert));
+	memcpy(cddm2->medge, medge, sizeof(MEdge)*BLI_array_count(medge));
+	memcpy(cddm2->mloop, mloop, sizeof(MLoop)*BLI_array_count(mloop));
+	memcpy(cddm2->mpoly, mpoly, sizeof(MPoly)*BLI_array_count(mpoly));
+	BLI_array_free(mvert); BLI_array_free(medge); BLI_array_free(mloop); BLI_array_free(mpoly);
+
+	CDDM_recalc_tesselation(cddm2);
 	
 	if (newv) 
 		MEM_freeN(newv); 
@@ -2545,10 +2474,10 @@
 		MEM_freeN(oldl); 
 	if (oldp) 
 		MEM_freeN(oldp);
-	
-	BLI_smallhash_release(hash);
-	BLI_smallhash_release(hash2);
-	
+	if (ehash)
+		BLI_edgehash_free(ehash, NULL);
+
+	/*free old derivedmesh*/
 	dm->needsFree = 1;
 	dm->release(dm);
 	
@@ -2743,6 +2672,11 @@
 	return ((CDDerivedMesh*)dm)->mface;
 }
 
+MLoop *CDDM_get_loops(DerivedMesh *dm)
+{
+	return ((CDDerivedMesh*)dm)->mloop;
+}
+
 MPoly *CDDM_get_polys(DerivedMesh *dm)
 {
 	return ((CDDerivedMesh*)dm)->mpoly;

Modified: branches/bmesh/blender/source/blender/modifiers/intern/MOD_array.c
===================================================================
--- branches/bmesh/blender/source/blender/modifiers/intern/MOD_array.c	2011-02-27 06:19:40 UTC (rev 35213)
+++ branches/bmesh/blender/source/blender/modifiers/intern/MOD_array.c	2011-02-27 07:49:36 UTC (rev 35214)
@@ -529,7 +529,7 @@
 }
 
 static DerivedMesh *applyModifierEM(
-		ModifierData *md, Object *ob, struct EditMesh *editData,
+		ModifierData *md, Object *ob, struct BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
 	return applyModifier(md, ob, derivedData, 0, 1);
@@ -560,6 +560,7 @@
 	/* isDisabled */        0,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list