Blender V5.3
asset_library_service.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <memory>
10
11#include "BKE_blender.hh"
12#include "BKE_preferences.h"
13
14#include "BLI_fileops.hh" // IWYU pragma: keep
15#include "BLI_path_utils.hh"
16#include "BLI_string_ref.hh"
17#include "BLI_vector.hh"
18
19#include "DNA_asset_types.h"
20#include "DNA_userdef_types.h"
21
22#include "CLG_log.h"
23
24#include "AS_asset_library.hh"
26#include "all_library.hh"
28#include "asset_catalog_definition_file.hh" // IWYU pragma: keep
30#include "essentials_library.hh"
31#include "on_disk_library.hh"
33#include "remote_library.hh"
34#include "runtime_library.hh"
35#include "utils.hh"
36
37namespace blender {
38
39/* When enabled, use a pre file load handler (#BKE_CB_EVT_LOAD_PRE) callback to destroy the asset
40 * library service. Without this an explicit call from the file loading code is needed to do this,
41 * which is not as nice.
42 *
43 * TODO Currently disabled because UI data depends on asset library data, so we have to make sure
44 * it's freed in the right order (UI first). Pre-load handlers don't give us this order.
45 * Should be addressed with a proper ownership model for the asset system:
46 * https://developer.blender.org/docs/features/asset_system/backend/#ownership-model
47 */
48// #define WITH_DESTROY_VIA_LOAD_HANDLER
49
50static CLG_LogRef LOG = {"asset.library"};
51
52namespace asset_system {
53
54std::unique_ptr<AssetLibraryService> AssetLibraryService::instance_;
55bool AssetLibraryService::atexit_handler_registered_ = false;
56
58{
59 if (!instance_) {
61 }
62 return instance_.get();
63}
64
66{
67 if (!instance_) {
68 return;
69 }
70 instance_->app_handler_unregister();
71 instance_.reset();
72}
73
75 const Main *bmain, const AssetLibraryReference &library_reference)
76{
77 const eAssetLibraryType type = eAssetLibraryType(library_reference.type);
78
79 switch (type) {
81 const StringRefNull root_path = essentials_directory_path();
82 if (root_path.is_empty()) {
83 return nullptr;
84 }
85
86 return this->get_asset_library_on_disk_builtin(type, root_path);
87 }
90 }
92 /* For the "Current File" library we get the asset library root path based on main. */
93 std::string root_path = bmain ? AS_asset_library_find_suitable_root_path_from_main(bmain) :
94 "";
95
96 if (root_path.empty()) {
97 /* File wasn't saved yet. */
98 return this->get_asset_library_current_file();
99 }
100 return this->get_asset_library_on_disk_builtin(type, root_path);
101 }
103 return this->get_asset_library_all(bmain);
106 library_reference);
107 if (!custom_library) {
108 return nullptr;
109 }
110
111 if (custom_library->flag & ASSET_LIBRARY_USE_REMOTE_URL) {
112 if (is_online_essentials_url(custom_library->remote_url)) {
114 }
115 return this->get_preferences_remote_asset_library(*custom_library);
116 }
117
118 std::string root_path = custom_library->resolved_dirpath;
119 if (root_path.empty()) {
120 return nullptr;
121 }
122
124 library->may_override_import_method_ = true;
125
126 return library;
127 }
128 }
129
130 return nullptr;
131}
132
134{
135 if (online_essentials_library_) {
136 CLOG_DEBUG(&LOG, "get online essentials lib (cached)");
137 online_essentials_library_->load_or_reload_catalogs();
138 }
139 else {
140 CLOG_DEBUG(&LOG, "get online essentials lib (loaded)");
141 online_essentials_library_ = std::make_unique<OnlineEssentialsLibrary>();
142 }
143
144 AssetLibrary *lib = online_essentials_library_.get();
145 return lib;
146}
147
149 const bUserAssetLibrary &custom_library)
150{
151 if (!custom_library.remote_url[0]) {
152 return nullptr;
153 }
154
155 const StringRefNull remote_url = custom_library.remote_url;
156
157 /* Lock for the entire "lookup and if not found -> create and insert" scope, so no two threads do
158 * this in parallel and interfere with each other. */
159 std::scoped_lock lock{remote_libraries_mutex_};
160
161 std::unique_ptr<PreferencesRemoteAssetLibrary> *lib_uptr_ptr = remote_libraries_.lookup_ptr(
162 remote_url);
163 if (lib_uptr_ptr != nullptr) {
164 CLOG_DEBUG(&LOG, "get \"%s\" (cached)", remote_url.c_str());
165 AssetLibrary *lib = lib_uptr_ptr->get();
167 return lib;
168 }
169
170 std::unique_ptr<PreferencesRemoteAssetLibrary> lib_uptr =
171 std::make_unique<PreferencesRemoteAssetLibrary>(custom_library);
172 AssetLibrary *lib = lib_uptr.get();
174
175 remote_libraries_.add_new(remote_url, std::move(lib_uptr));
176 CLOG_DEBUG(&LOG, "get \"%s\" (loaded)", remote_url.c_str());
177 return lib;
178}
179
181 eAssetLibraryType library_type,
182 StringRef name,
183 StringRefNull root_path,
184 const bool load_catalogs,
185 bUserAssetLibrary *preferences_library)
186{
187 /* Lock for the entire "lookup and if not found -> create and insert" scope, so no two threads do
188 * this in parallel and interfere with each other. */
189 std::scoped_lock lock{on_disk_libraries_mutex_};
190
191 const std::string resolved_root_path = utils::resolve_directory_path(root_path);
192 if (OnDiskAssetLibrary *lib = this->lookup_on_disk_library(library_type, resolved_root_path)) {
193 CLOG_DEBUG(&LOG, "get \"%s\" (cached)", resolved_root_path.c_str());
194 if (load_catalogs) {
195 lib->load_or_reload_catalogs();
196 }
197 return lib;
198 }
199
200 std::unique_ptr<OnDiskAssetLibrary> lib_uptr;
201 switch (library_type) {
203 if (preferences_library) {
204 lib_uptr = std::make_unique<PreferencesOnDiskAssetLibrary>(*preferences_library);
205 }
206 else {
207 /* Only used by unit tests. */
208 lib_uptr = std::make_unique<OnDiskAssetLibrary>(
209 library_type, name, resolved_root_path, /*is_read_only=*/false);
210 }
211 break;
213 lib_uptr = std::make_unique<EssentialsAssetLibrary>();
214 break;
216 lib_uptr = std::make_unique<OnDiskAssetLibrary>(
217 library_type, name, resolved_root_path, /*is_read_only=*/false);
218 break;
219 default:
220 lib_uptr = std::make_unique<OnDiskAssetLibrary>(
221 library_type, name, resolved_root_path, /*is_read_only=*/true);
222 break;
223 }
224
225 /* Get underlying pointer before moving. */
226 AssetLibrary *lib = lib_uptr.get();
227 on_disk_libraries_.add_new({library_type, resolved_root_path}, std::move(lib_uptr));
228 CLOG_DEBUG(&LOG, "get \"%s\" (loaded)", resolved_root_path.c_str());
229
230 if (load_catalogs) {
232 }
233
234 return lib;
235}
236
242
244 bUserAssetLibrary *custom_library)
245{
247 custom_library->name,
248 custom_library->resolved_dirpath,
249 true,
250 custom_library);
251}
252
254 StringRefNull root_path)
255{
257 type != ASSET_LIBRARY_CUSTOM,
258 "Use `get_asset_library_on_disk_custom()` for libraries of type `ASSET_LIBRARY_CUSTOM`");
259
260 /* Builtin asset libraries don't need a name, the #eAssetLibraryType is enough to identify them
261 * (and doesn't change, unlike the name). */
262 return this->get_asset_library_on_disk(type, {}, root_path);
263}
264
266{
267 if (current_file_library_) {
268 CLOG_DEBUG(&LOG, "get current file lib (cached)");
269 current_file_library_->refresh_catalogs();
270 }
271 else {
272 CLOG_DEBUG(&LOG, "get current file lib (loaded)");
273 current_file_library_ = std::make_unique<RuntimeAssetLibrary>();
274 }
275
276 AssetLibrary *lib = current_file_library_.get();
277 return lib;
278}
279
281{
282 if (all_library_) {
283 all_library_->tag_catalogs_dirty();
284 }
285}
286
288{
289 if (all_library_ && all_library_->is_catalogs_dirty()) {
290 /* Don't reload catalogs from nested libraries from disk, just reflect their currently known
291 * state in the "All" library. Loading catalog changes from disk is only done with a
292 * #AS_asset_library_load()/#AssetLibraryService:get_asset_library() call. */
293 const bool reload_nested_catalogs = false;
294 all_library_->rebuild_catalogs_from_nested(reload_nested_catalogs);
295 }
296}
297
299 const Main &bmain)
300{
301 AssetLibraryService &library_service = *AssetLibraryService::get();
302
303 const std::string root_path = AS_asset_library_find_suitable_root_path_from_main(&bmain);
304 if (root_path.empty()) {
305 return nullptr;
306 }
307
308#ifndef NDEBUG
309 {
310 std::scoped_lock lock{library_service.on_disk_libraries_mutex_};
311 BLI_assert_msg(!library_service.lookup_on_disk_library(ASSET_LIBRARY_LOCAL, root_path),
312 "On-disk \"Current File\" asset library shouldn't exist yet, it should only be "
313 "created now in response to initially saving the file - catalog service "
314 "will be overridden");
315 }
316#endif
317
318 /* Create on disk library without loading catalogs. We'll steal the catalog service from the
319 * runtime library below. */
320 AssetLibrary *on_disk_library = library_service.get_asset_library_on_disk(
322 {},
323 root_path,
324 /*load_catalogs=*/false);
325
326 {
327 /* These should always be completely separate, just sanity check since it would cause a
328 * deadlock below. */
329 BLI_assert(on_disk_library != library_service.current_file_library_.get());
330
331 std::lock_guard lock_on_disk{on_disk_library->catalog_service_mutex_};
332 std::lock_guard lock_runtime{library_service.current_file_library_->catalog_service_mutex_};
333 on_disk_library->catalog_service_.swap(
334 library_service.current_file_library_->catalog_service_);
335 }
336
337 AssetCatalogService &catalog_service = on_disk_library->catalog_service();
338 catalog_service.asset_library_root_ = on_disk_library->root_path();
339 /* The catalogs are not stored on disk, so there should not be any CDF. Otherwise, we'd have to
340 * remap their stored file-path too (#AssetCatalogDefinitionFile.file_path). */
341 BLI_assert_msg(catalog_service.get_catalog_definition_file() == nullptr,
342 "new on-disk library shouldn't have catalog definition files - root path "
343 "changed, so they would have to be relocated");
344
345 /* Create a CDF with the runtime catalogs that on-disk catalogs can be merged into. Only do if
346 * there's catalogs to write, otherwise we create empty CDFs on disk on every new .blend save. */
347 if (!catalog_service.catalog_collection_->is_empty()) {
348 char asset_lib_cdf_path[PATH_MAX];
349 BLI_path_join(asset_lib_cdf_path,
350 sizeof(asset_lib_cdf_path),
351 on_disk_library->root_path().c_str(),
353 catalog_service.catalog_collection_->catalog_definition_file_ =
354 catalog_service.construct_cdf_in_memory(asset_lib_cdf_path);
355 }
356
357 library_service.current_file_library_ = nullptr;
358
359 return on_disk_library;
360}
361
363{
364 /* (Re-)load all other asset libraries. */
366 /* Skip self :) */
367 if (library_ref.type == ASSET_LIBRARY_ALL) {
368 continue;
369 }
370
371 /* Ensure all asset libraries are loaded. */
372 this->get_asset_library(bmain, library_ref);
373 }
374
375 if (!all_library_) {
376 CLOG_DEBUG(&LOG, "get all lib (loaded)");
377 all_library_ = std::make_unique<AllAssetLibrary>();
378 }
379 else {
380 CLOG_DEBUG(&LOG, "get all lib (cached)");
381 }
382
383 /* Don't reload catalogs, they've just been loaded above. */
384 all_library_->rebuild_catalogs_from_nested(/*reload_nested_catalogs=*/false);
385
386 return all_library_.get();
387}
388
390 StringRefNull root_path)
391{
392 BLI_assert_msg(!root_path.is_empty(),
393 "top level directory must be given for on-disk asset library");
394
395 std::string resolved_root_path = utils::resolve_directory_path(root_path);
396
397 std::scoped_lock lock{on_disk_libraries_mutex_};
398 std::unique_ptr<OnDiskAssetLibrary> *lib_uptr_ptr = on_disk_libraries_.lookup_ptr(
399 {library_type, resolved_root_path});
400 return lib_uptr_ptr ? lib_uptr_ptr->get() : nullptr;
401}
402
412
414 StringRef name) const
415{
416 std::scoped_lock lock{on_disk_libraries_mutex_};
417 for (const std::unique_ptr<OnDiskAssetLibrary> &library : on_disk_libraries_.values()) {
418 if (library->name_ == name) {
419 return library.get();
420 }
421 }
422 return nullptr;
423}
424
426 const AssetWeakReference &asset_reference)
427{
428 StringRefNull library_dirpath;
429
430 switch (eAssetLibraryType(asset_reference.asset_library_type)) {
433 asset_reference);
434 if (custom_lib) {
435 library_dirpath = custom_lib->resolved_dirpath;
436 break;
437 }
438
439 /* A bit of an odd-ball, the API supports loading custom libraries from arbitrary paths (used
440 * by unit tests). So check all loaded on-disk libraries too. */
442 asset_reference.asset_library_identifier);
443 if (!loaded_custom_lib) {
444 return "";
445 }
446
447 library_dirpath = *loaded_custom_lib->root_path_;
448 break;
449 }
451 library_dirpath = essentials_directory_path();
452 break;
454 library_dirpath = online_essentials_cache_directory_path();
455 break;
458 return "";
459 }
460
461 std::string normalized_library_dirpath = utils::resolve_path(library_dirpath);
462 return normalized_library_dirpath;
463}
464
466{
467 const std::vector<StringRefNull> blendfile_extensions = {".blend" SEP_STR,
468 ".blend.gz" SEP_STR,
469 ".ble" SEP_STR,
470 ".blend" ALTSEP_STR,
471 ".blend.gz" ALTSEP_STR,
472 ".ble" ALTSEP_STR};
473 int64_t blendfile_extension_pos = StringRef::not_found;
474
475 for (StringRefNull blendfile_ext : blendfile_extensions) {
476 const int64_t iter_ext_pos = path.rfind(blendfile_ext);
477 if (iter_ext_pos == StringRef::not_found) {
478 continue;
479 }
480
481 if ((blendfile_extension_pos == StringRef::not_found) ||
482 (blendfile_extension_pos < iter_ext_pos))
483 {
484 blendfile_extension_pos = iter_ext_pos;
485 }
486 }
487
488 return blendfile_extension_pos;
489}
490
492 const AssetWeakReference &asset_reference)
493{
494 StringRefNull relative_asset_identifier = asset_reference.relative_asset_identifier;
495
496 int64_t blend_ext_pos = rfind_blendfile_extension(asset_reference.relative_asset_identifier);
497 const bool has_blend_ext = blend_ext_pos != StringRef::not_found;
498
499 int64_t blend_path_len = 0;
500 /* Get the position of the path separator after the blend file extension. */
501 if (has_blend_ext) {
502 blend_path_len = relative_asset_identifier.find_first_of(SEP_STR ALTSEP_STR, blend_ext_pos);
503
504 /* If there is a blend file in the relative asset path, then there should be group and id name
505 * after it. */
506 BLI_assert(blend_path_len != StringRef::not_found);
507 /* Skip slash. */
508 blend_path_len += 1;
509 }
510
511 /* Find the first path separator (after the blend file extension if any). This will be the one
512 * separating the group from the name. */
513 const int64_t group_name_sep_pos = relative_asset_identifier.find_first_of(SEP_STR ALTSEP_STR,
514 blend_path_len);
515
516 return utils::resolve_path(relative_asset_identifier,
517 (group_name_sep_pos == StringRef::not_found) ?
519 group_name_sep_pos + 1);
520}
521
523 const AssetWeakReference &asset_reference)
524{
525 /* TODO currently only works for asset libraries on disk (custom or essentials asset libraries).
526 * Once there is a proper registry of asset libraries, this could contain an asset library
527 * locator and/or identifier, so a full path (not necessarily file path) can be built for all
528 * asset libraries. */
529
530 if (asset_reference.relative_asset_identifier[0] == '\0') {
531 return "";
532 }
533
534 std::string library_dirpath = resolve_asset_weak_reference_to_library_path(asset_reference);
535 if (library_dirpath.empty()) {
536 return "";
537 }
538
539 std::string normalized_full_path = utils::resolve_path(library_dirpath + SEP_STR) +
541 asset_reference);
542
543 return normalized_full_path;
544}
545
546std::optional<AssetLibraryService::ExplodedPath> AssetLibraryService::
548{
549 if (asset_reference.relative_asset_identifier[0] == '\0') {
550 return std::nullopt;
551 }
552
553 switch (eAssetLibraryType(asset_reference.asset_library_type)) {
554 case ASSET_LIBRARY_LOCAL: {
555 std::string path_in_file = this->normalize_asset_weak_reference_relative_asset_identifier(
556 asset_reference);
557 const int64_t group_len = int64_t(path_in_file.find(SEP));
558
559 ExplodedPath exploded;
560 exploded.full_path = std::make_unique<std::string>(path_in_file);
561 exploded.group_component = StringRef(*exploded.full_path).substr(0, group_len);
562 exploded.name_component = StringRef(*exploded.full_path).substr(group_len + 1);
563
564 return exploded;
565 }
569 std::string full_path = this->resolve_asset_weak_reference_to_full_path(asset_reference);
570 /* #full_path uses native slashes, so others don't need to be considered in the following. */
571
572 if (full_path.empty()) {
573 return std::nullopt;
574 }
575
576 int64_t blendfile_extension_pos = this->rfind_blendfile_extension(full_path);
577 BLI_assert(blendfile_extension_pos != StringRef::not_found);
578
579 size_t group_pos = full_path.find(SEP, blendfile_extension_pos);
580 BLI_assert(group_pos != std::string::npos);
581
582 size_t name_pos = full_path.find(SEP, group_pos + 1);
583 BLI_assert(group_pos != std::string::npos);
584
585 const int64_t dir_len = int64_t(group_pos);
586 const int64_t group_len = int64_t(name_pos - group_pos - 1);
587
588 ExplodedPath exploded;
589 exploded.full_path = std::make_unique<std::string>(full_path);
590 StringRef full_path_ref = *exploded.full_path;
591 exploded.dir_component = full_path_ref.substr(0, dir_len);
592 exploded.group_component = full_path_ref.substr(dir_len + 1, group_len);
593 exploded.name_component = full_path_ref.substr(dir_len + 1 + group_len + 1);
594
595 return exploded;
596 }
598 return std::nullopt;
599 }
600
601 return std::nullopt;
602}
603
612
614 const AssetLibraryReference &library_reference)
615{
616 if (ELEM(library_reference.type, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL)) {
617 return "";
618 }
619 if (ELEM(library_reference.type, ASSET_LIBRARY_ESSENTIALS)) {
621 }
622 if (library_reference.type == ASSET_LIBRARY_ONLINE_ESSENTIALS) {
624 }
625
627 library_reference);
628 if (!custom_library || !custom_library->resolved_dirpath[0]) {
629 return "";
630 }
631
632 return custom_library->resolved_dirpath;
633}
634
636{
637 instance_ = std::make_unique<AssetLibraryService>();
638 instance_->app_handler_register();
639
640 if (!atexit_handler_registered_) {
641 /* Ensure the instance gets freed before Blender's memory leak detector runs. */
642 BKE_blender_atexit_register([](void * /*user_data*/) { AssetLibraryService::destroy(); },
643 nullptr);
644 atexit_handler_registered_ = true;
645 }
646}
647
648static void on_blendfile_load(Main * /*bmain*/,
649 PointerRNA ** /*pointers*/,
650 const int /*num_pointers*/,
651 void * /*arg*/)
652{
653#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
655#endif
656}
657
659{
660 /* The callback system doesn't own `on_load_callback_store_`. */
661 on_load_callback_store_.alloc = false;
662
663 on_load_callback_store_.func = &on_blendfile_load;
664 on_load_callback_store_.arg = this;
665
666 BKE_callback_add(&on_load_callback_store_, BKE_CB_EVT_LOAD_PRE);
667}
668
670{
671 BKE_callback_remove(&on_load_callback_store_, BKE_CB_EVT_LOAD_PRE);
672 on_load_callback_store_.func = nullptr;
673 on_load_callback_store_.arg = nullptr;
674}
675
677{
678 bool has_unsaved_changes = false;
679
681 [&has_unsaved_changes](AssetLibrary &library) {
682 if (library.catalog_service().has_unsaved_changes()) {
683 has_unsaved_changes = true;
684 }
685 },
686 true);
687 return has_unsaved_changes;
688}
689
691 const bool include_all_library) const
692{
693 /* Collect the libraries to visit first, then invoke the callback without holding any of the
694 * library mutexes. The callback may re-enter the asset library service, e.g. the "All" library
695 * reading triggers a catalog rebuild, which itself calls #foreach_loaded() - so running it while
696 * holding these mutexes can deadlock.
697 *
698 * Holding on to the raw pointers is safe as long as loaded libraries are not freed concurrently.
699 */
701
702 if (include_all_library && all_library_) {
703 libraries.append(all_library_.get());
704 }
705
706 if (current_file_library_) {
707 libraries.append(current_file_library_.get());
708 }
709
710 {
711 std::scoped_lock lock{on_disk_libraries_mutex_};
712 /* Do essentials library first. Plenty of general features use the essentials, these features
713 * should be available as soon as possible. Not only after other, potentially big libraries are
714 * loaded. */
715 for (const auto &asset_lib_uptr : on_disk_libraries_.values()) {
716 if (asset_lib_uptr->library_type() != ASSET_LIBRARY_ESSENTIALS) {
717 continue;
718 }
719
720 if (asset_lib_uptr->is_enabled()) {
721 libraries.append(asset_lib_uptr.get());
722 }
723 break;
724 }
725 }
726
727 const bool include_remote_libraries = USER_EXPERIMENTAL_TEST(&U, use_remote_asset_libraries);
728
729 if (include_remote_libraries && online_essentials_library_ &&
731 {
732 libraries.append(online_essentials_library_.get());
733 }
734
735 {
736 std::scoped_lock lock{on_disk_libraries_mutex_};
737 for (const auto &asset_lib_uptr : on_disk_libraries_.values()) {
738 /* Already handled above. */
739 if (asset_lib_uptr->library_type() == ASSET_LIBRARY_ESSENTIALS) {
740 continue;
741 }
742
743 if (asset_lib_uptr->is_enabled()) {
744 libraries.append(asset_lib_uptr.get());
745 }
746 }
747 }
748
749 if (include_remote_libraries) {
750 std::scoped_lock lock{remote_libraries_mutex_};
751 for (const auto &asset_lib_uptr : remote_libraries_.values()) {
752 if (asset_lib_uptr->is_enabled()) {
753 libraries.append(asset_lib_uptr.get());
754 }
755 }
756 }
757
758 for (AssetLibrary *library : libraries) {
759 fn(*library);
760 }
761}
762
763} // namespace asset_system
764
765} // namespace blender
Blender util stuff.
File and directory operations.
#define PATH_MAX
#define BLI_path_join(...)
#define ALTSEP_STR
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define USER_EXPERIMENTAL_TEST(userdef, member)
volatile int lock
#define ELEM(...)
#define BLI_assert_msg(a, msg)
constexpr const char * c_str() const
constexpr StringRef()
void append(const T &value)
std::unique_ptr< AssetCatalogDefinitionFile > construct_cdf_in_memory(const CatalogFilePath &file_path) const
static const CatalogFilePath DEFAULT_CATALOG_FILENAME
const AssetCatalogDefinitionFile * get_catalog_definition_file() const
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_on_disk_custom_preferences(bUserAssetLibrary *custom_library)
AssetLibrary * get_asset_library(const Main *bmain, const AssetLibraryReference &library_reference)
AssetLibrary * find_loaded_on_disk_asset_library_from_name(StringRef name) const
static bUserAssetLibrary * find_custom_asset_library_from_library_ref(const AssetLibraryReference &library_reference)
OnDiskAssetLibrary * lookup_on_disk_library(eAssetLibraryType type, StringRefNull root_path)
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)
AssetLibrary * get_asset_library_on_disk_custom(StringRef name, StringRefNull root_path)
static std::string root_path_from_library_ref(const AssetLibraryReference &library_reference)
std::string normalize_asset_weak_reference_relative_asset_identifier(const AssetWeakReference &asset_reference)
static bUserAssetLibrary * find_custom_preferences_asset_library_from_asset_weak_ref(const AssetWeakReference &asset_reference)
std::string resolve_asset_weak_reference_to_library_path(const AssetWeakReference &asset_reference)
AssetLibrary * get_asset_library_on_disk(eAssetLibraryType library_type, StringRef name, StringRefNull root_path, bool load_catalogs=true, bUserAssetLibrary *preferences_library=nullptr)
AssetLibrary * get_preferences_remote_asset_library(const bUserAssetLibrary &custom_library)
AssetLibrary * get_asset_library_all(const Main *bmain)
std::shared_ptr< AssetCatalogService > catalog_service_
AssetCatalogService & catalog_service() const
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
constexpr int64_t rfind(char c, int64_t pos=INT64_MAX) const
static constexpr int64_t not_found
constexpr bool is_empty() const
constexpr StringRef substr(int64_t start, int64_t size) const
std::string resolve_directory_path(StringRef directory)
std::string resolve_path(StringRefNull path, int64_t max_len)
Vector< AssetLibraryReference > all_valid_asset_library_refs()
StringRefNull online_essentials_cache_directory_path()
static void on_blendfile_load(Main *, PointerRNA **, const int, void *)
StringRefNull essentials_directory_path()
bool is_online_essentials_url(StringRef url)
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ USER_ASSETS_USE_ONLINE_ESSENTIALS
__int64 int64_t
Definition BKE_text.h:90
@ BKE_CB_EVT_LOAD_PRE
@ ASSET_LIBRARY_USE_REMOTE_URL
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_ONLINE_ESSENTIALS
@ ASSET_LIBRARY_LOCAL
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
Definition callbacks.cc:87
std::string AS_asset_library_find_suitable_root_path_from_main(const Main *bmain)
void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt)
Definition callbacks.cc:94
struct bUserAssetLibrary * BKE_preferences_asset_library_find_by_name(const struct UserDef *userdef, const char *name) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
static CLG_LogRef LOG
Definition logging.cpp:12
constexpr char SEP
void BKE_blender_atexit_register(void(*func)(void *user_data), void *user_data)
Definition blender.cc:484
eAssetLibraryType asset_library_type
#define SEP_STR
Definition unit.cc:41