3
0

hydra_AtomEditorComponents_DisplayMapperAdded.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. display_mapper_creation = (
  14. "Display Mapper Entity successfully created",
  15. "P0: Display Mapper Entity failed to be created")
  16. display_mapper_component = (
  17. "Entity has a Display Mapper component",
  18. "P0: Entity failed to find Display Mapper 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. ldr_color_grading_lut = (
  32. "LDR color Grading LUT asset set",
  33. "P0: LDR color Grading LUT asset could not be set")
  34. enable_ldr_color_grading_lut = (
  35. "Enable LDR color grading LUT set",
  36. "P0: Enable LDR color grading LUT could not be set")
  37. entity_deleted = (
  38. "Entity deleted",
  39. "P0: Entity was not deleted")
  40. deletion_undo = (
  41. "UNDO deletion success",
  42. "P0: UNDO deletion failed")
  43. deletion_redo = (
  44. "REDO deletion success",
  45. "P0: REDO deletion failed")
  46. override_defaults = (
  47. "Override Defaults property set",
  48. "P1: Override Defaults property failed to be set correctly")
  49. alter_surround = (
  50. "Alter Surround property set",
  51. "P1: Alter Surround property failed to be set correctly")
  52. alter_desaturation = (
  53. "Alter Desaturation property set",
  54. "P1: Alter Desaturation property failed to be set correctly")
  55. alter_cat = (
  56. "Alter CAT D60 to D65 property set",
  57. "P1: Alter CAT D60 to D65 property failed to be set correctly")
  58. black_level_min = (
  59. "Cinema Limit (black) property set to minimum value",
  60. "P1: Cinema Limit (black) property failed to take minimum value")
  61. black_level_max = (
  62. "Cinema Limit (black) property set to maximum value",
  63. "P1: Cinema Limit (black) property failed to take maximum value")
  64. white_level_min = (
  65. "Cinema Limit (white) property set to minimum value",
  66. "P1: Cinema Limit (white) property failed to take minimum value")
  67. white_level_max = (
  68. "Cinema Limit (white) property set to maximum value",
  69. "P1: Cinema Limit (white) property failed to take maximum value")
  70. luminance_level_min = (
  71. "Min Point (luminance) property set",
  72. "P1: Min Point (luminance) property failed to set expected value")
  73. luminance_level_mid = (
  74. "Mid Point (luminance) property set",
  75. "P1: Mid Point (luminance) property failed to set expected value")
  76. luminance_level_max = (
  77. "Max Point (luminance) property set",
  78. "P1: Max Point (luminance) property failed to set expected value")
  79. surround_gamma = (
  80. "Surround Gamma property set",
  81. "P1: Surround Gamma property failed to set expected value")
  82. gamma = (
  83. "Gamma property set",
  84. "P1: Gamma property failed to set expected value")
  85. display_mapper_type = (
  86. "Display Mapper Operation Type is correctly set",
  87. "P1: Display Mapper Operation type is not as expected")
  88. # IsClose tolerance defaults to , 1e-9, but float values in some tests need a looser tolerance
  89. TOLERANCE = 1e-6
  90. def AtomEditorComponents_DisplayMapper_AddedToEntity():
  91. """
  92. Summary:
  93. Tests the Display Mapper component can be added to an entity and has the expected functionality.
  94. Test setup:
  95. - Wait for Editor idle loop.
  96. - Open the "Base" level.
  97. Expected Behavior:
  98. The component can be added, used in game mode, hidden/shown, deleted, and has accurate required components.
  99. Creation and deletion undo/redo should also work.
  100. Test Steps:
  101. 1) Create a Display Mapper entity with no components.
  102. 2) Add Display Mapper component to Display Mapper entity.
  103. 3) UNDO the entity creation and component addition.
  104. 4) REDO the entity creation and component addition.
  105. 5) Set LDR color Grading LUT asset.
  106. 6) Set the Display Mapper Operation Type enumerated in DISPLAY_MAPPER_OPERATION_TYPE for each type
  107. 7) Set Enable LDR color grading LUT property True
  108. 8) Toggle Override Defaults
  109. 9) Toggle Alter Surround
  110. 10) Toggle Alter Desaturation
  111. 11) Toggle 'Alter CAT D60 to D65'
  112. 12) Set 'Cinema Limit (black)' max value which is dynamic based on Cinema Limit (white) then min value
  113. 13) Set 'Cinema Limit (white)' max value then min, and finally back to default
  114. 14) Set 'Min Point (luminance)' to high and low value
  115. 15) Set 'Mid Point (luminance)' to high and low value then set default
  116. 16) Set 'Max Point (luminance)' to high and low value then set default
  117. 17) Set 'Surround Gamma' to high and low value
  118. 18) Set 'Gamma' to high and low value
  119. 19) Enter/Exit game mode.
  120. 20) Select and load each preset
  121. 21) Test IsHidden.
  122. 22) Test IsVisible.
  123. 23) Delete Display Mapper entity.
  124. 24) UNDO deletion.
  125. 25) REDO deletion.
  126. 26) Look for errors and asserts.
  127. :return: None
  128. """
  129. import os
  130. import azlmbr.bus as bus
  131. import azlmbr.legacy.general as general
  132. import azlmbr.render as render
  133. from azlmbr.math import Math_IsClose
  134. from editor_python_test_tools.asset_utils import Asset
  135. from editor_python_test_tools.editor_entity_utils import EditorEntity
  136. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  137. from Atom.atom_utils.atom_constants import AtomComponentProperties, DISPLAY_MAPPER_PRESET, DISPLAY_MAPPER_OPERATION_TYPE
  138. with Tracer() as error_tracer:
  139. # Test setup begins.
  140. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  141. TestHelper.init_idle()
  142. TestHelper.open_level("Graphics", "base_empty")
  143. # Test steps begin.
  144. # 1. Create a Display Mapper entity with no components.
  145. display_mapper_entity = EditorEntity.create_editor_entity(AtomComponentProperties.display_mapper())
  146. Report.critical_result(Tests.display_mapper_creation, display_mapper_entity.exists())
  147. # 2. Add Display Mapper component to Display Mapper entity.
  148. display_mapper_component = display_mapper_entity.add_component(AtomComponentProperties.display_mapper())
  149. Report.critical_result(
  150. Tests.display_mapper_component,
  151. display_mapper_entity.has_component(AtomComponentProperties.display_mapper()))
  152. # 3. UNDO the entity creation and component addition.
  153. # -> UNDO component addition.
  154. general.undo()
  155. # -> UNDO naming entity.
  156. general.undo()
  157. # -> UNDO selecting entity.
  158. general.undo()
  159. # -> UNDO entity creation.
  160. general.undo()
  161. general.idle_wait_frames(1)
  162. Report.result(Tests.creation_undo, not display_mapper_entity.exists())
  163. # 4. REDO the entity creation and component addition.
  164. # -> REDO entity creation.
  165. general.redo()
  166. # -> REDO selecting entity.
  167. general.redo()
  168. # -> REDO naming entity.
  169. general.redo()
  170. # -> REDO component addition.
  171. general.redo()
  172. general.idle_wait_frames(1)
  173. Report.result(Tests.creation_redo, display_mapper_entity.exists())
  174. # 5. Set LDR color Grading LUT asset.
  175. display_mapper_asset_path = os.path.join("lookuptables", "lut_sepia.azasset")
  176. display_mapper_asset = Asset.find_asset_by_path(display_mapper_asset_path, False)
  177. display_mapper_component.set_component_property_value(
  178. AtomComponentProperties.display_mapper('LDR color Grading LUT'), display_mapper_asset.id)
  179. Report.result(
  180. Tests.ldr_color_grading_lut,
  181. display_mapper_component.get_component_property_value(
  182. AtomComponentProperties.display_mapper('LDR color Grading LUT')) == display_mapper_asset.id)
  183. for operation_type in DISPLAY_MAPPER_OPERATION_TYPE.keys():
  184. # 6. Set the Display Mapper Operation Type enumerated in DISPLAY_MAPPER_OPERATION_TYPE for each type
  185. display_mapper_component.set_component_property_value(
  186. AtomComponentProperties.display_mapper('Type'), DISPLAY_MAPPER_OPERATION_TYPE[operation_type])
  187. general.idle_wait_frames(3)
  188. set_type = render.DisplayMapperComponentRequestBus(bus.Broadcast, "GetDisplayMapperOperationType")
  189. Report.info(f"DiplayMapperOperationType: {set_type}")
  190. Report.result(Tests.display_mapper_type, set_type == DISPLAY_MAPPER_OPERATION_TYPE[operation_type])
  191. # 7. Set Enable LDR color grading LUT property True
  192. display_mapper_component.set_component_property_value(
  193. AtomComponentProperties.display_mapper('Enable LDR color grading LUT'), True)
  194. Report.result(
  195. Tests.enable_ldr_color_grading_lut,
  196. display_mapper_component.get_component_property_value(
  197. AtomComponentProperties.display_mapper('Enable LDR color grading LUT')) is True)
  198. # 8. Toggle Override Defaults
  199. # Set Override Defaults to False
  200. display_mapper_component.set_component_property_value(
  201. AtomComponentProperties.display_mapper('Override Defaults'), False)
  202. Report.result(
  203. Tests.override_defaults,
  204. display_mapper_component.get_component_property_value(
  205. AtomComponentProperties.display_mapper('Override Defaults')) is False)
  206. # Set Override Defaults to True
  207. display_mapper_component.set_component_property_value(
  208. AtomComponentProperties.display_mapper('Override Defaults'), True)
  209. Report.result(
  210. Tests.override_defaults,
  211. display_mapper_component.get_component_property_value(
  212. AtomComponentProperties.display_mapper('Override Defaults')) is True)
  213. # 9. Toggle Alter Surround
  214. # Set Alter Surround to True
  215. display_mapper_component.set_component_property_value(
  216. AtomComponentProperties.display_mapper('Alter Surround'), True)
  217. Report.result(
  218. Tests.alter_surround,
  219. display_mapper_component.get_component_property_value(
  220. AtomComponentProperties.display_mapper('Alter Surround')) is True)
  221. # Set Alter Surround to False
  222. display_mapper_component.set_component_property_value(
  223. AtomComponentProperties.display_mapper('Alter Surround'), False)
  224. Report.result(
  225. Tests.alter_surround,
  226. display_mapper_component.get_component_property_value(
  227. AtomComponentProperties.display_mapper('Alter Surround')) is False)
  228. # 10. Toggle Alter Desaturation
  229. # Set Alter Desaturation to True
  230. display_mapper_component.set_component_property_value(
  231. AtomComponentProperties.display_mapper('Alter Desaturation'), True)
  232. Report.result(
  233. Tests.alter_desaturation,
  234. display_mapper_component.get_component_property_value(
  235. AtomComponentProperties.display_mapper('Alter Desaturation')) is True)
  236. # Set Alter Desaturation to False
  237. display_mapper_component.set_component_property_value(
  238. AtomComponentProperties.display_mapper('Alter Desaturation'), False)
  239. Report.result(
  240. Tests.alter_desaturation,
  241. display_mapper_component.get_component_property_value(
  242. AtomComponentProperties.display_mapper('Alter Desaturation')) is False)
  243. # 11. Toggle 'Alter CAT D60 to D65'
  244. # Set 'Alter CAT D60 to D65' to True
  245. display_mapper_component.set_component_property_value(
  246. AtomComponentProperties.display_mapper('Alter CAT D60 to D65'), True)
  247. Report.result(
  248. Tests.alter_cat,
  249. display_mapper_component.get_component_property_value(
  250. AtomComponentProperties.display_mapper('Alter CAT D60 to D65')) is True)
  251. # Set 'Alter CAT D60 to D65' to False
  252. display_mapper_component.set_component_property_value(
  253. AtomComponentProperties.display_mapper('Alter CAT D60 to D65'), False)
  254. Report.result(
  255. Tests.alter_cat,
  256. display_mapper_component.get_component_property_value(
  257. AtomComponentProperties.display_mapper('Alter CAT D60 to D65')) is False)
  258. general.idle_wait_frames(1)
  259. # 12. Set 'Cinema Limit (black)' max value which is dynamic based on Cinema Limit (white) then min value
  260. # set max value
  261. display_mapper_component.set_component_property_value(
  262. AtomComponentProperties.display_mapper('Cinema Limit (black)'), value=48.0)
  263. Report.result(Tests.black_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  264. AtomComponentProperties.display_mapper('Cinema Limit (black)')), 48.0, TOLERANCE))
  265. # set min value
  266. display_mapper_component.set_component_property_value(
  267. AtomComponentProperties.display_mapper('Cinema Limit (black)'), value=0.02)
  268. Report.result(Tests.black_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  269. AtomComponentProperties.display_mapper('Cinema Limit (black)')), 0.02, TOLERANCE))
  270. # 13. Set 'Cinema Limit (white)' maximum value then min, and finally back to default
  271. # set max value
  272. display_mapper_component.set_component_property_value(
  273. AtomComponentProperties.display_mapper('Cinema Limit (white)'), value=4000.0)
  274. Report.result(Tests.white_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  275. AtomComponentProperties.display_mapper('Cinema Limit (white)')), 4000.0, TOLERANCE))
  276. # Set min value which is dynamic based on Cinema Limit (black)
  277. display_mapper_component.set_component_property_value(
  278. AtomComponentProperties.display_mapper('Cinema Limit (white)'), value=0.02)
  279. Report.result(Tests.white_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  280. AtomComponentProperties.display_mapper('Cinema Limit (white)')), 0.02, TOLERANCE))
  281. # Reset this to the default 48 so following cycles don't impact Cinema Limit (Black)
  282. display_mapper_component.set_component_property_value(
  283. AtomComponentProperties.display_mapper('Cinema Limit (white)'), value=48.0)
  284. # 14. Set 'Min Point (luminance)' to high and low value
  285. # set high value
  286. display_mapper_component.set_component_property_value(
  287. AtomComponentProperties.display_mapper('Min Point (luminance)'), value=4.8)
  288. Report.info(display_mapper_component.get_component_property_value(
  289. AtomComponentProperties.display_mapper('Min Point (luminance)')))
  290. Report.result(Tests.luminance_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  291. AtomComponentProperties.display_mapper('Min Point (luminance)')), 4.8, TOLERANCE))
  292. # set low value
  293. display_mapper_component.set_component_property_value(
  294. AtomComponentProperties.display_mapper('Min Point (luminance)'), value=0.002)
  295. Report.result(Tests.luminance_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  296. AtomComponentProperties.display_mapper('Min Point (luminance)')), 0.002, TOLERANCE))
  297. # 15. Set 'Mid Point (luminance)' to high and low value then set default
  298. # set high value
  299. display_mapper_component.set_component_property_value(
  300. AtomComponentProperties.display_mapper('Mid Point (luminance)'), value=1005.0)
  301. Report.result(Tests.luminance_level_mid, Math_IsClose(display_mapper_component.get_component_property_value(
  302. AtomComponentProperties.display_mapper('Mid Point (luminance)')), 1005.0, TOLERANCE))
  303. # set low value
  304. display_mapper_component.set_component_property_value(
  305. AtomComponentProperties.display_mapper('Mid Point (luminance)'), value=0.002)
  306. Report.result(Tests.luminance_level_mid, Math_IsClose(display_mapper_component.get_component_property_value(
  307. AtomComponentProperties.display_mapper('Mid Point (luminance)')), 0.002, TOLERANCE))
  308. # restore the default since as this impacts the range of 'Min Point (luminance)'
  309. display_mapper_component.set_component_property_value(
  310. AtomComponentProperties.display_mapper('Mid Point (luminance)'), value=4.8)
  311. # 16. Set 'Max Point (luminance)' to high and low value then set default
  312. # set a high value
  313. display_mapper_component.set_component_property_value(
  314. AtomComponentProperties.display_mapper('Max Point (luminance)'), value=4000.0)
  315. Report.result(Tests.luminance_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  316. AtomComponentProperties.display_mapper('Max Point (luminance)')), 4000.0, TOLERANCE))
  317. # set a low value
  318. display_mapper_component.set_component_property_value(
  319. AtomComponentProperties.display_mapper('Max Point (luminance)'), value=0.002)
  320. Report.result(Tests.luminance_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  321. AtomComponentProperties.display_mapper('Max Point (luminance)')), 0.002, TOLERANCE))
  322. # restore the default since this impacts the range of 'Mid Point (luminance)'
  323. display_mapper_component.set_component_property_value(
  324. AtomComponentProperties.display_mapper('Max Point (luminance)'), value=1005.7191162)
  325. # 17. Set 'Surround Gamma' to high and low value
  326. # set a high value
  327. display_mapper_component.set_component_property_value(
  328. AtomComponentProperties.display_mapper('Surround Gamma'), value=1.2)
  329. Report.result(Tests.surround_gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  330. AtomComponentProperties.display_mapper('Surround Gamma')), 1.2, TOLERANCE))
  331. # set a low value
  332. display_mapper_component.set_component_property_value(
  333. AtomComponentProperties.display_mapper('Surround Gamma'), value=0.6)
  334. Report.result(Tests.surround_gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  335. AtomComponentProperties.display_mapper('Surround Gamma')), 0.6, TOLERANCE))
  336. # 18. Set 'Gamma' to high and low value
  337. # set a high value
  338. display_mapper_component.set_component_property_value(
  339. AtomComponentProperties.display_mapper('Gamma'), value=4.0)
  340. Report.result(Tests.gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  341. AtomComponentProperties.display_mapper('Gamma')), 4.0, TOLERANCE))
  342. # set a low value
  343. display_mapper_component.set_component_property_value(
  344. AtomComponentProperties.display_mapper('Gamma'), value=0.2)
  345. Report.result(Tests.gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  346. AtomComponentProperties.display_mapper('Gamma')), 0.2, TOLERANCE))
  347. # 19. Enter/Exit game mode.
  348. TestHelper.enter_game_mode(Tests.enter_game_mode)
  349. general.idle_wait_frames(1)
  350. TestHelper.exit_game_mode(Tests.exit_game_mode)
  351. display_mapper_component.set_component_property_value(
  352. AtomComponentProperties.display_mapper('Enable LDR color grading LUT'), False)
  353. display_mapper_component.set_component_property_value(
  354. AtomComponentProperties.display_mapper('Enable LDR color grading LUT'), True)
  355. cinema_limit_white_presets = [48.0, 184.3200073, 368.6400146, 737.2800293]
  356. for preset in DISPLAY_MAPPER_PRESET.keys():
  357. # 20. Select and load each preset
  358. display_mapper_component.set_component_property_value(
  359. AtomComponentProperties.display_mapper('Preset Selection'), DISPLAY_MAPPER_PRESET[preset])
  360. general.idle_wait_frames(1)
  361. render.DisplayMapperComponentRequestBus(
  362. bus.Broadcast,
  363. "LoadPreset",
  364. display_mapper_component.get_component_property_value(
  365. AtomComponentProperties.display_mapper('Preset Selection')))
  366. general.idle_wait_frames(1)
  367. # check some value to confirm preset loaded
  368. test_preset = (f"Preset {preset} loaded expected value",
  369. f"P1: Preset {preset} failed to load values as expected")
  370. Report.result(test_preset, Math_IsClose(
  371. display_mapper_component.get_component_property_value(
  372. AtomComponentProperties.display_mapper('Cinema Limit (white)')),
  373. cinema_limit_white_presets[DISPLAY_MAPPER_PRESET[preset]], TOLERANCE))
  374. # 21. Test IsHidden.
  375. display_mapper_entity.set_visibility_state(False)
  376. Report.result(Tests.is_hidden, display_mapper_entity.is_hidden() is True)
  377. # 22. Test IsVisible.
  378. display_mapper_entity.set_visibility_state(True)
  379. general.idle_wait_frames(1)
  380. Report.result(Tests.is_visible, display_mapper_entity.is_visible() is True)
  381. # 23. Delete Display Mapper entity.
  382. display_mapper_entity.delete()
  383. Report.result(Tests.entity_deleted, not display_mapper_entity.exists())
  384. # 24. UNDO deletion.
  385. general.undo()
  386. general.idle_wait_frames(1)
  387. Report.result(Tests.deletion_undo, display_mapper_entity.exists())
  388. # 25. REDO deletion.
  389. general.redo()
  390. general.idle_wait_frames(1)
  391. Report.result(Tests.deletion_redo, not display_mapper_entity.exists())
  392. # 26. Look for errors and asserts.
  393. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  394. for error_info in error_tracer.errors:
  395. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  396. for assert_info in error_tracer.asserts:
  397. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  398. if __name__ == "__main__":
  399. from editor_python_test_tools.utils import Report
  400. Report.start_test(AtomEditorComponents_DisplayMapper_AddedToEntity)