Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,132 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <RC/ResourceCompilerScene/Tests/Cgf/CgfExportContextTestBase.h>
#include <RC/ResourceCompilerScene/Common/ColorStreamExporter.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/GraphData/MockIMeshData.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/GraphData/MockIMeshVertexColorData.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/ManifestBase/MockISceneNodeSelectionList.h>
namespace AZ
{
namespace RC
{
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::_;
class ColorStreamExporterContextTestBase
: public CgfExporterContextTestBase
{
public:
ColorStreamExporterContextTestBase()
: m_stubMeshData(new SceneAPI::DataTypes::MockIMeshData())
, m_stubMeshVertexColorData(new SceneAPI::DataTypes::MockIMeshVertexColorData())
, m_sampleColor({1.f, 0.f, 0.f, 1.f})
{
}
~ColorStreamExporterContextTestBase() override = default;
protected:
// Minimal data subset:
// - Graph contains a single MeshData node
// - MeshData node has a single MeshDataVertexColor child
void SetUp() override
{
CgfExporterContextTestBase::SetUp();
SceneAPI::Containers::SceneGraph& graph = m_stubScene.GetGraph();
SceneAPI::Containers::SceneGraph::NodeIndex rootIndex = graph.GetRoot();
SceneAPI::Containers::SceneGraph::NodeIndex meshIndex = graph.AddChild(rootIndex, "sampleMeshData", m_stubMeshData);
UpdateNodeIndex(meshIndex);
graph.AddChild(m_sampleNodeIndex, "sampleMeshVertexColorData", m_stubMeshVertexColorData);
m_outMesh.SetVertexCount(3);
EXPECT_CALL(*m_stubMeshData, GetVertexCount())
.WillRepeatedly(Return(3));
EXPECT_CALL(*m_stubMeshVertexColorData, GetCount())
.WillRepeatedly(Return(3));
EXPECT_CALL(*m_stubMeshVertexColorData, GetColor(_))
.WillRepeatedly(ReturnRef(m_sampleColor));
}
bool TestCausedNoChanges()
{
CMesh emptyMesh;
emptyMesh.SetVertexCount(3);
return emptyMesh.CompareStreams(m_outMesh);
}
AZStd::shared_ptr<SceneAPI::DataTypes::MockIMeshData> m_stubMeshData;
AZStd::shared_ptr<SceneAPI::DataTypes::MockIMeshVertexColorData> m_stubMeshVertexColorData;
ColorStreamExporter m_testExporter;
AZ::SceneAPI::DataTypes::Color m_sampleColor;
};
class ColorStreamExporterNoOpTests
: public ColorStreamExporterContextTestBase
{
public:
~ColorStreamExporterNoOpTests() override = default;
};
TEST_P(ColorStreamExporterNoOpTests, Process_UnsupportedContext_MeshRemainsEmpty)
{
m_testExporter.Process(m_stubContext);
EXPECT_TRUE(TestCausedNoChanges());
}
static const ContextPhaseTuple g_CgfColorStreamExporterTestsunsupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Construction },
{ TestContextMeshGroup, Phase::Filling },
{ TestContextMeshGroup, Phase::Finalizing },
{ TestContextContainer, Phase::Construction },
{ TestContextContainer, Phase::Filling },
{ TestContextContainer, Phase::Finalizing },
{ TestContextNode, Phase::Construction },
{ TestContextNode, Phase::Filling },
{ TestContextNode, Phase::Finalizing },
{ TestContextMeshNode, Phase::Construction },
{ TestContextMeshNode, Phase::Finalizing }
};
INSTANTIATE_TEST_CASE_P(ColorStreamExporter,
ColorStreamExporterNoOpTests,
::testing::ValuesIn(g_CgfColorStreamExporterTestsunsupportedContextPhaseTuples));
class ColorStreamExporterSimpleTests
: public ColorStreamExporterContextTestBase
{
public:
~ColorStreamExporterSimpleTests() override = default;
};
// Need a new way to test as ColorStreamExporter is update to derive from CallProcessorBinder
//TEST_P(ColorStreamExporterSimpleTests, Process_SupportedContext_MeshIsNotEmpty)
//{
// m_testExporter.Process(m_stubContext);
// EXPECT_TRUE(!TestCausedNoChanges());
//}
static const ContextPhaseTuple g_CgfColorStreamExporterTestsSupportedContextPhaseTuples[] =
{
{ TestContextMeshNode, Phase::Filling }
};
INSTANTIATE_TEST_CASE_P(ColorStreamExporter,
ColorStreamExporterSimpleTests,
::testing::ValuesIn(g_CgfColorStreamExporterTestsSupportedContextPhaseTuples));
} // namespace RC
} // namespace AZ
@@ -0,0 +1,121 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <RC/ResourceCompilerScene/Tests/Cgf/CgfExportContextTestBase.h>
#include <RC/ResourceCompilerScene/Common/ContainerSettingsExporter.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/ManifestBase/MockISceneNodeSelectionList.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/Rules/MockIMeshAdvancedRule.h>
namespace AZ
{
namespace RC
{
using ::testing::Const;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::_;
class ContainerSettingsExporterContextTestBase
: public CgfExporterContextTestBase
{
public:
ContainerSettingsExporterContextTestBase()
: m_stubMeshAdvancedRule(new SceneAPI::DataTypes::MockIMeshAdvancedRule())
{
m_ruleContainer.AddRule(m_stubMeshAdvancedRule);
}
~ContainerSettingsExporterContextTestBase() override = default;
protected:
// Minimal subset for check
// - Group has advanced rule
// - Advanced rule defines 32 bit vertex precision to be true
void SetUp() override
{
CgfExporterContextTestBase::SetUp();
EXPECT_CALL(*m_stubMeshAdvancedRule, Use32bitVertices())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_stubMeshAdvancedRule, MergeMeshes())
.WillRepeatedly(Return(false));
ON_CALL(m_stubMeshGroup, GetRuleContainer())
.WillByDefault(ReturnRef(m_ruleContainer));
ON_CALL(Const(m_stubMeshGroup), GetRuleContainerConst())
.WillByDefault(ReturnRef(m_ruleContainer));
}
bool TestDataChanged()
{
return m_outContent.GetExportInfo()->bWantF32Vertices;
}
AZStd::shared_ptr<SceneAPI::DataTypes::MockIMeshAdvancedRule> m_stubMeshAdvancedRule;
SceneAPI::Containers::RuleContainer m_ruleContainer;
ContainerSettingsExporter m_testExporter;
};
class ContainerSettingsExporterNoOpTests
: public ContainerSettingsExporterContextTestBase
{
public:
~ContainerSettingsExporterNoOpTests() override = default;
};
TEST_P(ContainerSettingsExporterNoOpTests, Process_UnsupportedContext_ExportInfoNotChanged)
{
m_testExporter.Process(m_stubContext);
EXPECT_FALSE(TestDataChanged());
}
static const ContextPhaseTuple g_CgfContainerSettingsExporterTestsUnsupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Construction },
{ TestContextMeshGroup, Phase::Filling },
{ TestContextMeshGroup, Phase::Finalizing },
{ TestContextContainer, Phase::Filling },
{ TestContextContainer, Phase::Finalizing },
{ TestContextNode, Phase::Construction },
{ TestContextNode, Phase::Filling },
{ TestContextNode, Phase::Finalizing },
{ TestContextMeshNode, Phase::Construction },
{ TestContextMeshNode, Phase::Filling },
{ TestContextMeshNode, Phase::Finalizing }
};
INSTANTIATE_TEST_CASE_P(ContainerSettingsExporter,
ContainerSettingsExporterNoOpTests,
::testing::ValuesIn(g_CgfContainerSettingsExporterTestsUnsupportedContextPhaseTuples));
class ContainerSettingsExporterSimpleTests
: public ContainerSettingsExporterContextTestBase
{
public:
~ContainerSettingsExporterSimpleTests() override = default;
};
TEST_P(ContainerSettingsExporterSimpleTests, Process_SupportedContext_ExportInfoChanged)
{
m_testExporter.Process(m_stubContext);
EXPECT_TRUE(TestDataChanged());
}
static const ContextPhaseTuple g_CgfContainerSettingsExporterTestsSupportedContextPhaseTuples[] =
{
{TestContextContainer, Phase::Construction}
};
INSTANTIATE_TEST_CASE_P(ContainerSettingsExporter,
ContainerSettingsExporterSimpleTests,
::testing::ValuesIn(g_CgfContainerSettingsExporterTestsSupportedContextPhaseTuples));
} // namespace RC
} // namespace AZ
@@ -0,0 +1,120 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <Cry_Geo.h>
#include <Mocks/MockCGFContent.h>
#include <RC/ResourceCompilerScene/Common/CommonExportContexts.h>
#include <RC/ResourceCompilerScene/Cgf/CgfExportContexts.h>
#include <SceneAPI/SceneCore/Events/CallProcessorBus.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Events/ExportProductList.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/Groups/MockIMeshGroup.h>
#include <gmock/gmock.h>
#pragma once
namespace AZ
{
namespace RC
{
using ::testing::StrictMock;
namespace SceneEvents = SceneAPI::Events;
enum TestContextType
{
TestContextMeshGroup,
TestContextContainer,
TestContextNode,
TestContextMeshNode,
TestContextCount
};
typedef AZStd::pair<TestContextType, Phase> ContextPhaseTuple;
class CgfExporterContextTestBase
: public ::testing::TestWithParam<ContextPhaseTuple>
{
public:
CgfExporterContextTestBase()
: m_stubScene(m_sampleSceneName)
, m_outContent(m_sampleOutputDirectory.c_str())
, m_sampleNodeIndex(m_stubScene.GetGraph().Find("InvalidNodeName"))
, m_stubContext(nullptr)
, m_stubMeshGroupExportContext(m_productList, m_stubScene, m_sampleOutputDirectory, m_stubMeshGroup, GetParam().second)
, m_stubContainerExportContext(m_stubScene, m_sampleOutputDirectory, m_stubMeshGroup, m_outContent, GetParam().second)
, m_stubNodeExportContext(m_stubContainerExportContext, m_outNode, m_sampleNodeName, m_sampleNodeIndex, m_samplePhysGeomType, m_sampleRootBoneName, GetParam().second)
, m_stubMeshNodeExportContext(m_stubNodeExportContext, m_outMesh, GetParam().second)
{
m_outContent.GetExportInfo()->bWantF32Vertices = false;
}
~CgfExporterContextTestBase() override = default;
protected:
void SetUp() override
{
switch(GetParam().first)
{
case TestContextMeshGroup:
m_stubContext = &m_stubMeshGroupExportContext;
break;
case TestContextContainer:
m_stubContext = &m_stubContainerExportContext;
break;
case TestContextNode:
m_stubContext = &m_stubNodeExportContext;
break;
case TestContextMeshNode:
m_stubContext = &m_stubMeshNodeExportContext;
break;
default:
m_stubContext = nullptr;
break;
}
}
void TearDown() override
{
}
void UpdateNodeIndex(SceneAPI::Containers::SceneGraph::NodeIndex nodeIndex)
{
m_sampleNodeIndex = nodeIndex;
m_stubNodeExportContext.m_nodeIndex = nodeIndex;
m_stubMeshNodeExportContext.m_nodeIndex = nodeIndex;
}
// Sample Context Data Payloads
AZ::SceneAPI::Events::ExportProductList m_productList;
AZStd::string m_sampleSceneName = "SampleScene";
SceneAPI::Containers::Scene m_stubScene;
AZStd::string m_sampleOutputDirectory = "TEST:\\Sample\\Output";
AZStd::string m_sampleGroupName = "SampleGroupName";
SceneAPI::DataTypes::MockIMeshGroup m_stubMeshGroup;
CContentCGF m_outContent;
CNodeCGF m_outNode;
AZStd::string m_sampleNodeName = "SampleNodeName";
// Note that m_sampleNodeIndex will always be invalid and fetched using a non existent node
// from the graph. This is not important for the tests, just needs to be present as a parameter
SceneAPI::Containers::SceneGraph::NodeIndex m_sampleNodeIndex;
EPhysicsGeomType m_samplePhysGeomType = PHYS_GEOM_TYPE_NONE;
AZStd::string m_sampleRootBoneName;
CMesh m_outMesh;
// Sample Context Types
SceneEvents::ICallContext* m_stubContext;
CgfGroupExportContext m_stubMeshGroupExportContext;
ContainerExportContext m_stubContainerExportContext;
NodeExportContext m_stubNodeExportContext;
MeshNodeExportContext m_stubMeshNodeExportContext;
};
}
}
@@ -0,0 +1,135 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <Cry_Geo.h> // Needed for Cry_Matrix34.h
#include <IIndexedMesh.h>
#include <CGFContent.h>
#include <ConvertContext.h>
#include <RC/ResourceCompilerScene/Tests/Cgf/CgfExportContextTestBase.h>
#include <RC/ResourceCompilerScene/Common/MaterialExporter.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/ManifestBase/MockISceneNodeSelectionList.h>
namespace AZ
{
namespace RC
{
class MaterialExporterContextTestBase
: public CgfExporterContextTestBase
{
public:
MaterialExporterContextTestBase()
: m_cacheGenerationContext(m_productList, m_stubScene, m_sampleOutputDirectory, m_stubMeshGroup, Phase::Construction)
, m_testExporter()
{
}
~MaterialExporterContextTestBase() override = default;
protected:
static const size_t s_testFaceCount = 3;
static const unsigned char s_testDefaultSubset = 0;
void SetUp() override
{
CgfExporterContextTestBase::SetUp();
m_outContent.SetCommonMaterial(nullptr);
m_outNode.pMaterial = nullptr;
// We require a MeshGroupContext in the Construction phase for correct behavior of
// all other contexts
m_testExporter.Process(&m_cacheGenerationContext);
}
virtual bool TestChangedData()
{
if (m_outContent.GetCommonMaterial() != nullptr)
{
return true;
}
if (m_outNode.pMaterial != nullptr)
{
return true;
}
return false;
}
ConvertContext m_convertContext;
CgfGroupExportContext m_cacheGenerationContext;
MaterialExporter m_testExporter;
};
class MaterialExporterNoOpTests
: public MaterialExporterContextTestBase
{
public:
~MaterialExporterNoOpTests() override = default;
protected:
// To
void SetUp() override
{
MaterialExporterContextTestBase::SetUp();
}
};
TEST_P(MaterialExporterNoOpTests, Process_UnsupportedContext_DataNotChanged)
{
m_testExporter.Process(m_stubContext);
EXPECT_FALSE(TestChangedData());
}
static const ContextPhaseTuple g_CgfMaterialExporterTestsUnsupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Filling },
{ TestContextMeshGroup, Phase::Finalizing }, // Technically changes, but only internal state
{ TestContextContainer, Phase::Filling },
{ TestContextNode, Phase::Construction },
{ TestContextNode, Phase::Finalizing },
{ TestContextMeshNode, Phase::Construction },
{ TestContextMeshNode, Phase::Finalizing }
};
INSTANTIATE_TEST_CASE_P(MaterialExporter,
MaterialExporterNoOpTests,
::testing::ValuesIn(g_CgfMaterialExporterTestsUnsupportedContextPhaseTuples));
class MaterialExporterContainerContextTests
: public MaterialExporterContextTestBase
{
public:
~MaterialExporterContainerContextTests() override = default;
protected:
// To
void SetUp() override
{
MaterialExporterContextTestBase::SetUp();
}
};
// Tests still required
// ContainerContext/Finalizing - Should be trivial
// NodeContext/Filling - Will require complex setup of internal cache
// MeshNodeContext/Filling - Will require complex setup of internal cache
static const ContextPhaseTuple g_CgfMaterialExporterTestsSupportedContextPhaseTuples[] =
{
{ TestContextContainer, Phase::Construction }
};
INSTANTIATE_TEST_CASE_P(MaterialExporter,
MaterialExporterContainerContextTests,
::testing::ValuesIn(g_CgfMaterialExporterTestsSupportedContextPhaseTuples));
} // namespace RC
} // namespace AZ
@@ -0,0 +1,121 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <RC/ResourceCompilerScene/Tests/Cgf/CgfExportContextTestBase.h>
#include <RC/ResourceCompilerScene/Common/MeshExporter.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/ManifestBase/MockISceneNodeSelectionList.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/GraphData/MockIMeshData.h>
namespace AZ
{
namespace RC
{
using ::testing::Return;
class MeshExporterContextTestBase
: public CgfExporterContextTestBase
{
public:
MeshExporterContextTestBase()
: m_stubMeshData(new SceneAPI::DataTypes::MockIMeshData())
{
}
~MeshExporterContextTestBase() override = default;
protected:
// Minimal subset for a valid Processing pass
void SetUp() override
{
CgfExporterContextTestBase::SetUp();
SceneAPI::Containers::SceneGraph& graph = m_stubScene.GetGraph();
SceneAPI::Containers::SceneGraph::NodeIndex rootIndex = graph.GetRoot();
SceneAPI::Containers::SceneGraph::NodeIndex meshIndex = graph.AddChild(rootIndex, "sampleMeshData", m_stubMeshData);
UpdateNodeIndex(meshIndex);
m_outMesh.SetVertexCount(3);
m_outContent.GetExportInfo()->bNoMesh = true;
}
bool TestChangedData()
{
return !m_outContent.GetExportInfo()->bNoMesh;
}
AZStd::shared_ptr<SceneAPI::DataTypes::MockIMeshData> m_stubMeshData;
MeshExporter m_testExporter;
};
class MeshExporterNoOpTests
: public MeshExporterContextTestBase
{
public:
~MeshExporterNoOpTests() override = default;
};
TEST_P(MeshExporterNoOpTests, Process_UnsupportedContext_ContentNotChanged)
{
m_testExporter.Process(m_stubContext);
EXPECT_FALSE(TestChangedData());
}
static const ContextPhaseTuple g_CgfMeshExporterTestsUnsupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Construction },
{ TestContextMeshGroup, Phase::Filling },
{ TestContextMeshGroup, Phase::Finalizing },
{ TestContextContainer, Phase::Construction },
{ TestContextContainer, Phase::Filling },
{ TestContextContainer, Phase::Finalizing },
{ TestContextNode, Phase::Construction },
{ TestContextNode, Phase::Finalizing },
{ TestContextMeshNode, Phase::Construction },
{ TestContextMeshNode, Phase::Filling },
{ TestContextMeshNode, Phase::Finalizing }
};
INSTANTIATE_TEST_CASE_P(MeshExporter,
MeshExporterNoOpTests,
::testing::ValuesIn(g_CgfMeshExporterTestsUnsupportedContextPhaseTuples));
class MeshExporterSimpleTests
: public MeshExporterContextTestBase
{
public:
~MeshExporterSimpleTests() override = default;
};
TEST_P(MeshExporterSimpleTests, Process_SupportedContext_ContentChanged)
{
EXPECT_CALL(*m_stubMeshData, GetVertexCount())
.WillRepeatedly(Return(0));
EXPECT_CALL(*m_stubMeshData, GetFaceCount())
.WillRepeatedly(Return(0));
EXPECT_CALL(*m_stubMeshData, HasNormalData())
.WillRepeatedly(Return(false));
m_testExporter.Process(&m_stubNodeExportContext);
EXPECT_TRUE(TestChangedData());
}
static const ContextPhaseTuple g_CgfMeshExporterTestsSupportedContextPhaseTuples[] =
{
{TestContextNode, Phase::Filling}
};
INSTANTIATE_TEST_CASE_P(MeshExporter,
MeshExporterSimpleTests,
::testing::ValuesIn(g_CgfMeshExporterTestsSupportedContextPhaseTuples));
} // namespace RC
} // namespace AZ
@@ -0,0 +1,113 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <RC/ResourceCompilerScene/Tests/Cgf/CgfExportContextTestBase.h>
#include <RC/ResourceCompilerScene/Cgf/CgfExportContexts.h>
#include <RC/ResourceCompilerScene/Cgf/CgfGroupExporter.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/ManifestBase/MockISceneNodeSelectionList.h>
namespace AZ
{
namespace RC
{
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::Const;
class CgfGroupExporterContextTestBase
: public CgfExporterContextTestBase
{
public:
CgfGroupExporterContextTestBase()
: m_testExporter(&m_mockAssetWriter)
{
}
~CgfGroupExporterContextTestBase() override = default;
protected:
StrictMock<MockIAssetWriter> m_mockAssetWriter;
CgfGroupExporter m_testExporter;
};
class CgfGroupExporterNoOpTests
: public CgfGroupExporterContextTestBase
{
public:
~CgfGroupExporterNoOpTests() override = default;
};
TEST_P(CgfGroupExporterNoOpTests, Process_UnsupportedContext_WriterNotUsed)
{
m_testExporter.Process(m_stubContext);
}
static const ContextPhaseTuple g_CgfMeshGroupExporterTestsUnsupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Construction },
{ TestContextMeshGroup, Phase::Finalizing },
{ TestContextContainer, Phase::Construction },
{ TestContextContainer, Phase::Filling },
{ TestContextContainer, Phase::Finalizing },
{ TestContextNode, Phase::Construction },
{ TestContextNode, Phase::Filling },
{ TestContextNode, Phase::Finalizing },
{ TestContextMeshNode, Phase::Construction },
{ TestContextMeshNode, Phase::Filling },
{ TestContextMeshNode, Phase::Finalizing }
};
INSTANTIATE_TEST_CASE_P(MeshGroupExporter,
CgfGroupExporterNoOpTests,
::testing::ValuesIn(g_CgfMeshGroupExporterTestsUnsupportedContextPhaseTuples));
class CgfGroupExporterSimpleTestFramework
: public CgfGroupExporterContextTestBase
{
public:
~CgfGroupExporterSimpleTestFramework() override = default;
protected:
void SetUp() override
{
}
void TearDown() override
{
}
SceneAPI::DataTypes::MockISceneNodeSelectionList m_stubSceneNodeSelectionList;
};
TEST_P(CgfGroupExporterSimpleTestFramework, Process_SupportedContextNoNodesSelected_WriterNotUsed)
{
AZStd::string testGroupName = "testName";
EXPECT_CALL(m_stubSceneNodeSelectionList, GetSelectedNodeCount())
.WillRepeatedly(Return(0));
EXPECT_CALL(m_stubSceneNodeSelectionList, GetUnselectedNodeCount())
.WillRepeatedly(Return(0));
EXPECT_CALL(Const(m_stubMeshGroup), GetSceneNodeSelectionList())
.WillRepeatedly(ReturnRef(m_stubSceneNodeSelectionList));
EXPECT_CALL(m_stubMeshGroup, GetName())
.WillRepeatedly(ReturnRef(testGroupName));
m_testExporter.Process(&m_stubMeshGroupExportContext);
}
static const ContextPhaseTuple g_CgfMeshGroupExporterTestsSupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Filling }
};
INSTANTIATE_TEST_CASE_P(MeshGroupExporter,
CgfGroupExporterSimpleTestFramework,
::testing::ValuesIn(g_CgfMeshGroupExporterTestsSupportedContextPhaseTuples));
} // namespace RC
} // namespace AZ
@@ -0,0 +1,137 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <RC/ResourceCompilerScene/Tests/Cgf/CgfExportContextTestBase.h>
#include <RC/ResourceCompilerScene/Cgf/CgfExportContexts.h>
#include <RC/ResourceCompilerScene/Common/UVStreamExporter.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/GraphData/MockIMeshData.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/GraphData/MockIMeshVertexUVData.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/ManifestBase/MockISceneNodeSelectionList.h>
namespace AZ
{
namespace RC
{
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::_;
class UVStreamExporterContextTestBase
: public CgfExporterContextTestBase
{
public:
UVStreamExporterContextTestBase()
: m_stubMeshData(new SceneAPI::DataTypes::MockIMeshData())
, m_stubMeshVertexUVData(new SceneAPI::DataTypes::MockIMeshVertexUVData())
{
}
~UVStreamExporterContextTestBase() override = default;
protected:
// Minimal data subset:
// - Graph contains a single MeshData node
// - MeshData node has a single MeshDataVertexColor child
void SetUp() override
{
CgfExporterContextTestBase::SetUp();
SceneAPI::Containers::SceneGraph& graph = m_stubScene.GetGraph();
SceneAPI::Containers::SceneGraph::NodeIndex rootIndex = graph.GetRoot();
SceneAPI::Containers::SceneGraph::NodeIndex meshIndex = graph.AddChild(rootIndex, "sampleMeshData", m_stubMeshData);
UpdateNodeIndex(meshIndex);
graph.AddChild(m_sampleNodeIndex, "sampleMeshVertexColorData", m_stubMeshVertexUVData);
m_outMesh.SetVertexCount(3);
m_uvs.push_back(AZ::Vector2(0.f, 0.f));
m_uvs.push_back(AZ::Vector2(1.f, 0.f));
m_uvs.push_back(AZ::Vector2(1.f, 1.f));
EXPECT_CALL(*m_stubMeshData, GetVertexCount())
.WillRepeatedly(Return(3));
EXPECT_CALL(*m_stubMeshVertexUVData, GetCount())
.WillRepeatedly(Return(3));
EXPECT_CALL(*m_stubMeshVertexUVData, GetUV(0))
.WillRepeatedly(ReturnRef(m_uvs[0]));
EXPECT_CALL(*m_stubMeshVertexUVData, GetUV(1))
.WillRepeatedly(ReturnRef(m_uvs[1]));
EXPECT_CALL(*m_stubMeshVertexUVData, GetUV(2))
.WillRepeatedly(ReturnRef(m_uvs[2]));
}
bool TestCausedNoChanges()
{
CMesh emptyMesh;
emptyMesh.SetVertexCount(3);
return emptyMesh.CompareStreams(m_outMesh);
}
AZStd::shared_ptr<SceneAPI::DataTypes::MockIMeshData> m_stubMeshData;
AZStd::shared_ptr<SceneAPI::DataTypes::MockIMeshVertexUVData> m_stubMeshVertexUVData;
UVStreamExporter m_testExporter;
AZStd::vector<AZ::Vector2> m_uvs;
};
class UVStreamExporterNoOpTests
: public UVStreamExporterContextTestBase
{
public:
~UVStreamExporterNoOpTests() override = default;
};
TEST_P(UVStreamExporterNoOpTests, Process_UnsupportedContext_OutDataNotChanged)
{
m_testExporter.Process(m_stubContext);
EXPECT_TRUE(TestCausedNoChanges());
}
static const ContextPhaseTuple g_CgfUVStreamExporterTestsUnsupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Construction },
{ TestContextMeshGroup, Phase::Filling },
{ TestContextMeshGroup, Phase::Finalizing },
{ TestContextContainer, Phase::Construction },
{ TestContextContainer, Phase::Filling },
{ TestContextContainer, Phase::Finalizing },
{ TestContextNode, Phase::Construction },
{ TestContextNode, Phase::Filling },
{ TestContextNode, Phase::Finalizing },
{ TestContextMeshNode, Phase::Construction },
{ TestContextMeshNode, Phase::Finalizing }
};
INSTANTIATE_TEST_CASE_P(UVStreamExporter,
UVStreamExporterNoOpTests,
::testing::ValuesIn(g_CgfUVStreamExporterTestsUnsupportedContextPhaseTuples));
class UVStreamExporterSimpleTests
: public UVStreamExporterContextTestBase
{
public:
~UVStreamExporterSimpleTests() override = default;
};
TEST_P(UVStreamExporterSimpleTests, Process_SupportedContext_OutDataChanged)
{
m_testExporter.Process(&m_stubMeshNodeExportContext);
EXPECT_FALSE(TestCausedNoChanges());
}
static const ContextPhaseTuple g_CgfUVStreamExporterTestsSupportedContextPhaseTuples[] = {
{TestContextMeshNode, Phase::Filling}
};
INSTANTIATE_TEST_CASE_P(UVStreamExporter,
UVStreamExporterSimpleTests,
::testing::ValuesIn(g_CgfUVStreamExporterTestsSupportedContextPhaseTuples));
} // namespace RC
} // namespace AZ
@@ -0,0 +1,143 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <Cry_Geo.h> // Needed for Cry_Matrix34.h
#include <Cry_Matrix34.h>
#include <RC/ResourceCompilerScene/Tests/Cgf/CgfExportContextTestBase.h>
#include <RC/ResourceCompilerScene/Cgf/CgfExportContexts.h>
#include <RC/ResourceCompilerScene/Common/WorldMatrixExporter.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/GraphData/MockITransform.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/GraphData/MockIMeshData.h>
#include <SceneAPI/SceneCore/Mocks/DataTypes/ManifestBase/MockISceneNodeSelectionList.h>
namespace AZ
{
namespace RC
{
using ::testing::Const;
using ::testing::Return;
using ::testing::ReturnRef;
class WorldMatrixExporterContextTestBase
: public CgfExporterContextTestBase
{
public:
WorldMatrixExporterContextTestBase()
: m_stubTransformData(new SceneAPI::DataTypes::MockITransform())
, m_stubMeshData(new SceneAPI::DataTypes::MockIMeshData())
, m_stubTransform(AZ::SceneAPI::DataTypes::MatrixType::CreateTranslation(AZ::Vector3(0.f, 0.f, 1.f)))
{
}
~WorldMatrixExporterContextTestBase() override = default;
protected:
void SetUp()
{
CgfExporterContextTestBase::SetUp();
m_outNode.bIdentityMatrix = true;
SceneAPI::Containers::SceneGraph& sceneGraph = m_stubScene.GetGraph();
SceneAPI::Containers::SceneGraph::NodeIndex rootIndex = sceneGraph.GetRoot();
SceneAPI::Containers::SceneGraph::NodeIndex transformIndex = sceneGraph.AddChild(rootIndex, "SampleTransformData", m_stubTransformData);
SceneAPI::Containers::SceneGraph::NodeIndex meshIndex = sceneGraph.AddChild(transformIndex, "SampleMeshData", m_stubMeshData);
UpdateNodeIndex(meshIndex);
EXPECT_CALL(Const(*m_stubTransformData), GetMatrix())
.WillRepeatedly(ReturnRef(m_stubTransform));
ON_CALL(m_stubMeshGroup, GetRuleContainer())
.WillByDefault(ReturnRef(m_ruleContainer));
ON_CALL(Const(m_stubMeshGroup), GetRuleContainerConst())
.WillByDefault(ReturnRef(m_ruleContainer));
}
bool TestChangedData()
{
return !m_outNode.bIdentityMatrix;
}
AZStd::shared_ptr<SceneAPI::DataTypes::MockITransform> m_stubTransformData;
AZStd::shared_ptr<SceneAPI::DataTypes::MockIMeshData> m_stubMeshData;
AZ::SceneAPI::DataTypes::MatrixType m_stubTransform;
WorldMatrixExporter m_testExporter;
SceneAPI::Containers::RuleContainer m_ruleContainer;
};
class WorldMatrixExporterNoOpTestFramework
: public WorldMatrixExporterContextTestBase
{
public:
~WorldMatrixExporterNoOpTestFramework() override = default;
};
TEST_P(WorldMatrixExporterNoOpTestFramework, Process_UnsupportedContext_OutNodeAtIndentity)
{
m_testExporter.Process(m_stubContext);
EXPECT_FALSE(TestChangedData());
}
ContextPhaseTuple g_CgfWorldMatrixExporterTestsUnsupportedContextPhaseTuples[] =
{
{ TestContextMeshGroup, Phase::Filling },
{ TestContextMeshGroup, Phase::Finalizing },
{ TestContextContainer, Phase::Construction },
{ TestContextContainer, Phase::Filling },
{ TestContextContainer, Phase::Finalizing },
{ TestContextNode, Phase::Construction },
{ TestContextNode, Phase::Finalizing },
{ TestContextMeshNode, Phase::Construction },
{ TestContextMeshNode, Phase::Filling },
{ TestContextMeshNode, Phase::Finalizing }
};
INSTANTIATE_TEST_CASE_P(WorldMatrixExporter,
WorldMatrixExporterNoOpTestFramework,
::testing::ValuesIn(g_CgfWorldMatrixExporterTestsUnsupportedContextPhaseTuples));
class WorldMatrixExporterSimpleTests
: public WorldMatrixExporterContextTestBase
{
public:
WorldMatrixExporterSimpleTests()
: m_cacheGenerationContext(m_productList, m_stubScene, m_sampleOutputDirectory, m_stubMeshGroup, Phase::Construction)
{
}
~WorldMatrixExporterSimpleTests() override = default;
protected:
void SetUp() override
{
WorldMatrixExporterContextTestBase::SetUp();
m_testExporter.Process(&m_cacheGenerationContext);
}
CgfGroupExportContext m_cacheGenerationContext;
};
// Disable the test due to an assert that checking consistency of cached mesh group which lacks a way to support currently
//TEST_P(WorldMatrixExporterSimpleTests, Process_SupportedContext_OutNodeNotAtIndentity)
//{
// m_testExporter.Process(m_stubContext);
// EXPECT_TRUE(TestChangedData());
//}
ContextPhaseTuple g_CgfWorldMatrixExporterTestsSupportedContextPhaseTuples[] =
{
{ TestContextNode, Phase::Filling }
};
INSTANTIATE_TEST_CASE_P(WorldMatrixExporter,
WorldMatrixExporterSimpleTests,
::testing::ValuesIn(g_CgfWorldMatrixExporterTestsSupportedContextPhaseTuples));
} // namespace RC
} // namespace AZ
@@ -0,0 +1,88 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzTest/AzTest.h>
#include <AzCore/Module/Environment.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Module/DynamicModuleHandle.h>
class ResourceCompilerSceneTestEnvironment
: public AZ::Test::ITestEnvironment
{
public:
virtual ~ResourceCompilerSceneTestEnvironment()
{}
protected:
void SetupEnvironment() override
{
if (!AZ::AllocatorInstance<AZ::SystemAllocator>().IsReady())
{
AZ::AllocatorInstance<AZ::SystemAllocator>().Create();
m_hasLocalMemoryAllocator = true;
}
{
sceneCoreModule = AZ::DynamicModuleHandle::Create("SceneCore");
AZ_Assert(sceneCoreModule, "ResourceCompilerScene unit tests failed to create SceneCore module.");
bool loaded = sceneCoreModule->Load(false);
AZ_Assert(loaded, "ResourceCompilerScene unit tests failed to load SceneCore module.");
auto init = sceneCoreModule->GetFunction<AZ::InitializeDynamicModuleFunction>(AZ::InitializeDynamicModuleFunctionName);
AZ_Assert(init, "ResourceCompilerScene unit tests failed to find the initialization function the SceneCore module.");
(*init)(AZ::Environment::GetInstance());
}
{
sceneDataModule = AZ::DynamicModuleHandle::Create("SceneData");
AZ_Assert(sceneDataModule, "ResourceCompilerScene unit tests failed to create SceneData module.");
bool loaded = sceneDataModule->Load(false);
AZ_Assert(loaded, "ResourceCompilerScene unit tests failed to load SceneData module.");
auto init = sceneDataModule->GetFunction<AZ::InitializeDynamicModuleFunction>(AZ::InitializeDynamicModuleFunctionName);
AZ_Assert(init, "ResourceCompilerScene unit tests failed to find the initialization function the SceneData module.");
(*init)(AZ::Environment::GetInstance());
}
{
fbxSceneBuilderModule = AZ::DynamicModuleHandle::Create("FbxSceneBuilder");
AZ_Assert(fbxSceneBuilderModule, "ResourceCompilerScene unit tests failed to create FbxSceneBuilder module.");
bool loaded = fbxSceneBuilderModule->Load(false);
AZ_Assert(loaded, "ResourceCompilerScene unit tests failed to load FbxSceneBuilder module.");
}
}
void TeardownEnvironment() override
{
fbxSceneBuilderModule.reset();
auto uninit = sceneDataModule->GetFunction<AZ::UninitializeDynamicModuleFunction>(AZ::UninitializeDynamicModuleFunctionName);
AZ_Assert(uninit, "FbxSceneBuilder unit tests failed to find the uninitialization function the SceneData module.");
(*uninit)();
sceneDataModule.reset();
uninit = sceneCoreModule->GetFunction<AZ::UninitializeDynamicModuleFunction>(AZ::UninitializeDynamicModuleFunctionName);
AZ_Assert(uninit, "FbxSceneBuilder unit tests failed to find the uninitialization function the SceneCore module.");
(*uninit)();
sceneCoreModule.reset();
if (m_hasLocalMemoryAllocator)
{
AZ::AllocatorInstance<AZ::SystemAllocator>().Destroy();
}
}
private:
bool m_hasLocalMemoryAllocator = false;
AZStd::unique_ptr<AZ::DynamicModuleHandle> sceneCoreModule;
AZStd::unique_ptr<AZ::DynamicModuleHandle> sceneDataModule;
AZStd::unique_ptr<AZ::DynamicModuleHandle> fbxSceneBuilderModule;
};
AZ_UNIT_TEST_HOOK(new ResourceCompilerSceneTestEnvironment);