Collider_SphereShapeEditing.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. Test case ID : C4982800
  6. Test Case Title : Verify that the shape Sphere can be selected from the drop downlist and the value for its radius can be set
  7. """
  8. # fmt: off
  9. class Tests():
  10. entity_created = ("Test Entity created successfully", "Failed to create Test Entity")
  11. collider_added = ("PhysX Primitive Collider added successfully", "Failed to add PhysX Primitive Collider")
  12. collider_shape_changed = ("PhysX Primitive Collider shape changed successfully", "Failed change PhysX Primitive Collider shape")
  13. shape_dimensions_changed = ("Shape dimensions modified successfully", "Failed to modify Shape dimensions")
  14. # fmt: on
  15. def Collider_SphereShapeEditing():
  16. """
  17. Summary:
  18. Adding PhysX Primitive Collider and Shape components to test entity, then attempting to modify the shape's dimensions
  19. Expected Behavior:
  20. Sphere shape can be selected for the Shape Component and the value for Radius can be changed
  21. Test Steps:
  22. 1) Load the empty level
  23. 2) Create the test entity
  24. 3) Add PhysX Primitive Collider component to test entity
  25. 4) Change the PhysX Primitive Collider shape and store the original dimensions
  26. 5) Modify the dimensions
  27. 6) Verify they have been changed
  28. Note:
  29. - This test file must be called from the Open 3D Engine Editor command terminal
  30. - Any passed and failed tests are written to the Editor.log file.
  31. Parsing the file or running a log_monitor are required to observe the test results.
  32. :return: None
  33. """
  34. # Helper Files
  35. from editor_python_test_tools.editor_entity_utils import EditorEntity as Entity
  36. from editor_python_test_tools.utils import Report
  37. from editor_python_test_tools.utils import TestHelper as helper
  38. from consts.physics import PHYSX_PRIMITIVE_COLLIDER
  39. # Open 3D Engine Imports
  40. import azlmbr.math as math
  41. SPHERE_SHAPETYPE_ENUM = 0
  42. DIMENSION_TO_SET = 2.5
  43. DIMENSION_SIZE_TOLERANCE = 0.5
  44. helper.init_idle()
  45. # 1) Load the empty level
  46. helper.open_level("", "Base")
  47. # 2) Create the test entity
  48. test_entity = Entity.create_editor_entity("Test Entity")
  49. test_entity.add_component("PhysX Static Rigid Body")
  50. Report.result(Tests.entity_created, test_entity.id.IsValid())
  51. # 3) Add PhysX Primitive Collider component to test entity
  52. test_component = test_entity.add_component(PHYSX_PRIMITIVE_COLLIDER)
  53. Report.result(Tests.collider_added, test_entity.has_component(PHYSX_PRIMITIVE_COLLIDER))
  54. # 4) Change the PhysX Primitive Collider shape and store the original dimensions
  55. test_component.set_component_property_value("Shape Configuration|Shape", SPHERE_SHAPETYPE_ENUM)
  56. add_check = test_component.get_component_property_value("Shape Configuration|Shape") == SPHERE_SHAPETYPE_ENUM
  57. Report.result(Tests.collider_shape_changed, add_check)
  58. # 5) Modify the dimensions
  59. test_component.set_component_property_value("Shape Configuration|Sphere|Radius", DIMENSION_TO_SET)
  60. # 6) Verify they have been changed
  61. modified_dimensions = test_component.get_component_property_value("Shape Configuration|Sphere|Radius")
  62. dimensions_successfully_modified = math.Math_IsClose(
  63. DIMENSION_TO_SET, modified_dimensions, DIMENSION_SIZE_TOLERANCE
  64. )
  65. if not dimensions_successfully_modified:
  66. assert (
  67. False
  68. ), f"The modified value was not within the allowed tolerance\nExpected:{DIMENSION_TO_SET}\nActual: {modified_dimensions}"
  69. Report.result(Tests.shape_dimensions_changed, dimensions_successfully_modified)
  70. if __name__ == "__main__":
  71. from editor_python_test_tools.utils import Report
  72. Report.start_test(Collider_SphereShapeEditing)