Gems/Atom/RPI/Code/Tests/Model/ModelTests.cpp
// Tests that validation still fails when expected
// even after producing a valid mesh due to a missing
// BeginMesh call
Tests that validation still fails when expected
even after producing a valid mesh due to a missing
BeginMesh call
Tests that validation still fails when expected even after producing a valid mesh due to a missing BeginMesh call
TEST_F(ModelTests, SecondMeshFailureNoBeginMesh)
    {
        using namespace AZ;
        RPI::ModelLodAssetCreator creator;
        creator.Begin(Data::AssetId(AZ::Uuid::CreateRandom()));
        uint32_t indexCount = 36;
        uint32_t vertexCount = 36;
        RHI::BufferViewDescriptor indexBufferViewDescriptor =
            RHI::BufferViewDescriptor::CreateStructured(0, indexCount, sizeof(uint32_t));
        RHI::BufferViewDescriptor vertexBufferViewDescriptor =
            RHI::BufferViewDescriptor::CreateStructured(0, vertexCount, sizeof(float) * 3);
        {
            AZ::Aabb aabb = AZ::Aabb::CreateCenterRadius(Vector3::CreateZero(), 1.0f);
            creator.BeginMesh();
            creator.SetMeshAabb(AZStd::move(aabb));
            creator.SetMeshMaterialSlot(0);
            creator.SetMeshIndexBuffer({ BuildTestBuffer(indexCount, sizeof(uint32_t)), indexBufferViewDescriptor });
            creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { BuildTestBuffer(vertexCount, sizeof(float) * 3), vertexBufferViewDescriptor });
            creator.EndMesh();
        }
        {
            AZ::Aabb aabb = AZ::Aabb::CreateCenterRadius(Vector3::CreateZero(), 1.0f);
            ErrorMessageFinder messageFinder("BeginMesh() was not called", 5);
            creator.SetMeshAabb(AZStd::move(aabb));
            creator.SetMeshMaterialSlot(0);
            creator.SetMeshIndexBuffer({ BuildTestBuffer(indexCount, sizeof(uint32_t)), indexBufferViewDescriptor });
            creator.AddMeshStreamBuffer(GetPositionSemantic(), AZ::Name(), { BuildTestBuffer(vertexCount, sizeof(float) * 3), vertexBufferViewDescriptor });
            creator.EndMesh();
        }
        Data::Asset<RPI::ModelLodAsset> asset;
        EXPECT_TRUE(creator.End(asset));
        EXPECT_TRUE(asset.IsReady());
        EXPECT_NE(asset.Get(), nullptr);
        ASSERT_EQ(asset->GetMeshes().size(), 1);
    }
TEST_F ( ModelTests , SecondMeshFailureNoBeginMesh ) { using namespace AZ ; RPI :: ModelLodAssetCreator creator ; creator . Begin ( Data :: AssetId ( AZ :: Uuid :: CreateRandom ( ) ) ) ; uint32_t indexCount = 36 ; uint32_t vertexCount = 36 ; RHI :: BufferViewDescriptor indexBufferViewDescriptor = RHI :: BufferViewDescriptor :: CreateStructured ( 0 , indexCount , sizeof ( uint32_t ) ) ; RHI :: BufferViewDescriptor vertexBufferViewDescriptor = RHI :: BufferViewDescriptor :: CreateStructured ( 0 , vertexCount , sizeof ( float ) * 3 ) ; { AZ :: Aabb aabb = AZ :: Aabb :: CreateCenterRadius ( Vector3 :: CreateZero ( ) , 1.0f ) ; creator . BeginMesh ( ) ; creator . SetMeshAabb ( AZStd :: move ( aabb ) ) ; creator . SetMeshMaterialSlot ( 0 ) ; creator . SetMeshIndexBuffer ( { BuildTestBuffer ( indexCount , sizeof ( uint32_t ) ) , indexBufferViewDescriptor } ) ; creator . AddMeshStreamBuffer ( GetPositionSemantic ( ) , AZ :: Name ( ) , { BuildTestBuffer ( vertexCount , sizeof ( float ) * 3 ) , vertexBufferViewDescriptor } ) ; creator . EndMesh ( ) ; } { AZ :: Aabb aabb = AZ :: Aabb :: CreateCenterRadius ( Vector3 :: CreateZero ( ) , 1.0f ) ; ErrorMessageFinder messageFinder ( " " , 5 ) ; creator . SetMeshAabb ( AZStd :: move ( aabb ) ) ; creator . SetMeshMaterialSlot ( 0 ) ; creator . SetMeshIndexBuffer ( { BuildTestBuffer ( indexCount , sizeof ( uint32_t ) ) , indexBufferViewDescriptor } ) ; creator . AddMeshStreamBuffer ( GetPositionSemantic ( ) , AZ :: Name ( ) , { BuildTestBuffer ( vertexCount , sizeof ( float ) * 3 ) , vertexBufferViewDescriptor } ) ; creator . EndMesh ( ) ; } Data :: Asset < RPI :: ModelLodAsset > asset ; EXPECT_TRUE ( creator . End ( asset ) ) ; EXPECT_TRUE ( asset . IsReady ( ) ) ; EXPECT_NE ( asset . Get ( ) , nullptr ) ; ASSERT_EQ ( asset -> GetMeshes ( ) . size ( ) , 1 ) ; }
Tests that validation still fails when expected
even after producing a valid mesh due to a missing
BeginMesh call
Tests that validation still fails when expected even after producing a valid mesh due to a missing BeginMesh call
//Creating this first mesh should work as expected // This second mesh should fail at every point since we have forgotten to // call BeginMesh again // We should still be able to produce a valid asset however // Make sure that this lod only has one mesh like we expect