3
0

hydra_AtomEditorComponents_LightAdded.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. # Shape components associated with specific light types.
  7. LIGHT_SHAPES = {
  8. 'sphere': 'Sphere Shape',
  9. 'spot_disk': 'Disk Shape',
  10. 'capsule': 'Capsule Shape',
  11. 'quad': 'Quad Shape',
  12. 'polygon': 'Polygon Prism Shape',
  13. }
  14. class Tests:
  15. light_creation = (
  16. "Light Entity successfully created",
  17. "P0: Light Entity failed to be created")
  18. light_component_removal = (
  19. "Light component successfully removed",
  20. "P1: Light component failed to be removed")
  21. light_component = (
  22. "Entity has a Light component",
  23. "P0: Entity failed to find Light component")
  24. removal_undo = (
  25. "UNDO Light component removal success",
  26. "P0: UNDO Light component removal failed")
  27. edit_light_color = (
  28. f"Light color updated",
  29. f"P1: Light color failed to update")
  30. edit_intensity_value = (
  31. f"Intensity updated",
  32. f"P1: Intensity failed to update")
  33. edit_attenuation_radius = (
  34. f"Attenuation radius Radius updated",
  35. f"P1: Attenuation radius Radius failed to update")
  36. enable_shadows = (
  37. f"Shadows enabled",
  38. f"P1: Shadows failed to be enabled")
  39. disable_shadows = (
  40. f"Shadows disabled",
  41. f"P1: Shadows failed to be disabled")
  42. edit_shadow_bias = (
  43. f"Shadow Bias updated",
  44. f"P1: Shadow Bias failed to be updated")
  45. edit_normal_bias = (
  46. f"Normal shadow bias updated",
  47. f"P1: Normal shadow bias failed to update")
  48. edit_filtering_sample_count = (
  49. f"Filtering sample count updated",
  50. f"P1: Filtering sample count failed to update")
  51. edit_esm_exponent = (
  52. f"ESM exponent updated",
  53. f"P1: ESM exponent failed to update")
  54. edit_inner_angle = (
  55. f"Shutters Inner angle updated",
  56. f"P1: Inner angle failed to update")
  57. edit_outer_angle = (
  58. f"Shutters Outer angle updated",
  59. f"P1: Outer angle failed to update")
  60. disable_shutters = (
  61. f"Shutters disabled",
  62. f"P1: Shutters failed to be disabled")
  63. enable_shutters = (
  64. f"Shutters enabled",
  65. f"P1: Shutters failed to be enabled")
  66. enable_both_directions = (
  67. f"Both directions enabled",
  68. f"P1: Both directions failed to be enabled")
  69. disable_both_directions = (
  70. f"Both directions disabled",
  71. f"P1: Both directions failed to be disabled")
  72. enable_fast_approximation = (
  73. f"Fast approximation enabled",
  74. f"P1: Fast approximation failed to be enabled")
  75. disable_fast_approximation = (
  76. f"Fast approximation disabled",
  77. f"P1: Fast approximation failed to be disabled")
  78. enter_game_mode = (
  79. "Entered game mode",
  80. "P0: Failed to enter game mode")
  81. exit_game_mode = (
  82. "Exited game mode",
  83. "P0: Couldn't exit game mode")
  84. is_hidden = (
  85. "Entity is hidden",
  86. "P0: Entity was not hidden")
  87. is_visible = (
  88. "Entity is visible",
  89. "P0: Entity was not visible")
  90. entity_deleted = (
  91. "Entity deleted",
  92. "P0: Entity was not deleted")
  93. deletion_undo = (
  94. "UNDO deletion success",
  95. "P0: UNDO deletion failed")
  96. deletion_redo = (
  97. "REDO deletion success",
  98. "P0: REDO deletion failed")
  99. def AtomEditorComponents_Light_AddedToEntity():
  100. """
  101. Summary:
  102. Tests the Light component can be added to an entity and has the expected functionality.
  103. Test setup:
  104. - Wait for Editor idle loop.
  105. - Open the "Base" level.
  106. Expected Behavior:
  107. The component can be added, used in game mode, hidden/shown, deleted, all components can be manipulated,
  108. and has accurate required components.
  109. Creation and deletion undo/redo should also work.
  110. Test Steps:
  111. 1) Create a Light entity with no components.
  112. 2) Add Light component to the Light entity.
  113. 3) Remove existing Light component on the entity.
  114. 4) UNDO the light component removal.
  115. 5) Set the light type.
  116. 6) Check for Shape component.
  117. 7) Edit the Color parameter.
  118. 8) Set the Intensity mode parameter.
  119. 9) Edit the Intensity parameter.
  120. 10) Set the Attenuation radius Mode.
  121. 11) Edit the Attenuation radius Radius parameter (explicit only).
  122. 12) Enable shadows (if applicable).
  123. 13) Edit the Shadows Bias parameter.
  124. 14) Edit the Normal shadow bias parameter.
  125. 15) Set the Shadowmap size.
  126. 16) Set the Shadow filter method.
  127. 17) Edit the Filtering sample count parameter.
  128. 18) Edit the ESM Exponent parameter.
  129. 19) Disable Shadows (re-enabled after test for game mode verification).
  130. 20) Edit the Inner angle parameter.
  131. 21) Edit the Outer angle parameter.
  132. 22) Disable Shutters.
  133. 23) Enable Shutters.
  134. 24) Enable Both directions.
  135. 25) Disable Both directions (re-enabled after test for game mode verification).
  136. 26) Enable Fast approximation.
  137. 27) Disable Fast approximation.
  138. 28) Enter/Exit game mode.
  139. 29) Test IsHidden.
  140. 30) Test IsVisible.
  141. REPEAT tests 2-30 for all applicable light types.
  142. 31) Delete Light entity.
  143. 32) UNDO deletion.
  144. 33) REDO deletion.
  145. 34) Look for errors.
  146. :return: None
  147. """
  148. import azlmbr.legacy.general as general
  149. import azlmbr.math as math
  150. from editor_python_test_tools.editor_entity_utils import EditorEntity
  151. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  152. from Atom.atom_utils.atom_constants import (AtomComponentProperties, LIGHT_TYPES, INTENSITY_MODE,
  153. ATTENUATION_RADIUS_MODE, SHADOWMAP_SIZE, SHADOW_FILTER_METHOD)
  154. with Tracer() as error_tracer:
  155. # Test setup begins.
  156. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  157. TestHelper.init_idle()
  158. TestHelper.open_level("Graphics", "base_empty")
  159. # Test steps begin.
  160. # 1. Create a Light entity with no components.
  161. light_entity = EditorEntity.create_editor_entity(AtomComponentProperties.light())
  162. Report.critical_result(Tests.light_creation, light_entity.exists())
  163. # 2. Add a Light component to the Light entity.
  164. light_component = light_entity.add_component(AtomComponentProperties.light())
  165. Report.critical_result(Tests.light_component,
  166. light_entity.has_component(AtomComponentProperties.light()))
  167. # 3. Remove the light component.
  168. light_component.remove()
  169. general.idle_wait_frames(1)
  170. Report.critical_result(Tests.light_component_removal,
  171. not light_entity.has_component(AtomComponentProperties.light()))
  172. # 4. Undo the Light component removal.
  173. general.undo()
  174. general.idle_wait_frames(1)
  175. Report.result(Tests.removal_undo,
  176. light_entity.has_component(AtomComponentProperties.light()))
  177. # Copy LIGHT_TYPES to pop the 'unknown' key to prevent it from being run in this test.
  178. light_types_copy = LIGHT_TYPES.copy()
  179. light_types_copy.pop('unknown')
  180. # Cycle through light types to test component properties.
  181. for light_type in light_types_copy.keys():
  182. # Remove the Light component to begin loop with a clean component.
  183. light_component.remove()
  184. general.idle_wait_frames(1)
  185. Report.critical_result(Tests.light_component_removal,
  186. not light_entity.has_component(AtomComponentProperties.light()))
  187. # Add a new Light component to begin parameter tests.
  188. light_component = light_entity.add_component(AtomComponentProperties.light())
  189. # 5. Set light type.
  190. light_component.set_component_property_value(
  191. AtomComponentProperties.light('Light type'), LIGHT_TYPES[light_type])
  192. general.idle_wait_frames(1)
  193. test_light_type = (
  194. f"Set light type: {light_type.upper()}",
  195. f"P0: Light component failed to set {light_type.upper()} type")
  196. Report.result(test_light_type, light_component.get_component_property_value(
  197. AtomComponentProperties.light('Light type')) == LIGHT_TYPES[light_type])
  198. # 6. Check for Shape component.
  199. if LIGHT_TYPES[light_type] in (LIGHT_TYPES['sphere'], LIGHT_TYPES['spot_disk'], LIGHT_TYPES['capsule'],
  200. LIGHT_TYPES['quad'], LIGHT_TYPES['polygon']):
  201. light_shape = LIGHT_SHAPES[light_type]
  202. test_light_shape = (
  203. f"{light_shape} present",
  204. f"P1: {light_shape} was not found")
  205. Report.result(test_light_shape, light_entity.has_component(light_shape))
  206. # 7. Edit Color parameter.
  207. color_value = math.Color(1.0, 0.0, 0.0, 1.0)
  208. light_component.set_component_property_value(AtomComponentProperties.light('Color'), color_value)
  209. general.idle_wait_frames(1)
  210. light_color = light_component.get_component_property_value(
  211. AtomComponentProperties.light('Color'))
  212. Report.result(Tests.edit_light_color, light_color.IsClose(color_value))
  213. # 8. Set Intensity mode.
  214. if LIGHT_TYPES[light_type] not in (LIGHT_TYPES['simple_point'], LIGHT_TYPES['simple_spot']):
  215. for intensity_mode in INTENSITY_MODE.keys():
  216. light_component.set_component_property_value(
  217. AtomComponentProperties.light('Intensity mode'), INTENSITY_MODE[intensity_mode])
  218. general.idle_wait_frames(1)
  219. test_intensity_mode = (
  220. f"Intensity mode set to {intensity_mode}",
  221. f"P1: Intensity mode failed to be set to {intensity_mode}")
  222. Report.result(test_intensity_mode, light_component.get_component_property_value(
  223. AtomComponentProperties.light('Intensity mode')) == INTENSITY_MODE[intensity_mode])
  224. # 9. Edit the Intensity parameter.
  225. light_component.set_component_property_value(AtomComponentProperties.light('Intensity'), 1000)
  226. general.idle_wait_frames(1)
  227. Report.result(Tests.edit_intensity_value,
  228. light_component.get_component_property_value(
  229. AtomComponentProperties.light('Intensity')) == 1000)
  230. # 10. Set the Attenuation radius Mode:
  231. for radius_mode in ATTENUATION_RADIUS_MODE.keys():
  232. light_component.set_component_property_value(
  233. AtomComponentProperties.light('Attenuation radius Mode'), ATTENUATION_RADIUS_MODE[radius_mode])
  234. general.idle_wait_frames(1)
  235. test_attenuation_mode = (
  236. f"Attenuation radius Mode set to {radius_mode}",
  237. f"P1: Attenuation radius Mode failed to be set to {radius_mode}")
  238. Report.result(test_attenuation_mode, light_component.get_component_property_value(
  239. AtomComponentProperties.light('Attenuation radius Mode')) == ATTENUATION_RADIUS_MODE[radius_mode])
  240. # 11. Edit the Attenuation radius Radius parameter (explicit only).
  241. if ATTENUATION_RADIUS_MODE[radius_mode] == ATTENUATION_RADIUS_MODE['explicit']:
  242. light_component.set_component_property_value(
  243. AtomComponentProperties.light('Attenuation radius Radius'), 1000)
  244. general.idle_wait_frames(1)
  245. Report.result(Tests.edit_attenuation_radius,
  246. light_component.get_component_property_value(
  247. AtomComponentProperties.light('Attenuation radius Radius')) == 1000)
  248. # Shadow tests for applicable light types:
  249. if LIGHT_TYPES[light_type] in (LIGHT_TYPES['sphere'], LIGHT_TYPES['spot_disk']):
  250. # 12. Enable Shadows:
  251. light_component.set_component_property_value(
  252. AtomComponentProperties.light('Enable shadow'), True)
  253. general.idle_wait_frames(1)
  254. Report.result(
  255. Tests.enable_shadows,
  256. light_component.get_component_property_value(
  257. AtomComponentProperties.light('Enable shadow')) is True)
  258. # 13. Edit the Shadows Bias parameter.
  259. light_component.set_component_property_value(
  260. AtomComponentProperties.light('Shadows Bias'), 100)
  261. general.idle_wait_frames(1)
  262. Report.result(
  263. Tests.edit_shadow_bias,
  264. light_component.get_component_property_value(
  265. AtomComponentProperties.light('Shadows Bias')) == 100)
  266. # 14. Edit the Normal shadow bias parameter.
  267. light_component.set_component_property_value(
  268. AtomComponentProperties.light('Normal shadow bias'), 10)
  269. general.idle_wait_frames(1)
  270. Report.result(
  271. Tests.edit_normal_bias,
  272. light_component.get_component_property_value(
  273. AtomComponentProperties.light('Normal shadow bias')) == 10)
  274. # 15. Set the Shadowmap size.
  275. for shadowmap_size in SHADOWMAP_SIZE.keys():
  276. light_component.set_component_property_value(
  277. AtomComponentProperties.light('Shadowmap size'), SHADOWMAP_SIZE[shadowmap_size])
  278. general.idle_wait_frames(1)
  279. test_shadowmap_size = (
  280. f"Shadowmap size set to {shadowmap_size}.",
  281. f"P1: Shadowmap size failed to be set to {shadowmap_size}.")
  282. Report.result(test_shadowmap_size, light_component.get_component_property_value(
  283. AtomComponentProperties.light('Shadowmap size')) == SHADOWMAP_SIZE[shadowmap_size])
  284. # Shadow filter method tests.
  285. # 16. Set the Shadow filter method.
  286. for filter_method in SHADOW_FILTER_METHOD.keys():
  287. light_component.set_component_property_value(
  288. AtomComponentProperties.light('Shadow filter method'), SHADOW_FILTER_METHOD[filter_method])
  289. general.idle_wait_frames(1)
  290. test_shadow_filter_method = (
  291. f"Shadow filter method set to {filter_method}",
  292. f"P1: Shadow filter method set to {filter_method}")
  293. Report.result(test_shadow_filter_method, light_component.get_component_property_value(
  294. AtomComponentProperties.light('Shadow filter method')) == SHADOW_FILTER_METHOD[filter_method])
  295. # 17. Edit the Filtering sample count parameter.
  296. if SHADOW_FILTER_METHOD[filter_method] in (SHADOW_FILTER_METHOD['PCF'],
  297. SHADOW_FILTER_METHOD['PCF+ESM']):
  298. light_component.set_component_property_value(
  299. AtomComponentProperties.light('Filtering sample count'), 64)
  300. general.idle_wait_frames(1)
  301. Report.result(Tests.edit_filtering_sample_count,
  302. light_component.get_component_property_value(
  303. AtomComponentProperties.light('Filtering sample count')) == 64)
  304. # 18. Edit the ESM Exponent parameter.
  305. if SHADOW_FILTER_METHOD[filter_method] in (SHADOW_FILTER_METHOD['ESM'],
  306. SHADOW_FILTER_METHOD['PCF+ESM']):
  307. light_component.set_component_property_value(
  308. AtomComponentProperties.light('ESM exponent'), 5000)
  309. general.idle_wait_frames(1)
  310. Report.result(Tests.edit_esm_exponent,
  311. light_component.get_component_property_value(
  312. AtomComponentProperties.light('ESM exponent')) == 5000)
  313. # 19. Disable Shadows (re-enabled after test for game mode verification):
  314. light_component.set_component_property_value(
  315. AtomComponentProperties.light('Enable shadow'), False)
  316. general.idle_wait_frames(1)
  317. Report.result(
  318. Tests.disable_shadows,
  319. light_component.get_component_property_value(
  320. AtomComponentProperties.light('Enable shadow')) is False)
  321. light_component.set_component_property_value(
  322. AtomComponentProperties.light('Enable shadow'), True)
  323. # Shutter tests for applicable light types:
  324. if LIGHT_TYPES[light_type] in (LIGHT_TYPES['spot_disk'], LIGHT_TYPES['simple_spot']):
  325. # 20. Edit the Inner angle parameter:
  326. light_component.set_component_property_value(
  327. AtomComponentProperties.light('Inner angle'), 0.5)
  328. general.idle_wait_frames(1)
  329. Report.result(Tests.edit_inner_angle,
  330. light_component.get_component_property_value(
  331. AtomComponentProperties.light('Inner angle')) == 0.5)
  332. # 21. Edit the Outer angle parameter:
  333. light_component.set_component_property_value(
  334. AtomComponentProperties.light('Outer angle'), 90)
  335. general.idle_wait_frames(1)
  336. Report.result(Tests.edit_outer_angle,
  337. light_component.get_component_property_value(
  338. AtomComponentProperties.light('Outer angle')) == 90)
  339. # Disable/Enable Shutters tests:
  340. if LIGHT_TYPES[light_type] == LIGHT_TYPES['spot_disk']:
  341. # 22. Disable Shutters:
  342. light_component.set_component_property_value(
  343. AtomComponentProperties.light('Enable shutters'), False)
  344. general.idle_wait_frames(1)
  345. Report.result(
  346. Tests.disable_shutters,
  347. light_component.get_component_property_value(
  348. AtomComponentProperties.light('Enable shutters')) is False)
  349. # 23. Enable Shutters:
  350. light_component.set_component_property_value(
  351. AtomComponentProperties.light('Enable shutters'), True)
  352. general.idle_wait_frames(1)
  353. Report.result(
  354. Tests.enable_shutters,
  355. light_component.get_component_property_value(
  356. AtomComponentProperties.light('Enable shutters')) is True)
  357. # Enable/Disable Both directions tests:
  358. if LIGHT_TYPES[light_type] in (LIGHT_TYPES['quad'], LIGHT_TYPES['polygon']):
  359. # 24. Enable Both directions:
  360. light_component.set_component_property_value(
  361. AtomComponentProperties.light('Both directions'), True)
  362. general.idle_wait_frames(1)
  363. Report.result(
  364. Tests.enable_both_directions,
  365. light_component.get_component_property_value(
  366. AtomComponentProperties.light('Both directions')) is True)
  367. # 25. Disable Both directions parameter (re-enabled after test for game-mode verification):
  368. light_component.set_component_property_value(
  369. AtomComponentProperties.light('Both directions'), False)
  370. general.idle_wait_frames(1)
  371. Report.result(
  372. Tests.disable_both_directions,
  373. light_component.get_component_property_value(
  374. AtomComponentProperties.light('Both directions')) is False)
  375. light_component.set_component_property_value(
  376. AtomComponentProperties.light('Both directions'), True)
  377. # Enable/Disable Fast approximation tests:
  378. if LIGHT_TYPES[light_type] == LIGHT_TYPES['quad']:
  379. # 26. Enable Fast approximation:
  380. light_component.set_component_property_value(
  381. AtomComponentProperties.light('Fast approximation'), True)
  382. general.idle_wait_frames(1)
  383. Report.result(
  384. Tests.enable_fast_approximation,
  385. light_component.get_component_property_value(
  386. AtomComponentProperties.light('Fast approximation')) is True)
  387. # 27. Disable Fast approximation:
  388. light_component.set_component_property_value(
  389. AtomComponentProperties.light('Fast approximation'), False)
  390. general.idle_wait_frames(1)
  391. Report.result(
  392. Tests.disable_fast_approximation,
  393. light_component.get_component_property_value(
  394. AtomComponentProperties.light('Fast approximation')) is False)
  395. # 28. Enter/Exit game mode.
  396. TestHelper.enter_game_mode(Tests.enter_game_mode)
  397. general.idle_wait_frames(1)
  398. TestHelper.exit_game_mode(Tests.exit_game_mode)
  399. # 29. Test IsHidden.
  400. light_entity.set_visibility_state(False)
  401. general.idle_wait_frames(1)
  402. Report.result(Tests.is_hidden, light_entity.is_hidden() is True)
  403. # 30. Test IsVisible.
  404. light_entity.set_visibility_state(True)
  405. general.idle_wait_frames(1)
  406. Report.result(Tests.is_visible, light_entity.is_visible() is True)
  407. # 31. Delete Light entity.
  408. light_entity.delete()
  409. general.idle_wait_frames(1)
  410. Report.result(Tests.entity_deleted, not light_entity.exists())
  411. # 32. UNDO deletion.
  412. general.undo()
  413. general.idle_wait_frames(1)
  414. Report.result(Tests.deletion_undo, light_entity.exists())
  415. # 33. REDO deletion.
  416. general.redo()
  417. general.idle_wait_frames(1)
  418. Report.result(Tests.deletion_redo, not light_entity.exists())
  419. # 34. Look for errors asserts.
  420. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  421. for error_info in error_tracer.errors:
  422. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  423. for assert_info in error_tracer.asserts:
  424. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  425. if __name__ == "__main__":
  426. from editor_python_test_tools.utils import Report
  427. Report.start_test(AtomEditorComponents_Light_AddedToEntity)