Sculpt Branch:
[blender.git] / source / blender / blenloader / intern / readfile.c
index eada820ba89d34391c9eed19682370b6b66f17c2..2937b7b22e7faf90d1e424b1d7913924203c2ee6 100644 (file)
@@ -3325,14 +3325,14 @@ static void direct_link_dverts(FileData *fd, int count, MDeformVert *mdverts)
        }
 }
 
-static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps)
+static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int external)
 {
        if(mdisps) {
                int i;
 
                for(i = 0; i < count; ++i) {
                        mdisps[i].disps = newdataadr(fd, mdisps[i].disps);
-                       if(!mdisps[i].disps)
+                       if(!external && !mdisps[i].disps)
                                mdisps[i].totdisp = 0;
                }
        }       
@@ -3343,14 +3343,18 @@ static void direct_link_customdata(FileData *fd, CustomData *data, int count)
        int i = 0;
 
        data->layers= newdataadr(fd, data->layers);
+       data->external= newdataadr(fd, data->external);
 
        while (i < data->totlayer) {
                CustomDataLayer *layer = &data->layers[i];
 
+               if(layer->flag & CD_FLAG_EXTERNAL)
+                       layer->flag &= ~CD_FLAG_IN_MEMORY;
+
                if (CustomData_verify_versions(data, i)) {
                        layer->data = newdataadr(fd, layer->data);
                        if(layer->type == CD_MDISPS)
-                               direct_link_mdisps(fd, count, layer->data);
+                               direct_link_mdisps(fd, count, layer->data, layer->flag & CD_FLAG_EXTERNAL);
                        i++;
                }
        }
@@ -3938,12 +3942,6 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                                                SWITCH_INT(mmd->dynverts[a])
                        }
                }
-               else if (md->type==eModifierType_Multires) {
-                       MultiresModifierData *mmd = (MultiresModifierData*) md;
-                       
-                       mmd->undo_verts = newdataadr(fd, mmd->undo_verts);
-                       mmd->undo_signal = !!mmd->undo_verts;
-               }
        }
 }
 
@@ -9635,7 +9633,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                ToolSettings *ts;
                //PTCacheID *pid;
                //ListBase pidlist;
-               int i, a;
+               int a;
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
                        //BKE_ptcache_ids_from_object(&pidlist, ob);
@@ -9652,58 +9650,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                void *olddata = ob->data;
                                ob->data = me;
 
-                               if(me && me->id.lib==NULL && me->mr) { /* XXX - library meshes crash on loading most yoFrankie levels, the multires pointer gets invalid -  Campbell */
-                                       MultiresLevel *lvl;
-                                       ModifierData *md;
-                                       MultiresModifierData *mmd;
-                                       DerivedMesh *dm, *orig;
-
-                                       /* Load original level into the mesh */
-                                       lvl = me->mr->levels.first;
-                                       CustomData_free_layers(&me->vdata, CD_MVERT, lvl->totvert);
-                                       CustomData_free_layers(&me->edata, CD_MEDGE, lvl->totedge);
-                                       CustomData_free_layers(&me->fdata, CD_MFACE, lvl->totface);
-                                       me->totvert = lvl->totvert;
-                                       me->totedge = lvl->totedge;
-                                       me->totface = lvl->totface;
-                                       me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert);
-                                       me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, me->totedge);
-                                       me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface);
-                                       memcpy(me->mvert, me->mr->verts, sizeof(MVert) * me->totvert);
-                                       for(i = 0; i < me->totedge; ++i) {
-                                               me->medge[i].v1 = lvl->edges[i].v[0];
-                                               me->medge[i].v2 = lvl->edges[i].v[1];
-                                       }
-                                       for(i = 0; i < me->totface; ++i) {
-                                               me->mface[i].v1 = lvl->faces[i].v[0];
-                                               me->mface[i].v2 = lvl->faces[i].v[1];
-                                               me->mface[i].v3 = lvl->faces[i].v[2];
-                                               me->mface[i].v4 = lvl->faces[i].v[3];
-                                       }
-
-                                       /* Add a multires modifier to the object */
-                                       md = ob->modifiers.first;
-                                       while(md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform)
-                                               md = md->next;                          
-                                       mmd = (MultiresModifierData*)modifier_new(eModifierType_Multires);
-                                       BLI_insertlinkbefore(&ob->modifiers, md, mmd);
-
-                                       multiresModifier_subdivide(mmd, ob, me->mr->level_count - 1, 1, 0);
-
-                                       mmd->lvl = mmd->totlvl;
-                                       orig = CDDM_from_mesh(me, NULL);
-                                       dm = multires_dm_create_from_derived(mmd, 0, orig, ob, 0, 0);
-                                       
-                                       multires_load_old(dm, me->mr);
-
-                                       MultiresDM_mark_as_modified(dm);
-                                       dm->release(dm);
-                                       orig->release(orig);
-
-                                       /* Remove the old multires */
-                                       multires_free(me->mr);
-                                       me->mr = NULL;
-                               }
+                               if(me && me->id.lib==NULL && me->mr) /* XXX - library meshes crash on loading most yoFrankie levels, the multires pointer gets invalid -  Campbell */
+                                       multires_load_old(ob, me);
 
                                ob->data = olddata;
                        }
@@ -10175,15 +10123,34 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        
-       /* put 2.50 compatibility code here until next subversion bump */
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9))
        {
-               Scene *sce= main->scene.first;
+               Scene *sce;
+               Mesh *me;
+               Object *ob;
 
                for(sce=main->scene.first; sce; sce=sce->id.next)
                        if(!sce->toolsettings->particle.selectmode)
                                sce->toolsettings->particle.selectmode= SCE_SELECT_PATH;
+
+               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);
+
+                               if(mmd) {
+                                       mmd->totlvl--;
+                                       mmd->lvl--;
+                                       mmd->sculptlvl= mmd->lvl;
+                                       mmd->renderlvl= mmd->lvl;
+                               }
+                       }
+               }
        }
 
+       /* put 2.50 compatibility code here until next subversion bump */
        {
                Object *ob;
                
@@ -10199,6 +10166,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        }
                }
        }
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */