Commit: 126136baabac679e95d578267d2b4f042dc5f9bd Author: Julian Eisel Date: Wed Nov 30 20:15:04 2022 +0100 Branches: temp-asset-library-all https://developer.blender.org/rB126136baabac679e95d578267d2b4f042dc5f9bd
Fix missing asset previews and broken drag & drop in "All" library Together with the changes made in master, all this does is making sure the assets are loaded and removed using the correct asset library nested within the "All" library. Now full paths for the assets can be built correctly from the asset identifier, which fixes preview loading and drag & drop. =================================================================== M source/blender/asset_system/AS_asset_library.hh M source/blender/asset_system/intern/asset_library.cc M source/blender/editors/space_file/filelist.cc =================================================================== diff --git a/source/blender/asset_system/AS_asset_library.hh b/source/blender/asset_system/AS_asset_library.hh index cb75a2540ff..561452d3ac8 100644 --- a/source/blender/asset_system/AS_asset_library.hh +++ b/source/blender/asset_system/AS_asset_library.hh @@ -101,6 +101,9 @@ class AssetLibrary { /** Remove an asset from the library that was added using #add_external_asset() or * #add_local_id_asset(). Can usually be expected to be constant time complexity (worst case may * differ). + * Can also be called when this asset library is just a merged library containing multiple nested + * ones ("All" library). Will then check if it exists in a nested library and remove it. + * * \note This is save to call if \a asset is freed (dangling reference), will not perform any * change then. * \return True on success, false if the asset couldn't be found inside the library (also the diff --git a/source/blender/asset_system/intern/asset_library.cc b/source/blender/asset_system/intern/asset_library.cc index 043d1a45ef2..944e91bcf4d 100644 --- a/source/blender/asset_system/intern/asset_library.cc +++ b/source/blender/asset_system/intern/asset_library.cc @@ -170,7 +170,24 @@ AssetRepresentation &AssetLibrary::add_local_id_asset(StringRef relative_asset_p bool AssetLibrary::remove_asset(AssetRepresentation &asset) { - return asset_storage_->remove_asset(asset); + /* Usual case, only the "All" library differs and uses nested libraries (see below). */ + if (asset_storage_->remove_asset(asset)) { + return true; + } + + /* If asset is not stored in this library, check nested ones (for "All" library). */ + for (AssetLibrary *library : nested_libs_) { + if (!library) { + BLI_assert_unreachable(); + continue; + } + + if (asset_storage_->remove_asset(asset)) { + return true; + } + } + + return false; } void AssetLibrary::foreach_nested(FunctionRef<void(AssetLibrary &)> fn) diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc index 5039fcdce5a..9d1191ad80e 100644 --- a/source/blender/editors/space_file/filelist.cc +++ b/source/blender/editors/space_file/filelist.cc @@ -2928,6 +2928,11 @@ struct FileListReadJob { * `Materials/Material.001`). */ char cur_relbase[FILE_MAX_LIBEXTRA]; + /** The current asset library to load. Usually the same as #FileList.asset_library, however + * sometimes the #FileList one is a combination of multiple other ones ("All" asset library), + * which need to be loaded individually. Then this can be set to override the #FileList library. + * Use this in all loading code. */ + asset_system::AssetLibrary *load_asset_library; /** Set to request a partial read that only adds files representing #Main data (IDs). Used when * #Main may have received changes of interest (e.g. asset removed or renamed). */ bool only_main_data; @@ -3105,7 +3110,6 @@ static void filelist_readjob_list_lib_add_datablock(FileListReadJob *job_params, const int idcode, const char *group_name) { - FileList *filelist = job_params->tmp_filelist; /* Use the thread-safe filelist queue. */ FileListInternEntry *entry = MEM_cnew<FileListInternEntry>(__func__); if (prefix_relpath_with_group_name) { std::string datablock_path = StringRef(group_name) + "/" + datablock_info->name; @@ -3121,13 +3125,13 @@ static void filelist_readjob_list_lib_add_datablock(FileListReadJob *job_params, if (datablock_info->asset_data) { entry->typeflag |= FILE_TYPE_ASSET; - if (filelist->asset_library) { + if (job_params->load_asset_library) { /** XXX Moving out the asset metadata like this isn't great. */ std::unique_ptr metadata = BKE_asset_metadata_move_to_unique_ptr( datablock_info->asset_data); BKE_asset_metadata_free(&datablock_info->asset_data); - entry->asset = &filelist->asset_library->add_external_asset( + entry->asset = &job_params->load_asset_library->add_external_asset( entry->relpath, datablock_info->name, std::move(metadata)); } } @@ -3631,7 +3635,7 @@ static void filelist_readjob_recursive_dir_add_items(const bool do_lib, } /* Only load assets when browsing an asset library. For normal file browsing we return all * entries. `FLF_ASSETS_ONLY` filter can be enabled/disabled by the user. */ - if (filelist->asset_library_ref) { + if (job_params->load_asset_library) { list_lib_options |= LIST_LIB_ASSETS_ONLY; } std::optional<int> lib_entries_num = filelist_readjob_list_lib( @@ -3746,6 +3750,8 @@ static void filelist_readjob_load_asset_library_data(FileListReadJob *job_params * #filelist_readjob_endjob() will move it into the real filelist. */ tmp_filelist->asset_library = AS_asset_library_load(job_params->current_main, *job_params->filelist->asset_library_ref); + /* Set asset library to load (may be overridden later for loading nested ones). */ + job_params->load_asset_library = tmp_filelist->asset_library; *do_update = true; } @@ -3783,8 +3789,8 @@ static void filelist_readjob_main_assets_add_items(FileListReadJob *job_params, entry->local_data.preview_image = BKE_asset_metadata_preview_get_from_id(id_iter->asset_data, id_iter); entry->local_data.id = id_iter; - if (filelist->asset_library) { - entry->asset = &filelist->asset_library->add_local_id_asset(entry->relpath, *id_iter); + if (job_params->load_asset_library) { + entry->asset = &job_params->load_asset_library->add_local_id_asset(entry->relpath, *id_iter); } entries_num++; BLI_addtail(&tmp_entries, entry); @@ -3902,6 +3908,8 @@ static void filelist_readjob_all_asset_library(FileListReadJob *job_params, return; } + /* Override library info to read this library. */ + job_params->load_asset_library = &nested_library; BLI_strncpy(filelist->filelist.root, root_path.c_str(), sizeof(filelist->filelist.root)); filelist_readjob_recursive_dir_add_items(true, job_params, stop, do_update, progress); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs