PrefabBehaviorTestMocks.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <PrefabGroup/tests/PrefabBehaviorTestMocks.h>
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <AzCore/Serialization/Json/JsonSystemComponent.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzCore/std/smart_ptr/make_shared.h>
  13. #include <SceneAPI/SceneCore/Containers/Scene.h>
  14. #include <SceneAPI/SceneCore/Mocks/DataTypes/MockIGraphObject.h>
  15. #include <SceneAPI/SceneData/GraphData/MeshData.h>
  16. namespace AZ::Render
  17. {
  18. void EditorMeshComponent::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serializeContext->Class<AZ::Render::EditorMeshComponent>();
  23. }
  24. if (BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  25. {
  26. behaviorContext->Class<EditorMeshComponent>("AZ::Render::EditorMeshComponent");
  27. }
  28. }
  29. void EditorMeshComponentHelper::Reflect(AZ::ReflectContext* reflection) const
  30. {
  31. AZ::Render::EditorMeshComponent::Reflect(reflection);
  32. }
  33. }
  34. namespace UnitTest
  35. {
  36. AZStd::unique_ptr<AZ::SceneAPI::Containers::Scene> CreateMockScene(
  37. const AZStd::string_view manifestFilename,
  38. const AZStd::string_view sourceFileName,
  39. const AZStd::string_view watchFolder)
  40. {
  41. auto scene = CreateEmptyMockSceneWithRoot(manifestFilename, sourceFileName, watchFolder);
  42. BuildMockScene(*scene.get());
  43. return scene;
  44. }
  45. AZStd::unique_ptr<AZ::SceneAPI::Containers::Scene> CreateEmptyMockSceneWithRoot(
  46. const AZStd::string_view manifestFilename,
  47. const AZStd::string_view sourceFileName,
  48. const AZStd::string_view watchFolder)
  49. {
  50. using namespace AZ::SceneAPI;
  51. auto scene = AZStd::make_unique<Containers::Scene>("mock_scene");
  52. scene->SetManifestFilename(manifestFilename.data());
  53. scene->SetSource(sourceFileName.data(), AZ::Uuid::CreateRandom());
  54. scene->SetWatchFolder(watchFolder.data());
  55. auto root = scene->GetGraph().GetRoot();
  56. scene->GetGraph().SetContent(root, AZStd::make_shared<DataTypes::MockIGraphObject>(0));
  57. return AZStd::move(scene);
  58. }
  59. void BuildMockScene(AZ::SceneAPI::Containers::Scene& scene)
  60. {
  61. using namespace AZ::SceneAPI;
  62. /*---------------------------------------\
  63. Root
  64. |
  65. 1
  66. |
  67. 2
  68. / \
  69. ------3m 7
  70. / / / \
  71. 6 5 4t 8m-------
  72. \ \ \
  73. 9t 10 11
  74. \---------------------------------------*/
  75. // Build up the graph
  76. auto root = scene.GetGraph().GetRoot();
  77. auto index1 = scene.GetGraph().AddChild(root, "1", AZStd::make_shared<DataTypes::MockIGraphObject>(1));
  78. auto index2 = scene.GetGraph().AddChild(index1, "2", AZStd::make_shared<DataTypes::MockIGraphObject>(2));
  79. auto index3 = scene.GetGraph().AddChild(index2, "3", AZStd::make_shared<AZ::SceneData::GraphData::MeshData>());
  80. auto index4 = scene.GetGraph().AddChild(index3, "4", AZStd::make_shared<MockTransform>());
  81. auto index5 = scene.GetGraph().AddChild(index3, "5", AZStd::make_shared<DataTypes::MockIGraphObject>(5));
  82. auto index6 = scene.GetGraph().AddChild(index3, "6", AZStd::make_shared<DataTypes::MockIGraphObject>(6));
  83. auto index7 = scene.GetGraph().AddChild(index2, "7", AZStd::make_shared<DataTypes::MockIGraphObject>(7));
  84. auto index8 = scene.GetGraph().AddChild(index7, "8", AZStd::make_shared<AZ::SceneData::GraphData::MeshData>());
  85. auto index9 = scene.GetGraph().AddChild(index8, "9", AZStd::make_shared<MockTransform>());
  86. auto index10 = scene.GetGraph().AddChild(index8, "10", AZStd::make_shared<DataTypes::MockIGraphObject>(10));
  87. auto index11 = scene.GetGraph().AddChild(index8, "11", AZStd::make_shared<DataTypes::MockIGraphObject>(11));
  88. scene.GetGraph().MakeEndPoint(index4);
  89. scene.GetGraph().MakeEndPoint(index5);
  90. scene.GetGraph().MakeEndPoint(index6);
  91. scene.GetGraph().MakeEndPoint(index9);
  92. scene.GetGraph().MakeEndPoint(index10);
  93. scene.GetGraph().MakeEndPoint(index11);
  94. }
  95. }