diff options
author | Julian Eisel <julian@blender.org> | 2022-11-08 20:43:25 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-11-08 20:43:25 +0300 |
commit | b090c18ce46697c97a4e1eaba60bb92a4212431d (patch) | |
tree | 14a861964421c6772877d99557494c695158b282 | |
parent | 2e1ba1ee20dd28292fbacca123e33dac243e9ff8 (diff) |
Store ID in asset representation directly
This should make some things more convenient in future, since we can
directly access the ID if an asset represents one, without having to
look it up. But also, we need to do ID remapping either way, which
currently requires the ID pointer to identify the ID, not other ID data
(like the contained asset metadata).
4 files changed, 14 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_asset_library.hh b/source/blender/blenkernel/BKE_asset_library.hh index 6402799b3a1..3358e37231e 100644 --- a/source/blender/blenkernel/BKE_asset_library.hh +++ b/source/blender/blenkernel/BKE_asset_library.hh @@ -60,7 +60,7 @@ struct AssetLibrary { * loading a different file). */ AssetRepresentation &add_external_asset(std::unique_ptr<AssetMetaData> metadata); - AssetRepresentation &add_local_id_asset(const ID &id); + AssetRepresentation &add_local_id_asset(ID &id); /** Remove an asset from the library that was added using #add_external_asset() or * #add_local_id_asset(). * \return True on success, false if the asset couldn't be found inside the library. */ diff --git a/source/blender/blenkernel/BKE_asset_representation.hh b/source/blender/blenkernel/BKE_asset_representation.hh index 35aecba51e5..0b81f7b05b1 100644 --- a/source/blender/blenkernel/BKE_asset_representation.hh +++ b/source/blender/blenkernel/BKE_asset_representation.hh @@ -23,15 +23,15 @@ namespace blender::bke { class AssetRepresentation { /** Null if the asset represents a local ID, in which case the ID owns the metadata. */ std::unique_ptr<AssetMetaData> metadata_ = nullptr; - /** If the asset representation was constructed from a local ID, this points to the editable - * asset metadata of the ID. */ - AssetMetaData *local_id_metadata_ = nullptr; /* Non-owning. */ + /** If this asset represents an ID in the current file, this references the ID directly. This + * means the represented asset is a fully local, and editable entity. */ + ID *local_asset_id_ = nullptr; /* Non-owning. */ public: explicit AssetRepresentation(std::unique_ptr<AssetMetaData> metadata); /** Constructs an asset representation for an ID stored in the current file. This makes the asset * local and fully editable. */ - explicit AssetRepresentation(const ID &id); + explicit AssetRepresentation(ID &id); AssetMetaData &get_metadata() const; /** Returns if this asset is stored inside this current file, and as such fully editable. */ diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc index edf804f70bc..826c24647a2 100644 --- a/source/blender/blenkernel/intern/asset_library.cc +++ b/source/blender/blenkernel/intern/asset_library.cc @@ -130,7 +130,7 @@ AssetRepresentation &AssetLibrary::add_external_asset(std::unique_ptr<AssetMetaD return *asset_storage_.last(); } -AssetRepresentation &AssetLibrary::add_local_id_asset(const ID &id) +AssetRepresentation &AssetLibrary::add_local_id_asset(ID &id) { asset_storage_.append(std::make_unique<AssetRepresentation>(id)); return *asset_storage_.last(); diff --git a/source/blender/blenkernel/intern/asset_representation.cc b/source/blender/blenkernel/intern/asset_representation.cc index 7123d7aba55..97f37edfa43 100644 --- a/source/blender/blenkernel/intern/asset_representation.cc +++ b/source/blender/blenkernel/intern/asset_representation.cc @@ -4,6 +4,8 @@ * \ingroup bke */ +#include <stdexcept> + #include "DNA_ID.h" #include "DNA_asset_types.h" @@ -17,18 +19,21 @@ AssetRepresentation::AssetRepresentation(std::unique_ptr<AssetMetaData> metadata { } -AssetRepresentation::AssetRepresentation(const ID &id) : local_id_metadata_(id.asset_data) +AssetRepresentation::AssetRepresentation(ID &id) : local_asset_id_(&id) { + if (!id.asset_data) { + throw std::invalid_argument("Passed ID is not an asset"); + } } AssetMetaData &AssetRepresentation::get_metadata() const { - return local_id_metadata_ ? *local_id_metadata_ : *metadata_; + return local_asset_id_ ? *local_asset_id_->asset_data : *metadata_; } bool AssetRepresentation::is_local_id() const { - return local_id_metadata_ != nullptr; + return local_asset_id_ != nullptr; } } // namespace blender::bke |