From 1efc94bb2f7b0321935ce6564b23d5d92ee41594 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 9 Nov 2022 18:34:31 +0100 Subject: Asset System: New core type to represent assets (`AssetRepresenation`) Introduces a new `AssetRepresentation` type, as a runtime only container to hold asset information. It is supposed to become _the_ main way to represent and refer to assets in the asset system, see T87235. It can store things like the asset name, asset traits, preview and other asset metadata. Technical documentation: https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Representation. By introducing a proper asset representation type, we do an important step away from the previous, non-optimal representation of assets as files in the file browser backend, and towards the asset system as backend. It should replace the temporary & hacky `AssetHandle` design in the near future. Note that the loading of asset data still happens through the file browser backend, check the linked to Wiki page for more information on that. As a side-effect, asset metadata isn't stored in file browser file entries when browsing with link/append anymore. Don't think this was ever used, but scripts may have accessed this. Can be brought back if there's a need for it. --- .../blender/blenkernel/BKE_asset_representation.hh | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 source/blender/blenkernel/BKE_asset_representation.hh (limited to 'source/blender/blenkernel/BKE_asset_representation.hh') diff --git a/source/blender/blenkernel/BKE_asset_representation.hh b/source/blender/blenkernel/BKE_asset_representation.hh new file mode 100644 index 00000000000..0297e35c18c --- /dev/null +++ b/source/blender/blenkernel/BKE_asset_representation.hh @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup bke + */ + +#pragma once + +#include +#include + +#include "BLI_string_ref.hh" + +struct AssetMetaData; +struct ID; + +namespace blender::bke { + +/** + * \brief Abstraction to reference an asset, with necessary data for display & interaction. + * + * #AssetRepresentation is the data-structure to store information about a single asset. It doesn't + * contain the asset itself, but information like the metadata and preview, as well as methods to + * interact with them. Think of it like a view on an asset. + */ +class AssetRepresentation { + friend class AssetLibrary; + + struct ExternalAsset { + std::string name; + std::unique_ptr metadata_ = nullptr; + }; + + /** Indicate if this is a local or external asset, and as such, which of the union members below + * should be used. */ + const bool is_local_id_ = false; + + union { + ExternalAsset external_asset_; + ID *local_asset_id_ = nullptr; /* Non-owning. */ + }; + + public: + /** Constructs an asset representation for an external ID. The asset will not be editable. */ + explicit AssetRepresentation(StringRef name, std::unique_ptr metadata); + /** Constructs an asset representation for an ID stored in the current file. This makes the asset + * local and fully editable. */ + explicit AssetRepresentation(ID &id); + AssetRepresentation(AssetRepresentation &&other); + /* Non-copyable type. */ + AssetRepresentation(const AssetRepresentation &other) = delete; + ~AssetRepresentation(); + + /* Non-move-assignable type. Move construction is fine, but treat the "identity" (e.g. local vs + * external asset) of an asset representation as immutable. */ + AssetRepresentation &operator=(AssetRepresentation &&other) = delete; + /* Non-copyable type. */ + AssetRepresentation &operator=(const AssetRepresentation &other) = delete; + + StringRefNull get_name() const; + AssetMetaData &get_metadata() const; + /** Returns if this asset is stored inside this current file, and as such fully editable. */ + bool is_local_id() const; +}; + +} // namespace blender::bke -- cgit v1.2.3 From ad227e73f35dbe5b0c4a281ce471411e0ec97b87 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 9 Nov 2022 19:37:05 +0100 Subject: Cleanup: Link to documentation page for asset representation type --- source/blender/blenkernel/BKE_asset_representation.hh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source/blender/blenkernel/BKE_asset_representation.hh') diff --git a/source/blender/blenkernel/BKE_asset_representation.hh b/source/blender/blenkernel/BKE_asset_representation.hh index 0297e35c18c..4de63473113 100644 --- a/source/blender/blenkernel/BKE_asset_representation.hh +++ b/source/blender/blenkernel/BKE_asset_representation.hh @@ -19,9 +19,7 @@ namespace blender::bke { /** * \brief Abstraction to reference an asset, with necessary data for display & interaction. * - * #AssetRepresentation is the data-structure to store information about a single asset. It doesn't - * contain the asset itself, but information like the metadata and preview, as well as methods to - * interact with them. Think of it like a view on an asset. + * https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Representation */ class AssetRepresentation { friend class AssetLibrary; -- cgit v1.2.3 From b8fc7ed994049570da9d00589e2a952839670b73 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 9 Nov 2022 22:33:53 +0100 Subject: Fix incorrect forward declarations, causing warnings on Windows --- source/blender/blenkernel/BKE_asset_representation.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenkernel/BKE_asset_representation.hh') diff --git a/source/blender/blenkernel/BKE_asset_representation.hh b/source/blender/blenkernel/BKE_asset_representation.hh index 4de63473113..edaa5a203ba 100644 --- a/source/blender/blenkernel/BKE_asset_representation.hh +++ b/source/blender/blenkernel/BKE_asset_representation.hh @@ -22,7 +22,7 @@ namespace blender::bke { * https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Representation */ class AssetRepresentation { - friend class AssetLibrary; + friend struct AssetLibrary; struct ExternalAsset { std::string name; -- cgit v1.2.3