diff --git a/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py b/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py index 2655a79fde..559f4aebee 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py @@ -257,8 +257,13 @@ class AtomComponentProperties: 'name': 'Light', 'Attenuation Radius Mode': 'Controller|Configuration|Attenuation radius|Mode', 'Color': 'Controller|Configuration|Color', + 'Enable shadow': 'Controller|Configuration|Shadows|Enable shadow', + 'Enable shutters': 'Controller|Configuration|Shutters|Enable shutters', + 'Inner angle': 'Controller|Configuration|Shutters|Inner angle', 'Intensity': 'Controller|Configuration|Intensity', 'Light type': 'Controller|Configuration|Light type', + 'Outer angle': 'Controller|Configuration|Shutters|Outer angle', + 'Shadowmap size': 'Controller|Configuration|Shadows|Shadowmap size', } return properties[property] diff --git a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomGPU_SpotLightScreenshotTest.py b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomGPU_SpotLightScreenshotTest.py index e7ac32b339..9b1c88a4fc 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomGPU_SpotLightScreenshotTest.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomGPU_SpotLightScreenshotTest.py @@ -7,9 +7,54 @@ SPDX-License-Identifier: Apache-2.0 OR MIT class Tests: - tbd = ( - "tbd", - "tbd") + directional_light_component_disabled = ( + "Disabled Directional Light component", + "Couldn't disable Directional Light component") + enter_game_mode = ( + "Entered game mode", + "Failed to enter game mode") + exit_game_mode = ( + "Exited game mode", + "Couldn't exit game mode") + global_skylight_component_disabled = ( + "Disabled Global Skylight (IBL) component", + "Couldn't disable Global Skylight (IBL) component") + hdri_skybox_component_disabled = ( + "Disabled HDRi Skybox component", + "Couldn't disable HDRi Skybox component") + light_component_added = ( + "Light component added", + "Couldn't add Light component") + light_component_color_property_set = ( + "Color property was set", + "Color property was not set") + light_component_enable_shadow_property_set = ( + "Enable shadow property was set", + "Enable shadow property was not set") + light_component_enable_shutters_property_set = ( + "Enable shutters property was set", + "Enable shutters property was not set") + light_component_inner_angle_property_set = ( + "Inner angle property was set", + "Inner angle property was not set") + light_component_intensity_property_set = ( + "Intensity property was set", + "Intensity property was not set") + light_component_light_type_property_set = ( + "Light type property was set", + "Light type property was not set") + light_component_outer_angle_property_set = ( + "Outer angle property was set", + "Outer angle property was not set") + light_component_shadowmap_size_property_set = ( + "Shadowmap size was set", + "Shadowmap size was not set") + material_component_material_asset_property_set = ( + "Material Asset property was set", + "Material Asset property was not set") + spot_light_entity_created = ( + "Spot Light entity created", + "Couldn't create Spot Light entity") def AtomGPU_LightComponent_SpotLightScreenshotsMatchGoldenImages(): @@ -28,17 +73,26 @@ def AtomGPU_LightComponent_SpotLightScreenshotsMatchGoldenImages(): The test scripts sets up the scenes correctly and takes accurate screenshots. Test Steps: - 1. Add Directional Light component to the existing Directional Light entity. - 2. + 1. Find the Directional Light entity then disable its Directional Light component. + 2. Disable Global Skylight (IBL) and HDRi Skybox components on the Global Skylight entity. + + :return: None """ + import os import azlmbr.legacy.general as general import azlmbr.paths + from editor_python_test_tools.asset_utils import Asset + from editor_python_test_tools.editor_entity_utils import EditorEntity from editor_python_test_tools.utils import Report, Tracer, TestHelper + from Atom.atom_utils.atom_constants import AtomComponentProperties, LIGHT_TYPES from Atom.atom_utils.atom_component_helper import initial_viewport_setup, create_basic_atom_rendering_scene + from Atom.atom_utils.screenshot_utils import ScreenshotHelper + + DEGREE_RADIAN_FACTOR = 0.0174533 with Tracer() as error_tracer: # Test setup begins. @@ -56,14 +110,153 @@ def AtomGPU_LightComponent_SpotLightScreenshotsMatchGoldenImages(): create_basic_atom_rendering_scene() # Test steps begin. - # 1. - - # ???. Look for errors. - TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0) - for error_info in error_tracer.errors: - Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}") - for assert_info in error_tracer.asserts: - Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}") + # 1. Find the Directional Light entity then disable its Directional Light component. + directional_light_name = AtomComponentProperties.directional_light() + directional_light_entity = EditorEntity.find_editor_entity(directional_light_name) + directional_light_component = directional_light_entity.get_components_of_type([directional_light_name])[0] + directional_light_component.disable_component() + Report.critical_result(Tests.directional_light_component_disabled, not directional_light_component.is_enabled()) + + # 2. Disable Global Skylight (IBL) component on the Global Skylight (IBL) entity. + global_skylight_name = AtomComponentProperties.global_skylight() + global_skylight_entity = EditorEntity.find_editor_entity(global_skylight_name) + global_skylight_component = global_skylight_entity.get_components_of_type([global_skylight_name])[0] + global_skylight_component.disable_component() + Report.critical_result(Tests.global_skylight_component_disabled, not global_skylight_component.is_enabled()) + + # 3. Disable HDRi Skybox component on the Global Skylight (IBL) entity + hdri_skybox_name = AtomComponentProperties.hdri_skybox() + hdri_skybox_component = global_skylight_entity.get_components_of_type([hdri_skybox_name])[0] + hdri_skybox_component.disable_component() + Report.critical_result(Tests.hdri_skybox_component_disabled, not hdri_skybox_component.is_enabled()) + + # 4. Create a Spot Light entity and rotate it. + spot_light_name = "Spot Light" + spot_light_entity = EditorEntity.create_editor_entity_at( + azlmbr.math.Vector3(0.7, -2.0, 1.0), spot_light_name) + rotation = azlmbr.math.Vector3(DEGREE_RADIAN_FACTOR * 300.0, 0.0, 0.0) + spot_light_entity.set_local_rotation(rotation) + Report.critical_result(Tests.spot_light_entity_created, spot_light_entity.exists()) + + # 5. Attach a Light component to the Spot Light entity. + light_name = AtomComponentProperties.light() + light_component = spot_light_entity.add_component(light_name) + Report.critical_result(Tests.light_component_added, light_component.is_enabled()) + + # 6. Set the Light component Light Type to Spot (disk). + light_component.set_component_property_value( + AtomComponentProperties.light('Light type'), LIGHT_TYPES['spot_disk']) + Report.result( + Tests.light_component_light_type_property_set, + light_component.get_component_property_value( + AtomComponentProperties.light('Light type')) == LIGHT_TYPES['spot_disk']) + + # 7. Enter game mode and take a screenshot then exit game mode. + TestHelper.enter_game_mode(Tests.enter_game_mode) + TestHelper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=4.0) + ScreenshotHelper(general.idle_wait_frames).capture_screenshot_blocking("SpotLight_1.ppm") + TestHelper.exit_game_mode(Tests.exit_game_mode) + TestHelper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=4.0) + + # 8. Change the default material asset for the Ground Plane entity. + ground_plane_name = "Ground Plane" + ground_plane_entity = EditorEntity.find_editor_entity(ground_plane_name) + ground_plane_material_component_name = AtomComponentProperties.material() + ground_plane_material_component = ground_plane_entity.get_components_of_type( + [ground_plane_material_component_name])[0] + ground_plane_material_asset_path = os.path.join( + "Materials", "Presets", "Macbeth", "22_neutral_5-0_0-70d.azmaterial") + ground_plane_material_asset = Asset.find_asset_by_path(ground_plane_material_asset_path, False) + ground_plane_material_component.set_component_property_value( + AtomComponentProperties.material('Material Asset'), ground_plane_material_asset.id) + Report.result( + Tests.material_component_material_asset_property_set, + light_component.get_component_property_value(AtomComponentProperties.material('Material Asset'))) + + # 9. Enter game mode and take a screenshot then exit game mode. + TestHelper.enter_game_mode(Tests.enter_game_mode) + TestHelper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=4.0) + ScreenshotHelper(general.idle_wait_frames).capture_screenshot_blocking("SpotLight_2.ppm") + TestHelper.exit_game_mode(Tests.exit_game_mode) + TestHelper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=4.0) + + # 10. Increase the Intensity value of the Light component. + light_component.set_component_property_value(AtomComponentProperties.light('Intensity'), 800.0) + Report.result( + Tests.light_component_intensity_property_set, + light_component.get_component_property_value( + AtomComponentProperties.light('Intensity')) == 800.0) + + # 11. Enter game mode and take a screenshot then exit game mode. + TestHelper.enter_game_mode(Tests.enter_game_mode) + TestHelper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=4.0) + ScreenshotHelper(general.idle_wait_frames).capture_screenshot_blocking("SpotLight_3.ppm") + TestHelper.exit_game_mode(Tests.exit_game_mode) + TestHelper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=4.0) + + # 12. Change the Light component Color property value. + color_value = azlmbr.math.Color(47.0 / 255.0, 75.0 / 255.0, 37.0 / 255.0, 255.0 / 255.0) + light_component.set_component_property_value(AtomComponentProperties.light('Color'), color_value) + Report.result( + Tests.light_component_color_property_set, + light_component.get_component_property_value(AtomComponentProperties.light('Color')) == color_value) + + # 13. Enter game mode and take a screenshot then exit game mode. + TestHelper.enter_game_mode(Tests.enter_game_mode) + TestHelper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=4.0) + ScreenshotHelper(general.idle_wait_frames).capture_screenshot_blocking("SpotLight_4.ppm") + TestHelper.exit_game_mode(Tests.exit_game_mode) + TestHelper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=4.0) + + # 14. Change the Light component Enable shutters, Inner angle, and Outer angle property values. + enable_shutters = True + inner_angle = 60.0 + outer_angle = 75.0 + light_component.set_component_property_value(AtomComponentProperties.light('Enable shutters'), enable_shutters) + light_component.set_component_property_value(AtomComponentProperties.light('Inner angle'), inner_angle) + light_component.set_component_property_value(AtomComponentProperties.light('Outer angle'), outer_angle) + Report.result( + Tests.light_component_enable_shutters_property_set, + light_component.get_component_property_value( + AtomComponentProperties.light('Enable shutters')) == enable_shutters) + Report.result( + Tests.light_component_inner_angle_property_set, + light_component.get_component_property_value(AtomComponentProperties.light('Inner angle')) == inner_angle) + Report.result( + Tests.light_component_outer_angle_property_set, + light_component.get_component_property_value(AtomComponentProperties.light('Outer angle')) == outer_angle) + + # 15. Enter game mode and take a screenshot then exit game mode. + TestHelper.enter_game_mode(Tests.enter_game_mode) + TestHelper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=4.0) + ScreenshotHelper(general.idle_wait_frames).capture_screenshot_blocking("SpotLight_5.ppm") + TestHelper.exit_game_mode(Tests.exit_game_mode) + TestHelper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=4.0) + + # 16. Change the Light component Enable shadow and Shadowmap size property values then move Spot Light entity. + light_component.set_component_property_value(AtomComponentProperties.light('Enable shadow'), True) + light_component.set_component_property_value(AtomComponentProperties.light('Shadowmap size'), 256.0) + spot_light_entity.set_world_rotation(azlmbr.math.Vector3(0.7, -2.0, 1.9)) + Report.result( + Tests.light_component_enable_shadow_property_set, + light_component.get_component_property_value(AtomComponentProperties.light('Enable shadow')) is True) + Report.result( + Tests.light_component_shadowmap_size_property_set, + light_component.get_component_property_value(AtomComponentProperties.light('Shadowmap size')) == 256.0) + + # 17. Enter game mode and take a screenshot then exit game mode. + TestHelper.enter_game_mode(Tests.enter_game_mode) + TestHelper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=4.0) + ScreenshotHelper(general.idle_wait_frames).capture_screenshot_blocking("SpotLight_6.ppm") + TestHelper.exit_game_mode(Tests.exit_game_mode) + TestHelper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=4.0) + + # 18. Look for errors. + TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0) + for error_info in error_tracer.errors: + Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}") + for assert_info in error_tracer.asserts: + Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}") if __name__ == "__main__": diff --git a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_GPUTest_BasicLevelSetup.py b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_GPUTest_BasicLevelSetup.py deleted file mode 100644 index 1641b529ae..0000000000 --- a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_GPUTest_BasicLevelSetup.py +++ /dev/null @@ -1,200 +0,0 @@ -""" -Copyright (c) Contributors to the Open 3D Engine Project. -For complete copyright and license terms please see the LICENSE at the root of this distribution. - -SPDX-License-Identifier: Apache-2.0 OR MIT -""" - -import os - -import editor_python_test_tools.hydra_editor_utils as hydra -from editor_python_test_tools.editor_test_helper import EditorTestHelper -from Atom.atom_utils.screenshot_utils import ScreenshotHelper - -SCREEN_WIDTH = 1280 -SCREEN_HEIGHT = 720 -DEGREE_RADIAN_FACTOR = 0.0174533 - -helper = EditorTestHelper(log_prefix="Test_Atom_BasicLevelSetup") - - -def run(): - """ - 1. View -> Layouts -> Restore Default Layout, sets the viewport to ratio 16:9 @ 1280 x 720 - 2. Runs console command r_DisplayInfo = 0 - 3. Deletes all entities currently present in the level. - 4. Creates a "default_level" entity to hold all other entities, setting the translate values to x:0, y:0, z:0 - 5. Adds a Grid component to the "default_level" & updates its Grid Spacing to 1.0m - 6. Adds a "global_skylight" entity to "default_level", attaching an HDRi Skybox w/ a Cubemap Texture. - 7. Adds a Global Skylight (IBL) component w/ diffuse image and specular image to "global_skylight" entity. - 8. Adds a "ground_plane" entity to "default_level", attaching a Mesh component & Material component. - 9. Adds a "directional_light" entity to "default_level" & adds a Directional Light component. - 10. Adds a "sphere" entity to "default_level" & adds a Mesh component with a Material component to it. - 11. Adds a "camera" entity to "default_level" & adds a Camera component with 80 degree FOV and Transform values: - Translate - x:5.5m, y:-12.0m, z:9.0m - Rotate - x:-27.0, y:-12.0, z:25.0 - 12. Finally enters game mode, takes a screenshot, & exits game mode. - :return: None - """ - import azlmbr.asset as asset - import azlmbr.bus as bus - import azlmbr.camera as camera - import azlmbr.entity as entity - import azlmbr.legacy.general as general - import azlmbr.math as math - import azlmbr.paths - import azlmbr.editor as editor - - def initial_viewport_setup(screen_width, screen_height): - general.set_viewport_size(screen_width, screen_height) - general.update_viewport() - helper.wait_for_condition( - function=lambda: helper.isclose(a=general.get_viewport_size().x, b=SCREEN_WIDTH, rel_tol=0.1) - and helper.isclose(a=general.get_viewport_size().y, b=SCREEN_HEIGHT, rel_tol=0.1), - timeout_in_seconds=4.0 - ) - result = helper.isclose(a=general.get_viewport_size().x, b=SCREEN_WIDTH, rel_tol=0.1) and helper.isclose( - a=general.get_viewport_size().y, b=SCREEN_HEIGHT, rel_tol=0.1) - general.log(general.get_viewport_size().x) - general.log(general.get_viewport_size().y) - general.log(general.get_viewport_size().z) - general.log(f"Viewport is set to the expected size: {result}") - general.run_console("r_DisplayInfo = 0") - - def after_level_load(): - """Function to call after creating/opening a level to ensure it loads.""" - # Give everything a second to initialize. - general.idle_enable(True) - general.idle_wait(1.0) - general.update_viewport() - general.idle_wait(0.5) # half a second is more than enough for updating the viewport. - - # Close out problematic windows, FPS meters, and anti-aliasing. - if general.is_helpers_shown(): # Turn off the helper gizmos if visible - general.toggle_helpers() - general.idle_wait(1.0) - if general.is_pane_visible("Error Report"): # Close Error Report windows that block focus. - general.close_pane("Error Report") - if general.is_pane_visible("Error Log"): # Close Error Log windows that block focus. - general.close_pane("Error Log") - general.idle_wait(1.0) - general.run_console("r_displayInfo=0") - general.idle_wait(1.0) - - # Wait for Editor idle loop before executing Python hydra scripts. - general.idle_enable(True) - - # Basic setup for opened level. - helper.open_level(level_name="Base") - after_level_load() - initial_viewport_setup(SCREEN_WIDTH, SCREEN_HEIGHT) - - # Create default_level entity - search_filter = azlmbr.entity.SearchFilter() - all_entities = entity.SearchBus(azlmbr.bus.Broadcast, "SearchEntities", search_filter) - editor.ToolsApplicationRequestBus(bus.Broadcast, "DeleteEntities", all_entities) - - default_level = hydra.Entity("default_level") - position = math.Vector3(0.0, 0.0, 0.0) - default_level.create_entity(position, ["Grid"]) - default_level.get_set_test(0, "Controller|Configuration|Secondary Grid Spacing", 1.0) - - # Create global_skylight entity and set the properties - global_skylight = hydra.Entity("global_skylight") - global_skylight.create_entity( - entity_position=math.Vector3(0.0, 0.0, 0.0), - components=["HDRi Skybox", "Global Skylight (IBL)"], - parent_id=default_level.id - ) - global_skylight_image_asset_path = os.path.join("LightingPresets", "default_iblskyboxcm.exr.streamingimage") - global_skylight_image_asset = asset.AssetCatalogRequestBus( - bus.Broadcast, "GetAssetIdByPath", global_skylight_image_asset_path, math.Uuid(), False) - global_skylight.get_set_test(0, "Controller|Configuration|Cubemap Texture", global_skylight_image_asset) - hydra.get_set_test(global_skylight, 1, "Controller|Configuration|Diffuse Image", global_skylight_image_asset) - hydra.get_set_test(global_skylight, 1, "Controller|Configuration|Specular Image", global_skylight_image_asset) - - # Create ground_plane entity and set the properties - ground_plane = hydra.Entity("ground_plane") - ground_plane.create_entity( - entity_position=math.Vector3(0.0, 0.0, 0.0), - components=["Material"], - parent_id=default_level.id - ) - azlmbr.components.TransformBus(azlmbr.bus.Event, "SetLocalUniformScale", ground_plane.id, 32.0) - - # Work around to add the correct Atom Mesh component and asset. - mesh_type_id = azlmbr.globals.property.EditorMeshComponentTypeId - ground_plane.components.append( - editor.EditorComponentAPIBus( - bus.Broadcast, "AddComponentsOfType", ground_plane.id, [mesh_type_id] - ).GetValue()[0] - ) - ground_plane_mesh_asset_path = os.path.join("TestData", "Objects", "plane.azmodel") - ground_plane_mesh_asset = asset.AssetCatalogRequestBus( - bus.Broadcast, "GetAssetIdByPath", ground_plane_mesh_asset_path, math.Uuid(), False) - hydra.get_set_test(ground_plane, 1, "Controller|Configuration|Mesh Asset", ground_plane_mesh_asset) - - # Add Atom Material component and asset. - ground_plane_material_asset_path = os.path.join("Materials", "Presets", "PBR", "metal_chrome.azmaterial") - ground_plane_material_asset = asset.AssetCatalogRequestBus( - bus.Broadcast, "GetAssetIdByPath", ground_plane_material_asset_path, math.Uuid(), False) - ground_plane.get_set_test(0, "Default Material|Material Asset", ground_plane_material_asset) - - # Create directional_light entity and set the properties - directional_light = hydra.Entity("directional_light") - directional_light.create_entity( - entity_position=math.Vector3(0.0, 0.0, 10.0), - components=["Directional Light"], - parent_id=default_level.id - ) - rotation = math.Vector3(DEGREE_RADIAN_FACTOR * -90.0, 0.0, 0.0) - azlmbr.components.TransformBus(azlmbr.bus.Event, "SetLocalRotation", directional_light.id, rotation) - - # Create sphere entity and set the properties - sphere = hydra.Entity("sphere") - sphere.create_entity( - entity_position=math.Vector3(0.0, 0.0, 1.0), - components=["Material"], - parent_id=default_level.id - ) - - # Work around to add the correct Atom Mesh component and asset. - sphere.components.append( - editor.EditorComponentAPIBus( - bus.Broadcast, "AddComponentsOfType", sphere.id, [mesh_type_id] - ).GetValue()[0] - ) - sphere_mesh_asset_path = os.path.join("Models", "sphere.azmodel") - sphere_mesh_asset = asset.AssetCatalogRequestBus( - bus.Broadcast, "GetAssetIdByPath", sphere_mesh_asset_path, math.Uuid(), False) - hydra.get_set_test(sphere, 1, "Controller|Configuration|Mesh Asset", sphere_mesh_asset) - - # Add Atom Material component and asset. - sphere_material_asset_path = os.path.join("Materials", "Presets", "PBR", "metal_brass_polished.azmaterial") - sphere_material_asset = asset.AssetCatalogRequestBus( - bus.Broadcast, "GetAssetIdByPath", sphere_material_asset_path, math.Uuid(), False) - sphere.get_set_test(0, "Default Material|Material Asset", sphere_material_asset) - - # Create camera component and set the properties - camera_entity = hydra.Entity("camera") - position = math.Vector3(5.5, -12.0, 9.0) - camera_entity.create_entity(components=["Camera"], entity_position=position, parent_id=default_level.id) - rotation = math.Vector3( - DEGREE_RADIAN_FACTOR * -27.0, DEGREE_RADIAN_FACTOR * -12.0, DEGREE_RADIAN_FACTOR * 25.0 - ) - azlmbr.components.TransformBus(azlmbr.bus.Event, "SetLocalRotation", camera_entity.id, rotation) - camera_entity.get_set_test(0, "Controller|Configuration|Field of view", 60.0) - camera.EditorCameraViewRequestBus(azlmbr.bus.Event, "ToggleCameraAsActiveView", camera_entity.id) - - # Enter game mode, take screenshot, & exit game mode. - general.idle_wait(0.5) - general.enter_game_mode() - general.idle_wait(1.0) - helper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=2.0) - ScreenshotHelper(general.idle_wait_frames).capture_screenshot_blocking(f"{'AtomBasicLevelSetup'}.ppm") - general.exit_game_mode() - helper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=2.0) - - -if __name__ == "__main__": - run() diff --git a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_GPUTest_LightComponent.py b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_GPUTest_LightComponent.py deleted file mode 100644 index f69ceb2120..0000000000 --- a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_GPUTest_LightComponent.py +++ /dev/null @@ -1,261 +0,0 @@ -""" -Copyright (c) Contributors to the Open 3D Engine Project. -For complete copyright and license terms please see the LICENSE at the root of this distribution. - -SPDX-License-Identifier: Apache-2.0 OR MIT -""" -import os -import sys - -import azlmbr.asset as asset -import azlmbr.bus as bus -import azlmbr.editor as editor -import azlmbr.math as math -import azlmbr.paths -import azlmbr.legacy.general as general - -sys.path.append(os.path.join(azlmbr.paths.projectroot, "Gem", "PythonTests")) - -import editor_python_test_tools.hydra_editor_utils as hydra -from Atom.atom_utils import atom_component_helper, atom_constants, screenshot_utils -from editor_python_test_tools.editor_test_helper import EditorTestHelper - -helper = EditorTestHelper(log_prefix="Atom_EditorTestHelper") - -LEVEL_NAME = "Base" -LIGHT_COMPONENT = "Light" -LIGHT_TYPE_PROPERTY = 'Controller|Configuration|Light type' -DEGREE_RADIAN_FACTOR = 0.0174533 - - -def run(): - """ - Sets up the tests by making sure the required level is created & setup correctly. - It then executes 2 test cases - see each associated test function's docstring for more info. - - Finally prints the string "Light component tests completed" after completion - - Tests will fail immediately if any of these log lines are found: - 1. Trace::Assert - 2. Trace::Error - 3. Traceback (most recent call last): - - :return: None - """ - atom_component_helper.create_basic_atom_level(level_name=LEVEL_NAME) - - # Run tests. - area_light_test() - spot_light_test() - general.log("Light component tests completed.") - - -def area_light_test(): - """ - Basic test for the "Light" component attached to an "area_light" entity. - - Test Case - Light Component: Capsule, Spot (disk), and Point (sphere): - 1. Creates "area_light" entity w/ a Light component that has a Capsule Light type w/ the color set to 255, 0, 0 - 2. Enters game mode to take a screenshot for comparison, then exits game mode. - 3. Sets the Light component Intensity Mode to Lumens (default). - 4. Ensures the Light component Mode is Automatic (default). - 5. Sets the Intensity value of the Light component to 0.0 - 6. Enters game mode again, takes another screenshot for comparison, then exits game mode. - 7. Updates the Intensity value of the Light component to 1000.0 - 8. Enters game mode again, takes another screenshot for comparison, then exits game mode. - 9. Swaps the Capsule light type option to Spot (disk) light type on the Light component - 10. Updates "area_light" entity Transform rotate value to x: 90.0, y:0.0, z:0.0 - 11. Enters game mode again, takes another screenshot for comparison, then exits game mode. - 12. Swaps the Spot (disk) light type for the Point (sphere) light type in the Light component. - 13. Enters game mode again, takes another screenshot for comparison, then exits game mode. - 14. Deletes the Light component from the "area_light" entity and verifies its successful. - """ - # Create an "area_light" entity with "Light" component using Light type of "Capsule" - area_light_entity_name = "area_light" - area_light = hydra.Entity(area_light_entity_name) - area_light.create_entity(math.Vector3(-1.0, -2.0, 3.0), [LIGHT_COMPONENT]) - general.log( - f"{area_light_entity_name}_test: Component added to the entity: " - f"{hydra.has_components(area_light.id, [LIGHT_COMPONENT])}") - light_component_id_pair = hydra.attach_component_to_entity(area_light.id, LIGHT_COMPONENT) - - # Select the "Capsule" light type option. - azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, - 'SetComponentProperty', - light_component_id_pair, - LIGHT_TYPE_PROPERTY, - atom_constants.LIGHT_TYPES['capsule'] - ) - - # Update color and take screenshot in game mode - color = math.Color(255.0, 0.0, 0.0, 0.0) - area_light.get_set_test(0, "Controller|Configuration|Color", color) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("AreaLight_1", area_light_entity_name) - - # Update intensity value to 0.0 and take screenshot in game mode - area_light.get_set_test(0, "Controller|Configuration|Attenuation Radius|Mode", 1) - area_light.get_set_test(0, "Controller|Configuration|Intensity", 0.0) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("AreaLight_2", area_light_entity_name) - - # Update intensity value to 1000.0 and take screenshot in game mode - area_light.get_set_test(0, "Controller|Configuration|Intensity", 1000.0) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("AreaLight_3", area_light_entity_name) - - # Swap the "Capsule" light type option to "Spot (disk)" light type - azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, - 'SetComponentProperty', - light_component_id_pair, - LIGHT_TYPE_PROPERTY, - atom_constants.LIGHT_TYPES['spot_disk'] - ) - area_light_rotation = math.Vector3(DEGREE_RADIAN_FACTOR * 90.0, 0.0, 0.0) - azlmbr.components.TransformBus(azlmbr.bus.Event, "SetLocalRotation", area_light.id, area_light_rotation) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("AreaLight_4", area_light_entity_name) - - # Swap the "Spot (disk)" light type to the "Point (sphere)" light type and take screenshot. - azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, - 'SetComponentProperty', - light_component_id_pair, - LIGHT_TYPE_PROPERTY, - atom_constants.LIGHT_TYPES['sphere'] - ) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("AreaLight_5", area_light_entity_name) - - editor.ToolsApplicationRequestBus(bus.Broadcast, "DeleteEntityById", area_light.id) - - -def spot_light_test(): - """ - Basic test for the Light component attached to a "spot_light" entity. - - Test Case - Light Component: Spot (disk) with shadows & colors: - 1. Creates "spot_light" entity w/ a Light component attached to it. - 2. Selects the "directional_light" entity already present in the level and disables it. - 3. Selects the "global_skylight" entity already present in the level and disables the HDRi Skybox component, - as well as the Global Skylight (IBL) component. - 4. Enters game mode to take a screenshot for comparison, then exits game mode. - 5. Selects the "ground_plane" entity and changes updates the material to a new material. - 6. Enters game mode to take a screenshot for comparison, then exits game mode. - 7. Selects the "spot_light" entity and increases the Light component Intensity to 800 lm - 8. Enters game mode to take a screenshot for comparison, then exits game mode. - 9. Selects the "spot_light" entity and sets the Light component Color to 47, 75, 37 - 10. Enters game mode to take a screenshot for comparison, then exits game mode. - 11. Selects the "spot_light" entity and modifies the Shutter controls to the following values: - - Enable shutters: True - - Inner Angle: 60.0 - - Outer Angle: 75.0 - 12. Enters game mode to take a screenshot for comparison, then exits game mode. - 13. Selects the "spot_light" entity and modifies the Shadow controls to the following values: - - Enable Shadow: True - - ShadowmapSize: 256 - 14. Modifies the world translate position of the "spot_light" entity to 0.7, -2.0, 1.9 (for casting shadows better) - 15. Enters game mode to take a screenshot for comparison, then exits game mode. - """ - # Disable "Directional Light" component for the "directional_light" entity - # "directional_light" entity is created by the create_basic_atom_level() function by default. - directional_light_entity_id = hydra.find_entity_by_name("directional_light") - directional_light = hydra.Entity(name='directional_light', id=directional_light_entity_id) - directional_light_component_type = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Directional Light"], 0)[0] - directional_light_component = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'GetComponentOfType', directional_light.id, directional_light_component_type - ).GetValue() - editor.EditorComponentAPIBus(bus.Broadcast, "DisableComponents", [directional_light_component]) - general.idle_wait(0.5) - - # Disable "Global Skylight (IBL)" and "HDRi Skybox" components for the "global_skylight" entity - global_skylight_entity_id = hydra.find_entity_by_name("global_skylight") - global_skylight = hydra.Entity(name='global_skylight', id=global_skylight_entity_id) - global_skylight_component_type = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Global Skylight (IBL)"], 0)[0] - global_skylight_component = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'GetComponentOfType', global_skylight.id, global_skylight_component_type - ).GetValue() - editor.EditorComponentAPIBus(bus.Broadcast, "DisableComponents", [global_skylight_component]) - hdri_skybox_component_type = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["HDRi Skybox"], 0)[0] - hdri_skybox_component = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'GetComponentOfType', global_skylight.id, hdri_skybox_component_type - ).GetValue() - editor.EditorComponentAPIBus(bus.Broadcast, "DisableComponents", [hdri_skybox_component]) - general.idle_wait(0.5) - - # Create a "spot_light" entity with "Light" component using Light Type of "Spot (disk)" - spot_light_entity_name = "spot_light" - spot_light = hydra.Entity(spot_light_entity_name) - spot_light.create_entity(math.Vector3(0.7, -2.0, 1.0), [LIGHT_COMPONENT]) - general.log( - f"{spot_light_entity_name}_test: Component added to the entity: " - f"{hydra.has_components(spot_light.id, [LIGHT_COMPONENT])}") - rotation = math.Vector3(DEGREE_RADIAN_FACTOR * 300.0, 0.0, 0.0) - azlmbr.components.TransformBus(azlmbr.bus.Event, "SetLocalRotation", spot_light.id, rotation) - light_component_type = hydra.attach_component_to_entity(spot_light.id, LIGHT_COMPONENT) - editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, - 'SetComponentProperty', - light_component_type, - LIGHT_TYPE_PROPERTY, - atom_constants.LIGHT_TYPES['spot_disk'] - ) - - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("SpotLight_1", spot_light_entity_name) - - # Change default material of ground plane entity and take screenshot - ground_plane_entity_id = hydra.find_entity_by_name("ground_plane") - ground_plane = hydra.Entity(name='ground_plane', id=ground_plane_entity_id) - ground_plane_asset_path = os.path.join("Materials", "Presets", "MacBeth", "22_neutral_5-0_0-70d.azmaterial") - ground_plane_asset_value = asset.AssetCatalogRequestBus( - bus.Broadcast, "GetAssetIdByPath", ground_plane_asset_path, math.Uuid(), False) - material_property_path = "Default Material|Material Asset" - material_component_type = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Material"], 0)[0] - material_component = azlmbr.editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, 'GetComponentOfType', ground_plane.id, material_component_type).GetValue() - editor.EditorComponentAPIBus( - azlmbr.bus.Broadcast, - 'SetComponentProperty', - material_component, - material_property_path, - ground_plane_asset_value - ) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("SpotLight_2", spot_light_entity_name) - - # Increase intensity value of the Spot light and take screenshot in game mode - spot_light.get_set_test(0, "Controller|Configuration|Intensity", 800.0) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("SpotLight_3", spot_light_entity_name) - - # Update the Spot light color and take screenshot in game mode - color_value = math.Color(47.0 / 255.0, 75.0 / 255.0, 37.0 / 255.0, 255.0 / 255.0) - spot_light.get_set_test(0, "Controller|Configuration|Color", color_value) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("SpotLight_4", spot_light_entity_name) - - # Update the Shutter controls of the Light component and take screenshot - spot_light.get_set_test(0, "Controller|Configuration|Shutters|Enable shutters", True) - spot_light.get_set_test(0, "Controller|Configuration|Shutters|Inner angle", 60.0) - spot_light.get_set_test(0, "Controller|Configuration|Shutters|Outer angle", 75.0) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("SpotLight_5", spot_light_entity_name) - - # Update the Shadow controls, move the spot_light entity world translate position and take screenshot - spot_light.get_set_test(0, "Controller|Configuration|Shadows|Enable shadow", True) - spot_light.get_set_test(0, "Controller|Configuration|Shadows|Shadowmap size", 256.0) - azlmbr.components.TransformBus( - azlmbr.bus.Event, "SetWorldTranslation", spot_light.id, math.Vector3(0.7, -2.0, 1.9)) - general.idle_wait(1.0) - screenshot_utils.take_screenshot_game_mode("SpotLight_6", spot_light_entity_name) - - -if __name__ == "__main__": - run() diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py index 59e454479c..5b0ab0067c 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py @@ -25,7 +25,7 @@ class EditorComponent: """ EditorComponent class used to set and get the component property value using path EditorComponent object is returned from either of - EditorEntity.add_component() or Entity.add_components() or EditorEntity.get_component_objects() + EditorEntity.add_component() or Entity.add_components() or EditorEntity.get_components_of_type() which also assigns self.id and self.type_id to the EditorComponent object. """ @@ -94,6 +94,13 @@ class EditorComponent: """ return editor.EditorComponentAPIBus(bus.Broadcast, "IsComponentEnabled", self.id) + def disable_component(self): + """ + Used to disable the component using its id value. + :return: None + """ + editor.EditorComponentAPIBus(bus.Broadcast, "DisableComponents", [self.id]) + @staticmethod def get_type_ids(component_names: list) -> list: """ @@ -107,7 +114,6 @@ class EditorComponent: return type_ids - def convert_to_azvector3(xyz) -> azlmbr.math.Vector3: """ Converts a vector3-like element into a azlmbr.math.Vector3 @@ -120,6 +126,7 @@ def convert_to_azvector3(xyz) -> azlmbr.math.Vector3: else: raise ValueError("vector must be a 3 element list/tuple or azlmbr.math.Vector3") + class EditorEntity: """ Entity class is used to create and interact with Editor Entities. @@ -136,10 +143,11 @@ class EditorEntity: # Creation functions @classmethod - def find_editor_entity(cls, entity_name: str, must_be_unique : bool = False) -> EditorEntity: + def find_editor_entity(cls, entity_name: str, must_be_unique: bool = False) -> EditorEntity: """ Given Entity name, outputs entity object :param entity_name: Name of entity to find + :param must_be_unique: bool that asserts the entity_name specified is unique when set to True :return: EditorEntity class object """ entities = cls.find_editor_entities([entity_name]) @@ -147,14 +155,14 @@ class EditorEntity: if must_be_unique: assert len(entities) == 1, f"Failure: Multiple entities with name: '{entity_name}' when expected only one" - entity = cls(entities[0]) + entity = entities[0] return entity @classmethod - def find_editor_entities(cls, entity_names: List[str]) -> EditorEntity: + def find_editor_entities(cls, entity_names: List[str]) -> List[EditorEntity]: """ Given Entities names, returns a list of EditorEntity - :param entity_name: Name of entity to find + :param entity_names: List of entity names to find :return: List[EditorEntity] class object """ searchFilter = azlmbr.entity.SearchFilter() @@ -438,7 +446,7 @@ class EditorEntity: def set_local_rotation(self, new_rotation) -> None: """ Sets the set the local rotation(relative to the parent) of the current entity. - :param vector3_rotation: The math.Vector3 value to use for rotation on the entity (uses radians). + :param new_rotation: The math.Vector3 value to use for rotation on the entity (uses radians). :return: None """ new_rotation = convert_to_azvector3(new_rotation) @@ -454,7 +462,7 @@ class EditorEntity: def set_local_translation(self, new_translation) -> None: """ Sets the local translation(relative to the parent) of the current entity. - :param vector3_translation: The math.Vector3 value to use for translation on the entity. + :param new_translation: The math.Vector3 value to use for translation on the entity. :return: None """ new_translation = convert_to_azvector3(new_translation)