diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 716 |
1 files changed, 484 insertions, 232 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4385caa19df..3b62b5a5e47 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -39,7 +39,6 @@ #ifndef WIN32 #include <unistd.h> // for read close - #include <sys/param.h> // for MAXPATHLEN #else #include <io.h> // for open close read #include "winsock2.h" @@ -89,6 +88,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" +#include "BLI_utildefines.h" #include "BKE_anim.h" #include "BKE_action.h" @@ -107,6 +107,7 @@ #include "BKE_lattice.h" #include "BKE_library.h" // for which_libbase #include "BKE_idcode.h" +#include "BKE_material.h" #include "BKE_main.h" // for Main #include "BKE_mesh.h" // for ME_ defines (patching) #include "BKE_modifier.h" @@ -227,7 +228,7 @@ typedef struct OldNewMap { /* local prototypes */ -static void *read_struct(FileData *fd, BHead *bh, char *blockname); +static void *read_struct(FileData *fd, BHead *bh, const char *blockname); static OldNewMap *oldnewmap_new(void) @@ -381,10 +382,10 @@ static void add_main_to_main(Main *mainvar, Main *from) ListBase *lbarray[MAX_LIBARRAY], *fromarray[MAX_LIBARRAY]; int a; - a= set_listbasepointers(mainvar, lbarray); + set_listbasepointers(mainvar, lbarray); a= set_listbasepointers(from, fromarray); while(a--) { - addlisttolist(lbarray[a], fromarray[a]); + BLI_movelisttolist(lbarray[a], fromarray[a]); } } @@ -588,20 +589,16 @@ static void bh8_from_bh4(BHead *bhead, BHead4 *bhead4) static BHeadN *get_bhead(FileData *fd) { - BHead8 bhead8; - BHead4 bhead4; - BHead bhead; BHeadN *new_bhead = 0; int readsize; if (fd) { if ( ! fd->eof) { - - /* not strictly needed but shuts valgrind up + /* initializing to zero isn't strictly needed but shuts valgrind up * since uninitialized memory gets compared */ - memset(&bhead8, 0, sizeof(BHead8)); - memset(&bhead4, 0, sizeof(BHead4)); - memset(&bhead, 0, sizeof(BHead)); + BHead8 bhead8= {0}; + BHead4 bhead4= {0}; + BHead bhead= {0}; // First read the bhead structure. // Depending on the platform the file was written on this can @@ -704,7 +701,7 @@ BHead *blo_firstbhead(FileData *fd) return(bhead); } -BHead *blo_prevbhead(FileData *fd, BHead *thisblock) +BHead *blo_prevbhead(FileData *UNUSED(fd), BHead *thisblock) { BHeadN *bheadn= (BHeadN *) (((char *) thisblock) - GET_INT_FROM_POINTER( &((BHeadN*)0)->bhead) ); BHeadN *prev= bheadn->prev; @@ -831,8 +828,8 @@ static int fd_read_gzip_from_file(FileData *filedata, void *buffer, unsigned int static int fd_read_from_memory(FileData *filedata, void *buffer, unsigned int size) { - // don't read more bytes then there are available in the buffer - int readsize = MIN2(size, filedata->buffersize - filedata->seek); + // don't read more bytes then there are available in the buffer + int readsize = (int)MIN2(size, (unsigned int)(filedata->buffersize - filedata->seek)); memcpy(buffer, filedata->buffer + filedata->seek, readsize); filedata->seek += readsize; @@ -925,13 +922,13 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports) if (fd->flags & FD_FLAGS_FILE_OK) { if (!read_file_dna(fd)) { - BKE_report(reports, RPT_ERROR, "File incomplete"); + BKE_reportf(reports, RPT_ERROR, "Failed to read blend file: \"%s\", incomplete", fd->relabase); blo_freefiledata(fd); fd= NULL; } } else { - BKE_report(reports, RPT_ERROR, "File is not a Blender file"); + BKE_reportf(reports, RPT_ERROR, "Failed to read blend file: \"%s\", not a blend file", fd->relabase); blo_freefiledata(fd); fd= NULL; } @@ -941,7 +938,7 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports) /* cannot be called with relative paths anymore! */ /* on each new library added, it now checks for the current FileData and expands relativeness */ -FileData *blo_openblenderfile(char *name, ReportList *reports) +FileData *blo_openblenderfile(const char *name, ReportList *reports) { gzFile gzfile; errno= 0; @@ -1042,7 +1039,7 @@ void blo_freefiledata(FileData *fd) int BLO_has_bfile_extension(char *str) { - return (BLI_testextensie(str, ".ble") || BLI_testextensie(str, ".blend")||BLI_testextensie(str, ".blend.gz")); + return (BLI_testextensie(str, ".ble") || BLI_testextensie(str, ".blend") || BLI_testextensie(str, ".blend.gz")); } int BLO_is_a_library(const char *path, char *dir, char *group) @@ -1155,7 +1152,7 @@ static void change_idid_adr(ListBase *mainlist, FileData *basefd, void *old, voi * to clear that pointer before reading the undo memfile since * the object might be removed, it is set again in reading * if the local object still exists */ -void blo_clear_proxy_pointers_from_lib(FileData *fd, Main *oldmain) +void blo_clear_proxy_pointers_from_lib(Main *oldmain) { Object *ob= oldmain->object.first; @@ -1268,7 +1265,7 @@ static void switch_endian_structs(struct SDNA *filesdna, BHead *bhead) } } -static void *read_struct(FileData *fd, BHead *bh, char *blockname) +static void *read_struct(FileData *fd, BHead *bh, const char *blockname) { void *temp= NULL; @@ -1384,8 +1381,8 @@ static void test_pointer_array(FileData *fd, void **mat) /* ************ READ ID Properties *************** */ -void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd); -void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd); +static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd); +static void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd); static void IDP_DirectLinkIDPArray(IDProperty *prop, int switch_endian, FileData *fd) { @@ -1442,7 +1439,7 @@ static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, FileData *f } } -static void IDP_DirectLinkString(IDProperty *prop, int switch_endian, FileData *fd) +static void IDP_DirectLinkString(IDProperty *prop, FileData *fd) { /*since we didn't save the extra string buffer, set totallen to len.*/ prop->totallen = prop->len; @@ -1469,7 +1466,7 @@ void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd) IDP_DirectLinkGroup(prop, switch_endian, fd); break; case IDP_STRING: - IDP_DirectLinkString(prop, switch_endian, fd); + IDP_DirectLinkString(prop, fd); break; case IDP_ARRAY: IDP_DirectLinkArray(prop, switch_endian, fd); @@ -1499,7 +1496,7 @@ void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd) } /*stub function*/ -void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd) +void IDP_LibLinkProperty(IDProperty *UNUSED(prop), int UNUSED(switch_endian), FileData *UNUSED(fd)) { } @@ -1552,7 +1549,7 @@ static void direct_link_brush(FileData *fd, Brush *brush) brush->icon_imbuf= NULL; } -static void direct_link_script(FileData *fd, Script *script) +static void direct_link_script(FileData *UNUSED(fd), Script *script) { script->id.us = 1; SCRIPT_SET_NULL(script) @@ -1980,9 +1977,13 @@ static void direct_link_animdata(FileData *fd, AnimData *adt) link_list(fd, &adt->nla_tracks); direct_link_nladata(fd, &adt->nla_tracks); - /* clear temp pointers that may have been set... */ - // TODO: it's probably only a small cost to reload this anyway... - adt->actstrip= NULL; + /* relink active strip - even though strictly speaking this should only be used + * if we're in 'tweaking mode', we need to be able to have this loaded back for + * undo, but also since users may not exit tweakmode before saving (#24535) + */ + // TODO: it's not really nice that anyone should be able to save the file in this + // state, but it's going to be too hard to enforce this single case... + adt->actstrip= newdataadr(fd, adt->actstrip); } /* ************ READ MOTION PATHS *************** */ @@ -2030,7 +2031,7 @@ static void lib_link_nodetree(FileData *fd, Main *main) /* 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*/ -static void lib_verify_nodetree(Main *main, int open) +static void lib_verify_nodetree(Main *main, int UNUSED(open)) { Scene *sce; Material *ma; @@ -2103,8 +2104,11 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) else if(ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) ((ImageUser *)node->storage)->ok= 1; } - else if( ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) ) { - direct_link_curvemapping(fd, node->storage); + else if( ntree->type==NTREE_TEXTURE) { + if(node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) + direct_link_curvemapping(fd, node->storage); + else if(node->type==TEX_NODE_IMAGE) + ((ImageUser *)node->storage)->ok= 1; } } link_list(fd, &node->inputs); @@ -2139,7 +2143,7 @@ typedef struct tConstraintLinkData { ID *id; } tConstraintLinkData; /* callback function used to relink constraint ID-links */ -static void lib_link_constraint_cb(bConstraint *con, ID **idpoin, void *userdata) +static void lib_link_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, void *userdata) { tConstraintLinkData *cld= (tConstraintLinkData *)userdata; *idpoin = newlibadr(cld->fd, cld->id->lib, *idpoin); @@ -2200,6 +2204,12 @@ static void direct_link_constraints(FileData *fd, ListBase *lb) con->lin_error = 0.f; con->rot_error = 0.f; } + case CONSTRAINT_TYPE_CHILDOF: + { + /* XXX version patch, in older code this flag wasn't always set, and is inherent to type */ + if(con->ownspace == CONSTRAINT_SPACE_POSE) + con->flag |= CONSTRAINT_SPACEONCE; + } break; } } @@ -2214,13 +2224,21 @@ static void lib_link_pose(FileData *fd, Object *ob, bPose *pose) if (!pose || !arm) return; + /* always rebuild to match proxy or lib changes */ rebuild= ob->proxy || (ob->id.lib==NULL && arm->id.lib); - if (ob->proxy && pose->proxy_act_bone[0]) { - Bone *bone = get_named_bone(arm, pose->proxy_act_bone); - if (bone) - arm->act_bone = bone; + if(ob->proxy) { + /* sync proxy layer */ + if(pose->proxy_layer) + arm->layer = pose->proxy_layer; + + /* sync proxy active bone */ + if(pose->proxy_act_bone[0]) { + Bone *bone = get_named_bone(arm, pose->proxy_act_bone); + if (bone) + arm->act_bone = bone; + } } for (pchan = pose->chanbase.first; pchan; pchan=pchan->next) { @@ -2229,7 +2247,7 @@ static void lib_link_pose(FileData *fd, Object *ob, bPose *pose) /* hurms... loop in a loop, but yah... later... (ton) */ pchan->bone= get_named_bone(arm, pchan->name); - pchan->custom= newlibadr(fd, arm->id.lib, pchan->custom); + pchan->custom= newlibadr_us(fd, arm->id.lib, pchan->custom); if(pchan->bone==NULL) rebuild= 1; else if(ob->id.lib==NULL && arm->id.lib) { @@ -2240,7 +2258,7 @@ static void lib_link_pose(FileData *fd, Object *ob, bPose *pose) } if(rebuild) { - ob->recalc= OB_RECALC_ALL; + ob->recalc= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; pose->flag |= POSE_RECALC; } } @@ -2442,7 +2460,7 @@ static void direct_link_key(FileData *fd, Key *key) while(kb) { kb->data= newdataadr(fd, kb->data); - + if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) switch_endian_keyblock(key, kb); @@ -2534,7 +2552,7 @@ static void direct_link_world(FileData *fd, World *wrld) /* ************ READ VFONT ***************** */ -static void lib_link_vfont(FileData *fd, Main *main) +static void lib_link_vfont(FileData *UNUSED(fd), Main *main) { VFont *vf; @@ -2555,7 +2573,7 @@ static void direct_link_vfont(FileData *fd, VFont *vf) /* ************ READ TEXT ****************** */ -static void lib_link_text(FileData *fd, Main *main) +static void lib_link_text(FileData *UNUSED(fd), Main *main) { Text *text; @@ -2735,7 +2753,7 @@ static void direct_link_curve(FileData *fd, Curve *cu) cu->strinfo= newdataadr(fd, cu->strinfo); cu->tb= newdataadr(fd, cu->tb); - if(cu->vfont==0) link_list(fd, &(cu->nurb)); + if(cu->vfont == NULL) link_list(fd, &(cu->nurb)); else { cu->nurb.first=cu->nurb.last= 0; @@ -2766,7 +2784,7 @@ static void direct_link_curve(FileData *fd, Curve *cu) nu->bp= newdataadr(fd, nu->bp); nu->knotsu= newdataadr(fd, nu->knotsu); nu->knotsv= newdataadr(fd, nu->knotsv); - if (cu->vfont==0) nu->charidx= nu->mat_nr; + if (cu->vfont == NULL) nu->charidx= nu->mat_nr; if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) { switch_endian_knots(nu); @@ -2909,11 +2927,22 @@ static void direct_link_material(FileData *fd, Material *ma) } /* ************ READ PARTICLE SETTINGS ***************** */ - +/* update this also to writefile.c */ +static const char *ptcache_data_struct[] = { + "", // BPHYS_DATA_INDEX + "", // BPHYS_DATA_LOCATION + "", // BPHYS_DATA_VELOCITY + "", // BPHYS_DATA_ROTATION + "", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */ + "", // BPHYS_DATA_SIZE: + "", // BPHYS_DATA_TIMES: + "BoidData" // case BPHYS_DATA_BOIDS: +}; static void direct_link_pointcache(FileData *fd, PointCache *cache) { if((cache->flag & PTCACHE_DISK_CACHE)==0) { PTCacheMem *pm; + PTCacheExtra *extra; int i; link_list(fd, &cache->mem_cache); @@ -2921,13 +2950,23 @@ static void direct_link_pointcache(FileData *fd, PointCache *cache) pm = cache->mem_cache.first; for(; pm; pm=pm->next) { - if(pm->index_array) - pm->index_array = newdataadr(fd, pm->index_array); - for(i=0; i<BPHYS_TOT_DATA; i++) { - if(pm->data[i] && pm->data_types & (1<<i)) - pm->data[i] = newdataadr(fd, pm->data[i]); + pm->data[i] = newdataadr(fd, pm->data[i]); + + /* the cache saves non-struct data without DNA */ + if(pm->data[i] && strcmp(ptcache_data_struct[i], "")==0 && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) { + int j, tot= (BKE_ptcache_data_size (i) * pm->totpoint)/4; /* data_size returns bytes */ + int *poin= pm->data[i]; + + for(j= 0; j<tot; j++) + SWITCH_INT(poin[j]); + } } + + link_list(fd, &pm->extradata); + + for(extra=pm->extradata.first; extra; extra=extra->next) + extra->data = newdataadr(fd, extra->data); } } else @@ -2937,16 +2976,21 @@ static void direct_link_pointcache(FileData *fd, PointCache *cache) cache->simframe= 0; cache->edit= NULL; cache->free_edit= NULL; + cache->cached_frames= NULL; } -static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointCache **ocache) +static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointCache **ocache, int force_disk) { - PointCache *cache; - if(ptcaches->first) { + PointCache *cache= NULL; link_list(fd, ptcaches); - for(cache=ptcaches->first; cache; cache=cache->next) + for(cache=ptcaches->first; cache; cache=cache->next) { direct_link_pointcache(fd, cache); + if(force_disk) { + cache->flag |= PTCACHE_DISK_CACHE; + cache->step = 1; + } + } *ocache = newdataadr(fd, *ocache); } @@ -2954,6 +2998,10 @@ static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointC /* old "single" caches need to be linked too */ *ocache = newdataadr(fd, *ocache); direct_link_pointcache(fd, *ocache); + if(force_disk) { + (*ocache)->flag |= PTCACHE_DISK_CACHE; + (*ocache)->step = 1; + } ptcaches->first = ptcaches->last = *ocache; } @@ -3121,11 +3169,12 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) for(a=1,pa++; a<psys->totpart; a++, pa++) pa->boid = (pa-1)->boid + 1; } - else { + else if(psys->particles) { 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->effectors = NULL; @@ -3140,8 +3189,9 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) psys->childcachebufs.first = psys->childcachebufs.last = NULL; psys->frand = NULL; psys->pdd = NULL; + psys->renderdata = NULL; - direct_link_pointcache_list(fd, &psys->ptcaches, &psys->pointcache); + direct_link_pointcache_list(fd, &psys->ptcaches, &psys->pointcache, 0); if(psys->clmd) { psys->clmd = newdataadr(fd, psys->clmd); @@ -3250,10 +3300,21 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte for(i = 0; i < count; ++i) { mdisps[i].disps = newdataadr(fd, mdisps[i].disps); + + if( (fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps) ) { + /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ + /* this does swap for data written at write_mdisps() - readfile.c */ + int x; + float *tmpdisps= *mdisps[i].disps; + for(x=0;x<mdisps[i].totdisp*3;x++) { + SWITCH_INT(*tmpdisps); + tmpdisps++; + } + } if(!external && !mdisps[i].disps) mdisps[i].totdisp = 0; } - } + } } static void direct_link_customdata(FileData *fd, CustomData *data, int count) @@ -3376,6 +3437,7 @@ static void lib_link_latt(FileData *fd, Main *main) lt= main->latt.first; while(lt) { if(lt->id.flag & LIB_NEEDLINK) { + if(lt->adt) lib_link_animdata(fd, <->id, lt->adt); lt->ipo= newlibadr_us(fd, lt->id.lib, lt->ipo); // XXX depreceated - old animation system lt->key= newlibadr_us(fd, lt->id.lib, lt->key); @@ -3394,6 +3456,9 @@ static void direct_link_latt(FileData *fd, Lattice *lt) direct_link_dverts(fd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert); lt->editlatt= NULL; + + lt->adt = newdataadr(fd, lt->adt); + direct_link_animdata(fd, lt->adt); } @@ -3456,14 +3521,14 @@ static void lib_link_object(FileData *fd, Main *main) /* this triggers object_update to always use a copy */ ob->proxy->proxy_from= ob; /* force proxy updates after load/undo, a bit weak */ - ob->recalc= ob->proxy->recalc= OB_RECALC_ALL; + ob->recalc= ob->proxy->recalc= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; } } ob->proxy_group= newlibadr(fd, ob->id.lib, ob->proxy_group); poin= ob->data; ob->data= newlibadr_us(fd, ob->id.lib, ob->data); - + if(ob->data==NULL && poin!=NULL) { if(ob->id.lib) printf("Can't find obdata of %s lib %s\n", ob->id.name+2, ob->id.lib->name); @@ -3481,6 +3546,17 @@ static void lib_link_object(FileData *fd, Main *main) } for(a=0; a<ob->totcol; a++) ob->mat[a]= newlibadr_us(fd, ob->id.lib, ob->mat[a]); + /* When the object is local and the data is library its possible + * the material list size gets out of sync. [#22663] */ + if(ob->data && ob->id.lib != ((ID *)ob->data)->lib) { + short *totcol_data= give_totcolp(ob); + /* Only expand so as not to loose any object materials that might be set. */ + if(totcol_data && *totcol_data > ob->totcol) { + /* printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data); */ + resize_object_material(ob, *totcol_data); + } + } + ob->gpd= newlibadr_us(fd, ob->id.lib, ob->gpd); ob->duplilist= NULL; @@ -3637,6 +3713,8 @@ static void lib_link_object(FileData *fd, Main *main) smd->domain->fluid_group = newlibadr_us(fd, ob->id.lib, smd->domain->fluid_group); smd->domain->effector_weights->group = newlibadr(fd, ob->id.lib, smd->domain->effector_weights->group); + + smd->domain->flags |= MOD_SMOKE_FILE_LOAD; /* flag for refreshing the simulation after loading */ } } @@ -3698,6 +3776,9 @@ static void direct_link_pose(FileData *fd, bPose *pose) pchan->iktree.first= pchan->iktree.last= NULL; pchan->path= NULL; + + /* incase this value changes in future, clamp else we get undefined behavior */ + CLAMP(pchan->rotmode, ROT_MODE_MIN, ROT_MODE_MAX); } pose->ikdata = NULL; if (pose->ikparam != NULL) { @@ -3737,19 +3818,20 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) clmd->sim_parms= newdataadr(fd, clmd->sim_parms); clmd->coll_parms= newdataadr(fd, clmd->coll_parms); - direct_link_pointcache_list(fd, &clmd->ptcaches, &clmd->point_cache); + direct_link_pointcache_list(fd, &clmd->ptcaches, &clmd->point_cache, 0); if(clmd->sim_parms) { if(clmd->sim_parms->presets > 10) clmd->sim_parms->presets = 0; clmd->sim_parms->reset = 0; - } - clmd->sim_parms->effector_weights = newdataadr(fd, clmd->sim_parms->effector_weights); - if(!clmd->sim_parms->effector_weights) - clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL); - + clmd->sim_parms->effector_weights = newdataadr(fd, clmd->sim_parms->effector_weights); + + if(!clmd->sim_parms->effector_weights) { + clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL); + } + } } else if (md->type==eModifierType_Fluidsim) { FluidsimModifierData *fluidmd = (FluidsimModifierData*) md; @@ -3779,8 +3861,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) if(!smd->domain->effector_weights) smd->domain->effector_weights = BKE_add_effector_weights(NULL); - direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0])); - direct_link_pointcache_list(fd, &(smd->domain->ptcaches[1]), &(smd->domain->point_cache[1])); + direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0]), 1); + + /* Smoke uses only one cache from now on, so store pointer convert */ + if(smd->domain->ptcaches[1].first || smd->domain->point_cache[1]) { + printf("High resolution smoke cache not available due to pointcache update. Please reset the simulation.\n"); + smd->domain->ptcaches[1].first = NULL; + smd->domain->ptcaches[1].last = NULL; + smd->domain->point_cache[1] = NULL; + } } else if(smd->type==MOD_SMOKE_TYPE_FLOW) { @@ -3853,9 +3942,10 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) } else if (md->type==eModifierType_ParticleSystem) { ParticleSystemModifierData *psmd = (ParticleSystemModifierData*) md; - psmd->dm=0; - psmd->psys=newdataadr(fd, psmd->psys); + psmd->dm= NULL; + psmd->psys= newdataadr(fd, psmd->psys); psmd->flag &= ~eParticleSystemFlag_psys_updated; + psmd->flag |= eParticleSystemFlag_file_loaded; } else if (md->type==eModifierType_Explode) { ExplodeModifierData *psmd = (ExplodeModifierData*) md; @@ -4014,7 +4104,7 @@ static void direct_link_object(FileData *fd, Object *ob) if(!sb->effector_weights) sb->effector_weights = BKE_add_effector_weights(NULL); - direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache); + direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache, 0); } ob->bsoft= newdataadr(fd, ob->bsoft); ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */ @@ -4104,8 +4194,13 @@ static void direct_link_object(FileData *fd, Object *ob) ob->gpulamp.first= ob->gpulamp.last= NULL; link_list(fd, &ob->pc_ids); - if(ob->sculpt) + /* incase this value changes in future, clamp else we get undefined behavior */ + CLAMP(ob->rotmode, ROT_MODE_MIN, ROT_MODE_MAX); + + if(ob->sculpt) { ob->sculpt= MEM_callocN(sizeof(SculptSession), "reload sculpt session"); + ob->sculpt->ob= ob; + } } /* ************ READ SCENE ***************** */ @@ -4149,7 +4244,6 @@ static void lib_link_scene(FileData *fd, Main *main) sce->camera= newlibadr(fd, sce->id.lib, sce->camera); sce->world= newlibadr_us(fd, sce->id.lib, sce->world); sce->set= newlibadr(fd, sce->id.lib, sce->set); - sce->ima= newlibadr_us(fd, sce->id.lib, sce->ima); sce->gpd= newlibadr_us(fd, sce->id.lib, sce->gpd); link_paint(fd, sce, &sce->toolsettings->sculpt->paint); @@ -4239,9 +4333,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)); + (*paint)= newdataadr(fd, (*paint)); } static void direct_link_scene(FileData *fd, Scene *sce) @@ -4463,6 +4556,7 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) wm->drags.first= wm->drags.last= NULL; wm->windrawable= NULL; + wm->winactive= NULL; wm->initialized= 0; wm->op_undo_depth= 0; } @@ -4648,6 +4742,7 @@ static void lib_link_screen(FileData *fd, Main *main) SpaceText *st= (SpaceText *)sl; st->text= newlibadr(fd, sc->id.lib, st->text); + st->drawcache= NULL; } else if(sl->spacetype==SPACE_SCRIPT) { @@ -4826,10 +4921,6 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene) else if(sl->spacetype==SPACE_FILE) { SpaceFile *sfile= (SpaceFile *)sl; - sfile->files= NULL; - sfile->folders_prev= NULL; - sfile->folders_next= NULL; - sfile->params= NULL; sfile->op= NULL; } else if(sl->spacetype==SPACE_IMASEL) { @@ -5192,7 +5283,11 @@ static void direct_link_screen(FileData *fd, bScreen *sc) for(cl= sconsole->history.first; cl; cl= cl_next) { cl_next= cl->next; cl->line= newdataadr(fd, cl->line); - if (cl->line == NULL) { + if (cl->line) { + /* the allocted length is not written, so reset here */ + cl->len_alloc= cl->len + 1; + } + else { BLI_remlink(&sconsole->history, cl); MEM_freeN(cl); } @@ -5232,14 +5327,14 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) if(newmain->curlib) { if(strcmp(newmain->curlib->filepath, lib->filepath)==0) { printf("Fixed error in file; multiple instances of lib:\n %s\n", lib->filepath); - + BKE_reportf(fd->reports, RPT_WARNING, "Library '%s', '%s' had multiple instances, save and reload!", lib->name, lib->filepath); + change_idid_adr(&fd->mainlist, fd, lib, newmain->curlib); // change_idid_adr_fd(fd, lib, newmain->curlib); BLI_remlink(&main->library, lib); MEM_freeN(lib); - - BKE_report(fd->reports, RPT_WARNING, "Library had multiple instances, save and reload!"); + return; } @@ -5260,7 +5355,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) lib->parent= NULL; } -static void lib_link_library(FileData *fd, Main *main) +static void lib_link_library(FileData *UNUSED(fd), Main *main) { Library *lib; for(lib= main->library.first; lib; lib= lib->id.next) { @@ -5356,7 +5451,7 @@ static void lib_link_group(FileData *fd, Main *main) /* ************** GENERAL & MAIN ******************** */ -static char *dataname(short id_code) +static const char *dataname(short id_code) { switch( id_code ) { @@ -5391,7 +5486,7 @@ static char *dataname(short id_code) } -static BHead *read_data_into_oldnewmap(FileData *fd, BHead *bhead, char *allocname) +static BHead *read_data_into_oldnewmap(FileData *fd, BHead *bhead, const char *allocname) { bhead = blo_nextbhead(fd, bhead); @@ -5427,7 +5522,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID ID *id; ListBase *lb; - char *allocname; + const char *allocname; /* read libblock */ id = read_struct(fd, bhead, "lib block"); @@ -5454,6 +5549,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID if(id->flag & LIB_FAKEUSER) id->us= 1; else id->us= 0; id->icon_id = 0; + id->flag &= ~LIB_ID_RECALC; /* this case cannot be direct_linked: it's just the ID part */ if(bhead->code==ID_ID) { @@ -5578,12 +5674,14 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead) bfd->main->subversionfile= fg->subversion; bfd->main->minversionfile= fg->minversion; bfd->main->minsubversionfile= fg->minsubversion; + bfd->main->revision= fg->revision; bfd->winpos= fg->winpos; bfd->fileflags= fg->fileflags; bfd->displaymode= fg->displaymode; bfd->globalf= fg->globalf; BLI_strncpy(bfd->filename, fg->filename, sizeof(bfd->filename)); + if(G.fileflags & G_FILE_RECOVER) BLI_strncpy(fd->relabase, fg->filename, sizeof(fd->relabase)); @@ -5652,6 +5750,23 @@ static int map_223_keybd_code_to_224_keybd_code(int code) } } +static void do_version_bone_head_tail_237(Bone *bone) +{ + Bone *child; + float vec[3]; + + /* head */ + copy_v3_v3(bone->arm_head, bone->arm_mat[3]); + + /* tail is in current local coord system */ + copy_v3_v3(vec, bone->arm_mat[1]); + mul_v3_fl(vec, bone->length); + add_v3_v3v3(bone->arm_tail, bone->arm_head, vec); + + for(child= bone->childbase.first; child; child= child->next) + do_version_bone_head_tail_237(child); +} + static void bone_version_238(ListBase *lb) { Bone *bone; @@ -6091,7 +6206,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) case SPACE_NODE: ar= MEM_callocN(sizeof(ARegion), "nodetree area for node"); BLI_addtail(lb, ar); - ar->regiontype= RGN_TYPE_CHANNELS; + ar->regiontype= RGN_TYPE_UI; ar->alignment= RGN_ALIGN_LEFT; ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM); ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL; @@ -6244,6 +6359,8 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) } case SPACE_ACTION: { + SpaceAction *saction= (SpaceAction *)sl; + /* we totally reinit the view for the Action Editor, as some old instances had some weird cruft set */ ar->v2d.tot.xmin= -20.0f; ar->v2d.tot.ymin= (float)(-sa->winy)/3.0f; @@ -6253,10 +6370,10 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) ar->v2d.cur= ar->v2d.tot; ar->v2d.min[0]= 0.0f; - ar->v2d.min[1]= 0.0f; + ar->v2d.min[1]= 0.0f; ar->v2d.max[0]= MAXFRAMEF; - ar->v2d.max[1]= FLT_MAX; + ar->v2d.max[1]= FLT_MAX; ar->v2d.minzoom= 0.01f; ar->v2d.maxzoom= 50; @@ -6265,6 +6382,13 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) ar->v2d.keepzoom= V2D_LOCKZOOM_Y; ar->v2d.align= V2D_ALIGN_NO_POS_Y; ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL; + + /* for old files with ShapeKey editors open + an action set, clear the action as + * it doesn't make sense in the new system (i.e. violates concept that ShapeKey edit + * only shows ShapeKey-rooted actions only) + */ + if (saction->mode == SACTCONT_SHAPEKEY) + saction->action = NULL; break; } case SPACE_SEQ: @@ -6340,6 +6464,9 @@ static void do_versions_windowmanager_2_50(bScreen *screen) sl->spacetype= SPACE_INFO; /* spacedata then matches */ } + /* it seems to be possible in 2.5 to have this saved, filewindow probably */ + sa->butspacetype= sa->spacetype; + /* pushed back spaces also need regions! */ if(sa->spacedata.first) { sl= sa->spacedata.first; @@ -6352,7 +6479,7 @@ static void do_versions_windowmanager_2_50(bScreen *screen) } } -static void versions_gpencil_add_main(ListBase *lb, ID *id, char *name) +static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name) { BLI_addtail(lb, id); @@ -6472,7 +6599,7 @@ static void do_version_mtex_factor_2_50(MTex **mtex_array, short idtype) } } -static void do_version_mdef_250(FileData *fd, Library *lib, Main *main) +static void do_version_mdef_250(Main *main) { Object *ob; ModifierData *md; @@ -6503,23 +6630,23 @@ static void do_version_constraints_radians_degrees_250(ListBase *lb) for (con=lb->first; con; con=con->next) { if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) { bRigidBodyJointConstraint *data = con->data; - data->axX *= M_PI/180.0; - data->axY *= M_PI/180.0; - data->axZ *= M_PI/180.0; + data->axX *= (float)(M_PI/180.0); + data->axY *= (float)(M_PI/180.0); + data->axZ *= (float)(M_PI/180.0); } else if(con->type==CONSTRAINT_TYPE_KINEMATIC) { bKinematicConstraint *data = con->data; - data->poleangle *= M_PI/180.0; + data->poleangle *= (float)(M_PI/180.0); } else if(con->type==CONSTRAINT_TYPE_ROTLIMIT) { bRotLimitConstraint *data = con->data; - data->xmin *= M_PI/180.0; - data->xmax *= M_PI/180.0; - data->ymin *= M_PI/180.0; - data->ymax *= M_PI/180.0; - data->zmin *= M_PI/180.0; - data->zmax *= M_PI/180.0; + data->xmin *= (float)(M_PI/180.0); + data->xmax *= (float)(M_PI/180.0); + data->ymin *= (float)(M_PI/180.0); + data->ymax *= (float)(M_PI/180.0); + data->zmin *= (float)(M_PI/180.0); + data->zmax *= (float)(M_PI/180.0); } } } @@ -6558,12 +6685,25 @@ static void do_versions_seq_unique_name_all_strips( } } + +static void do_version_bone_roll_256(Bone *bone) +{ + Bone *child; + float submat[3][3]; + + copy_m3_m4(submat, bone->arm_mat); + mat3_to_vec_roll(submat, 0, &bone->arm_roll); + + for(child = bone->childbase.first; child; child = child->next) + do_version_bone_roll_256(child); +} + static void do_versions(FileData *fd, Library *lib, Main *main) { /* WATCH IT!!!: pointers from libdata have not been converted */ if(G.f & G_DEBUG) - printf("read file %s\n Version %d sub %d\n", fd->relabase, main->versionfile, main->subversionfile); + printf("read file %s\n Version %d sub %d svn r%d\n", fd->relabase, main->versionfile, main->subversionfile, main->revision); if(main->versionfile == 100) { /* tex->extend and tex->imageflag have changed: */ @@ -7256,8 +7396,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main) Object *ob; for (vf= main->vfont.first; vf; vf= vf->id.next) { - if (BLI_streq(vf->name+strlen(vf->name)-6, ".Bfont")) { - strcpy(vf->name, "<builtin>"); + if (strcmp(vf->name+strlen(vf->name)-6, ".Bfont")==0) { + strcpy(vf->name, FO_BUILTIN_NAME); } } @@ -7867,10 +8007,14 @@ static void do_versions(FileData *fd, Library *lib, Main *main) bArmature *arm; bConstraint *con; Object *ob; + Bone *bone; // armature recode checks for(arm= main->armature.first; arm; arm= arm->id.next) { where_is_armature(arm); + + for(bone= arm->bonebase.first; bone; bone= bone->next) + do_version_bone_head_tail_237(bone); } for(ob= main->object.first; ob; ob= ob->id.next) { if(ob->parent) { @@ -7883,7 +8027,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if(ob->type==OB_ARMATURE) { if(ob->pose) ob->pose->flag |= POSE_RECALC; - ob->recalc |= OB_RECALC_ALL; // cannot call stuff now (pointers!), done in setup_app_data + ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; // cannot call stuff now (pointers!), done in setup_app_data /* new generic xray option */ arm= newlibadr(fd, lib, ob->data); @@ -8154,7 +8298,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if(arm->layer==0) arm->layer= 1; } for(sce= main->scene.first; sce; sce= sce->id.next) { - if(sce->jumpframe==0) sce->jumpframe= 10; if(sce->audio.mixrate==0) sce->audio.mixrate= 44100; if(sce->r.xparts<2) sce->r.xparts= 4; @@ -8187,7 +8330,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } if(sce->r.mode & R_PANORAMA) { - /* all these checks to ensure saved files with cvs version keep working... */ + /* all these checks to ensure saved files with svn version keep working... */ if(sce->r.xsch < sce->r.ysch) { Object *obc= newlibadr(fd, lib, sce->camera); if(obc && obc->type==OB_CAMERA) { @@ -8775,9 +8918,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main) ob->soft->pointcache= BKE_ptcache_add(&ob->soft->ptcaches); for(psys=ob->particlesystem.first; psys; psys=psys->next) { - //if(psys->soft && !psys->soft->pointcache) - // psys->soft->pointcache= BKE_ptcache_add(&psys->soft->ptcaches); - if(!psys->pointcache) + if(psys->pointcache) { + if(psys->pointcache->flag & PTCACHE_BAKED && (psys->pointcache->flag & PTCACHE_DISK_CACHE)==0) { + printf("Old memory cache isn't supported for particles, so re-bake the simulation!\n"); + psys->pointcache->flag &= ~PTCACHE_BAKED; + } + } + else psys->pointcache= BKE_ptcache_add(&psys->ptcaches); } @@ -9435,7 +9582,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) for(act= ob->actuators.first; act; act= act->next) { if (act->type == ACT_MESSAGE) { bMessageActuator *msgAct = (bMessageActuator *) act->data; - if (strlen(msgAct->toPropName) > 2) { + if (BLI_strnlen(msgAct->toPropName, 3) > 2) { /* strip first 2 chars, would have only worked if these were OB anyway */ memmove( msgAct->toPropName, msgAct->toPropName+2, sizeof(msgAct->toPropName)-2 ); } else { @@ -9544,7 +9691,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* Adjustments needed after Bullets update */ for(ob = main->object.first; ob; ob= ob->id.next) { ob->damping *= 0.635f; - ob->rdamping = 0.1 + (0.8f * ob->rdamping); + ob->rdamping = 0.1f + (0.8f * ob->rdamping); } } @@ -9624,8 +9771,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) seq->strip->proxy->size = sce->r.size; } else { - seq->strip->proxy->size - = 25.0; + seq->strip->proxy->size = 25; } seq->strip->proxy->quality =90; } @@ -9706,7 +9852,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) { char str[FILE_MAX]; BLI_join_dirfile(str, seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(str, G.sce); + BLI_path_abs(str, G.main->name); seq->sound = sound_new_file(main, str); } /* don't know, if anybody used that @@ -9892,12 +10038,15 @@ static void do_versions(FileData *fd, Library *lib, Main *main) for(a=0; a<MAX_MTEX; a++) { if(ma->mtex[a]) { tex= ma->mtex[a]->tex; - if(!tex) - ma->mtex[a]->texflag |= MTEX_NEW_BUMP; - else { + if(!tex) { + ma->mtex[a]->texflag |= MTEX_3TAP_BUMP; + ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE; + } else { tex= (Tex*)newlibadr(fd, ma->id.lib, tex); - if(tex && tex->type == 0) /* invalid type */ - ma->mtex[a]->texflag |= MTEX_NEW_BUMP; + if(tex && tex->type == 0) { /* invalid type */ + ma->mtex[a]->texflag |= MTEX_3TAP_BUMP; + ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE; + } } } } @@ -10075,14 +10224,14 @@ static void do_versions(FileData *fd, Library *lib, Main *main) for(sce= main->scene.first; sce; sce= sce->id.next) { - if(sce->audio.main == 0.0) - sce->audio.main = 1.0; + if(sce->audio.main == 0.0f) + sce->audio.main = 1.0f; sce->r.ffcodecdata.audio_mixrate = sce->audio.mixrate; sce->r.ffcodecdata.audio_volume = sce->audio.main; - sce->audio.distance_model = 2.0; - sce->audio.doppler_factor = 1.0; - sce->audio.speed_of_sound = 343.3; + sce->audio.distance_model = 2; + sce->audio.doppler_factor = 1.0f; + sce->audio.speed_of_sound = 343.3f; } /* Add default gravity to scenes */ @@ -10108,11 +10257,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main) for(md= ob->modifiers.first; md; md= md->next) { ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); if(clmd) - clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2]/-9.81; + clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2]/-9.81f; } if(ob->soft) - ob->soft->effector_weights->global_gravity = ob->soft->grav/9.81; + ob->soft->effector_weights->global_gravity = ob->soft->grav/9.81f; } /* Normal wind shape is plane */ @@ -10124,6 +10273,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main) ob->pd->shape = PFIELD_SHAPE_PLANE; else if(ob->pd->flag & PFIELD_SURFACE) ob->pd->shape = PFIELD_SHAPE_SURFACE; + + ob->pd->flag |= PFIELD_DO_LOCATION; } } } @@ -10335,31 +10486,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } } - /* clear hanging 'temp' screens from older 2.5 files*/ - if (main->versionfile == 250) { - bScreen *screen, *nextscreen; - wmWindowManager *wm; - wmWindow *win, *nextwin; - - for(screen= main->screen.first; screen; screen= nextscreen) { - nextscreen= screen->id.next; - - if (screen->full == SCREENTEMP) { - /* remove corresponding windows */ - for(wm= main->wm.first; wm; wm=wm->id.next) { - for(win= wm->windows.first; win; win=nextwin) { - nextwin= win->next; - - if(newlibadr(fd, wm->id.lib, win->screen) == screen) - BLI_freelinkN(&wm->windows, win); - } - } - - /* remove screen itself */ - free_libblock(&main->screen, screen); - } - } - } } if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9)) @@ -10497,7 +10623,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* game engine changes */ for(sce = main->scene.first; sce; sce = sce->id.next) { - sce->gm.eyeseparation = 0.10; + sce->gm.eyeseparation = 0.10f; } /* anim viz changes */ @@ -10602,12 +10728,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if (ob->pose) { for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) { - pchan->limitmin[0] *= M_PI/180.0; - pchan->limitmin[1] *= M_PI/180.0; - pchan->limitmin[2] *= M_PI/180.0; - pchan->limitmax[0] *= M_PI/180.0; - pchan->limitmax[1] *= M_PI/180.0; - pchan->limitmax[2] *= M_PI/180.0; + pchan->limitmin[0] *= (float)(M_PI/180.0); + pchan->limitmin[1] *= (float)(M_PI/180.0); + pchan->limitmin[2] *= (float)(M_PI/180.0); + pchan->limitmax[0] *= (float)(M_PI/180.0); + pchan->limitmax[1] *= (float)(M_PI/180.0); + pchan->limitmax[2] *= (float)(M_PI/180.0); do_version_constraints_radians_degrees_250(&pchan->constraints); } @@ -10706,7 +10832,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) int a; for(a=0; a<PE_TOT_BRUSH; a++) - pset->brush[a].strength /= 100.0; + pset->brush[a].strength /= 100.0f; } for(ma = main->mat.first; ma; ma=ma->id.next) @@ -10898,7 +11024,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } - do_version_mdef_250(fd, lib, main); + do_version_mdef_250(main); /* parent type to modifier */ for(ob = main->object.first; ob; ob = ob->id.next) { @@ -10953,44 +11079,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main) tex->saturation= 1.0f; } - //set defaults for obstacle avoidance, recast data - { - Scene *sce; - for(sce = main->scene.first; sce; sce = sce->id.next) - { - - if (sce->gm.levelHeight == 0.f) - sce->gm.levelHeight = 2.f; - - if(sce->gm.recastData.cellsize == 0.0f) - sce->gm.recastData.cellsize = 0.3f; - if(sce->gm.recastData.cellheight == 0.0f) - sce->gm.recastData.cellheight = 0.2f; - if(sce->gm.recastData.agentmaxslope == 0.0f) - sce->gm.recastData.agentmaxslope = M_PI/4; - if(sce->gm.recastData.agentmaxclimb == 0.0f) - sce->gm.recastData.agentmaxclimb = 0.9f; - if(sce->gm.recastData.agentheight == 0.0f) - sce->gm.recastData.agentheight = 2.0f; - if(sce->gm.recastData.agentradius == 0.0f) - sce->gm.recastData.agentradius = 0.6f; - if(sce->gm.recastData.edgemaxlen == 0.0f) - sce->gm.recastData.edgemaxlen = 12.0f; - if(sce->gm.recastData.edgemaxerror == 0.0f) - sce->gm.recastData.edgemaxerror = 1.3f; - if(sce->gm.recastData.regionminsize == 0.0f) - sce->gm.recastData.regionminsize = 50.f; - if(sce->gm.recastData.regionmergesize == 0.0f) - sce->gm.recastData.regionmergesize = 20.f; - if(sce->gm.recastData.vertsperpoly<3) - sce->gm.recastData.vertsperpoly = 6; - if(sce->gm.recastData.detailsampledist == 0.0f) - sce->gm.recastData.detailsampledist = 6.0f; - if(sce->gm.recastData.detailsamplemaxerror == 0.0f) - sce->gm.recastData.detailsamplemaxerror = 1.0f; - } - } - { Curve *cu; for(cu= main->curve.first; cu; cu= cu->id.next) { @@ -11025,7 +11113,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) // bad radius if (brush->unprojected_radius == 0) - brush->unprojected_radius = 0.125; + brush->unprojected_radius = 0.125f; // unusable size if (brush->size == 0) @@ -11067,22 +11155,23 @@ static void do_versions(FileData *fd, Library *lib, Main *main) brush->add_col[1] == 0 && brush->add_col[2] == 0) { - brush->add_col[0] = 1.00; - brush->add_col[1] = 0.39; - brush->add_col[2] = 0.39; + brush->add_col[0] = 1.00f; + brush->add_col[1] = 0.39f; + brush->add_col[2] = 0.39f; } if (brush->sub_col[0] == 0 && brush->sub_col[1] == 0 && brush->sub_col[2] == 0) { - brush->sub_col[0] = 0.39; - brush->sub_col[1] = 0.39; - brush->sub_col[2] = 1.00; + brush->sub_col[0] = 0.39f; + brush->sub_col[1] = 0.39f; + brush->sub_col[2] = 1.00f; } } } } + /* GSOC Sculpt 2010 - Sanity check on Sculpt/Paint settings */ if (main->versionfile < 253) { Scene *sce; @@ -11148,20 +11237,63 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } - /* put compatibility code here until next subversion bump */ - { + if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 1)) { Brush *br; + ParticleSettings *part; + bScreen *sc; + Object *ob; + 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); + br->ob_mode= OB_MODE_ALL_PAINT; } - - } - { - ParticleSettings *part; + for(part = main->particle.first; part; part = part->id.next) { if(part->boids) part->boids->pitch = 1.0f; + + part->flag &= ~PART_HAIR_REGROW; /* this was a deprecated flag before */ + part->kink_amp_clump = 1.f; /* keep old files looking similar */ + } + + 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_INFO) { + SpaceInfo *sinfo= (SpaceInfo *)sl; + ARegion *ar; + + sinfo->rpt_mask= INFO_RPT_OP; + + for (ar= sa->regionbase.first; ar; ar= ar->next) { + if (ar->regiontype == RGN_TYPE_WINDOW) { + ar->v2d.scroll = (V2D_SCROLL_RIGHT); + ar->v2d.align = V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y; /* align bottom left */ + ar->v2d.keepofs = V2D_LOCKOFS_X; + ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT); + ar->v2d.keeptot= V2D_KEEPTOT_BOUNDS; + ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f; + } + } + } + } + } + } + + /* fix rotation actuators for objects so they use real angles (radians) + * since before blender went opensource this strange scalar was used: (1 / 0.02) * 2 * math.pi/360 */ + for(ob= main->object.first; ob; ob= ob->id.next) { + bActuator *act= ob->actuators.first; + while(act) { + if (act->type==ACT_OBJECT) { + /* multiply velocity with 50 in old files */ + bObjectActuator *oa= act->data; + mul_v3_fl(oa->drot, 0.8726646259971648f); + } + act= act->next; + } } } @@ -11181,6 +11313,115 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } } + + if (main->versionfile < 256) { + bScreen *sc; + ScrArea *sa; + Key *key; + + /* Fix for sample line scope initializing with no height */ + for(sc= main->screen.first; sc; sc= sc->id.next) { + sa= sc->areabase.first; + while(sa) { + SpaceLink *sl; + for (sl= sa->spacedata.first; sl; sl= sl->next) { + if(sl->spacetype==SPACE_IMAGE) { + SpaceImage *sima= (SpaceImage *)sl; + if (sima->sample_line_hist.height == 0 ) + sima->sample_line_hist.height = 100; + } + } + sa= sa->next; + } + } + + /* old files could have been saved with slidermin = slidermax = 0.0, but the UI in + * 2.4x would never reveal this to users as a dummy value always ended up getting used + * instead + */ + for (key = main->key.first; key; key = key->id.next) { + KeyBlock *kb; + + for (kb = key->block.first; kb; kb = kb->next) { + if (IS_EQ(kb->slidermin, kb->slidermax) && IS_EQ(kb->slidermax, 0)) + kb->slidermax = kb->slidermin + 1.0f; + } + } + } + + if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 1)) { + /* fix for bones that didn't have arm_roll before */ + bArmature* arm; + Bone* bone; + Object *ob; + + for (arm = main->armature.first; arm; arm = arm->id.next) + for (bone = arm->bonebase.first; bone; bone = bone->next) + do_version_bone_roll_256(bone); + + /* fix for objects which have zero dquat's + * since this is multiplied with the quat rather then added */ + for(ob= main->object.first; ob; ob= ob->id.next) { + if(is_zero_v4(ob->dquat)) { + unit_qt(ob->dquat); + } + if(is_zero_v3(ob->drotAxis) && ob->drotAngle == 0.0f) { + unit_axis_angle(ob->drotAxis, &ob->drotAngle); + } + } + } + + /* put compatibility code here until next subversion bump */ + + { + bScreen *sc; + + /* redraws flag in SpaceTime has been moved to Screen level */ + for (sc = main->screen.first; sc; sc= sc->id.next) { + if (sc->redraws_flag == 0) { + /* just initialise to default? */ + // XXX: we could also have iterated through areas, and taken them from the first timeline available... + sc->redraws_flag = TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN; + } + } + } + + //set defaults for obstacle avoidance, recast data + { + Scene *sce; + for(sce = main->scene.first; sce; sce = sce->id.next) + { + if (sce->gm.levelHeight == 0.f) + sce->gm.levelHeight = 2.f; + + if(sce->gm.recastData.cellsize == 0.0f) + sce->gm.recastData.cellsize = 0.3f; + if(sce->gm.recastData.cellheight == 0.0f) + sce->gm.recastData.cellheight = 0.2f; + if(sce->gm.recastData.agentmaxslope == 0.0f) + sce->gm.recastData.agentmaxslope = M_PI/4; + if(sce->gm.recastData.agentmaxclimb == 0.0f) + sce->gm.recastData.agentmaxclimb = 0.9f; + if(sce->gm.recastData.agentheight == 0.0f) + sce->gm.recastData.agentheight = 2.0f; + if(sce->gm.recastData.agentradius == 0.0f) + sce->gm.recastData.agentradius = 0.6f; + if(sce->gm.recastData.edgemaxlen == 0.0f) + sce->gm.recastData.edgemaxlen = 12.0f; + if(sce->gm.recastData.edgemaxerror == 0.0f) + sce->gm.recastData.edgemaxerror = 1.3f; + if(sce->gm.recastData.regionminsize == 0.0f) + sce->gm.recastData.regionminsize = 50.f; + if(sce->gm.recastData.regionmergesize == 0.0f) + sce->gm.recastData.regionmergesize = 20.f; + if(sce->gm.recastData.vertsperpoly<3) + sce->gm.recastData.vertsperpoly = 6; + if(sce->gm.recastData.detailsampledist == 0.0f) + sce->gm.recastData.detailsampledist = 6.0f; + if(sce->gm.recastData.detailsamplemaxerror == 0.0f) + sce->gm.recastData.detailsamplemaxerror = 1.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! */ @@ -11344,7 +11585,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filename) lib_link_all(fd, bfd->main); //do_versions_after_linking(fd, NULL, bfd->main); // XXX: not here (or even in this function at all)! this causes crashes on many files - Aligorith (July 04, 2010) - lib_verify_nodetree(bfd->main, 1); + lib_verify_nodetree(bfd->main, TRUE); fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */ link_global(fd, bfd); /* as last */ @@ -11476,7 +11717,11 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old) * 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 */ - /*oldnewmap_insert(fd->libmap, bhead->old, id, 1);*/ + + /* 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! */ + if(id->flag & LIB_PRE_EXISTING) + oldnewmap_insert(fd->libmap, bhead->old, id, 1); change_idid_adr_fd(fd, bhead->old, id); // commented because this can print way too much @@ -11732,6 +11977,9 @@ static void expand_lattice(FileData *fd, Main *mainvar, Lattice *lt) { expand_doit(fd, mainvar, lt->ipo); // XXX depreceated - old animation system expand_doit(fd, mainvar, lt->key); + + if (lt->adt) + expand_animdata(fd, mainvar, lt->adt); } @@ -11829,7 +12077,7 @@ typedef struct tConstraintExpandData { Main *mainvar; } tConstraintExpandData; /* callback function used to expand constraint ID-links */ -static void expand_constraint_cb(bConstraint *con, ID **idpoin, void *userdata) +static void expand_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, void *userdata) { tConstraintExpandData *ced= (tConstraintExpandData *)userdata; expand_doit(ced->fd, ced->mainvar, *idpoin); @@ -12312,7 +12560,7 @@ static void give_base_to_groups(Main *mainvar, Scene *scene) base= scene_add_base(scene, ob); base->flag |= SELECT; base->object->flag= base->flag; - ob->recalc |= OB_RECALC_ALL; + ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; scene->basact= base; /* assign the group */ @@ -12324,7 +12572,7 @@ static void give_base_to_groups(Main *mainvar, Scene *scene) } } -static void append_named_part(const bContext *C, Main *mainl, FileData *fd, char *name, int idcode, short flag) +static void append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *name, int idcode, short flag) { Scene *scene= CTX_data_scene(C); Object *ob; @@ -12390,7 +12638,7 @@ static void append_named_part(const bContext *C, Main *mainl, FileData *fd, char } } -void BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, char *name, int idcode, short flag) +void BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *name, int idcode, short flag) { FileData *fd= (FileData*)(*bh); append_named_part(C, mainl, fd, name, idcode, flag); @@ -12427,7 +12675,7 @@ static Main* library_append_begin(const bContext *C, FileData **fd, char *dir) blo_split_main(&(*fd)->mainlist, mainvar); /* which one do we need? */ - mainl = blo_find_main(*fd, &(*fd)->mainlist, dir, G.sce); + mainl = blo_find_main(*fd, &(*fd)->mainlist, dir, G.main->name); /* needed for do_version */ mainl->versionfile= (*fd)->fileversion; @@ -12492,31 +12740,35 @@ static void append_do_cursor(Scene *scene, Library *curlib, short flag) static void library_append_end(const bContext *C, Main *mainl, FileData **fd, int idcode, short flag) { - Main *mainvar= CTX_data_main(C); + Main *mainvar; Scene *scene= CTX_data_scene(C); + Library *curlib; /* make main consistent */ expand_main(*fd, mainl); /* do this when expand found other libs */ read_libraries(*fd, &(*fd)->mainlist); + + curlib= mainl->curlib; /* make the lib path relative if required */ if(flag & FILE_RELPATH) { /* use the full path, this could have been read by other library even */ - BLI_strncpy(mainl->curlib->name, mainl->curlib->filepath, sizeof(mainl->curlib->name)); + BLI_strncpy(curlib->name, curlib->filepath, sizeof(curlib->name)); /* uses current .blend file as reference */ - BLI_path_rel(mainl->curlib->name, G.sce); + BLI_path_rel(curlib->name, G.main->name); } blo_join_main(&(*fd)->mainlist); mainvar= (*fd)->mainlist.first; + mainl= NULL; /* blo_join_main free's mainl, cant use anymore */ lib_link_all(*fd, mainvar); - lib_verify_nodetree(mainvar, 0); - fix_relpaths_library(G.sce, mainvar); /* make all relative paths, relative to the open blend file */ + lib_verify_nodetree(mainvar, FALSE); + fix_relpaths_library(G.main->name, mainvar); /* make all relative paths, relative to the open blend file */ /* give a base to loose objects. If group append, do it for objects too */ if(scene) { @@ -12527,7 +12779,7 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in if (flag & FILE_LINK) { give_base_to_objects(mainvar, scene, NULL, 0); } else { - give_base_to_objects(mainvar, scene, mainl->curlib, 1); + give_base_to_objects(mainvar, scene, curlib, 1); } if (flag & FILE_GROUP_INSTANCE) { @@ -12547,7 +12799,7 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in *fd = NULL; } - append_do_cursor(scene, mainl->curlib, flag); + append_do_cursor(scene, curlib, flag); } void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag) @@ -12564,7 +12816,7 @@ void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** /* tentatively removed, Python should be able to use the split functions too: */ /* BLO_library_append_begin, BLO_library_append_end, BLO_library_append_named_part */ #if 0 -void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, +void BLO_script_library_append(BlendHandle **bh, char *dir, const char *name, int idcode, short flag, Main *mainvar, Scene *scene, ReportList *reports) { FileData *fd= (FileData*)(*bh); @@ -12591,7 +12843,7 @@ static int mainvar_count_libread_blocks(Main *mainvar) a= set_listbasepointers(mainvar, lbarray); while(a--) { - ID *id= lbarray[a]->first; + ID *id; for (id= lbarray[a]->first; id; id= id->next) if (id->flag & LIB_READ) @@ -12632,7 +12884,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) while(fd==NULL) { char newlib_path[240] = { 0 }; printf("Missing library...'\n"); - printf(" current file: %s\n", G.sce); + printf(" current file: %s\n", G.main->name); printf(" absolute lib: %s\n", mainptr->curlib->filepath); printf(" relative lib: %s\n", mainptr->curlib->name); printf(" enter a new path:\n"); @@ -12640,7 +12892,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) if(scanf("%s", newlib_path) > 0) { strcpy(mainptr->curlib->name, newlib_path); strcpy(mainptr->curlib->filepath, newlib_path); - cleanup_path(G.sce, mainptr->curlib->filepath); + cleanup_path(G.main->name, mainptr->curlib->filepath); fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports); |