armature ghost stepsize was not initialized, Aligorith: can you check this is correct?
[blender.git] / source / blender / blenloader / intern / readfile.c
index ebfa701be4ef53eccfed3bfa43686d12f118c216..88c120dc1e15176b5e1609df0cd0eb02481230ce 100644 (file)
 
 #include "MEM_guardedalloc.h"
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "BLI_storage_types.h" // for relname flags
 
 #include "BKE_animsys.h"
+#include "BKE_anim.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_brush.h"
 #include "BKE_report.h"
 #include "BKE_sca.h" // for init_actuator
 #include "BKE_scene.h"
+#include "BKE_screen.h"
 #include "BKE_softbody.h"      // sbNew()
 #include "BKE_bullet.h"                // bsbNew()
-#include "BKE_sequence.h"
+#include "BKE_sequencer.h"
 #include "BKE_texture.h" // for open_plugin_tex
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
 #include "BKE_idprop.h"
@@ -1702,6 +1704,9 @@ static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list)
 {
        FCurve *fcu;
        
+       if (list == NULL)
+               return;
+       
        /* relink ID-block references... */
        for (fcu= list->first; fcu; fcu= fcu->next) {
                /* driver data */
@@ -1848,6 +1853,9 @@ static void lib_link_nladata_strips(FileData *fd, ID *id, ListBase *list)
                /* check strip's children */
                lib_link_nladata_strips(fd, id, &strip->strips);
                
+               /* check strip's F-Curves */
+               lib_link_fcurves(fd, id, &strip->fcurves);
+               
                /* reassign the counted-reference to action */
                strip->act = newlibadr_us(fd, id->lib, strip->act);
        }
@@ -1974,6 +1982,19 @@ static void direct_link_animdata(FileData *fd, AnimData *adt)
        adt->actstrip= NULL;
 }      
 
+/* ************ READ MOTION PATHS *************** */
+
+/* direct data for cache */
+static void direct_link_motionpath(FileData *fd, bMotionPath *mpath)
+{
+       /* sanity check */
+       if (mpath == NULL)
+               return;
+       
+       /* relink points cache */
+       mpath->points= newdataadr(fd, mpath->points);
+}
+
 /* ************ READ NODE TREE *************** */
 
 /* singe node tree (also used for material/scene trees), ntree is not NULL */
@@ -1983,6 +2004,8 @@ static void lib_link_ntree(FileData *fd, ID *id, bNodeTree *ntree)
        
        if(ntree->adt) lib_link_animdata(fd, &ntree->id, ntree->adt);
        
+       ntree->gpd= newlibadr_us(fd, id->lib, ntree->gpd);
+       
        for(node= ntree->nodes.first; node; node= node->next)
                node->id= newlibadr_us(fd, id->lib, node->id);
 }
@@ -2333,7 +2356,7 @@ static void lib_link_pose(FileData *fd, Object *ob, bPose *pose)
                        rebuild= 1;
                else if(ob->id.lib==NULL && arm->id.lib) {
                        /* local pose selection copied to armature, bit hackish */
-                       pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE);
+                       pchan->bone->flag &= ~BONE_SELECTED;
                        pchan->bone->flag |= pchan->selectflag;
                }
        }
@@ -2367,6 +2390,8 @@ static void direct_link_bones(FileData *fd, Bone* bone)
        bone->prop= newdataadr(fd, bone->prop);
        if(bone->prop)
                IDP_DirectLinkProperty(bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+               
+       bone->flag &= ~BONE_DRAW_ACTIVE;
 
        link_list(fd, &bone->childbase);
 
@@ -2381,13 +2406,18 @@ static void direct_link_armature(FileData *fd, bArmature *arm)
        link_list(fd, &arm->bonebase);
        arm->edbo= NULL;
        arm->sketch = NULL;
+       
        arm->adt= newdataadr(fd, arm->adt);
+       direct_link_animdata(fd, arm->adt);
        
        bone=arm->bonebase.first;
        while (bone) {
                direct_link_bones(fd, bone);
                bone=bone->next;
        }
+
+       arm->act_bone= newdataadr(fd, arm->act_bone);
+       arm->act_edbone= NULL;
 }
 
 /* ************ READ CAMERA ***************** */
@@ -2882,10 +2912,8 @@ static void lib_link_texture(FileData *fd, Main *main)
                        tex->ima= newlibadr_us(fd, tex->id.lib, tex->ima);
                        tex->ipo= newlibadr_us(fd, tex->id.lib, tex->ipo);
                        if(tex->env) tex->env->object= newlibadr(fd, tex->id.lib, tex->env->object);
-                       if(tex->pd) {
+                       if(tex->pd)
                                tex->pd->object= newlibadr(fd, tex->id.lib, tex->pd->object);
-                               tex->pd->psys= newlibadr(fd, tex->id.lib, tex->pd->psys);
-                       }
                        if(tex->vd) tex->vd->object= newlibadr(fd, tex->id.lib, tex->vd->object);
 
                        if(tex->nodetree)
@@ -3051,6 +3079,12 @@ static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointC
        }
 }
 
+void lib_link_partdeflect(FileData *fd, ID *id, PartDeflect *pd)
+{
+       if(pd && pd->tex)
+               pd->tex=newlibadr_us(fd, id->lib, pd->tex);
+}
+
 static void lib_link_particlesettings(FileData *fd, Main *main)
 {
        ParticleSettings *part;
@@ -3067,6 +3101,9 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
                        part->eff_group = newlibadr(fd, part->id.lib, part->eff_group);
                        part->bb_ob = newlibadr(fd, part->id.lib, part->bb_ob);
 
+                       lib_link_partdeflect(fd, &part->id, part->pd);
+                       lib_link_partdeflect(fd, &part->id, part->pd2);
+
                        if(part->effector_weights)
                                part->effector_weights->group = newlibadr(fd, part->id.lib, part->effector_weights->group);
 
@@ -3103,15 +3140,22 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
        }
 }
 
+static void direct_link_partdeflect(PartDeflect *pd)
+{
+       if(pd) pd->rng=NULL;
+}
+
 static void direct_link_particlesettings(FileData *fd, ParticleSettings *part)
 {
        part->adt= newdataadr(fd, part->adt);
        part->pd= newdataadr(fd, part->pd);
        part->pd2= newdataadr(fd, part->pd2);
 
-       if(part->effector_weights)
-               part->effector_weights = newdataadr(fd, part->effector_weights);
-       else
+       direct_link_partdeflect(part->pd);
+       direct_link_partdeflect(part->pd2);
+
+       part->effector_weights = newdataadr(fd, part->effector_weights);
+       if(!part->effector_weights)
                part->effector_weights = BKE_add_effector_weights(part->eff_group);
 
        link_list(fd, &part->dupliweights);
@@ -3306,14 +3350,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;
                }
        }       
@@ -3324,14 +3368,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++;
                }
        }
@@ -3692,8 +3740,7 @@ static void lib_link_object(FileData *fd, Main *main)
                        
                        /* texture field */
                        if(ob->pd)
-                               if(ob->pd->tex)
-                                       ob->pd->tex=newlibadr_us(fd, ob->id.lib, ob->pd->tex);
+                               lib_link_partdeflect(fd, &ob->id, ob->pd);
 
                        if(ob->soft)
                                ob->soft->effector_weights->group = newlibadr(fd, ob->id.lib, ob->soft->effector_weights->group);
@@ -3730,6 +3777,10 @@ static void direct_link_pose(FileData *fd, bPose *pose)
                if (pchan->prop)
                        IDP_DirectLinkProperty(pchan->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
                
+               pchan->mpath= newdataadr(fd, pchan->mpath);
+               if (pchan->mpath)
+                       direct_link_motionpath(fd, pchan->mpath);
+               
                pchan->iktree.first= pchan->iktree.last= NULL;
                pchan->path= NULL;
        }
@@ -3776,11 +3827,12 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        if(clmd->sim_parms) {
                                if(clmd->sim_parms->presets > 10)
                                        clmd->sim_parms->presets = 0;
+
+                               clmd->sim_parms->reset = 0;
                        }
 
-                       if(clmd->sim_parms->effector_weights)
-                               clmd->sim_parms->effector_weights = newdataadr(fd, clmd->sim_parms->effector_weights);
-                       else
+                       clmd->sim_parms->effector_weights = newdataadr(fd, clmd->sim_parms->effector_weights);
+                       if(!clmd->sim_parms->effector_weights)
                                clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL);
                        
                }
@@ -3807,9 +3859,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                                smd->domain->tex_shadow = NULL;
                                smd->domain->tex_wt = NULL;
 
-                               if(smd->domain->effector_weights)
-                                       smd->domain->effector_weights = newdataadr(fd, smd->domain->effector_weights);
-                               else
+                               smd->domain->effector_weights = newdataadr(fd, smd->domain->effector_weights);
+                               if(!smd->domain->effector_weights)
                                        smd->domain->effector_weights = BKE_add_effector_weights(NULL);
 
                                direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0]));
@@ -3858,7 +3909,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        collmd->current_x = NULL;
                        collmd->current_xnew = NULL;
                        collmd->current_v = NULL;
-                       collmd->time = -1;
+                       collmd->time = -1000;
                        collmd->numverts = 0;
                        collmd->bvhtree = NULL;
                        collmd->mfaces = NULL;
@@ -3917,12 +3968,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;
-               }
        }
 }
 
@@ -3948,6 +3993,10 @@ static void direct_link_object(FileData *fd, Object *ob)
        
        ob->pose= newdataadr(fd, ob->pose);
        direct_link_pose(fd, ob->pose);
+       
+       ob->mpath= newdataadr(fd, ob->mpath);
+       if (ob->mpath)
+               direct_link_motionpath(fd, ob->mpath);
 
        link_list(fd, &ob->defbase);
 // XXX depreceated - old animation system <<<
@@ -4014,8 +4063,7 @@ static void direct_link_object(FileData *fd, Object *ob)
        }
 
        ob->pd= newdataadr(fd, ob->pd);
-       if(ob->pd)
-               ob->pd->rng=NULL;
+       direct_link_partdeflect(ob->pd);
        ob->soft= newdataadr(fd, ob->soft);
        if(ob->soft) {
                SoftBody *sb= ob->soft;         
@@ -4033,9 +4081,8 @@ static void direct_link_object(FileData *fd, Object *ob)
                        }
                }
 
-               if(sb->effector_weights)
-                       sb->effector_weights = newdataadr(fd, sb->effector_weights);
-               else
+               sb->effector_weights = newdataadr(fd, sb->effector_weights);
+               if(!sb->effector_weights)
                        sb->effector_weights = BKE_add_effector_weights(NULL);
 
                direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache);
@@ -4159,6 +4206,7 @@ static void lib_link_scene(FileData *fd, Main *main)
        Base *base, *next;
        Sequence *seq;
        SceneRenderLayer *srl;
+       TimeMarker *marker;
        
        sce= main->scene.first;
        while(sce) {
@@ -4196,16 +4244,12 @@ static void lib_link_scene(FileData *fd, Main *main)
                                        MEM_freeN(base);
                                }
                        }
-                       
-                       if (sce->ed) {
-                               Editing *ed= sce->ed;
-                               ed->act_seq= NULL; //   ed->act_seq=  newlibadr(fd, ed->act_seq); // FIXME
-                       }
 
                        SEQ_BEGIN(sce->ed, seq) {
                                if(seq->ipo) seq->ipo= newlibadr_us(fd, sce->id.lib, seq->ipo);
                                if(seq->scene) seq->scene= newlibadr(fd, sce->id.lib, seq->scene);
                                if(seq->sound) {
+                                       seq->sound_handle= NULL;
                                        if(seq->type == SEQ_HD_SOUND)
                                                seq->type = SEQ_SOUND;
                                        else
@@ -4218,6 +4262,17 @@ static void lib_link_scene(FileData *fd, Main *main)
                                seq->anim= 0;
                        }
                        SEQ_END
+
+#ifdef DURIAN_CAMERA_SWITCH
+                       for(marker= sce->markers.first; marker; marker= marker->next) {
+                               if(marker->camera) {
+                                       marker->camera= newlibadr(fd, sce->id.lib, marker->camera);
+                               }
+                       }
+#endif
+
+                       if(sce->ed)
+                               seq_update_muting(sce->ed);
                        
                        if(sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
@@ -4252,10 +4307,13 @@ static void link_recurs_seq(FileData *fd, ListBase *lb)
 
 static void direct_link_paint(FileData *fd, Paint **paint)
 {
-       (*paint)= newdataadr(fd, (*paint));
-       if(*paint) {
-               (*paint)->paint_cursor= NULL;
-               (*paint)->brushes= newdataadr(fd, (*paint)->brushes);
+       Paint *p;
+
+       p= (*paint)= newdataadr(fd, (*paint));
+       if(p) {
+               p->paint_cursor= NULL;
+               p->brushes= newdataadr(fd, p->brushes);
+               test_pointer_array(fd, (void**)&p->brushes);
        }
 }
 
@@ -4292,6 +4350,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
 
                sce->toolsettings->imapaint.paint.brushes= newdataadr(fd, sce->toolsettings->imapaint.paint.brushes);
+               test_pointer_array(fd, (void**)&sce->toolsettings->imapaint.paint.brushes);
 
                sce->toolsettings->imapaint.paintcursor= NULL;
                sce->toolsettings->particle.paintcursor= NULL;
@@ -4301,7 +4360,8 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                ListBase *old_seqbasep= &((Editing *)sce->ed)->seqbase;
                
                ed= sce->ed= newdataadr(fd, sce->ed);
-               ed->act_seq= NULL; //           ed->act_seq=  newdataadr(fd, ed->act_seq); // FIXME
+
+               ed->act_seq= newdataadr(fd, ed->act_seq);
 
                /* recursive link sequences, lb will be correctly initialized */
                link_recurs_seq(fd, &ed->seqbase);
@@ -4433,7 +4493,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        link_list(fd, &(sce->markers));
        link_list(fd, &(sce->transform_spaces));
        link_list(fd, &(sce->r.layers));
-       
+
        sce->nodetree= newdataadr(fd, sce->nodetree);
        if(sce->nodetree)
                direct_link_nodetree(fd, sce->nodetree);
@@ -5032,6 +5092,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                        if (sl->spacetype==SPACE_VIEW3D) {
                                View3D *v3d= (View3D*) sl;
                                v3d->bgpic= newdataadr(fd, v3d->bgpic);
+                               v3d->flag |= V3D_INVALID_BACKBUF;
                                if(v3d->bgpic)
                                        v3d->bgpic->iuser.ok= 1;
                                if(v3d->gpd) {
@@ -5256,7 +5317,7 @@ static void lib_link_group(FileData *fd, Main *main)
                                go= go->next;
                        }
                        if(add_us) group->id.us++;
-                       rem_from_group(group, NULL);    /* removes NULL entries */
+                       rem_from_group(group, NULL, NULL, NULL);        /* removes NULL entries */
                }
                group= group->id.next;
        }
@@ -5926,7 +5987,8 @@ static void area_add_header_region(ScrArea *sa, ListBase *lb)
 static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
 {
        ARegion *ar;
-       
+       ARegion *ar_main;
+
        if(sl) {
                /* first channels for ipo action nla... */
                switch(sl->spacetype) {
@@ -5985,13 +6047,50 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                ar->regiontype= RGN_TYPE_UI;
                                ar->alignment= RGN_ALIGN_TOP;
                                break;
+                       case SPACE_SEQ:
+                               ar_main = (ARegion*)lb->first;
+                               for (; ar_main; ar_main = ar_main->next) {
+                                       if (ar_main->regiontype == RGN_TYPE_WINDOW)
+                                               break;
+                               }
+                               ar= MEM_callocN(sizeof(ARegion), "preview area for sequencer");
+                               BLI_insertlinkbefore(lb, ar_main, ar);
+                               ar->regiontype= RGN_TYPE_PREVIEW;
+                               ar->alignment= RGN_ALIGN_TOP;
+                               ar->flag |= RGN_FLAG_HIDDEN;
+                               break;
+                       case SPACE_VIEW3D:
+                               /* toolbar */
+                               ar= MEM_callocN(sizeof(ARegion), "toolbar for view3d");
+                               
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_TOOLS;
+                               ar->alignment= RGN_ALIGN_LEFT;
+                               ar->flag = RGN_FLAG_HIDDEN;
+                               
+                               /* tool properties */
+                               ar= MEM_callocN(sizeof(ARegion), "tool properties for view3d");
+                               
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_TOOL_PROPS;
+                               ar->alignment= RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV;
+                               ar->flag = RGN_FLAG_HIDDEN;
+                               
+                               /* buttons/list view */
+                               ar= MEM_callocN(sizeof(ARegion), "buttons for view3d");
+                               
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_UI;
+                               ar->alignment= RGN_ALIGN_RIGHT;
+                               ar->flag = RGN_FLAG_HIDDEN;
 #if 0
                        case SPACE_BUTS:
                                /* context UI region */
                                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                                BLI_addtail(lb, ar);
-                               ar->regiontype= RGN_TYPE_CHANNELS;
-                               ar->alignment= RGN_ALIGN_TOP;
+                               ar->regiontype= RGN_TYPE_UI;
+                               ar->alignment= RGN_ALIGN_RIGHT;
+                               
                                break;
 #endif
                }
@@ -8461,7 +8560,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                                
                                /* correctly initialise constinv matrix */
-                               Mat4One(ob->constinv);
+                               unit_m4(ob->constinv);
                                
                                if (ob->type == OB_ARMATURE) {
                                        if (ob->pose) {
@@ -8491,7 +8590,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                        }
                                                        
                                                        /* correctly initialise constinv matrix */
-                                                       Mat4One(pchan->constinv);
+                                                       unit_m4(pchan->constinv);
                                                }
                                        }
                                }
@@ -9154,15 +9253,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 4)){
-               Scene *sce= main->scene.first;
-               while(sce) {
-                       if(sce->frame_step==0)
-                               sce->frame_step= 1;
-                       sce= sce->id.next;
-               }
-       }
-
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 5)) {
                Lamp *la= main->lamp.first;
                for(; la; la= la->id.next) {
@@ -9524,7 +9614,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                /* and composit trees */
                for(sce= main->scene.first; sce; sce= sce->id.next) {
                        if(sce->nodetree && strlen(sce->nodetree->id.name)==0)
-                               strcpy(sce->nodetree->id.name, "NTComposit Nodetree");
+                               strcpy(sce->nodetree->id.name, "NTCompositing Nodetree");
 
                        /* move to cameras */
                        if(sce->r.mode & R_PANORAMA) {
@@ -9599,7 +9689,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);
@@ -9616,58 +9706,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;
                        }
@@ -9905,7 +9945,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                /* Add default gravity to scenes */
                for(sce= main->scene.first; sce; sce= sce->id.next) {
                        if((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0
-                               && VecLength(sce->physics_settings.gravity) == 0.0f) {
+                               && len_v3(sce->physics_settings.gravity) == 0.0f) {
 
                                sce->physics_settings.gravity[0] = sce->physics_settings.gravity[1] = 0.0f;
                                sce->physics_settings.gravity[2] = -9.81f;
@@ -10031,8 +10071,321 @@ 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 < 8))
+       {
+               {
+                       Scene *sce= main->scene.first;
+                       while(sce) {
+                               Sequence *seq;
+                               
+                               if(sce->r.frame_step==0)
+                                       sce->r.frame_step= 1;
+                               
+                               if(sce->ed && sce->ed->seqbasep)
+                               {
+                                       seq=sce->ed->seqbasep->first;
+                                       while(seq) {
+                                               seqUniqueName(sce->ed->seqbasep, seq);
+                                               seq=seq->next;
+                                       }
+                               }
+                               
+                               sce= sce->id.next;
+                       }
+               }
+               {
+                       /* ensure all nodes have unique names */
+                       bNodeTree *ntree= main->nodetree.first;
+                       while(ntree) {
+                               bNode *node=ntree->nodes.first;
+                               
+                               while(node) {
+                                       nodeUniqueName(ntree, node);
+                                       node= node->next;
+                               }
+                               
+                               ntree= ntree->id.next;
+                       }
+               }
+               {
+                       Object *ob=main->object.first;
+                       while (ob) {
+                               /* shaded mode disabled for now */
+                               if (ob->dt == OB_SHADED) ob->dt = OB_TEXTURE;
+                               ob=ob->id.next;
+                       }
+               }
+               
+               {
+                       bScreen *screen;
+                       ScrArea *sa;
+                       SpaceLink *sl;
+                       
+                       for(screen= main->screen.first; screen; screen= screen->id.next) {
+                               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                                       for(sl= sa->spacedata.first; sl; sl= sl->next) {
+                                               if(sl->spacetype==SPACE_VIEW3D) {
+                                                       View3D *v3d = (View3D *)sl;
+                                                       if (v3d->drawtype == OB_SHADED) v3d->drawtype = OB_SOLID;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               
+               /* only convert old 2.50 files with color management */
+               if (main->versionfile == 250) {
+                       Scene *sce=main->scene.first;
+                       Material *ma=main->mat.first;
+                       World *wo=main->world.first;
+                       int convert=0;
+                       
+                       /* convert to new color management system:
+                        while previously colors were stored as srgb, 
+                        now they are stored as linear internally, 
+                        with screen gamma correction in certain places in the UI. */
+
+                       /* don't know what scene is active, so we'll convert if any scene has it enabled... */
+                       while (sce) {
+                               if(sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
+                                       convert=1;
+                               sce=sce->id.next;
+                       }
+                       
+                       if (convert) {
+                               while(ma) {
+                                       srgb_to_linearrgb_v3_v3(&ma->r, &ma->r);
+                                       srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr);
+                                       srgb_to_linearrgb_v3_v3(&ma->mirr, &ma->mirr);
+                                       srgb_to_linearrgb_v3_v3(ma->sss_col, ma->sss_col);
+                                       ma=ma->id.next;
+                               }
+                               
+                               while(wo) {
+                                       srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr);
+                                       srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr);
+                                       srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr);
+                                       wo=wo->id.next;
+                               }
+                       }
+               }
+               /* clear hanging 'temp' screens from older 2.5 files*/
+               if (main->versionfile == 250) {
+                       bScreen *screen, *nextscreen;
+                       wmWindowManager *wm;
+                       wmWindow *win, *nextwin;
+
+                       for(screen= main->screen.first; screen; screen= nextscreen) {
+                               nextscreen= screen->id.next;
+
+                               if (screen->full == SCREENTEMP) {
+                                       /* remove corresponding windows */
+                                       for(wm= main->wm.first; wm; wm=wm->id.next) {
+                                               for(win= wm->windows.first; win; win=nextwin) {
+                                                       nextwin= win->next;
+
+                                                       if(newlibadr(fd, wm->id.lib, win->screen) == screen)
+                                                               BLI_freelinkN(&wm->windows, win);
+                                               }
+                                       }
+
+                                       /* remove screen itself */
+                                       free_libblock(&main->screen, screen);
+                               }
+                       }
+               }
+       }
+       
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9))
+       {
+               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;
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 10))
+       {
+               Object *ob;
+
+               /* properly initialise hair clothsim data on old files */
+               for(ob = main->object.first; ob; ob = ob->id.next) {
+                       ModifierData *md;
+                       for(md= ob->modifiers.first; md; md= md->next) {
+                               if (md->type == eModifierType_Cloth) {
+                                       ClothModifierData *clmd = (ClothModifierData *)md;
+                                       if (clmd->sim_parms->velocity_smooth < 0.01f)
+                                               clmd->sim_parms->velocity_smooth = 0.f;
+                               }
+                       }
+               }
+       }
+
+       /* fix bad area setup in subversion 10 */
+       if (main->versionfile == 250 && main->subversionfile == 10)
+       {
+               /* fix for new view type in sequencer */
+               bScreen *screen;
+               ScrArea *sa;
+               SpaceLink *sl;
+
+
+               /* remove all preview window in wrong spaces */
+               for(screen= main->screen.first; screen; screen= screen->id.next) {
+                       for(sa= screen->areabase.first; sa; sa= sa->next) {
+                               for(sl= sa->spacedata.first; sl; sl= sl->next) {
+                                       if(sl->spacetype!=SPACE_SEQ) {
+                                               ARegion *ar;
+                                               ListBase *regionbase;
+
+                                               if (sl == sa->spacedata.first) {
+                                                       regionbase = &sa->regionbase;
+                                               } else {
+                                                       regionbase = &sl->regionbase;
+                                               }
+
+
+                                               for( ar = regionbase->first; ar; ar = ar->next) {
+                                                       if (ar->regiontype == RGN_TYPE_PREVIEW)
+                                                               break;
+                                               }
+
+                                               if (ar) {
+                                                       SpaceType *st= BKE_spacetype_from_id(SPACE_SEQ);
+                                                       BKE_area_region_free(st, ar);
+                                                       BLI_freelinkN(regionbase, ar);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 11))
        {
+               {
+                       /* fix for new view type in sequencer */
+                       bScreen *screen;
+                       ScrArea *sa;
+                       SpaceLink *sl;
+
+
+                       for(screen= main->screen.first; screen; screen= screen->id.next) {
+                               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                                       for(sl= sa->spacedata.first; sl; sl= sl->next) {
+                                               if(sl->spacetype==SPACE_SEQ) {
+                                                       ARegion *ar;
+                                                       ARegion *ar_main;
+                                                       ListBase *regionbase;
+                                                       SpaceSeq *sseq = (SpaceSeq *)sl;
+
+                                                       if (sl == sa->spacedata.first) {
+                                                               regionbase = &sa->regionbase;
+                                                       } else {
+                                                               regionbase = &sl->regionbase;
+                                                       }
+
+                                                       if (sseq->view == 0) sseq->view = SEQ_VIEW_SEQUENCE;
+                                                       if (sseq->mainb == 0) sseq->mainb = SEQ_DRAW_IMG_IMBUF;
+
+                                                       ar_main = (ARegion*)regionbase->first;
+                                                       for (; ar_main; ar_main = ar_main->next) {
+                                                               if (ar_main->regiontype == RGN_TYPE_WINDOW)
+                                                                       break;
+                                                       }
+                                                       ar= MEM_callocN(sizeof(ARegion), "preview area for sequencer");
+                                                       BLI_insertlinkbefore(regionbase, ar_main, ar);
+                                                       ar->regiontype= RGN_TYPE_PREVIEW;
+                                                       ar->alignment= RGN_ALIGN_TOP;
+                                                       ar->flag |= RGN_FLAG_HIDDEN;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /* put 2.50 compatibility code here until next subversion bump */
+
+       if (1) {
+               Scene *sce;
+               Object *ob;
+               
+               /* game engine changes */
+               for(sce = main->scene.first; sce; sce = sce->id.next) {
+                       sce->gm.eyeseparation = 0.10;
+               }
+               
+               /* anim viz changes */
+               for (ob= main->object.first; ob; ob= ob->id.next) {
+                       /* initialise object defaults */
+                       animviz_settings_init(&ob->avs);
+                       
+                       /* if armature, copy settings for pose from armature data */
+                       if (ob->pose && ob->data) {
+                               bArmature *arm= newlibadr(fd, lib, ob->data);
+                               bAnimVizSettings *avs= &ob->pose->avs;
+                               
+                               /* ghosting settings ---------------- */
+                                       /* ranges */
+                               avs->ghost_bc= avs->ghost_ac= arm->ghostep;
+                               
+                               avs->ghost_sf= arm->ghostsf;
+                               avs->ghost_ef= arm->ghostef;
+                                       
+                                       /* type */
+                               avs->ghost_type= arm->ghosttype;
+                                       
+                                       /* stepsize */
+                               avs->ghost_step= arm->ghostsize;
+                               
+                               /* path settings --------------------- */
+                                       /* ranges */
+                               avs->path_bc= arm->pathbc;
+                               avs->path_ac= arm->pathac;
+                               
+                               avs->path_sf= arm->pathsf;
+                               avs->path_ef= arm->pathef;
+                               
+                                       /* flags */
+                               if (arm->pathflag & ARM_PATH_FNUMS)
+                                       avs->path_viewflag |= MOTIONPATH_VIEW_FNUMS;
+                               if (arm->pathflag & ARM_PATH_KFRAS)
+                                       avs->path_viewflag |= MOTIONPATH_VIEW_KFRAS;
+                               if (arm->pathflag & ARM_PATH_KFNOS)
+                                       avs->path_viewflag |= MOTIONPATH_VIEW_KFNOS;
+                                       
+                                       /* bake flags */
+                               if (arm->pathflag & ARM_PATH_HEADS)
+                                       avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS;
+                                       
+                                       /* type */
+                               if (arm->pathflag & ARM_PATH_ACFRA)
+                                       avs->path_type = MOTIONPATH_TYPE_ACFRA;
+                               
+                                       /* stepsize */
+                               avs->path_step= arm->pathsize;
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -10373,15 +10726,56 @@ static void expand_constraint_channels(FileData *fd, Main *mainvar, ListBase *ch
        }
 }
 
-// XXX depreceated - old animation system
+static void expand_fmodifiers(FileData *fd, Main *mainvar, ListBase *list)
+{
+       FModifier *fcm;
+       
+       for (fcm= list->first; fcm; fcm= fcm->next) {
+               /* library data for specific F-Modifier types */
+               switch (fcm->type) {
+                       case FMODIFIER_TYPE_PYTHON:
+                       {
+                               FMod_Python *data= (FMod_Python *)fcm->data;
+                               
+                               expand_doit(fd, mainvar, data->script);
+                       }
+                               break;
+               }
+       }
+}
+
+static void expand_fcurves(FileData *fd, Main *mainvar, ListBase *list)
+{
+       FCurve *fcu;
+       
+       for (fcu= list->first; fcu; fcu= fcu->next) {
+               /* Driver targets if there is a driver */
+               if (fcu->driver) {
+                       ChannelDriver *driver= fcu->driver;
+                       DriverTarget *dtar;
+                       
+                       for (dtar= driver->targets.first; dtar; dtar= dtar->next)
+                               expand_doit(fd, mainvar, dtar->id);
+               }
+               
+               /* F-Curve Modifiers */
+               expand_fmodifiers(fd, mainvar, &fcu->modifiers);
+       }
+}
+
 static void expand_action(FileData *fd, Main *mainvar, bAction *act)
 {
        bActionChannel *chan;
        
+       // XXX depreceated - old animation system --------------
        for (chan=act->chanbase.first; chan; chan=chan->next) {
                expand_doit(fd, mainvar, chan->ipo);
                expand_constraint_channels(fd, mainvar, &chan->constraintChannels);
        }
+       // ---------------------------------------------------
+       
+       /* F-Curves in Action */
+       expand_fcurves(fd, mainvar, &act->curves);
 }
 
 static void expand_keyingsets(FileData *fd, Main *mainvar, ListBase *list)
@@ -10405,6 +10799,12 @@ static void expand_animdata_nlastrips(FileData *fd, Main *mainvar, ListBase *lis
                /* check child strips */
                expand_animdata_nlastrips(fd, mainvar, &strip->strips);
                
+               /* check F-Curves */
+               expand_fcurves(fd, mainvar, &strip->fcurves);
+               
+               /* check F-Modifiers */
+               expand_fmodifiers(fd, mainvar, &strip->modifiers);
+               
                /* relink referenced action */
                expand_doit(fd, mainvar, strip->act);
        }
@@ -10412,7 +10812,6 @@ static void expand_animdata_nlastrips(FileData *fd, Main *mainvar, ListBase *lis
 
 static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
 {
-       FCurve *fcd;
        NlaTrack *nlt;
        
        /* own action */
@@ -10420,13 +10819,7 @@ static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
        expand_doit(fd, mainvar, adt->tmpact);
        
        /* drivers - assume that these F-Curves have driver data to be in this list... */
-       for (fcd= adt->drivers.first; fcd; fcd= fcd->next) {
-               ChannelDriver *driver= fcd->driver;
-               DriverTarget *dtar;
-               
-               for (dtar= driver->targets.first; dtar; dtar= dtar->next)
-                       expand_doit(fd, mainvar, dtar->id);
-       }
+       expand_fcurves(fd, mainvar, &adt->drivers);
        
        /* nla-data - referenced actions */
        for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) 
@@ -10467,6 +10860,9 @@ static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree)
        
        if(ntree->adt)
                expand_animdata(fd, mainvar, ntree->adt);
+               
+       if(ntree->gpd)
+               expand_doit(fd, mainvar, ntree->gpd);
        
        for(node= ntree->nodes.first; node; node= node->next)
                if(node->id && node->type!=CMP_NODE_R_LAYERS)
@@ -11018,6 +11414,28 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
                
        if(sce->gpd)
                expand_doit(fd, mainvar, sce->gpd);
+
+       if(sce->ed) {
+               Sequence *seq;
+
+               SEQ_BEGIN(sce->ed, seq) {
+                       if(seq->scene) expand_doit(fd, mainvar, seq->scene);
+                       if(seq->sound) expand_doit(fd, mainvar, seq->sound);
+               }
+               SEQ_END
+       }
+
+#ifdef DURIAN_CAMERA_SWITCH
+       {
+               TimeMarker *marker;
+
+               for(marker= sce->markers.first; marker; marker= marker->next) {
+                       if(marker->camera) {
+                               expand_doit(fd, mainvar, marker->camera);
+                       }
+               }
+       }
+#endif
 }
 
 static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)