diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-01-15 16:57:02 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-01-16 19:11:03 +0300 |
commit | 72ec6dbb0b3ff8a0bbec1f2f70c30450d6713ddd (patch) | |
tree | 7e48ea82355c0ef551709f8946541f159223435a /source/blender/blenkernel/intern | |
parent | 436eea2d93b4a4b6b6b9e5b3d05c5cb01f788c83 (diff) |
Static overrides API: add functions to create overrides from several datablocks at once.
This simplifies remapping task, since you don't have to ensure your
overrides are created in the correct dependency order.
Uses famous LIB_TAG_DOIT to mark IDs to be overridden.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/library_override.c | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c index a65aea4c292..8b8658921b5 100644 --- a/source/blender/blenkernel/intern/library_override.c +++ b/source/blender/blenkernel/intern/library_override.c @@ -152,12 +152,8 @@ void BKE_override_static_free(struct IDOverrideStatic **override) *override = NULL; } -/** Create an overriden local copy of linked reference. */ -ID *BKE_override_static_create_from(Main *bmain, ID *reference_id) +static ID *override_static_create_from(Main *bmain, ID *reference_id) { - BLI_assert(reference_id != NULL); - BLI_assert(reference_id->lib != NULL); - ID *local_id; if (!id_copy(bmain, reference_id, (ID **)&local_id, false)) { @@ -168,12 +164,63 @@ ID *BKE_override_static_create_from(Main *bmain, ID *reference_id) BKE_override_static_init(local_id, reference_id); local_id->flag |= LIB_OVERRIDE_STATIC_AUTO; + return local_id; +} + + +/** Create an overriden local copy of linked reference. */ +ID *BKE_override_static_create_from_id(Main *bmain, ID *reference_id) +{ + BLI_assert(reference_id != NULL); + BLI_assert(reference_id->lib != NULL); + + ID *local_id = override_static_create_from(bmain, reference_id); + /* Remapping, we obviously only want to affect local data (and not our own reference pointer to overriden ID). */ BKE_libblock_remap(bmain, reference_id, local_id, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE); return local_id; } +/** Create overriden local copies of all tagged data-blocks in given Main. + * + * \note Set id->newid of overridden libs with newly created overrides, caller is responsible to clean those pointers + * before/after usage as needed. + * + * \return \a true on success, \a false otherwise. + */ +bool BKE_override_static_create_from_tag(Main *bmain) +{ + ListBase *lbarray[MAX_LIBARRAY]; + int a; + bool ret = true; + + const int num_types = a = set_listbasepointers(bmain, lbarray); + while (a--) { + for (ID *reference_id = lbarray[a]->first; reference_id != NULL; reference_id = reference_id->next) { + if ((reference_id->tag & LIB_TAG_DOIT) != 0 && reference_id->lib != NULL) { + if ((reference_id->newid = override_static_create_from(bmain, reference_id)) == NULL) { + ret = false; + } + } + } + } + + /* Remapping, we obviously only want to affect local data (and not our own reference pointer to overriden ID). */ + a = num_types; + while (a--) { + for (ID *reference_id = lbarray[a]->first; reference_id != NULL; reference_id = reference_id->next) { + if ((reference_id->tag & LIB_TAG_DOIT) != 0 && reference_id->lib != NULL && reference_id->newid != NULL) { + ID *local_id = reference_id->newid; + BKE_libblock_remap(bmain, reference_id, local_id, + ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE); + } + } + } + + return ret; +} + /** * Find override property from given RNA path, if it exists. */ |