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
This commit is contained in:
Dalai Felinto
2025-09-24 09:58:30 +02:00
parent 1c7489b841
commit baff9dd8a6
3 changed files with 32 additions and 4 deletions

View File

@@ -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<eAssetImportMethod> import_method = std::nullopt);
} // namespace blender::ed::asset

View File

@@ -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<eAssetImportMethod> 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,

View File

@@ -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<Scene *>(
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;
}