3
0

hydra_AtomEditorComponents_GlobalSkylightIBLAdded.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. camera_creation = (
  8. "Camera Entity successfully created",
  9. "Camera Entity failed to be created")
  10. camera_component_added = (
  11. "Camera component was added to entity",
  12. "Camera component failed to be added to entity")
  13. camera_component_check = (
  14. "Entity has a Camera component",
  15. "Entity failed to find Camera component")
  16. creation_undo = (
  17. "UNDO Entity creation success",
  18. "UNDO Entity creation failed")
  19. creation_redo = (
  20. "REDO Entity creation success",
  21. "REDO Entity creation failed")
  22. global_skylight_creation = (
  23. "Global Skylight (IBL) Entity successfully created",
  24. "P0: Global Skylight (IBL) Entity failed to be created")
  25. global_skylight_component = (
  26. "Entity has a Global Skylight (IBL) component",
  27. "P0: Entity failed to find Global Skylight (IBL) component")
  28. default_diffuse_image_set = (
  29. "Entity has the default Diffuse Image set",
  30. "P0: Entity failed to set default Diffuse Image")
  31. default_specular_image_set = (
  32. "Entity has the default Specular Image set",
  33. "P0: Entity failed to set default Specular Diffuse Image")
  34. exposure_set_max_value = (
  35. "Exposure set to maximum value",
  36. "P1: Exposure failed to set maximum value")
  37. exposure_set_min_value = (
  38. "Exposure set to minimum value",
  39. "P1: Exposure failed to set minimum value")
  40. high_contrast_diffuse_image_set = (
  41. "Entity has the high contrast Diffuse Image set",
  42. "P1: Entity failed to set high contrast Diffuse Image")
  43. high_contrast_specular_image_set = (
  44. "Entity has the high contrast Specular Image set",
  45. "P1: Entity failed to set high contrast Specular Diffuse Image")
  46. enter_game_mode = (
  47. "Entered game mode",
  48. "P0: Failed to enter game mode")
  49. exit_game_mode = (
  50. "Exited game mode",
  51. "P0: Couldn't exit game mode")
  52. is_visible = (
  53. "Entity is visible",
  54. "P0: Entity was not visible")
  55. is_hidden = (
  56. "Entity is hidden",
  57. "P0: Entity was not hidden")
  58. entity_deleted = (
  59. "Entity deleted",
  60. "P0: Entity was not deleted")
  61. deletion_undo = (
  62. "UNDO deletion success",
  63. "P0: UNDO deletion failed")
  64. deletion_redo = (
  65. "REDO deletion success",
  66. "P0: REDO deletion failed")
  67. def AtomEditorComponents_GlobalSkylightIBL_AddedToEntity():
  68. """
  69. Summary:
  70. Tests the Global Skylight (IBL) component can be added to an entity and has the expected functionality.
  71. Test setup:
  72. - Wait for Editor idle loop.
  73. - Open the "Base" level.
  74. Expected Behavior:
  75. The component can be added, used in game mode, hidden/shown, deleted, and has accurate required components.
  76. Creation and deletion undo/redo should also work.
  77. Test Steps:
  78. 1) Create a Global Skylight (IBL) entity with no components.
  79. 2) Add Global Skylight (IBL) component to Global Skylight (IBL) entity.
  80. 3) UNDO the entity creation and component addition.
  81. 4) REDO the entity creation and component addition.
  82. 5) Enter/Exit game mode.
  83. 6) Test IsHidden.
  84. 7) Test IsVisible.
  85. 8) Add Post FX Layer component.
  86. 9) Add Camera component
  87. 10) Delete Global Skylight (IBL) entity.
  88. 11) UNDO deletion.
  89. 12) REDO deletion.
  90. 13) Look for errors.
  91. :return: None
  92. """
  93. import os
  94. import azlmbr.legacy.general as general
  95. from editor_python_test_tools.asset_utils import Asset
  96. from editor_python_test_tools.editor_entity_utils import EditorEntity
  97. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  98. from Atom.atom_utils.atom_constants import AtomComponentProperties
  99. with Tracer() as error_tracer:
  100. # Test setup begins.
  101. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  102. TestHelper.init_idle()
  103. TestHelper.open_level("Graphics", "base_empty")
  104. # Test steps begin.
  105. # 1. Create a Global Skylight (IBL) entity with no components.
  106. global_skylight_entity = EditorEntity.create_editor_entity(AtomComponentProperties.global_skylight())
  107. Report.critical_result(Tests.global_skylight_creation, global_skylight_entity.exists())
  108. # 2. Add Global Skylight (IBL) component to Global Skylight (IBL) entity.
  109. global_skylight_component = global_skylight_entity.add_component(AtomComponentProperties.global_skylight())
  110. Report.critical_result(
  111. Tests.global_skylight_component,
  112. global_skylight_entity.has_component(AtomComponentProperties.global_skylight()))
  113. # 3. UNDO the entity creation and component addition.
  114. # -> UNDO component addition.
  115. general.undo()
  116. # -> UNDO naming entity.
  117. general.undo()
  118. # -> UNDO selecting entity.
  119. general.undo()
  120. # -> UNDO entity creation.
  121. general.undo()
  122. general.idle_wait_frames(1)
  123. Report.result(Tests.creation_undo, not global_skylight_entity.exists())
  124. # 4. REDO the entity creation and component addition.
  125. # -> REDO entity creation.
  126. general.redo()
  127. # -> REDO selecting entity.
  128. general.redo()
  129. # -> REDO naming entity.
  130. general.redo()
  131. # -> REDO component addition.
  132. general.redo()
  133. general.idle_wait_frames(1)
  134. Report.result(Tests.creation_redo, global_skylight_entity.exists())
  135. # 5. Test IsHidden.
  136. global_skylight_entity.set_visibility_state(False)
  137. Report.result(Tests.is_hidden, global_skylight_entity.is_hidden() is True)
  138. # 6. Test IsVisible.
  139. global_skylight_entity.set_visibility_state(True)
  140. general.idle_wait_frames(1)
  141. Report.result(Tests.is_visible, global_skylight_entity.is_visible() is True)
  142. # 7. Set the default Diffuse Image asset on the Global Skylight (IBL) entity.
  143. diffuse_image_path = os.path.join("lightingpresets", "default_iblskyboxcm.exr.streamingimage")
  144. diffuse_image_asset = Asset.find_asset_by_path(diffuse_image_path, False)
  145. global_skylight_component.set_component_property_value(
  146. AtomComponentProperties.global_skylight('Diffuse Image'), diffuse_image_asset.id)
  147. Report.result(
  148. Tests.default_diffuse_image_set,
  149. diffuse_image_asset.id == global_skylight_component.get_component_property_value(
  150. AtomComponentProperties.global_skylight('Diffuse Image')))
  151. # 8. Set the default Specular Image asset on the Global Light (IBL) entity.
  152. specular_image_path = os.path.join("lightingpresets", "default_iblskyboxcm.exr.streamingimage")
  153. specular_image_asset = Asset.find_asset_by_path(specular_image_path, False)
  154. global_skylight_component.set_component_property_value(
  155. AtomComponentProperties.global_skylight('Specular Image'), specular_image_asset.id)
  156. Report.result(
  157. Tests.default_specular_image_set,
  158. specular_image_asset.id == global_skylight_component.get_component_property_value(
  159. AtomComponentProperties.global_skylight('Specular Image')))
  160. # 9. Set Exposure value to min value
  161. global_skylight_component.set_component_property_value(
  162. AtomComponentProperties.global_skylight('Exposure'), value=-5)
  163. current_exposure_value = global_skylight_component.get_component_property_value(
  164. AtomComponentProperties.global_skylight('Exposure'))
  165. Report.result(Tests.exposure_set_min_value, current_exposure_value == -5)
  166. # 10. Set Exposure value to max value
  167. global_skylight_component.set_component_property_value(
  168. AtomComponentProperties.global_skylight('Exposure'), value=5)
  169. current_exposure_value = global_skylight_component.get_component_property_value(
  170. AtomComponentProperties.global_skylight('Exposure'))
  171. Report.result(Tests.exposure_set_max_value, current_exposure_value == 5)
  172. # 11. Set the High Contrast Diffuse Image asset on the Global Skylight (IBL) entity.
  173. diffuse_image_path = os.path.join(
  174. "lightingpresets", "highcontrast", "goegap_4k_iblglobalcm_ibldiffuse.exr.streamingimage")
  175. diffuse_image_asset = Asset.find_asset_by_path(diffuse_image_path, False)
  176. global_skylight_component.set_component_property_value(
  177. AtomComponentProperties.global_skylight('Diffuse Image'), diffuse_image_asset.id)
  178. Report.result(
  179. Tests.high_contrast_diffuse_image_set,
  180. diffuse_image_asset.id == global_skylight_component.get_component_property_value(
  181. AtomComponentProperties.global_skylight('Diffuse Image')))
  182. # 12. Set the High Contrast Specular Image asset on the Global Light (IBL) entity.
  183. specular_image_path = os.path.join(
  184. "lightingpresets", "highcontrast", "goegap_4k_iblglobalcm_iblspecular.exr.streamingimage")
  185. specular_image_asset = Asset.find_asset_by_path(specular_image_path, False)
  186. global_skylight_component.set_component_property_value(
  187. AtomComponentProperties.global_skylight('Specular Image'), specular_image_asset.id)
  188. Report.result(
  189. Tests.high_contrast_specular_image_set,
  190. specular_image_asset.id == global_skylight_component.get_component_property_value(
  191. AtomComponentProperties.global_skylight('Specular Image')))
  192. # 13. Set Exposure valuye to min value
  193. global_skylight_component.set_component_property_value(
  194. AtomComponentProperties.global_skylight('Exposure'), value=-5)
  195. current_exposure_value = global_skylight_component.get_component_property_value(
  196. AtomComponentProperties.global_skylight('Exposure'))
  197. Report.result(Tests.exposure_set_min_value, current_exposure_value == -5)
  198. # 14. Set Exposure value to max value
  199. global_skylight_component.set_component_property_value(
  200. AtomComponentProperties.global_skylight('Exposure'), value=5)
  201. current_exposure_value = global_skylight_component.get_component_property_value(
  202. AtomComponentProperties.global_skylight('Exposure'))
  203. Report.result(Tests.exposure_set_max_value, current_exposure_value == 5)
  204. # 15. Enter/Exit game mode.
  205. TestHelper.enter_game_mode(Tests.enter_game_mode)
  206. general.idle_wait_frames(1)
  207. TestHelper.exit_game_mode(Tests.exit_game_mode)
  208. # 16. Delete Global Skylight (IBL) entity.
  209. global_skylight_entity.delete()
  210. Report.result(Tests.entity_deleted, not global_skylight_entity.exists())
  211. # 17. UNDO deletion.
  212. general.undo()
  213. general.idle_wait_frames(1)
  214. Report.result(Tests.deletion_undo, global_skylight_entity.exists())
  215. # 18. REDO deletion.
  216. general.redo()
  217. general.idle_wait_frames(1)
  218. Report.result(Tests.deletion_redo, not global_skylight_entity.exists())
  219. # 19. Look for errors and asserts.
  220. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  221. for error_info in error_tracer.errors:
  222. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  223. for assert_info in error_tracer.asserts:
  224. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  225. if __name__ == "__main__":
  226. from editor_python_test_tools.utils import Report
  227. Report.start_test(AtomEditorComponents_GlobalSkylightIBL_AddedToEntity)