diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 173 |
1 files changed, 130 insertions, 43 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 79a552a5b86..d76a2fc2cd0 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -145,6 +145,7 @@ #include "BKE_multires.h" #include "BKE_node.h" // for tree type defines #include "BKE_object.h" +#include "BKE_ocean.h" #include "BKE_paint.h" #include "BKE_particle.h" #include "BKE_pointcache.h" @@ -157,6 +158,8 @@ #include "BKE_colortools.h" #include "BKE_workspace.h" +#include "DRW_engine.h" + #include "DEG_depsgraph.h" #include "NOD_common.h" @@ -1338,6 +1341,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) @@ -1525,6 +1530,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) @@ -1630,6 +1642,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; @@ -2300,6 +2343,11 @@ static void direct_link_id(FileData *fd, ID *id) 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 *************** */ @@ -2866,19 +2914,6 @@ static void direct_link_cachefile(FileData *fd, CacheFile *cache_file) /* ************ READ WORKSPACES *************** */ -static void lib_link_workspace_scene_data(FileData *fd, WorkSpace *workspace) -{ - for (WorkSpaceSceneRelation *relation = workspace->scene_layer_relations.first; - relation != NULL; - relation = relation->next) - { - relation->scene = newlibadr(fd, workspace->id.lib, relation->scene); - } - - /* Free any relations that got lost due to missing datablocks. */ - BKE_workspace_scene_relations_free_invalid(workspace); -} - static void lib_link_workspaces(FileData *fd, Main *bmain) { for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { @@ -2891,8 +2926,6 @@ static void lib_link_workspaces(FileData *fd, Main *bmain) IDP_LibLinkProperty(id->properties, fd); id_us_ensure_real(id); - lib_link_workspace_scene_data(fd, workspace); - for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) { bScreen *screen = newlibadr(fd, id->lib, BKE_workspace_layout_screen_get(layout)); @@ -2918,7 +2951,6 @@ static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main { link_list(fd, BKE_workspace_layouts_get(workspace)); link_list(fd, &workspace->hook_layout_relations); - link_list(fd, &workspace->scene_layer_relations); link_list(fd, &workspace->owner_ids); link_list(fd, &workspace->tools); @@ -3311,6 +3343,10 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) direct_link_curvemapping(fd, node->storage); else if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) ((ImageUser *)node->storage)->ok = 1; + else if (node->type==CMP_NODE_CRYPTOMATTE) { + NodeCryptomatte *nc = (NodeCryptomatte *) node->storage; + nc->matte_id = newdataadr(fd, nc->matte_id); + } } else if ( ntree->type==NTREE_TEXTURE) { if (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) @@ -5068,6 +5104,9 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) smd->domain->tex = NULL; smd->domain->tex_shadow = NULL; smd->domain->tex_flame = 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); @@ -5241,7 +5280,6 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) OceanModifierData *omd = (OceanModifierData *)md; omd->oceancache = NULL; omd->ocean = NULL; - omd->refresh = (MOD_OCEAN_REFRESH_ADD|MOD_OCEAN_REFRESH_RESET|MOD_OCEAN_REFRESH_SIM); } else if (md->type == eModifierType_Warp) { WarpModifierData *tmd = (WarpModifierData *)md; @@ -5437,7 +5475,18 @@ 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->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */ @@ -5497,7 +5546,6 @@ static void direct_link_object(FileData *fd, Object *ob) ob->derivedFinal = NULL; BKE_object_runtime_reset(ob); BLI_listbase_clear(&ob->gpulamp); - BLI_listbase_clear(&ob->drawdata); link_list(fd, &ob->pc_ids); /* Runtime curve data */ @@ -5744,6 +5792,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 @@ -6304,6 +6387,19 @@ static void direct_link_scene(FileData *fd, Scene *sce) direct_link_view_layer(fd, view_layer); } + 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); } @@ -6439,7 +6535,6 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) ar->v2d.tab_cur = 0; ar->v2d.sms = NULL; ar->v2d.alpha_hor = ar->v2d.alpha_vert = 255; /* visible by default */ - ar->v2d.size_hor = ar->v2d.size_vert = 0; BLI_listbase_clear(&ar->panels_category); BLI_listbase_clear(&ar->handlers); BLI_listbase_clear(&ar->uiblocks); @@ -6447,7 +6542,7 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) ar->visible = 0; ar->type = NULL; ar->do_draw = 0; - ar->manipulator_map = NULL; + ar->gizmo_map = NULL; ar->regiontimer = NULL; ar->draw_buffer = NULL; memset(&ar->drawrct, 0, sizeof(ar->drawrct)); @@ -6515,9 +6610,10 @@ static void direct_link_area(FileData *fd, ScrArea *area) v3d->properties_storage = 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->shading.type == OB_RENDER) { + v3d->shading.type = OB_SOLID; + } + v3d->shading.prev_type = OB_SOLID; if (v3d->fx_settings.dof) v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof); @@ -6915,16 +7011,18 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) link_list(fd, &wm->windows); for (win = wm->windows.first; win; win = win->next) { - WorkSpaceInstanceHook *hook = win->workspace_hook; + 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->gwnctx = NULL; + win->gpuctx = NULL; win->eventstate = NULL; win->cursor_keymap_status = NULL; win->tweak = NULL; @@ -7127,19 +7225,6 @@ 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); } -static void lib_link_workspace_scene_data_restore(struct IDNameLib_Map *id_map, WorkSpace *workspace) -{ - for (WorkSpaceSceneRelation *relation = workspace->scene_layer_relations.first; - relation != NULL; - relation = relation->next) - { - relation->scene = restore_pointer_by_name(id_map, &relation->scene->id, USER_IGNORE); - } - - /* Free any relations that got lost due to missing datablocks or view layers. */ - BKE_workspace_scene_relations_free_invalid(workspace); -} - static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene) { bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); @@ -7402,9 +7487,6 @@ void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain); for (WorkSpace *workspace = newmain->workspaces.first; workspace; workspace = workspace->id.next) { - lib_link_workspace_scene_data_restore(id_map, workspace); - BKE_workspace_view_layer_set(workspace, cur_view_layer, curscene); - ListBase *layouts = BKE_workspace_layouts_get(workspace); for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { @@ -7423,6 +7505,9 @@ void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene 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); /* keep cursor location through undo */ @@ -7622,6 +7707,7 @@ static void direct_link_speaker(FileData *fd, Speaker *spk) static void direct_link_sound(FileData *fd, bSound *sound) { + sound->tags = 0; sound->handle = NULL; sound->playback_handle = NULL; @@ -7633,6 +7719,7 @@ static void direct_link_sound(FileData *fd, bSound *sound) if (fd->soundmap) { sound->waveform = newsoundadr(fd, sound->waveform); + sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD; } else { sound->waveform = NULL; @@ -7643,7 +7730,7 @@ static void direct_link_sound(FileData *fd, bSound *sound) BLI_spin_init(sound->spinlock); } /* clear waveform loading flag */ - sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; + sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING; sound->packedfile = direct_link_packedfile(fd, sound->packedfile); sound->newpackedfile = direct_link_packedfile(fd, sound->newpackedfile); |