SimulatedObjectPipelineTests.cpp 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <AzCore/std/smart_ptr/unique_ptr.h>
  9. #include <Tests/InitSceneAPIFixture.h>
  10. #include <AzToolsFramework/UI/PropertyEditor/PropertyManagerComponent.h>
  11. #include <SceneAPI/SceneCore/Mocks/Containers/MockScene.h>
  12. #include <SceneAPI/SceneData/GraphData/BoneData.h>
  13. #include <SceneAPI/SceneData/GraphData/MeshData.h>
  14. #include <SceneAPI/SceneCore/Events/ProcessingResult.h>
  15. #include <SceneAPI/SceneCore/Events/ExportEventContext.h>
  16. #include <SceneAPI/SceneCore/Events/ExportProductList.h>
  17. #include <MCore/Source/RefCounted.h>
  18. #include <EMotionFX/Pipeline/RCExt/Actor/ActorBuilder.h>
  19. #include <EMotionFX/Pipeline/RCExt/Actor/ActorGroupExporter.h>
  20. #include <EMotionFX/Pipeline/RCExt/ExportContexts.h>
  21. #include <EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.h>
  22. #include <EMotionFX/Pipeline/SceneAPIExt/Rules/SimulatedObjectSetupRule.h>
  23. #include <EMotionFX/Source/Actor.h>
  24. namespace EMotionFX
  25. {
  26. using ActorCanSaveSimulatedObjectSetupFixtureBase = InitSceneAPIFixture<
  27. AZ::AssetManagerComponent,
  28. AZ::JobManagerComponent,
  29. AZ::StreamerComponent,
  30. AzToolsFramework::Components::PropertyManagerComponent,
  31. EMotionFX::Integration::SystemComponent,
  32. EMotionFX::Pipeline::ActorBuilder
  33. >;
  34. class ActorCanSaveSimulatedObjectSetupFixture
  35. : public ActorCanSaveSimulatedObjectSetupFixtureBase
  36. {
  37. public:
  38. void SetUp() override
  39. {
  40. ActorCanSaveSimulatedObjectSetupFixtureBase::SetUp();
  41. // Set up the scene graph
  42. m_scene = AZStd::make_unique<AZ::SceneAPI::Containers::MockScene>("MockScene");
  43. m_scene->SetOriginalSceneOrientation(AZ::SceneAPI::Containers::Scene::SceneOrientation::ZUp);
  44. AZ::SceneAPI::Containers::SceneGraph& graph = m_scene->GetGraph();
  45. graph.AddChild(graph.GetRoot(), "testRootBone", AZStd::make_shared<AZ::SceneData::GraphData::BoneData>());
  46. }
  47. AZStd::unique_ptr<AZ::SceneAPI::Containers::Scene> m_scene{};
  48. };
  49. TEST_F(ActorCanSaveSimulatedObjectSetupFixture, Test)
  50. {
  51. EMotionFX::Pipeline::Group::ActorGroup actorGroup;
  52. actorGroup.SetName("TestSimulatedObjectSaving");
  53. actorGroup.SetSelectedRootBone("testRootBone");
  54. auto simulatedObjectSetupRule = AZStd::make_shared<EMotionFX::Pipeline::Rule::SimulatedObjectSetupRule>();
  55. auto simulatedObjectSetup = AZStd::make_shared<EMotionFX::SimulatedObjectSetup>();
  56. simulatedObjectSetup->AddSimulatedObject("testSimulatedObject");
  57. simulatedObjectSetupRule->SetData(simulatedObjectSetup);
  58. actorGroup.GetRuleContainer().AddRule(simulatedObjectSetupRule);
  59. AZ::SceneAPI::Events::ExportProductList products;
  60. // Only run the Filling phase, to avoid any file writes
  61. EMotionFX::Pipeline::ActorGroupExportContext actorGroupExportContext(
  62. products,
  63. *m_scene,
  64. /*outputDirectory =*/"tmp",
  65. actorGroup,
  66. AZ::RC::Phase::Filling
  67. );
  68. EMotionFX::Pipeline::ActorGroupExporter exporter;
  69. AZ::SceneAPI::Events::ProcessingResult result = exporter.ProcessContext(actorGroupExportContext);
  70. ASSERT_EQ(result, AZ::SceneAPI::Events::ProcessingResult::Success) << "Failed to build actor";
  71. Actor* actor = exporter.GetActor();
  72. ASSERT_TRUE(actor);
  73. ASSERT_TRUE(actor->GetSimulatedObjectSetup());
  74. ASSERT_EQ(actor->GetSimulatedObjectSetup()->GetNumSimulatedObjects(), 1);
  75. EXPECT_STREQ(actor->GetSimulatedObjectSetup()->GetSimulatedObject(0)->GetName().c_str(), "testSimulatedObject");
  76. }
  77. } // namespace EMotionFX