Blender V5.0
blender::asset_system::AssetLibrary Class Referenceabstract

#include <AS_asset_library.hh>

Inherited by blender::asset_system::AllAssetLibrary, blender::asset_system::OnDiskAssetLibrary, and blender::asset_system::RuntimeAssetLibrary.

Public Member Functions

 AssetLibrary (eAssetLibraryType library_type, StringRef name="", StringRef root_path="")
virtual ~AssetLibrary ()
virtual std::optional< AssetLibraryReferencelibrary_reference () const =0
void load_or_reload_catalogs ()
AssetCatalogServicecatalog_service () const
std::weak_ptr< AssetRepresentationadd_external_asset (StringRef relative_asset_path, StringRef name, int id_type, std::unique_ptr< AssetMetaData > metadata)
std::weak_ptr< AssetRepresentationadd_local_id_asset (ID &id)
bool remove_asset (AssetRepresentation &asset)
void remap_ids_and_remove_invalid (const blender::bke::id::IDRemapper &mappings)
void refresh_catalog_simplename (AssetMetaData *asset_data)
void on_blend_save_handler_register ()
void on_blend_save_handler_unregister ()
void on_blend_save_post (Main *bmain, PointerRNA **pointers, int num_pointers)
std::string resolve_asset_weak_reference_to_full_path (const AssetWeakReference &asset_reference)
eAssetLibraryType library_type () const
StringRefNull name () const
StringRefNull root_path () const

Static Public Member Functions

static void foreach_loaded (FunctionRef< void(AssetLibrary &)> fn, bool include_all_library)

Static Public Attributes

static bool save_catalogs_when_file_is_saved = true

Protected Member Functions

virtual void refresh_catalogs ()

Protected Attributes

std::unique_ptr< AssetCatalogServicecatalog_service_
Mutex catalog_service_mutex_
std::optional< eAssetImportMethodimport_method_
bool may_override_import_method_ = false
bool use_relative_path_ = true
bCallbackFuncStore on_save_callback_store_ {}

Friends

class AssetLibraryService
class AssetRepresentation

Detailed Description

AssetLibrary provides access to an asset library's data.

The asset library contains catalogs and storage for asset representations. It could be extended to also include asset indexes and more.

Definition at line 41 of file AS_asset_library.hh.

Constructor & Destructor Documentation

◆ AssetLibrary()

blender::asset_system::AssetLibrary::AssetLibrary ( eAssetLibraryType library_type,
StringRef name = "",
StringRef root_path = "" )
Parameters
nameThe name this asset library will be displayed in the UI as. Will also be used as a weak way to identify an asset library (e.g. by AssetWeakReference). Make sure this is set for any custom (not builtin) asset library. That is, ASSET_LIBRARY_CUSTOM ones.
root_pathIf this is an asset library on disk, the top-level directory path.

Definition at line 230 of file asset_library.cc.

References catalog_service_, library_type(), name(), and root_path().

Referenced by blender::asset_system::AllAssetLibrary::AllAssetLibrary(), AssetRepresentation, foreach_loaded(), blender::asset_system::OnDiskAssetLibrary::OnDiskAssetLibrary(), blender::asset_system::AllAssetLibrary::rebuild_catalogs_from_nested(), and blender::asset_system::RuntimeAssetLibrary::RuntimeAssetLibrary().

◆ ~AssetLibrary()

blender::asset_system::AssetLibrary::~AssetLibrary ( )
virtual

Member Function Documentation

◆ add_external_asset()

std::weak_ptr< AssetRepresentation > blender::asset_system::AssetLibrary::add_external_asset ( StringRef relative_asset_path,
StringRef name,
int id_type,
std::unique_ptr< AssetMetaData > metadata )

Create a representation of an asset to be considered part of this library. Once the representation is not needed anymore, it must be freed using remove_asset(), or there will be leaking that's only cleared when the library storage is destructed (typically on exit or loading a different file).

Parameters
relative_asset_pathThe path of the asset relative to the asset library root. With this the asset must be uniquely identifiable within the asset library.
Returns
A weak pointer to the new asset representation. The caller needs to keep some reference stored to be able to call remove_asset(). This would be dangling once the asset library is destructed, so a weak pointer should be used to reference it.

Definition at line 281 of file asset_library.cc.

References name().

Referenced by blender::asset_system::tests::AssetRepresentationTest::add_dummy_asset(), and filelist_readjob_list_lib_add_datablock().

◆ add_local_id_asset()

std::weak_ptr< AssetRepresentation > blender::asset_system::AssetLibrary::add_local_id_asset ( ID & id)

See #AssetLibrary::add_external_asset().

Definition at line 291 of file asset_library.cc.

Referenced by blender::asset_system::tests::AssetRepresentationTest::add_dummy_id_asset(), and filelist_readjob_main_assets_add_items().

◆ catalog_service()

AssetCatalogService & blender::asset_system::AssetLibrary::catalog_service ( ) const

Definition at line 274 of file asset_library.cc.

References catalog_service_.

Referenced by blender::ed::asset_browser::AssetCatalogTreeView::AssetCatalogTreeView(), blender::ed::sculpt_paint::brush_asset_edit_metadata_invoke(), blender::ed::sculpt_paint::brush_asset_save_as_exec(), blender::ed::sculpt_paint::brush_asset_save_as_invoke(), blender::ed::asset::build_filtered_all_catalog_tree(), blender::ed::asset::build_filtered_catalog_tree(), blender::ed::asset::catalog_add(), blender::ed::asset::shelf::catalog_filter_from_shelf_settings(), blender::ed::asset::catalog_move(), blender::ed::asset::catalog_remove(), blender::ed::asset::catalog_rename(), blender::ed::asset::catalogs_read_only(), blender::ed::asset::catalogs_save_from_asset_reference(), blender::ed::asset::catalogs_save_from_main_path(), compare_asset_catalog(), blender::ed::animrig::create_pose_asset_user_library(), blender::ed::asset_browser::file_ensure_updated_catalog_filter_data(), blender::ed::asset::get_catalog_service(), blender::ed::asset_browser::AssetCatalogDropTarget::get_drag_catalog(), blender::asset_system::AssetLibraryService::has_any_unsaved_catalogs(), blender::ed::asset::library_ensure_catalog(), blender::ed::asset::library_ensure_catalogs_in_path(), load_or_reload_catalogs(), blender::asset_system::AssetLibraryService::move_runtime_current_file_into_on_disk_library(), on_blend_save_post(), blender::asset_system::AllAssetLibrary::rebuild_catalogs_from_nested(), refresh_catalog_simplename(), blender::asset_system::OnDiskAssetLibrary::refresh_catalogs(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and blender::ed::asset::visit_library_catalogs_catalog_for_search().

◆ foreach_loaded()

void blender::asset_system::AssetLibrary::foreach_loaded ( FunctionRef< void(AssetLibrary &)> fn,
bool include_all_library )
static

Execute fn for every asset library that is loaded. The asset library is passed to the fn call.

Parameters
skip_all_libraryWhen true, the fn will also be executed for the "All" asset library. This is just a combination of the other ones, so usually iterating over it is redundant.

Definition at line 245 of file asset_library.cc.

References AssetLibrary(), AssetLibraryService, blender::asset_system::AssetLibraryService::foreach_loaded_asset_library(), and blender::asset_system::AssetLibraryService::get().

Referenced by filelist_readjob_all_asset_library(), and blender::asset_system::AllAssetLibrary::rebuild_catalogs_from_nested().

◆ library_reference()

virtual std::optional< AssetLibraryReference > blender::asset_system::AssetLibrary::library_reference ( ) const
pure virtual

◆ library_type()

◆ load_or_reload_catalogs()

void blender::asset_system::AssetLibrary::load_or_reload_catalogs ( )

◆ name()

◆ on_blend_save_handler_register()

void blender::asset_system::AssetLibrary::on_blend_save_handler_register ( )

◆ on_blend_save_handler_unregister()

void blender::asset_system::AssetLibrary::on_blend_save_handler_unregister ( )

Definition at line 377 of file asset_library.cc.

References BKE_callback_remove(), BKE_CB_EVT_SAVE_POST, and on_save_callback_store_.

Referenced by ~AssetLibrary().

◆ on_blend_save_post()

void blender::asset_system::AssetLibrary::on_blend_save_post ( Main * bmain,
PointerRNA ** pointers,
int num_pointers )

◆ refresh_catalog_simplename()

void blender::asset_system::AssetLibrary::refresh_catalog_simplename ( AssetMetaData * asset_data)

Update catalog_simple_name by looking up the asset's catalog by its ID.

No-op if the catalog cannot be found. This could be the kind of "the catalog definition file is corrupt/lost" scenario that the simple name is meant to help recover from.

Definition at line 400 of file asset_library.cc.

References BLI_uuid_is_nil(), AssetMetaData::catalog_id, catalog_service(), AssetMetaData::catalog_simple_name, blender::asset_system::AssetCatalogService::find_catalog(), blender::asset_system::AssetCatalog::simple_name, and STRNCPY().

◆ refresh_catalogs()

void blender::asset_system::AssetLibrary::refresh_catalogs ( )
protectedvirtual

Load catalogs that have changed on disk.

Reimplemented in blender::asset_system::AllAssetLibrary, and blender::asset_system::OnDiskAssetLibrary.

Definition at line 279 of file asset_library.cc.

Referenced by load_or_reload_catalogs().

◆ remap_ids_and_remove_invalid()

void blender::asset_system::AssetLibrary::remap_ids_and_remove_invalid ( const blender::bke::id::IDRemapper & mappings)

Remap ID pointers for local ID assets, see #BKE_lib_remap.hh. When an ID pointer would be mapped to null (typically when an ID gets removed), the asset is removed, because we don't support such empty/null assets.

Definition at line 314 of file asset_library.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), blender::bke::id::IDRemapper::apply(), AssetRepresentation, BLI_assert, ID_REMAP_APPLY_DEFAULT, ID_REMAP_RESULT_SOURCE_UNASSIGNED, blender::asset_system::AssetRepresentation::is_local_id(), remove_asset(), and result.

Referenced by AS_asset_library_remap_ids().

◆ remove_asset()

bool blender::asset_system::AssetLibrary::remove_asset ( AssetRepresentation & asset)

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).

Note
This is safe to call if asset is freed (dangling reference), will not perform any change then.
Returns
True on success, false if the asset couldn't be found inside the library (also the case when the reference is dangling).

Definition at line 297 of file asset_library.cc.

References AssetRepresentation, BLI_assert, and remove_asset().

Referenced by filelist_intern_entry_free(), remap_ids_and_remove_invalid(), and remove_asset().

◆ resolve_asset_weak_reference_to_full_path()

std::string blender::asset_system::AssetLibrary::resolve_asset_weak_reference_to_full_path ( const AssetWeakReference & asset_reference)

◆ root_path()

◆ AssetLibraryService

friend class AssetLibraryService
friend

◆ AssetRepresentation

friend class AssetRepresentation
friend

Member Data Documentation

◆ catalog_service_

std::unique_ptr<AssetCatalogService> blender::asset_system::AssetLibrary::catalog_service_
protected

◆ catalog_service_mutex_

Mutex blender::asset_system::AssetLibrary::catalog_service_mutex_
protected

◆ import_method_

std::optional<eAssetImportMethod> blender::asset_system::AssetLibrary::import_method_
protected

◆ may_override_import_method_

bool blender::asset_system::AssetLibrary::may_override_import_method_ = false
protected

Assets owned by this library may be imported with a different method than set in import_method_ above, it's just a default.

Definition at line 90 of file AS_asset_library.hh.

Referenced by blender::asset_system::AssetLibraryService::get_asset_library().

◆ on_save_callback_store_

bCallbackFuncStore blender::asset_system::AssetLibrary::on_save_callback_store_ {}
protected

◆ save_catalogs_when_file_is_saved

◆ use_relative_path_

bool blender::asset_system::AssetLibrary::use_relative_path_ = true
protected

The documentation for this class was generated from the following files: