Moved the material slot list from ModelLodAsset to ModelAsset, so all the slots live in one main list. This removes data duplication between LODs and cleans up the code a bit.
I had to update the ModelLod class to take in both the ModelLodAsset and ModelAsset for initialization so it can fetch the slots for each mesh. Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
@@ -90,8 +90,8 @@ namespace AZ
|
||||
private:
|
||||
Model() = default;
|
||||
|
||||
static Data::Instance<Model> CreateInternal(ModelAsset& modelAsset);
|
||||
RHI::ResultCode Init(ModelAsset& modelAsset);
|
||||
static Data::Instance<Model> CreateInternal(const Data::Asset<ModelAsset>& modelAsset);
|
||||
RHI::ResultCode Init(const Data::Asset<ModelAsset>& modelAsset);
|
||||
|
||||
AZStd::fixed_vector<Data::Instance<ModelLod>, ModelLodAsset::LodCountMax> m_lods;
|
||||
Data::Asset<ModelAsset> m_modelAsset;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <Atom/RHI.Reflect/Limits.h>
|
||||
|
||||
#include <Atom/RPI.Reflect/Model/ModelLodAsset.h>
|
||||
#include <Atom/RPI.Reflect/Model/ModelAsset.h>
|
||||
|
||||
#include <AtomCore/std/containers/array_view.h>
|
||||
#include <AtomCore/std/containers/vector_set.h>
|
||||
@@ -84,7 +85,7 @@ namespace AZ
|
||||
AZ_INSTANCE_DATA(ModelLod, "{3C796FC9-2067-4E0F-A660-269F8254D1D5}");
|
||||
AZ_CLASS_ALLOCATOR(ModelLod, AZ::SystemAllocator, 0);
|
||||
|
||||
static Data::Instance<ModelLod> FindOrCreate(const Data::Asset<ModelLodAsset>& lodAsset);
|
||||
static Data::Instance<ModelLod> FindOrCreate(const Data::Asset<ModelLodAsset>& lodAsset, const Data::Asset<ModelAsset>& modelAsset);
|
||||
|
||||
~ModelLod() = default;
|
||||
|
||||
@@ -124,8 +125,8 @@ namespace AZ
|
||||
private:
|
||||
ModelLod() = default;
|
||||
|
||||
static Data::Instance<ModelLod> CreateInternal(ModelLodAsset& lodAsset);
|
||||
RHI::ResultCode Init(ModelLodAsset& lodAsset);
|
||||
static Data::Instance<ModelLod> CreateInternal(const Data::Asset<ModelLodAsset>& lodAsset, const AZStd::any* modelAssetAny);
|
||||
RHI::ResultCode Init(const Data::Asset<ModelLodAsset>& lodAsset, const Data::Asset<ModelAsset>& modelAsset);
|
||||
|
||||
bool SetMeshInstanceData(
|
||||
const ModelLodAsset::Mesh::StreamBufferInfo& streamBufferInfo,
|
||||
|
||||
@@ -51,7 +51,10 @@ namespace AZ
|
||||
const AZ::Aabb& GetAabb() const;
|
||||
|
||||
//! Returns the list of all ModelMaterialSlot's for the model, across all LODs.
|
||||
RPI::ModelMaterialSlotMap GetModelMaterialSlots() const;
|
||||
const ModelMaterialSlotMap& GetMaterialSlots() const;
|
||||
|
||||
//! Find a material slot with the given stableId, or returns an invalid slot if it isn't found.
|
||||
const ModelMaterialSlot& FindMaterialSlot(uint32_t stableId) const;
|
||||
|
||||
//! Returns the number of Lods in the model
|
||||
size_t GetLodCount() const;
|
||||
@@ -100,6 +103,13 @@ namespace AZ
|
||||
volatile mutable bool m_isKdTreeCalculationRunning = false;
|
||||
mutable AZStd::mutex m_kdTreeLock;
|
||||
mutable AZStd::optional<AZStd::size_t> m_modelTriangleCount;
|
||||
|
||||
// Lists all of the material slots that are used by this LOD.
|
||||
// Note the same slot can appear in multiple LODs in the model, so that LODs don't have to refer back to the model asset.
|
||||
ModelMaterialSlotMap m_materialSlots;
|
||||
|
||||
// A default ModelMaterialSlot to be returned upon error conditions.
|
||||
ModelMaterialSlot m_fallbackSlot;
|
||||
|
||||
AZStd::size_t CalculateTriangleCount() const;
|
||||
};
|
||||
|
||||
@@ -29,6 +29,10 @@ namespace AZ
|
||||
|
||||
//! Assigns a name to the model
|
||||
void SetName(AZStd::string_view name);
|
||||
|
||||
//! Adds a new material slot to the asset.
|
||||
//! If a slot with the same stable ID already exists, it will be replaced.
|
||||
void AddMaterialSlot(const ModelMaterialSlot& materialSlot);
|
||||
|
||||
//! Adds a Lod to the model.
|
||||
void AddLodAsset(Data::Asset<ModelLodAsset>&& lodAsset);
|
||||
|
||||
@@ -85,9 +85,9 @@ namespace AZ
|
||||
//! Returns the number of indices in this mesh
|
||||
uint32_t GetIndexCount() const;
|
||||
|
||||
//! Returns the index of the material slot used by this mesh.
|
||||
//! This indexes into the ModelLodAsset's material slot list.
|
||||
size_t GetMaterialSlotIndex() const;
|
||||
//! Returns the ID of the material slot used by this mesh.
|
||||
//! This maps into the ModelAsset's material slot list.
|
||||
ModelMaterialSlot::StableId GetMaterialSlotId() const;
|
||||
|
||||
//! Returns the name of this mesh
|
||||
const AZ::Name& GetName() const;
|
||||
@@ -126,9 +126,9 @@ namespace AZ
|
||||
AZ::Name m_name;
|
||||
AZ::Aabb m_aabb = AZ::Aabb::CreateNull();
|
||||
|
||||
// Identifies the material that is used by this mesh.
|
||||
// References material slot in the ModelLodAsset that owns this mesh; see ModelLodAsset::GetMaterialSlot().
|
||||
size_t m_materialSlotIndex = 0;
|
||||
// Identifies the material slot that is used by this mesh.
|
||||
// References material slot in the ModelAsset that owns this mesh; see ModelAsset::FindMaterialSlot().
|
||||
ModelMaterialSlot::StableId m_materialSlotId = ModelMaterialSlot::InvalidStableId;
|
||||
|
||||
// Both the buffer in m_indexBufferAssetView and the buffers in m_streamBufferInfo
|
||||
// may point to either unique buffers for the mesh or to consolidated
|
||||
@@ -147,16 +147,6 @@ namespace AZ
|
||||
|
||||
//! Returns the model-space axis-aligned bounding box of all meshes in the lod
|
||||
const AZ::Aabb& GetAabb() const;
|
||||
|
||||
//! Returns an array view into the collection of material slots available to this lod
|
||||
AZStd::array_view<ModelMaterialSlot> GetMaterialSlots() const;
|
||||
|
||||
//! Returns a specific material slot by index, with error checking.
|
||||
//! The index can be retrieved from Mesh::GetMaterialSlotIndex().
|
||||
const ModelMaterialSlot& GetMaterialSlot(size_t slotIndex) const;
|
||||
|
||||
//! Find a material slot with the given stableId, or returns null if it isn't found.
|
||||
const ModelMaterialSlot* FindMaterialSlot(uint32_t stableId) const;
|
||||
|
||||
private:
|
||||
AZStd::vector<Mesh> m_meshes;
|
||||
@@ -169,13 +159,6 @@ namespace AZ
|
||||
Data::Asset<BufferAsset> m_indexBuffer;
|
||||
AZStd::vector<Data::Asset<BufferAsset>> m_streamBuffers;
|
||||
|
||||
// Lists all of the material slots that are used by this LOD.
|
||||
// Note the same slot can appear in multiple LODs in the model, so that LODs don't have to refer back to the model asset.
|
||||
AZStd::vector<ModelMaterialSlot> m_materialSlots;
|
||||
|
||||
// A default ModelMaterialSlot to be returned upon error conditions.
|
||||
ModelMaterialSlot m_fallbackSlot;
|
||||
|
||||
void AddMesh(const Mesh& mesh);
|
||||
|
||||
void SetReady();
|
||||
|
||||
@@ -46,10 +46,9 @@ namespace AZ
|
||||
//! Begin and BeginMesh must be called first.
|
||||
void SetMeshAabb(AZ::Aabb&& aabb);
|
||||
|
||||
//! Sets the material slot data for the current SubMesh.
|
||||
//! Adds a new material slot to the ModelLodAsset if it doesn't already exist.
|
||||
//! Sets the ID of the model's material slot that this mesh uses.
|
||||
//! Begin and BeginMesh must be called first
|
||||
void SetMeshMaterialSlot(const ModelMaterialSlot& materialSlot);
|
||||
void SetMeshMaterialSlot(ModelMaterialSlot::StableId id);
|
||||
|
||||
//! Sets the given BufferAssetView to the current SubMesh as the index buffer.
|
||||
//! Begin and BeginMesh must be called first
|
||||
|
||||
Reference in New Issue
Block a user