|
@@ -17,6 +17,7 @@
|
|
|
|
|
|
#include <AzCore/std/limits.h>
|
|
|
#include <AzCore/Component/Entity.h>
|
|
|
+#include <AzCore/Math/Sfmt.h>
|
|
|
|
|
|
#include <AZTestShared/Math/MathTestHelpers.h>
|
|
|
#include <AzTest/AzTest.h>
|
|
@@ -91,7 +92,7 @@ namespace UnitTest
|
|
|
AZ::Aabb m_aabb = AZ::Aabb::CreateNull();
|
|
|
uint32_t m_indexCount = 0;
|
|
|
uint32_t m_vertexCount = 0;
|
|
|
- AZ::Data::Asset<AZ::RPI::MaterialAsset> m_material;
|
|
|
+ AZ::RPI::ModelMaterialSlot::StableId m_materialSlotId = AZ::RPI::ModelMaterialSlot::InvalidStableId;
|
|
|
};
|
|
|
|
|
|
struct ExpectedLod
|
|
@@ -106,6 +107,18 @@ namespace UnitTest
|
|
|
AZStd::vector<ExpectedLod> m_lods;
|
|
|
};
|
|
|
|
|
|
+ void SetUp() override
|
|
|
+ {
|
|
|
+ RPITestFixture::SetUp();
|
|
|
+
|
|
|
+ auto assetId = AZ::Data::AssetId(AZ::Uuid::CreateRandom(), 0);
|
|
|
+ auto typeId = AZ::AzTypeInfo<AZ::RPI::MaterialAsset>::Uuid();
|
|
|
+ m_materialAsset = AZ::Data::Asset<AZ::RPI::MaterialAsset>(assetId, typeId, "");
|
|
|
+
|
|
|
+ // Some tests attempt to serialize-in the model asset, which should not attempt to actually load this dummy asset reference.
|
|
|
+ m_materialAsset.SetAutoLoadBehavior(AZ::Data::AssetLoadBehaviorNamespace::NoLoad);
|
|
|
+ }
|
|
|
+
|
|
|
AZ::RHI::ShaderSemantic GetPositionSemantic() const
|
|
|
{
|
|
|
return AZ::RHI::ShaderSemantic(AZ::Name("POSITION"));
|
|
@@ -136,6 +149,7 @@ namespace UnitTest
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ //! This function assumes the model has "sharedMeshCount + separateMeshCount" unique material slots, with incremental IDs starting at 0.
|
|
|
AZ::Data::Asset<AZ::RPI::ModelLodAsset> BuildTestLod(const uint32_t sharedMeshCount, const uint32_t separateMeshCount, ExpectedLod& expectedLod)
|
|
|
{
|
|
|
using namespace AZ;
|
|
@@ -148,6 +162,8 @@ namespace UnitTest
|
|
|
const uint32_t indexCount = 36;
|
|
|
const uint32_t vertexCount = 36;
|
|
|
|
|
|
+ RPI::ModelMaterialSlot::StableId materialSlotId = 0;
|
|
|
+
|
|
|
if(sharedMeshCount > 0)
|
|
|
{
|
|
|
const uint32_t sharedIndexCount = indexCount * sharedMeshCount;
|
|
@@ -164,7 +180,7 @@ namespace UnitTest
|
|
|
ExpectedMesh expectedMesh;
|
|
|
expectedMesh.m_indexCount = indexCount;
|
|
|
expectedMesh.m_vertexCount = vertexCount;
|
|
|
- expectedMesh.m_material = m_materialAsset;
|
|
|
+ expectedMesh.m_materialSlotId = i;
|
|
|
|
|
|
RHI::BufferViewDescriptor indexBufferViewDescriptor =
|
|
|
RHI::BufferViewDescriptor::CreateStructured(i * indexCount, indexCount, sizeof(uint32_t));
|
|
@@ -180,7 +196,7 @@ namespace UnitTest
|
|
|
creator.BeginMesh();
|
|
|
Aabb aabb = expectedMesh.m_aabb;
|
|
|
creator.SetMeshAabb(AZStd::move(aabb));
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(materialSlotId++);
|
|
|
creator.SetMeshIndexBuffer({ sharedIndexBuffer, indexBufferViewDescriptor });
|
|
|
creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { sharedPositionBuffer, vertexBufferViewDescriptor });
|
|
|
creator.EndMesh();
|
|
@@ -195,7 +211,7 @@ namespace UnitTest
|
|
|
ExpectedMesh expectedMesh;
|
|
|
expectedMesh.m_indexCount = indexCount;
|
|
|
expectedMesh.m_vertexCount = vertexCount;
|
|
|
- expectedMesh.m_material = m_materialAsset;
|
|
|
+ expectedMesh.m_materialSlotId = sharedMeshCount + i;
|
|
|
|
|
|
RHI::BufferViewDescriptor indexBufferViewDescriptor =
|
|
|
RHI::BufferViewDescriptor::CreateStructured(0, indexCount, sizeof(uint32_t));
|
|
@@ -213,7 +229,7 @@ namespace UnitTest
|
|
|
creator.BeginMesh();
|
|
|
Aabb aabb = expectedMesh.m_aabb;
|
|
|
creator.SetMeshAabb(AZStd::move(aabb));
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(materialSlotId++);
|
|
|
creator.SetMeshIndexBuffer({ BuildTestBuffer(indexCount, sizeof(uint32_t)), indexBufferViewDescriptor });
|
|
|
creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { positonBuffer, positionBufferViewDescriptor });
|
|
|
|
|
@@ -239,6 +255,15 @@ namespace UnitTest
|
|
|
|
|
|
creator.Begin(Data::AssetId(AZ::Uuid::CreateRandom()));
|
|
|
creator.SetName("TestModel");
|
|
|
+
|
|
|
+ for (RPI::ModelMaterialSlot::StableId materialSlotId = 0; materialSlotId < sharedMeshCount + separateMeshCount; ++materialSlotId)
|
|
|
+ {
|
|
|
+ RPI::ModelMaterialSlot slot;
|
|
|
+ slot.m_defaultMaterialAsset = m_materialAsset;
|
|
|
+ slot.m_displayName = AZStd::string::format("Slot%d", materialSlotId);
|
|
|
+ slot.m_stableId = materialSlotId;
|
|
|
+ creator.AddMaterialSlot(slot);
|
|
|
+ }
|
|
|
|
|
|
for (uint32_t i = 0; i < lodCount; ++i)
|
|
|
{
|
|
@@ -263,7 +288,7 @@ namespace UnitTest
|
|
|
EXPECT_TRUE(mesh.GetAabb() == expectedMesh.m_aabb);
|
|
|
EXPECT_TRUE(mesh.GetIndexCount() == expectedMesh.m_indexCount);
|
|
|
EXPECT_TRUE(mesh.GetVertexCount() == expectedMesh.m_vertexCount);
|
|
|
- EXPECT_TRUE(mesh.GetMaterialAsset() == expectedMesh.m_material);
|
|
|
+ EXPECT_TRUE(mesh.GetMaterialSlotId() == expectedMesh.m_materialSlotId);
|
|
|
}
|
|
|
|
|
|
void ValidateLodAsset(const AZ::RPI::ModelLodAsset* lodAsset, const ExpectedLod& expectedLod)
|
|
@@ -299,9 +324,7 @@ namespace UnitTest
|
|
|
}
|
|
|
|
|
|
const uint32_t m_manyMesh = 100; // Not too much to hold up the tests but enough to stress them
|
|
|
- AZ::Data::Asset<AZ::RPI::MaterialAsset> m_materialAsset =
|
|
|
- AZ::Data::Asset<AZ::RPI::MaterialAsset>(AZ::Data::AssetId(AZ::Uuid::CreateRandom(), 0),
|
|
|
- AZ::AzTypeInfo<AZ::RPI::MaterialAsset>::Uuid(), "");
|
|
|
+ AZ::Data::Asset<AZ::RPI::MaterialAsset> m_materialAsset;
|
|
|
|
|
|
};
|
|
|
|
|
@@ -687,11 +710,11 @@ namespace UnitTest
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Tests that if we try to set the material id on a mesh
|
|
|
+ // Tests that if we try to set the material slot on a mesh
|
|
|
// without calling Begin or BeginMesh that it fails
|
|
|
// as expected. Also tests the case that Begin *is*
|
|
|
// called but BeginMesh is not.
|
|
|
- TEST_F(ModelTests, SetMaterialIdNoBeginNoBeginMesh)
|
|
|
+ TEST_F(ModelTests, SetMaterialSlotNoBeginNoBeginMesh)
|
|
|
{
|
|
|
using namespace AZ;
|
|
|
|
|
@@ -699,7 +722,7 @@ namespace UnitTest
|
|
|
|
|
|
{
|
|
|
ErrorMessageFinder messageFinder("Begin() was not called");
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(0);
|
|
|
}
|
|
|
|
|
|
creator.Begin(Data::AssetId(AZ::Uuid::CreateRandom()));
|
|
@@ -707,7 +730,7 @@ namespace UnitTest
|
|
|
//This should still fail even if we call Begin but not BeginMesh
|
|
|
{
|
|
|
ErrorMessageFinder messageFinder("BeginMesh() was not called");
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -827,7 +850,7 @@ namespace UnitTest
|
|
|
|
|
|
creator.BeginMesh();
|
|
|
creator.SetMeshAabb(AZStd::move(aabb));
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(0);
|
|
|
creator.SetMeshIndexBuffer({ BuildTestBuffer(indexCount, sizeof(uint32_t)), indexBufferViewDescriptor });
|
|
|
creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { BuildTestBuffer(vertexCount, sizeof(float) * 3), vertexBufferViewDescriptor });
|
|
|
|
|
@@ -842,7 +865,7 @@ namespace UnitTest
|
|
|
ErrorMessageFinder messageFinder("BeginMesh() was not called", 5);
|
|
|
|
|
|
creator.SetMeshAabb(AZStd::move(aabb));
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(0);
|
|
|
creator.SetMeshIndexBuffer({ BuildTestBuffer(indexCount, sizeof(uint32_t)), indexBufferViewDescriptor });
|
|
|
creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { BuildTestBuffer(vertexCount, sizeof(float) * 3), vertexBufferViewDescriptor });
|
|
|
|
|
@@ -885,7 +908,7 @@ namespace UnitTest
|
|
|
|
|
|
creator.BeginMesh();
|
|
|
creator.SetMeshAabb(AZStd::move(aabb));
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(0);
|
|
|
creator.SetMeshIndexBuffer({ BuildTestBuffer(indexCount, sizeof(uint32_t)), indexBufferViewDescriptor });
|
|
|
creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { BuildTestBuffer(vertexCount, sizeof(float) * 3), vertexBufferViewDescriptor });
|
|
|
|
|
@@ -907,7 +930,7 @@ namespace UnitTest
|
|
|
|
|
|
creator.BeginMesh();
|
|
|
creator.SetMeshAabb(AZStd::move(aabb));
|
|
|
- creator.SetMeshMaterialAsset(m_materialAsset);
|
|
|
+ creator.SetMeshMaterialSlot(0);
|
|
|
creator.SetMeshIndexBuffer({ BuildTestBuffer(indexCount, sizeof(uint32_t)), indexBufferViewDescriptor });
|
|
|
creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { BuildTestBuffer(vertexCount, sizeof(float) * 3), vertexBufferViewDescriptor });
|
|
|
|
|
@@ -1019,10 +1042,7 @@ namespace UnitTest
|
|
|
|
|
|
lodCreator.BeginMesh();
|
|
|
lodCreator.SetMeshAabb(AZ::Aabb::CreateFromMinMax({-1.0f, -1.0f, -0.5f}, {1.0f, 1.0f, 0.5f}));
|
|
|
- lodCreator.SetMeshMaterialAsset(
|
|
|
- AZ::Data::Asset<AZ::RPI::MaterialAsset>(AZ::Data::AssetId(AZ::Uuid::CreateRandom(), 0),
|
|
|
- AZ::AzTypeInfo<AZ::RPI::MaterialAsset>::Uuid(), "")
|
|
|
- );
|
|
|
+ lodCreator.SetMeshMaterialSlot(AZ::Sfmt::GetInstance().Rand32());
|
|
|
|
|
|
{
|
|
|
AZ::Data::Asset<AZ::RPI::BufferAsset> indexBuffer = BuildTestBuffer(indicesCount, sizeof(uint32_t));
|