Blender V5.0
blender::asset_system::AssetLibraryService Class Reference

#include <asset_library_service.hh>

Classes

struct  ExplodedPath

Public Member Functions

 AssetLibraryService ()=default
 ~AssetLibraryService ()=default
AssetLibraryget_asset_library (const Main *bmain, const AssetLibraryReference &library_reference)
AssetLibraryget_asset_library_on_disk_custom (StringRef name, StringRefNull root_path)
AssetLibraryget_asset_library_on_disk_custom_preferences (bUserAssetLibrary *custom_library)
AssetLibraryget_asset_library_on_disk_builtin (eAssetLibraryType type, StringRefNull root_path)
AssetLibraryget_asset_library_current_file ()
AssetLibraryget_asset_library_all (const Main *bmain)
void tag_all_library_catalogs_dirty ()
void reload_all_library_catalogs_if_dirty ()
int64_t rfind_blendfile_extension (StringRef path)
std::string normalize_asset_weak_reference_relative_asset_identifier (const AssetWeakReference &asset_reference)
std::string resolve_asset_weak_reference_to_library_path (const AssetWeakReference &asset_reference)
std::string resolve_asset_weak_reference_to_full_path (const AssetWeakReference &asset_reference)
std::optional< ExplodedPathresolve_asset_weak_reference_to_exploded_path (const AssetWeakReference &asset_reference)
bool has_any_unsaved_catalogs () const
void foreach_loaded_asset_library (FunctionRef< void(AssetLibrary &)> fn, bool include_all_library) const

Static Public Member Functions

static AssetLibraryServiceget ()
static void destroy ()
static std::string root_path_from_library_ref (const AssetLibraryReference &library_reference)
static bUserAssetLibraryfind_custom_asset_library_from_library_ref (const AssetLibraryReference &library_reference)
static bUserAssetLibraryfind_custom_preferences_asset_library_from_asset_weak_ref (const AssetWeakReference &asset_reference)
static AssetLibrarymove_runtime_current_file_into_on_disk_library (const Main &bmain)

Protected Member Functions

OnDiskAssetLibrarylookup_on_disk_library (eAssetLibraryType type, StringRefNull root_path)
AssetLibraryfind_loaded_on_disk_asset_library_from_name (StringRef name) const
AssetLibraryget_asset_library_on_disk (eAssetLibraryType library_type, StringRef name, StringRefNull root_path, bool load_catalogs=true, bUserAssetLibrary *preferences_library=nullptr)
void app_handler_register ()
void app_handler_unregister ()

Static Protected Member Functions

static void allocate_service_instance ()

Detailed Description

Global singleton-ish that provides access to individual AssetLibrary instances.

Whenever a blend file is loaded, the existing instance of AssetLibraryService is destructed, and a new one is created – hence the "singleton-ish". This ensures only information about relevant asset libraries is loaded.

Note
How Asset libraries are identified may change in the future. For now they are assumed to be:
  • on disk (identified by the absolute directory), or
  • the "current file" library (which is in memory but could have catalogs loaded from a file on disk).

Definition at line 43 of file asset_library_service.hh.

Constructor & Destructor Documentation

◆ AssetLibraryService()

blender::asset_system::AssetLibraryService::AssetLibraryService ( )
default

◆ ~AssetLibraryService()

blender::asset_system::AssetLibraryService::~AssetLibraryService ( )
default

References AssetLibraryService(), and name.

Member Function Documentation

◆ allocate_service_instance()

void blender::asset_system::AssetLibraryService::allocate_service_instance ( )
staticprotected

Allocate a new instance of the service and assign it to instance_.

Definition at line 546 of file asset_library_service.cc.

References BKE_blender_atexit_register(), and destroy().

Referenced by get().

◆ app_handler_register()

void blender::asset_system::AssetLibraryService::app_handler_register ( )
protected

Ensure the AssetLibraryService instance is destroyed before a new blend file is loaded. This makes memory management simple, and ensures a fresh start for every blend file.

Definition at line 569 of file asset_library_service.cc.

References BKE_callback_add(), BKE_CB_EVT_LOAD_PRE, and blender::asset_system::on_blendfile_load().

◆ app_handler_unregister()

void blender::asset_system::AssetLibraryService::app_handler_unregister ( )
protected

Definition at line 580 of file asset_library_service.cc.

References BKE_callback_remove(), and BKE_CB_EVT_LOAD_PRE.

Referenced by destroy().

◆ destroy()

◆ find_custom_asset_library_from_library_ref()

bUserAssetLibrary * blender::asset_system::AssetLibraryService::find_custom_asset_library_from_library_ref ( const AssetLibraryReference & library_reference)
static

◆ find_custom_preferences_asset_library_from_asset_weak_ref()

bUserAssetLibrary * blender::asset_system::AssetLibraryService::find_custom_preferences_asset_library_from_asset_weak_ref ( const AssetWeakReference & asset_reference)
static

◆ find_loaded_on_disk_asset_library_from_name()

AssetLibrary * blender::asset_system::AssetLibraryService::find_loaded_on_disk_asset_library_from_name ( StringRef name) const
protected

Definition at line 332 of file asset_library_service.cc.

References name.

Referenced by resolve_asset_weak_reference_to_library_path().

◆ foreach_loaded_asset_library()

void blender::asset_system::AssetLibraryService::foreach_loaded_asset_library ( FunctionRef< void(AssetLibrary &)> fn,
bool include_all_library ) const

◆ get()

AssetLibraryService * blender::asset_system::AssetLibraryService::get ( )
static

Return the AssetLibraryService singleton, allocating it if necessary.

Definition at line 51 of file asset_library_service.cc.

References allocate_service_instance(), AssetLibraryService(), and get().

Referenced by blender::asset_system::all_library_reload_catalogs_if_dirty(), AS_asset_full_path_explode_from_weak_ref(), AS_asset_library_has_any_unsaved_catalogs(), AS_asset_library_load(), AS_asset_library_load_from_directory(), AS_asset_library_remap_ids(), blender::asset_system::AssetCatalogService::create_catalog(), blender::asset_system::AssetLibrary::foreach_loaded(), get(), blender::asset_system::tests::AssetRepresentationTest::get_builtin_library_from_type(), move_runtime_current_file_into_on_disk_library(), blender::asset_system::AssetCatalogService::prune_catalogs_by_path(), blender::asset_system::AssetCatalogService::redo(), blender::asset_system::AssetLibrary::resolve_asset_weak_reference_to_full_path(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::AssetCatalogService::undo(), and blender::asset_system::AssetCatalogService::update_catalog_path().

◆ get_asset_library()

◆ get_asset_library_all()

AssetLibrary * blender::asset_system::AssetLibraryService::get_asset_library_all ( const Main * bmain)

Get the "All" asset library, which loads all others and merges them into one.

Definition at line 282 of file asset_library_service.cc.

References blender::asset_system::all_valid_asset_library_refs(), ASSET_LIBRARY_ALL, CLOG_DEBUG, get_asset_library(), and LOG.

Referenced by get_asset_library().

◆ get_asset_library_current_file()

AssetLibrary * blender::asset_system::AssetLibraryService::get_asset_library_current_file ( )

◆ get_asset_library_on_disk()

AssetLibrary * blender::asset_system::AssetLibraryService::get_asset_library_on_disk ( eAssetLibraryType library_type,
StringRef name,
StringRefNull root_path,
bool load_catalogs = true,
bUserAssetLibrary * preferences_library = nullptr )
protected

Get the given asset library. Opens it (i.e. creates a new AssetLibrary instance) if necessary.

Parameters
root_pathThe top level directory.
preferences_libraryThe definition of the library from the Preferences. Set this to null if the library is not registered in the Preferences (but non-null if it is!).

Definition at line 119 of file asset_library_service.cc.

References ASSET_LIBRARY_CUSTOM, ASSET_LIBRARY_ESSENTIALS, blender::StringRefNull::c_str(), CLOG_DEBUG, lib, LOG, lookup_on_disk_library(), name, and blender::asset_system::utils::normalize_directory_path().

Referenced by get_asset_library_on_disk_builtin(), get_asset_library_on_disk_custom(), get_asset_library_on_disk_custom_preferences(), and move_runtime_current_file_into_on_disk_library().

◆ get_asset_library_on_disk_builtin()

AssetLibrary * blender::asset_system::AssetLibraryService::get_asset_library_on_disk_builtin ( eAssetLibraryType type,
StringRefNull root_path )

Get a builtin (not user defined) asset library. I.e. a library that is not of type ASSET_LIBRARY_CUSTOM.

Definition at line 178 of file asset_library_service.cc.

References ASSET_LIBRARY_CUSTOM, BLI_assert_msg, and get_asset_library_on_disk().

Referenced by get_asset_library().

◆ get_asset_library_on_disk_custom()

◆ get_asset_library_on_disk_custom_preferences()

AssetLibrary * blender::asset_system::AssetLibraryService::get_asset_library_on_disk_custom_preferences ( bUserAssetLibrary * custom_library)

Get an asset library of type ASSET_LIBRARY_CUSTOM from an asset library definition in the Preferences.

Definition at line 171 of file asset_library_service.cc.

References ASSET_LIBRARY_CUSTOM, bUserAssetLibrary::dirpath, get_asset_library_on_disk(), and bUserAssetLibrary::name.

Referenced by get_asset_library().

◆ has_any_unsaved_catalogs()

bool blender::asset_system::AssetLibraryService::has_any_unsaved_catalogs ( ) const

◆ lookup_on_disk_library()

OnDiskAssetLibrary * blender::asset_system::AssetLibraryService::lookup_on_disk_library ( eAssetLibraryType type,
StringRefNull root_path )
protected

◆ move_runtime_current_file_into_on_disk_library()

AssetLibrary * blender::asset_system::AssetLibraryService::move_runtime_current_file_into_on_disk_library ( const Main & bmain)
static

Turn the runtime current file library into an on-disk current file library, preserving catalog data like undo/redo history, deleted catalog info, catalog saving state, etc. Note that this creates a new on-disk asset library and destroys the runtime one.

Call when the .blend file is saved to disk.

Returns
the new on-disk current file asset library (null in case of failure to find a path to store the library in, based on the Main.filepath from main).

Definition at line 223 of file asset_library_service.cc.

References AS_asset_library_find_suitable_root_path_from_main(), ASSET_LIBRARY_LOCAL, AssetLibraryService(), BLI_assert, BLI_assert_msg, BLI_path_join, blender::StringRefNull::c_str(), blender::asset_system::AssetLibrary::catalog_service(), blender::asset_system::AssetLibrary::catalog_service_, blender::asset_system::AssetLibrary::catalog_service_mutex_, blender::asset_system::AssetCatalogService::construct_cdf_in_memory(), blender::asset_system::AssetCatalogService::DEFAULT_CATALOG_FILENAME, get(), get_asset_library_on_disk(), blender::asset_system::AssetCatalogService::get_catalog_definition_file(), lookup_on_disk_library(), PATH_MAX, and blender::asset_system::AssetLibrary::root_path().

Referenced by blender::asset_system::tests::TEST_F(), and blender::asset_system::tests::TEST_F().

◆ normalize_asset_weak_reference_relative_asset_identifier()

std::string blender::asset_system::AssetLibraryService::normalize_asset_weak_reference_relative_asset_identifier ( const AssetWeakReference & asset_reference)

◆ reload_all_library_catalogs_if_dirty()

void blender::asset_system::AssetLibraryService::reload_all_library_catalogs_if_dirty ( )

◆ resolve_asset_weak_reference_to_exploded_path()

◆ resolve_asset_weak_reference_to_full_path()

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

Attempt to build a full path to an asset based on the currently available (not necessary loaded) asset libraries. The path is not guaranteed to exist. The returned path will be normalized and using native slashes.

Note
Only works for asset libraries on disk (others can't be resolved).

Definition at line 437 of file asset_library_service.cc.

References normalize_asset_weak_reference_relative_asset_identifier(), blender::asset_system::utils::normalize_path(), AssetWeakReference::relative_asset_identifier, resolve_asset_weak_reference_to_library_path(), and SEP_STR.

Referenced by resolve_asset_weak_reference_to_exploded_path(), blender::asset_system::AssetLibrary::resolve_asset_weak_reference_to_full_path(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and blender::asset_system::tests::TEST_F().

◆ resolve_asset_weak_reference_to_library_path()

◆ rfind_blendfile_extension()

int64_t blender::asset_system::AssetLibraryService::rfind_blendfile_extension ( StringRef path)

Return the start position of the last blend-file extension in given path, or #std::string::npos if not found. Works with both kind of path separators.

Definition at line 380 of file asset_library_service.cc.

References ALTSEP_STR, blender::StringRefBase::not_found, blender::StringRefBase::rfind(), and SEP_STR.

Referenced by normalize_asset_weak_reference_relative_asset_identifier(), and resolve_asset_weak_reference_to_exploded_path().

◆ root_path_from_library_ref()

◆ tag_all_library_catalogs_dirty()

void blender::asset_system::AssetLibraryService::tag_all_library_catalogs_dirty ( )

Tag the "All" asset library as needing to reload catalogs. This should be called when catalog data of other asset libraries changes. Note that changes to the catalog definition file on disk don't ever affect this "dirty" flag. It only reflects changes from this Blender session.

Definition at line 205 of file asset_library_service.cc.

Referenced by blender::asset_system::AssetCatalogService::create_catalog(), blender::asset_system::AssetCatalogService::prune_catalogs_by_path(), blender::asset_system::AssetCatalogService::redo(), blender::asset_system::AssetCatalogService::undo(), and blender::asset_system::AssetCatalogService::update_catalog_path().


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