From 16758ae52fd7f9f93a89c5f382943d9a77fede3d Mon Sep 17 00:00:00 2001 From: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:25:47 -0600 Subject: [PATCH 1/4] Adding new Image Gradient test to validate surface modification Signed-off-by: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> --- .../ImageGradient_ModifiesSurfaces.py | 117 ++++++++++++++++++ .../gradient_signal/TestSuite_Periodic.py | 3 + 2 files changed, 120 insertions(+) create mode 100644 AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py new file mode 100644 index 0000000000..142b3d1bd5 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py @@ -0,0 +1,117 @@ +""" +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 +""" + + +class Tests: + image_gradient_entity_created = ( + "Image Gradient entity created", + "Failed to create Image Gradient entity", + ) + image_gradient_assigned = ( + "Successfully assigned image gradient asset", + "Failed to assign image gradient asset" + ) + instance_validation = ( + "Found the expected number of instances", + "Found an unexpected number of instances" + ) + +def ImageGradient_ModifiesSurfaces(): + """ + Summary: + This test verifies that an Image Gradient + Gradient Surface Tag Emitter properly modifies surfaces. + + Expected Behavior: + Vegetation is used to verify expected surface modification. + + Test Steps: + 1) Open a level + 2) Create an entity with Image Gradient, Gradient Transform Modifier, Shape Reference, and Gradient Surface Tag + Emitter components with an Image asset assigned. + 3) Create a Vegetation Layer Spawner setup to plant on the generated surface. + 4) Update all surface tag references + 5) Validate expected instances planted on the modified surface. + + :return: None + """ + + import os + + import azlmbr.asset as asset + import azlmbr.bus as bus + import azlmbr.entity as EntityId + import azlmbr.editor as editor + import azlmbr.math as math + import azlmbr.surface_data as surface_data + + import editor_python_test_tools.editor_entity_utils as entity + import editor_python_test_tools.hydra_editor_utils as hydra + from largeworlds.large_worlds_utils import editor_dynveg_test_helper as dynveg + from editor_python_test_tools.utils import Report + from editor_python_test_tools.utils import TestHelper as helper + + # 1) Open an existing simple level + hydra.open_base_level() + + # 2) Create an entity with required Image Gradient + Surface Tag Emitter components and assign image asset + components_to_add = ["Image Gradient", "Gradient Transform Modifier", "Shape Reference", + "Gradient Surface Tag Emitter"] + entity_position = math.Vector3(0.0, 0.0, 0.0) + new_entity_id = editor.ToolsApplicationRequestBus( + bus.Broadcast, "CreateNewEntityAtPosition", entity_position, EntityId.EntityId() + ) + Report.critical_result(Tests.image_gradient_entity_created, new_entity_id.IsValid()) + image_gradient_entity = entity.EditorEntity.create_editor_entity_at(entity_position, "Image Gradient") + image_gradient_entity.add_components(components_to_add) + test_img_gradient_path = os.path.join("Assets", "ImageGradients", "image_grad_test_gsi.png.streamingimage") + asset_id = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", test_img_gradient_path, math.Uuid(), + False) + image_gradient_entity.components[0].set_component_property_value("Configuration|Image Asset", asset_id) + success = image_gradient_entity.components[0].get_component_property_value("Configuration|Image Asset") == asset_id + Report.result(Tests.image_gradient_assigned, success) + + # 3) Create vegetation and planting surface entities, and assign the Image Gradient entity's Shape Reference + + # Create vegetation entity + purple_flower_prefab_path = os.path.join("assets", "prefabs", "PurpleFlower.spawnable") + spawner_entity = dynveg.create_prefab_vegetation_area("Instance Spawner", entity_position, 50.0, 50.0, 10.0, + purple_flower_prefab_path) + spawner_entity.add_component("Vegetation Surface Mask Filter") + + # Create surface entity + dynveg.create_surface_entity("Box Shape", entity_position, 50.0, 50.0, 1.0) + + # Assign Image Gradient entity's Shape Reference + image_gradient_entity.components[2].set_component_property_value("Configuration|Shape Entity Id", spawner_entity.id) + + # 4) Assign surface tags to the required components + tag_list = [surface_data.SurfaceTag()] + surface_tags = {"terrain": 3363197873} + + # Set the Veg Spawner entity's Surface Tag Mask Filter component to include the "terrain" tag + hydra.get_property_tree(spawner_entity.components[3]) + hydra.get_set_test(spawner_entity, 3, "Configuration|Inclusion|Surface Tags", tag_list) + hydra.get_set_test(spawner_entity, 3, "Configuration|Inclusion|Surface Tags|[0]|Surface Tag", + surface_tags["terrain"]) + + # Set the Image Gradient entity's Gradient Surface Tag Emitter component to modify the "terrain" tag + # NOTE: This requires a disable/re-enable of the component to force a refresh as assigning a tag via script does not + image_gradient_entity.components[3].add_container_item("Configuration|Extended Tags", 0, surface_tags["terrain"]) + image_gradient_entity.components[3].set_enabled(False) + image_gradient_entity.components[3].set_enabled(True) + + # 5) Validate the expected number of vegetation instances. Instances should only spawn on the modified + num_expected_instances = 168 + success = helper.wait_for_condition(lambda: dynveg.validate_instance_count_in_entity_shape( + spawner_entity.id, num_expected_instances), 5.0) + Report.result(Tests.instance_validation, success) + + +if __name__ == "__main__": + + from editor_python_test_tools.utils import Report + Report.start_test(ImageGradient_ModifiesSurfaces) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/TestSuite_Periodic.py b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/TestSuite_Periodic.py index d4199c31f6..7482d2b04a 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/TestSuite_Periodic.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/TestSuite_Periodic.py @@ -48,6 +48,9 @@ class TestAutomation(EditorTestSuite): class test_GradientTransform_RequiresShape(EditorSharedTest): from .EditorScripts import GradientTransform_RequiresShape as test_module + class test_ImageGradient_ModifiesSurfaces(EditorSharedTest): + from .EditorScripts import ImageGradient_ModifiesSurfaces as test_module + class test_ImageGradient_ProcessedImageAssignedSuccessfully(EditorSharedTest): from .EditorScripts import ImageGradient_ProcessedImageAssignedSuccessfully as test_module From bc29e31367938658fa3a3767f95ac2710627d7e0 Mon Sep 17 00:00:00 2001 From: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:28:32 -0600 Subject: [PATCH 2/4] Updating whitespace and improving component CRUD readability Signed-off-by: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> --- .../EditorScripts/ImageGradient_ModifiesSurfaces.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py index 142b3d1bd5..31704dc22c 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py @@ -20,6 +20,7 @@ class Tests: "Found an unexpected number of instances" ) + def ImageGradient_ModifiesSurfaces(): """ Summary: @@ -100,9 +101,10 @@ def ImageGradient_ModifiesSurfaces(): # Set the Image Gradient entity's Gradient Surface Tag Emitter component to modify the "terrain" tag # NOTE: This requires a disable/re-enable of the component to force a refresh as assigning a tag via script does not - image_gradient_entity.components[3].add_container_item("Configuration|Extended Tags", 0, surface_tags["terrain"]) - image_gradient_entity.components[3].set_enabled(False) - image_gradient_entity.components[3].set_enabled(True) + grad_surf_tag_emitter_component = image_gradient_entity.components[3] + grad_surf_tag_emitter_component.add_container_item("Configuration|Extended Tags", 0, surface_tags["terrain"]) + grad_surf_tag_emitter_component.set_enabled(False) + grad_surf_tag_emitter_component.set_enabled(True) # 5) Validate the expected number of vegetation instances. Instances should only spawn on the modified num_expected_instances = 168 From 52354d4c2e130a734df7cbf0bd0a9741ebe6cecc Mon Sep 17 00:00:00 2001 From: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> Date: Fri, 11 Feb 2022 16:00:28 -0600 Subject: [PATCH 3/4] Simplifying surface tag assignment, fixing incomplete comment, and removing un-needed property tree query Signed-off-by: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> --- .../EditorScripts/ImageGradient_ModifiesSurfaces.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py index 31704dc22c..2c9f6d22e9 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py @@ -90,23 +90,19 @@ def ImageGradient_ModifiesSurfaces(): image_gradient_entity.components[2].set_component_property_value("Configuration|Shape Entity Id", spawner_entity.id) # 4) Assign surface tags to the required components - tag_list = [surface_data.SurfaceTag()] - surface_tags = {"terrain": 3363197873} + tag_list = [surface_data.SurfaceTag("terrain")] # Set the Veg Spawner entity's Surface Tag Mask Filter component to include the "terrain" tag - hydra.get_property_tree(spawner_entity.components[3]) hydra.get_set_test(spawner_entity, 3, "Configuration|Inclusion|Surface Tags", tag_list) - hydra.get_set_test(spawner_entity, 3, "Configuration|Inclusion|Surface Tags|[0]|Surface Tag", - surface_tags["terrain"]) # Set the Image Gradient entity's Gradient Surface Tag Emitter component to modify the "terrain" tag # NOTE: This requires a disable/re-enable of the component to force a refresh as assigning a tag via script does not grad_surf_tag_emitter_component = image_gradient_entity.components[3] - grad_surf_tag_emitter_component.add_container_item("Configuration|Extended Tags", 0, surface_tags["terrain"]) + grad_surf_tag_emitter_component.add_container_item("Configuration|Extended Tags", 0, tag_list[0]) grad_surf_tag_emitter_component.set_enabled(False) grad_surf_tag_emitter_component.set_enabled(True) - # 5) Validate the expected number of vegetation instances. Instances should only spawn on the modified + # 5) Validate the expected number of vegetation instances. Instances should only spawn on the modified surface num_expected_instances = 168 success = helper.wait_for_condition(lambda: dynveg.validate_instance_count_in_entity_shape( spawner_entity.id, num_expected_instances), 5.0) From 2d28c19c0a135a42ce3dd8513c189339705fc7c2 Mon Sep 17 00:00:00 2001 From: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> Date: Mon, 14 Feb 2022 10:18:50 -0600 Subject: [PATCH 4/4] Simplifying entity creation and asset path calls Signed-off-by: jckand-amzn <82226555+jckand-amzn@users.noreply.github.com> --- .../EditorScripts/ImageGradient_ModifiesSurfaces.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py index 2c9f6d22e9..23c144a3e2 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/gradient_signal/EditorScripts/ImageGradient_ModifiesSurfaces.py @@ -42,15 +42,15 @@ def ImageGradient_ModifiesSurfaces(): import os - import azlmbr.asset as asset import azlmbr.bus as bus import azlmbr.entity as EntityId import azlmbr.editor as editor import azlmbr.math as math import azlmbr.surface_data as surface_data - import editor_python_test_tools.editor_entity_utils as entity import editor_python_test_tools.hydra_editor_utils as hydra + from editor_python_test_tools.asset_utils import Asset + from editor_python_test_tools.editor_entity_utils import EditorEntity from largeworlds.large_worlds_utils import editor_dynveg_test_helper as dynveg from editor_python_test_tools.utils import Report from editor_python_test_tools.utils import TestHelper as helper @@ -66,13 +66,12 @@ def ImageGradient_ModifiesSurfaces(): bus.Broadcast, "CreateNewEntityAtPosition", entity_position, EntityId.EntityId() ) Report.critical_result(Tests.image_gradient_entity_created, new_entity_id.IsValid()) - image_gradient_entity = entity.EditorEntity.create_editor_entity_at(entity_position, "Image Gradient") + image_gradient_entity = EditorEntity.create_editor_entity_at(entity_position, "Image Gradient") image_gradient_entity.add_components(components_to_add) test_img_gradient_path = os.path.join("Assets", "ImageGradients", "image_grad_test_gsi.png.streamingimage") - asset_id = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", test_img_gradient_path, math.Uuid(), - False) - image_gradient_entity.components[0].set_component_property_value("Configuration|Image Asset", asset_id) - success = image_gradient_entity.components[0].get_component_property_value("Configuration|Image Asset") == asset_id + asset = Asset.find_asset_by_path(test_img_gradient_path) + image_gradient_entity.components[0].set_component_property_value("Configuration|Image Asset", asset.id) + success = image_gradient_entity.components[0].get_component_property_value("Configuration|Image Asset") == asset.id Report.result(Tests.image_gradient_assigned, success) # 3) Create vegetation and planting surface entities, and assign the Image Gradient entity's Shape Reference