MeshComponentControllerTests.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzTest/AzTest.h>
  9. #include <AzToolsFramework/ActionManager/Action/ActionManagerInternalInterface.h>
  10. #include <AzToolsFramework/ActionManager/HotKey/HotKeyManagerInternalInterface.h>
  11. #include <AzToolsFramework/ActionManager/Menu/MenuManagerInternalInterface.h>
  12. #include <AzToolsFramework/ActionManager/ToolBar/ToolBarManagerInternalInterface.h>
  13. #include <AzToolsFramework/Entity/EditorEntityHelpers.h>
  14. #include <AzToolsFramework/ToolsComponents/TransformComponent.h>
  15. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  16. #include <Mesh/EditorMeshComponent.h>
  17. #include <Mesh/MeshComponentController.h>
  18. namespace UnitTest
  19. {
  20. class IntersectionNotificationDetector : public AzFramework::RenderGeometry::IntersectionNotificationBus::Handler
  21. {
  22. public:
  23. void Connect(const AzFramework::EntityContextId& entityContextId);
  24. void Disconnect();
  25. // IntersectionNotificationBus overrides ...
  26. void OnEntityConnected(AZ::EntityId entityId) override;
  27. void OnEntityDisconnected(AZ::EntityId entityId) override;
  28. void OnGeometryChanged(AZ::EntityId entityId) override;
  29. AZ::EntityId m_lastEntityIdChanged;
  30. };
  31. void IntersectionNotificationDetector::Connect(const AzFramework::EntityContextId& entityContextId)
  32. {
  33. AzFramework::RenderGeometry::IntersectionNotificationBus::Handler::BusConnect(entityContextId);
  34. }
  35. void IntersectionNotificationDetector::Disconnect()
  36. {
  37. AzFramework::RenderGeometry::IntersectionNotificationBus::Handler::BusDisconnect();
  38. }
  39. void IntersectionNotificationDetector::OnEntityConnected([[maybe_unused]] AZ::EntityId entityId)
  40. {
  41. }
  42. void IntersectionNotificationDetector::OnEntityDisconnected([[maybe_unused]] AZ::EntityId entityId)
  43. {
  44. }
  45. void IntersectionNotificationDetector::OnGeometryChanged(AZ::EntityId entityId)
  46. {
  47. m_lastEntityIdChanged = entityId;
  48. }
  49. class MeshComponentControllerFixture : public ToolsApplicationFixture<false>
  50. {
  51. public:
  52. void SetUpEditorFixtureImpl() override
  53. {
  54. m_meshComponentDescriptor = AZStd::unique_ptr<AZ::ComponentDescriptor>(AZ::Render::MeshComponent::CreateDescriptor());
  55. m_meshComponentDescriptor->Reflect(GetApplication()->GetSerializeContext());
  56. m_editorMeshComponentDescriptor =
  57. AZStd::unique_ptr<AZ::ComponentDescriptor>(AZ::Render::EditorMeshComponent::CreateDescriptor());
  58. m_editorMeshComponentDescriptor->Reflect(GetApplication()->GetSerializeContext());
  59. m_entity = AZStd::make_unique<AZ::Entity>();
  60. m_entity->Init();
  61. m_entity->CreateComponent<AzToolsFramework::Components::TransformComponent>();
  62. m_entity->Activate();
  63. AzFramework::EntityContextId contextId(AZStd::string_view{"123456"});
  64. m_intersectionNotificationDetector.Connect(contextId);
  65. }
  66. void TearDownEditorFixtureImpl() override
  67. {
  68. m_entity.reset();
  69. m_intersectionNotificationDetector.Disconnect();
  70. m_meshComponentDescriptor.reset();
  71. m_editorMeshComponentDescriptor.reset();
  72. }
  73. AZStd::unique_ptr<AZ::Entity> m_entity;
  74. AZStd::unique_ptr<AZ::ComponentDescriptor> m_meshComponentDescriptor;
  75. AZStd::unique_ptr<AZ::ComponentDescriptor> m_editorMeshComponentDescriptor;
  76. IntersectionNotificationDetector m_intersectionNotificationDetector;
  77. };
  78. TEST_F(MeshComponentControllerFixture, IntersectionNotificationBusIsNotifiedWhenMeshComponentControllerTransformIsModified)
  79. {
  80. // suppress warning when feature process is not created in test environment
  81. UnitTest::ErrorHandler featureProcessorNotFound("Unable to find a MeshFeatureProcessorInterface on the entityId.");
  82. m_entity->Deactivate();
  83. m_entity->CreateComponent<AZ::Render::EditorMeshComponent>();
  84. m_entity->Activate();
  85. AZ::TransformBus::Event(
  86. m_entity->GetId(), &AZ::TransformBus::Events::SetWorldTM, AZ::Transform::CreateTranslation(AZ::Vector3(1.0f, 2.0f, 3.0f)));
  87. using ::testing::Eq;
  88. EXPECT_THAT(m_entity->GetId(), Eq(m_intersectionNotificationDetector.m_lastEntityIdChanged));
  89. }
  90. } // namespace UnitTest