Merging r46111 through r46136 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index 3276816..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"
 
@@ -1476,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) {
@@ -1491,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) {
@@ -4841,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) {
@@ -4972,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);
@@ -5387,8 +5391,10 @@ 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;
                                                sclip->scopes.ok = 0;
                                        }
                                }
@@ -5653,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;
                                }
@@ -6166,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;
@@ -6201,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)
@@ -6221,6 +6244,90 @@ 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 ******************** */
 
 
@@ -6427,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*/
@@ -8994,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;
                                }
@@ -10409,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;
                        }
@@ -10762,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;
                                        }
@@ -10831,7 +10944,8 @@ 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) {
+                               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);
@@ -11801,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
@@ -12070,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;
                                        }
@@ -12545,7 +12661,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        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
@@ -12848,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;
+                                               }
                                        }
                                }
                        }
@@ -13261,6 +13378,70 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        part->flag |= PART_ROTATIONS;
        }
 
+       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! */
 
@@ -13306,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 */
 
@@ -14220,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);
@@ -14425,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;
@@ -14529,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;
@@ -14674,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;
        }       
 }