Merging r46111 through r46136 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index 93cf4f2..84bc089 100644 (file)
@@ -77,6 +77,7 @@
 #include "DNA_nla_types.h"
 #include "DNA_node_types.h"
 #include "DNA_object_fluidsim.h" // NT
+#include "DNA_object_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_property_types.h"
@@ -94,6 +95,7 @@
 #include "DNA_vfont_types.h"
 #include "DNA_world_types.h"
 #include "DNA_movieclip_types.h"
+#include "DNA_mask_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -612,7 +614,7 @@ static void bh4_from_bh8(BHead *bhead, BHead8 *bhead8, int do_endian_swap)
                }
 
                /* this patch is to avoid a long long being read from not-eight aligned positions
-                  is necessary on any modern 64bit architecture) */
+                * is necessary on any modern 64bit architecture) */
                memcpy(&old, &bhead8->old, 8);
                bhead4->old = (int) (old >> 3);
 
@@ -1061,8 +1063,7 @@ void blo_freefiledata(FileData *fd)
                        close(fd->filedes);
                }
 
-               if (fd->gzfiledes != NULL)
-               {
+               if (fd->gzfiledes != NULL) {
                        gzclose(fd->gzfiledes);
                }
 
@@ -1138,7 +1139,7 @@ int BLO_is_a_library(const char *path, char *dir, char *group)
                if (!fd || !BLO_has_bfile_extension(fd+1)) return 0;
 
                /* now we know that we are in a blend file and it is safe to 
-                  assume that gp actually points to a group */
+                * assume that gp actually points to a group */
                if (strcmp("Screen", gp)!=0)
                        BLI_strncpy(group, gp, GROUP_MAX);
        }
@@ -1477,7 +1478,7 @@ static void test_pointer_array(FileData *fd, void **mat)
                len= MEM_allocN_len(*mat)/fd->filesdna->pointerlen;
 
                if (fd->filesdna->pointerlen==8 && fd->memsdna->pointerlen==4) {
-                       ipoin=imat= MEM_mallocN( len*4, "newmatar");
+                       ipoin=imat= MEM_mallocN(len*4, "newmatar");
                        lpoin= *mat;
 
                        while (len-- > 0) {
@@ -1492,7 +1493,7 @@ static void test_pointer_array(FileData *fd, void **mat)
                }
 
                if (fd->filesdna->pointerlen==4 && fd->memsdna->pointerlen==8) {
-                       lpoin=lmat= MEM_mallocN( len*8, "newmatar");
+                       lpoin=lmat= MEM_mallocN(len*8, "newmatar");
                        ipoin= *mat;
 
                        while (len-- > 0) {
@@ -1606,7 +1607,7 @@ static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData
                         * in the same field as int val; val2 in the
                         * IDPropertyData struct, they have to deal with
                         * endianness specifically
-
+                        *
                         * in theory, val and val2 would've already been swapped
                         * if switch_endian is true, so we have to first unswap
                         * them then reswap them as a single 64-bit entity.
@@ -2290,17 +2291,19 @@ static void lib_nodetree_do_versions_update_cb(void *UNUSED(data), ID *UNUSED(id
 
 /* verify types for nodes and groups, all data has to be read */
 /* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic
-* typedefs*/
+ * typedefs */
 static void lib_verify_nodetree(Main *main, int UNUSED(open))
 {
        bNodeTree *ntree;
        int i;
        bNodeTreeType *ntreetype;
 
-       /* this crashes blender on undo/redo
+       /* this crashes blender on undo/redo */
+#if 0
                if (open==1) {
                        reinit_nodesystem();
-               }*/
+               }
+#endif
        
        /* set node->typeinfo pointers */
        for (i=0; i < NUM_NTREE_TYPES; ++i) {
@@ -2754,9 +2757,9 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb)
                cp= key->elemstr;
                poin= data;
 
-               while ( cp[0] ) {       /* cp[0]==amount */
+               while ( cp[0] ) {  /* cp[0] == amount */
 
-                       switch(cp[1]) {         /* cp[1]= type */
+                       switch (cp[1]) {  /* cp[1] = type */
                        case IPO_FLOAT:
                        case IPO_BPOINT:
                        case IPO_BEZTRIPLE:
@@ -2936,12 +2939,12 @@ static void direct_link_text(FileData *fd, Text *text)
 
        text->compiled= NULL;
 
-/*
+#if 0
        if (text->flags & TXT_ISEXT) {
                reopen_text(text);
                }
                else {
-*/
+#endif
 
        link_list(fd, &text->lines);
        link_list(fd, &text->markers);
@@ -3242,8 +3245,8 @@ static void lib_link_material(FileData *fd, Main *main)
                if (ma->id.flag & LIB_NEEDLINK) {
                        if (ma->adt) lib_link_animdata(fd, &ma->id, ma->adt);
 
-                       /*Link ID Properties -- and copy this comment EXACTLY for easy finding
-                       of library blocks that implement this.*/
+                       /* Link ID Properties -- and copy this comment EXACTLY for easy finding
+                        * of library blocks that implement this.*/
                        if (ma->id.properties) IDP_LibLinkProperty(ma->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 
                        ma->ipo= newlibadr_us(fd, ma->id.lib, ma->ipo);
@@ -3440,7 +3443,7 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
                                for (; state; state=state->next) {
                                        rule = state->rules.first;
                                for (; rule; rule=rule->next)
-                                       switch(rule->type) {
+                                       switch (rule->type) {
                                                case eBoidRuleType_Goal:
                                                case eBoidRuleType_Avoid:
                                                {
@@ -3539,7 +3542,7 @@ static void lib_link_particlesystems(FileData *fd, Object *ob, ID *id, ListBase
                }
                else {
                        /* particle modifier must be removed before particle system */
-                       ParticleSystemModifierData *psmd= psys_get_modifier(ob,psys);
+                       ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
                        BLI_remlink(&ob->modifiers, psmd);
                        modifier_free((ModifierData *)psmd);
 
@@ -3555,15 +3558,15 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
        int a;
 
        for (psys=particles->first; psys; psys=psys->next) {
-               psys->particles=newdataadr(fd,psys->particles);
+               psys->particles=newdataadr(fd, psys->particles);
                
                if (psys->particles && psys->particles->hair) {
-                       for (a=0,pa=psys->particles; a<psys->totpart; a++, pa++)
-                               pa->hair=newdataadr(fd,pa->hair);
+                       for (a=0, pa=psys->particles; a<psys->totpart; a++, pa++)
+                               pa->hair=newdataadr(fd, pa->hair);
                }
                
                if (psys->particles && psys->particles->keys) {
-                       for (a=0,pa=psys->particles; a<psys->totpart; a++, pa++) {
+                       for (a=0, pa=psys->particles; a<psys->totpart; a++, pa++) {
                                pa->keys= NULL;
                                pa->totkey= 0;
                        }
@@ -3574,17 +3577,17 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
                if (psys->particles && psys->particles->boid) {
                        pa = psys->particles;
                        pa->boid = newdataadr(fd, pa->boid);
-                       for (a=1,pa++; a<psys->totpart; a++, pa++)
+                       for (a=1, pa++; a<psys->totpart; a++, pa++)
                                pa->boid = (pa-1)->boid + 1;
                }
                else if (psys->particles) {
-                       for (a=0,pa=psys->particles; a<psys->totpart; a++, pa++)
+                       for (a=0, pa=psys->particles; a<psys->totpart; a++, pa++)
                                pa->boid = NULL;
                }
 
                psys->fluid_springs = newdataadr(fd, psys->fluid_springs);
 
-               psys->child = newdataadr(fd,psys->child);
+               psys->child = newdataadr(fd, psys->child);
                psys->effectors = NULL;
 
                link_list(fd, &psys->targets);
@@ -3683,8 +3686,8 @@ static void lib_link_mesh(FileData *fd, Main *main)
                if (me->id.flag & LIB_NEEDLINK) {
                        int i;
 
-                       /*Link ID Properties -- and copy this comment EXACTLY for easy finding
-                       of library blocks that implement this.*/
+                       /* Link ID Properties -- and copy this comment EXACTLY for easy finding
+                        * of library blocks that implement this.*/
                        if (me->id.properties) IDP_LibLinkProperty(me->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
                        if (me->adt) lib_link_animdata(fd, &me->id, me->adt);
 
@@ -3709,7 +3712,7 @@ static void lib_link_mesh(FileData *fd, Main *main)
                        /*check if we need to convert mfaces to mpolys*/
                        if (me->totface && !me->totpoly) {
                                /* temporarily switch main so that reading from
-                                  external CustomData works */
+                                * external CustomData works */
                                Main *gmain = G.main;
                                G.main = main;
                                
@@ -3779,9 +3782,9 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte
 
                        if (mdisps[i].totdisp && !mdisps[i].level) {
                                /* this calculation is only correct for loop mdisps;
-                                  if loading pre-BMesh face mdisps this will be
-                                  overwritten with the correct value in
-                                  bm_corners_to_loops() */
+                                * if loading pre-BMesh face mdisps this will be
+                                * overwritten with the correct value in
+                                * bm_corners_to_loops() */
                                float gridsize = sqrtf(mdisps[i].totdisp);
                                mdisps[i].level = (int)(logf(gridsize - 1.0f) / M_LN2) + 1;
                        }
@@ -3808,6 +3811,14 @@ static void direct_link_customdata(FileData *fd, CustomData *data, int count)
        int i = 0;
 
        data->layers= newdataadr(fd, data->layers);
+
+       /* annoying workaround for bug [#31079] loading legacy files with
+        * no polygons _but_ have stale customdata */
+       if (UNLIKELY(count == 0 && data->layers == NULL && data->totlayer != 0)) {
+               memset(data, 0, sizeof(*data));
+               return;
+       }
+
        data->external= newdataadr(fd, data->external);
 
        while (i < data->totlayer) {
@@ -3852,7 +3863,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
        direct_link_animdata(fd, mesh->adt);
 
        /* normally direct_link_dverts should be called in direct_link_customdata,
-          but for backwards compat in do_versions to work we do it here */
+        * but for backwards compat in do_versions to work we do it here */
        direct_link_dverts(fd, mesh->totvert, mesh->dvert);
 
        direct_link_customdata(fd, &mesh->vdata, mesh->totvert);
@@ -3912,11 +3923,11 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
                mesh->mr->verts = newdataadr(fd, mesh->mr->verts);
                
                /* If mesh has the same number of vertices as the
-                  highest multires level, load the current mesh verts
-                  into multires and discard the old data. Needed
-                  because some saved files either do not have a verts
-                  array, or the verts array contains out-of-date
-                  data. */
+                * highest multires level, load the current mesh verts
+                * into multires and discard the old data. Needed
+                * because some saved files either do not have a verts
+                * array, or the verts array contains out-of-date
+                * data. */
                if (mesh->totvert == ((MultiresLevel*)mesh->mr->levels.last)->totvert) {
                        if (mesh->mr->verts)
                                MEM_freeN(mesh->mr->verts);
@@ -4225,8 +4236,7 @@ static void lib_link_object(FileData *fd, Main *main)
                        {
                                SmokeModifierData *smd = (SmokeModifierData *)modifiers_findByType(ob, eModifierType_Smoke);
                                
-                               if (smd && smd->type == MOD_SMOKE_TYPE_DOMAIN && smd->domain)
-                               {
+                               if (smd && smd->type == MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
                                        smd->domain->flags |= MOD_SMOKE_FILE_LOAD; /* flag for refreshing the simulation after loading */
                                }
                        }
@@ -4349,8 +4359,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                else if (md->type==eModifierType_Smoke) {
                        SmokeModifierData *smd = (SmokeModifierData*) md;
 
-                       if (smd->type==MOD_SMOKE_TYPE_DOMAIN)
-                       {
+                       if (smd->type==MOD_SMOKE_TYPE_DOMAIN) {
                                smd->flow = NULL;
                                smd->coll = NULL;
                                smd->domain = newdataadr(fd, smd->domain);
@@ -4395,8 +4404,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                                smd->flow = NULL;
                                smd->domain = NULL;
                                smd->coll = newdataadr(fd, smd->coll);
-                               if (smd->coll)
-                               {
+                               if (smd->coll) {
                                        smd->coll->points = NULL;
                                        smd->coll->numpoints = 0;
                                }
@@ -4408,8 +4416,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                else if (md->type==eModifierType_DynamicPaint) {
                        DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
 
-                       if (pmd->canvas)
-                       {
+                       if (pmd->canvas) {
                                pmd->canvas = newdataadr(fd, pmd->canvas);
                                pmd->canvas->pmd = pmd;
                                pmd->canvas->dm = NULL;
@@ -4429,8 +4436,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                                        }
                                }
                        }
-                       if (pmd->brush)
-                       {
+                       if (pmd->brush) {
                                pmd->brush = newdataadr(fd, pmd->brush);
                                pmd->brush->pmd = pmd;
                                pmd->brush->psys = newdataadr(fd, pmd->brush->psys);
@@ -4449,9 +4455,9 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        collmd->xnew = newdataadr(fd, collmd->xnew);
                        collmd->mfaces = newdataadr(fd, collmd->mfaces);
                        
-                       collmd->current_x = MEM_callocN(sizeof(MVert)*collmd->numverts,"current_x");
-                       collmd->current_xnew = MEM_callocN(sizeof(MVert)*collmd->numverts,"current_xnew");
-                       collmd->current_v = MEM_callocN(sizeof(MVert)*collmd->numverts,"current_v");
+                       collmd->current_x = MEM_callocN(sizeof(MVert)*collmd->numverts, "current_x");
+                       collmd->current_xnew = MEM_callocN(sizeof(MVert)*collmd->numverts, "current_xnew");
+                       collmd->current_v = MEM_callocN(sizeof(MVert)*collmd->numverts, "current_v");
                        */
                        
                        collmd->x = NULL;
@@ -4567,7 +4573,7 @@ static void direct_link_object(FileData *fd, Object *ob)
        ob->flag &= ~OB_FROMGROUP;
 
        /* loading saved files with editmode enabled works, but for undo we like
-          to stay in object mode during undo presses so keep editmode disabled */
+        * to stay in object mode during undo presses so keep editmode disabled */
        if (fd->memfile)
                ob->mode &= ~(OB_MODE_EDIT|OB_MODE_PARTICLE_EDIT);
        
@@ -4677,7 +4683,7 @@ static void direct_link_object(FileData *fd, Object *ob)
        ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */
 
        link_list(fd, &ob->particlesystem);
-       direct_link_particlesystems(fd,&ob->particlesystem);
+       direct_link_particlesystems(fd, &ob->particlesystem);
        
        link_list(fd, &ob->prop);
        prop= ob->prop.first;
@@ -4802,8 +4808,8 @@ static void lib_link_scene(FileData *fd, Main *main)
        sce= main->scene.first;
        while (sce) {
                if (sce->id.flag & LIB_NEEDLINK) {
-                       /*Link ID Properties -- and copy this comment EXACTLY for easy finding
-                       of library blocks that implement this.*/
+                       /* 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);
                        
@@ -4837,7 +4843,8 @@ static void lib_link_scene(FileData *fd, Main *main)
                                }
                        }
 
-                       SEQ_BEGIN(sce->ed, seq) {
+                       SEQ_BEGIN (sce->ed, seq)
+                       {
                                if (seq->ipo) seq->ipo= newlibadr_us(fd, sce->id.lib, seq->ipo);
                                seq->scene_sound = NULL;
                                if (seq->scene) {
@@ -4968,7 +4975,8 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                /* recursive link sequences, lb will be correctly initialized */
                link_recurs_seq(fd, &ed->seqbase);
 
-               SEQ_BEGIN(ed, seq) {
+               SEQ_BEGIN (ed, seq)
+               {
                        seq->seq1= newdataadr(fd, seq->seq1);
                        seq->seq2= newdataadr(fd, seq->seq2);
                        seq->seq3= newdataadr(fd, seq->seq3);
@@ -5222,7 +5230,7 @@ static void butspace_version_132(SpaceButs *buts)
 }
 
 /* note: file read without screens option G_FILE_NO_UI; 
  check lib pointers in call below */
* check lib pointers in call below */
 static void lib_link_screen(FileData *fd, Main *main)
 {
        bScreen *sc;
@@ -5383,6 +5391,7 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                SpaceClip *sclip= (SpaceClip *)sl;
 
                                                sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
+                                               sclip->mask= newlibadr_us(fd, sc->id.lib, sclip->mask);
 
                                                sclip->scopes.track_preview = NULL;
                                                sclip->draw_context = NULL;
@@ -5650,6 +5659,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        SpaceClip *sclip= (SpaceClip *)sl;
 
                                        sclip->clip= restore_pointer_by_name(newmain, (ID *)sclip->clip, 1);
+                                       sclip->mask= restore_pointer_by_name(newmain, (ID *)sclip->mask, 1);
 
                                        sclip->scopes.ok = 0;
                                }
@@ -5745,7 +5755,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
        sc->swap= 0;
        
        /* hacky patch... but people have been saving files with the verse-blender,
-          causing the handler to keep running for ever, with no means to disable it */
+        * causing the handler to keep running for ever, with no means to disable it */
        for (a=0; a<SCREEN_MAXHANDLER; a+=2) {
                if ( sc->handler[a]==SCREEN_HANDLER_VERSE) {
                        sc->handler[a]= 0;
@@ -5922,9 +5932,9 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                //for (cl= sconsole->scrollback.first; cl; cl= cl->next)
                                //      cl->line= newdataadr(fd, cl->line);
                                
-                               /*comma expressions, (e.g. expr1, expr2, expr3) evalutate each expression,
-                                 from left to right.  the right-most expression sets the result of the comma
-                                 expression as a whole*/
+                               /* comma expressions, (e.g. expr1, expr2, expr3) evalutate each expression,
+                                * from left to right.  the right-most expression sets the result of the comma
+                                * expression as a whole*/
                                for (cl= sconsole->history.first; cl; cl= cl_next) {
                                        cl_next= cl->next;
                                        cl->line= newdataadr(fd, cl->line);
@@ -6065,8 +6075,10 @@ static void direct_link_speaker(FileData *fd, Speaker *spk)
        spk->adt= newdataadr(fd, spk->adt);
        direct_link_animdata(fd, spk->adt);
 
-       /*spk->sound= newdataadr(fd, spk->sound);
-       direct_link_sound(fd, spk->sound);*/
+#if 0
+       spk->sound= newdataadr(fd, spk->sound);
+       direct_link_sound(fd, spk->sound);
+#endif
 }
 
 /* ************** READ SOUND ******************* */
@@ -6078,8 +6090,7 @@ static void direct_link_sound(FileData *fd, bSound *sound)
        sound->waveform = NULL;
 
        // versioning stuff, if there was a cache, then we enable caching:
-       if (sound->cache)
-       {
+       if (sound->cache) {
                sound->flags |= SOUND_FLAGS_CACHING;
                sound->cache = NULL;
        }
@@ -6162,6 +6173,20 @@ static void direct_link_movieTracks(FileData *fd, ListBase *tracksbase)
        }
 }
 
+static void direct_link_movieDopesheet(FileData *fd, MovieTrackingDopesheet *dopesheet)
+{
+       MovieTrackingDopesheetChannel *channel;
+
+       link_list(fd, &dopesheet->channels);
+
+       channel = dopesheet->channels.first;
+       while (channel) {
+               channel->track = newdataadr(fd, channel->track);
+
+               channel = channel->next;
+       }
+}
+
 static void direct_link_movieclip(FileData *fd, MovieClip *clip)
 {
        MovieTracking *tracking= &clip->tracking;
@@ -6197,6 +6222,8 @@ static void direct_link_movieclip(FileData *fd, MovieClip *clip)
 
                object= object->next;
        }
+
+       direct_link_movieDopesheet(fd, &clip->tracking.dopesheet);
 }
 
 static void lib_link_movieclip(FileData *fd, Main *main)
@@ -6217,13 +6244,96 @@ static void lib_link_movieclip(FileData *fd, Main *main)
        }
 }
 
+/* ***************** READ MOVIECLIP *************** */
+
+static void direct_link_mask(FileData *fd, Mask *mask)
+{
+       MaskShape *shape;
+
+       mask->adt = newdataadr(fd, mask->adt);
+
+       link_list(fd, &mask->shapes);
+
+       shape = mask->shapes.first;
+       while (shape) {
+               MaskSpline *spline;
+
+               link_list(fd, &shape->splines);
+
+               spline = shape->splines.first;
+               while (spline) {
+                       int i;
+
+                       spline->points = newdataadr(fd, spline->points);
+
+                       for (i = 0; i < spline->tot_point; i++) {
+                               MaskSplinePoint *point = &spline->points[i];
+
+                               if (point->tot_uw)
+                                       point->uw = newdataadr(fd, point->uw);
+                       }
+
+                       spline = spline->next;
+               }
+
+               shape->act_spline = newdataadr(fd, shape->act_spline);
+               shape->act_point = newdataadr(fd, shape->act_point);
+
+               shape = shape->next;
+       }
+}
+
+static void lib_link_mask_parent(FileData *fd, Mask *mask, MaskParent *parent)
+{
+       parent->id = newlibadr_us(fd, mask->id.lib, parent->id);
+}
+
+static void lib_link_mask(FileData *fd, Main *main)
+{
+       Mask *mask;
+
+       mask = main->mask.first;
+       while (mask) {
+               if(mask->id.flag & LIB_NEEDLINK) {
+                       MaskShape *shape;
+
+                       if (mask->adt)
+                               lib_link_animdata(fd, &mask->id, mask->adt);
+
+                       shape = mask->shapes.first;
+                       while (shape) {
+                               MaskSpline *spline;
+
+                               spline = shape->splines.first;
+                               while (spline) {
+                                       int i;
+
+                                       for (i = 0; i < spline->tot_point; i++) {
+                                               MaskSplinePoint *point = &spline->points[i];
+
+                                               lib_link_mask_parent(fd, mask, &point->parent);
+                                       }
+
+                                       lib_link_mask_parent(fd, mask, &spline->parent);
+
+                                       spline = spline->next;
+                               }
+
+                               shape = shape->next;
+                       }
+
+                       mask->id.flag -= LIB_NEEDLINK;
+               }
+               mask = mask->id.next;
+       }
+}
+
 /* ************** GENERAL & MAIN ******************** */
 
 
 static const char *dataname(short id_code)
 {
-       
-       switch( id_code ) {
+       switch ( id_code ) {
                case ID_OB: return "Data from OB";
                case ID_ME: return "Data from ME";
                case ID_IP: return "Data from IP";
@@ -6333,7 +6443,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
        bhead= read_data_into_oldnewmap(fd, bhead, allocname);
 
        /* init pointers direct data */
-       switch( GS(id->name) ) {
+       switch (GS(id->name)) {
                case ID_WM:
                        direct_link_windowmanager(fd, (wmWindowManager *)id);
                        break;
@@ -6424,6 +6534,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                case ID_MC:
                        direct_link_movieclip(fd, (MovieClip *)id);
                        break;
+               case ID_MSK:
+                       direct_link_mask(fd, (Mask *)id);
+                       break;
        }
        
        /*link direct data of ID properties*/
@@ -6911,7 +7024,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
 
        if (sl) {
                /* first channels for ipo action nla... */
-               switch(sl->spacetype) {
+               switch (sl->spacetype) {
                        case SPACE_IPO:
                                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                                BLI_addtail(lb, ar);
@@ -7033,7 +7146,7 @@ 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) {
+               switch (sl->spacetype) {
                        case SPACE_VIEW3D:
                                view3d_split_250((View3D *)sl, lb);
                                break;          
@@ -7396,7 +7509,7 @@ static void do_version_mdef_250(Main *main)
 
                                if (mmd->bindcos) {
                                        /* make bindcos NULL in order to trick older versions
-                                          into thinking that the mesh was not bound yet */
+                                        * into thinking that the mesh was not bound yet */
                                        mmd->bindcagecos= mmd->bindcos;
                                        mmd->bindcos= NULL;
 
@@ -7439,8 +7552,7 @@ static void do_version_constraints_radians_degrees_250(ListBase *lb)
 static void do_version_old_trackto_to_constraints(Object *ob)
 {
        /* create new trackto constraint from the relationship */
-       if (ob->track)
-       {
+       if (ob->track) {
                bConstraint *con= add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_TRACKTO);
                bTrackToConstraint *data = con->data;
                
@@ -8325,8 +8437,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                Mesh *me;
 
                sound = main->sound.first;
-               while (sound)
-               {
+               while (sound) {
                        sound->max_gain = 1.0;
                        sound->min_gain = 0.0;
                        sound->distance = 1.0;
@@ -8388,7 +8499,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        /* in future, distinguish between different
                         * object bounding shapes */
                        ob->formfactor = 0.4f;
-                       /* patch form factor , note that inertia equiv radius
+                       /* patch form factor, note that inertia equiv radius
                         * of a rotation symmetrical obj */
                        if (ob->inertia != 1.0f) {
                                ob->formfactor /= ob->inertia * ob->inertia;
@@ -8539,9 +8650,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                bScreen *sc;
                Object *ob;
 
-               /*  As of now, this insures that the transition from the old Track system
-                       to the new full constraint Track is painless for everyone. - theeth
-               */
+               /* As of now, this insures that the transition from the old Track system
+                * to the new full constraint Track is painless for everyone. - theeth
+                */
                ob = main->object.first;
 
                while (ob) {
@@ -8549,7 +8660,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        list = &ob->constraints;
 
                        /* check for already existing TrackTo constraint
-                          set their track and up flag correctly */
+                        * set their track and up flag correctly */
 
                        if (list) {
                                bConstraint *curcon;
@@ -8627,8 +8738,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                Object *ob;
 
 
-               /*  As of now, this insures that the transition from the old Track system
-                       to the new full constraint Track is painless for everyone.*/
+               /* As of now, this insures that the transition from the old Track system
+                * to the new full constraint Track is painless for everyone.*/
                ob = main->object.first;
 
                while (ob) {
@@ -8636,7 +8747,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        list = &ob->constraints;
 
                        /* check for already existing TrackTo constraint
-                          set their track and up flag correctly */
+                        * set their track and up flag correctly */
 
                        if (list) {
                                bConstraint *curcon;
@@ -8737,9 +8848,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        /* ton: made this 230 instead of 229,
-          to be sure (tuho files) and this is a reliable check anyway
-          nevertheless, we might need to think over a fitness (initialize)
-          check apart from the do_versions() */
+        * to be sure (tuho files) and this is a reliable check anyway
+        * nevertheless, we might need to think over a fitness (initialize)
+        * check apart from the do_versions() */
 
        if (main->versionfile <= 230) {
                bScreen *sc;
@@ -8993,7 +9104,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                while (sce) {
                        ed= sce->ed;
                        if (ed) {
-                               SEQ_BEGIN(sce->ed, seq) {
+                               SEQ_BEGIN (sce->ed, seq)
+                               {
                                        if (seq->type==SEQ_IMAGE || seq->type==SEQ_MOVIE)
                                                seq->flag |= SEQ_MAKE_PREMUL;
                                }
@@ -9140,7 +9252,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
                while (sce) {
                        if (sce->toolsettings == NULL) {
-                               sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings),"Tool Settings Struct");    
+                               sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
                                sce->toolsettings->cornertype=0;
                                sce->toolsettings->degr = 90; 
                                sce->toolsettings->step = 9;
@@ -9150,7 +9262,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                sce->toolsettings->segments = 32;
                                sce->toolsettings->rings = 32;
                                sce->toolsettings->vertices = 32;
-                               sce->toolsettings->editbutflag =1;
                        }
                        sce= sce->id.next;      
                }
@@ -9519,7 +9630,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        list = &ob->constraints;
 
                        /* check for already existing MinMax (floor) constraint
-                          and update the sticky flagging */
+                        * and update the sticky flagging */
 
                        if (list) {
                                bConstraint *curcon;
@@ -9743,17 +9854,16 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                        if (md->type==eModifierType_Mirror) {
                                                MirrorModifierData *mmd = (MirrorModifierData*) md;
 
-                                               switch(mmd->axis)
-                                               {
-                                               case 0:
-                                                       mmd->flag |= MOD_MIR_AXIS_X;
-                                                       break;
-                                               case 1:
-                                                       mmd->flag |= MOD_MIR_AXIS_Y;
-                                                       break;
-                                               case 2:
-                                                       mmd->flag |= MOD_MIR_AXIS_Z;
-                                                       break;
+                                               switch (mmd->axis) {
+                                                       case 0:
+                                                               mmd->flag |= MOD_MIR_AXIS_X;
+                                                               break;
+                                                       case 1:
+                                                               mmd->flag |= MOD_MIR_AXIS_Y;
+                                                               break;
+                                                       case 2:
+                                                               mmd->flag |= MOD_MIR_AXIS_Z;
+                                                               break;
                                                }
 
                                                mmd->axis = 0;
@@ -9945,7 +10055,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
 
                /* Copy over old per-level multires vertex data
-                  into a single vertex array in struct Multires */
+                * into a single vertex array in struct Multires */
                for (me = main->mesh.first; me; me=me->id.next) {
                        if (me->mr && !me->mr->verts) {
                                MultiresLevel *lvl = me->mr->levels.last;
@@ -10052,8 +10162,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
         * */
        {
                Scene *sce;
-               for (sce=main->scene.first; sce; sce = sce->id.next)
-               {
+               for (sce=main->scene.first; sce; sce = sce->id.next) {
                        if (sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[1] ||
                                sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[2] ||
                                sce->toolsettings->skgen_subdivisions[1] == sce->toolsettings->skgen_subdivisions[2])
@@ -10411,7 +10520,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                Sequence *seq;
                
                for (sce=main->scene.first; sce; sce=sce->id.next) {
-                       SEQ_BEGIN(sce->ed, seq) {
+                       SEQ_BEGIN (sce->ed, seq)
+                       {
                                if (seq->blend_mode == 0)
                                        seq->blend_opacity = 100.0f;
                        }
@@ -10469,13 +10579,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
        
        // convert fluids to modifier
-       if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1))
-       {
+       if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
                Object *ob;
                
                for (ob = main->object.first; ob; ob= ob->id.next) {
-                       if (ob->fluidsimSettings)
-                       {
+                       if (ob->fluidsimSettings) {
                                FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifier_new(eModifierType_Fluidsim);
                                BLI_addhead(&ob->modifiers, (ModifierData *)fluidmd);
                                
@@ -10729,7 +10837,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        ob->m_contactProcessingThreshold = 1.0f; //pad3 is used for m_contactProcessingThreshold
                        if (ob->parent) {
                                /* check if top parent has compound shape set and if yes, set this object
-                                  to compound shaper as well (was the behavior before, now it's optional) */
+                                * to compound shaper as well (was the behavior before, now it's optional) */
                                Object *parent= newlibadr(fd, lib, ob->parent);
                                while (parent && parent != ob &&  parent->parent != NULL) {
                                        parent = newlibadr(fd, lib, parent->parent);
@@ -10766,7 +10874,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                while (sce) {
                        ed= sce->ed;
                        if (ed) {
-                               SEQP_BEGIN(ed, seq) {
+                               SEQP_BEGIN (ed, seq)
+                               {
                                        if (seq->strip && seq->strip->proxy) {
                                                seq->strip->proxy->quality =90;
                                        }
@@ -10799,10 +10908,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                bActuator *act;
                int a;
 
-               for (sound = main->sound.first; sound; sound = sound->id.next)
-               {
-                       if (sound->newpackedfile)
-                       {
+               for (sound = main->sound.first; sound; sound = sound->id.next) {
+                       if (sound->newpackedfile) {
                                sound->packedfile = sound->newpackedfile;
                                sound->newpackedfile = NULL;
                        }
@@ -10812,8 +10919,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        for (act= ob->actuators.first; act; act= act->next) {
                                if (act->type == ACT_SOUND) {
                                        bSoundActuator *sAct = (bSoundActuator*) act->data;
-                                       if (sAct->sound)
-                                       {
+                                       if (sAct->sound) {
                                                sound = newlibadr(fd, lib, sAct->sound);
                                                sAct->flag = sound->flags & SOUND_FLAGS_3D ? ACT_SND_3D_SOUND : 0;
                                                sAct->pitch = sound->pitch;
@@ -10836,21 +10942,19 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        }
                }
 
-               for (scene = main->scene.first; scene; scene = scene->id.next)
-               {
-                       if (scene->ed && scene->ed->seqbasep)
-                       {
-                               SEQ_BEGIN(scene->ed, seq) {
-                                       if (seq->type == SEQ_HD_SOUND)
-                                       {
+               for (scene = main->scene.first; scene; scene = scene->id.next) {
+                       if (scene->ed && scene->ed->seqbasep) {
+                               SEQ_BEGIN (scene->ed, seq)
+                               {
+                                       if (seq->type == SEQ_HD_SOUND) {
                                                char str[FILE_MAX];
                                                BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name);
                                                BLI_path_abs(str, main->name);
                                                seq->sound = sound_new_file(main, str);
                                        }
                                        /* don't know, if anybody used that
-                                          this way, but just in case, upgrade
-                                          to new way... */
+                                        * this way, but just in case, upgrade
+                                        * to new way... */
                                        if ((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) &&
                                           !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR))
                                        {
@@ -11218,8 +11322,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                if (tex->vd->extend == 0)
                                        tex->vd->extend = TEX_CLIP;
                
-               for (sce= main->scene.first; sce; sce= sce->id.next)
-               {
+               for (sce= main->scene.first; sce; sce= sce->id.next) {
                        if (sce->audio.main == 0.0f)
                                sce->audio.main = 1.0f;
 
@@ -11232,9 +11335,9 @@ 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
-                               && len_v3(sce->physics_settings.gravity) == 0.0f) {
-
+                       if ((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0 &&
+                           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;
                                sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
@@ -11310,8 +11413,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                int a, tot;
 
                /* shape keys are no longer applied to the mesh itself, but rather
-                  to the derivedmesh/displist, so here we ensure that the basis
-                  shape key is always set in the mesh coordinates. */
+                * to the derivedmesh/displist, so here we ensure that the basis
+                * shape key is always set in the mesh coordinates. */
 
                for (me= main->mesh.first; me; me= me->id.next) {
                        if ((key = newlibadr(fd, lib, me->key)) && key->refkey) {
@@ -11361,8 +11464,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 8))
-       {
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 8)) {
                {
                        Scene *sce= main->scene.first;
                        while (sce) {
@@ -11428,9 +11530,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        int i, 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. */
+                        * 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) {
@@ -11484,8 +11586,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9))
-       {
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9)) {
                Scene *sce;
                Mesh *me;
                Object *ob;
@@ -11511,8 +11612,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 10))
-       {
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 10)) {
                Object *ob;
 
                /* properly initialize hair clothsim data on old files */
@@ -11529,8 +11629,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
 
        /* fix bad area setup in subversion 10 */
-       if (main->versionfile == 250 && main->subversionfile == 10)
-       {
+       if (main->versionfile == 250 && main->subversionfile == 10) {
                /* fix for new view type in sequencer */
                bScreen *screen;
                ScrArea *sa;
@@ -11569,8 +11668,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 11))
-       {
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 11)) {
                {
                        /* fix for new view type in sequencer */
                        bScreen *screen;
@@ -11612,8 +11710,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 12))
-       {
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 12)) {
                Scene *sce;
                Object *ob;
                Brush *brush;
@@ -11715,7 +11812,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        
        if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 13)) {
                /* NOTE: if you do more conversion, be sure to do it outside of this and
-                  increase subversion again, otherwise it will not be correct */
+                * increase subversion again, otherwise it will not be correct */
                Object *ob;
                
                /* convert degrees to radians for internal use */
@@ -11818,7 +11915,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        if ((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0)
                                sce->r.ffcodecdata.audio_codec = 0x0; // CODEC_ID_NONE
 
-                       SEQ_BEGIN(sce->ed, seq) {
+                       SEQ_BEGIN (sce->ed, seq)
+                       {
                                seq->volume = 1.0f;
                        }
                        SEQ_END
@@ -11974,8 +12072,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
        
 
-       if (main->versionfile < 253)
-       {
+       if (main->versionfile < 253) {
                Object *ob;
                Scene *scene;
                bScreen *sc;
@@ -12088,7 +12185,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                for (scene= main->scene.first; scene; scene=scene->id.next) {
                        if (scene) {
                                Sequence *seq;
-                               SEQ_BEGIN(scene->ed, seq) {
+                               SEQ_BEGIN (scene->ed, seq)
+                               {
                                        if (seq->sat==0.0f) {
                                                seq->sat= 1.0f;
                                        }
@@ -12186,8 +12284,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 253 || (main->versionfile == 253 && main->subversionfile < 1))
-               {
+       if (main->versionfile < 253 || (main->versionfile == 253 && main->subversionfile < 1)) {
                        Object *ob;
 
                        for (ob = main->object.first; ob; ob = ob->id.next) {
@@ -12196,8 +12293,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                        if (md->type == eModifierType_Smoke) {
                                                SmokeModifierData *smd = (SmokeModifierData *)md;
 
-                                               if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
-                                               {
+                                               if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
                                                        smd->domain->vorticity = 2.0f;
                                                        smd->domain->time_scale = 1.0f;
 
@@ -12216,8 +12312,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                                                if (md2->type == eModifierType_Smoke) {
                                                                                        SmokeModifierData *smd2 = (SmokeModifierData *)md2;
 
-                                                                                       if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow)
-                                                                                       {
+                                                                                       if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) {
                                                                                                smd2->flow->flags |= MOD_SMOKE_FLOW_INITVELOCITY;
                                                                                        }
                                                                                }
@@ -12303,8 +12398,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        for (act= ob->actuators.first; act; act= act->next) {
                                if (act->type==ACT_STEERING) {
                                        bSteeringActuator* stact = act->data;
-                                       if (stact->facingaxis==0)
-                                       {
+                                       if (stact->facingaxis==0) {
                                                stact->facingaxis=1;
                                        }                                               
                                }
@@ -12564,11 +12658,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        Scene *scene;
                        Sequence *seq;
 
-                       for (scene=main->scene.first; scene; scene=scene->id.next)
-                       {
+                       for (scene=main->scene.first; scene; scene=scene->id.next) {
                                scene->r.ffcodecdata.audio_channels = 2;
                                scene->audio.volume = 1.0f;
-                               SEQ_BEGIN(scene->ed, seq) {
+                               SEQ_BEGIN (scene->ed, seq)
+                               {
                                        seq->pitch = 1.0f;
                                }
                                SEQ_END
@@ -12739,8 +12833,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                {
                        /* set defaults for obstacle avoidance, recast data */
                        Scene *sce;
-                       for (sce = main->scene.first; sce; sce = sce->id.next)
-                       {
+                       for (sce = main->scene.first; sce; sce = sce->id.next) {
                                if (sce->gm.levelHeight == 0.f)
                                        sce->gm.levelHeight = 2.f;
 
@@ -12782,7 +12875,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        
                        for (sce=main->scene.first; sce; sce=sce->id.next) {
                                /* there are files with invalid audio_channels value, the real cause
-                                  is unknown, but we fix it here anyway to avoid crashes */
+                                * is unknown, but we fix it here anyway to avoid crashes */
                                if (sce->r.ffcodecdata.audio_channels == 0)
                                        sce->r.ffcodecdata.audio_channels = 2;
 
@@ -12872,15 +12965,15 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                                v3d->bundle_size= 0.2f;
                                                                v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
                                                        }
-                                                       else if (sl->spacetype==SPACE_CLIP) {
-                                                               SpaceClip *sc= (SpaceClip *)sl;
-                                                               if (sc->scopes.track_preview_height==0)
-                                                                       sc->scopes.track_preview_height= 120;
-                                                       }
 
                                                        if (v3d->bundle_drawtype==0)
                                                                v3d->bundle_drawtype= OB_PLAINAXES;
                                                }
+                                               else if (sl->spacetype==SPACE_CLIP) {
+                                                       SpaceClip *sc= (SpaceClip *)sl;
+                                                       if (sc->scopes.track_preview_height==0)
+                                                               sc->scopes.track_preview_height= 120;
+                                               }
                                        }
                                }
                        }
@@ -12920,8 +13013,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 6))
-       {
+       if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 6)) {
                Scene *sce;
                MovieClip *clip;
                bScreen *sc;
@@ -12985,8 +13077,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 8))
-       {
+       if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 8)) {
                Brush *brush;
 
                for (brush= main->brush.first; brush; brush= brush->id.next) {
@@ -12995,8 +13086,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 1))
-       {
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 1)) {
                {
                        /* update use flags for node sockets (was only temporary before) */
                        Scene *sce;
@@ -13097,8 +13187,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 2))
-       {
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 2)) {
                {
                        /* convert Camera Actuator values to defines */
                        Object *ob;
@@ -13119,7 +13208,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
                {
                        /* convert deprecated sculpt_paint_unified_* fields to
-                          UnifiedPaintSettings */
+                        * UnifiedPaintSettings */
                        Scene *scene;
                        for (scene= main->scene.first; scene; scene= scene->id.next) {
                                ToolSettings *ts= scene->toolsettings;
@@ -13132,8 +13221,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 3))
-       {
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 3)) {
                {
                        /* convert extended ascii to utf-8 for text editor */
                        Text *text;
@@ -13159,8 +13247,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                for (md= ob->modifiers.first; md; md= md->next) {
                                        if (md->type == eModifierType_DynamicPaint) {
                                                DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
-                                               if (pmd->canvas)
-                                               {
+                                               if (pmd->canvas) {
                                                        DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
                                                        for (; surface; surface=surface->next) {
                                                                surface->color_dry_threshold = 1.0f;
@@ -13175,8 +13262,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        
-       if (main->versionfile < 262)
-       {
+       if (main->versionfile < 262) {
                Object *ob;
                for (ob=main->object.first; ob; ob= ob->id.next) {
                        ModifierData *md;
@@ -13191,10 +13277,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 263)
-       {
+       if (main->versionfile < 263) {
                /* set fluidsim rate. the version patch for this in 2.62 was wrong, so
-                  try to correct it, if rate is 0.0 that's likely not intentional */
+                * try to correct it, if rate is 0.0 that's likely not intentional */
                Object *ob;
 
                for (ob = main->object.first; ob; ob = ob->id.next) {
@@ -13209,8 +13294,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 1))
-       {
+       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 1)) {
                /* update use flags for node sockets (was only temporary before) */
                Scene *sce;
                bNodeTree *ntree;
@@ -13225,8 +13309,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
 
        /* only swap for pre-release bmesh merge which had MLoopCol red/blue swap */
-       if (main->versionfile == 262 && main->subversionfile == 1)
-       {
+       if (main->versionfile == 262 && main->subversionfile == 1) {
                {
                        Mesh *me;
                        for (me = main->mesh.first; me; me = me->id.next) {
@@ -13236,8 +13319,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
        }
 
-       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 2))
-       {
+       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 2)) {
                {
                        /* Set new idname of keyingsets from their now "label-only" name. */
                        Scene *scene;
@@ -13251,14 +13333,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        
-       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 3))
-       {
+       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 3)) {
                Object *ob;
                ModifierData *md;
        
-               for(ob = main->object.first; ob; ob = ob->id.next) {
-                       for(md=ob->modifiers.first; md; md=md->next) {
-                               if(md->type == eModifierType_Lattice) {
+               for (ob = main->object.first; ob; ob = ob->id.next) {
+                       for (md=ob->modifiers.first; md; md=md->next) {
+                               if (md->type == eModifierType_Lattice) {
                                        LatticeModifierData *lmd = (LatticeModifierData *)md;
                                        lmd->strength = 1.0f;
                                }
@@ -13266,8 +13347,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 4))
-       {
+       if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 4)) {
                /* Read Viscosity presets from older files */
                Object *ob;
 
@@ -13276,11 +13356,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        for (md = ob->modifiers.first; md; md = md->next) {
                                if (md->type == eModifierType_Fluidsim) {
                                        FluidsimModifierData *fmd = (FluidsimModifierData *)md;
-                                       if(fmd->fss->viscosityMode == 3) {
+                                       if (fmd->fss->viscosityMode == 3) {
                                                fmd->fss->viscosityValue = 5.0;
                                                fmd->fss->viscosityExponent = 5;
                                        }
-                                       else if(fmd->fss->viscosityMode == 4) {
+                                       else if (fmd->fss->viscosityMode == 4) {
                                                fmd->fss->viscosityValue = 2.0;
                                                fmd->fss->viscosityExponent = 3;
                                        }
@@ -13291,18 +13371,77 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
 
 
-       {
+       if (main->versionfile < 263) {
                /* Default for old files is to save particle rotations to pointcache */
                ParticleSettings *part;
                for (part = main->particle.first; part; part = part->id.next)
                        part->flag |= PART_ROTATIONS;
        }
 
-       /* put compatibility code here until next subversion bump */
-       {
+       if (main->versionfile <= 263 && main->subversionfile == 0) {
+               Scene *scene;
+               Brush *brush;
 
+               /* For weight paint, each brush now gets its own weight;
+                  unified paint settings also have weight. Update unified
+                  paint settings and brushes with a default weight value. */
+               
+               for (scene = main->scene.first; scene; scene = scene->id.next) {
+                       ToolSettings *ts = scene->toolsettings;
+                       if (ts) {
+                               ts->unified_paint_settings.weight = ts->vgroup_weight;
+                               ts->unified_paint_settings.flag |= UNIFIED_PAINT_WEIGHT;
+                       }
+               }
+
+               for (brush = main->brush.first; brush; brush = brush->id.next) {
+                       brush->weight = 0.5;
+               }
        }
 
+       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 2)) {
+               bScreen *sc;
+
+               for (sc = main->screen.first; sc; sc = sc->id.next) {
+                       ScrArea *sa;
+                       for (sa = sc->areabase.first; sa; sa = sa->next) {
+                               SpaceLink *sl;
+
+                               for (sl = sa->spacedata.first; sl; sl = sl->next) {
+                                       if (sl->spacetype == SPACE_CLIP) {
+                                               SpaceClip *sclip = (SpaceClip *)sl;
+                                               ARegion *ar;
+                                               int hide = FALSE;
+
+                                               for (ar = sa->regionbase.first; ar; ar = ar->next) {
+                                                       if (ar->regiontype == RGN_TYPE_PREVIEW) {
+                                                               if (ar->alignment != RGN_ALIGN_NONE) {
+                                                                       ar->flag |= RGN_FLAG_HIDDEN;
+                                                                       ar->v2d.flag &= ~V2D_IS_INITIALISED;
+                                                                       ar->alignment = RGN_ALIGN_NONE;
+
+                                                                       hide = TRUE;
+                                                               }
+                                                       }
+                                               }
+
+                                               if (hide) {
+                                                       sclip->view = SC_VIEW_CLIP;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       {
+               Lamp *la;
+               for (la= main->lamp.first; la; la= la->id.next) {
+                       if (la->shadow_frustum_size == 0.0)
+                               la->shadow_frustum_size= 10.0f;
+               }
+       }
+       
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 
@@ -13348,6 +13487,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_brush(fd, main);
        lib_link_particlesettings(fd, main);
        lib_link_movieclip(fd, main);
+       lib_link_mask(fd, main);
 
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
 
@@ -13434,7 +13574,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
        BLI_strncpy(bfd->main->name, filepath, sizeof(bfd->main->name));
 
        while (bhead) {
-               switch(bhead->code) {
+               switch (bhead->code) {
                case DATA:
                case DNA1:
                case TEST: /* used as preview since 2.5x */
@@ -13453,10 +13593,10 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
 
                case ID_LI:
                        /* skip library datablocks in undo, this works together with
-                          BLO_read_from_memfile, where the old main->library is restored
-                          overwriting  the libraries from the memory file. previously
-                          it did not save ID_LI/ID_ID blocks in this case, but they are
-                          needed to make quit.blend recover them correctly. */
+                        * BLO_read_from_memfile, where the old main->library is restored
+                        * overwriting  the libraries from the memory file. previously
+                        * it did not save ID_LI/ID_ID blocks in this case, but they are
+                        * needed to make quit.blend recover them correctly. */
                        if (fd->memfile)
                                bhead= blo_nextbhead(fd, bhead);
                        else
@@ -13626,7 +13766,7 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
                                        /* This crashes files, must look further into it */
                                        
                                        /* Update: the issue is that in file reading, the oldnewmap is OK, but for existing data, it has to be
-                                          inserted in the map to be found! */
+                                        * inserted in the map to be found! */
                                        if (id->flag & LIB_PRE_EXISTING)
                                                oldnewmap_insert(fd->libmap, bhead->old, id, 1);
                                        
@@ -13645,7 +13785,7 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
                        }
                        else {
                                /* this is actually only needed on UI call? when ID was already read before, and another append
-                                  happens which invokes same ID... in that case the lookup table needs this entry */
+                                * happens which invokes same ID... in that case the lookup table needs this entry */
                                oldnewmap_insert(fd->libmap, bhead->old, id, 1);
                                // commented because this can print way too much
                                // if (G.debug & G_DEBUG) printf("expand: already read %s\n", id->name);
@@ -14262,7 +14402,8 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
        if (sce->ed) {
                Sequence *seq;
 
-               SEQ_BEGIN(sce->ed, seq) {
+               SEQ_BEGIN (sce->ed, seq)
+               {
                        if (seq->scene) expand_doit(fd, mainvar, seq->scene);
                        if (seq->scene_camera) expand_doit(fd, mainvar, seq->scene_camera);
                        if (seq->sound) expand_doit(fd, mainvar, seq->sound);
@@ -14330,7 +14471,7 @@ static void expand_main(FileData *fd, Main *mainvar)
                        while (id) {
                                if (id->flag & LIB_TEST) {
 
-                                       switch(GS(id->name)) {
+                                       switch (GS(id->name)) {
 
                                        case ID_OB:
                                                expand_object(fd, mainvar, (Object *)id);
@@ -14360,7 +14501,7 @@ static void expand_main(FileData *fd, Main *mainvar)
                                                expand_lattice(fd, mainvar, (Lattice *)id);
                                                break;
                                        case ID_LA:
-                                               expand_lamp(fd, mainvar,(Lamp *)id);
+                                               expand_lamp(fd, mainvar, (Lamp *)id);
                                                break;
                                        case ID_KE:
                                                expand_key(fd, mainvar, (Key *)id);
@@ -14369,7 +14510,7 @@ static void expand_main(FileData *fd, Main *mainvar)
                                                expand_camera(fd, mainvar, (Camera *)id);
                                                break;
                                        case ID_SPK:
-                                               expand_speaker(fd, mainvar,(Speaker *)id);
+                                               expand_speaker(fd, mainvar, (Speaker *)id);
                                                break;
                                        case ID_SO:
                                                expand_sound(fd, mainvar, (bSound *)id);
@@ -14431,11 +14572,11 @@ static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, const
                
                if ( ob->id.flag & LIB_INDIRECT ) {
                        
-                               /* IF below is quite confusing!
-                               if we are appending, but this object wasnt just added along with a group,
-                               then this is already used indirectly in the scene somewhere else and we didnt just append it.
-                               
-                               (ob->id.flag & LIB_PRE_EXISTING)==0 means that this is a newly appended object - Campbell */
+                       /* IF below is quite confusing!
+                        * if we are appending, but this object wasnt just added along with a group,
+                        * then this is already used indirectly in the scene somewhere else and we didnt just append it.
+                        *
+                        * (ob->id.flag & LIB_PRE_EXISTING)==0 means that this is a newly appended object - Campbell */
                        if (is_group_append==0 || (ob->id.flag & LIB_PRE_EXISTING)==0) {
                                
                                int do_it= 0;
@@ -14467,7 +14608,7 @@ static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, const
                                }
 
                                if (do_it) {
-                                       base= MEM_callocN( sizeof(Base), "add_ext_base");
+                                       base= MEM_callocN(sizeof(Base), "add_ext_base");
                                        BLI_addtail(&(sce->base), base);
                                        base->lay= ob->lay;
                                        base->object= ob;
@@ -14513,7 +14654,7 @@ static void give_base_to_groups(Main *mainvar, Scene *scene)
 }
 
 /* returns true if the item was found
-* but it may already have already been appended/linked */
+ * but it may already have already been appended/linked */
 static ID *append_named_part(Main *mainl, FileData *fd, const char *idname, const short idcode)
 {
        BHead *bhead;
@@ -14571,7 +14712,7 @@ static ID *append_named_part_ex(const bContext *C, Main *mainl, FileData *fd, co
                        Base *base;
                        Object *ob;
 
-                       base= MEM_callocN( sizeof(Base), "app_nam_part");
+                       base= MEM_callocN(sizeof(Base), "app_nam_part");
                        BLI_addtail(&scene->base, base);
 
                        ob= (Object *)id;
@@ -14716,7 +14857,7 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in
        
        /* patch to prevent switch_endian happens twice */
        if ((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) {
-               blo_freefiledata( *fd );
+               blo_freefiledata(*fd);
                *fd = NULL;
        }       
 }