diff options
Diffstat (limited to 'source/blender/blenloader')
17 files changed, 5240 insertions, 4451 deletions
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 11f34732cfc..ef02e7d7034 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -39,15 +39,18 @@ extern "C" { struct BlendThumbnail; struct bScreen; struct LinkNode; +struct ListBase; struct Main; struct MemFile; struct ReportList; struct Scene; +struct ViewLayer; struct UserDef; struct View3D; struct bContext; struct BHead; struct FileData; +struct wmWindowManager; typedef struct BlendHandle BlendHandle; @@ -65,12 +68,19 @@ typedef struct BlendFileData { int globalf; char filename[1024]; /* 1024 = FILE_MAX */ - struct bScreen *curscreen; + struct bScreen *curscreen; /* TODO think this isn't needed anymore? */ struct Scene *curscene; + struct ViewLayer *cur_view_layer; /* layer to activate in workspaces when reading without UI */ eBlenFileType type; } BlendFileData; +typedef struct WorkspaceConfigFileData { + struct Main *main; /* has to be freed when done reading file data */ + + struct ListBase workspaces; +} WorkspaceConfigFileData; + /* skip reading some data-block types (may want to skip screen data too). */ typedef enum eBLOReadSkip { @@ -105,6 +115,7 @@ void BLO_blendhandle_close(BlendHandle *bh); /***/ #define BLO_GROUP_MAX 32 +#define BLO_EMBEDDED_STARTUP_BLEND "<startup.blend>" bool BLO_has_bfile_extension(const char *str); bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name); @@ -124,17 +135,19 @@ struct ID *BLO_library_link_named_part(struct Main *mainl, BlendHandle **bh, con struct ID *BLO_library_link_named_part_ex( struct Main *mainl, BlendHandle **bh, const short idcode, const char *name, const int flag, - struct Scene *scene, struct View3D *v3d); -void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct View3D *v3d); + struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer); +void BLO_library_link_end( + struct Main *mainl, BlendHandle **bh, int flag, + struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer); void BLO_library_link_copypaste(struct Main *mainl, BlendHandle *bh); void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname); -BlendFileData *blo_read_blendafterruntime(int file, const char *name, int actualsize, struct ReportList *reports); - /* internal function but we need to expose it */ -void blo_lib_link_screen_restore(struct Main *newmain, struct bScreen *curscreen, struct Scene *curscene); +void blo_lib_link_restore( + struct Main *newmain, struct wmWindowManager *curwm, + struct Scene *curscene, struct ViewLayer *cur_render_layer); typedef void (*BLOExpandDoitCallback) (void *fdhandle, struct Main *mainvar, void *idv); @@ -143,12 +156,18 @@ void BLO_expand_main(void *fdhandle, struct Main *mainvar); /* Update defaults in startup.blend & userprefs.blend, without having to save and embed it */ void BLO_update_defaults_userpref_blend(void); -void BLO_update_defaults_startup_blend(struct Main *mainvar); +void BLO_update_defaults_startup_blend(struct Main *mainvar, const char *app_template); + +/* Version patch user preferences. */ +void BLO_version_defaults_userpref_blend(struct Main *mainvar, struct UserDef *userdef); struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath); struct Main *BLO_main_from_memfile(struct MemFile *memfile, struct Main *bmain, struct Scene **r_scene); +/* datafiles (generated theme) */ +extern const struct bTheme U_theme_default; + #ifdef __cplusplus } #endif diff --git a/source/blender/blenloader/BLO_runtime.h b/source/blender/blenloader/BLO_runtime.h deleted file mode 100644 index 09f25bdca53..00000000000 --- a/source/blender/blenloader/BLO_runtime.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - * - */ - -#ifndef __BLO_RUNTIME_H__ -#define __BLO_RUNTIME_H__ - -/** \file BLO_runtime.h - * \ingroup blenloader - */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct BlendFileData; -struct Main; -struct ReportList; - -int BLO_is_a_runtime(const char *file); -struct BlendFileData *BLO_read_runtime(const char *file, struct ReportList *reports); - -bool BLO_main_validate_libraries(struct Main *bmain, struct ReportList *reports); - -#ifdef __cplusplus -} -#endif - -#endif /* __BLO_RUNTIME_H__ */ diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h index f6d0be6f5f0..d615514f081 100644 --- a/source/blender/blenloader/BLO_writefile.h +++ b/source/blender/blenloader/BLO_writefile.h @@ -44,4 +44,6 @@ extern bool BLO_write_file( extern bool BLO_write_file_mem( struct Main *mainvar, struct MemFile *compare, struct MemFile *current, int write_flags); +bool BLO_main_validate_libraries(struct Main *bmain, struct ReportList *reports); + #endif diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index dd0a8543b9f..e0453e71a05 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -29,6 +29,8 @@ set(INC ../blenkernel ../blenlib ../blentranslation + ../depsgraph + ../draw ../imbuf ../makesdna ../makesrna @@ -46,21 +48,22 @@ set(INC_SYS ) set(SRC + ${CMAKE_SOURCE_DIR}/release/datafiles/userdef/userdef_default_theme.c intern/blend_validate.c intern/readblenentry.c intern/readfile.c - intern/runtime.c intern/undofile.c intern/versioning_250.c intern/versioning_260.c intern/versioning_270.c + intern/versioning_280.c intern/versioning_defaults.c intern/versioning_legacy.c + intern/versioning_userdef.c intern/writefile.c BLO_blend_defs.h BLO_readfile.h - BLO_runtime.h BLO_undofile.h BLO_writefile.h intern/readfile.h diff --git a/source/blender/blenloader/intern/blend_validate.c b/source/blender/blenloader/intern/blend_validate.c index 4fb5d0e1286..1bc503719b4 100644 --- a/source/blender/blenloader/intern/blend_validate.c +++ b/source/blender/blenloader/intern/blend_validate.c @@ -47,7 +47,7 @@ #include "BKE_report.h" #include "BLO_readfile.h" -#include "BLO_runtime.h" +#include "BLO_writefile.h" #include "readfile.h" diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index 7488d62bb3c..6fd77c34977 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -393,6 +393,9 @@ BlendFileData *BLO_read_from_memfile( /* makes lookup of existing images in old main */ blo_make_image_pointer_map(fd, oldmain); + /* makes lookup of existing light caches in old main */ + blo_make_scene_pointer_map(fd, oldmain); + /* makes lookup of existing video clips in old main */ blo_make_movieclip_pointer_map(fd, oldmain); @@ -403,6 +406,9 @@ BlendFileData *BLO_read_from_memfile( bfd = blo_read_file_internal(fd, filename); + /* ensures relinked light caches are not freed */ + blo_end_scene_pointer_map(fd, oldmain); + /* ensures relinked images are not freed */ blo_end_image_pointer_map(fd, oldmain); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 9478c2e0351..84a57e9449a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -54,25 +54,30 @@ /* allow readfile to use deprecated functionality */ #define DNA_DEPRECATED_ALLOW +/* Allow using DNA struct members that are marked as private for read/write. + * Note: Each header that uses this needs to define its own way of handling + * it. There's no generic implementation, direct use does nothing. */ +#define DNA_PRIVATE_READ_WRITE_ALLOW #include "DNA_anim_types.h" #include "DNA_armature_types.h" -#include "DNA_actuator_types.h" #include "DNA_brush_types.h" #include "DNA_camera_types.h" #include "DNA_cachefile_types.h" #include "DNA_cloth_types.h" -#include "DNA_controller_types.h" +#include "DNA_collection_types.h" #include "DNA_constraint_types.h" #include "DNA_dynamicpaint_types.h" #include "DNA_effect_types.h" #include "DNA_fileglobal_types.h" #include "DNA_genfile.h" -#include "DNA_group_types.h" #include "DNA_gpencil_types.h" +#include "DNA_gpencil_modifier_types.h" +#include "DNA_shader_fx_types.h" #include "DNA_ipo_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" +#include "DNA_layer_types.h" #include "DNA_lamp_types.h" #include "DNA_linestyle_types.h" #include "DNA_meta_types.h" @@ -85,12 +90,11 @@ #include "DNA_object_types.h" #include "DNA_packedFile_types.h" #include "DNA_particle_types.h" -#include "DNA_property_types.h" +#include "DNA_lightprobe_types.h" #include "DNA_rigidbody_types.h" #include "DNA_text_types.h" #include "DNA_view3d_types.h" #include "DNA_screen_types.h" -#include "DNA_sensor_types.h" #include "DNA_sdna_types.h" #include "DNA_scene_types.h" #include "DNA_sequence_types.h" @@ -99,10 +103,13 @@ #include "DNA_sound_types.h" #include "DNA_space_types.h" #include "DNA_vfont_types.h" +#include "DNA_workspace_types.h" #include "DNA_world_types.h" #include "DNA_movieclip_types.h" #include "DNA_mask_types.h" +#include "RNA_access.h" + #include "MEM_guardedalloc.h" #include "BLI_endian_switch.h" @@ -118,22 +125,26 @@ #include "BKE_brush.h" #include "BKE_cachefile.h" #include "BKE_cloth.h" +#include "BKE_collection.h" #include "BKE_constraint.h" #include "BKE_context.h" #include "BKE_curve.h" -#include "BKE_depsgraph.h" #include "BKE_effect.h" #include "BKE_fcurve.h" #include "BKE_global.h" // for G -#include "BKE_group.h" +#include "BKE_gpencil.h" +#include "BKE_gpencil_modifier.h" +#include "BKE_layer.h" #include "BKE_library.h" // for which_libbase #include "BKE_library_idmap.h" +#include "BKE_library_override.h" #include "BKE_library_query.h" #include "BKE_idcode.h" #include "BKE_idprop.h" #include "BKE_material.h" #include "BKE_main.h" // for Main #include "BKE_mesh.h" // for ME_ defines (patching) +#include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_multires.h" #include "BKE_node.h" // for tree type defines @@ -143,13 +154,18 @@ #include "BKE_particle.h" #include "BKE_pointcache.h" #include "BKE_report.h" -#include "BKE_sca.h" // for init_actuator #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_sequencer.h" +#include "BKE_shader_fx.h" #include "BKE_outliner_treehash.h" #include "BKE_sound.h" #include "BKE_colortools.h" +#include "BKE_workspace.h" + +#include "DRW_engine.h" + +#include "DEG_depsgraph.h" #include "NOD_common.h" #include "NOD_socket.h" @@ -249,10 +265,15 @@ typedef struct OldNewMap { /* local prototypes */ static void *read_struct(FileData *fd, BHead *bh, const char *blockname); static void direct_link_modifiers(FileData *fd, ListBase *lb); -static void convert_tface_mt(FileData *fd, Main *main); static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const char *name); static BHead *find_bhead_from_idname(FileData *fd, const char *idname); +#ifdef USE_COLLECTION_COMPAT_28 +static void expand_scene_collection(FileData *fd, Main *mainvar, SceneCollection *sc); +#endif +static void direct_link_animdata(FileData *fd, AnimData *adt); +static void lib_link_animdata(FileData *fd, ID *id, AnimData *adt); + /* this function ensures that reports are printed, * in the case of libraray linking errors this is important! * @@ -1013,20 +1034,6 @@ static int *read_file_thumbnail(FileData *fd) return blend_thumb; } -static int fd_read_from_file(FileData *filedata, void *buffer, unsigned int size) -{ - int readsize = read(filedata->filedes, buffer, size); - - if (readsize < 0) { - readsize = EOF; - } - else { - filedata->seek += readsize; - } - - return readsize; -} - static int fd_read_gzip_from_file(FileData *filedata, void *buffer, unsigned int size) { int readsize = gzread(filedata->gzfiledes, buffer, size); @@ -1327,6 +1334,8 @@ void blo_freefiledata(FileData *fd) oldnewmap_free(fd->imamap); if (fd->movieclipmap) oldnewmap_free(fd->movieclipmap); + if (fd->scenemap) + oldnewmap_free(fd->scenemap); if (fd->soundmap) oldnewmap_free(fd->soundmap); if (fd->packedmap) @@ -1397,6 +1406,9 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, cha if (BLO_has_bfile_extension(r_dir) && BLI_is_file(r_dir)) { break; } + else if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) { + break; + } if (prev_slash) { *prev_slash = c; @@ -1514,6 +1526,13 @@ static void *newimaadr(FileData *fd, const void *adr) /* used to restore im return NULL; } +static void *newsceadr(FileData *fd, const void *adr) /* used to restore scene data after undo */ +{ + if (fd->scenemap && adr) + return oldnewmap_lookup_and_inc(fd->scenemap, adr, true); + return NULL; +} + static void *newmclipadr(FileData *fd, const void *adr) /* used to restore movie clip data after undo */ { if (fd->movieclipmap && adr) @@ -1619,6 +1638,37 @@ void blo_clear_proxy_pointers_from_lib(Main *oldmain) } } +void blo_make_scene_pointer_map(FileData *fd, Main *oldmain) +{ + Scene *sce = oldmain->scene.first; + + fd->scenemap = oldnewmap_new(); + + for (; sce; sce = sce->id.next) { + if (sce->eevee.light_cache) { + struct LightCache *light_cache = sce->eevee.light_cache; + oldnewmap_insert(fd->scenemap, light_cache, light_cache, 0); + } + } +} + +void blo_end_scene_pointer_map(FileData *fd, Main *oldmain) +{ + OldNew *entry = fd->scenemap->entries; + Scene *sce = oldmain->scene.first; + int i; + + /* used entries were restored, so we put them to zero */ + for (i = 0; i < fd->scenemap->nentries; i++, entry++) { + if (entry->nr > 0) + entry->newp = NULL; + } + + for (; sce; sce = sce->id.next) { + sce->eevee.light_cache = newsceadr(fd, sce->eevee.light_cache); + } +} + void blo_make_image_pointer_map(FileData *fd, Main *oldmain) { Image *ima = oldmain->image.first; @@ -1635,9 +1685,9 @@ void blo_make_image_pointer_map(FileData *fd, Main *oldmain) oldnewmap_insert(fd->imamap, ima->gputexture[a], ima->gputexture[a], 0); if (ima->rr) oldnewmap_insert(fd->imamap, ima->rr, ima->rr, 0); - for (a=0; a < IMA_MAX_RENDER_SLOT; a++) - if (ima->renders[a]) - oldnewmap_insert(fd->imamap, ima->renders[a], ima->renders[a], 0); + LISTBASE_FOREACH(RenderSlot *, slot, &ima->renderslots) + if (slot->render) + oldnewmap_insert(fd->imamap, slot->render, slot->render, 0); } for (; sce; sce = sce->id.next) { if (sce->nodetree && sce->nodetree->previews) { @@ -1670,13 +1720,12 @@ void blo_end_image_pointer_map(FileData *fd, Main *oldmain) if (ima->cache == NULL) { ima->tpageflag &= ~IMA_GLBIND_IS_DATA; for (i = 0; i < TEXTARGET_COUNT; i++) { - ima->bindcode[i] = 0; ima->gputexture[i] = NULL; } ima->rr = NULL; } - for (i = 0; i < IMA_MAX_RENDER_SLOT; i++) - ima->renders[i] = newimaadr(fd, ima->renders[i]); + LISTBASE_FOREACH(RenderSlot *, slot, &ima->renderslots) + slot->render = newimaadr(fd, slot->render); for (i = 0; i < TEXTARGET_COUNT; i++) ima->gputexture[i] = newimaadr(fd, ima->gputexture[i]); @@ -2235,6 +2284,42 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p /* ************ READ ID *************** */ +static void lib_link_id(FileData *fd, Main *main) +{ + ListBase *lbarray[MAX_LIBARRAY]; + int base_count, i; + + base_count = set_listbasepointers(main, lbarray); + + for (i = 0; i < base_count; i++) { + ListBase *lb = lbarray[i]; + ID *id; + + for (id = lb->first; id; id = id->next) { + if (id->override_static) { + id->override_static->reference = newlibadr_us(fd, id->lib, id->override_static->reference); + id->override_static->storage = newlibadr_us(fd, id->lib, id->override_static->storage); + } + } + } +} + +static void direct_link_id_override_property_operation_cb(FileData *fd, void *data) +{ + IDOverrideStaticPropertyOperation *opop = data; + + opop->subitem_reference_name = newdataadr(fd, opop->subitem_reference_name); + opop->subitem_local_name = newdataadr(fd, opop->subitem_local_name); +} + +static void direct_link_id_override_property_cb(FileData *fd, void *data) +{ + IDOverrideStaticProperty *op = data; + + op->rna_path = newdataadr(fd, op->rna_path); + link_list_ex(fd, &op->operations, direct_link_id_override_property_operation_cb); +} + static void direct_link_id(FileData *fd, ID *id) { /*link direct data of ID properties*/ @@ -2248,6 +2333,17 @@ static void direct_link_id(FileData *fd, ID *id) /* That way datablock reading not going through main read_libblock() function are still in a clear tag state. * (glowering at certain nodetree fake datablock here...). */ id->tag = 0; + + /* Link direct data of overrides. */ + if (id->override_static) { + id->override_static = newdataadr(fd, id->override_static); + link_list_ex(fd, &id->override_static->properties, direct_link_id_override_property_cb); + } + + DrawDataList *drawdata = DRW_drawdatalist_from_id(id); + if (drawdata) { + BLI_listbase_clear((ListBase *)drawdata); + } } /* ************ READ CurveMapping *************** */ @@ -2268,6 +2364,7 @@ static void direct_link_curvemapping(FileData *fd, CurveMapping *cumap) } /* ************ READ Brush *************** */ + /* library brush linking after fileread */ static void lib_link_brush(FileData *fd, Main *main) { @@ -2283,6 +2380,11 @@ static void lib_link_brush(FileData *fd, Main *main) brush->toggle_brush = newlibadr(fd, brush->id.lib, brush->toggle_brush); brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve); + /* link default grease pencil palette */ + if (brush->gpencil_settings != NULL) { + brush->gpencil_settings->material = newlibadr_us(fd, brush->id.lib, brush->gpencil_settings->material); + } + brush->id.tag &= ~LIB_TAG_NEED_LINK; } } @@ -2294,6 +2396,7 @@ static void direct_link_brush(FileData *fd, Brush *brush) /* fallof curve */ brush->curve = newdataadr(fd, brush->curve); + brush->gradient = newdataadr(fd, brush->gradient); if (brush->curve) @@ -2301,11 +2404,29 @@ static void direct_link_brush(FileData *fd, Brush *brush) else BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP); + /* grease pencil */ + brush->gpencil_settings = newdataadr(fd, brush->gpencil_settings); + if (brush->gpencil_settings != NULL) { + brush->gpencil_settings->curve_sensitivity = newdataadr(fd, brush->gpencil_settings->curve_sensitivity); + brush->gpencil_settings->curve_strength = newdataadr(fd, brush->gpencil_settings->curve_strength); + brush->gpencil_settings->curve_jitter = newdataadr(fd, brush->gpencil_settings->curve_jitter); + + if (brush->gpencil_settings->curve_sensitivity) + direct_link_curvemapping(fd, brush->gpencil_settings->curve_sensitivity); + + if (brush->gpencil_settings->curve_strength) + direct_link_curvemapping(fd, brush->gpencil_settings->curve_strength); + + if (brush->gpencil_settings->curve_jitter) + direct_link_curvemapping(fd, brush->gpencil_settings->curve_jitter); + } + brush->preview = NULL; brush->icon_imbuf = NULL; } /* ************ READ Palette *************** */ + static void lib_link_palette(FileData *fd, Main *main) { /* only link ID pointers */ @@ -2320,6 +2441,7 @@ static void lib_link_palette(FileData *fd, Main *main) static void direct_link_palette(FileData *fd, Palette *palette) { + /* palette itself has been read */ link_list(fd, &palette->colors); } @@ -2553,6 +2675,7 @@ static void direct_link_fcurves(FileData *fd, ListBase *list) /* compiled expression data will need to be regenerated (old pointer may still be set here) */ driver->expr_comp = NULL; + driver->expr_simple = NULL; /* give the driver a fresh chance - the operating environment may be different now * (addons, etc. may be different) so the driver namespace may be sane now [#32155] @@ -2767,6 +2890,7 @@ static void direct_link_animdata(FileData *fd, AnimData *adt) /* link drivers */ link_list(fd, &adt->drivers); direct_link_fcurves(fd, &adt->drivers); + adt->driver_array = NULL; /* link overrides */ // TODO... @@ -2811,6 +2935,81 @@ static void direct_link_cachefile(FileData *fd, CacheFile *cache_file) direct_link_animdata(fd, cache_file->adt); } +/* ************ READ WORKSPACES *************** */ + +static void lib_link_workspaces(FileData *fd, Main *bmain) +{ + for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { + ListBase *layouts = BKE_workspace_layouts_get(workspace); + ID *id = (ID *)workspace; + + if ((id->tag & LIB_TAG_NEED_LINK) == 0) { + continue; + } + IDP_LibLinkProperty(id->properties, fd); + id_us_ensure_real(id); + + for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) { + layout->screen = newlibadr_us(fd, id->lib, layout->screen); + + layout_next = layout->next; + if (layout->screen) { + if (ID_IS_LINKED(id)) { + layout->screen->winid = 0; + if (layout->screen->temp) { + /* delete temp layouts when appending */ + BKE_workspace_layout_remove(bmain, workspace, layout); + } + } + } + } + + id->tag &= ~LIB_TAG_NEED_LINK; + } +} + +static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main *main) +{ + link_list(fd, BKE_workspace_layouts_get(workspace)); + link_list(fd, &workspace->hook_layout_relations); + link_list(fd, &workspace->owner_ids); + link_list(fd, &workspace->tools); + + for (WorkSpaceDataRelation *relation = workspace->hook_layout_relations.first; + relation; + relation = relation->next) + { + relation->parent = newglobadr(fd, relation->parent); /* data from window - need to access through global oldnew-map */ + relation->value = newdataadr(fd, relation->value); + } + + /* Same issue/fix as in direct_link_workspace_link_scene_data: Can't read workspace data + * when reading windows, so have to update windows after/when reading workspaces. */ + for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) { + for (wmWindow *win = wm->windows.first; win; win = win->next) { + WorkSpaceLayout *act_layout = newdataadr(fd, BKE_workspace_active_layout_get(win->workspace_hook)); + if (act_layout) { + BKE_workspace_active_layout_set(win->workspace_hook, act_layout); + } + } + } + + for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) { + tref->runtime = NULL; + tref->properties = newdataadr(fd, tref->properties); + IDP_DirectLinkGroup_OrFree(&tref->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + } + + workspace->status_text = NULL; +} + +static void lib_link_workspace_instance_hook(FileData *fd, WorkSpaceInstanceHook *hook, ID *id) +{ + WorkSpace *workspace = BKE_workspace_active_get(hook); + BKE_workspace_active_set(hook, newlibadr(fd, id->lib, workspace)); +} + + /* ************ READ MOTION PATHS *************** */ /* direct data for cache */ @@ -2822,6 +3021,10 @@ static void direct_link_motionpath(FileData *fd, bMotionPath *mpath) /* relink points cache */ mpath->points = newdataadr(fd, mpath->points); + + mpath->points_vbo = NULL; + mpath->batch_line = NULL; + mpath->batch_points = NULL; } /* ************ READ NODE TREE *************** */ @@ -3265,6 +3468,11 @@ static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist) } /* own ipo, all constraints have it */ con->ipo = newlibadr_us(fd, id->lib, con->ipo); // XXX deprecated - old animation system + + /* If linking from a library, clear 'local' static override flag. */ + if (id->lib != NULL) { + con->flag &= ~CONSTRAINT_STATICOVERRIDE_LOCAL; + } } /* relink all ID-blocks used by the constraints */ @@ -3338,7 +3546,7 @@ static void lib_link_pose(FileData *fd, Main *bmain, Object *ob, bPose *pose) bool rebuild = false; if (fd->memfile == NULL) { - if (ob->proxy || (ob->id.lib==NULL && arm->id.lib)) { + if (ob->proxy || ob->id.lib != arm->id.lib) { rebuild = true; } } @@ -3382,7 +3590,7 @@ static void lib_link_pose(FileData *fd, Main *bmain, Object *ob, bPose *pose) if (rebuild) { - DAG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); + DEG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); BKE_pose_tag_recalc(bmain, pose); } } @@ -3420,6 +3628,9 @@ static void direct_link_bones(FileData *fd, Bone *bone) bone->prop = newdataadr(fd, bone->prop); IDP_DirectLinkGroup_OrFree(&bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + bone->bbone_next = newdataadr(fd, bone->bbone_next); + bone->bbone_prev = newdataadr(fd, bone->bbone_prev); + bone->flag &= ~BONE_DRAW_ACTIVE; link_list(fd, &bone->childbase); @@ -3434,7 +3645,6 @@ static void direct_link_armature(FileData *fd, bArmature *arm) link_list(fd, &arm->bonebase); arm->edbo = NULL; - arm->sketch = NULL; arm->adt = newdataadr(fd, arm->adt); direct_link_animdata(fd, arm->adt); @@ -3460,6 +3670,11 @@ static void lib_link_camera(FileData *fd, Main *main) ca->dof_ob = newlibadr(fd, ca->id.lib, ca->dof_ob); + for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) { + bgpic->ima = newlibadr_us(fd, ca->id.lib, bgpic->ima); + bgpic->clip = newlibadr_us(fd, ca->id.lib, bgpic->clip); + } + ca->id.tag &= ~LIB_TAG_NEED_LINK; } } @@ -3469,6 +3684,12 @@ static void direct_link_camera(FileData *fd, Camera *ca) { ca->adt = newdataadr(fd, ca->adt); direct_link_animdata(fd, ca->adt); + + link_list(fd, &ca->bg_images); + + for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) { + bgpic->iuser.ok = 1; + } } @@ -3481,14 +3702,6 @@ static void lib_link_lamp(FileData *fd, Main *main) IDP_LibLinkProperty(la->id.properties, fd); lib_link_animdata(fd, &la->id, la->adt); - for (int a = 0; a < MAX_MTEX; a++) { - MTex *mtex = la->mtex[a]; - if (mtex) { - mtex->tex = newlibadr_us(fd, la->id.lib, mtex->tex); - mtex->object = newlibadr(fd, la->id.lib, mtex->object); - } - } - la->ipo = newlibadr_us(fd, la->id.lib, la->ipo); // XXX deprecated - old animation system if (la->nodetree) { @@ -3503,15 +3716,9 @@ static void lib_link_lamp(FileData *fd, Main *main) static void direct_link_lamp(FileData *fd, Lamp *la) { - int a; - la->adt = newdataadr(fd, la->adt); direct_link_animdata(fd, la->adt); - for (a=0; a<MAX_MTEX; a++) { - la->mtex[a] = newdataadr(fd, la->mtex[a]); - } - la->curfalloff = newdataadr(fd, la->curfalloff); if (la->curfalloff) direct_link_curvemapping(fd, la->curfalloff); @@ -3636,6 +3843,7 @@ static void direct_link_mball(FileData *fd, MetaBall *mb) mb->editelems = NULL; /* mb->edit_elems.first= mb->edit_elems.last= NULL;*/ mb->lastelem = NULL; + mb->batch_cache = NULL; } /* ************ READ WORLD ***************** */ @@ -3649,14 +3857,6 @@ static void lib_link_world(FileData *fd, Main *main) wrld->ipo = newlibadr_us(fd, wrld->id.lib, wrld->ipo); // XXX deprecated - old animation system - for (int a = 0; a < MAX_MTEX; a++) { - MTex *mtex = wrld->mtex[a]; - if (mtex) { - mtex->tex = newlibadr_us(fd, wrld->id.lib, mtex->tex); - mtex->object = newlibadr(fd, wrld->id.lib, mtex->object); - } - } - if (wrld->nodetree) { lib_link_ntree(fd, &wrld->id, wrld->nodetree); wrld->nodetree->id.lib = wrld->id.lib; @@ -3669,15 +3869,9 @@ static void lib_link_world(FileData *fd, Main *main) static void direct_link_world(FileData *fd, World *wrld) { - int a; - wrld->adt = newdataadr(fd, wrld->adt); direct_link_animdata(fd, wrld->adt); - for (a = 0; a < MAX_MTEX; a++) { - wrld->mtex[a] = newdataadr(fd, wrld->mtex[a]); - } - wrld->nodetree = newdataadr(fd, wrld->nodetree); if (wrld->nodetree) { direct_link_id(fd, &wrld->nodetree->id); @@ -3784,23 +3978,22 @@ static void direct_link_image(FileData *fd, Image *ima) if (!ima->cache) { ima->tpageflag &= ~IMA_GLBIND_IS_DATA; for (int i = 0; i < TEXTARGET_COUNT; i++) { - ima->bindcode[i] = 0; ima->gputexture[i] = NULL; } ima->rr = NULL; } - ima->repbind = NULL; - /* undo system, try to restore render buffers */ + link_list(fd, &(ima->renderslots)); if (fd->imamap) { - int a; - - for (a = 0; a < IMA_MAX_RENDER_SLOT; a++) - ima->renders[a] = newimaadr(fd, ima->renders[a]); + LISTBASE_FOREACH(RenderSlot *, slot, &ima->renderslots) { + slot->render = newimaadr(fd, slot->render); + } } else { - memset(ima->renders, 0, sizeof(ima->renders)); + LISTBASE_FOREACH(RenderSlot *, slot, &ima->renderslots) { + slot->render = NULL; + } ima->last_render_slot = ima->render_slot; } @@ -3904,6 +4097,7 @@ static void direct_link_curve(FileData *fd, Curve *cu) cu->editnurb = NULL; cu->editfont = NULL; + cu->batch_cache = NULL; for (nu = cu->nurb.first; nu; nu = nu->next) { nu->bezt = newdataadr(fd, nu->bezt); @@ -3930,14 +4124,6 @@ static void lib_link_texture(FileData *fd, Main *main) tex->ima = newlibadr_us(fd, tex->id.lib, tex->ima); tex->ipo = newlibadr_us(fd, tex->id.lib, tex->ipo); // XXX deprecated - old animation system - if (tex->env) - tex->env->object = newlibadr(fd, tex->id.lib, tex->env->object); - if (tex->pd) - tex->pd->object = newlibadr(fd, tex->id.lib, tex->pd->object); - if (tex->vd) - tex->vd->object = newlibadr(fd, tex->id.lib, tex->vd->object); - if (tex->ot) - tex->ot->object = newlibadr(fd, tex->id.lib, tex->ot->object); if (tex->nodetree) { lib_link_ntree(fd, &tex->id, tex->nodetree); @@ -3955,34 +4141,6 @@ static void direct_link_texture(FileData *fd, Tex *tex) direct_link_animdata(fd, tex->adt); tex->coba = newdataadr(fd, tex->coba); - tex->env = newdataadr(fd, tex->env); - if (tex->env) { - tex->env->ima = NULL; - memset(tex->env->cube, 0, 6 * sizeof(void *)); - tex->env->ok= 0; - } - tex->pd = newdataadr(fd, tex->pd); - if (tex->pd) { - tex->pd->point_tree = NULL; - tex->pd->coba = newdataadr(fd, tex->pd->coba); - tex->pd->falloff_curve = newdataadr(fd, tex->pd->falloff_curve); - if (tex->pd->falloff_curve) { - direct_link_curvemapping(fd, tex->pd->falloff_curve); - } - tex->pd->point_data = NULL; /* runtime data */ - } - - tex->vd = newdataadr(fd, tex->vd); - if (tex->vd) { - tex->vd->dataset = NULL; - tex->vd->ok = 0; - } - else { - if (tex->type == TEX_VOXELDATA) - tex->vd = MEM_callocN(sizeof(VoxelData), "direct_link_texture VoxelData"); - } - - tex->ot = newdataadr(fd, tex->ot); tex->nodetree = newdataadr(fd, tex->nodetree); if (tex->nodetree) { @@ -4007,21 +4165,23 @@ static void lib_link_material(FileData *fd, Main *main) lib_link_animdata(fd, &ma->id, ma->adt); ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo); // XXX deprecated - old animation system - ma->group = newlibadr_us(fd, ma->id.lib, ma->group); - - for (int a = 0; a < MAX_MTEX; a++) { - MTex *mtex = ma->mtex[a]; - if (mtex) { - mtex->tex = newlibadr_us(fd, ma->id.lib, mtex->tex); - mtex->object = newlibadr(fd, ma->id.lib, mtex->object); - } - } if (ma->nodetree) { lib_link_ntree(fd, &ma->id, ma->nodetree); ma->nodetree->id.lib = ma->id.lib; } + /* relink grease pencil settings */ + if (ma->gp_style != NULL) { + MaterialGPencilStyle *gp_style = ma->gp_style; + if (gp_style->sima != NULL) { + gp_style->sima = newlibadr_us(fd, ma->id.lib, gp_style->sima); + } + if (gp_style->ima != NULL) { + gp_style->ima = newlibadr_us(fd, ma->id.lib, gp_style->ima); + } + } + ma->id.tag &= ~LIB_TAG_NEED_LINK; } } @@ -4029,19 +4189,11 @@ static void lib_link_material(FileData *fd, Main *main) static void direct_link_material(FileData *fd, Material *ma) { - int a; - ma->adt = newdataadr(fd, ma->adt); direct_link_animdata(fd, ma->adt); - for (a = 0; a < MAX_MTEX; a++) { - ma->mtex[a] = newdataadr(fd, ma->mtex[a]); - } ma->texpaintslot = NULL; - ma->ramp_col = newdataadr(fd, ma->ramp_col); - ma->ramp_spec = newdataadr(fd, ma->ramp_spec); - ma->nodetree = newdataadr(fd, ma->nodetree); if (ma->nodetree) { direct_link_id(fd, &ma->nodetree->id); @@ -4050,6 +4202,8 @@ static void direct_link_material(FileData *fd, Material *ma) ma->preview = direct_link_preview_image(fd, ma->preview); BLI_listbase_clear(&ma->gpumaterial); + + ma->gp_style = newdataadr(fd, ma->gp_style); } /* ************ READ PARTICLE SETTINGS ***************** */ @@ -4165,40 +4319,8 @@ static void lib_link_particlesettings(FileData *fd, Main *main) } if (part->dupliweights.first && part->dup_group) { - ParticleDupliWeight *dw; - int index_ok = 0; - /* check for old files without indices (all indexes 0) */ - if (BLI_listbase_is_single(&part->dupliweights)) { - /* special case for only one object in the group */ - index_ok = 1; - } - 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 */ - for (dw = part->dupliweights.first; dw; dw = dw->next) { - /* Do not try to restore pointer here, we have to search for group objects in another - * separated step. - * Reason is, the used group may be linked from another library, which has not yet - * been 'lib_linked'. - * Since dw->ob is not considered as an object user (it does not make objet directly linked), - * we may have no valid way to retrieve it yet. - * See T49273. */ - dw->ob = NULL; - } - } - else { - /* otherwise try to get objects from own library (won't work on library linked groups) */ - for (dw = part->dupliweights.first; dw; dw = dw->next) { - dw->ob = newlibadr(fd, part->id.lib, dw->ob); - } + for (ParticleDupliWeight *dw = part->dupliweights.first; dw; dw = dw->next) { + dw->ob = newlibadr(fd, part->id.lib, dw->ob); } } else { @@ -4385,7 +4507,6 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) BLI_listbase_clear(&psys->pathcachebufs); BLI_listbase_clear(&psys->childcachebufs); psys->pdd = NULL; - psys->renderdata = NULL; if (psys->clmd) { psys->clmd = newdataadr(fd, psys->clmd); @@ -4401,7 +4522,7 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) psys->clmd->sim_parms->presets = 0; } - psys->hair_in_dm = psys->hair_out_dm = NULL; + psys->hair_in_mesh = psys->hair_out_mesh = NULL; psys->clmd->solver_result = NULL; } @@ -4412,55 +4533,15 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) psys->tree = NULL; psys->bvhtree = NULL; + + psys->orig_psys = NULL; + psys->batch_cache = NULL; } return; } /* ************ READ MESH ***************** */ -static void lib_link_mtface(FileData *fd, Mesh *me, MTFace *mtface, int totface) -{ - MTFace *tf= mtface; - int i; - - /* Add pseudo-references (not fake users!) to images used by texface. A - * little bogus; it would be better if each mesh consistently added one ref - * to each image it used. - z0r */ - for (i = 0; i < totface; i++, tf++) { - tf->tpage = newlibadr_real_us(fd, me->id.lib, tf->tpage); - } -} - -static void lib_link_customdata_mtface(FileData *fd, Mesh *me, CustomData *fdata, int totface) -{ - int i; - for (i = 0; i < fdata->totlayer; i++) { - CustomDataLayer *layer = &fdata->layers[i]; - - if (layer->type == CD_MTFACE) - lib_link_mtface(fd, me, layer->data, totface); - } - -} - -static void lib_link_customdata_mtpoly(FileData *fd, Mesh *me, CustomData *pdata, int totface) -{ - int i; - - for (i=0; i < pdata->totlayer; i++) { - CustomDataLayer *layer = &pdata->layers[i]; - - if (layer->type == CD_MTEXPOLY) { - MTexPoly *tf= layer->data; - int j; - - for (j = 0; j < totface; j++, tf++) { - tf->tpage = newlibadr_real_us(fd, me->id.lib, tf->tpage); - } - } - } -} - static void lib_link_mesh(FileData *fd, Main *main) { Mesh *me; @@ -4487,19 +4568,9 @@ static void lib_link_mesh(FileData *fd, Main *main) me->ipo = newlibadr_us(fd, me->id.lib, me->ipo); // XXX: deprecated: old anim sys me->key = newlibadr_us(fd, me->id.lib, me->key); me->texcomesh = newlibadr_us(fd, me->id.lib, me->texcomesh); - - lib_link_customdata_mtface(fd, me, &me->fdata, me->totface); - lib_link_customdata_mtpoly(fd, me, &me->pdata, me->totpoly); - if (me->mr && me->mr->levels.first) { - lib_link_customdata_mtface(fd, me, &me->mr->fdata, - ((MultiresLevel*)me->mr->levels.first)->totface); - } } } - /* convert texface options to material */ - convert_tface_mt(fd, main); - for (me = main->mesh.first; me; me = me->id.next) { if (me->id.tag & LIB_TAG_NEED_LINK) { /*check if we need to convert mfaces to mpolys*/ @@ -4655,7 +4726,6 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) mesh->dvert = newdataadr(fd, mesh->dvert); mesh->mloopcol = newdataadr(fd, mesh->mloopcol); mesh->mloopuv = newdataadr(fd, mesh->mloopuv); - mesh->mtpoly = newdataadr(fd, mesh->mtpoly); mesh->mselect = newdataadr(fd, mesh->mselect); /* animdata */ @@ -4674,18 +4744,13 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) mesh->bb = NULL; mesh->edit_btmesh = NULL; + BKE_mesh_runtime_reset(mesh); /* happens with old files */ if (mesh->mselect == NULL) { mesh->totselect = 0; } - if (mesh->mloopuv || mesh->mtpoly) { - /* for now we have to ensure texpoly and mloopuv layers are aligned - * in the future we may allow non-aligned layers */ - BKE_mesh_cd_validate(mesh); - } - /* Multires data */ mesh->mr= newdataadr(fd, mesh->mr); if (mesh->mr) { @@ -4765,6 +4830,7 @@ 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->batch_cache = NULL; lt->adt = newdataadr(fd, lt->adt); direct_link_animdata(fd, lt->adt); @@ -4773,7 +4839,7 @@ static void direct_link_latt(FileData *fd, Lattice *lt) /* ************ READ OBJECT ***************** */ -static void lib_link_modifiers__linkModifiers( +static void lib_link_modifiers_common( void *userData, Object *ob, ID **idpoin, int cb_flag) { FileData *fd = userData; @@ -4783,9 +4849,42 @@ static void lib_link_modifiers__linkModifiers( id_us_plus_no_lib(*idpoin); } } + static void lib_link_modifiers(FileData *fd, Object *ob) { - modifiers_foreachIDLink(ob, lib_link_modifiers__linkModifiers, fd); + modifiers_foreachIDLink(ob, lib_link_modifiers_common, fd); + + /* If linking from a library, clear 'local' static override flag. */ + if (ob->id.lib != NULL) { + for (ModifierData *mod = ob->modifiers.first; mod != NULL; mod = mod->next) { + mod->flag &= ~eModifierFlag_StaticOverride_Local; + } + } + +} + +static void lib_link_gpencil_modifiers(FileData *fd, Object *ob) +{ + BKE_gpencil_modifiers_foreachIDLink(ob, lib_link_modifiers_common, fd); + + /* If linking from a library, clear 'local' static override flag. */ + if (ob->id.lib != NULL) { + for (GpencilModifierData *mod = ob->greasepencil_modifiers.first; mod != NULL; mod = mod->next) { + mod->flag &= ~eGpencilModifierFlag_StaticOverride_Local; + } + } +} + +static void lib_link_shaderfxs(FileData *fd, Object *ob) +{ + BKE_shaderfx_foreachIDLink(ob, lib_link_modifiers_common, fd); + + /* If linking from a library, clear 'local' static override flag. */ + if (ob->id.lib != NULL) { + for (ShaderFxData *fx = ob->shader_fx.first; fx != NULL; fx = fx->next) { + fx->flag &= ~eShaderFxFlag_StaticOverride_Local; + } + } } static void lib_link_object(FileData *fd, Main *main) @@ -4807,7 +4906,15 @@ static void lib_link_object(FileData *fd, Main *main) ob->parent = newlibadr(fd, ob->id.lib, ob->parent); ob->track = newlibadr(fd, ob->id.lib, ob->track); ob->poselib = newlibadr_us(fd, ob->id.lib, ob->poselib); - ob->dup_group = newlibadr_us(fd, ob->id.lib, ob->dup_group); + + /* 2.8x drops support for non-empty dupli instances. */ + if (ob->type == OB_EMPTY) { + ob->dup_group = newlibadr_us(fd, ob->id.lib, ob->dup_group); + } + else { + ob->dup_group = NULL; + ob->transflag &= ~OB_DUPLICOLLECTION; + } ob->proxy = newlibadr_us(fd, ob->id.lib, ob->proxy); if (ob->proxy) { @@ -4870,7 +4977,6 @@ static void lib_link_object(FileData *fd, Main *main) } ob->gpd = newlibadr_us(fd, ob->id.lib, ob->gpd); - ob->duplilist = NULL; ob->id.tag &= ~LIB_TAG_NEED_LINK; /* if id.us==0 a new base will be created later on */ @@ -4890,143 +4996,6 @@ static void lib_link_object(FileData *fd, Main *main) } } - for (bSensor *sens = ob->sensors.first; sens; sens = sens->next) { - for (a = 0; a < sens->totlinks; a++) - sens->links[a] = newglobadr(fd, sens->links[a]); - - if (sens->type == SENS_MESSAGE) { - bMessageSensor *ms = sens->data; - ms->fromObject = - newlibadr(fd, ob->id.lib, ms->fromObject); - } - } - - for (bController *cont = ob->controllers.first; cont; cont = cont->next) { - for (a=0; a < cont->totlinks; a++) - cont->links[a] = newglobadr(fd, cont->links[a]); - - if (cont->type == CONT_PYTHON) { - bPythonCont *pc = cont->data; - pc->text = newlibadr(fd, ob->id.lib, pc->text); - } - cont->slinks = NULL; - cont->totslinks = 0; - } - - for (bActuator *act = ob->actuators.first; act; act = act->next) { - switch (act->type) { - case ACT_SOUND: - { - bSoundActuator *sa = act->data; - sa->sound = newlibadr_us(fd, ob->id.lib, sa->sound); - break; - } - case ACT_GAME: - /* bGameActuator *ga= act->data; */ - break; - case ACT_CAMERA: - { - bCameraActuator *ca = act->data; - ca->ob = newlibadr(fd, ob->id.lib, ca->ob); - break; - } - /* leave this one, it's obsolete but necessary to read for conversion */ - case ACT_ADD_OBJECT: - { - bAddObjectActuator *eoa = act->data; - if (eoa) - eoa->ob = newlibadr(fd, ob->id.lib, eoa->ob); - break; - } - case ACT_OBJECT: - { - bObjectActuator *oa = act->data; - if (oa == NULL) { - init_actuator(act); - } - else { - oa->reference = newlibadr(fd, ob->id.lib, oa->reference); - } - break; - } - case ACT_EDIT_OBJECT: - { - bEditObjectActuator *eoa = act->data; - if (eoa == NULL) { - init_actuator(act); - } - else { - eoa->ob = newlibadr(fd, ob->id.lib, eoa->ob); - eoa->me = newlibadr(fd, ob->id.lib, eoa->me); - } - break; - } - case ACT_SCENE: - { - bSceneActuator *sa = act->data; - sa->camera = newlibadr(fd, ob->id.lib, sa->camera); - sa->scene = newlibadr(fd, ob->id.lib, sa->scene); - break; - } - case ACT_ACTION: - { - bActionActuator *aa = act->data; - aa->act = newlibadr_us(fd, ob->id.lib, aa->act); - break; - } - case ACT_SHAPEACTION: - { - bActionActuator *aa = act->data; - aa->act = newlibadr_us(fd, ob->id.lib, aa->act); - break; - } - case ACT_PROPERTY: - { - bPropertyActuator *pa = act->data; - pa->ob = newlibadr(fd, ob->id.lib, pa->ob); - break; - } - case ACT_MESSAGE: - { - bMessageActuator *ma = act->data; - ma->toObject = newlibadr(fd, ob->id.lib, ma->toObject); - break; - } - case ACT_2DFILTER: - { - bTwoDFilterActuator *_2dfa = act->data; - _2dfa->text = newlibadr(fd, ob->id.lib, _2dfa->text); - break; - } - case ACT_PARENT: - { - bParentActuator *parenta = act->data; - parenta->ob = newlibadr(fd, ob->id.lib, parenta->ob); - break; - } - case ACT_STATE: - /* bStateActuator *statea = act->data; */ - break; - case ACT_ARMATURE: - { - bArmatureActuator *arma= act->data; - arma->target = newlibadr(fd, ob->id.lib, arma->target); - arma->subtarget = newlibadr(fd, ob->id.lib, arma->subtarget); - break; - } - case ACT_STEERING: - { - bSteeringActuator *steeringa = act->data; - steeringa->target = newlibadr(fd, ob->id.lib, steeringa->target); - steeringa->navmesh = newlibadr(fd, ob->id.lib, steeringa->navmesh); - break; - } - case ACT_MOUSE: - /* bMouseActuator *moa = act->data; */ - break; - } - } - { FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim); @@ -5054,6 +5023,8 @@ static void lib_link_object(FileData *fd, Main *main) lib_link_particlesystems(fd, ob, &ob->id, &ob->particlesystem); lib_link_modifiers(fd, ob); + lib_link_gpencil_modifiers(fd, ob); + lib_link_shaderfxs(fd, ob); if (ob->rigidbody_constraint) { ob->rigidbody_constraint->ob1 = newlibadr(fd, ob->id.lib, ob->rigidbody_constraint->ob1); @@ -5114,6 +5085,8 @@ static void direct_link_pose(FileData *fd, bPose *pose) /* in case this value changes in future, clamp else we get undefined behavior */ CLAMP(pchan->rotmode, ROT_MODE_MIN, ROT_MODE_MAX); + + pchan->draw_data = NULL; } pose->ikdata = NULL; if (pose->ikparam != NULL) { @@ -5129,7 +5102,6 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) for (md=lb->first; md; md=md->next) { md->error = NULL; - md->scene = NULL; /* if modifiers disappear, or for upward compatibility */ if (NULL == modifierType_getInfo(md->type)) @@ -5195,6 +5167,13 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) smd->domain->shadow = NULL; smd->domain->tex = NULL; smd->domain->tex_shadow = NULL; + smd->domain->tex_flame = NULL; + smd->domain->tex_flame_coba = NULL; + smd->domain->tex_coba = NULL; + smd->domain->tex_field = NULL; + smd->domain->tex_velocity_x = NULL; + smd->domain->tex_velocity_y = NULL; + smd->domain->tex_velocity_z = NULL; smd->domain->tex_wt = NULL; smd->domain->coba = newdataadr(fd, smd->domain->coba); @@ -5225,7 +5204,7 @@ 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->mesh = NULL; smd->flow->verts_old = NULL; smd->flow->numverts = 0; smd->flow->psys = newdataadr(fd, smd->flow->psys); @@ -5238,7 +5217,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) smd->coll->smd = smd; smd->coll->verts_old = NULL; smd->coll->numverts = 0; - smd->coll->dm = NULL; + smd->coll->mesh = NULL; } else { smd->type = 0; @@ -5254,7 +5233,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) if (pmd->canvas) { pmd->canvas = newdataadr(fd, pmd->canvas); pmd->canvas->pmd = pmd; - pmd->canvas->dm = NULL; + pmd->canvas->mesh = NULL; pmd->canvas->flags &= ~MOD_DPAINT_BAKING; /* just in case */ if (pmd->canvas->surfaces.first) { @@ -5277,7 +5256,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) pmd->brush->psys = newdataadr(fd, pmd->brush->psys); pmd->brush->paint_ramp = newdataadr(fd, pmd->brush->paint_ramp); pmd->brush->vel_ramp = newdataadr(fd, pmd->brush->vel_ramp); - pmd->brush->dm = NULL; + pmd->brush->mesh = NULL; } } else if (md->type == eModifierType_Collision) { @@ -5310,7 +5289,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) else if (md->type == eModifierType_Surface) { SurfaceModifierData *surmd = (SurfaceModifierData *)md; - surmd->dm = NULL; + surmd->mesh = NULL; surmd->bvhtree = NULL; surmd->x = NULL; surmd->v = NULL; @@ -5332,8 +5311,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) else if (md->type == eModifierType_ParticleSystem) { ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md; - psmd->dm_final = NULL; - psmd->dm_deformed = NULL; + psmd->mesh_final = NULL; + psmd->mesh_original = NULL; psmd->psys= newdataadr(fd, psmd->psys); psmd->flag &= ~eParticleSystemFlag_psys_updated; psmd->flag |= eParticleSystemFlag_file_loaded; @@ -5367,8 +5346,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) else if (md->type == eModifierType_Ocean) { OceanModifierData *omd = (OceanModifierData *)md; omd->oceancache = NULL; - omd->ocean = BKE_ocean_add(); - omd->refresh = MOD_OCEAN_REFRESH_RESET; + omd->ocean = NULL; } else if (md->type == eModifierType_Warp) { WarpModifierData *tmd = (WarpModifierData *)md; @@ -5442,24 +5420,71 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) } } } + else if (md->type == eModifierType_Bevel) { + BevelModifierData *bmd = (BevelModifierData *)md; + bmd->clnordata.faceHash = NULL; + } } } -static void direct_link_object(FileData *fd, Object *ob) +static void direct_link_gpencil_modifiers(FileData *fd, ListBase *lb) { - PartEff *paf; - bProperty *prop; - bSensor *sens; - bController *cont; - bActuator *act; + GpencilModifierData *md; - /* weak weak... this was only meant as draw flag, now is used in give_base_to_objects too */ - ob->flag &= ~OB_FROMGROUP; + link_list(fd, lb); - /* This is a transient flag; clear in order to avoid unneeded object update pending from - * time when file was saved. - */ - ob->recalc = 0; + for (md = lb->first; md; md = md->next) { + md->error = NULL; + + /* if modifiers disappear, or for upward compatibility */ + if (NULL == BKE_gpencil_modifierType_getInfo(md->type)) + md->type = eModifierType_None; + + if (md->type == eGpencilModifierType_Lattice) { + LatticeGpencilModifierData *gpmd = (LatticeGpencilModifierData*)md; + gpmd->cache_data = NULL; + } + else if (md->type == eGpencilModifierType_Hook) { + HookGpencilModifierData *hmd = (HookGpencilModifierData *)md; + + hmd->curfalloff = newdataadr(fd, hmd->curfalloff); + if (hmd->curfalloff) { + direct_link_curvemapping(fd, hmd->curfalloff); + } + } + else if (md->type == eGpencilModifierType_Thick) { + ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md; + + gpmd->curve_thickness = newdataadr(fd, gpmd->curve_thickness); + if (gpmd->curve_thickness) { + direct_link_curvemapping(fd, gpmd->curve_thickness); + /* initialize the curve. Maybe this could be moved to modififer logic */ + curvemapping_initialize(gpmd->curve_thickness); + } + } + + } +} + +static void direct_link_shaderfxs(FileData *fd, ListBase *lb) +{ + ShaderFxData *fx; + + link_list(fd, lb); + + for (fx = lb->first; fx; fx = fx->next) { + fx->error = NULL; + + /* if shader disappear, or for upward compatibility */ + if (NULL == BKE_shaderfxType_getInfo(fx->type)) + fx->type = eShaderFxType_None; + + } +} + +static void direct_link_object(FileData *fd, Object *ob) +{ + PartEff *paf; /* XXX This should not be needed - but seems like it can happen in some cases, so for now play safe... */ ob->proxy_from = NULL; @@ -5488,6 +5513,7 @@ static void direct_link_object(FileData *fd, Object *ob) direct_link_motionpath(fd, ob->mpath); link_list(fd, &ob->defbase); + link_list(fd, &ob->fmaps); // XXX deprecated - old animation system <<< direct_link_nlastrips(fd, &ob->nlastrips); link_list(fd, &ob->constraintChannels); @@ -5499,6 +5525,8 @@ static void direct_link_object(FileData *fd, Object *ob) /* do it here, below old data gets converted */ direct_link_modifiers(fd, &ob->modifiers); + direct_link_gpencil_modifiers(fd, &ob->greasepencil_modifiers); + direct_link_shaderfxs(fd, &ob->shader_fx); link_list(fd, &ob->effect); paf= ob->effect.first; @@ -5575,20 +5603,26 @@ 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, 0); + sb->shared = newdataadr(fd, sb->shared); + if (sb->shared == NULL) { + /* Link deprecated caches if they exist, so we can use them for versioning. + * We should only do this when sb->shared == NULL, because those pointers + * are always set (for compatibility with older Blenders). We mustn't link + * the same pointcache twice. */ + direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache, false); + } + else { + /* link caches */ + direct_link_pointcache_list(fd, &sb->shared->ptcaches, &sb->shared->pointcache, false); + } } - ob->bsoft = newdataadr(fd, ob->bsoft); ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */ ob->rigidbody_object = newdataadr(fd, ob->rigidbody_object); if (ob->rigidbody_object) { RigidBodyOb *rbo = ob->rigidbody_object; - - /* must nullify the references to physics sim objects, since they no-longer exist - * (and will need to be recalculated) - */ - rbo->physics_object = NULL; - rbo->physics_shape = NULL; + /* Allocate runtime-only struct */ + rbo->shared = MEM_callocN(sizeof(*rbo->shared), "RigidBodyObShared"); } ob->rigidbody_constraint = newdataadr(fd, ob->rigidbody_constraint); if (ob->rigidbody_constraint) @@ -5597,43 +5631,8 @@ static void direct_link_object(FileData *fd, Object *ob) link_list(fd, &ob->particlesystem); direct_link_particlesystems(fd, &ob->particlesystem); - link_list(fd, &ob->prop); - for (prop = ob->prop.first; prop; prop = prop->next) { - prop->poin = newdataadr(fd, prop->poin); - if (prop->poin == NULL) - prop->poin = &prop->data; - } - - link_list(fd, &ob->sensors); - for (sens = ob->sensors.first; sens; sens = sens->next) { - sens->data = newdataadr(fd, sens->data); - sens->links = newdataadr(fd, sens->links); - test_pointer_array(fd, (void **)&sens->links); - } - direct_link_constraints(fd, &ob->constraints); - link_glob_list(fd, &ob->controllers); - if (ob->init_state) { - /* if a known first state is specified, set it so that the game will start ok */ - ob->state = ob->init_state; - } - else if (!ob->state) { - ob->state = 1; - } - for (cont = ob->controllers.first; cont; cont = cont->next) { - cont->data = newdataadr(fd, cont->data); - cont->links = newdataadr(fd, cont->links); - test_pointer_array(fd, (void **)&cont->links); - if (cont->state_mask == 0) - cont->state_mask = 1; - } - - link_glob_list(fd, &ob->actuators); - for (act = ob->actuators.first; act; act = act->next) { - act->data = newdataadr(fd, act->data); - } - link_list(fd, &ob->hooks); while (ob->hooks.first) { ObHook *hook = ob->hooks.first; @@ -5673,12 +5672,9 @@ static void direct_link_object(FileData *fd, Object *ob) ob->bb = NULL; ob->derivedDeform = NULL; ob->derivedFinal = NULL; - BLI_listbase_clear(&ob->gpulamp); + BKE_object_runtime_reset(ob); link_list(fd, &ob->pc_ids); - /* Runtime curve data */ - ob->curve_cache = NULL; - /* in case this value changes in future, clamp else we get undefined behavior */ CLAMP(ob->rotmode, ROT_MODE_MIN, ROT_MODE_MAX); @@ -5698,6 +5694,205 @@ static void direct_link_object(FileData *fd, Object *ob) ob->preview = direct_link_preview_image(fd, ob->preview); } +static void direct_link_view_settings(FileData *fd, ColorManagedViewSettings *view_settings) +{ + view_settings->curve_mapping = newdataadr(fd, view_settings->curve_mapping); + + if (view_settings->curve_mapping) + direct_link_curvemapping(fd, view_settings->curve_mapping); +} + +/* ***************** READ VIEW LAYER *************** */ + +static void direct_link_layer_collections(FileData *fd, ListBase *lb, bool master) +{ + link_list(fd, lb); + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { +#ifdef USE_COLLECTION_COMPAT_28 + lc->scene_collection = newdataadr(fd, lc->scene_collection); +#endif + + /* Master collection is not a real datablock. */ + if (master) { + lc->collection = newdataadr(fd, lc->collection); + } + + direct_link_layer_collections(fd, &lc->layer_collections, false); + } +} + +static void direct_link_view_layer(FileData *fd, ViewLayer *view_layer) +{ + view_layer->stats = NULL; + link_list(fd, &view_layer->object_bases); + view_layer->basact = newdataadr(fd, view_layer->basact); + + direct_link_layer_collections(fd, &view_layer->layer_collections, true); + view_layer->active_collection = newdataadr(fd, view_layer->active_collection); + + view_layer->id_properties = newdataadr(fd, view_layer->id_properties); + IDP_DirectLinkGroup_OrFree(&view_layer->id_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + + link_list(fd, &(view_layer->freestyle_config.modules)); + link_list(fd, &(view_layer->freestyle_config.linesets)); + + BLI_listbase_clear(&view_layer->drawdata); + view_layer->object_bases_array = NULL; + view_layer->object_bases_hash = NULL; +} + +static void lib_link_layer_collection(FileData *fd, Library *lib, LayerCollection *layer_collection, bool master) +{ + /* Master collection is not a real datablock. */ + if (!master) { + layer_collection->collection = newlibadr(fd, lib, layer_collection->collection); + } + + for (LayerCollection *layer_collection_nested = layer_collection->layer_collections.first; + layer_collection_nested != NULL; + layer_collection_nested = layer_collection_nested->next) + { + lib_link_layer_collection(fd, lib, layer_collection_nested, false); + } +} + +static void lib_link_view_layer(FileData *fd, Library *lib, ViewLayer *view_layer) +{ + for (FreestyleModuleConfig *fmc = view_layer->freestyle_config.modules.first; fmc; fmc = fmc->next) { + fmc->script = newlibadr(fd, lib, fmc->script); + } + + for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; fls = fls->next) { + fls->linestyle = newlibadr_us(fd, lib, fls->linestyle); + fls->group = newlibadr_us(fd, lib, fls->group); + } + + for (Base *base = view_layer->object_bases.first, *base_next = NULL; base; base = base_next) { + base_next = base->next; + + /* we only bump the use count for the collection objects */ + base->object = newlibadr(fd, lib, base->object); + + if (base->object == NULL) { + /* Free in case linked object got lost. */ + BLI_freelinkN(&view_layer->object_bases, base); + if (view_layer->basact == base) { + view_layer->basact = NULL; + } + } + } + + for (LayerCollection *layer_collection = view_layer->layer_collections.first; + layer_collection != NULL; + layer_collection = layer_collection->next) + { + lib_link_layer_collection(fd, lib, layer_collection, true); + } + + IDP_LibLinkProperty(view_layer->id_properties, fd); +} + +/* ***************** READ COLLECTION *************** */ + +#ifdef USE_COLLECTION_COMPAT_28 +static void direct_link_scene_collection(FileData *fd, SceneCollection *sc) +{ + link_list(fd, &sc->objects); + link_list(fd, &sc->scene_collections); + + for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { + direct_link_scene_collection(fd, nsc); + } +} + +static void lib_link_scene_collection(FileData *fd, Library *lib, SceneCollection *sc) +{ + for (LinkData *link = sc->objects.first; link; link = link->next) { + link->data = newlibadr_us(fd, lib, link->data); + BLI_assert(link->data); + } + + for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { + lib_link_scene_collection(fd, lib, nsc); + } +} +#endif + +static void direct_link_collection(FileData *fd, Collection *collection) +{ + link_list(fd, &collection->gobject); + link_list(fd, &collection->children); + + collection->preview = direct_link_preview_image(fd, collection->preview); + + collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; + BLI_listbase_clear(&collection->object_cache); + BLI_listbase_clear(&collection->parents); + +#ifdef USE_COLLECTION_COMPAT_28 + /* This runs before the very first doversion. */ + collection->collection = newdataadr(fd, collection->collection); + if (collection->collection != NULL) { + direct_link_scene_collection(fd, collection->collection); + } + + collection->view_layer = newdataadr(fd, collection->view_layer); + if (collection->view_layer != NULL) { + direct_link_view_layer(fd, collection->view_layer); + } +#endif +} + +static void lib_link_collection_data(FileData *fd, Library *lib, Collection *collection) +{ + for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) { + cob_next = cob->next; + cob->ob = newlibadr_us(fd, lib, cob->ob); + + if (cob->ob == NULL) { + BLI_freelinkN(&collection->gobject, cob); + } + } + + for (CollectionChild *child = collection->children.first, *child_next = NULL; child; child = child_next) { + child_next = child->next; + child->collection = newlibadr_us(fd, lib, child->collection); + + if (child->collection == NULL || + BKE_collection_find_cycle(collection, child->collection)) + { + BLI_freelinkN(&collection->children, child); + } + else { + CollectionParent *cparent = MEM_callocN(sizeof(CollectionParent), "CollectionParent"); + cparent->collection = collection; + BLI_addtail(&child->collection->parents, cparent); + } + } +} + +static void lib_link_collection(FileData *fd, Main *main) +{ + for (Collection *collection = main->collection.first; collection; collection = collection->id.next) { + if (collection->id.tag & LIB_TAG_NEED_LINK) { + collection->id.tag &= ~LIB_TAG_NEED_LINK; + IDP_LibLinkProperty(collection->id.properties, fd); + +#ifdef USE_COLLECTION_COMPAT_28 + if (collection->collection) { + lib_link_scene_collection(fd, collection->id.lib, collection->collection); + } + + if (collection->view_layer) { + lib_link_view_layer(fd, collection->id.lib, collection->view_layer); + } +#endif + + lib_link_collection_data(fd, collection->id.lib, collection); + } + } +} + /* ************ READ SCENE ***************** */ /* patch for missing scene IDs, can't be in do-versions */ @@ -5730,6 +5925,41 @@ static void lib_link_sequence_modifiers(FileData *fd, Scene *scene, ListBase *lb } } +static void direct_link_lightcache_texture(FileData *fd, LightCacheTexture *lctex) +{ + lctex->tex = NULL; + + if (lctex->data) { + lctex->data = newdataadr(fd, lctex->data); + if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { + int data_size = lctex->components * lctex->tex_size[0] * lctex->tex_size[1] * lctex->tex_size[2]; + + if (lctex->data_type == LIGHTCACHETEX_FLOAT) { + BLI_endian_switch_float_array((float *)lctex->data, data_size * sizeof(float)); + } + else if (lctex->data_type == LIGHTCACHETEX_UINT) { + BLI_endian_switch_uint32_array((unsigned int *)lctex->data, data_size * sizeof(unsigned int)); + } + } + } +} + +static void direct_link_lightcache(FileData *fd, LightCache *cache) +{ + direct_link_lightcache_texture(fd, &cache->cube_tx); + direct_link_lightcache_texture(fd, &cache->grid_tx); + + if (cache->cube_mips) { + cache->cube_mips = newdataadr(fd, cache->cube_mips); + for (int i = 0; i < cache->mips_len; ++i) { + direct_link_lightcache_texture(fd, &cache->cube_mips[i]); + } + } + + cache->cube_data = newdataadr(fd, cache->cube_data); + cache->grid_data = newdataadr(fd, cache->grid_data); +} + /* check for cyclic set-scene, * libs can cause this case which is normally prevented, see (T#####) */ #define USE_SETSCENE_CHECK @@ -5786,6 +6016,7 @@ static void lib_link_scene(FileData *fd, Main *main) link_paint(fd, sce, &sce->toolsettings->wpaint->paint); link_paint(fd, sce, &sce->toolsettings->imapaint.paint); link_paint(fd, sce, &sce->toolsettings->uvsculpt->paint); + link_paint(fd, sce, &sce->toolsettings->gp_paint->paint); if (sce->toolsettings->sculpt) sce->toolsettings->sculpt->gravity_object = @@ -5803,21 +6034,19 @@ static void lib_link_scene(FileData *fd, Main *main) sce->toolsettings->imapaint.canvas = newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.canvas); - sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template); - sce->toolsettings->particle.shape_object = newlibadr(fd, sce->id.lib, sce->toolsettings->particle.shape_object); - for (Base *next, *base = sce->base.first; base; base = next) { - next = base->next; + for (Base *base_legacy_next, *base_legacy = sce->base.first; base_legacy; base_legacy = base_legacy_next) { + base_legacy_next = base_legacy->next; - base->object = newlibadr_us(fd, sce->id.lib, base->object); + base_legacy->object = newlibadr_us(fd, sce->id.lib, base_legacy->object); - if (base->object == NULL) { + if (base_legacy->object == NULL) { blo_reportf_wrap(fd->reports, RPT_WARNING, TIP_("LIB: object lost from scene: '%s'"), sce->id.name + 2); - BLI_remlink(&sce->base, base); - if (base == sce->basact) sce->basact = NULL; - MEM_freeN(base); + BLI_remlink(&sce->base, base_legacy); + if (base_legacy == sce->basact) sce->basact = NULL; + MEM_freeN(base_legacy); } } @@ -5872,7 +6101,7 @@ static void lib_link_scene(FileData *fd, Main *main) BKE_sequencer_update_sound_bounds_all(sce); - /* rigidbody world relies on it's linked groups */ + /* rigidbody world relies on it's linked collections */ if (sce->rigidbody_world) { RigidBodyWorld *rbw = sce->rigidbody_world; if (rbw->group) @@ -5891,7 +6120,6 @@ static void lib_link_scene(FileData *fd, Main *main) for (SceneRenderLayer *srl = sce->r.layers.first; srl; srl = srl->next) { srl->mat_override = newlibadr_us(fd, sce->id.lib, srl->mat_override); - srl->light_override = newlibadr_us(fd, sce->id.lib, srl->light_override); for (FreestyleModuleConfig *fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) { fmc->script = newlibadr(fd, sce->id.lib, fmc->script); } @@ -5900,12 +6128,23 @@ static void lib_link_scene(FileData *fd, Main *main) fls->group = newlibadr_us(fd, sce->id.lib, fls->group); } } - /*Game Settings: Dome Warp Text*/ - sce->gm.dome.warptext = newlibadr(fd, sce->id.lib, sce->gm.dome.warptext); - /* Motion Tracking */ sce->clip = newlibadr_us(fd, sce->id.lib, sce->clip); +#ifdef USE_COLLECTION_COMPAT_28 + if (sce->collection) { + lib_link_scene_collection(fd, sce->id.lib, sce->collection); + } +#endif + + if (sce->master_collection) { + lib_link_collection_data(fd, sce->id.lib, sce->master_collection); + } + + for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { + lib_link_view_layer(fd, sce->id.lib, view_layer); + } + #ifdef USE_SETSCENE_CHECK if (sce->set != NULL) { /* link flag for scenes with set would be reset later, @@ -6001,29 +6240,18 @@ static void direct_link_sequence_modifiers(FileData *fd, ListBase *lb) } } -static void direct_link_view_settings(FileData *fd, ColorManagedViewSettings *view_settings) -{ - view_settings->curve_mapping = newdataadr(fd, view_settings->curve_mapping); - - if (view_settings->curve_mapping) - direct_link_curvemapping(fd, view_settings->curve_mapping); -} - static void direct_link_scene(FileData *fd, Scene *sce) { Editing *ed; Sequence *seq; MetaStack *ms; RigidBodyWorld *rbw; + ViewLayer *view_layer; SceneRenderLayer *srl; - sce->theDag = NULL; - sce->depsgraph = NULL; - sce->obedit = NULL; - sce->stats = NULL; + sce->depsgraph_hash = NULL; sce->fps_info = NULL; sce->customdata_mask_modal = 0; - sce->lay_updated = 0; BKE_sound_create_scene(sce); @@ -6046,6 +6274,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->vpaint); direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->wpaint); direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->uvsculpt); + direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->gp_paint); direct_link_paint(fd, &sce->toolsettings->imapaint.paint); @@ -6055,28 +6284,16 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->toolsettings->particle.object = NULL; sce->toolsettings->gp_sculpt.paintcursor = NULL; - /* relink grease pencil drawing brushes */ - link_list(fd, &sce->toolsettings->gp_brushes); - for (bGPDbrush *brush = sce->toolsettings->gp_brushes.first; brush; brush = brush->next) { - brush->cur_sensitivity = newdataadr(fd, brush->cur_sensitivity); - if (brush->cur_sensitivity) { - direct_link_curvemapping(fd, brush->cur_sensitivity); - } - brush->cur_strength = newdataadr(fd, brush->cur_strength); - if (brush->cur_strength) { - direct_link_curvemapping(fd, brush->cur_strength); - } - brush->cur_jitter = newdataadr(fd, brush->cur_jitter); - if (brush->cur_jitter) { - direct_link_curvemapping(fd, brush->cur_jitter); - } - } - /* relink grease pencil interpolation curves */ sce->toolsettings->gp_interpolate.custom_ipo = newdataadr(fd, sce->toolsettings->gp_interpolate.custom_ipo); if (sce->toolsettings->gp_interpolate.custom_ipo) { direct_link_curvemapping(fd, sce->toolsettings->gp_interpolate.custom_ipo); } + /* relink grease pencil multiframe falloff curve */ + sce->toolsettings->gp_sculpt.cur_falloff = newdataadr(fd, sce->toolsettings->gp_sculpt.cur_falloff); + if (sce->toolsettings->gp_sculpt.cur_falloff) { + direct_link_curvemapping(fd, sce->toolsettings->gp_sculpt.cur_falloff); + } } if (sce->ed) { @@ -6198,11 +6415,6 @@ static void direct_link_scene(FileData *fd, Scene *sce) } } -#ifdef DURIAN_CAMERA_SWITCH - /* Runtime */ - sce->r.mode &= ~R_NO_CAMERA_SWITCH; -#endif - sce->r.avicodecdata = newdataadr(fd, sce->r.avicodecdata); if (sce->r.avicodecdata) { sce->r.avicodecdata->lpFormat = newdataadr(fd, sce->r.avicodecdata->lpFormat); @@ -6222,11 +6434,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) for (srl = sce->r.layers.first; srl; srl = srl->next) { srl->prop = newdataadr(fd, srl->prop); IDP_DirectLinkGroup_OrFree(&srl->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } - for (srl = sce->r.layers.first; srl; srl = srl->next) { link_list(fd, &(srl->freestyleConfig.modules)); - } - for (srl = sce->r.layers.first; srl; srl = srl->next) { link_list(fd, &(srl->freestyleConfig.linesets)); } @@ -6241,10 +6449,34 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->rigidbody_world = newdataadr(fd, sce->rigidbody_world); rbw = sce->rigidbody_world; if (rbw) { - /* must nullify the reference to physics sim object, since it no-longer exist - * (and will need to be recalculated) - */ - rbw->physics_world = NULL; + rbw->shared = newdataadr(fd, rbw->shared); + + if (rbw->shared == NULL) { + /* Link deprecated caches if they exist, so we can use them for versioning. + * We should only do this when rbw->shared == NULL, because those pointers + * are always set (for compatibility with older Blenders). We mustn't link + * the same pointcache twice. */ + direct_link_pointcache_list(fd, &rbw->ptcaches, &rbw->pointcache, false); + + /* make sure simulation starts from the beginning after loading file */ + if (rbw->pointcache) { + rbw->ltime = (float)rbw->pointcache->startframe; + } + } + else { + /* must nullify the reference to physics sim object, since it no-longer exist + * (and will need to be recalculated) + */ + rbw->shared->physics_world = NULL; + + /* link caches */ + direct_link_pointcache_list(fd, &rbw->shared->ptcaches, &rbw->shared->pointcache, false); + + /* make sure simulation starts from the beginning after loading file */ + if (rbw->shared->pointcache) { + rbw->ltime = (float)rbw->shared->pointcache->startframe; + } + } rbw->objects = NULL; rbw->numbodies = 0; @@ -6252,101 +6484,48 @@ static void direct_link_scene(FileData *fd, Scene *sce) rbw->effector_weights = newdataadr(fd, rbw->effector_weights); if (!rbw->effector_weights) rbw->effector_weights = BKE_add_effector_weights(NULL); - - /* link cache */ - direct_link_pointcache_list(fd, &rbw->ptcaches, &rbw->pointcache, false); - /* make sure simulation starts from the beginning after loading file */ - if (rbw->pointcache) { - rbw->ltime = (float)rbw->pointcache->startframe; - } } sce->preview = direct_link_preview_image(fd, sce->preview); direct_link_curvemapping(fd, &sce->r.mblur_shutter_curve); -} - -/* ************ READ WM ***************** */ - -static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) -{ - wmWindow *win; - id_us_ensure_real(&wm->id); - link_list(fd, &wm->windows); - - for (win = wm->windows.first; win; win = win->next) { - win->ghostwin = NULL; - win->eventstate = NULL; - win->curswin = NULL; - win->tweak = NULL; -#ifdef WIN32 - win->ime_data = NULL; +#ifdef USE_COLLECTION_COMPAT_28 + /* this runs before the very first doversion */ + if (sce->collection) { + sce->collection = newdataadr(fd, sce->collection); + direct_link_scene_collection(fd, sce->collection); + } #endif - BLI_listbase_clear(&win->queue); - BLI_listbase_clear(&win->handlers); - BLI_listbase_clear(&win->modalhandlers); - BLI_listbase_clear(&win->subwindows); - BLI_listbase_clear(&win->gesture); - BLI_listbase_clear(&win->drawdata); - - win->drawmethod = -1; - win->drawfail = 0; - win->active = 0; - - win->cursor = 0; - win->lastcursor = 0; - win->modalcursor = 0; - win->grabcursor = 0; - win->addmousemove = true; - win->multisamples = 0; - win->stereo3d_format = newdataadr(fd, win->stereo3d_format); - - /* multiview always fallback to anaglyph at file opening - * otherwise quadbuffer saved files can break Blender */ - if (win->stereo3d_format) { - win->stereo3d_format->display_mode = S3D_DISPLAY_ANAGLYPH; - } + if (sce->master_collection) { + sce->master_collection = newdataadr(fd, sce->master_collection); + direct_link_collection(fd, sce->master_collection); + /* Needed because this is an ID outside of Main. */ + sce->master_collection->id.py_instance = NULL; } - BLI_listbase_clear(&wm->timers); - BLI_listbase_clear(&wm->operators); - BLI_listbase_clear(&wm->paintcursors); - BLI_listbase_clear(&wm->queue); - BKE_reports_init(&wm->reports, RPT_STORE); - - BLI_listbase_clear(&wm->keyconfigs); - wm->defaultconf = NULL; - wm->addonconf = NULL; - wm->userconf = NULL; - wm->undo_stack = NULL; - - BLI_listbase_clear(&wm->jobs); - BLI_listbase_clear(&wm->drags); - - wm->windrawable = NULL; - wm->winactive = NULL; - wm->initialized = 0; - wm->op_undo_depth = 0; - wm->is_interface_locked = 0; -} - -static void lib_link_windowmanager(FileData *fd, Main *main) -{ - wmWindowManager *wm; - wmWindow *win; - - for (wm = main->wm.first; wm; wm = wm->id.next) { - if (wm->id.tag & LIB_TAG_NEED_LINK) { - /* Note: WM IDProperties are never written to file, hence no need to read/link them here. */ - for (win = wm->windows.first; win; win = win->next) { - win->screen = newlibadr(fd, NULL, win->screen); - } + /* insert into global old-new map for reading without UI (link_global accesses it again) */ + link_glob_list(fd, &sce->view_layers); + for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { + direct_link_view_layer(fd, view_layer); + } - wm->id.tag &= ~LIB_TAG_NEED_LINK; + if (fd->memfile) { + /* If it's undo try to recover the cache. */ + if (fd->scenemap) sce->eevee.light_cache = newsceadr(fd, sce->eevee.light_cache); + else sce->eevee.light_cache = NULL; + } + else { + /* else read the cache from file. */ + if (sce->eevee.light_cache) { + sce->eevee.light_cache = newdataadr(fd, sce->eevee.light_cache); + direct_link_lightcache(fd, sce->eevee.light_cache); } } + + sce->layer_properties = newdataadr(fd, sce->layer_properties); + IDP_DirectLinkGroup_OrFree(&sce->layer_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } /* ****************** READ GREASE PENCIL ***************** */ @@ -6354,11 +6533,24 @@ static void lib_link_windowmanager(FileData *fd, Main *main) /* relink's grease pencil data's refs */ static void lib_link_gpencil(FileData *fd, Main *main) { + /* Relink all datablock linked by GP datablock */ for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { if (gpd->id.tag & LIB_TAG_NEED_LINK) { + /* Layers */ + for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + /* Layer -> Parent References */ + gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent); + } + + /* Datablock Stuff */ IDP_LibLinkProperty(gpd->id.properties, fd); lib_link_animdata(fd, &gpd->id, gpd->adt); + /* materials */ + for (int a = 0; a < gpd->totcol; a++) { + gpd->mat[a] = newlibadr_us(fd, gpd->id.lib, gpd->mat[a]); + } + gpd->id.tag &= ~LIB_TAG_NEED_LINK; } } @@ -6380,263 +6572,704 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) gpd->adt = newdataadr(fd, gpd->adt); direct_link_animdata(fd, gpd->adt); - /* relink palettes */ + /* relink palettes (old palettes deprecated, only to convert old files) */ link_list(fd, &gpd->palettes); - for (palette = gpd->palettes.first; palette; palette = palette->next) { - link_list(fd, &palette->colors); + if (gpd->palettes.first != NULL) { + for (palette = gpd->palettes.first; palette; palette = palette->next) { + link_list(fd, &palette->colors); + } } + /* materials */ + gpd->mat = newdataadr(fd, gpd->mat); + test_pointer_array(fd, (void **)&gpd->mat); + /* relink layers */ link_list(fd, &gpd->layers); for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { - /* parent */ - gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent); /* relink frames */ link_list(fd, &gpl->frames); + gpl->actframe = newdataadr(fd, gpl->actframe); + gpl->runtime.derived_array = NULL; + gpl->runtime.len_derived = 0; + gpl->runtime.icon_id = 0; + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { /* relink strokes (and their points) */ link_list(fd, &gpf->strokes); for (gps = gpf->strokes.first; gps; gps = gps->next) { + /* relink stroke points array */ gps->points = newdataadr(fd, gps->points); + /* relink weight data */ + if (gps->dvert) { + gps->dvert = newdataadr(fd, gps->dvert); + direct_link_dverts(fd, gps->totpoints, gps->dvert); + } + /* the triangulation is not saved, so need to be recalculated */ gps->triangles = NULL; gps->tot_triangles = 0; gps->flag |= GP_STROKE_RECALC_CACHES; - /* the color pointer is not saved, so need to be recalculated using the color name */ - gps->palcolor = NULL; - gps->flag |= GP_STROKE_RECALC_COLOR; } } } } -/* ****************** READ SCREEN ***************** */ +/* *********** READ AREA **************** */ -/* note: file read without screens option G_FILE_NO_UI; - * check lib pointers in call below */ -static void lib_link_screen(FileData *fd, Main *main) +static void direct_link_panel_list(FileData *fd, ListBase *lb) { - for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) { - if (sc->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(sc->id.properties, fd); - id_us_ensure_real(&sc->id); + link_list(fd, lb); - sc->scene = newlibadr(fd, sc->id.lib, sc->scene); + for (Panel *pa = lb->first; pa; pa = pa->next) { + pa->paneltab = newdataadr(fd, pa->paneltab); + pa->runtime_flag = 0; + pa->activedata = NULL; + pa->type = NULL; + direct_link_panel_list(fd, &pa->children); + } +} - /* this should not happen, but apparently it does somehow. Until we figure out the cause, - * just assign first available scene */ - if (!sc->scene) - sc->scene = main->scene.first; +static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) +{ + uiList *ui_list; - sc->animtimer = NULL; /* saved in rare cases */ - sc->tool_tip = NULL; - sc->scrubbing = false; + direct_link_panel_list(fd, &ar->panels); - for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { - sa->full = newlibadr(fd, sc->id.lib, sa->full); + link_list(fd, &ar->panels_category_active); - for (SpaceLink *sl = sa->spacedata.first; sl; sl= sl->next) { - switch (sl->spacetype) { - case SPACE_VIEW3D: - { - View3D *v3d = (View3D*) sl; - BGpic *bgpic = NULL; + link_list(fd, &ar->ui_lists); - v3d->camera= newlibadr(fd, sc->id.lib, v3d->camera); - v3d->ob_centre= newlibadr(fd, sc->id.lib, v3d->ob_centre); + for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { + ui_list->type = NULL; + ui_list->dyn_data = NULL; + ui_list->properties = newdataadr(fd, ui_list->properties); + IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + } - /* should be do_versions but not easy adding into the listbase */ - if (v3d->bgpic) { - v3d->bgpic = newlibadr(fd, sc->id.lib, v3d->bgpic); - BLI_addtail(&v3d->bgpicbase, bgpic); - v3d->bgpic = NULL; - } + link_list(fd, &ar->ui_previews); - for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { - bgpic->ima = newlibadr_us(fd, sc->id.lib, bgpic->ima); - bgpic->clip = newlibadr_us(fd, sc->id.lib, bgpic->clip); - } - if (v3d->localvd) { - v3d->localvd->camera = newlibadr(fd, sc->id.lib, v3d->localvd->camera); - } - break; - } - case SPACE_IPO: - { - SpaceIpo *sipo = (SpaceIpo *)sl; - bDopeSheet *ads = sipo->ads; + if (spacetype == SPACE_EMPTY) { + /* unkown space type, don't leak regiondata */ + ar->regiondata = NULL; + } + else if (ar->flag & RGN_FLAG_TEMP_REGIONDATA) { + /* Runtime data, don't use. */ + ar->regiondata = NULL; + } + else { + ar->regiondata = newdataadr(fd, ar->regiondata); + if (ar->regiondata) { + if (spacetype == SPACE_VIEW3D) { + RegionView3D *rv3d = ar->regiondata; - if (ads) { - ads->source = newlibadr(fd, sc->id.lib, ads->source); - ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); - } - break; - } - case SPACE_BUTS: - { - SpaceButs *sbuts = (SpaceButs *)sl; - sbuts->pinid = newlibadr(fd, sc->id.lib, sbuts->pinid); - if (sbuts->pinid == NULL) { - sbuts->flag &= ~SB_PIN_CONTEXT; - } - break; - } - case SPACE_FILE: - break; - case SPACE_ACTION: - { - SpaceAction *saction = (SpaceAction *)sl; - bDopeSheet *ads = &saction->ads; + rv3d->localvd = newdataadr(fd, rv3d->localvd); + rv3d->clipbb = newdataadr(fd, rv3d->clipbb); - if (ads) { - ads->source = newlibadr(fd, sc->id.lib, ads->source); - ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); - } + rv3d->depths = NULL; + rv3d->gpuoffscreen = NULL; + rv3d->render_engine = NULL; + rv3d->sms = NULL; + rv3d->smooth_timer = NULL; + } + } + } - saction->action = newlibadr(fd, sc->id.lib, saction->action); - break; - } - case SPACE_IMAGE: - { - SpaceImage *sima = (SpaceImage *)sl; + ar->v2d.tab_offset = NULL; + ar->v2d.tab_num = 0; + ar->v2d.tab_cur = 0; + ar->v2d.sms = NULL; + ar->v2d.alpha_hor = ar->v2d.alpha_vert = 255; /* visible by default */ + BLI_listbase_clear(&ar->panels_category); + BLI_listbase_clear(&ar->handlers); + BLI_listbase_clear(&ar->uiblocks); + ar->headerstr = NULL; + ar->visible = 0; + ar->type = NULL; + ar->do_draw = 0; + ar->gizmo_map = NULL; + ar->regiontimer = NULL; + ar->draw_buffer = NULL; + memset(&ar->drawrct, 0, sizeof(ar->drawrct)); +} - sima->image = newlibadr_real_us(fd, sc->id.lib, sima->image); - sima->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sima->mask_info.mask); +static void direct_link_area(FileData *fd, ScrArea *area) +{ + SpaceLink *sl; + ARegion *ar; - /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data - * so fingers crossed this works fine! - */ - sima->gpd = newlibadr_us(fd, sc->id.lib, sima->gpd); - break; - } - case SPACE_SEQ: - { - SpaceSeq *sseq = (SpaceSeq *)sl; + link_list(fd, &(area->spacedata)); + link_list(fd, &(area->regionbase)); - /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data - * so fingers crossed this works fine! - */ - sseq->gpd = newlibadr_us(fd, sc->id.lib, sseq->gpd); - break; - } - case SPACE_NLA: - { - SpaceNla *snla= (SpaceNla *)sl; - bDopeSheet *ads= snla->ads; + BLI_listbase_clear(&area->handlers); + area->type = NULL; /* spacetype callbacks */ + area->butspacetype = SPACE_EMPTY; /* Should always be unset so that rna_Area_type_get works correctly */ + area->region_active_win = -1; - if (ads) { - ads->source = newlibadr(fd, sc->id.lib, ads->source); - ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); - } - break; - } - case SPACE_TEXT: - { - SpaceText *st= (SpaceText *)sl; + area->global = newdataadr(fd, area->global); - st->text= newlibadr(fd, sc->id.lib, st->text); - break; - } - case SPACE_SCRIPT: - { - SpaceScript *scpt = (SpaceScript *)sl; - /*scpt->script = NULL; - 2.45 set to null, better re-run the script */ - if (scpt->script) { - scpt->script = newlibadr(fd, sc->id.lib, scpt->script); - if (scpt->script) { - SCRIPT_SET_NULL(scpt->script); - } - } - break; - } - case SPACE_OUTLINER: - { - SpaceOops *so= (SpaceOops *)sl; - so->search_tse.id = newlibadr(fd, NULL, so->search_tse.id); + /* if we do not have the spacetype registered we cannot + * free it, so don't allocate any new memory for such spacetypes. */ + if (!BKE_spacetype_exists(area->spacetype)) { + area->butspacetype = area->spacetype; /* Hint for versioning code to replace deprecated space types. */ + area->spacetype = SPACE_EMPTY; + } - if (so->treestore) { - TreeStoreElem *tselem; - BLI_mempool_iter iter; + for (ar = area->regionbase.first; ar; ar = ar->next) { + direct_link_region(fd, ar, area->spacetype); + } - BLI_mempool_iternew(so->treestore, &iter); - while ((tselem = BLI_mempool_iterstep(&iter))) { - tselem->id = newlibadr(fd, NULL, tselem->id); - } - if (so->treehash) { - /* rebuild hash table, because it depends on ids too */ - so->storeflag |= SO_TREESTORE_REBUILD; - } - } - break; - } - case SPACE_NODE: - { - SpaceNode *snode = (SpaceNode *)sl; - bNodeTreePath *path, *path_next; - bNodeTree *ntree; + /* accident can happen when read/save new file with older version */ + /* 2.50: we now always add spacedata for info */ + if (area->spacedata.first == NULL) { + SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo"); + area->spacetype= sinfo->spacetype= SPACE_INFO; + BLI_addtail(&area->spacedata, sinfo); + } + /* add local view3d too */ + else if (area->spacetype == SPACE_VIEW3D) { + blo_do_versions_view3d_split_250(area->spacedata.first, &area->regionbase); + } - /* node tree can be stored locally in id too, link this first */ - snode->id = newlibadr(fd, sc->id.lib, snode->id); - snode->from = newlibadr(fd, sc->id.lib, snode->from); + for (sl = area->spacedata.first; sl; sl = sl->next) { + link_list(fd, &(sl->regionbase)); - ntree = snode->id ? ntreeFromID(snode->id) : NULL; - snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree); + /* if we do not have the spacetype registered we cannot + * free it, so don't allocate any new memory for such spacetypes. */ + if (!BKE_spacetype_exists(sl->spacetype)) + sl->spacetype = SPACE_EMPTY; - for (path = snode->treepath.first; path; path = path->next) { - if (path == snode->treepath.first) { - /* first nodetree in path is same as snode->nodetree */ - path->nodetree = snode->nodetree; - } - else - path->nodetree = newlibadr_us(fd, sc->id.lib, path->nodetree); + for (ar = sl->regionbase.first; ar; ar = ar->next) + direct_link_region(fd, ar, sl->spacetype); - if (!path->nodetree) - break; - } + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d= (View3D*) sl; - /* remaining path entries are invalid, remove */ - for (; path; path = path_next) { - path_next = path->next; + v3d->flag |= V3D_INVALID_BACKBUF; - BLI_remlink(&snode->treepath, path); - MEM_freeN(path); - } + if (v3d->gpd) { + v3d->gpd = newdataadr(fd, v3d->gpd); + direct_link_gpencil(fd, v3d->gpd); + } + v3d->localvd = newdataadr(fd, v3d->localvd); + v3d->properties_storage = NULL; - /* edittree is just the last in the path, - * set this directly since the path may have been shortened above */ - if (snode->treepath.last) { - path = snode->treepath.last; - snode->edittree = path->nodetree; - } - else { - snode->edittree = NULL; - } - break; - } - case SPACE_CLIP: - { - SpaceClip *sclip = (SpaceClip *)sl; + /* render can be quite heavy, set to solid on load */ + if (v3d->shading.type == OB_RENDER) { + v3d->shading.type = OB_SOLID; + } + v3d->shading.prev_type = OB_SOLID; - sclip->clip = newlibadr_real_us(fd, sc->id.lib, sclip->clip); - sclip->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sclip->mask_info.mask); - break; - } - case SPACE_LOGIC: - { - SpaceLogic *slogic = (SpaceLogic *)sl; + if (v3d->fx_settings.dof) + v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof); + if (v3d->fx_settings.ssao) + v3d->fx_settings.ssao = newdataadr(fd, v3d->fx_settings.ssao); - slogic->gpd = newlibadr_us(fd, sc->id.lib, slogic->gpd); - break; - } - default: - break; + blo_do_versions_view3d_split_250(v3d, &sl->regionbase); + } + else if (sl->spacetype == SPACE_IPO) { + SpaceIpo *sipo = (SpaceIpo *)sl; + + sipo->ads = newdataadr(fd, sipo->ads); + BLI_listbase_clear(&sipo->ghostCurves); + } + else if (sl->spacetype == SPACE_NLA) { + SpaceNla *snla = (SpaceNla *)sl; + + snla->ads = newdataadr(fd, snla->ads); + } + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *soops = (SpaceOops *) sl; + + /* use newdataadr_no_us and do not free old memory avoiding double + * frees and use of freed memory. this could happen because of a + * bug fixed in revision 58959 where the treestore memory address + * was not unique */ + TreeStore *ts = newdataadr_no_us(fd, soops->treestore); + soops->treestore = NULL; + if (ts) { + TreeStoreElem *elems = newdataadr_no_us(fd, ts->data); + + soops->treestore = BLI_mempool_create(sizeof(TreeStoreElem), ts->usedelem, + 512, BLI_MEMPOOL_ALLOW_ITER); + if (ts->usedelem && elems) { + int i; + for (i = 0; i < ts->usedelem; i++) { + TreeStoreElem *new_elem = BLI_mempool_alloc(soops->treestore); + *new_elem = elems[i]; + } + } + /* we only saved what was used */ + soops->storeflag |= SO_TREESTORE_CLEANUP; // at first draw + } + soops->treehash = NULL; + soops->tree.first = soops->tree.last= NULL; + } + else if (sl->spacetype == SPACE_IMAGE) { + SpaceImage *sima = (SpaceImage *)sl; + + sima->iuser.scene = NULL; + sima->iuser.ok = 1; + sima->scopes.waveform_1 = NULL; + sima->scopes.waveform_2 = NULL; + sima->scopes.waveform_3 = NULL; + sima->scopes.vecscope = NULL; + sima->scopes.ok = 0; + + /* WARNING: gpencil data is no longer stored directly in sima after 2.5 + * so sacrifice a few old files for now to avoid crashes with new files! + * committed: r28002 */ +#if 0 + sima->gpd = newdataadr(fd, sima->gpd); + if (sima->gpd) + direct_link_gpencil(fd, sima->gpd); +#endif + } + else if (sl->spacetype == SPACE_NODE) { + SpaceNode *snode = (SpaceNode *)sl; + + if (snode->gpd) { + snode->gpd = newdataadr(fd, snode->gpd); + direct_link_gpencil(fd, snode->gpd); + } + + link_list(fd, &snode->treepath); + snode->edittree = NULL; + snode->iofsd = NULL; + BLI_listbase_clear(&snode->linkdrag); + } + else if (sl->spacetype == SPACE_TEXT) { + SpaceText *st= (SpaceText *)sl; + + st->drawcache = NULL; + st->scroll_accum[0] = 0.0f; + st->scroll_accum[1] = 0.0f; + } + else if (sl->spacetype == SPACE_SEQ) { + SpaceSeq *sseq = (SpaceSeq *)sl; + + /* grease pencil data is not a direct data and can't be linked from direct_link* + * functions, it should be linked from lib_link* functions instead + * + * otherwise it'll lead to lost grease data on open because it'll likely be + * read from file after all other users of grease pencil and newdataadr would + * simple return NULL here (sergey) + */ +#if 0 + if (sseq->gpd) { + sseq->gpd = newdataadr(fd, sseq->gpd); + direct_link_gpencil(fd, sseq->gpd); + } +#endif + sseq->scopes.reference_ibuf = NULL; + sseq->scopes.zebra_ibuf = NULL; + sseq->scopes.waveform_ibuf = NULL; + sseq->scopes.sep_waveform_ibuf = NULL; + sseq->scopes.vector_ibuf = NULL; + sseq->scopes.histogram_ibuf = NULL; + sseq->compositor = NULL; + } + else if (sl->spacetype == SPACE_BUTS) { + SpaceButs *sbuts = (SpaceButs *)sl; + + sbuts->path= NULL; + sbuts->texuser= NULL; + sbuts->mainbo = sbuts->mainb; + sbuts->mainbuser = sbuts->mainb; + } + else if (sl->spacetype == SPACE_CONSOLE) { + SpaceConsole *sconsole = (SpaceConsole *)sl; + ConsoleLine *cl, *cl_next; + + link_list(fd, &sconsole->scrollback); + link_list(fd, &sconsole->history); + + //for (cl= sconsole->scrollback.first; cl; cl= cl->next) + // cl->line= newdataadr(fd, cl->line); + + /* comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression, + * from left to right. the right-most expression sets the result of the comma + * expression as a whole*/ + for (cl = sconsole->history.first; cl; cl = cl_next) { + cl_next = cl->next; + cl->line = newdataadr(fd, cl->line); + 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); + } + } + } + else if (sl->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)sl; + + /* this sort of info is probably irrelevant for reloading... + * plus, it isn't saved to files yet! + */ + sfile->folders_prev = sfile->folders_next = NULL; + sfile->files = NULL; + sfile->layout = NULL; + sfile->op = NULL; + sfile->previews_timer = NULL; + sfile->params = newdataadr(fd, sfile->params); + } + else if (sl->spacetype == SPACE_CLIP) { + SpaceClip *sclip = (SpaceClip *)sl; + + sclip->scopes.track_search = NULL; + sclip->scopes.track_preview = NULL; + sclip->scopes.ok = 0; + } + } + + BLI_listbase_clear(&area->actionzones); + + area->v1 = newdataadr(fd, area->v1); + area->v2 = newdataadr(fd, area->v2); + area->v3 = newdataadr(fd, area->v3); + area->v4 = newdataadr(fd, area->v4); +} + +static void lib_link_area(FileData *fd, ID *parent_id, ScrArea *area) +{ + area->full = newlibadr(fd, parent_id->lib, area->full); + + memset(&area->runtime, 0x0, sizeof(area->runtime)); + + for (SpaceLink *sl = area->spacedata.first; sl; sl= sl->next) { + switch (sl->spacetype) { + case SPACE_VIEW3D: + { + View3D *v3d = (View3D*) sl; + + v3d->camera= newlibadr(fd, parent_id->lib, v3d->camera); + v3d->ob_centre= newlibadr(fd, parent_id->lib, v3d->ob_centre); + + if (v3d->localvd) { + v3d->localvd->camera = newlibadr(fd, parent_id->lib, v3d->localvd->camera); + } + break; + } + case SPACE_IPO: + { + SpaceIpo *sipo = (SpaceIpo *)sl; + bDopeSheet *ads = sipo->ads; + + if (ads) { + ads->source = newlibadr(fd, parent_id->lib, ads->source); + ads->filter_grp = newlibadr(fd, parent_id->lib, ads->filter_grp); + } + break; + } + case SPACE_BUTS: + { + SpaceButs *sbuts = (SpaceButs *)sl; + sbuts->pinid = newlibadr(fd, parent_id->lib, sbuts->pinid); + if (sbuts->pinid == NULL) { + sbuts->flag &= ~SB_PIN_CONTEXT; + } + break; + } + case SPACE_FILE: + break; + case SPACE_ACTION: + { + SpaceAction *saction = (SpaceAction *)sl; + bDopeSheet *ads = &saction->ads; + + if (ads) { + ads->source = newlibadr(fd, parent_id->lib, ads->source); + ads->filter_grp = newlibadr(fd, parent_id->lib, ads->filter_grp); + } + + saction->action = newlibadr(fd, parent_id->lib, saction->action); + break; + } + case SPACE_IMAGE: + { + SpaceImage *sima = (SpaceImage *)sl; + + sima->image = newlibadr_real_us(fd, parent_id->lib, sima->image); + sima->mask_info.mask = newlibadr_real_us(fd, parent_id->lib, sima->mask_info.mask); + + /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data + * so fingers crossed this works fine! + */ + sima->gpd = newlibadr_us(fd, parent_id->lib, sima->gpd); + break; + } + case SPACE_SEQ: + { + SpaceSeq *sseq = (SpaceSeq *)sl; + + /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data + * so fingers crossed this works fine! + */ + sseq->gpd = newlibadr_us(fd, parent_id->lib, sseq->gpd); + break; + } + case SPACE_NLA: + { + SpaceNla *snla= (SpaceNla *)sl; + bDopeSheet *ads= snla->ads; + + if (ads) { + ads->source = newlibadr(fd, parent_id->lib, ads->source); + ads->filter_grp = newlibadr(fd, parent_id->lib, ads->filter_grp); + } + break; + } + case SPACE_TEXT: + { + SpaceText *st= (SpaceText *)sl; + + st->text= newlibadr(fd, parent_id->lib, st->text); + break; + } + case SPACE_SCRIPT: + { + SpaceScript *scpt = (SpaceScript *)sl; + /*scpt->script = NULL; - 2.45 set to null, better re-run the script */ + if (scpt->script) { + scpt->script = newlibadr(fd, parent_id->lib, scpt->script); + if (scpt->script) { + SCRIPT_SET_NULL(scpt->script); + } + } + break; + } + case SPACE_OUTLINER: + { + SpaceOops *so= (SpaceOops *)sl; + so->search_tse.id = newlibadr(fd, NULL, so->search_tse.id); + + if (so->treestore) { + TreeStoreElem *tselem; + BLI_mempool_iter iter; + + BLI_mempool_iternew(so->treestore, &iter); + while ((tselem = BLI_mempool_iterstep(&iter))) { + tselem->id = newlibadr(fd, NULL, tselem->id); + } + if (so->treehash) { + /* rebuild hash table, because it depends on ids too */ + so->storeflag |= SO_TREESTORE_REBUILD; } } + break; + } + case SPACE_NODE: + { + SpaceNode *snode = (SpaceNode *)sl; + bNodeTreePath *path, *path_next; + bNodeTree *ntree; + + /* node tree can be stored locally in id too, link this first */ + snode->id = newlibadr(fd, parent_id->lib, snode->id); + snode->from = newlibadr(fd, parent_id->lib, snode->from); + + ntree = snode->id ? ntreeFromID(snode->id) : NULL; + snode->nodetree = ntree ? ntree : newlibadr_us(fd, parent_id->lib, snode->nodetree); + + for (path = snode->treepath.first; path; path = path->next) { + if (path == snode->treepath.first) { + /* first nodetree in path is same as snode->nodetree */ + path->nodetree = snode->nodetree; + } + else + path->nodetree = newlibadr_us(fd, parent_id->lib, path->nodetree); + + if (!path->nodetree) + break; + } + + /* remaining path entries are invalid, remove */ + for (; path; path = path_next) { + path_next = path->next; + + BLI_remlink(&snode->treepath, path); + MEM_freeN(path); + } + + /* edittree is just the last in the path, + * set this directly since the path may have been shortened above */ + if (snode->treepath.last) { + path = snode->treepath.last; + snode->edittree = path->nodetree; + } + else { + snode->edittree = NULL; + } + break; + } + case SPACE_CLIP: + { + SpaceClip *sclip = (SpaceClip *)sl; + sclip->clip = newlibadr_real_us(fd, parent_id->lib, sclip->clip); + sclip->mask_info.mask = newlibadr_real_us(fd, parent_id->lib, sclip->mask_info.mask); + break; + } + default: + break; + } + } +} + +/** + * \return false on error. + */ +static bool direct_link_area_map(FileData *fd, ScrAreaMap *area_map) +{ + link_list(fd, &area_map->vertbase); + link_list(fd, &area_map->edgebase); + link_list(fd, &area_map->areabase); + for (ScrArea *area = area_map->areabase.first; area; area = area->next) { + direct_link_area(fd, area); + } + + /* edges */ + for (ScrEdge *se = area_map->edgebase.first; se; se = se->next) { + se->v1 = newdataadr(fd, se->v1); + se->v2 = newdataadr(fd, se->v2); + BKE_screen_sort_scrvert(&se->v1, &se->v2); + + if (se->v1 == NULL) { + BLI_remlink(&area_map->edgebase, se); + + return false; + } + } + + return true; +} + +/* ************ READ WM ***************** */ + +static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) +{ + wmWindow *win; + + id_us_ensure_real(&wm->id); + link_list(fd, &wm->windows); + + for (win = wm->windows.first; win; win = win->next) { + win->parent = newdataadr(fd, win->parent); + + WorkSpaceInstanceHook *hook = win->workspace_hook; + win->workspace_hook = newdataadr(fd, hook); + + /* we need to restore a pointer to this later when reading workspaces, so store in global oldnew-map */ + oldnewmap_insert(fd->globmap, hook, win->workspace_hook, 0); + + direct_link_area_map(fd, &win->global_areas); + + win->ghostwin = NULL; + win->gpuctx = NULL; + win->eventstate = NULL; + win->cursor_keymap_status = NULL; + win->tweak = NULL; +#ifdef WIN32 + win->ime_data = NULL; +#endif + + BLI_listbase_clear(&win->queue); + BLI_listbase_clear(&win->handlers); + BLI_listbase_clear(&win->modalhandlers); + BLI_listbase_clear(&win->gesture); + + win->active = 0; + + win->cursor = 0; + win->lastcursor = 0; + win->modalcursor = 0; + win->grabcursor = 0; + win->addmousemove = true; + win->stereo3d_format = newdataadr(fd, win->stereo3d_format); + + /* multiview always fallback to anaglyph at file opening + * otherwise quadbuffer saved files can break Blender */ + if (win->stereo3d_format) { + win->stereo3d_format->display_mode = S3D_DISPLAY_ANAGLYPH; + } + } + + BLI_listbase_clear(&wm->timers); + BLI_listbase_clear(&wm->operators); + BLI_listbase_clear(&wm->paintcursors); + BLI_listbase_clear(&wm->queue); + BKE_reports_init(&wm->reports, RPT_STORE); + + BLI_listbase_clear(&wm->keyconfigs); + wm->defaultconf = NULL; + wm->addonconf = NULL; + wm->userconf = NULL; + wm->undo_stack = NULL; + + wm->message_bus = NULL; + + BLI_listbase_clear(&wm->jobs); + BLI_listbase_clear(&wm->drags); + + wm->windrawable = NULL; + wm->winactive = NULL; + wm->initialized = 0; + wm->op_undo_depth = 0; + wm->is_interface_locked = 0; +} + +static void lib_link_windowmanager(FileData *fd, Main *main) +{ + wmWindowManager *wm; + wmWindow *win; + + for (wm = main->wm.first; wm; wm = wm->id.next) { + if (wm->id.tag & LIB_TAG_NEED_LINK) { + /* Note: WM IDProperties are never written to file, hence no need to read/link them here. */ + for (win = wm->windows.first; win; win = win->next) { + if (win->workspace_hook) { /* NULL for old files */ + lib_link_workspace_instance_hook(fd, win->workspace_hook, &wm->id); + } + win->scene = newlibadr(fd, wm->id.lib, win->scene); + /* deprecated, but needed for versioning (will be NULL'ed then) */ + win->screen = newlibadr(fd, NULL, win->screen); + + for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) { + lib_link_area(fd, &wm->id, area); + } + } + + wm->id.tag &= ~LIB_TAG_NEED_LINK; + } + } +} + +/* ****************** READ SCREEN ***************** */ + +/* note: file read without screens option G_FILE_NO_UI; + * check lib pointers in call below */ +static void lib_link_screen(FileData *fd, Main *main) +{ + for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) { + if (sc->id.tag & LIB_TAG_NEED_LINK) { + IDP_LibLinkProperty(sc->id.properties, fd); + + /* deprecated, but needed for versioning (will be NULL'ed then) */ + sc->scene = newlibadr(fd, sc->id.lib, sc->scene); + + sc->animtimer = NULL; /* saved in rare cases */ + sc->tool_tip = NULL; + sc->scrubbing = false; + + for (ScrArea *area = sc->areabase.first; area; area = area->next) { + lib_link_area(fd, &sc->id, area); } sc->id.tag &= ~LIB_TAG_NEED_LINK; } @@ -6741,88 +7374,60 @@ static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map) BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); } -/* called from kernel/blender.c */ -/* used to link a file (without UI) to the current UI */ -/* note that it assumes the old pointers in UI are still valid, so old Main is not freed */ -void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene) +static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene) { - wmWindow *win; - wmWindowManager *wm; - bScreen *sc; - ScrArea *sa; + bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); - struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain); + for (ScrArea *area = screen->areabase.first; area; area = area->next) { + for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + + if (v3d->camera == NULL || v3d->scenelock) { + v3d->camera = scene->camera; + } - /* first windowmanager */ - for (wm = newmain->wm.first; wm; wm = wm->id.next) { - for (win= wm->windows.first; win; win= win->next) { - win->screen = restore_pointer_by_name(id_map, (ID *)win->screen, USER_REAL); + if (v3d->localvd) { + /*Base *base;*/ - if (win->screen == NULL) - win->screen = curscreen; + v3d->localvd->camera = scene->camera; - win->screen->winid = win->winid; + /* localview can become invalid during undo/redo steps, so we exit it when no could be found */ +#if 0 /* XXX regionlocalview ? */ + for (base= sc->scene->base.first; base; base= base->next) { + if (base->lay & v3d->lay) break; + } + if (base==NULL) { + v3d->lay= v3d->localvd->lay; + v3d->layact= v3d->localvd->layact; + MEM_freeN(v3d->localvd); + v3d->localvd= NULL; + } +#endif + } + else if (v3d->scenelock) { + v3d->lay = scene->lay; + } + } } } +} +static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, Main *newmain, WorkSpaceLayout *layout) +{ + bScreen *screen = BKE_workspace_layout_screen_get(layout); - for (sc = newmain->screen.first; sc; sc = sc->id.next) { - Scene *oldscene = sc->scene; - - sc->scene= restore_pointer_by_name(id_map, (ID *)sc->scene, USER_REAL); - if (sc->scene == NULL) - sc->scene = curscene; - - /* keep cursor location through undo */ - copy_v3_v3(sc->scene->cursor, oldscene->cursor); - - for (sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - - for (sl = sa->spacedata.first; sl; sl = sl->next) { + /* avoid conflicts with 2.8x branch */ + { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; - BGpic *bgpic; ARegion *ar; - if (v3d->scenelock) - v3d->camera = NULL; /* always get from scene */ - else - v3d->camera = restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL); - if (v3d->camera == NULL) - v3d->camera = sc->scene->camera; + v3d->camera = restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL); v3d->ob_centre = restore_pointer_by_name(id_map, (ID *)v3d->ob_centre, USER_REAL); - for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) { - if ((bgpic->ima = restore_pointer_by_name(id_map, (ID *)bgpic->ima, USER_IGNORE))) { - id_us_plus((ID *)bgpic->ima); - } - if ((bgpic->clip = restore_pointer_by_name(id_map, (ID *)bgpic->clip, USER_IGNORE))) { - id_us_plus((ID *)bgpic->clip); - } - } - if (v3d->localvd) { - /*Base *base;*/ - - v3d->localvd->camera = sc->scene->camera; - - /* localview can become invalid during undo/redo steps, so we exit it when no could be found */ -#if 0 /* XXX regionlocalview ? */ - for (base= sc->scene->base.first; base; base= base->next) { - if (base->lay & v3d->lay) break; - } - if (base==NULL) { - v3d->lay= v3d->localvd->lay; - v3d->layact= v3d->localvd->layact; - MEM_freeN(v3d->localvd); - v3d->localvd= NULL; - } -#endif - } - else if (v3d->scenelock) { - v3d->lay = sc->scene->lay; - } - /* not very nice, but could help */ if ((v3d->layact & v3d->lay) == 0) v3d->layact = v3d->lay; @@ -7017,89 +7622,55 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc sclip->scopes.ok = 0; } - else if (sl->spacetype == SPACE_LOGIC) { - SpaceLogic *slogic = (SpaceLogic *)sl; - - slogic->gpd = restore_pointer_by_name(id_map, (ID *)slogic->gpd, USER_REAL); - } } } } - - /* update IDs stored in all possible clipboards */ - lib_link_clipboard_restore(id_map); - - BKE_main_idmap_destroy(id_map); } -static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) +/** + * Used to link a file (without UI) to the current UI. + * Note that it assumes the old pointers in UI are still valid, so old Main is not freed. + */ +void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene, ViewLayer *cur_view_layer) { - Panel *pa; - uiList *ui_list; + struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain); - link_list(fd, &ar->panels); + for (WorkSpace *workspace = newmain->workspaces.first; workspace; workspace = workspace->id.next) { + ListBase *layouts = BKE_workspace_layouts_get(workspace); - for (pa = ar->panels.first; pa; pa = pa->next) { - pa->paneltab = newdataadr(fd, pa->paneltab); - pa->runtime_flag = 0; - pa->activedata = NULL; - pa->type = NULL; + for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { + lib_link_workspace_layout_restore(id_map, newmain, layout); + } } - link_list(fd, &ar->panels_category_active); + for (wmWindow *win = curwm->windows.first; win; win = win->next) { + WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook); + ID *workspace_id = (ID *)workspace; + Scene *oldscene = win->scene; - link_list(fd, &ar->ui_lists); - - for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { - ui_list->type = NULL; - ui_list->dyn_data = NULL; - ui_list->properties = newdataadr(fd, ui_list->properties); - IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } + workspace = restore_pointer_by_name(id_map, workspace_id, USER_REAL); + BKE_workspace_active_set(win->workspace_hook, workspace); + win->scene = restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL); + if (win->scene == NULL) { + win->scene = curscene; + } + if (BKE_view_layer_find(win->scene, win->view_layer_name) == NULL) { + STRNCPY(win->view_layer_name, cur_view_layer->name); + } + BKE_workspace_active_set(win->workspace_hook, workspace); - link_list(fd, &ar->ui_previews); + /* keep cursor location through undo */ + copy_v3_v3(win->scene->cursor.location, oldscene->cursor.location); + copy_qt_qt(win->scene->cursor.rotation, oldscene->cursor.rotation); + lib_link_window_scene_data_restore(win, win->scene); - if (spacetype == SPACE_EMPTY) { - /* unkown space type, don't leak regiondata */ - ar->regiondata = NULL; - } - else if (ar->flag & RGN_FLAG_TEMP_REGIONDATA) { - /* Runtime data, don't use. */ - ar->regiondata = NULL; + BLI_assert(win->screen == NULL); } - else { - ar->regiondata = newdataadr(fd, ar->regiondata); - if (ar->regiondata) { - if (spacetype == SPACE_VIEW3D) { - RegionView3D *rv3d = ar->regiondata; - rv3d->localvd = newdataadr(fd, rv3d->localvd); - rv3d->clipbb = newdataadr(fd, rv3d->clipbb); - - rv3d->depths = NULL; - rv3d->gpuoffscreen = NULL; - rv3d->render_engine = NULL; - rv3d->sms = NULL; - rv3d->smooth_timer = NULL; - rv3d->compositor = NULL; - } - } - } + /* update IDs stored in all possible clipboards */ + lib_link_clipboard_restore(id_map); - ar->v2d.tab_offset = NULL; - ar->v2d.tab_num = 0; - ar->v2d.tab_cur = 0; - ar->v2d.sms = NULL; - BLI_listbase_clear(&ar->panels_category); - BLI_listbase_clear(&ar->handlers); - BLI_listbase_clear(&ar->uiblocks); - ar->headerstr = NULL; - ar->swinid = 0; - ar->type = NULL; - ar->swap = 0; - ar->do_draw = 0; - ar->regiontimer = NULL; - memset(&ar->drawrct, 0, sizeof(ar->drawrct)); + BKE_main_idmap_destroy(id_map); } /* for the saved 2.50 files without regiondata */ @@ -7122,308 +7693,23 @@ void blo_do_versions_view3d_split_250(View3D *v3d, ListBase *regions) } /* this was not initialized correct always */ - if (v3d->twtype == 0) - v3d->twtype = V3D_MANIP_TRANSLATE; if (v3d->gridsubdiv == 0) v3d->gridsubdiv = 10; } static bool direct_link_screen(FileData *fd, bScreen *sc) { - ScrArea *sa; - ScrVert *sv; - ScrEdge *se; bool wrong_id = false; - link_list(fd, &(sc->vertbase)); - link_list(fd, &(sc->edgebase)); - link_list(fd, &(sc->areabase)); sc->regionbase.first = sc->regionbase.last= NULL; sc->context = NULL; + sc->active_region = NULL; - sc->mainwin = sc->subwinactive= 0; /* indices */ - sc->swap = 0; - - /* edges */ - for (se = sc->edgebase.first; se; se = se->next) { - se->v1 = newdataadr(fd, se->v1); - se->v2 = newdataadr(fd, se->v2); - if ((intptr_t)se->v1 > (intptr_t)se->v2) { - sv = se->v1; - se->v1 = se->v2; - se->v2 = sv; - } - - if (se->v1 == NULL) { - printf("Error reading Screen %s... removing it.\n", sc->id.name+2); - BLI_remlink(&sc->edgebase, se); - wrong_id = true; - } - } - - /* areas */ - for (sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - ARegion *ar; - - link_list(fd, &(sa->spacedata)); - link_list(fd, &(sa->regionbase)); - - BLI_listbase_clear(&sa->handlers); - sa->type = NULL; /* spacetype callbacks */ - sa->region_active_win = -1; - - /* if we do not have the spacetype registered (game player), we cannot - * free it, so don't allocate any new memory for such spacetypes. */ - if (!BKE_spacetype_exists(sa->spacetype)) - sa->spacetype = SPACE_EMPTY; - - for (ar = sa->regionbase.first; ar; ar = ar->next) - direct_link_region(fd, ar, sa->spacetype); - - /* accident can happen when read/save new file with older version */ - /* 2.50: we now always add spacedata for info */ - if (sa->spacedata.first==NULL) { - SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo"); - sa->spacetype= sinfo->spacetype= SPACE_INFO; - BLI_addtail(&sa->spacedata, sinfo); - } - /* add local view3d too */ - else if (sa->spacetype == SPACE_VIEW3D) - blo_do_versions_view3d_split_250(sa->spacedata.first, &sa->regionbase); - - /* incase we set above */ - sa->butspacetype = sa->spacetype; - - for (sl = sa->spacedata.first; sl; sl = sl->next) { - link_list(fd, &(sl->regionbase)); - - /* if we do not have the spacetype registered (game player), we cannot - * free it, so don't allocate any new memory for such spacetypes. */ - if (!BKE_spacetype_exists(sl->spacetype)) - sl->spacetype = SPACE_EMPTY; - - for (ar = sl->regionbase.first; ar; ar = ar->next) - direct_link_region(fd, ar, sl->spacetype); - - if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d= (View3D*) sl; - BGpic *bgpic; - - v3d->flag |= V3D_INVALID_BACKBUF; - - link_list(fd, &v3d->bgpicbase); - - /* should be do_versions except this doesnt fit well there */ - if (v3d->bgpic) { - bgpic = newdataadr(fd, v3d->bgpic); - BLI_addtail(&v3d->bgpicbase, bgpic); - v3d->bgpic = NULL; - } - - for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) - bgpic->iuser.ok = 1; - - if (v3d->gpd) { - v3d->gpd = newdataadr(fd, v3d->gpd); - direct_link_gpencil(fd, v3d->gpd); - } - v3d->localvd = newdataadr(fd, v3d->localvd); - BLI_listbase_clear(&v3d->afterdraw_transp); - BLI_listbase_clear(&v3d->afterdraw_xray); - BLI_listbase_clear(&v3d->afterdraw_xraytransp); - v3d->properties_storage = NULL; - v3d->defmaterial = NULL; - - /* render can be quite heavy, set to solid on load */ - if (v3d->drawtype == OB_RENDER) - v3d->drawtype = OB_SOLID; - v3d->prev_drawtype = OB_SOLID; - - if (v3d->fx_settings.dof) - v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof); - if (v3d->fx_settings.ssao) - v3d->fx_settings.ssao = newdataadr(fd, v3d->fx_settings.ssao); - - blo_do_versions_view3d_split_250(v3d, &sl->regionbase); - } - else if (sl->spacetype == SPACE_IPO) { - SpaceIpo *sipo = (SpaceIpo *)sl; - - sipo->ads = newdataadr(fd, sipo->ads); - BLI_listbase_clear(&sipo->ghostCurves); - } - else if (sl->spacetype == SPACE_NLA) { - SpaceNla *snla = (SpaceNla *)sl; - - snla->ads = newdataadr(fd, snla->ads); - } - else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOops *soops = (SpaceOops *) sl; - - /* use newdataadr_no_us and do not free old memory avoiding double - * frees and use of freed memory. this could happen because of a - * bug fixed in revision 58959 where the treestore memory address - * was not unique */ - TreeStore *ts = newdataadr_no_us(fd, soops->treestore); - soops->treestore = NULL; - if (ts) { - TreeStoreElem *elems = newdataadr_no_us(fd, ts->data); - - soops->treestore = BLI_mempool_create(sizeof(TreeStoreElem), ts->usedelem, - 512, BLI_MEMPOOL_ALLOW_ITER); - if (ts->usedelem && elems) { - int i; - for (i = 0; i < ts->usedelem; i++) { - TreeStoreElem *new_elem = BLI_mempool_alloc(soops->treestore); - *new_elem = elems[i]; - } - } - /* we only saved what was used */ - soops->storeflag |= SO_TREESTORE_CLEANUP; // at first draw - } - soops->treehash = NULL; - soops->tree.first = soops->tree.last= NULL; - } - else if (sl->spacetype == SPACE_IMAGE) { - SpaceImage *sima = (SpaceImage *)sl; - - sima->iuser.scene = NULL; - sima->iuser.ok = 1; - sima->scopes.waveform_1 = NULL; - sima->scopes.waveform_2 = NULL; - sima->scopes.waveform_3 = NULL; - sima->scopes.vecscope = NULL; - sima->scopes.ok = 0; - - /* WARNING: gpencil data is no longer stored directly in sima after 2.5 - * so sacrifice a few old files for now to avoid crashes with new files! - * committed: r28002 */ -#if 0 - sima->gpd = newdataadr(fd, sima->gpd); - if (sima->gpd) - direct_link_gpencil(fd, sima->gpd); -#endif - } - else if (sl->spacetype == SPACE_NODE) { - SpaceNode *snode = (SpaceNode *)sl; - - if (snode->gpd) { - snode->gpd = newdataadr(fd, snode->gpd); - direct_link_gpencil(fd, snode->gpd); - } - - link_list(fd, &snode->treepath); - snode->edittree = NULL; - snode->iofsd = NULL; - BLI_listbase_clear(&snode->linkdrag); - } - else if (sl->spacetype == SPACE_TEXT) { - SpaceText *st= (SpaceText *)sl; - - st->drawcache = NULL; - st->scroll_accum[0] = 0.0f; - st->scroll_accum[1] = 0.0f; - } - else if (sl->spacetype == SPACE_TIME) { - SpaceTime *stime = (SpaceTime *)sl; - BLI_listbase_clear(&stime->caches); - } - else if (sl->spacetype == SPACE_LOGIC) { - SpaceLogic *slogic = (SpaceLogic *)sl; - - /* XXX: this is new stuff, which shouldn't be directly linking to gpd... */ - if (slogic->gpd) { - slogic->gpd = newdataadr(fd, slogic->gpd); - direct_link_gpencil(fd, slogic->gpd); - } - } - else if (sl->spacetype == SPACE_SEQ) { - SpaceSeq *sseq = (SpaceSeq *)sl; - - /* grease pencil data is not a direct data and can't be linked from direct_link* - * functions, it should be linked from lib_link* functions instead - * - * otherwise it'll lead to lost grease data on open because it'll likely be - * read from file after all other users of grease pencil and newdataadr would - * simple return NULL here (sergey) - */ -#if 0 - if (sseq->gpd) { - sseq->gpd = newdataadr(fd, sseq->gpd); - direct_link_gpencil(fd, sseq->gpd); - } -#endif - sseq->scopes.reference_ibuf = NULL; - sseq->scopes.zebra_ibuf = NULL; - sseq->scopes.waveform_ibuf = NULL; - sseq->scopes.sep_waveform_ibuf = NULL; - sseq->scopes.vector_ibuf = NULL; - sseq->scopes.histogram_ibuf = NULL; - sseq->compositor = NULL; - } - else if (sl->spacetype == SPACE_BUTS) { - SpaceButs *sbuts = (SpaceButs *)sl; - - sbuts->path= NULL; - sbuts->texuser= NULL; - sbuts->mainbo = sbuts->mainb; - sbuts->mainbuser = sbuts->mainb; - } - else if (sl->spacetype == SPACE_CONSOLE) { - SpaceConsole *sconsole = (SpaceConsole *)sl; - ConsoleLine *cl, *cl_next; - - link_list(fd, &sconsole->scrollback); - link_list(fd, &sconsole->history); - - //for (cl= sconsole->scrollback.first; cl; cl= cl->next) - // cl->line= newdataadr(fd, cl->line); - - /* comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression, - * from left to right. the right-most expression sets the result of the comma - * expression as a whole*/ - for (cl = sconsole->history.first; cl; cl = cl_next) { - cl_next = cl->next; - cl->line = newdataadr(fd, cl->line); - 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); - } - } - } - else if (sl->spacetype == SPACE_FILE) { - SpaceFile *sfile = (SpaceFile *)sl; - - /* this sort of info is probably irrelevant for reloading... - * plus, it isn't saved to files yet! - */ - sfile->folders_prev = sfile->folders_next = NULL; - sfile->files = NULL; - sfile->layout = NULL; - sfile->op = NULL; - sfile->previews_timer = NULL; - sfile->params = newdataadr(fd, sfile->params); - } - else if (sl->spacetype == SPACE_CLIP) { - SpaceClip *sclip = (SpaceClip *)sl; + sc->preview = direct_link_preview_image(fd, sc->preview); - sclip->scopes.track_search = NULL; - sclip->scopes.track_preview = NULL; - sclip->scopes.ok = 0; - } - } - - BLI_listbase_clear(&sa->actionzones); - - sa->v1 = newdataadr(fd, sa->v1); - sa->v2 = newdataadr(fd, sa->v2); - sa->v3 = newdataadr(fd, sa->v3); - sa->v4 = newdataadr(fd, sa->v4); + if (!direct_link_area_map(fd, AREAMAP_FROM_SCREEN(sc))) { + printf("Error reading Screen %s... removing it.\n", sc->id.name + 2); + wrong_id = true; } return wrong_id; @@ -7517,6 +7803,28 @@ static void fix_relpaths_library(const char *basepath, Main *main) } } +/* ************ READ PROBE ***************** */ + +static void lib_link_lightprobe(FileData *fd, Main *main) +{ + for (LightProbe *prb = main->lightprobe.first; prb; prb = prb->id.next) { + if (prb->id.tag & LIB_TAG_NEED_LINK) { + IDP_LibLinkProperty(prb->id.properties, fd); + lib_link_animdata(fd, &prb->id, prb->adt); + + prb->visibility_grp = newlibadr(fd, prb->id.lib, prb->visibility_grp); + + prb->id.tag &= ~LIB_TAG_NEED_LINK; + } + } +} + +static void direct_link_lightprobe(FileData *fd, LightProbe *prb) +{ + prb->adt = newdataadr(fd, prb->adt); + direct_link_animdata(fd, prb->adt); +} + /* ************ READ SPEAKER ***************** */ static void lib_link_speaker(FileData *fd, Main *main) @@ -7591,40 +7899,6 @@ static void lib_link_sound(FileData *fd, Main *main) } } } -/* ***************** READ GROUP *************** */ - -static void direct_link_group(FileData *fd, Group *group) -{ - link_list(fd, &group->gobject); - - group->preview = direct_link_preview_image(fd, group->preview); -} - -static void lib_link_group(FileData *fd, Main *bmain) -{ - for (Group *group = bmain->group.first; group; group = group->id.next) { - if (group->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(group->id.properties, fd); - - bool add_us = false; - - for (GroupObject *go = group->gobject.first; go; go = go->next) { - go->ob = newlibadr_real_us(fd, group->id.lib, go->ob); - if (go->ob) { - go->ob->flag |= OB_FROMGROUP; - /* if group has an object, it increments user... */ - add_us = true; - } - } - if (add_us) { - id_us_ensure_real(&group->id); - } - BKE_group_object_unlink(bmain, group, NULL, NULL, NULL); /* removes NULL entries */ - - group->id.tag &= ~LIB_TAG_NEED_LINK; - } - } -} /* ***************** READ MOVIECLIP *************** */ @@ -8134,6 +8408,7 @@ static const char *dataname(short id_code) case ID_VF: return "Data from VF"; case ID_TXT: return "Data from TXT"; case ID_SPK: return "Data from SPK"; + case ID_LP: return "Data from LP"; case ID_SO: return "Data from SO"; case ID_NT: return "Data from NT"; case ID_BR: return "Data from BR"; @@ -8146,6 +8421,7 @@ static const char *dataname(short id_code) case ID_MSK: return "Data from MSK"; case ID_LS: return "Data from LS"; case ID_CF: return "Data from CF"; + case ID_WS: return "Data from WS"; } return "Data from Lib Block"; @@ -8268,6 +8544,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short id->us = ID_FAKE_USERS(id); id->icon_id = 0; id->newid = NULL; /* Needed because .blend may have been saved with crap value here... */ + id->orig_id = NULL; id->recalc = 0; /* this case cannot be direct_linked: it's just the ID part */ @@ -8355,8 +8632,11 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short case ID_SO: direct_link_sound(fd, (bSound *)id); break; + case ID_LP: + direct_link_lightprobe(fd, (LightProbe *)id); + break; case ID_GR: - direct_link_group(fd, (Group *)id); + direct_link_collection(fd, (Collection *)id); break; case ID_AR: direct_link_armature(fd, (bArmature*)id); @@ -8394,6 +8674,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short case ID_CF: direct_link_cachefile(fd, (CacheFile *)id); break; + case ID_WS: + direct_link_workspace(fd, (WorkSpace *)id, main); + break; } oldnewmap_free_unused(fd->datamap); @@ -8439,6 +8722,7 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead) bfd->curscreen = fg->curscreen; bfd->curscene = fg->curscene; + bfd->cur_view_layer = fg->cur_view_layer; MEM_freeN(fg); @@ -8451,6 +8735,7 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead) /* note, this has to be kept for reading older files... */ static void link_global(FileData *fd, BlendFileData *bfd) { + bfd->cur_view_layer = newglobadr(fd, bfd->cur_view_layer); bfd->curscreen = newlibadr(fd, NULL, bfd->curscreen); bfd->curscene = newlibadr(fd, NULL, bfd->curscene); // this happens in files older than 2.35 @@ -8459,27 +8744,6 @@ static void link_global(FileData *fd, BlendFileData *bfd) } } -static void convert_tface_mt(FileData *fd, Main *main) -{ - Main *gmain; - - /* this is a delayed do_version (so it can create new materials) */ - if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 3)) { - //XXX hack, material.c uses G_MAIN all over the place, instead of main - /* XXX NOTE: this hack should not beneeded anymore... but will check/remove this in 2.8 code rather */ - // temporarily set G_MAIN to the current main - gmain = G_MAIN; - G_MAIN = main; - - if (!(do_version_tface(main))) { - 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 - G_MAIN = gmain; - } -} - /* initialize userdef with non-UI dependency stuff */ /* other initializers (such as theme color defaults) go to resources.c */ static void do_versions_userdef(FileData *fd, BlendFileData *bfd) @@ -8507,6 +8771,11 @@ static void do_versions_userdef(FileData *fd, BlendFileData *bfd) user->walk_navigation.jump_height = 0.4f; /* m */ user->walk_navigation.teleport_time = 0.2f; /* s */ } + + /* grease pencil multisamples */ + if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "gpencil_multisamples")) { + user->gpencil_multisamples = 4; + } } static void do_versions(FileData *fd, Library *lib, Main *main) @@ -8533,6 +8802,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) blo_do_versions_250(fd, lib, main); blo_do_versions_260(fd, lib, main); blo_do_versions_270(fd, lib, main); + blo_do_versions_280(fd, lib, main); /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */ @@ -8546,12 +8816,15 @@ static void do_versions_after_linking(Main *main) // main->curlib ? "LIB" : "MAIN", main->versionfile, main->subversionfile); do_versions_after_linking_270(main); + do_versions_after_linking_280(main); } static void lib_link_all(FileData *fd, Main *main) { oldnewmap_sort(fd); + lib_link_id(fd, main); + /* No load UI for undo memfiles */ if (fd->memfile == NULL) { lib_link_windowmanager(fd, main); @@ -8574,14 +8847,15 @@ static void lib_link_all(FileData *fd, Main *main) lib_link_text(fd, main); lib_link_camera(fd, main); lib_link_speaker(fd, main); + lib_link_lightprobe(fd, main); lib_link_sound(fd, main); - lib_link_group(fd, main); + lib_link_collection(fd, main); lib_link_armature(fd, main); lib_link_action(fd, main); lib_link_vfont(fd, main); lib_link_nodetree(fd, main); /* has to be done after scene/materials, this will verify group nodes */ - lib_link_brush(fd, main); lib_link_palette(fd, main); + lib_link_brush(fd, main); lib_link_paint_curve(fd, main); lib_link_particlesettings(fd, main); lib_link_movieclip(fd, main); @@ -8589,6 +8863,7 @@ static void lib_link_all(FileData *fd, Main *main) lib_link_linestyle(fd, main); lib_link_gpencil(fd, main); lib_link_cachefiles(fd, main); + lib_link_workspaces(fd, main); lib_link_library(fd, main); /* only init users */ } @@ -8626,6 +8901,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) link_list(fd, &user->themes); link_list(fd, &user->user_keymaps); + link_list(fd, &user->user_menus); link_list(fd, &user->addons); link_list(fd, &user->autoexec_paths); @@ -8651,6 +8927,17 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) direct_link_keymapitem(fd, kmi); } + for (bUserMenu *um = user->user_menus.first; um; um = um->next) { + link_list(fd, &um->items); + for (bUserMenuItem *umi = um->items.first; umi; umi = umi->next) { + if (umi->type == USER_MENU_TYPE_OPERATOR) { + bUserMenuItem_Op *umi_op = (bUserMenuItem_Op *)umi; + umi_op->prop = newdataadr(fd, umi_op->prop); + IDP_DirectLinkGroup_OrFree(&umi_op->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + } + } + } + for (addon = user->addons.first; addon; addon = addon->next) { addon->prop = newdataadr(fd, addon->prop); IDP_DirectLinkGroup_OrFree(&addon->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); @@ -8661,6 +8948,9 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) link_list(fd, &user->uistyles); + /* Don't read the active app template, use the default one. */ + user->app_template[0] = '\0'; + /* free fd->datamap again */ oldnewmap_free_unused(fd->datamap); oldnewmap_clear(fd->datamap); @@ -8781,6 +9071,14 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath) BKE_main_id_tag_all(bfd->main, LIB_TAG_NEW, false); + /* Now that all our data-blocks are loaded, we can re-generate overrides from their references. */ + if (fd->memfile == NULL) { + /* Do not apply in undo case! */ + lib_verify_nodetree(bfd->main, true); /* Needed to ensure we have typeinfo in nodes... */ + BKE_main_override_static_update(bfd->main); + BKE_collections_after_lib_link(bfd->main); + } + lib_verify_nodetree(bfd->main, true); fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */ @@ -8981,6 +9279,11 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old) } } else { + /* in 2.50+ file identifier for screens is patched, forward compatibility */ + if (bhead->code == ID_SCRN) { + bhead->code = ID_SCR; + } + id = is_yet_read(fd, mainvar, bhead); if (id == NULL) { read_libblock(fd, mainvar, bhead, LIB_TAG_TESTIND, NULL); @@ -9017,6 +9320,14 @@ static void expand_constraint_channels(FileData *fd, Main *mainvar, ListBase *ch } } +static void expand_id(FileData *fd, Main *mainvar, ID *id) +{ + if (id->override_static) { + expand_doit(fd, mainvar, id->override_static->reference); + expand_doit(fd, mainvar, id->override_static->storage); + } +} + static void expand_idprops(FileData *fd, Main *mainvar, IDProperty *prop) { if (!prop) @@ -9205,15 +9516,27 @@ static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSetting } } } + + for (ParticleDupliWeight *dw = part->dupliweights.first; dw; dw = dw->next) { + expand_doit(fd, mainvar, dw->ob); + } } -static void expand_group(FileData *fd, Main *mainvar, Group *group) +static void expand_collection(FileData *fd, Main *mainvar, Collection *collection) { - GroupObject *go; + for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + expand_doit(fd, mainvar, cob->ob); + } - for (go = group->gobject.first; go; go = go->next) { - expand_doit(fd, mainvar, go->ob); + for (CollectionChild *child = collection->children.first; child; child = child->next) { + expand_doit(fd, mainvar, child->collection); } + +#ifdef USE_COLLECTION_COMPAT_28 + if (collection->collection != NULL) { + expand_scene_collection(fd, mainvar, collection->collection); + } +#endif } static void expand_key(FileData *fd, Main *mainvar, Key *key) @@ -9272,19 +9595,13 @@ static void expand_brush(FileData *fd, Main *mainvar, Brush *brush) expand_doit(fd, mainvar, brush->mask_mtex.tex); expand_doit(fd, mainvar, brush->clone.image); expand_doit(fd, mainvar, brush->paint_curve); + if (brush->gpencil_settings != NULL) { + expand_doit(fd, mainvar, brush->gpencil_settings->material); + } } static void expand_material(FileData *fd, Main *mainvar, Material *ma) { - int a; - - for (a = 0; a < MAX_MTEX; a++) { - if (ma->mtex[a]) { - expand_doit(fd, mainvar, ma->mtex[a]->tex); - expand_doit(fd, mainvar, ma->mtex[a]->object); - } - } - expand_doit(fd, mainvar, ma->ipo); // XXX deprecated - old animation system if (ma->adt) @@ -9293,21 +9610,15 @@ static void expand_material(FileData *fd, Main *mainvar, Material *ma) if (ma->nodetree) expand_nodetree(fd, mainvar, ma->nodetree); - if (ma->group) - expand_doit(fd, mainvar, ma->group); + if (ma->gp_style) { + MaterialGPencilStyle *gp_style = ma->gp_style; + expand_doit(fd, mainvar, gp_style->sima); + expand_doit(fd, mainvar, gp_style->ima); + } } static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la) { - int a; - - for (a = 0; a < MAX_MTEX; a++) { - if (la->mtex[a]) { - expand_doit(fd, mainvar, la->mtex[a]->tex); - expand_doit(fd, mainvar, la->mtex[a]->object); - } - } - expand_doit(fd, mainvar, la->ipo); // XXX deprecated - old animation system if (la->adt) @@ -9329,15 +9640,6 @@ static void expand_lattice(FileData *fd, Main *mainvar, Lattice *lt) static void expand_world(FileData *fd, Main *mainvar, World *wrld) { - int a; - - for (a = 0; a < MAX_MTEX; a++) { - if (wrld->mtex[a]) { - expand_doit(fd, mainvar, wrld->mtex[a]->tex); - expand_doit(fd, mainvar, wrld->mtex[a]->object); - } - } - expand_doit(fd, mainvar, wrld->ipo); // XXX deprecated - old animation system if (wrld->adt) @@ -9384,9 +9686,7 @@ static void expand_curve(FileData *fd, Main *mainvar, Curve *cu) static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me) { - CustomDataLayer *layer; - TFace *tf; - int a, i; + int a; if (me->adt) expand_animdata(fd, mainvar, me->adt); @@ -9397,46 +9697,6 @@ static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me) expand_doit(fd, mainvar, me->key); expand_doit(fd, mainvar, me->texcomesh); - - if (me->tface) { - tf = me->tface; - for (i=0; i<me->totface; i++, tf++) { - if (tf->tpage) - expand_doit(fd, mainvar, tf->tpage); - } - } - - if (me->mface && !me->mpoly) { - MTFace *mtf; - - for (a = 0; a < me->fdata.totlayer; a++) { - layer = &me->fdata.layers[a]; - - if (layer->type == CD_MTFACE) { - mtf = (MTFace *) layer->data; - for (i = 0; i < me->totface; i++, mtf++) { - if (mtf->tpage) - expand_doit(fd, mainvar, mtf->tpage); - } - } - } - } - else { - MTexPoly *mtp; - - for (a = 0; a < me->pdata.totlayer; a++) { - layer = &me->pdata.layers[a]; - - if (layer->type == CD_MTEXPOLY) { - mtp = (MTexPoly *) layer->data; - - for (i = 0; i < me->totpoly; i++, mtp++) { - if (mtp->tpage) - expand_doit(fd, mainvar, mtp->tpage); - } - } - } - } } /* temp struct used to transport needed info to expand_constraint_cb() */ @@ -9516,9 +9776,6 @@ static void expand_object_expandModifiers( static void expand_object(FileData *fd, Main *mainvar, Object *ob) { ParticleSystem *psys; - bSensor *sens; - bController *cont; - bActuator *act; bActionStrip *strip; PartEff *paf; int a; @@ -9534,6 +9791,24 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) modifiers_foreachIDLink(ob, expand_object_expandModifiers, (void *)&data); } + /* expand_object_expandModifier() */ + if (ob->greasepencil_modifiers.first) { + struct { FileData *fd; Main *mainvar; } data; + data.fd = fd; + data.mainvar = mainvar; + + BKE_gpencil_modifiers_foreachIDLink(ob, expand_object_expandModifiers, (void *)&data); + } + + /* expand_object_expandShaderFx() */ + if (ob->shader_fx.first) { + struct { FileData *fd; Main *mainvar; } data; + data.fd = fd; + data.mainvar = mainvar; + + BKE_shaderfx_foreachIDLink(ob, expand_object_expandModifiers, (void *)&data); + } + expand_pose(fd, mainvar, ob->pose); expand_doit(fd, mainvar, ob->poselib); expand_constraints(fd, mainvar, &ob->constraints); @@ -9575,84 +9850,6 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) for (psys = ob->particlesystem.first; psys; psys = psys->next) expand_doit(fd, mainvar, psys->part); - for (sens = ob->sensors.first; sens; sens = sens->next) { - if (sens->type == SENS_MESSAGE) { - bMessageSensor *ms = sens->data; - expand_doit(fd, mainvar, ms->fromObject); - } - } - - for (cont = ob->controllers.first; cont; cont = cont->next) { - if (cont->type == CONT_PYTHON) { - bPythonCont *pc = cont->data; - expand_doit(fd, mainvar, pc->text); - } - } - - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_SOUND) { - bSoundActuator *sa = act->data; - expand_doit(fd, mainvar, sa->sound); - } - else if (act->type == ACT_CAMERA) { - bCameraActuator *ca = act->data; - expand_doit(fd, mainvar, ca->ob); - } - else if (act->type == ACT_EDIT_OBJECT) { - bEditObjectActuator *eoa = act->data; - if (eoa) { - expand_doit(fd, mainvar, eoa->ob); - expand_doit(fd, mainvar, eoa->me); - } - } - else if (act->type == ACT_OBJECT) { - bObjectActuator *oa = act->data; - expand_doit(fd, mainvar, oa->reference); - } - else if (act->type == ACT_ADD_OBJECT) { - bAddObjectActuator *aoa = act->data; - expand_doit(fd, mainvar, aoa->ob); - } - else if (act->type == ACT_SCENE) { - bSceneActuator *sa = act->data; - expand_doit(fd, mainvar, sa->camera); - expand_doit(fd, mainvar, sa->scene); - } - else if (act->type == ACT_2DFILTER) { - bTwoDFilterActuator *tdfa = act->data; - expand_doit(fd, mainvar, tdfa->text); - } - else if (act->type == ACT_ACTION) { - bActionActuator *aa = act->data; - expand_doit(fd, mainvar, aa->act); - } - else if (act->type == ACT_SHAPEACTION) { - bActionActuator *aa = act->data; - expand_doit(fd, mainvar, aa->act); - } - else if (act->type == ACT_PROPERTY) { - bPropertyActuator *pa = act->data; - expand_doit(fd, mainvar, pa->ob); - } - else if (act->type == ACT_MESSAGE) { - bMessageActuator *ma = act->data; - expand_doit(fd, mainvar, ma->toObject); - } - else if (act->type==ACT_PARENT) { - bParentActuator *pa = act->data; - expand_doit(fd, mainvar, pa->ob); - } - else if (act->type == ACT_ARMATURE) { - bArmatureActuator *arma = act->data; - expand_doit(fd, mainvar, arma->target); - } - else if (act->type == ACT_STEERING) { - bSteeringActuator *sta = act->data; - expand_doit(fd, mainvar, sta->target); - expand_doit(fd, mainvar, sta->navmesh); - } - } - if (ob->pd) { expand_doit(fd, mainvar, ob->pd->tex); expand_doit(fd, mainvar, ob->pd->f_source); @@ -9679,15 +9876,27 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) } } +#ifdef USE_COLLECTION_COMPAT_28 +static void expand_scene_collection(FileData *fd, Main *mainvar, SceneCollection *sc) +{ + for (LinkData *link = sc->objects.first; link; link = link->next) { + expand_doit(fd, mainvar, link->data); + } + + for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { + expand_scene_collection(fd, mainvar, nsc); + } +} +#endif + static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) { - Base *base; SceneRenderLayer *srl; FreestyleModuleConfig *module; FreestyleLineSet *lineset; - for (base = sce->base.first; base; base = base->next) { - expand_doit(fd, mainvar, base->object); + for (Base *base_legacy = sce->base.first; base_legacy; base_legacy = base_legacy->next) { + expand_doit(fd, mainvar, base_legacy->object); } expand_doit(fd, mainvar, sce->camera); expand_doit(fd, mainvar, sce->world); @@ -9704,7 +9913,6 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) for (srl = sce->r.layers.first; srl; srl = srl->next) { expand_doit(fd, mainvar, srl->mat_override); - expand_doit(fd, mainvar, srl->light_override); for (module = srl->freestyleConfig.modules.first; module; module = module->next) { if (module->script) expand_doit(fd, mainvar, module->script); @@ -9716,8 +9924,22 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) } } - if (sce->r.dometext) - expand_doit(fd, mainvar, sce->gm.dome.warptext); + for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { + expand_idprops(fd, mainvar, view_layer->id_properties); + + for (module = view_layer->freestyle_config.modules.first; module; module = module->next) { + if (module->script) { + expand_doit(fd, mainvar, module->script); + } + } + + for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) { + if (lineset->group) { + expand_doit(fd, mainvar, lineset->group); + } + expand_doit(fd, mainvar, lineset->linestyle); + } + } if (sce->gpd) expand_doit(fd, mainvar, sce->gpd); @@ -9750,6 +9972,16 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) } expand_doit(fd, mainvar, sce->clip); + +#ifdef USE_COLLECTION_COMPAT_28 + if (sce->collection) { + expand_scene_collection(fd, mainvar, sce->collection); + } +#endif + + if (sce->master_collection) { + expand_collection(fd, mainvar, sce->master_collection); + } } static void expand_camera(FileData *fd, Main *mainvar, Camera *ca) @@ -9780,6 +10012,12 @@ static void expand_sound(FileData *fd, Main *mainvar, bSound *snd) expand_doit(fd, mainvar, snd->ipo); // XXX deprecated - old animation system } +static void expand_lightprobe(FileData *fd, Main *mainvar, LightProbe *prb) +{ + if (prb->adt) + expand_animdata(fd, mainvar, prb->adt); +} + static void expand_movieclip(FileData *fd, Main *mainvar, MovieClip *clip) { if (clip->adt) @@ -9849,8 +10087,27 @@ static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *li static void expand_gpencil(FileData *fd, Main *mainvar, bGPdata *gpd) { - if (gpd->adt) + if (gpd->adt) { expand_animdata(fd, mainvar, gpd->adt); + } + + for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + expand_doit(fd, mainvar, gpl->parent); + } + + for (int a = 0; a < gpd->totcol; a++) { + expand_doit(fd, mainvar, gpd->mat[a]); + } + +} + +static void expand_workspace(FileData *fd, Main *mainvar, WorkSpace *workspace) +{ + ListBase *layouts = BKE_workspace_layouts_get(workspace); + + for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { + expand_doit(fd, mainvar, BKE_workspace_layout_screen_get(layout)); + } } /** @@ -9886,6 +10143,7 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) id = lbarray[a]->first; while (id) { if (id->tag & LIB_TAG_NEED_EXPAND) { + expand_id(fd, mainvar, id); expand_idprops(fd, mainvar, id->properties); switch (GS(id->name)) { @@ -9931,6 +10189,9 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_SO: expand_sound(fd, mainvar, (bSound *)id); break; + case ID_LP: + expand_lightprobe(fd, mainvar, (LightProbe *)id); + break; case ID_AR: expand_armature(fd, mainvar, (bArmature *)id); break; @@ -9938,7 +10199,7 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) expand_action(fd, mainvar, (bAction *)id); // XXX deprecated - old animation system break; case ID_GR: - expand_group(fd, mainvar, (Group *)id); + expand_collection(fd, mainvar, (Collection *)id); break; case ID_NT: expand_nodetree(fd, mainvar, (bNodeTree *)id); @@ -9967,6 +10228,9 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_CF: expand_cachefile(fd, mainvar, (CacheFile *)id); break; + case ID_WS: + expand_workspace(fd, mainvar, (WorkSpace *)id); + break; default: break; } @@ -9984,12 +10248,12 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) /* ***************************** */ -static bool object_in_any_scene(Main *mainvar, Object *ob) +static bool object_in_any_scene(Main *bmain, Object *ob) { Scene *sce; - for (sce = mainvar->scene.first; sce; sce = sce->id.next) { - if (BKE_scene_base_find(sce, ob)) { + for (sce = bmain->scene.first; sce; sce = sce->id.next) { + if (BKE_scene_object_find(sce, ob)) { return true; } } @@ -9997,50 +10261,59 @@ static bool object_in_any_scene(Main *mainvar, Object *ob) return false; } -static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Library *lib, const short flag) +static Collection *get_collection_active( + Main *bmain, Scene *scene, ViewLayer *view_layer, const int flag) +{ + if (flag & FILE_ACTIVE_COLLECTION) { + LayerCollection *lc = BKE_layer_collection_get_active(view_layer); + return lc->collection; + } + else { + return BKE_collection_add(bmain, scene->master_collection, NULL); + } +} + +static void add_loose_objects_to_scene( + Main *mainvar, Main *bmain, Scene *scene, ViewLayer *view_layer, Library *lib, const short flag) { - Object *ob; - Base *base; - const unsigned int active_lay = (flag & FILE_ACTIVELAY) ? BKE_screen_view3d_layer_active(v3d, scene) : 0; const bool is_link = (flag & FILE_LINK) != 0; BLI_assert(scene); - /* give all objects which are LIB_TAG_INDIRECT a base, or for a group when *lib has been set */ - for (ob = mainvar->object.first; ob; ob = ob->id.next) { + /* Give all objects which are LIB_TAG_INDIRECT a base, or for a collection when *lib has been set. */ + for (Object *ob = mainvar->object.first; ob; ob = ob->id.next) { if ((ob->id.tag & LIB_TAG_INDIRECT) && (ob->id.tag & LIB_TAG_PRE_EXISTING) == 0) { bool do_it = false; - if (ob->id.us == 0) { - do_it = true; - } - else if (!is_link && (ob->id.lib == lib) && (object_in_any_scene(mainvar, ob) == 0)) { - /* When appending, make sure any indirectly loaded objects get a base, else they cant be accessed at all - * (see T27437). */ - do_it = true; + if (!is_link) { + if (ob->id.us == 0) { + do_it = true; + } + else if ((ob->id.lib == lib) && (object_in_any_scene(bmain, ob) == 0)) { + /* When appending, make sure any indirectly loaded objects get a base, else they cant be accessed at all + * (see T27437). */ + do_it = true; + } } if (do_it) { - base = MEM_callocN(sizeof(Base), __func__); - BLI_addtail(&scene->base, base); + CLAMP_MIN(ob->id.us, 0); + + Collection *active_collection = get_collection_active(bmain, scene, view_layer, FILE_ACTIVE_COLLECTION); + BKE_collection_object_add(bmain, active_collection, ob); + Base *base = BKE_view_layer_base_find(view_layer, ob); + BKE_scene_object_base_flag_sync_from_base(base); - if (active_lay) { - ob->lay = active_lay; - } if (flag & FILE_AUTOSELECT) { /* Note that link_object_postprocess() already checks for FILE_AUTOSELECT flag, - * but it will miss objects from non-instantiated groups... */ - ob->flag |= SELECT; - /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */ + * but it will miss objects from non-instantiated collections... */ + if (base->flag & BASE_SELECTABLE) { + base->flag |= BASE_SELECTED; + BKE_scene_object_base_flag_sync_from_base(base); + } + /* Do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level. */ } - base->object = ob; - base->lay = ob->lay; - base->flag = ob->flag; - - CLAMP_MIN(ob->id.us, 0); - id_us_plus_no_lib((ID *)ob); - ob->id.tag &= ~LIB_TAG_INDIRECT; ob->id.tag |= LIB_TAG_EXTERN; } @@ -10048,36 +10321,46 @@ static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Libra } } -static void give_base_to_groups( - Main *mainvar, Scene *scene, View3D *v3d, Library *UNUSED(lib), const short UNUSED(flag)) +static void add_collections_to_scene( + Main *mainvar, Main *bmain, Scene *scene, ViewLayer *view_layer, Library *UNUSED(lib), const short flag) { - Group *group; - Base *base; - Object *ob; - const unsigned int active_lay = BKE_screen_view3d_layer_active(v3d, scene); + Collection *active_collection = get_collection_active(bmain, scene, view_layer, FILE_ACTIVE_COLLECTION); + + /* Give all objects which are tagged a base. */ + for (Collection *collection = mainvar->collection.first; collection; collection = collection->id.next) { + if (collection->id.tag & LIB_TAG_DOIT) { + if (flag & FILE_GROUP_INSTANCE) { + /* Any indirect collection should not have been tagged. */ + BLI_assert((collection->id.tag & LIB_TAG_INDIRECT) == 0); + + /* BKE_object_add(...) messes with the selection. */ + Object *ob = BKE_object_add_only_object(bmain, OB_EMPTY, collection->id.name + 2); + ob->type = OB_EMPTY; + + BKE_collection_object_add(bmain, active_collection, ob); + Base *base = BKE_view_layer_base_find(view_layer, ob); - /* give all objects which are tagged a base */ - for (group = mainvar->group.first; group; group = group->id.next) { - if (group->id.tag & LIB_TAG_DOIT) { - /* any indirect group should not have been tagged */ - BLI_assert((group->id.tag & LIB_TAG_INDIRECT) == 0); + if (base->flag & BASE_SELECTABLE) { + base->flag |= BASE_SELECTED; + } - /* BKE_object_add(...) messes with the selection */ - ob = BKE_object_add_only_object(mainvar, OB_EMPTY, group->id.name + 2); - ob->type = OB_EMPTY; - ob->lay = active_lay; + BKE_scene_object_base_flag_sync_from_base(base); + DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); + view_layer->basact = base; - /* assign the base */ - base = BKE_scene_base_add(scene, ob); - base->flag |= SELECT; - base->object->flag = base->flag; - DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); - scene->basact = base; + /* Assign the collection. */ + ob->dup_group = collection; + id_us_plus(&collection->id); + ob->transflag |= OB_DUPLICOLLECTION; + copy_v3_v3(ob->loc, scene->cursor.location); + } + else { + /* Add collection as child of active collection. */ + BKE_collection_child_add(bmain, active_collection, collection); - /* assign the group */ - ob->dup_group = group; - ob->transflag |= OB_DUPLIGROUP; - copy_v3_v3(ob->loc, scene->cursor); + collection->id.tag &= ~LIB_TAG_INDIRECT; + collection->id.tag |= LIB_TAG_EXTERN; + } } } } @@ -10151,31 +10434,27 @@ static ID *link_named_part( return id; } -static void link_object_postprocess(ID *id, Scene *scene, View3D *v3d, const int flag) +static void link_object_postprocess(ID *id, Main *bmain, Scene *scene, ViewLayer *view_layer, const int flag) { if (scene) { + /* link to scene */ Base *base; Object *ob; - - base = MEM_callocN(sizeof(Base), "app_nam_part"); - BLI_addtail(&scene->base, base); + Collection *collection; ob = (Object *)id; - - /* link at active layer (view3d if available in context, else scene one */ - if (flag & FILE_ACTIVELAY) { - ob->lay = BKE_screen_view3d_layer_active(v3d, scene); - } - ob->mode = OB_MODE_OBJECT; - base->lay = ob->lay; - base->object = ob; - base->flag = ob->flag; - id_us_plus_no_lib((ID *)ob); + + collection = get_collection_active(bmain, scene, view_layer, flag); + BKE_collection_object_add(bmain, collection, ob); + base = BKE_view_layer_base_find(view_layer, ob); + BKE_scene_object_base_flag_sync_from_base(base); if (flag & FILE_AUTOSELECT) { - base->flag |= SELECT; - base->object->flag = base->flag; + if (base->flag & BASE_SELECTABLE) { + base->flag |= BASE_SELECTED; + BKE_scene_object_base_flag_sync_from_base(base); + } /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */ } } @@ -10205,11 +10484,11 @@ void BLO_library_link_copypaste(Main *mainl, BlendHandle *bh) id_sort_by_name(lb, id); if (bhead->code == ID_OB) { - /* Instead of instancing Base's directly, postpone until after groups are loaded - * otherwise the base's flag is set incorrectly when groups are used */ + /* Instead of instancing Base's directly, postpone until after collections are loaded + * otherwise the base's flag is set incorrectly when collections are used */ Object *ob = (Object *)id; ob->mode = OB_MODE_OBJECT; - /* ensure give_base_to_objects runs on this object */ + /* ensure add_loose_objects_to_scene runs on this object */ BLI_assert(id->us == 0); } } @@ -10218,17 +10497,16 @@ void BLO_library_link_copypaste(Main *mainl, BlendHandle *bh) static ID *link_named_part_ex( Main *mainl, FileData *fd, const short idcode, const char *name, const int flag, - Scene *scene, View3D *v3d) + Main *bmain, Scene *scene, ViewLayer *view_layer) { ID *id = link_named_part(mainl, fd, idcode, name, flag); if (id && (GS(id->name) == ID_OB)) { /* loose object: give a base */ - link_object_postprocess(id, scene, v3d, flag); + link_object_postprocess(id, bmain, scene, view_layer, flag); } else if (id && (GS(id->name) == ID_GR)) { - /* tag as needing to be instantiated */ - if (flag & FILE_GROUP_INSTANCE) - id->tag |= LIB_TAG_DOIT; + /* tag as needing to be instantiated or linked */ + id->tag |= LIB_TAG_DOIT; } return id; @@ -10251,24 +10529,24 @@ ID *BLO_library_link_named_part(Main *mainl, BlendHandle **bh, const short idcod /** * Link a named datablock from an external blend file. - * Optionally instantiate the object/group in the scene when the flags are set. + * Optionally instantiate the object/collection in the scene when the flags are set. * * \param mainl The main database to link from (not the active one). * \param bh The blender file handle. * \param idcode The kind of datablock to link. * \param name The name of the datablock (without the 2 char ID prefix). * \param flag Options for linking, used for instantiating. - * \param scene The scene in which to instantiate objects/groups (if NULL, no instantiation is done). - * \param v3d The active View3D (only to define active layers for instantiated objects & groups, can be NULL). + * \param scene The scene in which to instantiate objects/collections (if NULL, no instantiation is done). + * \param v3d The active View3D (only to define active layers for instantiated objects & collections, can be NULL). * \return the linked ID when found. */ ID *BLO_library_link_named_part_ex( Main *mainl, BlendHandle **bh, const short idcode, const char *name, const int flag, - Scene *scene, View3D *v3d) + Main *bmain, Scene *scene, ViewLayer *view_layer) { FileData *fd = (FileData*)(*bh); - return link_named_part_ex(mainl, fd, idcode, name, flag, scene, v3d); + return link_named_part_ex(mainl, fd, idcode, name, flag, bmain, scene, view_layer); } static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID *id, ID **r_id) @@ -10321,8 +10599,8 @@ static Main *library_link_begin(Main *mainvar, FileData **fd, const char *filepa (*fd)->mainlist = MEM_callocN(sizeof(ListBase), "FileData.mainlist"); - /* clear for group instantiating tag */ - BKE_main_id_tag_listbase(&(mainvar->group), LIB_TAG_DOIT, false); + /* clear for collection instantiating tag */ + BKE_main_id_tag_listbase(&(mainvar->collection), LIB_TAG_DOIT, false); /* make mains */ blo_split_main((*fd)->mainlist, mainvar); @@ -10381,7 +10659,7 @@ static void split_main_newid(Main *mainptr, Main *main_newid) } /* scene and v3d may be NULL. */ -static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene *scene, View3D *v3d) +static void library_link_end(Main *mainl, FileData **fd, const short flag, Main *bmain, Scene *scene, ViewLayer *view_layer) { Main *mainvar; Library *curlib; @@ -10411,19 +10689,21 @@ static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene mainl = NULL; /* blo_join_main free's mainl, cant use anymore */ lib_link_all(*fd, mainvar); + BKE_collections_after_lib_link(mainvar); /* Yep, second splitting... but this is a very cheap operation, so no big deal. */ blo_split_main((*fd)->mainlist, mainvar); - Main main_newid = {0}; + Main *main_newid = BKE_main_new(); for (mainvar = ((Main *)(*fd)->mainlist->first)->next; mainvar; mainvar = mainvar->next) { BLI_assert(mainvar->versionfile != 0); /* We need to split out IDs already existing, or they will go again through do_versions - bad, very bad! */ - split_main_newid(mainvar, &main_newid); + split_main_newid(mainvar, main_newid); - do_versions_after_linking(&main_newid); + do_versions_after_linking(main_newid); - add_main_to_main(mainvar, &main_newid); + add_main_to_main(mainvar, main_newid); } + BKE_main_free(main_newid); blo_join_main((*fd)->mainlist); mainvar = (*fd)->mainlist->first; MEM_freeN((*fd)->mainlist); @@ -10433,22 +10713,19 @@ static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene lib_verify_nodetree(mainvar, false); fix_relpaths_library(BKE_main_blendfile_path(mainvar), 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. - * Only directly linked objects & groups are instantiated by `BLO_library_link_named_part_ex()` & co, + /* Give a base to loose objects and collections. + * Only directly linked objects & collections are instantiated by `BLO_library_link_named_part_ex()` & co, * here we handle indirect ones and other possible edge-cases. */ if (scene) { - give_base_to_objects(mainvar, scene, v3d, curlib, flag); - - if (flag & FILE_GROUP_INSTANCE) { - give_base_to_groups(mainvar, scene, v3d, curlib, flag); - } + add_collections_to_scene(mainvar, bmain, scene, view_layer, curlib, flag); + add_loose_objects_to_scene(mainvar, bmain, scene, view_layer, curlib, flag); } else { /* printf("library_append_end, scene is NULL (objects wont get bases)\n"); */ } - /* clear group instantiating tag */ - BKE_main_id_tag_listbase(&(mainvar->group), LIB_TAG_DOIT, false); + /* clear collection instantiating tag */ + BKE_main_id_tag_listbase(&(mainvar->collection), LIB_TAG_DOIT, false); /* patch to prevent switch_endian happens twice */ if ((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) { @@ -10459,19 +10736,20 @@ static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene /** * Finalize linking from a given .blend file (library). - * Optionally instance the indirect object/group in the scene when the flags are set. + * Optionally instance the indirect object/collection in the scene when the flags are set. * \note Do not use \a bh after calling this function, it may frees it. * * \param mainl The main database to link from (not the active one). * \param bh The blender file handle (WARNING! may be freed by this function!). * \param flag Options for linking, used for instantiating. - * \param scene The scene in which to instantiate objects/groups (if NULL, no instantiation is done). - * \param v3d The active View3D (only to define active layers for instantiated objects & groups, can be NULL). + * \param bmain The main database in which to instantiate objects/collections + * \param scene The scene in which to instantiate objects/collections (if NULL, no instantiation is done). + * \param view_layer The scene layer in which to instantiate objects/collections (if NULL, no instantiation is done). */ -void BLO_library_link_end(Main *mainl, BlendHandle **bh, short flag, Scene *scene, View3D *v3d) +void BLO_library_link_end(Main *mainl, BlendHandle **bh, int flag, Main *bmain, Scene *scene, ViewLayer *view_layer) { FileData *fd = (FileData*)(*bh); - library_link_end(mainl, &fd, flag, scene, v3d); + library_link_end(mainl, &fd, flag, bmain, scene, view_layer); *bh = (BlendHandle*)fd; } @@ -10689,19 +10967,19 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) } /* do versions, link, and free */ - Main main_newid = {0}; + Main *main_newid = BKE_main_new(); for (mainptr = mainl->next; mainptr; mainptr = mainptr->next) { /* some mains still have to be read, then versionfile is still zero! */ if (mainptr->versionfile) { /* We need to split out IDs already existing, or they will go again through do_versions - bad, very bad! */ - split_main_newid(mainptr, &main_newid); + split_main_newid(mainptr, main_newid); if (mainptr->curlib->filedata) // can be zero... with shift+f1 append - do_versions(mainptr->curlib->filedata, mainptr->curlib, &main_newid); + do_versions(mainptr->curlib->filedata, mainptr->curlib, main_newid); else - do_versions(basefd, NULL, &main_newid); + do_versions(basefd, NULL, main_newid); - add_main_to_main(mainptr, &main_newid); + add_main_to_main(mainptr, main_newid); } if (mainptr->curlib->filedata) @@ -10710,29 +10988,5 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) if (mainptr->curlib->filedata) blo_freefiledata(mainptr->curlib->filedata); mainptr->curlib->filedata = NULL; } -} - - -/* reading runtime */ - -BlendFileData *blo_read_blendafterruntime(int file, const char *name, int actualsize, ReportList *reports) -{ - BlendFileData *bfd = NULL; - FileData *fd = filedata_new(); - fd->filedes = file; - fd->buffersize = actualsize; - fd->read = fd_read_from_file; - - /* needed for library_append and read_libraries */ - BLI_strncpy(fd->relabase, name, sizeof(fd->relabase)); - - fd = blo_decode_and_check(fd, reports); - if (!fd) - return NULL; - - fd->reports = reports; - bfd = blo_read_file_internal(fd, ""); - blo_freefiledata(fd); - - return bfd; + BKE_main_free(main_newid); } diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index 66161d86f02..10f0c7a2942 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -34,6 +34,8 @@ #define __READFILE_H__ #include "zlib.h" +#include "DNA_sdna_types.h" +#include "DNA_space_types.h" #include "DNA_windowmanager_types.h" /* for ReportType */ struct OldNewMap; @@ -88,6 +90,7 @@ typedef struct FileData { struct OldNewMap *libmap; struct OldNewMap *imamap; struct OldNewMap *movieclipmap; + struct OldNewMap *scenemap; struct OldNewMap *soundmap; struct OldNewMap *packedmap; @@ -138,6 +141,8 @@ FileData *blo_openblendermemfile(struct MemFile *memfile, struct ReportList *rep void blo_clear_proxy_pointers_from_lib(Main *oldmain); void blo_make_image_pointer_map(FileData *fd, Main *oldmain); void blo_end_image_pointer_map(FileData *fd, Main *oldmain); +void blo_make_scene_pointer_map(FileData *fd, Main *oldmain); +void blo_end_scene_pointer_map(FileData *fd, Main *oldmain); void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain); void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain); void blo_make_sound_pointer_map(FileData *fd, Main *oldmain); @@ -171,7 +176,9 @@ void blo_do_versions_pre250(struct FileData *fd, struct Library *lib, struct Mai void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *bmain); +void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *bmain); void do_versions_after_linking_270(struct Main *bmain); +void do_versions_after_linking_280(struct Main *bmain); #endif diff --git a/source/blender/blenloader/intern/runtime.c b/source/blender/blenloader/intern/runtime.c deleted file mode 100644 index 985e8169819..00000000000 --- a/source/blender/blenloader/intern/runtime.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - * - */ - -/** - * \file runtime.c - * \brief This file handles the loading of .blend files embedded in runtimes - * \ingroup blenloader - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> - -#ifdef WIN32 -# include <io.h> // read, open -# include "BLI_winstuff.h" -#else // ! WIN32 -# include <unistd.h> // read -#endif - -#include "BLI_blenlib.h" -#include "BLI_utildefines.h" - -#include "BLO_readfile.h" -#include "BLO_runtime.h" - -#include "BKE_report.h" - -/* Runtime reading */ - -static int handle_read_msb_int(int handle) -{ - unsigned char buf[4]; - - if (read(handle, buf, 4) != 4) - return -1; - - return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3] << 0); -} - -int BLO_is_a_runtime(const char *path) -{ - int res = 0, fd = BLI_open(path, O_BINARY | O_RDONLY, 0); - int datastart; - char buf[8]; - - if (fd == -1) - goto cleanup; - - lseek(fd, -12, SEEK_END); - - datastart = handle_read_msb_int(fd); - - if (datastart == -1) - goto cleanup; - else if (read(fd, buf, 8) != 8) - goto cleanup; - else if (memcmp(buf, "BRUNTIME", 8) != 0) - goto cleanup; - else - res = 1; - -cleanup: - if (fd != -1) - close(fd); - - return res; -} - -BlendFileData *BLO_read_runtime(const char *path, ReportList *reports) -{ - BlendFileData *bfd = NULL; - size_t actualsize; - int fd, datastart; - char buf[8]; - - fd = BLI_open(path, O_BINARY | O_RDONLY, 0); - - if (fd == -1) { - BKE_reportf(reports, RPT_ERROR, "Unable to open '%s': %s", path, strerror(errno)); - goto cleanup; - } - - actualsize = BLI_file_descriptor_size(fd); - - lseek(fd, -12, SEEK_END); - - datastart = handle_read_msb_int(fd); - - if (datastart == -1) { - BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (problem seeking)", path); - goto cleanup; - } - else if (read(fd, buf, 8) != 8) { - BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (truncated header)", path); - goto cleanup; - } - else if (memcmp(buf, "BRUNTIME", 8) != 0) { - BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (not a blend file)", path); - goto cleanup; - } - else { - //printf("starting to read runtime from %s at datastart %d\n", path, datastart); - lseek(fd, datastart, SEEK_SET); - bfd = blo_read_blendafterruntime(fd, path, actualsize - datastart, reports); - fd = -1; // file was closed in blo_read_blendafterruntime() - } - -cleanup: - if (fd != -1) - close(fd); - - return bfd; -} diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 28720ef5145..390fa460a55 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -39,7 +39,6 @@ #include "DNA_anim_types.h" #include "DNA_armature_types.h" -#include "DNA_actuator_types.h" #include "DNA_brush_types.h" #include "DNA_camera_types.h" #include "DNA_cloth_types.h" @@ -84,7 +83,6 @@ #include "BKE_sequencer.h" #include "BKE_texture.h" #include "BKE_sound.h" -#include "BKE_sca.h" #include "NOD_socket.h" @@ -101,7 +99,7 @@ static void area_add_header_region(ScrArea *sa, ListBase *lb) BLI_addtail(lb, ar); ar->regiontype = RGN_TYPE_HEADER; - if (sa->headertype == HEADERDOWN) + if (sa->headertype == 1) ar->alignment = RGN_ALIGN_BOTTOM; else ar->alignment = RGN_ALIGN_TOP; @@ -287,19 +285,6 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) //ar->v2d.flag |= V2D_IS_INITIALISED; } break; - case SPACE_TIME: - { - SpaceTime *stime = (SpaceTime *)sl; - memcpy(&ar->v2d, &stime->v2d, sizeof(View2D)); - - ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL); - ar->v2d.align |= V2D_ALIGN_NO_NEG_Y; - ar->v2d.keepofs |= V2D_LOCKOFS_Y; - ar->v2d.keepzoom |= V2D_LOCKZOOM_Y; - ar->v2d.tot.ymin = ar->v2d.cur.ymin = -10.0; - ar->v2d.min[1] = ar->v2d.max[1] = 20.0; - } - break; case SPACE_IPO: { SpaceIpo *sipo = (SpaceIpo *)sl; @@ -444,9 +429,6 @@ static void do_versions_windowmanager_2_50(bScreen *screen) sl->spacetype = SPACE_EMPTY; /* 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; @@ -517,70 +499,6 @@ static void do_versions_gpencil_2_50(Main *main, bScreen *screen) } } -static void do_version_mtex_factor_2_50(MTex **mtex_array, short idtype) -{ - MTex *mtex; - float varfac, colfac; - int a, neg; - - if (!mtex_array) - return; - - for (a = 0; a < MAX_MTEX; a++) { - if (mtex_array[a]) { - mtex = mtex_array[a]; - - neg = mtex->maptoneg; - varfac = mtex->varfac; - colfac = mtex->colfac; - - if (neg & MAP_DISP) mtex->dispfac = -mtex->dispfac; - if (neg & MAP_NORM) mtex->norfac = -mtex->norfac; - if (neg & MAP_WARP) mtex->warpfac = -mtex->warpfac; - - mtex->colspecfac = (neg & MAP_COLSPEC)? -colfac: colfac; - mtex->mirrfac = (neg & MAP_COLMIR)? -colfac: colfac; - mtex->alphafac = (neg & MAP_ALPHA)? -varfac: varfac; - mtex->difffac = (neg & MAP_REF)? -varfac: varfac; - mtex->specfac = (neg & MAP_SPEC)? -varfac: varfac; - mtex->emitfac = (neg & MAP_EMIT)? -varfac: varfac; - mtex->hardfac = (neg & MAP_HAR)? -varfac: varfac; - mtex->raymirrfac = (neg & MAP_RAYMIRR)? -varfac: varfac; - mtex->translfac = (neg & MAP_TRANSLU)? -varfac: varfac; - mtex->ambfac = (neg & MAP_AMB)? -varfac: varfac; - mtex->colemitfac = (neg & MAP_EMISSION_COL)? -colfac: colfac; - mtex->colreflfac = (neg & MAP_REFLECTION_COL)? -colfac: colfac; - mtex->coltransfac = (neg & MAP_TRANSMISSION_COL)? -colfac: colfac; - mtex->densfac = (neg & MAP_DENSITY)? -varfac: varfac; - mtex->scatterfac = (neg & MAP_SCATTERING)? -varfac: varfac; - mtex->reflfac = (neg & MAP_REFLECTION)? -varfac: varfac; - - mtex->timefac = (neg & MAP_PA_TIME)? -varfac: varfac; - mtex->lengthfac = (neg & MAP_PA_LENGTH)? -varfac: varfac; - mtex->clumpfac = (neg & MAP_PA_CLUMP)? -varfac: varfac; - mtex->kinkfac = (neg & MAP_PA_KINK)? -varfac: varfac; - mtex->roughfac = (neg & MAP_PA_ROUGH)? -varfac: varfac; - mtex->padensfac = (neg & MAP_PA_DENS)? -varfac: varfac; - mtex->lifefac = (neg & MAP_PA_LIFE)? -varfac: varfac; - mtex->sizefac = (neg & MAP_PA_SIZE)? -varfac: varfac; - mtex->ivelfac = (neg & MAP_PA_IVEL)? -varfac: varfac; - - mtex->shadowfac = (neg & LAMAP_SHAD)? -colfac: colfac; - - mtex->zenupfac = (neg & WOMAP_ZENUP)? -colfac: colfac; - mtex->zendownfac = (neg & WOMAP_ZENDOWN)? -colfac: colfac; - mtex->blendfac = (neg & WOMAP_BLEND)? -varfac: varfac; - - if (idtype == ID_MA) - mtex->colfac = (neg & MAP_COL)? -colfac: colfac; - else if (idtype == ID_LA) - mtex->colfac = (neg & LAMAP_COL)? -colfac: colfac; - else if (idtype == ID_WO) - mtex->colfac = (neg & WOMAP_HORIZ)? -colfac: colfac; - } - } -} - static void do_version_mdef_250(Main *main) { Object *ob; @@ -610,13 +528,7 @@ static void do_version_constraints_radians_degrees_250(ListBase *lb) bConstraint *con; for (con = lb->first; con; con = con->next) { - if (con->type == CONSTRAINT_TYPE_RIGIDBODYJOINT) { - bRigidBodyJointConstraint *data = con->data; - 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) { + if (con->type == CONSTRAINT_TYPE_KINEMATIC) { bKinematicConstraint *data = con->data; data->poleangle *= (float)(M_PI / 180.0); } @@ -725,7 +637,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) Base *base; Material *ma; Camera *cam; - Mesh *me; Curve *cu; Scene *sce; Tex *tx; @@ -736,8 +647,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) bSound *sound; Sequence *seq; - bActuator *act; - int a; for (sound = bmain->sound.first; sound; sound = sound->id.next) { if (sound->newpackedfile) { @@ -746,33 +655,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } } - for (ob = bmain->object.first; ob; ob = ob->id.next) { - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_SOUND) { - bSoundActuator *sAct = (bSoundActuator*) act->data; - if (sAct->sound) { - sound = blo_do_versions_newlibadr(fd, lib, sAct->sound); - sAct->flag = (sound->flags & SOUND_FLAGS_3D) ? ACT_SND_3D_SOUND : 0; - sAct->pitch = sound->pitch; - sAct->volume = sound->volume; - sAct->sound3D.reference_distance = sound->distance; - sAct->sound3D.max_gain = sound->max_gain; - sAct->sound3D.min_gain = sound->min_gain; - sAct->sound3D.rolloff_factor = sound->attenuation; - } - else { - sAct->sound3D.reference_distance = 1.0f; - sAct->volume = 1.0f; - sAct->sound3D.max_gain = 1.0f; - sAct->sound3D.rolloff_factor = 1.0f; - } - sAct->sound3D.cone_inner_angle = 360.0f; - sAct->sound3D.cone_outer_angle = 360.0f; - sAct->sound3D.max_distance = FLT_MAX; - } - } - } - for (scene = bmain->scene.first; scene; scene = scene->id.next) { if (scene->ed && scene->ed->seqbasep) { SEQ_BEGIN (scene->ed, seq) @@ -809,15 +691,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (ma = bmain->mat.first; ma; ma = ma->id.next) { if (ma->nodetree && ma->nodetree->id.name[0] == '\0') strcpy(ma->nodetree->id.name, "NTShader Nodetree"); - - /* which_output 0 is now "not specified" */ - for (a = 0; a < MAX_MTEX; a++) { - if (ma->mtex[a]) { - tx = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex); - if (tx && tx->use_nodes) - ma->mtex[a]->which_output++; - } - } } /* and composite trees */ @@ -855,10 +728,12 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } } +#if 0 /* ME_DRAWEDGES and others was moved to viewport. */ /* copy standard draw flag to meshes(used to be global, is not available here) */ for (me = bmain->mesh.first; me; me = me->id.next) { - me->drawflag = ME_DRAWEDGES|ME_DRAWFACES|ME_DRAWCREASES; + me->drawflag = ME_DRAWEDGES | ME_DRAWFACES | ME_DRAWCREASES; } +#endif /* particle draw and render types */ for (part = bmain->particle.first; part; part = part->id.next) { @@ -903,7 +778,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 1)) { Object *ob; - Material *ma; Tex *tex; Scene *sce; ToolSettings *ts; @@ -949,65 +823,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) tex->afmax = 8; } - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - int a; - - if (ma->mode & MA_WIRE) { - ma->material_type = MA_TYPE_WIRE; - ma->mode &= ~MA_WIRE; - } - - if (ma->mode & MA_HALO) { - ma->material_type = MA_TYPE_HALO; - ma->mode &= ~MA_HALO; - } - - if (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP)) { - ma->mode |= MA_TRANSP; - } - else { - /* ma->mode |= MA_ZTRANSP; */ /* leave ztransp as is even if its not used [#28113] */ - ma->mode &= ~MA_TRANSP; - } - - /* set new bump for unused slots */ - for (a = 0; a < MAX_MTEX; a++) { - if (ma->mtex[a]) { - tex = ma->mtex[a]->tex; - if (!tex) { - ma->mtex[a]->texflag |= MTEX_3TAP_BUMP; - ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE; - } - else { - tex = (Tex*) blo_do_versions_newlibadr(fd, ma->id.lib, tex); - if (tex && tex->type == 0) { /* invalid type */ - ma->mtex[a]->texflag |= MTEX_3TAP_BUMP; - ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE; - } - } - } - } - - /* volume rendering settings */ - if (ma->vol.stepsize < 0.0001f) { - ma->vol.density = 1.0f; - ma->vol.emission = 0.0f; - ma->vol.scattering = 1.0f; - ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f; - ma->vol.density_scale = 1.0f; - ma->vol.depth_cutoff = 0.01f; - ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED; - ma->vol.stepsize = 0.2f; - ma->vol.shade_type = MA_VOL_SHADE_SHADED; - ma->vol.shadeflag |= MA_VOL_PRECACHESHADING; - ma->vol.precache_resolution = 50; - } - } - for (sce = bmain->scene.first; sce; sce = sce->id.next) { ts = sce->toolsettings; - if (ts->normalsize == 0.0f || !ts->uv_selectmode || ts->vgroup_weight == 0.0f) { - ts->normalsize = 0.1f; + if (!ts->uv_selectmode || ts->vgroup_weight == 0.0f) { ts->selectmode = SCE_SELECT_VERTEX; /* autokeying - setting should be taken from the user-prefs @@ -1020,95 +838,12 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) ts->uv_selectmode = UV_SELECT_VERTEX; ts->vgroup_weight = 1.0f; } - - /* Game Settings */ - /* Dome */ - sce->gm.dome.angle = sce->r.domeangle; - sce->gm.dome.mode = sce->r.domemode; - sce->gm.dome.res = sce->r.domeres; - sce->gm.dome.resbuf = sce->r.domeresbuf; - sce->gm.dome.tilt = sce->r.dometilt; - sce->gm.dome.warptext = sce->r.dometext; - - /* Stand Alone */ - sce->gm.playerflag |= (sce->r.fullscreen ? GAME_PLAYER_FULLSCREEN : 0); - sce->gm.xplay = sce->r.xplay; - sce->gm.yplay = sce->r.yplay; - sce->gm.freqplay = sce->r.freqplay; - sce->gm.depth = sce->r.depth; - sce->gm.attrib = sce->r.attrib; - - /* Stereo */ - sce->gm.stereomode = sce->r.stereomode; - /* reassigning stereomode NO_STEREO and DOME to a separeted flag*/ - if (sce->gm.stereomode == 1) { // 1 = STEREO_NOSTEREO - sce->gm.stereoflag = STEREO_NOSTEREO; - sce->gm.stereomode = STEREO_ANAGLYPH; - } - else if (sce->gm.stereomode == 8) { // 8 = STEREO_DOME - sce->gm.stereoflag = STEREO_DOME; - sce->gm.stereomode = STEREO_ANAGLYPH; - } - else - sce->gm.stereoflag = STEREO_ENABLED; - - /* Framing */ - sce->gm.framing = sce->framing; - sce->gm.xplay = sce->r.xplay; - sce->gm.yplay = sce->r.yplay; - sce->gm.freqplay = sce->r.freqplay; - sce->gm.depth = sce->r.depth; - - /* Physic (previously stored in world) */ - sce->gm.gravity =9.8f; - sce->gm.physicsEngine = WOPHY_BULLET; /* Bullet by default */ - sce->gm.mode = WO_DBVT_CULLING; /* DBVT culling by default */ - sce->gm.occlusionRes = 128; - sce->gm.ticrate = 60; - sce->gm.maxlogicstep = 5; - sce->gm.physubstep = 1; - sce->gm.maxphystep = 5; } } if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 2)) { - Scene *sce; Object *ob; - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - if (fd->fileflags & G_FILE_ENABLE_ALL_FRAMES) - sce->gm.flag |= GAME_ENABLE_ALL_FRAMES; - if (fd->fileflags & G_FILE_SHOW_DEBUG_PROPS) - sce->gm.flag |= GAME_SHOW_DEBUG_PROPS; - if (fd->fileflags & G_FILE_SHOW_FRAMERATE) - sce->gm.flag |= GAME_SHOW_FRAMERATE; - if (fd->fileflags & G_FILE_SHOW_PHYSICS) - sce->gm.flag |= GAME_SHOW_PHYSICS; - if (fd->fileflags & G_FILE_GLSL_NO_SHADOWS) - sce->gm.flag |= GAME_GLSL_NO_SHADOWS; - if (fd->fileflags & G_FILE_GLSL_NO_SHADERS) - sce->gm.flag |= GAME_GLSL_NO_SHADERS; - if (fd->fileflags & G_FILE_GLSL_NO_RAMPS) - sce->gm.flag |= GAME_GLSL_NO_RAMPS; - if (fd->fileflags & G_FILE_GLSL_NO_NODES) - sce->gm.flag |= GAME_GLSL_NO_NODES; - if (fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX) - sce->gm.flag |= GAME_GLSL_NO_EXTRA_TEX; - if (fd->fileflags & G_FILE_GLSL_NO_ENV_LIGHTING) - sce->gm.flag |= GAME_GLSL_NO_ENV_LIGHTING; - if (fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS) - sce->gm.flag |= GAME_IGNORE_DEPRECATION_WARNINGS; - - if (fd->fileflags & G_FILE_GAME_MAT_GLSL) - sce->gm.matmode = GAME_MAT_GLSL; - else if (fd->fileflags & G_FILE_GAME_MAT) - sce->gm.matmode = GAME_MAT_MULTITEX; - else - sce->gm.matmode = GAME_MAT_TEXFACE; - - sce->gm.flag |= GAME_DISPLAY_LISTS; - } - for (ob = bmain->object.first; ob; ob = ob->id.next) { if (ob->flag & 8192) // OB_POSEMODE = 8192 ob->mode |= OB_MODE_POSE; @@ -1118,10 +853,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 4)) { Scene *sce; Object *ob; - Material *ma; - Lamp *la; - World *wo; - Tex *tex; ParticleSettings *part; bool do_gravity = false; @@ -1139,27 +870,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) ob->rotmode = ROT_MODE_EUL; } - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - if (ma->vol.reflection == 0.f) { - ma->vol.reflection = 1.f; - ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f; - ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f; - } - - do_version_mtex_factor_2_50(ma->mtex, ID_MA); - } - - for (la = bmain->lamp.first; la; la = la->id.next) - do_version_mtex_factor_2_50(la->mtex, ID_LA); - - for (wo = bmain->world.first; wo; wo = wo->id.next) - do_version_mtex_factor_2_50(wo->mtex, ID_WO); - - for (tex = bmain->tex.first; tex; tex = tex->id.next) - if (tex->vd) - if (tex->vd->extend == 0) - tex->vd->extend = TEX_CLIP; - for (sce = bmain->scene.first; sce; sce = sce->id.next) { if (sce->audio.main == 0.0f) sce->audio.main = 1.0f; @@ -1220,7 +930,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 6)) { Object *ob; - Lamp *la; /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialization */ for (ob = bmain->object.first; ob; ob = ob->id.next) { @@ -1238,9 +947,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } } } - - for (la = bmain->lamp.first; la; la = la->id.next) - la->compressthresh = 0.05f; } if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 7)) { @@ -1309,8 +1015,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) while (sce) { if (sce->r.frame_step == 0) sce->r.frame_step = 1; - if (sce->r.mblur_samples == 0) - sce->r.mblur_samples = sce->r.osa; sce = sce->id.next; } @@ -1363,7 +1067,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile == 250) { Scene *sce = bmain->scene.first; Material *ma = bmain->mat.first; - World *wo = bmain->world.first; Tex *tex = bmain->tex.first; int i, convert = 0; @@ -1381,26 +1084,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (convert) { while (ma) { - if (ma->ramp_col) { - ColorBand *band = (ColorBand *)ma->ramp_col; - for (i = 0; i < band->tot; i++) { - CBData *data = band->data + i; - srgb_to_linearrgb_v3_v3(&data->r, &data->r); - } - } - - if (ma->ramp_spec) { - ColorBand *band = (ColorBand *)ma->ramp_spec; - for (i = 0; i < band->tot; i++) { - CBData *data = band->data + i; - srgb_to_linearrgb_v3_v3(&data->r, &data->r); - } - } - srgb_to_linearrgb_v3_v3(&ma->r, &ma->r); srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr); - srgb_to_linearrgb_v3_v3(&ma->mirr, &ma->mirr); - srgb_to_linearrgb_v3_v3(ma->sss_col, ma->sss_col); ma = ma->id.next; } @@ -1414,13 +1099,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } tex = tex->id.next; } - - while (wo) { - srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr); - srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr); - srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr); - wo = wo->id.next; - } } } } @@ -1549,15 +1227,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 12)) { - Scene *sce; Object *ob; Brush *brush; - Material *ma; - - /* game engine changes */ - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - sce->gm.eyeseparation = 0.10f; - } /* anim viz changes */ for (ob = bmain->object.first; ob; ob = ob->id.next) { @@ -1639,14 +1310,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) BKE_texture_mtex_default(&brush->mtex); BKE_texture_mtex_default(&brush->mask_mtex); } - - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - if (ma->vol.ms_spread < 0.0001f) { - ma->vol.ms_spread = 0.2f; - ma->vol.ms_diff = 1.f; - ma->vol.ms_intensity = 1.f; - } - } } if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 13)) { @@ -1705,41 +1368,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 15)) { - World *wo; - Material *ma; - - /* ambient default from 0.5f to 1.0f */ - for (ma = bmain->mat.first; ma; ma = ma->id.next) - ma->amb *= 2.0f; - - for (wo = bmain->world.first; wo; wo = wo->id.next) { - /* ao splitting into ao/env/indirect */ - wo->ao_env_energy = wo->aoenergy; - wo->aoenergy = 1.0f; - - if (wo->ao_indirect_bounces == 0) - wo->ao_indirect_bounces = 1; - else - wo->mode |= WO_INDIRECT_LIGHT; - - if (wo->aomix == WO_AOSUB) - wo->ao_env_energy = -wo->ao_env_energy; - else if (wo->aomix == WO_AOADDSUB) - wo->mode |= WO_AMB_OCC; - - wo->aomix = WO_AOMUL; - - /* ambient default from 0.5f to 1.0f */ - mul_v3_fl(&wo->ambr, 0.5f); - wo->ao_env_energy *= 0.5f; - } - } - if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 17)) { Scene *sce; Sequence *seq; - Material *ma; /* initialize to sane default so toggling on border shows something */ for (sce = bmain->scene.first; sce; sce = sce->id.next) { @@ -1771,10 +1402,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) pset->brush[a].strength /= 100.0f; } - for (ma = bmain->mat.first; ma; ma = ma->id.next) - if (ma->mode & MA_TRACEBLE) - ma->shade_flag |= MA_APPROX_OCCLUSION; - /* sequencer changes */ { bScreen *screen; @@ -1952,14 +1579,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } } } - else if (sl->spacetype == SPACE_TIME) { - SpaceTime *stime = (SpaceTime *) sl; - - /* enable all cache display */ - stime->cache_display |= TIME_CACHE_DISPLAY; - stime->cache_display |= (TIME_CACHE_SOFTBODY|TIME_CACHE_PARTICLES); - stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE|TIME_CACHE_DYNAMICPAINT); - } } } } @@ -2179,7 +1798,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) Brush *br; ParticleSettings *part; bScreen *sc; - Object *ob; for (br = bmain->brush.first; br; br = br->id.next) { if (br->ob_mode == 0) @@ -2219,41 +1837,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } } } - - /* 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 = bmain->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; - } - } - } - - /* init facing axis property of steering actuators */ - { - Object *ob; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - bActuator *act; - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_STEERING) { - bSteeringActuator *stact = act->data; - if (stact == NULL) {//HG1 - init_actuator(act); - } - else { - if (stact->facingaxis == 0) { - stact->facingaxis = 1; - } - } - } - } - } } if (bmain->versionfile < 255 || (bmain->versionfile == 255 && bmain->subversionfile < 3)) { @@ -2412,27 +1995,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) Brush *brush; Object *ob; ParticleSettings *part; - Material *mat; - int tex_nr, transp_tex; - - for (mat = bmain->mat.first; mat; mat = mat->id.next) { - if (!(mat->mode & MA_TRANSP) && !(mat->material_type & MA_TYPE_VOLUME)) { - transp_tex = 0; - - for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) { - if (!mat->mtex[tex_nr]) - continue; - if (mat->mtex[tex_nr]->mapto & MAP_ALPHA) - transp_tex = 1; - } - - /* weak! material alpha could be animated */ - if (mat->alpha < 1.0f || mat->fresnel_tra > 0.0f || transp_tex) { - mat->mode |= MA_TRANSP; - mat->mode &= ~(MA_ZTRANSP|MA_RAYTRANSP); - } - } - } /* redraws flag in SpaceTime has been moved to Screen level */ for (sc = bmain->screen.first; sc; sc = sc->id.next) { @@ -2526,41 +2088,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } { - /* Initialize texture point density curve falloff */ - Tex *tex; - for (tex = bmain->tex.first; tex; tex = tex->id.next) { - if (tex->pd) { - if (tex->pd->falloff_speed_scale == 0.0f) - tex->pd->falloff_speed_scale = 100.0f; - - if (!tex->pd->falloff_curve) { - tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1); - - tex->pd->falloff_curve->preset = CURVE_PRESET_LINE; - tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; - curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE); - curvemapping_changed(tex->pd->falloff_curve, false); - } - } - } - } - - { - /* add default value for behind strength of camera actuator */ - Object *ob; - bActuator *act; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_CAMERA) { - bCameraActuator *ba = act->data; - - ba->damping = 1.0/32.0; - } - } - } - } - - { ParticleSettings *part; for (part = bmain->particle.first; part; part = part->id.next) { /* Initialize particle billboard scale */ @@ -2651,50 +2178,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } } } - - { - /* convert fcurve and shape action actuators to action actuators */ - Object *ob; - bActuator *act; - bIpoActuator *ia; - bActionActuator *aa; - - for (ob = bmain->object.first; ob; ob = ob->id.next) { - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_IPO) { - /* Create the new actuator */ - ia = act->data; - aa = MEM_callocN(sizeof(bActionActuator), "fcurve -> action actuator do_version"); - - /* Copy values */ - aa->type = ia->type; - aa->flag = ia->flag; - aa->sta = ia->sta; - aa->end = ia->end; - BLI_strncpy(aa->name, ia->name, sizeof(aa->name)); - BLI_strncpy(aa->frameProp, ia->frameProp, sizeof(aa->frameProp)); - if (ob->adt) - aa->act = ob->adt->action; - - /* Get rid of the old actuator */ - MEM_freeN(ia); - - /* Assign the new actuator */ - act->data = aa; - act->type = act->otype = ACT_ACTION; - - /* Fix for converting 2.4x files: if we don't have an action, but we have an - * object IPO, then leave the actuator as an IPO actuator for now and let the - * IPO conversion code handle it */ - if (ob->ipo && !aa->act) - act->type = ACT_IPO; - } - else if (act->type == ACT_SHAPEACTION) { - act->type = act->otype = ACT_ACTION; - } - } - } - } } if (bmain->versionfile < 259 || (bmain->versionfile == 259 && bmain->subversionfile < 2)) { @@ -2742,41 +2225,5 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) part->time_flag &= ~PART_TIME_AUTOSF; } } - - { - /* set defaults for obstacle avoidance, recast data */ - Scene *sce; - for (sce = bmain->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 = (float)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 = 8.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; - } - } } } diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index c5062ed1e16..9efaca83126 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -31,7 +31,6 @@ #define DNA_DEPRECATED_ALLOW #include "DNA_anim_types.h" -#include "DNA_actuator_types.h" #include "DNA_brush_types.h" #include "DNA_camera_types.h" #include "DNA_cloth_types.h" @@ -43,11 +42,9 @@ #include "DNA_meshdata_types.h" #include "DNA_object_fluidsim_types.h" #include "DNA_object_types.h" -#include "DNA_property_types.h" #include "DNA_text_types.h" #include "DNA_view3d_types.h" #include "DNA_screen_types.h" -#include "DNA_sensor_types.h" #include "DNA_sdna_types.h" #include "DNA_smoke_types.h" #include "DNA_space_types.h" @@ -67,7 +64,6 @@ #include "BKE_modifier.h" #include "BKE_particle.h" #include "BKE_pointcache.h" -#include "BKE_property.h" // for BKE_bproperty_object_get #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_sequencer.h" @@ -432,25 +428,6 @@ static void do_versions_nodetree_frame_2_64_6(bNodeTree *ntree) } } -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; @@ -900,14 +877,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } } { - /* Initialize BGE exit key to esc key */ - Scene *scene; - for (scene = bmain->scene.first; scene; scene = scene->id.next) { - if (!scene->gm.exitkey) - scene->gm.exitkey = 218; // Blender key code for ESC - } - } - { MovieClip *clip; Object *ob; @@ -943,45 +912,10 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } - { - /* Warn the user if he is using ["Text"] properties for Font objects */ - Object *ob; - bProperty *prop; - - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->type == OB_FONT) { - prop = BKE_bproperty_object_get(ob, "Text"); - if (prop) { - blo_reportf_wrap(fd->reports, RPT_WARNING, - TIP_("Game property name conflict in object '%s': text objects reserve the " - "['Text'] game property to change their content through logic bricks"), - ob->id.name + 2); - } - } - } - } } if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 2)) { { - /* convert Camera Actuator values to defines */ - Object *ob; - bActuator *act; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_CAMERA) { - bCameraActuator *ba = act->data; - - if (ba->axis == (float) 'x') ba->axis = OB_POSX; - else if (ba->axis == (float)'y') ba->axis = OB_POSY; - /* don't do an if/else to avoid imediate subversion bump*/ -// ba->axis=((ba->axis == (float)'x') ? OB_POSX_X : OB_POSY); - } - } - } - } - - { /* convert deprecated sculpt_paint_unified_* fields to * UnifiedPaintSettings */ Scene *scene; @@ -1222,15 +1156,9 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 4)) { - Lamp *la; Camera *cam; Curve *cu; - for (la = bmain->lamp.first; la; la = la->id.next) { - if (la->shadow_frustum_size == 0.0f) - la->shadow_frustum_size = 10.0f; - } - for (cam = bmain->camera.first; cam; cam = cam->id.next) { if (cam->flag & CAM_PANORAMA) { cam->type = CAM_PANO; @@ -1316,19 +1244,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - - if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 8)) { - /* set new deactivation values for game settings */ - Scene *sce; - - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - /* Game Settings */ - sce->gm.lineardeactthreshold = 0.8f; - sce->gm.angulardeactthreshold = 1.0f; - sce->gm.deactivationtime = 2.0f; - } - } - if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 9)) { FOREACH_NODETREE(bmain, ntree, id) { if (ntree->type == NTREE_SHADER) { @@ -1339,7 +1254,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) tex->iuser.frames = 1; tex->iuser.sfra = 1; - tex->iuser.fie_ima = 2; tex->iuser.ok = 1; } } @@ -1420,14 +1334,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 12)) { - Material *ma; - - for (ma = bmain->mat.first; ma; ma = ma->id.next) - if (ma->strand_widthfade == 2.0f) - ma->strand_widthfade = 0.0f; - } - if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 13)) { FOREACH_NODETREE(bmain, ntree, id) { if (ntree->type == NTREE_COMPOSIT) { @@ -1574,20 +1480,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - /* remove texco */ if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 21)) { - Material *ma; - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - int a; - for (a = 0; a < MAX_MTEX; a++) { - if (ma->mtex[a]) { - if (ma->mtex[a]->texco == TEXCO_STICKY_) { - ma->mtex[a]->texco = TEXCO_UV; - } - } - } - } - { Mesh *me; for (me = bmain->mesh.first; me; me = me->id.next) { @@ -1738,24 +1631,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } FOREACH_NODETREE_END } - if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 6)) { - bScreen *sc; - - for (sc = bmain->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 (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) { /* convert tiles size from resolution and number of tiles */ { @@ -1763,17 +1638,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (scene = bmain->scene.first; scene; scene = scene->id.next) { if (scene->r.tilex == 0 || scene->r.tiley == 1) { - if (scene->r.xparts && scene->r.yparts) { - /* 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); - } - else { - /* happens when mixing using current trunk and previous release */ - scene->r.tilex = scene->r.tiley = 64; - } + scene->r.tilex = scene->r.tiley = 64; } } } @@ -1809,17 +1674,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - if (bmain->versionfile < 265) { - Object *ob; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->step_height == 0.0f) { - ob->step_height = 0.15f; - ob->jump_speed = 10.0f; - ob->fall_speed = 55.0f; - } - } - } - if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 3)) { bScreen *sc; for (sc = bmain->screen.first; sc; sc = sc->id.next) { @@ -1831,7 +1685,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) case SPACE_VIEW3D: { View3D *v3d = (View3D *)sl; - v3d->flag2 |= V3D_SHOW_GPENCIL; + v3d->flag2 |= V3D_SHOW_ANNOTATION; break; } case SPACE_SEQ: @@ -1855,7 +1709,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) case SPACE_CLIP: { SpaceClip *sclip = (SpaceClip *)sl; - sclip->flag |= SC_SHOW_GPENCIL; + sclip->flag |= SC_SHOW_ANNOTATION; break; } } @@ -1870,7 +1724,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (scene = bmain->scene.first; scene; scene = scene->id.next) { Sequence *seq; - bool set_premul = false; SEQ_BEGIN (scene->ed, seq) { @@ -1885,24 +1738,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) if (scene->r.bake_samples == 0) scene->r.bake_samples = 256; - - if (scene->world) { - World *world = blo_do_versions_newlibadr(fd, scene->id.lib, scene->world); - - if (world && is_zero_v3(&world->horr)) { - if ((world->skytype & WO_SKYBLEND) == 0 || is_zero_v3(&world->zenr)) { - set_premul = true; - } - } - } - else - set_premul = true; - - if (set_premul) { - printf("2.66 versioning fix: replacing black sky with premultiplied alpha for scene %s\n", - scene->id.name + 2); - scene->r.alphamode = R_ALPHAPREMUL; - } } for (Image *image = bmain->image.first; image; image = image->id.next) { @@ -2335,32 +2170,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } - - for (ob = bmain->object.first; ob; ob = ob->id.next) { - bSensor *sens; - bTouchSensor *ts; - bCollisionSensor *cs; - Material *ma; - - for (sens = ob->sensors.first; sens; sens = sens->next) { - if (sens->type == SENS_TOUCH) { - ts = sens->data; - cs = MEM_callocN(sizeof(bCollisionSensor), "touch -> collision sensor do_version"); - - if (ts->ma) { - ma = blo_do_versions_newlibadr(fd, ob->id.lib, ts->ma); - BLI_strncpy(cs->materialName, ma->id.name + 2, sizeof(cs->materialName)); - } - - cs->mode = SENS_COLLISION_MATERIAL; - - MEM_freeN(ts); - - sens->data = cs; - sens->type = sens->otype = SENS_COLLISION; - } - } - } } if (!MAIN_VERSION_ATLEAST(bmain, 268, 5)) { @@ -2453,11 +2262,13 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) if (sl->spacetype == SPACE_OUTLINER) { SpaceOops *so = (SpaceOops *)sl; - if (!ELEM(so->outlinevis, SO_ALL_SCENES, SO_CUR_SCENE, SO_VISIBLE, SO_SELECTED, SO_ACTIVE, - SO_SAME_TYPE, SO_GROUPS, SO_LIBRARIES, SO_SEQUENCE, SO_DATABLOCKS, - SO_USERDEF)) + if (!ELEM(so->outlinevis, + SO_SCENES, + SO_LIBRARIES, + SO_SEQUENCE, + SO_DATA_API)) { - so->outlinevis = SO_ALL_SCENES; + so->outlinevis = SO_SCENES; } } } @@ -2511,10 +2322,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) if (ts->sculpt) ts->sculpt->flags |= SCULPT_DYNTOPO_SUBDIVIDE; - /* single texture mode removed from game engine */ - if (scene->gm.matmode == GAME_MAT_TEXFACE) - scene->gm.matmode = GAME_MAT_MULTITEX; - /* 'Increment' mode disabled for nodes, use true grid snapping instead */ if (scene->toolsettings->snap_node_mode == SCE_SNAP_MODE_INCREMENT) scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID; @@ -2541,8 +2348,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (ob = bmain->object.first; ob; ob = ob->id.next) { ModifierData *md; - bSensor *bs; - bActuator *ba; for (md = ob->modifiers.first; md; md = md->next) { if (md->type == eModifierType_EdgeSplit) { @@ -2554,28 +2359,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) bmd->bevel_angle = DEG2RADF(bmd->bevel_angle); } } - - for (bs = ob->sensors.first; bs; bs = bs->next) { - if (bs->type == SENS_RADAR) { - bRadarSensor *brs = bs->data; - brs->angle = DEG2RADF(brs->angle); - } - } - - for (ba = ob->actuators.first; ba; ba = ba->next) { - if (ba->type == ACT_CONSTRAINT) { - bConstraintActuator *bca = ba->data; - if (bca->type == ACT_CONST_TYPE_ORI) { - bca->minloc[0] = DEG2RADF(bca->minloc[0]); - bca->maxloc[0] = DEG2RADF(bca->maxloc[0]); - } - } - else if (ba->type == ACT_SOUND) { - bSoundActuator *bsa = ba->data; - bsa->sound3D.cone_outer_angle = DEG2RADF(bsa->sound3D.cone_outer_angle); - bsa->sound3D.cone_inner_angle = DEG2RADF(bsa->sound3D.cone_inner_angle); - } - } } for (scene = bmain->scene.first; scene; scene = scene->id.next) { diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 7b787725084..fadf332c850 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -52,7 +52,6 @@ #include "DNA_modifier_types.h" #include "DNA_particle_types.h" #include "DNA_linestyle_types.h" -#include "DNA_actuator_types.h" #include "DNA_view3d_types.h" #include "DNA_smoke_types.h" #include "DNA_rigidbody_types.h" @@ -77,6 +76,9 @@ #include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_string.h" +#include "BLI_string_utils.h" + +#include "BLT_translation.h" #include "BLO_readfile.h" @@ -88,6 +90,64 @@ #include "MEM_guardedalloc.h" +/* ************************************************** */ +/* GP Palettes API (Deprecated) */ + +/* add a new gp-palette */ +static bGPDpalette *BKE_gpencil_palette_addnew(bGPdata *gpd, const char *name) +{ + bGPDpalette *palette; + + /* check that list is ok */ + if (gpd == NULL) { + return NULL; + } + + /* allocate memory and add to end of list */ + palette = MEM_callocN(sizeof(bGPDpalette), "bGPDpalette"); + + /* add to datablock */ + BLI_addtail(&gpd->palettes, palette); + + /* set basic settings */ + /* auto-name */ + BLI_strncpy(palette->info, name, sizeof(palette->info)); + BLI_uniquename(&gpd->palettes, palette, DATA_("GP_Palette"), '.', offsetof(bGPDpalette, info), + sizeof(palette->info)); + + /* return palette */ + return palette; +} + +/* add a new gp-palettecolor */ +static bGPDpalettecolor *BKE_gpencil_palettecolor_addnew(bGPDpalette *palette, const char *name) +{ + bGPDpalettecolor *palcolor; + + /* check that list is ok */ + if (palette == NULL) { + return NULL; + } + + /* allocate memory and add to end of list */ + palcolor = MEM_callocN(sizeof(bGPDpalettecolor), "bGPDpalettecolor"); + + /* add to datablock */ + BLI_addtail(&palette->colors, palcolor); + + /* set basic settings */ + copy_v4_v4(palcolor->color, U.gpencil_new_layer_col); + ARRAY_SET_ITEMS(palcolor->fill, 1.0f, 1.0f, 1.0f); + + /* auto-name */ + BLI_strncpy(palcolor->info, name, sizeof(palcolor->info)); + BLI_uniquename(&palette->colors, palcolor, DATA_("Color"), '.', offsetof(bGPDpalettecolor, info), + sizeof(palcolor->info)); + + /* return palette color */ + return palcolor; +} + /** * Setup rotation stabilization from ancient single track spec. * Former Version of 2D stabilization used a single tracking marker to determine the rotation @@ -308,18 +368,6 @@ static char *replace_bbone_easing_rnapath(char *old_path) } } -/* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already. - * But in 2.79 another case generating non-unique names was discovered (see T55668, involving Meta strips)... */ -static void do_versions_seq_unique_name_all_strips(Scene *sce, ListBase *seqbasep) -{ - for (Sequence *seq = seqbasep->first; seq != NULL; seq = seq->next) { - BKE_sequence_base_unique_name_recursive(&sce->ed->seqbase, seq); - if (seq->seqbase.first != NULL) { - do_versions_seq_unique_name_all_strips(sce, &seq->seqbase); - } - } -} - static void do_version_bbone_easing_fcurve_fix(ID *UNUSED(id), FCurve *fcu, void *UNUSED(user_data)) { /* F-Curve's path (for bbone_in/out) */ @@ -418,7 +466,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (!MAIN_VERSION_ATLEAST(bmain, 270, 1)) { - Scene *sce; Object *ob; /* Update Transform constraint (another deg -> rad stuff). */ @@ -433,12 +480,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } - - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) { - sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO; - } - } } if (!MAIN_VERSION_ATLEAST(bmain, 270, 2)) { @@ -501,13 +542,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (!MAIN_VERSION_ATLEAST(bmain, 271, 0)) { - if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) { - Material *ma; - - for (ma = bmain->mat.first; ma; ma = ma->id.next) - ma->mode2 = MA_CASTSHADOW; - } - if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) { Scene *sce; @@ -566,29 +600,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - if (!MAIN_VERSION_ATLEAST(bmain, 271, 2)) { - /* init up & track axis property of trackto actuators */ - Object *ob; - - for (ob = bmain->object.first; ob; ob = ob->id.next) { - bActuator *act; - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_EDIT_OBJECT) { - bEditObjectActuator *eoact = act->data; - eoact->trackflag = ob->trackflag; - /* if trackflag is pointing +-Z axis then upflag should point Y axis. - * Rest of trackflag cases, upflag should be point z axis */ - if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) { - eoact->upflag = 1; - } - else { - eoact->upflag = 2; - } - } - } - } - } - if (!MAIN_VERSION_ATLEAST(bmain, 271, 3)) { Brush *br; @@ -869,40 +880,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } - - if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) { - Scene *scene; - for (scene = bmain->scene.first; scene; scene = scene->id.next) { - scene->gm.scehysteresis = 10; - } - } - } - - if (!MAIN_VERSION_ATLEAST(bmain, 274, 2)) { - FOREACH_NODETREE(bmain, ntree, id) { - bNode *node; - bNodeSocket *sock; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == SH_NODE_MATERIAL) { - for (sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Refl")) { - BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name)); - } - } - } - else if (node->type == SH_NODE_MATERIAL_EXT) { - for (sock = node->outputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Refl")) { - BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name)); - } - else if (STREQ(sock->name, "Ray Mirror")) { - BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name)); - } - } - } - } - } FOREACH_NODETREE_END } if (!MAIN_VERSION_ATLEAST(bmain, 274, 4)) { @@ -1104,16 +1081,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } #undef LA_YF_PHOTON } - - { - Object *ob; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) { - ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX; - } - } - } - } if (!MAIN_VERSION_ATLEAST(bmain, 276, 3)) { @@ -1224,12 +1191,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) else gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS; } - - if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) { - for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { - ob->max_jumps = 1; - } - } } if (!MAIN_VERSION_ATLEAST(bmain, 276, 5)) { ListBase *lbarray[MAX_LIBARRAY]; @@ -1444,8 +1405,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) ToolSettings *ts = scene->toolsettings; /* initialize use position for sculpt brushes */ ts->gp_sculpt.flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION; - /* initialize selected vertices alpha factor */ - ts->gp_sculpt.alpha = 1.0f; /* new strength sculpt brush */ if (ts->gp_sculpt.brush[0].size >= 11) { @@ -1458,25 +1417,16 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; } } - /* create a default grease pencil drawing brushes set */ - if (!BLI_listbase_is_empty(&bmain->gpencil)) { - for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { - ToolSettings *ts = scene->toolsettings; - if (BLI_listbase_is_empty(&ts->gp_brushes)) { - BKE_gpencil_brush_init_presets(ts); - } - } - } /* Convert Grease Pencil to new palettes/brushes * Loop all strokes and create the palette and all colors */ for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) { if (BLI_listbase_is_empty(&gpd->palettes)) { /* create palette */ - bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette", true); + bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette"); for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { /* create color using layer name */ - bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info, true); + bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info); if (palcolor != NULL) { /* set color attributes */ copy_v4_v4(palcolor->color, gpl->color); @@ -1486,7 +1436,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) if (gpl->flag & GP_LAYER_LOCKED) palcolor->flag |= PC_COLOR_LOCKED; if (gpl->flag & GP_LAYER_ONIONSKIN) palcolor->flag |= PC_COLOR_ONIONSKIN; if (gpl->flag & GP_LAYER_VOLUMETRIC) palcolor->flag |= PC_COLOR_VOLUMETRIC; - if (gpl->flag & GP_LAYER_HQ_FILL) palcolor->flag |= PC_COLOR_HQ_FILL; /* set layer opacity to 1 */ gpl->opacity = 1.0f; @@ -1499,8 +1448,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* set stroke to palette and force recalculation */ BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname)); - gps->palcolor = NULL; - gps->flag |= GP_STROKE_RECALC_COLOR; gps->thickness = gpl->thickness; /* set alpha strength to 1 */ @@ -1510,13 +1457,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } - - /* set thickness to 0 (now it is a factor to override stroke thickness) */ - gpl->thickness = 0.0f; } - /* set first color as active */ - if (palette->colors.first) - BKE_gpencil_palettecolor_setactive(palette, palette->colors.first); } } } @@ -1838,14 +1779,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } - - if (!MAIN_VERSION_ATLEAST(bmain, 279, 6)) { - for (Scene *sce = bmain->scene.first; sce != NULL; sce = sce->id.next) { - if (sce->ed != NULL && sce->ed->seqbase.first != NULL) { - do_versions_seq_unique_name_all_strips(sce, &sce->ed->seqbase); - } - } - } } void do_versions_after_linking_270(Main *bmain) diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c new file mode 100644 index 00000000000..ab52a9b8b8f --- /dev/null +++ b/source/blender/blenloader/intern/versioning_280.c @@ -0,0 +1,2168 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Dalai Felinto + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +/** \file blender/blenloader/intern/versioning_280.c + * \ingroup blenloader + */ + +/* allow readfile to use deprecated functionality */ +#define DNA_DEPRECATED_ALLOW + +#include <string.h> +#include <float.h> + +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_mempool.h" +#include "BLI_string.h" +#include "BLI_string_utf8.h" +#include "BLI_utildefines.h" + +#include "DNA_object_types.h" +#include "DNA_camera_types.h" +#include "DNA_cloth_types.h" +#include "DNA_collection_types.h" +#include "DNA_constraint_types.h" +#include "DNA_gpu_types.h" +#include "DNA_lamp_types.h" +#include "DNA_layer_types.h" +#include "DNA_lightprobe_types.h" +#include "DNA_material_types.h" +#include "DNA_mesh_types.h" +#include "DNA_modifier_types.h" +#include "DNA_particle_types.h" +#include "DNA_rigidbody_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_view3d_types.h" +#include "DNA_genfile.h" +#include "DNA_gpencil_types.h" +#include "DNA_workspace_types.h" +#include "DNA_key_types.h" +#include "DNA_curve_types.h" +#include "DNA_armature_types.h" + +#include "BKE_action.h" +#include "BKE_collection.h" +#include "BKE_constraint.h" +#include "BKE_customdata.h" +#include "BKE_colortools.h" +#include "BKE_freestyle.h" +#include "BKE_idprop.h" +#include "BKE_image.h" +#include "BKE_layer.h" +#include "BKE_main.h" +#include "BKE_material.h" +#include "BKE_mesh.h" +#include "BKE_node.h" +#include "BKE_pointcache.h" +#include "BKE_report.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_sequencer.h" +#include "BKE_studiolight.h" +#include "BKE_workspace.h" +#include "BKE_gpencil.h" +#include "BKE_paint.h" +#include "BKE_object.h" +#include "BKE_cloth.h" +#include "BKE_key.h" +#include "BKE_unit.h" + +#include "DEG_depsgraph.h" + +#include "BLT_translation.h" + +#include "BLO_readfile.h" +#include "readfile.h" + +#include "MEM_guardedalloc.h" + +static bScreen *screen_parent_find(const bScreen *screen) +{ + /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */ + if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) { + for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + if (sa->full && sa->full != screen) { + BLI_assert(sa->full->state == screen->state); + return sa->full; + } + } + } + + return NULL; +} + +static void do_version_workspaces_create_from_screens(Main *bmain) +{ + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + const bScreen *screen_parent = screen_parent_find(screen); + WorkSpace *workspace; + if (screen->temp) { + continue; + } + + if (screen_parent) { + /* fullscreen with "Back to Previous" option, don't create + * a new workspace, add layout workspace containing parent */ + workspace = BLI_findstring( + &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2); + } + else { + workspace = BKE_workspace_add(bmain, screen->id.name + 2); + } + if (workspace == NULL) { + continue; /* Not much we can do.. */ + } + BKE_workspace_layout_add(bmain, workspace, screen, screen->id.name + 2); + } +} + +static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene) +{ + SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION); + SpaceAction *saction = (SpaceAction *)stype->new(area, scene); + ARegion *region_channels; + + /* Properly free current regions */ + for (ARegion *region = area->regionbase.first; region; region = region->next) { + BKE_area_region_free(area->type, region); + } + BLI_freelistN(&area->regionbase); + + area->type = stype; + area->spacetype = stype->spaceid; + + BLI_addhead(&area->spacedata, saction); + area->regionbase = saction->regionbase; + BLI_listbase_clear(&saction->regionbase); + + /* Different defaults for timeline */ + region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS); + region_channels->flag |= RGN_FLAG_HIDDEN; + + saction->mode = SACTCONT_TIMELINE; + saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED; + saction->ads.filterflag |= ADS_FILTER_SUMMARY; +} + +/** + * \brief After lib-link versioning for new workspace design. + * + * - Adds a workspace for (almost) each screen of the old file + * and adds the needed workspace-layout to wrap the screen. + * - Active screen isn't stored directly in window anymore, but in the active workspace. + * - Active scene isn't stored in screen anymore, but in window. + * - Create workspace instance hook for each window. + * + * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend. + */ +static void do_version_workspaces_after_lib_link(Main *bmain) +{ + BLI_assert(BLI_listbase_is_empty(&bmain->workspaces)); + + do_version_workspaces_create_from_screens(bmain); + + for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { + for (wmWindow *win = wm->windows.first; win; win = win->next) { + bScreen *screen_parent = screen_parent_find(win->screen); + bScreen *screen = screen_parent ? screen_parent : win->screen; + + if (screen->temp) { + /* We do not generate a new workspace for those screens... still need to set some data in win. */ + win->workspace_hook = BKE_workspace_instance_hook_create(bmain); + win->scene = screen->scene; + /* Deprecated from now on! */ + win->screen = NULL; + continue; + } + + WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2); + BLI_assert(workspace != NULL); + ListBase *layouts = BKE_workspace_layouts_get(workspace); + + win->workspace_hook = BKE_workspace_instance_hook_create(bmain); + + BKE_workspace_active_set(win->workspace_hook, workspace); + BKE_workspace_active_layout_set(win->workspace_hook, layouts->first); + + /* Move scene and view layer to window. */ + Scene *scene = screen->scene; + ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay); + if (!layer) { + layer = BKE_view_layer_default_view(scene); + } + + win->scene = scene; + STRNCPY(win->view_layer_name, layer->name); + + /* Deprecated from now on! */ + win->screen = NULL; + } + } + + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + /* Deprecated from now on! */ + BLI_freelistN(&screen->scene->transform_spaces); + screen->scene = NULL; + } +} + +#ifdef USE_COLLECTION_COMPAT_28 +enum { + COLLECTION_DEPRECATED_VISIBLE = (1 << 0), + COLLECTION_DEPRECATED_VIEWPORT = (1 << 0), + COLLECTION_DEPRECATED_SELECTABLE = (1 << 1), + COLLECTION_DEPRECATED_DISABLED = (1 << 2), + COLLECTION_DEPRECATED_RENDER = (1 << 3), +}; + +static void do_version_view_layer_visibility(ViewLayer *view_layer) +{ + /* Convert from deprecated VISIBLE flag to DISABLED */ + LayerCollection *lc; + for (lc = view_layer->layer_collections.first; + lc; + lc = lc->next) + { + if (lc->flag & COLLECTION_DEPRECATED_DISABLED) { + lc->flag &= ~COLLECTION_DEPRECATED_DISABLED; + } + + if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) { + lc->flag |= COLLECTION_DEPRECATED_DISABLED; + } + + lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER; + } +} + +static void do_version_layer_collection_pre( + ViewLayer *view_layer, + ListBase *lb, + GSet *enabled_set, + GSet *selectable_set) +{ + /* Convert from deprecated DISABLED to new layer collection and collection flags */ + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + if (lc->scene_collection) { + if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) { + BLI_gset_insert(enabled_set, lc->scene_collection); + } + if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) { + BLI_gset_insert(selectable_set, lc->scene_collection); + } + } + + do_version_layer_collection_pre(view_layer, &lc->layer_collections, enabled_set, selectable_set); + } +} + +static void do_version_layer_collection_post( + ViewLayer *view_layer, + ListBase *lb, + GSet *enabled_set, + GSet *selectable_set, + GHash *collection_map) +{ + /* Apply layer collection exclude flags. */ + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + if (!(lc->collection->flag & COLLECTION_IS_MASTER)) { + SceneCollection *sc = BLI_ghash_lookup(collection_map, lc->collection); + const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc)); + const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc)); + + if (!enabled) { + lc->flag |= LAYER_COLLECTION_EXCLUDE; + } + if (enabled && !selectable) { + lc->collection->flag |= COLLECTION_RESTRICT_SELECT; + } + } + + do_version_layer_collection_post( + view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map); + } +} + +static void do_version_scene_collection_convert( + Main *bmain, + ID *id, + SceneCollection *sc, + Collection *collection, + GHash *collection_map) +{ + if (collection_map) { + BLI_ghash_insert(collection_map, collection, sc); + } + + for (SceneCollection *nsc = sc->scene_collections.first; nsc;) { + SceneCollection *nsc_next = nsc->next; + Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name); + ncollection->id.lib = id->lib; + do_version_scene_collection_convert(bmain, id, nsc, ncollection, collection_map); + nsc = nsc_next; + } + + for (LinkData *link = sc->objects.first; link; link = link->next) { + Object *ob = link->data; + if (ob) { + BKE_collection_object_add(bmain, collection, ob); + id_us_min(&ob->id); + } + } + + BLI_freelistN(&sc->objects); + MEM_freeN(sc); +} + +static void do_version_group_collection_to_collection(Main *bmain, Collection *group) +{ + /* Convert old 2.8 group collections to new unified collections. */ + if (group->collection) { + do_version_scene_collection_convert(bmain, &group->id, group->collection, group, NULL); + } + + group->collection = NULL; + group->view_layer = NULL; + id_fake_user_set(&group->id); +} + +static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene) +{ + /* Convert old 2.8 scene collections to new unified collections. */ + + /* Temporarily clear view layers so we don't do any layer collection syncing + * and destroy old flags that we want to restore. */ + ListBase view_layers = scene->view_layers; + BLI_listbase_clear(&scene->view_layers); + + if (!scene->master_collection) { + scene->master_collection = BKE_collection_master_add(); + } + + /* Convert scene collections. */ + GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); + if (scene->collection) { + do_version_scene_collection_convert(bmain, &scene->id, scene->collection, scene->master_collection, collection_map); + scene->collection = NULL; + } + + scene->view_layers = view_layers; + + /* Convert layer collections. */ + ViewLayer *view_layer; + for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { + GSet *enabled_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); + GSet *selectable_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); + + do_version_layer_collection_pre( + view_layer, &view_layer->layer_collections, enabled_set, selectable_set); + + BKE_layer_collection_sync(scene, view_layer); + + do_version_layer_collection_post( + view_layer, &view_layer->layer_collections, enabled_set, selectable_set, collection_map); + + BLI_gset_free(enabled_set, NULL); + BLI_gset_free(selectable_set, NULL); + + BKE_layer_collection_sync(scene, view_layer); + } + + BLI_ghash_free(collection_map, NULL, NULL); +} +#endif + + +static void do_version_layers_to_collections(Main *bmain, Scene *scene) +{ + /* Since we don't have access to FileData we check the (always valid) first + * render layer instead. */ + if (!scene->master_collection) { + scene->master_collection = BKE_collection_master_add(); + } + + if (scene->view_layers.first) { + return; + } + + /* Create collections from layers. */ + Collection *collection_master = BKE_collection_master(scene); + Collection *collections[20] = {NULL}; + + for (int layer = 0; layer < 20; layer++) { + for (Base *base = scene->base.first; base; base = base->next) { + if (base->lay & (1 << layer)) { + /* Create collections when needed only. */ + if (collections[layer] == NULL) { + char name[MAX_NAME]; + + BLI_snprintf(name, + sizeof(collection_master->id.name), + DATA_("Collection %d"), + layer + 1); + + Collection *collection = BKE_collection_add(bmain, collection_master, name); + collection->id.lib = scene->id.lib; + collections[layer] = collection; + + if (!(scene->lay & (1 << layer))) { + collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER; + } + } + + /* Note usually this would do slow collection syncing for view layers, + * but since no view layers exists yet at this point it's fast. */ + BKE_collection_object_add( + bmain, + collections[layer], base->object); + } + + if (base->flag & SELECT) { + base->object->flag |= SELECT; + } + else { + base->object->flag &= ~SELECT; + } + } + } + + /* Handle legacy render layers. */ + bool have_override = false; + + for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) { + ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name); + + if (srl->samples != 0) { + have_override = true; + + /* It is up to the external engine to handle + * its own doversion in this case. */ + BKE_override_view_layer_int_add( + view_layer, + ID_SCE, + "samples", + srl->samples); + } + + if (srl->mat_override) { + have_override = true; + + BKE_override_view_layer_datablock_add( + view_layer, + ID_MA, + "self", + (ID *)srl->mat_override); + } + + if (srl->layflag & SCE_LAY_DISABLE) { + view_layer->flag &= ~VIEW_LAYER_RENDER; + } + + if ((srl->layflag & SCE_LAY_FRS) == 0) { + view_layer->flag &= ~VIEW_LAYER_FREESTYLE; + } + + /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */ + view_layer->layflag = srl->layflag; + /* XXX Not sure if we should keep the passes (dfelinto). */ + view_layer->passflag = srl->passflag; + view_layer->pass_xor = srl->pass_xor; + view_layer->pass_alpha_threshold = srl->pass_alpha_threshold; + + BKE_freestyle_config_free(&view_layer->freestyle_config, true); + view_layer->freestyle_config = srl->freestyleConfig; + view_layer->id_properties = srl->prop; + + /* Set exclusion and overrides. */ + for (int layer = 0; layer < 20; layer++) { + Collection *collection = collections[layer]; + if (collection) { + LayerCollection *lc = BKE_layer_collection_first_from_scene_collection(view_layer, collection); + + if (srl->lay_exclude & (1 << layer)) { + /* Disable excluded layer. */ + have_override = true; + lc->flag |= LAYER_COLLECTION_EXCLUDE; + for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { + nlc->flag |= LAYER_COLLECTION_EXCLUDE; + } + } + else { + if (srl->lay_zmask & (1 << layer)) { + have_override = true; + lc->flag |= LAYER_COLLECTION_HOLDOUT; + } + + if ((srl->lay & (1 << layer)) == 0) { + have_override = true; + lc->flag |= LAYER_COLLECTION_INDIRECT_ONLY; + } + } + } + } + + /* for convenience set the same active object in all the layers */ + if (scene->basact) { + view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object); + } + + for (Base *base = view_layer->object_bases.first; base; base = base->next) { + if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) { + base->flag |= BASE_SELECTED; + } + } + } + + BLI_freelistN(&scene->r.layers); + + /* If render layers included overrides, we also create a vanilla + * viewport layer without them. */ + if (have_override) { + ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport"); + + /* Make it first in the list. */ + BLI_remlink(&scene->view_layers, view_layer); + BLI_addhead(&scene->view_layers, view_layer); + + /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */ + if (!BLI_listbase_is_single(&scene->view_layers)) { + view_layer->flag &= ~VIEW_LAYER_RENDER; + } + + /* convert active base */ + if (scene->basact) { + view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object); + } + + /* convert selected bases */ + for (Base *base = view_layer->object_bases.first; base; base = base->next) { + if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) { + base->flag |= BASE_SELECTED; + } + + /* keep lay around for forward compatibility (open those files in 2.79) */ + base->lay = base->object->lay; + } + } + + /* remove bases once and for all */ + for (Base *base = scene->base.first; base; base = base->next) { + id_us_min(&base->object->id); + } + + BLI_freelistN(&scene->base); + scene->basact = NULL; +} + +static void do_version_collection_propagate_lib_to_children(Collection *collection) +{ + if (collection->id.lib != NULL) { + for (CollectionChild *collection_child = collection->children.first; + collection_child != NULL; + collection_child = collection_child->next) + { + if (collection_child->collection->id.lib == NULL) { + collection_child->collection->id.lib = collection->id.lib; + } + do_version_collection_propagate_lib_to_children(collection_child->collection); + } + } +} + +void do_versions_after_linking_280(Main *bmain) +{ + bool use_collection_compat_28 = true; + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) { + use_collection_compat_28 = false; + + /* Convert group layer visibility flags to hidden nested collection. */ + for (Collection *collection = bmain->collection.first; collection; collection = collection->id.next) { + /* Add fake user for all existing groups. */ + id_fake_user_set(&collection->id); + + if (collection->flag & (COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER)) { + continue; + } + + Collection *hidden_collection_array[20] = {NULL}; + for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) { + cob_next = cob->next; + Object *ob = cob->ob; + + if (!(ob->lay & collection->layer)) { + /* Find or create hidden collection matching object's first layer. */ + Collection **collection_hidden = NULL; + int coll_idx = 0; + for (; coll_idx < 20; coll_idx++) { + if (ob->lay & (1 << coll_idx)) { + collection_hidden = &hidden_collection_array[coll_idx]; + break; + } + } + BLI_assert(collection_hidden != NULL); + + if (*collection_hidden == NULL) { + char name[MAX_ID_NAME]; + BLI_snprintf(name, sizeof(name), DATA_("Hidden %d"), coll_idx + 1); + *collection_hidden = BKE_collection_add(bmain, collection, name); + (*collection_hidden)->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER; + } + + BKE_collection_object_add(bmain, *collection_hidden, ob); + BKE_collection_object_remove(bmain, collection, ob, true); + } + } + } + + /* We need to assign lib pointer to generated hidden collections *after* all have been created, otherwise we'll + * end up with several datablocks sharing same name/library, which is FORBIDDEN! + * Note: we need this to be recursive, since a child collection may be sorted before its parent in bmain... */ + for (Collection *collection = bmain->collection.first; collection != NULL; collection = collection->id.next) { + do_version_collection_propagate_lib_to_children(collection); + } + + /* Convert layers to collections. */ + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + do_version_layers_to_collections(bmain, scene); + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + /* same render-layer as do_version_workspaces_after_lib_link will activate, + * so same layer as BKE_view_layer_default_view would return */ + ViewLayer *layer = screen->scene->view_layers.first; + + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *space = sa->spacedata.first; space; space = space->next) { + if (space->spacetype == SPACE_OUTLINER) { + SpaceOops *soutliner = (SpaceOops *)space; + + soutliner->outlinevis = SO_VIEW_LAYER; + + if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) { + if (soutliner->treestore == NULL) { + soutliner->treestore = BLI_mempool_create( + sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER); + } + + /* Create a tree store element for the collection. This is normally + * done in check_persistent (outliner_tree.c), but we need to access + * it here :/ (expand element if it's the only one) */ + TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore); + tselem->type = TSE_LAYER_COLLECTION; + tselem->id = layer->layer_collections.first; + tselem->nr = tselem->used = 0; + tselem->flag &= ~TSE_CLOSED; + } + } + } + } + } + } + + /* New workspace design */ + if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) { + do_version_workspaces_after_lib_link(bmain); + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) { + /* Cleanup any remaining SceneRenderLayer data for files that were created + * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */ + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) { + if (srl->prop) { + IDP_FreeProperty(srl->prop); + MEM_freeN(srl->prop); + } + BKE_freestyle_config_free(&srl->freestyleConfig, true); + } + BLI_freelistN(&scene->r.layers); + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) { + /* Due to several changes to particle RNA and draw code particles from older files may no longer + * be visible. Here we correct this by setting a default draw size for those files. */ + for (Object *object = bmain->object.first; object; object = object->id.next) { + for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) { + if (psys->part->draw_size == 0.0f) { + psys->part->draw_size = 0.1f; + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 4)) { + for (Object *object = bmain->object.first; object; object = object->id.next) { +#ifndef VERSION_280_SUBVERSION_4 + /* If any object already has an initialized value for + * duplicator_visibility_flag it means we've already doversioned it. + * TODO(all) remove the VERSION_280_SUBVERSION_4 code once the subversion was bumped. */ + if (object->duplicator_visibility_flag != 0) { + break; + } +#endif + if (object->particlesystem.first) { + object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT; + for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) { + if (psys->part->draw & PART_DRAW_EMITTER) { + object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER; +#ifndef VERSION_280_SUBVERSION_4 + psys->part->draw &= ~PART_DRAW_EMITTER; +#else + break; +#endif + } + } + } + else if (object->transflag & OB_DUPLI) { + object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT; + } + else { + object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER; + } + } + } + + /* SpaceTime & SpaceLogic removal/replacing */ + if (!MAIN_VERSION_ATLEAST(bmain, 280, 9)) { + const wmWindowManager *wm = bmain->wm.first; + const Scene *scene = bmain->scene.first; + + if (wm != NULL) { + /* Action editors need a scene for creation. First, update active + * screens using the active scene of the window they're displayed in. + * Next, update remaining screens using first scene in main listbase. */ + + for (wmWindow *win = wm->windows.first; win; win = win->next) { + const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); + for (ScrArea *area = screen->areabase.first; area; area = area->next) { + if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) { + do_version_area_change_space_to_space_action(area, win->scene); + + /* Don't forget to unset! */ + area->butspacetype = SPACE_EMPTY; + } + } + } + } + if (scene != NULL) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *area = screen->areabase.first; area; area = area->next) { + if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) { + /* Areas that were already handled won't be handled again */ + do_version_area_change_space_to_space_action(area, scene); + + /* Don't forget to unset! */ + area->butspacetype = SPACE_EMPTY; + } + } + } + } + } + +#ifdef USE_COLLECTION_COMPAT_28 + if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 14)) { + for (Collection *group = bmain->collection.first; group; group = group->id.next) { + do_version_group_collection_to_collection(bmain, group); + } + + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + do_version_scene_collection_to_collection(bmain, scene); + } + } +#endif + + /* Update Curve object Shape Key data layout to include the Radius property */ + if (!MAIN_VERSION_ATLEAST(bmain, 280, 23)) { + for (Curve *cu = bmain->curve.first; cu; cu = cu->id.next) { + if (!cu->key || cu->key->elemsize != sizeof(float[4])) + continue; + + cu->key->elemstr[0] = 3; /*KEYELEM_ELEM_SIZE_CURVE*/ + cu->key->elemsize = sizeof(float[3]); + + int new_count = BKE_keyblock_curve_element_count(&cu->nurb); + + for (KeyBlock *block = cu->key->block.first; block; block = block->next) { + int old_count = block->totelem; + void *old_data = block->data; + + if (!old_data || old_count <= 0) + continue; + + block->totelem = new_count; + block->data = MEM_callocN(sizeof(float[3]) * new_count, __func__); + + float *oldptr = old_data; + float (*newptr)[3] = block->data; + + for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->bezt) { + BezTriple *bezt = nu->bezt; + + for (int a = 0; a < nu->pntsu; a++, bezt++) { + if ((old_count -= 3) < 0) { + memcpy(newptr, bezt->vec, sizeof(float[3][3])); + newptr[3][0] = bezt->alfa; + } + else { + memcpy(newptr, oldptr, sizeof(float[3][4])); + } + + newptr[3][1] = bezt->radius; + + oldptr += 3 * 4; + newptr += 4; /*KEYELEM_ELEM_LEN_BEZTRIPLE*/ + } + } + else if (nu->bp) { + BPoint *bp = nu->bp; + + for (int a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) { + if (--old_count < 0) { + copy_v3_v3(newptr[0], bp->vec); + newptr[1][0] = bp->alfa; + } + else { + memcpy(newptr, oldptr, sizeof(float[4])); + } + + newptr[1][1] = bp->radius; + + oldptr += 4; + newptr += 2; /*KEYELEM_ELEM_LEN_BPOINT*/ + } + } + } + + MEM_freeN(old_data); + } + } + } + + /* Move B-Bone custom handle settings from bPoseChannel to Bone. */ + if (!MAIN_VERSION_ATLEAST(bmain, 280, 25)) { + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + bArmature *arm = ob->data; + + /* If it is an armature from the same file. */ + if (ob->pose && arm && arm->id.lib == ob->id.lib) { + bool rebuild = false; + + for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + /* If the 2.7 flag is enabled, processing is needed. */ + if (pchan->bone && (pchan->bboneflag & PCHAN_BBONE_CUSTOM_HANDLES)) { + /* If the settings in the Bone are not set, copy. */ + if (pchan->bone->bbone_prev_type == BBONE_HANDLE_AUTO && + pchan->bone->bbone_next_type == BBONE_HANDLE_AUTO && + pchan->bone->bbone_prev == NULL && pchan->bone->bbone_next == NULL) + { + pchan->bone->bbone_prev_type = (pchan->bboneflag & PCHAN_BBONE_CUSTOM_START_REL) ? BBONE_HANDLE_RELATIVE : BBONE_HANDLE_ABSOLUTE; + pchan->bone->bbone_next_type = (pchan->bboneflag & PCHAN_BBONE_CUSTOM_END_REL) ? BBONE_HANDLE_RELATIVE : BBONE_HANDLE_ABSOLUTE; + + if (pchan->bbone_prev) { + pchan->bone->bbone_prev = pchan->bbone_prev->bone; + } + if (pchan->bbone_next) { + pchan->bone->bbone_next = pchan->bbone_next->bone; + } + } + + rebuild = true; + pchan->bboneflag = 0; + } + } + + /* Tag pose rebuild for all objects that use this armature. */ + if (rebuild) { + for (Object *ob2 = bmain->object.first; ob2; ob2 = ob2->id.next) { + if (ob2->pose && ob2->data == arm) { + ob2->pose->flag |= POSE_RECALC; + } + } + } + } + } + } +} + +/* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already. + * But in 2.79 another case generating non-unique names was discovered (see T55668, involving Meta strips)... */ +static void do_versions_seq_unique_name_all_strips(Scene *sce, ListBase *seqbasep) +{ + for (Sequence *seq = seqbasep->first; seq != NULL; seq = seq->next) { + BKE_sequence_base_unique_name_recursive(&sce->ed->seqbase, seq); + if (seq->seqbase.first != NULL) { + do_versions_seq_unique_name_all_strips(sce, &seq->seqbase); + } + } +} + +void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) +{ + bool use_collection_compat_28 = true; + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) { + use_collection_compat_28 = false; + + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + scene->r.gauss = 1.5f; + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) { + for (Lamp *la = bmain->lamp.first; la; la = la->id.next) { + la->bleedexp = 2.5f; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) { + for (Camera *ca = bmain->camera.first; ca; ca = ca->id.next) { + ca->gpu_dof.ratio = 1.0f; + } + } + + /* MTexPoly now removed. */ + if (DNA_struct_find(fd->filesdna, "MTexPoly")) { + const int cd_mtexpoly = 15; /* CD_MTEXPOLY, deprecated */ + for (Mesh *me = bmain->mesh.first; me; me = me->id.next) { + /* If we have UV's, so this file will have MTexPoly layers too! */ + if (me->mloopuv != NULL) { + CustomData_update_typemap(&me->pdata); + CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly); + BKE_mesh_update_customdata_pointers(me, false); + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) { + for (Lamp *la = bmain->lamp.first; la; la = la->id.next) { + la->cascade_max_dist = 1000.0f; + la->cascade_count = 4; + la->cascade_exponent = 0.8f; + la->cascade_fade = 0.1f; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) { + for (Lamp *la = bmain->lamp.first; la; la = la->id.next) { + la->contact_dist = 0.2f; + la->contact_bias = 0.03f; + la->contact_spread = 0.2f; + la->contact_thickness = 0.2f; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) { + for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) { + probe->vis_bias = 1.0f; + probe->vis_blur = 0.2f; + } + } + + typedef enum eNTreeDoVersionErrors { + NTREE_DOVERSION_NO_ERROR = 0, + NTREE_DOVERSION_NEED_OUTPUT = (1 << 0), + NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1), + } eNTreeDoVersionErrors; + + /* Eevee shader nodes renamed because of the output node system. + * Note that a new output node is not being added here, because it would be overkill + * to handle this case in lib_verify_nodetree. + * + * Also, metallic node is now unified into the principled node. */ + eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR; + + FOREACH_NODETREE(bmain, ntree, id) { + if (ntree->type == NTREE_SHADER) { + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ && + STREQ(node->idname, "ShaderNodeOutputMetallic")) + { + BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname)); + error |= NTREE_DOVERSION_NEED_OUTPUT; + } + + else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) { + BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname)); + error |= NTREE_DOVERSION_NEED_OUTPUT; + } + + else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ && + STREQ(node->idname, "ShaderNodeOutputEeveeMaterial")) + { + node->type = SH_NODE_OUTPUT_MATERIAL; + BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname)); + } + + else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ && + STREQ(node->idname, "ShaderNodeEeveeMetallic")) + { + node->type = SH_NODE_BSDF_PRINCIPLED; + BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname)); + node->custom1 = SHD_GLOSSY_MULTI_GGX; + error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION; + } + } + } + } FOREACH_NODETREE_END + + if (error & NTREE_DOVERSION_NEED_OUTPUT) { + BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console"); + printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n"); + } + + if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) { + BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console"); + printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n"); + } + +#ifdef USE_COLLECTION_COMPAT_28 + if (use_collection_compat_28 && + (DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) && + DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers")) + { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + ViewLayer *view_layer; + for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { + view_layer->flag |= VIEW_LAYER_FREESTYLE; + view_layer->layflag = 0x7FFF; /* solid ztra halo edge strand */ + view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z; + view_layer->pass_alpha_threshold = 0.5f; + BKE_freestyle_config_init(&view_layer->freestyle_config); + } + } + } +#endif + + { + /* Grease pencil sculpt and paint cursors */ + if (!DNA_struct_elem_find(fd->filesdna, "GP_BrushEdit_Settings", "int", "weighttype")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + /* sculpt brushes */ + GP_BrushEdit_Settings *gset = &scene->toolsettings->gp_sculpt; + if (gset) { + gset->weighttype = GP_EDITBRUSH_TYPE_WEIGHT; + } + } + } + + { + float curcolor_add[3], curcolor_sub[3]; + ARRAY_SET_ITEMS(curcolor_add, 1.0f, 0.6f, 0.6f); + ARRAY_SET_ITEMS(curcolor_sub, 0.6f, 0.6f, 1.0f); + GP_EditBrush_Data *gp_brush; + + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + ToolSettings *ts = scene->toolsettings; + /* sculpt brushes */ + GP_BrushEdit_Settings *gset = &ts->gp_sculpt; + for (int i = 0; i < TOT_GP_EDITBRUSH_TYPES; ++i) { + gp_brush = &gset->brush[i]; + gp_brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR; + copy_v3_v3(gp_brush->curcolor_add, curcolor_add); + copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub); + } + } + } + + /* Init grease pencil edit line color */ + if (!DNA_struct_elem_find(fd->filesdna, "bGPdata", "float", "line_color[4]")) { + for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) { + ARRAY_SET_ITEMS(gpd->line_color, 0.6f, 0.6f, 0.6f, 0.5f); + } + } + + /* Init grease pencil pixel size factor */ + if (!DNA_struct_elem_find(fd->filesdna, "bGPDdata", "int", "pixfactor")) { + for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) { + gpd->pixfactor = GP_DEFAULT_PIX_FACTOR; + } + } + + /* Grease pencil multiframe falloff curve */ + if (!DNA_struct_elem_find(fd->filesdna, "GP_BrushEdit_Settings", "CurveMapping", "cur_falloff")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + /* sculpt brushes */ + GP_BrushEdit_Settings *gset = &scene->toolsettings->gp_sculpt; + if ((gset) && (gset->cur_falloff == NULL)) { + gset->cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + curvemapping_initialize(gset->cur_falloff); + curvemap_reset(gset->cur_falloff->cm, + &gset->cur_falloff->clipr, + CURVE_PRESET_GAUSS, + CURVEMAP_SLOPE_POSITIVE); + } + } + } + } + } + +#ifdef USE_COLLECTION_COMPAT_28 + if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 3)) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + ViewLayer *view_layer; + for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { + do_version_view_layer_visibility(view_layer); + } + } + + for (Collection *group = bmain->collection.first; group; group = group->id.next) { + if (group->view_layer != NULL) { + do_version_view_layer_visibility(group->view_layer); + } + } + } +#endif + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) { + /* init grease pencil grids and paper */ + if (!DNA_struct_elem_find(fd->filesdna, "gp_paper_opacity", "float", "gpencil_paper_color[3]")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *area = screen->areabase.first; area; area = area->next) { + for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.gpencil_paper_opacity = 0.5f; + v3d->overlay.gpencil_grid_opacity = 0.9f; + } + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 6)) { + if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) { + bScreen *sc; + ScrArea *sa; + SpaceLink *sl; + + /* Update files using invalid (outdated) outlinevis Outliner values. */ + for (sc = bmain->screen.first; sc; sc = sc->id.next) { + for (sa = sc->areabase.first; sa; sa = sa->next) { + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *so = (SpaceOops *)sl; + + if (!ELEM(so->outlinevis, + SO_SCENES, + SO_LIBRARIES, + SO_SEQUENCE, + SO_DATA_API, + SO_ID_ORPHANS)) + { + so->outlinevis = SO_VIEW_LAYER; + } + } + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) { + for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) { + probe->intensity = 1.0f; + } + } + + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + bConstraint *con, *con_next; + con = ob->constraints.first; + while (con) { + con_next = con->next; + if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */ + BLI_remlink(&ob->constraints, con); + BKE_constraint_free_data(con); + MEM_freeN(con); + } + con = con_next; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + scene->orientation_index_custom = -1; + } + } + + for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) { + for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.light = V3D_LIGHTING_STUDIO; + v3d->shading.flag |= V3D_SHADING_OBJECT_OUTLINE; + + /* Assume (demo) files written with 2.8 want to show + * Eevee renders in the viewport. */ + if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) { + v3d->drawtype = OB_MATERIAL; + } + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 7)) { + /* Render engine storage moved elsewhere and back during 2.8 + * development, we assume any files saved in 2.8 had Eevee set + * as scene render engine. */ + if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine)); + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 8)) { + /* Blender Internal removal */ + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + if (STREQ(scene->r.engine, "BLENDER_RENDER") || + STREQ(scene->r.engine, "BLENDER_GAME")) + { + BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine)); + } + + scene->r.bake_mode = 0; + } + + for (Tex *tex = bmain->tex.first; tex; tex = tex->id.next) { + /* Removed envmap, pointdensity, voxeldata, ocean textures. */ + if (ELEM(tex->type, 10, 14, 15, 16)) { + tex->type = 0; + } + } + + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) { + + /* Remove info editor, but only if at the top of the window. */ + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + /* Calculate window width/height from screen vertices */ + int win_width = 0, win_height = 0; + for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) { + win_width = MAX2(win_width, vert->vec.x); + win_height = MAX2(win_height, vert->vec.y); + } + + for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) { + area_next = area->next; + + if (area->spacetype == SPACE_INFO) { + if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) { + BKE_screen_area_free(area); + + BLI_remlink(&screen->areabase, area); + + BKE_screen_remove_double_scredges(screen); + BKE_screen_remove_unused_scredges(screen); + BKE_screen_remove_unused_scrverts(screen); + + MEM_freeN(area); + } + } + /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas + * which are deleted above, so don't need to unset it. Its slot/bit can be reused */ + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) { + for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) { + if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */ + lamp->mode |= LA_SHADOW; + lamp->mode &= ~(1 << 13); + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 12)) { + /* Remove tool property regions. */ + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) { + ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + + for (ARegion *region = regionbase->first, *region_next; region; region = region_next) { + region_next = region->next; + + if (region->regiontype == RGN_TYPE_TOOL_PROPS) { + BKE_area_region_free(NULL, region); + BLI_freelinkN(regionbase, region); + } + } + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 13)) { + /* Initialize specular factor. */ + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) { + for (Lamp *la = bmain->lamp.first; la; la = la->id.next) { + la->spec_fac = 1.0f; + } + } + + /* Initialize new view3D options. */ + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.light = V3D_LIGHTING_STUDIO; + v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR; + copy_v3_fl(v3d->shading.single_color, 0.8f); + v3d->shading.shadow_intensity = 0.5; + + v3d->overlay.backwire_opacity = 0.5f; + v3d->overlay.normals_length = 0.1f; + v3d->overlay.flag = 0; + } + } + } + } + + if (!DNA_struct_find(fd->filesdna, "View3DCursor")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + unit_qt(scene->cursor.rotation); + } + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + unit_qt(v3d->cursor.rotation); + } + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 14)) { + if (!DNA_struct_elem_find(fd->filesdna, "Scene", "SceneDisplay", "display")) { + /* Initialize new scene.SceneDisplay */ + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + copy_v3_v3(scene->display.light_direction, (float[3]){-M_SQRT1_3, -M_SQRT1_3, M_SQRT1_3}); + } + } + if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_shift")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + scene->display.shadow_shift = 0.1; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "Object", "ObjectDisplay", "display")) { + /* Initialize new object.ObjectDisplay */ + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + ob->display.flag = OB_SHOW_SHADOW; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "transform_pivot_point")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + scene->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEAN; + } + } + + if (!DNA_struct_find(fd->filesdna, "SceneEEVEE")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + /* First set the default for all the properties. */ + + scene->eevee.gi_diffuse_bounces = 3; + scene->eevee.gi_cubemap_resolution = 512; + scene->eevee.gi_visibility_resolution = 32; + + scene->eevee.taa_samples = 16; + scene->eevee.taa_render_samples = 64; + + scene->eevee.sss_samples = 7; + scene->eevee.sss_jitter_threshold = 0.3f; + + scene->eevee.ssr_quality = 0.25f; + scene->eevee.ssr_max_roughness = 0.5f; + scene->eevee.ssr_thickness = 0.2f; + scene->eevee.ssr_border_fade = 0.075f; + scene->eevee.ssr_firefly_fac = 10.0f; + + scene->eevee.volumetric_start = 0.1f; + scene->eevee.volumetric_end = 100.0f; + scene->eevee.volumetric_tile_size = 8; + scene->eevee.volumetric_samples = 64; + scene->eevee.volumetric_sample_distribution = 0.8f; + scene->eevee.volumetric_light_clamp = 0.0f; + scene->eevee.volumetric_shadow_samples = 16; + + scene->eevee.gtao_distance = 0.2f; + scene->eevee.gtao_factor = 1.0f; + scene->eevee.gtao_quality = 0.25f; + + scene->eevee.bokeh_max_size = 100.0f; + scene->eevee.bokeh_threshold = 1.0f; + + copy_v3_fl(scene->eevee.bloom_color, 1.0f); + scene->eevee.bloom_threshold = 0.8f; + scene->eevee.bloom_knee = 0.5f; + scene->eevee.bloom_intensity = 0.8f; + scene->eevee.bloom_radius = 6.5f; + scene->eevee.bloom_clamp = 1.0f; + + scene->eevee.motion_blur_samples = 8; + scene->eevee.motion_blur_shutter = 1.0f; + + scene->eevee.shadow_method = SHADOW_ESM; + scene->eevee.shadow_cube_size = 512; + scene->eevee.shadow_cascade_size = 1024; + + scene->eevee.flag = + SCE_EEVEE_VOLUMETRIC_LIGHTS | + SCE_EEVEE_GTAO_BENT_NORMALS | + SCE_EEVEE_GTAO_BOUNCE | + SCE_EEVEE_TAA_REPROJECTION | + SCE_EEVEE_SSR_HALF_RESOLUTION; + + + /* If the file is pre-2.80 move on. */ + if (scene->layer_properties == NULL) { + continue; + } + + /* Now we handle eventual properties that may be set in the file. */ +#define EEVEE_GET_BOOL(_props, _name, _flag) \ + { \ + IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \ + if (_idprop != NULL) { \ + const int _value = IDP_Int(_idprop); \ + if (_value) { \ + scene->eevee.flag |= _flag; \ + } \ + else { \ + scene->eevee.flag &= ~_flag; \ + } \ + } \ + } + +#define EEVEE_GET_INT(_props, _name) \ + { \ + IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \ + if (_idprop != NULL) { \ + scene->eevee._name = IDP_Int(_idprop); \ + } \ + } + +#define EEVEE_GET_FLOAT(_props, _name) \ + { \ + IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \ + if (_idprop != NULL) { \ + scene->eevee._name = IDP_Float(_idprop); \ + } \ + } + +#define EEVEE_GET_FLOAT_ARRAY(_props, _name, _length) \ + { \ + IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \ + if (_idprop != NULL) { \ + const float *_values = IDP_Array(_idprop); \ + for (int _i = 0; _i < _length; _i++) { \ + scene->eevee._name [_i] = _values[_i]; \ + } \ + } \ + } + + IDProperty *props = IDP_GetPropertyFromGroup(scene->layer_properties, RE_engine_id_BLENDER_EEVEE); + EEVEE_GET_BOOL(props, volumetric_enable, SCE_EEVEE_VOLUMETRIC_ENABLED); + EEVEE_GET_BOOL(props, volumetric_lights, SCE_EEVEE_VOLUMETRIC_LIGHTS); + EEVEE_GET_BOOL(props, volumetric_shadows, SCE_EEVEE_VOLUMETRIC_SHADOWS); + EEVEE_GET_BOOL(props, gtao_enable, SCE_EEVEE_GTAO_ENABLED); + EEVEE_GET_BOOL(props, gtao_use_bent_normals, SCE_EEVEE_GTAO_BENT_NORMALS); + EEVEE_GET_BOOL(props, gtao_bounce, SCE_EEVEE_GTAO_BOUNCE); + EEVEE_GET_BOOL(props, dof_enable, SCE_EEVEE_DOF_ENABLED); + EEVEE_GET_BOOL(props, bloom_enable, SCE_EEVEE_BLOOM_ENABLED); + EEVEE_GET_BOOL(props, motion_blur_enable, SCE_EEVEE_MOTION_BLUR_ENABLED); + EEVEE_GET_BOOL(props, shadow_high_bitdepth, SCE_EEVEE_SHADOW_HIGH_BITDEPTH); + EEVEE_GET_BOOL(props, taa_reprojection, SCE_EEVEE_TAA_REPROJECTION); + EEVEE_GET_BOOL(props, sss_enable, SCE_EEVEE_SSS_ENABLED); + EEVEE_GET_BOOL(props, sss_separate_albedo, SCE_EEVEE_SSS_SEPARATE_ALBEDO); + EEVEE_GET_BOOL(props, ssr_enable, SCE_EEVEE_SSR_ENABLED); + EEVEE_GET_BOOL(props, ssr_refraction, SCE_EEVEE_SSR_REFRACTION); + EEVEE_GET_BOOL(props, ssr_halfres, SCE_EEVEE_SSR_HALF_RESOLUTION); + + EEVEE_GET_INT(props, gi_diffuse_bounces); + EEVEE_GET_INT(props, gi_diffuse_bounces); + EEVEE_GET_INT(props, gi_cubemap_resolution); + EEVEE_GET_INT(props, gi_visibility_resolution); + + EEVEE_GET_INT(props, taa_samples); + EEVEE_GET_INT(props, taa_render_samples); + + EEVEE_GET_INT(props, sss_samples); + EEVEE_GET_FLOAT(props, sss_jitter_threshold); + + EEVEE_GET_FLOAT(props, ssr_quality); + EEVEE_GET_FLOAT(props, ssr_max_roughness); + EEVEE_GET_FLOAT(props, ssr_thickness); + EEVEE_GET_FLOAT(props, ssr_border_fade); + EEVEE_GET_FLOAT(props, ssr_firefly_fac); + + EEVEE_GET_FLOAT(props, volumetric_start); + EEVEE_GET_FLOAT(props, volumetric_end); + EEVEE_GET_INT(props, volumetric_tile_size); + EEVEE_GET_INT(props, volumetric_samples); + EEVEE_GET_FLOAT(props, volumetric_sample_distribution); + EEVEE_GET_FLOAT(props, volumetric_light_clamp); + EEVEE_GET_INT(props, volumetric_shadow_samples); + + EEVEE_GET_FLOAT(props, gtao_distance); + EEVEE_GET_FLOAT(props, gtao_factor); + EEVEE_GET_FLOAT(props, gtao_quality); + + EEVEE_GET_FLOAT(props, bokeh_max_size); + EEVEE_GET_FLOAT(props, bokeh_threshold); + + EEVEE_GET_FLOAT_ARRAY(props, bloom_color, 3); + EEVEE_GET_FLOAT(props, bloom_threshold); + EEVEE_GET_FLOAT(props, bloom_knee); + EEVEE_GET_FLOAT(props, bloom_intensity); + EEVEE_GET_FLOAT(props, bloom_radius); + EEVEE_GET_FLOAT(props, bloom_clamp); + + EEVEE_GET_INT(props, motion_blur_samples); + EEVEE_GET_FLOAT(props, motion_blur_shutter); + + EEVEE_GET_INT(props, shadow_method); + EEVEE_GET_INT(props, shadow_cube_size); + EEVEE_GET_INT(props, shadow_cascade_size); + + /* Cleanup. */ + IDP_FreeProperty(scene->layer_properties); + MEM_freeN(scene->layer_properties); + scene->layer_properties = NULL; + +#undef EEVEE_GET_FLOAT_ARRAY +#undef EEVEE_GET_FLOAT +#undef EEVEE_GET_INT +#undef EEVEE_GET_BOOL + } + } + + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 15)) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + scene->display.matcap_ssao_distance = 0.2f; + scene->display.matcap_ssao_attenuation = 1.0f; + scene->display.matcap_ssao_samples = 16; + } + + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *soops = (SpaceOops *)sl; + soops->filter_id_type = ID_GR; + soops->outlinevis = SO_VIEW_LAYER; + } + } + } + } + + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + switch (scene->toolsettings->snap_mode) { + case 0: scene->toolsettings->snap_mode = SCE_SNAP_MODE_INCREMENT; break; + case 1: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VERTEX ; break; + case 2: scene->toolsettings->snap_mode = SCE_SNAP_MODE_EDGE ; break; + case 3: scene->toolsettings->snap_mode = SCE_SNAP_MODE_FACE ; break; + case 4: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VOLUME ; break; + } + switch (scene->toolsettings->snap_node_mode) { + case 5: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X; break; + case 6: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_Y; break; + case 7: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X | SCE_SNAP_MODE_NODE_Y; break; + case 8: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID ; break; + } + switch (scene->toolsettings->snap_uv_mode) { + case 0: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_INCREMENT; break; + case 1: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_VERTEX ; break; + } + } + + ParticleSettings *part; + for (part = bmain->particle.first; part; part = part->id.next) { + part->shape_flag = PART_SHAPE_CLOSE_TIP; + part->shape = 0.0f; + part->rad_root = 1.0f; + part->rad_tip = 0.0f; + part->rad_scale = 0.01f; + } + } + + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 18)) { + if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "roughness")) { + for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) { + if (mat->use_nodes) { + if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) { + mat->roughness = mat->gloss_mir; + } + else { + mat->roughness = 0.25f; + } + } + else { + mat->roughness = 1.0f - mat->gloss_mir; + } + mat->metallic = mat->ray_mirror; + } + + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT; + } + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.xray_alpha = 0.5f; + } + } + } + } + } + if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "matcap[256]")) { + StudioLight *default_matcap = BKE_studiolight_find_first(STUDIOLIGHT_ORIENTATION_VIEWNORMAL); + /* when loading the internal file is loaded before the matcaps */ + if (default_matcap) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + BLI_strncpy(v3d->shading.matcap, default_matcap->name, FILE_MAXFILE); + } + } + } + } + } + } + if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "wireframe_threshold")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.wireframe_threshold = 0.5f; + } + } + } + } + } + if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "cavity_valley_factor")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.cavity_valley_factor = 1.0f; + v3d->shading.cavity_ridge_factor = 1.0f; + } + } + } + } + } + if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_select_alpha")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.bone_select_alpha = 0.5f; + } + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 19)) { + if (!DNA_struct_elem_find(fd->filesdna, "Image", "ListBase", "renderslot")) { + for (Image *ima = bmain->image.first; ima; ima = ima->id.next) { + if (ima->type == IMA_TYPE_R_RESULT) { + for (int i = 0; i < 8; i++) { + RenderSlot *slot = MEM_callocN(sizeof(RenderSlot), "Image Render Slot Init"); + BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", i + 1); + BLI_addtail(&ima->renderslots, slot); + } + } + } + } + if (!DNA_struct_elem_find(fd->filesdna, "SpaceAction", "char", "mode_prev")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_ACTION) { + SpaceAction *saction = (SpaceAction *)sl; + /* "Dopesheet" should be default here, unless it looks like the Action Editor was active instead */ + if ((saction->mode_prev == 0) && (saction->action == NULL)) { + saction->mode_prev = SACTCONT_DOPESHEET; + } + } + } + } + } + } + + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + if (v3d->drawtype == OB_TEXTURE) { + v3d->drawtype = OB_SOLID; + v3d->shading.light = V3D_LIGHTING_STUDIO; + v3d->shading.color_type = V3D_SHADING_TEXTURE_COLOR; + } + } + } + } + } + + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 21)) { + for (Scene *sce = bmain->scene.first; sce != NULL; sce = sce->id.next) { + if (sce->ed != NULL && sce->ed->seqbase.first != NULL) { + do_versions_seq_unique_name_all_strips(sce, &sce->ed->seqbase); + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "texture_paint_mode_opacity")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + float alpha = v3d->flag2 & V3D_SHOW_MODE_SHADE_OVERRIDE ? 0.0f : 0.8f; + v3d->overlay.texture_paint_mode_opacity = alpha; + v3d->overlay.vertex_paint_mode_opacity = alpha; + v3d->overlay.weight_paint_mode_opacity = alpha; + } + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "View3DShadeing", "short", "background_type")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + copy_v3_fl(v3d->shading.background_color, 0.05f); + } + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "gi_cubemap_draw_size")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + scene->eevee.gi_irradiance_draw_size = 0.1f; + scene->eevee.gi_cubemap_draw_size = 0.3f; + } + } + + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + if (scene->toolsettings->gizmo_flag == 0) { + scene->toolsettings->gizmo_flag = SCE_GIZMO_SHOW_TRANSLATE | SCE_GIZMO_SHOW_ROTATE | SCE_GIZMO_SHOW_SCALE; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "RigidBodyWorld", "RigidBodyWorld_Shared", "*shared")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + RigidBodyWorld *rbw = scene->rigidbody_world; + + if (rbw == NULL) { + continue; + } + + if (rbw->shared == NULL) { + rbw->shared = MEM_callocN(sizeof(*rbw->shared), "RigidBodyWorld_Shared"); + } + + /* Move shared pointers from deprecated location to current location */ + rbw->shared->pointcache = rbw->pointcache; + rbw->shared->ptcaches = rbw->ptcaches; + + rbw->pointcache = NULL; + BLI_listbase_clear(&rbw->ptcaches); + + if (rbw->shared->pointcache == NULL) { + rbw->shared->pointcache = BKE_ptcache_add(&(rbw->shared->ptcaches)); + } + + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "SoftBody", "SoftBody_Shared", "*shared")) { + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + SoftBody *sb = ob->soft; + if (sb == NULL) { + continue; + } + if (sb->shared == NULL) { + sb->shared = MEM_callocN(sizeof(*sb->shared), "SoftBody_Shared"); + } + + /* Move shared pointers from deprecated location to current location */ + sb->shared->pointcache = sb->pointcache; + sb->shared->ptcaches = sb->ptcaches; + + sb->pointcache = NULL; + BLI_listbase_clear(&sb->ptcaches); + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "short", "type")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + if (v3d->drawtype == OB_RENDER) { + v3d->drawtype = OB_SOLID; + } + v3d->shading.type = v3d->drawtype; + v3d->shading.prev_type = OB_SOLID; + } + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "View3DShading", "shading")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + BKE_screen_view3d_shading_init(&scene->display.shading); + } + } + /* initialize grease pencil view data */ + if (!DNA_struct_elem_find(fd->filesdna, "SpaceView3D", "float", "vertex_opacity")) { + for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) { + for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->vertex_opacity = 1.0f; + v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES; + } + } + } + } + } + + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 22)) { + if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "annotate_v3d_align")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + scene->toolsettings->annotate_v3d_align = GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR; + scene->toolsettings->annotate_thickness = 3; + } + } + if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "short", "line_change")) { + for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) { + for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + gpl->line_change = gpl->thickness; + if ((gpl->thickness < 1) || (gpl->thickness > 10)) { + gpl->thickness = 3; + } + } + } + } + if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_paper_opacity")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.gpencil_paper_opacity = 0.5f; + } + } + } + } + } + if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_grid_opacity")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.gpencil_grid_opacity = 0.5f; + } + } + } + } + } + + /* default loc axis */ + if (!DNA_struct_elem_find(fd->filesdna, "GP_BrushEdit_Settings", "int", "lock_axis")) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + /* lock axis */ + GP_BrushEdit_Settings *gset = &scene->toolsettings->gp_sculpt; + if (gset) { + gset->lock_axis = GP_LOCKAXIS_Y; + } + } + } + + /* Versioning code for Subsurf modifier. */ + if (!DNA_struct_elem_find(fd->filesdna, "SubsurfModifier", "short", "uv_smooth")) { + for (Object *object = bmain->object.first; object != NULL; object = object->id.next) { + for (ModifierData *md = object->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Subsurf) { + SubsurfModifierData *smd = (SubsurfModifierData *)md; + if (smd->flags & eSubsurfModifierFlag_SubsurfUv_DEPRECATED) { + smd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS; + } + else { + smd->uv_smooth = SUBSURF_UV_SMOOTH_NONE; + } + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "SubsurfModifier", "short", "quality")) { + for (Object *object = bmain->object.first; object != NULL; object = object->id.next) { + for (ModifierData *md = object->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Subsurf) { + SubsurfModifierData *smd = (SubsurfModifierData *)md; + smd->quality = min_ii(smd->renderLevels, 3); + } + } + } + } + /* Versioning code for Multires modifier. */ + if (!DNA_struct_elem_find(fd->filesdna, "MultiresModifier", "short", "quality")) { + for (Object *object = bmain->object.first; object != NULL; object = object->id.next) { + for (ModifierData *md = object->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Multires) { + MultiresModifierData *mmd = (MultiresModifierData *)md; + mmd->quality = 3; + if (mmd->flags & eMultiresModifierFlag_PlainUv_DEPRECATED) { + mmd->uv_smooth = SUBSURF_UV_SMOOTH_NONE; + } + else { + mmd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS; + } + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "short", "bending_model")) { + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + for (ModifierData *md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Cloth) { + ClothModifierData *clmd = (ClothModifierData *)md; + + clmd->sim_parms->bending_model = CLOTH_BENDING_LINEAR; + clmd->sim_parms->tension = clmd->sim_parms->structural; + clmd->sim_parms->compression = clmd->sim_parms->structural; + clmd->sim_parms->shear = clmd->sim_parms->structural; + clmd->sim_parms->max_tension = clmd->sim_parms->max_struct; + clmd->sim_parms->max_compression = clmd->sim_parms->max_struct; + clmd->sim_parms->max_shear = clmd->sim_parms->max_struct; + clmd->sim_parms->vgroup_shear = clmd->sim_parms->vgroup_struct; + clmd->sim_parms->tension_damp = clmd->sim_parms->Cdis; + clmd->sim_parms->compression_damp = clmd->sim_parms->Cdis; + clmd->sim_parms->shear_damp = clmd->sim_parms->Cdis; + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "BrushGpencilSettings", "float", "era_strength_f")) { + for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) { + if (brush->gpencil_settings != NULL) { + BrushGpencilSettings *gp = brush->gpencil_settings; + if (gp->brush_type == GP_BRUSH_TYPE_ERASE) { + gp->era_strength_f = 100.0f; + gp->era_thickness_f = 10.0f; + } + } + } + } + + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + for (ModifierData *md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Cloth) { + ClothModifierData *clmd = (ClothModifierData *)md; + + if (!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL)) { + clmd->sim_parms->vgroup_mass = 0; + } + + if (!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING)) { + clmd->sim_parms->vgroup_struct = 0; + clmd->sim_parms->vgroup_shear = 0; + clmd->sim_parms->vgroup_bend = 0; + } + + if (!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW)) { + clmd->sim_parms->shrink_min = 0.0f; + clmd->sim_parms->vgroup_shrink = 0; + } + + if (!(clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)) { + clmd->coll_parms->flags &= ~CLOTH_COLLSETTINGS_FLAG_SELF; + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 24)) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.edit_flag |= V3D_OVERLAY_EDIT_FACES | + V3D_OVERLAY_EDIT_SEAMS | + V3D_OVERLAY_EDIT_SHARP | + V3D_OVERLAY_EDIT_FREESTYLE_EDGE | + V3D_OVERLAY_EDIT_FREESTYLE_FACE | + V3D_OVERLAY_EDIT_EDGES | + V3D_OVERLAY_EDIT_CREASES | + V3D_OVERLAY_EDIT_BWEIGHTS | + V3D_OVERLAY_EDIT_CU_HANDLES | + V3D_OVERLAY_EDIT_CU_NORMALS; + } + } + } + } + } + + { + if (!DNA_struct_elem_find(fd->filesdna, "ShrinkwrapModifierData", "char", "shrinkMode")) { + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + for (ModifierData *md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Shrinkwrap) { + ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *)md; + if (smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) { + smd->shrinkMode = MOD_SHRINKWRAP_ABOVE_SURFACE; + smd->shrinkOpts &= ~MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE; + } + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 24)) { + if (!DNA_struct_elem_find(fd->filesdna, "PartDeflect", "float", "pdef_cfrict")) { + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->pd) { + ob->pd->pdef_cfrict = 5.0f; + } + + for (ModifierData *md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Cloth) { + ClothModifierData *clmd = (ClothModifierData *)md; + + clmd->coll_parms->selfepsilon = 0.015f; + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha_wire")) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.xray_alpha_wire = 0.5f; + } + } + } + } + + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.flag |= V3D_SHADING_XRAY_WIREFRAME; + } + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 25)) { + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + UnitSettings *unit = &scene->unit; + if (unit->system != USER_UNIT_NONE) { + unit->length_unit = bUnit_GetBaseUnitOfType(scene->unit.system, B_UNIT_LENGTH); + unit->mass_unit = bUnit_GetBaseUnitOfType(scene->unit.system, B_UNIT_MASS); + } + unit->time_unit = bUnit_GetBaseUnitOfType(USER_UNIT_NONE, B_UNIT_TIME); + } + + /* gpencil grid settings */ + for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) { + ARRAY_SET_ITEMS(gpd->grid.color, 0.5f, 0.5f, 0.5f); // Color + ARRAY_SET_ITEMS(gpd->grid.scale, 1.0f, 1.0f); // Scale + gpd->grid.lines = GP_DEFAULT_GRID_LINES; // Number of lines + gpd->grid.axis = GP_GRID_AXIS_Y; + } + + + } +} diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 558c709d14c..c843ebe6765 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -25,53 +25,36 @@ * \ingroup blenloader */ +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_string.h" -#include "DNA_brush_types.h" -#include "DNA_freestyle_types.h" -#include "DNA_linestyle_types.h" +#include "DNA_gpencil_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_userdef_types.h" -#include "DNA_mesh_types.h" -#include "DNA_material_types.h" #include "DNA_object_types.h" +#include "DNA_workspace_types.h" +#include "DNA_windowmanager_types.h" -#include "BKE_brush.h" -#include "BKE_library.h" +#include "BKE_colortools.h" +#include "BKE_layer.h" #include "BKE_main.h" +#include "BKE_node.h" +#include "BKE_screen.h" +#include "BKE_workspace.h" #include "BLO_readfile.h" - /** * Override values in in-memory startup.blend, avoids resaving for small changes. */ void BLO_update_defaults_userpref_blend(void) { - /* defaults from T37518 */ - - U.uiflag |= USER_DEPTH_CURSOR; - U.uiflag |= USER_QUIT_PROMPT; - U.uiflag |= USER_CONTINUOUS_MOUSE; - - /* See T45301 */ - U.uiflag |= USER_LOCK_CURSOR_ADJUST; - - U.versions = 1; - U.savetime = 2; - - /* default from T47064 */ - U.audiorate = 48000; - - /* Keep this a very small, non-zero number so zero-alpha doesn't mask out objects behind it. - * but take care since some hardware has driver bugs here (T46962). - * Further hardware workarounds should be made in gpu_extensions.c */ - U.glalphaclip = (1.0f / 255); - /* default so DPI is detected automatically */ U.dpi = 0; U.ui_scale = 1.0f; @@ -83,130 +66,26 @@ void BLO_update_defaults_userpref_blend(void) #else U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE; #endif + + /* Ignore the theme saved in the blend file, + * instead use the theme from 'userdef_default_theme.c' */ + { + bTheme *theme = U.themes.first; + memcpy(theme, &U_theme_default, sizeof(bTheme)); + } } /** * Update defaults in startup.blend, without having to save and embed the file. * This function can be emptied each time the startup.blend is updated. */ -void BLO_update_defaults_startup_blend(Main *bmain) +void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) { - for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { - scene->r.im_format.planes = R_IMF_PLANES_RGBA; - scene->r.im_format.compress = 15; - - for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) { - srl->freestyleConfig.sphere_radius = 0.1f; - srl->pass_alpha_threshold = 0.5f; - } - - if (scene->toolsettings) { - ToolSettings *ts = scene->toolsettings; - - if (ts->sculpt) { - Sculpt *sculpt = ts->sculpt; - sculpt->paint.symmetry_flags |= PAINT_SYMM_X; - sculpt->flags |= SCULPT_DYNTOPO_COLLAPSE; - sculpt->detail_size = 12; - } - - if (ts->vpaint) { - VPaint *vp = ts->vpaint; - vp->radial_symm[0] = vp->radial_symm[1] = vp->radial_symm[2] = 1; - } - - if (ts->wpaint) { - VPaint *wp = ts->wpaint; - wp->radial_symm[0] = wp->radial_symm[1] = wp->radial_symm[2] = 1; - } - - if (ts->gp_sculpt.brush[0].size == 0) { - GP_BrushEdit_Settings *gset = &ts->gp_sculpt; - GP_EditBrush_Data *brush; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH]; - brush->size = 25; - brush->strength = 0.3f; - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS]; - brush->size = 25; - brush->strength = 0.5f; - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH]; - brush->size = 25; - brush->strength = 0.5f; - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB]; - brush->size = 50; - brush->strength = 0.3f; - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH]; - brush->size = 25; - brush->strength = 0.3f; - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST]; - brush->size = 50; - brush->strength = 0.3f; // XXX? - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH]; - brush->size = 50; - brush->strength = 0.5f; // XXX? - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE]; - brush->size = 25; - brush->strength = 0.5f; - brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; - } - - ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE; - ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE; - ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE; - ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE; - - ParticleEditSettings *pset = &ts->particle; - for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) { - pset->brush[a].strength = 0.5f; - pset->brush[a].count = 10; - } - pset->brush[PE_BRUSH_CUT].strength = 1.0f; - } - - scene->gm.lodflag |= SCE_LOD_USE_HYST; - scene->gm.scehysteresis = 10; - - scene->r.ffcodecdata.audio_mixrate = 48000; - } - - for (FreestyleLineStyle *linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) { - linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE; - linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA; - linestyle->integration_type = LS_INTEGRATION_MEAN; - linestyle->texstep = 1.0; - linestyle->chain_count = 10; - } - + /* For all startup.blend files. */ for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { - ScrArea *area; - for (area = screen->areabase.first; area; area = area->next) { - SpaceLink *space_link; - ARegion *ar; - - for (space_link = area->spacedata.first; space_link; space_link = space_link->next) { - if (space_link->spacetype == SPACE_CLIP) { - SpaceClip *space_clip = (SpaceClip *) space_link; - space_clip->flag &= ~SC_MANUAL_CALIBRATION; - } - } - - for (ar = area->regionbase.first; ar; ar = ar->next) { + for (ScrArea *area = screen->areabase.first; area; area = area->next) { + for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) { /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */ - BLI_freelistN(&ar->panels); + BKE_area_region_panels_free(&ar->panels); /* some toolbars have been saved as initialized, * we don't want them to have odd zoom-level or scrolling set, see: T47047 */ @@ -217,97 +96,114 @@ void BLO_update_defaults_startup_blend(Main *bmain) } } - for (Mesh *me = bmain->mesh.first; me; me = me->id.next) { - me->smoothresh = DEG2RADF(180.0f); - me->flag &= ~ME_TWOSIDED; - } - - for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) { - mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f; - mat->line_col[3] = 1.0f; - } - - { - Object *ob; - - ob = (Object *)BKE_libblock_find_name(bmain, ID_OB, "Camera"); - if (ob) { - ob->rot[1] = 0.0f; + if (app_template == NULL) { + /* Clear all tools to use default options instead, ignore the tool saved in the file. */ + for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { + while (!BLI_listbase_is_empty(&workspace->tools)) { + BKE_workspace_tool_remove(workspace, workspace->tools.first); + } } - } - - { - Brush *br; - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Fill"); - if (!br) { - br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT); - id_us_min(&br->id); /* fake user only */ - br->imagepaint_tool = PAINT_TOOL_FILL; - br->ob_mode = OB_MODE_TEXTURE_PAINT; + /* Name all screens by their workspaces (avoids 'Default.###' names). */ + { + /* Default only has one window. */ + wmWindow *win = ((wmWindowManager *)bmain->wm.first)->windows.first; + for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { + WorkSpaceLayout *layout = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook, workspace); + bScreen *screen = layout->screen; + BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2); + } } - /* Vertex/Weight Paint */ - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Average"); - if (!br) { - br = BKE_brush_add(bmain, "Average", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT); - id_us_min(&br->id); /* fake user only */ - br->vertexpaint_tool = PAINT_BLEND_AVERAGE; - br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT; - } - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Smear"); - if (!br) { - br = BKE_brush_add(bmain, "Smear", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT); - id_us_min(&br->id); /* fake user only */ - br->vertexpaint_tool = PAINT_BLEND_SMEAR; - br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT; + { + /* 'UV Editing' should use UV mode. */ + bScreen *screen = BLI_findstring(&bmain->screen, "UV Editing", offsetof(ID, name) + 2); + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_IMAGE) { + SpaceImage *sima = (SpaceImage *)sl; + if (sima->mode == SI_MODE_VIEW) { + sima->mode = SI_MODE_UV; + } + } + } + } } + } - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Mask"); - if (br) { - br->imagepaint_tool = PAINT_TOOL_MASK; - br->ob_mode |= OB_MODE_TEXTURE_PAINT; - } + /* For 2D animation template. */ + if (app_template && STREQ(app_template, "2D_Animation")) { + for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { + const char *name = workspace->id.name + 2; - /* remove polish brush (flatten/contrast does the same) */ - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Polish"); - if (br) { - BKE_libblock_delete(bmain, br); + if (STREQ(name, "Drawing")) { + workspace->object_mode = OB_MODE_GPENCIL_PAINT; + } } - - /* remove brush brush (huh?) from some modes (draw brushes do the same) */ - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Brush"); - if (br) { - BKE_libblock_delete(bmain, br); + /* set object in drawing mode */ + for (Object *object = bmain->object.first; object; object = object->id.next) { + if (object->type == OB_GPENCIL) { + bGPdata *gpd = (bGPdata *)object->data; + object->mode = OB_MODE_GPENCIL_PAINT; + gpd->flag |= GP_DATA_STROKE_PAINTMODE; + break; + } } - /* remove draw brush from texpaint (draw brushes do the same) */ - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Draw"); - if (br) { - br->ob_mode &= ~OB_MODE_TEXTURE_PAINT; + /* Be sure curfalloff is initializated */ + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + ToolSettings *ts = scene->toolsettings; + if (ts->gp_sculpt.cur_falloff == NULL) { + ts->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff; + curvemapping_initialize(gp_falloff_curve); + curvemap_reset(gp_falloff_curve->cm, + &gp_falloff_curve->clipr, + CURVE_PRESET_GAUSS, + CURVEMAP_SLOPE_POSITIVE); + } } + } - /* rename twist brush to rotate brush to match rotate tool */ - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Twist"); - if (br) { - BKE_libblock_rename(bmain, &br->id, "Rotate"); + /* For all builtin templates shipped with Blender. */ + bool builtin_template = !app_template || + STREQ(app_template, "2D_Animation") || + STREQ(app_template, "Sculpting") || + STREQ(app_template, "VFX") || + STREQ(app_template, "Video_Editing"); + + if (builtin_template) { + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + /* Hide channels in timelines. */ + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + SpaceAction *saction = (sa->spacetype == SPACE_ACTION) ? sa->spacedata.first : NULL; + + if (saction && saction->mode == SACTCONT_TIMELINE) { + for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { + if (ar->regiontype == RGN_TYPE_CHANNELS) { + ar->flag |= RGN_FLAG_HIDDEN; + } + } + } + } } - /* use original normal for grab brush (otherwise flickers with normal weighting). */ - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Grab"); - if (br) { - br->flag |= BRUSH_ORIGINAL_NORMAL; - } + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine)); - /* increase strength, better for smoothing method */ - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Blur"); - if (br) { - br->alpha = 1.0f; - } + scene->r.cfra = 1.0f; + scene->r.displaymode = R_OUTPUT_WINDOW; + + /* Don't enable compositing nodes. */ + if (scene->nodetree) { + ntreeFreeTree(scene->nodetree); + MEM_freeN(scene->nodetree); + scene->nodetree = NULL; + scene->use_nodes = false; + } - br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Flatten/Contrast"); - if (br) { - br->flag |= BRUSH_ACCUMULATE; + /* Rename render layers. */ + BKE_view_layer_rename(bmain, scene, scene->view_layers.first, "View Layer"); } } } diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 3511aefc2a5..61966ec49b7 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -45,11 +45,10 @@ #define DNA_DEPRECATED_ALLOW #include "DNA_armature_types.h" -#include "DNA_actuator_types.h" #include "DNA_camera_types.h" +#include "DNA_collection_types.h" #include "DNA_constraint_types.h" #include "DNA_effect_types.h" -#include "DNA_group_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" #include "DNA_lamp_types.h" @@ -60,10 +59,8 @@ #include "DNA_node_types.h" #include "DNA_object_fluidsim_types.h" #include "DNA_object_types.h" -#include "DNA_property_types.h" #include "DNA_view3d_types.h" #include "DNA_screen_types.h" -#include "DNA_sensor_types.h" #include "DNA_sdna_types.h" #include "DNA_sequence_types.h" #include "DNA_sound_types.h" @@ -90,7 +87,6 @@ #include "BKE_modifier.h" #include "BKE_particle.h" #include "BKE_pointcache.h" -#include "BKE_property.h" // for BKE_bproperty_object_get #include "BKE_scene.h" #include "BKE_sequencer.h" @@ -128,38 +124,6 @@ static void vcol_to_fcol(Mesh *me) me->mcol = (MCol *)mcolmain; } -static int map_223_keybd_code_to_224_keybd_code(int code) -{ - switch (code) { - case 312: - return 311; /* F12KEY */ - case 159: - return 161; /* PADSLASHKEY */ - case 161: - return 150; /* PAD0 */ - case 154: - return 151; /* PAD1 */ - case 150: - return 152; /* PAD2 */ - case 155: - return 153; /* PAD3 */ - case 151: - return 154; /* PAD4 */ - case 156: - return 155; /* PAD5 */ - case 152: - return 156; /* PAD6 */ - case 157: - return 157; /* PAD7 */ - case 153: - return 158; /* PAD8 */ - case 158: - return 159; /* PAD9 */ - default: - return code; - } -} - static void do_version_bone_head_tail_237(Bone *bone) { Bone *child; @@ -248,12 +212,6 @@ static void ntree_version_242(bNodeTree *ntree) } } } - else if (ntree->type == NTREE_SHADER) { - for (node = ntree->nodes.first; node; node = node->next) - if (node->type == SH_NODE_GEOMETRY && node->storage == NULL) - node->storage = MEM_callocN(sizeof(NodeGeometry), "NodeGeometry"); - } - } static void ntree_version_245(FileData *fd, Library *lib, bNodeTree *ntree) @@ -319,55 +277,6 @@ static void idproperties_fix_group_lengths(ListBase idlist) } } -static void alphasort_version_246(FileData *fd, Library *lib, Mesh *me) -{ - Material *ma; - MFace *mf; - MTFace *tf; - int a, b, texalpha; - - /* verify we have a tface layer */ - for (b = 0; b < me->fdata.totlayer; b++) - if (me->fdata.layers[b].type == CD_MTFACE) - break; - - if (b == me->fdata.totlayer) - return; - - /* if we do, set alpha sort if the game engine did it before */ - for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { - if (mf->mat_nr < me->totcol) { - ma = blo_do_versions_newlibadr(fd, lib, me->mat[mf->mat_nr]); - texalpha = 0; - - /* we can't read from this if it comes from a library, - * because direct_link might not have happened on it, - * so ma->mtex is not pointing to valid memory yet */ - if (ma && ma->id.lib) - ma = NULL; - - for (b = 0; ma && b < MAX_MTEX; b++) - if (ma->mtex[b] && ma->mtex[b]->mapto & MAP_ALPHA) - texalpha = 1; - } - else { - ma = NULL; - texalpha = 0; - } - - for (b = 0; b < me->fdata.totlayer; b++) { - if (me->fdata.layers[b].type == CD_MTFACE) { - tf = ((MTFace*)me->fdata.layers[b].data) + a; - - tf->mode &= ~TF_ALPHASORT; - if (ma && (ma->mode & MA_ZTRANSP)) - if (ELEM(tf->transp, TF_ALPHA, TF_ADD) || (texalpha && (tf->transp != TF_CLIP))) - tf->mode |= TF_ALPHASORT; - } - } - } -} - static void customdata_version_242(Mesh *me) { CustomDataLayer *layer; @@ -403,13 +312,6 @@ static void customdata_version_242(Mesh *me) for (a = 0; a < me->totface; a++, mtf++, tf++, mcol += 4) { memcpy(mcol, tf->col, sizeof(tf->col)); memcpy(mtf->uv, tf->uv, sizeof(tf->uv)); - - mtf->flag = tf->flag; - mtf->unwrap = tf->unwrap; - mtf->mode = tf->mode; - mtf->tile = tf->tile; - mtf->tpage = tf->tpage; - mtf->transp = tf->transp; } MEM_freeN(me->tface); @@ -478,7 +380,6 @@ static void do_version_ntree_242_2(bNodeTree *ntree) iuser->sfra = nia->sfra; iuser->offset = nia->nr-1; iuser->cycl = nia->cyclic; - iuser->fie_ima = 2; iuser->ok = 1; node->storage = iuser; @@ -487,7 +388,6 @@ static void do_version_ntree_242_2(bNodeTree *ntree) else { ImageUser *iuser = node->storage = MEM_callocN(sizeof(ImageUser), "node image user"); iuser->sfra = 1; - iuser->fie_ima = 2; iuser->ok = 1; } } @@ -617,15 +517,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile <= 102) { - /* init halo's at 1.0 */ - Material *ma = bmain->mat.first; - while (ma) { - ma->add = 1.0; - ma = ma->id.next; - } - } - if (bmain->versionfile <= 103) { /* new variable in object: colbits */ Object *ob = bmain->object.first; @@ -677,11 +568,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile <= 107) { Object *ob; - Scene *sce = bmain->scene.first; - while (sce) { - sce->r.mode |= R_GAMMA; - sce = sce->id.next; - } ob = bmain->object.first; while (ob) { if (ob->dt == 0) @@ -713,17 +599,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile <= 113) { - Material *ma = bmain->mat.first; - while (ma) { - if (ma->flaresize == 0.0f) - ma->flaresize = 1.0f; - ma->subsize = 1.0f; - ma->flareboost = 1.0f; - ma = ma->id.next; - } - } - if (bmain->versionfile <= 134) { Tex *tex = bmain->tex.first; while (tex) { @@ -888,148 +763,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile <= 191) { - Object *ob = bmain->object.first; - Material *ma = bmain->mat.first; - - /* let faces have default add factor of 0.0 */ - while (ma) { - if (!(ma->mode & MA_HALO)) - ma->add = 0.0; - ma = ma->id.next; - } - - while (ob) { - ob->mass = 1.0f; - ob->damping = 0.1f; - /*ob->quat[1] = 1.0f;*/ /* quats arnt used yet */ - ob = ob->id.next; - } - } - - if (bmain->versionfile <= 193) { - Object *ob = bmain->object.first; - while (ob) { - ob->inertia = 1.0f; - ob->rdamping = 0.1f; - ob = ob->id.next; - } - } - - if (bmain->versionfile <= 196) { - Mesh *me = bmain->mesh.first; - int a, b; - while (me) { - if (me->tface) { - TFace *tface = me->tface; - for (a = 0; a < me->totface; a++, tface++) { - for (b = 0; b < 4; b++) { - tface->mode |= TF_DYNAMIC; - tface->mode &= ~TF_INVISIBLE; - } - } - } - me = me->id.next; - } - } - - if (bmain->versionfile <= 200) { - Object *ob = bmain->object.first; - while (ob) { - ob->scaflag = ob->gameflag & (OB_DO_FH|OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS); - /* 64 is do_fh */ - ob->gameflag &= ~(OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS); - ob = ob->id.next; - } - } - - if (bmain->versionfile <= 201) { - /* add-object + end-object are joined to edit-object actuator */ - Object *ob = bmain->object.first; - bProperty *prop; - bActuator *act; - bIpoActuator *ia; - bEditObjectActuator *eoa; - bAddObjectActuator *aoa; - while (ob) { - act = ob->actuators.first; - while (act) { - if (act->type == ACT_IPO) { - ia = act->data; - prop = BKE_bproperty_object_get(ob, ia->name); - if (prop) { - ia->type = ACT_IPO_FROM_PROP; - } - } - else if (act->type == ACT_ADD_OBJECT) { - aoa = act->data; - eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act"); - eoa->type = ACT_EDOB_ADD_OBJECT; - eoa->ob = aoa->ob; - eoa->time = aoa->time; - MEM_freeN(aoa); - act->data = eoa; - act->type = act->otype = ACT_EDIT_OBJECT; - } - else if (act->type == ACT_END_OBJECT) { - eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act"); - eoa->type = ACT_EDOB_END_OBJECT; - act->data = eoa; - act->type = act->otype = ACT_EDIT_OBJECT; - } - act = act->next; - } - ob = ob->id.next; - } - } - - if (bmain->versionfile <= 202) { - /* add-object and end-object are joined to edit-object - * actuator */ - Object *ob = bmain->object.first; - bActuator *act; - bObjectActuator *oa; - while (ob) { - act = ob->actuators.first; - while (act) { - if (act->type == ACT_OBJECT) { - oa = act->data; - oa->flag &= ~(ACT_TORQUE_LOCAL|ACT_DROT_LOCAL); /* this actuator didn't do local/glob rot before */ - } - act = act->next; - } - ob = ob->id.next; - } - } - if (bmain->versionfile <= 204) { - /* patches for new physics */ - Object *ob = bmain->object.first; - bActuator *act; - bObjectActuator *oa; bSound *sound; - while (ob) { - - /* please check this for demo20 files like - * original Egypt levels etc. converted - * rotation factor of 50 is not workable */ - act = ob->actuators.first; - while (act) { - if (act->type == ACT_OBJECT) { - oa = act->data; - - oa->forceloc[0] *= 25.0f; - oa->forceloc[1] *= 25.0f; - oa->forceloc[2] *= 25.0f; - - oa->forcerot[0] *= 10.0f; - oa->forcerot[1] *= 10.0f; - oa->forcerot[2] *= 10.0f; - } - act = act->next; - } - ob = ob->id.next; - } sound = bmain->sound.first; while (sound) { @@ -1040,120 +775,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile <= 205) { - /* patches for new physics */ - Object *ob = bmain->object.first; - bActuator *act; - bSensor *sens; - bEditObjectActuator *oa; - bRaySensor *rs; - bCollisionSensor *cs; - while (ob) { - /* Set anisotropic friction off for old objects, - * values to 1.0. */ - ob->gameflag &= ~OB_ANISOTROPIC_FRICTION; - ob->anisotropicFriction[0] = 1.0; - ob->anisotropicFriction[1] = 1.0; - ob->anisotropicFriction[2] = 1.0; - - act = ob->actuators.first; - while (act) { - if (act->type == ACT_EDIT_OBJECT) { - /* Zero initial velocity for newly - * added objects */ - oa = act->data; - oa->linVelocity[0] = 0.0; - oa->linVelocity[1] = 0.0; - oa->linVelocity[2] = 0.0; - oa->localflag = 0; - } - act = act->next; - } - - sens = ob->sensors.first; - while (sens) { - /* Extra fields for radar sensors. */ - if (sens->type == SENS_RADAR) { - bRadarSensor *s = sens->data; - s->range = 10000.0; - } - - /* Pulsing: defaults for new sensors. */ - if (sens->type != SENS_ALWAYS) { - sens->pulse = 0; - sens->freq = 0; - } - else { - sens->pulse = 1; - } - - /* Invert: off. */ - sens->invert = 0; - - /* Collision and ray: default = trigger - * on property. The material field can - * remain empty. */ - if (sens->type == SENS_COLLISION) { - cs = (bCollisionSensor*) sens->data; - cs->mode = 0; - } - if (sens->type == SENS_RAY) { - rs = (bRaySensor*) sens->data; - rs->mode = 0; - } - sens = sens->next; - } - ob = ob->id.next; - } - /* have to check the exact multiplier */ - } - - if (bmain->versionfile <= 211) { - /* Render setting: per scene, the applicable gamma value - * can be set. Default is 1.0, which means no - * correction. */ - bActuator *act; - bObjectActuator *oa; - Object *ob; - - /* added alpha in obcolor */ - ob = bmain->object.first; - while (ob) { - ob->col[3] = 1.0; - ob = ob->id.next; - } - - /* added alpha in obcolor */ - ob = bmain->object.first; - while (ob) { - act = ob->actuators.first; - while (act) { - if (act->type == ACT_OBJECT) { - /* multiply velocity with 50 in old files */ - oa = act->data; - if (fabsf(oa->linearvelocity[0]) >= 0.01f) - oa->linearvelocity[0] *= 50.0f; - if (fabsf(oa->linearvelocity[1]) >= 0.01f) - oa->linearvelocity[1] *= 50.0f; - if (fabsf(oa->linearvelocity[2]) >= 0.01f) - oa->linearvelocity[2] *= 50.0f; - if (fabsf(oa->angularvelocity[0]) >= 0.01f) - oa->angularvelocity[0] *= 50.0f; - if (fabsf(oa->angularvelocity[1]) >= 0.01f) - oa->angularvelocity[1] *= 50.0f; - if (fabsf(oa->angularvelocity[2]) >= 0.01f) - oa->angularvelocity[2] *= 50.0f; - } - act = act->next; - } - ob = ob->id.next; - } - } - if (bmain->versionfile <= 212) { bSound *sound; - bProperty *prop; - Object *ob; Mesh *me; sound = bmain->sound.first; @@ -1170,21 +793,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) sound = sound->id.next; } - ob = bmain->object.first; - - while (ob) { - prop = ob->prop.first; - while (prop) { - if (prop->type == GPROP_TIME) { - // convert old GPROP_TIME values from int to float - *((float *)&prop->data) = (float) prop->data; - } - - prop = prop->next; - } - ob = ob->id.next; - } - /* me->subdiv changed to reflect the actual reparametization * better, and smeshes were removed - if it was a smesh make * it a subsurf, and reset the subdiv level because subsurf @@ -1207,29 +815,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } if (bmain->versionfile <= 220) { - Object *ob; Mesh *me; - ob = bmain->object.first; - - /* adapt form factor in order to get the 'old' physics - * behavior back... - */ - - while (ob) { - /* in future, distinguish between different - * object bounding shapes - */ - ob->formfactor = 0.4f; - /* patch form factor, note that inertia equiv radius - * of a rotation symmetrical obj - */ - if (ob->inertia != 1.0f) { - ob->formfactor /= ob->inertia * ob->inertia; - } - ob = ob->id.next; - } - /* Began using alpha component of vertex colors, but * old file vertex colors are undefined, reset them * to be fully opaque. -zr @@ -1259,61 +846,13 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile <= 221) { - Scene *sce = bmain->scene.first; - - /* new variables for std-alone player and runtime */ - while (sce) { - sce->r.xplay = 640; - sce->r.yplay = 480; - sce->r.freqplay = 60; - - sce = sce->id.next; - } - - } - - if (bmain->versionfile <= 222) { - Scene *sce = bmain->scene.first; - - /* new variables for std-alone player and runtime */ - while (sce) { - sce->r.depth = 32; - - sce = sce->id.next; - } - } - if (bmain->versionfile <= 223) { VFont *vf; - Image *ima; - Object *ob; - for (vf = bmain->vfont.first; vf; vf = vf->id.next) { if (STREQ(vf->name + strlen(vf->name) - 6, ".Bfont")) { strcpy(vf->name, FO_BUILTIN_NAME); } } - - /* Old textures animate at 25 FPS */ - for (ima = bmain->image.first; ima; ima = ima->id.next) { - ima->animspeed = 25; - } - - /* Zr remapped some keyboard codes to be linear (stupid zr) */ - for (ob = bmain->object.first; ob; ob = ob->id.next) { - bSensor *sens; - - for (sens = ob->sensors.first; sens; sens = sens->next) { - if (sens->type == SENS_KEYBOARD) { - bKeyboardSensor *ks = sens->data; - - ks->key = map_223_keybd_code_to_224_keybd_code(ks->key); - ks->qual = map_223_keybd_code_to_224_keybd_code(ks->qual); - ks->qual2 = map_223_keybd_code_to_224_keybd_code(ks->qual2); - } - } - } } if (bmain->versionfile <= 224) { @@ -1357,17 +896,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile <= 225) { - World *wo; - /* Use Sumo for old games */ - for (wo = bmain->world.first; wo; wo = wo->id.next) { - wo->physicsEngine = 2; - } - } - if (bmain->versionfile <= 227) { Scene *sce; - Material *ma; bScreen *sc; Object *ob; @@ -1420,17 +950,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (sce = bmain->scene.first; sce; sce = sce->id.next) { sce->audio.mixrate = 48000; sce->audio.flag |= AUDIO_SCRUB; - sce->r.mode |= R_ENVMAP; - } - - /* init new shader vars */ - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - ma->refrac = 4.0f; - ma->roughness = 0.5f; - ma->param[0] = 0.5f; - ma->param[1] = 0.1f; - ma->param[2] = 0.1f; - ma->param[3] = 0.05f; } /* patch for old wrong max view2d settings, allows zooming out more */ @@ -1455,7 +974,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } if (bmain->versionfile <= 228) { - Scene *sce; bScreen *sc; Object *ob; @@ -1501,10 +1019,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) ob = ob->id.next; } - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - sce->r.mode |= R_ENVMAP; - } - /* convert old mainb values for new button panels */ for (sc = bmain->screen.first; sc; sc = sc->id.next) { ScrArea *sa; @@ -1517,7 +1031,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) SpaceButs *sbuts = (SpaceButs *) sl; sbuts->v2d.maxzoom = 1.2f; - sbuts->align = 1; /* horizontal default */ if (sbuts->mainb == BUTS_LAMP) { sbuts->mainb = CONTEXT_SHADING; @@ -1542,9 +1055,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) sbuts->mainb = CONTEXT_SCENE; //sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_RENDER; } - else if (sbuts->mainb == BUTS_GAME) { - sbuts->mainb = CONTEXT_LOGIC; - } else if (sbuts->mainb == BUTS_FPAINT) { sbuts->mainb = CONTEXT_EDITING; } @@ -1598,57 +1108,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } if (bmain->versionfile <= 231) { - Material *ma = bmain->mat.first; bScreen *sc = bmain->screen.first; - Scene *sce; - Lamp *la; - World *wrld; - - /* introduction of raytrace */ - while (ma) { - if (ma->fresnel_tra_i == 0.0f) - ma->fresnel_tra_i = 1.25f; - if (ma->fresnel_mir_i == 0.0f) - ma->fresnel_mir_i = 1.25f; - - ma->ang = 1.0; - ma->ray_depth = 2; - ma->ray_depth_tra = 2; - ma->fresnel_tra = 0.0; - ma->fresnel_mir = 0.0; - - ma = ma->id.next; - } - sce = bmain->scene.first; - while (sce) { - if (sce->r.gauss == 0.0f) - sce->r.gauss = 1.0f; - sce = sce->id.next; - } - la = bmain->lamp.first; - while (la) { - if (la->k == 0.0f) la->k = 1.0; - if (la->ray_samp == 0) - la->ray_samp = 1; - if (la->ray_sampy == 0) - la->ray_sampy = 1; - if (la->ray_sampz == 0) - la->ray_sampz = 1; - if (la->area_size == 0.0f) - la->area_size = 1.0f; - if (la->area_sizey == 0.0f) - la->area_sizey = 1.0f; - if (la->area_sizez == 0.0f) - la->area_sizez = 1.0f; - la = la->id.next; - } - wrld = bmain->world.first; - while (wrld) { - if (wrld->range == 0.0f) { - wrld->range = 1.0f / wrld->exposure; - } - wrld = wrld->id.next; - } /* new bit flags for showing/hiding grid floor and axes */ @@ -1679,7 +1139,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Tex *tex = bmain->tex.first; World *wrld = bmain->world.first; bScreen *sc; - Scene *sce; while (tex) { if ((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) { @@ -1706,10 +1165,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) while (wrld) { if (wrld->aodist == 0.0f) { wrld->aodist = 10.0f; - wrld->aobias = 0.05f; } - if (wrld->aosamp == 0) - wrld->aosamp = 5; if (wrld->aoenergy == 0.0f) wrld->aoenergy = 1.0f; wrld = wrld->id.next; @@ -1731,13 +1187,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } } - sce = bmain->scene.first; - while (sce) { - if (sce->r.ocres == 0) - sce->r.ocres = 64; - sce = sce->id.next; - } - } if (bmain->versionfile <= 233) { @@ -1746,10 +1195,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) /* Object *ob = bmain->object.first; */ while (ma) { - if (ma->rampfac_col == 0.0f) - ma->rampfac_col = 1.0; - if (ma->rampfac_spec == 0.0f) - ma->rampfac_spec = 1.0; if (ma->pr_lamp == 0) ma->pr_lamp = 3; ma = ma->id.next; @@ -1770,15 +1215,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } if (bmain->versionfile <= 234) { - World *wo; bScreen *sc; - /* force sumo engine to be active */ - for (wo = bmain->world.first; wo; wo = wo->id.next) { - if (wo->physicsEngine == 0) - wo->physicsEngine = 2; - } - for (sc = bmain->screen.first; sc; sc = sc->id.next) { ScrArea *sa; for (sa = sc->areabase.first; sa; sa = sa->next) { @@ -1827,8 +1265,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile <= 236) { Object *ob; Camera *cam = bmain->camera.first; - Material *ma; - bScreen *sc; while (cam) { if (cam->ortho_scale == 0.0f) { @@ -1838,29 +1274,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } cam = cam->id.next; } - /* set manipulator type */ /* force oops draw if depgraph was set*/ /* set time line var */ - for (sc = bmain->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->twtype == 0) - v3d->twtype = V3D_MANIP_TRANSLATE; - } - } - } - } - /* init new shader vars */ - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - if (ma->darkness == 0.0f) { - ma->rms = 0.1f; - ma->darkness = 1.0f; - } - } /* softbody init new vars */ for (ob = bmain->object.first; ob; ob = ob->id.next) { @@ -1912,7 +1327,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) BKE_pose_tag_recalc(bmain, ob->pose); /* cannot call stuff now (pointers!), done in setup_app_data */ - ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + ob->id.recalc |= ID_RECALC_ALL; /* new generic xray option */ arm = blo_do_versions_newlibadr(fd, lib, ob->data); @@ -2089,7 +1504,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Object *ob; Scene *sce = bmain->scene.first; Camera *cam = bmain->camera.first; - Material *ma = bmain->mat.first; int set_passepartout = 0; /* deformflag is local in modifier now */ @@ -2122,11 +1536,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) set_passepartout = 1; sce->r.scemode &= ~R_PASSEPARTOUT; } - /* gauss is filter variable now */ - if (sce->r.mode & R_GAUSS) { - sce->r.filtertype = R_FILTER_GAUSS; - sce->r.mode &= ~R_GAUSS; - } } for (; cam; cam = cam->id.next) { @@ -2141,36 +1550,15 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (!(cam->passepartalpha)) cam->passepartalpha = 0.2f; } - - for (; ma; ma = ma->id.next) { - if (ma->strand_sta == 0.0f) { - ma->strand_sta = ma->strand_end = 1.0f; - ma->mode |= MA_TANGENT_STR; - } - if (ma->mode & MA_TRACEBLE) - ma->mode |= MA_SHADBUF; - } } if (bmain->versionfile <= 241) { Object *ob; - Tex *tex; Scene *sce; - World *wo; Lamp *la; - Material *ma; bArmature *arm; bNodeTree *ntree; - for (wo = bmain->world.first; wo; wo = wo->id.next) { - /* Migrate to Bullet for games, except for the NaN versions */ - /* People can still explicitly choose for Sumo (after 2.42 is out) */ - if (bmain->versionfile > 225) - wo->physicsEngine = WOPHY_BULLET; - if (WO_AODIST == wo->aomode) - wo->aocolor = WO_AOPLAIN; - } - /* updating layers still */ for (arm = bmain->armature.first; arm; arm = arm->id.next) { bone_version_239(&arm->bonebase); @@ -2181,23 +1569,16 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (sce->audio.mixrate == 0) sce->audio.mixrate = 48000; - if (sce->r.xparts <2 ) - sce->r.xparts = 4; - if (sce->r.yparts < 2) - sce->r.yparts = 4; - - /* adds default layer */ - if (BLI_listbase_is_empty(&sce->r.layers)) { - BKE_scene_add_render_layer(sce, NULL); - } - else { - SceneRenderLayer *srl; - /* new layer flag for sky, was default for solid */ - for (srl = sce->r.layers.first; srl; srl = srl->next) { - if (srl->layflag & SCE_LAY_SOLID) - srl->layflag |= SCE_LAY_SKY; - srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR); - } + /* We don't add default layer since blender2.8 because the layers + * are now in Scene->view_layers and a default layer is created in + * the doversion later on. + */ + SceneRenderLayer *srl; + /* new layer flag for sky, was default for solid */ + for (srl = sce->r.layers.first; srl; srl = srl->next) { + if (srl->layflag & SCE_LAY_SOLID) + srl->layflag |= SCE_LAY_SKY; + srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR); } /* node version changes */ @@ -2209,20 +1590,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) sce->toolsettings->uvcalc_flag = UVCALC_FILLHOLES; sce->toolsettings->unwrapper = 1; } - - if (sce->r.mode & R_PANORAMA) { - /* all these checks to ensure saved files between released versions keep working... */ - if (sce->r.xsch < sce->r.ysch) { - Object *obc = blo_do_versions_newlibadr(fd, lib, sce->camera); - if (obc && obc->type == OB_CAMERA) { - Camera *cam = blo_do_versions_newlibadr(fd, lib, obc->data); - if (cam->lens >= 10.0f) { - sce->r.xsch *= sce->r.xparts; - cam->lens *= (float)sce->r.ysch / (float)sce->r.xsch; - } - } - } - } } for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) @@ -2232,12 +1599,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (la->buffers == 0) la->buffers = 1; - for (tex = bmain->tex.first; tex; tex = tex->id.next) { - if (tex->env && tex->env->viewscale == 0.0f) - tex->env->viewscale = 1.0f; - //tex->imaflag |= TEX_GAUSS_MIP; - } - /* for empty drawsize and drawtype */ for (ob = bmain->object.first; ob; ob = ob->id.next) { if (ob->empty_drawsize == 0.0f) { @@ -2246,21 +1607,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - /* stucci returns intensity from now on */ - int a; - for (a = 0; a < MAX_MTEX; a++) { - if (ma->mtex[a] && ma->mtex[a]->tex) { - tex = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex); - if (tex && tex->type == TEX_STUCCI) - ma->mtex[a]->mapto &= ~(MAP_COL|MAP_SPEC|MAP_REF); - } - } - /* transmissivity defaults */ - if (ma->tx_falloff == 0.0f) - ma->tx_falloff = 1.0f; - } - /* during 2.41 images with this name were used for viewer node output, lets fix that */ if (bmain->versionfile == 241) { Image *ima; @@ -2280,7 +1626,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Curve *cu; Material *ma; Mesh *me; - Group *group; + Collection *collection; Nurb *nu; BezTriple *bezt; BPoint *bp; @@ -2430,8 +1776,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } for (ma = bmain->mat.first; ma; ma = ma->id.next) { - if (ma->shad_alpha == 0.0f) - ma->shad_alpha = 1.0f; if (ma->nodetree) ntree_version_242(ma->nodetree); } @@ -2439,9 +1783,9 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (me = bmain->mesh.first; me; me = me->id.next) customdata_version_242(me); - for (group = bmain->group.first; group; group = group->id.next) - if (group->layer == 0) - group->layer = (1 << 20) - 1; + for (collection = bmain->collection.first; collection; collection = collection->id.next) + if (collection->layer == 0) + collection->layer = (1 << 20) - 1; /* now, subversion control! */ if (bmain->subversionfile < 3) { @@ -2471,13 +1815,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) ima = blo_do_versions_newlibadr(fd, lib, tex->ima); if (tex->imaflag & TEX_ANIM5_) ima->source = IMA_SRC_MOVIE; - if (tex->imaflag & TEX_FIELDS_) - ima->flag |= IMA_FIELDS; - if (tex->imaflag & TEX_STD_FIELD_) - ima->flag |= IMA_STD_FIELD; } tex->iuser.frames = tex->frames; - tex->iuser.fie_ima = (char)tex->fie_ima; tex->iuser.offset = tex->offset; tex->iuser.sfra = tex->sfra; tex->iuser.cycl = (tex->imaflag & TEX_ANIMCYCLIC_)!=0; @@ -2491,30 +1830,12 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (ma = bmain->mat.first; ma; ma = ma->id.next) if (ma->nodetree) do_version_ntree_242_2(ma->nodetree); - - for (sc = bmain->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_IMAGE) - ((SpaceImage *)sl)->iuser.fie_ima = 2; - else if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d = (View3D *)sl; - BGpic *bgpic; - for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) - bgpic->iuser.fie_ima = 2; - } - } - } - } } if (bmain->subversionfile < 4) { for (sce = bmain->scene.first; sce; sce = sce->id.next) { sce->r.bake_mode = 1; /* prevent to include render stuff here */ sce->r.bake_filter = 16; - sce->r.bake_osa = 5; sce->r.bake_flag = R_BAKE_CLEAR; } } @@ -2522,32 +1843,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile <= 243) { Object *ob = bmain->object.first; - Material *ma; - - for (ma = bmain->mat.first; ma; ma = ma->id.next) { - if (ma->sss_scale == 0.0f) { - ma->sss_radius[0] = 1.0f; - ma->sss_radius[1] = 1.0f; - ma->sss_radius[2] = 1.0f; - ma->sss_col[0] = 0.8f; - ma->sss_col[1] = 0.8f; - ma->sss_col[2] = 0.8f; - ma->sss_error = 0.05f; - ma->sss_scale = 0.1f; - ma->sss_ior = 1.3f; - ma->sss_colfac = 1.0f; - ma->sss_texfac = 0.0f; - } - if (ma->sss_front == 0 && ma->sss_back == 0) { - ma->sss_front = 1.0f; - ma->sss_back = 1.0f; - } - if (ma->sss_col[0] == 0 && ma->sss_col[1] == 0 && ma->sss_col[2] == 0) { - ma->sss_col[0] = ma->r; - ma->sss_col[1] = ma->g; - ma->sss_col[2] = ma->b; - } - } for (; ob; ob = ob->id.next) { bDeformGroup *curdef; @@ -2595,15 +1890,9 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } if (bmain->versionfile <= 244) { - Scene *sce; bScreen *sc; - Lamp *la; - World *wrld; if (bmain->versionfile != 244 || bmain->subversionfile < 2) { - for (sce = bmain->scene.first; sce; sce = sce->id.next) - sce->r.mode |= R_SSS; - /* correct older action editors - incorrect scrolling */ for (sc = bmain->screen.first; sc; sc = sc->id.next) { ScrArea *sa; @@ -2626,28 +1915,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } } - - if (bmain->versionfile != 244 || bmain->subversionfile < 3) { - /* constraints recode version patch used to be here. Moved to 245 now... */ - - for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) { - if (wrld->mode & WO_AMB_OCC) - wrld->ao_samp_method = WO_AOSAMP_CONSTANT; - else - wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY; - - wrld->ao_adapt_thresh = 0.005f; - } - - for (la = bmain->lamp.first; la; la = la->id.next) { - if (la->type == LA_AREA) - la->ray_samp_method = LA_SAMP_CONSTANT; - else - la->ray_samp_method = LA_SAMP_HALTON; - - la->adapt_thresh = 0.001f; - } - } } if (bmain->versionfile <= 245) { @@ -2657,7 +1924,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Lamp *la; Material *ma; ParticleSettings *part; - World *wrld; Mesh *me; bNodeTree *ntree; Tex *tex; @@ -2789,10 +2055,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile != 245 || bmain->subversionfile < 1) { for (la = bmain->lamp.first; la; la = la->id.next) { - if (la->mode & LA_QUAD) - la->falloff_type = LA_FALLOFF_SLIDERS; - else - la->falloff_type = LA_FALLOFF_INVLINEAR; + la->falloff_type = LA_FALLOFF_INVLINEAR; if (la->curfalloff == NULL) { la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f); @@ -2802,51 +2065,23 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } for (ma = bmain->mat.first; ma; ma = ma->id.next) { - if (ma->samp_gloss_mir == 0) { - ma->gloss_mir = ma->gloss_tra = 1.0f; - ma->aniso_gloss_mir = 1.0f; - ma->samp_gloss_mir = ma->samp_gloss_tra = 18; - ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005f; - ma->dist_mir = 0.0f; - ma->fadeto_mir = MA_RAYMIR_FADETOSKY; + if (ma->gloss_mir == 0.0f) { + ma->gloss_mir = 1.0f; } - - if (ma->strand_min == 0.0f) - ma->strand_min = 1.0f; } for (part = bmain->particle.first; part; part = part->id.next) { if (part->ren_child_nbr == 0) part->ren_child_nbr = part->child_nbr; - - if (part->simplify_refsize == 0) { - part->simplify_refsize = 1920; - part->simplify_rate = 1.0f; - part->simplify_transition = 0.1f; - part->simplify_viewport = 0.8f; - } - } - - for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) { - if (wrld->ao_approx_error == 0.0f) - wrld->ao_approx_error = 0.25f; } for (sce = bmain->scene.first; sce; sce = sce->id.next) { if (sce->nodetree) ntree_version_245(fd, lib, sce->nodetree); - if (sce->r.simplify_shadowsamples == 0) { + if (sce->r.simplify_subsurf == 0) { sce->r.simplify_subsurf = 6; sce->r.simplify_particles = 1.0f; - sce->r.simplify_shadowsamples = 16; - sce->r.simplify_aosss = 1.0f; - } - - if (sce->r.cineongamma == 0) { - sce->r.cineonblack = 95; - sce->r.cineonwhite = 685; - sce->r.cineongamma = 1.7f; } } @@ -2874,22 +2109,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - /* sanity check for skgen */ - { - Scene *sce; - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - if (sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[1] || - sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[2] || - sce->toolsettings->skgen_subdivisions[1] == sce->toolsettings->skgen_subdivisions[2]) - { - sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION; - sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH; - sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE; - } - } - } - - if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 2)) { Image *ima; @@ -3126,16 +2345,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } } - if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 9)) { - Material *ma; - int a; - - for (ma = bmain->mat.first; ma; ma = ma->id.next) - if (ma->mode & MA_NORMAP_TANG) - for (a = 0; a < MAX_MTEX; a++) - if (ma->mtex[a] && ma->mtex[a]->tex) - ma->mtex[a]->normapspace = MTEX_NSPACE_TANGENT; - } if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 10)) { Object *ob; @@ -3210,7 +2419,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) idproperties_fix_group_lengths(bmain->vfont); idproperties_fix_group_lengths(bmain->text); idproperties_fix_group_lengths(bmain->sound); - idproperties_fix_group_lengths(bmain->group); + idproperties_fix_group_lengths(bmain->collection); idproperties_fix_group_lengths(bmain->armature); idproperties_fix_group_lengths(bmain->action); idproperties_fix_group_lengths(bmain->nodetree); @@ -3218,25 +2427,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) idproperties_fix_group_lengths(bmain->particle); } - /* sun/sky */ - if (bmain->versionfile < 246) { - Object *ob; - bActuator *act; - - /* dRot actuator change direction in 2.46 */ - for (ob = bmain->object.first; ob; ob = ob->id.next) { - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_OBJECT) { - bObjectActuator *ba = act->data; - - ba->drot[0] = -ba->drot[0]; - ba->drot[1] = -ba->drot[1]; - ba->drot[2] = -ba->drot[2]; - } - } - } - } - /* convert fluids to modifier */ if (bmain->versionfile < 246 || (bmain->versionfile == 246 && bmain->subversionfile < 1)) { Object *ob; @@ -3258,14 +2448,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - - if (bmain->versionfile < 246 || (bmain->versionfile == 246 && bmain->subversionfile < 1)) { - Mesh *me; - - for (me = bmain->mesh.first; me; me = me->id.next) - alphasort_version_246(fd, lib, me); - } - if (bmain->versionfile < 246 || (bmain->versionfile == 246 && bmain->subversionfile < 1)) { Object *ob; for (ob = bmain->object.first; ob; ob = ob->id.next) { @@ -3274,33 +2456,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 2)) { - Object *ob; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - ob->gameflag |= OB_COLLISION; - ob->margin = 0.06f; - } - } - - if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 3)) { - Object *ob; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - /* Starting from subversion 3, ACTOR is a separate feature. - * Before it was conditioning all the other dynamic flags */ - if (!(ob->gameflag & OB_ACTOR)) - ob->gameflag &= ~(OB_GHOST|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_COLLISION_RESPONSE); - /* suitable default for older files */ - } - } - - if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 5)) { - Lamp *la = bmain->lamp.first; - for (; la; la = la->id.next) { - la->skyblendtype = MA_RAMP_ADD; - la->skyblendfac = 1.0f; - } - } - /* set the curve radius interpolation to 2.47 default - easy */ if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 6)) { Curve *cu; @@ -3324,72 +2479,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - /* direction constraint actuators were always local in previous version */ - if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 7)) { - bActuator *act; - Object *ob; - - for (ob = bmain->object.first; ob; ob = ob->id.next) { - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_CONSTRAINT) { - bConstraintActuator *coa = act->data; - if (coa->type == ACT_CONST_TYPE_DIST) { - coa->flag |= ACT_CONST_LOCAL; - } - } - } - } - } - - if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 9)) { - Lamp *la = bmain->lamp.first; - for (; la; la = la->id.next) { - la->sky_exposure = 1.0f; - } - } - - /* BGE message actuators needed OB prefix, very confusing */ - if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 10)) { - bActuator *act; - Object *ob; - - for (ob = bmain->object.first; ob; ob = ob->id.next) { - for (act = ob->actuators.first; act; act = act->next) { - if (act->type == ACT_MESSAGE) { - bMessageActuator *msgAct = (bMessageActuator *) act->data; - - 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 { - msgAct->toPropName[0] = '\0'; - } - } - } - } - } - - if (bmain->versionfile < 248) { - Lamp *la; - - for (la = bmain->lamp.first; la; la = la->id.next) { - if (la->atm_turbidity == 0.0f) { - la->sun_effect_type = 0; - la->horizon_brightness = 1.0f; - la->spread = 1.0f; - la->sun_brightness = 1.0f; - la->sun_size = 1.0f; - la->backscattered_light = 1.0f; - la->atm_turbidity = 2.0f; - la->atm_inscattering_factor = 1.0f; - la->atm_extinction_factor = 1.0f; - la->atm_distance_factor = 1.0f; - la->sun_intensity = 1.0f; - } - } - } - if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 2)) { Scene *sce; @@ -3397,31 +2486,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (sce = bmain->scene.first; sce; sce = sce->id.next) { sce->toolsettings->imapaint.seam_bleed = 2; sce->toolsettings->imapaint.normal_angle = 80; - - /* initialize skeleton generation toolsettings */ - sce->toolsettings->skgen_resolution = 250; - sce->toolsettings->skgen_threshold_internal = 0.1f; - sce->toolsettings->skgen_threshold_external = 0.1f; - sce->toolsettings->skgen_angle_limit = 30.0f; - sce->toolsettings->skgen_length_ratio = 1.3f; - sce->toolsettings->skgen_length_limit = 1.5f; - sce->toolsettings->skgen_correlation_limit = 0.98f; - sce->toolsettings->skgen_symmetry_limit = 0.1f; - sce->toolsettings->skgen_postpro = SKGEN_SMOOTH; - sce->toolsettings->skgen_postpro_passes = 3; - sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_SUB_CORRELATION|SKGEN_HARMONIC; - sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION; - sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH; - sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE; - - - sce->toolsettings->skgen_retarget_angle_weight = 1.0f; - sce->toolsettings->skgen_retarget_length_weight = 1.0f; - sce->toolsettings->skgen_retarget_distance_weight = 1.0f; - - /* Skeleton Sketching */ - sce->toolsettings->bone_sketching = 0; - sce->toolsettings->skgen_retarget_roll = SK_RETARGET_ROLL_VIEW; } } @@ -3463,60 +2527,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 3)) { - Object *ob; - - /* Adjustments needed after Bullets update */ - for (ob = bmain->object.first; ob; ob = ob->id.next) { - ob->damping *= 0.635f; - ob->rdamping = 0.1f + (0.8f * ob->rdamping); - } - } - - if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 4)) { - Scene *sce; - World *wrld; - - /* Dome (Fisheye) default parameters */ - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - sce->r.domeangle = 180; - sce->r.domemode = 1; - sce->r.domeres = 4; - sce->r.domeresbuf = 1.0f; - sce->r.dometilt = 0; - } - /* DBVT culling by default */ - for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) { - wrld->mode |= WO_DBVT_CULLING; - wrld->occlusionRes = 128; - } - } - - if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 5)) { - Object *ob; - World *wrld; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->parent) { - /* check if top parent has compound shape set and if yes, set this object - * to compound shaper as well (was the behavior before, now it's optional) */ - Object *parent = blo_do_versions_newlibadr(fd, lib, ob->parent); - while (parent && parent != ob && parent->parent != NULL) { - parent = blo_do_versions_newlibadr(fd, lib, parent->parent); - } - if (parent) { - if (parent->gameflag & OB_CHILD) - ob->gameflag |= OB_CHILD; - } - } - } - for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) { - wrld->ticrate = 60; - wrld->maxlogicstep = 5; - wrld->physubstep = 1; - wrld->maxphystep = 5; - } - } - /* correct introduce of seed for wind force */ if (bmain->versionfile < 249 && bmain->subversionfile < 1) { Object *ob; diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c new file mode 100644 index 00000000000..2f98d068e7d --- /dev/null +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -0,0 +1,366 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +/** \file blender/blenloader/intern/versioning_userdef.c + * \ingroup blenloader + * + * Version patch user preferences. + */ + +#include <string.h> + +#include "BLI_math.h" +#include "BLI_utildefines.h" + +#include "DNA_userdef_types.h" +#include "DNA_curve_types.h" +#include "DNA_windowmanager_types.h" + +#include "BKE_addon.h" +#include "BKE_colorband.h" +#include "BKE_main.h" + +#include "BLO_readfile.h" /* Own include. */ + +/* Disallow access to global userdef. */ +#define U (_error_) + + +static void do_versions_theme(UserDef *userdef, bTheme *btheme) +{ + +#define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver) + if (!USER_VERSION_ATLEAST(280, 20)) { + memcpy(btheme, &U_theme_default, sizeof(*btheme)); + } + + if (!USER_VERSION_ATLEAST(280, 25)) { + copy_v4_v4_char(btheme->tact.anim_preview_range, btheme->tact.anim_active); + copy_v4_v4_char(btheme->tnla.anim_preview_range, btheme->tnla.anim_active); + copy_v4_v4_char(btheme->tipo.anim_preview_range, btheme->tact.anim_active); + } + + if (!USER_VERSION_ATLEAST(280, 26)) { + copy_v4_v4_char(btheme->tui.icon_collection, U_theme_default.tui.icon_collection); + copy_v4_v4_char(btheme->tui.icon_object, U_theme_default.tui.icon_object); + copy_v4_v4_char(btheme->tui.icon_object_data, U_theme_default.tui.icon_object_data); + copy_v4_v4_char(btheme->tui.icon_modifier, U_theme_default.tui.icon_modifier); + copy_v4_v4_char(btheme->tui.icon_shading, U_theme_default.tui.icon_shading); + } + + if (!USER_VERSION_ATLEAST(280, 27)) { + copy_v4_v4_char(btheme->tact.shade2, U_theme_default.tact.shade2); + copy_v4_v4_char(btheme->tact.hilite, U_theme_default.tact.hilite); + copy_v4_v4_char(btheme->tact.group, U_theme_default.tact.group); + copy_v4_v4_char(btheme->tact.group_active, U_theme_default.tact.group_active); + copy_v4_v4_char(btheme->tact.strip_select, U_theme_default.tact.strip_select); + copy_v4_v4_char(btheme->tact.ds_channel, U_theme_default.tact.ds_channel); + copy_v4_v4_char(btheme->tact.ds_subchannel, U_theme_default.tact.ds_subchannel); + copy_v4_v4_char(btheme->tact.keytype_movehold, U_theme_default.tact.keytype_movehold); + copy_v4_v4_char(btheme->tact.keytype_movehold_select, U_theme_default.tact.keytype_movehold_select); + } +#undef USER_VERSION_ATLEAST + +} + +/* patching UserDef struct and Themes */ +void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef) +{ + +#define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(bmain, ver, subver) + + /* the UserDef struct is not corrected with do_versions() .... ugh! */ + if (userdef->wheellinescroll == 0) userdef->wheellinescroll = 3; + if (userdef->menuthreshold1 == 0) { + userdef->menuthreshold1 = 5; + userdef->menuthreshold2 = 2; + } + if (userdef->tb_leftmouse == 0) { + userdef->tb_leftmouse = 5; + userdef->tb_rightmouse = 5; + } + if (userdef->mixbufsize == 0) userdef->mixbufsize = 2048; + if (userdef->autokey_mode == 0) { + /* 'add/replace' but not on */ + userdef->autokey_mode = 2; + } + if (userdef->savetime <= 0) { + userdef->savetime = 1; +// XXX error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n"); + } + if (userdef->gizmo_size == 0) { + userdef->gizmo_size = 75; + userdef->gizmo_flag |= USER_GIZMO_DRAW; + } + if (userdef->pad_rot_angle == 0.0f) + userdef->pad_rot_angle = 15.0f; + + /* graph editor - unselected F-Curve visibility */ + if (userdef->fcu_inactive_alpha == 0) { + userdef->fcu_inactive_alpha = 0.25f; + } + + if (!USER_VERSION_ATLEAST(192, 0)) { + strcpy(userdef->sounddir, "/"); + } + + /* patch to set Dupli Armature */ + if (!USER_VERSION_ATLEAST(220, 0)) { + userdef->dupflag |= USER_DUP_ARM; + } + + /* added seam, normal color, undo */ + if (!USER_VERSION_ATLEAST(235, 0)) { + userdef->uiflag |= USER_GLOBALUNDO; + if (userdef->undosteps == 0) userdef->undosteps = 32; + } + if (!USER_VERSION_ATLEAST(236, 0)) { + /* illegal combo... */ + if (userdef->flag & USER_LMOUSESELECT) + userdef->flag &= ~USER_TWOBUTTONMOUSE; + } + if (!USER_VERSION_ATLEAST(240, 0)) { + userdef->uiflag |= USER_PLAINMENUS; + if (userdef->obcenter_dia == 0) userdef->obcenter_dia = 6; + } + if (!USER_VERSION_ATLEAST(242, 0)) { + /* set defaults for 3D View rotating axis indicator */ + /* since size can't be set to 0, this indicates it's not saved in startup.blend */ + if (userdef->rvisize == 0) { + userdef->rvisize = 15; + userdef->rvibright = 8; + userdef->uiflag |= USER_SHOW_GIZMO_AXIS; + } + + } + if (!USER_VERSION_ATLEAST(244, 0)) { + /* set default number of recently-used files (if not set) */ + if (userdef->recent_files == 0) userdef->recent_files = 10; + } + if (!USER_VERSION_ATLEAST(245, 3)) { + if (userdef->coba_weight.tot == 0) + BKE_colorband_init(&userdef->coba_weight, true); + } + if (!USER_VERSION_ATLEAST(245, 3)) { + userdef->flag |= USER_ADD_VIEWALIGNED | USER_ADD_EDITMODE; + } + if (!USER_VERSION_ATLEAST(250, 0)) { + /* adjust grease-pencil distances */ + userdef->gp_manhattendist = 1; + userdef->gp_euclideandist = 2; + + /* adjust default interpolation for new IPO-curves */ + userdef->ipo_new = BEZT_IPO_BEZ; + } + + if (!USER_VERSION_ATLEAST(250, 3)) { + /* new audio system */ + if (userdef->audiochannels == 0) + userdef->audiochannels = 2; + if (userdef->audioformat == 0) + userdef->audioformat = 0x24; + if (userdef->audiorate == 0) + userdef->audiorate = 48000; + } + + if (!USER_VERSION_ATLEAST(250, 8)) { + wmKeyMap *km; + + for (km = userdef->user_keymaps.first; km; km = km->next) { + if (STREQ(km->idname, "Armature_Sketch")) + strcpy(km->idname, "Armature Sketch"); + else if (STREQ(km->idname, "View3D")) + strcpy(km->idname, "3D View"); + else if (STREQ(km->idname, "View3D Generic")) + strcpy(km->idname, "3D View Generic"); + else if (STREQ(km->idname, "EditMesh")) + strcpy(km->idname, "Mesh"); + else if (STREQ(km->idname, "UVEdit")) + strcpy(km->idname, "UV Editor"); + else if (STREQ(km->idname, "Animation_Channels")) + strcpy(km->idname, "Animation Channels"); + else if (STREQ(km->idname, "GraphEdit Keys")) + strcpy(km->idname, "Graph Editor"); + else if (STREQ(km->idname, "GraphEdit Generic")) + strcpy(km->idname, "Graph Editor Generic"); + else if (STREQ(km->idname, "Action_Keys")) + strcpy(km->idname, "Dopesheet"); + else if (STREQ(km->idname, "NLA Data")) + strcpy(km->idname, "NLA Editor"); + else if (STREQ(km->idname, "Node Generic")) + strcpy(km->idname, "Node Editor"); + else if (STREQ(km->idname, "Logic Generic")) + strcpy(km->idname, "Logic Editor"); + else if (STREQ(km->idname, "File")) + strcpy(km->idname, "File Browser"); + else if (STREQ(km->idname, "FileMain")) + strcpy(km->idname, "File Browser Main"); + else if (STREQ(km->idname, "FileButtons")) + strcpy(km->idname, "File Browser Buttons"); + else if (STREQ(km->idname, "Buttons Generic")) + strcpy(km->idname, "Property Editor"); + } + } + + if (!USER_VERSION_ATLEAST(252, 3)) { + if (userdef->flag & USER_LMOUSESELECT) + userdef->flag &= ~USER_TWOBUTTONMOUSE; + } + if (!USER_VERSION_ATLEAST(252, 4)) { + /* default new handle type is auto handles */ + userdef->keyhandles_new = HD_AUTO; + } + + if (!USER_VERSION_ATLEAST(257, 0)) { + /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs, + * so that it doesn't linger around from old configs like a ghost */ + userdef->autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET; + } + + if (!USER_VERSION_ATLEAST(260, 3)) { + /* if new keyframes handle default is stuff "auto", make it "auto-clamped" instead + * was changed in 260 as part of GSoC11, but version patch was wrong + */ + if (userdef->keyhandles_new == HD_AUTO) + userdef->keyhandles_new = HD_AUTO_ANIM; + + /* enable (Cycles) addon by default */ + BKE_addon_ensure(&userdef->addons, "cycles"); + } + + if (!USER_VERSION_ATLEAST(261, 4)) { + userdef->use_16bit_textures = true; + } + + if (!USER_VERSION_ATLEAST(267, 0)) { + + /* GL Texture Garbage Collection */ + if (userdef->textimeout == 0) { + userdef->texcollectrate = 60; + userdef->textimeout = 120; + } + if (userdef->memcachelimit <= 0) { + userdef->memcachelimit = 32; + } + if (userdef->dbl_click_time == 0) { + userdef->dbl_click_time = 350; + } + if (userdef->v2d_min_gridsize == 0) { + userdef->v2d_min_gridsize = 35; + } + if (userdef->dragthreshold == 0) + userdef->dragthreshold = 5; + if (userdef->widget_unit == 0) + userdef->widget_unit = 20; + if (userdef->anisotropic_filter <= 0) + userdef->anisotropic_filter = 1; + + if (userdef->ndof_sensitivity == 0.0f) { + userdef->ndof_sensitivity = 1.0f; + userdef->ndof_flag = (NDOF_LOCK_HORIZON | NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE); + } + + if (userdef->ndof_orbit_sensitivity == 0.0f) { + userdef->ndof_orbit_sensitivity = userdef->ndof_sensitivity; + + if (!(userdef->flag & USER_TRACKBALL)) + userdef->ndof_flag |= NDOF_TURNTABLE; + } + if (userdef->tweak_threshold == 0) + userdef->tweak_threshold = 10; + } + + /* NOTE!! from now on use userdef->versionfile and userdef->subversionfile */ +#undef USER_VERSION_ATLEAST +#define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver) + + if (!USER_VERSION_ATLEAST(271, 5)) { + userdef->pie_menu_radius = 100; + userdef->pie_menu_threshold = 12; + userdef->pie_animation_timeout = 6; + } + + if (!USER_VERSION_ATLEAST(275, 2)) { + userdef->ndof_deadzone = 0.1; + } + + if (!USER_VERSION_ATLEAST(275, 4)) { + userdef->node_margin = 80; + } + + if (!USER_VERSION_ATLEAST(278, 6)) { + /* Clear preference flags for re-use. */ + userdef->flag &= ~( + USER_FLAG_NUMINPUT_ADVANCED | USER_FLAG_DEPRECATED_2 | USER_FLAG_DEPRECATED_3 | + USER_FLAG_DEPRECATED_6 | USER_FLAG_DEPRECATED_7 | + USER_FLAG_DEPRECATED_9 | USER_DEVELOPER_UI); + userdef->uiflag &= ~( + USER_UIFLAG_DEPRECATED_7); + userdef->transopts &= ~( + USER_TR_DEPRECATED_2 | USER_TR_DEPRECATED_3 | USER_TR_DEPRECATED_4 | + USER_TR_DEPRECATED_6 | USER_TR_DEPRECATED_7); + + userdef->uiflag |= USER_LOCK_CURSOR_ADJUST; + } + + + if (!USER_VERSION_ATLEAST(280, 20)) { + userdef->gpu_viewport_quality = 0.6f; + + /* Reset theme, old themes will not be compatible with minor version updates from now on. */ + for (bTheme *btheme = userdef->themes.first; btheme; btheme = btheme->next) { + memcpy(btheme, &U_theme_default, sizeof(*btheme)); + } + + /* Annotations - new layer color + * Replace anything that used to be set if it looks like was left + * on the old default (i.e. black), which most users used + */ + if ((userdef->gpencil_new_layer_col[3] < 0.1f) || (userdef->gpencil_new_layer_col[0] < 0.1f)) { + /* - New color matches the annotation pencil icon + * - Non-full alpha looks better! + */ + ARRAY_SET_ITEMS(userdef->gpencil_new_layer_col, 0.38f, 0.61f, 0.78f, 0.9f); + } + } + + /** + * Include next version bump. + */ + { + /* (keep this block even if it becomes empty). */ + } + + if (userdef->pixelsize == 0.0f) + userdef->pixelsize = 1.0f; + + if (userdef->image_draw_method == 0) + userdef->image_draw_method = IMAGE_DRAW_METHOD_2DTEXTURE; + + // we default to the first audio device + userdef->audiodevice = 0; + + for (bTheme *btheme = userdef->themes.first; btheme; btheme = btheme->next) { + do_versions_theme(userdef, btheme); + } +#undef USER_VERSION_ATLEAST + +} diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 4b64d0a3d3f..16bc845a3e9 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -102,24 +102,29 @@ /* allow writefile to use deprecated functionality (for forward compatibility code) */ #define DNA_DEPRECATED_ALLOW +/* Allow using DNA struct members that are marked as private for read/write. + * Note: Each header that uses this needs to define its own way of handling + * it. There's no generic implementation, direct use does nothing. */ +#define DNA_PRIVATE_READ_WRITE_ALLOW #include "DNA_anim_types.h" #include "DNA_armature_types.h" -#include "DNA_actuator_types.h" #include "DNA_brush_types.h" #include "DNA_cachefile_types.h" #include "DNA_camera_types.h" #include "DNA_cloth_types.h" +#include "DNA_collection_types.h" #include "DNA_constraint_types.h" -#include "DNA_controller_types.h" #include "DNA_dynamicpaint_types.h" #include "DNA_genfile.h" -#include "DNA_group_types.h" #include "DNA_gpencil_types.h" +#include "DNA_gpencil_modifier_types.h" +#include "DNA_shader_fx_types.h" #include "DNA_fileglobal_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" #include "DNA_lamp_types.h" +#include "DNA_layer_types.h" #include "DNA_linestyle_types.h" #include "DNA_meta_types.h" #include "DNA_mesh_types.h" @@ -130,12 +135,11 @@ #include "DNA_object_force_types.h" #include "DNA_packedFile_types.h" #include "DNA_particle_types.h" -#include "DNA_property_types.h" +#include "DNA_lightprobe_types.h" #include "DNA_rigidbody_types.h" #include "DNA_scene_types.h" #include "DNA_sdna_types.h" #include "DNA_sequence_types.h" -#include "DNA_sensor_types.h" #include "DNA_smoke_types.h" #include "DNA_space_types.h" #include "DNA_screen_types.h" @@ -146,6 +150,7 @@ #include "DNA_vfont_types.h" #include "DNA_world_types.h" #include "DNA_windowmanager_types.h" +#include "DNA_workspace_types.h" #include "DNA_movieclip_types.h" #include "DNA_mask_types.h" @@ -159,19 +164,25 @@ #include "BKE_blender_version.h" #include "BKE_bpath.h" #include "BKE_curve.h" +#include "BKE_collection.h" #include "BKE_constraint.h" #include "BKE_global.h" // for G +#include "BKE_gpencil_modifier.h" #include "BKE_idcode.h" +#include "BKE_layer.h" #include "BKE_library.h" // for set_listbasepointers +#include "BKE_library_override.h" #include "BKE_main.h" #include "BKE_node.h" #include "BKE_report.h" #include "BKE_sequencer.h" +#include "BKE_shader_fx.h" #include "BKE_subsurf.h" #include "BKE_modifier.h" #include "BKE_fcurve.h" #include "BKE_pointcache.h" #include "BKE_mesh.h" +#include "BKE_workspace.h" #ifdef USE_NODE_COMPAT_CUSTOMNODES #include "NOD_socket.h" /* for sock->default_value data */ @@ -180,7 +191,6 @@ #include "BLO_writefile.h" #include "BLO_readfile.h" -#include "BLO_runtime.h" #include "BLO_undofile.h" #include "BLO_blend_defs.h" @@ -709,6 +719,25 @@ static void write_iddata(void *wd, const ID *id) if (id->properties && !ELEM(GS(id->name), ID_WM)) { IDP_WriteProperty(id->properties, wd); } + + if (id->override_static) { + writestruct(wd, DATA, IDOverrideStatic, 1, id->override_static); + + writelist(wd, DATA, IDOverrideStaticProperty, &id->override_static->properties); + for (IDOverrideStaticProperty *op = id->override_static->properties.first; op; op = op->next) { + writedata(wd, DATA, strlen(op->rna_path) + 1, op->rna_path); + + writelist(wd, DATA, IDOverrideStaticPropertyOperation, &op->operations); + for (IDOverrideStaticPropertyOperation *opop = op->operations.first; opop; opop = opop->next) { + if (opop->subitem_reference_name) { + writedata(wd, DATA, strlen(opop->subitem_reference_name) + 1, opop->subitem_reference_name); + } + if (opop->subitem_local_name) { + writedata(wd, DATA, strlen(opop->subitem_local_name) + 1, opop->subitem_local_name); + } + } + } + } } static void write_previews(WriteData *wd, const PreviewImage *prv_orig) @@ -1119,7 +1148,9 @@ static void write_nodetree_nolib(WriteData *wd, bNodeTree *ntree) * Take care using 'use_active_win', since we wont want the currently active window * to change which scene renders (currently only used for undo). */ -static void current_screen_compat(Main *mainvar, bScreen **r_screen, bool use_active_win) +static void current_screen_compat( + Main *mainvar, bool use_active_win, + bScreen **r_screen, Scene **r_scene, ViewLayer **r_view_layer) { wmWindowManager *wm; wmWindow *window = NULL; @@ -1147,7 +1178,9 @@ static void current_screen_compat(Main *mainvar, bScreen **r_screen, bool use_ac } } - *r_screen = (window) ? window->screen : NULL; + *r_screen = (window) ? BKE_workspace_active_screen_get(window->workspace_hook) : NULL; + *r_scene = (window) ? window->scene : NULL; + *r_view_layer = (window && *r_scene) ? BKE_view_layer_find(*r_scene, window->view_layer_name) : NULL; } typedef struct RenderInfo { @@ -1163,13 +1196,11 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) { bScreen *curscreen; Scene *sce, *curscene = NULL; + ViewLayer *view_layer; RenderInfo data; /* XXX in future, handle multiple windows with multiple screens? */ - current_screen_compat(mainvar, &curscreen, false); - if (curscreen) { - curscene = curscreen->scene; - } + current_screen_compat(mainvar, false, &curscreen, &curscene, &view_layer); for (sce = mainvar->scene.first; sce; sce = sce->id.next) { if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) { @@ -1218,6 +1249,30 @@ static void write_userdef(WriteData *wd, const UserDef *userdef) } } + for (const bUserMenu *um = userdef->user_menus.first; um; um = um->next) { + writestruct(wd, DATA, bUserMenu, 1, um); + for (const bUserMenuItem *umi = um->items.first; umi; umi = umi->next) { + if (umi->type == USER_MENU_TYPE_OPERATOR) { + const bUserMenuItem_Op *umi_op = (const bUserMenuItem_Op *)umi; + writestruct(wd, DATA, bUserMenuItem_Op, 1, umi_op); + if (umi_op->prop) { + IDP_WriteProperty(umi_op->prop, wd); + } + } + else if (umi->type == USER_MENU_TYPE_MENU) { + const bUserMenuItem_Menu *umi_mt = (const bUserMenuItem_Menu *)umi; + writestruct(wd, DATA, bUserMenuItem_Menu, 1, umi_mt); + } + else if (umi->type == USER_MENU_TYPE_PROP) { + const bUserMenuItem_Prop *umi_pr = (const bUserMenuItem_Prop *)umi; + writestruct(wd, DATA, bUserMenuItem_Prop, 1, umi_pr); + } + else { + writestruct(wd, DATA, bUserMenuItem, 1, umi); + } + } + } + for (const bAddon *bext = userdef->addons.first; bext; bext = bext->next) { writestruct(wd, DATA, bAddon, 1, bext); if (bext->prop) { @@ -1354,9 +1409,13 @@ static void write_particlesettings(WriteData *wd, ParticleSettings *part) if (dw->ob != NULL) { dw->index = 0; if (part->dup_group) { /* can be NULL if lining fails or set to None */ - for (GroupObject *go = part->dup_group->gobject.first; - go && go->ob != dw->ob; - go = go->next, dw->index++); + FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(part->dup_group, object) + { + if (object != dw->ob) { + dw->index++; + } + } + FOREACH_COLLECTION_OBJECT_RECURSIVE_END; } } writestruct(wd, DATA, ParticleDupliWeight, 1, dw); @@ -1433,180 +1492,6 @@ static void write_particlesystems(WriteData *wd, ListBase *particles) } } -static void write_properties(WriteData *wd, ListBase *lb) -{ - bProperty *prop; - - prop = lb->first; - while (prop) { - writestruct(wd, DATA, bProperty, 1, prop); - - if (prop->poin && prop->poin != &prop->data) { - writedata(wd, DATA, MEM_allocN_len(prop->poin), prop->poin); - } - - prop = prop->next; - } -} - -static void write_sensors(WriteData *wd, ListBase *lb) -{ - bSensor *sens; - - sens = lb->first; - while (sens) { - writestruct(wd, DATA, bSensor, 1, sens); - - writedata(wd, DATA, sizeof(void *) * sens->totlinks, sens->links); - - switch (sens->type) { - case SENS_NEAR: - writestruct(wd, DATA, bNearSensor, 1, sens->data); - break; - case SENS_MOUSE: - writestruct(wd, DATA, bMouseSensor, 1, sens->data); - break; - case SENS_KEYBOARD: - writestruct(wd, DATA, bKeyboardSensor, 1, sens->data); - break; - case SENS_PROPERTY: - writestruct(wd, DATA, bPropertySensor, 1, sens->data); - break; - case SENS_ARMATURE: - writestruct(wd, DATA, bArmatureSensor, 1, sens->data); - break; - case SENS_ACTUATOR: - writestruct(wd, DATA, bActuatorSensor, 1, sens->data); - break; - case SENS_DELAY: - writestruct(wd, DATA, bDelaySensor, 1, sens->data); - break; - case SENS_COLLISION: - writestruct(wd, DATA, bCollisionSensor, 1, sens->data); - break; - case SENS_RADAR: - writestruct(wd, DATA, bRadarSensor, 1, sens->data); - break; - case SENS_RANDOM: - writestruct(wd, DATA, bRandomSensor, 1, sens->data); - break; - case SENS_RAY: - writestruct(wd, DATA, bRaySensor, 1, sens->data); - break; - case SENS_MESSAGE: - writestruct(wd, DATA, bMessageSensor, 1, sens->data); - break; - case SENS_JOYSTICK: - writestruct(wd, DATA, bJoystickSensor, 1, sens->data); - break; - default: - ; /* error: don't know how to write this file */ - } - - sens = sens->next; - } -} - -static void write_controllers(WriteData *wd, ListBase *lb) -{ - bController *cont; - - cont = lb->first; - while (cont) { - writestruct(wd, DATA, bController, 1, cont); - - writedata(wd, DATA, sizeof(void *) * cont->totlinks, cont->links); - - switch (cont->type) { - case CONT_EXPRESSION: - writestruct(wd, DATA, bExpressionCont, 1, cont->data); - break; - case CONT_PYTHON: - writestruct(wd, DATA, bPythonCont, 1, cont->data); - break; - default: - ; /* error: don't know how to write this file */ - } - - cont = cont->next; - } -} - -static void write_actuators(WriteData *wd, ListBase *lb) -{ - bActuator *act; - - act = lb->first; - while (act) { - writestruct(wd, DATA, bActuator, 1, act); - - switch (act->type) { - case ACT_ACTION: - case ACT_SHAPEACTION: - writestruct(wd, DATA, bActionActuator, 1, act->data); - break; - case ACT_SOUND: - writestruct(wd, DATA, bSoundActuator, 1, act->data); - break; - case ACT_OBJECT: - writestruct(wd, DATA, bObjectActuator, 1, act->data); - break; - case ACT_PROPERTY: - writestruct(wd, DATA, bPropertyActuator, 1, act->data); - break; - case ACT_CAMERA: - writestruct(wd, DATA, bCameraActuator, 1, act->data); - break; - case ACT_CONSTRAINT: - writestruct(wd, DATA, bConstraintActuator, 1, act->data); - break; - case ACT_EDIT_OBJECT: - writestruct(wd, DATA, bEditObjectActuator, 1, act->data); - break; - case ACT_SCENE: - writestruct(wd, DATA, bSceneActuator, 1, act->data); - break; - case ACT_GROUP: - writestruct(wd, DATA, bGroupActuator, 1, act->data); - break; - case ACT_RANDOM: - writestruct(wd, DATA, bRandomActuator, 1, act->data); - break; - case ACT_MESSAGE: - writestruct(wd, DATA, bMessageActuator, 1, act->data); - break; - case ACT_GAME: - writestruct(wd, DATA, bGameActuator, 1, act->data); - break; - case ACT_VISIBILITY: - writestruct(wd, DATA, bVisibilityActuator, 1, act->data); - break; - case ACT_2DFILTER: - writestruct(wd, DATA, bTwoDFilterActuator, 1, act->data); - break; - case ACT_PARENT: - writestruct(wd, DATA, bParentActuator, 1, act->data); - break; - case ACT_STATE: - writestruct(wd, DATA, bStateActuator, 1, act->data); - break; - case ACT_ARMATURE: - writestruct(wd, DATA, bArmatureActuator, 1, act->data); - break; - case ACT_STEERING: - writestruct(wd, DATA, bSteeringActuator, 1, act->data); - break; - case ACT_MOUSE: - writestruct(wd, DATA, bMouseActuator, 1, act->data); - break; - default: - ; /* error: don't know how to write this file */ - } - - act = act->next; - } -} - static void write_motionpath(WriteData *wd, bMotionPath *mpath) { /* sanity checks */ @@ -1725,6 +1610,13 @@ static void write_defgroups(WriteData *wd, ListBase *defbase) } } +static void write_fmaps(WriteData *wd, ListBase *fbase) +{ + for (bFaceMap *fmap = fbase->first; fmap; fmap = fmap->next) { + writestruct(wd, DATA, bFaceMap, 1, fmap); + } +} + static void write_modifiers(WriteData *wd, ListBase *modbase) { ModifierData *md; @@ -1762,6 +1654,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) SmokeModifierData *smd = (SmokeModifierData *)md; if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { + writestruct(wd, DATA, SmokeDomainSettings, 1, smd->domain); + if (smd->domain) { write_pointcaches(wd, &(smd->domain->ptcaches[0])); @@ -1775,11 +1669,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) if (smd->domain->coba) { writestruct(wd, DATA, ColorBand, 1, smd->domain->coba); } - } - writestruct(wd, DATA, SmokeDomainSettings, 1, smd->domain); - if (smd->domain) { /* cleanup the fake pointcache */ BKE_ptcache_free_list(&smd->domain->ptcaches[1]); smd->domain->point_cache[1] = NULL; @@ -1900,6 +1791,57 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) } } +static void write_gpencil_modifiers(WriteData *wd, ListBase *modbase) +{ + GpencilModifierData *md; + + if (modbase == NULL) { + return; + } + + for (md = modbase->first; md; md = md->next) { + const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type); + if (mti == NULL) { + return; + } + + writestruct_id(wd, DATA, mti->struct_name, 1, md); + + if (md->type == eGpencilModifierType_Thick) { + ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md; + + if (gpmd->curve_thickness) { + write_curvemapping(wd, gpmd->curve_thickness); + } + } + else if (md->type == eGpencilModifierType_Hook) { + HookGpencilModifierData *gpmd = (HookGpencilModifierData *)md; + + if (gpmd->curfalloff) { + write_curvemapping(wd, gpmd->curfalloff); + } + } + } +} + +static void write_shaderfxs(WriteData *wd, ListBase *fxbase) +{ + ShaderFxData *fx; + + if (fxbase == NULL) { + return; + } + + for (fx = fxbase->first; fx; fx = fx->next) { + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); + if (fxi == NULL) { + return; + } + + writestruct_id(wd, DATA, fxi->struct_name, 1, fx); + } +} + static void write_object(WriteData *wd, Object *ob) { if (ob->id.us > 0 || wd->use_memfile) { @@ -1915,10 +1857,6 @@ static void write_object(WriteData *wd, Object *ob) writedata(wd, DATA, sizeof(void *) * ob->totcol, ob->mat); writedata(wd, DATA, sizeof(char) * ob->totcol, ob->matbits); /* write_effects(wd, &ob->effect); */ /* not used anymore */ - write_properties(wd, &ob->prop); - write_sensors(wd, &ob->sensors); - write_controllers(wd, &ob->controllers); - write_actuators(wd, &ob->actuators); if (ob->type == OB_ARMATURE) { bArmature *arm = ob->data; @@ -1929,16 +1867,20 @@ static void write_object(WriteData *wd, Object *ob) write_pose(wd, ob->pose); write_defgroups(wd, &ob->defbase); + write_fmaps(wd, &ob->fmaps); write_constraints(wd, &ob->constraints); write_motionpath(wd, ob->mpath); writestruct(wd, DATA, PartDeflect, 1, ob->pd); - writestruct(wd, DATA, SoftBody, 1, ob->soft); if (ob->soft) { - write_pointcaches(wd, &ob->soft->ptcaches); + /* Set deprecated pointers to prevent crashes of older Blenders */ + ob->soft->pointcache = ob->soft->shared->pointcache; + ob->soft->ptcaches = ob->soft->shared->ptcaches; + writestruct(wd, DATA, SoftBody, 1, ob->soft); + writestruct(wd, DATA, SoftBody_Shared, 1, ob->soft->shared); + write_pointcaches(wd, &(ob->soft->shared->ptcaches)); writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights); } - writestruct(wd, DATA, BulletSoftBody, 1, ob->bsoft); if (ob->rigidbody_object) { /* TODO: if any extra data is added to handle duplis, will need separate function then */ @@ -1954,6 +1896,8 @@ static void write_object(WriteData *wd, Object *ob) write_particlesystems(wd, &ob->particlesystem); write_modifiers(wd, &ob->modifiers); + write_gpencil_modifiers(wd, &ob->greasepencil_modifiers); + write_shaderfxs(wd, &ob->shader_fx); writelist(wd, DATA, LinkData, &ob->pc_ids); writelist(wd, DATA, LodLevel, &ob->lodlevels); @@ -2011,6 +1955,10 @@ static void write_camera(WriteData *wd, Camera *cam) if (cam->adt) { write_animdata(wd, cam->adt); } + + for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) { + writestruct(wd, DATA, CameraBGImage, 1, bgpic); + } } } @@ -2161,6 +2109,10 @@ static void write_customdata( else if (layer->type == CD_GRID_PAINT_MASK) { write_grid_paint_mask(wd, count, layer->data); } + else if (layer->type == CD_FACEMAP) { + const int *layer_data = layer->data; + writedata(wd, DATA, sizeof(*layer_data) * count, layer_data); + } else { CustomData_file_write_info(layer->type, &structname, &structnum); if (structnum) { @@ -2315,6 +2267,8 @@ static void write_image(WriteData *wd, Image *ima) writestruct(wd, DATA, Stereo3dFormat, 1, ima->stereo3d_format); ima->packedfile = NULL; + + writelist(wd, DATA, RenderSlot, &ima->renderslots); } } @@ -2333,24 +2287,6 @@ static void write_texture(WriteData *wd, Tex *tex) if (tex->coba) { writestruct(wd, DATA, ColorBand, 1, tex->coba); } - if (tex->type == TEX_ENVMAP && tex->env) { - writestruct(wd, DATA, EnvMap, 1, tex->env); - } - if (tex->type == TEX_POINTDENSITY && tex->pd) { - writestruct(wd, DATA, PointDensity, 1, tex->pd); - if (tex->pd->coba) { - writestruct(wd, DATA, ColorBand, 1, tex->pd->coba); - } - if (tex->pd->falloff_curve) { - write_curvemapping(wd, tex->pd->falloff_curve); - } - } - if (tex->type == TEX_VOXELDATA) { - writestruct(wd, DATA, VoxelData, 1, tex->vd); - } - if (tex->type == TEX_OCEAN && tex->ot) { - writestruct(wd, DATA, OceanTex, 1, tex->ot); - } /* nodetree is integral part of texture, no libdata */ if (tex->nodetree) { @@ -2373,19 +2309,6 @@ static void write_material(WriteData *wd, Material *ma) write_animdata(wd, ma->adt); } - for (int a = 0; a < MAX_MTEX; a++) { - if (ma->mtex[a]) { - writestruct(wd, DATA, MTex, 1, ma->mtex[a]); - } - } - - if (ma->ramp_col) { - writestruct(wd, DATA, ColorBand, 1, ma->ramp_col); - } - if (ma->ramp_spec) { - writestruct(wd, DATA, ColorBand, 1, ma->ramp_spec); - } - /* nodetree is integral part of material, no libdata */ if (ma->nodetree) { writestruct(wd, DATA, bNodeTree, 1, ma->nodetree); @@ -2393,6 +2316,11 @@ static void write_material(WriteData *wd, Material *ma) } write_previews(wd, ma->preview); + + /* grease pencil settings */ + if (ma->gp_style) { + writestruct(wd, DATA, MaterialGPencilStyle, 1, ma->gp_style); + } } } @@ -2407,12 +2335,6 @@ static void write_world(WriteData *wd, World *wrld) write_animdata(wd, wrld->adt); } - for (int a = 0; a < MAX_MTEX; a++) { - if (wrld->mtex[a]) { - writestruct(wd, DATA, MTex, 1, wrld->mtex[a]); - } - } - /* nodetree is integral part of world, no libdata */ if (wrld->nodetree) { writestruct(wd, DATA, bNodeTree, 1, wrld->nodetree); @@ -2434,13 +2356,6 @@ static void write_lamp(WriteData *wd, Lamp *la) write_animdata(wd, la->adt); } - /* direct data */ - for (int a = 0; a < MAX_MTEX; a++) { - if (la->mtex[a]) { - writestruct(wd, DATA, MTex, 1, la->mtex[a]); - } - } - if (la->curfalloff) { write_curvemapping(wd, la->curfalloff); } @@ -2455,6 +2370,31 @@ static void write_lamp(WriteData *wd, Lamp *la) } } +static void write_collection_nolib(WriteData *wd, Collection *collection) +{ + /* Shared function for collection datablocks and scene master collection. */ + write_previews(wd, collection->preview); + + for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + writestruct(wd, DATA, CollectionObject, 1, cob); + } + + for (CollectionChild *child = collection->children.first; child; child = child->next) { + writestruct(wd, DATA, CollectionChild, 1, child); + } +} + +static void write_collection(WriteData *wd, Collection *collection) +{ + if (collection->id.us > 0 || wd->use_memfile) { + /* write LibData */ + writestruct(wd, ID_GR, Collection, 1, collection); + write_iddata(wd, &collection->id); + + write_collection_nolib(wd, collection); + } +} + static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) { SequenceModifierData *smd; @@ -2496,6 +2436,64 @@ static void write_paint(WriteData *wd, Paint *p) } } +static void write_layer_collections(WriteData *wd, ListBase *lb) +{ + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + writestruct(wd, DATA, LayerCollection, 1, lc); + + write_layer_collections(wd, &lc->layer_collections); + } +} + +static void write_view_layer(WriteData *wd, ViewLayer *view_layer) +{ + writestruct(wd, DATA, ViewLayer, 1, view_layer); + writelist(wd, DATA, Base, &view_layer->object_bases); + + if (view_layer->id_properties) { + IDP_WriteProperty(view_layer->id_properties, wd); + } + + for (FreestyleModuleConfig *fmc = view_layer->freestyle_config.modules.first; fmc; fmc = fmc->next) { + writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc); + } + + for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; fls = fls->next) { + writestruct(wd, DATA, FreestyleLineSet, 1, fls); + } + write_layer_collections(wd, &view_layer->layer_collections); +} + +static void write_lightcache_texture(WriteData *wd, LightCacheTexture *tex) +{ + if (tex->data) { + size_t data_size = tex->components * tex->tex_size[0] * tex->tex_size[1] * tex->tex_size[2]; + if (tex->data_type == LIGHTCACHETEX_FLOAT) { + data_size *= sizeof(float); + } + else if (tex->data_type == LIGHTCACHETEX_UINT) { + data_size *= sizeof(unsigned int); + } + writedata(wd, DATA, data_size, tex->data); + } +} + +static void write_lightcache(WriteData *wd, LightCache *cache) +{ + write_lightcache_texture(wd, &cache->grid_tx); + write_lightcache_texture(wd, &cache->cube_tx); + + if (cache->cube_mips) { + writestruct(wd, DATA, LightCacheTexture, cache->mips_len, cache->cube_mips); + for (int i = 0; i < cache->mips_len; ++i) { + write_lightcache_texture(wd, &cache->cube_mips[i]); + } + } + + writestruct(wd, DATA, LightGridCache, cache->grid_len, cache->grid_data); + writestruct(wd, DATA, LightProbeCache, cache->cube_len, cache->cube_data); +} + static void write_scene(WriteData *wd, Scene *sce) { /* write LibData */ @@ -2508,10 +2506,6 @@ static void write_scene(WriteData *wd, Scene *sce) write_keyingsets(wd, &sce->keyingsets); /* direct data */ - for (Base *base = sce->base.first; base; base = base->next) { - writestruct(wd, DATA, Base, 1, base); - } - ToolSettings *tos = sce->toolsettings; writestruct(wd, DATA, ToolSettings, 1, tos); if (tos->vpaint) { @@ -2530,24 +2524,18 @@ static void write_scene(WriteData *wd, Scene *sce) writestruct(wd, DATA, UvSculpt, 1, tos->uvsculpt); write_paint(wd, &tos->uvsculpt->paint); } - /* write grease-pencil drawing brushes to file */ - writelist(wd, DATA, bGPDbrush, &tos->gp_brushes); - for (bGPDbrush *brush = tos->gp_brushes.first; brush; brush = brush->next) { - if (brush->cur_sensitivity) { - write_curvemapping(wd, brush->cur_sensitivity); - } - if (brush->cur_strength) { - write_curvemapping(wd, brush->cur_strength); - } - if (brush->cur_jitter) { - write_curvemapping(wd, brush->cur_jitter); - } + if (tos->gp_paint) { + writestruct(wd, DATA, GpPaint, 1, tos->gp_paint); + write_paint(wd, &tos->gp_paint->paint); } /* write grease-pencil custom ipo curve to file */ if (tos->gp_interpolate.custom_ipo) { write_curvemapping(wd, tos->gp_interpolate.custom_ipo); } - + /* write grease-pencil multiframe falloff curve to file */ + if (tos->gp_sculpt.cur_falloff) { + write_curvemapping(wd, tos->gp_sculpt.cur_falloff); + } write_paint(wd, &tos->imapaint.paint); @@ -2664,19 +2652,6 @@ static void write_scene(WriteData *wd, Scene *sce) writestruct(wd, DATA, TransformOrientation, 1, ts); } - for (SceneRenderLayer *srl = sce->r.layers.first; srl; srl = srl->next) { - writestruct(wd, DATA, SceneRenderLayer, 1, srl); - if (srl->prop) { - IDP_WriteProperty(srl->prop, wd); - } - for (FreestyleModuleConfig *fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) { - writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc); - } - for (FreestyleLineSet *fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) { - writestruct(wd, DATA, FreestyleLineSet, 1, fls); - } - } - /* writing MultiView to the blend file */ for (SceneRenderView *srv = sce->r.views.first; srv; srv = srv->next) { writestruct(wd, DATA, SceneRenderView, 1, srv); @@ -2691,13 +2666,36 @@ static void write_scene(WriteData *wd, Scene *sce) /* writing RigidBodyWorld data to the blend file */ if (sce->rigidbody_world) { + /* Set deprecated pointers to prevent crashes of older Blenders */ + sce->rigidbody_world->pointcache = sce->rigidbody_world->shared->pointcache; + sce->rigidbody_world->ptcaches = sce->rigidbody_world->shared->ptcaches; writestruct(wd, DATA, RigidBodyWorld, 1, sce->rigidbody_world); + + writestruct(wd, DATA, RigidBodyWorld_Shared, 1, sce->rigidbody_world->shared); writestruct(wd, DATA, EffectorWeights, 1, sce->rigidbody_world->effector_weights); - write_pointcaches(wd, &(sce->rigidbody_world->ptcaches)); + write_pointcaches(wd, &(sce->rigidbody_world->shared->ptcaches)); } write_previews(wd, sce->preview); write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve); + + for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { + write_view_layer(wd, view_layer); + } + + if (sce->master_collection) { + writestruct(wd, DATA, Collection, 1, sce->master_collection); + write_collection_nolib(wd, sce->master_collection); + } + + /* Eevee Lightcache */ + if (sce->eevee.light_cache && !wd->use_memfile) { + writestruct(wd, DATA, LightCache, 1, sce->eevee.light_cache); + write_lightcache(wd, sce->eevee.light_cache); + } + + /* Freed on doversion. */ + BLI_assert(sce->layer_properties == NULL); } static void write_gpencil(WriteData *wd, bGPdata *gpd) @@ -2711,6 +2709,8 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd) write_animdata(wd, gpd->adt); } + writedata(wd, DATA, sizeof(void *) * gpd->totcol, gpd->mat); + /* write grease-pencil layers to file */ writelist(wd, DATA, bGPDlayer, &gpd->layers); for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -2721,26 +2721,10 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd) writelist(wd, DATA, bGPDstroke, &gpf->strokes); for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { writestruct(wd, DATA, bGPDspoint, gps->totpoints, gps->points); + write_dverts(wd, gps->totpoints, gps->dvert); } } } - - /* write grease-pencil palettes */ - writelist(wd, DATA, bGPDpalette, &gpd->palettes); - for (bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) { - writelist(wd, DATA, bGPDpalettecolor, &palette->colors); - } - } -} - -static void write_windowmanager(WriteData *wd, wmWindowManager *wm) -{ - writestruct(wd, ID_WM, wmWindowManager, 1, wm); - write_iddata(wd, &wm->id); - - for (wmWindow *win = wm->windows.first; win; win = win->next) { - writestruct(wd, DATA, wmWindow, 1, win); - writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); } } @@ -2828,167 +2812,210 @@ static void write_soops(WriteData *wd, SpaceOops *so) } } -static void write_screen(WriteData *wd, bScreen *sc) +static void write_panel_list(WriteData *wd, ListBase *lb) { - /* write LibData */ - /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ - writestruct(wd, ID_SCRN, bScreen, 1, sc); - write_iddata(wd, &sc->id); - - /* direct data */ - for (ScrVert *sv = sc->vertbase.first; sv; sv = sv->next) { - writestruct(wd, DATA, ScrVert, 1, sv); + for (Panel *pa = lb->first; pa; pa = pa->next) { + writestruct(wd, DATA, Panel, 1, pa); + write_panel_list(wd, &pa->children); } +} - for (ScrEdge *se = sc->edgebase.first; se; se = se->next) { - writestruct(wd, DATA, ScrEdge, 1, se); - } +static void write_area_regions(WriteData *wd, ScrArea *area) +{ + for (ARegion *region = area->regionbase.first; region; region = region->next) { + write_region(wd, region, area->spacetype); + write_panel_list(wd, ®ion->panels); - for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - Panel *pa; - uiList *ui_list; - uiPreview *ui_preview; - PanelCategoryStack *pc_act; - ARegion *ar; + for (PanelCategoryStack *pc_act = region->panels_category_active.first; pc_act; pc_act = pc_act->next) { + writestruct(wd, DATA, PanelCategoryStack, 1, pc_act); + } - writestruct(wd, DATA, ScrArea, 1, sa); + for (uiList *ui_list = region->ui_lists.first; ui_list; ui_list = ui_list->next) { + write_uilist(wd, ui_list); + } - for (ar = sa->regionbase.first; ar; ar = ar->next) { - write_region(wd, ar, sa->spacetype); + for (uiPreview *ui_preview = region->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { + writestruct(wd, DATA, uiPreview, 1, ui_preview); + } + } - for (pa = ar->panels.first; pa; pa = pa->next) { - writestruct(wd, DATA, Panel, 1, pa); + for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + for (ARegion *region = sl->regionbase.first; region; region = region->next) { + write_region(wd, region, sl->spacetype); + } + + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + writestruct(wd, DATA, View3D, 1, v3d); + + if (v3d->localvd) { + writestruct(wd, DATA, View3D, 1, v3d->localvd); } - for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) { - writestruct(wd, DATA, PanelCategoryStack, 1, pc_act); + if (v3d->fx_settings.ssao) { + writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao); } + if (v3d->fx_settings.dof) { + writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof); + } + } + else if (sl->spacetype == SPACE_IPO) { + SpaceIpo *sipo = (SpaceIpo *)sl; + ListBase tmpGhosts = sipo->ghostCurves; + + /* temporarily disable ghost curves when saving */ + sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; - for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { - write_uilist(wd, ui_list); + writestruct(wd, DATA, SpaceIpo, 1, sl); + if (sipo->ads) { + writestruct(wd, DATA, bDopeSheet, 1, sipo->ads); } - for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { - writestruct(wd, DATA, uiPreview, 1, ui_preview); + /* reenable ghost curves */ + sipo->ghostCurves = tmpGhosts; + } + else if (sl->spacetype == SPACE_BUTS) { + writestruct(wd, DATA, SpaceButs, 1, sl); + } + else if (sl->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)sl; + + writestruct(wd, DATA, SpaceFile, 1, sl); + if (sfile->params) { + writestruct(wd, DATA, FileSelectParams, 1, sfile->params); } } + else if (sl->spacetype == SPACE_SEQ) { + writestruct(wd, DATA, SpaceSeq, 1, sl); + } + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *so = (SpaceOops *)sl; + write_soops(wd, so); + } + else if (sl->spacetype == SPACE_IMAGE) { + writestruct(wd, DATA, SpaceImage, 1, sl); + } + else if (sl->spacetype == SPACE_TEXT) { + writestruct(wd, DATA, SpaceText, 1, sl); + } + else if (sl->spacetype == SPACE_SCRIPT) { + SpaceScript *scr = (SpaceScript *)sl; + scr->but_refs = NULL; + writestruct(wd, DATA, SpaceScript, 1, sl); + } + else if (sl->spacetype == SPACE_ACTION) { + writestruct(wd, DATA, SpaceAction, 1, sl); + } + else if (sl->spacetype == SPACE_NLA) { + SpaceNla *snla = (SpaceNla *)sl; - for (sl = sa->spacedata.first; sl; sl = sl->next) { - for (ar = sl->regionbase.first; ar; ar = ar->next) { - write_region(wd, ar, sl->spacetype); + writestruct(wd, DATA, SpaceNla, 1, snla); + if (snla->ads) { + writestruct(wd, DATA, bDopeSheet, 1, snla->ads); } + } + else if (sl->spacetype == SPACE_NODE) { + SpaceNode *snode = (SpaceNode *)sl; + bNodeTreePath *path; + writestruct(wd, DATA, SpaceNode, 1, snode); - if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d = (View3D *)sl; - BGpic *bgpic; - writestruct(wd, DATA, View3D, 1, v3d); - for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { - writestruct(wd, DATA, BGpic, 1, bgpic); - } - if (v3d->localvd) { - writestruct(wd, DATA, View3D, 1, v3d->localvd); - } + for (path = snode->treepath.first; path; path = path->next) { + writestruct(wd, DATA, bNodeTreePath, 1, path); + } + } + else if (sl->spacetype == SPACE_CONSOLE) { + SpaceConsole *con = (SpaceConsole *)sl; + ConsoleLine *cl; - if (v3d->fx_settings.ssao) { - writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao); - } - if (v3d->fx_settings.dof) { - writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof); - } + for (cl = con->history.first; cl; cl = cl->next) { + /* 'len_alloc' is invalid on write, set from 'len' on read */ + writestruct(wd, DATA, ConsoleLine, 1, cl); + writedata(wd, DATA, cl->len + 1, cl->line); } - else if (sl->spacetype == SPACE_IPO) { - SpaceIpo *sipo = (SpaceIpo *)sl; - ListBase tmpGhosts = sipo->ghostCurves; + writestruct(wd, DATA, SpaceConsole, 1, sl); + } +#ifdef WITH_GLOBAL_AREA_WRITING + else if (sl->spacetype == SPACE_TOPBAR) { + writestruct(wd, DATA, SpaceTopBar, 1, sl); + } + else if (sl->spacetype == SPACE_STATUSBAR) { + writestruct(wd, DATA, SpaceStatusBar, 1, sl); + } +#endif + else if (sl->spacetype == SPACE_USERPREF) { + writestruct(wd, DATA, SpaceUserPref, 1, sl); + } + else if (sl->spacetype == SPACE_CLIP) { + writestruct(wd, DATA, SpaceClip, 1, sl); + } + else if (sl->spacetype == SPACE_INFO) { + writestruct(wd, DATA, SpaceInfo, 1, sl); + } + } +} - /* temporarily disable ghost curves when saving */ - sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; +static void write_area_map(WriteData *wd, ScrAreaMap *area_map) +{ + writelist(wd, DATA, ScrVert, &area_map->vertbase); + writelist(wd, DATA, ScrEdge, &area_map->edgebase); + for (ScrArea *area = area_map->areabase.first; area; area = area->next) { + area->butspacetype = area->spacetype; /* Just for compatibility, will be reset below. */ - writestruct(wd, DATA, SpaceIpo, 1, sl); - if (sipo->ads) { - writestruct(wd, DATA, bDopeSheet, 1, sipo->ads); - } + writestruct(wd, DATA, ScrArea, 1, area); - /* reenable ghost curves */ - sipo->ghostCurves = tmpGhosts; - } - else if (sl->spacetype == SPACE_BUTS) { - writestruct(wd, DATA, SpaceButs, 1, sl); - } - else if (sl->spacetype == SPACE_FILE) { - SpaceFile *sfile = (SpaceFile *)sl; +#ifdef WITH_GLOBAL_AREA_WRITING + writestruct(wd, DATA, ScrGlobalAreaData, 1, area->global); +#endif - writestruct(wd, DATA, SpaceFile, 1, sl); - if (sfile->params) { - writestruct(wd, DATA, FileSelectParams, 1, sfile->params); - } - } - else if (sl->spacetype == SPACE_SEQ) { - writestruct(wd, DATA, SpaceSeq, 1, sl); - } - else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOops *so = (SpaceOops *)sl; - write_soops(wd, so); - } - else if (sl->spacetype == SPACE_IMAGE) { - writestruct(wd, DATA, SpaceImage, 1, sl); - } - else if (sl->spacetype == SPACE_TEXT) { - writestruct(wd, DATA, SpaceText, 1, sl); - } - else if (sl->spacetype == SPACE_SCRIPT) { - SpaceScript *scr = (SpaceScript *)sl; - scr->but_refs = NULL; - writestruct(wd, DATA, SpaceScript, 1, sl); - } - else if (sl->spacetype == SPACE_ACTION) { - writestruct(wd, DATA, SpaceAction, 1, sl); - } - else if (sl->spacetype == SPACE_NLA) { - SpaceNla *snla = (SpaceNla *)sl; + write_area_regions(wd, area); - writestruct(wd, DATA, SpaceNla, 1, snla); - if (snla->ads) { - writestruct(wd, DATA, bDopeSheet, 1, snla->ads); - } - } - else if (sl->spacetype == SPACE_TIME) { - writestruct(wd, DATA, SpaceTime, 1, sl); - } - else if (sl->spacetype == SPACE_NODE) { - SpaceNode *snode = (SpaceNode *)sl; - bNodeTreePath *path; - writestruct(wd, DATA, SpaceNode, 1, snode); + area->butspacetype = SPACE_EMPTY; /* Unset again, was changed above. */ + } +} - for (path = snode->treepath.first; path; path = path->next) { - writestruct(wd, DATA, bNodeTreePath, 1, path); - } - } - else if (sl->spacetype == SPACE_LOGIC) { - writestruct(wd, DATA, SpaceLogic, 1, sl); - } - else if (sl->spacetype == SPACE_CONSOLE) { - SpaceConsole *con = (SpaceConsole *)sl; - ConsoleLine *cl; - - for (cl = con->history.first; cl; cl = cl->next) { - /* 'len_alloc' is invalid on write, set from 'len' on read */ - writestruct(wd, DATA, ConsoleLine, 1, cl); - writedata(wd, DATA, cl->len + 1, cl->line); - } - writestruct(wd, DATA, SpaceConsole, 1, sl); +static void write_windowmanager(WriteData *wd, wmWindowManager *wm) +{ + writestruct(wd, ID_WM, wmWindowManager, 1, wm); + write_iddata(wd, &wm->id); - } - else if (sl->spacetype == SPACE_USERPREF) { - writestruct(wd, DATA, SpaceUserPref, 1, sl); - } - else if (sl->spacetype == SPACE_CLIP) { - writestruct(wd, DATA, SpaceClip, 1, sl); - } - else if (sl->spacetype == SPACE_INFO) { - writestruct(wd, DATA, SpaceInfo, 1, sl); - } - } + for (wmWindow *win = wm->windows.first; win; win = win->next) { +#ifndef WITH_GLOBAL_AREA_WRITING + /* Don't write global areas yet, while we make changes to them. */ + ScrAreaMap global_areas = win->global_areas; + memset(&win->global_areas, 0, sizeof(win->global_areas)); +#endif + + /* update deprecated screen member (for so loading in 2.7x uses the correct screen) */ + win->screen = BKE_workspace_active_screen_get(win->workspace_hook); + + writestruct(wd, DATA, wmWindow, 1, win); + writestruct(wd, DATA, WorkSpaceInstanceHook, 1, win->workspace_hook); + writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); + +#ifdef WITH_GLOBAL_AREA_WRITING + write_area_map(wd, &win->global_areas); +#else + win->global_areas = global_areas; +#endif + + /* data is written, clear deprecated data again */ + win->screen = NULL; + } +} + +static void write_screen(WriteData *wd, bScreen *sc) +{ + /* Screens are reference counted, only saved if used by a workspace. */ + if (sc->id.us > 0 || wd->use_memfile) { + /* write LibData */ + /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ + writestruct(wd, ID_SCRN, bScreen, 1, sc); + write_iddata(wd, &sc->id); + + write_previews(wd, sc->preview); + + /* direct data */ + write_area_map(wd, AREAMAP_FROM_SCREEN(sc)); } } @@ -3083,17 +3110,15 @@ static void write_sound(WriteData *wd, bSound *sound) } } -static void write_group(WriteData *wd, Group *group) +static void write_probe(WriteData *wd, LightProbe *prb) { - if (group->id.us > 0 || wd->use_memfile) { + if (prb->id.us > 0 || wd->use_memfile) { /* write LibData */ - writestruct(wd, ID_GR, Group, 1, group); - write_iddata(wd, &group->id); + writestruct(wd, ID_LP, LightProbe, 1, prb); + write_iddata(wd, &prb->id); - write_previews(wd, group->preview); - - for (GroupObject *go = group->gobject.first; go; go = go->next) { - writestruct(wd, DATA, GroupObject, 1, go); + if (prb->adt) { + write_animdata(wd, prb->adt); } } } @@ -3189,6 +3214,20 @@ static void write_brush(WriteData *wd, Brush *brush) if (brush->curve) { write_curvemapping(wd, brush->curve); } + + if (brush->gpencil_settings) { + writestruct(wd, DATA, BrushGpencilSettings, 1, brush->gpencil_settings); + + if (brush->gpencil_settings->curve_sensitivity) { + write_curvemapping(wd, brush->gpencil_settings->curve_sensitivity); + } + if (brush->gpencil_settings->curve_strength) { + write_curvemapping(wd, brush->gpencil_settings->curve_strength); + } + if (brush->gpencil_settings->curve_jitter) { + write_curvemapping(wd, brush->gpencil_settings->curve_jitter); + } + } if (brush->gradient) { writestruct(wd, DATA, ColorBand, 1, brush->gradient); } @@ -3628,6 +3667,22 @@ static void write_cachefile(WriteData *wd, CacheFile *cache_file) } } +static void write_workspace(WriteData *wd, WorkSpace *workspace) +{ + ListBase *layouts = BKE_workspace_layouts_get(workspace); + + writestruct(wd, ID_WS, WorkSpace, 1, workspace); + writelist(wd, DATA, WorkSpaceLayout, layouts); + writelist(wd, DATA, WorkSpaceDataRelation, &workspace->hook_layout_relations); + writelist(wd, DATA, wmOwnerID, &workspace->owner_ids); + writelist(wd, DATA, bToolRef, &workspace->tools); + for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) { + if (tref->properties) { + IDP_WriteProperty(tref->properties, wd); + } + } +} + /* Keep it last of write_foodata functions. */ static void write_libraries(WriteData *wd, Main *main) { @@ -3659,6 +3714,8 @@ static void write_libraries(WriteData *wd, Main *main) /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the] * quit.blend and temp saves */ if (found_one) { + /* Not overridable. */ + writestruct(wd, ID_LI, Library, 1, main->curlib); write_iddata(wd, &main->curlib->id); @@ -3697,18 +3754,22 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) const bool is_undo = wd->use_memfile; FileGlobal fg; bScreen *screen; + Scene *scene; + ViewLayer *view_layer; char subvstr[8]; /* prevent mem checkers from complaining */ memset(fg.pad, 0, sizeof(fg.pad)); memset(fg.filename, 0, sizeof(fg.filename)); memset(fg.build_hash, 0, sizeof(fg.build_hash)); + fg.pad1 = NULL; - current_screen_compat(mainvar, &screen, is_undo); + current_screen_compat(mainvar, is_undo, &screen, &scene, &view_layer); /* XXX still remap G */ fg.curscreen = screen; - fg.curscene = screen ? screen->scene : NULL; + fg.curscene = scene; + fg.cur_view_layer = view_layer; /* prevent to save this, is not good convention, and feature with concerns... */ fg.fileflags = (fileflags & ~G_FILE_FLAGS_RUNTIME); @@ -3792,131 +3853,159 @@ static bool write_file_handle( * avoid thumbnail detecting changes because of this. */ mywrite_flush(wd); - ListBase *lbarray[MAX_LIBARRAY]; - int a = set_listbasepointers(mainvar, lbarray); - while (a--) { - ID *id = lbarray[a]->first; + OverrideStaticStorage *override_storage = wd->use_memfile ? NULL : BKE_override_static_operations_store_initialize(); - if (id && GS(id->name) == ID_LI) { - continue; /* Libraries are handled separately below. */ - } + /* This outer loop allows to save first datablocks from real mainvar, then the temp ones from override process, + * if needed, without duplicating whole code. */ + Main *bmain = mainvar; + do { + ListBase *lbarray[MAX_LIBARRAY]; + int a = set_listbasepointers(bmain, lbarray); + while (a--) { + ID *id = lbarray[a]->first; - for (; id; id = id->next) { - /* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */ - BLI_assert((id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0); + if (id && GS(id->name) == ID_LI) { + continue; /* Libraries are handled separately below. */ + } - switch ((ID_Type)GS(id->name)) { - case ID_WM: - write_windowmanager(wd, (wmWindowManager *)id); - break; - case ID_SCR: - write_screen(wd, (bScreen *)id); - break; - case ID_MC: - write_movieclip(wd, (MovieClip *)id); - break; - case ID_MSK: - write_mask(wd, (Mask *)id); - break; - case ID_SCE: - write_scene(wd, (Scene *)id); - break; - case ID_CU: - write_curve(wd, (Curve *)id); - break; - case ID_MB: - write_mball(wd, (MetaBall *)id); - break; - case ID_IM: - write_image(wd, (Image *)id); - break; - case ID_CA: - write_camera(wd, (Camera *)id); - break; - case ID_LA: - write_lamp(wd, (Lamp *)id); - break; - case ID_LT: - write_lattice(wd, (Lattice *)id); - break; - case ID_VF: - write_vfont(wd, (VFont *)id); - break; - case ID_KE: - write_key(wd, (Key *)id); - break; - case ID_WO: - write_world(wd, (World *)id); - break; - case ID_TXT: - write_text(wd, (Text *)id); - break; - case ID_SPK: - write_speaker(wd, (Speaker *)id); - break; - case ID_SO: - write_sound(wd, (bSound *)id); - break; - case ID_GR: - write_group(wd, (Group *)id); - break; - case ID_AR: - write_armature(wd, (bArmature *)id); - break; - case ID_AC: - write_action(wd, (bAction *)id); - break; - case ID_OB: - write_object(wd, (Object *)id); - break; - case ID_MA: - write_material(wd, (Material *)id); - break; - case ID_TE: - write_texture(wd, (Tex *)id); - break; - case ID_ME: - write_mesh(wd, (Mesh *)id); - break; - case ID_PA: - write_particlesettings(wd, (ParticleSettings *)id); - break; - case ID_NT: - write_nodetree(wd, (bNodeTree *)id); - break; - case ID_BR: - write_brush(wd, (Brush *)id); - break; - case ID_PAL: - write_palette(wd, (Palette *)id); - break; - case ID_PC: - write_paintcurve(wd, (PaintCurve *)id); - break; - case ID_GD: - write_gpencil(wd, (bGPdata *)id); - break; - case ID_LS: - write_linestyle(wd, (FreestyleLineStyle *)id); - break; - case ID_CF: - write_cachefile(wd, (CacheFile *)id); - break; - case ID_LI: - /* Do nothing, handled below - and should never be reached. */ - BLI_assert(0); - break; - case ID_IP: - /* Do nothing, deprecated. */ - break; - default: - /* Should never be reached. */ - BLI_assert(0); - break; + for (; id; id = id->next) { + /* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */ + BLI_assert((id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0); + + const bool do_override = !ELEM(override_storage, NULL, bmain) && id->override_static; + + if (do_override) { + BKE_override_static_operations_store_start(bmain, override_storage, id); + } + + switch ((ID_Type)GS(id->name)) { + case ID_WM: + write_windowmanager(wd, (wmWindowManager *)id); + break; + case ID_WS: + write_workspace(wd, (WorkSpace *)id); + break; + case ID_SCR: + write_screen(wd, (bScreen *)id); + break; + case ID_MC: + write_movieclip(wd, (MovieClip *)id); + break; + case ID_MSK: + write_mask(wd, (Mask *)id); + break; + case ID_SCE: + write_scene(wd, (Scene *)id); + break; + case ID_CU: + write_curve(wd, (Curve *)id); + break; + case ID_MB: + write_mball(wd, (MetaBall *)id); + break; + case ID_IM: + write_image(wd, (Image *)id); + break; + case ID_CA: + write_camera(wd, (Camera *)id); + break; + case ID_LA: + write_lamp(wd, (Lamp *)id); + break; + case ID_LT: + write_lattice(wd, (Lattice *)id); + break; + case ID_VF: + write_vfont(wd, (VFont *)id); + break; + case ID_KE: + write_key(wd, (Key *)id); + break; + case ID_WO: + write_world(wd, (World *)id); + break; + case ID_TXT: + write_text(wd, (Text *)id); + break; + case ID_SPK: + write_speaker(wd, (Speaker *)id); + break; + case ID_LP: + write_probe(wd, (LightProbe *)id); + break; + case ID_SO: + write_sound(wd, (bSound *)id); + break; + case ID_GR: + write_collection(wd, (Collection *)id); + break; + case ID_AR: + write_armature(wd, (bArmature *)id); + break; + case ID_AC: + write_action(wd, (bAction *)id); + break; + case ID_OB: + write_object(wd, (Object *)id); + break; + case ID_MA: + write_material(wd, (Material *)id); + break; + case ID_TE: + write_texture(wd, (Tex *)id); + break; + case ID_ME: + write_mesh(wd, (Mesh *)id); + break; + case ID_PA: + write_particlesettings(wd, (ParticleSettings *)id); + break; + case ID_NT: + write_nodetree(wd, (bNodeTree *)id); + break; + case ID_BR: + write_brush(wd, (Brush *)id); + break; + case ID_PAL: + write_palette(wd, (Palette *)id); + break; + case ID_PC: + write_paintcurve(wd, (PaintCurve *)id); + break; + case ID_GD: + write_gpencil(wd, (bGPdata *)id); + break; + case ID_LS: + write_linestyle(wd, (FreestyleLineStyle *)id); + break; + case ID_CF: + write_cachefile(wd, (CacheFile *)id); + break; + case ID_LI: + /* Do nothing, handled below - and should never be reached. */ + BLI_assert(0); + break; + case ID_IP: + /* Do nothing, deprecated. */ + break; + default: + /* Should never be reached. */ + BLI_assert(0); + break; + } + + if (do_override) { + BKE_override_static_operations_store_end(override_storage, id); + } } + + mywrite_flush(wd); } + } while ((bmain != override_storage) && (bmain = override_storage)); - mywrite_flush(wd); + if (override_storage) { + BKE_override_static_operations_store_finalize(override_storage); + override_storage = NULL; } /* Special handling, operating over split Mains... */ |