OpenLevel_ContainingTwoEntities.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 OpenLevel_ContainingTwoEntities():
  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 PhysXMeshCollider 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. from consts.physics import PHYSX_MESH_COLLIDER
  25. import editor_python_test_tools.hydra_editor_utils as hydra
  26. import azlmbr.entity as entity
  27. import azlmbr.bus as bus
  28. from azlmbr.math import Vector3
  29. EXPECTED_EMPTY_ENTITY_POS = Vector3(10.00, 20.0, 30.0)
  30. helper.init_idle()
  31. helper.open_level("Prefab", "PrefabLevel_OpensLevelWithEntities")
  32. def find_entity(entity_name):
  33. searchFilter = entity.SearchFilter()
  34. searchFilter.names = [entity_name]
  35. entityIds = entity.SearchBus(bus.Broadcast, 'SearchEntities', searchFilter)
  36. if entityIds[0].IsValid():
  37. return entityIds[0]
  38. return None
  39. # Checks for an entity called "EmptyEntity"
  40. helper.wait_for_condition(lambda: find_entity("EmptyEntity").IsValid(), 5.0)
  41. empty_entity_id = find_entity("EmptyEntity")
  42. Report.result(Tests.find_empty_entity, empty_entity_id.IsValid())
  43. # 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
  44. empty_entity_pos = azlmbr.components.TransformBus(azlmbr.bus.Event, "GetWorldTranslation", empty_entity_id)
  45. is_at_position = empty_entity_pos.IsClose(EXPECTED_EMPTY_ENTITY_POS)
  46. Report.result(Tests.empty_entity_pos, is_at_position)
  47. if not is_at_position:
  48. Report.info(f'Expected position: {EXPECTED_EMPTY_ENTITY_POS.ToString()}, actual position: {empty_entity_pos.ToString()}')
  49. # Checks for an entity called "EntityWithPxCollider" and if it has the PhysX Mesh Collider component
  50. pxentity = find_entity("EntityWithPxCollider")
  51. Report.result(Tests.find_pxentity, pxentity.IsValid())
  52. pxcollider_id = hydra.get_component_type_id(PHYSX_MESH_COLLIDER)
  53. hasComponent = azlmbr.editor.EditorComponentAPIBus(azlmbr.bus.Broadcast, 'HasComponentOfType', pxentity, pxcollider_id)
  54. Report.result(Tests.pxentity_component, hasComponent)
  55. if __name__ == "__main__":
  56. from editor_python_test_tools.utils import Report
  57. Report.start_test(OpenLevel_ContainingTwoEntities)