diff --git a/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.cpp b/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.cpp index 7f919bc097..0b1848eb4b 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.cpp +++ b/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.cpp @@ -27,6 +27,7 @@ namespace LmbrCentral { incompatible.push_back(AZ_CRC_CE("ShapeService")); incompatible.push_back(AZ_CRC_CE("AxisAlignedBoxShapeService")); + incompatible.push_back(AZ_CRC_CE("NonUniformScaleService")); } void AxisAlignedBoxShapeComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) @@ -34,11 +35,6 @@ namespace LmbrCentral required.push_back(AZ_CRC_CE("TransformService")); } - void AxisAlignedBoxShapeComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) - { - dependent.push_back(AZ_CRC_CE("NonUniformScaleService")); - } - void AxisAlignedBoxShapeDebugDisplayComponent::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) @@ -54,8 +50,6 @@ namespace LmbrCentral { EntityDebugDisplayComponent::Activate(); ShapeComponentNotificationsBus::Handler::BusConnect(GetEntityId()); - m_nonUniformScale = AZ::Vector3::CreateOne(); - AZ::NonUniformScaleRequestBus::EventResult(m_nonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale); } void AxisAlignedBoxShapeDebugDisplayComponent::Deactivate() @@ -74,7 +68,7 @@ namespace LmbrCentral transform.SetRotation(AZ::Quaternion::CreateIdentity()); saveMatrix = debugDisplay.PopPremultipliedMatrix(); debugDisplay.PushMatrix(transform); - DrawBoxShape(drawParams, m_boxShapeConfig, debugDisplay, m_nonUniformScale); + DrawBoxShape(drawParams, m_boxShapeConfig, debugDisplay); debugDisplay.PopMatrix(); debugDisplay.PushPremultipliedMatrix(saveMatrix); } @@ -104,7 +98,6 @@ namespace LmbrCentral if (changeReason == ShapeChangeReasons::ShapeChanged) { BoxShapeComponentRequestsBus::EventResult(m_boxShapeConfig, GetEntityId(), &BoxShapeComponentRequests::GetBoxConfiguration); - AZ::NonUniformScaleRequestBus::EventResult(m_nonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale); } } diff --git a/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.h b/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.h index e180e1d536..9e6060914f 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.h +++ b/Gems/LmbrCentral/Code/Source/Shape/AxisAlignedBoxShapeComponent.h @@ -33,7 +33,6 @@ namespace LmbrCentral static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); - static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); AxisAlignedBoxShape m_aaboxShape; ///< Stores underlying box type for this component. }; @@ -65,6 +64,5 @@ namespace LmbrCentral void OnShapeChanged(ShapeChangeReasons changeReason) override; BoxShapeConfig m_boxShapeConfig; ///< Stores configuration data for box shape. - AZ::Vector3 m_nonUniformScale = AZ::Vector3::CreateOne(); ///< Caches non-uniform scale for this entity. }; } // namespace LmbrCentral diff --git a/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.cpp b/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.cpp index f78f2f048d..e8be486731 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.cpp +++ b/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.cpp @@ -89,9 +89,10 @@ namespace LmbrCentral provided.push_back(AZ_CRC_CE("AxisAlignedBoxShapeService")); } - void EditorAxisAlignedBoxShapeComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) + void EditorAxisAlignedBoxShapeComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { - dependent.push_back(AZ_CRC_CE("NonUniformScaleService")); + EditorBaseShapeComponent::GetIncompatibleServices(incompatible); + incompatible.push_back(AZ_CRC_CE("NonUniformScaleService")); } void EditorAxisAlignedBoxShapeComponent::DisplayEntityViewport( @@ -104,7 +105,7 @@ namespace LmbrCentral { DrawBoxShape( { m_aaboxShape.GetBoxConfiguration().GetDrawColor(), m_shapeWireColor, m_aaboxShape.GetBoxConfiguration().IsFilled() }, - m_aaboxShape.GetBoxConfiguration(), debugDisplay, m_aaboxShape.GetCurrentNonUniformScale()); + m_aaboxShape.GetBoxConfiguration(), debugDisplay); }, m_aaboxShape.GetCurrentTransform()); } @@ -163,6 +164,6 @@ namespace LmbrCentral AZ::Vector3 EditorAxisAlignedBoxShapeComponent::GetBoxScale() { - return AZ::Vector3(m_aaboxShape.GetCurrentTransform().GetUniformScale() * m_aaboxShape.GetCurrentNonUniformScale()); + return AZ::Vector3(m_aaboxShape.GetCurrentTransform().GetUniformScale()); } } // namespace LmbrCentral diff --git a/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.h b/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.h index 8bff4ea7e1..786a18b989 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.h +++ b/Gems/LmbrCentral/Code/Source/Shape/EditorAxisAlignedBoxShapeComponent.h @@ -38,7 +38,7 @@ namespace LmbrCentral protected: static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); - static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); + static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); // EditorComponentBase void BuildGameEntity(AZ::Entity* gameEntity) override; diff --git a/Gems/LmbrCentral/Code/Tests/AxisAlignedBoxShapeTest.cpp b/Gems/LmbrCentral/Code/Tests/AxisAlignedBoxShapeTest.cpp index c3e8d06791..a0f3b9e7a9 100644 --- a/Gems/LmbrCentral/Code/Tests/AxisAlignedBoxShapeTest.cpp +++ b/Gems/LmbrCentral/Code/Tests/AxisAlignedBoxShapeTest.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -26,7 +25,6 @@ namespace UnitTest AZStd::unique_ptr m_transformComponentDescriptor; AZStd::unique_ptr m_axisAlignedBoxShapeComponentDescriptor; AZStd::unique_ptr m_axisAlignedBoxShapeDebugDisplayComponentDescriptor; - AZStd::unique_ptr m_nonUniformScaleComponentDescriptor; public: void SetUp() override @@ -43,9 +41,6 @@ namespace UnitTest m_axisAlignedBoxShapeDebugDisplayComponentDescriptor = AZStd::unique_ptr(LmbrCentral::AxisAlignedBoxShapeDebugDisplayComponent::CreateDescriptor()); m_axisAlignedBoxShapeDebugDisplayComponentDescriptor->Reflect(&(*m_serializeContext)); - m_nonUniformScaleComponentDescriptor = - AZStd::unique_ptr(AzFramework::NonUniformScaleComponent::CreateDescriptor()); - m_nonUniformScaleComponentDescriptor->Reflect(&(*m_serializeContext)); } void TearDown() override @@ -53,7 +48,6 @@ namespace UnitTest m_transformComponentDescriptor.reset(); m_axisAlignedBoxShapeComponentDescriptor.reset(); m_axisAlignedBoxShapeDebugDisplayComponentDescriptor.reset(); - m_nonUniformScaleComponentDescriptor.reset(); m_serializeContext.reset(); AllocatorsFixture::TearDown(); } @@ -73,23 +67,6 @@ namespace UnitTest entity.GetId(), &LmbrCentral::BoxShapeComponentRequestsBus::Events::SetBoxDimensions, dimensions); } - void CreateAxisAlignedBoxWithNonUniformScale( - const AZ::Transform& transform, const AZ::Vector3& nonUniformScale, const AZ::Vector3& dimensions, AZ::Entity& entity) - { - entity.CreateComponent(); - entity.CreateComponent(); - entity.CreateComponent(); - entity.CreateComponent(); - - entity.Init(); - entity.Activate(); - - AZ::TransformBus::Event(entity.GetId(), &AZ::TransformBus::Events::SetWorldTM, transform); - LmbrCentral::BoxShapeComponentRequestsBus::Event( - entity.GetId(), &LmbrCentral::BoxShapeComponentRequestsBus::Events::SetBoxDimensions, dimensions); - AZ::NonUniformScaleRequestBus::Event(entity.GetId(), &AZ::NonUniformScaleRequests::SetScale, nonUniformScale); - } - void CreateDefaultAxisAlignedBox(const AZ::Transform& transform, AZ::Entity& entity) { CreateAxisAlignedBox(transform, AZ::Vector3(10.0f, 10.0f, 10.0f), entity); @@ -187,52 +164,4 @@ namespace UnitTest EXPECT_TRUE(rayHit); EXPECT_NEAR(distance, 4.0f, 1e-2f); } - - TEST_F(AxisAlignedBoxShapeTest, RayIntersectWithBoxRotatedNonUniformScale) - { - AZ::Entity entity; - CreateAxisAlignedBoxWithNonUniformScale( - AZ::Transform( - AZ::Vector3(2.0f, -5.0f, 3.0f), AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisY(), AZ::Constants::QuarterPi), - 0.5f), - AZ::Vector3(2.2f, 1.8f, 0.4f), AZ::Vector3(0.2f, 2.6f, 1.2f), entity); - - // This test creates a box of dimensions (2.2, 1.8, 0.4) centered on (2.0, -5, 3) and rotated about the Y axis by 45 degrees. - // The box is tested for axis-alignment by firing various rays and ensuring they either hit or miss the box. Any failure here - // would show the box has been rotated. - - // Ray should just miss the box - bool rayHit = false; - float distance = AZ::Constants::FloatMax; - LmbrCentral::ShapeComponentRequestsBus::EventResult( - rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(1.8f, -6.2f, 3.0f), - AZ::Vector3(1.0f, 0.0f, 0.0f), distance); - EXPECT_FALSE(rayHit); - - // Ray should just hit the box - rayHit = false; - distance = AZ::Constants::FloatMax; - LmbrCentral::ShapeComponentRequestsBus::EventResult( - rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(1.8f, -6.1f, 3.0f), - AZ::Vector3(1.0f, 0.0f, 0.0f), distance); - EXPECT_TRUE(rayHit); - EXPECT_NEAR(distance, 0.09f, 1e-3f); - - // Ray should just miss the box - rayHit = false; - distance = AZ::Constants::FloatMax; - LmbrCentral::ShapeComponentRequestsBus::EventResult( - rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(2.2f, -6.2f, 3.0f), - AZ::Vector3(0.0f, 1.0f, 0.0f), distance); - EXPECT_FALSE(rayHit); - - // Ray should just hit the box - rayHit = false; - distance = AZ::Constants::FloatMax; - LmbrCentral::ShapeComponentRequestsBus::EventResult( - rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(2.1f, -6.2f, 3.0f), - AZ::Vector3(0.0f, 1.0f, 0.0f), distance); - EXPECT_TRUE(rayHit); - EXPECT_NEAR(distance, 0.03f, 1e-3f); - } } // namespace UnitTest