Merge branch 'main' into SpawnableIndexQuery

This commit is contained in:
AMZN-koppersr
2021-05-26 09:48:20 -07:00
411 changed files with 34696 additions and 4469 deletions
@@ -11,6 +11,7 @@
*/
#include <AzTest/AzTest.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/UnitTest/UnitTest.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
@@ -40,6 +41,13 @@ namespace UnitTest
void SetUp() override
{
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_application->Start({});
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
+9
View File
@@ -16,6 +16,7 @@
#include <AzCore/UnitTest/UnitTest.h>
#include <AzCore/IO/SystemFile.h> // for max path decl
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/std/parallel/thread.h>
#include <AzCore/std/parallel/semaphore.h>
#include <AzCore/std/functional.h> // for function<> in the find files callback.
@@ -42,6 +43,14 @@ namespace UnitTest
{
AZ::ComponentApplication::Descriptor descriptor;
descriptor.m_stackRecordLevels = 30;
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_application->Start(descriptor);
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
+8
View File
@@ -23,6 +23,7 @@
#include <AzCore/Math/Uuid.h>
#include <AzCore/Memory/Memory.h>
#include <AzCore/Memory/PoolAllocator.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
@@ -304,6 +305,13 @@ namespace UnitTest
m_app.reset(aznew AzFramework::Application());
AZ::ComponentApplication::Descriptor desc;
desc.m_useExistingAllocator = true;
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_app->Start(desc);
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
@@ -12,6 +12,7 @@
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Outcome/Outcome.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
@@ -572,6 +573,12 @@ namespace UnitTest
{
AllocatorsTestFixture::SetUp();
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
AzFramework::Application::Descriptor descriptor;
descriptor.m_enableDrilling = false;
m_app.Start(descriptor);
+7
View File
@@ -17,6 +17,7 @@
#include <AzCore/Serialization/Json/JsonSerialization.h>
#include <AzCore/Serialization/Json/JsonSystemComponent.h>
#include <AzCore/Serialization/Json/RegistrationContext.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Utils/Utils.h>
#include <AzFramework/FileFunc/FileFunc.h>
@@ -278,6 +279,12 @@ namespace UnitTest
{
FrameworkApplicationFixture::SetUp();
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
m_jsonRegistrationContext = AZStd::make_unique<AZ::JsonRegistrationContext>();
m_jsonSystemComponent = AZStd::make_unique<AZ::JsonSystemComponent>();
+1
View File
@@ -83,6 +83,7 @@ namespace UnitTest
void SetUp() override
{
AllocatorsFixture::SetUp();
m_data = AZStd::make_unique<StaticData>();
using namespace AzFramework::FileTag;
AZ::ComponentApplication::Descriptor desc;
@@ -54,7 +54,7 @@ namespace UnitTest
};
void SetUp() override
{
{
m_appDescriptor.m_allocationRecords = true;
m_appDescriptor.m_allocationRecordsSaveNames = true;
m_appDescriptor.m_recordingMode = AZ::Debug::AllocationRecords::Mode::RECORD_FULL;
@@ -12,6 +12,7 @@
#include <AzTest/AzTest.h>
#include <AzCore/Slice/SliceComponent.h>
#include <AzCore/Serialization/Utils.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
#include <AzToolsFramework/ToolsComponents/GenericComponentWrapper.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
@@ -59,6 +60,12 @@ class WrappedEditorComponentTest
protected:
void SetUp() override
{
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_app.Start(AZ::ComponentApplication::Descriptor());
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
@@ -178,6 +185,12 @@ class FindWrappedComponentsTest
public:
void SetUp() override
{
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_app.Start(AzFramework::Application::Descriptor());
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
+77 -18
View File
@@ -14,6 +14,7 @@
#include <AzCore/Console/IConsole.h>
#include <AzCore/Console/Console.h>
#include <AzCore/Name/NameDictionary.h>
#include <AzCore/Console/IConsole.h>
#include <AzFramework/Visibility/OctreeSystemComponent.h>
#include <random>
@@ -94,6 +95,20 @@ namespace UnitTest
AZ::Console* m_console;
};
void ValidateEntryCountEqualsExpectedCount(const IVisibilityScene* visScene, uint32_t expectedEntryCount)
{
// InsertOrUpdateEntry assumes that updating an existing entry won't change the count
// so it doesn't modify the counter used by GetEntryCount.
// If an entry is removed from the octree as an unintended side effect of updating an existing entry,
// GetEntryCount can't be relied upon to report the actual entry count.
// So manually count the entries when using the entry count for validation.
uint32_t manualEntryCount = 0;
visScene->EnumerateNoCull([&manualEntryCount](const AzFramework::IVisibilityScene::NodeData& nodeData) { manualEntryCount += nodeData.m_entries.size(); });
EXPECT_EQ(manualEntryCount, expectedEntryCount);
EXPECT_EQ(visScene->GetEntryCount(), expectedEntryCount);
}
TEST_F(OctreeTests, InsertDeleteSingleEntry)
{
AzFramework::VisibilityEntry visEntry;
@@ -102,11 +117,11 @@ namespace UnitTest
m_octreeScene->InsertOrUpdateEntry(visEntry);
EXPECT_TRUE(visEntry.m_internalNode != nullptr);
EXPECT_TRUE(visEntry.m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 1);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 1);
m_octreeScene->RemoveEntry(visEntry);
EXPECT_TRUE(visEntry.m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 0);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 0);
EXPECT_TRUE(true); //TEST
}
@@ -121,34 +136,34 @@ namespace UnitTest
m_octreeScene->InsertOrUpdateEntry(visEntry[0]);
EXPECT_TRUE(visEntry[0].m_internalNode != nullptr);
EXPECT_TRUE(visEntry[0].m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 1);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 1);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
m_octreeScene->InsertOrUpdateEntry(visEntry[1]); // This should force a split of the root node
EXPECT_TRUE(visEntry[1].m_internalNode != nullptr);
EXPECT_TRUE(visEntry[1].m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 2);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 2);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1 + m_octreeScene->GetChildNodeCount());
m_octreeScene->InsertOrUpdateEntry(visEntry[2]); // This should force a split of the roots +/+/+ child node
EXPECT_TRUE(visEntry[2].m_internalNode != nullptr);
EXPECT_TRUE(visEntry[2].m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 3);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 3);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1 + (2 * m_octreeScene->GetChildNodeCount()));
m_octreeScene->RemoveEntry(visEntry[2]);
EXPECT_TRUE(visEntry[2].m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 2);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 2);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1 + m_octreeScene->GetChildNodeCount());
m_octreeScene->RemoveEntry(visEntry[1]);
EXPECT_TRUE(visEntry[1].m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 1);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 1);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
m_octreeScene->RemoveEntry(visEntry[0]);
EXPECT_TRUE(visEntry[0].m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 0);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 0);
}
TEST_F(OctreeTests, UpdateSingleEntry)
@@ -159,19 +174,19 @@ namespace UnitTest
m_octreeScene->InsertOrUpdateEntry(visEntry);
EXPECT_TRUE(visEntry.m_internalNode != nullptr);
EXPECT_TRUE(visEntry.m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 1);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 1);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
visEntry.m_boundingVolume = AZ::Aabb::CreateFromMinMax(AZ::Vector3(-0.5f), AZ::Vector3(0.5f));
m_octreeScene->InsertOrUpdateEntry(visEntry);
EXPECT_TRUE(visEntry.m_internalNode != nullptr);
EXPECT_TRUE(visEntry.m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 1);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 1);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
m_octreeScene->RemoveEntry(visEntry);
EXPECT_TRUE(visEntry.m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 0);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 0);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
}
@@ -185,19 +200,19 @@ namespace UnitTest
m_octreeScene->InsertOrUpdateEntry(visEntry[0]);
EXPECT_TRUE(visEntry[0].m_internalNode != nullptr);
EXPECT_TRUE(visEntry[0].m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 1);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 1);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
m_octreeScene->InsertOrUpdateEntry(visEntry[1]); // This should force a split of the root node
EXPECT_TRUE(visEntry[1].m_internalNode != nullptr);
EXPECT_TRUE(visEntry[1].m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 2);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 2);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1 + m_octreeScene->GetChildNodeCount());
m_octreeScene->InsertOrUpdateEntry(visEntry[2]); // This should force a split of the roots +/+/+ child node
EXPECT_TRUE(visEntry[2].m_internalNode != nullptr);
EXPECT_TRUE(visEntry[2].m_internalNodeIndex == 0);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 3);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 3);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1 + (2 * m_octreeScene->GetChildNodeCount()));
visEntry[1].m_boundingVolume = AZ::Aabb::CreateFromMinMax(AZ::Vector3(-0.9f), AZ::Vector3(-0.6f));
@@ -206,22 +221,22 @@ namespace UnitTest
m_octreeScene->InsertOrUpdateEntry(visEntry[0]);
m_octreeScene->InsertOrUpdateEntry(visEntry[1]);
m_octreeScene->InsertOrUpdateEntry(visEntry[2]);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 3);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 3);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1 + (2 * m_octreeScene->GetChildNodeCount()));
m_octreeScene->RemoveEntry(visEntry[2]);
EXPECT_TRUE(visEntry[2].m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 2);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 2);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1 + m_octreeScene->GetChildNodeCount());
m_octreeScene->RemoveEntry(visEntry[1]);
EXPECT_TRUE(visEntry[1].m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 1);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 1);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
m_octreeScene->RemoveEntry(visEntry[0]);
EXPECT_TRUE(visEntry[0].m_internalNode == nullptr);
EXPECT_TRUE(m_octreeScene->GetEntryCount() == 0);
ValidateEntryCountEqualsExpectedCount(m_octreeScene, 0);
EXPECT_TRUE(m_octreeScene->GetNodeCount() == 1);
}
@@ -365,4 +380,48 @@ namespace UnitTest
AZ::Frustum bound3 = AZ::Frustum(AZ::ViewFrustumAttributes(frustumTransform, 1.0f, 2.0f * atanf(0.5f), 2.6f, 2.9f));
EnumerateMultipleEntriesHelper(m_octreeScene, bound1, bound2, bound3);
}
TEST_F(OctreeTests, InsertOrUpdateEntry_OverFillRootNodeWithLargeEntries_EntriesAreNotLost)
{
// Validate that the octree works if you exceed the max entry count with large entries,
// which will overfill the root node since they can't be distributed to child nodes
// Get the max extents and entries-per-node for the octree
AZ::IConsole* console = AZ::Interface<AZ::IConsole>::Get();
EXPECT_TRUE(console);
float maxExtents = 0.0f;
AZ::GetValueResult getCvarResult = console->GetCvarValue("bg_octreeMaxWorldExtents", maxExtents);
EXPECT_EQ(getCvarResult, AZ::GetValueResult::Success);
uint32_t maxEntriesPerNode = 0;
getCvarResult = console->GetCvarValue("bg_octreeNodeMaxEntries", maxEntriesPerNode);
EXPECT_EQ(getCvarResult, AZ::GetValueResult::Success);
// Create root entries that would exceed the size of the root node
AZ::Aabb exceedMaxExtents = AZ::Aabb::CreateFromMinMax(AZ::Vector3(-maxExtents - 1.0f), AZ::Vector3(maxExtents + 1.0f));
uint32_t exceedMaxEntriesPerNode = maxEntriesPerNode + 1;
AzFramework::VisibilityEntry visEntry;
visEntry.m_boundingVolume = exceedMaxExtents;
AZStd::vector<AzFramework::VisibilityEntry> visEntries(exceedMaxEntriesPerNode, visEntry);
// Insert them all into the scene
for (AzFramework::VisibilityEntry& entry : visEntries)
{
m_octreeScene->InsertOrUpdateEntry(entry);
}
// Expect all the entries to be in the scene
ValidateEntryCountEqualsExpectedCount(m_octreeScene, visEntries.size());
// Update them, without making any actual changes
for (AzFramework::VisibilityEntry& entry : visEntries)
{
m_octreeScene->InsertOrUpdateEntry(entry);
}
// Expect all the entries to be in the scene
ValidateEntryCountEqualsExpectedCount(m_octreeScene, visEntries.size());
}
}
+7
View File
@@ -22,6 +22,7 @@
#include <AzCore/Slice/SliceAssetHandler.h>
#include <AzCore/Script/ScriptSystemComponent.h>
#include <AzCore/Script/ScriptAsset.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/std/chrono/chrono.h>
#include <AzCore/RTTI/TypeInfo.h>
#include <AzCore/UnitTest/TestTypes.h>
@@ -1059,6 +1060,12 @@ namespace UnitTest
void SetUp() override
{
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_app.Start(AzFramework::Application::Descriptor());
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
+43 -110
View File
@@ -24,6 +24,8 @@
#include <AzToolsFramework/Application/ToolsApplication.h>
#include <AzToolsFramework/ToolsComponents/TransformComponent.h>
#include <AZTestShared/Math/MathTestHelpers.h>
using namespace AZ;
using namespace AzFramework;
@@ -362,8 +364,8 @@ namespace UnitTest
TEST_F(TransformComponentTransformMatrixSetGet, SetLocalRotation_SimpleValues_Set)
{
// add some scale first
float sx = 1.03f, sy = 0.67f, sz = 1.23f;
Transform tm = Transform::CreateScale(Vector3(sx, sy, sz));
float scale = 1.23f;
Transform tm = Transform::CreateUniformScale(scale);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalTM, tm);
float rx = 42.435f;
@@ -379,13 +381,13 @@ namespace UnitTest
Matrix3x3 finalRotate = rotateX * rotateY * rotateZ;
Vector3 basisX = tm.GetBasisX();
Vector3 expectedBasisX = finalRotate.GetBasisX() * sx;
Vector3 expectedBasisX = finalRotate.GetBasisX() * scale;
EXPECT_TRUE(basisX.IsClose(expectedBasisX));
Vector3 basisY = tm.GetBasisY();
Vector3 expectedBasisY = finalRotate.GetBasisY() * sy;
Vector3 expectedBasisY = finalRotate.GetBasisY() * scale;
EXPECT_TRUE(basisY.IsClose(expectedBasisY));
Vector3 basisZ = tm.GetBasisZ();
Vector3 expectedBasisZ = finalRotate.GetBasisZ() * sz;
Vector3 expectedBasisZ = finalRotate.GetBasisZ() * scale;
EXPECT_TRUE(basisZ.IsClose(expectedBasisZ));
}
@@ -476,18 +478,15 @@ namespace UnitTest
{
TransformBus::Event(m_childId, &TransformBus::Events::RotateAroundLocalX, rx);
}
Vector3 localScale;
TransformBus::EventResult(localScale, m_childId, &TransformBus::Events::GetLocalScale);
EXPECT_TRUE(localScale.IsClose(Vector3(1.0f, 1.0f, 1.0f)));
float localScale = FLT_MAX;
TransformBus::EventResult(localScale, m_childId, &TransformBus::Events::GetLocalUniformScale);
EXPECT_NEAR(localScale, 1.0f, AZ::Constants::Tolerance);
}
TEST_F(TransformComponentTransformMatrixSetGet, RotateAroundLocalX_ScaleDoesNotSkewRotation)
{
float sx = 42.564f;
float sy = 12.460f;
float sz = 28.692f;
Vector3 expectedScales(sx, sy, sz);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalScale, expectedScales);
float expectedScale = 42.564f;
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalUniformScale, expectedScale);
float rx = 1.43f;
TransformBus::Event(m_childId, &TransformBus::Events::RotateAroundLocalX, rx);
@@ -513,18 +512,15 @@ namespace UnitTest
{
TransformBus::Event(m_childId, &TransformBus::Events::RotateAroundLocalY, ry);
}
Vector3 localScale;
TransformBus::EventResult(localScale, m_childId, &TransformBus::Events::GetLocalScale);
EXPECT_TRUE(localScale.IsClose(Vector3(1.0f, 1.0f, 1.0f)));
float localScale = FLT_MAX;
TransformBus::EventResult(localScale, m_childId, &TransformBus::Events::GetLocalUniformScale);
EXPECT_NEAR(localScale, 1.0f, AZ::Constants::Tolerance);
}
TEST_F(TransformComponentTransformMatrixSetGet, RotateAroundLocalY_ScaleDoesNotSkewRotation)
{
float sx = 42.564f;
float sy = 12.460f;
float sz = 28.692f;
Vector3 expectedScales(sx, sy, sz);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalScale, expectedScales);
float expectedScale = 42.564f;
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalUniformScale, expectedScale);
float ry = 1.43f;
TransformBus::Event(m_childId, &TransformBus::Events::RotateAroundLocalY, ry);
@@ -550,18 +546,15 @@ namespace UnitTest
{
TransformBus::Event(m_childId, &TransformBus::Events::RotateAroundLocalZ, rz);
}
Vector3 localScale;
TransformBus::EventResult(localScale, m_childId, &TransformBus::Events::GetLocalScale);
EXPECT_TRUE(localScale.IsClose(Vector3(1.0f, 1.0f, 1.0f)));
float localScale = FLT_MAX;
TransformBus::EventResult(localScale, m_childId, &TransformBus::Events::GetLocalUniformScale);
EXPECT_NEAR(localScale, 1.0f, AZ::Constants::Tolerance);
}
TEST_F(TransformComponentTransformMatrixSetGet, RotateAroundLocalZ_ScaleDoesNotSkewRotation)
{
float sx = 42.564f;
float sy = 12.460f;
float sz = 28.692f;
Vector3 expectedScales(sx, sy, sz);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalScale, expectedScales);
float expectedScale = 42.564f;
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalUniformScale, expectedScale);
float rz = 1.43f;
TransformBus::Event(m_childId, &TransformBus::Events::RotateAroundLocalZ, rz);
@@ -572,110 +565,50 @@ namespace UnitTest
TEST_F(TransformComponentTransformMatrixSetGet, SetLocalScale_SimpleValues_Set)
{
float sx = 42.564f;
float sy = 12.460f;
float sz = 28.692f;
Vector3 expectedScales(sx, sy, sz);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalScale, expectedScales);
float expectedScale = 42.564f;
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalUniformScale, expectedScale);
Transform tm ;
TransformBus::EventResult(tm, m_childId, &TransformBus::Events::GetLocalTM);
Vector3 scales = tm.GetScale();
EXPECT_TRUE(scales.IsClose(expectedScales));
}
TEST_F(TransformComponentTransformMatrixSetGet, SetLocalScaleX_SimpleValues_Set)
{
float sx = 64.336f;
Transform tm;
TransformBus::EventResult(tm, m_childId, &TransformBus::Events::GetLocalTM);
Vector3 expectedScales = tm.GetScale();
expectedScales.SetX(sx);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalScaleX, sx);
TransformBus::EventResult(tm, m_childId, &TransformBus::Events::GetLocalTM);
Vector3 scales = tm.GetScale();
EXPECT_TRUE(scales.IsClose(expectedScales));
}
TEST_F(TransformComponentTransformMatrixSetGet, SetLocalScaleY_SimpleValues_Set)
{
float sy = 23.754f;
Transform tm;
TransformBus::EventResult(tm, m_childId, &TransformBus::Events::GetLocalTM);
Vector3 expectedScales = tm.GetScale();
expectedScales.SetY(sy);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalScaleY, sy);
TransformBus::EventResult(tm, m_childId, &TransformBus::Events::GetLocalTM);
Vector3 scales = tm.GetScale();
EXPECT_TRUE(scales.IsClose(expectedScales));
}
TEST_F(TransformComponentTransformMatrixSetGet, SetLocalScaleZ_SimpleValues_Set)
{
float sz = 65.140f;
Transform tm;
TransformBus::EventResult(tm, m_childId, &TransformBus::Events::GetLocalTM);
Vector3 expectedScales = tm.GetScale();
expectedScales.SetZ(sz);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalScaleZ, sz);
TransformBus::EventResult(tm, m_childId, &TransformBus::Events::GetLocalTM);
Vector3 scales = tm.GetScale();
EXPECT_TRUE(scales.IsClose(expectedScales));
float scale = tm.GetUniformScale();
EXPECT_NEAR(scale, expectedScale, AZ::Constants::Tolerance);
}
TEST_F(TransformComponentTransformMatrixSetGet, GetLocalScale_SimpleValues_Return)
{
float sx = 43.463f;
float sy = 346.22f;
float sz = 863.32f;
Vector3 expectedScales(sx, sy, sz);
Transform scaleTM = Transform::CreateScale(expectedScales);
float expectedScale = 43.463f;
Transform scaleTM = Transform::CreateUniformScale(expectedScale);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalTM, scaleTM);
Vector3 scales;
TransformBus::EventResult(scales, m_childId, &TransformBus::Events::GetLocalScale);
EXPECT_TRUE(scales.IsClose(expectedScales));
float scale;
TransformBus::EventResult(scale, m_childId, &TransformBus::Events::GetLocalUniformScale);
EXPECT_NEAR(scale, expectedScale, AZ::Constants::Tolerance);
}
TEST_F(TransformComponentTransformMatrixSetGet, GetWorldScale_ChildHasNoScale_ReturnScaleSameAsParent)
{
float sx = 43.463f;
float sy = 346.22f;
float sz = 863.32f;
Vector3 expectedScales(sx, sy, sz);
Transform scaleTM = Transform::CreateScale(expectedScales);
float expectedScale = 43.463f;
Transform scaleTM = Transform::CreateUniformScale(expectedScale);
TransformBus::Event(m_parentId, &TransformBus::Events::SetLocalTM, scaleTM);
Vector3 scales;
TransformBus::EventResult(scales, m_childId, &TransformBus::Events::GetWorldScale);
EXPECT_TRUE(scales.IsClose(expectedScales));
float scale = FLT_MAX;
TransformBus::EventResult(scale, m_childId, &TransformBus::Events::GetWorldUniformScale);
EXPECT_NEAR(scale, expectedScale, AZ::Constants::Tolerance);
}
TEST_F(TransformComponentTransformMatrixSetGet, GetWorldScale_ChildHasScale_ReturnCompoundScale)
{
float sx = 4.463f;
float sy = 3.22f;
float sz = 8.32f;
Vector3 parentScales(sx, sy, sz);
Transform parentScaleTM = Transform::CreateScale(parentScales);
float parentScale = 4.463f;
Transform parentScaleTM = Transform::CreateUniformScale(parentScale);
TransformBus::Event(m_parentId, &TransformBus::Events::SetLocalTM, parentScaleTM);
float csx = 1.64f;
float csy = 9.35f;
float csz = 1.57f;
Vector3 childScales(csx, csy, csz);
Transform childScaleTM = Transform::CreateScale(childScales);
float childScale = 1.64f;
Transform childScaleTM = Transform::CreateUniformScale(childScale);
TransformBus::Event(m_childId, &TransformBus::Events::SetLocalTM, childScaleTM);
Vector3 scales;
TransformBus::EventResult(scales, m_childId, &TransformBus::Events::GetWorldScale);
EXPECT_TRUE(scales.IsClose(parentScales * childScales));
float scale = FLT_MAX;
TransformBus::EventResult(scale, m_childId, &TransformBus::Events::GetWorldUniformScale);
EXPECT_NEAR(scale, parentScale * childScale, AZ::Constants::Tolerance);
}
class TransformComponentHierarchy