diff options
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 38 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 8 |
2 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f3b92b1f6a4..d7c8dbabcea 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -108,11 +108,14 @@ #include "BLI_mempool.h" #include "BLI_threads.h" +#include "RNA_types.h" + #include "BLT_translation.h" #include "BKE_action.h" #include "BKE_anim_data.h" #include "BKE_armature.h" +#include "BKE_asset_engine.h" #include "BKE_brush.h" #include "BKE_collection.h" #include "BKE_colortools.h" @@ -2874,6 +2877,12 @@ static void direct_link_id_common( BLI_listbase_clear((ListBase *)drawdata); } + if (id->uuid) { + BLO_read_data_address(reader, &id->uuid); + /* Make sure runtime fields are always zeroed out. */ + BKE_asset_uuid_runtime_reset(id->uuid); + } + /* Handle 'private IDs'. */ direct_link_id_embedded_id(reader, current_library, id, id_old); } @@ -9735,6 +9744,18 @@ static BHead *read_libblock(FileData *fd, } } + if (id->uuid) { + /* Read all data into fd->datamap. */ + bhead = read_data_into_datamap(fd, bhead, __func__); + + id->uuid = newdataadr(fd, id->uuid); + /* Make sure runtime fields are always zeroed out. */ + BKE_asset_uuid_runtime_reset(id->uuid); + + oldnewmap_clear(fd->datamap); + return bhead; + } + direct_link_id(fd, main, id_tag, id, id_old); return blo_bhead_next(fd, bhead); } @@ -12349,6 +12370,21 @@ static void read_library_linked_ids(FileData *basefd, * (known case: some directly linked shapekey from a missing lib...). */ /* BLI_assert(*realid != NULL); */ + if (*realid && id->uuid) { + /* it is important to keep the UUID we stored in that .blend file, not the (potentially + * different) one we get from the library, updating UUID should be handled by asset + * engine later - even though changing UUID is not recommended in any case. */ + if ((*realid)->uuid != NULL) { + MEM_SAFE_FREE((*realid)->uuid); + } + /* We can give ownership of that pointer to new ID. */ + (*realid)->uuid = id->uuid; + id->uuid = NULL; + } + else { + MEM_SAFE_FREE(id->uuid); + } + /* Now that we have a real ID, replace all pointers to placeholders in * fd->libmap with pointers to the real data-blocks. We do this for all * libraries since multiple might be referencing this ID. */ @@ -12363,6 +12399,8 @@ static void read_library_linked_ids(FileData *basefd, /* Clear GHash and free link placeholder IDs of the current type. */ BLI_ghash_clear(loaded_ids, NULL, NULL); + /* Note: this is currently just freeing ID struct itself, assuming there is no remaining + * allocated sub-data owned by this ID. */ BLI_freelistN(&pending_free_ids); } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 2cc6cecd815..e24ce5f3a77 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -736,6 +736,9 @@ static void write_iddata(BlendWriter *writer, ID *id) if (id->properties && !ELEM(GS(id->name), ID_WM)) { IDP_WriteProperty(id->properties, writer); } + if (id->uuid) { + BLO_write_struct(writer, AssetUUID, id->uuid); + } if (id->override_library) { BLO_write_struct(writer, IDOverrideLibrary, id->override_library); @@ -4012,6 +4015,11 @@ static void write_libraries(WriteData *wd, Main *main) BLI_assert(0); } writestruct(wd, ID_LINK_PLACEHOLDER, ID, 1, id); + /* It is mandatory to write id's asset uuid reference for placeholders too, otherwise + * the whole asset info would be completely lost when reloading the linked data-block, + * especially in case it is not immediately found and needs to go through the whole + * 'asset engine update' process after main .blend read process is finished. */ + write_iddata(&writer, id); } } } |