PrefabLevel_OpensLevelWithEntities.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. find_empty_entity = ("Entity: 'EmptyEntity' found", "Entity: 'EmptyEntity' *not* found in level")
  9. empty_entity_pos = ("'EmptyEntity' position is at the expected position", "'EmptyEntity' position is *not* at the expected position")
  10. find_pxentity = ("Entity: 'EntityWithPxCollider' found", "Entity: 'EntityWithPxCollider' *not* found in level")
  11. pxentity_component = ("Entity: 'EntityWithPxCollider' has a Physx Collider", "Entity: 'EntityWithPxCollider' does *not* have a Physx Collider")
  12. # fmt:on
  13. def PrefabLevel_OpensLevelWithEntities():
  14. """
  15. Opens the level that contains 2 entities, "EmptyEntity" and "EntityWithPxCollider".
  16. This test makes sure that both entities exist after opening the level and that:
  17. - EmptyEntity is at Position: (10, 20, 30)
  18. - EntityWithPxCollider has a PhysXCollider component
  19. """
  20. import os
  21. import sys
  22. from editor_python_test_tools.utils import Report
  23. from editor_python_test_tools.utils import TestHelper as helper
  24. import editor_python_test_tools.hydra_editor_utils as hydra
  25. import azlmbr.entity as entity
  26. import azlmbr.bus as bus
  27. from azlmbr.math import Vector3
  28. EXPECTED_EMPTY_ENTITY_POS = Vector3(10.00, 20.0, 30.0)
  29. helper.init_idle()
  30. helper.open_level("Prefab", "PrefabLevel_OpensLevelWithEntities")
  31. def find_entity(entity_name):
  32. searchFilter = entity.SearchFilter()
  33. searchFilter.names = [entity_name]
  34. entityIds = entity.SearchBus(bus.Broadcast, 'SearchEntities', searchFilter)
  35. if entityIds[0].IsValid():
  36. return entityIds[0]
  37. return None
  38. # Checks for an entity called "EmptyEntity"
  39. helper.wait_for_condition(lambda: find_entity("EmptyEntity").IsValid(), 5.0)
  40. empty_entity_id = find_entity("EmptyEntity")
  41. Report.result(Tests.find_empty_entity, empty_entity_id.IsValid())
  42. # Checks if the EmptyEntity is in the correct position and if it fails, it will provide the expected postion and the actual postion of the entity in the Editor log
  43. empty_entity_pos = azlmbr.components.TransformBus(azlmbr.bus.Event, "GetWorldTranslation", empty_entity_id)
  44. is_at_position = empty_entity_pos.IsClose(EXPECTED_EMPTY_ENTITY_POS)
  45. Report.result(Tests.empty_entity_pos, is_at_position)
  46. if not is_at_position:
  47. Report.info(f'Expected position: {EXPECTED_EMPTY_ENTITY_POS.ToString()}, actual position: {empty_entity_pos.ToString()}')
  48. # Checks for an entity called "EntityWithPxCollider" and if it has the PhysX Collider component
  49. pxentity = find_entity("EntityWithPxCollider")
  50. Report.result(Tests.find_pxentity, pxentity.IsValid())
  51. pxcollider_id = hydra.get_component_type_id("PhysX Collider")
  52. hasComponent = azlmbr.editor.EditorComponentAPIBus(azlmbr.bus.Broadcast, 'HasComponentOfType', pxentity, pxcollider_id)
  53. Report.result(Tests.pxentity_component, hasComponent)
  54. if __name__ == "__main__":
  55. from editor_python_test_tools.utils import Report
  56. Report.start_test(PrefabLevel_OpensLevelWithEntities)