RulesTests.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <SceneAPI/SceneCore/Containers/Scene.h>
  10. #include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
  11. #include <SceneAPI/SceneData/GraphData/MeshData.h>
  12. #include <SceneAPI/SceneData/Behaviors/LodRuleBehavior.h>
  13. #include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
  14. #include <SceneAPI/SceneData/Behaviors/Registry.h>
  15. #include <SceneAPI/SceneData/Groups/MeshGroup.h>
  16. #include <SceneAPI/SceneData/Rules/LodRule.h>
  17. #include <SceneAPI/SceneData/Rules/TangentsRule.h>
  18. namespace AZ
  19. {
  20. namespace SceneData
  21. {
  22. struct SoftNameMock
  23. : SceneAPI::Events::GraphMetaInfoBus::Handler
  24. {
  25. SoftNameMock()
  26. {
  27. BusConnect();
  28. }
  29. ~SoftNameMock() override
  30. {
  31. BusDisconnect();
  32. }
  33. void GetVirtualTypes(
  34. SceneAPI::Events::GraphMetaInfo::VirtualTypesSet& types,
  35. const SceneAPI::Containers::Scene&,
  36. SceneAPI::Containers::SceneGraph::NodeIndex) override
  37. {
  38. // Indicate this node is a LOD1 type
  39. types.emplace(AZ_CRC_CE("LODMesh1"));
  40. }
  41. };
  42. TEST(LOD, LODRuleTest)
  43. {
  44. // Test that UpdateManifest doesn't crash when trying to auto-add new LOD levels
  45. SoftNameMock softNameMock;
  46. SceneAPI::SceneData::LodRuleBehavior lod;
  47. SceneAPI::Containers::Scene scene("test");
  48. auto lodRule = AZStd::shared_ptr<SceneAPI::SceneData::LodRule>(aznew SceneAPI::SceneData::LodRule());
  49. scene.GetManifest().AddEntry(lodRule);
  50. auto group = AZStd::shared_ptr<SceneAPI::SceneData::MeshGroup>(aznew SceneAPI::SceneData::MeshGroup());
  51. // Add a bunch of other rules first
  52. // This is necessary to replicate the bug condition where the index of the rule is used instead of the index of the LOD
  53. for (int i = 0; i < 5; ++i)
  54. {
  55. auto tangentsRule = AZStd::shared_ptr<SceneAPI::SceneData::TangentsRule>(aznew SceneAPI::SceneData::TangentsRule());
  56. group->GetRuleContainer().AddRule(tangentsRule);
  57. }
  58. group->GetRuleContainer().AddRule(lodRule);
  59. scene.GetManifest().AddEntry(group);
  60. auto meshData = AZStd::shared_ptr<GraphData::MeshData>(new GraphData::MeshData());
  61. scene.GetGraph().AddChild(scene.GetGraph().GetRoot(), "test", meshData);
  62. EXPECT_EQ(lodRule->GetLodCount(), 0);
  63. // This should auto-add 1 LOD because of the "test" node we added above along with the SoftNameMock which will report it as an LOD1
  64. lod.UpdateManifest(scene, SceneAPI::Events::AssetImportRequest::Update, SceneAPI::Events::AssetImportRequest::Generic);
  65. EXPECT_EQ(lodRule->GetLodCount(), 1);
  66. }
  67. }
  68. }