Animato - Basic version patching support
[blender.git] / source / blender / blenloader / intern / readfile.c
index 82fe3199eafcfe2c876e2469b4c013a41321fac6..23f22523e194b2fc7e9d18755b1cf629d67a9647 100644 (file)
@@ -48,6 +48,7 @@
     #include <io.h> // for open close read
 #endif
 
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_ID.h"
 #include "BLI_arithb.h"
 #include "BLI_storage_types.h" // for relname flags
 
+#include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_deform.h"
 #include "BKE_depsgraph.h"
 #include "BKE_effect.h" /* give_parteff */
+#include "BKE_fcurve.h"
 #include "BKE_global.h" // for G
 #include "BKE_group.h"
 #include "BKE_image.h"
-#include "BKE_ipo.h"
+#include "BKE_ipo.h" 
 #include "BKE_key.h" //void set_four_ipo
 #include "BKE_lattice.h"
 #include "BKE_library.h" // for wich_libbase
@@ -1490,6 +1493,8 @@ static void lib_link_brush(FileData *fd, Main *main)
                                if(mtex)
                                        mtex->tex= newlibadr_us(fd, brush->id.lib, mtex->tex);
                        }
+
+                       brush->clone.image= newlibadr_us(fd, brush->id.lib, brush->clone.image);
                }
        }
 }
@@ -1714,8 +1719,45 @@ static void direct_link_scriptlink(FileData *fd, ScriptLink *slink)
        }
 }
 
-/* ************ READ ARMATURE ***************** */
+/* ************ READ ANIMATION STUFF ***************** */
+
+/* Legacy Data Support (for Version Patching) ----------------------------- */
+
+// XXX depreceated - old animation system
+static void lib_link_ipo(FileData *fd, Main *main)
+{
+       Ipo *ipo;
+
+       ipo= main->ipo.first;
+       while(ipo) {
+               if(ipo->id.flag & LIB_NEEDLINK) {
+                       IpoCurve *icu;
+                       for(icu= ipo->curve.first; icu; icu= icu->next) {
+                               if(icu->driver)
+                                       icu->driver->ob= newlibadr(fd, ipo->id.lib, icu->driver->ob);
+                       }
+                       ipo->id.flag -= LIB_NEEDLINK;
+               }
+               ipo= ipo->id.next;
+       }
+}
+
+// XXX depreceated - old animation system
+static void direct_link_ipo(FileData *fd, Ipo *ipo)
+{
+       IpoCurve *icu;
 
+       link_list(fd, &(ipo->curve));
+       icu= ipo->curve.first;
+       while(icu) {
+               icu->bezt= newdataadr(fd, icu->bezt);
+               icu->bp= newdataadr(fd, icu->bp);
+               icu->driver= newdataadr(fd, icu->driver);
+               icu= icu->next;
+       }
+}
+
+// XXX depreceated - old animation system
 static void lib_link_nlastrips(FileData *fd, ID *id, ListBase *striplist)
 {
        bActionStrip *strip;
@@ -1730,6 +1772,18 @@ static void lib_link_nlastrips(FileData *fd, ID *id, ListBase *striplist)
        }
 }
 
+// XXX depreceated - old animation system
+static void direct_link_nlastrips(FileData *fd, ListBase *strips)
+{
+       bActionStrip *strip;
+       
+       link_list(fd, strips);
+       
+       for(strip= strips->first; strip; strip= strip->next)
+               link_list(fd, &strip->modifiers);
+}
+
+// XXX depreceated - old animation system
 static void lib_link_constraint_channels(FileData *fd, ID *id, ListBase *chanbase)
 {
        bConstraintChannel *chan;
@@ -1739,6 +1793,178 @@ static void lib_link_constraint_channels(FileData *fd, ID *id, ListBase *chanbas
        }
 }
 
+/* Data Linking ----------------------------- */
+
+static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list) 
+{
+       FCurve *fcu;
+       FModifier *fcm;
+       
+       /* relink ID-block references... */
+       for (fcu= list->first; fcu; fcu= fcu->next) {
+               /* driver data */
+               if (fcu->driver) {
+                       ChannelDriver *driver= fcu->driver;
+                       driver->id= newlibadr(fd, id->lib, driver->id); 
+                       driver->id2= newlibadr(fd, id->lib, driver->id2); 
+               }
+               
+               /* modifiers */
+               for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
+                       /* data for specific modifiers */
+                       switch (fcm->type) {
+                               case FMODIFIER_TYPE_PYTHON:
+                               {
+                                       FMod_Python *data= (FMod_Python *)fcm->data;
+                                       data->script = newlibadr(fd, id->lib, data->script);
+                               }
+                                       break;
+                       }
+               }
+       }
+}
+
+/* NOTE: this assumes that link_list has already been called on the list */
+static void direct_link_fcurves(FileData *fd, ListBase *list)
+{
+       FCurve *fcu;
+       FModifier *fcm;
+       
+       /* link F-Curve data to F-Curve again (non ID-libs) */
+       for (fcu= list->first; fcu; fcu= fcu->next) {
+               /* curve data */
+               fcu->bezt= newdataadr(fd, fcu->bezt);
+               fcu->fpt= newdataadr(fd, fcu->fpt);
+               
+               /* rna path */
+               fcu->rna_path= newdataadr(fd, fcu->rna_path);
+               
+               /* group */
+               fcu->grp= newdataadr(fd, fcu->grp);
+               
+               /* driver */
+               fcu->driver= newdataadr(fd, fcu->driver);
+               if (fcu->driver) {
+                       ChannelDriver *driver= fcu->driver;
+                       
+                       driver->rna_path= newdataadr(fd, driver->rna_path);
+                       driver->rna_path2= newdataadr(fd, driver->rna_path2);
+               }
+               
+               /* modifiers */
+               link_list(fd, &fcu->modifiers);
+               for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
+                       /* relink general data */
+                       fcm->data = newdataadr(fd, fcm->data);
+                       
+                       /* do relinking of data for specific types */
+                       switch (fcm->type) {
+                               case FMODIFIER_TYPE_GENERATOR:
+                               {
+                                       FMod_Generator *data= (FMod_Generator *)fcm->data;
+                                       
+                                       data->poly_coefficients= newdataadr(fd, data->poly_coefficients);
+                               }
+                                       break;
+                               case FMODIFIER_TYPE_PYTHON:
+                               {
+                                       FMod_Python *data= (FMod_Python *)fcm->data;
+                                       
+                                       data->prop = newdataadr(fd, data->prop);
+                                       IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+                               }
+                                       break;
+                       }
+               }
+       }
+}
+
+
+static void lib_link_action(FileData *fd, Main *main)
+{
+       bAction *act;
+       bActionChannel *chan;
+
+       for (act= main->action.first; act; act= act->id.next) {
+               if (act->id.flag & LIB_NEEDLINK) {
+                       act->id.flag -= LIB_NEEDLINK;
+                       
+// XXX depreceated - old animation system <<<
+                       for (chan=act->chanbase.first; chan; chan=chan->next) {
+                               chan->ipo= newlibadr_us(fd, act->id.lib, chan->ipo);
+                               lib_link_constraint_channels(fd, &act->id, &chan->constraintChannels);
+                       }
+// >>> XXX depreceated - old animation system
+                       
+                       lib_link_fcurves(fd, &act->id, &act->curves);
+               }
+       }
+}
+
+static void direct_link_action(FileData *fd, bAction *act)
+{
+       bActionChannel *achan; // XXX depreceated - old animation system
+       bActionGroup *agrp;
+
+       link_list(fd, &act->curves);
+       link_list(fd, &act->chanbase); // XXX depreceated - old animation system
+       link_list(fd, &act->groups);
+       link_list(fd, &act->markers);
+
+// XXX depreceated - old animation system <<<
+       for (achan = act->chanbase.first; achan; achan=achan->next) {
+               achan->grp= newdataadr(fd, achan->grp);
+               
+               link_list(fd, &achan->constraintChannels);
+       }
+// >>> XXX depreceated - old animation system
+
+       direct_link_fcurves(fd, &act->curves);
+       
+       for (agrp = act->groups.first; agrp; agrp= agrp->next) {
+               agrp->channels.first= newdataadr(fd, agrp->channels.first);
+               agrp->channels.last= newdataadr(fd, agrp->channels.last);
+       }
+}
+
+/* ------- */
+
+static void lib_link_animdata(FileData *fd, ID *id, AnimData *adt)
+{
+       if (adt == NULL)
+               return;
+       
+       /* link action data */
+       adt->action= newlibadr_us(fd, id->lib, adt->action);
+       
+       /* link drivers */
+       lib_link_fcurves(fd, id, &adt->drivers);
+       
+       /* overrides don't have lib-link for now, so no need to do anything */
+       
+       /* link NLA-data */
+       // TODO... 
+}
+
+static void direct_link_animdata(FileData *fd, AnimData *adt)
+{
+       /* NOTE: must have called newdataadr already before doing this... */
+       if (adt == NULL)
+               return;
+       
+       /* link drivers */
+       link_list(fd, &adt->drivers);
+       direct_link_fcurves(fd, &adt->drivers);
+       
+       /* link overrides */
+       // TODO...
+       
+       /* link NLA-data */
+       // TODO...
+}      
+
+/* ************ READ ARMATURE ***************** */
+
 static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist)
 {
        bConstraint *con;
@@ -1750,7 +1976,7 @@ static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist)
                        con->type= CONSTRAINT_TYPE_NULL;
                }
                /* own ipo, all constraints have it */
-               con->ipo= newlibadr_us(fd, id->lib, con->ipo);
+               con->ipo= newlibadr_us(fd, id->lib, con->ipo); // XXX depreceated - old animation system
                
                switch (con->type) {
                case CONSTRAINT_TYPE_PYTHON:
@@ -1943,26 +2169,6 @@ static void lib_link_armature(FileData *fd, Main *main)
        }
 }
 
-static void lib_link_action(FileData *fd, Main *main)
-{
-       bAction *act;
-       bActionChannel *chan;
-
-       act= main->action.first;
-       while(act) {
-               if(act->id.flag & LIB_NEEDLINK) {
-                       act->id.flag -= LIB_NEEDLINK;
-                       
-                       for (chan=act->chanbase.first; chan; chan=chan->next) {
-                               chan->ipo= newlibadr_us(fd, act->id.lib, chan->ipo);
-                               lib_link_constraint_channels(fd, &act->id, &chan->constraintChannels);
-                       }
-                       
-               }
-               act= act->id.next;
-       }
-}
-
 static void direct_link_bones(FileData *fd, Bone* bone)
 {
        Bone    *child;
@@ -1976,30 +2182,6 @@ static void direct_link_bones(FileData *fd, Bone* bone)
        }
 }
 
-
-static void direct_link_action(FileData *fd, bAction *act)
-{
-       bActionChannel *achan;
-       bActionGroup *agrp;
-
-       link_list(fd, &act->chanbase);
-       link_list(fd, &act->groups);
-       link_list(fd, &act->markers);
-
-       for (achan = act->chanbase.first; achan; achan=achan->next) {
-               achan->grp= newdataadr(fd, achan->grp);
-               
-               link_list(fd, &achan->constraintChannels);
-       }
-               
-       for (agrp = act->groups.first; agrp; agrp= agrp->next) {
-               if (agrp->channels.first) {
-                       agrp->channels.first= newdataadr(fd, agrp->channels.first);
-                       agrp->channels.last= newdataadr(fd, agrp->channels.last);
-               }
-       }
-}
-
 static void direct_link_armature(FileData *fd, bArmature *arm)
 {
        Bone    *bone;
@@ -2023,13 +2205,14 @@ static void lib_link_camera(FileData *fd, Main *main)
        ca= main->camera.first;
        while(ca) {
                if(ca->id.flag & LIB_NEEDLINK) {
-
-                       ca->ipo= newlibadr_us(fd, ca->id.lib, ca->ipo);
+                       if (ca->adt) lib_link_animdata(fd, &ca->id, ca->adt);
+                       
+                       ca->ipo= newlibadr_us(fd, ca->id.lib, ca->ipo); // XXX depreceated - old animation system
                        
                        ca->dof_ob= newlibadr_us(fd, ca->id.lib, ca->dof_ob);
                        
                        lib_link_scriptlink(fd, &ca->id, &ca->scriptlink);
-
+                       
                        ca->id.flag -= LIB_NEEDLINK;
                }
                ca= ca->id.next;
@@ -2038,6 +2221,9 @@ static void lib_link_camera(FileData *fd, Main *main)
 
 static void direct_link_camera(FileData *fd, Camera *ca)
 {
+       ca->adt= newdataadr(fd, ca->adt);
+       direct_link_animdata(fd, ca->adt);
+       
        direct_link_scriptlink(fd, &ca->scriptlink);
 }
 
@@ -2053,7 +2239,8 @@ static void lib_link_lamp(FileData *fd, Main *main)
        la= main->lamp.first;
        while(la) {
                if(la->id.flag & LIB_NEEDLINK) {
-
+                       if (la->adt) lib_link_animdata(fd, &la->id, la->adt);
+                       
                        for(a=0; a<MAX_MTEX; a++) {
                                mtex= la->mtex[a];
                                if(mtex) {
@@ -2061,11 +2248,11 @@ static void lib_link_lamp(FileData *fd, Main *main)
                                        mtex->object= newlibadr(fd, la->id.lib, mtex->object);
                                }
                        }
-
-                       la->ipo= newlibadr_us(fd, la->id.lib, la->ipo);
-
+                       
+                       la->ipo= newlibadr_us(fd, la->id.lib, la->ipo); // XXX depreceated - old animation system
+                       
                        lib_link_scriptlink(fd, &la->id, &la->scriptlink);
-
+                       
                        la->id.flag -= LIB_NEEDLINK;
                }
                la= la->id.next;
@@ -2075,7 +2262,10 @@ static void lib_link_lamp(FileData *fd, Main *main)
 static void direct_link_lamp(FileData *fd, Lamp *la)
 {
        int a;
-
+       
+       la->adt= newdataadr(fd, la->adt);
+       direct_link_animdata(fd, la->adt);
+       
        direct_link_scriptlink(fd, &la->scriptlink);
 
        for(a=0; a<MAX_MTEX; a++) {
@@ -2099,7 +2289,7 @@ static void lib_link_key(FileData *fd, Main *main)
        while(key) {
                if(key->id.flag & LIB_NEEDLINK) {
 
-                       key->ipo= newlibadr_us(fd, key->id.lib, key->ipo);
+                       key->ipo= newlibadr_us(fd, key->id.lib, key->ipo); // XXX depreceated - old animation system
                        key->from= newlibadr(fd, key->id.lib, key->from);
 
                        key->id.flag -= LIB_NEEDLINK;
@@ -2148,6 +2338,9 @@ static void direct_link_key(FileData *fd, Key *key)
 
        link_list(fd, &(key->block));
 
+       key->adt= newdataadr(fd, key->adt);
+       direct_link_animdata(fd, key->adt);
+       
        key->refkey= newdataadr(fd, key->refkey);
 
        kb= key->block.first;
@@ -2175,7 +2368,7 @@ static void lib_link_mball(FileData *fd, Main *main)
 
                        for(a=0; a<mb->totcol; a++) mb->mat[a]= newlibadr_us(fd, mb->id.lib, mb->mat[a]);
 
-                       mb->ipo= newlibadr_us(fd, mb->id.lib, mb->ipo);
+                       mb->ipo= newlibadr_us(fd, mb->id.lib, mb->ipo); // XXX depreceated - old animation system
 
                        mb->id.flag -= LIB_NEEDLINK;
                }
@@ -2206,9 +2399,10 @@ static void lib_link_world(FileData *fd, Main *main)
        wrld= main->world.first;
        while(wrld) {
                if(wrld->id.flag & LIB_NEEDLINK) {
-
-                       wrld->ipo= newlibadr_us(fd, wrld->id.lib, wrld->ipo);
-
+                       if (wrld->adt) lib_link_animdata(fd, &wrld->id, wrld->adt);
+                       
+                       wrld->ipo= newlibadr_us(fd, wrld->id.lib, wrld->ipo); // XXX depreceated - old animation system
+                       
                        for(a=0; a<MAX_MTEX; a++) {
                                mtex= wrld->mtex[a];
                                if(mtex) {
@@ -2216,9 +2410,9 @@ static void lib_link_world(FileData *fd, Main *main)
                                        mtex->object= newlibadr(fd, wrld->id.lib, mtex->object);
                                }
                        }
-
+                       
                        lib_link_scriptlink(fd, &wrld->id, &wrld->scriptlink);
-
+                       
                        wrld->id.flag -= LIB_NEEDLINK;
                }
                wrld= wrld->id.next;
@@ -2229,6 +2423,9 @@ static void direct_link_world(FileData *fd, World *wrld)
 {
        int a;
 
+       wrld->adt= newdataadr(fd, wrld->adt);
+       direct_link_animdata(fd, wrld->adt);
+       
        direct_link_scriptlink(fd, &wrld->scriptlink);
 
        for(a=0; a<MAX_MTEX; a++) {
@@ -2238,40 +2435,6 @@ static void direct_link_world(FileData *fd, World *wrld)
 }
 
 
-/* ************ READ IPO ***************** */
-
-static void lib_link_ipo(FileData *fd, Main *main)
-{
-       Ipo *ipo;
-
-       ipo= main->ipo.first;
-       while(ipo) {
-               if(ipo->id.flag & LIB_NEEDLINK) {
-                       IpoCurve *icu;
-                       for(icu= ipo->curve.first; icu; icu= icu->next) {
-                               if(icu->driver)
-                                       icu->driver->ob= newlibadr(fd, ipo->id.lib, icu->driver->ob);
-                       }
-                       ipo->id.flag -= LIB_NEEDLINK;
-               }
-               ipo= ipo->id.next;
-       }
-}
-
-static void direct_link_ipo(FileData *fd, Ipo *ipo)
-{
-       IpoCurve *icu;
-
-       link_list(fd, &(ipo->curve));
-       icu= ipo->curve.first;
-       while(icu) {
-               icu->bezt= newdataadr(fd, icu->bezt);
-               icu->bp= newdataadr(fd, icu->bp);
-               icu->driver= newdataadr(fd, icu->driver);
-               icu= icu->next;
-       }
-}
-
 /* ************ READ VFONT ***************** */
 
 static void lib_link_vfont(FileData *fd, Main *main)
@@ -2430,7 +2593,7 @@ static void lib_link_curve(FileData *fd, Main *main)
                        cu->vfonti= newlibadr_us(fd, cu->id.lib, cu->vfonti);
                        cu->vfontbi= newlibadr_us(fd, cu->id.lib, cu->vfontbi);
 
-                       cu->ipo= newlibadr_us(fd, cu->id.lib, cu->ipo);
+                       cu->ipo= newlibadr_us(fd, cu->id.lib, cu->ipo); // XXX depreceated - old animation system
                        cu->key= newlibadr_us(fd, cu->id.lib, cu->key);
 
                        cu->id.flag -= LIB_NEEDLINK;
@@ -2462,7 +2625,10 @@ static void direct_link_curve(FileData *fd, Curve *cu)
 {
        Nurb *nu;
        TextBox *tb;
-
+       
+       cu->adt= newdataadr(fd, cu->adt);
+       direct_link_animdata(fd, cu->adt);
+       
        cu->mat= newdataadr(fd, cu->mat);
        test_pointer_array(fd, (void **)&cu->mat);
        cu->str= newdataadr(fd, cu->str);
@@ -2490,6 +2656,7 @@ static void direct_link_curve(FileData *fd, Curve *cu)
        cu->bev.first=cu->bev.last= NULL;
        cu->disp.first=cu->disp.last= NULL;
        cu->editnurb= NULL;
+       cu->lastselbp= NULL;
        cu->path= NULL;
        cu->editstr= NULL;
        
@@ -2535,6 +2702,9 @@ static void lib_link_texture(FileData *fd, Main *main)
 
 static void direct_link_texture(FileData *fd, Tex *tex)
 {
+       tex->adt= newdataadr(fd, tex->adt);
+       direct_link_animdata(fd, tex->adt);
+       
        tex->plugin= newdataadr(fd, tex->plugin);
        if(tex->plugin) {
                tex->plugin->handle= 0;
@@ -2604,6 +2774,9 @@ static void direct_link_material(FileData *fd, Material *ma)
 {
        int a;
 
+       ma->adt= newdataadr(fd, ma->adt);
+       direct_link_animdata(fd, ma->adt);
+       
        for(a=0; a<MAX_MTEX; a++) {
                ma->mtex[a]= newdataadr(fd, ma->mtex[a]);
        }
@@ -2636,7 +2809,7 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
        part= main->particle.first;
        while(part) {
                if(part->id.flag & LIB_NEEDLINK) {
-                       part->ipo= newlibadr_us(fd, part->id.lib, part->ipo);
+                       part->ipo= newlibadr_us(fd, part->id.lib, part->ipo); // XXX depreceated - old animation system
                        part->dup_ob = newlibadr(fd, part->id.lib, part->dup_ob);
                        part->dup_group = newlibadr(fd, part->id.lib, part->dup_group);
                        part->eff_group = newlibadr(fd, part->id.lib, part->eff_group);
@@ -2926,7 +3099,7 @@ static void lib_link_latt(FileData *fd, Main *main)
        while(lt) {
                if(lt->id.flag & LIB_NEEDLINK) {
                        
-                       lt->ipo= newlibadr_us(fd, lt->id.lib, lt->ipo);
+                       lt->ipo= newlibadr_us(fd, lt->id.lib, lt->ipo); // XXX depreceated - old animation system
                        lt->key= newlibadr_us(fd, lt->id.lib, lt->key);
                        
                        lt->id.flag -= LIB_NEEDLINK;
@@ -2977,11 +3150,15 @@ static void lib_link_object(FileData *fd, Main *main)
        while(ob) {
                if(ob->id.flag & LIB_NEEDLINK) {
                        if (ob->id.properties) IDP_LibLinkProperty(ob->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+                       if (ob->adt) lib_link_animdata(fd, &ob->id, ob->adt);
+                       
+// XXX depreceated - old animation system <<<                  
+                       ob->ipo= newlibadr_us(fd, ob->id.lib, ob->ipo);
+                       ob->action = newlibadr_us(fd, ob->id.lib, ob->action);
+// >>> XXX depreceated - old animation system
 
                        ob->parent= newlibadr(fd, ob->id.lib, ob->parent);
                        ob->track= newlibadr(fd, ob->id.lib, ob->track);
-                       ob->ipo= newlibadr_us(fd, ob->id.lib, ob->ipo);
-                       ob->action = newlibadr_us(fd, ob->id.lib, ob->action);
                        ob->poselib= newlibadr_us(fd, ob->id.lib, ob->poselib);
                        ob->dup_group= newlibadr_us(fd, ob->id.lib, ob->dup_group);
                        
@@ -3000,7 +3177,7 @@ static void lib_link_object(FileData *fd, Main *main)
                                }
                        }
                        ob->proxy_group= newlibadr(fd, ob->id.lib, ob->proxy_group);
-
+                       
                        poin= ob->data;
                        ob->data= newlibadr_us(fd, ob->id.lib, ob->data);
                           
@@ -3017,15 +3194,18 @@ static void lib_link_object(FileData *fd, Main *main)
                                }
                        }
                        for(a=0; a<ob->totcol; a++) ob->mat[a]= newlibadr_us(fd, ob->id.lib, ob->mat[a]);
-
+                       
                        ob->id.flag -= LIB_NEEDLINK;
                        /* if id.us==0 a new base will be created later on */
-
+                       
                        /* WARNING! Also check expand_object(), should reflect the stuff below. */
                        lib_link_pose(fd, ob, ob->pose);
                        lib_link_constraints(fd, &ob->id, &ob->constraints);
-                       lib_link_nlastrips(fd, &ob->id, &ob->nlastrips);
+                       
+// XXX depreceated - old animation system <<<  
                        lib_link_constraint_channels(fd, &ob->id, &ob->constraintChannels);
+                       lib_link_nlastrips(fd, &ob->id, &ob->nlastrips);
+// >>> XXX depreceated - old animation system
 
                        for(paf= ob->effect.first; paf; paf= paf->next) {
                                if(paf->type==EFF_PARTICLE) {
@@ -3296,16 +3476,6 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
        }
 }
 
-static void direct_link_nlastrips(FileData *fd, ListBase *strips)
-{
-       bActionStrip *strip;
-       
-       link_list(fd, strips);
-       
-       for(strip= strips->first; strip; strip= strip->next)
-               link_list(fd, &strip->modifiers);
-}
-
 static void direct_link_object(FileData *fd, Object *ob)
 {
        PartEff *paf;
@@ -3319,13 +3489,18 @@ static void direct_link_object(FileData *fd, Object *ob)
        ob->flag &= ~OB_FROMGROUP;
 
        ob->disp.first=ob->disp.last= NULL;
-
+       
+       ob->adt= newdataadr(fd, ob->adt);
+       direct_link_animdata(fd, ob->adt);
+       
        ob->pose= newdataadr(fd, ob->pose);
        direct_link_pose(fd, ob->pose);
 
        link_list(fd, &ob->defbase);
+// XXX depreceated - old animation system <<<
        direct_link_nlastrips(fd, &ob->nlastrips);
        link_list(fd, &ob->constraintChannels);
+// >>> XXX depreceated - old animation system 
 
        direct_link_scriptlink(fd, &ob->scriptlink);
 
@@ -3502,7 +3677,6 @@ static void lib_link_scene(FileData *fd, Main *main)
        Base *base, *next;
        Sequence *seq;
        SceneRenderLayer *srl;
-       int a;
        
        sce= main->scene.first;
        while(sce) {
@@ -3510,20 +3684,17 @@ static void lib_link_scene(FileData *fd, Main *main)
                        /*Link ID Properties -- and copy this comment EXACTLY for easy finding
                        of library blocks that implement this.*/
                        if (sce->id.properties) IDP_LibLinkProperty(sce->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
-
+                       if (sce->adt) lib_link_animdata(fd, &sce->id, sce->adt);
+                       
                        sce->camera= newlibadr(fd, sce->id.lib, sce->camera);
                        sce->world= newlibadr_us(fd, sce->id.lib, sce->world);
                        sce->set= newlibadr(fd, sce->id.lib, sce->set);
                        sce->ima= newlibadr_us(fd, sce->id.lib, sce->ima);
                        sce->toolsettings->imapaint.brush=
                                newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.brush);
-
-                       /* Sculptdata textures */
-                       for(a=0; a<MAX_MTEX; ++a) {
-                               MTex *mtex= sce->sculptdata.mtex[a];
-                               if(mtex)
-                                       mtex->tex= newlibadr_us(fd, sce->id.lib, mtex->tex);
-                       }
+                       if(sce->toolsettings->sculpt)
+                               sce->toolsettings->sculpt->brush=
+                                       newlibadr_us(fd, sce->id.lib, sce->toolsettings->sculpt->brush);
 
                        for(base= sce->base.first; base; base= next) {
                                next= base->next;
@@ -3541,6 +3712,11 @@ 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);
@@ -3590,7 +3766,6 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        Editing *ed;
        Sequence *seq;
        MetaStack *ms;
-       int a;
 
        sce->theDag = NULL;
        sce->dagisvalid = 0;
@@ -3598,7 +3773,10 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        sce->id.us= 1;
 
        link_list(fd, &(sce->base));
-
+       
+       sce->adt= newdataadr(fd, sce->adt);
+       direct_link_animdata(fd, sce->adt);
+       
        sce->basact= newdataadr(fd, sce->basact);
 
        sce->radio= newdataadr(fd, sce->radio);
@@ -3607,16 +3785,16 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        if(sce->toolsettings) {
                sce->toolsettings->vpaint= newdataadr(fd, sce->toolsettings->vpaint);
                sce->toolsettings->wpaint= newdataadr(fd, sce->toolsettings->wpaint);
+               sce->toolsettings->sculpt= newdataadr(fd, sce->toolsettings->sculpt);
+               if(sce->toolsettings->sculpt)
+                       sce->toolsettings->sculpt->session= MEM_callocN(sizeof(SculptSession), "reload sculpt session");
        }
-       sce->sculptdata.session= NULL;
-       /* SculptData textures */
-       for(a=0; a<MAX_MTEX; ++a)
-               sce->sculptdata.mtex[a]= newdataadr(fd,sce->sculptdata.mtex[a]);
 
        if(sce->ed) {
                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
 
                /* recursive link sequences, lb will be correctly initialized */
                link_recurs_seq(fd, &ed->seqbase);
@@ -3761,6 +3939,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
 
    This is needed, to make Ipo-Pinning work for Sequence-Ipos...
 */
+// XXX old animation system - depreceated stuff...
 static Sequence * find_sequence_from_ipo_helper(Main * main, Ipo * ipo)
 {
        Sequence *seq;
@@ -3827,6 +4006,9 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
                win->queue.first= win->queue.last= NULL;
                win->handlers.first= win->handlers.last= NULL;
                win->subwindows.first= win->subwindows.last= NULL;
+
+               win->drawtex= 0;
+               win->drawmethod= 0;
        }
        
        wm->operators.first= wm->operators.last= NULL;
@@ -3936,8 +4118,6 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                if(v3d->localvd) {
                                                        v3d->localvd->camera= newlibadr(fd, sc->id.lib, v3d->localvd->camera);
                                                }
-                                               v3d->depths= NULL;
-                                               v3d->ri= NULL;
                                        }
                                        else if(sl->spacetype==SPACE_IPO) {
                                                SpaceIpo *sipo= (SpaceIpo *)sl;
@@ -4244,7 +4424,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
        }
 }
 
-static void direct_link_region(FileData *fd, ARegion *ar)
+static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
 {
        Panel *pa;
 
@@ -4256,13 +4436,50 @@ static void direct_link_region(FileData *fd, ARegion *ar)
                pa->sortcounter= 0;
                pa->activedata= NULL;
        }
-
+       
+       ar->regiondata= newdataadr(fd, ar->regiondata);
+       if(ar->regiondata) {
+               if(spacetype==SPACE_VIEW3D) {
+                       RegionView3D *rv3d= ar->regiondata;
+                       
+                       rv3d->localvd= newdataadr(fd, rv3d->localvd);
+                       rv3d->clipbb= newdataadr(fd, rv3d->clipbb);
+                       
+                       rv3d->depths= NULL;
+                       rv3d->retopo_view_data= NULL;
+                       rv3d->ri= NULL;
+                       rv3d->sms= NULL;
+                       rv3d->smooth_timer= NULL;
+               }
+       }
+       
        ar->handlers.first= ar->handlers.last= NULL;
        ar->uiblocks.first= ar->uiblocks.last= NULL;
        ar->headerstr= NULL;
-       ar->regiondata= NULL;
        ar->swinid= 0;
        ar->type= NULL;
+       ar->swap= 0;
+}
+
+/* for the saved 2.50 files without regiondata */
+/* and as patch for 2.48 and older */
+static void view3d_split_250(View3D *v3d, ListBase *regions)
+{
+       ARegion *ar;
+       
+       for(ar= regions->first; ar; ar= ar->next) {
+               if(ar->regiontype==RGN_TYPE_WINDOW && ar->regiondata==NULL) {
+                       RegionView3D *rv3d;
+                       
+                       rv3d= ar->regiondata= MEM_callocN(sizeof(RegionView3D), "region v3d");
+                       rv3d->persp= v3d->persp;
+                       rv3d->view= v3d->view;
+                       rv3d->dist= v3d->dist;
+                       VECCOPY(rv3d->ofs, v3d->ofs);
+                       QUATCOPY(rv3d->viewquat, v3d->viewquat);
+                       Mat4One(rv3d->twmat);
+               }
+       }
 }
 
 static void direct_link_screen(FileData *fd, bScreen *sc)
@@ -4317,6 +4534,9 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                sa->handlers.first= sa->handlers.last= NULL;
                sa->type= NULL; /* spacetype callbacks */
                
+               for(ar= sa->regionbase.first; ar; ar= ar->next)
+                       direct_link_region(fd, ar, sa->spacetype);
+               
                /* accident can happen when read/save new file with older version */
                /* 2.50: we now always add spacedata for info */
                if(sa->spacedata.first==NULL) {
@@ -4324,12 +4544,15 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                        sa->spacetype= SPACE_INFO;
                        BLI_addtail(&sa->spacedata, sinfo);
                }
+               /* add local view3d too */
+               else if(sa->spacetype==SPACE_VIEW3D)
+                       view3d_split_250(sa->spacedata.first, &sa->regionbase);
                
                for (sl= sa->spacedata.first; sl; sl= sl->next) {
                        link_list(fd, &(sl->regionbase));
 
                        for(ar= sl->regionbase.first; ar; ar= ar->next)
-                               direct_link_region(fd, ar);
+                               direct_link_region(fd, ar, sl->spacetype);
 
                        if (sl->spacetype==SPACE_VIEW3D) {
                                View3D *v3d= (View3D*) sl;
@@ -4342,11 +4565,9 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                }
                                v3d->localvd= newdataadr(fd, v3d->localvd);
                                v3d->afterdraw.first= v3d->afterdraw.last= NULL;
-                               v3d->clipbb= newdataadr(fd, v3d->clipbb);
-                               v3d->retopo_view_data= NULL;
                                v3d->properties_storage= NULL;
-                               v3d->sms= NULL;
-                               v3d->smooth_timer= NULL;
+                               
+                               view3d_split_250(v3d, &sl->regionbase);
                        }
                        else if (sl->spacetype==SPACE_OOPS) {
                                SpaceOops *soops= (SpaceOops*) sl;
@@ -4396,9 +4617,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                        }
                }
                
-               for(ar= sa->regionbase.first; ar; ar= ar->next)
-                       direct_link_region(fd, ar);
-               
                sa->actionzones.first= sa->actionzones.last= NULL;
 
                sa->v1= newdataadr(fd, sa->v1);
@@ -4495,7 +4713,7 @@ static void lib_link_sound(FileData *fd, Main *main)
        while(sound) {
                if(sound->id.flag & LIB_NEEDLINK) {
                        sound->id.flag -= LIB_NEEDLINK;
-                       sound->ipo= newlibadr_us(fd, sound->id.lib, sound->ipo);
+                       sound->ipo= newlibadr_us(fd, sound->id.lib, sound->ipo); // XXX depreceated - old animation system
                        sound->stream = 0;
                }
                sound= sound->id.next;
@@ -5214,6 +5432,13 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                ar->v2d.scroll= V2D_SCROLL_BOTTOM;
                                ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
                                break;
+                       case SPACE_NODE:
+                               ar= MEM_callocN(sizeof(ARegion), "nodetree area for node");
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_CHANNELS;
+                               ar->alignment= RGN_ALIGN_LEFT;
+                               ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
+                               ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
                        case SPACE_FILE:
                                /* channel (bookmarks/directories) region */
                                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
@@ -5229,6 +5454,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                break;
                }
        }
+
        /* main region */
        ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
        
@@ -5239,7 +5465,12 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
        
        if(sl) {
                /* if active spacetype has view2d data, copy that over to main region */
+               /* and we split view3d */
                switch(sl->spacetype) {
+                       case SPACE_VIEW3D:
+                               view3d_split_250((View3D *)sl, lb);
+                               break;          
+                                               
                        case SPACE_OOPS:
                        {
                                SpaceOops *soops= (SpaceOops *)sl;
@@ -5355,7 +5586,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                        }
                        case SPACE_FILE:
                        {
-                               SpaceFile *sfile= (SpaceFile *)sl;
+                               // SpaceFile *sfile= (SpaceFile *)sl;
                                ar->v2d.tot.xmin = ar->v2d.tot.ymin = 0;
                                ar->v2d.tot.xmax = ar->winx;
                                ar->v2d.tot.ymax = ar->winy;
@@ -8437,14 +8668,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
        if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 3)) {
                bScreen *sc;
-               Ipo *ipo;
-               IpoCurve *icu;
-               
-               /* fix IPO-curves to work with new interpolation options */
-               for (ipo=main->ipo.first; ipo; ipo= ipo->id.next) {
-                       for (icu= ipo->curve.first; icu; icu= icu->next) 
-                               set_interpolation_ipocurve(icu, icu->ipo);
-               }
                
                /* adjust default settings for Animation Editors */
                for (sc= main->screen.first; sc; sc= sc->id.next) {
@@ -8491,9 +8714,18 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                for(screen= main->screen.first; screen; screen= screen->id.next)
                        do_versions_windowmanager_2_50(screen);
                
+               /* old Animation System (using IPO's) needs to be converted to the new Animato system 
+                * (NOTE: conversion code in blenkernel/intern/ipo.c for now)
+                */
+               //do_versions_ipos_to_animato(main);
+               
                /* struct audio data moved to renderdata */
-               for(scene= main->scene.first; scene; scene= scene->id.next)
+               for(scene= main->scene.first; scene; scene= scene->id.next) {
                        scene->r.audio = scene->audio;
+                       
+                       if(!scene->toolsettings->uv_selectmode)
+                               scene->toolsettings->uv_selectmode= UV_SELECT_VERTEX;
+               }
                
                /* shader, composit and texture node trees have id.name empty, put something in
                 * to have them show in RNA viewer and accessible otherwise.
@@ -8501,7 +8733,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                for(ma= main->mat.first; ma; ma= ma->id.next) {
                        if(ma->nodetree && strlen(ma->nodetree->id.name)==0)
                                strcpy(ma->nodetree->id.name, "NTShader Nodetree");
-       }
+               }
                /* and composit trees */
                for(sce= main->scene.first; sce; sce= sce->id.next) {
                        if(sce->nodetree && strlen(sce->nodetree->id.name)==0)
@@ -8604,7 +8836,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_material(fd, main);
        lib_link_texture(fd, main);
        lib_link_image(fd, main);
-       lib_link_ipo(fd, main);
+       lib_link_ipo(fd, main);         // XXX depreceated... still needs to be maintained for version patches still
        lib_link_key(fd, main);
        lib_link_world(fd, main);
        lib_link_lamp(fd, main);
@@ -8866,14 +9098,9 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
        }
 }
 
-static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSettings *part)
-{
-       expand_doit(fd, mainvar, part->dup_ob);
-       expand_doit(fd, mainvar, part->dup_group);
-       expand_doit(fd, mainvar, part->eff_group);
-       expand_doit(fd, mainvar, part->bb_ob);
-}
 
+
+// XXX depreceated - old animation system
 static void expand_ipo(FileData *fd, Main *mainvar, Ipo *ipo)
 {
        IpoCurve *icu;
@@ -8883,6 +9110,50 @@ static void expand_ipo(FileData *fd, Main *mainvar, Ipo *ipo)
        }
 }
 
+// XXX depreceated - old animation system
+static void expand_constraint_channels(FileData *fd, Main *mainvar, ListBase *chanbase)
+{
+       bConstraintChannel *chan;
+       for (chan=chanbase->first; chan; chan=chan->next) {
+               expand_doit(fd, mainvar, chan->ipo);
+       }
+}
+
+// XXX depreceated - old animation system
+static void expand_action(FileData *fd, Main *mainvar, bAction *act)
+{
+       bActionChannel *chan;
+       
+       for (chan=act->chanbase.first; chan; chan=chan->next) {
+               expand_doit(fd, mainvar, chan->ipo);
+               expand_constraint_channels(fd, mainvar, &chan->constraintChannels);
+       }
+}
+
+static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
+{
+       FCurve *fcd;
+       
+       /* own action */
+       expand_doit(fd, mainvar, adt->action);
+       
+       /* 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;
+               
+               expand_doit(fd, mainvar, driver->id);
+               expand_doit(fd, mainvar, driver->id2);
+       }
+}      
+
+static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSettings *part)
+{
+       expand_doit(fd, mainvar, part->dup_ob);
+       expand_doit(fd, mainvar, part->dup_group);
+       expand_doit(fd, mainvar, part->eff_group);
+       expand_doit(fd, mainvar, part->bb_ob);
+}
+
 static void expand_group(FileData *fd, Main *mainvar, Group *group)
 {
        GroupObject *go;
@@ -8894,7 +9165,10 @@ static void expand_group(FileData *fd, Main *mainvar, Group *group)
 
 static void expand_key(FileData *fd, Main *mainvar, Key *key)
 {
-       expand_doit(fd, mainvar, key->ipo);
+       expand_doit(fd, mainvar, key->ipo); // XXX depreceated - old animation system
+       
+       if(key->adt)
+               expand_animdata(fd, mainvar, key->adt);
 }
 
 static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree)
@@ -8910,7 +9184,10 @@ static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree)
 static void expand_texture(FileData *fd, Main *mainvar, Tex *tex)
 {
        expand_doit(fd, mainvar, tex->ima);
-       expand_doit(fd, mainvar, tex->ipo);
+       expand_doit(fd, mainvar, tex->ipo); // XXX depreceated - old animation system
+       
+       if(tex->adt)
+               expand_animdata(fd, mainvar, tex->adt);
        
        if(tex->nodetree)
                expand_nodetree(fd, mainvar, tex->nodetree);
@@ -8937,7 +9214,10 @@ static void expand_material(FileData *fd, Main *mainvar, Material *ma)
                }
        }
        
-       expand_doit(fd, mainvar, ma->ipo);
+       expand_doit(fd, mainvar, ma->ipo); // XXX depreceated - old animation system
+       
+       if(ma->adt)
+               expand_animdata(fd, mainvar, ma->adt);
        
        if(ma->nodetree)
                expand_nodetree(fd, mainvar, ma->nodetree);
@@ -8953,12 +9233,16 @@ static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la)
                        expand_doit(fd, mainvar, la->mtex[a]->object);
                }
        }
-       expand_doit(fd, mainvar, la->ipo);
+       
+       expand_doit(fd, mainvar, la->ipo); // XXX depreceated - old animation system
+       
+       if (la->adt)
+               expand_animdata(fd, mainvar, la->adt);
 }
 
 static void expand_lattice(FileData *fd, Main *mainvar, Lattice *lt)
 {
-       expand_doit(fd, mainvar, lt->ipo);
+       expand_doit(fd, mainvar, lt->ipo); // XXX depreceated - old animation system
        expand_doit(fd, mainvar, lt->key);
 }
 
@@ -8973,7 +9257,11 @@ static void expand_world(FileData *fd, Main *mainvar, World *wrld)
                        expand_doit(fd, mainvar, wrld->mtex[a]->object);
                }
        }
-       expand_doit(fd, mainvar, wrld->ipo);
+       
+       expand_doit(fd, mainvar, wrld->ipo); // XXX depreceated - old animation system
+       
+       if (wrld->adt)
+               expand_animdata(fd, mainvar, wrld->adt);
 }
 
 
@@ -8993,15 +9281,19 @@ static void expand_curve(FileData *fd, Main *mainvar, Curve *cu)
        for(a=0; a<cu->totcol; a++) {
                expand_doit(fd, mainvar, cu->mat[a]);
        }
+       
        expand_doit(fd, mainvar, cu->vfont);
        expand_doit(fd, mainvar, cu->vfontb);   
        expand_doit(fd, mainvar, cu->vfonti);
        expand_doit(fd, mainvar, cu->vfontbi);
        expand_doit(fd, mainvar, cu->key);
-       expand_doit(fd, mainvar, cu->ipo);
+       expand_doit(fd, mainvar, cu->ipo); // XXX depreceated - old animation system
        expand_doit(fd, mainvar, cu->bevobj);
        expand_doit(fd, mainvar, cu->taperobj);
        expand_doit(fd, mainvar, cu->textoncurve);
+       
+       if(cu->adt)
+               expand_animdata(fd, mainvar, cu->adt);
 }
 
 static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me)
@@ -9044,7 +9336,7 @@ static void expand_constraints(FileData *fd, Main *mainvar, ListBase *lb)
        for (curcon=lb->first; curcon; curcon=curcon->next) {
                
                if (curcon->ipo)
-                       expand_doit(fd, mainvar, curcon->ipo);
+                       expand_doit(fd, mainvar, curcon->ipo); // XXX depreceated - old animation system
                
                switch (curcon->type) {
                case CONSTRAINT_TYPE_NULL:
@@ -9190,23 +9482,6 @@ static void expand_armature(FileData *fd, Main *mainvar, bArmature *arm)
        }
 }
 
-static void expand_constraint_channels(FileData *fd, Main *mainvar, ListBase *chanbase)
-{
-       bConstraintChannel *chan;
-       for (chan=chanbase->first; chan; chan=chan->next){
-               expand_doit(fd, mainvar, chan->ipo);
-       }
-}
-
-static void expand_action(FileData *fd, Main *mainvar, bAction *act)
-{
-       bActionChannel *chan;
-       for (chan=act->chanbase.first; chan; chan=chan->next) {
-               expand_doit(fd, mainvar, chan->ipo);
-               expand_constraint_channels(fd, mainvar, &chan->constraintChannels);
-       }
-}
-
 static void expand_modifier(FileData *fd, Main *mainvar, ModifierData *md)
 {
        if (md->type==eModifierType_Lattice) {
@@ -9260,16 +9535,19 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
 
 
        expand_doit(fd, mainvar, ob->data);
-       expand_doit(fd, mainvar, ob->ipo);
-       expand_doit(fd, mainvar, ob->action);
-       expand_doit(fd, mainvar, ob->poselib);
-
+       
        for (md=ob->modifiers.first; md; md=md->next) {
                expand_modifier(fd, mainvar, md);
        }
 
        expand_pose(fd, mainvar, ob->pose);
+       expand_doit(fd, mainvar, ob->poselib);
        expand_constraints(fd, mainvar, &ob->constraints);
+       
+// XXX depreceated - old animation system (for version patching only) 
+       expand_doit(fd, mainvar, ob->ipo);
+       expand_doit(fd, mainvar, ob->action);
+       
        expand_constraint_channels(fd, mainvar, &ob->constraintChannels);
 
        for (strip=ob->nlastrips.first; strip; strip=strip->next){
@@ -9277,7 +9555,11 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
                expand_doit(fd, mainvar, strip->act);
                expand_doit(fd, mainvar, strip->ipo);
        }
-
+// XXX depreceated - old animation system (for version patching only)
+       
+       if(ob->adt)
+               expand_animdata(fd, mainvar, ob->adt);
+       
        for(a=0; a<ob->totcol; a++) {
                expand_doit(fd, mainvar, ob->mat[a]);
        }
@@ -9377,6 +9659,9 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
        expand_doit(fd, mainvar, sce->camera);
        expand_doit(fd, mainvar, sce->world);
        
+       if(sce->adt)
+               expand_animdata(fd, mainvar, sce->adt);
+       
        if(sce->nodetree)
                expand_nodetree(fd, mainvar, sce->nodetree);
        
@@ -9384,17 +9669,19 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
                expand_doit(fd, mainvar, srl->mat_override);
                expand_doit(fd, mainvar, srl->light_override);
        }
-                               
 }
 
 static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
 {
-       expand_doit(fd, mainvar, ca->ipo);
+       expand_doit(fd, mainvar, ca->ipo); // XXX depreceated - old animation system
+       
+       if(ca->adt)
+               expand_animdata(fd, mainvar, ca->adt);
 }
 
 static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
 {
-       expand_doit(fd, mainvar, snd->ipo);
+       expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
 }
 
 
@@ -9461,7 +9748,7 @@ static void expand_main(FileData *fd, Main *mainvar)
                                                expand_armature(fd, mainvar, (bArmature *)id);
                                                break;
                                        case ID_AC:
-                                               expand_action(fd, mainvar, (bAction *)id);
+                                               expand_action(fd, mainvar, (bAction *)id); // XXX depreceated - old animation system
                                                break;
                                        case ID_GR:
                                                expand_group(fd, mainvar, (Group *)id);
@@ -9473,7 +9760,7 @@ static void expand_main(FileData *fd, Main *mainvar)
                                                expand_brush(fd, mainvar, (Brush *)id);
                                                break;
                                        case ID_IP:
-                                               expand_ipo(fd, mainvar, (Ipo *)id);
+                                               expand_ipo(fd, mainvar, (Ipo *)id); // XXX depreceated - old animation system
                                                break;
                                        case ID_PA:
                                                expand_particlesettings(fd, mainvar, (ParticleSettings *)id);