LODSkinnedMeshTests.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 <gtest/gtest.h>
  9. #include <QtTest>
  10. #include <QTreeView>
  11. #include <QTreeWidget>
  12. #include <AzCore/Component/TickBus.h>
  13. #include <AzFramework/Components/TransformComponent.h>
  14. #include <Integration/Components/ActorComponent.h>
  15. #include <Integration/Components/SimpleLODComponent.h>
  16. #include <Integration/Rendering/RenderBackend.h>
  17. #include <Integration/Rendering/RenderBackendManager.h>
  18. #include <AzToolsFramework/UI/PropertyEditor/ReflectedPropertyEditor.hxx>
  19. #include <AzToolsFramework/UI/PropertyEditor/PropertyRowWidget.hxx>
  20. #include <Editor/Plugins/SkeletonOutliner/SkeletonOutlinerPlugin.h>
  21. #include <EMotionFX/Source/Mesh.h>
  22. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  23. #include <EMotionStudio/EMStudioSDK/Source/NodeHierarchyWidget.h>
  24. #include <Tests/TestAssetCode/ActorFactory.h>
  25. #include <Tests/TestAssetCode/SimpleActors.h>
  26. #include <Tests/TestAssetCode/TestActorAssets.h>
  27. #include <Tests/UI/UIFixture.h>
  28. #include <Editor/ReselectingTreeView.h>
  29. #include <Mocks/ISystemMock.h>
  30. namespace EMotionFX
  31. {
  32. class LODSkinnedMeshFixture
  33. : public ::testing::WithParamInterface <int>
  34. , public UIFixture
  35. {
  36. public:
  37. };
  38. class LODSystemMock : public SystemMock
  39. {
  40. };
  41. class LODSkinnedMeshColorFixture
  42. : public UIFixture
  43. {
  44. public:
  45. void SetUp() override
  46. {
  47. UIFixture::SetUp();
  48. m_app.RegisterComponentDescriptor(Integration::SimpleLODComponent::CreateDescriptor());
  49. m_app.RegisterComponentDescriptor(Integration::ActorComponent::CreateDescriptor());
  50. m_app.RegisterComponentDescriptor(AzFramework::TransformComponent::CreateDescriptor());
  51. m_envPrev = gEnv;
  52. m_env.pSystem = &m_data.m_system;
  53. gEnv = &m_env;
  54. }
  55. void TearDown() override
  56. {
  57. UIFixture::TearDown();
  58. gEnv = m_envPrev;
  59. }
  60. struct DataMembers
  61. {
  62. testing::NiceMock<LODSystemMock> m_system;
  63. };
  64. SSystemGlobalEnvironment* m_envPrev = nullptr;
  65. SSystemGlobalEnvironment m_env;
  66. DataMembers m_data;
  67. };
  68. AZ::Data::Asset<Integration::ActorAsset> CreateLODActor(int numLODs)
  69. {
  70. AZ::Data::AssetId actorAssetId("{5060227D-B6F4-422E-BF82-41AAC5F228A5}");
  71. AZ::Data::Asset<Integration::ActorAsset> actorAsset =
  72. TestActorAssets::CreateActorAssetAndRegister<PlaneActor>(actorAssetId, "LODSkinnedMeshTestsActor");
  73. // Modify the actor to have numLODs LOD levels.
  74. Actor* actor = actorAsset->GetActor();
  75. Mesh* lodMesh = actor->GetMesh(0, 0);
  76. for (int i = 1; i < numLODs; ++i)
  77. {
  78. actor->InsertLODLevel(i);
  79. actor->SetMesh(i, 0, lodMesh->Clone());
  80. }
  81. return AZStd::move(actorAsset);
  82. }
  83. class LODPropertyRowWidget
  84. : public AzToolsFramework::PropertyRowWidget
  85. {
  86. public:
  87. QLabel* GetDefaultLabel() { return m_defaultLabel; }
  88. };
  89. INSTANTIATE_TEST_CASE_P(LODSkinnedMeshFixtureTests, LODSkinnedMeshFixture, ::testing::Range<int>(1, 7));
  90. // TODO: Re-enabled the test when we can access viewport context in the SimpleLODComponent.
  91. TEST_F(LODSkinnedMeshColorFixture, DISABLED_CheckLODDistanceChange)
  92. {
  93. const int numLODs = 6;
  94. RecordProperty("test_case_id", "C29202698");
  95. AZ::EntityId entityId(740216387);
  96. auto gameEntity = AZStd::make_unique<AZ::Entity>();
  97. gameEntity->SetId(entityId);
  98. AZ::Data::AssetId actorAssetId("{85D3EF54-7400-43F8-8A40-F6BCBF534E54}");
  99. AZ::Data::Asset<Integration::ActorAsset> actorAsset = CreateLODActor(numLODs);
  100. gameEntity->CreateComponent<AzFramework::TransformComponent>();
  101. Integration::ActorComponent::Configuration actorConf;
  102. actorConf.m_actorAsset = actorAsset;
  103. Integration::ActorComponent* actorComponent = gameEntity->CreateComponent<Integration::ActorComponent>(&actorConf);
  104. Integration::SimpleLODComponent::Configuration lodConf;
  105. lodConf.GenerateDefaultValue(numLODs);
  106. gameEntity->CreateComponent<Integration::SimpleLODComponent>(&lodConf);
  107. gameEntity->Init();
  108. gameEntity->Activate();
  109. actorComponent->SetActorAsset(actorAsset);
  110. ActorInstance* actorInstance = actorComponent->GetActorInstance();
  111. EXPECT_TRUE(actorInstance);
  112. // Tick!
  113. AZ::TickBus::Broadcast(&AZ::TickBus::Events::OnTick, 0.0f, AZ::ScriptTimePoint{});
  114. EXPECT_EQ(actorInstance->GetLODLevel(), 0);
  115. Vec3 newVec{ 0,30,0 };
  116. // Tick!
  117. AZ::TickBus::Broadcast(&AZ::TickBus::Events::OnTick, 0.0f, AZ::ScriptTimePoint{});
  118. actorInstance->UpdateTransformations(0.0f);
  119. EXPECT_EQ(actorInstance->GetLODLevel(), 3);
  120. newVec.y = 50;
  121. // Tick!
  122. AZ::TickBus::Broadcast(&AZ::TickBus::Events::OnTick, 0.0f, AZ::ScriptTimePoint{});
  123. actorInstance->UpdateTransformations(0.0f);
  124. EXPECT_EQ(actorInstance->GetLODLevel(), 5);
  125. gameEntity->Deactivate();
  126. }
  127. }