diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 296 |
1 files changed, 220 insertions, 76 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c399ca13437..c918a82f36a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -39,6 +39,7 @@ #include "BLI_winstuff.h" #endif +#include <limits.h> #include <stdio.h> // for printf fopen fwrite fclose sprintf FILE #include <stdlib.h> // for getenv atoi #include <fcntl.h> // for open @@ -136,10 +137,11 @@ #include "BKE_object.h" #include "BKE_particle.h" #include "BKE_pointcache.h" -#include "BKE_property.h" // for get_property +#include "BKE_property.h" // for get_ob_property #include "BKE_sca.h" // for init_actuator #include "BKE_scene.h" #include "BKE_softbody.h" // sbNew() +#include "BKE_bullet.h" // bsbNew() #include "BKE_sculpt.h" #include "BKE_texture.h" // for open_plugin_tex #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND @@ -970,9 +972,11 @@ FileData *blo_openblenderfile(char *name, BlendReadError *error_r) } else { FileData *fd = filedata_new(); fd->gzfiledes = gzfile; - BLI_strncpy(fd->filename, name, sizeof(fd->filename)); // now only in use by library append fd->read = fd_read_gzip_from_file; + /* needed for library_append and read_libraries */ + BLI_strncpy(fd->filename, name, sizeof(fd->filename)); + return blo_decode_and_check(fd, error_r); } } @@ -1138,6 +1142,8 @@ void blo_make_image_pointer_map(FileData *fd) Link *ibuf= ima->ibufs.first; for(; ibuf; ibuf= ibuf->next) oldnewmap_insert(fd->imamap, ibuf, ibuf, 0); + if(ima->gputexture) + oldnewmap_insert(fd->imamap, ima->gputexture, ima->gputexture, 0); } for(; sce; sce= sce->id.next) { if(sce->nodetree) { @@ -1172,8 +1178,11 @@ void blo_end_image_pointer_map(FileData *fd) if(NULL==newimaadr(fd, ibuf)) { /* so was restored */ BLI_remlink(&ima->ibufs, ibuf); ima->bindcode= 0; + ima->gputexture= NULL; } } + + ima->gputexture= newimaadr(fd, ima->gputexture); } for(; sce; sce= sce->id.next) { if(sce->nodetree) { @@ -1338,7 +1347,7 @@ static void test_pointer_array(FileData *fd, void **mat) void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, void *fd); void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, void *fd); -void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, void *fd) +static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, void *fd) { int i; @@ -1359,14 +1368,14 @@ void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, void *fd) } } -void IDP_DirectLinkString(IDProperty *prop, int switch_endian, void *fd) +static void IDP_DirectLinkString(IDProperty *prop, int switch_endian, void *fd) { /*since we didn't save the extra string buffer, set totallen to len.*/ prop->totallen = prop->len; prop->data.pointer = newdataadr(fd, prop->data.pointer); } -void IDP_DirectLinkGroup(IDProperty *prop, int switch_endian, void *fd) +static void IDP_DirectLinkGroup(IDProperty *prop, int switch_endian, void *fd) { ListBase *lb = &prop->data.group; IDProperty *loop; @@ -2273,6 +2282,7 @@ static void direct_link_text(FileData *fd, Text *text) */ link_list(fd, &text->lines); + link_list(fd, &text->markers); text->curl= newdataadr(fd, text->curl); text->sell= newdataadr(fd, text->sell); @@ -2339,8 +2349,10 @@ static void direct_link_image(FileData *fd, Image *ima) ima->ibufs.first= ima->ibufs.last= NULL; /* if not restored, we keep the binded opengl index */ - if(ima->ibufs.first==NULL) + if(ima->ibufs.first==NULL) { ima->bindcode= 0; + ima->gputexture= NULL; + } ima->anim= NULL; ima->rr= NULL; @@ -2551,6 +2563,7 @@ static void direct_link_material(FileData *fd, Material *ma) direct_link_nodetree(fd, ma->nodetree); ma->preview = direct_link_preview_image(fd, ma->preview); + ma->gpumaterial.first = ma->gpumaterial.last = NULL; } /* ************ READ PARTICLE SETTINGS ***************** */ @@ -2582,21 +2595,36 @@ static void lib_link_particlesettings(FileData *fd, Main *main) static void direct_link_particlesettings(FileData *fd, ParticleSettings *part) { part->pd= newdataadr(fd, part->pd); + part->pd2= newdataadr(fd, part->pd2); } -static void lib_link_particlesystems(FileData *fd, ID *id, ListBase *particles) +static void lib_link_particlesystems(FileData *fd, Object *ob, ID *id, ListBase *particles) { - ParticleSystem *psys; + ParticleSystem *psys, *psysnext; int a; - for(psys=particles->first; psys; psys=psys->next){ + for(psys=particles->first; psys; psys=psysnext){ ParticleData *pa; + + psysnext= psys->next; + psys->part = newlibadr_us(fd, id->lib, psys->part); - psys->target_ob = newlibadr(fd, id->lib, psys->target_ob); - psys->keyed_ob = newlibadr(fd, id->lib, psys->keyed_ob); + if(psys->part) { + psys->target_ob = newlibadr(fd, id->lib, psys->target_ob); + psys->keyed_ob = newlibadr(fd, id->lib, psys->keyed_ob); - for(a=0,pa=psys->particles; a<psys->totpart; a++,pa++){ - pa->stick_ob=newlibadr(fd, id->lib, pa->stick_ob); + for(a=0,pa=psys->particles; a<psys->totpart; a++,pa++){ + pa->stick_ob=newlibadr(fd, id->lib, pa->stick_ob); + } + } + else { + /* particle modifier must be removed before particle system */ + ParticleSystemModifierData *psmd= psys_get_modifier(ob,psys); + BLI_remlink(&ob->modifiers, psmd); + modifier_free((ModifierData *)psmd); + + BLI_remlink(particles, psys); + MEM_freeN(psys); } } } @@ -2942,11 +2970,9 @@ static void lib_link_object(FileData *fd, Main *main) sens= ob->sensors.first; while(sens) { - if(ob->id.lib==NULL) { // done in expand_main - for(a=0; a<sens->totlinks; a++) { - sens->links[a]= newglobadr(fd, sens->links[a]); - } - } + for(a=0; a<sens->totlinks; a++) + sens->links[a]= newglobadr(fd, sens->links[a]); + if(sens->type==SENS_TOUCH) { bTouchSensor *ts= sens->data; ts->ma= newlibadr(fd, ob->id.lib, ts->ma); @@ -2961,11 +2987,9 @@ static void lib_link_object(FileData *fd, Main *main) cont= ob->controllers.first; while(cont) { - if(ob->id.lib==NULL) { // done in expand_main - for(a=0; a<cont->totlinks; a++) { - cont->links[a]= newglobadr(fd, cont->links[a]); - } - } + for(a=0; a<cont->totlinks; a++) + cont->links[a]= newglobadr(fd, cont->links[a]); + if(cont->type==CONT_PYTHON) { bPythonCont *pc= cont->data; pc->text= newlibadr(fd, ob->id.lib, pc->text); @@ -3041,9 +3065,12 @@ static void lib_link_object(FileData *fd, Main *main) } act= act->next; } - - if(ob->fluidsimSettings) { - ob->fluidsimSettings->ipo = newlibadr_us(fd, ob->id.lib, ob->fluidsimSettings->ipo); + + { + FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim); + + if(fluidmd && fluidmd->fss) + fluidmd->fss->ipo = newlibadr_us(fd, ob->id.lib, fluidmd->fss->ipo); } /* texture field */ @@ -3052,7 +3079,7 @@ static void lib_link_object(FileData *fd, Main *main) ob->pd->tex=newlibadr_us(fd, ob->id.lib, ob->pd->tex); lib_link_scriptlink(fd, &ob->id, &ob->scriptlink); - lib_link_particlesystems(fd, &ob->id, &ob->particlesystem); + lib_link_particlesystems(fd, ob, &ob->id, &ob->particlesystem); lib_link_modifiers(fd, ob); } ob= ob->id.next; @@ -3118,6 +3145,11 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) } } + else if (md->type==eModifierType_Fluidsim) { + FluidsimModifierData *fluidmd = (FluidsimModifierData*) md; + + fluidmd->fss= newdataadr(fd, fluidmd->fss); + } else if (md->type==eModifierType_Collision) { CollisionModifierData *collmd = (CollisionModifierData*) md; @@ -3303,14 +3335,8 @@ static void direct_link_object(FileData *fd, Object *ob) if(sb->pointcache) direct_link_pointcache(fd, sb->pointcache); } + ob->bsoft= newdataadr(fd, ob->bsoft); ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */ - if(ob->fluidsimSettings) { - // reinit mesh pointers - ob->fluidsimSettings->orgMesh = NULL; //ob->data; - ob->fluidsimSettings->meshSurface = NULL; - ob->fluidsimSettings->meshBB = NULL; - ob->fluidsimSettings->meshSurfNormals = NULL; - } link_list(fd, &ob->particlesystem); direct_link_particlesystems(fd,&ob->particlesystem); @@ -3392,6 +3418,7 @@ static void direct_link_object(FileData *fd, Object *ob) ob->bb= NULL; ob->derivedDeform= NULL; ob->derivedFinal= NULL; + ob->gpulamp.first= ob->gpulamp.last= NULL; } /* ************ READ SCENE ***************** */ @@ -3593,9 +3620,9 @@ static void direct_link_scene(FileData *fd, Scene *sce) { Sequence temp; char *poin; - long offset; + intptr_t offset; - offset= ((long)&(temp.seqbase)) - ((long)&temp); + offset= ((intptr_t)&(temp.seqbase)) - ((intptr_t)&temp); /* root pointer */ if(ed->seqbasep == old_seqbasep) { @@ -4094,7 +4121,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc) while(se) { se->v1= newdataadr(fd, se->v1); se->v2= newdataadr(fd, se->v2); - if( (long)se->v1 > (long)se->v2) { + if( (intptr_t)se->v1 > (intptr_t)se->v2) { sv= se->v1; se->v1= se->v2; se->v2= sv; @@ -4166,6 +4193,9 @@ static void direct_link_screen(FileData *fd, bScreen *sc) sima->cumap= newdataadr(fd, sima->cumap); if(sima->cumap) direct_link_curvemapping(fd, sima->cumap); + sima->gpd= newdataadr(fd, sima->gpd); + if (sima->gpd) + link_gpencil(fd, sima->gpd); sima->iuser.ok= 1; } else if(sl->spacetype==SPACE_NODE) { @@ -4844,7 +4874,7 @@ static void ntree_version_245(FileData *fd, Library *lib, bNodeTree *ntree) } } -void idproperties_fix_groups_lengths_recurse(IDProperty *prop) +static void idproperties_fix_groups_lengths_recurse(IDProperty *prop) { IDProperty *loop; int i; @@ -4859,7 +4889,7 @@ void idproperties_fix_groups_lengths_recurse(IDProperty *prop) } } -void idproperties_fix_group_lengths(ListBase idlist) +static void idproperties_fix_group_lengths(ListBase idlist) { ID *id; @@ -4870,7 +4900,7 @@ void idproperties_fix_group_lengths(ListBase idlist) } } -void alphasort_version_246(FileData *fd, Library *lib, Mesh *me) +static void alphasort_version_246(FileData *fd, Library *lib, Mesh *me) { Material *ma; MFace *mf; @@ -5299,7 +5329,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) while (act) { if(act->type==ACT_IPO) { ia= act->data; - prop= get_property(ob, ia->name); + prop= get_ob_property(ob, ia->name); if(prop) { ia->type= ACT_IPO_FROM_PROP; } @@ -7621,8 +7651,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } - if(ob->fluidsimSettings && ob->fluidsimSettings->type == OB_FLUIDSIM_PARTICLE) - part->type = PART_FLUID; + + { + FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim); + if(fluidmd && fluidmd->fss && fluidmd->fss->type == OB_FLUIDSIM_PARTICLE) + part->type = PART_FLUID; + } free_effects(&ob->effect); @@ -7748,35 +7782,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main) idproperties_fix_group_lengths(main->brush); idproperties_fix_group_lengths(main->particle); } - - /* only needed until old bad svn/RC1,2 files are saved with a > 17 version -dg */ - if(main->versionfile == 245 && main->subversionfile < 17) { - ModifierData *md; - Object *ob; - - for(ob = main->object.first; ob; ob= ob->id.next) { - for(md=ob->modifiers.first; md; ) { - if(md->type==eModifierType_Cloth) { - ModifierData *next; - MEM_freeN(((ClothModifierData *)md)->sim_parms); - MEM_freeN(((ClothModifierData *)md)->coll_parms); - MEM_freeN(((ClothModifierData *)md)->point_cache); - ((ClothModifierData *)md)->sim_parms = NULL; - ((ClothModifierData *)md)->coll_parms = NULL; - ((ClothModifierData *)md)->point_cache = NULL; - next=md->next; - BLI_remlink(&ob->modifiers, md); - md = next; - } - else - md = md->next; - } - } - } /* sun/sky */ if(main->versionfile < 246) { Lamp *la; + Object *ob; + bActuator *act; for(la=main->lamp.first; la; la= la->id.next) { la->sun_effect_type = 0; @@ -7791,15 +7802,151 @@ static void do_versions(FileData *fd, Library *lib, Main *main) la->atm_distance_factor = 1.0; la->sun_intensity = 1.0; } + /* dRot actuator change direction in 2.46 */ + for(ob = main->object.first; ob; ob= ob->id.next) { + for(act= ob->actuators.first; act; act= act->next) { + if (act->type == ACT_OBJECT) { + bObjectActuator *ba= act->data; + + ba->drot[0] = -ba->drot[0]; + ba->drot[1] = -ba->drot[1]; + ba->drot[2] = -ba->drot[2]; + } + } + } } + + // convert fluids to modifier + 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) + { + FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifier_new(eModifierType_Fluidsim); + BLI_addhead(&ob->modifiers, (ModifierData *)fluidmd); + + MEM_freeN(fluidmd->fss); + fluidmd->fss = MEM_dupallocN(ob->fluidsimSettings); + fluidmd->fss->ipo = newlibadr_us(fd, ob->id.lib, ob->fluidsimSettings->ipo); + MEM_freeN(ob->fluidsimSettings); + + fluidmd->fss->lastgoodframe = INT_MAX; + fluidmd->fss->flag = 0; + } + } + } + - if(main->versionfile <= 246 && main->subversionfile < 1){ + if(main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) { Mesh *me; for(me=main->mesh.first; me; me= me->id.next) alphasort_version_246(fd, lib, me); } + + if(main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)){ + Object *ob; + for(ob = main->object.first; ob; ob= ob->id.next) { + if(ob->pd && (ob->pd->forcefield == PFIELD_WIND)) + ob->pd->f_noise = 0.0; + } + } + + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 2)){ + Object *ob; + for(ob = main->object.first; ob; ob= ob->id.next) { + ob->gameflag |= OB_COLLISION; + ob->margin = 0.06; + } + } + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 3)){ + Object *ob; + for(ob = main->object.first; ob; ob= ob->id.next) { + // Starting from subversion 3, ACTOR is a separate feature. + // Before it was conditioning all the other dynamic flags + if (!(ob->gameflag & OB_ACTOR)) + ob->gameflag &= ~(OB_GHOST|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_COLLISION_RESPONSE); + /* suitable default for older files */ + } + } + + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 4)){ + Scene *sce= main->scene.first; + while(sce) { + if(sce->frame_step==0) + sce->frame_step= 1; + sce= sce->id.next; + } + } + + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 5)) { + Lamp *la= main->lamp.first; + for(; la; la= la->id.next) { + la->skyblendtype= MA_RAMP_ADD; + la->skyblendfac= 1.0f; + } + } + + /* set the curve radius interpolation to 2.47 default - easy */ + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 6)) { + Curve *cu; + Nurb *nu; + + for(cu= main->curve.first; cu; cu= cu->id.next) { + for(nu= cu->nurb.first; nu; nu= nu->next) { + if (nu) { + nu->radius_interp = 3; + + /* resolu and resolv are now used differently for surfaces + * rather then using the resolution to define the entire number of divisions, + * use it for the number of divisions per segment + */ + if (nu->pntsv > 1) { + nu->resolu = MAX2( 1, (int)(((float)nu->resolu / (float)nu->pntsu)+0.5f) ); + nu->resolv = MAX2( 1, (int)(((float)nu->resolv / (float)nu->pntsv)+0.5f) ); + } + } + } + } + } + /* direction constraint actuators were always local in previous version */ + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 7)) { + bActuator *act; + Object *ob; + + for(ob = main->object.first; ob; ob= ob->id.next) { + for(act= ob->actuators.first; act; act= act->next) { + if (act->type == ACT_CONSTRAINT) { + bConstraintActuator *coa = act->data; + if (coa->type == ACT_CONST_TYPE_DIST) { + coa->flag |= ACT_CONST_LOCAL; + } + } + } + } + } + /* autokey mode settings now used from scene, but need to be initialised off userprefs */ + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 8)) { + Scene *sce; + + for (sce= main->scene.first; sce; sce= sce->id.next) { + if (sce->autokey_mode == 0) + sce->autokey_mode= U.autokey_mode; + } + } + + if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 9)) { + Lamp *la= main->lamp.first; + for(; la; la= la->id.next) { + la->sky_exposure= 1.0f; + } + } + + + /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */ @@ -8516,9 +8663,6 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) sens= ob->sensors.first; while(sens) { - for(a=0; a<sens->totlinks; a++) { - sens->links[a]= newglobadr(fd, sens->links[a]); - } if(sens->type==SENS_TOUCH) { bTouchSensor *ts= sens->data; expand_doit(fd, mainvar, ts->ma); @@ -8532,9 +8676,6 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) cont= ob->controllers.first; while(cont) { - for(a=0; a<cont->totlinks; a++) { - cont->links[a]= newglobadr(fd, cont->links[a]); - } if(cont->type==CONT_PYTHON) { bPythonCont *pc= cont->data; expand_doit(fd, mainvar, pc->text); @@ -9156,7 +9297,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) /* reading runtime */ -BlendFileData *blo_read_blendafterruntime(int file, int actualsize, BlendReadError *error_r) +BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize, BlendReadError *error_r) { BlendFileData *bfd = NULL; FileData *fd = filedata_new(); @@ -9164,6 +9305,9 @@ BlendFileData *blo_read_blendafterruntime(int file, int actualsize, BlendReadErr fd->buffersize = actualsize; fd->read = fd_read_from_file; + /* needed for library_append and read_libraries */ + BLI_strncpy(fd->filename, name, sizeof(fd->filename)); + fd = blo_decode_and_check(fd, error_r); if (!fd) return NULL; |