diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-03-08 17:01:31 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-03-08 17:01:31 +0300 |
commit | 9e0921497912cbfe9846358d1cb1220f88315f80 (patch) | |
tree | 093e2de27514b297de63ce6ea1597401507622ab /source/blender/blenloader/intern | |
parent | cfd11af9819433c5b83359b72f002fcd59fdc1ab (diff) |
PyAPI: add bpy.types.BlendFile.temp_data for temporary library loading
This adds support for creating a `BlendFile` (internally called `Main`),
which is limited to a context.
Temporary data can now be created which can then use
`.libraries.load()` the same as with `bpy.data`.
To prevent errors caused by mixing the temporary ID's with data in
`bpy.data` they are tagged as temporary so they can't be assigned
to properties, however they can be passed as arguments to functions.
Reviewed By: mont29, sybren
Ref D10612
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 13 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_250.c | 4 |
2 files changed, 14 insertions, 3 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index aa3362aa211..de7353d827a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2424,7 +2424,9 @@ static void direct_link_id_common( id->session_uuid = MAIN_ID_SESSION_UUID_UNSET; } - BKE_lib_libblock_session_uuid_ensure(id); + if ((tag & LIB_TAG_TEMP_MAIN) == 0) { + BKE_lib_libblock_session_uuid_ensure(id); + } id->lib = current_library; id->us = ID_FAKE_USERS(id); @@ -3168,7 +3170,9 @@ static ID *create_placeholder(Main *mainvar, const short idcode, const char *idn BLI_addtail(lb, ph_id); id_sort_by_name(lb, ph_id, NULL); - BKE_lib_libblock_session_uuid_ensure(ph_id); + if ((tag & LIB_TAG_TEMP_MAIN) == 0) { + BKE_lib_libblock_session_uuid_ensure(ph_id); + } return ph_id; } @@ -4998,6 +5002,11 @@ static Main *library_link_begin( { Main *mainl; + /* Only allow specific tags to be set as extra, + * otherwise this could conflict with library loading logic. + * Other flags can be added here, as long as they are safe. */ + BLI_assert((id_tag_extra & ~LIB_TAG_TEMP_MAIN) == 0); + (*fd)->id_tag_extra = id_tag_extra; (*fd)->mainlist = MEM_callocN(sizeof(ListBase), "FileData.mainlist"); diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 983fdce15f1..467fd8b0399 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -449,7 +449,9 @@ static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name) BKE_id_new_name_validate(lb, id, name); /* alphabetic insertion: is in BKE_id_new_name_validate */ - BKE_lib_libblock_session_uuid_ensure(id); + if ((id->tag & LIB_TAG_TEMP_MAIN) == 0) { + BKE_lib_libblock_session_uuid_ensure(id); + } if (G.debug & G_DEBUG) { printf("Converted GPencil to ID: %s\n", id->name + 2); |