diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 602 |
1 files changed, 474 insertions, 128 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 26d9fb9e829..30331713463 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -105,6 +105,8 @@ #include "BLI_math.h" #include "BLI_edgehash.h" +#include "BLF_translation.h" + #include "BKE_anim.h" #include "BKE_action.h" #include "BKE_armature.h" @@ -358,36 +360,39 @@ static void *oldnewmap_lookup_and_inc(OldNewMap *onm, void *addr) } /* for libdata, nr has ID code, no increment */ -static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib) +static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib) { - int i; - - if (addr == NULL) return NULL; - + if (addr == NULL) { + return NULL; + } + /* lasthit works fine for non-libdata, linking there is done in same sequence as writing */ if (onm->sorted) { OldNew entry_s, *entry; - + entry_s.old = addr; - + entry = bsearch(&entry_s, onm->entries, onm->nentries, sizeof(OldNew), verg_oldnewmap); if (entry) { ID *id = entry->newp; - + if (id && (!lib || id->lib)) { - return entry->newp; + return id; } } } - - for (i = 0; i < onm->nentries; i++) { - OldNew *entry = &onm->entries[i]; - - if (entry->old == addr) { - ID *id = entry->newp; - - if (id && (!lib || id->lib)) { - return entry->newp; + else { + /* note, this can be a bottle neck when loading some files */ + unsigned int nentries = (unsigned int)onm->nentries; + unsigned int i; + OldNew *entry; + + for (i = 0, entry = onm->entries; i < nentries; i++, entry++) { + if (entry->old == addr) { + ID *id = id = entry->newp; + if (id && (!lib || id->lib)) { + return id; + } } } } @@ -816,7 +821,7 @@ static void decode_blender_header(FileData *fd) /* is the file saved in a different endian * than we need ? */ - if (((((char*)&remove_this_endian_test)[0]==1)?L_ENDIAN:B_ENDIAN) != ((header[8]=='v')?L_ENDIAN:B_ENDIAN)) { + if (((((char *)&remove_this_endian_test)[0] == 1) ? L_ENDIAN : B_ENDIAN) != ((header[8] == 'v') ? L_ENDIAN : B_ENDIAN)) { fd->flags |= FD_FLAGS_SWITCH_ENDIAN; } @@ -938,7 +943,7 @@ static int fd_read_from_memfile(FileData *filedata, void *buffer, unsigned int s if (chunkoffset+readsize > chunk->size) readsize= chunk->size-chunkoffset; - memcpy((char*)buffer + totread, chunk->buf + chunkoffset, readsize); + memcpy((char *)buffer + totread, chunk->buf + chunkoffset, readsize); totread += readsize; filedata->seek += readsize; seek += readsize; @@ -976,13 +981,13 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports) if (fd->flags & FD_FLAGS_FILE_OK) { if (!read_file_dna(fd)) { - BKE_reportf(reports, RPT_ERROR, "Failed to read blend file: \"%s\", incomplete", fd->relabase); + BKE_reportf(reports, RPT_ERROR, "Failed to read blend file '%s', incomplete", fd->relabase); blo_freefiledata(fd); fd = NULL; } - } + } else { - BKE_reportf(reports, RPT_ERROR, "Failed to read blend file: \"%s\", not a blend file", fd->relabase); + BKE_reportf(reports, RPT_ERROR, "Failed to read blend file '%s', not a blend file", fd->relabase); blo_freefiledata(fd); fd = NULL; } @@ -999,7 +1004,8 @@ FileData *blo_openblenderfile(const char *filepath, ReportList *reports) gzfile = BLI_gzopen(filepath, "rb"); if (gzfile == (gzFile)Z_NULL) { - BKE_reportf(reports, RPT_WARNING, "Unable to open \"%s\": %s.", filepath, errno ? strerror(errno) : "Unknown error reading file"); + BKE_reportf(reports, RPT_WARNING, "Unable to open '%s': %s", + filepath, errno ? strerror(errno) : TIP_("unknown error reading file")); return NULL; } else { @@ -1017,7 +1023,7 @@ FileData *blo_openblenderfile(const char *filepath, ReportList *reports) FileData *blo_openblendermemory(void *mem, int memsize, ReportList *reports) { if (!mem || memsize<SIZEOFBLENDERHEADER) { - BKE_report(reports, RPT_WARNING, (mem)? "Unable to read": "Unable to open"); + BKE_report(reports, RPT_WARNING, (mem) ? TIP_("Unable to read"): TIP_("Unable to open")); return NULL; } else { @@ -1126,7 +1132,7 @@ int BLO_is_a_library(const char *path, char *dir, char *group) /* the last part of the dir is a .blend file, no group follows */ *fd = '/'; /* put back the removed slash separating the dir and the .blend file name */ } - else { + else { char *gp = fd + 1; // in case we have a .blend file, gp points to the group /* Find the last slash */ @@ -1290,6 +1296,7 @@ void blo_end_image_pointer_map(FileData *fd, Main *oldmain) if (NULL == newimaadr(fd, ibuf)) { /* so was restored */ BLI_remlink(&ima->ibufs, ibuf); ima->bindcode = 0; + ima->tpageflag &= ~IMA_GLBIND_IS_DATA; ima->gputexture = NULL; } } @@ -1628,6 +1635,19 @@ static void IDP_LibLinkProperty(IDProperty *UNUSED(prop), int UNUSED(switch_endi { } +/* ************ READ ID *************** */ + +static void direct_link_id(FileData *fd, ID *id) +{ + /*link direct data of ID properties*/ + if (id->properties) { + id->properties = newdataadr(fd, id->properties); + if (id->properties) { /* this case means the data was written incorrectly, it should not happen */ + IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + } + } +} + /* ************ READ CurveMapping *************** */ /* cuma itself has been read! */ @@ -1821,7 +1841,7 @@ static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list) for (dvar= driver->variables.first; dvar; dvar= dvar->next) { DRIVER_TARGETS_LOOPER(dvar) - { + { /* only relink if still used */ if (tarIndex < dvar->num_targets) dtar->id = newlibadr(fd, id->lib, dtar->id); @@ -2396,6 +2416,14 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) link_list(fd, &node->inputs); link_list(fd, &node->outputs); + link_list(fd, &node->internal_links); + for (link = node->internal_links.first; link; link = link->next) { + link->fromnode = newdataadr(fd, link->fromnode); + link->fromsock = newdataadr(fd, link->fromsock); + link->tonode = newdataadr(fd, link->tonode); + link->tosock = newdataadr(fd, link->tosock); + } + if (node->type == CMP_NODE_MOVIEDISTORTION) { node->storage = newmclipadr(fd, node->storage); } @@ -2404,8 +2432,18 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) if (node->storage) { /* could be handlerized at some point */ - if (ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) - direct_link_curvemapping(fd, node->storage); + if (ntree->type==NTREE_SHADER) { + if (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB) { + direct_link_curvemapping(fd, node->storage); + } + else if (node->type==SH_NODE_SCRIPT) { + NodeShaderScript *nss = (NodeShaderScript *) node->storage; + nss->bytecode = newdataadr(fd, nss->bytecode); + nss->prop = newdataadr(fd, nss->prop); + if (nss->prop) + IDP_DirectLinkProperty(nss->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + } + } else if (ntree->type==NTREE_COMPOSIT) { if (ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) direct_link_curvemapping(fd, node->storage); @@ -2527,8 +2565,13 @@ static void direct_link_constraints(FileData *fd, ListBase *lb) break; case CONSTRAINT_TYPE_KINEMATIC: { + bKinematicConstraint *data = con->data; + con->lin_error = 0.f; con->rot_error = 0.f; + + /* version patch for runtime flag, was not cleared in some case */ + data->flag &= ~CONSTRAINT_IK_AUTO; } case CONSTRAINT_TYPE_CHILDOF: { @@ -2709,8 +2752,10 @@ static void direct_link_lamp(FileData *fd, Lamp *la) direct_link_curvemapping(fd, la->curfalloff); la->nodetree= newdataadr(fd, la->nodetree); - if (la->nodetree) + if (la->nodetree) { + direct_link_id(fd, &la->nodetree->id); direct_link_nodetree(fd, la->nodetree); + } la->preview = direct_link_preview_image(fd, la->preview); } @@ -2773,7 +2818,7 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb) cp += 2; } - data+= elemsize; + data += elemsize; } } @@ -2808,7 +2853,7 @@ static void lib_link_mball(FileData *fd, Main *main) if (mb->adt) lib_link_animdata(fd, &mb->id, mb->adt); for (a = 0; a < mb->totcol; a++) - mb->mat[a]= newlibadr_us(fd, mb->id.lib, mb->mat[a]); + mb->mat[a] = newlibadr_us(fd, mb->id.lib, mb->mat[a]); mb->ipo = newlibadr_us(fd, mb->id.lib, mb->ipo); // XXX deprecated - old animation system @@ -2876,8 +2921,10 @@ static void direct_link_world(FileData *fd, World *wrld) } wrld->nodetree = newdataadr(fd, wrld->nodetree); - if (wrld->nodetree) + if (wrld->nodetree) { + direct_link_id(fd, &wrld->nodetree->id); direct_link_nodetree(fd, wrld->nodetree); + } wrld->preview = direct_link_preview_image(fd, wrld->preview); } @@ -3000,6 +3047,7 @@ static void direct_link_image(FileData *fd, Image *ima) /* if not restored, we keep the binded opengl index */ if (ima->ibufs.first == NULL) { ima->bindcode = 0; + ima->tpageflag &= ~IMA_GLBIND_IS_DATA; ima->gputexture = NULL; } @@ -3043,7 +3091,7 @@ static void lib_link_curve(FileData *fd, Main *main) cu->taperobj = newlibadr(fd, cu->id.lib, cu->taperobj); cu->textoncurve = newlibadr(fd, cu->id.lib, cu->textoncurve); cu->vfont = newlibadr_us(fd, cu->id.lib, cu->vfont); - cu->vfontb = newlibadr_us(fd, cu->id.lib, cu->vfontb); + cu->vfontb = newlibadr_us(fd, cu->id.lib, cu->vfontb); cu->vfonti = newlibadr_us(fd, cu->id.lib, cu->vfonti); cu->vfontbi = newlibadr_us(fd, cu->id.lib, cu->vfontbi); @@ -3077,7 +3125,7 @@ static void direct_link_curve(FileData *fd, Curve *cu) cu->mat = newdataadr(fd, cu->mat); test_pointer_array(fd, (void **)&cu->mat); cu->str = newdataadr(fd, cu->str); - cu->strinfo= newdataadr(fd, cu->strinfo); + cu->strinfo= newdataadr(fd, cu->strinfo); cu->tb = newdataadr(fd, cu->tb); if (cu->vfont == NULL) link_list(fd, &(cu->nurb)); @@ -3088,14 +3136,14 @@ static void direct_link_curve(FileData *fd, Curve *cu) if (cu->tb) { memcpy(tb, cu->tb, cu->totbox*sizeof(TextBox)); MEM_freeN(cu->tb); - cu->tb = tb; + cu->tb = tb; } else { cu->totbox = 1; cu->actbox = 1; cu->tb = tb; cu->tb[0].w = cu->linewidth; - } + } if (cu->wordspace == 0.0f) cu->wordspace = 1.0f; } @@ -3184,8 +3232,10 @@ static void direct_link_texture(FileData *fd, Tex *tex) tex->ot = newdataadr(fd, tex->ot); tex->nodetree = newdataadr(fd, tex->nodetree); - if (tex->nodetree) + if (tex->nodetree) { + direct_link_id(fd, &tex->nodetree->id); direct_link_nodetree(fd, tex->nodetree); + } tex->preview = direct_link_preview_image(fd, tex->preview); @@ -3244,8 +3294,10 @@ static void direct_link_material(FileData *fd, Material *ma) ma->ramp_spec = newdataadr(fd, ma->ramp_spec); ma->nodetree = newdataadr(fd, ma->nodetree); - if (ma->nodetree) + if (ma->nodetree) { + direct_link_id(fd, &ma->nodetree->id); direct_link_nodetree(fd, ma->nodetree); + } ma->preview = direct_link_preview_image(fd, ma->preview); ma->gpumaterial.first = ma->gpumaterial.last = NULL; @@ -3260,7 +3312,7 @@ static const char *ptcache_data_struct[] = { "", // BPHYS_DATA_ROTATION "", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */ "", // BPHYS_DATA_SIZE: - "", // BPHYS_DATA_TIMES: + "", // BPHYS_DATA_TIMES: "BoidData" // case BPHYS_DATA_BOIDS: }; static void direct_link_pointcache(FileData *fd, PointCache *cache) @@ -3335,6 +3387,8 @@ static void lib_link_partdeflect(FileData *fd, ID *id, PartDeflect *pd) { if (pd && pd->tex) pd->tex = newlibadr_us(fd, id->lib, pd->tex); + if (pd && pd->f_source) + pd->f_source = newlibadr_us(fd, id->lib, pd->f_source); } static void lib_link_particlesettings(FileData *fd, Main *main) @@ -3363,32 +3417,31 @@ static void lib_link_particlesettings(FileData *fd, Main *main) if (part->dupliweights.first && part->dup_group) { int index_ok = 0; /* check for old files without indices (all indexes 0) */ - dw = part->dupliweights.first; if (part->dupliweights.first == part->dupliweights.last) { /* special case for only one object in the group */ index_ok = 1; } - else { - for (; dw; dw=dw->next) { + else { + for (dw = part->dupliweights.first; dw; dw = dw->next) { if (dw->index > 0) { index_ok = 1; break; } } } - + if (index_ok) { /* if we have indexes, let's use them */ - dw = part->dupliweights.first; - for (; dw; dw=dw->next) { + for (dw = part->dupliweights.first; dw; dw = dw->next) { GroupObject *go = (GroupObject *)BLI_findlink(&part->dup_group->gobject, dw->index); - dw->ob = go ? go->ob : NULL; + dw->ob = go ? newlibadr(fd, part->id.lib, dw->ob) : NULL; } } else { /* otherwise try to get objects from own library (won't work on library linked groups) */ - for (; dw; dw=dw->next) + for (dw = part->dupliweights.first; dw; dw = dw->next) { dw->ob = newlibadr(fd, part->id.lib, dw->ob); + } } } else { @@ -3567,10 +3620,10 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) psys->clmd->clothObject = NULL; psys->clmd->sim_parms= newdataadr(fd, psys->clmd->sim_parms); - psys->clmd->sim_parms->effector_weights = NULL; psys->clmd->coll_parms= newdataadr(fd, psys->clmd->coll_parms); if (psys->clmd->sim_parms) { + psys->clmd->sim_parms->effector_weights = NULL; if (psys->clmd->sim_parms->presets > 10) psys->clmd->sim_parms->presets = 0; } @@ -3605,7 +3658,7 @@ static void lib_link_mtface(FileData *fd, Mesh *me, MTFace *mtface, int totface) static void lib_link_customdata_mtface(FileData *fd, Mesh *me, CustomData *fdata, int totface) { - int i; + int i; for (i = 0; i < fdata->totlayer; i++) { CustomDataLayer *layer = &fdata->layers[i]; @@ -3624,12 +3677,13 @@ static void lib_link_customdata_mtpoly(FileData *fd, Mesh *me, CustomData *pdata if (layer->type == CD_MTEXPOLY) { MTexPoly *tf= layer->data; - int i; + int j; - for (i = 0; i < totface; i++, tf++) { + for (j = 0; j < totface; j++, tf++) { tf->tpage = newlibadr(fd, me->id.lib, tf->tpage); - if (tf->tpage && tf->tpage->id.us==0) + if (tf->tpage && tf->tpage->id.us == 0) { tf->tpage->id.us = 1; + } } } } @@ -3688,7 +3742,7 @@ static void lib_link_mesh(FileData *fd, Main *main) /* * Re-tessellate, even if the polys were just created from tessfaces, this * is important because it: - * - fill the CD_POLYINDEX layer + * - fill the CD_ORIGINDEX layer * - gives consistency of tessface between loading from a file and * converting an edited BMesh back into a mesh (i.e. it replaces * quad tessfaces in a loaded mesh immediately, instead of lazily @@ -3783,7 +3837,7 @@ static void direct_link_customdata(FileData *fd, CustomData *data, int count) /* annoying workaround for bug [#31079] loading legacy files with * no polygons _but_ have stale customdata */ if (UNLIKELY(count == 0 && data->layers == NULL && data->totlayer != 0)) { - memset(data, 0, sizeof(*data)); + CustomData_reset(data); return; } @@ -4053,7 +4107,7 @@ static void lib_link_object(FileData *fd, Main *main) if (paf->type == EFF_PARTICLE) { paf->group = newlibadr_us(fd, ob->id.lib, paf->group); } - } + } for (sens = ob->sensors.first; sens; sens = sens->next) { for (a = 0; a < sens->totlinks; a++) @@ -4317,10 +4371,12 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) if (smd->domain->ptcaches[1].first || smd->domain->point_cache[1]) { if (smd->domain->point_cache[1]) { PointCache *cache = newdataadr(fd, smd->domain->point_cache[1]); - if (cache->flag & PTCACHE_FAKE_SMOKE) - ; /* Smoke was already saved in "new format" and this cache is a fake one. */ - else + if (cache->flag & PTCACHE_FAKE_SMOKE) { + /* Smoke was already saved in "new format" and this cache is a fake one. */ + } + else { printf("High resolution smoke cache not available due to pointcache update. Please reset the simulation.\n"); + } BKE_ptcache_free(cache); } smd->domain->ptcaches[1].first = NULL; @@ -4333,6 +4389,9 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) smd->coll = NULL; smd->flow = newdataadr(fd, smd->flow); smd->flow->smd = smd; + smd->flow->dm = NULL; + smd->flow->verts_old = NULL; + smd->flow->numverts = 0; smd->flow->psys = newdataadr(fd, smd->flow->psys); } else if (smd->type == MOD_SMOKE_TYPE_COLL) { @@ -4341,11 +4400,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) smd->coll = newdataadr(fd, smd->coll); if (smd->coll) { smd->coll->smd = smd; - smd->coll->points = NULL; - smd->coll->numpoints = 0; + smd->coll->verts_old = NULL; + smd->coll->numverts = 0; + smd->coll->dm = NULL; } else { smd->type = 0; + smd->flow = NULL; + smd->domain = NULL; + smd->coll = NULL; } } } @@ -4576,7 +4639,7 @@ static void direct_link_object(FileData *fd, Object *ob) direct_link_partdeflect(ob->pd); ob->soft= newdataadr(fd, ob->soft); if (ob->soft) { - SoftBody *sb = ob->soft; + SoftBody *sb = ob->soft; sb->bpoint = NULL; // init pointers so it gets rebuilt nicely sb->bspring = NULL; @@ -4753,8 +4816,7 @@ static void lib_link_scene(FileData *fd, Main *main) base->object = newlibadr_us(fd, sce->id.lib, base->object); if (base->object == NULL) { - BKE_reportf_wrap(fd->reports, RPT_WARNING, - "LIB ERROR: Object lost from scene:'%s\'", + BKE_reportf_wrap(fd->reports, RPT_WARNING, TIP_("LIB ERROR: object lost from scene: '%s'"), sce->id.name + 2); BLI_remlink(&sce->base, base); if (base == sce->basact) sce->basact = NULL; @@ -5020,7 +5082,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) ed->seqbasep = (ListBase *)(poin+offset); else ed->seqbasep = &ed->seqbase; - } + } /* stack */ link_list(fd, &(ed->metastack)); @@ -5054,7 +5116,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) } if (sce->r.ffcodecdata.properties) { sce->r.ffcodecdata.properties = newdataadr(fd, sce->r.ffcodecdata.properties); - if (sce->r.ffcodecdata.properties) { + if (sce->r.ffcodecdata.properties) { IDP_DirectLinkProperty(sce->r.ffcodecdata.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } @@ -5065,8 +5127,10 @@ static void direct_link_scene(FileData *fd, Scene *sce) link_list(fd, &(sce->r.layers)); sce->nodetree = newdataadr(fd, sce->nodetree); - if (sce->nodetree) + if (sce->nodetree) { + direct_link_id(fd, &sce->nodetree->id); direct_link_nodetree(fd, sce->nodetree); + } direct_link_view_settings(fd, &sce->view_settings); } @@ -5980,11 +6044,11 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) if (newmain->curlib) { if (BLI_path_cmp(newmain->curlib->filepath, lib->filepath) == 0) { BKE_reportf_wrap(fd->reports, RPT_WARNING, - "Library '%s', '%s' had multiple instances, save and reload!", + TIP_("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); +/* change_idid_adr_fd(fd, lib, newmain->curlib); */ BLI_remlink(&main->library, lib); MEM_freeN(lib); @@ -5998,8 +6062,10 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) BLI_strncpy(lib->filepath, lib->name, sizeof(lib->name)); cleanup_path(fd->relabase, lib->filepath); -// printf("direct_link_library: name %s\n", lib->name); -// printf("direct_link_library: filename %s\n", lib->filename); +#if 0 + printf("direct_link_library: name %s\n", lib->name); + printf("direct_link_library: filename %s\n", lib->filename); +#endif /* new main */ newmain= MEM_callocN(sizeof(Main), "directlink"); @@ -6436,6 +6502,8 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID bhead = read_data_into_oldnewmap(fd, bhead, allocname); /* init pointers direct data */ + direct_link_id(fd, id); + switch (GS(id->name)) { case ID_WM: direct_link_windowmanager(fd, (wmWindowManager *)id); @@ -6532,14 +6600,6 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID break; } - /*link direct data of ID properties*/ - if (id->properties) { - id->properties = newdataadr(fd, id->properties); - if (id->properties) { /* this case means the data was written incorrectly, it should not happen */ - IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } - } - oldnewmap_free_unused(fd->datamap); oldnewmap_clear(fd->datamap); @@ -6602,7 +6662,7 @@ void convert_tface_mt(FileData *fd, Main *main) G.main = main; if (!(do_version_tface(main, 1))) { - BKE_report(fd->reports, RPT_WARNING, "Texface conversion problem. Error in console"); + BKE_report(fd->reports, RPT_WARNING, "Texface conversion problem (see error in console)"); } //XXX hack, material.c uses G.main allover the place, instead of main @@ -6775,7 +6835,6 @@ static void do_versions_nodetree_socket_use_flags_2_62(bNodeTree *ntree) static void do_versions_nodetree_multi_file_output_format_2_62_1(Scene *sce, bNodeTree *ntree) { bNode *node; - bNodeSocket *sock; for (node = ntree->nodes.first; node; node = node->next) { if (node->type == CMP_NODE_OUTPUT_FILE) { @@ -6852,6 +6911,7 @@ static void do_versions_nodetree_multi_file_output_format_2_62_1(Scene *sce, bNo } else if (node->type==CMP_NODE_OUTPUT_MULTI_FILE__DEPRECATED) { NodeImageMultiFile *nimf = node->storage; + bNodeSocket *sock; /* CMP_NODE_OUTPUT_MULTI_FILE has been redeclared as CMP_NODE_OUTPUT_FILE */ node->type = CMP_NODE_OUTPUT_FILE; @@ -7005,6 +7065,20 @@ static void do_version_ntree_dilateerode_264(void *UNUSED(data), ID *UNUSED(id), } } +static void do_version_ntree_defocus_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + bNode *node; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_DEFOCUS) { + NodeDefocus *data = node->storage; + if (data->maxblur == 0.0f) { + data->maxblur = 16.0f; + } + } + } +} + static void do_version_ntree_mask_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) { bNode *node; @@ -7047,6 +7121,88 @@ static void do_version_ntree_tex_coord_from_dupli_264(void *UNUSED(data), ID *UN node->flag |= NODE_OPTIONS; } +static void do_version_node_cleanup_dynamic_sockets_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + bNode *node; + bNodeSocket *sock; + + for (node = ntree->nodes.first; node; node = node->next) { + if (!ELEM(node->type, NODE_GROUP, CMP_NODE_IMAGE)) { + for (sock = node->inputs.first; sock; sock = sock->next) + sock->flag &= ~SOCK_DYNAMIC; + for (sock = node->outputs.first; sock; sock = sock->next) + sock->flag &= ~SOCK_DYNAMIC; + } + } +} + +static void do_version_node_fix_internal_links_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + bNode *node; + bNodeLink *link, *nextlink; + + for (node = ntree->nodes.first; node; node = node->next) { + for (link = node->internal_links.first; link; link = nextlink) { + nextlink = link->next; + if (!link->fromnode || !link->fromsock || !link->tonode || !link->tosock) { + BLI_remlink(&node->internal_links, link); + } + } + } +} + +static void do_version_logic_264(ListBase *regionbase) +{ + ARegion *ar; + + /* view settings for logic changed */ + for (ar = regionbase->first; ar; ar = ar->next) { + if (ar->regiontype == RGN_TYPE_WINDOW) { + if (ar->v2d.keeptot == 0) { + ar->v2d.maxzoom = 1.5f; + + ar->v2d.keepzoom = V2D_KEEPZOOM | V2D_LIMITZOOM | V2D_KEEPASPECT; + ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS; + ar->v2d.align = V2D_ALIGN_NO_POS_Y | V2D_ALIGN_NO_NEG_X; + ar->v2d.keepofs = V2D_KEEPOFS_Y; + } + } + } + + +} + +static void do_versions_affine_tracker_track(MovieTrackingTrack *track) +{ + int i; + + for (i = 0; i < track->markersnr; i++) { + MovieTrackingMarker *marker = &track->markers[i]; + + if (is_zero_v2(marker->pattern_corners[0]) && is_zero_v2(marker->pattern_corners[1]) && + is_zero_v2(marker->pattern_corners[2]) && is_zero_v2(marker->pattern_corners[3])) + { + marker->pattern_corners[0][0] = track->pat_min[0]; + marker->pattern_corners[0][1] = track->pat_min[1]; + + marker->pattern_corners[1][0] = track->pat_max[0]; + marker->pattern_corners[1][1] = track->pat_min[1]; + + marker->pattern_corners[2][0] = track->pat_max[0]; + marker->pattern_corners[2][1] = track->pat_max[1]; + + marker->pattern_corners[3][0] = track->pat_min[0]; + marker->pattern_corners[3][1] = track->pat_max[1]; + } + + if (is_zero_v2(marker->search_min) && is_zero_v2(marker->search_max)) { + copy_v2_v2(marker->search_min, track->search_min); + copy_v2_v2(marker->search_max, track->search_max); + } + } +} + + static void do_versions(FileData *fd, Library *lib, Main *main) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -7160,9 +7316,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main) 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; + SpaceClip *sclip = (SpaceClip *)sl; + if (sclip->scopes.track_preview_height == 0) + sclip->scopes.track_preview_height = 120; } } } @@ -7242,10 +7398,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if ( (ob->dsize[i] == 0.0f) || /* simple case, user never touched dsize */ (ob->size[i] == 0.0f)) /* cant scale the dsize to give a non zero result, so fallback to 1.0f */ { - ob->dscale[i]= 1.0f; + ob->dscale[i] = 1.0f; } else { - ob->dscale[i]= (ob->size[i] + ob->dsize[i]) / ob->size[i]; + ob->dscale[i] = (ob->size[i] + ob->dsize[i]) / ob->size[i]; } } } @@ -7370,8 +7526,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main) prop = BKE_bproperty_object_get(ob, "Text"); if (prop) { BKE_reportf_wrap(fd->reports, RPT_WARNING, - "Game property name conflict in object: \"%s\".\nText objects reserve the " - "[\"Text\"] game property to change their content through Logic Bricks.", + TIP_("Game property name conflict in object '%s':\ntext objects reserve the " + "['Text'] game property to change their content through logic bricks"), ob->id.name + 2); } } @@ -7564,13 +7720,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if (main->versionfile < 263) { /* Default for old files is to save particle rotations to pointcache */ ParticleSettings *part; - for (part = main->particle.first; part; part = part->id.next) + for (part = main->particle.first; part; part = part->id.next) { part->flag |= PART_ROTATIONS; - { - /* Default for old files is to save particle rotations to pointcache */ - ParticleSettings *part; - for (part = main->particle.first; part; part = part->id.next) - part->flag |= PART_ROTATIONS; } } @@ -7765,6 +7916,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 10)) { { Scene *scene; + bNodeTreeType *ntreetype; // composite redesign for (scene=main->scene.first; scene; scene=scene->id.next) { if (scene->nodetree) { @@ -7773,6 +7925,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } } + ntreetype = ntreeGetType(NTREE_COMPOSIT); + + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_ntree_defocus_264); + } { @@ -7814,32 +7971,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) track = clip->tracking.tracks.first; while (track) { - int i; - - for (i = 0; i < track->markersnr; i++) { - MovieTrackingMarker *marker = &track->markers[i]; - - if (is_zero_v2(marker->pattern_corners[0]) && is_zero_v2(marker->pattern_corners[1]) && - is_zero_v2(marker->pattern_corners[2]) && is_zero_v2(marker->pattern_corners[3])) - { - marker->pattern_corners[0][0] = track->pat_min[0]; - marker->pattern_corners[0][1] = track->pat_min[1]; - - marker->pattern_corners[1][0] = track->pat_max[0]; - marker->pattern_corners[1][1] = track->pat_min[1]; - - marker->pattern_corners[2][0] = track->pat_max[0]; - marker->pattern_corners[2][1] = track->pat_max[1]; - - marker->pattern_corners[3][0] = track->pat_min[0]; - marker->pattern_corners[3][1] = track->pat_max[1]; - } - - if (is_zero_v2(marker->search_min) && is_zero_v2(marker->search_max)) { - copy_v2_v2(marker->search_min, track->search_min); - copy_v2_v2(marker->search_max, track->search_max); - } - } + do_versions_affine_tracker_track(track); track = track->next; } @@ -7983,6 +8115,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) { Mesh *me; for (me = main->mesh.first; me; me = me->id.next) { + CustomData_update_typemap(&me->vdata); CustomData_free_layers(&me->vdata, CD_MSTICKY, me->totvert); } } @@ -8016,6 +8149,221 @@ static void do_versions(FileData *fd, Library *lib, Main *main) do_version_ntree_tex_coord_from_dupli_264(NULL, NULL, ntree); } + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 2)) { + MovieClip *clip; + + for (clip = main->movieclip.first; clip; clip = clip->id.next) { + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *tracking_object; + + for (tracking_object = tracking->objects.first; + tracking_object; + tracking_object = tracking_object->next) + { + if (tracking_object->keyframe1 == 0 && tracking_object->keyframe2 == 0) { + tracking_object->keyframe1 = tracking->settings.keyframe1; + tracking_object->keyframe2 = tracking->settings.keyframe2; + } + } + } + } + + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 3)) { + /* smoke branch */ + { + 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) { + /* keep branch saves if possible */ + if (!smd->domain->flame_max_temp) { + smd->domain->burning_rate = 0.75f; + smd->domain->flame_smoke = 1.0f; + smd->domain->flame_vorticity = 0.5f; + smd->domain->flame_ignition = 1.25f; + smd->domain->flame_max_temp = 1.75f; + smd->domain->adapt_threshold = 0.02f; + smd->domain->adapt_margin = 4; + smd->domain->flame_smoke_color[0] = 0.7f; + smd->domain->flame_smoke_color[1] = 0.7f; + smd->domain->flame_smoke_color[2] = 0.7f; + } + } + else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) { + if (!smd->flow->texture_size) { + smd->flow->fuel_amount = 1.0; + smd->flow->surface_distance = 1.5; + smd->flow->color[0] = 0.7f; + smd->flow->color[1] = 0.7f; + smd->flow->color[2] = 0.7f; + smd->flow->texture_size = 1.0f; + } + } + } + } + } + } + + /* render border for viewport */ + { + 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_VIEW3D) { + View3D *v3d = (View3D *)sl; + if (v3d->render_border.xmin == 0.0f && v3d->render_border.ymin == 0.0f && + v3d->render_border.xmax == 0.0f && v3d->render_border.ymax == 0.0f) + { + v3d->render_border.xmax = 1.0f; + v3d->render_border.ymax = 1.0f; + } + } + } + } + } + } + } + + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 4)) { + /* Fix for old node flags: Apparently the SOCK_DYNAMIC flag has been in use for other + * purposes before and then removed and later reused for SOCK_DYNAMIC. This socket should + * only be used by certain node types which don't use template lists, cleaning this up here. + */ + bNodeTreeType *ntreetype; + bNodeTree *ntree; + + ntreetype = ntreeGetType(NTREE_COMPOSIT); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_node_cleanup_dynamic_sockets_264); + ntreetype = ntreeGetType(NTREE_SHADER); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_node_cleanup_dynamic_sockets_264); + ntreetype = ntreeGetType(NTREE_TEXTURE); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_node_cleanup_dynamic_sockets_264); + + for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) + do_version_node_cleanup_dynamic_sockets_264(NULL, NULL, ntree); + } + + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 5)) { + /* set a unwrapping margin and ABF by default */ + Scene *scene; + + for (scene=main->scene.first; scene; scene=scene->id.next) { + if (scene->toolsettings->uvcalc_margin == 0.0f) { + scene->toolsettings->uvcalc_margin = 0.001f; + scene->toolsettings->unwrapper = 0; + } + } + } + + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 6)) { + /* Fix for bug #32982, internal_links list could get corrupted from r51630 onward. + * Simply remove bad internal_links lists to avoid NULL pointers. + */ + bNodeTreeType *ntreetype; + bNodeTree *ntree; + + ntreetype = ntreeGetType(NTREE_COMPOSIT); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_internal_links_264); + ntreetype = ntreeGetType(NTREE_SHADER); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_internal_links_264); + ntreetype = ntreeGetType(NTREE_TEXTURE); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_internal_links_264); + + for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) + do_version_node_fix_internal_links_264(NULL, NULL, ntree); + + } + + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 6)) { + 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; + if ( sa->spacetype == SPACE_LOGIC) + do_version_logic_264(&sa->regionbase); + + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_LOGIC) + do_version_logic_264(&sl->regionbase); + } + } + } + } + + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 7)) { + /* convert tiles size from resolution and number of tiles */ + { + Scene *scene; + + for (scene = main->scene.first; scene; scene = scene->id.next) { + if (scene->r.tilex == 0 || scene->r.tiley == 1) { + /* scene could be set for panoramic rendering, so clamp with the + * lowest possible tile size value + */ + scene->r.tilex = max_ii(scene->r.xsch * scene->r.size / scene->r.xparts / 100, 8); + scene->r.tiley = max_ii(scene->r.ysch * scene->r.size / scene->r.yparts / 100, 8); + } + } + } + + /* collision masks */ + { + Object *ob; + for (ob = main->object.first; ob; ob = ob->id.next) { + if (ob->col_group == 0) { + ob->col_group = 0x01; + ob->col_mask = 0xff; + } + } + } + + /* fallbck resection method settings */ + { + MovieClip *clip; + + for (clip = main->movieclip.first; clip; clip = clip->id.next) { + if (clip->tracking.settings.reconstruction_success_threshold == 0.0f) { + clip->tracking.settings.reconstruction_success_threshold = 1e-3; + } + } + } + } + + if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 7)) { + MovieClip *clip; + + for (clip = main->movieclip.first; clip; clip = clip->id.next) { + MovieTrackingTrack *track; + MovieTrackingObject *object; + + for (track = clip->tracking.tracks.first; track; track = track->next) { + do_versions_affine_tracker_track(track); + } + + for (object = clip->tracking.objects.first; object; object = object->next) { + for (track = object->tracks.first; track; track = track->next) { + do_versions_affine_tracker_track(track); + } + } + } + } + /* 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! */ @@ -8672,7 +9020,7 @@ static void expand_curve(FileData *fd, Main *mainvar, Curve *cu) } expand_doit(fd, mainvar, cu->vfont); - expand_doit(fd, mainvar, cu->vfontb); + expand_doit(fd, mainvar, cu->vfontb); expand_doit(fd, mainvar, cu->vfonti); expand_doit(fd, mainvar, cu->vfontbi); expand_doit(fd, mainvar, cu->key); @@ -9494,7 +9842,7 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in if ((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) { blo_freefiledata(*fd); *fd = NULL; - } + } } void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag) @@ -9549,8 +9897,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) if (fd == NULL) { /* printf and reports for now... its important users know this */ - BKE_reportf_wrap(basefd->reports, RPT_INFO, - "read library: '%s', '%s'", + BKE_reportf_wrap(basefd->reports, RPT_INFO, TIP_("Read library: '%s', '%s'"), mainptr->curlib->filepath, mainptr->curlib->name); fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports); @@ -9603,8 +9950,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) else mainptr->curlib->filedata = NULL; if (fd == NULL) { - BKE_reportf_wrap(basefd->reports, RPT_WARNING, - "Can't find lib '%s'", + BKE_reportf_wrap(basefd->reports, RPT_WARNING, TIP_("Cannot find lib '%s'"), mainptr->curlib->filepath); } } @@ -9623,7 +9969,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) append_id_part(fd, mainptr, id, &realid); if (!realid) { BKE_reportf_wrap(fd->reports, RPT_WARNING, - "LIB ERROR: %s:'%s' missing from '%s'", + TIP_("LIB ERROR: %s: '%s' missing from '%s'"), BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath); } @@ -9655,7 +10001,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) if (id->flag & LIB_READ) { BLI_remlink(lbarray[a], id); BKE_reportf_wrap(basefd->reports, RPT_WARNING, - "LIB ERROR: %s:'%s' unread libblock missing from '%s'", + TIP_("LIB ERROR: %s: '%s' unread lib block missing from '%s'"), BKE_idcode_to_name(GS(id->name)), id->name + 2, mainptr->curlib->filepath); change_idid_adr(mainlist, basefd, id, NULL); |