Blender V5.3
AS_asset_library.hh
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#pragma once
10
11#include <memory>
12#include <mutex>
13#include <optional>
14
15#include "AS_asset_catalog.hh"
16#include "AS_asset_representation.hh" /* For URLWithHash. */
17
18#include "DNA_asset_types.h"
19
20#include "BLI_mutex.hh"
21#include "BLI_set.hh"
22#include "BLI_string_ref.hh"
23#include "BLI_vector.hh"
24
25#include "BKE_callbacks.hh"
26#include "DNA_userdef_types.h"
27
28namespace blender {
29
30struct Main;
31
32namespace bke::id {
33class IDRemapper;
34}
35
36namespace asset_system {
37
39
47 eAssetLibraryType library_type_;
49 bool is_read_only_ = true;
54 std::string name_;
61 std::shared_ptr<std::string> root_path_;
62
77 struct AssetStorage {
78 /* Uses shared pointers so the UI can acquire weak pointers. It can then ensure pointers are
79 * not dangling before accessing. */
80
82 Mutex external_assets_mutex;
83 /* Store local ID assets separately for efficient lookups.
84 * TODO(Julian): A [ID *, asset] or even [ID.session_uid, asset] map would be preferable for
85 * faster lookups. Not possible until each asset is only represented once in the storage. */
87 Mutex local_id_assets_mutex;
88 };
89 AssetStorage asset_storage_;
90
91 protected:
92 /* Changing this pointer should be protected using #catalog_service_mutex_. Note that changes
93 * within the catalog service may still happen without the mutex being locked. They should be
94 * protected separately.
95 *
96 * This is a #shared_ptr (rather than #unique_ptr) so that readers can keep the service alive
97 * while using it, even if another thread replaces #catalog_service_ in the meantime (which frees
98 * the previously referenced service). See #catalog_service_ptr(). */
99 std::shared_ptr<AssetCatalogService> catalog_service_;
100 mutable std::recursive_mutex catalog_service_mutex_;
101
107
109
110 public:
111 /* Controlled by #ed::asset::catalogs_set_save_catalogs_when_file_is_saved,
112 * for managing the "Save Catalog Changes" in the quit-confirmation dialog box. */
114
117
128 bool is_read_only,
129 StringRef name = "",
130 StringRef root_path = "");
131 virtual ~AssetLibrary();
132
143 static void foreach_loaded(FunctionRef<void(AssetLibrary &)> fn, bool include_all_library);
144
155 virtual void force_remote_listing_download() const;
156
162 virtual std::optional<AssetLibraryReference> library_reference() const = 0;
163
167 virtual const bUserAssetLibrary *user_asset_library() const;
168
176 virtual std::optional<eAssetImportMethod> import_method() const = 0;
177
178 virtual bool use_relative_paths() const;
179
187 virtual std::optional<StringRefNull> remote_url() const;
188
189 virtual std::optional<StringRefNull> auth_token() const;
190
192
201 std::shared_ptr<AssetCatalogService> catalog_service_ptr() const;
202
216 std::weak_ptr<AssetRepresentation> add_external_on_disk_asset(
217 StringRef relative_asset_path,
219 int id_type,
220 std::unique_ptr<AssetMetaData> metadata);
225 std::weak_ptr<AssetRepresentation> add_external_online_asset(
226 StringRef relative_asset_path,
228 int id_type,
229 std::unique_ptr<AssetMetaData> metadata,
230 OnlineAssetInfo online_info);
232 std::weak_ptr<AssetRepresentation> add_local_id_asset(ID &id);
243
250
259
261
264
265 void on_blend_save_post(Main *bmain, PointerRNA **pointers, int num_pointers);
266
267 std::string resolve_asset_weak_reference_to_full_path(const AssetWeakReference &asset_reference);
268
270 StringRefNull name() const;
271 StringRefNull root_path() const;
283 bool is_read_only() const;
284
285 protected:
287 virtual void refresh_catalogs();
288};
289
292
297
300
307
309
310} // namespace asset_system
311
324 const AssetLibraryReference &library_reference);
325
327 const AssetLibraryReference &library_reference);
328
347
358
366
375 const char *library_dirpath);
376
382
385
391
411 char r_path_buffer[/*FILE_MAX_LIBEXTRA*/ 1282],
412 char **r_dir,
413 char **r_group,
414 char **r_name);
415
421
422} // namespace blender
Main runtime representation of an asset.
void on_blend_save_post(Main *bmain, PointerRNA **pointers, int num_pointers)
eAssetLibraryType library_type() const
std::shared_ptr< AssetCatalogService > catalog_service_
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)
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)
AssetLibrary(eAssetLibraryType library_type, bool is_read_only, StringRef name="", StringRef root_path="")
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
virtual std::optional< eAssetImportMethod > import_method() const =0
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)
virtual void force_remote_listing_download() const
virtual std::optional< AssetLibraryReference > library_reference() const =0
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()
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()
BMesh Iterators.
std::string AS_asset_library_find_suitable_root_path_from_path(StringRefNull input_path)
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)
std::string AS_asset_library_resolve_path(StringRef path)
std::string AS_asset_library_find_suitable_root_path_from_main(const Main *bmain)
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)
std::mutex Mutex
Definition BLI_mutex.hh:51
asset_system::AssetLibrary * AS_asset_library_load_from_directory(const char *name, const char *library_dirpath)
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...