TerrainPhysicsCollider_ChangesSizeWithAxisAlignedBoxShapeChanges.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. #fmt: off
  7. class Tests:
  8. create_test_entity = ("Entity created successfully", "Failed to create Entity")
  9. add_axis_aligned_box_shape = ("Axis Aligned Box Shape component added", "Failed to add Axis Aligned Box Shape component")
  10. add_terrain_collider = ("Terrain Physics Heightfield Collider component added", "Failed to add a Terrain Physics Heightfield Collider component")
  11. box_dimensions_changed = ("Aabb dimensions changed successfully", "Failed change Aabb dimensions")
  12. configuration_changed = ("Terrain size changed successfully", "Failed terrain size change")
  13. #fmt: on
  14. def TerrainPhysicsCollider_ChangesSizeWithAxisAlignedBoxShapeChanges():
  15. """
  16. Summary:
  17. Test aspects of the Terrain Physics Heightfield Collider through the BehaviorContext and the Property Tree.
  18. Test Steps:
  19. Expected Behavior:
  20. The Editor is stable there are no warnings or errors.
  21. Test Steps:
  22. 1) Load the base level
  23. 2) Create test entity
  24. 3) Start the Tracer to catch any errors and warnings
  25. 4) Add the Axis Aligned Box Shape and Terrain Physics Heightfield Collider components
  26. 5) Change the Axis Aligned Box Shape dimensions
  27. 6) Check the Heightfield provider is returning the correct size
  28. 7) Verify there are no errors and warnings in the logs
  29. :return: None
  30. """
  31. import editor_python_test_tools.hydra_editor_utils as hydra
  32. from editor_python_test_tools.editor_entity_utils import EditorEntity
  33. from editor_python_test_tools.utils import TestHelper as helper
  34. from editor_python_test_tools.utils import Report, Tracer
  35. import azlmbr.physics as physics
  36. import azlmbr.math as azmath
  37. import azlmbr.bus as bus
  38. import math
  39. SET_BOX_X_SIZE = 5.0
  40. SET_BOX_Y_SIZE = 6.0
  41. # Our box is being created at (0,0), so it goes from (-2.5,-3) to (2.5,3)
  42. # The default terrain grid step size is 1, and we expect our physics heightfield to be aligned to the grid,
  43. # so the heightfield should go from (-2, -3) to (2, 3).
  44. # The heightfield is also expected to create final vertex endpoints in each direction, so we expect the
  45. # X axis to create (-2, -1, 0, 1, 2) = 5 points, and the Y axis to create (-3, -2, -1, 0, 1, 2, 3) = 7 points
  46. EXPECTED_COLUMN_SIZE = 5
  47. EXPECTED_ROW_SIZE = 7
  48. # 1) Load the level
  49. hydra.open_base_level()
  50. #1a) Load the level components
  51. hydra.add_level_component("Terrain World")
  52. hydra.add_level_component("Terrain World Renderer")
  53. # 2) Create test entity
  54. test_entity = EditorEntity.create_editor_entity_at(azmath.Vector3(0.0, 0.0, 0.0), "TestEntity")
  55. Report.result(Tests.create_test_entity, test_entity.id.IsValid())
  56. # 3) Start the Tracer to catch any errors and warnings
  57. with Tracer() as section_tracer:
  58. # 4) Add the Axis Aligned Box Shape and Terrain Physics Heightfield Collider components
  59. aaBoxShape_component = test_entity.add_component("Axis Aligned Box Shape")
  60. Report.result(Tests.add_axis_aligned_box_shape, test_entity.has_component("Axis Aligned Box Shape"))
  61. terrainPhysics_component = test_entity.add_component("Terrain Physics Heightfield Collider")
  62. Report.result(Tests.add_terrain_collider, test_entity.has_component("Terrain Physics Heightfield Collider"))
  63. # 5) Change the Axis Aligned Box Shape dimensions
  64. aaBoxShape_component.set_component_property_value("Axis Aligned Box Shape|Box Configuration|Dimensions", azmath.Vector3(SET_BOX_X_SIZE, SET_BOX_Y_SIZE, 1.0))
  65. add_check = aaBoxShape_component.get_component_property_value("Axis Aligned Box Shape|Box Configuration|Dimensions") == azmath.Vector3(SET_BOX_X_SIZE, SET_BOX_Y_SIZE, 1.0)
  66. Report.result(Tests.box_dimensions_changed, add_check)
  67. # 6) Check the Heightfield provider is returning the correct size
  68. columns = physics.HeightfieldProviderRequestsBus(bus.Broadcast, "GetHeightfieldGridColumns")
  69. rows = physics.HeightfieldProviderRequestsBus(bus.Broadcast, "GetHeightfieldGridRows")
  70. Report.result(Tests.configuration_changed, math.isclose(columns, EXPECTED_COLUMN_SIZE) and math.isclose(rows, EXPECTED_ROW_SIZE))
  71. helper.wait_for_condition(lambda: section_tracer.has_errors or section_tracer.has_asserts, 1.0)
  72. for error_info in section_tracer.errors:
  73. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  74. for assert_info in section_tracer.asserts:
  75. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  76. if __name__ == "__main__":
  77. from editor_python_test_tools.utils import Report
  78. Report.start_test(TerrainPhysicsCollider_ChangesSizeWithAxisAlignedBoxShapeChanges)