merge with trunk at r31523
[blender.git] / source / blender / blenloader / intern / readfile.c
index 96bb83df11b812f51b4dad6aba14a0a7a867e00b..44cc6b5c1d921f3ca5f0b1fdc115e79b27308c58 100644 (file)
 #endif
 
 #include "DNA_anim_types.h"
-#include "DNA_action_types.h"
 #include "DNA_armature_types.h"
-#include "DNA_ID.h"
 #include "DNA_actuator_types.h"
-#include "DNA_boid_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_cloth_types.h"
-#include "DNA_color_types.h"
 #include "DNA_controller_types.h"
 #include "DNA_constraint_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_customdata_types.h"
 #include "DNA_effect_types.h"
 #include "DNA_fileglobal_types.h"
 #include "DNA_genfile.h"
 #include "DNA_group_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_ipo_types.h"
-#include "DNA_image_types.h"
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
-#include "DNA_modifier_types.h"
 #include "DNA_nla_types.h"
 #include "DNA_node_types.h"
-#include "DNA_object_types.h"
-#include "DNA_object_force.h"
 #include "DNA_object_fluidsim.h" // NT
-#include "DNA_outliner_types.h"
-#include "DNA_object_force.h"
 #include "DNA_packedFile_types.h"
-#include "DNA_particle_types.h"
 #include "DNA_property_types.h"
 #include "DNA_text_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_smoke_types.h"
 #include "DNA_sound_types.h"
 #include "DNA_space_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_userdef_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_world_types.h"
-#include "DNA_windowmanager_types.h"
 
 #include "MEM_guardedalloc.h"
+
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_cellalloc.h"
 #include "BKE_image.h"
 #include "BKE_lattice.h"
 #include "BKE_library.h" // for which_libbase
+#include "BKE_idcode.h"
 #include "BKE_main.h" // for Main
 #include "BKE_mesh.h" // for ME_ defines (patching)
 #include "BKE_modifier.h"
 #include "BKE_sequencer.h"
 #include "BKE_texture.h" // for open_plugin_tex
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
-#include "BKE_ipo.h"
 #include "BKE_sound.h"
 
 //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
 #include <errno.h>
 
 /*
- Remark: still a weak point is the newadress() function, that doesnt solve reading from
+ Remark: still a weak point is the newaddress() function, that doesnt solve reading from
  multiple files at the same time
 
  (added remark: oh, i thought that was solved? will look at that... (ton)
@@ -176,7 +161,7 @@ READ
                - read associated 'direct data'
                - link direct data (internal and to LibBlock)
 - read FileGlobal
-- read USER data, only when indicated (file is ~/.B.blend or .B25.blend)
+- read USER data, only when indicated (file is ~/X.XX/startup.blend)
 - free file
 - per Library (per Main)
        - read file
@@ -1541,7 +1526,6 @@ static void lib_link_brush(FileData *fd, Main *main)
                        brush->id.flag -= LIB_NEEDLINK;
 
                        brush->mtex.tex= newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
-                       brush->image_icon= newlibadr_us(fd, brush->id.lib, brush->image_icon);
                        brush->clone.image= newlibadr_us(fd, brush->id.lib, brush->clone.image);
                }
        }
@@ -1557,6 +1541,9 @@ static void direct_link_brush(FileData *fd, Brush *brush)
                direct_link_curvemapping(fd, brush->curve);
        else
                brush_curve_preset(brush, CURVE_PRESET_SHARP);
+
+       brush->preview= NULL;
+       brush->icon_imbuf= NULL;
 }
 
 static void direct_link_script(FileData *fd, Script *script)
@@ -3468,6 +3455,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
        mesh->mloopuv= newdataadr(fd, mesh->mloopuv);
        mesh->mtpoly= newdataadr(fd, mesh->mtpoly);
 
+       /* animdata */
        mesh->adt= newdataadr(fd, mesh->adt);
        direct_link_animdata(fd, mesh->adt);
 
@@ -4299,10 +4287,9 @@ static void composite_patch(bNodeTree *ntree, Scene *scene)
 
 static void link_paint(FileData *fd, Scene *sce, Paint *p)
 {
-       if(p && p->brushes) {
-               int i;
-               for(i = 0; i < p->brush_count; ++i)
-                       p->brushes[i]= newlibadr_us(fd, sce->id.lib, p->brushes[i]);
+       if(p) {
+               p->brush= newlibadr_us(fd, sce->id.lib, p->brush);
+               p->paint_cursor= NULL;
        }
 }
 
@@ -4418,13 +4405,8 @@ static void link_recurs_seq(FileData *fd, ListBase *lb)
 static void direct_link_paint(FileData *fd, Paint **paint)
 {
        Paint *p;
-
+/* TODO. is this needed */
        p= (*paint)= newdataadr(fd, (*paint));
-       if(p) {
-               p->paint_cursor= NULL;
-               p->brushes= newdataadr(fd, p->brushes);
-               test_pointer_array(fd, (void**)&p->brushes);
-       }
 }
 
 static void direct_link_scene(FileData *fd, Scene *sce)
@@ -4460,9 +4442,6 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                direct_link_paint(fd, (Paint**)&sce->toolsettings->vpaint);
                direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
 
-               sce->toolsettings->imapaint.paint.brushes= newdataadr(fd, sce->toolsettings->imapaint.paint.brushes);
-               test_pointer_array(fd, (void**)&sce->toolsettings->imapaint.paint.brushes);
-
                sce->toolsettings->imapaint.paintcursor= NULL;
                sce->toolsettings->particle.paintcursor= NULL;
        }
@@ -4498,11 +4477,6 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                        seq->strip= newdataadr(fd, seq->strip);
                        if(seq->strip && seq->strip->done==0) {
                                seq->strip->done= 1;
-                               seq->strip->tstripdata = 0;
-                               seq->strip->tstripdata_startstill = 0;
-                               seq->strip->tstripdata_endstill = 0;
-                               seq->strip->ibuf_startstill = 0;
-                               seq->strip->ibuf_endstill = 0;
 
                                if(seq->type == SEQ_IMAGE ||
                                   seq->type == SEQ_MOVIE ||
@@ -9465,7 +9439,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                idproperties_fix_group_lengths(main->mat);
                idproperties_fix_group_lengths(main->tex);
                idproperties_fix_group_lengths(main->image);
-               idproperties_fix_group_lengths(main->wave);
                idproperties_fix_group_lengths(main->latt);
                idproperties_fix_group_lengths(main->lamp);
                idproperties_fix_group_lengths(main->camera);
@@ -11030,12 +11003,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
        
 
-       /* put 2.50 compatibility code here until next subversion bump */
+       if (main->versionfile < 253)
        {
                Object *ob;
                Scene *scene;
                bScreen *sc;
                Tex *tex;
+               Brush *brush;
 
                for (sc= main->screen.first; sc; sc= sc->id.next) {
                        ScrArea *sa;
@@ -11144,17 +11118,16 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        if(scene) {
                                Sequence *seq;
                                SEQ_BEGIN(scene->ed, seq) {
-                                       seq->sat= 1.0f;
+                                       if(seq->sat==0.0f) {
+                                               seq->sat= 1.0f;
+                                       }
                                }
                                SEQ_END
                        }
                }
-       }
 
-       {
                /* GSOC 2010 Sculpt - New settings for Brush */
 
-               Brush *brush;
                for (brush= main->brush.first; brush; brush= brush->id.next) {
                        /* Sanity Check */
 
@@ -11227,6 +11200,81 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
+       /* GSOC Sculpt 2010 - Sanity check on Sculpt/Paint settings */
+       if (main->versionfile < 253) {
+               Scene *sce;
+               for (sce= main->scene.first; sce; sce= sce->id.next) {
+                       if (sce->toolsettings->sculpt_paint_unified_alpha == 0)
+                               sce->toolsettings->sculpt_paint_unified_alpha = 0.5f;
+
+                       if (sce->toolsettings->sculpt_paint_unified_unprojected_radius == 0) 
+                               sce->toolsettings->sculpt_paint_unified_unprojected_radius = 0.125f;
+
+                       if (sce->toolsettings->sculpt_paint_unified_size == 0)
+                               sce->toolsettings->sculpt_paint_unified_size = 35;
+               }
+       }
+
+       if (main->versionfile < 253 || (main->versionfile == 253 && main->subversionfile < 1))
+               {
+                       Object *ob;
+
+                       for(ob = main->object.first; ob; ob = ob->id.next) {
+                               ModifierData *md;
+                               for(md= ob->modifiers.first; md; md= md->next) {
+                                       if (md->type == eModifierType_Smoke) {
+                                               SmokeModifierData *smd = (SmokeModifierData *)md;
+
+                                               if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
+                                               {
+                                                       smd->domain->vorticity = 2.0f;
+                                                       smd->domain->time_scale = 1.0f;
+
+                                                       if(!(smd->domain->flags & (1<<4)))
+                                                               continue;
+
+                                                       /* delete old MOD_SMOKE_INITVELOCITY flag */
+                                                       smd->domain->flags &= ~(1<<4);
+
+                                                       /* for now just add it to all flow objects in the scene */
+                                                       {
+                                                               Object *ob2;
+                                                               for(ob2 = main->object.first; ob2; ob2 = ob2->id.next) {
+                                                                       ModifierData *md2;
+                                                                       for(md2= ob2->modifiers.first; md2; md2= md2->next) {
+                                                                               if (md2->type == eModifierType_Smoke) {
+                                                                                       SmokeModifierData *smd2 = (SmokeModifierData *)md2;
+
+                                                                                       if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow)
+                                                                                       {
+                                                                                               smd2->flow->flags |= MOD_SMOKE_FLOW_INITVELOCITY;
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+
+                                               }
+                                               else if((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow)
+                                               {
+                                                       smd->flow->vel_multi = 1.0f;
+                                               }
+
+                                       }
+                               }
+                       }
+               }
+
+       /* put compatibility code here until next subversion bump */
+       {
+               Brush *br;
+               for(br= main->brush.first; br; br= br->id.next) {
+                       if(br->ob_mode==0)
+                               br->ob_mode= (OB_MODE_SCULPT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT);
+               }
+               
+       }
+
        /* 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! */
 
@@ -11517,7 +11565,7 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
                                else {
                                        /* The line below was commented by Ton (I assume), when Hos did the merge from the orange branch. rev 6568
                                         * This line is NEEDED, the case is that you have 3 blend files...
-                                        * user.blend, lib.blend and lib_indirect.blend - if user.blend alredy references a "tree" from
+                                        * user.blend, lib.blend and lib_indirect.blend - if user.blend already references a "tree" from
                                         * lib_indirect.blend but lib.blend does too, linking in a Scene or Group from lib.blend can result in an
                                         * empty without the dupli group referenced. Once you save and reload the group would appier. - Campbell */
                                        /* This crashes files, must look further into it */
@@ -11839,6 +11887,9 @@ static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me)
        TFace *tf;
        int a, i;
        
+       if(me->adt)
+               expand_animdata(fd, mainvar, me->adt);
+               
        for(a=0; a<me->totcol; a++) {
                expand_doit(fd, mainvar, me->mat[a]);
        }
@@ -12301,7 +12352,7 @@ static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, int is
                        
                                /* IF below is quite confusing!
                                if we are appending, but this object wasnt just added allong with a group,
-                               then this is alredy used indirectly in the scene somewhere else and we didnt just append it.
+                               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) {
@@ -12510,9 +12561,7 @@ static void append_do_cursor(Scene *scene, Library *curlib, short flag)
                return;
        
        /* move from the center of the appended objects to cursor */
-       centerloc[0]= (min[0]+max[0])/2;
-       centerloc[1]= (min[1]+max[1])/2;
-       centerloc[2]= (min[2]+max[2])/2;
+       mid_v3_v3v3(centerloc, min, max);
        curs = scene->cursor;
        VECSUB(centerloc,curs,centerloc);
        
@@ -12615,7 +12664,7 @@ void BLO_script_library_append(BlendHandle **bh, char *dir, char *name,
 
        /* do we need to do this? */
        if(scene)
-               DAG_scene_sort(scene);
+               DAG_scene_sort(bmain, scene);
 
        *bh= (BlendHandle*)fd;
 }
@@ -12725,8 +12774,8 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
 
                                                                append_id_part(fd, mainptr, id, &realid);
                                                                if (!realid) {
-                                                                       BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-                                                                       if(!G.background && basefd->reports) printf("LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+                                                                       BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+                                                                       if(!G.background && basefd->reports) printf("LIB ERROR: %s:'%s' missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
                                                                }
                                                                
                                                                change_idid_adr(mainlist, basefd, id, realid);
@@ -12761,8 +12810,8 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                ID *idn= id->next;
                                if(id->flag & LIB_READ) {
                                        BLI_remlink(lbarray[a], id);
-                                       BKE_reportf(basefd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-                                       if(!G.background && basefd->reports)printf("LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+                                       BKE_reportf(basefd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+                                       if(!G.background && basefd->reports)printf("LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
                                        change_idid_adr(mainlist, basefd, id, NULL);
 
                                        MEM_freeN(id);