Blender V4.3
blender::asset_system::AssetLibrary Class Reference

#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 ()
 
void load_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 (StringRef relative_asset_path, 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_
 
std::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 40 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 165 of file asset_library.cc.

◆ ~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 202 of file asset_library.cc.

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 ( StringRef relative_asset_path,
ID & id )

◆ catalog_service()

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

Definition at line 195 of file asset_library.cc.

References catalog_service_.

Referenced by blender::ed::sculpt_paint::asset_library_ensure_catalog(), blender::ed::sculpt_paint::asset_library_ensure_catalogs_in_path(), blender::ed::asset_browser::AssetCatalogTreeView::AssetCatalogTreeView(), blender::ed::sculpt_paint::brush_asset_edit_metadata_exec(), 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_main_path(), compare_asset_catalog(), 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(), load_catalogs(), 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(), and blender::ed::sculpt_paint::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 180 of file asset_library.cc.

References 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_type()

eAssetLibraryType blender::asset_system::AssetLibrary::library_type ( ) const

Definition at line 310 of file asset_library.cc.

◆ load_catalogs()

void blender::asset_system::AssetLibrary::load_catalogs ( )

◆ name()

StringRefNull blender::asset_system::AssetLibrary::name ( ) const

Definition at line 315 of file asset_library.cc.

Referenced by compare_asset_catalog().

◆ on_blend_save_handler_register()

◆ on_blend_save_handler_unregister()

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

◆ 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 295 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 200 of file asset_library.cc.

◆ 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 227 of file asset_library.cc.

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

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 219 of file asset_library.cc.

Referenced by filelist_intern_entry_free(), and remap_ids_and_remove_invalid().

◆ 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()

Friends And Related Symbol Documentation

◆ AssetLibraryService

friend class AssetLibraryService
friend

Definition at line 100 of file AS_asset_library.hh.

◆ AssetRepresentation

friend class AssetRepresentation
friend

Definition at line 101 of file AS_asset_library.hh.

Member Data Documentation

◆ catalog_service_

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

Definition at line 83 of file AS_asset_library.hh.

Referenced by catalog_service(), and load_catalogs().

◆ catalog_service_mutex_

std::mutex blender::asset_system::AssetLibrary::catalog_service_mutex_
protected

Definition at line 84 of file AS_asset_library.hh.

Referenced by load_catalogs().

◆ import_method_

◆ 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 89 of file AS_asset_library.hh.

Referenced by blender::asset_system::AssetLibraryService::get_asset_library(), and blender::asset_system::AssetRepresentation::may_override_import_method().

◆ 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: