CreatePrefab_WithNestedEntities.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. def CreatePrefab_WithNestedEntities():
  7. """
  8. Test description:
  9. - Creates linear nested entities.
  10. - Creates a prefab from the nested entities.
  11. Test passed if the 3 entities inside the newly instanced prefab have correct hierarchy and positions.
  12. """
  13. from pathlib import Path
  14. from editor_python_test_tools.prefab_utils import Prefab
  15. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  16. NESTED_ENTITIES_PREFAB_FILE_NAME = Path(__file__).stem + 'nested_entities_prefab'
  17. NESTED_ENTITIES_NAME_PREFIX = 'Entity_'
  18. OLD_POSITION = azlmbr.math.Vector3(100.0, 100.0, 100.0)
  19. NEW_POSITION = azlmbr.math.Vector3(200.0, 200.0, 200.0)
  20. NUM_NESTED_ENTITIES_LEVELS = 3
  21. prefab_test_utils.open_base_tests_level()
  22. # Creates new nested entities at the root level
  23. # Asserts if creation didn't succeed
  24. nested_entities_root = prefab_test_utils.create_linear_nested_entities(NESTED_ENTITIES_NAME_PREFIX, NUM_NESTED_ENTITIES_LEVELS, OLD_POSITION)
  25. nested_entities_root_parent = nested_entities_root.get_parent_id()
  26. prefab_test_utils.validate_linear_nested_entities(nested_entities_root, NUM_NESTED_ENTITIES_LEVELS, OLD_POSITION)
  27. # Asserts if prefab creation doesn't succeed
  28. _, nested_entities_prefab_instance = Prefab.create_prefab([nested_entities_root], NESTED_ENTITIES_PREFAB_FILE_NAME)
  29. nested_entities_root_on_instance = nested_entities_prefab_instance.get_direct_child_entities()[0]
  30. prefab_test_utils.validate_linear_nested_entities(nested_entities_root_on_instance, NUM_NESTED_ENTITIES_LEVELS, OLD_POSITION)
  31. # Test undo/redo on prefab creation
  32. prefab_test_utils.validate_undo_redo_on_prefab_creation(nested_entities_prefab_instance, nested_entities_root_parent)
  33. # Moves the position of root of the nested entities, it should also update all the entities' positions
  34. nested_entities_root_on_instance.set_world_translation(NEW_POSITION)
  35. prefab_test_utils.validate_linear_nested_entities(nested_entities_root_on_instance, NUM_NESTED_ENTITIES_LEVELS, NEW_POSITION)
  36. if __name__ == "__main__":
  37. from editor_python_test_tools.utils import Report
  38. Report.start_test(CreatePrefab_WithNestedEntities)