From c84fee1ffeab3842d01779f1a2e5bfd826b48e60 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 17 Jun 2020 15:27:22 +0200 Subject: ID Duplicate: uniformize Action duplication. Previously, object (and sub-data) actions would be controlled by the user preferences flag, collections actions would never be duplicted, and scenes actions were always duplicated... Now they all follow the user preferences settings. --- source/blender/blenkernel/intern/anim_data.c | 2 ++ source/blender/blenkernel/intern/collection.c | 6 ++++++ source/blender/blenkernel/intern/object.c | 4 +++- source/blender/blenkernel/intern/scene.c | 25 ++++++++++++++++++++----- 4 files changed, 31 insertions(+), 6 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c index cbb34cbee30..841fdaa3b2c 100644 --- a/source/blender/blenkernel/intern/anim_data.c +++ b/source/blender/blenkernel/intern/anim_data.c @@ -399,6 +399,8 @@ void BKE_animdata_copy_id_action(Main *bmain, ID *id, const bool set_newid) if (ntree) { BKE_animdata_copy_id_action(bmain, &ntree->id, set_newid); } + /* Note that collections are not animatable currently, so no need to handle scenes' master + * collection here. */ } /* Merge copies of the data from the src AnimData into the destination AnimData */ diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 6127ad075f4..f115b9e8b7b 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -28,6 +28,7 @@ #include "BLI_threads.h" #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_collection.h" #include "BKE_icons.h" #include "BKE_idprop.h" @@ -350,6 +351,11 @@ static Collection *collection_duplicate_recursive(Main *bmain, id_us_min(&collection_new->id); ID_NEW_SET(collection_old, collection_new); + + if (duplicate_flags & USER_DUP_ACT) { + BKE_animdata_copy_id_action(bmain, &collection_new->id, true); + } + do_full_process = true; } else { diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 15cfe4a1d6a..28f7a9f12d0 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1771,7 +1771,7 @@ Object *BKE_object_duplicate(Main *bmain, } Material ***matarar; - ID *id, *id_new; + ID *id, *id_new = NULL; int a; const bool is_object_liboverride = ID_IS_OVERRIDE_LIBRARY(ob); @@ -1958,6 +1958,8 @@ Object *BKE_object_duplicate(Main *bmain, /* Check if obdata is copied. */ if (duplicated_obdata) { + BLI_assert(id_new != NULL); + Key *key = BKE_key_from_object(obn); Key *oldkey = BKE_key_from_object(ob); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 8e1800ad122..82e219e60f0 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -822,10 +822,16 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type) return sce_copy; } else { - BKE_id_copy_ex(bmain, (ID *)sce, (ID **)&sce_copy, LIB_ID_COPY_ACTIONS); + const eDupli_ID_Flags duplicate_flags = U.dupflag | USER_DUP_OBJECT; + + BKE_id_copy(bmain, (ID *)sce, (ID **)&sce_copy); id_us_min(&sce_copy->id); id_us_ensure_real(&sce_copy->id); + if (duplicate_flags & USER_DUP_ACT) { + BKE_animdata_copy_id_action(bmain, &sce_copy->id, true); + } + /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks. */ if (type == SCE_COPY_FULL) { @@ -847,9 +853,12 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type) if (is_scene_liboverride && ID_IS_LINKED(id)) { continue; } - BKE_id_copy_ex(bmain, id, &id_new, LIB_ID_COPY_ACTIONS); + BKE_id_copy(bmain, id, &id_new); 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); + } } } } @@ -858,9 +867,12 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type) id = &sce->world->id; if (id && id->newid == NULL) { if (!is_scene_liboverride || !ID_IS_LINKED(id)) { - BKE_id_copy_ex(bmain, id, &id_new, LIB_ID_COPY_ACTIONS); + BKE_id_copy(bmain, id, &id_new); 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); + } } } @@ -868,9 +880,12 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type) id = &sce->gpd->id; if (id && id->newid == NULL) { if (!is_scene_liboverride || !ID_IS_LINKED(id)) { - BKE_id_copy_ex(bmain, id, &id_new, LIB_ID_COPY_ACTIONS); + BKE_id_copy(bmain, id, &id_new); 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); + } } } @@ -879,7 +894,7 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type) BKE_collection_duplicate(bmain, NULL, sce_copy->master_collection, - USER_DUP_OBJECT | U.dupflag, + duplicate_flags, LIB_ID_DUPLICATE_IS_SUBPROCESS); if (!is_subprocess) { -- cgit v1.2.3