hydra_AtomEditorComponents_OcclusionCullingPlaneAdded.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. class Tests:
  7. creation_undo = (
  8. "UNDO Entity creation success",
  9. "P0: UNDO Entity creation failed")
  10. creation_redo = (
  11. "REDO Entity creation success",
  12. "P0: REDO Entity creation failed")
  13. occlusion_culling_plane_entity_creation = (
  14. "Occlusion Culling Plane Entity successfully created",
  15. "P0: Occlusion Culling Plane Entity failed to be created")
  16. occlusion_culling_plane_component_added = (
  17. "Entity has a Occlusion Culling Plane component",
  18. "P0: Entity failed to find Occlusion Culling Plane component")
  19. enter_game_mode = (
  20. "Entered game mode",
  21. "P0: Failed to enter game mode")
  22. exit_game_mode = (
  23. "Exited game mode",
  24. "P0: Couldn't exit game mode")
  25. is_visible = (
  26. "Entity is visible",
  27. "P0: Entity was not visible")
  28. is_hidden = (
  29. "Entity is hidden",
  30. "P0: Entity was not hidden")
  31. entity_deleted = (
  32. "Entity deleted",
  33. "P0: Entity was not deleted")
  34. deletion_undo = (
  35. "UNDO deletion success",
  36. "P0: UNDO deletion failed")
  37. deletion_redo = (
  38. "REDO deletion success",
  39. "P0: REDO deletion failed")
  40. show_visualization = (
  41. "Show Visualization property set",
  42. "P1: Show Visualization property failed to be set correctly")
  43. transparent_visualization = (
  44. "Transparent Visualization property set",
  45. "P1: Transparent Visualization property failed to be set correctly")
  46. scale = (
  47. "Occlusion Culling Plane entity scaled as expected",
  48. "P1: Occlusion Culling Plane entity failed to scale as expected")
  49. def AtomEditorComponents_OcclusionCullingPlane_AddedToEntity():
  50. """
  51. Summary:
  52. Tests the occlusion culling plane component can be added to an entity and has the expected functionality.
  53. Test setup:
  54. - Wait for Editor idle loop.
  55. - Open the "Base" level.
  56. Expected Behavior:
  57. The component can be added, used in game mode, hidden/shown, deleted, and has accurate required components.
  58. Creation and deletion undo/redo should also work.
  59. Test Steps:
  60. 1) Create a Occlusion Culling Plane entity with no components.
  61. 2) Add a Occlusion Culling Plane component to Occlusion Culling Plane entity.
  62. 3) UNDO the entity creation and component addition.
  63. 4) REDO the entity creation and component addition.
  64. 5) Toggle Show Visualization
  65. 6) Toggle Transparent Visualization
  66. 7) Set local uniform scale this is how the Occlusion Culling Plane is sized for use
  67. 8) Enter/Exit game mode.
  68. 9) Test IsHidden.
  69. 10) Test IsVisible.
  70. 11) Delete Occlusion Culling Plane entity.
  71. 12) UNDO deletion.
  72. 13) REDO deletion.
  73. 14) Look for errors.
  74. :return: None
  75. """
  76. import azlmbr.legacy.general as general
  77. from editor_python_test_tools.editor_entity_utils import EditorEntity
  78. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  79. from Atom.atom_utils.atom_constants import AtomComponentProperties
  80. with Tracer() as error_tracer:
  81. # Test setup begins.
  82. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  83. TestHelper.init_idle()
  84. TestHelper.open_level("Graphics", "base_empty")
  85. # Test steps begin.
  86. # 1. Create a occlusion culling plane entity with no components.
  87. occlusion_culling_plane_entity = EditorEntity.create_editor_entity(
  88. AtomComponentProperties.occlusion_culling_plane())
  89. Report.critical_result(Tests.occlusion_culling_plane_entity_creation,
  90. occlusion_culling_plane_entity.exists())
  91. # 2. Add a occlusion culling plane component to occlusion culling plane entity.
  92. occlusion_culling_plane_component = occlusion_culling_plane_entity.add_component(
  93. AtomComponentProperties.occlusion_culling_plane())
  94. Report.critical_result(
  95. Tests.occlusion_culling_plane_component_added,
  96. occlusion_culling_plane_entity.has_component(AtomComponentProperties.occlusion_culling_plane()))
  97. # 3. UNDO the entity creation and component addition.
  98. # -> UNDO component addition.
  99. general.undo()
  100. # -> UNDO naming entity.
  101. general.undo()
  102. # -> UNDO selecting entity.
  103. general.undo()
  104. # -> UNDO entity creation.
  105. general.undo()
  106. general.idle_wait_frames(1)
  107. Report.result(Tests.creation_undo, not occlusion_culling_plane_entity.exists())
  108. # 4. REDO the entity creation and component addition.
  109. # -> REDO entity creation.
  110. general.redo()
  111. # -> REDO selecting entity.
  112. general.redo()
  113. # -> REDO naming entity.
  114. general.redo()
  115. # -> REDO component addition.
  116. general.redo()
  117. general.idle_wait_frames(1)
  118. Report.result(Tests.creation_redo, occlusion_culling_plane_entity.exists())
  119. # 5. Toggle Show Visualization
  120. # Set Show Visualization to False
  121. occlusion_culling_plane_component.set_component_property_value(
  122. AtomComponentProperties.occlusion_culling_plane('Show Visualization'), False)
  123. Report.result(
  124. Tests.show_visualization,
  125. occlusion_culling_plane_component.get_component_property_value(
  126. AtomComponentProperties.occlusion_culling_plane('Show Visualization')) is False)
  127. # Set Show Visualization to True
  128. occlusion_culling_plane_component.set_component_property_value(
  129. AtomComponentProperties.occlusion_culling_plane('Show Visualization'), True)
  130. Report.result(
  131. Tests.show_visualization,
  132. occlusion_culling_plane_component.get_component_property_value(
  133. AtomComponentProperties.occlusion_culling_plane('Show Visualization')) is True)
  134. # 6. Toggle Transparent Visualization
  135. # Set Transparent Visualization to True
  136. occlusion_culling_plane_component.set_component_property_value(
  137. AtomComponentProperties.occlusion_culling_plane('Transparent Visualization'), True)
  138. Report.result(
  139. Tests.transparent_visualization,
  140. occlusion_culling_plane_component.get_component_property_value(
  141. AtomComponentProperties.occlusion_culling_plane('Transparent Visualization')) is True)
  142. # Set Transparent Visualization to False
  143. occlusion_culling_plane_component.set_component_property_value(
  144. AtomComponentProperties.occlusion_culling_plane('Transparent Visualization'), False)
  145. Report.result(
  146. Tests.transparent_visualization,
  147. occlusion_culling_plane_component.get_component_property_value(
  148. AtomComponentProperties.occlusion_culling_plane('Transparent Visualization')) is False)
  149. # 7. Set local uniform scale this is how the Occlusion Culling Plane is sized for use
  150. occlusion_culling_plane_entity.set_local_uniform_scale(5.0)
  151. Report.result(
  152. Tests.scale,
  153. occlusion_culling_plane_entity.get_local_uniform_scale() == 5.0)
  154. # 8. Enter/Exit game mode.
  155. TestHelper.enter_game_mode(Tests.enter_game_mode)
  156. general.idle_wait_frames(1)
  157. TestHelper.exit_game_mode(Tests.exit_game_mode)
  158. # 9. Test IsHidden.
  159. occlusion_culling_plane_entity.set_visibility_state(False)
  160. Report.result(Tests.is_hidden, occlusion_culling_plane_entity.is_hidden() is True)
  161. # 10. Test IsVisible.
  162. occlusion_culling_plane_entity.set_visibility_state(True)
  163. general.idle_wait_frames(1)
  164. Report.result(Tests.is_visible, occlusion_culling_plane_entity.is_visible() is True)
  165. # 11. Delete occlusion_culling_plane entity.
  166. occlusion_culling_plane_entity.delete()
  167. Report.result(Tests.entity_deleted, not occlusion_culling_plane_entity.exists())
  168. # 12. UNDO deletion.
  169. general.undo()
  170. general.idle_wait_frames(1)
  171. Report.result(Tests.deletion_undo, occlusion_culling_plane_entity.exists())
  172. # 13. REDO deletion.
  173. general.redo()
  174. general.idle_wait_frames(1)
  175. Report.result(Tests.deletion_redo, not occlusion_culling_plane_entity.exists())
  176. # 14. Look for errors or asserts.
  177. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  178. for error_info in error_tracer.errors:
  179. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  180. for assert_info in error_tracer.asserts:
  181. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  182. if __name__ == "__main__":
  183. from editor_python_test_tools.utils import Report
  184. Report.start_test(AtomEditorComponents_OcclusionCullingPlane_AddedToEntity)