Blender V4.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
9#pragma once
10
11#include <memory>
12#include <mutex>
13
14#include "AS_asset_catalog.hh"
15
16#include "DNA_asset_types.h"
17
18#include "BLI_set.hh"
19#include "BLI_string_ref.hh"
20#include "BLI_vector.hh"
21
22#include "BKE_callbacks.hh"
23
24struct Main;
25
27class IDRemapper;
28}
29
30namespace blender::asset_system {
31
32class AssetRepresentation;
33
41 eAssetLibraryType library_type_;
46 std::string name_;
51 std::shared_ptr<std::string> root_path_;
52
67 struct AssetStorage {
68 /* Uses shared pointers so the UI can acquire weak pointers. It can then ensure pointers are
69 * not dangling before accessing. */
70
72 /* Store local ID assets separately for efficient lookups.
73 * TODO(Julian): A [ID *, asset] or even [ID.session_uid, asset] map would be preferable for
74 * faster lookups. Not possible until each asset is only represented once in the storage. */
76 };
77 AssetStorage asset_storage_;
78
79 protected:
80 /* Changing this pointer should be protected using #catalog_service_mutex_. Note that changes
81 * within the catalog service may still happen without the mutex being locked. They should be
82 * protected separately. */
83 std::unique_ptr<AssetCatalogService> catalog_service_;
85
86 std::optional<eAssetImportMethod> import_method_;
90
91 bool use_relative_path_ = true;
92
94
95 public:
96 /* Controlled by #ed::asset::catalogs_set_save_catalogs_when_file_is_saved,
97 * for managing the "Save Catalog Changes" in the quit-confirmation dialog box. */
99
102
103 public:
112 virtual ~AssetLibrary();
113
122 static void foreach_loaded(FunctionRef<void(AssetLibrary &)> fn, bool include_all_library);
123
124 void load_catalogs();
125
127
141 std::weak_ptr<AssetRepresentation> add_external_asset(StringRef relative_asset_path,
142 StringRef name,
143 int id_type,
144 std::unique_ptr<AssetMetaData> metadata);
146 std::weak_ptr<AssetRepresentation> add_local_id_asset(StringRef relative_asset_path, ID &id);
157
164
173
176
177 void on_blend_save_post(Main *bmain, PointerRNA **pointers, int num_pointers);
178
179 std::string resolve_asset_weak_reference_to_full_path(const AssetWeakReference &asset_reference);
180
182 StringRefNull name() const;
183 StringRefNull root_path() const;
184
185 protected:
187 virtual void refresh_catalogs();
188};
189
191
194
195} // namespace blender::asset_system
196
209 const Main *bmain, const AssetLibraryReference &library_reference);
210
212 const AssetLibraryReference &library_reference);
213
236
247
255
264 const char *library_dirpath);
265
268
274
294 char r_path_buffer[1090 /* FILE_MAX_LIBEXTRA */],
295 char **r_dir,
296 char **r_group,
297 char **r_name);
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()
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[1090], char **r_dir, char **r_group, char **r_name)
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(StringRef relative_asset_path, 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)
AssetLibraryReference all_library_reference()
void all_library_reload_catalogs_if_dirty()
Vector< AssetLibraryReference > all_valid_asset_library_refs()
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
Definition DNA_ID.h:413