merged changes to revision 24077
[blender.git] / source / blender / blenloader / intern / readfile.c
index 2ee5a13c47a534eb93da8446c1e94471d57ea2ee..cbc72a0366df867c5678f5c52515a8892c83a140 100644 (file)
@@ -977,7 +977,7 @@ FileData *blo_openblenderfile(char *name, ReportList *reports)
                fd->read = fd_read_gzip_from_file;
 
                /* needed for library_append and read_libraries */
-               BLI_strncpy(fd->filename, name, sizeof(fd->filename));
+               BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
 
                return blo_decode_and_check(fd, reports);
        }
@@ -4119,7 +4119,7 @@ static void composite_patch(bNodeTree *ntree, Scene *scene)
        bNode *node;
        
        for(node= ntree->nodes.first; node; node= node->next)
-               if(node->id==NULL && ELEM(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE))
+               if(node->id==NULL && ELEM3(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS))
                        node->id= &scene->id;
 }
 
@@ -4232,8 +4232,10 @@ static void link_recurs_seq(FileData *fd, ListBase *lb)
 static void direct_link_paint(FileData *fd, Paint **paint)
 {
        (*paint)= newdataadr(fd, (*paint));
-       if(*paint)
+       if(*paint) {
+               (*paint)->paint_cursor= NULL;
                (*paint)->brushes= newdataadr(fd, (*paint)->brushes);
+       }
 }
 
 static void direct_link_scene(FileData *fd, Scene *sce)
@@ -4437,7 +4439,6 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
                win->curswin= NULL;
                win->tweak= NULL;
 
-               win->timers.first= win->timers.last= NULL;
                win->queue.first= win->queue.last= NULL;
                win->handlers.first= win->handlers.last= NULL;
                win->modalhandlers.first= win->modalhandlers.last= NULL;
@@ -4449,6 +4450,7 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
                win->drawfail= 0;
        }
        
+       wm->timers.first= wm->timers.last= NULL;
        wm->operators.first= wm->operators.last= NULL;
        wm->paintcursors.first= wm->paintcursors.last= NULL;
        wm->queue.first= wm->queue.last= NULL;
@@ -5139,7 +5141,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
        }
        /* make sure we have full path in lib->filename */
        BLI_strncpy(lib->filename, lib->name, sizeof(lib->name));
-       cleanup_path(fd->filename, lib->filename);
+       cleanup_path(fd->relabase, lib->filename);
        
 //     printf("direct_link_library: name %s\n", lib->name);
 //     printf("direct_link_library: filename %s\n", lib->filename);
@@ -5473,6 +5475,9 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)
        bfd->fileflags= fg->fileflags;
        bfd->displaymode= fg->displaymode;
        bfd->globalf= fg->globalf;
+       BLI_strncpy(bfd->filename, fg->filename, sizeof(bfd->filename));
+       if(G.fileflags & G_FILE_RECOVER)
+               BLI_strncpy(fd->relabase, fg->filename, sizeof(fd->relabase));
        
        bfd->curscreen= fg->curscreen;
        bfd->curscene= fg->curscene;
@@ -6288,7 +6293,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        /* WATCH IT!!!: pointers from libdata have not been converted */
 
        if(G.f & G_DEBUG)
-               printf("read file %s\n  Version %d sub %d\n", fd->filename, main->versionfile, main->subversionfile);
+               printf("read file %s\n  Version %d sub %d\n", fd->relabase, main->versionfile, main->subversionfile);
        
        if(main->versionfile == 100) {
                /* tex->extend and tex->imageflag have changed: */
@@ -9924,7 +9929,6 @@ 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 < 6)) {
                Object *ob;
                Lamp *la;
@@ -9950,6 +9954,71 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        la->compressthresh= 0.05f;
        }
 
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 7)) {
+               Mesh *me;
+               Nurb *nu;
+               Lattice *lt;
+               Curve *cu;
+               Key *key;
+               float *data;
+               int a, tot;
+
+               /* shape keys are no longer applied to the mesh itself, but rather
+                  to the derivedmesh/displist, so here we ensure that the basis
+                  shape key is always set in the mesh coordinates. */
+
+               for(me= main->mesh.first; me; me= me->id.next) {
+                       if((key = newlibadr(fd, lib, me->key)) && key->refkey) {
+                               data= key->refkey->data;
+                               tot= MIN2(me->totvert, key->refkey->totelem);
+
+                               for(a=0; a<tot; a++, data+=3)
+                                       VECCOPY(me->mvert[a].co, data)
+                       }
+               }
+
+               for(lt= main->latt.first; lt; lt= lt->id.next) {
+                       if((key = newlibadr(fd, lib, lt->key)) && key->refkey) {
+                               data= key->refkey->data;
+                               tot= MIN2(lt->pntsu*lt->pntsv*lt->pntsw, key->refkey->totelem);
+
+                               for(a=0; a<tot; a++, data+=3)
+                                       VECCOPY(lt->def[a].vec, data)
+                       }
+               }
+
+               for(cu= main->curve.first; cu; cu= cu->id.next) {
+                       if((key = newlibadr(fd, lib, cu->key)) && key->refkey) {
+                               data= key->refkey->data;
+
+                               for(nu=cu->nurb.first; nu; nu=nu->next) {
+                                       if(nu->bezt) {
+                                               BezTriple *bezt = nu->bezt;
+
+                                               for(a=0; a<nu->pntsu; a++, bezt++) {
+                                                       VECCOPY(bezt->vec[0], data); data+=3;
+                                                       VECCOPY(bezt->vec[1], data); data+=3;
+                                                       VECCOPY(bezt->vec[2], data); data+=3;
+                                                       bezt->alfa= *data; data++;
+                                               }
+                                       }
+                                       else if(nu->bp) {
+                                               BPoint *bp = nu->bp;
+
+                                               for(a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
+                                                       VECCOPY(bp->vec, data); data+=3;
+                                                       bp->alfa= *data; data++;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /* put 2.50 compatibility code here until next subversion bump */
+       {
+       }
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
 
@@ -10062,14 +10131,25 @@ BlendFileData *blo_read_file_internal(FileData *fd, char *file)
                        break;
 
                case ID_LI:
-                       bhead = read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
+                       /* skip library datablocks in undo, this works together with
+                          BLO_read_from_memfile, where the old main->library is restored
+                          overwriting  the libraries from the memory file. previously
+                          it did not save ID_LI/ID_ID blocks in this case, but they are
+                          needed to make quit.blend recover them correctly. */
+                       if(fd->memfile)
+                               bhead= blo_nextbhead(fd, bhead);
+                       else
+                               bhead= read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
                        break;
                case ID_ID:
+                       /* same as above */
+                       if(fd->memfile)
+                               bhead= blo_nextbhead(fd, bhead);
+                       else
                                /* always adds to the most recently loaded
                                 * ID_LI block, see direct_link_library.
-                                * this is part of the file format definition.
-                                */
-                       bhead = read_libblock(fd, fd->mainlist.last, bhead, LIB_READ+LIB_EXTERN, NULL);
+                                * this is part of the file format definition. */
+                               bhead = read_libblock(fd, fd->mainlist.last, bhead, LIB_READ+LIB_EXTERN, NULL);
                        break;
                        
                        /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
@@ -10091,7 +10171,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, char *file)
 
        lib_link_all(fd, bfd->main);
        lib_verify_nodetree(bfd->main, 1);
-       fix_relpaths_library(fd->filename, bfd->main); /* make all relative paths, relative to the open blend file */
+       fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */
        
        link_global(fd, bfd);   /* as last */
        
@@ -10139,6 +10219,10 @@ static void sort_bhead_old_map(FileData *fd)
 
 static BHead *find_previous_lib(FileData *fd, BHead *bhead)
 {
+       /* skip library datablocks in undo, see comment in read_libblock */
+       if(fd->memfile)
+               return NULL;
+
        for (; bhead; bhead= blo_prevbhead(fd, bhead))
                if (bhead->code==ID_LI)
                        break;
@@ -10210,7 +10294,7 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
 
                        if(bheadlib) {
                                Library *lib= read_struct(fd, bheadlib, "Library");
-                               Main *ptr= blo_find_main(fd, &fd->mainlist, lib->name, fd->filename);
+                               Main *ptr= blo_find_main(fd, &fd->mainlist, lib->name, fd->relabase);
 
                                id= is_yet_read(fd, ptr, bhead);
 
@@ -11468,7 +11552,7 @@ BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize,
        fd->read = fd_read_from_file;
 
        /* needed for library_append and read_libraries */
-       BLI_strncpy(fd->filename, name, sizeof(fd->filename));
+       BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
 
        fd = blo_decode_and_check(fd, reports);
        if (!fd)