37using namespace blender::asset_system;
62 if (library_dirpath ==
nullptr || library_dirpath[0] ==
'\0') {
93 return preferences_lib->resolved_dirpath;
114 char r_path_buffer[ 1282],
120 std::optional<AssetLibraryService::ExplodedPath> exploded =
133 r_path_buffer[0] =
'\0';
137 BLI_assert(!exploded->group_component.is_empty());
138 BLI_assert(!exploded->name_component.is_empty());
140 BLI_strncpy(r_path_buffer, exploded->full_path->c_str(), 1282);
142 if (!exploded->dir_component.is_empty()) {
143 r_path_buffer[exploded->dir_component.size()] =
'\0';
144 r_path_buffer[exploded->dir_component.size() + 1 + exploded->group_component.size()] =
'\0';
147 *r_dir = r_path_buffer;
150 *r_group = r_path_buffer + exploded->dir_component.size() + 1;
153 *r_name = r_path_buffer + exploded->dir_component.size() + 1 +
154 exploded->group_component.size() + 1;
158 r_path_buffer[exploded->group_component.size()] =
'\0';
164 *r_group = r_path_buffer;
167 *r_name = r_path_buffer + exploded->group_component.size() + 1;
175 if (
U.experimental.no_data_block_packing) {
200 if (
U.experimental.no_data_block_packing) {
230 root_path_(std::make_shared<std::string>(
utils::resolve_directory_path(
root_path))),
245 const bool include_all_library)
300 auto catalog_service = std::make_unique<AssetCatalogService>(*root_path_);
322 std::unique_ptr<AssetMetaData>
metadata)
324 std::scoped_lock
lock{asset_storage_.external_assets_mutex};
325 return asset_storage_.external_assets.lookup_key_or_add(std::make_shared<AssetRepresentation>(
326 relative_asset_path,
name, id_type, std::move(
metadata), *
this));
333 std::unique_ptr<AssetMetaData>
metadata,
336 std::scoped_lock
lock{asset_storage_.external_assets_mutex};
337 return asset_storage_.external_assets.lookup_key_or_add(std::make_shared<AssetRepresentation>(
338 relative_asset_path,
name, id_type, std::move(
metadata), *
this, online_info));
343 std::scoped_lock
lock{asset_storage_.local_id_assets_mutex};
344 return asset_storage_.local_id_assets.lookup_key_or_add(
345 std::make_shared<AssetRepresentation>(
id, *
this));
352 if (&asset.owner_asset_library_ !=
this) {
356 std::scoped_lock
lock{asset_storage_.external_assets_mutex,
357 asset_storage_.local_id_assets_mutex};
359 BLI_assert(asset_storage_.local_id_assets.contains_as(&asset) ||
360 asset_storage_.external_assets.contains_as(&asset));
362 if (asset_storage_.local_id_assets.remove_as(&asset)) {
365 return asset_storage_.external_assets.remove_as(&asset);
373 std::scoped_lock
lock{asset_storage_.local_id_assets_mutex};
375 for (
const auto &asset_ptr : asset_storage_.local_id_assets) {
384 removed_assets.
add(&asset);
395void asset_library_on_save_post(
Main *bmain,
397 const int num_pointers,
410 on_disk_lib->catalog_service().undo_push();
465 if (catalog ==
nullptr) {
475 return library_type_;
490 return is_read_only_;
500 result.append(library_ref);
505 if (include_remote_libraries && include_online_essentials) {
509 result.append(library_ref);
512 for (
const auto [i, asset_library] :
U.asset_libraries.enumerate()) {
519 result.append(library_ref);
525 result.append(library_ref);
534 return all_library_ref;
542 return all_library_ref;
575 switch (reference.
type) {
601 switch (
library.library_type()) {
606 bool has_match =
false;
620 return library.remote_url() == remote_url;
Main runtime representation of an asset.
#define USER_EXPERIMENTAL_TEST(userdef, member)
constexpr const char * c_str() const
AssetCatalog * find_catalog(CatalogID catalog_id) const
bool write_to_disk(const CatalogFilePath &blend_file_path)
void tag_all_library_catalogs_dirty()
void foreach_loaded_asset_library(FunctionRef< void(AssetLibrary &)> fn, bool include_all_library) const
AssetLibrary * get_asset_library_on_disk_builtin(eAssetLibraryType type, StringRefNull root_path)
AssetLibrary * get_asset_library(const Main *bmain, const AssetLibraryReference &library_reference)
AssetLibrary * get_asset_library_current_file()
static bUserAssetLibrary * find_custom_asset_library_from_library_ref(const AssetLibraryReference &library_reference)
void reload_all_library_catalogs_if_dirty()
std::optional< ExplodedPath > resolve_asset_weak_reference_to_exploded_path(const AssetWeakReference &asset_reference)
static AssetLibrary * move_runtime_current_file_into_on_disk_library(const Main &bmain)
std::string resolve_asset_weak_reference_to_full_path(const AssetWeakReference &asset_reference)
static AssetLibraryService * get()
AssetLibrary * get_asset_library_on_disk_custom(StringRef name, StringRefNull root_path)
static std::string root_path_from_library_ref(const AssetLibraryReference &library_reference)
bool has_any_unsaved_catalogs() const
void on_blend_save_post(Main *bmain, PointerRNA **pointers, int num_pointers)
void load_or_reload_catalogs()
static bool save_catalogs_when_file_is_saved
eAssetLibraryType library_type() const
void on_blend_save_handler_register()
std::shared_ptr< AssetCatalogService > catalog_service_
friend class AssetLibraryService
virtual bool use_relative_paths() const
virtual const bUserAssetLibrary * user_asset_library() const
std::shared_ptr< AssetCatalogService > catalog_service_ptr() const
std::weak_ptr< AssetRepresentation > add_local_id_asset(ID &id)
friend class AssetRepresentation
virtual std::optional< StringRefNull > remote_url() 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::recursive_mutex catalog_service_mutex_
AssetLibrary(eAssetLibraryType library_type, bool is_read_only, StringRef name="", StringRef root_path="")
bool is_read_only() const
bCallbackFuncStore on_save_callback_store_
AssetCatalogService & catalog_service() const
void remap_ids_and_remove_invalid(const bke::id::IDRemapper &mappings)
static void foreach_loaded(FunctionRef< void(AssetLibrary &)> fn, bool include_all_library)
virtual std::optional< StringRefNull > auth_token() const
bool remove_asset(AssetRepresentation &asset)
void refresh_catalog_simplename(AssetMetaData *asset_data)
std::string resolve_asset_weak_reference_to_full_path(const AssetWeakReference &asset_reference)
StringRefNull name() const
StringRefNull root_path() const
virtual void refresh_catalogs()
void on_blend_save_handler_unregister()
virtual void force_remote_listing_download() const
IDRemapperApplyResult apply(ID **r_id_ptr, IDRemapperApplyOptions options, ID *id_self=nullptr) const
constexpr bool is_empty() const
std::string resolve_directory_path(StringRef directory)
AssetLibraryReference all_library_reference()
AssetLibraryReference essentials_library_reference()
AssetLibraryReference current_file_library_reference()
void all_library_reload_catalogs_if_dirty()
Vector< AssetLibraryReference > all_valid_asset_library_refs()
void all_library_tag_catalogs_dirty()
bool is_or_contains_remote_libraries(const AssetLibraryReference &reference)
bool contains_assets_from_remote_url(const AssetLibrary &library, StringRef remote_url)
AssetLibraryReference online_essentials_library_reference()
bool is_online_essentials_url(StringRef url)
@ ID_REMAP_RESULT_SOURCE_UNASSIGNED
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ USER_ASSETS_USE_ONLINE_ESSENTIALS
@ FILE_ASSET_IMPORT_APPEND_REUSE
char * STRNCPY(char(&dst)[N], const char *src)
std::string AS_asset_library_find_suitable_root_path_from_path(StringRefNull input_path)
static void update_import_method_for_asset_browsers(Main &bmain)
bool BLI_uuid_is_nil(bUUID uuid)
@ ASSET_LIBRARY_USE_REMOTE_URL
static void update_import_method_for_user_libraries()
bool AS_asset_library_has_any_unsaved_catalogs()
void AS_asset_full_path_explode_from_weak_ref(const AssetWeakReference *asset_reference, char r_path_buffer[1282], char **r_dir, char **r_group, char **r_name)
bool BKE_preferences_asset_library_is_valid(const UserDef *userdef, const struct bUserAssetLibrary *library, const bool check_directory_exists) ATTR_NONNULL()
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_ONLINE_ESSENTIALS
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
std::string AS_asset_library_resolve_path(StringRef path)
@ ASSET_IMPORT_APPEND_REUSE
std::string AS_asset_library_find_suitable_root_path_from_main(const Main *bmain)
void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt)
void AS_asset_library_import_method_ensure_valid(Main &bmain)
void AS_asset_libraries_exit()
asset_system::AssetLibrary * AS_asset_library_load(const Main *bmain, const AssetLibraryReference &library_reference)
void AS_asset_library_remap_ids(const bke::id::IDRemapper &mappings)
std::string AS_asset_library_root_path_from_library_ref(const AssetLibraryReference &library_reference)
asset_system::AssetLibrary * AS_asset_library_load_from_directory(const char *name, const char *library_dirpath)
struct bUserAssetLibrary * BKE_preferences_asset_library_containing_path(const struct UserDef *userdef, const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
eFileAssetImportMethod import_method
ListBaseT< bScreen > screens
ListBaseT< SpaceLink > spacedata
FileAssetSelectParams * asset_params
void(*) func(Main *, PointerRNA **, int pointers_num, void *arg)
ListBaseT< struct ScrArea > areabase