Sculpt Branch: multires conversion from 2.4 working again.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 11 Dec 2009 10:56:20 +0000 (10:56 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 11 Dec 2009 10:56:20 +0000 (10:56 +0000)
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/CCGSubSurf.h
source/blender/blenkernel/intern/multires.c
source/blender/blenloader/intern/readfile.c

index 4bd0586c592fcb820d405b570ed8fdcb3ba291e4..dc863869ad842fa042ddf70dfd5b3b2af2f796ac 100644 (file)
@@ -2188,6 +2188,48 @@ CCGError ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF
        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)
index d51cf0128c304b6e17fa4006dcfa22c282568727..12212c7a37b2d94fffc031bca0051aaea62d81ce 100644 (file)
@@ -60,6 +60,7 @@ CCGError      ccgSubSurf_syncFaceDel  (CCGSubSurf *ss, CCGFaceHDL fHDL);
 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);
index bf02bd89f721ee1ceeab22308553b5785df6f039..e1f2b22c9f0ca0c45fd327d1af85827a96db44b6 100644 (file)
@@ -838,7 +838,6 @@ void multires_free(Multires *mr)
        }
 }
 
-#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_load_old_faces(ListBase **fmap, ListBase **emap, MultiresLe
        }
 }
 
+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 @@ static void multires_load_old_dm(DerivedMesh *dm, Multires *mr, int totlvl)
        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 @@ static void multires_load_old_dm(DerivedMesh *dm, Multires *mr, int totlvl)
                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 @@ void multires_load_old(Object *ob, Mesh *me)
        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;
 }
 
index 039f8c60201b788d97b52f6a6c6d7121e2f7d8d6..d6d43eacd8509c2094fa1d4379d76c45cfcce7c3 100644 (file)
@@ -10133,17 +10133,19 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        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;
+                               }
                        }
                }
        }