ShapeCollider_InactiveWhenNoShapeComponent.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 : C19578018
  6. Test Case Title : Verify that a shape collider component with no shape component indicates a missing service
  7. """
  8. # fmt: off
  9. class Tests():
  10. create_collider_entity = ("Created Collider Entity", "Failed to create Collider Entity")
  11. add_physx_shape_collider = ("PhysX Shape Collider added", "Failed to add PhysX Shape Collider")
  12. collider_component_inactive = ("Collider component is Inactive", "Collider component is Active")
  13. add_shape_component = ("Shape component added", "Failed to add Shape component")
  14. collider_component_active = ("Collider component is active", "Collider component is inactive")
  15. # fmt: on
  16. def ShapeCollider_InactiveWhenNoShapeComponent():
  17. """
  18. Summary:
  19. Create an Entity with PhysX Shape Collider component and verify that PhysX Shape Collider Component
  20. is inactive without shape component.
  21. Expected Behavior:
  22. The PhysX Shape Collider component should be inactive.
  23. Verify that after a shape component is added, the warning goes away.
  24. Test Steps:
  25. 1) Load the level
  26. 2) Add an entity with a PhysX Shape Collider component.
  27. 3) Validate Collider Entity
  28. 4) Validate PhysX Shape Collider component is inactive.
  29. 5) Add Shape component to Entity
  30. 6) Validate PhysX Shape Collider component is Active.
  31. 7) Close the editor
  32. Note:
  33. - This test file must be called from the Open 3D Engine Editor command terminal
  34. - Any passed and failed tests are written to the Editor.log file.
  35. Parsing the file or running a log_monitor are required to observe the test results.
  36. :return: None
  37. """
  38. # Built-in Imports
  39. # Helper Imports
  40. from editor_python_test_tools.utils import Report
  41. from editor_python_test_tools.editor_entity_utils import EditorEntity
  42. from editor_python_test_tools.utils import TestHelper as helper
  43. from consts.physics import PHYSX_SHAPE_COLLIDER
  44. import editor_python_test_tools.hydra_editor_utils as hydra
  45. # Open 3D Engine Imports
  46. import azlmbr.bus as bus
  47. import azlmbr.editor as editor
  48. def is_component_active(component_id) -> bool:
  49. """
  50. Used to check if component is Active
  51. :return: boolean, True if component is active, else False
  52. """
  53. return editor.EditorComponentAPIBus(bus.Broadcast, "IsComponentEnabled", component_id)
  54. # 1) Load the level
  55. hydra.open_base_level()
  56. # 2) Add an entity with a PhysX Shape Collider component.
  57. collider = EditorEntity.create_editor_entity("Collider")
  58. collider.add_component("PhysX Static Rigid Body")
  59. physx_component = collider.add_component(PHYSX_SHAPE_COLLIDER)
  60. # 3) Validate Collider Entity
  61. Report.result(Tests.create_collider_entity, collider.id.IsValid())
  62. # 4) Validate PhysX Shape Collider component is inactive.
  63. Report.result(Tests.add_physx_shape_collider, collider.has_component(PHYSX_SHAPE_COLLIDER))
  64. Report.result(Tests.collider_component_inactive, not is_component_active(physx_component.id))
  65. # 5) Add Shape component to Entity
  66. collider.add_component("Box Shape")
  67. Report.result(Tests.add_shape_component, collider.has_component("Box Shape"))
  68. # 6) Validate PhysX Shape Collider component is Active.
  69. Report.result(Tests.collider_component_active, is_component_active(physx_component.id))
  70. if __name__ == "__main__":
  71. from editor_python_test_tools.utils import Report
  72. Report.start_test(ShapeCollider_InactiveWhenNoShapeComponent)