Blender V5.0
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 <optional>
13
14#include "AS_asset_catalog.hh"
15
16#include "DNA_asset_types.h"
17
18#include "BLI_mutex.hh"
19#include "BLI_set.hh"
20#include "BLI_string_ref.hh"
21#include "BLI_vector.hh"
22
23#include "BKE_callbacks.hh"
24
25struct Main;
26
28class IDRemapper;
29}
30
31namespace blender::asset_system {
32
33class AssetRepresentation;
34
42 eAssetLibraryType library_type_;
47 std::string name_;
52 std::shared_ptr<std::string> root_path_;
53
68 struct AssetStorage {
69 /* Uses shared pointers so the UI can acquire weak pointers. It can then ensure pointers are
70 * not dangling before accessing. */
71
73 /* Store local ID assets separately for efficient lookups.
74 * TODO(Julian): A [ID *, asset] or even [ID.session_uid, asset] map would be preferable for
75 * faster lookups. Not possible until each asset is only represented once in the storage. */
77 };
78 AssetStorage asset_storage_;
79
80 protected:
81 /* Changing this pointer should be protected using #catalog_service_mutex_. Note that changes
82 * within the catalog service may still happen without the mutex being locked. They should be
83 * protected separately. */
84 std::unique_ptr<AssetCatalogService> catalog_service_;
86
87 std::optional<eAssetImportMethod> import_method_;
91
92 bool use_relative_path_ = true;
93
95
96 public:
97 /* Controlled by #ed::asset::catalogs_set_save_catalogs_when_file_is_saved,
98 * for managing the "Save Catalog Changes" in the quit-confirmation dialog box. */
100
103
112 virtual ~AssetLibrary();
113
122 static void foreach_loaded(FunctionRef<void(AssetLibrary &)> fn, bool include_all_library);
123
129 virtual std::optional<AssetLibraryReference> library_reference() const = 0;
130
132
134
148 std::weak_ptr<AssetRepresentation> add_external_asset(StringRef relative_asset_path,
150 int id_type,
151 std::unique_ptr<AssetMetaData> metadata);
153 std::weak_ptr<AssetRepresentation> add_local_id_asset(ID &id);
164
171
180
183
184 void on_blend_save_post(Main *bmain, PointerRNA **pointers, int num_pointers);
185
186 std::string resolve_asset_weak_reference_to_full_path(const AssetWeakReference &asset_reference);
187
189 StringRefNull name() const;
190 StringRefNull root_path() const;
191
192 protected:
194 virtual void refresh_catalogs();
195};
196
198
202
203} // namespace blender::asset_system
204
217 const Main *bmain, const AssetLibraryReference &library_reference);
218
220 const AssetLibraryReference &library_reference);
221
244
255
263
272 const char *name, const char *library_dirpath);
273
276
282
302 char r_path_buffer[/*FILE_MAX_LIBEXTRA*/ 1282],
303 char **r_dir,
304 char **r_group,
305 char **r_name);
306
blender::asset_system::AssetLibrary * AS_asset_library_load(const Main *bmain, const AssetLibraryReference &library_reference)
void AS_asset_library_remap_ids(const blender::bke::id::IDRemapper &mappings)
std::string AS_asset_library_find_suitable_root_path_from_main(const Main *bmain)
void AS_asset_libraries_exit()
void AS_asset_library_essential_import_method_update()
void AS_asset_library_import_method_ensure_valid(Main &bmain)
std::string AS_asset_library_root_path_from_library_ref(const AssetLibraryReference &library_reference)
std::string AS_asset_library_find_suitable_root_path_from_path(blender::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)
blender::asset_system::AssetLibrary * AS_asset_library_load_from_directory(const char *name, const char *library_dirpath)
eAssetLibraryType
void on_blend_save_post(Main *bmain, PointerRNA **pointers, int num_pointers)
std::optional< eAssetImportMethod > import_method_
eAssetLibraryType library_type() const
std::unique_ptr< AssetCatalogService > catalog_service_
void remap_ids_and_remove_invalid(const blender::bke::id::IDRemapper &mappings)
std::weak_ptr< AssetRepresentation > add_local_id_asset(ID &id)
AssetCatalogService & catalog_service() const
static void foreach_loaded(FunctionRef< void(AssetLibrary &)> fn, bool include_all_library)
AssetLibrary(eAssetLibraryType library_type, StringRef name="", StringRef root_path="")
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)
std::weak_ptr< AssetRepresentation > add_external_asset(StringRef relative_asset_path, StringRef name, int id_type, std::unique_ptr< AssetMetaData > metadata)
virtual std::optional< AssetLibraryReference > library_reference() const =0
AssetLibraryReference all_library_reference()
AssetLibraryReference current_file_library_reference()
void all_library_reload_catalogs_if_dirty()
Vector< AssetLibraryReference > all_valid_asset_library_refs()
std::mutex Mutex
Definition BLI_mutex.hh:47
const char * name
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
Definition DNA_ID.h:414