[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25308] branches/sculpt25/source/blender: Sculpt Branch: multires conversion from 2.4 working again.

Brecht Van Lommel brecht at blender.org
Fri Dec 11 11:56:20 CET 2009


Revision: 25308
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25308
Author:   blendix
Date:     2009-12-11 11:56:20 +0100 (Fri, 11 Dec 2009)

Log Message:
-----------
Sculpt Branch: multires conversion from 2.4 working again.

Modified Paths:
--------------
    branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.c
    branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.h
    branches/sculpt25/source/blender/blenkernel/intern/multires.c
    branches/sculpt25/source/blender/blenloader/intern/readfile.c

Modified: branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.c
===================================================================
--- branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.c	2009-12-11 08:05:05 UTC (rev 25307)
+++ branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.c	2009-12-11 10:56:20 UTC (rev 25308)
@@ -2188,6 +2188,48 @@
 	return eCCGError_None;
 }
 
+/* copy other places to face grid coordinates */
+CCGError ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, int numEffectedF)
+{
+	int i, S, x, gridSize, cornerIdx, subdivLevels;
+	int vertDataSize = ss->meshIFC.vertDataSize, freeF;
+
+	subdivLevels = ss->subdivLevels;
+	lvl = (lvl)? lvl: subdivLevels;
+	gridSize = 1 + (1<<(lvl-1));
+	cornerIdx = gridSize-1;
+
+	ccgSubSurf__allFaces(ss, &effectedF, &numEffectedF, &freeF);
+
+	for (i=0; i<numEffectedF; i++) {
+		CCGFace *f = effectedF[i];
+
+		for (S=0; S<f->numVerts; S++) {
+			int prevS = (S+f->numVerts-1)%f->numVerts;
+			CCGEdge *e = FACE_getEdges(f)[S];
+			CCGEdge *prevE = FACE_getEdges(f)[prevS];
+
+			for (x=0; x<gridSize; x++) {
+				int eI = gridSize-1-x;
+				VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, x), _edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI,vertDataSize));
+				VertDataCopy(FACE_getIFCo(f, lvl, S, x, cornerIdx), _edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI,vertDataSize));
+			}
+
+			for (x=1; x<gridSize-1; x++) {
+				VertDataCopy(FACE_getIFCo(f, lvl, S, 0, x), FACE_getIECo(f, lvl, prevS, x));
+				VertDataCopy(FACE_getIFCo(f, lvl, S, x, 0), FACE_getIECo(f, lvl, S, x));
+			}
+
+			VertDataCopy(FACE_getIFCo(f, lvl, S, 0, 0), FACE_getCenterData(f));
+			VertDataCopy(FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx), VERT_getCo(FACE_getVerts(f)[S], lvl));
+		}
+	}
+
+	if(freeF) CCGSUBSURF_free(ss, effectedF);
+
+	return eCCGError_None;
+}
+
 /* stitch together face grids, averaging coordinates at edges
    and vertices, for multires displacements */
 CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, int numEffectedF)

Modified: branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.h
===================================================================
--- branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.h	2009-12-11 08:05:05 UTC (rev 25307)
+++ branches/sculpt25/source/blender/blenkernel/intern/CCGSubSurf.h	2009-12-11 10:56:20 UTC (rev 25308)
@@ -60,6 +60,7 @@
 CCGError	ccgSubSurf_processSync	(CCGSubSurf *ss);
 
 CCGError	ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
+CCGError	ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
 CCGError	ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **faces, int numFaces);
 CCGError	ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
 CCGError	ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);

Modified: branches/sculpt25/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/sculpt25/source/blender/blenkernel/intern/multires.c	2009-12-11 08:05:05 UTC (rev 25307)
+++ branches/sculpt25/source/blender/blenkernel/intern/multires.c	2009-12-11 10:56:20 UTC (rev 25308)
@@ -838,7 +838,6 @@
 	}
 }
 
-#if 0
 static void create_old_vert_face_map(ListBase **map, IndexNode **mem, const MultiresFace *mface,
 				     const int totvert, const int totface)
 {
@@ -961,10 +960,71 @@
 	}
 }
 
+static void multires_old_mvert_to_ss(DerivedMesh *dm, MVert *mvert)
+{
+	CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
+	CCGSubSurf *ss = ccgdm->ss;
+	DMGridData *vd;
+	int index;
+	int totvert, totedge, totface;
+	int gridSize = ccgSubSurf_getGridSize(ss);
+	int edgeSize = ccgSubSurf_getEdgeSize(ss);
+	int i = 0;
+
+	totface = ccgSubSurf_getNumFaces(ss);
+	for(index = 0; index < totface; index++) {
+		CCGFace *f = ccgdm->faceMap[index].face;
+		int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
+
+		vd= ccgSubSurf_getFaceCenterData(f);
+		copy_v3_v3(vd->co, mvert[i].co);
+		i++;
+		
+		for(S = 0; S < numVerts; S++) {
+			for(x = 1; x < gridSize - 1; x++, i++) {
+				vd= ccgSubSurf_getFaceGridEdgeData(ss, f, S, x);
+				copy_v3_v3(vd->co, mvert[i].co);
+			}
+		}
+
+		for(S = 0; S < numVerts; S++) {
+			for(y = 1; y < gridSize - 1; y++) {
+				for(x = 1; x < gridSize - 1; x++, i++) {
+					vd= ccgSubSurf_getFaceGridData(ss, f, S, x, y);
+					copy_v3_v3(vd->co, mvert[i].co);
+				}
+			}
+		}
+	}
+
+	totedge = ccgSubSurf_getNumEdges(ss);
+	for(index = 0; index < totedge; index++) {
+		CCGEdge *e = ccgdm->edgeMap[index].edge;
+		int x;
+
+		for(x = 1; x < edgeSize - 1; x++, i++) {
+			vd= ccgSubSurf_getEdgeData(ss, e, x);
+			copy_v3_v3(vd->co, mvert[i].co);
+		}
+	}
+
+	totvert = ccgSubSurf_getNumVerts(ss);
+	for(index = 0; index < totvert; index++) {
+		CCGVert *v = ccgdm->vertMap[index].vert;
+
+		vd= ccgSubSurf_getVertData(ss, v);
+		copy_v3_v3(vd->co, mvert[i].co);
+		i++;
+	}
+
+	ccgSubSurf_updateToFaces(ss, 0, NULL, 0);
+}
+
 /* Loads a multires object stored in the old Multires struct into the new format */
-static void multires_load_old_dm(DerivedMesh *dm, Multires *mr, int totlvl)
+static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl)
 {
 	MultiresLevel *lvl, *lvl1;
+	Multires *mr= me->mr;
 	MVert *vsrc, *vdst;
 	int src, dst;
 	int st = multires_side_tot[totlvl - 1] - 1;
@@ -976,7 +1036,7 @@
 	src = 0;
 	dst = 0;
 	vsrc = mr->verts;
-	vdst = CDDM_get_verts(dm);
+	vdst = dm->getVertArray(dm);
 	totvert = dm->getNumVerts(dm);
 	vvmap = MEM_callocN(sizeof(int) * totvert, "multires vvmap");
 
@@ -1123,13 +1183,13 @@
 		copy_v3_v3(vdst[i].co, vsrc[vvmap[i]].co);
 
 	MEM_freeN(vvmap);
+
+	multires_old_mvert_to_ss(dm, vdst);
 }
-#endif
 
+
 void multires_load_old(Object *ob, Mesh *me)
 {
-	/* XXX not implemented */
-#if 0
 	MultiresLevel *lvl;
 	ModifierData *md;
 	MultiresModifierData *mmd;
@@ -1173,14 +1233,14 @@
 	orig = CDDM_from_mesh(me, NULL);
 	dm = multires_dm_create_from_derived(mmd, 0, orig, ob, 0, 0);
 					   
-	multires_load_old_dm(dm, me->mr, mmd->totlvl);
+	multires_load_old_dm(dm, me, mmd->totlvl+1);
 
 	multires_dm_mark_as_modified(dm);
 	dm->release(dm);
 	orig->release(orig);
-#endif
 
 	/* Remove the old multires */
 	multires_free(me->mr);
+	me->mr= NULL;
 }
 

Modified: branches/sculpt25/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sculpt25/source/blender/blenloader/intern/readfile.c	2009-12-11 08:05:05 UTC (rev 25307)
+++ branches/sculpt25/source/blender/blenloader/intern/readfile.c	2009-12-11 10:56:20 UTC (rev 25308)
@@ -10133,17 +10133,19 @@
 			if(!sce->toolsettings->particle.selectmode)
 				sce->toolsettings->particle.selectmode= SCE_SELECT_PATH;
 
-		for(me=main->mesh.first; me; me=me->id.next)
-			multires_load_old_250(me);
+		if (main->versionfile == 250 && main->subversionfile > 1) {
+			for(me=main->mesh.first; me; me=me->id.next)
+				multires_load_old_250(me);
 
-		for(ob=main->object.first; ob; ob=ob->id.next) {
-			MultiresModifierData *mmd = (MultiresModifierData *)modifiers_findByType(ob, eModifierType_Multires);
+			for(ob=main->object.first; ob; ob=ob->id.next) {
+				MultiresModifierData *mmd = (MultiresModifierData *)modifiers_findByType(ob, eModifierType_Multires);
 
-			if(mmd) {
-				mmd->totlvl--;
-				mmd->lvl--;
-				mmd->sculptlvl= mmd->lvl;
-				mmd->renderlvl= mmd->lvl;
+				if(mmd) {
+					mmd->totlvl--;
+					mmd->lvl--;
+					mmd->sculptlvl= mmd->lvl;
+					mmd->renderlvl= mmd->lvl;
+				}
 			}
 		}
 	}





More information about the Bf-blender-cvs mailing list