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

#include <AS_asset_library.hh>

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

Public Member Functions

 AssetLibrary (eAssetLibraryType library_type, bool is_read_only, StringRef name="", StringRef root_path="")
virtual ~AssetLibrary ()
virtual void force_remote_listing_download () const
virtual std::optional< AssetLibraryReference > library_reference () const =0
virtual const bUserAssetLibrary * user_asset_library () const
virtual std::optional< eAssetImportMethod > import_method () const =0
virtual bool use_relative_paths () const
virtual std::optional< StringRefNull > remote_url () const
virtual std::optional< StringRefNull > auth_token () const
AssetCatalogService & catalog_service () const
std::shared_ptr< AssetCatalogService > catalog_service_ptr () const
std::weak_ptr< AssetRepresentation > add_external_on_disk_asset (StringRef relative_asset_path, StringRef name, int id_type, std::unique_ptr< AssetMetaData > metadata)
std::weak_ptr< AssetRepresentation > add_external_online_asset (StringRef relative_asset_path, StringRef name, int id_type, std::unique_ptr< AssetMetaData > metadata, OnlineAssetInfo online_info)
std::weak_ptr< AssetRepresentation > add_local_id_asset (ID &id)
bool remove_asset (AssetRepresentation &asset)
void remap_ids_and_remove_invalid (const bke::id::IDRemapper &mappings)
void refresh_catalog_simplename (AssetMetaData *asset_data)
void load_or_reload_catalogs ()
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
bool is_read_only () 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::shared_ptr< AssetCatalogService > catalog_service_
std::recursive_mutex catalog_service_mutex_
bool may_override_import_method_ = false
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 46 of file AS_asset_library.hh.

Constructor & Destructor Documentation

◆ AssetLibrary()

blender::asset_system::AssetLibrary::AssetLibrary ( eAssetLibraryType library_type,
bool is_read_only,
StringRef name = "",
StringRef root_path = "" )
Parameters
is_read_onlyIf true, the user should not be able to edit assets or asset catalogs from this library. See is_read_only().
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 223 of file asset_library.cc.

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

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

◆ ~AssetLibrary()

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

Member Function Documentation

◆ add_external_on_disk_asset()

std::weak_ptr< AssetRepresentation > blender::asset_system::AssetLibrary::add_external_on_disk_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 318 of file asset_library.cc.

References lock, and name().

Referenced by blender::filelist_readjob_list_lib_add_datablock(), and import_method().

◆ add_external_online_asset()

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

See #AssetLibrary::add_external_on_disk_asset(). Use this for assets that are not available on disk, and part of an online asset library.

Definition at line 329 of file asset_library.cc.

References lock, and name().

Referenced by blender::filelist_readjob_list_lib_add_datablock(), and import_method().

◆ add_local_id_asset()

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

See #AssetLibrary::add_external_on_disk_asset().

Definition at line 341 of file asset_library.cc.

References lock.

Referenced by blender::filelist_readjob_main_assets_add_items(), and import_method().

◆ auth_token()

◆ catalog_service()

◆ catalog_service_ptr()

std::shared_ptr< AssetCatalogService > blender::asset_system::AssetLibrary::catalog_service_ptr ( ) const

Get shared ownership of the catalog service. Unlike catalog_service(), this keeps the service alive for as long as the returned pointer is held, even if another thread replaces the library's catalog service in the meantime (e.g. a background catalog reload job). Use this instead of catalog_service() when accessing the service from a thread that may run concurrently with such a replacement (e.g. the drawing/main thread while an asset read job is running).

Definition at line 283 of file asset_library.cc.

References catalog_service_, catalog_service_mutex_, and lock.

Referenced by import_method().

◆ force_remote_listing_download()

void blender::asset_system::AssetLibrary::force_remote_listing_download ( ) const
virtual

(Re-)download the remote listing for this library.

This only has an effect for asset libraries that are themselves a remote library, or contain one (such as the "Essentials" library if it includes online essentials, or the "All" if there are any remote libraries included).

The "Allow Online Access" option will be enforced internally, but probably some check to give a user message should be done at a higher level.

Reimplemented in blender::asset_system::AllAssetLibrary, blender::asset_system::EssentialsAssetLibrary, and blender::asset_system::RemoteAssetLibrary.

Definition at line 251 of file asset_library.cc.

Referenced by AssetRepresentation.

◆ 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 and enabled. The asset library is passed to the fn call.

Note
Libraries may note be freed during the iteration.
Parameters
include_all_libraryWhen true, 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 244 of file asset_library.cc.

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

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

◆ import_method()

◆ is_read_only()

bool blender::asset_system::AssetLibrary::is_read_only ( ) const

Check if this is a read-only library, meaning the user shouldn't be able to do edits to assets and asset catalogs from this library.

Note
This isn't enforced by the asset system - the UI or other editing code has to respect this flag. Also see #AssetCatalogService::is_read_only().

Of course it's possible to modify the .blend files containing the assets manually; and similarly, to open a .blend file in the library directory to edit asset catalogs. This function only speaks for editing directly via this library.

Definition at line 488 of file asset_library.cc.

Referenced by AssetLibrary(), AssetRepresentation, blender::ed::asset::get_user_library_ref_for_save(), import_method(), on_blend_save_post(), blender::asset_system::OnDiskAssetLibrary::OnDiskAssetLibrary(), and blender::asset_system::RemoteAssetLibrary::RemoteAssetLibrary().

◆ library_reference()

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

◆ library_type()

◆ load_or_reload_catalogs()

◆ name()

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

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

Referenced by import_method().

◆ refresh_catalogs()

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

◆ remap_ids_and_remove_invalid()

void blender::asset_system::AssetLibrary::remap_ids_and_remove_invalid ( const 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 368 of file asset_library.cc.

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

Referenced by import_method().

◆ remote_url()

std::optional< StringRefNull > blender::asset_system::AssetLibrary::remote_url ( ) const
virtual

Return the URL of the remote asset library, or #std::nullopt if this is not a remote library.

Note: don't use this as a way to distinguish remote vs. local libraries. Either query the asset itself, or use is_or_contains_remote_libraries(). The Essentials and All libraries may contain a mixture of remote and local assets.

Reimplemented in blender::asset_system::RemoteAssetLibrary.

Definition at line 266 of file asset_library.cc.

Referenced by blender::asset_system::contains_assets_from_remote_url(), blender::ED_fileselect_asset_import_method_get(), blender::filelist_readjob_all_asset_library(), blender::asset_system::AllAssetLibrary::force_remote_listing_download(), import_method(), and blender::asset_system::AllAssetLibrary::rebuild_catalogs_from_nested().

◆ remove_asset()

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

Remove an asset from the library that was added using add_external_on_disk_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 348 of file asset_library.cc.

References AssetRepresentation, blender::BLI_assert(), lock, and remove_asset().

Referenced by blender::filelist_intern_entry_free(), import_method(), 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()

◆ use_relative_paths()

bool blender::asset_system::AssetLibrary::use_relative_paths ( ) const
virtual

Reimplemented in blender::asset_system::PreferencesOnDiskAssetLibrary.

Definition at line 261 of file asset_library.cc.

Referenced by import_method().

◆ user_asset_library()

const bUserAssetLibrary * blender::asset_system::AssetLibrary::user_asset_library ( ) const
virtual

Get the bUserAssetLibrary that's backing this asset library, if there is any.

Reimplemented in blender::asset_system::PreferencesOnDiskAssetLibrary, and blender::asset_system::PreferencesRemoteAssetLibrary.

Definition at line 256 of file asset_library.cc.

Referenced by library_reference().

◆ AssetLibraryService

friend class AssetLibraryService
friend

◆ AssetRepresentation

Member Data Documentation

◆ catalog_service_

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

◆ catalog_service_mutex_

std::recursive_mutex blender::asset_system::AssetLibrary::catalog_service_mutex_
mutableprotected

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

Referenced by blender::asset_system::PreferencesRemoteAssetLibrary::PreferencesRemoteAssetLibrary(), and blender::asset_system::RemoteAssetLibrary::RemoteAssetLibrary().

◆ on_save_callback_store_

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

◆ save_catalogs_when_file_is_saved

bool blender::AssetLibrary::save_catalogs_when_file_is_saved = true
static

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