From 7b1c406b5431ce65d84ddb5f2c53977c25c18373 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 9 Jul 2020 15:33:34 +0200 Subject: 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. --- source/blender/blenkernel/intern/anim_data.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'source/blender/blenkernel/intern/anim_data.c') diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c index 3e2c69fbcea..61181278c60 100644 --- a/source/blender/blenkernel/intern/anim_data.c +++ b/source/blender/blenkernel/intern/anim_data.c @@ -375,17 +375,19 @@ bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag) return true; } -void BKE_animdata_copy_id_action(Main *bmain, ID *id, const bool set_newid) +static void animdata_copy_id_action(Main *bmain, + ID *id, + const bool set_newid, + const bool do_linked_id) { - const bool is_id_liboverride = ID_IS_OVERRIDE_LIBRARY(id); AnimData *adt = BKE_animdata_from_id(id); if (adt) { - if (adt->action && (!is_id_liboverride || !ID_IS_LINKED(adt->action))) { + if (adt->action && (do_linked_id || !ID_IS_LINKED(adt->action))) { id_us_min((ID *)adt->action); adt->action = set_newid ? ID_NEW_SET(adt->action, BKE_action_copy(bmain, adt->action)) : BKE_action_copy(bmain, adt->action); } - if (adt->tmpact && (!is_id_liboverride || !ID_IS_LINKED(adt->tmpact))) { + if (adt->tmpact && (do_linked_id || !ID_IS_LINKED(adt->tmpact))) { id_us_min((ID *)adt->tmpact); adt->tmpact = set_newid ? ID_NEW_SET(adt->tmpact, BKE_action_copy(bmain, adt->tmpact)) : BKE_action_copy(bmain, adt->tmpact); @@ -393,12 +395,27 @@ void BKE_animdata_copy_id_action(Main *bmain, ID *id, const bool set_newid) } bNodeTree *ntree = ntreeFromID(id); if (ntree) { - BKE_animdata_copy_id_action(bmain, &ntree->id, set_newid); + animdata_copy_id_action(bmain, &ntree->id, set_newid, do_linked_id); } /* Note that collections are not animatable currently, so no need to handle scenes' master * collection here. */ } +void BKE_animdata_copy_id_action(Main *bmain, ID *id) +{ + const bool is_id_liboverride = ID_IS_OVERRIDE_LIBRARY(id); + animdata_copy_id_action(bmain, id, false, !is_id_liboverride); +} + +void BKE_animdata_duplicate_id_action(struct Main *bmain, + struct ID *id, + const eDupli_ID_Flags duplicate_flags) +{ + if (duplicate_flags & USER_DUP_ACT) { + animdata_copy_id_action(bmain, id, true, (duplicate_flags & USER_DUP_LINKED_ID) != 0); + } +} + /* Merge copies of the data from the src AnimData into the destination AnimData */ void BKE_animdata_merge_copy( Main *bmain, ID *dst_id, ID *src_id, eAnimData_MergeCopy_Modes action_mode, bool fix_drivers) -- cgit v1.2.3