From baff9dd8a63819250f3421229d1716b472a30e5b Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Wed, 24 Sep 2025 09:58:30 +0200 Subject: [PATCH] VSE: Story Tools: Scene Asset behaviour: always add a new scene * If the asset was local to the file, creates a copy of it. * If the asset was from an external asset library makes sure it is appended. Design ref: #145522 Pull Request: https://projects.blender.org/blender/blender/pulls/146657 --- source/blender/editors/asset/ED_asset_import.hh | 8 +++++++- .../blender/editors/asset/intern/asset_import.cc | 16 ++++++++++++++-- .../editors/space_sequencer/sequencer_add.cc | 12 +++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/asset/ED_asset_import.hh b/source/blender/editors/asset/ED_asset_import.hh index 8c4d634aea7..4f329e5daa3 100644 --- a/source/blender/editors/asset/ED_asset_import.hh +++ b/source/blender/editors/asset/ED_asset_import.hh @@ -19,7 +19,13 @@ namespace blender::ed::asset { /** * If the asset already has a corresponding local #ID, return it. Otherwise, link or append the * asset's data-block, using "Append & Reuse" if the method is unspecified. + * + * \param import_method: Overrides library's default importing method. + * If not set and the library has no default, #ASSET_IMPORT_APPEND_REUSE will be used. */ -ID *asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetRepresentation &asset); +ID *asset_local_id_ensure_imported( + Main &bmain, + const asset_system::AssetRepresentation &asset, + const std::optional import_method = std::nullopt); } // namespace blender::ed::asset diff --git a/source/blender/editors/asset/intern/asset_import.cc b/source/blender/editors/asset/intern/asset_import.cc index a2b62d0b289..4a9380469ac 100644 --- a/source/blender/editors/asset/intern/asset_import.cc +++ b/source/blender/editors/asset/intern/asset_import.cc @@ -18,7 +18,9 @@ namespace blender::ed::asset { -ID *asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetRepresentation &asset) +ID *asset_local_id_ensure_imported(Main &bmain, + const asset_system::AssetRepresentation &asset, + const std::optional import_method) { if (ID *local_id = asset.local_id()) { return local_id; @@ -29,7 +31,17 @@ ID *asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetReprese return nullptr; } - switch (asset.get_import_method().value_or(ASSET_IMPORT_APPEND_REUSE)) { + const eAssetImportMethod method = [&]() { + if (import_method) { + return *import_method; + } + if (std::optional asset_method = asset.get_import_method()) { + return *asset_method; + } + return ASSET_IMPORT_APPEND_REUSE; + }(); + + switch (method) { case ASSET_IMPORT_LINK: return WM_file_link_datablock(&bmain, nullptr, diff --git a/source/blender/editors/space_sequencer/sequencer_add.cc b/source/blender/editors/space_sequencer/sequencer_add.cc index b40efbe2daf..33532dc75ac 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.cc +++ b/source/blender/editors/space_sequencer/sequencer_add.cc @@ -793,13 +793,23 @@ void SEQUENCER_OT_scene_strip_add_new(wmOperatorType *ot) /** \name Add Scene Strip From Scene Asset * \{ */ +/** + * Make sure the scene is always unique and ready to edit. + * If it was local it should be duplicated. If external it should be appended. + */ static Scene *sequencer_add_scene_asset(const bContext &C, const asset_system::AssetRepresentation &asset, ReportList & /*reports*/) { Main &bmain = *CTX_data_main(&C); Scene *scene_asset = reinterpret_cast( - asset::asset_local_id_ensure_imported(bmain, asset)); + asset::asset_local_id_ensure_imported(bmain, asset, ASSET_IMPORT_APPEND)); + + if (asset.is_local_id()) { + /* Local scene that needs to be duplicated. */ + Scene *scene_copy = BKE_scene_duplicate(&bmain, scene_asset, SCE_COPY_FULL); + return scene_copy; + } return scene_asset; }