3
0

hydra_AtomEditorComponents_ReflectionProbeAdded.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. reflection_probe_creation = (
  14. "Reflection Probe Entity successfully created",
  15. "P0: Reflection Probe Entity failed to be created")
  16. reflection_probe_component = (
  17. "Entity has a Reflection Probe component",
  18. "P0: Entity failed to find Reflection Probe component")
  19. reflection_probe_disabled = (
  20. "Reflection Probe component disabled",
  21. "P0: Reflection Probe component was not disabled.")
  22. reflection_map_generated = (
  23. "Reflection Probe cubemap generated",
  24. "P0: Reflection Probe cubemap generation timed out waiting for AssetProcessor to return a path to cubemap")
  25. box_shape_component = (
  26. "Entity has a Box Shape component",
  27. "P0: Entity did not have a Box Shape component")
  28. reflection_probe_enabled = (
  29. "Reflection Probe component enabled",
  30. "P0: Reflection Probe component was not enabled.")
  31. enter_game_mode = (
  32. "Entered game mode",
  33. "P0: Failed to enter game mode")
  34. exit_game_mode = (
  35. "Exited game mode",
  36. "P0: Couldn't exit game mode")
  37. is_visible = (
  38. "Entity is visible",
  39. "P0: Entity was not visible")
  40. is_hidden = (
  41. "Entity is hidden",
  42. "P0: Entity was not hidden")
  43. entity_deleted = (
  44. "Entity deleted",
  45. "P0: Entity was not deleted")
  46. deletion_undo = (
  47. "UNDO deletion success",
  48. "P0: UNDO deletion failed")
  49. deletion_redo = (
  50. "REDO deletion success",
  51. "P0: REDO deletion failed")
  52. parallax_correction = (
  53. "Parallax Correction property set",
  54. "P1: Parallax Correction property failed to set correctly")
  55. use_baked_cubemap = (
  56. "Use Baked Cubemap property set",
  57. "P1: Use Baked Cubemap property failed to set correctly")
  58. show_visualization = (
  59. "Show Visualization property set",
  60. "P1: Show Visualization property failed to set correctly")
  61. bake_exposure_low = (
  62. "Bake Exposure property set to minimum value",
  63. "P1: Bake Exposure property failed to take minimum value")
  64. bake_exposure_high = (
  65. "Bake Exposure property set to maximum value",
  66. "P1: Bake Exposure property failed to take maximum value")
  67. settings_exposure_low = (
  68. "Settings|Exposure property set to minimum value",
  69. "P1: Settings|Exposure property failed to take minimum value")
  70. settings_exposure_high = (
  71. "Settings|Exposure property set to maximum value",
  72. "P1: Settings|Exposure property failed to take maximum value")
  73. inner_extents_height_low = (
  74. "Inner Extents|Height property set to minimum value",
  75. "P1: Inner Extents|Height property failed to take minimum value")
  76. inner_extents_height_high = (
  77. "Inner Extents|Height property set to maximum value for default shape size",
  78. "P1: Inner Extents|Height property failed to take maximum value for default shape size")
  79. inner_extents_length_low = (
  80. "Inner Extents|Length property set to minimum value",
  81. "P1: Inner Extents|Length property failed to take minimum value")
  82. inner_extents_length_high = (
  83. "Inner Extents|Length property set to maximum value for default shape size",
  84. "P1: Inner Extents|Length property failed to take maximum value for default shape size")
  85. inner_extents_width_low = (
  86. "Inner Extents|Width property set to minimum value",
  87. "P1: Inner Extents|Width property failed to take minimum value")
  88. inner_extents_width_high = (
  89. "Inner Extents|Width property set to maximum value for default shape size",
  90. "P1: Inner Extents|Width property failed to take maximum value for default shape size")
  91. def AtomEditorComponents_ReflectionProbe_AddedToEntity():
  92. """
  93. Summary:
  94. Tests the Reflection Probe component can be added to an entity and has the expected functionality.
  95. Test setup:
  96. - Wait for Editor idle loop.
  97. - Open the "Base" level.
  98. Expected Behavior:
  99. The component can be added, used in game mode, hidden/shown, deleted, and has accurate required components.
  100. Creation and deletion undo/redo should also work.
  101. Test Steps:
  102. 1) Create a Reflection Probe entity with no components.
  103. 2) Add a Reflection Probe component to Reflection Probe entity.
  104. 3) UNDO the entity creation and component addition.
  105. 4) REDO the entity creation and component addition.
  106. 5) Verify Reflection Probe component not enabled.
  107. 6) Add Shape component since it is required by the Reflection Probe component.
  108. 7) Verify Reflection Probe component is enabled.
  109. 8) Toggle Parallax Correction (default True)
  110. 9) Toggle Use Baked Cubemap (default True)
  111. 10) Toggle Show Visualization (default True)
  112. 11) Bake Exposure (float range -20.0 to 20.0)
  113. 12) Inner Extents|Height (float 0.0 to required shape dimension constraint default 8.0)
  114. 13) Inner Extents|Length (float 0.0 to required shape dimension constraint default 8.0)
  115. 14) Inner Extents|Width (float 0.0 to required shape dimension constraint default 8.0)
  116. 15) Settings|Exposure (float range -20.0 to 20.0)
  117. 16) Baked Cubemap Quality (unsigned int use dictionary constant)
  118. 17) Enter/Exit game mode.
  119. 18) Test IsHidden.
  120. 19) Test IsVisible.
  121. 20) Delete Reflection Probe entity.
  122. 21) UNDO deletion.
  123. 22) REDO deletion.
  124. 23) Look for errors and asserts.
  125. :return: None
  126. """
  127. import azlmbr.legacy.general as general
  128. import azlmbr.render as render
  129. from azlmbr.math import Math_IsClose
  130. from editor_python_test_tools.editor_entity_utils import EditorEntity
  131. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  132. from Atom.atom_utils.atom_constants import AtomComponentProperties, BAKED_CUBEMAP_QUALITY
  133. with Tracer() as error_tracer:
  134. # Test setup begins.
  135. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  136. TestHelper.init_idle()
  137. TestHelper.open_level("Graphics", "base_empty")
  138. # Test steps begin.
  139. # 1. Create a Reflection Probe entity with no components.
  140. reflection_probe_entity = EditorEntity.create_editor_entity(AtomComponentProperties.reflection_probe())
  141. Report.critical_result(Tests.reflection_probe_creation, reflection_probe_entity.exists())
  142. # 2. Add a Reflection Probe component to Reflection Probe entity.
  143. reflection_probe_component = reflection_probe_entity.add_component(AtomComponentProperties.reflection_probe())
  144. Report.critical_result(
  145. Tests.reflection_probe_component,
  146. reflection_probe_entity.has_component(AtomComponentProperties.reflection_probe()))
  147. # 3. UNDO the entity creation and component addition.
  148. # -> UNDO component addition.
  149. general.undo()
  150. # -> UNDO naming entity.
  151. general.undo()
  152. # -> UNDO selecting entity.
  153. general.undo()
  154. # -> UNDO entity creation.
  155. general.undo()
  156. general.idle_wait_frames(1)
  157. Report.result(Tests.creation_undo, not reflection_probe_entity.exists())
  158. # 4. REDO the entity creation and component addition.
  159. # -> REDO entity creation.
  160. general.redo()
  161. # -> REDO selecting entity.
  162. general.redo()
  163. # -> REDO naming entity.
  164. general.redo()
  165. # -> REDO component addition.
  166. general.redo()
  167. general.idle_wait_frames(1)
  168. Report.result(Tests.creation_redo, reflection_probe_entity.exists())
  169. # 5. Verify Reflection Probe component not enabled.
  170. Report.result(Tests.reflection_probe_disabled, not reflection_probe_component.is_enabled())
  171. # 6. Add Shape component since it is required by the Reflection Probe component.
  172. for shape in AtomComponentProperties.reflection_probe('shapes'):
  173. reflection_probe_entity.add_component(shape)
  174. test_shape = (
  175. f"Entity has a {shape} component",
  176. f"Entity did not have a {shape} component")
  177. Report.result(test_shape, reflection_probe_entity.has_component(shape))
  178. # 7. Check if required shape allows Reflection Probe to be enabled
  179. Report.result(Tests.reflection_probe_enabled, reflection_probe_component.is_enabled())
  180. # Undo to remove each added shape except the last one and verify Reflection Probe is not enabled.
  181. if not (shape == AtomComponentProperties.reflection_probe('shapes')[-1]):
  182. general.undo()
  183. TestHelper.wait_for_condition(lambda: not reflection_probe_entity.has_component(shape), 1.0)
  184. Report.result(Tests.reflection_probe_disabled, not reflection_probe_component.is_enabled())
  185. # 8. Toggle Parallax Correction (default True)
  186. reflection_probe_component.set_component_property_value(
  187. AtomComponentProperties.reflection_probe('Parallax Correction'), False)
  188. Report.result(
  189. Tests.parallax_correction,
  190. reflection_probe_component.get_component_property_value(
  191. AtomComponentProperties.reflection_probe('Parallax Correction')) is False)
  192. reflection_probe_component.set_component_property_value(
  193. AtomComponentProperties.reflection_probe('Parallax Correction'), True)
  194. Report.result(
  195. Tests.parallax_correction,
  196. reflection_probe_component.get_component_property_value(
  197. AtomComponentProperties.reflection_probe('Parallax Correction')) is True)
  198. # 9. Toggle Use Baked Cubemap (default True)
  199. reflection_probe_component.set_component_property_value(
  200. AtomComponentProperties.reflection_probe('Use Baked Cubemap'), False)
  201. Report.result(
  202. Tests.use_baked_cubemap,
  203. reflection_probe_component.get_component_property_value(
  204. AtomComponentProperties.reflection_probe('Use Baked Cubemap')) is False)
  205. reflection_probe_component.set_component_property_value(
  206. AtomComponentProperties.reflection_probe('Use Baked Cubemap'), True)
  207. Report.result(
  208. Tests.use_baked_cubemap,
  209. reflection_probe_component.get_component_property_value(
  210. AtomComponentProperties.reflection_probe('Use Baked Cubemap')) is True)
  211. # 10. Toggle Show Visualization (default True)
  212. reflection_probe_component.set_component_property_value(
  213. AtomComponentProperties.reflection_probe('Show Visualization'), False)
  214. Report.result(
  215. Tests.show_visualization,
  216. reflection_probe_component.get_component_property_value(
  217. AtomComponentProperties.reflection_probe('Show Visualization')) is False)
  218. reflection_probe_component.set_component_property_value(
  219. AtomComponentProperties.reflection_probe('Show Visualization'), True)
  220. Report.result(
  221. Tests.show_visualization,
  222. reflection_probe_component.get_component_property_value(
  223. AtomComponentProperties.reflection_probe('Show Visualization')) is True)
  224. # 11. Bake Exposure (float range -20.0 to 20.0)
  225. reflection_probe_component.set_component_property_value(
  226. AtomComponentProperties.reflection_probe('Bake Exposure'), -20.0)
  227. Report.result(
  228. Tests.bake_exposure_low,
  229. Math_IsClose(
  230. reflection_probe_component.get_component_property_value(
  231. AtomComponentProperties.reflection_probe('Bake Exposure')), -20.0))
  232. reflection_probe_component.set_component_property_value(
  233. AtomComponentProperties.reflection_probe('Bake Exposure'), 20.0)
  234. Report.result(
  235. Tests.bake_exposure_high,
  236. Math_IsClose(
  237. reflection_probe_component.get_component_property_value(
  238. AtomComponentProperties.reflection_probe('Bake Exposure')), 20.0))
  239. reflection_probe_component.set_component_property_value(
  240. AtomComponentProperties.reflection_probe('Bake Exposure'), 0.0)
  241. # 12. Inner Extents|Height (float 0.0 to required shape dimension constraint default 8.0)
  242. reflection_probe_component.set_component_property_value(
  243. AtomComponentProperties.reflection_probe('Height'), 0.0)
  244. Report.result(
  245. Tests.inner_extents_height_low,
  246. Math_IsClose(
  247. reflection_probe_component.get_component_property_value(
  248. AtomComponentProperties.reflection_probe('Height')), 0.0))
  249. reflection_probe_component.set_component_property_value(
  250. AtomComponentProperties.reflection_probe('Height'), 8.0)
  251. Report.result(
  252. Tests.inner_extents_height_high,
  253. Math_IsClose(
  254. reflection_probe_component.get_component_property_value(
  255. AtomComponentProperties.reflection_probe('Height')), 8.0))
  256. # 13. Inner Extents|Length (float 0.0 to required shape dimension constraint default 8.0)
  257. reflection_probe_component.set_component_property_value(
  258. AtomComponentProperties.reflection_probe('Length'), 0.0)
  259. Report.result(
  260. Tests.inner_extents_length_low,
  261. Math_IsClose(
  262. reflection_probe_component.get_component_property_value(
  263. AtomComponentProperties.reflection_probe('Length')), 0.0))
  264. reflection_probe_component.set_component_property_value(
  265. AtomComponentProperties.reflection_probe('Length'), 8.0)
  266. Report.result(
  267. Tests.inner_extents_length_high,
  268. Math_IsClose(
  269. reflection_probe_component.get_component_property_value(
  270. AtomComponentProperties.reflection_probe('Length')), 8.0))
  271. # 14. Inner Extents|Width (float 0.0 to required shape dimension constraint default 8.0)
  272. reflection_probe_component.set_component_property_value(
  273. AtomComponentProperties.reflection_probe('Width'), 0.0)
  274. Report.result(
  275. Tests.inner_extents_width_low,
  276. Math_IsClose(
  277. reflection_probe_component.get_component_property_value(
  278. AtomComponentProperties.reflection_probe('Width')), 0.0))
  279. reflection_probe_component.set_component_property_value(
  280. AtomComponentProperties.reflection_probe('Width'), 8.0)
  281. Report.result(
  282. Tests.inner_extents_width_high,
  283. Math_IsClose(
  284. reflection_probe_component.get_component_property_value(
  285. AtomComponentProperties.reflection_probe('Width')), 8.0))
  286. # 15. Settings|Exposure (float range -20.0 to 20.0)
  287. reflection_probe_component.set_component_property_value(
  288. AtomComponentProperties.reflection_probe('Settings Exposure'), -20.0)
  289. Report.result(
  290. Tests.settings_exposure_low,
  291. Math_IsClose(
  292. reflection_probe_component.get_component_property_value(
  293. AtomComponentProperties.reflection_probe('Settings Exposure')), -20.0))
  294. reflection_probe_component.set_component_property_value(
  295. AtomComponentProperties.reflection_probe('Settings Exposure'), 20.0)
  296. Report.result(
  297. Tests.settings_exposure_high,
  298. Math_IsClose(
  299. reflection_probe_component.get_component_property_value(
  300. AtomComponentProperties.reflection_probe('Settings Exposure')), 20.0))
  301. reflection_probe_component.set_component_property_value(
  302. AtomComponentProperties.reflection_probe('Settings Exposure'), 0.0)
  303. # # 16. Baked Cubemap Quality (unsigned int use dictionary constant)
  304. for quality in BAKED_CUBEMAP_QUALITY:
  305. test_quality = (
  306. f"Baked Cubemap Quality ({quality}) set as expected",
  307. f"P1: Baked Cubemap Quality ({quality}) failed to be set")
  308. reflection_probe_component.set_component_property_value(
  309. AtomComponentProperties.reflection_probe('Baked Cubemap Quality'), BAKED_CUBEMAP_QUALITY[quality])
  310. Report.result(
  311. test_quality,
  312. reflection_probe_component.get_component_property_value(
  313. AtomComponentProperties.reflection_probe('Baked Cubemap Quality')) == BAKED_CUBEMAP_QUALITY[quality])
  314. # 17. Enter/Exit game mode.
  315. TestHelper.enter_game_mode(Tests.enter_game_mode)
  316. general.idle_wait_frames(1)
  317. TestHelper.exit_game_mode(Tests.exit_game_mode)
  318. # 18. Test IsHidden.
  319. reflection_probe_entity.set_visibility_state(False)
  320. Report.result(Tests.is_hidden, reflection_probe_entity.is_hidden() is True)
  321. # 19. Test IsVisible.
  322. reflection_probe_entity.set_visibility_state(True)
  323. general.idle_wait_frames(1)
  324. Report.result(Tests.is_visible, reflection_probe_entity.is_visible() is True)
  325. # 20. Delete Reflection Probe entity.
  326. reflection_probe_entity.delete()
  327. Report.result(Tests.entity_deleted, not reflection_probe_entity.exists())
  328. # 21. UNDO deletion.
  329. general.undo()
  330. general.idle_wait_frames(1)
  331. Report.result(Tests.deletion_undo, reflection_probe_entity.exists())
  332. # 22. REDO deletion.
  333. general.redo()
  334. general.idle_wait_frames(1)
  335. Report.result(Tests.deletion_redo, not reflection_probe_entity.exists())
  336. # 23. Look for errors or asserts.
  337. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  338. for error_info in error_tracer.errors:
  339. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  340. for assert_info in error_tracer.asserts:
  341. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  342. if __name__ == "__main__":
  343. from editor_python_test_tools.utils import Report
  344. Report.start_test(AtomEditorComponents_ReflectionProbe_AddedToEntity)