diff options
author | Bastien Montagne <bastien@blender.org> | 2020-07-09 16:33:34 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-07-09 18:56:05 +0300 |
commit | 7b1c406b5431ce65d84ddb5f2c53977c25c18373 (patch) | |
tree | d10874f81e0ca717dc288ae2071bc127c6da990a /source/blender/blenkernel/intern/lib_id.c | |
parent | 78b629a98f0c7c5c2c8f3b6b6d1081646cbe6fde (diff) |
Implement T77959: Never duplicate linked data during deep-copy.
Note that this behavior is enforced on user level for now, but on code
side it is controlled with a flag, which should make it easy to refine
that behavior if needed.
Only exception is when we duplicate a linked ID directly (then we assume
user wants a local deep-copy of that linked data, and we always also
duplicate linked sub-data-blocks).
Note that this commit also slightly refactor the handling of actions of
animdata, by simplifying `BKE_animdata_copy_id_action()` and adding an
explicit new `BKE_animdata_duplicate_id_action()` to be used during ID
duplication (deep copy).
This also allows us to get rid of the special case for liboverrides.
Diffstat (limited to 'source/blender/blenkernel/intern/lib_id.c')
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 7c09ae51344..eb440de1a6f 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -611,41 +611,39 @@ bool BKE_id_copy(Main *bmain, const ID *id, ID **newid) * Invokes the appropriate copy method for the block and returns the result in * newid, unless test. Returns true if the block can be copied. */ -ID *BKE_id_copy_for_duplicate(Main *bmain, - ID *id, - const bool is_owner_id_liboverride, - const eDupli_ID_Flags duplicate_flags) +ID *BKE_id_copy_for_duplicate(Main *bmain, ID *id, const eDupli_ID_Flags duplicate_flags) { if (id == NULL) { - return NULL; + return id; } if (id->newid == NULL) { - if (!is_owner_id_liboverride || !ID_IS_LINKED(id)) { - ID *id_new; - BKE_id_copy(bmain, id, &id_new); - /* Copying add one user by default, need to get rid of that one. */ - id_us_min(id_new); - ID_NEW_SET(id, id_new); - - /* Shape keys are always copied with their owner ID, by default. */ - ID *key_new = (ID *)BKE_key_from_id(id_new); - ID *key = (ID *)BKE_key_from_id(id); - if (key != NULL) { - ID_NEW_SET(key, key_new); - } + const bool do_linked_id = (duplicate_flags & USER_DUP_LINKED_ID) != 0; + if (!(do_linked_id || !ID_IS_LINKED(id))) { + return id; + } - /* Note: embedded data (root nodetrees and master collections) should never be referenced by - * anything else, so we do not need to set their newid pointer and flag. */ + ID *id_new; + BKE_id_copy(bmain, id, &id_new); + /* Copying add one user by default, need to get rid of that one. */ + id_us_min(id_new); + ID_NEW_SET(id, id_new); - if (duplicate_flags & USER_DUP_ACT) { - BKE_animdata_copy_id_action(bmain, id_new, true); - if (key_new != NULL) { - BKE_animdata_copy_id_action(bmain, key_new, true); - } - /* Note that actions of embedded data (root nodetrees and master collections) are handled - * by `BKE_animdata_copy_id_action` as well. */ - } + /* Shape keys are always copied with their owner ID, by default. */ + ID *key_new = (ID *)BKE_key_from_id(id_new); + ID *key = (ID *)BKE_key_from_id(id); + if (key != NULL) { + ID_NEW_SET(key, key_new); + } + + /* Note: embedded data (root nodetrees and master collections) should never be referenced by + * anything else, so we do not need to set their newid pointer and flag. */ + + BKE_animdata_duplicate_id_action(bmain, id_new, duplicate_flags); + if (key_new != NULL) { + BKE_animdata_duplicate_id_action(bmain, id_new, duplicate_flags); } + /* Note that actions of embedded data (root nodetrees and master collections) are handled + * by `BKE_animdata_duplicate_id_action` as well. */ } return id->newid; } |