diff --git a/Assets/Editor/Presets/GeomCache/game.cbc b/Assets/Editor/Presets/GeomCache/game.cbc deleted file mode 100644 index 9b98f3460f..0000000000 --- a/Assets/Editor/Presets/GeomCache/game.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/game_lz4hc.cbc b/Assets/Editor/Presets/GeomCache/game_lz4hc.cbc deleted file mode 100644 index dbd0499175..0000000000 --- a/Assets/Editor/Presets/GeomCache/game_lz4hc.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/game_z_up.cbc b/Assets/Editor/Presets/GeomCache/game_z_up.cbc deleted file mode 100644 index ec2555a3e3..0000000000 --- a/Assets/Editor/Presets/GeomCache/game_z_up.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/game_z_up_lz4hc.cbc b/Assets/Editor/Presets/GeomCache/game_z_up_lz4hc.cbc deleted file mode 100644 index c2e30a6386..0000000000 --- a/Assets/Editor/Presets/GeomCache/game_z_up_lz4hc.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/prerendered.cbc b/Assets/Editor/Presets/GeomCache/prerendered.cbc deleted file mode 100644 index c09785111d..0000000000 --- a/Assets/Editor/Presets/GeomCache/prerendered.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/prerendered_z_up.cbc b/Assets/Editor/Presets/GeomCache/prerendered_z_up.cbc deleted file mode 100644 index e42a915e58..0000000000 --- a/Assets/Editor/Presets/GeomCache/prerendered_z_up.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/rigids_only.cbc b/Assets/Editor/Presets/GeomCache/rigids_only.cbc deleted file mode 100644 index e8620bc11e..0000000000 --- a/Assets/Editor/Presets/GeomCache/rigids_only.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/rigids_only_z_up.cbc b/Assets/Editor/Presets/GeomCache/rigids_only_z_up.cbc deleted file mode 100644 index d1f8bc2db3..0000000000 --- a/Assets/Editor/Presets/GeomCache/rigids_only_z_up.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/uncompressed.cbc b/Assets/Editor/Presets/GeomCache/uncompressed.cbc deleted file mode 100644 index e21d52d9d1..0000000000 --- a/Assets/Editor/Presets/GeomCache/uncompressed.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Editor/Presets/GeomCache/uncompressed_z_up.cbc b/Assets/Editor/Presets/GeomCache/uncompressed_z_up.cbc deleted file mode 100644 index 273ce1fbb1..0000000000 --- a/Assets/Editor/Presets/GeomCache/uncompressed_z_up.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.abc b/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.abc deleted file mode 100644 index 8ca759d342..0000000000 --- a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.abc +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9c36d7bc993ddf616f478115a123efabda5b4b833a4e6524312f43c228ae0902 -size 487003 diff --git a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.cbc b/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.cbc deleted file mode 100644 index 3c99ab1627..0000000000 --- a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.cbc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.ma b/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.ma deleted file mode 100644 index 65aade11a0..0000000000 --- a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.ma +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:96a21446422b834ea90a5d38eaaca309fdee31dc3cc03c0e9c094b39ec3a459d -size 4715164 diff --git a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.mtl b/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.mtl deleted file mode 100644 index 05dfe70b09..0000000000 --- a/Assets/Engine/EngineAssets/GeomCaches/defaultGeomCache.mtl +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/AutomatedTesting/Gem/Code/Platform/Mac/runtime_dependencies.cmake b/AutomatedTesting/Gem/Code/Platform/Mac/runtime_dependencies.cmake index 4d5680a30d..f9d1e60dda 100644 --- a/AutomatedTesting/Gem/Code/Platform/Mac/runtime_dependencies.cmake +++ b/AutomatedTesting/Gem/Code/Platform/Mac/runtime_dependencies.cmake @@ -8,3 +8,8 @@ # remove or modify any license notices. This file is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # + +set(GEM_DEPENDENCIES + Gem::Atom_RHI_Metal.Private + Gem::Atom_RHI_Null.Private +) \ No newline at end of file diff --git a/AutomatedTesting/Gem/Code/Platform/Mac/tool_dependencies.cmake b/AutomatedTesting/Gem/Code/Platform/Mac/tool_dependencies.cmake index 4d5680a30d..2e9d450ab8 100644 --- a/AutomatedTesting/Gem/Code/Platform/Mac/tool_dependencies.cmake +++ b/AutomatedTesting/Gem/Code/Platform/Mac/tool_dependencies.cmake @@ -8,3 +8,12 @@ # remove or modify any license notices. This file is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # + +set(GEM_DEPENDENCIES + Gem::Atom_RHI_Null.Private + Gem::Atom_RHI_Null.Builders + Gem::Atom_RHI_Metal.Private + Gem::Atom_RHI_Metal.Builders + Gem::Atom_RHI_Vulkan.Builders + Gem::Atom_RHI_DX12.Builders +) \ No newline at end of file diff --git a/AutomatedTesting/Gem/PythonTests/CMakeLists.txt b/AutomatedTesting/Gem/PythonTests/CMakeLists.txt index 6d3727195e..31afab87ed 100644 --- a/AutomatedTesting/Gem/PythonTests/CMakeLists.txt +++ b/AutomatedTesting/Gem/PythonTests/CMakeLists.txt @@ -51,7 +51,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS) TEST_SUITE sandbox TEST_SERIAL PATH ${CMAKE_CURRENT_LIST_DIR}/physics/TestSuite_Sandbox.py - TIMEOUT 3600 + TIMEOUT 1500 RUNTIME_DEPENDENCIES Legacy::Editor AZ::AssetProcessor @@ -68,7 +68,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS) TEST_SUITE periodic TEST_SERIAL PATH ${CMAKE_CURRENT_LIST_DIR}/scripting/TestSuite_Active.py - TIMEOUT 1500 + TIMEOUT 3000 RUNTIME_DEPENDENCIES Legacy::Editor AZ::AssetProcessor @@ -181,12 +181,30 @@ include(${pal_dir}/PAL_traits_${PAL_PLATFORM_NAME_LOWERCASE}.cmake) if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS AND PAL_TRAIT_LARGE_WORLDS_TEST_SUPPORTED) ## DynVeg ## + # Temporarily moving all tests to periodic suite - SPEC-6553 + #ly_add_pytest( + # NAME AutomatedTesting::DynamicVegetationTests_Main + # TEST_SERIAL + # TEST_SUITE main + # PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg + # PYTEST_MARKS "not SUITE_sandbox and not SUITE_periodic and not SUITE_benchmark" + # TIMEOUT 1500 + # RUNTIME_DEPENDENCIES + # AZ::AssetProcessor + # Legacy::Editor + # AutomatedTesting.GameLauncher + # AutomatedTesting.Assets + # COMPONENT + # LargeWorlds + #) + + ly_add_pytest( - NAME AutomatedTesting::DynamicVegetationTests_Main + NAME AutomatedTesting::DynamicVegetationTests_Sandbox TEST_SERIAL - TEST_SUITE main + TEST_SUITE sandbox PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg - PYTEST_MARKS "not SUITE_sandbox and not SUITE_periodic and not SUITE_benchmark" + PYTEST_MARKS "SUITE_sandbox" TIMEOUT 1500 RUNTIME_DEPENDENCIES AZ::AssetProcessor @@ -198,27 +216,26 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS AND PAL_TRAIT_ ) ly_add_pytest( - NAME AutomatedTesting::DynamicVegetationTests_Sandbox + NAME AutomatedTesting::DynamicVegetationFilterTests_Periodic TEST_SERIAL - TEST_SUITE sandbox + TEST_SUITE periodic PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg - PYTEST_MARKS "SUITE_sandbox" + PYTEST_MARKS "SUITE_periodic and dynveg_filter" TIMEOUT 1500 RUNTIME_DEPENDENCIES AZ::AssetProcessor Legacy::Editor - AutomatedTesting.GameLauncher AutomatedTesting.Assets COMPONENT LargeWorlds ) ly_add_pytest( - NAME AutomatedTesting::DynamicVegetationTests_Periodic + NAME AutomatedTesting::DynamicVegetationModifierTests_Periodic TEST_SERIAL TEST_SUITE periodic PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg - PYTEST_MARKS "SUITE_periodic" + PYTEST_MARKS "SUITE_periodic and dynveg_modifier" TIMEOUT 1500 RUNTIME_DEPENDENCIES AZ::AssetProcessor @@ -228,22 +245,82 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS AND PAL_TRAIT_ LargeWorlds ) -## LandscapeCanvas ## ly_add_pytest( - NAME AutomatedTesting::LandscapeCanvasTests_Main + NAME AutomatedTesting::DynamicVegetationRegressionTests_Periodic TEST_SERIAL - TEST_SUITE main - PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/landscape_canvas - PYTEST_MARKS "not SUITE_sandbox and not SUITE_periodic and not SUITE_benchmark" + TEST_SUITE periodic + PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg + PYTEST_MARKS "SUITE_periodic and dynveg_regression" TIMEOUT 1500 RUNTIME_DEPENDENCIES - AZ::AssetProcessor - Legacy::Editor - AutomatedTesting.Assets + AZ::AssetProcessor + Legacy::Editor + AutomatedTesting.Assets COMPONENT LargeWorlds ) + ly_add_pytest( + NAME AutomatedTesting::DynamicVegetationAreaTests_Periodic + TEST_SERIAL + TEST_SUITE periodic + PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg + PYTEST_MARKS "SUITE_periodic and dynveg_area" + TIMEOUT 1500 + RUNTIME_DEPENDENCIES + AZ::AssetProcessor + Legacy::Editor + AutomatedTesting.Assets + COMPONENT + LargeWorlds + ) + + ly_add_pytest( + NAME AutomatedTesting::DynamicVegetationMiscTests_Periodic + TEST_SERIAL + TEST_SUITE periodic + PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg + PYTEST_MARKS "SUITE_periodic and dynveg_misc" + TIMEOUT 1500 + RUNTIME_DEPENDENCIES + AZ::AssetProcessor + Legacy::Editor + AutomatedTesting.Assets + COMPONENT + LargeWorlds + ) + + ly_add_pytest( + NAME AutomatedTesting::DynamicVegetationSurfaceTagTests_Periodic + TEST_SERIAL + TEST_SUITE periodic + PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/dyn_veg + PYTEST_MARKS "SUITE_periodic and dynveg_surfacetagemitter" + TIMEOUT 1500 + RUNTIME_DEPENDENCIES + AZ::AssetProcessor + Legacy::Editor + AutomatedTesting.Assets + COMPONENT + LargeWorlds + ) +## LandscapeCanvas ## + # Temporarily moving all tests to periodic suite - SPEC-6553 + #ly_add_pytest( + # NAME AutomatedTesting::LandscapeCanvasTests_Main + # TEST_SERIAL + # TEST_SUITE main + # PATH ${CMAKE_CURRENT_LIST_DIR}/largeworlds/landscape_canvas + # PYTEST_MARKS "not SUITE_sandbox and not SUITE_periodic and not SUITE_benchmark" + # TIMEOUT 1500 + # RUNTIME_DEPENDENCIES + # AZ::AssetProcessor + # Legacy::Editor + # AutomatedTesting.Assets + # COMPONENT + # LargeWorlds + #) + ly_add_pytest( NAME AutomatedTesting::LandscapeCanvasTests_Periodic TEST_SERIAL diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test.py b/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test.py deleted file mode 100755 index 41ae0608a4..0000000000 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test.py +++ /dev/null @@ -1,75 +0,0 @@ -""" -All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -its licensors. - -For complete copyright and license terms please see the LICENSE at the root of this -distribution (the "License"). All use of this software is governed by the License, -or, if provided, by the license below or the license accompanying this file. Do not -remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -""" - -# -# This is a pytest module to test the in-Editor Python API from ViewPane.h -# -import pytest -pytest.importorskip('ly_test_tools') - -import sys -import os -sys.path.append(os.path.dirname(__file__)) -from hydra_utils import launch_test_case - - -@pytest.mark.SUITE_sandbox -@pytest.mark.parametrize('launcher_platform', ['windows_editor']) -@pytest.mark.parametrize('project', ['AutomatedTesting']) -@pytest.mark.parametrize('level', ['auto_test']) -class TestLegacyCryMaterialsCommandsAutomation(object): - - def test_Legacy_CryMaterials(self, request, editor, level, launcher_platform): - - unexpected_lines=[] - expected_lines = [ - # "Material Settings/Shader updated correctly", # Disabled, SPEC-3590 - # "Material Settings/Surface Type updated correctly", # Disabled, SPEC-3590 - "Texture Maps/Diffuse/Tiling/IsTileU updated correctly", - "Texture Maps/Diffuse/Tiling/TileU updated correctly", - "Texture Maps/Diffuse/Rotator/Type updated correctly", - "Texture Maps/Diffuse/Rotator/Amplitude updated correctly", - "Texture Maps/Diffuse/Oscillator/AmplitudeU updated correctly", - "Opacity Settings/Opacity updated correctly", - "Opacity Settings/AlphaTest updated correctly", - "Opacity Settings/Additive updated correctly", - "Lighting Settings/Diffuse Color updated correctly", - "Lighting Settings/Specular Color updated correctly", - "Lighting Settings/Emissive Intensity updated correctly", - "Lighting Settings/Emissive Color updated correctly", - "Advanced/Allow layer activation updated correctly", - "Advanced/2 Sided updated correctly", - "Advanced/No Shadow updated correctly", - "Advanced/Use Scattering updated correctly", - "Advanced/Hide After Breaking updated correctly", - "Advanced/Fog Volume Shading Quality High updated correctly", - "Advanced/Blend Terrain Color updated correctly", - "Advanced/Voxel Coverage updated correctly", - "Advanced/Propagate Opacity Settings updated correctly", - "Advanced/Propagate Lighting Settings updated correctly", - "Advanced/Propagate Advanced Settings updated correctly", - "Advanced/Propagate Texture Maps updated correctly", - "Advanced/Propagate Shader Params updated correctly", - "Advanced/Propagate Shader Generation updated correctly", - "Advanced/Propagate Vertex Deformation updated correctly", - # "Shader Params/Blend Factor updated correctly", # Disabled, SPEC-3590 - # "Shader Params/Indirect bounce color updated correctly", # Disabled, SPEC-3590 - "Vertex Deformation/Type updated correctly", - "Vertex Deformation/Wave Length X updated correctly", - "Vertex Deformation/Wave X/Level updated correctly", - "Vertex Deformation/Wave X/Amplitude updated correctly", - "Vertex Deformation/Wave X/Phase updated correctly", - "Vertex Deformation/Wave X/Frequency updated correctly" - ] - - test_case_file = os.path.join(os.path.dirname(__file__), 'CryMaterialsCommands_test_case.py') - launch_test_case(editor, test_case_file, expected_lines, unexpected_lines) - diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test_case.py b/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test_case.py deleted file mode 100755 index 913b1ace24..0000000000 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonBindings/CryMaterialsCommands_test_case.py +++ /dev/null @@ -1,116 +0,0 @@ -""" -All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -its licensors. - -For complete copyright and license terms please see the LICENSE at the root of this -distribution (the "License"). All use of this software is governed by the License, -or, if provided, by the license below or the license accompanying this file. Do not -remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -""" - -# Tests the legacy Python API for CryMaterials while the Editor is running - -import azlmbr.bus as bus -import azlmbr.editor as editor -import azlmbr.legacy.material as material -import azlmbr.math as math - -materialName = 'materials/ter_layer_green' -print(f'Starting CryMaterial test case using material {materialName}') - - -def MaterialPropertyTest(property, value, doReset=True): - try: - # get old value and attempt to set new value - oldValue = material.get_property(materialName, property) - if oldValue == value: - print(f'>>> `{property}` already set to {oldValue}') - return - material.set_property(materialName, property, value) - - # test that the set new value worked - newValue = material.get_property(materialName, property) - if oldValue != newValue: - print(f"{property} updated correctly") - - # reset back to old value - if doReset: - material.set_property(materialName, property, oldValue) - except: - print(f'!!! hit an exception when setting `{property}` to {value}') - - -color = math.Color() -color.r = 255.0 -color.g = 128.0 -color.b = 64.0 -color.a = 0.0 - -# Material Settings -# MaterialPropertyTest("Material Settings/Shader", "Geometrybeam") # Disabled, SPEC-3590 -# MaterialPropertyTest("Material Settings/Surface Type", "grass") # Disabled, SPEC-3590 - -# Texture Maps -MaterialPropertyTest("Texture Maps/Diffuse/Tiling/IsTileU", False) -MaterialPropertyTest("Texture Maps/Diffuse/Tiling/IsTileV", False) -MaterialPropertyTest("Texture Maps/Diffuse/Tiling/TileU", 0.42) -MaterialPropertyTest("Texture Maps/Diffuse/Rotator/Type", 'Oscillated Rotation') -MaterialPropertyTest("Texture Maps/Diffuse/Rotator/Amplitude", 42.0) -MaterialPropertyTest("Texture Maps/Diffuse/Oscillator/TypeU", 'Fixed Moving') -MaterialPropertyTest("Texture Maps/Diffuse/Oscillator/AmplitudeU", 42.0) - -# Vertex Deformation -MaterialPropertyTest("Vertex Deformation/Type", 'Sin Wave') -MaterialPropertyTest("Vertex Deformation/Wave Length X", 42.0) -MaterialPropertyTest("Vertex Deformation/Type", 'Perlin 3D') -MaterialPropertyTest("Vertex Deformation/Noise Scale", math.Vector3(1.1, 2.2, 3.3)) - -# Opacity Settings -MaterialPropertyTest("Opacity Settings/Opacity", 42) -MaterialPropertyTest("Opacity Settings/AlphaTest", 2) -MaterialPropertyTest("Opacity Settings/Additive", True) - -# Lighting Settings -MaterialPropertyTest("Lighting Settings/Diffuse Color", color) -MaterialPropertyTest("Lighting Settings/Specular Color", color) -MaterialPropertyTest("Lighting Settings/Emissive Intensity", 42.0) -MaterialPropertyTest("Lighting Settings/Emissive Color", color) -MaterialPropertyTest("Lighting Settings/Specular Level", 2.0) - -# Advanced -MaterialPropertyTest("Advanced/Allow layer activation", False) -MaterialPropertyTest("Advanced/2 Sided", True) -MaterialPropertyTest("Advanced/No Shadow", True) -MaterialPropertyTest("Advanced/Use Scattering", True) -MaterialPropertyTest("Advanced/Hide After Breaking", True) -MaterialPropertyTest("Advanced/Fog Volume Shading Quality High", True) -MaterialPropertyTest("Advanced/Blend Terrain Color", True) -MaterialPropertyTest("Advanced/Voxel Coverage", 0.42) -# --- MaterialPropertyTest("Advanced/Link to Material", "materials/ter_layer_blue") # Works, but clears on UI refresh -MaterialPropertyTest("Advanced/Propagate Opacity Settings", True) -MaterialPropertyTest("Advanced/Propagate Lighting Settings", True) -MaterialPropertyTest("Advanced/Propagate Advanced Settings", True) -MaterialPropertyTest("Advanced/Propagate Texture Maps", True) -MaterialPropertyTest("Advanced/Propagate Shader Params", True) -MaterialPropertyTest("Advanced/Propagate Shader Generation", True) -MaterialPropertyTest("Advanced/Propagate Vertex Deformation", True) - -# Shader parameters vary with each Shader, just testing a couple of them... -# MaterialPropertyTest("Shader Params/Blend Factor", 7.0, False) # Disabled, SPEC-3590 -# MaterialPropertyTest("Shader Params/Indirect bounce color", color, False) # Disabled, SPEC-3590 - -### These values are reset to False when set. Left them here commented for reference. -# MaterialPropertyTest("Shader Generation Params/Dust & Turbulence", True) -# MaterialPropertyTest("Shader Generation Params/Receive Shadows", True) -# MaterialPropertyTest("Shader Generation Params/UV Vignetting", True) - -# Vertex Deformation -MaterialPropertyTest("Vertex Deformation/Type", "Sin Wave") -MaterialPropertyTest("Vertex Deformation/Wave Length X", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Level", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Amplitude", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Phase", 42.0) -MaterialPropertyTest("Vertex Deformation/Wave X/Frequency", 42.0) - -editor.EditorToolsApplicationRequestBus(bus.Broadcast, 'ExitNoPrompt') diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py index a9f6d0aa02..c7f1aba031 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py @@ -265,6 +265,7 @@ class Tracer: self.warnings = [] self.errors = [] self.asserts = [] + self.prints = [] self.has_warnings = False self.has_errors = False self.has_asserts = False @@ -310,6 +311,11 @@ class Tracer: def __repr__(self): return f"[Assert: {self.message}]" + + class PrintInfo: + def __init__(self, args): + self.window = args[0] + self.message = args[1] def _on_warning(self, args): warningInfo = Tracer.WarningInfo(args) @@ -331,13 +337,19 @@ class Tracer: Report.info("Tracer caught Assert: %s:%i[%s] \"%s\"" % (assertInfo.filename, assertInfo.line, assertInfo.function, assertInfo.message)) self.has_asserts = True return False - + + def _on_printf(self, args): + printInfo = Tracer.PrintInfo(args) + self.prints.append(printInfo) + return False + def __enter__(self): self.handler = azlmbr.debug.TraceMessageBusHandler() self.handler.connect(None) self.handler.add_callback("OnPreAssert", self._on_assert) self.handler.add_callback("OnPreWarning", self._on_warning) self.handler.add_callback("OnPreError", self._on_error) + self.handler.add_callback("OnPrintf", self._on_printf) return self def __exit__(self, type, value, traceback): diff --git a/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomEditorComponents_AddedToEntity.py b/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomEditorComponents_AddedToEntity.py index 062c449ab7..e701ff8d16 100644 --- a/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomEditorComponents_AddedToEntity.py +++ b/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomEditorComponents_AddedToEntity.py @@ -161,20 +161,6 @@ def run(): # Deletion/Undo/Redo test verify_deletion_undo_redo(self.component_name, entity_obj) - # Area Light Component - area_light = "Area Light" - ComponentTests( - area_light, lambda entity_obj: verify_required_component_addition( - entity_obj, ["Capsule Shape"], area_light)) - - # Decal Component - material_asset_path = os.path.join("AutomatedTesting", "Materials", "basic_grey.material") - material_asset = asset.AssetCatalogRequestBus( - bus.Broadcast, "GetAssetIdByPath", material_asset_path, math.Uuid(), False) - ComponentTests( - "Decal (Atom)", lambda entity_obj: verify_set_property( - entity_obj, "Controller|Configuration|Material", material_asset)) - # DepthOfField Component camera_entity = hydra.Entity("camera_entity") camera_entity.create_entity(math.Vector3(512.0, 512.0, 34.0), ["Camera"]) @@ -185,6 +171,14 @@ def run(): lambda entity_obj: verify_set_property( entity_obj, "Controller|Configuration|Camera Entity", camera_entity.id)) + # Decal Component + material_asset_path = os.path.join("AutomatedTesting", "Materials", "basic_grey.material") + material_asset = asset.AssetCatalogRequestBus( + bus.Broadcast, "GetAssetIdByPath", material_asset_path, math.Uuid(), False) + ComponentTests( + "Decal (Atom)", lambda entity_obj: verify_set_property( + entity_obj, "Controller|Configuration|Material", material_asset)) + # Directional Light Component ComponentTests( "Directional Light", @@ -213,9 +207,6 @@ def run(): # Physical Sky Component ComponentTests("Physical Sky") - # Point Light Component - ComponentTests("Point Light") - # PostFX Layer Component ComponentTests("PostFX Layer") diff --git a/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_MainSuite.py b/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_MainSuite.py index 16139e3f66..aafa2ff9b7 100644 --- a/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_MainSuite.py +++ b/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_MainSuite.py @@ -27,194 +27,6 @@ TEST_DIRECTORY = os.path.join(os.path.dirname(__file__), "atom_hydra_scripts") @pytest.mark.parametrize("level", ["auto_test"]) class TestAtomEditorComponentsMain(object): - @pytest.mark.test_case_id( - "C32078117", # Area Light - "C32078130", # Display Mapper - "C32078129", # Light - "C32078131", # Radius Weight Modifier - "C32078127", # PostFX Layer - "C32078126", # Point Light - "C32078125", # Physical Sky - "C32078115", # Global Skylight (IBL) - "C32078121", # Exposure Control - "C32078120", # Directional Light - "C32078119", # DepthOfField - "C32078118") # Decal - def test_AtomEditorComponents_AddedToEntity(self, request, editor, level, workspace, project, launcher_platform): - cfg_args = [level] - - expected_lines = [ - # Area Light Component - "Area Light Entity successfully created", - "Area Light_test: Component added to the entity: True", - "Area Light_test: Component removed after UNDO: True", - "Area Light_test: Component added after REDO: True", - "Area Light_test: Entered game mode: True", - "Area Light_test: Entity enabled after adding required components: True", - "Area Light_test: Entity is hidden: True", - "Area Light_test: Entity is shown: True", - "Area Light_test: Entity deleted: True", - "Area Light_test: UNDO entity deletion works: True", - "Area Light_test: REDO entity deletion works: True", - # Decal Component - "Decal (Atom) Entity successfully created", - "Decal (Atom)_test: Component added to the entity: True", - "Decal (Atom)_test: Component removed after UNDO: True", - "Decal (Atom)_test: Component added after REDO: True", - "Decal (Atom)_test: Entered game mode: True", - "Decal (Atom)_test: Exit game mode: True", - "Decal (Atom) Controller|Configuration|Material: SUCCESS", - "Decal (Atom)_test: Entity is hidden: True", - "Decal (Atom)_test: Entity is shown: True", - "Decal (Atom)_test: Entity deleted: True", - "Decal (Atom)_test: UNDO entity deletion works: True", - "Decal (Atom)_test: REDO entity deletion works: True", - # DepthOfField Component - "DepthOfField Entity successfully created", - "DepthOfField_test: Component added to the entity: True", - "DepthOfField_test: Component removed after UNDO: True", - "DepthOfField_test: Component added after REDO: True", - "DepthOfField_test: Entered game mode: True", - "DepthOfField_test: Exit game mode: True", - "DepthOfField_test: Entity disabled initially: True", - "DepthOfField_test: Entity enabled after adding required components: True", - "DepthOfField Controller|Configuration|Camera Entity: SUCCESS", - "DepthOfField_test: Entity is hidden: True", - "DepthOfField_test: Entity is shown: True", - "DepthOfField_test: Entity deleted: True", - "DepthOfField_test: UNDO entity deletion works: True", - "DepthOfField_test: REDO entity deletion works: True", - # Directional Light Component - "Directional Light Entity successfully created", - "Directional Light_test: Component added to the entity: True", - "Directional Light_test: Component removed after UNDO: True", - "Directional Light_test: Component added after REDO: True", - "Directional Light_test: Entered game mode: True", - "Directional Light_test: Exit game mode: True", - "Directional Light Controller|Configuration|Shadow|Camera: SUCCESS", - "Directional Light_test: Entity is hidden: True", - "Directional Light_test: Entity is shown: True", - "Directional Light_test: Entity deleted: True", - "Directional Light_test: UNDO entity deletion works: True", - "Directional Light_test: REDO entity deletion works: True", - # Exposure Control Component - "Exposure Control Entity successfully created", - "Exposure Control_test: Component added to the entity: True", - "Exposure Control_test: Component removed after UNDO: True", - "Exposure Control_test: Component added after REDO: True", - "Exposure Control_test: Entered game mode: True", - "Exposure Control_test: Exit game mode: True", - "Exposure Control_test: Entity disabled initially: True", - "Exposure Control_test: Entity enabled after adding required components: True", - "Exposure Control_test: Entity is hidden: True", - "Exposure Control_test: Entity is shown: True", - "Exposure Control_test: Entity deleted: True", - "Exposure Control_test: UNDO entity deletion works: True", - "Exposure Control_test: REDO entity deletion works: True", - # Global Skylight (IBL) Component - "Global Skylight (IBL) Entity successfully created", - "Global Skylight (IBL)_test: Component added to the entity: True", - "Global Skylight (IBL)_test: Component removed after UNDO: True", - "Global Skylight (IBL)_test: Component added after REDO: True", - "Global Skylight (IBL)_test: Entered game mode: True", - "Global Skylight (IBL)_test: Exit game mode: True", - "Global Skylight (IBL) Controller|Configuration|Diffuse Image: SUCCESS", - "Global Skylight (IBL) Controller|Configuration|Specular Image: SUCCESS", - "Global Skylight (IBL)_test: Entity is hidden: True", - "Global Skylight (IBL)_test: Entity is shown: True", - "Global Skylight (IBL)_test: Entity deleted: True", - "Global Skylight (IBL)_test: UNDO entity deletion works: True", - "Global Skylight (IBL)_test: REDO entity deletion works: True", - # Physical Sky Component - "Physical Sky Entity successfully created", - "Physical Sky component was added to entity", - "Entity has a Physical Sky component", - "Physical Sky_test: Component added to the entity: True", - "Physical Sky_test: Component removed after UNDO: True", - "Physical Sky_test: Component added after REDO: True", - "Physical Sky_test: Entered game mode: True", - "Physical Sky_test: Exit game mode: True", - "Physical Sky_test: Entity is hidden: True", - "Physical Sky_test: Entity is shown: True", - "Physical Sky_test: Entity deleted: True", - "Physical Sky_test: UNDO entity deletion works: True", - "Physical Sky_test: REDO entity deletion works: True", - # Point Light Component - "Point Light Entity successfully created", - "Point Light_test: Component added to the entity: True", - "Point Light_test: Component removed after UNDO: True", - "Point Light_test: Component added after REDO: True", - "Point Light_test: Entered game mode: True", - "Point Light_test: Exit game mode: True", - "Point Light_test: Entity is hidden: True", - "Point Light_test: Entity is shown: True", - "Point Light_test: Entity deleted: True", - "Point Light_test: UNDO entity deletion works: True", - "Point Light_test: REDO entity deletion works: True", - # PostFX Layer Component - "PostFX Layer Entity successfully created", - "PostFX Layer_test: Component added to the entity: True", - "PostFX Layer_test: Component removed after UNDO: True", - "PostFX Layer_test: Component added after REDO: True", - "PostFX Layer_test: Entered game mode: True", - "PostFX Layer_test: Exit game mode: True", - "PostFX Layer_test: Entity is hidden: True", - "PostFX Layer_test: Entity is shown: True", - "PostFX Layer_test: Entity deleted: True", - "PostFX Layer_test: UNDO entity deletion works: True", - "PostFX Layer_test: REDO entity deletion works: True", - # Radius Weight Modifier Component - "Radius Weight Modifier Entity successfully created", - "Radius Weight Modifier_test: Component added to the entity: True", - "Radius Weight Modifier_test: Component removed after UNDO: True", - "Radius Weight Modifier_test: Component added after REDO: True", - "Radius Weight Modifier_test: Entered game mode: True", - "Radius Weight Modifier_test: Exit game mode: True", - "Radius Weight Modifier_test: Entity is hidden: True", - "Radius Weight Modifier_test: Entity is shown: True", - "Radius Weight Modifier_test: Entity deleted: True", - "Radius Weight Modifier_test: UNDO entity deletion works: True", - "Radius Weight Modifier_test: REDO entity deletion works: True", - # Light Component - "Light Entity successfully created", - "Light_test: Component added to the entity: True", - "Light_test: Component removed after UNDO: True", - "Light_test: Component added after REDO: True", - "Light_test: Entered game mode: True", - "Light_test: Exit game mode: True", - "Light_test: Entity is hidden: True", - "Light_test: Entity is shown: True", - "Light_test: Entity deleted: True", - "Light_test: UNDO entity deletion works: True", - "Light_test: REDO entity deletion works: True", - # Display Mapper Component - "Display Mapper Entity successfully created", - "Display Mapper_test: Component added to the entity: True", - "Display Mapper_test: Component removed after UNDO: True", - "Display Mapper_test: Component added after REDO: True", - "Display Mapper_test: Entered game mode: True", - "Display Mapper_test: Exit game mode: True", - "Display Mapper_test: Entity is hidden: True", - "Display Mapper_test: Entity is shown: True", - "Display Mapper_test: Entity deleted: True", - "Display Mapper_test: UNDO entity deletion works: True", - "Display Mapper_test: REDO entity deletion works: True", - ] - - unexpected_lines = [ - "failed to open", - "Traceback (most recent call last):", - ] - - hydra.launch_and_validate_results( - request, - TEST_DIRECTORY, - editor, - "hydra_AtomEditorComponents_AddedToEntity.py", - timeout=EDITOR_TIMEOUT, - expected_lines=expected_lines, - unexpected_lines=unexpected_lines, - halt_on_unexpected=True, - null_renderer=True, - cfg_args=cfg_args, - ) + # It requires at least one test + def test_Dummy(self, request, editor, level, workspace, project, launcher_platform): + pass diff --git a/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_SandboxSuite.py b/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_SandboxSuite.py index 0fb873e677..8ca5b5aa31 100644 --- a/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_SandboxSuite.py +++ b/AutomatedTesting/Gem/PythonTests/atom_renderer/test_Atom_SandboxSuite.py @@ -19,6 +19,170 @@ import pytest @pytest.mark.parametrize("level", ["auto_test"]) class TestAtomEditorComponentsSandbox(object): - # It requires at least one test - def test_Dummy(self, request, editor, level, workspace, project, launcher_platform): - pass + @pytest.mark.test_case_id( + "C32078117", # Area Light + "C32078130", # Display Mapper + "C32078129", # Light + "C32078131", # Radius Weight Modifier + "C32078127", # PostFX Layer + "C32078126", # Point Light + "C32078125", # Physical Sky + "C32078115", # Global Skylight (IBL) + "C32078121", # Exposure Control + "C32078120", # Directional Light + "C32078119", # DepthOfField + "C32078118") # Decal + def test_AtomEditorComponents_AddedToEntity(self, request, editor, level, workspace, project, launcher_platform): + cfg_args = [level] + + expected_lines = [ + # Decal Component + "Decal (Atom) Entity successfully created", + "Decal (Atom)_test: Component added to the entity: True", + "Decal (Atom)_test: Component removed after UNDO: True", + "Decal (Atom)_test: Component added after REDO: True", + "Decal (Atom)_test: Entered game mode: True", + "Decal (Atom)_test: Exit game mode: True", + "Decal (Atom) Controller|Configuration|Material: SUCCESS", + "Decal (Atom)_test: Entity is hidden: True", + "Decal (Atom)_test: Entity is shown: True", + "Decal (Atom)_test: Entity deleted: True", + "Decal (Atom)_test: UNDO entity deletion works: True", + "Decal (Atom)_test: REDO entity deletion works: True", + # DepthOfField Component + "DepthOfField Entity successfully created", + "DepthOfField_test: Component added to the entity: True", + "DepthOfField_test: Component removed after UNDO: True", + "DepthOfField_test: Component added after REDO: True", + "DepthOfField_test: Entered game mode: True", + "DepthOfField_test: Exit game mode: True", + "DepthOfField_test: Entity disabled initially: True", + "DepthOfField_test: Entity enabled after adding required components: True", + "DepthOfField Controller|Configuration|Camera Entity: SUCCESS", + "DepthOfField_test: Entity is hidden: True", + "DepthOfField_test: Entity is shown: True", + "DepthOfField_test: Entity deleted: True", + "DepthOfField_test: UNDO entity deletion works: True", + "DepthOfField_test: REDO entity deletion works: True", + # Directional Light Component + "Directional Light Entity successfully created", + "Directional Light_test: Component added to the entity: True", + "Directional Light_test: Component removed after UNDO: True", + "Directional Light_test: Component added after REDO: True", + "Directional Light_test: Entered game mode: True", + "Directional Light_test: Exit game mode: True", + "Directional Light Controller|Configuration|Shadow|Camera: SUCCESS", + "Directional Light_test: Entity is hidden: True", + "Directional Light_test: Entity is shown: True", + "Directional Light_test: Entity deleted: True", + "Directional Light_test: UNDO entity deletion works: True", + "Directional Light_test: REDO entity deletion works: True", + # Exposure Control Component + "Exposure Control Entity successfully created", + "Exposure Control_test: Component added to the entity: True", + "Exposure Control_test: Component removed after UNDO: True", + "Exposure Control_test: Component added after REDO: True", + "Exposure Control_test: Entered game mode: True", + "Exposure Control_test: Exit game mode: True", + "Exposure Control_test: Entity disabled initially: True", + "Exposure Control_test: Entity enabled after adding required components: True", + "Exposure Control_test: Entity is hidden: True", + "Exposure Control_test: Entity is shown: True", + "Exposure Control_test: Entity deleted: True", + "Exposure Control_test: UNDO entity deletion works: True", + "Exposure Control_test: REDO entity deletion works: True", + # Global Skylight (IBL) Component + "Global Skylight (IBL) Entity successfully created", + "Global Skylight (IBL)_test: Component added to the entity: True", + "Global Skylight (IBL)_test: Component removed after UNDO: True", + "Global Skylight (IBL)_test: Component added after REDO: True", + "Global Skylight (IBL)_test: Entered game mode: True", + "Global Skylight (IBL)_test: Exit game mode: True", + "Global Skylight (IBL) Controller|Configuration|Diffuse Image: SUCCESS", + "Global Skylight (IBL) Controller|Configuration|Specular Image: SUCCESS", + "Global Skylight (IBL)_test: Entity is hidden: True", + "Global Skylight (IBL)_test: Entity is shown: True", + "Global Skylight (IBL)_test: Entity deleted: True", + "Global Skylight (IBL)_test: UNDO entity deletion works: True", + "Global Skylight (IBL)_test: REDO entity deletion works: True", + # Physical Sky Component + "Physical Sky Entity successfully created", + "Physical Sky component was added to entity", + "Entity has a Physical Sky component", + "Physical Sky_test: Component added to the entity: True", + "Physical Sky_test: Component removed after UNDO: True", + "Physical Sky_test: Component added after REDO: True", + "Physical Sky_test: Entered game mode: True", + "Physical Sky_test: Exit game mode: True", + "Physical Sky_test: Entity is hidden: True", + "Physical Sky_test: Entity is shown: True", + "Physical Sky_test: Entity deleted: True", + "Physical Sky_test: UNDO entity deletion works: True", + "Physical Sky_test: REDO entity deletion works: True", + # PostFX Layer Component + "PostFX Layer Entity successfully created", + "PostFX Layer_test: Component added to the entity: True", + "PostFX Layer_test: Component removed after UNDO: True", + "PostFX Layer_test: Component added after REDO: True", + "PostFX Layer_test: Entered game mode: True", + "PostFX Layer_test: Exit game mode: True", + "PostFX Layer_test: Entity is hidden: True", + "PostFX Layer_test: Entity is shown: True", + "PostFX Layer_test: Entity deleted: True", + "PostFX Layer_test: UNDO entity deletion works: True", + "PostFX Layer_test: REDO entity deletion works: True", + # Radius Weight Modifier Component + "Radius Weight Modifier Entity successfully created", + "Radius Weight Modifier_test: Component added to the entity: True", + "Radius Weight Modifier_test: Component removed after UNDO: True", + "Radius Weight Modifier_test: Component added after REDO: True", + "Radius Weight Modifier_test: Entered game mode: True", + "Radius Weight Modifier_test: Exit game mode: True", + "Radius Weight Modifier_test: Entity is hidden: True", + "Radius Weight Modifier_test: Entity is shown: True", + "Radius Weight Modifier_test: Entity deleted: True", + "Radius Weight Modifier_test: UNDO entity deletion works: True", + "Radius Weight Modifier_test: REDO entity deletion works: True", + # Light Component + "Light Entity successfully created", + "Light_test: Component added to the entity: True", + "Light_test: Component removed after UNDO: True", + "Light_test: Component added after REDO: True", + "Light_test: Entered game mode: True", + "Light_test: Exit game mode: True", + "Light_test: Entity is hidden: True", + "Light_test: Entity is shown: True", + "Light_test: Entity deleted: True", + "Light_test: UNDO entity deletion works: True", + "Light_test: REDO entity deletion works: True", + # Display Mapper Component + "Display Mapper Entity successfully created", + "Display Mapper_test: Component added to the entity: True", + "Display Mapper_test: Component removed after UNDO: True", + "Display Mapper_test: Component added after REDO: True", + "Display Mapper_test: Entered game mode: True", + "Display Mapper_test: Exit game mode: True", + "Display Mapper_test: Entity is hidden: True", + "Display Mapper_test: Entity is shown: True", + "Display Mapper_test: Entity deleted: True", + "Display Mapper_test: UNDO entity deletion works: True", + "Display Mapper_test: REDO entity deletion works: True", + ] + + unexpected_lines = [ + "failed to open", + "Traceback (most recent call last):", + ] + + hydra.launch_and_validate_results( + request, + TEST_DIRECTORY, + editor, + "hydra_AtomEditorComponents_AddedToEntity.py", + timeout=EDITOR_TIMEOUT, + expected_lines=expected_lines, + unexpected_lines=unexpected_lines, + halt_on_unexpected=True, + null_renderer=True, + cfg_args=cfg_args, + ) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks.py index 0be220cad0..466cd610e4 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks.py @@ -114,11 +114,8 @@ class TestDynamicSliceInstanceSpawner(EditorTestHelper): # This should result in 400 instances, since our box is 16 m x 16 m and by default the veg system plants # 20 instances per 16 meters spawner_entity.get_set_test(0, 'Configuration|Allow Empty Assets', True) - general.idle_wait(1.0) num_expected_instances = 20 * 20 - box = azlmbr.shape.ShapeComponentRequestsBus(bus.Event, 'GetEncompassingAabb', spawner_entity.id) - num_found = azlmbr.areasystem.AreaSystemRequestBus(bus.Broadcast, 'GetInstanceCountInAabb', box) - property_tree_success = property_tree_success and (num_found == num_expected_instances) + property_tree_success = property_tree_success and self.wait_for_condition(lambda: dynveg.validate_instance_count_in_entity_shape(spawner_entity.id, num_expected_instances), 5.0) self.test_success = self.test_success and property_tree_success self.log(f'Property Tree spawner type test: {property_tree_success}') @@ -127,10 +124,8 @@ class TestDynamicSliceInstanceSpawner(EditorTestHelper): # Since we have an empty slice path, we should have 0 instances once we disable 'Allow Empty Assets' num_expected_instances = 0 allow_empty_assets_success = allow_empty_assets_success and spawner_entity.get_set_test(0, 'Configuration|Allow Empty Assets', False) - general.idle_wait(1.0) - num_found = azlmbr.areasystem.AreaSystemRequestBus(bus.Broadcast, 'GetInstanceCountInAabb', box) - self.log(f'Allow Empty Assets test: Found {num_found} instances -- Expected {num_expected_instances} instances') - allow_empty_assets_success = allow_empty_assets_success and (num_found == num_expected_instances) + self.log('Allow Empty Assets test:') + allow_empty_assets_success = allow_empty_assets_success and self.wait_for_condition(lambda: dynveg.validate_instance_count_in_entity_shape(spawner_entity.id, num_expected_instances), 5.0) self.test_success = self.test_success and allow_empty_assets_success self.log(f'Allow Empty Assets test: {allow_empty_assets_success}') @@ -143,10 +138,8 @@ class TestDynamicSliceInstanceSpawner(EditorTestHelper): descriptor = hydra.get_component_property_value(spawner_entity.components[2], 'Configuration|Embedded Assets|[0]') descriptor.spawner = dynamic_slice_spawner spawns_slices_success = spawns_slices_success and spawner_entity.get_set_test(2, "Configuration|Embedded Assets|[0]", descriptor) - general.idle_wait(1.0) - num_found = azlmbr.areasystem.AreaSystemRequestBus(bus.Broadcast, 'GetInstanceCountInAabb', box) - self.log(f'Spawn dynamic slices test: Found {num_found} instances -- Expected {num_expected_instances} instances') - spawns_slices_success = spawns_slices_success and (num_found == num_expected_instances) + self.log('Spawn dynamic slices test:') + spawns_slices_success = spawns_slices_success and self.wait_for_condition(lambda: dynveg.validate_instance_count_in_entity_shape(spawner_entity.id, num_expected_instances), 5.0) self.test_success = self.test_success and spawns_slices_success self.log(f'Spawn dynamic slices test: {spawns_slices_success}') diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/EmptyInstanceSpawner_EmptySpawnerWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/EmptyInstanceSpawner_EmptySpawnerWorks.py index 161ad038a5..dc353aca1a 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/EmptyInstanceSpawner_EmptySpawnerWorks.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/EmptyInstanceSpawner_EmptySpawnerWorks.py @@ -100,21 +100,15 @@ class TestEmptyInstanceSpawner(EditorTestHelper): # This should result in 400 instances, since our box is 16 m x 16 m and by default the veg system plants # 20 instances per 16 meters - general.idle_wait(2.0) num_expected_instances = 20 * 20 - box = azlmbr.shape.ShapeComponentRequestsBus(bus.Event, 'GetEncompassingAabb', spawner_entity.id) - num_found = azlmbr.areasystem.AreaSystemRequestBus(bus.Broadcast, 'GetInstanceCountInAabb', box) - property_tree_success = property_tree_success and (num_found == num_expected_instances) + property_tree_success = property_tree_success and self.wait_for_condition(lambda: dynveg.validate_instance_count_in_entity_shape(spawner_entity.id, num_expected_instances), 5.0) self.test_success = self.test_success and property_tree_success - self.log(f'Found {num_found} instances -- Expected {num_expected_instances} instances') self.log(f'Property Tree spawner type test: {property_tree_success}') # 6) Validate that the "Allow Empty Assets" setting doesn't affect the EmptyInstanceSpawner allow_empty_assets_success = True spawner_entity.get_set_test(0, 'Configuration|Allow Empty Assets', False) - general.idle_wait(2.0) - num_found = azlmbr.areasystem.AreaSystemRequestBus(bus.Broadcast, 'GetInstanceCountInAabb', box) - allow_empty_assets_success = allow_empty_assets_success and (num_found == num_expected_instances) + allow_empty_assets_success = allow_empty_assets_success and self.wait_for_condition(lambda: dynveg.validate_instance_count_in_entity_shape(spawner_entity.id, num_expected_instances), 5.0) self.test_success = self.test_success and allow_empty_assets_success self.log(f'Allow Empty Assets test: {allow_empty_assets_success}') diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AltitudeFilter.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AltitudeFilter.py index 2db8534696..17a5f72863 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AltitudeFilter.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AltitudeFilter.py @@ -37,6 +37,7 @@ class TestAltitudeFilter(object): @pytest.mark.test_case_id('C4814463', 'C4847477') @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_AltitudeFilter_ComponentAndOverrides_InstancesPlantAtSpecifiedAltitude(self, request, editor, level, launcher_platform): @@ -61,6 +62,7 @@ class TestAltitudeFilter(object): @pytest.mark.test_case_id("C4847476") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_AltitudeFilter_ShapeSample_InstancesPlantAtSpecifiedAltitude(self, request, editor, level, launcher_platform): @@ -85,6 +87,7 @@ class TestAltitudeFilter(object): @pytest.mark.test_case_id("C4847478") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter @pytest.mark.xfail # LYN-3275 def test_AltitudeFilter_FilterStageToggle(self, request, editor, level, workspace, launcher_platform): cfg_args = [level] diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AreaComponentSlices.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AreaComponentSlices.py index 1353efbf2e..5f42fc6de0 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AreaComponentSlices.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AreaComponentSlices.py @@ -52,6 +52,7 @@ class TestAreaComponents(object): @pytest.mark.test_case_id("C2627900", "C2627905", "C2627904") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_AreaComponents_SliceCreationVisibilityToggleWorks(self, request, editor, level, workspace, launcher_platform): cfg_args = [level] diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetListCombiner.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetListCombiner.py index ad0917ca22..b40d99b100 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetListCombiner.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetListCombiner.py @@ -38,6 +38,7 @@ class TestAssetListCombiner(object): @pytest.mark.test_case_id("C4762374", "C4762373") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_AssetListCombiner_CombinedDescriptorsExpressInConfiguredArea(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetWeightSelector.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetWeightSelector.py index 65472df3bc..7b34a10d66 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetWeightSelector.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_AssetWeightSelector.py @@ -42,6 +42,7 @@ class TestAssetWeightSelector(object): @pytest.mark.test_case_id("C6269654", "C4762368") @pytest.mark.SUITE_sandbox + @pytest.mark.dynveg_filter def test_AssetWeightSelector_InstancesExpressBasedOnWeight(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_Debugger.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_Debugger.py index 45518b71fc..7466089173 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_Debugger.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_Debugger.py @@ -40,6 +40,7 @@ class TestDebugger(object): @pytest.mark.test_case_id("C2789148") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_Debugger_DebugCVarsWork(self, request, editor, level, workspace, launcher_platform): cfg_args = [level] diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DistanceBetweenFilter.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DistanceBetweenFilter.py index 3171cc032f..191f27fca0 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DistanceBetweenFilter.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DistanceBetweenFilter.py @@ -38,6 +38,7 @@ class TestDistanceBetweenFilter(object): @pytest.mark.test_case_id("C4851066") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_DistanceBetweenFilter_InstancesPlantAtSpecifiedRadius(self, request, editor, level, launcher_platform): expected_lines = [ @@ -58,6 +59,7 @@ class TestDistanceBetweenFilter(object): @pytest.mark.test_case_id("C4814458") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_DistanceBetweenFilterOverrides_InstancesPlantAtSpecifiedRadius(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynVeg_Regressions.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynVeg_Regressions.py index b3cf344b2b..5c6e034a12 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynVeg_Regressions.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynVeg_Regressions.py @@ -40,6 +40,7 @@ class Test_DynVeg_Regressions(object): @pytest.mark.test_case_id("C29470845") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_regression def test_SurfaceDataRefreshes_RemainsStable(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py index f0673a9438..9898570692 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py @@ -41,7 +41,8 @@ class TestDynamicSliceInstanceSpawner(object): return console @pytest.mark.test_case_id("C28851763") - @pytest.mark.SUITE_sandbox + @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.parametrize("launcher_platform", ['windows_editor']) def test_DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks(self, request, editor, level, workspace, project, launcher_platform): @@ -66,6 +67,7 @@ class TestDynamicSliceInstanceSpawner(object): @pytest.mark.test_case_id('C2574330') @pytest.mark.BAT @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.parametrize("launcher_platform", ['windows_editor']) def test_DynamicSliceInstanceSpawner_Embedded_E2E_Editor(self, workspace, request, editor, level, project, launcher_platform): @@ -85,6 +87,7 @@ class TestDynamicSliceInstanceSpawner(object): @pytest.mark.test_case_id('C2574330') @pytest.mark.BAT @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.parametrize("launcher_platform", ['windows']) @pytest.mark.skip # ATOM-14703 def test_DynamicSliceInstanceSpawner_Embedded_E2E_Launcher(self, workspace, launcher, level, @@ -101,6 +104,7 @@ class TestDynamicSliceInstanceSpawner(object): @pytest.mark.test_case_id('C4762367') @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.parametrize("launcher_platform", ['windows_editor']) def test_DynamicSliceInstanceSpawner_External_E2E_Editor(self, workspace, request, editor, level, project, launcher_platform): @@ -119,6 +123,7 @@ class TestDynamicSliceInstanceSpawner(object): @pytest.mark.test_case_id('C4762367') @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.parametrize("launcher_platform", ['windows']) @pytest.mark.skip # ATOM-14703 def test_DynamicSliceInstanceSpawner_External_E2E_Launcher(self, workspace, launcher, level, diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py index fc8c31fc7b..7bd8484cf4 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py @@ -36,13 +36,9 @@ class TestEmptyInstanceSpawner(object): file_system.delete([os.path.join(workspace.paths.engine_root(), project, "Levels", level)], True, True) - # Main suite needs at least one test - @pytest.mark.SUITE_main - def test_EmptyInstanceSpawner_Dummy(self, request, editor, level, workspace, project, launcher_platform): - pass - @pytest.mark.test_case_id("C28851762") - @pytest.mark.SUITE_sandbox + @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area def test_EmptyInstanceSpawner_EmptySpawnerWorks(self, request, editor, level, launcher_platform): cfg_args = [level] diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_InstanceSpawnerPriority.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_InstanceSpawnerPriority.py index d04b827985..53b5c3b760 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_InstanceSpawnerPriority.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_InstanceSpawnerPriority.py @@ -43,6 +43,7 @@ class TestInstanceSpawnerPriority(object): @pytest.mark.test_case_id("C5747383", "C4762382") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_InstanceSpawnerPriority_LayerAndSubPriority_HigherValuesPlantOverLower(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlender.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlender.py index 2286238364..76b8b3cd3a 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlender.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlender.py @@ -20,17 +20,10 @@ import pytest pytest.importorskip("ly_test_tools") -import time as time - -import editor_python_test_tools.hydra_test_utils as hydra -import ly_test_tools.launchers.launcher_helper as launcher_helper +import ly_remote_console.remote_console_commands as remote_console_commands import ly_test_tools.environment.waiter as waiter import ly_test_tools.environment.file_system as file_system -import ly_remote_console.remote_console_commands as remote_console_commands -from ly_remote_console.remote_console_commands import send_command_and_expect_response as send_command_and_expect_response - -import automatedtesting_shared.screenshot_utils as screenshot_utils -from automatedtesting_shared.network_utils import check_for_listening_port +import editor_python_test_tools.hydra_test_utils as hydra test_directory = os.path.join(os.path.dirname(__file__), "EditorScripts") @@ -58,6 +51,7 @@ class TestLayerBlender(object): @pytest.mark.test_case_id("C2627906") @pytest.mark.BAT @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.parametrize("launcher_platform", ['windows_editor']) def test_LayerBlender_E2E_Editor(self, workspace, request, editor, project, level, launcher_platform): # Make sure temp level doesn't already exist @@ -95,6 +89,7 @@ class TestLayerBlender(object): @pytest.mark.test_case_id("C2627906") @pytest.mark.BAT @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.xfail @pytest.mark.parametrize("launcher_platform", ['windows']) def test_LayerBlender_E2E_Launcher(self, workspace, project, launcher, level, remote_console_instance, diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlocker.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlocker.py index 6da0cdd6db..308f4480c5 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlocker.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerBlocker.py @@ -38,6 +38,7 @@ class TestLayerBlocker(object): @pytest.mark.test_case_id("C2793772") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area def test_LayerBlocker_InstancesBlockedInConfiguredArea(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerSpawner.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerSpawner.py index 93149c9490..d206a962da 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerSpawner.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_LayerSpawner.py @@ -40,6 +40,7 @@ class TestLayerSpawner(object): @pytest.mark.test_case_id("C4762381") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_LayerSpawner_InheritBehaviorFlag(self, request, editor, level, workspace, launcher_platform): expected_lines = [ @@ -60,6 +61,7 @@ class TestLayerSpawner(object): @pytest.mark.test_case_id("C2802020") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_LayerSpawner_InstancesPlantInAllSupportedShapes(self, request, editor, level, launcher_platform): expected_lines = [ @@ -101,6 +103,7 @@ class TestLayerSpawner(object): @pytest.mark.test_case_id("C4765973") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc @pytest.mark.xfail # LYN-3275 def test_LayerSpawner_FilterStageToggle(self, request, editor, level, workspace, launcher_platform): @@ -122,6 +125,7 @@ class TestLayerSpawner(object): @pytest.mark.test_case_id("C30000751") @pytest.mark.SUITE_sandbox + @pytest.mark.dynveg_misc @pytest.mark.skip # ATOM-14828 def test_LayerSpawner_InstancesRefreshUsingCorrectViewportCamera(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshBlocker.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshBlocker.py index c04390e647..7e1b416556 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshBlocker.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshBlocker.py @@ -46,6 +46,7 @@ class TestMeshBlocker(object): """ @pytest.mark.test_case_id("C3980834") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.xfail # LYN-3273 def test_MeshBlocker_InstancesBlockedByMesh(self, request, editor, level, launcher_platform): expected_lines = [ @@ -70,6 +71,7 @@ class TestMeshBlocker(object): """ @pytest.mark.test_case_id("C4766030") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_area @pytest.mark.xfail # LYN-3273 def test_MeshBlocker_InstancesBlockedByMeshHeightTuning(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshSurfaceTagEmitter.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshSurfaceTagEmitter.py index 77638cb576..dcbffdf3b7 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshSurfaceTagEmitter.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_MeshSurfaceTagEmitter.py @@ -38,6 +38,7 @@ class TestMeshSurfaceTagEmitter(object): @pytest.mark.test_case_id("C2908172") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_surfacetagemitter def test_MeshSurfaceTagEmitter_DependentOnMeshComponent(self, request, editor, level, launcher_platform): expected_lines = [ @@ -66,6 +67,7 @@ class TestMeshSurfaceTagEmitter(object): @pytest.mark.test_case_id("C2908174") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_surfacetagemitter def test_MeshSurfaceTagEmitter_SurfaceTagsAddRemoveSuccessfully(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PhysXColliderSurfaceTagEmitter.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PhysXColliderSurfaceTagEmitter.py index ca4e30a719..0f84e2caa2 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PhysXColliderSurfaceTagEmitter.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PhysXColliderSurfaceTagEmitter.py @@ -38,6 +38,7 @@ class TestPhysXColliderSurfaceTagEmitter(object): @pytest.mark.test_case_id("C29053640") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_surfacetagemitter def test_PhysXColliderSurfaceTagEmitter_E2E_Editor(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PositionModifier.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PositionModifier.py index ac3e0abb4f..2cf8db3b96 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PositionModifier.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_PositionModifier.py @@ -38,6 +38,7 @@ class TestPositionModifier(object): @pytest.mark.test_case_id("C4874099", "C4814461") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_modifier def test_PositionModifier_ComponentAndOverrides_InstancesPlantAtSpecifiedOffsets(self, request, editor, level, launcher_platform): @@ -60,6 +61,7 @@ class TestPositionModifier(object): @pytest.mark.test_case_id("C4874100") @pytest.mark.SUITE_sandbox + @pytest.mark.dynveg_modifier @pytest.mark.xfail # LYN-3275 def test_PositionModifier_AutoSnapToSurfaceWorks(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_RotationModifier.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_RotationModifier.py index 518949c0c0..3b0c9b3947 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_RotationModifier.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_RotationModifier.py @@ -42,6 +42,7 @@ class TestRotationModifier(object): @pytest.mark.test_case_id("C4896922") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_modifier def test_RotationModifier_InstancesRotateWithinRange(self, request, editor, level, launcher_platform) -> None: """ Launches editor and run test script to test that rotation modifier works for all axis. @@ -71,6 +72,7 @@ class TestRotationModifier(object): @pytest.mark.test_case_id("C4814460") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_modifier def test_RotationModifierOverrides_InstancesRotateWithinRange(self, request, editor, level, launcher_platform) -> None: expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ScaleModifier.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ScaleModifier.py index 6acd95e4f6..7fe7a4ece2 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ScaleModifier.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ScaleModifier.py @@ -41,6 +41,7 @@ class TestScaleOverrideWorksSuccessfully(object): @pytest.mark.test_case_id("C4814462") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_modifier def test_ScaleModifierOverrides_InstancesProperlyScale(self, request, editor, level, launcher_platform): expected_lines = [ @@ -70,6 +71,7 @@ class TestScaleOverrideWorksSuccessfully(object): @pytest.mark.test_case_id("C4896937") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_modifier def test_ScaleModifier_InstancesProperlyScale(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ShapeIntersectionFilter.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ShapeIntersectionFilter.py index ea90b67a7f..8acdb1b644 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ShapeIntersectionFilter.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_ShapeIntersectionFilter.py @@ -38,6 +38,7 @@ class TestShapeIntersectionFilter(object): @pytest.mark.test_case_id("C4874094") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_ShapeIntersectionFilter_InstancesPlantInAssignedShape(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeAlignmentModifier.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeAlignmentModifier.py index 563ac1dcc5..6825686509 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeAlignmentModifier.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeAlignmentModifier.py @@ -41,6 +41,7 @@ class TestSlopeAlignmentModifier(object): @pytest.mark.test_case_id("C4896941") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_modifier @pytest.mark.skip # ATOM-14299 def test_SlopeAlignmentModifier_InstanceSurfaceAlignment(self, request, editor, level, launcher_platform): @@ -63,6 +64,7 @@ class TestSlopeAlignmentModifier(object): @pytest.mark.test_case_id("C4814459") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_modifier @pytest.mark.skip # ATOM-14299 def test_SlopeAlignmentModifierOverrides_InstanceSurfaceAlignment(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeFilter.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeFilter.py index dc0f0e6514..48e532adcd 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeFilter.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SlopeFilter.py @@ -39,6 +39,7 @@ class TestSlopeFilter(object): @pytest.mark.test_case_id("C4874097") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_SlopeFilter_FilterStageToggle(self, request, editor, level, workspace, launcher_platform): cfg_args = [level] @@ -70,6 +71,7 @@ class TestSlopeFilter(object): @pytest.mark.test_case_id("C4814464", "C4874096") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter @pytest.mark.skip # LYN-2211 def test_SlopeFilter_ComponentAndOverrides_InstancesPlantOnValidSlopes(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SurfaceMaskFilter.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SurfaceMaskFilter.py index 20cab85293..952c000232 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SurfaceMaskFilter.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SurfaceMaskFilter.py @@ -40,6 +40,7 @@ class TestSurfaceMaskFilter(object): # Simple validation test to ensure that SurfaceTag can be created, set to a value, and compared to another SurfaceTag. @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_SurfaceMaskFilter_BasicSurfaceTagCreation(self, request, level, editor, launcher_platform): expected_lines = [ @@ -61,6 +62,7 @@ class TestSurfaceMaskFilter(object): @pytest.mark.test_case_id("C2561342") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_SurfaceMaskFilter_ExclusiveSurfaceTags_Function(self, request, editor, level, launcher_platform): expected_lines = [ @@ -93,6 +95,7 @@ class TestSurfaceMaskFilter(object): @pytest.mark.test_case_id("C2561341") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_SurfaceMaskFilter_InclusiveSurfaceTags_Function(self, request, editor, level, launcher_platform): expected_lines = [ @@ -125,6 +128,7 @@ class TestSurfaceMaskFilter(object): @pytest.mark.test_case_id("C3711666") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_filter def test_SurfaceMaskFilterOverrides_MultipleDescriptorOverridesPlantAsExpected(self, request, editor, level, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SystemSettings.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SystemSettings.py index adf9a90587..0b55d06ae4 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SystemSettings.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_SystemSettings.py @@ -38,6 +38,7 @@ class TestSystemSettings(object): @pytest.mark.test_case_id("C2646869") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_SystemSettings_SectorPointDensity(self, request, editor, level, launcher_platform): expected_lines = [ @@ -64,6 +65,7 @@ class TestSystemSettings(object): @pytest.mark.test_case_id("C2646870") @pytest.mark.SUITE_periodic + @pytest.mark.dynveg_misc def test_SystemSettings_SectorSize(self, request, editor, level, launcher_platform): expected_lines = [ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C100000_RigidBody_EnablingGravityWorksPoC.py b/AutomatedTesting/Gem/PythonTests/physics/C100000_RigidBody_EnablingGravityWorksPoC.py index e0277180ae..1284c234bd 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C100000_RigidBody_EnablingGravityWorksPoC.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C100000_RigidBody_EnablingGravityWorksPoC.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C100000 # Test Case Title : Check that Gravity works -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/100000 + # fmt:off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C111111_RigidBody_EnablingGravityWorksUsingNotificationsPoC.py b/AutomatedTesting/Gem/PythonTests/physics/C111111_RigidBody_EnablingGravityWorksUsingNotificationsPoC.py index c7dd8debb9..725da5fb24 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C111111_RigidBody_EnablingGravityWorksUsingNotificationsPoC.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C111111_RigidBody_EnablingGravityWorksUsingNotificationsPoC.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C111111 # Test Case Title : Check that Gravity works -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/111111 + # fmt:off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12712452_ScriptCanvas_CollisionEvents.py b/AutomatedTesting/Gem/PythonTests/physics/C12712452_ScriptCanvas_CollisionEvents.py index 216a75233f..380bb8a3c8 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12712452_ScriptCanvas_CollisionEvents.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12712452_ScriptCanvas_CollisionEvents.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C12712452 # Test Case Title : Verify ScriptCanvas Collision Events -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/12712452 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12712453_ScriptCanvas_MultipleRaycastNode.py b/AutomatedTesting/Gem/PythonTests/physics/C12712453_ScriptCanvas_MultipleRaycastNode.py index 2adf30e65e..b415688de7 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12712453_ScriptCanvas_MultipleRaycastNode.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12712453_ScriptCanvas_MultipleRaycastNode.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C12712453 # Test Case Title : Verify Raycast Multiple Node -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/12712453 + # fmt:off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12712454_ScriptCanvas_OverlapNodeVerification.py b/AutomatedTesting/Gem/PythonTests/physics/C12712454_ScriptCanvas_OverlapNodeVerification.py index 94eed900ff..bcf980a710 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12712454_ScriptCanvas_OverlapNodeVerification.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12712454_ScriptCanvas_OverlapNodeVerification.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : 12712454 # Test Case Title : Verify overlap nodes in script canvas -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/12712454 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12712455_ScriptCanvas_ShapeCastVerification.py b/AutomatedTesting/Gem/PythonTests/physics/C12712455_ScriptCanvas_ShapeCastVerification.py index 61f26ebecb..668e8083c3 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12712455_ScriptCanvas_ShapeCastVerification.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12712455_ScriptCanvas_ShapeCastVerification.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C12712455 # Test Case Title : Verify shape cast nodes in SC -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/12712455 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12868578_ForceRegion_DirectionHasNoAffectOnMagnitude.py b/AutomatedTesting/Gem/PythonTests/physics/C12868578_ForceRegion_DirectionHasNoAffectOnMagnitude.py index 4745927e89..d2438110fe 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12868578_ForceRegion_DirectionHasNoAffectOnMagnitude.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12868578_ForceRegion_DirectionHasNoAffectOnMagnitude.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C12868578 # Test Case Title : Check that World space and local space force direction doesn't affect magnitude of force exerted -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/12868578 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12868580_ForceRegion_SplineModifiedTransform.py b/AutomatedTesting/Gem/PythonTests/physics/C12868580_ForceRegion_SplineModifiedTransform.py index 937fdd85a6..6372104fcf 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12868580_ForceRegion_SplineModifiedTransform.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12868580_ForceRegion_SplineModifiedTransform.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C12868580 # Test Case Title : Check that spline follow force works if transform components of entity are altered -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/12868580 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12905527_ForceRegion_MagnitudeDeviation.py b/AutomatedTesting/Gem/PythonTests/physics/C12905527_ForceRegion_MagnitudeDeviation.py index 0cb0a2f841..76578460d5 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12905527_ForceRegion_MagnitudeDeviation.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12905527_ForceRegion_MagnitudeDeviation.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C12905527 # Test Case Title : Check that deviation occurring in Force Magnitude due to Values in Force direction is not large -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/12905527 + # fmt: off class Tests(): diff --git a/AutomatedTesting/Gem/PythonTests/physics/C12905528_ForceRegion_WithNonTriggerCollider.py b/AutomatedTesting/Gem/PythonTests/physics/C12905528_ForceRegion_WithNonTriggerCollider.py index 42565333f7..38dc5488d2 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C12905528_ForceRegion_WithNonTriggerCollider.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C12905528_ForceRegion_WithNonTriggerCollider.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C12905528 Test Case Title : Check that user is warned if non-trigger collider component is used with force region -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/12905528 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C13351703_COM_NotIncludeTriggerShapes.py b/AutomatedTesting/Gem/PythonTests/physics/C13351703_COM_NotIncludeTriggerShapes.py index 828022ccf2..d5bd946d34 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C13351703_COM_NotIncludeTriggerShapes.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C13351703_COM_NotIncludeTriggerShapes.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C13351703 # Test Case Title : Check that Center of Mass calculations should not include trigger shapes -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/13351703 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C13352089_RigidBodies_MaxAngularVelocity.py b/AutomatedTesting/Gem/PythonTests/physics/C13352089_RigidBodies_MaxAngularVelocity.py index 77d93d9752..09b6956b06 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C13352089_RigidBodies_MaxAngularVelocity.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C13352089_RigidBodies_MaxAngularVelocity.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C13352089 # Test Case Title : Verify that maximum angular velocity interacts correctly with initial angular velocity -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/13352089 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C13508019_Terrain_TerrainTexturePainterWorks.py b/AutomatedTesting/Gem/PythonTests/physics/C13508019_Terrain_TerrainTexturePainterWorks.py index 1c580bfbfe..9c7a6e75e9 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C13508019_Terrain_TerrainTexturePainterWorks.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C13508019_Terrain_TerrainTexturePainterWorks.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C13508019 # Test Case Title : Verify terrain materials are updated after using terrain texture layer painter. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/13508019 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C13895144_Ragdoll_ChangeLevel.py b/AutomatedTesting/Gem/PythonTests/physics/C13895144_Ragdoll_ChangeLevel.py index 61efe20dbd..66050565a4 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C13895144_Ragdoll_ChangeLevel.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C13895144_Ragdoll_ChangeLevel.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C13895144 # Test Case Title : Run a level with multiple ragdolls and then switch levels -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/13895144 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14195074_ScriptCanvas_PostUpdateEvent.py b/AutomatedTesting/Gem/PythonTests/physics/C14195074_ScriptCanvas_PostUpdateEvent.py index 5668082f78..1d0e1d5ac8 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14195074_ScriptCanvas_PostUpdateEvent.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14195074_ScriptCanvas_PostUpdateEvent.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C14195074 # Test Case Title : Verify Postsimulate Events -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14195074 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14654881_CharacterController_SwitchLevels.py b/AutomatedTesting/Gem/PythonTests/physics/C14654881_CharacterController_SwitchLevels.py index fd5653b801..8fc58b4765 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14654881_CharacterController_SwitchLevels.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14654881_CharacterController_SwitchLevels.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C14654881 # Test Case Title : Switching levels from a level containing a character controller component # should not lead to a crash -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14654881 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14654882_Ragdoll_ragdollAPTest.py b/AutomatedTesting/Gem/PythonTests/physics/C14654882_Ragdoll_ragdollAPTest.py index 03c18a5f1a..33077f2607 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14654882_Ragdoll_ragdollAPTest.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14654882_Ragdoll_ragdollAPTest.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ Test case ID : C14654882 Test Case Title : Loading level with old PhysX Ragdoll component serialization should not produce asset processor errors -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14654882 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14861498_ConfirmError_NoPxMesh.py b/AutomatedTesting/Gem/PythonTests/physics/C14861498_ConfirmError_NoPxMesh.py index e52bdb7574..dca831456d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14861498_ConfirmError_NoPxMesh.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14861498_ConfirmError_NoPxMesh.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C14861498 # Test Case Title : Confirm that when a PhysXCollider has no physics asset, the physics asset collider \ # shape throw an error -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14861498 + # fmt:off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14861500_DefaultSetting_ColliderShape.py b/AutomatedTesting/Gem/PythonTests/physics/C14861500_DefaultSetting_ColliderShape.py index 7a65448dcd..c6a275d04d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14861500_DefaultSetting_ColliderShape.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14861500_DefaultSetting_ColliderShape.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C14861500 Test Case Title : Verify Default shape is Physics Asset -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14861500 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14861501_PhysXCollider_RenderMeshAutoAssigned.py b/AutomatedTesting/Gem/PythonTests/physics/C14861501_PhysXCollider_RenderMeshAutoAssigned.py index 904b5b0189..e415687001 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14861501_PhysXCollider_RenderMeshAutoAssigned.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14861501_PhysXCollider_RenderMeshAutoAssigned.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C14861501 Test Case Title : Verify PxMesh is auto-assigned when Collider component is added after Rendering Mesh component -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14861501 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14861502_PhysXCollider_AssetAutoAssigned.py b/AutomatedTesting/Gem/PythonTests/physics/C14861502_PhysXCollider_AssetAutoAssigned.py index 075c3f5b61..64820f7daf 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14861502_PhysXCollider_AssetAutoAssigned.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14861502_PhysXCollider_AssetAutoAssigned.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C14861502 Test Case Title : Verify PxMesh is auto-assigned in collider when Mesh is assigned in Rendering Mesh component -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14861502 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14861504_RenderMeshAsset_WithNoPxAsset.py b/AutomatedTesting/Gem/PythonTests/physics/C14861504_RenderMeshAsset_WithNoPxAsset.py index bbaabf67f6..766a359397 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14861504_RenderMeshAsset_WithNoPxAsset.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14861504_RenderMeshAsset_WithNoPxAsset.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C14861504 Test Case Title : Verify if Rendering Mesh does not have a PhysX Collision Mesh fbx, then PxMesh is not auto-assigned -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14861504 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14902097_ScriptCanvas_PreUpdateEvent.py b/AutomatedTesting/Gem/PythonTests/physics/C14902097_ScriptCanvas_PreUpdateEvent.py index 45557098f7..327f40ec38 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14902097_ScriptCanvas_PreUpdateEvent.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14902097_ScriptCanvas_PreUpdateEvent.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C14902097 # Test Case Title : Verify Presimulate Events -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14902097 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14902098_ScriptCanvas_PostPhysicsUpdate.py b/AutomatedTesting/Gem/PythonTests/physics/C14902098_ScriptCanvas_PostPhysicsUpdate.py index 19caaab4fe..f7c8be8804 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14902098_ScriptCanvas_PostPhysicsUpdate.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14902098_ScriptCanvas_PostPhysicsUpdate.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C14902098 # Test Case Title : Check that force region simulation with Postsimulate works independently from rendering tick -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14902098 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14976307_Gravity_SetGravityWorks.py b/AutomatedTesting/Gem/PythonTests/physics/C14976307_Gravity_SetGravityWorks.py index 342ac6bdbd..73137ac497 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14976307_Gravity_SetGravityWorks.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14976307_Gravity_SetGravityWorks.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C14976307 # Test Case Title : Check that Set Gravity Enabled works on an entity with gravity that starts as disabled -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/14976307 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C14976308_ScriptCanvas_SetKinematicTargetTransform.py b/AutomatedTesting/Gem/PythonTests/physics/C14976308_ScriptCanvas_SetKinematicTargetTransform.py index 815e922a76..c76c5cab80 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C14976308_ScriptCanvas_SetKinematicTargetTransform.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C14976308_ScriptCanvas_SetKinematicTargetTransform.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case # ID : C14976308 # Title : Verify that SetKinematicTarget on PhysX rigid body updates transform for kinematic entities and vice versa -# URL : https://testrail.agscollab.com/index.php?/cases/view/14976308 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_after.py b/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_after.py index 76ea9475ff..bdfc9d19be 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_after.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_after.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15096732 # Test Case Title : Verify Default material library works across different levels -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15096732 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_before.py b/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_before.py index 748052db56..d45423fe94 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_before.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15096732_Material_DefaultLibraryUpdatedAcrossLevels_before.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15096732 # Test Case Title : Verify Default material library works across different levels -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15096732 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15096735_Materials_DefaultLibraryConsistency.py b/AutomatedTesting/Gem/PythonTests/physics/C15096735_Materials_DefaultLibraryConsistency.py index 4c7949cc91..3dd49d4fe4 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15096735_Materials_DefaultLibraryConsistency.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15096735_Materials_DefaultLibraryConsistency.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15096735 # Test Case Title : Verify that default material library works consistently across all systems that use it -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15096735 + # fmt:off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15096737_Materials_DefaultMaterialLibraryChanges.py b/AutomatedTesting/Gem/PythonTests/physics/C15096737_Materials_DefaultMaterialLibraryChanges.py index cc7dc3c5e2..c806cbb7d4 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15096737_Materials_DefaultMaterialLibraryChanges.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15096737_Materials_DefaultMaterialLibraryChanges.py @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case Title : Verify that a change in the default material library material information # affects all the materials that reference it, even non-defaulted # exactly like if the library was selected -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15096737 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15096740_Material_LibraryUpdatedCorrectly.py b/AutomatedTesting/Gem/PythonTests/physics/C15096740_Material_LibraryUpdatedCorrectly.py index 0f33f0858b..bef98f6830 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15096740_Material_LibraryUpdatedCorrectly.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15096740_Material_LibraryUpdatedCorrectly.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C15096740 Test Case Title : Verify that clearing a material library on all systems that use it, assigns the default material library -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15096740 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15308217_NoCrash_LevelSwitch.py b/AutomatedTesting/Gem/PythonTests/physics/C15308217_NoCrash_LevelSwitch.py index 625a8bfb4a..dadfbd7a7e 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15308217_NoCrash_LevelSwitch.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15308217_NoCrash_LevelSwitch.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15308217 # Test Case Title : Verify that the Terrain texture layer doesn't crash when changing # from on a level with a terrain component to another level without a terrain component -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15308217 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15308221_Material_ComponentsInSyncWithLibrary.py b/AutomatedTesting/Gem/PythonTests/physics/C15308221_Material_ComponentsInSyncWithLibrary.py index 3f6457f15c..ebc7d3fadd 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15308221_Material_ComponentsInSyncWithLibrary.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15308221_Material_ComponentsInSyncWithLibrary.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C15308221 # Test Case Title : Verify that material library and slots are always in sync and work consistently through the different places of usage -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/15308221 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15425929_Undo_Redo.py b/AutomatedTesting/Gem/PythonTests/physics/C15425929_Undo_Redo.py index 57a0e6a75e..dba14552c8 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15425929_Undo_Redo.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15425929_Undo_Redo.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15425929 # Test Case Title : Verify that undo - redo operations do not create any error -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15425929 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15425935_Material_LibraryUpdatedAcrossLevels.py b/AutomatedTesting/Gem/PythonTests/physics/C15425935_Material_LibraryUpdatedAcrossLevels.py index f61886ccd0..8ff90fddaf 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15425935_Material_LibraryUpdatedAcrossLevels.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15425935_Material_LibraryUpdatedAcrossLevels.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15425935 # Test Case Title : Verify that the change in Material Library gets updated across levels -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15425935 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15556261_PhysXMaterials_CharacterControllerMaterialAssignment.py b/AutomatedTesting/Gem/PythonTests/physics/C15556261_PhysXMaterials_CharacterControllerMaterialAssignment.py index 99e0dcc669..21f5952678 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15556261_PhysXMaterials_CharacterControllerMaterialAssignment.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15556261_PhysXMaterials_CharacterControllerMaterialAssignment.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15556261 # Test Case Title : Check that the material assignment works with Character Controller -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15556261 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15563573_Material_AddModifyDeleteOnCharacterController.py b/AutomatedTesting/Gem/PythonTests/physics/C15563573_Material_AddModifyDeleteOnCharacterController.py index 4572dd322a..1e9b15fc90 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15563573_Material_AddModifyDeleteOnCharacterController.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15563573_Material_AddModifyDeleteOnCharacterController.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C15563573 # Test Case Title : Check that any change (Add/Delete/Modify) made to the material surface in the material library reflects immediately in the PhysX Character Controller -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/15563573 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C15845879_ForceRegion_HighLinearDampingForce.py b/AutomatedTesting/Gem/PythonTests/physics/C15845879_ForceRegion_HighLinearDampingForce.py index 52af7d8be5..6b31ffb13b 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C15845879_ForceRegion_HighLinearDampingForce.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C15845879_ForceRegion_HighLinearDampingForce.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C15845879 # Test Case Title : Check that linear damping with high values do not make the object to quiver -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/15845879 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C17411467_AddPhysxRagdollComponent.py b/AutomatedTesting/Gem/PythonTests/physics/C17411467_AddPhysxRagdollComponent.py index 68efd452b2..32bd02ae26 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C17411467_AddPhysxRagdollComponent.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C17411467_AddPhysxRagdollComponent.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C17411467 Test Case Title : Check that Physx Ragdoll component can be added without errors/warnings -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/17411467 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243580_Joints_Fixed2BodiesConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243580_Joints_Fixed2BodiesConstrained.py index b13869ce12..c3a351ebea 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243580_Joints_Fixed2BodiesConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243580_Joints_Fixed2BodiesConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243580 # Test Case Title : Check that fixed joint constrains 2 bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243580 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243581_Joints_FixedBreakable.py b/AutomatedTesting/Gem/PythonTests/physics/C18243581_Joints_FixedBreakable.py index 19feee575b..00e9a5625f 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243581_Joints_FixedBreakable.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243581_Joints_FixedBreakable.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243581 # Test Case Title : Check that fixed joint is breakable -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243581 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243582_Joints_FixedLeadFollowerCollide.py b/AutomatedTesting/Gem/PythonTests/physics/C18243582_Joints_FixedLeadFollowerCollide.py index c9c90d35a7..d34e3f67d3 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243582_Joints_FixedLeadFollowerCollide.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243582_Joints_FixedLeadFollowerCollide.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243582 # Test Case Title : Check that fixed joint allows lead-follower collision -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243582 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243583_Joints_Hinge2BodiesConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243583_Joints_Hinge2BodiesConstrained.py index 66343534a7..eafce6ceaf 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243583_Joints_Hinge2BodiesConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243583_Joints_Hinge2BodiesConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243583 # Test Case Title : Check that hinge joint constrains 2 bodies about X-axis -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243583 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243584_Joints_HingeSoftLimitsConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243584_Joints_HingeSoftLimitsConstrained.py index 3b335cc5c6..90027be2d7 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243584_Joints_HingeSoftLimitsConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243584_Joints_HingeSoftLimitsConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243584 # Test Case Title : Check that hinge joint allows soft limit constraints on 2 bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243584 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243585_Joints_HingeNoLimitsConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243585_Joints_HingeNoLimitsConstrained.py index 289522fcac..0f677d94ae 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243585_Joints_HingeNoLimitsConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243585_Joints_HingeNoLimitsConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243585 # Test Case Title : Check that hinge joint allows no limit constraints on 2 bodies -# URL of the test case :https://testrail.agscollab.com/index.php?/cases/view/18243585 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243586_Joints_HingeLeadFollowerCollide.py b/AutomatedTesting/Gem/PythonTests/physics/C18243586_Joints_HingeLeadFollowerCollide.py index 60b9189c83..7c973729d1 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243586_Joints_HingeLeadFollowerCollide.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243586_Joints_HingeLeadFollowerCollide.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243586 # Test Case Title : Check that hinge joint allows lead-follower collision -# URL of the test case :https://testrail.agscollab.com/index.php?/cases/view/18243586 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243587_Joints_HingeBreakable.py b/AutomatedTesting/Gem/PythonTests/physics/C18243587_Joints_HingeBreakable.py index af6fa8cbac..4734328d70 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243587_Joints_HingeBreakable.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243587_Joints_HingeBreakable.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243587 # Test Case Title : Check that hinge joint is breakable -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243587 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243588_Joints_Ball2BodiesConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243588_Joints_Ball2BodiesConstrained.py index 074ca03000..b6acfd6dd8 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243588_Joints_Ball2BodiesConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243588_Joints_Ball2BodiesConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243588 # Test Case Title : Check that ball joint constrains 2 bodies within cone limits -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243588 + # fmt: off class Tests: enter_game_mode = ("Entered game mode", "Failed to enter game mode") diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243589_Joints_BallSoftLimitsConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243589_Joints_BallSoftLimitsConstrained.py index e038b33043..1ca49035b5 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243589_Joints_BallSoftLimitsConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243589_Joints_BallSoftLimitsConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : 18243589 # Test Case Title : Check that ball joint allows soft limit constraints -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243589 + # fmt: off class Tests: @@ -57,6 +57,7 @@ def C18243589_Joints_BallSoftLimitsConstrained(): """ import os import sys + import math import ImportPathHelper as imports @@ -95,13 +96,33 @@ def C18243589_Joints_BallSoftLimitsConstrained(): Report.info_vector3(follower.position, "follower initial position:") leadInitialPosition = lead.position followerInitialPosition = follower.position - - # 4) Wait for several seconds - general.idle_wait(1.0) # wait for lead and follower to move + + followerMovedAboveJoint = False + #calculate the start vector from follower and lead positions + normalizedStartPos = JointsHelper.getRelativeVector(lead.position, follower.position) + normalizedStartPos = normalizedStartPos.GetNormalizedSafe() + #the targeted angle to reach between the initial vector and the current follower-lead vector + TARGET_ANGLE_DEG = 45 + targetAngle = math.radians(TARGET_ANGLE_DEG) + angleAchieved = 0.0 + + def checkAngleMet(): + #calculate the current follower-lead vector + normalVec = JointsHelper.getRelativeVector(lead.position, follower.position) + normalVec = normalVec.GetNormalizedSafe() + #dot product + acos to get the angle + angleAchieved = math.acos(normalizedStartPos.Dot(normalVec)) + #is it above target? + return angleAchieved > targetAngle + + MAX_WAIT_TIME = 2.0 #seconds + followerMovedAboveJoint = helper.wait_for_condition(checkAngleMet, MAX_WAIT_TIME) # 5) Check to see if lead and follower behaved as expected - Report.info_vector3(lead.position, "lead position after 1 second:") - Report.info_vector3(follower.position, "follower position after 1 second:") + Report.info_vector3(lead.position, "lead position:") + Report.info_vector3(follower.position, "follower position:") + angleAchievedDeg = math.degrees(angleAchieved) + Report.info(f"Angle achieved {angleAchievedDeg:.2f} Target {TARGET_ANGLE_DEG:.2f}") leadPositionDelta = lead.position.Subtract(leadInitialPosition) leadRemainedStill = JointsHelper.vector3SmallerThanScalar(leadPositionDelta, FLOAT_EPSILON) @@ -111,7 +132,6 @@ def C18243589_Joints_BallSoftLimitsConstrained(): followerMovedinXYZ = JointsHelper.vector3LargerThanScalar(followerPositionDelta, FLOAT_EPSILON) Report.critical_result(Tests.check_follower_position, followerMovedinXYZ) - followerMovedAboveJoint = follower.position.z > (followerInitialPosition.z + 2.5) # (followerInitialPosition.z + 2.5) is the z position past the 45 degree limit. This is to show that the follower swinged past the 45 degree cone limit, above the joint position. Report.critical_result(Tests.check_follower_above_joint, followerMovedAboveJoint) # 6) Exit Game Mode diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243590_Joints_BallNoLimitsConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243590_Joints_BallNoLimitsConstrained.py index ede46fd5c5..1d5a213cd8 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243590_Joints_BallNoLimitsConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243590_Joints_BallNoLimitsConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243590 # Test Case Title : Check that ball joint allows no limit constraints -# URL of the test case :https://testrail.agscollab.com/index.php?/cases/view/18243590 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243591_Joints_BallLeadFollowerCollide.py b/AutomatedTesting/Gem/PythonTests/physics/C18243591_Joints_BallLeadFollowerCollide.py index c3e527956f..8f7b2d7823 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243591_Joints_BallLeadFollowerCollide.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243591_Joints_BallLeadFollowerCollide.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243591 # Test Case Title : Check that ball joint allows lead-follower collision -# URL of the test case :https://testrail.agscollab.com/index.php?/cases/view/18243591 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243592_Joints_BallBreakable.py b/AutomatedTesting/Gem/PythonTests/physics/C18243592_Joints_BallBreakable.py index 350fccd125..0fa43cf9c8 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243592_Joints_BallBreakable.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243592_Joints_BallBreakable.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243592 # Test Case Title : Check that ball joint is breakable -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243592 + # fmt: off class Tests: enter_game_mode = ("Entered game mode", "Failed to enter game mode") diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18243593_Joints_GlobalFrameConstrained.py b/AutomatedTesting/Gem/PythonTests/physics/C18243593_Joints_GlobalFrameConstrained.py index 4580a229ea..37d659f181 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18243593_Joints_GlobalFrameConstrained.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18243593_Joints_GlobalFrameConstrained.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18243593 # Test Case Title : Check that fixed/hinge/ball joints allow constraints to global frame -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18243593 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18977601_Material_FrictionCombinePriority.py b/AutomatedTesting/Gem/PythonTests/physics/C18977601_Material_FrictionCombinePriority.py index 57dfc0f349..b17b97a816 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18977601_Material_FrictionCombinePriority.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18977601_Material_FrictionCombinePriority.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18977601 # Test Case Title : Verify that when two objects with different materials collide, the friction combine priority works -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18977601 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C18981526_Material_RestitutionCombinePriority.py b/AutomatedTesting/Gem/PythonTests/physics/C18981526_Material_RestitutionCombinePriority.py index 9b7fea1ab9..690d3d4d3f 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C18981526_Material_RestitutionCombinePriority.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C18981526_Material_RestitutionCombinePriority.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C18981526 # Test Case Title : Verify when two objects with different materials collide, the restitution combine priority works -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/18981526 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C19536274_GetCollisionName_PrintsName.py b/AutomatedTesting/Gem/PythonTests/physics/C19536274_GetCollisionName_PrintsName.py index 48c947aa1f..611b502019 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C19536274_GetCollisionName_PrintsName.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C19536274_GetCollisionName_PrintsName.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C19536274 Test Case Title : Verify that the Get Collision Layer Name node prints the name of the collision layer -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/19536274 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C19536277_GetCollisionName_PrintsNothing.py b/AutomatedTesting/Gem/PythonTests/physics/C19536277_GetCollisionName_PrintsNothing.py index 66e1302b5b..04d973cbb2 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C19536277_GetCollisionName_PrintsNothing.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C19536277_GetCollisionName_PrintsNothing.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C19536277 Test Case Title : Verify that when a group is modified using ToggleCollisionLayer node such that the new group is not in the pre-existing groups, GetCollisionGroupName node prints no value -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/19536277 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C19578018_ShapeColliderWithNoShapeComponent.py b/AutomatedTesting/Gem/PythonTests/physics/C19578018_ShapeColliderWithNoShapeComponent.py index 32ece8541c..23996934bc 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C19578018_ShapeColliderWithNoShapeComponent.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C19578018_ShapeColliderWithNoShapeComponent.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C19578018 Test Case Title : Verify that a shape collider component with no shape component indicates a missing service -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/19578018 + """ # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C19578021_ShapeCollider_CanBeAdded.py b/AutomatedTesting/Gem/PythonTests/physics/C19578021_ShapeCollider_CanBeAdded.py index 0c42f5457d..1eb36e16f4 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C19578021_ShapeCollider_CanBeAdded.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C19578021_ShapeCollider_CanBeAdded.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C19578021 Test Case Title : Verify that a shape collider component may be added to an entity along with one or more PhysX collider components -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/19578021 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C19723164_ShapeColliders_WontCrashEditor.py b/AutomatedTesting/Gem/PythonTests/physics/C19723164_ShapeColliders_WontCrashEditor.py index 769f08e3c4..f6584624c3 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C19723164_ShapeColliders_WontCrashEditor.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C19723164_ShapeColliders_WontCrashEditor.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C19723164 Test Case Title : Verify that if we had 512 shape colliders in the level, the level does not crash -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/19723164 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.py b/AutomatedTesting/Gem/PythonTests/physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.py index d8e0a6769c..101b96b99b 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C24308873 # Test Case Title : Check that cylinder shape collider collides with terrain -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/24308873 + # A cylinder is suspended slightly over PhysX Terrain to check that it collides when dropped @@ -20,7 +20,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. class Tests(): enter_game_mode = ("Entered game mode", "Failed to enter game mode") find_cylinder = ("Cylinder entity found", "Cylinder entity not found") - find_terrain = ("Terrain found", "Terrain not found") + create_terrain = ("Terrain entity created successfully", "Failed to create Terrain Entity") + find_terrain = ("Terrain entity found", "Terrain entity not found") + add_physx_shape_collider = ("Added PhysX Shape Collider", "Failed to add PhysX Shape Collider") + add_box_shape = ("Added Box Shape", "Failed to add Box Shape") cylinder_above_terrain = ("Cylinder position above ground", "Cylinder is not above the ground") time_out = ("No time out occurred", "A time out occurred, please validate level setup") touched_ground = ("Touched ground before time out", "Did not touch ground before time out") @@ -40,11 +43,12 @@ def C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain(): Once game mode is entered, the cylinder should fall toward and collide with the terrain. Steps: - 1) Open level and enter game mode - 2) Retrieve entities and positions - 3) Wait for cylinder to collide with terrain OR time out - 4) Exit game mode - 5) Close the editor + 1) Open level and create terrain Entity. + 2) Enter Game Mode. + 3) Retrieve entities and positions + 4) Wait for cylinder to collide with terrain OR time out + 5) Exit game mode + 6) Close the editor :return: """ @@ -54,29 +58,48 @@ def C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain(): import ImportPathHelper as imports imports.init() - + from editor_python_test_tools.editor_entity_utils import EditorEntity import azlmbr.legacy.general as general import azlmbr.bus + import azlmbr.math as math from editor_python_test_tools.utils import Report from editor_python_test_tools.utils import TestHelper as helper # Global time out TIME_OUT = 1.0 - # 1) Open level / Enter game mode + # 1) Open level helper.init_idle() helper.open_level("Physics", "C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain") + + # Create terrain entity + terrain = EditorEntity.create_editor_entity_at([30.0, 30.0, 33.96], "Terrain") + Report.result(Tests.create_terrain, terrain.id.IsValid()) + + terrain.add_component("PhysX Shape Collider") + Report.result(Tests.add_physx_shape_collider, terrain.has_component("PhysX Shape Collider")) + + box_shape_component = terrain.add_component("Box Shape") + Report.result(Tests.add_box_shape, terrain.has_component("Box Shape")) + + box_shape_component.set_component_property_value("Box Shape|Box Configuration|Dimensions", + math.Vector3(1024.0, 1024.0, 0.01)) + + # 2)Enter game mode helper.enter_game_mode(Tests.enter_game_mode) - # 2) Retrieve entities and positions + # 3) Retrieve entities and positions cylinder_id = general.find_game_entity("PhysX_Cylinder") Report.critical_result(Tests.find_cylinder, cylinder_id.IsValid()) + + + terrain_id = general.find_game_entity("Terrain") + Report.critical_result(Tests.find_terrain, terrain_id.IsValid()) - terrain_id = general.find_game_entity("PhysX_Terrain") - Report.critical_result(Tests.find_terrain, terrain_id.IsValid()) - cylinder_pos = azlmbr.components.TransformBus(azlmbr.bus.Event, "GetWorldTM", cylinder_id).GetPosition() - terrain_pos = azlmbr.components.TransformBus(azlmbr.bus.Event, "GetWorldTM", terrain_id).GetPosition() + cylinder_pos = azlmbr.components.TransformBus(azlmbr.bus.Event, "GetWorldTranslation", cylinder_id) + #Cylinder position is 64,84,35 + terrain_pos = azlmbr.components.TransformBus(azlmbr.bus.Event, "GetWorldTranslation", terrain_id) Report.info_vector3(cylinder_pos, "Cylinder:") Report.info_vector3(terrain_pos, "Terrain:") Report.critical_result( @@ -104,13 +127,13 @@ def C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain(): handler.connect(cylinder_id) handler.add_callback("OnCollisionBegin", on_collision_begin) - # 3) Wait for the cylinder to hit the ground OR time out + # 4) Wait for the cylinder to hit the ground OR time out test_completed = helper.wait_for_condition((lambda: TouchGround.value), TIME_OUT) Report.critical_result(Tests.time_out, test_completed) Report.result(Tests.touched_ground, TouchGround.value) - # 4) Exit game mode + # 5) Exit game mode helper.exit_game_mode(Tests.exit_game_mode) diff --git a/AutomatedTesting/Gem/PythonTests/physics/C28978033_Ragdoll_WorldBodyBusTests.py b/AutomatedTesting/Gem/PythonTests/physics/C28978033_Ragdoll_WorldBodyBusTests.py index 8980e68250..052795318a 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C28978033_Ragdoll_WorldBodyBusTests.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C28978033_Ragdoll_WorldBodyBusTests.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C28978033 # Test Case Title : Check that WorldRequestBus works with PhysX ragdoll -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/28978033 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C29032500_EditorComponents_WorldBodyBusWorks.py b/AutomatedTesting/Gem/PythonTests/physics/C29032500_EditorComponents_WorldBodyBusWorks.py index be541e4bf9..4915d362f7 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C29032500_EditorComponents_WorldBodyBusWorks.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C29032500_EditorComponents_WorldBodyBusWorks.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C29032500 # Test Case Title : Check that WorldRequestBus works with editor components -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/29032500 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C3510642_Terrain_NotCollideWithTerrain.py b/AutomatedTesting/Gem/PythonTests/physics/C3510642_Terrain_NotCollideWithTerrain.py index 3e3770adb9..b671cd3754 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C3510642_Terrain_NotCollideWithTerrain.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C3510642_Terrain_NotCollideWithTerrain.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C3510642 # Test Case Title : Check that when no physX terrain component is added, collision of a PhysX object # with terrain does not work. Consequently, PhysX material assignment to terrain cannot be tested. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/3510642 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044455_Material_libraryChangesInstantly.py b/AutomatedTesting/Gem/PythonTests/physics/C4044455_Material_libraryChangesInstantly.py index 5f2c40f11e..a7916129e8 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044455_Material_libraryChangesInstantly.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044455_Material_libraryChangesInstantly.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : 4044455 # Test Case Title : Verify that any change in any of the values including the name of the material, # once saved, is immediately reflected in the component and functionality -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044455 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044456_Material_FrictionCombine.py b/AutomatedTesting/Gem/PythonTests/physics/C4044456_Material_FrictionCombine.py index b71c1e8ede..eced55fc76 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044456_Material_FrictionCombine.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044456_Material_FrictionCombine.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4044456 # Test Case Title : Verify that when two objects with different materials collide, the friction combine works -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044456 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044457_Material_RestitutionCombine.py b/AutomatedTesting/Gem/PythonTests/physics/C4044457_Material_RestitutionCombine.py index 1ed2e8086c..5969541a86 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044457_Material_RestitutionCombine.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044457_Material_RestitutionCombine.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4044457 # Test Case Title : Verify that when two objects with different materials collide, the restitution combine works -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044457 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044459_Material_DynamicFriction.py b/AutomatedTesting/Gem/PythonTests/physics/C4044459_Material_DynamicFriction.py index c420250dfa..d414bc4813 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044459_Material_DynamicFriction.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044459_Material_DynamicFriction.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4044459 # Test Case Title : Verify the functionality of dynamic friction -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044459 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044460_Material_StaticFriction.py b/AutomatedTesting/Gem/PythonTests/physics/C4044460_Material_StaticFriction.py index 4e330002ff..6e864c554b 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044460_Material_StaticFriction.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044460_Material_StaticFriction.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4044460 # Test Case Title : Verify the functionality of static friction -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044460 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044461_Material_Restitution.py b/AutomatedTesting/Gem/PythonTests/physics/C4044461_Material_Restitution.py index af8990d87f..a5219ed2c7 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044461_Material_Restitution.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044461_Material_Restitution.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4044461 # Test Case Title : Verify the functionality of restitution -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044461 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044694_Material_EmptyLibraryUsesDefault.py b/AutomatedTesting/Gem/PythonTests/physics/C4044694_Material_EmptyLibraryUsesDefault.py index a8375114d5..e9106d89eb 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044694_Material_EmptyLibraryUsesDefault.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044694_Material_EmptyLibraryUsesDefault.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C4044694 # Test Case Title : Verify that if we add an empty Material library in Collider Component, the object continues to use Default material values -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/4044694 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044695_PhysXCollider_AddMultipleSurfaceFbx.py b/AutomatedTesting/Gem/PythonTests/physics/C4044695_PhysXCollider_AddMultipleSurfaceFbx.py index 858e778f07..d65e9050bd 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044695_PhysXCollider_AddMultipleSurfaceFbx.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044695_PhysXCollider_AddMultipleSurfaceFbx.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C4044695 Test Case Title : Verify that when you add a multiple surface fbx in PxMesh in PhysxCollider, multiple number of Material Slots populate in the Materials Section -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044695 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4044697_Material_PerfaceMaterialValidation.py b/AutomatedTesting/Gem/PythonTests/physics/C4044697_Material_PerfaceMaterialValidation.py index dba759015f..435e8242d5 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4044697_Material_PerfaceMaterialValidation.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4044697_Material_PerfaceMaterialValidation.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4044697 # Test Case Title : Verify that each surface picks up the material assigned to it and behaves accordingly. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4044697 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4888315_Material_AddModifyDeleteOnCollider.py b/AutomatedTesting/Gem/PythonTests/physics/C4888315_Material_AddModifyDeleteOnCollider.py index 145a5e1b60..b7b3ed855f 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4888315_Material_AddModifyDeleteOnCollider.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4888315_Material_AddModifyDeleteOnCollider.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C4888315 # Test Case Title : Check that any change (Add/Delete/Modify) made to the material surface in the material library reflects immediately in the PhysX Collider component -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/4888315 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4925577_Materials_MaterialAssignedToTerrain.py b/AutomatedTesting/Gem/PythonTests/physics/C4925577_Materials_MaterialAssignedToTerrain.py index 59b6a3fdfc..7ebb62eaf3 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4925577_Materials_MaterialAssignedToTerrain.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4925577_Materials_MaterialAssignedToTerrain.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4925577 # Test Case Title : Verify that material can be assigned to PhysX terrain in Terrain Texture Layers -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4925577 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4925579_Material_AddModifyDeleteOnTerrain.py b/AutomatedTesting/Gem/PythonTests/physics/C4925579_Material_AddModifyDeleteOnTerrain.py index e0425c35be..315cf9c3bd 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4925579_Material_AddModifyDeleteOnTerrain.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4925579_Material_AddModifyDeleteOnTerrain.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C4925579 # Test Case Title : Check that any change (Add/Delete/Modify) made to the material surface in the material library reflects immediately in the PhysX Terrain layers -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/4925579 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4925580_Material_RagdollBonesMaterial.py b/AutomatedTesting/Gem/PythonTests/physics/C4925580_Material_RagdollBonesMaterial.py index 9944a033e3..5fae373f47 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4925580_Material_RagdollBonesMaterial.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4925580_Material_RagdollBonesMaterial.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C4925580 # Test Case Title : Verify that Material can be assigned to Ragdoll Bones and they behave as per their material -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/4925580 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4925582_Material_AddModifyDeleteOnRagdollBones.py b/AutomatedTesting/Gem/PythonTests/physics/C4925582_Material_AddModifyDeleteOnRagdollBones.py index ed872ae99e..ca37be6ff0 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4925582_Material_AddModifyDeleteOnRagdollBones.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4925582_Material_AddModifyDeleteOnRagdollBones.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C4925582 # Test Case Title : Check that any change (Add/Delete/Modify) made to the material surface in the material library reflects immediately in the ragdoll bones -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/4925582 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976194_RigidBody_PhysXComponentIsValid.py b/AutomatedTesting/Gem/PythonTests/physics/C4976194_RigidBody_PhysXComponentIsValid.py index aa059eb224..8bb005711e 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976194_RigidBody_PhysXComponentIsValid.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976194_RigidBody_PhysXComponentIsValid.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976194 # Test Case Title : Verify that you can add PhysX Rigid Bodies Physics component to an Entity without any warning or Error. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976194 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976195_RigidBodies_InitialLinearVelocity.py b/AutomatedTesting/Gem/PythonTests/physics/C4976195_RigidBodies_InitialLinearVelocity.py index c5740b2798..3dbf26a0ac 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976195_RigidBodies_InitialLinearVelocity.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976195_RigidBodies_InitialLinearVelocity.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976195 # Test Case Title : Verify that when you assign an Initial Linear Velocity to an object, # ... it moves with that linear velocity when we switch to game mode. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976195 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976197_RigidBodies_InitialAngularVelocity.py b/AutomatedTesting/Gem/PythonTests/physics/C4976197_RigidBodies_InitialAngularVelocity.py index 08e171269e..7a17eb5941 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976197_RigidBodies_InitialAngularVelocity.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976197_RigidBodies_InitialAngularVelocity.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976197 # Test Case Title : Verify that when you assign an Initial Angular Velocity to an object, # it moves with that Angular velocity when we switch to game mode -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976197 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976199_RigidBodies_LinearDampingObjectMotion.py b/AutomatedTesting/Gem/PythonTests/physics/C4976199_RigidBodies_LinearDampingObjectMotion.py index 2e19b633c4..457cb18640 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976199_RigidBodies_LinearDampingObjectMotion.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976199_RigidBodies_LinearDampingObjectMotion.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976199 # Test Case Title : Verify that with higher linear damping, the object in motion comes to rest faster -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976199 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976200_RigidBody_AngularDampingObjectRotation.py b/AutomatedTesting/Gem/PythonTests/physics/C4976200_RigidBody_AngularDampingObjectRotation.py index b90b34be53..f423821757 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976200_RigidBody_AngularDampingObjectRotation.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976200_RigidBody_AngularDampingObjectRotation.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976200 # Test Case Title : Verify that with higher angular damping, the object in rotation comes to rest faster -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976200 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976201_RigidBody_MassIsAssigned.py b/AutomatedTesting/Gem/PythonTests/physics/C4976201_RigidBody_MassIsAssigned.py index 7fb0ff84ce..fd15cbbb0f 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976201_RigidBody_MassIsAssigned.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976201_RigidBody_MassIsAssigned.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976201 # Test Case Title : Verify that the value assigned to the Mass of the object, gets actually assigned to the object -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976201 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976202_RigidBody_StopsWhenBelowKineticThreshold.py b/AutomatedTesting/Gem/PythonTests/physics/C4976202_RigidBody_StopsWhenBelowKineticThreshold.py index 7d4cf1066e..c66f5cf7b6 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976202_RigidBody_StopsWhenBelowKineticThreshold.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976202_RigidBody_StopsWhenBelowKineticThreshold.py @@ -14,7 +14,7 @@ Test case ID : C4976202 Test Case Title : Verify that if the object is moving with Kinetic energy less than the sleep threshold value, then physX will put it to stop after 0.4 secs (once the wake counter goes to zero) if the KE is still below the threshold -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976202 + """ # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976204_Verify_Start_Asleep_Condition.py b/AutomatedTesting/Gem/PythonTests/physics/C4976204_Verify_Start_Asleep_Condition.py index 29fc2ec2a3..6b29062adf 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976204_Verify_Start_Asleep_Condition.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976204_Verify_Start_Asleep_Condition.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976204 # Test Case Title : Verify that when Start Asleep is checked, the object in air does not fall down due to # gravity or does not start moving with initial linear velocity assigned to it when switched to game mode -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976204 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976206_RigidBodies_GravityEnabledActive.py b/AutomatedTesting/Gem/PythonTests/physics/C4976206_RigidBodies_GravityEnabledActive.py index b97c590a93..934e546d65 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976206_RigidBodies_GravityEnabledActive.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976206_RigidBodies_GravityEnabledActive.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976206 # Test Case Title : VErify that when Gravity enables is checked, the object falls down due to gravity [sic] -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976206 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976207_PhysXRigidBodies_KinematicBehavior.py b/AutomatedTesting/Gem/PythonTests/physics/C4976207_PhysXRigidBodies_KinematicBehavior.py index 4481c00fc5..58193a1e9b 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976207_PhysXRigidBodies_KinematicBehavior.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976207_PhysXRigidBodies_KinematicBehavior.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976207 # Test Case Title : Verify that when Kinematic is checked, the object behaves as a Kinematic object -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976207 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976209_RigidBody_ComputesCOM.py b/AutomatedTesting/Gem/PythonTests/physics/C4976209_RigidBody_ComputesCOM.py index 79ea6e5dc7..600b20d98d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976209_RigidBody_ComputesCOM.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976209_RigidBody_ComputesCOM.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976209 # Test Case Title : Verify that when Compute COM is enabled, the PhysX system computes the COM of the object on its own -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976209 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976210_COM_ManualSetting.py b/AutomatedTesting/Gem/PythonTests/physics/C4976210_COM_ManualSetting.py index 451081ba23..c53fb3508d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976210_COM_ManualSetting.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976210_COM_ManualSetting.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976210 # Test Case Title : Verify that when Compute COM is disabled, the user gets an option to add the co-ordinates of # the COM and the COM gets implemented at those co-ordinates. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976210 + import os diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976218_RigidBodies_InertiaObjectsNotComputed.py b/AutomatedTesting/Gem/PythonTests/physics/C4976218_RigidBodies_InertiaObjectsNotComputed.py index 63f0d382c3..dada67548b 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976218_RigidBodies_InertiaObjectsNotComputed.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976218_RigidBodies_InertiaObjectsNotComputed.py @@ -9,7 +9,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ # Test case ID : C4976218 # Test Case Title: Verify that when compute inertia is checked, the physX engine does compute the inertia of the objects -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976218 + # fmt: off class Tests(): diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976227_Collider_NewGroup.py b/AutomatedTesting/Gem/PythonTests/physics/C4976227_Collider_NewGroup.py index 8d9dc01396..78c031870d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976227_Collider_NewGroup.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976227_Collider_NewGroup.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976227 # Test Case Title : Validate that a Collision Group can be added -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976227 + # Level has entity with custom collision group added. # If level enters game mode, collision group addition is validated. diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976236_AddPhysxColliderComponent.py b/AutomatedTesting/Gem/PythonTests/physics/C4976236_AddPhysxColliderComponent.py index 72442601e4..fdb862005f 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976236_AddPhysxColliderComponent.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976236_AddPhysxColliderComponent.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C4976236 Test Case Title : Verify that you can add the physX collider component to an entity without it throwing an error or warning -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976236 + """ # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976242_Collision_SameCollisionlayerSameCollisiongroup.py b/AutomatedTesting/Gem/PythonTests/physics/C4976242_Collision_SameCollisionlayerSameCollisiongroup.py index bb6234b69e..ac14164f45 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976242_Collision_SameCollisionlayerSameCollisiongroup.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976242_Collision_SameCollisionlayerSameCollisiongroup.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976242 # Test Case Title : Assign same collision layer and same collision group to two entities and # verify that they collide or not -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976242 + # fmt: off class Tests(): diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976243_Collision_SameCollisionGroupDiffCollisionLayers.py b/AutomatedTesting/Gem/PythonTests/physics/C4976243_Collision_SameCollisionGroupDiffCollisionLayers.py index 949ebb2b2a..44a8b15169 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976243_Collision_SameCollisionGroupDiffCollisionLayers.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976243_Collision_SameCollisionGroupDiffCollisionLayers.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976243 # Test Case Title : Assign different collision layers and same collision group # (such that this group has both these collision layers enabled) to two entities and verify that they collide -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976243 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976244_Collider_SameGroupSameLayerCollision.py b/AutomatedTesting/Gem/PythonTests/physics/C4976244_Collider_SameGroupSameLayerCollision.py index c35b9fab81..ca1e7f57f5 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976244_Collider_SameGroupSameLayerCollision.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976244_Collider_SameGroupSameLayerCollision.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976244 # Test Case Title : Checks that two entities of similar custom layer collide -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976244 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4976245_PhysXCollider_CollisionLayerTest.py b/AutomatedTesting/Gem/PythonTests/physics/C4976245_PhysXCollider_CollisionLayerTest.py index dafb8d9014..5f8c0a8d67 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4976245_PhysXCollider_CollisionLayerTest.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4976245_PhysXCollider_CollisionLayerTest.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4976245 # Test Case Title : Check that two entities of collision group "None" do not collide, # even though they have the same collision layer -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4976245 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982593_PhysXCollider_CollisionLayerTest.py b/AutomatedTesting/Gem/PythonTests/physics/C4982593_PhysXCollider_CollisionLayerTest.py index 8d985de402..126ebf48dc 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982593_PhysXCollider_CollisionLayerTest.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982593_PhysXCollider_CollisionLayerTest.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4982593 # Test Case Title : Check that two entities with different collision groups and layers do not collide. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4982593 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982595_Collider_TriggerDisablesCollision.py b/AutomatedTesting/Gem/PythonTests/physics/C4982595_Collider_TriggerDisablesCollision.py index 8746996ca8..c50c517086 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982595_Collider_TriggerDisablesCollision.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982595_Collider_TriggerDisablesCollision.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case ID : C4982595 # Test Case Title : Verify that when the Trigger Checkbox is ticked, the object no longer collides with another object # but simply passes through it -# Test Case URL : https://testrail.agscollab.com/index.php?/cases/view/4982595 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982797_Collider_ColliderOffset.py b/AutomatedTesting/Gem/PythonTests/physics/C4982797_Collider_ColliderOffset.py index 2bd4fc5adc..29a3b7f89d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982797_Collider_ColliderOffset.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982797_Collider_ColliderOffset.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4982797 # Test Case Title : Check that collision offsets trigger collision events, # not entity transform locations -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4982797 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982798_Collider_ColliderRotationOffset.py b/AutomatedTesting/Gem/PythonTests/physics/C4982798_Collider_ColliderRotationOffset.py index f86890d8bf..6276c81871 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982798_Collider_ColliderRotationOffset.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982798_Collider_ColliderRotationOffset.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C4982798 # Test Case Title : Verify that when the x,y,z values are defined in the offset, the collider frame # rotates from its original orientation in the direction defined by the x,y,z units -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4982798 + import os diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982800_PhysXColliderShape_CanBeSelected.py b/AutomatedTesting/Gem/PythonTests/physics/C4982800_PhysXColliderShape_CanBeSelected.py index c37ad2b2d2..1822a1efa7 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982800_PhysXColliderShape_CanBeSelected.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982800_PhysXColliderShape_CanBeSelected.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C4982800 Test Case Title : Verify that the shape Sphere can be selected from the drop downlist and the value for its radius can be set -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4982800 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982801_PhysXColliderShape_CanBeSelected.py b/AutomatedTesting/Gem/PythonTests/physics/C4982801_PhysXColliderShape_CanBeSelected.py index 19a835da18..ef9b8171c4 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982801_PhysXColliderShape_CanBeSelected.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982801_PhysXColliderShape_CanBeSelected.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C4982801 Test Case Title : Verify that the shape Box can be selected from drop downlist and the value for its dimensions in x,y,z can be set after that -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4982801 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982802_PhysXColliderShape_CanBeSelected.py b/AutomatedTesting/Gem/PythonTests/physics/C4982802_PhysXColliderShape_CanBeSelected.py index e1365d0887..642dea48de 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982802_PhysXColliderShape_CanBeSelected.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982802_PhysXColliderShape_CanBeSelected.py @@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C4982802 Test Case Title : Verify that the shape capsule can be selected from drop downlist and the value for its height and radius can be set after that -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4982802 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C4982803_Enable_PxMesh_Option.py b/AutomatedTesting/Gem/PythonTests/physics/C4982803_Enable_PxMesh_Option.py index 4ae177934a..99e93c26c9 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C4982803_Enable_PxMesh_Option.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C4982803_Enable_PxMesh_Option.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Test case ID : C4982803 Test Case Title : Verify that when the shape Physics Asset is selected, PxMesh option gets enabled and a Px Mesh can be selected and assigned to the object -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/4982803 + """ # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5296614_PhysXMaterial_ColliderShape.py b/AutomatedTesting/Gem/PythonTests/physics/C5296614_PhysXMaterial_ColliderShape.py index 9d2a49ac70..b4af6ab506 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5296614_PhysXMaterial_ColliderShape.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5296614_PhysXMaterial_ColliderShape.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5296614 # Test Case Title : Check that unless you assign a shape to a physX collider component, # the material assigned to it does not take affect -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5296614 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5340400_RigidBody_ManualMomentOfInertia.py b/AutomatedTesting/Gem/PythonTests/physics/C5340400_RigidBody_ManualMomentOfInertia.py index 7617e41cad..838007436c 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5340400_RigidBody_ManualMomentOfInertia.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5340400_RigidBody_ManualMomentOfInertia.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5340400 # Test Case Title : Verify that when Compute inertia is disabled, the user gets to set the moment of inertia # and physX engine work accordingly -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5340400 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5689518_PhysXTerrain_CollidesWithPhysXTerrain.py b/AutomatedTesting/Gem/PythonTests/physics/C5689518_PhysXTerrain_CollidesWithPhysXTerrain.py index 0686adf15d..f17bf2492f 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5689518_PhysXTerrain_CollidesWithPhysXTerrain.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5689518_PhysXTerrain_CollidesWithPhysXTerrain.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5689518 # Test Case Title : PhysX entities collide with PhysX Terrain -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5689518 + # A ball is suspended slightly over PhysX Terrain to check that it collides when dropped diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5689522_Physxterrain_AddPhysxterrainNoEditorCrash.py b/AutomatedTesting/Gem/PythonTests/physics/C5689522_Physxterrain_AddPhysxterrainNoEditorCrash.py index ffafeaab34..61ef63c4ae 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5689522_Physxterrain_AddPhysxterrainNoEditorCrash.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5689522_Physxterrain_AddPhysxterrainNoEditorCrash.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5689522 # Test Case Title : Create an entity with PhysX terrain. Add another PhysX terrain and verify that # you are able to add it without any crash or error. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5689522 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5689524_MultipleTerrains_CheckWarningInConsole.py b/AutomatedTesting/Gem/PythonTests/physics/C5689524_MultipleTerrains_CheckWarningInConsole.py index 2b1a73f1f3..c395507ea0 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5689524_MultipleTerrains_CheckWarningInConsole.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5689524_MultipleTerrains_CheckWarningInConsole.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5689524 # Test Case Title : Create multiple entities each with one or more terrain components and verify that you are # able to successfully add the PhysX Terrain components to them. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5689524 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5689528_Terrain_MultipleTerrainComponents.py b/AutomatedTesting/Gem/PythonTests/physics/C5689528_Terrain_MultipleTerrainComponents.py index 265836489d..12f3955bf6 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5689528_Terrain_MultipleTerrainComponents.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5689528_Terrain_MultipleTerrainComponents.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5689528 # Test Case Title : Create multiple entities each with one PhysX terrain component and verify that a warning # is thrown to the user -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5689528 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5689529_Verify_Terrain_RigidBody_Collider_Mesh.py b/AutomatedTesting/Gem/PythonTests/physics/C5689529_Verify_Terrain_RigidBody_Collider_Mesh.py index 138ae68408..c5342d7421 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5689529_Verify_Terrain_RigidBody_Collider_Mesh.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5689529_Verify_Terrain_RigidBody_Collider_Mesh.py @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test Case Title : Create an entity with PhysX Terrain component and add # PhysX Rigid Body PhysX, PhysX Collider and Rendering Mesh to it and # verify that it works in game mode -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5689529 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5689531_Warning_TerrainSliceTerrainComponent.py b/AutomatedTesting/Gem/PythonTests/physics/C5689531_Warning_TerrainSliceTerrainComponent.py index 7d60a61ec1..85a9037a36 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5689531_Warning_TerrainSliceTerrainComponent.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5689531_Warning_TerrainSliceTerrainComponent.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5689531 # Test Case Title : Check that when you add a spawner component to a level to spawn a # terrain and also add a terrain component explicitly, no crash happens -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5689531 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5932040_ForceRegion_CubeExertsWorldForce.py b/AutomatedTesting/Gem/PythonTests/physics/C5932040_ForceRegion_CubeExertsWorldForce.py index f01dd4582f..b1f9f8f934 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5932040_ForceRegion_CubeExertsWorldForce.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5932040_ForceRegion_CubeExertsWorldForce.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5932040 # Test Case Title : Check that force region exerts world space force on rigid bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5932040 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies.py b/AutomatedTesting/Gem/PythonTests/physics/C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies.py index 095a669541..5fc07fdc67 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5932041 # Test Case Title : Check that force region exerts local space force on rigid bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5932041 + # Sphere drops and is acted upon in an upward and positive x-ward direction by a force # with a magnitude close to the assigned force region magnitude when it reaches the force region. diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5932042_PhysXForceRegion_LinearDamping.py b/AutomatedTesting/Gem/PythonTests/physics/C5932042_PhysXForceRegion_LinearDamping.py index 04cecd45b2..b55ce59d7a 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5932042_PhysXForceRegion_LinearDamping.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5932042_PhysXForceRegion_LinearDamping.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5932042 # Test Case Title : Check that force region exerts linear damping force on rigid bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5932042 + # fmt: off @@ -135,7 +135,7 @@ def C5932042_PhysXForceRegion_LinearDamping(): # Constants CLOSE_ENOUGH = 0.001 - TIME_OUT = 2.0 + TIME_OUT = 3.0 INITIAL_VELOCITY = azmath.Vector3(0.0, 0.0, -10.0) # 1) Open level / Enter game mode diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5932043_ForceRegion_SimpleDragOnRigidBodies.py b/AutomatedTesting/Gem/PythonTests/physics/C5932043_ForceRegion_SimpleDragOnRigidBodies.py index 512698ce4b..b4d29f8065 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5932043_ForceRegion_SimpleDragOnRigidBodies.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5932043_ForceRegion_SimpleDragOnRigidBodies.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5932043 # Test Case Title : Check that force region exerts simple drag force on rigid bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5932043 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5932044_ForceRegion_PointForceOnRigidBody.py b/AutomatedTesting/Gem/PythonTests/physics/C5932044_ForceRegion_PointForceOnRigidBody.py index b7257b488b..6cfaf857a4 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5932044_ForceRegion_PointForceOnRigidBody.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5932044_ForceRegion_PointForceOnRigidBody.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5932044 # Test Case Title : Check that force region exerts point force on rigid bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5932044 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5932045_ForceRegion_Spline.py b/AutomatedTesting/Gem/PythonTests/physics/C5932045_ForceRegion_Spline.py index eca0679921..298265966c 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5932045_ForceRegion_Spline.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5932045_ForceRegion_Spline.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5932045 # Test Case Title : Check that force region exerts spline follow force on rigid bodies -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5932045 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959759_RigidBody_ForceRegionSpherePointForce.py b/AutomatedTesting/Gem/PythonTests/physics/C5959759_RigidBody_ForceRegionSpherePointForce.py index 6aff0a7145..a8ef614f75 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959759_RigidBody_ForceRegionSpherePointForce.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959759_RigidBody_ForceRegionSpherePointForce.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959759 # Test Case Title : Check that force region (sphere) exerts point force -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959759 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959760_PhysXForceRegion_PointForceExertion.py b/AutomatedTesting/Gem/PythonTests/physics/C5959760_PhysXForceRegion_PointForceExertion.py index 89eb1842be..4cb1cffd16 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959760_PhysXForceRegion_PointForceExertion.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959760_PhysXForceRegion_PointForceExertion.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959760 # Test Case Title : Check that force region (capsule) exerts point force -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959760 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959761_ForceRegion_PhysAssetExertsPointForce.py b/AutomatedTesting/Gem/PythonTests/physics/C5959761_ForceRegion_PhysAssetExertsPointForce.py index ba0475266b..27f9e41a7d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959761_ForceRegion_PhysAssetExertsPointForce.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959761_ForceRegion_PhysAssetExertsPointForce.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959761 # Test Case Title : Check that force region (physics asset) exerts point force -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959761 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959763_ForceRegion_ForceRegionImpulsesCube.py b/AutomatedTesting/Gem/PythonTests/physics/C5959763_ForceRegion_ForceRegionImpulsesCube.py index 76130d25eb..4b62f9a029 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959763_ForceRegion_ForceRegionImpulsesCube.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959763_ForceRegion_ForceRegionImpulsesCube.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959764 # Test Case Title : Check that rigid body (Cube) gets impulse from force region -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959764 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959764_ForceRegion_ForceRegionImpulsesCapsule.py b/AutomatedTesting/Gem/PythonTests/physics/C5959764_ForceRegion_ForceRegionImpulsesCapsule.py index f314dae5b7..aadc07b09b 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959764_ForceRegion_ForceRegionImpulsesCapsule.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959764_ForceRegion_ForceRegionImpulsesCapsule.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959764 # Test Case Title : Check that rigid body (Capsule) gets impulse from force region -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959764 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959765_ForceRegion_AssetGetsImpulsed.py b/AutomatedTesting/Gem/PythonTests/physics/C5959765_ForceRegion_AssetGetsImpulsed.py index ddcba5996b..ed007594c2 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959765_ForceRegion_AssetGetsImpulsed.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959765_ForceRegion_AssetGetsImpulsed.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959765 # Test Case Title : Check that rigid body (asset) gets impulse from force region -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959765 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959808_ForceRegion_PositionOffset.py b/AutomatedTesting/Gem/PythonTests/physics/C5959808_ForceRegion_PositionOffset.py index 175f73a420..7c3f8a43aa 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959808_ForceRegion_PositionOffset.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959808_ForceRegion_PositionOffset.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959808 # Test Case Title : Verify Force Region Position Offset -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959808 + # fmt:off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959809_ForceRegion_RotationalOffset.py b/AutomatedTesting/Gem/PythonTests/physics/C5959809_ForceRegion_RotationalOffset.py index 1ad53194d3..dc84be8798 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959809_ForceRegion_RotationalOffset.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959809_ForceRegion_RotationalOffset.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959809 # Test Case Title : Verify Force Region Rotational Offset -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959809 + # fmt:off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5959810_ForceRegion_ForceRegionCombinesForces.py b/AutomatedTesting/Gem/PythonTests/physics/C5959810_ForceRegion_ForceRegionCombinesForces.py index 212f7cc86b..8efc3dc635 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5959810_ForceRegion_ForceRegionCombinesForces.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5959810_ForceRegion_ForceRegionCombinesForces.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5959810 # Test Case Title : Check that multiple forces in single force region create correct net force -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5959810 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5968759_ForceRegion_ExertsSeveralForcesOnRigidBody.py b/AutomatedTesting/Gem/PythonTests/physics/C5968759_ForceRegion_ExertsSeveralForcesOnRigidBody.py index 4aa0fef642..948e172962 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5968759_ForceRegion_ExertsSeveralForcesOnRigidBody.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5968759_ForceRegion_ExertsSeveralForcesOnRigidBody.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5968759 # Test Case Title : Check nested force regions exert forces simultaneously on rigid body -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5968759 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C5968760_ForceRegion_CheckNetForceChange.py b/AutomatedTesting/Gem/PythonTests/physics/C5968760_ForceRegion_CheckNetForceChange.py index ba491c96a7..0897fcb0d7 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C5968760_ForceRegion_CheckNetForceChange.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C5968760_ForceRegion_CheckNetForceChange.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C5968760 # Test Case Title : Check moving force region changes net force -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/5968760 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6032082_Terrain_MultipleResolutionsValid.py b/AutomatedTesting/Gem/PythonTests/physics/C6032082_Terrain_MultipleResolutionsValid.py index 4543b0b8f6..00d53a2d6c 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6032082_Terrain_MultipleResolutionsValid.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6032082_Terrain_MultipleResolutionsValid.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6032082 # Test Case Title : Verify multiple terrain resolutions are supported -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6032082 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090546_ForceRegion_SliceFileInstantiates.py b/AutomatedTesting/Gem/PythonTests/physics/C6090546_ForceRegion_SliceFileInstantiates.py index 557b7e7ec5..2b427468b7 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090546_ForceRegion_SliceFileInstantiates.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090546_ForceRegion_SliceFileInstantiates.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6090546 # Test Case Title : Check that a force region slice can be saved and instantiated -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090546 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090547_ForceRegion_ParentChildForceRegions.py b/AutomatedTesting/Gem/PythonTests/physics/C6090547_ForceRegion_ParentChildForceRegions.py index a07fd1861b..84474f0226 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090547_ForceRegion_ParentChildForceRegions.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090547_ForceRegion_ParentChildForceRegions.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6090547 # Test Case Title : Check that force regions in parent and child entities work together. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090547 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090550_ForceRegion_WorldSpaceForceNegative.py b/AutomatedTesting/Gem/PythonTests/physics/C6090550_ForceRegion_WorldSpaceForceNegative.py index f8da62ebac..e2c55a024d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090550_ForceRegion_WorldSpaceForceNegative.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090550_ForceRegion_WorldSpaceForceNegative.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ Test case ID : C6090550 Test Case Title : Check that force region exerts world space force on rigid bodies (negative test) -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090550 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090551_ForceRegion_LocalSpaceForceNegative.py b/AutomatedTesting/Gem/PythonTests/physics/C6090551_ForceRegion_LocalSpaceForceNegative.py index 0788b1da66..2e201e20bd 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090551_ForceRegion_LocalSpaceForceNegative.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090551_ForceRegion_LocalSpaceForceNegative.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ Test case ID : C6090551 Test Case Title : Check that force region exerts local space force on rigid bodies (negative test) -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090551 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090552_ForceRegion_LinearDampingNegative.py b/AutomatedTesting/Gem/PythonTests/physics/C6090552_ForceRegion_LinearDampingNegative.py index a878819045..585a337389 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090552_ForceRegion_LinearDampingNegative.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090552_ForceRegion_LinearDampingNegative.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ Test case ID : C6090552 Test Case Title : Check that force region exerts linear damping force on rigid bodies (negative test) -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090552 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090553_ForceRegion_SimpleDragForceOnRigidBodies.py b/AutomatedTesting/Gem/PythonTests/physics/C6090553_ForceRegion_SimpleDragForceOnRigidBodies.py index 43c4335918..6abee0ad64 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090553_ForceRegion_SimpleDragForceOnRigidBodies.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090553_ForceRegion_SimpleDragForceOnRigidBodies.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6090553 # Test Case Title : Check that force region exerts simple drag force on rigid bodies (negative test) -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090553 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090554_ForceRegion_PointForceNegative.py b/AutomatedTesting/Gem/PythonTests/physics/C6090554_ForceRegion_PointForceNegative.py index d7781b6040..0969cebd8d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090554_ForceRegion_PointForceNegative.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090554_ForceRegion_PointForceNegative.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ Test case ID : C6090554 Test Case Title : Check that force region exerts point force on rigid bodies (negative test) -URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090554 + """ diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6090555_ForceRegion_SplineFollowOnRigidBodies.py b/AutomatedTesting/Gem/PythonTests/physics/C6090555_ForceRegion_SplineFollowOnRigidBodies.py index b1b76d896d..90f67391ad 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6090555_ForceRegion_SplineFollowOnRigidBodies.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6090555_ForceRegion_SplineFollowOnRigidBodies.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6090555 # Test Case Title : Check that force region exerts spline follow force on rigid bodies(negative test) -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6090555 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6131473_StaticSlice_OnDynamicSliceSpawn.py b/AutomatedTesting/Gem/PythonTests/physics/C6131473_StaticSlice_OnDynamicSliceSpawn.py index 11281df4eb..ee68ef6049 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6131473_StaticSlice_OnDynamicSliceSpawn.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6131473_StaticSlice_OnDynamicSliceSpawn.py @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6131473 # Test Case Title : Verify a static slice is not spawned automatically everytime a dynamic slice with # PhysX Components is spawned -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6131473 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6224408_ScriptCanvas_EntitySpawn.py b/AutomatedTesting/Gem/PythonTests/physics/C6224408_ScriptCanvas_EntitySpawn.py index 6501e11e68..6693c17dff 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6224408_ScriptCanvas_EntitySpawn.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6224408_ScriptCanvas_EntitySpawn.py @@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6224408 # Test Case Title : Entity using PhysX nodes in Script Canvas can be spawned. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6224408 + # fmt: off class Tests: diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6274125_ScriptCanvas_TriggerEvents.py b/AutomatedTesting/Gem/PythonTests/physics/C6274125_ScriptCanvas_TriggerEvents.py index 44c8be9e1e..c360473b7f 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6274125_ScriptCanvas_TriggerEvents.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6274125_ScriptCanvas_TriggerEvents.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6274125 # Test Case Title : Verify ScriptCanvas Trigger Events. -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6274125 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/C6321601_Force_HighValuesDirectionAxes.py b/AutomatedTesting/Gem/PythonTests/physics/C6321601_Force_HighValuesDirectionAxes.py index c1a51f2887..4b0b036970 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/C6321601_Force_HighValuesDirectionAxes.py +++ b/AutomatedTesting/Gem/PythonTests/physics/C6321601_Force_HighValuesDirectionAxes.py @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # Test case ID : C6321601 # Test Case Title : Check that very high values of direction axes of forces do not throw error -# URL of the test case : https://testrail.agscollab.com/index.php?/cases/view/6321601 + # fmt: off diff --git a/AutomatedTesting/Gem/PythonTests/physics/JointsHelper.py b/AutomatedTesting/Gem/PythonTests/physics/JointsHelper.py index e61118ef5b..476c1df237 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/JointsHelper.py +++ b/AutomatedTesting/Gem/PythonTests/physics/JointsHelper.py @@ -27,6 +27,13 @@ def vector3LargerThanScalar(vec3Value, scalarValue): vec3Value.y > scalarValue and vec3Value.z > scalarValue) +def getRelativeVector(vecA, vecB): + relativeVec = vecA + relativeVec.x = relativeVec.x - vecB.x + relativeVec.y = relativeVec.y - vecB.y + relativeVec.z = relativeVec.z - vecB.z + return relativeVec + # Entity class for joints tests class JointEntity: diff --git a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Main.py b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Main.py index 67e855a00e..8f1f2f7481 100644 --- a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Main.py +++ b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Main.py @@ -34,4 +34,61 @@ class TestAutomation(TestAutomationBase): def test_C111111_RigidBody_EnablingGravityWorksUsingNotificationsPoC(self, request, workspace, editor, launcher_platform): from . import C111111_RigidBody_EnablingGravityWorksUsingNotificationsPoC as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies(self, request, workspace, editor, launcher_platform): + from . import C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C4044459_Material_DynamicFriction(self, request, workspace, editor, launcher_platform): + from . import C4044459_Material_DynamicFriction as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C15425929_Undo_Redo(self, request, workspace, editor, launcher_platform): + from . import C15425929_Undo_Redo as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C4976243_Collision_SameCollisionGroupDiffCollisionLayers(self, request, workspace, editor, + launcher_platform): + from . import C4976243_Collision_SameCollisionGroupDiffCollisionLayers as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C14654881_CharacterController_SwitchLevels(self, request, workspace, editor, launcher_platform): + from . import C14654881_CharacterController_SwitchLevels as test_module + self._run_test(request, workspace, editor, test_module) + + def test_C17411467_AddPhysxRagdollComponent(self, request, workspace, editor, launcher_platform): + from . import C17411467_AddPhysxRagdollComponent as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C12712453_ScriptCanvas_MultipleRaycastNode(self, request, workspace, editor, launcher_platform): + from . import C12712453_ScriptCanvas_MultipleRaycastNode as test_module + # Fixme: unexpected_lines = ["Assert"] + test_module.Lines.unexpected + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + @fm.file_override('physxsystemconfiguration.setreg','C4982593_PhysXCollider_CollisionLayer.setreg_override', 'AutomatedTesting/Registry') + def test_C4982593_PhysXCollider_CollisionLayerTest(self, request, workspace, editor, launcher_platform): + from . import C4982593_PhysXCollider_CollisionLayerTest as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C18243586_Joints_HingeLeadFollowerCollide(self, request, workspace, editor, launcher_platform): + from . import C18243586_Joints_HingeLeadFollowerCollide as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C4982803_Enable_PxMesh_Option(self, request, workspace, editor, launcher_platform): + from . import C4982803_Enable_PxMesh_Option as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain(self, request, workspace, editor, launcher_platform): + from . import C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain as test_module self._run_test(request, workspace, editor, test_module) \ No newline at end of file diff --git a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py index 39ed85a65a..3bbfe64e38 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py +++ b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py @@ -52,11 +52,6 @@ class TestAutomation(TestAutomationBase): from . import C4976207_PhysXRigidBodies_KinematicBehavior as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies(self, request, workspace, editor, launcher_platform): - from . import C5932041_PhysXForceRegion_LocalSpaceForceOnRigidBodies as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C5932042_PhysXForceRegion_LinearDamping(self, request, workspace, editor, launcher_platform): from . import C5932042_PhysXForceRegion_LinearDamping as test_module @@ -92,11 +87,6 @@ class TestAutomation(TestAutomationBase): from . import C4976194_RigidBody_PhysXComponentIsValid as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C4044459_Material_DynamicFriction(self, request, workspace, editor, launcher_platform): - from . import C4044459_Material_DynamicFriction as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C5932045_ForceRegion_Spline(self, request, workspace, editor, launcher_platform): from . import C5932045_ForceRegion_Spline as test_module @@ -208,26 +198,11 @@ class TestAutomation(TestAutomationBase): from . import C18981526_Material_RestitutionCombinePriority as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C15425929_Undo_Redo(self, request, workspace, editor, launcher_platform): - from . import C15425929_Undo_Redo as test_module - self._run_test(request, workspace, editor, test_module) - - @revert_physics_config - def test_C15308217_NoCrash_LevelSwitch(self, request, workspace, editor, launcher_platform): - from . import C15308217_NoCrash_LevelSwitch as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C12868580_ForceRegion_SplineModifiedTransform(self, request, workspace, editor, launcher_platform): from . import C12868580_ForceRegion_SplineModifiedTransform as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C4976243_Collision_SameCollisionGroupDiffCollisionLayers(self, request, workspace, editor, launcher_platform): - from . import C4976243_Collision_SameCollisionGroupDiffCollisionLayers as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C12712455_ScriptCanvas_ShapeCastVerification(self, request, workspace, editor, launcher_platform): from . import C12712455_ScriptCanvas_ShapeCastVerification as test_module @@ -248,17 +223,6 @@ class TestAutomation(TestAutomationBase): from . import C6131473_StaticSlice_OnDynamicSliceSpawn as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C4982798_Collider_ColliderRotationOffset(self, request, workspace, editor, launcher_platform): - from . import C4982798_Collider_ColliderRotationOffset as test_module - self._run_test(request, workspace, editor, test_module) - - @revert_physics_config - def test_C12712453_ScriptCanvas_MultipleRaycastNode(self, request, workspace, editor, launcher_platform): - from . import C12712453_ScriptCanvas_MultipleRaycastNode as test_module - # Fixme: unexpected_lines = ["Assert"] + test_module.Lines.unexpected - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C5959808_ForceRegion_PositionOffset(self, request, workspace, editor, launcher_platform): from . import C5959808_ForceRegion_PositionOffset as test_module @@ -275,7 +239,7 @@ class TestAutomation(TestAutomationBase): def test_C13895144_Ragdoll_ChangeLevel(self, request, workspace, editor, launcher_platform): from . import C13895144_Ragdoll_ChangeLevel as test_module self._run_test(request, workspace, editor, test_module) - + @revert_physics_config def test_C5968759_ForceRegion_ExertsSeveralForcesOnRigidBody(self, request, workspace, editor, launcher_platform): from . import C5968759_ForceRegion_ExertsSeveralForcesOnRigidBody as test_module @@ -290,6 +254,8 @@ class TestAutomation(TestAutomationBase): from . import C4044697_Material_PerfaceMaterialValidation as test_module self._run_test(request, workspace, editor, test_module) + @pytest.mark.xfail( + reason="This test will sometimes fail as the ball will continue to roll before the timeout is reached.") @revert_physics_config def test_C4976202_RigidBody_StopsWhenBelowKineticThreshold(self, request, workspace, editor, launcher_platform): from . import C4976202_RigidBody_StopsWhenBelowKineticThreshold as test_module @@ -305,11 +271,6 @@ class TestAutomation(TestAutomationBase): from . import C5296614_PhysXMaterial_ColliderShape as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C6090547_ForceRegion_ParentChildForceRegions(self, request, workspace, editor, launcher_platform): - from . import C6090547_ForceRegion_ParentChildForceRegions as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C4982595_Collider_TriggerDisablesCollision(self, request, workspace, editor, launcher_platform): from . import C4982595_Collider_TriggerDisablesCollision as test_module @@ -320,11 +281,6 @@ class TestAutomation(TestAutomationBase): from . import C14976307_Gravity_SetGravityWorks as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C14654881_CharacterController_SwitchLevels(self, request, workspace, editor, launcher_platform): - from . import C14654881_CharacterController_SwitchLevels as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C15556261_PhysXMaterials_CharacterControllerMaterialAssignment(self, request, workspace, editor, launcher_platform): from . import C15556261_PhysXMaterials_CharacterControllerMaterialAssignment as test_module @@ -352,19 +308,19 @@ class TestAutomation(TestAutomationBase): self._run_test(request, workspace, editor, test_module) @revert_physics_config - @fm.file_override('physxsystemconfiguration.setreg','C4976245_PhysXCollider_CollisionLayerTest.setreg', 'AutomatedTesting/Registry') + @fm.file_override('physxsystemconfiguration.setreg','C4976245_PhysXCollider_CollisionLayerTest.setreg_override', 'AutomatedTesting/Registry') def test_C4976245_PhysXCollider_CollisionLayerTest(self, request, workspace, editor, launcher_platform): from . import C4976245_PhysXCollider_CollisionLayerTest as test_module self._run_test(request, workspace, editor, test_module) @revert_physics_config - @fm.file_override('physxsystemconfiguration.setreg','C4976244_Collider_SameGroupSameLayerCollision.setreg', 'AutomatedTesting/Registry') + @fm.file_override('physxsystemconfiguration.setreg','C4976244_Collider_SameGroupSameLayerCollision.setreg_override', 'AutomatedTesting/Registry') def test_C4976244_Collider_SameGroupSameLayerCollision(self, request, workspace, editor, launcher_platform): from . import C4976244_Collider_SameGroupSameLayerCollision as test_module self._run_test(request, workspace, editor, test_module) @revert_physics_config - @fm.file_override('physxdefaultsceneconfiguration.setreg','C14195074_ScriptCanvas_PostUpdateEvent.setreg', 'AutomatedTesting/Registry') + @fm.file_override('physxdefaultsceneconfiguration.setreg','C14195074_ScriptCanvas_PostUpdateEvent.setreg_override', 'AutomatedTesting/Registry') def test_C14195074_ScriptCanvas_PostUpdateEvent(self, request, workspace, editor, launcher_platform): from . import C14195074_ScriptCanvas_PostUpdateEvent as test_module self._run_test(request, workspace, editor, test_module) @@ -375,19 +331,7 @@ class TestAutomation(TestAutomationBase): self._run_test(request, workspace, editor, test_module) @revert_physics_config - @fm.file_override('physxsystemconfiguration.setreg','C4982593_PhysXCollider_CollisionLayer.setreg', 'AutomatedTesting/Registry') - def test_C4982593_PhysXCollider_CollisionLayerTest(self, request, workspace, editor, launcher_platform): - from . import C4982593_PhysXCollider_CollisionLayerTest as test_module - self._run_test(request, workspace, editor, test_module) - - @revert_physics_config - @fm.file_override('physxsystemconfiguration.setreg','C3510644_Collider_CollisionGroups.setreg', 'AutomatedTesting/Registry') - def test_C3510644_Collider_CollisionGroups(self, request, workspace, editor, launcher_platform): - from . import C3510644_Collider_CollisionGroups as test_module - self._run_test(request, workspace, editor, test_module) - - @revert_physics_config - @fm.file_override('physxdefaultsceneconfiguration.setreg','C14902097_ScriptCanvas_PreUpdateEvent.setreg', 'AutomatedTesting/Registry') + @fm.file_override('physxdefaultsceneconfiguration.setreg','C14902097_ScriptCanvas_PreUpdateEvent.setreg_override', 'AutomatedTesting/Registry') def test_C14902097_ScriptCanvas_PreUpdateEvent(self, request, workspace, editor, launcher_platform): from . import C14902097_ScriptCanvas_PreUpdateEvent as test_module self._run_test(request, workspace, editor, test_module) @@ -415,18 +359,13 @@ class TestAutomation(TestAutomationBase): from . import C18243589_Joints_BallSoftLimitsConstrained as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C18243586_Joints_HingeLeadFollowerCollide(self, request, workspace, editor, launcher_platform): - from . import C18243586_Joints_HingeLeadFollowerCollide as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C18243591_Joints_BallLeadFollowerCollide(self, request, workspace, editor, launcher_platform): from . import C18243591_Joints_BallLeadFollowerCollide as test_module self._run_test(request, workspace, editor, test_module) @revert_physics_config - @fm.file_override('physxsystemconfiguration.setreg','C4976227_Collider_NewGroup.setreg', 'AutomatedTesting/Registry') + @fm.file_override('physxsystemconfiguration.setreg','C4976227_Collider_NewGroup.setreg_override', 'AutomatedTesting/Registry') def test_C4976227_Collider_NewGroup(self, request, workspace, editor, launcher_platform): from . import C4976227_Collider_NewGroup as test_module self._run_test(request, workspace, editor, test_module) @@ -441,21 +380,11 @@ class TestAutomation(TestAutomationBase): from . import C14861500_DefaultSetting_ColliderShape as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C19578021_ShapeCollider_CanBeAdded(self, request, workspace, editor, launcher_platform): - from . import C19578021_ShapeCollider_CanBeAdded as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C19723164_ShapeCollider_WontCrashEditor(self, request, workspace, editor, launcher_platform): from . import C19723164_ShapeColliders_WontCrashEditor as test_module self._run_test(request, workspace, editor, test_module) - @revert_physics_config - def test_C4982803_Enable_PxMesh_Option(self, request, workspace, editor, launcher_platform): - from . import C4982803_Enable_PxMesh_Option as test_module - self._run_test(request, workspace, editor, test_module) - @revert_physics_config def test_C4982800_PhysXColliderShape_CanBeSelected(self, request, workspace, editor, launcher_platform): from . import C4982800_PhysXColliderShape_CanBeSelected as test_module @@ -471,10 +400,6 @@ class TestAutomation(TestAutomationBase): from . import C4982802_PhysXColliderShape_CanBeSelected as test_module self._run_test(request, workspace, editor, test_module) - def test_C17411467_AddPhysxRagdollComponent(self, request, workspace, editor, launcher_platform): - from . import C17411467_AddPhysxRagdollComponent as test_module - self._run_test(request, workspace, editor, test_module) - def test_C12905528_ForceRegion_WithNonTriggerCollider(self, request, workspace, editor, launcher_platform): from . import C12905528_ForceRegion_WithNonTriggerCollider as test_module # Fixme: expected_lines = ["[Warning] (PhysX Force Region) - Please ensure collider component marked as trigger exists in entity"] @@ -522,4 +447,35 @@ class TestAutomation(TestAutomationBase): def test_C100000_RigidBody_EnablingGravityWorksPoC(self, request, workspace, editor, launcher_platform): from . import C100000_RigidBody_EnablingGravityWorksPoC as test_module - self._run_test(request, workspace, editor, test_module) \ No newline at end of file + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + @fm.file_override('physxsystemconfiguration.setreg','C3510644_Collider_CollisionGroups.setreg_override', 'AutomatedTesting/Registry') + def test_C3510644_Collider_CollisionGroups(self, request, workspace, editor, launcher_platform): + from . import C3510644_Collider_CollisionGroups as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C4982798_Collider_ColliderRotationOffset(self, request, workspace, editor, launcher_platform): + from . import C4982798_Collider_ColliderRotationOffset as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C15308217_NoCrash_LevelSwitch(self, request, workspace, editor, launcher_platform): + from . import C15308217_NoCrash_LevelSwitch as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C6090547_ForceRegion_ParentChildForceRegions(self, request, workspace, editor, launcher_platform): + from . import C6090547_ForceRegion_ParentChildForceRegions as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C19578021_ShapeCollider_CanBeAdded(self, request, workspace, editor, launcher_platform): + from . import C19578021_ShapeCollider_CanBeAdded as test_module + self._run_test(request, workspace, editor, test_module) + + @revert_physics_config + def test_C15425929_Undo_Redo(self, request, workspace, editor, launcher_platform): + from . import C15425929_Undo_Redo as test_module + self._run_test(request, workspace, editor, test_module) diff --git a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Sandbox.py b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Sandbox.py index 39bc4c8188..e829726ba9 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Sandbox.py +++ b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Sandbox.py @@ -1,49 +1,49 @@ -""" -All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -its licensors. - -For complete copyright and license terms please see the LICENSE at the root of this -distribution (the "License"). All use of this software is governed by the License, -or, if provided, by the license below or the license accompanying this file. Do not -remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - -""" - -# This suite consists of all test cases that are passing and have been verified. - -import pytest -import os -import sys - -from .FileManagement import FileManagement as fm -from ly_test_tools import LAUNCHERS - -sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../automatedtesting_shared') - -from base import TestAutomationBase - - -revert_physics_config = fm.file_revert_list(['physxdebugconfiguration.setreg', 'physxdefaultsceneconfiguration.setreg', 'physxsystemconfiguration.setreg'], 'AutomatedTesting/Registry') - - -@pytest.mark.SUITE_sandbox -@pytest.mark.parametrize("launcher_platform", ['windows_editor']) -@pytest.mark.parametrize("project", ["AutomatedTesting"]) -class TestAutomation(TestAutomationBase): - - ## Seems to be flaky, need to investigate - def test_C19536274_GetCollisionName_PrintsName(self, request, workspace, editor, launcher_platform): - from . import C19536274_GetCollisionName_PrintsName as test_module - # Fixme: expected_lines=["Layer Name: Right"] - self._run_test(request, workspace, editor, test_module) - - ## Seems to be flaky, need to investigate - def test_C19536277_GetCollisionName_PrintsNothing(self, request, workspace, editor, launcher_platform): - from . import C19536277_GetCollisionName_PrintsNothing as test_module - # All groups present in the PhysX Collider that could show up in test - # Fixme: collision_groups = ["All", "None", "All_NoTouchBend", "All_3", "None_1", "All_NoTouchBend_1", "All_2", "None_1_1", "All_NoTouchBend_1_1", "All_1", "None_1_1_1", "All_NoTouchBend_1_1_1", "All_4", "None_1_1_1_1", "All_NoTouchBend_1_1_1_1", "GroupLeft", "GroupRight"] - # Fixme: for group in collision_groups: - # Fixme: unexpected_lines.append(f"GroupName: {group}") - # Fixme: expected_lines=["GroupName: "] - self._run_test(request, workspace, editor, test_module) \ No newline at end of file +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +""" + +# This suite consists of all test cases that are passing and have been verified. + +import pytest +import os +import sys + +from .FileManagement import FileManagement as fm +from ly_test_tools import LAUNCHERS + +sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../automatedtesting_shared') + +from base import TestAutomationBase + + +revert_physics_config = fm.file_revert_list(['physxdebugconfiguration.setreg', 'physxdefaultsceneconfiguration.setreg', 'physxsystemconfiguration.setreg'], 'AutomatedTesting/Registry') + + +@pytest.mark.SUITE_sandbox +@pytest.mark.parametrize("launcher_platform", ['windows_editor']) +@pytest.mark.parametrize("project", ["AutomatedTesting"]) +class TestAutomation(TestAutomationBase): + + ## Seems to be flaky, need to investigate + def test_C19536274_GetCollisionName_PrintsName(self, request, workspace, editor, launcher_platform): + from . import C19536274_GetCollisionName_PrintsName as test_module + # Fixme: expected_lines=["Layer Name: Right"] + self._run_test(request, workspace, editor, test_module) + + ## Seems to be flaky, need to investigate + def test_C19536277_GetCollisionName_PrintsNothing(self, request, workspace, editor, launcher_platform): + from . import C19536277_GetCollisionName_PrintsNothing as test_module + # All groups present in the PhysX Collider that could show up in test + # Fixme: collision_groups = ["All", "None", "All_NoTouchBend", "All_3", "None_1", "All_NoTouchBend_1", "All_2", "None_1_1", "All_NoTouchBend_1_1", "All_1", "None_1_1_1", "All_NoTouchBend_1_1_1", "All_4", "None_1_1_1_1", "All_NoTouchBend_1_1_1_1", "GroupLeft", "GroupRight"] + # Fixme: for group in collision_groups: + # Fixme: unexpected_lines.append(f"GroupName: {group}") + # Fixme: expected_lines=["GroupName: "] + self._run_test(request, workspace, editor, test_module) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/AssetEditor_CreateScriptEventFile.py b/AutomatedTesting/Gem/PythonTests/scripting/AssetEditor_CreateScriptEventFile.py new file mode 100644 index 0000000000..dcbbf47f0c --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/AssetEditor_CreateScriptEventFile.py @@ -0,0 +1,124 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92569013 +Test Case Title: Script Event file can be created +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569013 +""" + + +# fmt: off +class Tests(): + new_event_created = ("New Script Event created", "New Script Event not created") + child_event_created = ("Child Event created", "Child not created") + file_saved = ("Script event file saved", "Script event file did not save") + console_error = ("No unexpected error in console", "Error found in console") + console_warning = ("No unexpected warning in console", "Warning found in console") +# fmt: on + + +def CreateScriptEventFile(): + """ + Summary: + Script Event file can be created + + Expected Behavior: + File is created without any errors and warnings in Console + + Test Steps: + 1) Open Asset Editor + 2) Get Asset Editor Qt object + 3) Create new Script Event Asset + 4) Add new child event + 5) Save the Script Event file + 6) Verify if file is created + 7) Verify console for errors/warnings + 8) Close Asset Editor + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + import os + from utils import Report + from utils import TestHelper as helper + from utils import Tracer + import pyside_utils + + # Open 3D Engine imports + import azlmbr.legacy.general as general + import azlmbr.editor as editor + import azlmbr.bus as bus + + # Pyside imports + from PySide2 import QtWidgets + + GENERAL_WAIT = 1.0 # seconds + + FILE_PATH = os.path.join("AutomatedTesting", "ScriptCanvas", "test_file.scriptevent") + + # 1) Open Asset Editor + general.idle_enable(True) + # Initially close the Asset Editor and then reopen to ensure we don't have any existing assets open + general.close_pane("Asset Editor") + general.open_pane("Asset Editor") + helper.wait_for_condition(lambda: general.is_pane_visible("Asset Editor"), 5.0) + + # 2) Get Asset Editor Qt object + editor_window = pyside_utils.get_editor_main_window() + asset_editor_widget = editor_window.findChild(QtWidgets.QDockWidget, "Asset Editor").findChild( + QtWidgets.QWidget, "AssetEditorWindowClass" + ) + container = asset_editor_widget.findChild(QtWidgets.QWidget, "ContainerForRows") + menu_bar = asset_editor_widget.findChild(QtWidgets.QMenuBar) + + # 3) Create new Script Event Asset + action = pyside_utils.find_child_by_pattern(menu_bar, {"type": QtWidgets.QAction, "text": "Script Events"}) + action.trigger() + result = helper.wait_for_condition( + lambda: container.findChild(QtWidgets.QFrame, "Events") is not None, 3 * GENERAL_WAIT + ) + Report.result(Tests.new_event_created, result) + + # 4) Add new child event + add_event = container.findChild(QtWidgets.QFrame, "Events").findChild(QtWidgets.QToolButton, "") + add_event.click() + result = helper.wait_for_condition( + lambda: asset_editor_widget.findChild(QtWidgets.QFrame, "EventName") is not None, GENERAL_WAIT + ) + Report.result(Tests.child_event_created, result) + + with Tracer() as section_tracer: + # 5) Save the Script Event file + editor.AssetEditorWidgetRequestsBus(bus.Broadcast, "SaveAssetAs", FILE_PATH) + + # 6) Verify if file is created + result = helper.wait_for_condition(lambda: os.path.exists(FILE_PATH), 3 * GENERAL_WAIT) + Report.result(Tests.file_saved, result) + + # 7) Verify console for errors/warnings + Report.result(Tests.console_error, not section_tracer.has_errors) + Report.result(Tests.console_warning, not section_tracer.has_warnings) + + # 8) Close Asset Editor + general.close_pane("Asset Editor") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(CreateScriptEventFile) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/AssetEditor_NewScriptEvent.py b/AutomatedTesting/Gem/PythonTests/scripting/AssetEditor_NewScriptEvent.py new file mode 100644 index 0000000000..1f801d4eeb --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/AssetEditor_NewScriptEvent.py @@ -0,0 +1,129 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92568942 +Test Case Title: Clicking the "+" button and selecting "New Script Event" opens the +Asset Editor with a new Script Event asset +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92568942 +""" + +from PySide2 import QtWidgets +import azlmbr.legacy.general as general + +import editor_python_test_tools.pyside_utils as pyside_utils +from editor_python_test_tools.utils import TestHelper as helper +from editor_python_test_tools.utils import Report + + +class Tests: + action_found = "New Script event action found" + asset_editor_opened = "Asset Editor opened" + new_asset = "Asset Editor created with new asset" + script_event = "New Script event created in Asset Editor" + + +GENERAL_WAIT = 0.5 # seconds + + +class TestAssetEditor_NewScriptEvent: + """ + Summary: + Clicking the "+" button in Node Palette and creating New Script Event opens Asset Editor + + Expected Behavior: + Clicking the "+" button and selecting "New Script Event" opens the Asset Editor with a + new Script Event asset + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Close any existing AssetEditor window + 3) Get the SC window object + 4) Click on New Script Event on Node palette + 5) Verify if Asset Editor opened + 6) Verify if a new asset with Script Canvas category is opened + 7) Close Script Canvas and Asset Editor + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + @pyside_utils.wrap_async + async def run_test(self): + # 1) Open Script Canvas window (Tools > Script Canvas) + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + + # 2) Close any existing AssetEditor window + general.close_pane("Asset Editor") + helper.wait_for_condition(lambda: not general.is_pane_visible("Asset Editor"), 5.0) + + # 3) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + node_palette = sc.findChild(QtWidgets.QDockWidget, "NodePalette") + frame = node_palette.findChild(QtWidgets.QFrame, "searchCustomization") + button = frame.findChild(QtWidgets.QToolButton) + pyside_utils.click_button_async(button) + + # 4) Click on New Script Event on Node palette + menu = None + + def menu_has_focus(): + nonlocal menu + for fw in [ + QtWidgets.QApplication.activePopupWidget(), + QtWidgets.QApplication.activeModalWidget(), + QtWidgets.QApplication.focusWidget(), + QtWidgets.QApplication.activeWindow(), + ]: + print(fw) + if fw and isinstance(fw, QtWidgets.QMenu) and fw.isVisible(): + menu = fw + return True + return False + + await pyside_utils.wait_for_condition(menu_has_focus, GENERAL_WAIT) + action = await pyside_utils.wait_for_action_in_menu(menu, {"text": "New Script Event"}) + Report.info(f"{Tests.action_found}: {action is not None}") + action.trigger() + pyside_utils.queue_hide_event(menu) + + # 5) Verify if Asset Editor opened + result = helper.wait_for_condition(lambda: general.is_pane_visible("Asset Editor"), GENERAL_WAIT) + Report.info(f"{Tests.asset_editor_opened}: {result}") + + # 6) Verify if a new asset with Script Canvas category is opened + asset_editor = editor_window.findChild(QtWidgets.QDockWidget, "Asset Editor") + row_container = asset_editor.findChild(QtWidgets.QWidget, "ContainerForRows") + # NOTE: QWidget ContainerForRows will have frames of Name, Category, ToolTip etc. + # To validate if a new script event file is generated, we check for + # QFrame Category and its value + categories = row_container.findChildren(QtWidgets.QFrame, "Category") + Report.info(f"{Tests.new_asset}: {len(categories)>0}") + result = False + for frame in categories: + line_edit = frame.findChild(QtWidgets.QLineEdit) + result = True if (line_edit and line_edit.text() == "Script Events") else False + Report.info(f"{Tests.script_event}: {result}") + + # 7) Close Script Canvas and Asset Editor + general.close_pane("Script Canvas") + general.close_pane("Asset Editor") + + +test = TestAssetEditor_NewScriptEvent() +test.run_test() diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Debugging_TargetMultipleEntities.py b/AutomatedTesting/Gem/PythonTests/scripting/Debugging_TargetMultipleEntities.py new file mode 100644 index 0000000000..a26cb4f923 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/Debugging_TargetMultipleEntities.py @@ -0,0 +1,144 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92568856 +Test Case Title: Multiple Entities can be targeted in the Debugger tool +URLs of the test case: https://testrail.agscollab.com/index.php?/tests/view/92568856 +""" + + +# fmt: off +class Tests(): + level_created = ("New level created", "New level not created") + entities_found = ("Entities are found in Logging window", "Entities are not found in Logging window") + select_multiple_targets = ("Multiple targets are selected", "Multiple targets are not selected") +# fmt: on + + +GENERAL_WAIT = 0.5 # seconds + + +def Debugging_TargetMultipleEntities(): + """ + Summary: + Multiple Entities can be targeted in the Debugger tool + + Expected Behavior: + Selected files can be checked for logging. + Upon checking, checkboxes of the parent folders change to either full or partial check. + + Test Steps: + 1) Create temp level + 2) Create two entities with scriptcanvas components + 3) Set values for scriptcanvas + 4) Open Script Canvas window and get sc opbject + 5) Open Debugging(Logging) window + 6) Click on Entities tab in logging window + 7) Verify if the scriptcanvas exist under entities + 8) Verify if the entities can be selected + 9) Close Debugging window and Script Canvas window + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + from PySide2 import QtWidgets + from PySide2.QtCore import Qt + import azlmbr.legacy.general as general + import azlmbr.math as math + import azlmbr.asset as asset + import azlmbr.bus as bus + + import os + import pyside_utils + import hydra_editor_utils as hydra + from utils import TestHelper as helper + from utils import Report + + LEVEL_NAME = "tmp_level" + ASSET_NAME_1 = "ScriptCanvas_TwoComponents0.scriptcanvas" + ASSET_NAME_2 = "ScriptCanvas_TwoComponents1.scriptcanvas" + ASSET_1 = os.path.join("scriptcanvas", ASSET_NAME_1) + ASSET_2 = os.path.join("scriptcanvas", ASSET_NAME_2) + WAIT_TIME = 3.0 + + def get_asset(asset_path): + return asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", asset_path, math.Uuid(), False) + + # 1) Create temp level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Create two entities with scriptcanvas components + position = math.Vector3(512.0, 512.0, 32.0) + test_entity_1 = hydra.Entity("test_entity_1") + test_entity_1.create_entity(position, ["Script Canvas"]) + test_entity_2 = hydra.Entity("test_entity_2") + test_entity_2.create_entity(position, ["Script Canvas"]) + + # 3) Set values for scriptcanvas + test_entity_1.get_set_test(0, "Script Canvas Asset|Script Canvas Asset", get_asset(ASSET_1)) + test_entity_2.get_set_test(0, "Script Canvas Asset|Script Canvas Asset", get_asset(ASSET_2)) + + # 4) Open Script Canvas window and get sc opbject + general.open_pane("Script Canvas") + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + + # 5) Open Debugging(Logging) window + if ( + sc.findChild(QtWidgets.QDockWidget, "LoggingWindow") is None + or not sc.findChild(QtWidgets.QDockWidget, "LoggingWindow").isVisible() + ): + action = pyside_utils.find_child_by_pattern(sc, {"text": "Debugging", "type": QtWidgets.QAction}) + action.trigger() + logging_window = sc.findChild(QtWidgets.QDockWidget, "LoggingWindow") + + # 6) Click on Entities tab in logging window + button = pyside_utils.find_child_by_pattern(logging_window, {"type": QtWidgets.QPushButton, "text": "Entities"}) + button.click() + + # 7) Verify if the scriptcanvas exist under entities + entities = logging_window.findChild(QtWidgets.QWidget, "entitiesPage") + tree = entities.findChild(QtWidgets.QTreeView, "pivotTreeView") + asset_1_mi = pyside_utils.find_child_by_pattern(tree, ASSET_NAME_1.lower()) + asset_2_mi = pyside_utils.find_child_by_pattern(tree, ASSET_NAME_2.lower()) + result = asset_1_mi is not None and asset_2_mi is not None + Report.critical_result(Tests.entities_found, result) + + # 8) Verify if the entities can be selected + tree.expandAll() + tree.model().setData(asset_1_mi, 2, Qt.CheckStateRole) + tree.model().setData(asset_2_mi, 2, Qt.CheckStateRole) + checklist = [asset_1_mi, asset_1_mi.parent(), asset_2_mi, asset_2_mi.parent()] + result = all([index.data(Qt.CheckStateRole) == 2 for index in checklist]) + Report.critical_result(Tests.select_multiple_targets, result) + + # 9) Close Debugging window and Script Canvas window + logging_window.close() + general.close_pane("Script Canvas") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + from utils import Report + + Report.start_test(Debugging_TargetMultipleEntities) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Debugging_TargetMultipleGraphs.py b/AutomatedTesting/Gem/PythonTests/scripting/Debugging_TargetMultipleGraphs.py new file mode 100644 index 0000000000..4aa5c822a7 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/Debugging_TargetMultipleGraphs.py @@ -0,0 +1,113 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92569137 +Test Case Title: Multiple Graphs can be targeted in the Debugger tool +URLs of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569137 +""" + + +# fmt: off +class Tests(): + select_multiple_targets = ("Multiple targets are selected", "Multiple targets are not selected") +# fmt: on + + +GENERAL_WAIT = 0.5 # seconds + + +def Debugging_TargetMultipleGraphs(): + """ + Summary: + Multiple Graphs can be targeted in the Debugger tool + + Expected Behavior: + Selected files can be checked for logging. + Upon checking, checkboxes of the parent folders change to either full or partial check. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Open Debugging Tool if not opened already + 4) Select Graphs tab under logging window + 5) Select multiple targets from levels and scriptcanvas + 6) Verify if multiple targets are selected + 7) Close Debugging window and Script Canvas window + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + from PySide2 import QtWidgets + from PySide2.QtCore import Qt + import azlmbr.legacy.general as general + + import pyside_utils + from utils import TestHelper as helper + from utils import Report + + # 1) Open Script Canvas window (Tools > Script Canvas) + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 6.0) + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + + # 3) Open Debugging Tool if not opened already + if ( + sc.findChild(QtWidgets.QDockWidget, "LoggingWindow") is None + or not sc.findChild(QtWidgets.QDockWidget, "LoggingWindow").isVisible() + ): + action = pyside_utils.find_child_by_pattern(sc, {"text": "Debugging", "type": QtWidgets.QAction}) + action.trigger() + logging_window = sc.findChild(QtWidgets.QDockWidget, "LoggingWindow") + + # 4) Select Graphs tab under logging window + button = pyside_utils.find_child_by_pattern(logging_window, {"type": QtWidgets.QPushButton, "text": "Graphs"}) + button.click() + + # 5) Select multiple targets from levels and scriptcanvas + graphs = logging_window.findChild(QtWidgets.QWidget, "graphsPage") + tree = graphs.findChild(QtWidgets.QTreeView, "pivotTreeView") + # Select the first child under levels + level_model_index = pyside_utils.find_child_by_pattern(tree, "levels") + level_child_index = pyside_utils.get_item_view_index(tree, 0, 0, level_model_index) + tree.model().setData(level_child_index, 2, Qt.CheckStateRole) + # Select the first child under scriptcanvas + sc_model_index = pyside_utils.find_child_by_pattern(tree, "scriptcanvas") + sc_child_index = pyside_utils.get_item_view_index(tree, 0, 0, sc_model_index) + tree.model().setData(sc_child_index, 2, Qt.CheckStateRole) + + # 6) Verify if multiple targets are selected + result = all([index.data(Qt.CheckStateRole) != 0 for index in (level_model_index, sc_model_index)]) + result = result and all([index.data(Qt.CheckStateRole) == 2 for index in (level_child_index, sc_child_index)]) + Report.result(Tests.select_multiple_targets, result) + + # 7) Close Debugging window and Script Canvas window + logging_window.close() + general.close_pane("Script Canvas") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(Debugging_TargetMultipleGraphs) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Docking_Pane.py b/AutomatedTesting/Gem/PythonTests/scripting/Docking_Pane.py index 25dd83e5e2..4fa1e1257f 100755 --- a/AutomatedTesting/Gem/PythonTests/scripting/Docking_Pane.py +++ b/AutomatedTesting/Gem/PythonTests/scripting/Docking_Pane.py @@ -16,7 +16,6 @@ URLs of the test case: https://testrail.agscollab.com/index.php?/cases/view/1702 # fmt: off class Tests(): - open_sc_window = ("Script Canvas window is opened", "Failed to open Script Canvas window") pane_opened = ("Pane is opened successfully", "Failed to open pane") dock_pane = ("Pane is docked successfully", "Failed to dock Pane into one or more allowed area") # fmt: on @@ -78,8 +77,7 @@ def Docking_Pane(): # 1) Open Script Canvas window (Tools > Script Canvas) general.open_pane("Script Canvas") - is_sc_visible = helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) - Report.result(Tests.open_sc_window, is_sc_visible) + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) # 2) Make sure Node Palette pane is opened editor_window = pyside_utils.get_editor_main_window() diff --git a/AutomatedTesting/Gem/PythonTests/scripting/EditMenu_UndoRedo.py b/AutomatedTesting/Gem/PythonTests/scripting/EditMenu_UndoRedo.py new file mode 100644 index 0000000000..a87d9e9be9 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/EditMenu_UndoRedo.py @@ -0,0 +1,123 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92569049 +Test Case Title: Edit > Undo undoes the last action +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569049 +Test case ID: T92569051 +Test Case Title: Edit > Redo redoes the last undone action +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569051 +""" + + +# fmt: off +class Tests(): + variable_created = ("New variable created", "New variable not created") + undo_worked = ("Undo action working", "Undo action did not work") + redo_worked = ("Redo action working", "Redo action did not work") +# fmt: on + + +def EditMenu_UndoRedo(): + """ + Summary: + Edit > Undo undoes the last action + Edit > Redo redoes the last undone action + We create a new variable in variable manager, undo and verify if variable is removed, + redo it and verify if the variable is created again. + + Expected Behavior: + The last action is undone. + The last undone action is redone. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Open Variable Manager if not opened already + 4) Create Graph + 5) Create new variable + 6) Verify if the variable is created initially + 7) Trigger Undo action and verify if variable is removed in Variable Manager + 8) Trigger Redo action and verify if variable is readded in Variable Manager + 9) Close SC window + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + from PySide2 import QtWidgets, QtCore + + import azlmbr.legacy.general as general + + import pyside_utils + + # 1) Open Script Canvas window + general.idle_enable(True) + general.open_pane("Script Canvas") + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + + # 3) Open Variable Manager if not opened already + if sc.findChild(QtWidgets.QDockWidget, "VariableManager") is None: + action = pyside_utils.find_child_by_pattern(sc, {"text": "Variable Manager", "type": QtWidgets.QAction}) + action.trigger() + variable_manager = sc.findChild(QtWidgets.QDockWidget, "VariableManager") + + # 4) Create Graph + action = pyside_utils.find_child_by_pattern(sc, {"objectName": "action_New_Script", "type": QtWidgets.QAction}) + action.trigger() + + # 5) Create new variable + add_button = variable_manager.findChild(QtWidgets.QPushButton, "addButton") + add_button.click() # Click on Create Variable button + # Select variable type + table_view = variable_manager.findChild(QtWidgets.QTableView, "variablePalette") + model_index = pyside_utils.find_child_by_pattern(table_view, "Boolean") + # Click on it to create variable + pyside_utils.item_view_index_mouse_click(table_view, model_index) + + # 6) Verify if the variable is created initially + graph_vars = variable_manager.findChild(QtWidgets.QTableView, "graphVariables") + result = graph_vars.model().rowCount(QtCore.QModelIndex()) == 1 # since we added 1 variable, rowcount=1 + Report.result(Tests.variable_created, result) + + # 7) Trigger Undo action and verify if variable is removed in Variable Manager + action = sc.findChild(QtWidgets.QAction, "action_Undo") + action.trigger() + result = graph_vars.model().rowCount(QtCore.QModelIndex()) == 0 # since we triggered undo, rowcount=0 + Report.result(Tests.undo_worked, result) + + # 8) Trigger Redo action and verify if variable is readded in Variable Manager + action = sc.findChild(QtWidgets.QAction, "action_Redo") + action.trigger() + result = ( + graph_vars.model().rowCount(QtCore.QModelIndex()) == 1 + ) # since action is redone 1 variable is readded, rowcount=1 + Report.result(Tests.redo_worked, result) + + # 9) Close SC window + general.close_pane("Script Canvas") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(EditMenu_UndoRedo) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Entity_AddScriptCanvasComponent.py b/AutomatedTesting/Gem/PythonTests/scripting/Entity_AddScriptCanvasComponent.py new file mode 100644 index 0000000000..fd8e9b1173 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/Entity_AddScriptCanvasComponent.py @@ -0,0 +1,88 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92562978 +Test Case Title: Script Canvas Component can be added to an entity +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92562978 +""" + + +# fmt: off +class Tests(): + level_created = ("New level created", "Failed to create new level") + entity_created = ("Test Entity created", "Failed to create test entity") + add_sc_component = ("Script Canvas component added to entity", "Failed to add SC component to entity") + no_errors_found = ("Tracer found no errors", "One or more errors found by Tracer") + no_warnings_found = ("Tracer found no warnings", "One or more warnings found by Tracer") +# fmt: on + + +def Entity_AddScriptCanvasComponent(): + """ + Summary: + verify if Script Canvas component can be added to Entity without any issue + + Expected Behavior: + Script Canvas Component is added to the entity successfully without issue. + + Test Steps: + 1) Create temp level + 2) Create test entity + 3) Start Tracer + 4) Add Script Canvas component to test entity + 5) Search for errors and warnings + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + from utils import TestHelper as helper + from utils import Tracer + from editor_entity_utils import EditorEntity + import azlmbr.legacy.general as general + + LEVEL_NAME = "tmp_level" + WAIT_TIME = 3.0 # SECONDS + + # 1) Create temp level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Create new entity + test_entity = EditorEntity.create_editor_entity("test_entity") + Report.result(Tests.entity_created, test_entity.id.IsValid()) + + # 3) Start Tracer + with Tracer() as section_tracer: + + # 4) Add Script Canvas component to test entity + test_entity.add_component("Script Canvas") + Report.result(Tests.add_sc_component, test_entity.has_component("Script Canvas")) + + # 5) Search for errors and warnings + Report.result(Tests.no_errors_found, not section_tracer.has_errors) + Report.result(Tests.no_warnings_found, not section_tracer.has_warnings) + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + from utils import Report + + Report.start_test(Entity_AddScriptCanvasComponent) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/FileMenu_New_Open.py b/AutomatedTesting/Gem/PythonTests/scripting/FileMenu_New_Open.py new file mode 100644 index 0000000000..f72ac8ea01 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/FileMenu_New_Open.py @@ -0,0 +1,98 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92569037 +Test Case Title: File > New Script creates a new script +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569037 +Test case ID: T92569039 +Test Case Title: File > Open opens the Open... dialog +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569039 +""" + +import os +import sys +from PySide2 import QtWidgets +import azlmbr.legacy.general as general + +import editor_python_test_tools.pyside_utils as pyside_utils +from editor_python_test_tools.utils import Report + +# fmt: off +class Tests(): + new_action = "File->New action working as expected" + open_action = "File->Open action working as expected" +# fmt: on + + +GENERAL_WAIT = 0.5 # seconds + + +class TestFileMenuNewOpen: + """ + Summary: + When clicked on File->New, new script opens and File->Open should open the FileBrowser + + Expected Behavior: + New and Open actions should work as expected. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Trigger File->New action + 4) Verify if New tab is opened + 5) Trigger File->Open action + 6) Close Script Canvas window + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + @pyside_utils.wrap_async + async def run_test(self): + # 1) Open Script Canvas window (Tools > Script Canvas) + general.open_pane("Script Canvas") + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + sc_main = sc.findChild(QtWidgets.QMainWindow) + sc_tabs = sc_main.findChild(QtWidgets.QTabWidget, "ScriptCanvasTabs") + + # 3) Trigger File->New action + initial_tabs_count = sc_tabs.count() + action = pyside_utils.find_child_by_pattern( + sc_main, {"objectName": "action_New_Script", "type": QtWidgets.QAction} + ) + action.trigger() + + # 4) Verify if New tab is opened + general.idle_wait(GENERAL_WAIT) + Report.info(f"{Tests.new_action}: {sc_tabs.count() == initial_tabs_count + 1}") + + # 5) Trigger File->Open action + action = pyside_utils.find_child_by_pattern(sc_main, {"objectName": "action_Open", "type": QtWidgets.QAction}) + pyside_utils.trigger_action_async(action) + general.idle_wait(GENERAL_WAIT) + popup = await pyside_utils.wait_for_modal_widget() + Report.info(f"{Tests.open_action}: {popup and 'Open' in popup.windowTitle()}") + popup.close() + + # 6) Close Script Canvas window + general.close_pane("Script Canvas") + + +test = TestFileMenuNewOpen() +test.run_test() diff --git a/AutomatedTesting/Gem/PythonTests/scripting/GraphClose_SavePrompt.py b/AutomatedTesting/Gem/PythonTests/scripting/GraphClose_SavePrompt.py new file mode 100644 index 0000000000..ce610b159b --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/GraphClose_SavePrompt.py @@ -0,0 +1,110 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92563070 +Test Case Title: Graphs can be closed by clicking X on the Graph name tab +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92563070 +Test case ID: T92563068 +Test Case Title: Save Prompt: User is prompted to save a graph on close after +creating a new graph +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92563068 +""" + +import os +import sys +from PySide2 import QtWidgets +import azlmbr.legacy.general as general + +import editor_python_test_tools.pyside_utils as pyside_utils +from editor_python_test_tools.utils import TestHelper as helper +from editor_python_test_tools.utils import Report + +# fmt: off +class Tests(): + new_graph = "New graph created" + save_prompt = "Save prompt opened as expected" + close_graph = "Close button worked as expected" +# fmt: on + + +GENERAL_WAIT = 0.5 # seconds + + +class TestGraphCloseSavePrompt: + """ + Summary: + The graph is closed when x button is clicked. + Save Prompt is opened before closing. + + Expected Behavior: + New and Open actions should work as expected. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Trigger File->New action + 4) Verify if New tab is opened + 5) Close new tab using X on top of graph and check for save dialog + 6) Check if tab is closed + 7) Close Script Canvas window + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + @pyside_utils.wrap_async + async def run_test(self): + # 1) Open Script Canvas window (Tools > Script Canvas) + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + sc_main = sc.findChild(QtWidgets.QMainWindow) + sc_tabs = sc_main.findChild(QtWidgets.QTabWidget, "ScriptCanvasTabs") + tab_bar = sc_tabs.findChild(QtWidgets.QTabBar) + + # 3) Trigger File->New action + initial_tabs_count = sc_tabs.count() + action = pyside_utils.find_child_by_pattern( + sc_main, {"objectName": "action_New_Script", "type": QtWidgets.QAction} + ) + action.trigger() + + # 4) Verify if New tab is opened + result = helper.wait_for_condition(lambda: sc_tabs.count() == initial_tabs_count + 1, GENERAL_WAIT) + Report.info(f"{Tests.new_graph}: {result}") + + # 5) Close new tab using X on top of graph and check for save dialog + close_button = tab_bar.findChildren(QtWidgets.QAbstractButton)[0] + pyside_utils.click_button_async(close_button) + popup = await pyside_utils.wait_for_modal_widget() + if popup: + Report.info(f"{Tests.save_prompt}: {popup.findChild(QtWidgets.QDialog, 'SaveChangesDialog') is not None}") + dont_save = popup.findChild(QtWidgets.QPushButton, "m_continueButton") + dont_save.click() + + # 6) Check if tab is closed + await pyside_utils.wait_for_condition(lambda: sc_tabs.count() == initial_tabs_count, 5.0) + Report.info(f"{Tests.close_graph}: {sc_tabs.count()==initial_tabs_count}") + + # 7) Close Script Canvas window + general.close_pane("Script Canvas") + + +test = TestGraphCloseSavePrompt() +test.run_test() diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Graph_ZoomInZoomOut.py b/AutomatedTesting/Gem/PythonTests/scripting/Graph_ZoomInZoomOut.py new file mode 100644 index 0000000000..a93b6e61d1 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/Graph_ZoomInZoomOut.py @@ -0,0 +1,120 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92569079 +Test Case Title: View > Zoom In zooms the graph in +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569079 +Test case ID: T92569081 +Test Case Title: View > Zoom In zooms the graph out +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569081 +""" + + +# fmt: off +class Tests(): + zoom_in = ("Zoom In action working as expected", "Zoom In action not working as expected") + zoom_out = ("Zoom Out action working as expected", "Zoom Out action not working as expected") +# fmt: on + + +GENERAL_WAIT = 0.5 # seconds + + +def Graph_ZoomInZoomOut(): + """ + Summary: + The graph can be zoomed in and zoomed out. + + Expected Behavior: + The graph is zoomed in when when we click View->ZoomIn + The graph is zoomed out when when we click View->ZoomOut + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Create new graph + 4) Get initial graph transform values + 5) Trigger Zoom In and verify if the graph transform scale is increased + 6) Trigger Zoom Out and verify if the graph transform scale is decreased + 7) Close Script Canvas window + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + # Helper imports + import ImportPathHelper as imports + + imports.init() + + from PySide2 import QtWidgets + import azlmbr.legacy.general as general + + import pyside_utils + from utils import TestHelper as helper + from utils import Report + + # 1) Open Script Canvas window (Tools > Script Canvas) + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + sc_main = sc.findChild(QtWidgets.QMainWindow) + + # 3) Create new graph + create_new_graph = pyside_utils.find_child_by_pattern( + sc_main, {"objectName": "action_New_Script", "type": QtWidgets.QAction} + ) + create_new_graph.trigger() + + # 4) Get initial graph transform values + graphics_view = sc_main.findChild(QtWidgets.QGraphicsView) + # NOTE: transform m11 and m22 are horizontal and vertical scales of graph + # they increase when zoomed in and decreased when zoomed out + curr_m11, curr_m22 = graphics_view.transform().m11(), graphics_view.transform().m22() + + # 5) Trigger Zoom In and verify if the graph transform scale is increased + zin = pyside_utils.find_child_by_pattern(sc_main, {"objectName": "action_ZoomIn", "type": QtWidgets.QAction}) + zin.trigger() + result = helper.wait_for_condition( + lambda: curr_m11 < graphics_view.transform().m11() and curr_m22 < graphics_view.transform().m22(), GENERAL_WAIT, + ) + Report.result(Tests.zoom_in, result) + + # 6) Trigger Zoom Out and verify if the graph transform scale is decreased + curr_m11, curr_m22 = graphics_view.transform().m11(), graphics_view.transform().m22() + zout = pyside_utils.find_child_by_pattern(sc_main, {"objectName": "action_ZoomOut", "type": QtWidgets.QAction}) + zout.trigger() + result = helper.wait_for_condition( + lambda: curr_m11 > graphics_view.transform().m11() and curr_m22 > graphics_view.transform().m22(), GENERAL_WAIT, + ) + Report.result(Tests.zoom_out, result) + + # 7) Close Script Canvas window + general.close_pane("Script Canvas") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(Graph_ZoomInZoomOut) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/ImportPathHelper.py b/AutomatedTesting/Gem/PythonTests/scripting/ImportPathHelper.py index 8aede24d0e..a45024cebf 100755 --- a/AutomatedTesting/Gem/PythonTests/scripting/ImportPathHelper.py +++ b/AutomatedTesting/Gem/PythonTests/scripting/ImportPathHelper.py @@ -13,4 +13,5 @@ def init(): import os import sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../automatedtesting_shared') + sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../EditorPythonTestTools/editor_python_test_tools') \ No newline at end of file diff --git a/AutomatedTesting/Gem/PythonTests/scripting/NodeInspector_RenameVariable.py b/AutomatedTesting/Gem/PythonTests/scripting/NodeInspector_RenameVariable.py new file mode 100644 index 0000000000..33d3f4137a --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/NodeInspector_RenameVariable.py @@ -0,0 +1,132 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92568982 +Test Case Title: Renaming variables in the Node Inspector +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92568982 +""" + + +# fmt: off +class Tests(): + variable_created = ("New variable created", "New variable is not created") + node_inspector_rename = ("Variable is renamed in Node Inspector", "Variable is not renamed in Node Inspector") + variable_manager_rename = ("Variable is renamed in Variable Manager", "Variable is not renamed in Variable Manager") +# fmt: on + + +GENERAL_WAIT = 0.5 # seconds + + +def NodeInspector_RenameVariable(): + """ + Summary: + Renaming variables in the Node Inspector, renames the actual variable. + + Expected Behavior: + The Variable's name is changed in both Node Inspector and Variable Manager. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Open Variable Manager if not opened already + 4) Open Node Inspector if not opened already + 5) Create new graph and a new variable in Variable manager + 6) Click on the variable + 7) Update name in Node Inspector and click on ENTER + 8) Verify if the name is updated in Node inspector and Variable manager + 9) Close Script Canvas window + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + TEST_NAME = "test name" + + from PySide2 import QtWidgets, QtCore, QtTest + from PySide2.QtCore import Qt + import azlmbr.legacy.general as general + + import pyside_utils + from utils import TestHelper as helper + + def open_tool(sc, dock_widget_name, pane_name): + if sc.findChild(QtWidgets.QDockWidget, dock_widget_name) is None: + action = pyside_utils.find_child_by_pattern(sc, {"text": pane_name, "type": QtWidgets.QAction}) + action.trigger() + tool = sc.findChild(QtWidgets.QDockWidget, dock_widget_name) + return tool + + # 1) Open Script Canvas window + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + + # 3) Open Variable Manager if not opened already + variable_manager = open_tool(sc, "VariableManager", "Variable Manager") + + # 4) Open Node Inspector if not opened already + node_inspector = open_tool(sc, "NodeInspector", "Node Inspector") + + # 5) Create new graph and a new variable in Variable manager + action = pyside_utils.find_child_by_pattern(sc, {"objectName": "action_New_Script", "type": QtWidgets.QAction}) + action.trigger() + graph_vars = variable_manager.findChild(QtWidgets.QTableView, "graphVariables") + add_button = variable_manager.findChild(QtWidgets.QPushButton, "addButton") + add_button.click() + # Select variable type + table_view = variable_manager.findChild(QtWidgets.QTableView, "variablePalette") + model_index = pyside_utils.find_child_by_pattern(table_view, "Boolean") + # Click on it to create variable + pyside_utils.item_view_index_mouse_click(table_view, model_index) + result = graph_vars.model().rowCount(QtCore.QModelIndex()) == 1 + var_mi = pyside_utils.find_child_by_pattern(graph_vars, "Variable 1") + result = result and (var_mi is not None) + Report.critical_result(Tests.variable_created, result) + + # 6) Click on the variable + pyside_utils.item_view_index_mouse_click(graph_vars, var_mi) + + # 7) Update name in Node Inspector and click on ENTER + helper.wait_for_condition( + lambda: node_inspector.findChild(QtWidgets.QWidget, "ContainerForRows") is not None, GENERAL_WAIT + ) + row_container = node_inspector.findChild(QtWidgets.QWidget, "ContainerForRows") + name_frame = row_container.findChild(QtWidgets.QWidget, "Name") + name_line_edit = name_frame.findChild(QtWidgets.QLineEdit) + name_line_edit.setText(TEST_NAME) + QtTest.QTest.keyClick(name_line_edit, Qt.Key_Return, Qt.NoModifier) + + # 8) Verify if the name is updated in Node inspector and Variable manager + helper.wait_for_condition(lambda: var_mi.data(Qt.DisplayRole) == TEST_NAME, GENERAL_WAIT) + Report.critical_result(Tests.node_inspector_rename, name_line_edit.text() == TEST_NAME) + Report.critical_result(Tests.variable_manager_rename, var_mi.data(Qt.DisplayRole) == TEST_NAME) + + # 9) Close Script Canvas window + general.close_pane("Script Canvas") + + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(NodeInspector_RenameVariable) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/NodePalette_ClearSelection.py b/AutomatedTesting/Gem/PythonTests/scripting/NodePalette_ClearSelection.py new file mode 100644 index 0000000000..de30e46767 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/NodePalette_ClearSelection.py @@ -0,0 +1,94 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92562993 +Test Case Title: Clicking the X button on the Search Box clears the currently entered string +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92562993 +""" + + +# fmt: off +class Tests(): + set_search_string = ("Search string is set", "Search string is not set") + search_string_cleared = ("Search string cleared as expected", "Search string not cleared") +# fmt: on + + +def NodePalette_ClearSelection(): + """ + Summary: + We enter some string in the Node Palette Search box, and click on the X button to verify if the + search string got cleared. + + Expected Behavior: + Clicking the X button on the Search Box clears the currently entered string + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Open Node Manager if not opened already + 4) Set some string in the Search box + 5) Verify if the test string is set + 6) Clear search string and verify if it is cleared + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + from PySide2 import QtWidgets + + from utils import TestHelper as helper + + import azlmbr.legacy.general as general + + import pyside_utils + + TEST_STRING = "Test String" + + # 1) Open Script Canvas window (Tools > Script Canvas) + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 3.0) + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + + # 3) Open Node Manager if not opened already + if sc.findChild(QtWidgets.QDockWidget, "NodePalette") is None: + action = pyside_utils.find_child_by_pattern(sc, {"text": "Node Palette", "type": QtWidgets.QAction}) + action.trigger() + node_palette = sc.findChild(QtWidgets.QDockWidget, "NodePalette") + search_frame = node_palette.findChild(QtWidgets.QFrame, "searchFrame") + + # 4) Set some string in the Search box + search_box = search_frame.findChild(QtWidgets.QLineEdit, "searchFilter") + search_box.setText(TEST_STRING) + + # 5) Verify if the test string is set + Report.result(Tests.set_search_string, search_box.text() == TEST_STRING) + + # 6) Clear search string and verify if it is cleared + clear_text_button = search_frame.findChild(QtWidgets.QToolButton, "ClearToolButton") + clear_text_button.click() + Report.result(Tests.search_string_cleared, search_box.text() == "") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + from utils import Report + + Report.start_test(NodePalette_ClearSelection) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/NodePalette_SelectNode.py b/AutomatedTesting/Gem/PythonTests/scripting/NodePalette_SelectNode.py new file mode 100644 index 0000000000..2ab76071a6 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/NodePalette_SelectNode.py @@ -0,0 +1,104 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + + +Test case ID: T92568940 +Test Case Title: Categories and Nodes can be selected +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92568940 +""" + + +# fmt: off +class Tests(): + category_selected = ("Category can be selected", "Category cannot be selected") + node_selected = ("Node can be selected", "Node cannot be selected") +# fmt: on + + +GENERAL_WAIT = 0.5 # seconds + + +def NodePalette_SelectNode(): + """ + Summary: + Categories and Nodes can be selected + + Expected Behavior: + When clicked on Node Palette, nodes and categories can be selected. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Expand QTreeView + 4) Click on category and check if it is selected + 5) Click on node and check if it is selected + 6) Close Script Canvas window + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + CATEGORY = "AI" + NODE = "Find Path To Entity" + + from PySide2 import QtWidgets + import azlmbr.legacy.general as general + + import pyside_utils + from utils import TestHelper as helper + + # 1) Open Script Canvas window (Tools > Script Canvas) + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + if sc.findChild(QtWidgets.QDockWidget, "NodePalette") is None: + action = pyside_utils.find_child_by_pattern(sc, {"text": "Node Palette", "type": QtWidgets.QAction}) + action.trigger() + node_palette = sc.findChild(QtWidgets.QDockWidget, "NodePalette") + tree = node_palette.findChild(QtWidgets.QTreeView, "treeView") + + # 3) Expand QTreeView + tree.expandAll() + + # 4) Click on category and check if it is selected + category_index = pyside_utils.find_child_by_hierarchy(tree, CATEGORY) + tree.scrollTo(category_index) + pyside_utils.item_view_index_mouse_click(tree, category_index) + pyside_utils.wait_for_condition(tree.selectedIndexes() and tree.selectedIndexes()[0] == category_index) + Report.result(Tests.category_selected, tree.selectedIndexes()[0] == category_index) + + # 5) Click on node and check if it is selected + node_index = pyside_utils.find_child_by_pattern(tree, NODE) + helper.wait_for_condition(lambda: tree.isExpanded(node_index), GENERAL_WAIT) + pyside_utils.item_view_index_mouse_click(tree, node_index) + pyside_utils.wait_for_condition(tree.selectedIndexes()[0] == node_index) + Report.result(Tests.node_selected, tree.selectedIndexes()[0] == node_index) + + # 6) Close Script Canvas window + general.close_pane("Script Canvas") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(NodePalette_SelectNode) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/OnEntityActivatedDeactivated_PrintMessage.py b/AutomatedTesting/Gem/PythonTests/scripting/OnEntityActivatedDeactivated_PrintMessage.py new file mode 100644 index 0000000000..51b63c4268 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/OnEntityActivatedDeactivated_PrintMessage.py @@ -0,0 +1,184 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92569253 // T92569254 +Test Case Title: On Entity Activated // On Entity Deactivated +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92569253 // https://testrail.agscollab.com/index.php?/tests/view/92569254 +""" + + +# fmt: off +class Tests(): + level_created = ("Successfully created temp level", "Failed to create temp level") + controller_exists = ("Successfully found controller entity", "Failed to find controller entity") + activated_exists = ("Successfully found activated entity", "Failed to find activated entity") + deactivated_exists = ("Successfully found deactivated entity","Failed to find deactivated entity") + start_states_correct = ("Start states set up successfully", "Start states set up incorrectly") + game_mode_entered = ("Successfully entered game mode" "Failed to enter game mode") + lines_found = ("Successfully found expected prints", "Failed to find expected prints") + game_mode_exited = ("Successfully exited game mode" "Failed to exit game mode") +# fmt: on + + +def OnEntityActivatedDeactivated_PrintMessage(): + """ + Summary: + Verify that the On Entity Activation node is working as expected + + Expected Behavior: + Upon entering game mode, the Controller entity will wait 1 second and then activate the ActivationTest + entity. The script attached to ActivationTest will print out a message on activation. The Controller + will also deactivate the DeactivationTest entity, which should print a message. + + Test Steps: + 1) Create temp level + 2) Setup the level + 3) Validate the entities + 4) Start the Tracer + 5) Enter Game Mode + 6) Validate Print message + 7) Exit game mode + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + import os + + from utils import TestHelper as helper + from editor_entity_utils import EditorEntity as Entity + from utils import Report + from utils import Tracer + + import azlmbr.legacy.general as general + + EditorEntity = str + LEVEL_NAME = "tmp_level" + WAIT_TIME = 3.0 # SECONDS + EXPECTED_LINES = ["Activator Script: Activated", "Deactivator Script: Deactivated"] + controller_dict = { + "name": "Controller", + "status": "active", + "path": os.path.join("ScriptCanvas", "OnEntityActivatedScripts", "controller.scriptcanvas") + } + activated_dict = { + "name": "ActivationTest", + "status": "inactive", + "path": os.path.join("ScriptCanvas", "OnEntityActivatedScripts", "activator.scriptcanvas") + } + deactivated_dict = { + "name": "DeactivationTest", + "status": "active", + "path": os.path.join("ScriptCanvas", "OnEntityActivatedScripts", "deactivator.scriptcanvas") + } + + def get_asset(asset_path): + return azlmbr.asset.AssetCatalogRequestBus(azlmbr.bus.Broadcast, "GetAssetIdByPath", asset_path, azlmbr.math.Uuid(), False) + + def setup_level(): + def create_editor_entity(entity_dict:dict, entity_to_activate:EditorEntity=None, entity_to_deactivate:EditorEntity=None) -> EditorEntity: + entity = Entity.create_editor_entity(entity_dict["name"]) + entity.set_start_status(entity_dict["status"]) + sc_component = entity.add_component("Script Canvas") + sc_component.set_component_property_value("Script Canvas Asset|Script Canvas Asset", get_asset(entity_dict["path"])) + + if entity_dict["name"] == "Controller": + sc_component.get_property_tree() + sc_component.set_component_property_value("Properties|Variable Fields|Variables|[0]|Name,Value|Datum|Datum|EntityToActivate", entity_to_activate.id) + sc_component.set_component_property_value("Properties|Variable Fields|Variables|[1]|Name,Value|Datum|Datum|EntityToDeactivate", entity_to_deactivate.id) + return entity + + activated = create_editor_entity(activated_dict) + deactivated = create_editor_entity(deactivated_dict) + create_editor_entity(controller_dict, activated, deactivated) + + def validate_entity_exist(entity_name: str, test_tuple: tuple): + """ + Validate the entity with the given name exists in the level + :return: entity: editor entity object + """ + entity = Entity.find_editor_entity(entity_name) + Report.critical_result(test_tuple, entity.id.IsValid()) + return entity + + def validate_start_state(entity:EditorEntity, expected_state:str): + """ + Validate that the starting state of the entity is correct, if it isn't then attempt to rectify and recheck. + :return: bool: Whether state is set as expected + """ + state_options = { + "active": azlmbr.globals.property.EditorEntityStartStatus_StartActive, + "inactive": azlmbr.globals.property.EditorEntityStartStatus_StartInactive, + "editor": azlmbr.globals.property.EditorEntityStartStatus_EditorOnly, + } + if expected_state.lower() not in state_options.keys(): + raise ValueError(f"{expected_state} is an invalid option; valid options: active, inactive, or editor.") + + state = entity.get_start_status() + if state != state_options[expected_state]: + # If state fails to set, set_start_status will assert + entity.set_start_status(expected_state) + return True + + def validate_entities_in_level(): + controller = validate_entity_exist(controller_dict["name"], Tests.controller_exists) + state1_correct = validate_start_state(controller, controller_dict["status"]) + + act_tester = validate_entity_exist(activated_dict["name"], Tests.activated_exists) + state2_correct = validate_start_state(act_tester, activated_dict["status"]) + + deac_tester = validate_entity_exist(deactivated_dict["name"], Tests.deactivated_exists) + state3_correct = validate_start_state(deac_tester, deactivated_dict["status"]) + + all_states_correct = state1_correct and state2_correct and state3_correct + Report.critical_result(Tests.start_states_correct, all_states_correct) + + def locate_expected_lines(line_list: list): + found_lines = [printInfo.message.strip() for printInfo in section_tracer.prints] + return all(line in found_lines for line in line_list) + + # 1) Create temp level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Setup the level + setup_level() + + # 3) Validate the entities + validate_entities_in_level() + + # 4) Start the Tracer + with Tracer() as section_tracer: + + # 5) Enter Game Mode + helper.enter_game_mode(Tests.game_mode_entered) + + # 6) Validate Print message + helper.wait_for_condition(lambda: locate_expected_lines(EXPECTED_LINES), WAIT_TIME) + + Report.result(Tests.lines_found, locate_expected_lines(EXPECTED_LINES)) + + # 7) Exit game mode + helper.exit_game_mode(Tests.game_mode_exited) + + +if __name__ == "__main__": + import ImportPathHelper as imports + imports.init() + + from utils import Report + + Report.start_test(OnEntityActivatedDeactivated_PrintMessage) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Opening_Closing_Pane.py b/AutomatedTesting/Gem/PythonTests/scripting/Opening_Closing_Pane.py index 6100285092..666f052240 100755 --- a/AutomatedTesting/Gem/PythonTests/scripting/Opening_Closing_Pane.py +++ b/AutomatedTesting/Gem/PythonTests/scripting/Opening_Closing_Pane.py @@ -17,7 +17,6 @@ URLs of the test case: https://testrail.agscollab.com/index.php?/cases/view/1702 # fmt: off class Tests(): - open_sc_window = ("Script Canvas window is opened", "Failed to open Script Canvas window") default_visible = ("All the panes visible by default", "One or more panes do not visible by default") open_panes = ("All the Panes opened successfully", "Failed to open one or more panes") close_pane = ("All the Panes closed successfully", "Failed to close one or more panes") @@ -49,11 +48,6 @@ def Opening_Closing_Pane(): :return: None """ - # Helper imports - import ImportPathHelper as imports - - imports.init() - from editor_python_test_tools.utils import Report from editor_python_test_tools.utils import TestHelper as helper import editor_python_test_tools.pyside_utils as pyside_utils @@ -82,8 +76,7 @@ def Opening_Closing_Pane(): # 1) Open Script Canvas window (Tools > Script Canvas) general.open_pane("Script Canvas") - is_sc_visible = helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) - Report.result(Tests.open_sc_window, is_sc_visible) + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) # 2) Restore default layout editor_window = pyside_utils.get_editor_main_window() diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Pane_RetainOnSCRestart.py b/AutomatedTesting/Gem/PythonTests/scripting/Pane_RetainOnSCRestart.py new file mode 100644 index 0000000000..fa5e9e6068 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/Pane_RetainOnSCRestart.py @@ -0,0 +1,164 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: C1702821 // C1702832 +Test Case Title: Retain visibility, size and location upon Script Canvas restart +URLs of the test case: https://testrail.agscollab.com/index.php?/cases/view/1702821 and + https://testrail.agscollab.com/index.php?/cases/view/1702832 +""" + + +# fmt: off +class Tests(): + relaunch_sc = ("Script Canvas window is relaunched", "Failed to relaunch Script Canvas window") + test_panes_visible = ("All the test panes are opened", "Failed to open one or more test panes") + close_pane_1 = ("Test pane 1 is closed", "Failed to close test pane 1") + visiblity_retained = ("Test pane retained its visiblity on SC restart", "Failed to retain visiblity of test pane on SC restart") + resize_pane_3 = ("Test pane 3 resized successfully", "Failed to resize Test pane 3") + size_retained = ("Test pane retained its size on SC restart", "Failed to retain size of test pane on SC restart") + location_changed = ("Location of test pane 2 changed successfully", "Failed to change locatio of test pane 2") + location_retained = ("Test pane retained its location on SC restart", "Failed to retain location of test pane on SC restart") +# fmt: on + + +def Pane_RetainOnSCRestart(): + """ + Summary: + The Script Canvas window is opened to verify if Script canvas panes can retain its visibility, size and location + upon ScriptCanvas restart. + + Expected Behavior: + The ScriptCanvas pane retain it's visiblity, size and location upon ScriptCanvas restart. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Make sure test panes are open and visible + 3) Close test pane 1 + 4) Change dock location of test pane 2 + 5) Resize test pane 3 + 6) Relaunch Script Canvas + 7) Verify if test pane 1 retain its visiblity + 8) Verify if location of test pane 2 is retained + 9) Verify if size of test pane 3 is retained + 10) Restore default layout and close SC window + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + # Helper imports + from utils import Report + from utils import TestHelper as helper + import pyside_utils + + # Open 3D Engine Imports + import azlmbr.legacy.general as general + + # Pyside imports + from PySide2 import QtCore, QtWidgets + from PySide2.QtCore import Qt + + # Constants + TEST_PANE_1 = "NodePalette" # test visibility + TEST_PANE_2 = "VariableManager" # test location + TEST_PANE_3 = "NodeInspector" # test size + SCALE_INT = 10 # Random resize scale integer + DOCKAREA = Qt.TopDockWidgetArea # Preferred top area since no widget is docked on top + + def click_menu_option(window, option_text): + action = pyside_utils.find_child_by_pattern(window, {"text": option_text, "type": QtWidgets.QAction}) + action.trigger() + + def find_pane(window, pane_name): + return window.findChild(QtWidgets.QDockWidget, pane_name) + + # Test starts here + general.idle_enable(True) + + # 1) Open Script Canvas window (Tools > Script Canvas) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 3.0) + + # 2) Make sure test panes are open and visible + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + click_menu_option(sc, "Restore Default Layout") + test_pane_1 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_1) + test_pane_2 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_2) + test_pane_3 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_3) + + Report.result( + Tests.test_panes_visible, test_pane_1.isVisible() and test_pane_2.isVisible() and test_pane_3.isVisible() + ) + + # Initiate try block here to restore default in finally block + try: + # 3) Close test pane + test_pane_1.close() + Report.result(Tests.close_pane_1, not test_pane_1.isVisible()) + + # 4) Change dock location of test pane 2 + sc_main = sc.findChild(QtWidgets.QMainWindow) + sc_main.addDockWidget(DOCKAREA, find_pane(sc_main, TEST_PANE_2), QtCore.Qt.Vertical) + Report.result(Tests.location_changed, sc_main.dockWidgetArea(find_pane(sc_main, TEST_PANE_2)) == DOCKAREA) + + # 5) Resize test pane 3 + initial_size = test_pane_3.frameSize() + test_pane_3.resize(initial_size.width() + SCALE_INT, initial_size.height() + SCALE_INT) + new_size = test_pane_3.frameSize() + resize_success = ( + abs(initial_size.width() - new_size.width()) == abs(initial_size.height() - new_size.height()) == SCALE_INT + ) + Report.result(Tests.resize_pane_3, resize_success) + + # 6) Relaunch Script Canvas + general.close_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 2.0) + + general.open_pane("Script Canvas") + sc_visible = helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + Report.result(Tests.relaunch_sc, sc_visible) + + # 7) Verify if test pane 1 retain its visiblity + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + Report.result(Tests.visiblity_retained, not find_pane(sc, TEST_PANE_1).isVisible()) + + # 8) Verify if location of test pane 2 is retained + sc_main = sc.findChild(QtWidgets.QMainWindow) + Report.result(Tests.location_retained, sc_main.dockWidgetArea(find_pane(sc_main, TEST_PANE_2)) == DOCKAREA) + + # 9) Verify if size of test pane 3 is retained + test_pane_3 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_3) + retained_size = test_pane_3.frameSize() + retain_success = retained_size != initial_size + Report.result(Tests.size_retained, retain_success) + + finally: + # 10) Restore default layout and close SC window + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + click_menu_option(sc, "Restore Default Layout") + sc.close() + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(Pane_RetainOnSCRestart) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Resizing_Pane.py b/AutomatedTesting/Gem/PythonTests/scripting/Resizing_Pane.py index 9262e76cb0..180f577953 100755 --- a/AutomatedTesting/Gem/PythonTests/scripting/Resizing_Pane.py +++ b/AutomatedTesting/Gem/PythonTests/scripting/Resizing_Pane.py @@ -16,7 +16,6 @@ URLs of the test case: https://testrail.agscollab.com/index.php?/cases/view/1702 # fmt: off class Tests(): - open_sc_window = ("Script Canvas window is opened", "Failed to open Script Canvas window") open_pane = ("Pane opened successfully", "Failed to open pane") resize_pane = ("Pane window resized successfully", "Failed to resize pane window") # fmt: on @@ -46,11 +45,6 @@ def Resizing_Pane(): :return: None """ - # Helper imports - import ImportPathHelper as imports - - imports.init() - from editor_python_test_tools.utils import Report from editor_python_test_tools.utils import TestHelper as helper import editor_python_test_tools.pyside_utils as pyside_utils @@ -76,8 +70,7 @@ def Resizing_Pane(): # 1) Open Script Canvas window (Tools > Script Canvas) general.open_pane("Script Canvas") - is_sc_visible = helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) - Report.result(Tests.open_sc_window, is_sc_visible) + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) # 2) Restore default layout editor_window = pyside_utils.get_editor_main_window() diff --git a/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_ChangingAssets.py b/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_ChangingAssets.py new file mode 100644 index 0000000000..38d60ad871 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_ChangingAssets.py @@ -0,0 +1,116 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92562986 +Test Case Title: Changing the assigned Script Canvas Asset on an entity properly updates +level functionality +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92562986 +""" + + +# fmt: off +class Tests(): + level_created = ("New level created", "New level not created") + entity_created = ("Test Entity created", "Test Entity not created") + game_mode_entered = ("Game Mode successfully entered", "Game mode failed to enter") + game_mode_exited = ("Game Mode successfully exited", "Game mode failed to exited") + found_lines = ("Expected log lines were found", "Expected log lines were not found") +# fmt: on + + +def ScriptCanvas_ChangingAssets(): + """ + Summary: + Changing the assigned Script Canvas Asset on an entity properly updates level functionality + + Expected Behavior: + When game mode is entered, respective strings of assigned assets should be printed + + Test Steps: + 1) Create temp level + 2) Create new entity + 3) Start Tracer + 4) Set first script and evaluate + 5) Set second script and evaluate + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + import os + + from utils import TestHelper as helper + from utils import Tracer + import hydra_editor_utils as hydra + import azlmbr.legacy.general as general + import azlmbr.math as math + import azlmbr.asset as asset + import azlmbr.bus as bus + import azlmbr.paths as paths + + LEVEL_NAME = "tmp_level" + ASSET_1 = os.path.join("scriptcanvas", "ScriptCanvas_TwoComponents0.scriptcanvas") + ASSET_2 = os.path.join("scriptcanvas", "ScriptCanvas_TwoComponents1.scriptcanvas") + EXP_LINE_1 = "Greetings from the first script" + EXP_LINE_2 = "Greetings from the second script" + WAIT_TIME = 3.0 # SECONDS + + def get_asset(asset_path): + return asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", asset_path, math.Uuid(), False) + + def find_expected_line(expected_line): + found_lines = [printInfo.message.strip() for printInfo in section_tracer.prints] + return expected_line in found_lines + + def set_asset_evaluate(test_entity, ASSET_PATH, EXP_LINE): + # Set Script Canvas entity + test_entity.get_set_test(0, "Script Canvas Asset|Script Canvas Asset", get_asset(ASSET_PATH)) + + # Enter/exit game mode + helper.enter_game_mode(Tests.game_mode_entered) + helper.wait_for_condition(lambda: find_expected_line(EXP_LINE), WAIT_TIME) + Report.result(Tests.found_lines, find_expected_line(EXP_LINE)) + helper.exit_game_mode(Tests.game_mode_exited) + + + # 1) Create temp level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Create new entity + position = math.Vector3(512.0, 512.0, 32.0) + test_entity = hydra.Entity("test_entity") + test_entity.create_entity(position, ["Script Canvas"]) + + # 3) Start Tracer + with Tracer() as section_tracer: + + # 4) Set first script and evaluate + set_asset_evaluate(test_entity, ASSET_1, EXP_LINE_1) + + # 5) Set second script and evaluate + set_asset_evaluate(test_entity, ASSET_2, EXP_LINE_2) + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + from utils import Report + + Report.start_test(ScriptCanvas_ChangingAssets) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_TwoComponents.py b/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_TwoComponents.py new file mode 100644 index 0000000000..896bee96e5 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_TwoComponents.py @@ -0,0 +1,118 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92563190 +Test Case Title: A single Entity with two Script Canvas components works properly +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92563190 +""" + + +# fmt: off +class Tests(): + level_created = ("New level created", "New level not created") + game_mode_entered = ("Game Mode successfully entered", "Game mode failed to enter") + game_mode_exited = ("Game Mode successfully exited", "Game mode failed to exited") + found_lines = ("Expected log lines were found", "Expected log lines were not found") +# fmt: on + + +class LogLines: + expected_lines = ["Greetings from the first script", "Greetings from the second script"] + + +def ScriptCanvas_TwoComponents(): + """ + Summary: + A test entity contains two Script Canvas components with different unique script canvas files. + Each of these files will have a print node set to activate on graph start. + + Expected Behavior: + When game mode is entered, two unique strings should be printed out to the console + + Test Steps: + 1) Create level + 2) Create entity with SC components + 3) Start Tracer + 4) Enter game mode + 5) Wait for expected lines to be found + 6) Report if expected lines were found + 7) Exit game mode + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + import os + + from utils import TestHelper as helper + import hydra_editor_utils as hydra + from utils import Report + from utils import Tracer + import azlmbr.legacy.general as general + import azlmbr.math as math + import azlmbr.asset as asset + import azlmbr.bus as bus + + LEVEL_NAME = "tmp_level" + ASSET_1 = os.path.join("scriptcanvas", "ScriptCanvas_TwoComponents0.scriptcanvas") + ASSET_2 = os.path.join("scriptcanvas", "ScriptCanvas_TwoComponents1.scriptcanvas") + WAIT_TIME = 3.0 # SECONDS + + def get_asset(asset_path): + return asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", asset_path, math.Uuid(), False) + + def locate_expected_lines(): + found_lines = [] + for printInfo in section_tracer.prints: + found_lines.append(printInfo.message.strip()) + + return all(line in found_lines for line in LogLines.expected_lines) + + # 1) Create level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Create entity with SC components + position = math.Vector3(512.0, 512.0, 32.0) + test_entity = hydra.Entity("test_entity") + test_entity.create_entity(position, ["Script Canvas", "Script Canvas"]) + test_entity.get_set_test(0, "Script Canvas Asset|Script Canvas Asset", get_asset(ASSET_1)) + test_entity.get_set_test(1, "Script Canvas Asset|Script Canvas Asset", get_asset(ASSET_2)) + + # 3) Start Tracer + with Tracer() as section_tracer: + + # 4) Enter game mode + helper.enter_game_mode(Tests.game_mode_entered) + + # 5) Wait for expected lines to be found + helper.wait_for_condition(locate_expected_lines, WAIT_TIME) + + # 6) Report if expected lines were found + Report.result(Tests.found_lines, locate_expected_lines()) + + # 7) Exit game mode + helper.exit_game_mode(Tests.game_mode_exited) + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(ScriptCanvas_TwoComponents) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_TwoEntities.py b/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_TwoEntities.py new file mode 100644 index 0000000000..401e6c0271 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/ScriptCanvas_TwoEntities.py @@ -0,0 +1,107 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92563191 +Test Case Title: Two Entities can use the same Graph asset successfully at RunTime +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92563191 +""" + + +# fmt: off +class Tests(): + level_created = ("New level created", "New level not created") + game_mode_entered = ("Game Mode successfully entered", "Game mode failed to enter") + game_mode_exited = ("Game Mode successfully exited", "Game mode failed to exited") + found_lines = ("Expected log lines were found", "Expected log lines were not found") +# fmt: on + + +def ScriptCanvas_TwoEntities(): + """ + Summary: + Two Entities can use the same Graph asset successfully at RunTime. The script canvas asset + attached to the enties will print the respective entity names. + + Expected Behavior: + When game mode is entered, respective strings of different entities should be printed. + + Test Steps: + 1) Create temp level + 2) Create two new entities with different names + 3) Set ScriptCanvas asset to both the entities + 4) Enter/Exit game mode and verify log lines + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + import os + + from utils import TestHelper as helper + from utils import Tracer + import hydra_editor_utils as hydra + import azlmbr.legacy.general as general + import azlmbr.math as math + import azlmbr.asset as asset + import azlmbr.bus as bus + + LEVEL_NAME = "tmp_level" + ASSET_PATH = os.path.join("scriptcanvas", "T92563191_test.scriptcanvas") + EXPECTED_LINES = ["Entity Name: test_entity_1", "Entity Name: test_entity_2"] + WAIT_TIME = 0.5 # SECONDS + + def get_asset(asset_path): + return asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", asset_path, math.Uuid(), False) + + # 1) Create temp level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Create two new entities with different names + position = math.Vector3(512.0, 512.0, 32.0) + test_entity_1 = hydra.Entity("test_entity_1") + test_entity_1.create_entity(position, ["Script Canvas"]) + + test_entity_2 = hydra.Entity("test_entity_2") + test_entity_2.create_entity(position, ["Script Canvas"]) + + # 3) Set ScriptCanvas asset to both the entities + test_entity_1.get_set_test(0, "Script Canvas Asset|Script Canvas Asset", get_asset(ASSET_PATH)) + test_entity_2.get_set_test(0, "Script Canvas Asset|Script Canvas Asset", get_asset(ASSET_PATH)) + + # 4) Enter/Exit game mode and verify log lines + with Tracer() as section_tracer: + + helper.enter_game_mode(Tests.game_mode_entered) + # wait for WAIT_TIME to let the script print strings + general.idle_wait(WAIT_TIME) + helper.exit_game_mode(Tests.game_mode_exited) + + found_lines = [printInfo.message.strip() for printInfo in section_tracer.prints] + result = all(line in found_lines for line in EXPECTED_LINES) + + Report.result(Tests.found_lines, result) + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + from utils import Report + + Report.start_test(ScriptCanvas_TwoEntities) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/ScriptEvents_SendReceiveAcrossMultiple.py b/AutomatedTesting/Gem/PythonTests/scripting/ScriptEvents_SendReceiveAcrossMultiple.py new file mode 100644 index 0000000000..d671229cdf --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/ScriptEvents_SendReceiveAcrossMultiple.py @@ -0,0 +1,120 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92567321 +Test Case Title: Script Events: Can send and receive a script event across multiple entities successfully +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92567321 +""" + + +# fmt: off +class Tests(): + level_created = ("Successfully created temporary level", "Failed to create temporary level") + entitya_created = ("Successfully created EntityA", "Failed to create EntityA") + entityb_created = ("Successfully created EntityB", "Failed to create EntityB") + enter_game_mode = ("Successfully entered game mode", "Failed to enter game mode") + lines_found = ("Successfully found expected message", "Failed to find expected message") + exit_game_mode = ("Successfully exited game mode", "Failed to exit game mode") +# fmt: on + + +def ScriptEvents_SendReceiveAcrossMultiple(): + """ + Summary: + EntityA and EntityB will be created in a level. Attached to both will be a Script Canvas component. The Script Event created for the test will be sent from EntityA to EntityB. + + Expected Behavior: + The output of the Script Event should be printed to the console + + Test Steps: + 1) Create test level + 2) Create EntityA/EntityB (add scriptcanvas files part of entity setup) + 3) Start Tracer + 4) Enter Game Mode + 5) Read for line + 6) Exit Game Mode + + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + import os + + from editor_entity_utils import EditorEntity as Entity + from utils import Report + from utils import TestHelper as helper + from utils import Tracer + + import azlmbr.legacy.general as general + + LEVEL_NAME = "tmp_level" + WAIT_TIME = 3.0 + ASSET_PREFIX = "T92567321" + asset_paths = { + "event": os.path.join("TestAssets", f"{ASSET_PREFIX}.scriptevents"), + "assetA": os.path.join("ScriptCanvas", f"{ASSET_PREFIX}A.scriptcanvas"), + "assetB": os.path.join("ScriptCanvas", f"{ASSET_PREFIX}B.scriptcanvas"), + } + sc_for_entities = { + "EntityA": asset_paths["assetA"], + "EntityB": asset_paths["assetB"] + } + EXPECTED_LINES = ["Incoming Message Received"] + + def get_asset(asset_path): + return azlmbr.asset.AssetCatalogRequestBus(azlmbr.bus.Broadcast, "GetAssetIdByPath", asset_path, azlmbr.math.Uuid(), False) + + def create_editor_entity(name, sc_asset): + entity = Entity.create_editor_entity(name) + sc_comp = entity.add_component("Script Canvas") + sc_comp.set_component_property_value("Script Canvas Asset|Script Canvas Asset", get_asset(sc_asset)) + Report.critical_result(Tests.__dict__[name.lower()+"_created"], entity.id.isValid()) + + def locate_expected_lines(line_list: list): + found_lines = [printInfo.message.strip() for printInfo in section_tracer.prints] + + return all(line in found_lines for line in line_list) + + # 1) Create temp level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Create EntityA/EntityB + for key in sc_for_entities.keys(): + create_editor_entity(key, sc_for_entities[key]) + + # 3) Start Tracer + with Tracer() as section_tracer: + + # 4) Enter Game Mode + helper.enter_game_mode(Tests.enter_game_mode) + + # 5) Read for line + lines_located = helper.wait_for_condition(lambda: locate_expected_lines(EXPECTED_LINES), WAIT_TIME) + Report.result(Tests.lines_found, lines_located) + + # 6) Exit Game Mode + helper.exit_game_mode(Tests.exit_game_mode) + + +if __name__ == "__main__": + import ImportPathHelper as imports + imports.init() + + from utils import Report + + Report.start_test(ScriptEvents_SendReceiveAcrossMultiple) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/ScriptEvents_SendReceiveSuccessfully.py b/AutomatedTesting/Gem/PythonTests/scripting/ScriptEvents_SendReceiveSuccessfully.py new file mode 100644 index 0000000000..b5e26d14ae --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/ScriptEvents_SendReceiveSuccessfully.py @@ -0,0 +1,110 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92567320 +Test Case Title: Script Events: Can send and receive a script event successfully +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92567320 +""" + + +# fmt: off +class Tests(): + level_created = ("Successfully created temporary level", "Failed to create temporary level") + entity_created = ("Successfully created test entity", "Failed to create test entity") + enter_game_mode = ("Successfully entered game mode", "Failed to enter game mode") + lines_found = ("Successfully found expected message", "Failed to find expected message") + exit_game_mode = ("Successfully exited game mode", "Failed to exit game mode") +# fmt: on + + +def ScriptEvents_SendReceiveSuccessfully(): + """ + Summary: + An entity exists in the level that contains a Script Canvas component. In the graph is both a Send Event + and a Receive Event. + + Expected Behavior: + After entering game mode the graph on the entity should print an expected message to the console + + Test Steps: + 1) Create test level + 2) Create test entity + 3) Start Tracer + 4) Enter Game Mode + 5) Read for line + 6) Exit Game Mode + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + import os + from editor_entity_utils import EditorEntity as Entity + from utils import Report + from utils import TestHelper as helper + from utils import Tracer + + import azlmbr.legacy.general as general + import azlmbr.asset as asset + import azlmbr.math as math + import azlmbr.bus as bus + + LEVEL_NAME = "tmp_level" + WAIT_TIME = 3.0 # SECONDS + EXPECTED_LINES = ["T92567320: Message Received"] + SC_ASSET_PATH = os.path.join("ScriptCanvas", "T92567320.scriptcanvas") + + def create_editor_entity(name, sc_asset): + entity = Entity.create_editor_entity(name) + sc_comp = entity.add_component("Script Canvas") + asset_id = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", sc_asset, math.Uuid(), False) + sc_comp.set_component_property_value("Script Canvas Asset|Script Canvas Asset", asset_id) + Report.critical_result(Tests.entity_created, entity.id.isValid()) + + def locate_expected_lines(line_list: list): + found_lines = [printInfo.message.strip() for printInfo in section_tracer.prints] + + return all(line in found_lines for line in line_list) + + # 1) Create temp level + general.idle_enable(True) + result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True) + Report.critical_result(Tests.level_created, result == 0) + helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME) + general.close_pane("Error Report") + + # 2) Create test entity + create_editor_entity("TestEntity", SC_ASSET_PATH) + + # 3) Start Tracer + with Tracer() as section_tracer: + + # 4) Enter Game Mode + helper.enter_game_mode(Tests.enter_game_mode) + + # 5) Read for line + lines_located = helper.wait_for_condition(lambda: locate_expected_lines(EXPECTED_LINES), WAIT_TIME) + Report.result(Tests.lines_found, lines_located) + + # 6) Exit Game Mode + helper.exit_game_mode(Tests.exit_game_mode) + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(ScriptEvents_SendReceiveSuccessfully) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/TestSuite_Active.py b/AutomatedTesting/Gem/PythonTests/scripting/TestSuite_Active.py index 8c34f29ebf..d87f2986bf 100755 --- a/AutomatedTesting/Gem/PythonTests/scripting/TestSuite_Active.py +++ b/AutomatedTesting/Gem/PythonTests/scripting/TestSuite_Active.py @@ -12,22 +12,243 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import pytest import os import sys +sys.path.append(os.path.dirname(__file__)) +import ImportPathHelper as imports +imports.init() + +import hydra_test_utils as hydra +import ly_test_tools.environment.file_system as file_system from ly_test_tools import LAUNCHERS +from base import TestAutomationBase -sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../automatedtesting_shared') +TEST_DIRECTORY = os.path.dirname(__file__) -from base import TestAutomationBase @pytest.mark.SUITE_periodic @pytest.mark.parametrize("launcher_platform", ['windows_editor']) @pytest.mark.parametrize("project", ["AutomatedTesting"]) class TestAutomation(TestAutomationBase): - + @pytest.mark.test_case_id("C1702834", "C1702823") + def test_Opening_Closing_Pane(self, request, workspace, editor, launcher_platform): + from . import Opening_Closing_Pane as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("C1702824") def test_Docking_Pane(self, request, workspace, editor, launcher_platform): from . import Docking_Pane as test_module self._run_test(request, workspace, editor, test_module) + @pytest.mark.test_case_id("C1702829") def test_Resizing_Pane(self, request, workspace, editor, launcher_platform): from . import Resizing_Pane as test_module self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92563190") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_ScriptCanvas_TwoComponents(self, request, workspace, editor, launcher_platform, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import ScriptCanvas_TwoComponents as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92562986") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_ScriptCanvas_ChangingAssets(self, request, workspace, editor, launcher_platform, project, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import ScriptCanvas_ChangingAssets as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92569079", "T92569081") + def test_Graph_ZoomInZoomOut(self, request, workspace, editor, launcher_platform): + from . import Graph_ZoomInZoomOut as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92568940") + def test_NodePalette_SelectNode(self, request, workspace, editor, launcher_platform): + from . import NodePalette_SelectNode as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92569253") + @pytest.mark.test_case_id("T92569254") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_OnEntityActivatedDeactivated_PrintMessage(self, request, workspace, editor, launcher_platform, project, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import OnEntityActivatedDeactivated_PrintMessage as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92562993") + def test_NodePalette_ClearSelection(self, request, workspace, editor, launcher_platform, project): + from . import NodePalette_ClearSelection as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92563191") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_ScriptCanvas_TwoEntities(self, request, workspace, editor, launcher_platform, project, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import ScriptCanvas_TwoEntities as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92569013") + def test_AssetEditor_CreateScriptEventFile(self, request, workspace, editor, launcher_platform, project): + def teardown(): + file_system.delete( + [os.path.join(workspace.paths.project(), "ScriptCanvas", "test_file.scriptevent")], True, True + ) + request.addfinalizer(teardown) + file_system.delete( + [os.path.join(workspace.paths.project(), "ScriptCanvas", "test_file.scriptevent")], True, True + ) + from . import AssetEditor_CreateScriptEventFile as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92569165", "T92569167", "T92569168", "T92569170") + def test_Toggle_ScriptCanvasTools(self, request, workspace, editor, launcher_platform): + from . import Toggle_ScriptCanvasTools as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92568982") + def test_NodeInspector_RenameVariable(self, request, workspace, editor, launcher_platform, project): + from . import NodeInspector_RenameVariable as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92569137") + def test_Debugging_TargetMultipleGraphs(self, request, workspace, editor, launcher_platform, project): + from . import Debugging_TargetMultipleGraphs as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92568856") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_Debugging_TargetMultipleEntities(self, request, workspace, editor, launcher_platform, project, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import Debugging_TargetMultipleEntities as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92569049", "T92569051") + def test_EditMenu_UndoRedo(self, request, workspace, editor, launcher_platform, project): + from . import EditMenu_UndoRedo as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("C1702825", "C1702831") + def test_UnDockedPane_CloseSCWindow(self, request, workspace, editor, launcher_platform): + from . import UnDockedPane_CloseSCWindow as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92562978") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_Entity_AddScriptCanvasComponent(self, request, workspace, editor, launcher_platform, project, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import Entity_AddScriptCanvasComponent as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("C1702821", "C1702832") + def test_Pane_RetainOnSCRestart(self, request, workspace, editor, launcher_platform): + from . import Pane_RetainOnSCRestart as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92567321") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_ScriptEvents_SendReceiveAcrossMultiple(self, request, workspace, editor, launcher_platform, project, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import ScriptEvents_SendReceiveAcrossMultiple as test_module + self._run_test(request, workspace, editor, test_module) + + @pytest.mark.test_case_id("T92567320") + @pytest.mark.parametrize("level", ["tmp_level"]) + def test_ScriptEvents_SendReceiveSuccessfully(self, request, workspace, editor, launcher_platform, project, level): + def teardown(): + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + request.addfinalizer(teardown) + file_system.delete([os.path.join(workspace.paths.project(), "Levels", level)], True, True) + from . import ScriptEvents_SendReceiveSuccessfully as test_module + self._run_test(request, workspace, editor, test_module) + +# NOTE: We had to use hydra_test_utils.py, as TestAutomationBase run_test method +# fails because of pyside_utils import +@pytest.mark.SUITE_periodic +@pytest.mark.parametrize("launcher_platform", ["windows_editor"]) +@pytest.mark.parametrize("project", ["AutomatedTesting"]) +class TestScriptCanvasTests(object): + """ + The following tests use hydra_test_utils.py to launch the editor and validate the results. + """ + + @pytest.mark.test_case_id("T92569037", "T92569039") + def test_FileMenu_New_Open(self, request, editor, launcher_platform): + expected_lines = [ + "File->New action working as expected: True", + "File->Open action working as expected: True", + ] + hydra.launch_and_validate_results( + request, TEST_DIRECTORY, editor, "FileMenu_New_Open.py", expected_lines, auto_test_mode=False, timeout=60, + ) + + @pytest.mark.test_case_id("T92568942") + def test_AssetEditor_NewScriptEvent(self, request, editor, launcher_platform): + expected_lines = [ + "New Script event action found: True", + "Asset Editor opened: True", + "Asset Editor created with new asset: True", + "New Script event created in Asset Editor: True", + ] + hydra.launch_and_validate_results( + request, + TEST_DIRECTORY, + editor, + "AssetEditor_NewScriptEvent.py", + expected_lines, + auto_test_mode=False, + timeout=60, + ) + + @pytest.mark.test_case_id("T92563068", "T92563070") + def test_GraphClose_SavePrompt(self, request, editor, launcher_platform): + expected_lines = [ + "New graph created: True", + "Save prompt opened as expected: True", + "Close button worked as expected: True", + ] + hydra.launch_and_validate_results( + request, + TEST_DIRECTORY, + editor, + "GraphClose_SavePrompt.py", + expected_lines, + auto_test_mode=False, + timeout=60, + ) + + @pytest.mark.test_case_id("T92564789", "T92568873") + def test_VariableManager_CreateDeleteVars(self, request, editor, launcher_platform): + var_types = ["Boolean", "Color", "EntityID", "Number", "String", "Transform", "Vector2", "Vector3", "Vector4"] + expected_lines = [f"Success: {var_type} variable is created" for var_type in var_types] + expected_lines.extend([f"Success: {var_type} variable is deleted" for var_type in var_types]) + hydra.launch_and_validate_results( + request, + TEST_DIRECTORY, + editor, + "VariableManager_CreateDeleteVars.py", + expected_lines, + auto_test_mode=False, + timeout=60, + ) \ No newline at end of file diff --git a/AutomatedTesting/Gem/PythonTests/scripting/Toggle_ScriptCanvasTools.py b/AutomatedTesting/Gem/PythonTests/scripting/Toggle_ScriptCanvasTools.py new file mode 100644 index 0000000000..4024e28277 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/Toggle_ScriptCanvasTools.py @@ -0,0 +1,137 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: C92569165, C92569167, C92569168, C92569170 +Test Case Title: Tools > Node Palette toggles the Node Palette + Tools > Node Inspector toggles the Node Inspector + Tools > Bookmarks toggles the Bookmarks + Tools > Variable Manager toggles the Variable Manager + +URLs of the test case: https://testrail.agscollab.com/index.php?/cases/view/92569165 + https://testrail.agscollab.com/index.php?/cases/view/92569167 + https://testrail.agscollab.com/index.php?/cases/view/92569168 + https://testrail.agscollab.com/index.php?/cases/view/92569170 +""" + + +# fmt: off +class Tests(): + node_palette_opened = ("NodePalette is opened successfully", "Failed to open NodePalette") + node_inspector_opened = ("NodeInspector is opened successfully", "Failed to open NodeInspector") + bookmark_opened = ("Bookmarks is opened successfully", "Failed to open Bookmarks") + variable_manager_opened = ("VariableManager is opened successfully", "Failed to open VariableManager") + node_palette_closed_by_start = ("NodePalette is closed successfully", "Failed to close NodePalette") + node_inspector_closed_by_start = ("NodeInspector is closed successfully", "Failed to close NodeInspector") + bookmark_closed_by_start = ("Bookmarks is closed successfully", "Failed to close Bookmarks") + variable_manager_closed_by_start = ("VariableManager is closed successfully", "Failed to close VariableManager") + node_palette_closed_by_end = ("NodePalette is closed successfully", "Failed to close NodePalette") + node_inspector_closed_by_end = ("NodeInspector is closed successfully", "Failed to close NodeInspector") + bookmark_closed_by_end = ("Bookmarks is closed successfully", "Failed to close Bookmarks") + variable_manager_closed_by_end = ("VariableManager is closed successfully", "Failed to close VariableManager") +# fmt: on + + +def Toggle_ScriptCanvasTools(): + """ + Summary: + Toggle Node Palette, Node Inspector, Bookmarks and Variable Manager in Script Canvas. + Make sure each pane opens and closes successfully. + + Expected Behavior: + Each pane opens and closes successfully. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Make sure Node Palette, Node Inspector, Bookmarks and Variable Manager panes are closed in Script Canvas window + 3) Open Node Palette, Node Inspector, Bookmarks and Variable Manager in Script Canvas window + 4) Close Node Palette, Node Inspector, Bookmarks and Variable Manager in Script Canvas window + 5) Restore default layout + 6) Close Script Canvas window + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + from utils import Report + from utils import TestHelper as helper + import pyside_utils + + # Open 3D Engine imports + import azlmbr.legacy.general as general + + # Pyside imports + from PySide2 import QtWidgets + + def click_menu_option(window, option_text): + action = pyside_utils.find_child_by_pattern(window, {"text": option_text, "type": QtWidgets.QAction}) + action.trigger() + + def find_pane(window, pane_name): + return window.findChild(QtWidgets.QDockWidget, pane_name) + + def close_tool(window, pane_widget, test_tuple): + pane = find_pane(window, pane_widget) + pane.close() + Report.result(test_tuple, not pane.isVisible()) + + def open_tool(window, pane_widget, tool, test_tuple): + pane = find_pane(window, pane_widget) + if not pane.isVisible(): + click_menu_option(window, tool) + pane = find_pane(window, pane_widget) + Report.result(test_tuple, pane.isVisible()) + + # Test starts here + general.idle_enable(True) + + # 1) Open Script Canvas window (Tools > Script Canvas) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + + # 2) Make sure Node Palette, Node Inspector, Bookmarks and Variable Manager panes are closed in Script Canvas window + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + close_tool(sc, "NodePalette", Tests.node_palette_closed_by_start) + close_tool(sc, "NodeInspector", Tests.node_inspector_closed_by_start) + close_tool(sc, "BookmarkDockWidget", Tests.bookmark_closed_by_start) + close_tool(sc, "VariableManager", Tests.variable_manager_closed_by_start) + + # 3) Open Node Palette, Node Inspector, Bookmarks and Variable Manager in Script Canvas window + open_tool(sc, "NodePalette", "Node Palette", Tests.node_palette_opened) + open_tool(sc, "NodeInspector", "Node Inspector", Tests.node_inspector_opened) + open_tool(sc, "BookmarkDockWidget", "Bookmarks", Tests.bookmark_opened) + open_tool(sc, "VariableManager", "Variable Manager", Tests.variable_manager_opened) + + # 4) Close Node Palette, Node Inspector, Bookmarks and Variable Manager in Script Canvas window + close_tool(sc, "NodePalette", Tests.node_palette_closed_by_end) + close_tool(sc, "NodeInspector", Tests.node_inspector_closed_by_end) + close_tool(sc, "BookmarkDockWidget", Tests.bookmark_closed_by_end) + close_tool(sc, "VariableManager", Tests.variable_manager_closed_by_end) + + # 5) Restore default layout + # Need this step to restore to default in case of test failure + click_menu_option(sc, "Restore Default Layout") + + # 6) Close Script Canvas window + sc.close() + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(Toggle_ScriptCanvasTools) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/UnDockedPane_CloseSCWindow.py b/AutomatedTesting/Gem/PythonTests/scripting/UnDockedPane_CloseSCWindow.py new file mode 100644 index 0000000000..875f28ec95 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/UnDockedPane_CloseSCWindow.py @@ -0,0 +1,128 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: C1702825 // C1702831 +Test Case Title: Undocking // Closing script canvas with the pane floating +URLs of the test case: https://testrail.agscollab.com/index.php?/cases/view/1702825 & + https://testrail.agscollab.com/index.php?/cases/view/1702831 +""" + + +# fmt: off +class Tests(): + undock_pane = ("Pane is undocked successfully", "Failed to undock pane") + close_sc_window = ("Script Canvas window is closed", "Failed to close Script Canvas window") + pane_closed = ("Pane is closed successfully", "Failed to close the pane") +# fmt: on + + +def UnDockedPane_CloseSCWindow(): + """ + Summary: + The Script Canvas window is opened with one of the pane undocked. + Verify if undocked pane closes upon closing Script canvas window. + + Expected Behavior: + The undocked pane closes when Script Canvas window closed. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Undock Node Palette pane + 3) Connect to Pane visibility signal emitter to verify pane closed + 4) Close Script Canvas window + 5) Restore default layout + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + # Helper imports + from utils import Report + from utils import TestHelper as helper + import pyside_utils + + # Open 3D Engine imports + import azlmbr.legacy.general as general + + # Pyside imports + from PySide2 import QtWidgets + + TEST_PANE = "NodePalette" # Chosen most commonly used pane + + def click_menu_option(window, option_text): + action = pyside_utils.find_child_by_pattern(window, {"text": option_text, "type": QtWidgets.QAction}) + action.trigger() + + def find_pane(window, pane_name): + return window.findChild(QtWidgets.QDockWidget, pane_name) + + def on_top_level_changed(): + # This function has test condition always True since it gets emitted only when condition satisfied + Report.result(Tests.undock_pane, True) + + def on_pane_closed(): + # This function has test condition always True since it gets emitted only when condition satisfied + Report.result(Tests.pane_closed, True) + + # Test starts here + general.idle_enable(True) + + # 1) Open Script Canvas window (Tools > Script Canvas) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + + # 2) Undock Node Palette pane + # Make sure Node Palette pane is opened + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + pane = find_pane(sc, TEST_PANE) + if not pane.isVisible(): + click_menu_option(sc, "Node Palette") + pane = find_pane(sc, TEST_PANE) # New reference + + # We drag/drop pane over the graph since it doesn't allow docking, so this will undock it + try: + graph = find_pane(sc, "GraphCanvasEditorCentralWidget") + try: + pane.topLevelChanged.connect(on_top_level_changed) + pyside_utils.drag_and_drop(pane, graph) + finally: + pane.topLevelChanged.disconnect(on_top_level_changed) + + # 3) Connect to Pane visibility signal emitter to verify pane closed + # No need to disconnect this since pane widget gets deleted when SC window closed + pane.visibilityChanged.connect(on_pane_closed) + + # 4) Close Script Canvas window + sc.close() + is_sc_visible = helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 2.0) + Report.result(Tests.close_sc_window, not is_sc_visible) + + finally: + # 5) Restore default layout + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0) + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + click_menu_option(sc, "Restore Default Layout") + sc.close() + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + + from utils import Report + + Report.start_test(UnDockedPane_CloseSCWindow) diff --git a/AutomatedTesting/Gem/PythonTests/scripting/VariableManager_CreateDeleteVars.py b/AutomatedTesting/Gem/PythonTests/scripting/VariableManager_CreateDeleteVars.py new file mode 100644 index 0000000000..6facc324d4 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/scripting/VariableManager_CreateDeleteVars.py @@ -0,0 +1,123 @@ +""" +All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +its licensors. + +For complete copyright and license terms please see the LICENSE at the root of this +distribution (the "License"). All use of this software is governed by the License, +or, if provided, by the license below or the license accompanying this file. Do not +remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +Test case ID: T92564789 +Test Case Title: Each Variable type can be created +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92564789 +Test case ID: T92568873 +Test Case Title: Each Variable type can be deleted +URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92568873 +""" + + +def VariableManager_CreateDeleteVars(): + """ + Summary: + Each variable type can be created and deleted in variable manager. + + Expected Behavior: + Each variable type can be created and deleted in variable manager. + + Test Steps: + 1) Open Script Canvas window (Tools > Script Canvas) + 2) Get the SC window object + 3) Open Variable Manager if not opened already + 4) Create Graph + 5) Create variable of each type and verify if it is created + 6) Delete each type of variable and verify if it is deleted + 7) Close SC window + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + from PySide2 import QtWidgets, QtCore, QtTest + + from PySide2.QtCore import Qt + + from utils import TestHelper as helper + + import azlmbr.legacy.general as general + + import pyside_utils + + def generate_test_tuple(var_type, action): + return (f"{var_type} variable is {action}d", f"{var_type} variable is not {action}d") + + # 1) Open Script Canvas window + general.idle_enable(True) + general.open_pane("Script Canvas") + helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 10.0) + + # 2) Get the SC window object + editor_window = pyside_utils.get_editor_main_window() + sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas") + + # 3) Open Variable Manager if not opened already + if sc.findChild(QtWidgets.QDockWidget, "VariableManager") is None: + action = pyside_utils.find_child_by_pattern(sc, {"text": "Variable Manager", "type": QtWidgets.QAction}) + action.trigger() + variable_manager = sc.findChild(QtWidgets.QDockWidget, "VariableManager") + + # 4) Create Graph + action = pyside_utils.find_child_by_pattern(sc, {"objectName": "action_New_Script", "type": QtWidgets.QAction}) + action.trigger() + + graph_vars = variable_manager.findChild(QtWidgets.QTableView, "graphVariables") + + var_types = ["Boolean", "Color", "EntityID", "Number", "String", "Transform", "Vector2", "Vector3", "Vector4"] + + # 5) Create variable of each type and verify if it is created + for index, var_type in enumerate(var_types): + # Create new variable + add_button = variable_manager.findChild(QtWidgets.QPushButton, "addButton") + add_button.click() # Click on Create Variable button + # Select variable type + table_view = variable_manager.findChild(QtWidgets.QTableView, "variablePalette") + model_index = pyside_utils.find_child_by_pattern(table_view, var_type) + # Click on it to create variable + pyside_utils.item_view_index_mouse_click(table_view, model_index) + # Verify if the variable is created + # NOTE: To check if variable of a type is created, we are checking 1) rowcount + # 2) If we have row with variable "Variable " + # 3) Type of variable, which is next column of the variable name + result = graph_vars.model().rowCount(QtCore.QModelIndex()) == ( + index + 1 + ) # since we added 1 variable, rowcount will increase by 1 + var_mi = pyside_utils.find_child_by_pattern(graph_vars, f"Variable {index+1}") + result = result and (var_mi is not None) and (var_mi.siblingAtColumn(1).data(Qt.DisplayRole) == var_type) + Report.result(generate_test_tuple(var_type, "create"), result) + + # 6) Delete each type of variable and verify if it is deleted + for index, var_type in enumerate(var_types): + # Delete variable and verify if its deleted + # NOTE: To check if variable of a type is deleted, we are checking rowcount + var_mi = pyside_utils.find_child_by_pattern(graph_vars, f"Variable {index+1}") + pyside_utils.item_view_index_mouse_click(graph_vars, var_mi) + QtTest.QTest.keyClick(graph_vars, Qt.Key_Delete, Qt.NoModifier) + # since variable is deleted, rowcount will decrease by 1 + result = graph_vars.model().rowCount(QtCore.QModelIndex()) == (len(var_types) - (index + 1)) + Report.result(generate_test_tuple(var_type, "delete"), result) + + # 7) Close SC window + general.close_pane("Script Canvas") + + +if __name__ == "__main__": + import ImportPathHelper as imports + + imports.init() + from utils import Report + + Report.start_test(VariableManager_CreateDeleteVars) diff --git a/AutomatedTesting/Levels/Physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.ly b/AutomatedTesting/Levels/Physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.ly index ba141251d5..d618bf1873 100644 --- a/AutomatedTesting/Levels/Physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.ly +++ b/AutomatedTesting/Levels/Physics/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain/C24308873_CylinderShapeCollider_CollidesWithPhysXTerrain.ly @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:231d5ac32c95334eeb1cbf77ea0bceae1d8010de3290dfdbd991abb46d18bae6 -size 6844 +oid sha256:83af66a6db4ff2b4df7212099b661a96668cfb326d8984e41b16506ec0062141 +size 5844 diff --git a/AutomatedTesting/Registry/C14195074_ScriptCanvas_PostUpdateEvent.setreg b/AutomatedTesting/Registry/C14195074_ScriptCanvas_PostUpdateEvent.setreg_override similarity index 100% rename from AutomatedTesting/Registry/C14195074_ScriptCanvas_PostUpdateEvent.setreg rename to AutomatedTesting/Registry/C14195074_ScriptCanvas_PostUpdateEvent.setreg_override diff --git a/AutomatedTesting/Registry/C14902097_ScriptCanvas_PreUpdateEvent.setreg b/AutomatedTesting/Registry/C14902097_ScriptCanvas_PreUpdateEvent.setreg_override similarity index 100% rename from AutomatedTesting/Registry/C14902097_ScriptCanvas_PreUpdateEvent.setreg rename to AutomatedTesting/Registry/C14902097_ScriptCanvas_PreUpdateEvent.setreg_override diff --git a/AutomatedTesting/Registry/C3510644_Collider_CollisionGroups.setreg b/AutomatedTesting/Registry/C3510644_Collider_CollisionGroups.setreg_override similarity index 100% rename from AutomatedTesting/Registry/C3510644_Collider_CollisionGroups.setreg rename to AutomatedTesting/Registry/C3510644_Collider_CollisionGroups.setreg_override diff --git a/AutomatedTesting/Registry/C4976227_Collider_NewGroup.setreg b/AutomatedTesting/Registry/C4976227_Collider_NewGroup.setreg_override similarity index 100% rename from AutomatedTesting/Registry/C4976227_Collider_NewGroup.setreg rename to AutomatedTesting/Registry/C4976227_Collider_NewGroup.setreg_override diff --git a/AutomatedTesting/Registry/C4976244_Collider_SameGroupSameLayerCollision.setreg b/AutomatedTesting/Registry/C4976244_Collider_SameGroupSameLayerCollision.setreg_override similarity index 100% rename from AutomatedTesting/Registry/C4976244_Collider_SameGroupSameLayerCollision.setreg rename to AutomatedTesting/Registry/C4976244_Collider_SameGroupSameLayerCollision.setreg_override diff --git a/AutomatedTesting/Registry/C4976245_PhysXCollider_CollisionLayerTest.setreg b/AutomatedTesting/Registry/C4976245_PhysXCollider_CollisionLayerTest.setreg_override similarity index 100% rename from AutomatedTesting/Registry/C4976245_PhysXCollider_CollisionLayerTest.setreg rename to AutomatedTesting/Registry/C4976245_PhysXCollider_CollisionLayerTest.setreg_override diff --git a/AutomatedTesting/Registry/C4982593_PhysXCollider_CollisionLayer.setreg b/AutomatedTesting/Registry/C4982593_PhysXCollider_CollisionLayer.setreg_override similarity index 100% rename from AutomatedTesting/Registry/C4982593_PhysXCollider_CollisionLayer.setreg rename to AutomatedTesting/Registry/C4982593_PhysXCollider_CollisionLayer.setreg_override diff --git a/AutomatedTesting/Registry/assets_scan_folders.setreg b/AutomatedTesting/Registry/assets_scan_folders.setreg index 5394d381a3..91061f3337 100644 --- a/AutomatedTesting/Registry/assets_scan_folders.setreg +++ b/AutomatedTesting/Registry/assets_scan_folders.setreg @@ -38,6 +38,13 @@ "Gems/PrimitiveAssets" ] }, + "MaterialEditor": + { + "SourcePaths": + [ + "Gems/Atom/Tools/MaterialEditor" + ] + }, "UiBasics": { "SourcePaths": diff --git a/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/activator.scriptcanvas b/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/activator.scriptcanvas new file mode 100644 index 0000000000..89d86f0d54 --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/activator.scriptcanvas @@ -0,0 +1,778 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/controller.scriptcanvas b/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/controller.scriptcanvas new file mode 100644 index 0000000000..83a899798e --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/controller.scriptcanvas @@ -0,0 +1,1865 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/deactivator.scriptcanvas b/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/deactivator.scriptcanvas new file mode 100644 index 0000000000..ca98ee303a --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/OnEntityActivatedScripts/deactivator.scriptcanvas @@ -0,0 +1,766 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/ScriptCanvas_TwoComponents0.scriptcanvas b/AutomatedTesting/ScriptCanvas/ScriptCanvas_TwoComponents0.scriptcanvas new file mode 100644 index 0000000000..af3afead19 --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/ScriptCanvas_TwoComponents0.scriptcanvas @@ -0,0 +1,365 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/ScriptCanvas_TwoComponents1.scriptcanvas b/AutomatedTesting/ScriptCanvas/ScriptCanvas_TwoComponents1.scriptcanvas new file mode 100644 index 0000000000..0a16717520 --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/ScriptCanvas_TwoComponents1.scriptcanvas @@ -0,0 +1,365 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/T92563191_test.scriptcanvas b/AutomatedTesting/ScriptCanvas/T92563191_test.scriptcanvas new file mode 100644 index 0000000000..f0797739a5 --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/T92563191_test.scriptcanvas @@ -0,0 +1,750 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/T92567320.scriptcanvas b/AutomatedTesting/ScriptCanvas/T92567320.scriptcanvas new file mode 100644 index 0000000000..d509442435 --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/T92567320.scriptcanvas @@ -0,0 +1,1266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/T92567321A.scriptcanvas b/AutomatedTesting/ScriptCanvas/T92567321A.scriptcanvas new file mode 100644 index 0000000000..644a5daa17 --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/T92567321A.scriptcanvas @@ -0,0 +1,778 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ScriptCanvas/T92567321B.scriptcanvas b/AutomatedTesting/ScriptCanvas/T92567321B.scriptcanvas new file mode 100644 index 0000000000..54c83c2933 --- /dev/null +++ b/AutomatedTesting/ScriptCanvas/T92567321B.scriptcanvas @@ -0,0 +1,880 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/ShaderLib/raytracingscenesrg.srgi b/AutomatedTesting/ShaderLib/raytracingscenesrg.srgi deleted file mode 100644 index ac1d663bb8..0000000000 --- a/AutomatedTesting/ShaderLib/raytracingscenesrg.srgi +++ /dev/null @@ -1,28 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -// Please read README.md for an explanation on why scenesrg.srgi and viewsrg.srgi are -// located in this folder (And how you can optionally customize your own scenesrg.srgi -// and viewsrg.srgi in your game project). - -#include - -partial ShaderResourceGroup RayTracingSceneSrg : SRG_RayTracingScene -{ -/* Intentionally Empty. Helps define the SrgSemantic for RayTracingSceneSrg once.*/ -}; - -#define AZ_COLLECTING_PARTIAL_SRGS -#include -#undef AZ_COLLECTING_PARTIAL_SRGS diff --git a/AutomatedTesting/TestAssets/T92567320.scriptevents b/AutomatedTesting/TestAssets/T92567320.scriptevents new file mode 100644 index 0000000000..63cf20f2d0 --- /dev/null +++ b/AutomatedTesting/TestAssets/T92567320.scriptevents @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomatedTesting/TestAssets/T92567321.scriptevents b/AutomatedTesting/TestAssets/T92567321.scriptevents new file mode 100644 index 0000000000..6f9308ad02 --- /dev/null +++ b/AutomatedTesting/TestAssets/T92567321.scriptevents @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index cefbcf2ef4..ae8a7a05f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,9 @@ foreach(restricted_platform ${PAL_RESTRICTED_PLATFORMS}) endif() endforeach() -add_subdirectory(scripts) +if(NOT INSTALLED_ENGINE) + add_subdirectory(scripts) +endif() # SPEC-1417 will investigate and fix this if(NOT PAL_PLATFORM_NAME STREQUAL "Mac") @@ -125,5 +127,5 @@ if(NOT INSTALLED_ENGINE) ly_setup_o3de_install() # IMPORTANT: must be included last - include(cmake/CPack.cmake) + include(cmake/Packaging.cmake) endif() diff --git a/Code/CryEngine/CMakeLists.txt b/Code/CryEngine/CMakeLists.txt index 38fcbf4a27..96f6427268 100644 --- a/Code/CryEngine/CMakeLists.txt +++ b/Code/CryEngine/CMakeLists.txt @@ -10,5 +10,4 @@ # add_subdirectory(CryCommon) -add_subdirectory(CryFont) add_subdirectory(CrySystem) diff --git a/Code/CryEngine/CryCommon/CREVolumeObject.h b/Code/CryEngine/CryCommon/CREVolumeObject.h index d84c7b3e50..2137053a8e 100644 --- a/Code/CryEngine/CryCommon/CREVolumeObject.h +++ b/Code/CryEngine/CryCommon/CREVolumeObject.h @@ -55,7 +55,7 @@ public: Matrix34 m_matInv; Vec3 m_eyePosInWS; Vec3 m_eyePosInOS; - Plane m_volumeTraceStartPlane; + Plane_tpl m_volumeTraceStartPlane; AABB m_renderBoundsOS; bool m_viewerInsideVolume; bool m_nearPlaneIntersectsVolume; diff --git a/Code/CryEngine/CryCommon/CREWaterOcean.h b/Code/CryEngine/CryCommon/CREWaterOcean.h index 784588309f..e8ca310d41 100644 --- a/Code/CryEngine/CryCommon/CREWaterOcean.h +++ b/Code/CryEngine/CryCommon/CREWaterOcean.h @@ -25,7 +25,7 @@ public: virtual void mfPrepare(bool bCheckOverflow); virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - virtual void mfGetPlane(Plane& pl); + virtual void mfGetPlane(Plane_tpl& pl); virtual void Create(uint32 nVerticesCount, SVF_P3F_C4B_T2F* pVertices, uint32 nIndicesCount, const void* pIndices, uint32 nIndexSizeof); void ReleaseOcean(); diff --git a/Code/CryEngine/CryCommon/CREWaterVolume.h b/Code/CryEngine/CryCommon/CREWaterVolume.h index 3e7a0636e6..89102e3097 100644 --- a/Code/CryEngine/CryCommon/CREWaterVolume.h +++ b/Code/CryEngine/CryCommon/CREWaterVolume.h @@ -27,7 +27,7 @@ public: virtual ~CREWaterVolume(); virtual void mfPrepare(bool bCheckOverflow); virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - virtual void mfGetPlane(Plane& pl); + virtual void mfGetPlane(Plane_tpl& pl); virtual void mfCenter(Vec3& vCenter, CRenderObject* pObj); virtual void GetMemoryUsage(ICrySizer* pSizer) const @@ -69,7 +69,7 @@ public: Vec3 m_center; AABB m_WSBBox; - Plane m_fogPlane; + Plane_tpl m_fogPlane; float m_fogDensity; Vec3 m_fogColor; bool m_fogColorAffectedBySun; diff --git a/Code/CryEngine/CryCommon/CryEngineDecalInfo.h b/Code/CryEngine/CryCommon/CryEngineDecalInfo.h deleted file mode 100644 index f38533e341..0000000000 --- a/Code/CryEngine/CryCommon/CryEngineDecalInfo.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : declaration of struct CryEngineDecalInfo. - -// Note: -// 3D Engine and Character Animation subsystems (as well as perhaps -// some others) transfer data about the decals that need to be spawned -// via this structure. This is to avoid passing many parameters through -// each function call, and to save on copying these parameters when just -// simply passing the structure from one function to another. - -#ifndef CRYINCLUDE_CRYCOMMON_CRYENGINEDECALINFO_H -#define CRYINCLUDE_CRYCOMMON_CRYENGINEDECALINFO_H -#pragma once - -#include "Cry_Math.h" - -// Summary: -// Structure containing common parameters that describe a decal - -struct SDecalOwnerInfo -{ - SDecalOwnerInfo() { memset(this, 0, sizeof(*this)); nRenderNodeSlotId = nRenderNodeSlotSubObjectId = -1; } - struct IStatObj* GetOwner(Matrix34A& objMat); - - struct IRenderNode* pRenderNode; // Owner (decal will be attached to or wrapped around of this object) - PodArray* pDecalReceivers; - int nRenderNodeSlotId; // is set internally by 3dengine - int nRenderNodeSlotSubObjectId; // is set internally by 3dengine - int nMatID; -}; - -struct CryEngineDecalInfo -{ - SDecalOwnerInfo ownerInfo; - Vec3 vPos; // Decal position (world coordinates) - Vec3 vNormal; // Decal/face normal - float fSize; // Decal size - float fLifeTime; // Decal life time (in seconds) - float fAngle; // Angle of rotation - struct IStatObj* pIStatObj; // Decal geometry - Vec3 vHitDirection; // Direction from weapon/player position to decal position (bullet direction) - float fGrowTime, fGrowTimeAlpha;// Used for blood pools - unsigned int nGroupId; // Used for multi-component decals - bool bSkipOverlappingTest; // Always spawn decals even if there are a lot of other decals in same place - bool bAssemble; // Assemble to bigger decals if more than 1 decal is on the same place - bool bForceEdge; // force the decal to the nearest edge of the owner mesh and project it accordingly - bool bForceSingleOwner; // Do not attempt to cast the decal into the environment even if it's large enough - bool bDeferred; - uint8 sortPrio; - char szMaterialName[_MAX_PATH]; // name of material used for rendering the decal (in favor of szTextureName/nTid and the default decal shader) - bool preventDecalOnGround; // mainly for decal placement support - const Matrix33* pExplicitRightUpFront; // mainly for decal placement support - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{} - - // the constructor fills in some non-obligatory fields; the other fields must be filled in by the client - CryEngineDecalInfo () - { - memset(this, 0, sizeof(*this)); - ownerInfo.nRenderNodeSlotId = ownerInfo.nRenderNodeSlotSubObjectId = -1; - sortPrio = 255; - } -}; - -#endif // CRYINCLUDE_CRYCOMMON_CRYENGINEDECALINFO_H diff --git a/Code/CryEngine/CryCommon/CryFontBus.h b/Code/CryEngine/CryCommon/CryFontBus.h deleted file mode 100644 index 9922193f42..0000000000 --- a/Code/CryEngine/CryCommon/CryFontBus.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or - * its licensors. - * - * For complete copyright and license terms please see the LICENSE at the root of this - * distribution (the "License"). All use of this software is governed by the License, - * or, if provided, by the license below or the license accompanying this file. Do not - * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - */ - -#pragma once - -#include - -#include - -namespace AZ -{ - /*! - * Signal LY to create an ICryFont - */ - class CryFontCreationRequests - : public AZ::EBusTraits - { - public: - using MutexType = AZStd::recursive_mutex; - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - - virtual bool CreateCryFont([[maybe_unused]] SSystemGlobalEnvironment& env, [[maybe_unused]] const SSystemInitParams& initParams) {return false;} //! return false to fall back to default CryFont initialization - }; - using CryFontCreationRequestBus = AZ::EBus; - -} diff --git a/Code/CryEngine/CryCommon/Cry_Camera.h b/Code/CryEngine/CryCommon/Cry_Camera.h index a744d7335f..56a764d897 100644 --- a/Code/CryEngine/CryCommon/Cry_Camera.h +++ b/Code/CryEngine/CryCommon/Cry_Camera.h @@ -594,7 +594,7 @@ public: ILINE const Vec3& GetFPVertex(int nId) const; //get far-plane vertices ILINE const Vec3& GetPPVertex(int nId) const; //get projection-plane vertices - ILINE const Plane* GetFrustumPlane(int numplane) const { return &m_fp[numplane]; } + ILINE const Plane_tpl* GetFrustumPlane(int numplane) const { return &m_fp[numplane]; } ////////////////////////////////////////////////////////////////////////// // Z-Buffer ranges. @@ -720,7 +720,7 @@ private: Vec3 m_cltn, m_crtn, m_clbn, m_crbn; //this are the 4 vertices of the near-plane in cam-space Vec3 m_cltf, m_crtf, m_clbf, m_crbf; //this are the 4 vertices of the farclip-plane in cam-space - Plane m_fp [FRUSTUM_PLANES]; // + Plane_tpl m_fp [FRUSTUM_PLANES]; // uint32 m_idx1[FRUSTUM_PLANES], m_idy1[FRUSTUM_PLANES], m_idz1[FRUSTUM_PLANES]; // uint32 m_idx2[FRUSTUM_PLANES], m_idy2[FRUSTUM_PLANES], m_idz2[FRUSTUM_PLANES]; // @@ -742,7 +742,7 @@ public: m_crtp = arrvVerts[2]; m_crbp = arrvVerts[3]; } - inline void SetFrustumPlane(int i, const Plane& plane) + inline void SetFrustumPlane(int i, const Plane_tpl& plane) { m_fp[i] = plane; //do not break strict aliasing rules, use union instead of reinterpret_casts @@ -1180,12 +1180,12 @@ inline void CCamera::UpdateFrustum() //------------------------------------------------------------------------------- //--- calculate the six frustum-planes using the frustum edges in world-space --- //------------------------------------------------------------------------------- - m_fp[FR_PLANE_NEAR ] = Plane::CreatePlane(m_crtn + GetPosition(), m_cltn + GetPosition(), m_crbn + GetPosition()); - m_fp[FR_PLANE_RIGHT ] = Plane::CreatePlane(m_crbf + GetPosition(), m_crtf + GetPosition(), GetPosition()); - m_fp[FR_PLANE_LEFT ] = Plane::CreatePlane(m_cltf + GetPosition(), m_clbf + GetPosition(), GetPosition()); - m_fp[FR_PLANE_TOP ] = Plane::CreatePlane(m_crtf + GetPosition(), m_cltf + GetPosition(), GetPosition()); - m_fp[FR_PLANE_BOTTOM] = Plane::CreatePlane(m_clbf + GetPosition(), m_crbf + GetPosition(), GetPosition()); - m_fp[FR_PLANE_FAR ] = Plane::CreatePlane(m_crtf + GetPosition(), m_crbf + GetPosition(), m_cltf + GetPosition()); //clip-plane + m_fp[FR_PLANE_NEAR ] = Plane_tpl::CreatePlane(m_crtn + GetPosition(), m_cltn + GetPosition(), m_crbn + GetPosition()); + m_fp[FR_PLANE_RIGHT ] = Plane_tpl::CreatePlane(m_crbf + GetPosition(), m_crtf + GetPosition(), GetPosition()); + m_fp[FR_PLANE_LEFT ] = Plane_tpl::CreatePlane(m_cltf + GetPosition(), m_clbf + GetPosition(), GetPosition()); + m_fp[FR_PLANE_TOP ] = Plane_tpl::CreatePlane(m_crtf + GetPosition(), m_cltf + GetPosition(), GetPosition()); + m_fp[FR_PLANE_BOTTOM] = Plane_tpl::CreatePlane(m_clbf + GetPosition(), m_crbf + GetPosition(), GetPosition()); + m_fp[FR_PLANE_FAR ] = Plane_tpl::CreatePlane(m_crtf + GetPosition(), m_crbf + GetPosition(), m_cltf + GetPosition()); //clip-plane uint32 rh = m_Matrix.IsOrthonormalRH(); if (rh == 0) diff --git a/Code/CryEngine/CryCommon/Cry_GeoDistance.h b/Code/CryEngine/CryCommon/Cry_GeoDistance.h index 92c1f65d87..47794c7671 100644 --- a/Code/CryEngine/CryCommon/Cry_GeoDistance.h +++ b/Code/CryEngine/CryCommon/Cry_GeoDistance.h @@ -1168,17 +1168,6 @@ namespace Distance { return fDist2; } - // Compute both the min and max distances of a box to a plane, in the sense of the plane normal. - inline void AABB_Plane(float* pfDistMin, float* pfDistMax, const AABB& box, const Plane& pl) - { - float fDist0 = pl.DistFromPlane(box.min), - fDistX = (box.max.x - box.min.x) * pl.n.x, - fDistY = (box.max.y - box.min.y) * pl.n.y, - fDistZ = (box.max.z - box.min.z) * pl.n.z; - *pfDistMin = fDist0 + min(fDistX, 0.f) + min(fDistY, 0.f) + min(fDistZ, 0.f); - *pfDistMax = fDist0 + max(fDistX, 0.f) + max(fDistY, 0.f) + max(fDistZ, 0.f); - } - //---------------------------------------------------------------------------------- // Distance: Sphere_Triangle //---------------------------------------------------------------------------------- diff --git a/Code/CryEngine/CryCommon/Cry_GeoIntersect.h b/Code/CryEngine/CryCommon/Cry_GeoIntersect.h index c2f556c4b7..89f6d8ebaf 100644 --- a/Code/CryEngine/CryCommon/Cry_GeoIntersect.h +++ b/Code/CryEngine/CryCommon/Cry_GeoIntersect.h @@ -22,7 +22,7 @@ #include namespace Intersect { - inline bool Ray_Plane(const Ray& ray, const Plane& plane, Vec3& output, bool bSingleSidePlane = true) + inline bool Ray_Plane(const Ray& ray, const Plane_tpl& plane, Vec3& output, bool bSingleSidePlane = true) { float cosine = plane.n | ray.direction; @@ -49,7 +49,7 @@ namespace Intersect { return true; //intersection occurred } - inline bool Line_Plane(const Line& line, const Plane& plane, Vec3& output, bool bSingleSidePlane = true) + inline bool Line_Plane(const Line& line, const Plane_tpl& plane, Vec3& output, bool bSingleSidePlane = true) { float cosine = plane.n | line.direction; diff --git a/Code/CryEngine/CryCommon/Cry_GeoOverlap.h b/Code/CryEngine/CryCommon/Cry_GeoOverlap.h index 3f2c7081d7..ab560b7518 100644 --- a/Code/CryEngine/CryCommon/Cry_GeoOverlap.h +++ b/Code/CryEngine/CryCommon/Cry_GeoOverlap.h @@ -945,29 +945,6 @@ namespace Overlap { } } - - /*! - * - * we use the SEPARATING-AXIS-TEST for OBB/Plane overlap. - * - * Example: - * bool result=Overlap::OBB_Plane( pos,obb, plane ); - * - */ - inline bool OBB_Plane(const Vec3& pos, const OBB& obb, const Plane& plane) - { - //the new center-position in world-space - Vec3 p = obb.m33 * obb.c + pos; - //extract the orientation-vectors from the columns of the 3x3 matrix - //and scale them by the half-lengths - Vec3 ax = Vec3(obb.m33.m00, obb.m33.m10, obb.m33.m20) * obb.h.x; - Vec3 ay = Vec3(obb.m33.m01, obb.m33.m11, obb.m33.m21) * obb.h.y; - Vec3 az = Vec3(obb.m33.m02, obb.m33.m12, obb.m33.m22) * obb.h.z; - //check OBB against Plane, using the plane-normal as separating axis - return fabsf(plane | p) < (fabsf(plane.n | ax) + fabsf(plane.n | ay) + fabsf(plane.n | az)); - } - - /*! * * we use the SEPARATING AXIS TEST to check if a triangle and AABB overlap. @@ -1214,7 +1191,7 @@ namespace Overlap { //test if the box intersects the plane of the triangle //compute plane equation of triangle: normal*x+d=0 - Plane plane = Plane::CreatePlane((e0 % e1), v0); + Plane_tpl plane = Plane_tpl::CreatePlane((e0 % e1), v0); Vec3 vmin, vmax; if (plane.n.x > 0.0f) @@ -1505,7 +1482,7 @@ namespace Overlap { //test if the box overlaps the plane of the triangle //compute plane equation of triangle: normal*x+d=0 - Plane plane = Plane::CreatePlane((e0 % e1), v0); + Plane_tpl plane = Plane_tpl::CreatePlane((e0 % e1), v0); Vec3 vmin, vmax; if (plane.n.x > 0.0f) diff --git a/Code/CryEngine/CryCommon/Gem.h b/Code/CryEngine/CryCommon/Gem.h deleted file mode 100644 index 3097fcf304..0000000000 --- a/Code/CryEngine/CryCommon/Gem.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include - -#if defined(AZ_RESTRICTED_PLATFORM) - #include AZ_RESTRICTED_FILE(Gem_h) -#endif - -#if defined(LINUX) || defined(APPLE) || defined(ANDROID) - #define OPENGL 1 -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include <3dEngine.h> -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include diff --git a/Code/CryEngine/CryCommon/I3DEngine.h b/Code/CryEngine/CryCommon/I3DEngine.h deleted file mode 100644 index 8d3801ecb4..0000000000 --- a/Code/CryEngine/CryCommon/I3DEngine.h +++ /dev/null @@ -1,3021 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : 3dengine interface - -#ifndef CRYINCLUDE_CRYCOMMON_I3DENGINE_H -#define CRYINCLUDE_CRYCOMMON_I3DENGINE_H -#pragma once - -// The maximum number of unique surface types that can be used per node -#define MMRM_MAX_SURFACE_TYPES 16 -#define COMPILED_OCTREE_FILE_NAME "terrain/terrain.dat" - -// !!! Do not add any headers here !!! -#include "CryEngineDecalInfo.h" -#include -#include // <> required for Interfuscator -#include "IRenderer.h" -#include // <> required for Interfuscator -#include // <> required for Interfuscator -#include // <> required for Interfuscator -#include // <> required for Interfuscator -#include "CryArray.h" -#include // <> required for Interfuscator -#include -// !!! Do not add any headers here !!! - -class IOpticsManager; -class CContentCGF; -class ICrySizer; -class CRenderView; -struct ISystem; -struct CVars; -struct pe_params_particle; -struct IMaterial; -struct SpawnParams; -struct ForceObject; -struct IRenderNode; -struct IObjManager; -struct IDeferredPhysicsEventManager; -struct IBSPTree3D; -struct ITextureLoadHandler; -struct ITimeOfDay; -struct MacroTextureConfiguration; - -namespace LegacyProceduralVegetation -{ - class IVegetationPoolManager; -} - -namespace LegacyTerrain -{ - struct MacroTextureConfiguration; -} - -namespace ChunkFile -{ - struct IChunkFileWriter; -} - -namespace AZ -{ - class Aabb; -} - -enum E3DEngineParameter -{ - E3DPARAM_SUN_COLOR, - - E3DPARAM_SUN_SPECULAR_MULTIPLIER, - - E3DPARAM_AMBIENT_GROUND_COLOR, - E3DPARAM_AMBIENT_MIN_HEIGHT, - E3DPARAM_AMBIENT_MAX_HEIGHT, - - E3DPARAM_FOG_COLOR, - E3DPARAM_FOG_COLOR2, - E3DPARAM_FOG_RADIAL_COLOR, - - E3DPARAM_VOLFOG_HEIGHT_DENSITY, - E3DPARAM_VOLFOG_HEIGHT_DENSITY2, - - E3DPARAM_VOLFOG_GRADIENT_CTRL, - - E3DPARAM_VOLFOG_GLOBAL_DENSITY, - E3DPARAM_VOLFOG_RAMP, - - E3DPARAM_VOLFOG_SHADOW_RANGE, - E3DPARAM_VOLFOG_SHADOW_DARKENING, - E3DPARAM_VOLFOG_SHADOW_ENABLE, - - E3DPARAM_VOLFOG2_CTRL_PARAMS, - E3DPARAM_VOLFOG2_SCATTERING_PARAMS, - E3DPARAM_VOLFOG2_RAMP, - E3DPARAM_VOLFOG2_COLOR, - E3DPARAM_VOLFOG2_GLOBAL_DENSITY, - E3DPARAM_VOLFOG2_HEIGHT_DENSITY, - E3DPARAM_VOLFOG2_HEIGHT_DENSITY2, - E3DPARAM_VOLFOG2_COLOR1, - E3DPARAM_VOLFOG2_COLOR2, - - E3DPARAM_SKYLIGHT_SUN_INTENSITY, - - E3DPARAM_SKYLIGHT_KM, - E3DPARAM_SKYLIGHT_KR, - E3DPARAM_SKYLIGHT_G, - - E3DPARAM_SKYLIGHT_WAVELENGTH_R, - E3DPARAM_SKYLIGHT_WAVELENGTH_G, - E3DPARAM_SKYLIGHT_WAVELENGTH_B, - - E3DPARAM_NIGHSKY_HORIZON_COLOR, - E3DPARAM_NIGHSKY_ZENITH_COLOR, - E3DPARAM_NIGHSKY_ZENITH_SHIFT, - - E3DPARAM_NIGHSKY_STAR_INTENSITY, - - E3DPARAM_NIGHSKY_MOON_DIRECTION, - E3DPARAM_NIGHSKY_MOON_COLOR, - E3DPARAM_NIGHSKY_MOON_SIZE, - E3DPARAM_NIGHSKY_MOON_INNERCORONA_COLOR, - E3DPARAM_NIGHSKY_MOON_INNERCORONA_SCALE, - E3DPARAM_NIGHSKY_MOON_OUTERCORONA_COLOR, - E3DPARAM_NIGHSKY_MOON_OUTERCORONA_SCALE, - - E3DPARAM_CLOUDSHADING_MULTIPLIERS, - E3DPARAM_CLOUDSHADING_SUNCOLOR, - E3DPARAM_CLOUDSHADING_SKYCOLOR, - - E3DPARAM_CORONA_SIZE, - - E3DPARAM_OCEANFOG_COLOR, - E3DPARAM_OCEANFOG_DENSITY, - - // Sky highlight (ex. From Lightning) - E3DPARAM_SKY_HIGHLIGHT_COLOR, - E3DPARAM_SKY_HIGHLIGHT_SIZE, - E3DPARAM_SKY_HIGHLIGHT_POS, - - E3DPARAM_SKY_MOONROTATION, - - E3DPARAM_SKY_SKYBOX_ANGLE, - E3DPARAM_SKY_SKYBOX_STRETCHING, - - EPARAM_SUN_SHAFTS_VISIBILITY, - - E3DPARAM_SKYBOX_MULTIPLIER, - - E3DPARAM_DAY_NIGHT_INDICATOR, - - // Tone mapping tweakables - E3DPARAM_HDR_FILMCURVE_SHOULDER_SCALE, - E3DPARAM_HDR_FILMCURVE_LINEAR_SCALE, - E3DPARAM_HDR_FILMCURVE_TOE_SCALE, - E3DPARAM_HDR_FILMCURVE_WHITEPOINT, - - E3DPARAM_HDR_EYEADAPTATION_PARAMS, - E3DPARAM_HDR_EYEADAPTATION_PARAMS_LEGACY, - E3DPARAM_HDR_BLOOM_AMOUNT, - - E3DPARAM_HDR_COLORGRADING_COLOR_SATURATION, - E3DPARAM_HDR_COLORGRADING_COLOR_BALANCE, - - E3DPARAM_COLORGRADING_FILTERS_PHOTOFILTER_COLOR, - E3DPARAM_COLORGRADING_FILTERS_PHOTOFILTER_DENSITY, - E3DPARAM_COLORGRADING_FILTERS_GRAIN -}; - -enum EShadowMode -{ - ESM_NORMAL = 0, - ESM_HIGHQUALITY -}; - -struct IBSPTree3D -{ - typedef DynArray CFace; - typedef DynArray FaceList; - - virtual ~IBSPTree3D() {} - virtual bool IsInside(const Vec3& vPos) const = 0; - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - - virtual size_t WriteToBuffer(void* pBuffer) const = 0; - virtual void ReadFromBuffer(const void* pBuffer) = 0; -}; - -////////////////////////////////////////////////////////////////////////// -// Description: -// This structure is filled and passed by the caller to the DebugDraw functions of the stat object or entity. -struct SGeometryDebugDrawInfo -{ - Matrix34 tm; // Transformation Matrix - ColorB color; // Optional color of the lines. - ColorB lineColor; // Optional color of the lines. - - // Optional flags controlling how to render debug draw information. - uint32 bNoCull : 1; - uint32 bNoLines : 1; - uint32 bExtrude : 1; // Extrude debug draw geometry alittle bit so it is over real geometry. - - SGeometryDebugDrawInfo() - : color(255, 0, 255, 255) - , lineColor(255, 255, 0, 255) - , bNoLines(0) - , bNoCull(0) { tm.SetIdentity(); } -}; - -struct SFrameLodInfo -{ - uint32 nID; - float fLodRatio; - float fTargetSize; - uint nMinLod; - uint nMaxLod; - - SFrameLodInfo() - { - nID = 0; - fLodRatio = 0.f; - fTargetSize = 0.f; - nMinLod = 0; - nMaxLod = 6; - } -}; -struct SMeshLodInfo -{ - static const int s_nMaxLodCount = 5; - float fGeometricMean; - uint nFaceCount; - uint32 nFrameLodID; - SMeshLodInfo() - { - Clear(); - } - void Clear() - { - fGeometricMean = 0.f; - nFaceCount = 0; - nFrameLodID = 0; - } - void Merge(const SMeshLodInfo& lodInfo) - { - uint nTotalCount = nFaceCount + lodInfo.nFaceCount; - if (nTotalCount > 0) - { - float fGeometricMeanTotal = 0.f; - if (fGeometricMean > 0.f) - { - fGeometricMeanTotal += logf(fGeometricMean) * nFaceCount; - } - if (lodInfo.fGeometricMean > 0.f) - { - fGeometricMeanTotal += logf(lodInfo.fGeometricMean) * lodInfo.nFaceCount; - } - fGeometricMean = expf(fGeometricMeanTotal / (float)nTotalCount); - nFaceCount = nTotalCount; - } - } -}; -// Summary: -// Physics material enumerator, allows for 3dengine to get material id from game code. -struct IPhysMaterialEnumerator -{ - // - virtual ~IPhysMaterialEnumerator(){} - virtual int EnumPhysMaterial(const char* szPhysMatName) = 0; - virtual bool IsCollidable(int nMatId) = 0; - virtual int GetMaterialCount() = 0; - virtual const char* GetMaterialNameByIndex(int index) = 0; - // -}; - - -// Summary: -// Physics foreign data flags. -enum EPhysForeignFlags -{ - PFF_HIDABLE = 0x1, - PFF_HIDABLE_SECONDARY = 0x2, - PFF_EXCLUDE_FROM_STATIC = 0x4, - PFF_UNIMPORTANT = 0x20, - PFF_OUTDOOR_AREA = 0x40, - PFF_MOVING_PLATFORM = 0x80, -}; - -// Summary: -// Ocean data flags. -enum EOceanRenderFlags -{ - OCR_NO_DRAW = 1 << 0, - OCR_OCEANVOLUME_VISIBLE = 1 << 1, -}; - -// Summary: -// Structure to pass vegetation group properties. -struct IStatInstGroup -{ - enum EPlayerHideable - { - ePlayerHideable_None = 0, - ePlayerHideable_High, - ePlayerHideable_Mid, - ePlayerHideable_Low, - - ePlayerHideable_COUNT, - }; - - IStatInstGroup() - { - pStatObj = 0; - szFileName[0] = 0; - bHideability = 0; - bHideabilitySecondary = 0; - fBending = 0; - nCastShadowMinSpec = 0; - bRecvShadow = 0; - bDynamicDistanceShadows = false; - bUseAlphaBlending = 0; - fSpriteDistRatio = 1.f; - fShadowDistRatio = 1.f; - fMaxViewDistRatio = 1.f; - fLodDistRatio = 1.f; - fBrightness = 1.f; - pMaterial = 0; - - fDensity = 1; - fElevationMax = 4096; - fElevationMin = 8; - fSize = 1; - fSizeVar = 0; - fSlopeMax = 255; - fSlopeMin = 0; - fStiffness = 0.5f; - fDamping = 2.5f; - fVariance = 0.6f; - fAirResistance = 1.f; - bRandomRotation = false; - nRotationRangeToTerrainNormal = 0; - nMaterialLayers = 0; - bAllowIndoor = false; - fAlignToTerrainCoefficient = 0.f; - bAutoMerged = false; - minConfigSpec = (ESystemConfigSpec)0; - nTexturesAreStreamedIn = 0; - nPlayerHideable = ePlayerHideable_None; - nID = -1; - } - - IStatObj* GetStatObj() - { - IStatObj* p = pStatObj; - return (IStatObj*)p; - } - const IStatObj* GetStatObj() const - { - const IStatObj* p = pStatObj; - return (const IStatObj*)p; - } - - _smart_ptr pStatObj; - char szFileName[256]; - bool bHideability; - bool bHideabilitySecondary; - float fBending; - uint8 nCastShadowMinSpec; - bool bRecvShadow; - bool bDynamicDistanceShadows; - bool bUseAlphaBlending; - float fSpriteDistRatio; - float fLodDistRatio; - float fShadowDistRatio; - float fMaxViewDistRatio; - float fBrightness; - bool bRandomRotation; - int32 nRotationRangeToTerrainNormal; - float fAlignToTerrainCoefficient; - bool bAllowIndoor; - bool bAutoMerged; - - float fDensity; - float fElevationMax; - float fElevationMin; - float fSize; - float fSizeVar; - float fSlopeMax; - float fSlopeMin; - float fStiffness; - float fDamping; - float fVariance; - float fAirResistance; - - float fVegRadius; - float fVegRadiusVert; - float fVegRadiusHor; - - int nPlayerHideable; - int nID; - - // Minimal configuration spec for this vegetation group. - ESystemConfigSpec minConfigSpec; - - // Override material for this instance group. - _smart_ptr pMaterial; - - // Material layers bitmask -> which layers are active. - uint8 nMaterialLayers; - - // Textures Are Streamed In. - uint8 nTexturesAreStreamedIn; - - // Flags similar to entity render flags. - int m_dwRndFlags; -}; - -// Description: -// Water volumes should usually be created by I3DEngine::CreateWaterVolume. -// Summary: -// Interface to water volumes. -struct IWaterVolume -{ - // - //DOC-IGNORE-BEGIN - virtual ~IWaterVolume(){} - virtual void UpdatePoints(const Vec3* pPoints, int nCount, float fHeight) = 0; - virtual void SetFlowSpeed(float fSpeed) = 0; - virtual void SetAffectToVolFog(bool bAffectToVolFog) = 0; - virtual void SetTriSizeLimits(float fTriMinSize, float fTriMaxSize) = 0; - // virtual void SetMaterial(const char * szShaderName) = 0; - virtual void SetMaterial(_smart_ptr pMaterial) = 0; - virtual _smart_ptr GetMaterial() = 0; - virtual const char* GetName() const = 0; - virtual void SetName(const char* szName) = 0; - //DOC-IGNORE-END - - // Description: - // Used to change the water level. Will assign a new Z value to all - // vertices of the water geometry. - // Arguments: - // vNewOffset - Position of the new water level - // Summary: - // Sets a new water level. - virtual void SetPositionOffset(const Vec3& vNewOffset) = 0; - // -}; - -struct SClipVolumeBlendInfo -{ - static const int BlendPlaneCount = 2; - - Plane blendPlanes[BlendPlaneCount]; - struct IClipVolume* blendVolumes[BlendPlaneCount]; -}; - -struct IClipVolume -{ - enum EClipVolumeFlags - { - eClipVolumeConnectedToOutdoor = BIT(0), - eClipVolumeIgnoreGI = BIT(1), - eClipVolumeAffectedBySun = BIT(2), - eClipVolumeBlend = BIT(3), - eClipVolumeIsVisArea = BIT(4), - eClipVolumeIgnoreOutdoorAO = BIT(5), - }; - - virtual ~IClipVolume() {}; - virtual void GetClipVolumeMesh(_smart_ptr& renderMesh, Matrix34& worldTM) const = 0; - virtual AABB GetClipVolumeBBox() const = 0; - virtual bool IsPointInsideClipVolume(const Vec3& point) const = 0; - - virtual uint8 GetStencilRef() const = 0; - virtual uint GetClipVolumeFlags() const = 0; -}; - -// Summary: -// Provides information about the different VisArea volumes. -struct IVisArea - : public IClipVolume -{ - // - virtual ~IVisArea(){} - // Summary: - // Gets the last rendered frame id. - // Return Value: - // An int which contains the frame id. - virtual int GetVisFrameId() = 0; - - // Description: - // Gets a list of all the VisAreas which are connected to the current one. - // Arguments: - // pAreas - Pointer to an array of IVisArea* - // nMaxConnNum - The maximum of IVisArea to write in pAreas - // bSkipDisabledPortals - Ignore portals which are disabled - // Return Value: - // An integer which hold the amount of VisArea found to be connected. If - // the return is equal to nMaxConnNum, it's possible that not all - // connected VisAreas were returned due to the restriction imposed by the - // argument. - // Summary: - // Gets all the areas which are connected to the current one. - virtual int GetVisAreaConnections(IVisArea** pAreas, int nMaxConnNum, bool bSkipDisabledPortals = false) = 0; - - // Summary: - // Determines if it's connected to an outdoor area. - // Return Value: - // True if the VisArea is connected to an outdoor area. - virtual bool IsConnectedToOutdoor() const = 0; - - // Summary: - // Determines if the visarea ignores Global Illumination inside. - // Return Value: - // True if the VisArea ignores Global Illumination inside. - virtual bool IsIgnoringGI() const = 0; - - // Summary: - // Determines if the visarea ignores Outdoor Ambient occlusion inside. - // Return Value: - // True if the VisArea ignores Outdoor Ambient Occlusion inside. - virtual bool IsIgnoringOutdoorAO() const = 0; - - // Summary: - // Gets the name. - // Notes: - // The name is always returned in lower case. - // Return Value: - // A null terminated char array containing the name of the VisArea. - virtual const char* GetName() = 0; - - // Summary: - // Determines if this VisArea is a portal. - // Return Value: - // True if the VisArea is a portal, or false in the opposite case. - virtual bool IsPortal() const = 0; - - // Description: - // Searches for a specified VisArea to see if it's connected to the current - // VisArea. - // Arguments: - // pAnotherArea - A specified VisArea to find - // nMaxRecursion - The maximum number of recursion to do while searching - // bSkipDisabledPortals - Will avoid searching disabled VisAreas - // pVisitedAreas - if not NULL - will get list of all visited areas - // Return Value: - // True if the VisArea was found. - // Summary: - // Searches for a specified VisArea. - virtual bool FindVisArea(IVisArea* pAnotherArea, int nMaxRecursion, bool bSkipDisabledPortals) = 0; - - // Description: - // Searches for the surrounding VisAreas which connected to the current - // VisArea. - // Arguments: - // nMaxRecursion - The maximum number of recursion to do while searching - // bSkipDisabledPortals - Will avoid searching disabled VisAreas - // pVisitedAreas - if not NULL - will get list of all visited areas - // Return Value: - // None. - // Summary: - // Searches for the surrounding VisAreas. - virtual void FindSurroundingVisArea(int nMaxRecursion, bool bSkipDisabledPortals, PodArray* pVisitedAreas = NULL, int nMaxVisitedAreas = 0, int nDeepness = 0) = 0; - - // Summary: - // Determines if it's affected by outdoor lighting. - // Return Value: - // Returns true if the VisArea if it's affected by outdoor lighting, else - // false will be returned. - virtual bool IsAffectedByOutLights() const = 0; - - // Summary: - // Determines if the spere can be affect the VisArea. - // Return Value: - // Returns true if the VisArea can be affected by the sphere, else - // false will be returned. - virtual bool IsSphereInsideVisArea(const Vec3& vPos, const f32 fRadius) = 0; - - // Summary: - // Clips geometry inside or outside a vis area. - // Return Value: - // Whether geom was clipped. - virtual bool ClipToVisArea(bool bInside, Sphere& sphere, Vec3 const& vNormal) = 0; - - // Summary: - // Gives back the axis aligned bounding box of VisArea. - // Return Value: - // Returns the pointer of a AABB. - virtual const AABB* GetAABBox() const = 0; - - // Summary: - // Gives back the axis aligned bounding box of all static objects in the VisArea. - // This AABB can be huger than the ViaArea AABB as some objects might not be completely inside the VisArea. - // Return Value: - // Returns the pointer to the AABB. - virtual const AABB* GetStaticObjectAABBox() const = 0; - - // Summary: - // Determines if the point can be affect the VisArea. - // Return Value: - // Returns true if the VisArea can be affected by the point, else - // false will be returned. - virtual bool IsPointInsideVisArea(const Vec3& vPos) const = 0; - - virtual void GetShapePoints(const Vec3*& pPoints, size_t& nPoints) = 0; - virtual float GetHeight() = 0; - // -}; - -#include "OceanConstants.h" - -// float m_SortId : offseted by +WATER_LEVEL_SORTID_OFFSET if the camera object line is crossing the water surface -// : otherwise offseted by -WATER_LEVEL_SORTID_OFFSET -#define WATER_LEVEL_SORTID_OFFSET 10000000 - -#define DEFAULT_SID 0 - -// Summary: -// indirect lighting quadtree definition. -namespace NQT -{ - // Forward declaration - template - class CQuadTree; -} - -#define FILEVERSION_TERRAIN_SHLIGHTING_FILE 5 - -enum EVoxelBrushShape -{ - evbsSphere = 1, - evbsBox, -}; - -enum EVoxelEditTarget -{ - evetVoxelObjects = 1, -}; - -enum EVoxelEditOperation -{ - eveoNone = 0, - eveoPaintHeightPos, - eveoPaintHeightNeg, - eveoCreate, - eveoSubstract, - eveoMaterial, - eveoBaseColor, - eveoBlurPos, - eveoBlurNeg, - eveoCopyTerrainPos, - eveoCopyTerrainNeg, - eveoPickHeight, - eveoIntegrateMeshPos, - eveoIntegrateMeshNeg, - eveoForceDepth, - eveoLimitLod, - eveoLast, -}; - -#define COMPILED_VISAREA_MAP_FILE_NAME "terrain\\indoor.dat" -#define COMPILED_MERGED_MESHES_BASE_NAME "terrain\\merged_meshes_sectors\\" -#define COMPILED_MERGED_MESHES_LIST "mmrm_used_meshes.lst" -#define LEVEL_INFO_FILE_NAME "levelinfo.xml" - -////////////////////////////////////////////////////////////////////////// - -#pragma pack(push,4) - -#define VISAREAMANAGER_CHUNK_VERSION 6 - -#define SERIALIZATION_FLAG_BIG_ENDIAN 1 -#define SERIALIZATION_FLAG_SECTOR_PALETTES 2 - -#define TCH_FLAG2_AREA_ACTIVATION_IN_USE 1 - -struct SVisAreaManChunkHeader -{ - int8 nVersion; - int8 nDummy; - int8 nFlags; - int8 nFlags2; - int nChunkSize; - int nVisAreasNum; - int nPortalsNum; - int nOcclAreasNum; - - AUTO_STRUCT_INFO -}; - -struct SOcTreeNodeChunk -{ - int16 nChunkVersion; - int16 ucChildsMask; - AABB nodeBox; - int32 nObjectsBlockSize; - - AUTO_STRUCT_INFO -}; - -struct SHotUpdateInfo -{ - SHotUpdateInfo() - { - nHeigtmap = 1; - nObjTypeMask = ~0; - pVisibleLayerMask = NULL; - pLayerIdTranslation = NULL; - areaBox.Reset(); - } - - uint32 nHeigtmap; - uint32 nObjTypeMask; - const uint8* pVisibleLayerMask; - const uint16* pLayerIdTranslation; - AABB areaBox; - - AUTO_STRUCT_INFO -}; - -#define OCTREE_CHUNK_VERSION 29 - -//============================================================================================== - -// Summary: -// Common header for binary files used by 3dengine -struct SCommonFileHeader -{ - char signature[4]; // File signature, should be "CRY " - uint8 file_type; // File type - uint8 flags; // File common flags - uint16 version; // File version - - AUTO_STRUCT_INFO -}; - -struct IVisAreaCallback -{ - // - virtual ~IVisAreaCallback(){} - virtual void OnVisAreaDeleted(IVisArea* pVisArea) = 0; - // -}; - -struct IVisAreaManager -{ - // - virtual ~IVisAreaManager(){} - // Summary: - // Loads data into VisAreaManager engine from memory block. - virtual bool SetCompiledData(uint8* pData, int nDataSize, std::vector** ppStatObjTable, std::vector<_smart_ptr >** ppMatTable, bool bHotUpdate, SHotUpdateInfo* pExportInfo) = 0; - - // Summary: - // Saves data from VisAreaManager engine into memory block. - virtual bool GetCompiledData(uint8* pData, int nDataSize, std::vector** ppStatObjTable, std::vector<_smart_ptr >** ppMatTable, std::vector** ppStatInstGroupTable, EEndian eEndian, SHotUpdateInfo* pExportInfo = NULL) = 0; - - // Summary: - // Returns VisAreaManager data memory block size. - virtual int GetCompiledDataSize(SHotUpdateInfo* pExportInfo = NULL) = 0; - - // Summary: - // Returns the accumulated number of visareas and portals. - virtual int GetNumberOfVisArea() const = 0; - - // Summary: - // Returns the visarea interface based on the id (0..GetNumberOfVisArea()) it can be a visarea or a portal. - virtual IVisArea* GetVisAreaById(int nID) const = 0; - - virtual void AddListener(IVisAreaCallback* pListener) = 0; - virtual void RemoveListener(IVisAreaCallback* pListener) = 0; - - virtual void PrepareSegmentData(const AABB& box) = 0; - virtual void ReleaseInactiveSegments() = 0; - virtual bool CreateSegment(int nSID) = 0; - virtual bool DeleteSegment(int nSID, bool bDeleteNow) = 0; - virtual bool StreamCompiledData(uint8* pData, int nDataSize, int nSID, std::vector* pStatObjTable, std::vector<_smart_ptr >* pMatTable, std::vector* pStatInstGroupTable, const Vec2& vIndexOffset) = 0; - virtual void OffsetPosition(const Vec3& delta) = 0; - virtual void UpdateConnections() = 0; - // Summary: - // Clones all vis areas in a region of the level, offsetting and rotating them based - // on the values passed in. - // Arguments: - // offset - Offset amount, relative to the center of the region passed in. - // zRotation - Rotation around the z axis, in radians. - virtual void CloneRegion(const AABB& region, const Vec3& offset, float zRotation) = 0; - - // Summary: - // Removes all vis areas in a region of the level. - virtual void ClearRegion(const AABB& region) = 0; - - virtual void GetObjectsByType(PodArray& lstObjects, EERType objType, const AABB* pBBox, ObjectTreeQueryFilterCallback filterCallback = nullptr) = 0; - virtual void GetObjectsByFlags(uint dwFlags, PodArray& lstObjects) = 0; - - virtual void GetObjects(PodArray& lstObjects, const AABB* pBBox) = 0; - - virtual bool IsOutdoorAreasVisible() = 0; -}; - -struct SSkyLightRenderParams -{ - static const int skyDomeTextureWidth = 64; - static const int skyDomeTextureHeight = 32; - static const int skyDomeTextureSize = 64 * 32; - - static const int skyDomeTextureWidthBy8 = 8; - static const int skyDomeTextureWidthBy4Log = 4; // = log2(64/4) - static const int skyDomeTextureHeightBy2Log = 4; // = log2(32/2) - - SSkyLightRenderParams() - : m_pSkyDomeMesh(0) - , m_pSkyDomeTextureDataMie(0) - , m_pSkyDomeTextureDataRayleigh(0) - , m_skyDomeTexturePitch(0) - , m_skyDomeTextureTimeStamp(-1) - , m_partialMieInScatteringConst(0.0f, 0.0f, 0.0f, 0.0f) - , m_partialRayleighInScatteringConst(0.0f, 0.0f, 0.0f, 0.0f) - , m_sunDirection(0.0f, 0.0f, 0.0f, 0.0f) - , m_phaseFunctionConsts(0.0f, 0.0f, 0.0f, 0.0f) - , m_hazeColor(0.0f, 0.0f, 0.0f, 0.0f) - , m_hazeColorMieNoPremul(0.0f, 0.0f, 0.0f, 0.0f) - , m_hazeColorRayleighNoPremul(0.0f, 0.0f, 0.0f, 0.0f) - , m_skyColorTop(0.0f, 0.0f, 0.0f) - , m_skyColorNorth(0.0f, 0.0f, 0.0f) - , m_skyColorEast(0.0f, 0.0f, 0.0f) - , m_skyColorSouth(0.0f, 0.0f, 0.0f) - , m_skyColorWest(0.0f, 0.0f, 0.0f) - { - } - - // Sky dome mesh - _smart_ptr m_pSkyDomeMesh; - - // temporarily add padding bytes to prevent fetching Vec4 constants below from wrong offset - uint32 dummy0; - uint32 dummy1; - - // Sky dome texture data - const void* m_pSkyDomeTextureDataMie; - const void* m_pSkyDomeTextureDataRayleigh; - size_t m_skyDomeTexturePitch; - int m_skyDomeTextureTimeStamp; - - int pad;//Enable 16 byte alignment for Vec4s - - // Sky dome shader constants - Vec4 m_partialMieInScatteringConst; - Vec4 m_partialRayleighInScatteringConst; - Vec4 m_sunDirection; - Vec4 m_phaseFunctionConsts; - Vec4 m_hazeColor; - Vec4 m_hazeColorMieNoPremul; - Vec4 m_hazeColorRayleighNoPremul; - - // Sky hemisphere colors - Vec3 m_skyColorTop; - Vec3 m_skyColorNorth; - Vec3 m_skyColorEast; - Vec3 m_skyColorSouth; - Vec3 m_skyColorWest; -}; - -struct SVisAreaInfo -{ - float fHeight; - Vec3 vAmbientColor; - bool bAffectedByOutLights; - bool bIgnoreSkyColor; - bool bSkyOnly; - float fViewDistRatio; - bool bDoubleSide; - bool bUseDeepness; - bool bUseInIndoors; - bool bOceanIsVisible; - bool bIgnoreGI; - bool bIgnoreOutdoorAO; - float fPortalBlending; -}; - -struct SDebugFPSInfo -{ - SDebugFPSInfo() - : fAverageFPS(0.0f) - , fMaxFPS(0.0f) - , fMinFPS(0.0f) - { - } - float fAverageFPS; - float fMinFPS; - float fMaxFPS; -}; - -struct SRainParams -{ - SRainParams() - : fAmount(0.f) - , fCurrentAmount(0.f) - , fRadius(0.f) - , nUpdateFrameID(-1) - , bIgnoreVisareas(false) - , bDisableOcclusion(false) - , matOccTrans(IDENTITY) - , matOccTransRender(IDENTITY) - , qRainRotation(IDENTITY) - , areaAABB(AABB::RESET) - , bApplySkyColor(false) - , fSkyColorWeight(0.5f) - { - } - - Matrix44 matOccTrans; // Transformation matrix for rendering into a new occ map - Matrix44 matOccTransRender; // Transformation matrix for rendering occluded rain using current occ map - Quat qRainRotation; // Quaternion for the scene's rain entity rotation - AABB areaAABB; - - Vec3 vWorldPos; - Vec3 vColor; - - float fAmount; - float fCurrentAmount; - float fRadius; - - // Deferred rain params - float fFakeGlossiness; // unused - float fFakeReflectionAmount; // unused - float fDiffuseDarkening; - float fRainDropsAmount; - float fRainDropsSpeed; - float fRainDropsLighting; - float fMistAmount; - float fMistHeight; - float fPuddlesAmount; - float fPuddlesMaskAmount; - float fPuddlesRippleAmount; - float fSplashesAmount; - - int nUpdateFrameID; - - bool bApplyOcclusion; - bool bIgnoreVisareas; - bool bDisableOcclusion; - -// Summary: -// Common scene rain parameters shared across engine and editor - bool bApplySkyColor; - float fSkyColorWeight; - - // Bus ID to listen to -}; - -struct SSnowParams -{ - SSnowParams() - : m_vWorldPos(0, 0, 0) - , m_fRadius(0.0) - , m_fSnowAmount(0.0) - , m_fFrostAmount(0.0) - , m_fSurfaceFreezing(0.0) - , m_nSnowFlakeCount(0) - , m_fSnowFlakeSize(0.0) - , m_fSnowFallBrightness(0.0) - , m_fSnowFallGravityScale(0.0) - , m_fSnowFallWindScale(0.0) - , m_fSnowFallTurbulence(0.0) - , m_fSnowFallTurbulenceFreq(0.0) - { - } - - Vec3 m_vWorldPos; - float m_fRadius; - - // Surface params. - float m_fSnowAmount; - float m_fFrostAmount; - float m_fSurfaceFreezing; - - - // Snowfall params. - int m_nSnowFlakeCount; - float m_fSnowFlakeSize; - float m_fSnowFallBrightness; - float m_fSnowFallGravityScale; - float m_fSnowFallWindScale; - float m_fSnowFallTurbulence; - float m_fSnowFallTurbulenceFreq; -}; - - -struct IScreenshotCallback -{ - // - virtual ~IScreenshotCallback(){} - virtual void SendParameters(void* data, uint32 width, uint32 height, f32 minx, f32 miny, f32 maxx, f32 maxy) = 0; - // -}; - -class IStreamedObjectListener -{ -public: - // - virtual void OnCreatedStreamedObject(const char* filename, void* pHandle) = 0; - virtual void OnRequestedStreamedObject(void* pHandle) = 0; - virtual void OnReceivedStreamedObject(void* pHandle) = 0; - virtual void OnUnloadedStreamedObject(void* pHandle) = 0; - virtual void OnBegunUsingStreamedObjects(void** pHandles, size_t numHandles) = 0; - virtual void OnEndedUsingStreamedObjects(void** pHandles, size_t numHandles) = 0; - virtual void OnDestroyedStreamedObject(void* pHandle) = 0; - // -protected: - virtual ~IStreamedObjectListener() {} -}; - -#pragma pack(push, 16) - -struct SFogVolumeData -{ - AABB avgAABBox; - ColorF fogColor; - int m_volumeType; - Vec3 m_heightFallOffBasePoint; - float m_densityOffset; - Vec3 m_heightFallOffDirScaled; - float m_globalDensity; - - SFogVolumeData() : - avgAABBox(AABB::RESET), - m_globalDensity(0.0f), - m_densityOffset(0.0f), - m_volumeType(0), - m_heightFallOffBasePoint(Vec3(0, 0, 0)), - m_heightFallOffDirScaled(Vec3(0, 0, 0)), - fogColor(ColorF(1.0f, 1.0f, 1.0f, 1.0f)) - { - } - -}; - -// Summary: -// Light volumes data - -#define LIGHTVOLUME_MAXLIGHTS 16 - -struct SLightVolume -{ - struct SLightData - { - SLightData() - : vPos(0, 0, 0, 0) - , vColor(0, 0, 0, 0) - , vParams(0, 0, 0, 0) {} - SLightData(const Vec4& vInPos, const Vec4& vInColor, const Vec4& vInParams) - : vPos(vInPos) - , vColor(vInColor) - , vParams(vInParams) {} - - Vec4 vPos; - Vec4 vColor; - Vec4 vParams; - }; - - SLightVolume() - { - pData.reserve(LIGHTVOLUME_MAXLIGHTS); - } - - typedef DynArray LightDataVector; - - DEFINE_ALIGNED_DATA(LightDataVector, pData, 16); -}; - -#pragma pack(pop) - -struct CRNTmpData -{ - struct SRNUserData - { - int m_narrDrawFrames[MAX_RECURSION_LEVELS]; - SLodDistDissolveTransitionState lodDistDissolveTransitionState; - Matrix34 objMat; - OcclusionTestClient m_OcclState; - struct IClipVolume* m_pClipVolume; - SBending m_Bending; - SBending m_BendingPrev; - Vec3 vCurrentWind; - uint32 nBendingLastFrame : 29; - uint32 bWindCurrent : 1; - uint32 bBendingSet : 1; - uint16 nCubeMapId; - uint16 nCubeMapIdCacheClearCounter; - uint8 nWantedLod; - CRenderObject* m_pRenderObject[MAX_STATOBJ_LODS_NUM]; - CRenderObject* m_arrPermanentRenderObjects[MAX_STATOBJ_LODS_NUM]; - } userData; - - CRNTmpData() { memset(this, 0, sizeof(*this)); assert((void*)this == (void*)&this->userData); nPhysAreaChangedProxyId = ~0; } - CRNTmpData* pNext, * pPrev; - CRNTmpData** pOwnerRef; - uint32 nFrameInfoId; - uint32 nPhysAreaChangedProxyId; - - void Unlink() - { - if (!pNext || !pPrev) - { - return; - } - pNext->pPrev = pPrev; - pPrev->pNext = pNext; - pNext = pPrev = NULL; - } - - void Link(CRNTmpData* Before) - { - if (pNext || pPrev) - { - return; - } - pNext = Before->pNext; - Before->pNext->pPrev = this; - Before->pNext = this; - pPrev = Before; - } - - int Count() - { - int nCounter = 0; - for (CRNTmpData* pElem = pNext; pElem != this; pElem = pElem->pNext) - { - nCounter++; - } - return nCounter; - } - - void OffsetPosition(const Vec3& delta) - { - userData.objMat.SetTranslation(userData.objMat.GetTranslation() + delta); - } -}; - - -// Summary: -// Interface to the 3d Engine. -struct I3DEngine - : public IProcess -{ - struct SObjectsStreamingStatus - { - int nReady; - int nInProgress; - int nTotal; - int nActive; - int nAllocatedBytes; - int nMemRequired; - int nMeshPoolSize; // in MB - - }; - - struct OceanAnimationData - { - float fWindDirection; - float fWindSpeed; - float fWavesSpeed; - float fWavesAmount; - float fWavesSize; - float fWindDirectionU; - float fWindDirectionV; - }; - - struct SStremaingBandwidthData - { - SStremaingBandwidthData() - { - memset(this, 0, sizeof(SStremaingBandwidthData)); - } - float fBandwidthActual; - float fBandwidthRequested; - }; - - enum eStreamingSubsystem - { - eStreamingSubsystem_Textures, - eStreamingSubsystem_Objects, - eStreamingSubsystem_Audio, - }; - - using LoadStaticObjectAsyncResult = AZStd::function)>; - - struct StaticObjectAsyncLoadRequest - { - StaticObjectAsyncLoadRequest() = default; - - LoadStaticObjectAsyncResult m_callback; - string m_filename; - string m_geomName; - bool m_useStreaming; - unsigned long m_loadingFlags; - }; - - struct CausticsParams - { - float tiling = 0.0f; - float distanceAttenuation = 0.0f; - float height = 0.0f; - float depth = 0.0f; - float intensity = 0.0f; - }; - - - // - // Summary: - // Initializes the 3D Engine. - // See Also: - // ShutDown - // Notes: - // Only call once, after creating the instance. - virtual bool Init() = 0; - - - // Summary: - // Sets the path used to load levels. - // See Also: - // LoadLevel - // Arguments: - // szFolderName - Should contains the folder to be used - virtual void SetLevelPath(const char* szFolderName) = 0; - - virtual bool CheckMinSpec(uint32 nMinSpec) = 0; - - virtual void PrepareOcclusion(const CCamera& rCamera) = 0; - virtual void EndOcclusion() = 0; - // Description: - // Will load a level from the folder specified with SetLevelPath. If a - // level is already loaded, the resources will be deleted before. - // See Also: - // SetLevelPath - // Arguments: - // szFolderName - Name of the subfolder to load - // szMissionName - Name of the mission - // Return Value: - // A boolean which indicate the result of the function; true is - // succeed, or false if failed. - // Summary: - // Load a level. - virtual bool LoadLevel(const char* szFolderName, const char* szMissionName) = 0; - virtual bool InitLevelForEditor(const char* szFolderName, const char* szMissionName) = 0; - virtual bool LevelLoadingInProgress() = 0; - // Summary: - // Handles any work needed at start of new frame. - // Notes: - // Should be called for every frame. - virtual void OnFrameStart() = 0; - - // Description: - // Must be called after the game completely finishes loading the level. - // 3D engine uses it to pre-cache some resources needed for rendering. - // See Also: - // LoadLevel - // Summary: - // Pre-caches some resources need for rendering. - virtual void PostLoadLevel() = 0; - - // Description: - // Loads the required assets for a null level. - virtual void LoadEmptyLevel() = 0; - - // Summary: - // Clears all rendering resources, all objects, characters and materials, voxels and terrain. - // Notes: - // Should always be called before LoadLevel, and also before loading textures from a script. - virtual void UnloadLevel() = 0; - - - // Summary: - // Updates the 3D Engine. - // Notes: - // Should be called for every frame. - virtual void Update() = 0; - - // Summary: - // Returns the Camera used for Rendering on 3DEngine Side, normaly equal to the view camera, except if frozen with e_camerafreeze - // Notes: - // Only valid during RenderWorld(else the camera of the last frame is used) - // This is the camera which should be used for all Engine side culling (since e_camerafreeze allows easy debugging then) - virtual const CCamera& GetRenderingCamera() const = 0; - virtual float GetZoomFactor() const = 0; - - // Summary: - // clear all per frame temp data used in SRenderingPass - virtual void Tick() = 0; - - // Summary: - // Update all ShaderItems flags, only required after shaders were reloaded at runtime - virtual void UpdateShaderItems() = 0; - - // Summary: - // Deletes the 3D Engine instance. - virtual void Release() = 0; - - // Summary: - // Draws the world. - // See Also: - // SetCamera - // Arguments: - // szDebugName - name that can be visualized for debugging purpose, must not be 0 - virtual void RenderWorld(int nRenderFlags, const SRenderingPassInfo& passInfo, const char* szDebugName) = 0; - - virtual void RenderSceneReflection(int nRenderFlags, const SRenderingPassInfo& passInfo) = 0; - - // Summary: - // Prepares for the world stream update, should be called before rendering - virtual void PreWorldStreamUpdate(const CCamera& cam) = 0; - - // Summary: - // Performs the actual world streaming update. PreWorldStreamUpdate must be called before - virtual void WorldStreamUpdate() = 0; - - // Summary: - // Shuts down the 3D Engine. - virtual void ShutDown() = 0; - - // Summary: - // Loads a static object from a CGF file. Does not increment the static object's reference counter. The reference returned is not guaranteed to be valid when run outside the main thread. Best used for priming the cache - // See Also: - // IStatObj - // Arguments: - // fileName - CGF Filename - should not be 0 or "" - // geomName - Optional name of geometry inside CGF. - // subObject - [Out]Optional Out parameter,Pointer to the - // loadingFlags - Zero or a bitwise combination of the flags from ELoadingFlags, defined in IMaterial.h, under the interface IMaterialManager. - // data - Raw buffer contain CGF data. - // dataSize - Size of the raw data buffer. - // Return Value: - // A pointer to an object derived from IStatObj. - virtual IStatObj* LoadStatObjUnsafeManualRef(const char* fileName, const char* geomName = nullptr, /*[Out]*/ IStatObj::SSubObject** subObject = nullptr, - bool useStreaming = true, unsigned long loadingFlags = 0, const void* data = nullptr, int dataSize = 0) = 0; - - // Summary: - // Loads a static object from a CGF file. Increments the static object's reference counter. This method is threadsafe. Not suitable for preloading - // See Also: - // IStatObj - // Arguments: - // fileName - CGF Filename - should not be 0 or "", even if data is provided. - // geomName - Optional name of geometry inside CGF. - // subObject - [Out]Optional Out parameter,Pointer to the - // loadingFlags - Zero or a bitwise combination of the flags from ELoadingFlags, defined in IMaterial.h, under the interface IMaterialManager. - // data - Raw buffer contain CGF data. - // dataSize - Size of the raw data buffer. - // Return Value: - // A smart pointer to an object derived from IStatObj. - virtual _smart_ptr LoadStatObjAutoRef(const char* fileName, const char* geomName = nullptr, /*[Out]*/ IStatObj::SSubObject** subObject = nullptr, - bool useStreaming = true, unsigned long loadingFlags = 0, const void* data = nullptr, int dataSize = 0) = 0; - - // Summary: - // Flushes queued async mesh loads. - virtual void ProcessAsyncStaticObjectLoadRequests() = 0; - - // Summary: - // Loads a static object from a CGF file asynchronously and invokes a callback on completion. - // Actual load will occur on the main thread. - // See Also: - // IStatObj - // Arguments: - // callback - The user callback to invoke on completion. - // szFileName - CGF Filename - should not be 0 or "" - // szGeomName - Optional name of geometry inside CGF. - // ppSubObject - [Out]Optional Out parameter,Pointer to the - // nLoadingFlags - Zero or a bitwise combination of the flags from ELoadingFlags, - // defined in IMaterial.h, under the interface IMaterialManager. - // Return Value: - // None - virtual void LoadStatObjAsync(LoadStaticObjectAsyncResult resultCallback, const char* szFileName, const char* szGeomName = nullptr, bool bUseStreaming = true, unsigned long nLoadingFlags = 0) = 0; - - // Summary: - // Finds a static object created from the given filename - // See Also: - // IStatObj - // Arguments: - // szFileName - CGF Filename - should not be 0 or "" - // Return Value: - // A pointer to an object derived from IStatObj. - virtual IStatObj* FindStatObjectByFilename(const char* filename) = 0; - - // Summary: - // Gets gsm range - // Return Value: - // An integer representing the gsm range. - virtual const float GetGSMRange() = 0; - - // Summary: - // Gets gsm range step - // Return Value: - // An integer representing the gsm range step - virtual const float GetGSMRangeStep() = 0; - - // Summary: - // Gets the amount of loaded objects. - // Return Value: - // An integer representing the amount of loaded objects. - virtual int GetLoadedObjectCount() { return 0; } - - // Summary: - // Fills pObjectsArray with pointers to loaded static objects - // if pObjectsArray is NULL only fills nCount parameter with amount of loaded objects. - virtual void GetLoadedStatObjArray(IStatObj** pObjectsArray, int& nCount) = 0; - - // Summary: - // Gets stats on streamed objects - virtual void GetObjectsStreamingStatus(SObjectsStreamingStatus& outStatus) = 0; - - // Summary: - // Gets stats on the streaming bandwidth requests from subsystems - // Arguments: - // subsystem - the streaming subsystem we want bandwidth data for - // outData - structure containing the bandwidth data for the subsystem requested - virtual void GetStreamingSubsystemData(int subsystem, SStremaingBandwidthData& outData) = 0; - - // Summary: - // Registers an entity to be rendered. - // Arguments: - // pEntity - The entity to render - virtual void RegisterEntity(IRenderNode* pEntity, int nSID = -1, int nSIDConsideredSafe = -1) = 0; - - // Summary: - // Selects an entity for debugging. - // Arguments: - // pEntity - The entity to render - virtual void SelectEntity(IRenderNode* pEntity) = 0; - - ////////////////////////////////////////////// - // Start Confetti ////////////////////////// - // Summary: - // Return the setting for sun shadows. Return false for sub classes without sun shadows settings. - virtual bool IsSunShadows(){ return false; }; - // End Confetti////////////////////////////// - ////////////////////////////////////////////// - - // Summary: - // Offers same functionality as Cry3DEngineBase::MakeSystemMaterialFromShader - virtual _smart_ptr MakeSystemMaterialFromShaderHelper(const char* sShaderName, SInputShaderResources* Res = NULL) = 0; - - virtual bool CheckMinSpecHelper(uint32 nMinSpec) = 0; - - virtual void OnCasterDeleted(IShadowCaster* pCaster) = 0; - - virtual void GetStatObjAndMatTables(DynArray* pStatObjTable, DynArray<_smart_ptr>* pMatTable, DynArray* pStatInstGroupTable, uint32 nObjTypeMask) = 0; - -#ifndef _RELEASE - enum EDebugDrawListAssetTypes - { - DLOT_ALL = 0, - DLOT_CHARACTER = BIT(2), - DLOT_STATOBJ = BIT(3) - }; - - struct SObjectInfoToAddToDebugDrawList - { - const char* pName; - const char* pClassName; - const char* pFileName; - IRenderNode* pRenderNode; - uint32 numTris; - uint32 numVerts; - uint32 texMemory; - uint32 meshMemory; - EDebugDrawListAssetTypes type; - const AABB* pBox; - const Matrix34* pMat; - }; - - virtual void AddObjToDebugDrawList(SObjectInfoToAddToDebugDrawList& objInfo) = 0; - virtual bool IsDebugDrawListEnabled() const = 0; -#endif - - - // Summary: - // Notices the 3D Engine to stop rendering a specified entity. - // Arguments: - // pEntity - The entity to stop render - virtual void UnRegisterEntityDirect(IRenderNode* pEntity) = 0; - virtual void UnRegisterEntityAsJob(IRenderNode* pEnt) = 0; - // Summary: - // Returns whether a world pos is under water. - virtual bool IsUnderWater(const Vec3& vPos) const = 0; - - // Summary: - // Returns whether ocean volume is visible or not. - virtual void SetOceanRenderFlags(uint8 nFlags) = 0; - virtual uint8 GetOceanRenderFlags() const = 0; - virtual uint32 GetOceanVisiblePixelsCount() const = 0; - - // Summary: - // Gets the closest walkable bottom z straight beneath the given reference position. - // Notes: - // This function will take into account both the global terrain elevation and local voxel (or other solid walkable object). - // Arguments: - // referencePos - Position from where to start searching downwards. - // maxRelevantDepth - Max depth caller is interested in relative to referencePos (for ray casting performance reasons). - // objtypes - expects physics entity flags. Use this to specify what object types make a valid bottom for you. - // Return Value: - // A float value which indicate the global world z of the bottom level beneath the referencePos. - // If the referencePos is below terrain but not inside any voxel area BOTTOM_LEVEL_UNKNOWN is returned. - virtual float GetBottomLevel(const Vec3& referencePos, float maxRelevantDepth, int objtypes) = 0; - // A set of overloads for enabling users to use different sets of input params. Basically, only - // referencePos is mandatory. The overloads as such don't need to be virtual but this seems to be - // a purely virtual interface. - virtual float GetBottomLevel(const Vec3& referencePos, float maxRelevantDepth = 10.0f) = 0; - virtual float GetBottomLevel(const Vec3& referencePos, int objflags) = 0; - - // Summary: - // Gets the ocean water level. Fastest option, always prefer is only ocean height required. - // Notes: - // This function will take into account just the global water level. - // Return Value: - // A float value which indicate the water level. In case no water was - // found at the specified location, the value WATER_LEVEL_UNKNOWN will - // be returned. - virtual float GetWaterLevel() = 0; - - // Summary: - // Gets the closest walkable bottom z straight beneath the given reference position. - // - Use with caution the accurate query - SLOW - // Notes: - // This function will take into account both the global water level and any water volume present. - // Function is provided twice for performance with diff. arguments. - // Arguments: - // pvPos - Desired position to inspect the water level - // pent - Pointer to return the physical entity to test against (optional) - // Return Value: - // A float value which indicate the water level. In case no water was - // found at the specified location, the value WATER_LEVEL_UNKNOWN will - // be returned. - virtual float GetWaterLevel(const Vec3* pvPos, IPhysicalEntity* pent = NULL, bool bAccurate = false) = 0; - - // Summary: - // Gets the ocean water level for a specified position. - // - Use with caution the accurate query - SLOW - // Notes: - // This function only takes into account ocean water. - // Arguments: - // pCurrPos - Position to check water level - // Return Value: - // A float value which indicate the water level. - virtual float GetAccurateOceanHeight(const Vec3& pCurrPos) const = 0; - - // Summary: - // Gets caustics parameters. - virtual CausticsParams GetCausticsParams() const = 0; - - // Summary: - // Gets ocean animation parameters. - virtual OceanAnimationData GetOceanAnimationParams() const = 0; - - // Summary: - // Gets HDR setup parameters. - // Return Value: - virtual void GetHDRSetupParams (Vec4 pParams[5]) const = 0; - - // Summary: - // Removes all particles and decals from the world. - virtual void ResetParticlesAndDecals() = 0; - - // Summary: - // Creates new decals on the walls, static objects, terrain and entities. - // Arguments: - // Decal - Structure describing the decal effect to be applied - virtual void CreateDecal(const CryEngineDecalInfo& Decal) = 0; - - // Summary: - // Removes decals in a specified range. - // Arguments: - // vAreaBox - Specify the area in which the decals will be removed - // pEntity - if not NULL will only delete decals attached to this entity - virtual void DeleteDecalsInRange(AABB* pAreaBox, IRenderNode* pEntity) = 0; - - // Summary: - // Sets the current sun base color. - virtual void SetSunColor(Vec3 vColor) = 0; - - // Summary: - // Gets the current sun animated color. - virtual Vec3 GetSunAnimColor() = 0; - - // Summary: - // Sets the current sky brightening multiplier. - virtual void SetSunAnimColor(const Vec3& color) = 0; - - // Summary: - // Sets the current sun animation speed. - virtual float GetSunAnimSpeed() = 0; - - // Summary: - virtual void SetSunAnimSpeed(float sunAnimSpeed) = 0; - - // Summary: - // Gets the current sun animation phase. - virtual AZ::u8 GetSunAnimPhase() = 0; - // Summary: - // Sets the current sun animation phase. - virtual void SetSunAnimPhase(AZ::u8 sunAnimPhase) = 0; - - // Summary: - // Gets the current sun animation index. - virtual AZ::u8 GetSunAnimIndex() = 0; - - // Summary: - // Sets the current sun animation index. - virtual void SetSunAnimIndex(AZ::u8 sunAnimIndex) = 0; - - // Summary: - // Sets current rain parameters. - virtual void SetRainParams(const SRainParams& rainParams) = 0; - - // Summary: - // Gets the validity and fills current rain parameters. - virtual bool GetRainParams(SRainParams& rainParams) = 0; - - // Summary: - // Sets current snow surface parameters. - virtual void SetSnowSurfaceParams(const Vec3& vCenter, float fRadius, float fSnowAmount, float fFrostAmount, float fSurfaceFreezing) = 0; - - // Summary: - // Gets current snow surface parameters. - virtual bool GetSnowSurfaceParams(Vec3& vCenter, float& fRadius, float& fSnowAmount, float& fFrostAmount, float& fSurfaceFreezing) = 0; - - // Summary: - // Sets current snow parameters. - virtual void SetSnowFallParams(int nSnowFlakeCount, float fSnowFlakeSize, float fSnowFallBrightness, float fSnowFallGravityScale, float fSnowFallWindScale, float fSnowFallTurbulence, float fSnowFallTurbulenceFreq) = 0; - - // Summary: - // Gets current snow parameters. - virtual bool GetSnowFallParams(int& nSnowFlakeCount, float& fSnowFlakeSize, float& fSnowFallBrightness, float& fSnowFallGravityScale, float& fSnowFallWindScale, float& fSnowFallTurbulence, float& fSnowFallTurbulenceFreq) = 0; - - // Summary: - // Sets the view distance scale. - // Arguments: - // fScale - may be between 0 and 1, 1.f = Unmodified view distance set by level designer, value of 0.5 will reduce it twice - // Notes: - // This value will be reset automatically to 1 on next level loading. - virtual void SetMaxViewDistanceScale(float fScale) = 0; - - // Summary: - // Gets the view distance. - // Return Value: - // A float value representing the maximum view distance. - virtual float GetMaxViewDistance(bool bScaled = true) = 0; - - virtual const SFrameLodInfo& GetFrameLodInfo() const = 0; - virtual void SetFrameLodInfo(const SFrameLodInfo& frameLodInfo) = 0; - - // Summary: - // Sets the fog color. - virtual void SetFogColor(const Vec3& vFogColor) = 0; - - // Summary: - // Gets the fog color. - virtual Vec3 GetFogColor() = 0; - - // Summary: - // Gets various sky light parameters. - virtual void GetSkyLightParameters(Vec3& sunDir, Vec3& sunIntensity, float& Km, float& Kr, float& g, Vec3& rgbWaveLengths) = 0; - - // Summary: - // Sets various sky light parameters. - virtual void SetSkyLightParameters(const Vec3& sunDir, const Vec3& sunIntensity, float Km, float Kr, float g, const Vec3& rgbWaveLengths, bool forceImmediateUpdate = false) = 0; - - // Return Value: - // In logarithmic scale -4.0 .. 4.0 - virtual float GetLightsHDRDynamicPowerFactor() const = 0; - - // Return true if tessellation is allowed for given render object - virtual bool IsTessellationAllowed(const CRenderObject* pObj, const SRenderingPassInfo& passInfo, bool bIgnoreShadowPass = false) const = 0; - - // allows to modify material on render nodes at run-time (make sure it is properly restored back) - virtual void SetRenderNodeMaterialAtPosition(EERType eNodeType, const Vec3& vPos, _smart_ptr pMat) = 0; - - // override the camera precache point with the requested position for the current round - virtual void OverrideCameraPrecachePoint(const Vec3& vPos) = 0; - - // begin streaming of meshes and textures for specified position, pre-cache stops after fTimeOut seconds - virtual int AddPrecachePoint(const Vec3& vPos, const Vec3& vDir, float fTimeOut = 3.f, float fImportanceFactor = 1.0f) = 0; - virtual void ClearPrecachePoint(int id) = 0; - virtual void ClearAllPrecachePoints() = 0; - - virtual void GetPrecacheRoundIds(int pRoundIds[MAX_STREAM_PREDICTION_ZONES]) = 0; - - virtual void TraceFogVolumes(const Vec3& vPos, const AABB& objBBox, SFogVolumeData& fogVolData, const SRenderingPassInfo& passInfo, bool fogVolumeShadingQuality) = 0; - - //DOC-IGNORE-BEGIN - - // Internal functions, mostly used by the editor, which won't be documented for now - - // Summary: - // Removes all static objects on the map (for editor) - virtual void RemoveAllStaticObjects(int nSID = DEFAULT_SID) = 0; - - // Summary: - // Sets group parameters - virtual bool SetStatInstGroup(int nGroupId, const IStatInstGroup& siGroup, int nSID = 0) = 0; - - // Summary: - // Gets group parameters - virtual bool GetStatInstGroup(int nGroupId, IStatInstGroup& siGroup, int nSID = 0) = 0; - - //DOC-IGNORE-END - - // Summary: - // Notifies of an explosion, and maybe creates an hole in the terrain - // Description: - // This function should usually make sure that no static objects are near before making the hole. - // Arguments: - // vPos - Position of the explosion - // fRadius - Radius of the explosion - // bDeformTerrain - Allow to deform the terrain - virtual void OnExplosion(Vec3 vPos, float fRadius, bool bDeformTerrain = true) = 0; - - // Summary: - // Sets the physics material enumerator - // Arguments: - // pPhysMaterialEnumerator - The physics material enumarator to set - virtual void SetPhysMaterialEnumerator(IPhysMaterialEnumerator* pPhysMaterialEnumerator) = 0; - - // Summary: - // Gets the physics material enumerator - // Return Value: - // A pointer to an IPhysMaterialEnumerator derived object. - virtual IPhysMaterialEnumerator* GetPhysMaterialEnumerator() = 0; - - //DOC-IGNORE-BEGIN - //Internal functions - - // Summary: - // Allows to enable fog in editor - virtual void SetupDistanceFog() = 0; - - // Summary: - // Loads environment settings for specified mission - virtual void LoadMissionDataFromXMLNode(const char* szMissionName) = 0; - - virtual void LoadEnvironmentSettingsFromXML(XmlNodeRef pInputNode, int nSID = DEFAULT_SID) = 0; - - // Summary: - // This one is called by the editor when the terrain editing tools are not being built. - // This is the case when the game developers are using external tools to author terrain. - // The Octree data and the terrain heightmap data are stored in the same file. - // This method makes sure only the non-terrain data of the Octree is loaded. - virtual bool LoadCompiledOctreeForEditor() = 0; - - //DOC-IGNORE-END - - //DOC-IGNORE-BEGIN - // Set direction to the sun - // virtual void SetSunDir( const Vec3& vNewSunDir ) = 0; - - // Summary: - // Return non-normalized direction to the sun - virtual Vec3 GetSunDir() const = 0; - - // Summary: - // Return normalized direction to the sun - virtual Vec3 GetSunDirNormalized() const = 0; - - // Summary: - // Return realtime (updated every frame with real sun position) normalized direction to the scene - virtual Vec3 GetRealtimeSunDirNormalized() const = 0; - - //Internal function used by 3d engine and renderer - // Summary: - // Gets distance to the sector containig ocean water - virtual float GetDistanceToSectorWithWater() = 0; - //DOC-IGNORE-END - - // Summary: - // Gets the sun color - // Notes: - // Should have been specified in the editor. - // Return Value: - // An rgb value contained in a Vec3 object. - virtual Vec3 GetSunColor() const = 0; - - // Summary: - // Retrieves the current SSAO multiplier - // Notes: - // Return Value: - // scalar value - virtual float GetSSAOAmount() const = 0; - - // Summary: - // Retrieves the current SSAO contrast multiplier - // Notes: - // Return Value: - // scalar value - virtual float GetSSAOContrast() const = 0; - // Summary: - // Frees entity render info. - virtual void FreeRenderNodeState(IRenderNode* pEntity) = 0; - - // Summary: - // Adds the level's path to a specified filename. - // Arguments: - // szFileName - The filename for which we need to add the path - // Return Value: - // Full path for the filename; including the level path and the filename appended after. - virtual const char* GetLevelFilePath(const char* szFileName) = 0; - - // Summary: - // Displays statistic on the 3d Engine. - // Arguments: - // fTextPosX - X position for the text - // fTextPosY - Y position for the text - // fTextStepY - Amount of pixels to distance each line - // bEnhanced - false=normal, true=more interesting information - virtual void DisplayInfo(float& fTextPosX, float& fTextPosY, float& fTextStepY, bool bEnhanced) = 0; - - // Summary: - // Displays CPU and GPU memory usage statistics on screen - virtual void DisplayMemoryStatistics() = 0; - - // Summary: - // Draws text right aligned at the y pixel precision. - virtual void DrawTextRightAligned(const float x, const float y, const char* format, ...) PRINTF_PARAMS(4, 5) = 0; - virtual void DrawTextRightAligned(const float x, const float y, const float scale, const ColorF& color, const char* format, ...) PRINTF_PARAMS(6, 7) = 0; - - virtual void DrawBBoxHelper(const Vec3& vMin, const Vec3& vMax, ColorB col = Col_White) = 0; - virtual void DrawBBoxHelper(const AABB& box, ColorB col = Col_White) = 0; - - // Summary: - // Enables or disables portal at a specified position. - // Arguments: - // vPos - Position to place the portal - // bActivate - Set to true in order to enable the portal, or to false to disable - // szEntityName - - virtual void ActivatePortal(const Vec3& vPos, bool bActivate, const char* szEntityName) = 0; - - //DOC-IGNORE-BEGIN - // Summary: - // Counts memory usage - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - - // Summary: - // Counts resource memory usage - // Arguments: - // cstAABB - Use the whole level AABB if you want to grab the resources - // from the whole level. For height level, use something BIG - // (ie: +-FLT_MAX) - virtual void GetResourceMemoryUsage(ICrySizer* pSizer, const AABB& cstAABB) = 0; - //DOC-IGNORE-END - - // Summary: - // Creates a new VisArea. - // Return Value: - // A pointer to a newly created VisArea object - virtual IVisArea* CreateVisArea(uint64 visGUID) = 0; - - // Summary: - // Deletes a VisArea. - // Arguments: - // pVisArea - A pointer to the VisArea to delete - virtual void DeleteVisArea(IVisArea* pVisArea) = 0; - - //mat: todo - - // Summary: - // Updates the VisArea - // Arguments: - // pArea - - // pPoints - - // nCount - - // szName - - // info - - // bReregisterObjects - - virtual void UpdateVisArea(IVisArea* pArea, const Vec3* pPoints, int nCount, const char* szName, const SVisAreaInfo& info, bool bReregisterObjects) = 0; - - // Summary: - // Determines if two VisAreas are connected. - // Description: - // Used to determine if a sound is potentially hearable between two VisAreas. - // Arguments: - // pArea1 - A pointer to a VisArea - // pArea2 - A pointer to a VisArea - // nMaxRecursion - Maximum number of recursions to be done - // bSkipDisabledPortals - Indicate if disabled portals should be skipped - // Return Value: - // A boolean value set to true if the two VisAreas are connected, else false will be returned. - virtual bool IsVisAreasConnected(IVisArea* pArea1, IVisArea* pArea2, int nMaxRecursion = 1, bool bSkipDisabledPortals = true) = 0; - - // Summary: - // Creates a ClipVolume. - // Return Value: - // A pointer to a newly created ClipVolume object - virtual IClipVolume* CreateClipVolume() = 0; - - // Summary: - // Deletes a ClipVolume. - // Arguments: - // pClipVolume - A pointer to the ClipVolume to delete - virtual void DeleteClipVolume(IClipVolume* pClipVolume) = 0; - - // Summary: - // Updates a ClipVolume - // Arguments: - // pClipVolume - Pointer to volume that needs updating - // pRenderMesh - Pointer to new render mesh - // worldTM - Updated world transform - // szName - Updated ClipVolume name - virtual void UpdateClipVolume(IClipVolume* pClipVolume, _smart_ptr pRenderMesh, IBSPTree3D* pBspTree, const Matrix34& worldTM, bool bActive, uint32 flags, const char* szName) = 0; - - //mat: todo - - // Summary: - // Creates instance of IRenderNode object with specified type. - virtual IRenderNode* CreateRenderNode(EERType type) = 0; - - // Summary: - // Delete RenderNode object. - virtual void DeleteRenderNode(IRenderNode* pRenderNode) = 0; - - - // Summary: - // Gets wind direction and force, averaged within a box. - virtual Vec3 GetWind(const AABB& box, bool bIndoors) const = 0; - - // Summary: - // Gets the global wind vector. - virtual Vec3 GetGlobalWind(bool bIndoors) const = 0; - - // Summary: - // Gets wind direction and forace at the sample points provided. - // Note: the positions defining the samples will be overwritten - // with the accumulated wind influences. - virtual bool SampleWind(Vec3* pSamples, int nSamples, const AABB& volume, bool bIndoors) const = 0; - - // Description: - // Gets the VisArea which is present at a specified point. - // Arguments: - // vPos: - // Return Value: - // VisArea containing point, if any. 0 otherwise. - virtual IVisArea* GetVisAreaFromPos(const Vec3& vPos) = 0; - - // Description: - // Tests for intersection against Vis Areas. - // Arguments: - // box: Volume to test for intersection. - // pNodeCache (out, optional): Set to a cached pointer, for quicker calls to ClipToVisAreas. - // Return Value: - // Whether box intersects any vis areas. - virtual bool IntersectsVisAreas(const AABB& box, void** pNodeCache = 0) = 0; - - // Description: - // Clips geometry against the boundaries of VisAreas. - // Arguments: - // pInside: Vis Area to clip inside of. If 0, clip outside all Vis Areas. - // sphere - - // vNormal - - // pNodeChache - - // Return Value: - // Whether it was clipped - virtual bool ClipToVisAreas(IVisArea* pInside, Sphere& sphere, Vec3 const& vNormal, void* pNodeCache = 0) = 0; - - // Summary: - // Enables or disables ocean rendering. - // Arguments: - // bOcean - Will enable or disable the rendering of ocean - virtual void EnableOceanRendering(bool bOcean) = 0; - - // Description: - // Register a texture load handler - virtual void AddTextureLoadHandler(ITextureLoadHandler* pHandler) = 0; - - // Description - // Unregister a texture load handler - virtual void RemoveTextureLoadHandler(ITextureLoadHandler* pHandler) = 0; - - // Description: - // Get a texture load handler for a given extension - virtual ITextureLoadHandler* GetTextureLoadHandlerForImage(const char* ext) = 0; - // Summary: - // Creates a new light source. - // Return Value: - // Pointer to newly created light or -1 if it fails. - virtual struct ILightSource* CreateLightSource() = 0; - - // Summary: - // Deletes a light. - // Arguments: - // Pointer to the light - virtual void DeleteLightSource(ILightSource* pLightSource) = 0; - - // Summary: - // Gives access to the list holding all static light sources - // Return Value: - // An array holding all the CDLight pointers. - virtual const PodArray* GetLightEntities() = 0; - - // Summary: - // Gives access to list holding all lighting volumes - // Return Value: - // An array holding all the SLightVolume pointers. - virtual void GetLightVolumes(threadID nThreadID, SLightVolume*& pLightVols, uint32& nNumVols) = 0; - - // Summary: - // Registers a volume for lighting - // Return Value: - // The index of the registered volume. - virtual uint16 RegisterVolumeForLighting(const Vec3& vPos, f32 fRadius, uint8 nClipVolumeRef, const SRenderingPassInfo& passInfo) = 0; - - // Summary: - // Reload the heightmap. - // Description: - // Reloading the heightmap will resets all decals and particles. - // Notes: - // In future will restore deleted vegetations - // Returns: - // success - virtual bool RestoreTerrainFromDisk(int nSID = 0) = 0; - - //DOC-IGNORE-BEGIN - // tmp - virtual const char* GetFilePath(const char* szFileName) { return GetLevelFilePath(szFileName); } - //DOC-IGNORE-END - - // Summary: - // Post processing effects interfaces. - virtual class IPostEffectGroupManager* GetPostEffectGroups() const = 0; - virtual class IPostEffectGroup* GetPostEffectBaseGroup() const = 0; - - // Most code should use either GetPostEffectGroups() or GetPostEffectBaseGroup() instead of these - virtual void SetPostEffectParam(const char* pParam, float fValue, bool bForceValue = false) const = 0; - virtual void SetPostEffectParamVec4(const char* pParam, const Vec4& pValue, bool bForceValue = false) const = 0; - virtual void SetPostEffectParamString(const char* pParam, const char* pszArg) const = 0; - - virtual void GetPostEffectParam(const char* pParam, float& fValue) const = 0; - virtual void GetPostEffectParamVec4(const char* pParam, Vec4& pValue) const = 0; - virtual void GetPostEffectParamString(const char* pParam, const char*& pszArg) const = 0; - - virtual int32 GetPostEffectID(const char* pPostEffectName) = 0; - - virtual void ResetPostEffects(bool bOnSpecChange = false) = 0; - //Disable post effect groups other than default and base. - virtual void DisablePostEffects() = 0; - - virtual void SetShadowsGSMCache(bool bCache) = 0; - virtual void SetCachedShadowBounds(const AABB& shadowBounds, float fAdditionalCascadesScale) = 0; - virtual void SetRecomputeCachedShadows(uint nUpdateStrategy = 0) = 0; - - // Summary: - // In debug mode check memory heap and makes assert, do nothing in release - virtual void CheckMemoryHeap() = 0; - - // Summary: - // Removes all decals attached to specified entity. - virtual void DeleteEntityDecals(IRenderNode* pEntity) = 0; - - // Summary: - // Disables CGFs unloading. - virtual void LockCGFResources() = 0; - - // Summary: - // Enables CGFs unloading (this is default state), this function will also release all not used CGF's. - virtual void UnlockCGFResources() = 0; - - // Summary: - // Release all unused CGFs. - virtual void FreeUnusedCGFResources() = 0; - - - // Summary: - // Creates static object containing empty IndexedMesh. - virtual IStatObj* CreateStatObj() = 0; - virtual IStatObj* CreateStatObjOptionalIndexedMesh(bool createIndexedMesh) = 0; - - // Summary: - // Creates the instance of the indexed mesh. - virtual IIndexedMesh* CreateIndexedMesh() = 0; - - // Summary: - // Saves/loads state of engine objects. - virtual void SerializeState(TSerialize ser) = 0; - - // Summary: - // Cleanups after save/load. - virtual void PostSerialize(bool bReading) = 0; - - // Description: - // Retrieve pointer to the material i/o interface. - virtual IMaterialHelpers& GetMaterialHelpers() = 0; - - // Description: - // Retrieve pointer to the material manager interface. - virtual IMaterialManager* GetMaterialManager() = 0; - - // Description: - // Retrieve pointer to the object manager interface. - virtual IObjManager* GetObjManager() = 0; - - ////////////////////////////////////////////////////////////////////////// - // CGF Loader. - ////////////////////////////////////////////////////////////////////////// - // Description: - // Creates a chunkfile content instance - // Returns 'NULL' if the memory for the instance could not be allocated - virtual CContentCGF* CreateChunkfileContent(const char* filename) = 0; - - // Description: - // Deletes the chunkfile content instance - virtual void ReleaseChunkfileContent(CContentCGF*) = 0; - - // Description: - // Loads the contents of a chunkfile into the given CContentCGF. - // Returns 'false' on error. - virtual bool LoadChunkFileContent(CContentCGF* pCGF, const char* filename, bool bNoWarningMode = false, bool bCopyChunkFile = true) = 0; - - // Description: - // Loads the contents of a chunkfile into the given CContentCGF. - // Returns 'false' on error. - virtual bool LoadChunkFileContentFromMem(CContentCGF* pCGF, const void* pData, size_t nDataLen, uint32 nLoadingFlags, bool bNoWarningMode = false, bool bCopyChunkFile = true) = 0; - - // Description: - // Creates ChunkFile. - virtual IChunkFile* CreateChunkFile(bool bReadOnly = false) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Chunk file writer. - ////////////////////////////////////////////////////////////////////////// - enum EChunkFileFormat - { - eChunkFileFormat_0x745, - eChunkFileFormat_0x746, - }; - virtual ChunkFile::IChunkFileWriter* CreateChunkFileWriter(EChunkFileFormat eFormat, AZ::IO::IArchive* pPak, const char* filename) const = 0; - virtual void ReleaseChunkFileWriter(ChunkFile::IChunkFileWriter* p) const = 0; - - // Description: - // Returns true if the ocean was created successfully. - virtual bool CreateOcean(_smart_ptr pTerrainWaterMat, float waterLevel) = 0; - - // Description: - // Deletes the ocean if it exists, otherwise does nothing. - virtual void DeleteOcean() = 0; - - // Description: - // Changes ocean material if the ocean exists. - virtual void ChangeOceanMaterial(_smart_ptr pMat) = 0; - - // Description: - // Changes ocean water level if the ocean exists. - virtual void ChangeOceanWaterLevel(float fWaterLevel) = 0; - - virtual void InitMaterialDefautMappingAxis(_smart_ptr pMat) = 0; - - // Description: - // Returns interface to visarea manager. - virtual IVisAreaManager* GetIVisAreaManager() = 0; - - // Description: - // Places camera into every visarea or every manually set pre-cache points and render the scenes. - virtual void PrecacheLevel(bool bPrecacheAllVisAreas, Vec3* pPrecachePoints, int nPrecachePointsNum) = 0; - - // Description: - // Proposes 3dengine to load on next frame all shaders and textures synchronously. - virtual void ProposeContentPrecache() = 0; - - - - // Description: - // Returns TOD interface. - virtual ITimeOfDay* GetTimeOfDay() = 0; - - // Description: - // Updates the sky material paths. LoadSkyMaterial will handle loading these materials. - virtual void SetSkyMaterialPath(const string& skyMaterialPath) = 0; - virtual void SetSkyLowSpecMaterialPath(const string& skyMaterialPath) = 0; - - // Description: - // Loads the sky material for the level. e_SkyType will determine if we load the low spec sky material or the regular sky material. - virtual void LoadSkyMaterial() = 0; - - // Description: - // Returns SkyBox material. - virtual _smart_ptr GetSkyMaterial() = 0; - - // Description: - // Sets SkyBox Material. - virtual void SetSkyMaterial(_smart_ptr pSkyMat) = 0; - - // Description: - // Sets global 3d engine parameter. - virtual void SetGlobalParameter(E3DEngineParameter param, const Vec3& v) = 0; - void SetGlobalParameter(E3DEngineParameter param, float val) { SetGlobalParameter(param, Vec3(val, 0, 0)); }; - - // Description: - // Retrieves global 3d engine parameter. - virtual void GetGlobalParameter(E3DEngineParameter param, Vec3& v) = 0; - float GetGlobalParameter(E3DEngineParameter param) { Vec3 v(0, 0, 0); GetGlobalParameter(param, v); return v.x; }; - - virtual void SetShadowMode(EShadowMode shadowMode) = 0; - virtual EShadowMode GetShadowMode() const = 0; - virtual void AddPerObjectShadow(IShadowCaster* pCaster, float fConstBias, float fSlopeBias, float fJitter, const Vec3& vBBoxScale, uint nTexSize) = 0; - virtual void RemovePerObjectShadow(IShadowCaster* pCaster) = 0; - virtual struct SPerObjectShadow* GetPerObjectShadow(IShadowCaster* pCaster) = 0; - virtual void GetCustomShadowMapFrustums(struct ShadowMapFrustum*& arrFrustums, int& nFrustumCount) = 0; - - // Description: - // Saves pStatObj to a stream. - // Notes: - // Full mesh for generated ones, path/geom otherwise - virtual int SaveStatObj(IStatObj* pStatObj, TSerialize ser) = 0; - // Description: - // Loads statobj from a stream - virtual IStatObj* LoadStatObj(TSerialize ser) = 0; - - // Description: - // Returns true if input line segment intersect clouds sprites. - virtual bool CheckIntersectClouds(const Vec3& p1, const Vec3& p2) = 0; - - // Description: - // Removes references to RenderMesh - virtual void OnRenderMeshDeleted(IRenderMesh* pRenderMesh) = 0; - - // Used to highlight an object under the reticule - virtual void DebugDraw_UpdateDebugNode() = 0; - - // Description: - // Used by editor during AO computations - virtual bool RayObjectsIntersection2D(Vec3 vStart, Vec3 vEnd, Vec3& vHitPoint, EERType eERType) = 0; - - - // Description: - // Used by editor during object alignment - virtual bool RenderMeshRayIntersection(IRenderMesh* pRenderMesh, SRayHitInfo& hitInfo, _smart_ptr pCustomMtl = 0) = 0; - - virtual void CheckCreateRNTmpData(CRNTmpData** ppInfo, IRenderNode* pRNode, const SRenderingPassInfo& passInfo) = 0; - - // Description: - // Frees lod transition state - virtual void FreeRNTmpData(CRNTmpData** ppInfo) = 0; - - // Description: - // Returns true if the Octree is ready. - virtual bool IsObjectTreeReady() = 0; - - virtual IOctreeNode* GetIObjectTree() = 0; - - // Description: - // Call function 2 times (first to get the size then to fill in the data) - // Arguments: - // pObjects - 0 if only the count is required - // Return Value: - // Count returned - virtual uint32 GetObjectsByType(EERType objType, IRenderNode** pObjects = 0) = 0; - virtual uint32 GetObjectsByTypeInBox(EERType objType, const AABB& bbox, IRenderNode** pObjects = 0, ObjectTreeQueryFilterCallback filterCallback = nullptr) = 0; - virtual uint32 GetObjectsInBox(const AABB& bbox, IRenderNode** pObjects = 0) = 0; - virtual uint32 GetObjectsByFlags(uint dwFlag, IRenderNode** pObjects = 0) = 0; - - // variant which takes a POD array which is resized in the function itself - virtual void GetObjectsByTypeInBox(EERType objType, const AABB& bbox, PodArray* pLstObjects, ObjectTreeQueryFilterCallback filterCallback = nullptr) = 0; - - // Called from editor whenever an object is modified by the user - virtual void OnObjectModified(IRenderNode* pRenderNode, uint dwFlags) = 0; - - virtual void FillDebugFPSInfo(SDebugFPSInfo&) = 0; - - virtual const char* GetLevelFolder() = 0; - - virtual bool IsAreaActivationInUse() = 0; - - virtual void RenderRenderNode_ShadowPass(IShadowCaster* pRNode, const SRenderingPassInfo& passInfo, AZ::LegacyJobExecutor* pJobExecutor) = 0; - - virtual IOpticsManager* GetOpticsManager() = 0; - - // Description: - // Syncs and performs outstanding operations for the Asyncrhon ProcessStreaming Update - virtual void SyncProcessStreamingUpdate() = 0; - - // Set Callback for Editor to store additional information in Minimap tool - virtual void SetScreenshotCallback(IScreenshotCallback* pCallback) = 0; - - // Show/Hide objects by layer (useful for streaming and performance) - virtual void ActivateObjectsLayer(uint16 nLayerId, bool bActivate, bool bPhys, bool bObjects, bool bStaticLights, const char* pLayerName, IGeneralMemoryHeap* pHeap = NULL, bool bCheckLayerActivation = true) = 0; - - // Get object layer memory usage - virtual void GetLayerMemoryUsage(uint16 nLayerId, ICrySizer* pSizer, int* pNumBrushes, int* pNumDecals) const = 0; - - // Collect layer ID's to skip loading objects from these layers, e.g. to skip console specific layers - virtual void SkipLayerLoading(uint16 nLayerId, bool bClearList) = 0; - - // Activate streaming of render node and all sub-components - virtual void PrecacheRenderNode(IRenderNode* pObj, float fEntDistanceReal) = 0; - - virtual IDeferredPhysicsEventManager* GetDeferredPhysicsEventManager() = 0; - - virtual void SetStreamableListener(IStreamedObjectListener* pListener) = 0; - - // following functions are used by SRenderingPassInfo - virtual CCamera* GetRenderingPassCamera(const CCamera& rCamera) = 0; - - struct SSvoStaticTexInfo - { - SSvoStaticTexInfo() - { - ZeroStruct(*this); - } - - // SVO data pools - ITexture* pTexTree; - ITexture* pTexOpac; - ITexture* pTexRgb0; - ITexture* pTexRgb1; - ITexture* pTexDynl; - ITexture* pTexRgb2; - ITexture* pTexRgb3; - ITexture* pTexNorm; - ITexture* pTexAldi; - - ITexture* pGlobalSpecCM; - - float fGlobalSpecCM_Mult; - int nTexDimXY; - int nTexDimZ; - int nBrickSize; - bool bSvoReady; - bool bSvoFreeze; - }; - - struct SLightTI - { - Vec4 vPosR; - Vec4 vDirF; - Vec4 vCol; - float fSortVal; - class ITexture* pCM; - }; - - virtual void GetSvoStaticTextures(I3DEngine::SSvoStaticTexInfo& svoInfo, PodArray* pLightsTI_S, PodArray* pLightsTI_D) = 0; - - struct SSvoNodeInfo - { - AABB wsBox; - AABB tcBox; - int nAtlasOffset; - }; - - virtual void GetSvoBricksForUpdate(PodArray& arrNodeInfo, bool getDynamic) = 0; - -#if defined(USE_GEOM_CACHES) - // Summary: - // Loads a geometry cache from a CAX file. - // See Also: - // IGeomCache - // Arguments: - // szFileName - CAX Filename - should not be 0 or "" - // Return Value: - // A pointer to an object derived from IGeomCache. - virtual IGeomCache* LoadGeomCache(const char* szFileName) = 0; - - // Finds a geom cache created from the given filename - // See Also: - // IGeomCache - // Arguments: - // szFileName - CAX Filename - should not be 0 or "" - // Return Value: - // A pointer to an object derived from IGeomCache. - virtual IGeomCache* FindGeomCacheByFilename(const char* szFileName) = 0; -#endif - - // Summary: - // Loads a designer object from a stream of _decoded_ binary node. (Base64Decode) - // Arguments: - // szBinaryStream - decoded stream + size - virtual IStatObj* LoadDesignerObject(int nVersion, const char* szBinaryStream, int size) = 0; - - // Summary: - // Makes sure all queued culling jobs are completely finished. - // This is useful when adding or removing Components that trigger AZ::Job creation - // like the terrain system. It is important to complete those jobs before removing - // such type of components. - virtual void WaitForCullingJobsCompletion() = 0; - - // -}; - -#pragma pack(pop) - -#include - -// state of 3dengine during rendering -// used to prevent global state -struct SRenderingPassInfo -{ - enum EShadowMapType - { - SHADOW_MAP_NONE = 0, - SHADOW_MAP_GSM, - SHADOW_MAP_LOCAL, - SHADOW_MAP_CACHED, - SHADOW_MAP_CACHED_MGPU_COPY - }; - - // enum flags to identify which objects to skip for this pass - enum ESkipRenderingFlags - { - SHADOWS = BIT(0), - ENTITIES = BIT(3), - WATEROCEAN = BIT(5), - DECALS = BIT(7), - MERGED_MESHES = BIT(10), - ROADS = BIT(13), - WATER_VOLUMES = BIT(14), - CLOUDS = BIT(15), - CUBEMAP_GEN = BIT(16), - GEOM_CACHES = BIT(17), - DISABLE_RENDER_CHUNK_MERGE = BIT(18), - - // below are precombined flags - STATIC_OBJECTS = ENTITIES, - DEFAULT_FLAGS = SHADOWS | ENTITIES | WATEROCEAN | DECALS | MERGED_MESHES | ROADS | WATER_VOLUMES | CLOUDS | GEOM_CACHES, - DEFAULT_RECURSIVE_FLAGS = ENTITIES | WATEROCEAN | DECALS | MERGED_MESHES | ROADS | WATER_VOLUMES | CLOUDS | GEOM_CACHES - }; - - // creating function for RenderingPassInfo, the create functions will fetch all other necessary - // information like thread id/frame id, etc - static SRenderingPassInfo CreateGeneralPassRenderingInfo(const CCamera& rCamera, uint32 nRenderingFlags = DEFAULT_FLAGS, bool bAuxWindow = false); - static SRenderingPassInfo CreateRecursivePassRenderingInfo(const CCamera& rCamera, uint32 nRenderingFlags = DEFAULT_RECURSIVE_FLAGS); - static SRenderingPassInfo CreateShadowPassRenderingInfo(const CCamera& rCamera, int nLightFlags, int nShadowMapLod, bool bExtendedLod, bool bIsMGPUCopy, uint32* pShadowGenMask, uint32 nSide, uint32 nShadowFrustumID, uint32 nRenderingFlags = DEFAULT_FLAGS); - static SRenderingPassInfo CreateTempRenderingInfo(const CCamera& rCamera, const SRenderingPassInfo& rPassInfo); - static SRenderingPassInfo CreateTempRenderingInfo(uint32 nRenderingFlags, const SRenderingPassInfo& rPassInfo); - - // state getter - bool IsGeneralPass() const; - - bool IsRecursivePass() const; - uint32 GetRecursiveLevel() const; - - bool IsShadowPass() const; - bool IsCachedShadowPass() const; - EShadowMapType GetShadowMapType() const; - bool IsDisableRenderChunkMerge() const; - - bool IsAuxWindow() const; - - threadID ThreadID() const; - void SetThreadID(threadID id) { m_nThreadID = static_cast(id); } - - int GetFrameID() const; - uint32 GetMainFrameID() const; - - const CCamera& GetCamera() const; - bool IsCameraUnderWater() const; - - float GetZoomFactor() const; - float GetInverseZoomFactor() const; - bool RenderShadows() const; - bool RenderEntities() const; - bool RenderWaterOcean() const; - bool RenderDecals() const; - bool RenderWaterVolumes() const; - bool RenderClouds() const; - bool RenderGeomCaches() const; - - bool IsRenderingCubemap() const; - - uint32* ShadowGenMaskAddress() const; - uint32 ShadowFrustumID() const; - uint8 ShadowFrustumSide() const; - uint8 ShadowFrustumLod() const; - - CRenderView* GetRenderView() const; - - SRenderingPassInfo(threadID id) - { - SRenderingPassInfo(); - SetThreadID(id); - m_pRenderView = gEnv->pRenderer->GetRenderViewForThread(id); - } - -private: - - // private constructor, creation is only allowed with create functions - SRenderingPassInfo() - : pShadowGenMask(NULL) - , nShadowSide(0) - , nShadowLod(0) - , nShadowFrustumId(0) - , m_bAuxWindow(0) - , m_nRenderStackLevel(0) - , m_eShadowMapRendering(static_cast(SHADOW_MAP_NONE)) - , m_bCameraUnderWater(0) - , m_nRenderingFlags(0) - , m_fZoomFactor(0.0f) - , m_pCamera(NULL) - { - threadID nThreadID = 0; - gEnv->pRenderer->EF_Query(EFQ_MainThreadList, nThreadID); - m_nThreadID = aznumeric_caster(nThreadID); - m_nRenderFrameID = gEnv->pRenderer->GetFrameID(); - m_nRenderMainFrameID = gEnv->pRenderer->GetFrameID(false); - m_pRenderView = gEnv->pRenderer->GetRenderViewForThread(m_nThreadID); - } - - void InitRenderingFlags(uint32 nRenderingFlags); - void SetCamera(const CCamera& cam); - - uint8 m_nThreadID; - uint8 m_nRenderStackLevel; - uint8 m_eShadowMapRendering; // State flag denoting what type of shadow map is being currently rendered into - uint8 m_bCameraUnderWater; - - uint32 m_nRenderingFlags; - - float m_fZoomFactor; - - int m_nRenderFrameID; - uint32 m_nRenderMainFrameID; - - const CCamera* m_pCamera; - - // Render view used for this rendering pass - CRenderView* m_pRenderView; - - // members used only in shadow pass - uint32* pShadowGenMask; - uint32 nShadowFrustumId; - uint8 nShadowSide : 4; - uint8 nShadowLod : 4; - uint8 m_bAuxWindow; -}; - -/////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsGeneralPass() const -{ - return m_nRenderStackLevel == 0 && m_bAuxWindow == 0 && static_cast(m_eShadowMapRendering) == SHADOW_MAP_NONE; -} - -/////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsRecursivePass() const -{ - return m_nRenderStackLevel > 0; -} - -/////////////////////////////////////////////////////////////////////////////// -inline uint32 SRenderingPassInfo::GetRecursiveLevel() const -{ - return m_nRenderStackLevel; -} - -/////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsShadowPass() const -{ - return static_cast(m_eShadowMapRendering) != SHADOW_MAP_NONE; -} - -/////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsCachedShadowPass() const -{ - return IsShadowPass() && - (GetShadowMapType() == SRenderingPassInfo::SHADOW_MAP_CACHED || - GetShadowMapType() == SRenderingPassInfo::SHADOW_MAP_CACHED_MGPU_COPY); -} -/////////////////////////////////////////////////////////////////////////////// -inline SRenderingPassInfo::EShadowMapType SRenderingPassInfo::GetShadowMapType() const -{ - assert(IsShadowPass()); - return static_cast(m_eShadowMapRendering); -} - -/////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsAuxWindow() const -{ - return m_bAuxWindow != 0; -} - -/////////////////////////////////////////////////////////////////////////////// -inline threadID SRenderingPassInfo::ThreadID() const -{ - return m_nThreadID; -} - -/////////////////////////////////////////////////////////////////////////////// -inline int SRenderingPassInfo::GetFrameID() const -{ - return m_nRenderFrameID; -} - -/////////////////////////////////////////////////////////////////////////////// -inline uint32 SRenderingPassInfo::GetMainFrameID() const -{ - return m_nRenderMainFrameID; -} - -/////////////////////////////////////////////////////////////////////////////// -inline const CCamera& SRenderingPassInfo::GetCamera() const -{ - assert(m_pCamera != NULL); - return *m_pCamera; -} - -/////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsCameraUnderWater() const -{ - return m_bCameraUnderWater != 0; -} - -/////////////////////////////////////////////////////////////////////////////// -inline float SRenderingPassInfo::GetZoomFactor() const -{ - return m_fZoomFactor; -} - -/////////////////////////////////////////////////////////////////////////////// -inline float SRenderingPassInfo::GetInverseZoomFactor() const -{ - return 1.0f / m_fZoomFactor; -} - - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::RenderShadows() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::SHADOWS) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::RenderEntities() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::ENTITIES) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::RenderWaterOcean() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::WATEROCEAN) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::RenderDecals() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::DECALS) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::RenderWaterVolumes() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::WATER_VOLUMES) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::RenderClouds() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::CLOUDS) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::RenderGeomCaches() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::GEOM_CACHES) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsRenderingCubemap() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::CUBEMAP_GEN) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline bool SRenderingPassInfo::IsDisableRenderChunkMerge() const -{ - return (m_nRenderingFlags& SRenderingPassInfo::DISABLE_RENDER_CHUNK_MERGE) != 0; -} - -//////////////////////////////////////////////////////////////////////////////// -inline uint32* SRenderingPassInfo::ShadowGenMaskAddress() const -{ - assert(pShadowGenMask); - return pShadowGenMask; -} - -//////////////////////////////////////////////////////////////////////////////// -inline uint32 SRenderingPassInfo::ShadowFrustumID() const -{ - return nShadowFrustumId; -} - -//////////////////////////////////////////////////////////////////////////////// -inline uint8 SRenderingPassInfo::ShadowFrustumSide() const -{ - return nShadowSide; -} - -//////////////////////////////////////////////////////////////////////////////// -inline uint8 SRenderingPassInfo::ShadowFrustumLod() const -{ - return nShadowLod; -} -//////////////////////////////////////////////////////////////////////////////// -inline CRenderView* SRenderingPassInfo::GetRenderView() const -{ - return m_pRenderView; -} -//////////////////////////////////////////////////////////////////////////////// -inline void SRenderingPassInfo::SetCamera(const CCamera& cam) -{ - m_pCamera = gEnv->p3DEngine->GetRenderingPassCamera(cam); - m_bCameraUnderWater = gEnv->p3DEngine->IsUnderWater(cam.GetPosition()); - m_fZoomFactor = 0.2f + 0.8f * (RAD2DEG(cam.GetFov()) / 60.f); -} - -//////////////////////////////////////////////////////////////////////////////// -inline void SRenderingPassInfo::InitRenderingFlags(uint32 nRenderingFlags) -{ - m_nRenderingFlags = nRenderingFlags; -#if (ALLOW_CONST_CVAR_MODIFICATIONS) - static ICVar* pDefaultMaterial = gEnv->pConsole->GetCVar("e_DefaultMaterial"); - static ICVar* pShadows = gEnv->pConsole->GetCVar("e_Shadows"); - static ICVar* pEntities = gEnv->pConsole->GetCVar("e_Entities"); - static ICVar* pWaterOcean = gEnv->pConsole->GetCVar("e_WaterOcean"); - static ICVar* pDecals = gEnv->pConsole->GetCVar("e_Decals"); - static ICVar* pWaterVolumes = gEnv->pConsole->GetCVar("e_WaterVolumes"); - static ICVar* pClouds = gEnv->pConsole->GetCVar("e_Clouds"); - static ICVar* pGeomCaches = gEnv->pConsole->GetCVar("e_GeomCaches"); - - if (pShadows->GetIVal() == 0) - { - m_nRenderingFlags &= ~SRenderingPassInfo::SHADOWS; - } - if (pEntities->GetIVal() == 0) - { - m_nRenderingFlags &= ~SRenderingPassInfo::ENTITIES; - } - if (pWaterOcean->GetIVal() == 0) - { - m_nRenderingFlags &= ~SRenderingPassInfo::WATEROCEAN; - } - if (pDecals->GetIVal() == 0) - { - m_nRenderingFlags &= ~SRenderingPassInfo::DECALS; - } - if (pWaterVolumes->GetIVal() == 0) - { - m_nRenderingFlags &= ~SRenderingPassInfo::WATER_VOLUMES; - } - if (pClouds->GetIVal() == 0) - { - m_nRenderingFlags &= ~SRenderingPassInfo::CLOUDS; - } - if (pGeomCaches->GetIVal() == 0) - { - m_nRenderingFlags &= ~SRenderingPassInfo::GEOM_CACHES; - } - - // on dedicated server, never render any object at all - if (gEnv->IsDedicated()) - { - m_nRenderingFlags = 0; - } -#endif // (ALLOW_CONST_CVAR_MODIFICATIONS) -} - -//////////////////////////////////////////////////////////////////////////////// -inline SRenderingPassInfo SRenderingPassInfo::CreateGeneralPassRenderingInfo(const CCamera& rCamera, uint32 nRenderingFlags, bool bAuxWindow) -{ - static ICVar* pCameraFreeze = gEnv->pConsole->GetCVar("e_CameraFreeze"); - - // Update Camera only if e_camerafreeze is not set - const CCamera& rCameraToSet = (pCameraFreeze && pCameraFreeze->GetIVal() != 0) ? gEnv->p3DEngine->GetRenderingCamera() : rCamera; - - SRenderingPassInfo passInfo; - passInfo.SetCamera(rCameraToSet); - passInfo.InitRenderingFlags(nRenderingFlags); - passInfo.m_bAuxWindow = bAuxWindow; - - return passInfo; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRenderingPassInfo SRenderingPassInfo::CreateRecursivePassRenderingInfo(const CCamera& rCamera, uint32 nRenderingFlags) -{ - static ICVar* pRecursionViewDistRatio = gEnv->pConsole->GetCVar("e_RecursionViewDistRatio"); - - SRenderingPassInfo passInfo; - passInfo.m_nRenderStackLevel = 1; - passInfo.SetCamera(rCamera); - - // adjust view distance in recursive mode by adjusting the ZoomFactor - passInfo.m_fZoomFactor /= pRecursionViewDistRatio->GetFVal(); - - passInfo.InitRenderingFlags(nRenderingFlags); - - return passInfo; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRenderingPassInfo SRenderingPassInfo::CreateShadowPassRenderingInfo(const CCamera& rCamera, int nLightFlags, int nShadowMapLod, bool bExtendedLod, bool bIsMGPUCopy, uint32* pShadowGenMask, uint32 nSide, uint32 nShadowFrustumID, uint32 nRenderingFlags) -{ - SRenderingPassInfo passInfo; - passInfo.SetCamera(rCamera); - passInfo.InitRenderingFlags(nRenderingFlags); - - // set correct shadow map type - if (nLightFlags & DLF_SUN) - { - assert(nShadowMapLod >= 0 && nShadowMapLod < 8); - if (bExtendedLod) - { - passInfo.m_eShadowMapRendering = bIsMGPUCopy ? static_cast(SHADOW_MAP_CACHED_MGPU_COPY) : static_cast(SHADOW_MAP_CACHED); - } - else - { - passInfo.m_eShadowMapRendering = static_cast(SHADOW_MAP_GSM); - } - } - else if (nLightFlags & (DLF_POINT | DLF_PROJECT | DLF_AREA_LIGHT)) - { - passInfo.m_eShadowMapRendering = static_cast(SHADOW_MAP_LOCAL); - } - else - { - passInfo.m_eShadowMapRendering = static_cast(SHADOW_MAP_NONE); - } - - passInfo.pShadowGenMask = pShadowGenMask; - passInfo.nShadowSide = nSide; - passInfo.nShadowLod = nShadowMapLod; - passInfo.nShadowFrustumId = nShadowFrustumID; - - return passInfo; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRenderingPassInfo SRenderingPassInfo::CreateTempRenderingInfo(const CCamera& rCamera, const SRenderingPassInfo& rPassInfo) -{ - SRenderingPassInfo passInfo = rPassInfo; - passInfo.SetCamera(rCamera); - - passInfo.pShadowGenMask = NULL; - passInfo.nShadowSide = 0; - passInfo.nShadowFrustumId = 0; - - return passInfo; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRenderingPassInfo SRenderingPassInfo::CreateTempRenderingInfo(uint32 nRenderingFlags, const SRenderingPassInfo& rPassInfo) -{ - SRenderingPassInfo passInfo = rPassInfo; - passInfo.m_nRenderingFlags = nRenderingFlags; - return passInfo; -} - -/////////////////////////////////////////////////////////////////////////////// -// class to wrap a special counter used to presort SRendItems -// this is used to fix random ordering introduced by parallelization -// of parts of the 3DEngine -struct SRendItemSorter -{ - // Deferred PreProcess needs a special ordering, use these to prefix the values - // to ensure the deferred shading pass is after all LPV objects - enum EDeferredPreprocess - { - eLPVPass = 0, - eDeferredShadingPass = BIT(30) - }; - - static SRendItemSorter CreateRendItemSorter(const SRenderingPassInfo& passInfo); - static SRendItemSorter CreateShadowPassRendItemSorter(const SRenderingPassInfo& passInfo); - static SRendItemSorter CreateParticleRendItemSorter(const SRenderingPassInfo& passInfo); - static SRendItemSorter CreateDeferredPreProcessRendItemSorter(const SRenderingPassInfo& passInfo, EDeferredPreprocess deferredPrerocessType); - static SRendItemSorter CreateDefaultRendItemSorter(); - - void IncreaseOctreeCounter() { nValue += eOctreeNodeCounter; } - void IncreaseObjectCounter() { nValue += eObjectCounter; } - void IncreaseGroupCounter() { nValue += eGroupCounter; } - - void IncreaseParticleCounter() { nValue += eParticleCounter; } - uint32 ParticleCounter() const { return nValue & ~eRecursivePassMask; } - - uint32 ShadowFrustumID() const { return nValue & ~eRecursivePassMask; } - - uint32 GetValue() const { return nValue; } - - bool operator<(const SRendItemSorter& rOther) const - { - return nValue < rOther.nValue; - } - - bool IsRecursivePass() const { return (nValue & eRecursivePassMask) != 0; } - - SRendItemSorter() - : nValue(0) {} - explicit SRendItemSorter(uint32 _nValue) - : nValue(_nValue) {} - -private: - // encode various counter in a single value - enum - { - eRecursivePassMask = BIT(31) - }; // present in all combinations - - // flags used for regular SRendItems - enum - { - eObjectCounter = BIT(0) - }; // bits 0-14 used - enum - { - eOctreeNodeCounter = BIT(14) - }; // bits 15-27 used - enum - { - eGroupCounter = BIT(27) - }; // bits 28-31 used - - // flags used for Particles - enum - { - eParticleCounter = BIT(0) - }; - - uint32 nValue; -}; - -/////////////////////////////////////////////////////////////////////////////// -inline SRendItemSorter SRendItemSorter::CreateRendItemSorter(const SRenderingPassInfo& passInfo) -{ - SRendItemSorter rendItemSorter; - rendItemSorter.nValue = 0; - rendItemSorter.nValue |= passInfo.IsRecursivePass() ? eRecursivePassMask : 0; - return rendItemSorter; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRendItemSorter SRendItemSorter::CreateShadowPassRendItemSorter(const SRenderingPassInfo& passInfo) -{ - SRendItemSorter rendItemSorter; - rendItemSorter.nValue = passInfo.ShadowFrustumID(); - rendItemSorter.nValue |= passInfo.IsRecursivePass() ? eRecursivePassMask : 0; - return rendItemSorter; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRendItemSorter SRendItemSorter::CreateParticleRendItemSorter(const SRenderingPassInfo& passInfo) -{ - SRendItemSorter rendItemSorter; - rendItemSorter.nValue = 0; - rendItemSorter.nValue |= passInfo.IsRecursivePass() ? eRecursivePassMask : 0; - return rendItemSorter; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRendItemSorter SRendItemSorter::CreateDeferredPreProcessRendItemSorter(const SRenderingPassInfo& passInfo, EDeferredPreprocess deferredPrerocessType) -{ - SRendItemSorter rendItemSorter; - rendItemSorter.nValue = 0; - rendItemSorter.nValue |= passInfo.IsRecursivePass() ? eRecursivePassMask : 0; - rendItemSorter.nValue |= deferredPrerocessType; - return rendItemSorter; -} - -/////////////////////////////////////////////////////////////////////////////// -inline SRendItemSorter SRendItemSorter::CreateDefaultRendItemSorter() -{ - SRendItemSorter rendItemSorter; - rendItemSorter.nValue = 0; - return rendItemSorter; -} - -//Legacy Bus for communicating with SVOGI from the legacy engine code. -class SVOGILegacyRequests - : public AZ::EBusTraits -{ -public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - using MutexType = AZStd::recursive_mutex; -// static const bool LocklessDispatch = true; - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // Triggers an update of voxel data. - virtual void UpdateVoxelData() = 0; - - ////////////////////////////////////////////////////////////////////////// - // Triggers an update of voxel data to GPU. - virtual void UpdateRenderData() = 0; - - ////////////////////////////////////////////////////////////////////////// - // Called at framestart - virtual void OnFrameStart(const SRenderingPassInfo& passInfo) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Gets the textures bound for GI plus lighting data. - virtual void GetSvoStaticTextures(I3DEngine::SSvoStaticTexInfo& svoInfo, PodArray* pLightsTI_S, PodArray* pLightsTI_D) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Generates a list of bricks that need to be updated in compute shaders. - virtual void GetSvoBricksForUpdate(PodArray& arrNodeInfo, bool getDynamic) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Causes the GI system to free all voxel data. - virtual void ReleaseData() = 0; - - ////////////////////////////////////////////////////////////////////////// - // Register and unregister a mutex to protect assets during rendering. - virtual void RegisterMutex(AZStd::mutex* mutex) = 0; - virtual void UnregisterMutex() = 0; - -}; -using SVOGILegacyRequestBus = AZ::EBus; - - -#endif // CRYINCLUDE_CRYCOMMON_I3DENGINE_H - diff --git a/Code/CryEngine/CryCommon/I3DEngine_info.h b/Code/CryEngine/CryCommon/I3DEngine_info.h deleted file mode 100644 index f1c601fcc6..0000000000 --- a/Code/CryEngine/CryCommon/I3DEngine_info.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMON_I3DENGINE_INFO_H -#define CRYINCLUDE_CRYCOMMON_I3DENGINE_INFO_H -#pragma once - -#include "TypeInfo_impl.h" -#include "IShader_info.h" -#include // <> required for Interfuscator - -STRUCT_INFO_BEGIN(SVisAreaManChunkHeader) -STRUCT_VAR_INFO(nVersion, TYPE_INFO(int8)) -STRUCT_VAR_INFO(nDummy, TYPE_INFO(int8)) -STRUCT_VAR_INFO(nFlags, TYPE_INFO(int8)) -STRUCT_VAR_INFO(nFlags2, TYPE_INFO(int8)) -STRUCT_VAR_INFO(nChunkSize, TYPE_INFO(int)) -STRUCT_VAR_INFO(nVisAreasNum, TYPE_INFO(int)) -STRUCT_VAR_INFO(nPortalsNum, TYPE_INFO(int)) -STRUCT_VAR_INFO(nOcclAreasNum, TYPE_INFO(int)) -STRUCT_INFO_END(SVisAreaManChunkHeader) - -STRUCT_INFO_BEGIN(SOcTreeNodeChunk) -STRUCT_VAR_INFO(nChunkVersion, TYPE_INFO(int16)) -STRUCT_VAR_INFO(ucChildsMask, TYPE_INFO(int16)) -STRUCT_VAR_INFO(nodeBox, TYPE_INFO(AABB)) -STRUCT_VAR_INFO(nObjectsBlockSize, TYPE_INFO(int32)) -STRUCT_INFO_END(SOcTreeNodeChunk) - -STRUCT_INFO_BEGIN(SHotUpdateInfo) -STRUCT_VAR_INFO(nHeigtmap, TYPE_INFO(uint32)) -STRUCT_VAR_INFO(nObjTypeMask, TYPE_INFO(uint32)) -STRUCT_VAR_INFO(areaBox, TYPE_INFO(AABB)) -STRUCT_INFO_END(SHotUpdateInfo) - -STRUCT_INFO_BEGIN(SCommonFileHeader) -STRUCT_VAR_INFO(signature, TYPE_ARRAY(4, TYPE_INFO(char))) -STRUCT_VAR_INFO(file_type, TYPE_INFO(uint8)) -STRUCT_VAR_INFO(flags, TYPE_INFO(uint8)) -STRUCT_VAR_INFO(version, TYPE_INFO(uint16)) -STRUCT_INFO_END(SCommonFileHeader) - -#endif // CRYINCLUDE_CRYCOMMON_I3DENGINE_INFO_H diff --git a/Code/CryEngine/CryCommon/IEntityRenderState.h b/Code/CryEngine/CryCommon/IEntityRenderState.h index 912f4632ab..29b1bdc463 100644 --- a/Code/CryEngine/CryCommon/IEntityRenderState.h +++ b/Code/CryEngine/CryCommon/IEntityRenderState.h @@ -286,7 +286,6 @@ struct IRenderNode // Physicalizes node. virtual void Physicalize([[maybe_unused]] bool bInstant = false) {} - // Make sure I3DEngine::FreeRenderNodeState(this) is called in destructor of derived class. virtual ~IRenderNode() { assert(!m_pRNTmpData); }; // Summary: @@ -731,8 +730,8 @@ struct IWaterVolumeRenderNode virtual void SetAuxPhysParams(pe_params_area*) = 0; virtual void CreateOcean(uint64 volumeID, /* TBD */ bool keepSerializationParams = false) = 0; - virtual void CreateArea(uint64 volumeID, const Vec3* pVertices, unsigned int numVertices, const Vec2& surfUVScale, const Plane& fogPlane, bool keepSerializationParams = false, int nSID = -1) = 0; - virtual void CreateRiver(uint64 volumeID, const Vec3* pVertices, unsigned int numVertices, float uTexCoordBegin, float uTexCoordEnd, const Vec2& surfUVScale, const Plane& fogPlane, bool keepSerializationParams = false, int nSID = -1) = 0; + virtual void CreateArea(uint64 volumeID, const Vec3* pVertices, unsigned int numVertices, const Vec2& surfUVScale, const Plane_tpl& fogPlane, bool keepSerializationParams = false, int nSID = -1) = 0; + virtual void CreateRiver(uint64 volumeID, const Vec3* pVertices, unsigned int numVertices, float uTexCoordBegin, float uTexCoordEnd, const Vec2& surfUVScale, const Plane_tpl& fogPlane, bool keepSerializationParams = false, int nSID = -1) = 0; virtual void CreateRiver(uint64 volumeID, const AZStd::vector& verticies, const AZ::Transform& transform, float uTexCoordBegin, float uTexCoordEnd, const AZ::Vector2& surfUVScale, const AZ::Plane& fogPlane, bool keepSerializationParams = false, int nSID = -1) = 0; virtual void SetAreaPhysicsArea(const Vec3* pVertices, unsigned int numVertices, bool keepSerializationParams = false) = 0; diff --git a/Code/CryEngine/CryCommon/ILocalMemoryUsage.h b/Code/CryEngine/CryCommon/ILocalMemoryUsage.h deleted file mode 100644 index fd1e7e3693..0000000000 --- a/Code/CryEngine/CryCommon/ILocalMemoryUsage.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Interface for LocalMemoryUsage - - -#ifndef CRYINCLUDE_CRYCOMMON_ILOCALMEMORYUSAGE_H -#define CRYINCLUDE_CRYCOMMON_ILOCALMEMORYUSAGE_H -#pragma once - - -class CCamera; -struct IRenderer; - -struct ILocalMemoryUsage -{ - virtual ~ILocalMemoryUsage(){} - virtual void OnRender(IRenderer* pRenderer, const CCamera* camera) = 0; - virtual void OnUpdate() = 0; - virtual void DeleteGlobalData() = 0; -}; - -#endif // CRYINCLUDE_CRYCOMMON_ILOCALMEMORYUSAGE_H diff --git a/Code/CryEngine/CryCommon/IMaterial.h b/Code/CryEngine/CryCommon/IMaterial.h index 81d612397f..020ddcc871 100644 --- a/Code/CryEngine/CryCommon/IMaterial.h +++ b/Code/CryEngine/CryCommon/IMaterial.h @@ -273,7 +273,7 @@ struct IMaterial ////////////////////////////////////////////////////////////////////////// // material name ////////////////////////////////////////////////////////////////////////// - //! Set material name, (Do not use this directly, to change material name use I3DEngine::RenameMatInfo method). + //! Set material name, (Do not use this directly virtual void SetName(const char* pName) = 0; //! Returns material name. virtual const char* GetName() const = 0; @@ -404,7 +404,6 @@ struct IMaterial ////////////////////////////////////////////////////////////////////////// // Makes this specific material enter sketch mode. - // Se also: I3DEngine::LoadCGF, in I3DEngine.h. // Current supported sketch modes: // - 0, no sketch. // - 1, normal sketch mode. diff --git a/Code/CryEngine/CryCommon/IMovieSystem.h b/Code/CryEngine/CryCommon/IMovieSystem.h index c22394e1b3..ce4e59d43c 100644 --- a/Code/CryEngine/CryCommon/IMovieSystem.h +++ b/Code/CryEngine/CryCommon/IMovieSystem.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/Code/CryEngine/CryCommon/IObjManager.h b/Code/CryEngine/CryCommon/IObjManager.h index acbd5c5d18..a63a252976 100644 --- a/Code/CryEngine/CryCommon/IObjManager.h +++ b/Code/CryEngine/CryCommon/IObjManager.h @@ -202,7 +202,6 @@ struct IObjManager // time counters virtual bool IsAfterWater(const Vec3& vPos, const SRenderingPassInfo& passInfo) = 0; - virtual void GetObjectsStreamingStatus(I3DEngine::SObjectsStreamingStatus& outStatus) = 0; virtual void FreeNotUsedCGFs() = 0; virtual void MakeUnitCube() = 0; diff --git a/Code/CryEngine/CryCommon/IShader.h b/Code/CryEngine/CryCommon/IShader.h index 1e8553ac57..7fcbdefebb 100644 --- a/Code/CryEngine/CryCommon/IShader.h +++ b/Code/CryEngine/CryCommon/IShader.h @@ -52,7 +52,6 @@ struct SShaderItem; class ITexture; struct IMaterial; struct SParam; -class CMaterial; struct SShaderSerializeContext; struct IAnimNode; struct SSkinningData; diff --git a/Code/CryEngine/CryCommon/ISystem.h b/Code/CryEngine/CryCommon/ISystem.h index 9b1e817602..96d9a6ad10 100644 --- a/Code/CryEngine/CryCommon/ISystem.h +++ b/Code/CryEngine/CryCommon/ISystem.h @@ -66,7 +66,6 @@ struct IConsole; struct IRemoteConsole; struct IRenderer; struct IProcess; -struct I3DEngine; struct ITimer; struct ICryFont; struct IMovieSystem; @@ -123,8 +122,6 @@ namespace Serialization { struct IArchiveHost; } -struct ILocalMemoryUsage; - typedef void* WIN_HWND; class CCamera; @@ -793,7 +790,6 @@ struct SSystemUpdateStats // ISystem struct SSystemGlobalEnvironment { - I3DEngine* p3DEngine; AZ::IO::IArchive* pCryPak; AZ::IO::FileIOBase* pFileIO; IFileChangeMonitor* pFileChangeMonitor; @@ -801,7 +797,6 @@ struct SSystemGlobalEnvironment IOpticsManager* pOpticsManager; ITimer* pTimer; ICryFont* pCryFont; - ILocalMemoryUsage* pLocalMemoryUsage; ::IConsole* pConsole; ISystem* pSystem = nullptr; ILog* pLog; @@ -1113,25 +1108,9 @@ struct ISystem virtual void DoWorkDuringOcclusionChecks() = 0; virtual bool NeedDoWorkDuringOcclusionChecks() = 0; - // Summary: - // Renders subsystems. - virtual void Render() = 0; - // Summary: - // Begins rendering frame. - virtual void RenderBegin() = 0; - // Summary: - // Ends rendering frame and swap back buffer. - virtual void RenderEnd(bool bRenderStats = true, bool bMainWindow = true) = 0; - //! Update screen and call some important tick functions during loading. virtual void SynchronousLoadingTick(const char* pFunc, int line) = 0; - // Description: - // Renders the statistics; this is called from RenderEnd, but if the - // Host application (Editor) doesn't employ the Render cycle in ISystem, - // it may call this method to render the essential statistics. - virtual void RenderStatistics() = 0; - // Summary: // Returns the current used memory. virtual uint32 GetUsedMemory() = 0; @@ -1229,7 +1208,6 @@ struct ISystem virtual ICryFont* GetICryFont() = 0; virtual IMemoryManager* GetIMemoryManager() = 0; virtual IMovieSystem* GetIMovieSystem() = 0; - virtual I3DEngine* GetI3DEngine() = 0; virtual ::IConsole* GetIConsole() = 0; virtual IRemoteConsole* GetIRemoteConsole() = 0; // Returns: diff --git a/Code/CryEngine/CryCommon/ITimeOfDay.h b/Code/CryEngine/CryCommon/ITimeOfDay.h deleted file mode 100644 index b491ea9359..0000000000 --- a/Code/CryEngine/CryCommon/ITimeOfDay.h +++ /dev/null @@ -1,286 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#pragma once - -struct SBezierKey; -struct ITimeOfDayUpdateCallback; -struct ISplineInterpolator; - - -//! Interface to the Time Of Day functionality. -struct ITimeOfDay -{ - enum ETimeOfDayParamID - { - PARAM_SUN_COLOR, - PARAM_SUN_INTENSITY, - PARAM_SUN_SPECULAR_MULTIPLIER, - - PARAM_FOG_COLOR, - PARAM_FOG_COLOR_MULTIPLIER, - PARAM_VOLFOG_HEIGHT, - PARAM_VOLFOG_DENSITY, - PARAM_FOG_COLOR2, - PARAM_FOG_COLOR2_MULTIPLIER, - PARAM_VOLFOG_HEIGHT2, - PARAM_VOLFOG_DENSITY2, - PARAM_VOLFOG_HEIGHT_OFFSET, - - PARAM_FOG_RADIAL_COLOR, - PARAM_FOG_RADIAL_COLOR_MULTIPLIER, - PARAM_VOLFOG_RADIAL_SIZE, - PARAM_VOLFOG_RADIAL_LOBE, - - PARAM_VOLFOG_FINAL_DENSITY_CLAMP, - - PARAM_VOLFOG_GLOBAL_DENSITY, - PARAM_VOLFOG_RAMP_START, - PARAM_VOLFOG_RAMP_END, - PARAM_VOLFOG_RAMP_INFLUENCE, - - PARAM_VOLFOG_SHADOW_DARKENING, - PARAM_VOLFOG_SHADOW_DARKENING_SUN, - PARAM_VOLFOG_SHADOW_DARKENING_AMBIENT, - PARAM_VOLFOG_SHADOW_RANGE, - - PARAM_VOLFOG2_HEIGHT, - PARAM_VOLFOG2_DENSITY, - PARAM_VOLFOG2_HEIGHT2, - PARAM_VOLFOG2_DENSITY2, - PARAM_VOLFOG2_GLOBAL_DENSITY, - PARAM_VOLFOG2_RAMP_START, - PARAM_VOLFOG2_RAMP_END, - PARAM_VOLFOG2_COLOR1, - PARAM_VOLFOG2_ANISOTROPIC1, - PARAM_VOLFOG2_COLOR2, - PARAM_VOLFOG2_ANISOTROPIC2, - PARAM_VOLFOG2_BLEND_FACTOR, - PARAM_VOLFOG2_BLEND_MODE, - PARAM_VOLFOG2_COLOR, - PARAM_VOLFOG2_ANISOTROPIC, - PARAM_VOLFOG2_RANGE, - PARAM_VOLFOG2_INSCATTER, - PARAM_VOLFOG2_EXTINCTION, - PARAM_VOLFOG2_GLOBAL_FOG_VISIBILITY, - PARAM_VOLFOG2_FINAL_DENSITY_CLAMP, - - PARAM_SKYLIGHT_SUN_INTENSITY, - PARAM_SKYLIGHT_SUN_INTENSITY_MULTIPLIER, - - PARAM_SKYLIGHT_KM, - PARAM_SKYLIGHT_KR, - PARAM_SKYLIGHT_G, - - PARAM_SKYLIGHT_WAVELENGTH_R, - PARAM_SKYLIGHT_WAVELENGTH_G, - PARAM_SKYLIGHT_WAVELENGTH_B, - - PARAM_NIGHSKY_HORIZON_COLOR, - PARAM_NIGHSKY_HORIZON_COLOR_MULTIPLIER, - PARAM_NIGHSKY_ZENITH_COLOR, - PARAM_NIGHSKY_ZENITH_COLOR_MULTIPLIER, - PARAM_NIGHSKY_ZENITH_SHIFT, - - PARAM_NIGHSKY_START_INTENSITY, - - PARAM_NIGHSKY_MOON_COLOR, - PARAM_NIGHSKY_MOON_COLOR_MULTIPLIER, - PARAM_NIGHSKY_MOON_INNERCORONA_COLOR, - PARAM_NIGHSKY_MOON_INNERCORONA_COLOR_MULTIPLIER, - PARAM_NIGHSKY_MOON_INNERCORONA_SCALE, - PARAM_NIGHSKY_MOON_OUTERCORONA_COLOR, - PARAM_NIGHSKY_MOON_OUTERCORONA_COLOR_MULTIPLIER, - PARAM_NIGHSKY_MOON_OUTERCORONA_SCALE, - - PARAM_CLOUDSHADING_SUNLIGHT_MULTIPLIER, - PARAM_CLOUDSHADING_SUNLIGHT_CUSTOM_COLOR, - PARAM_CLOUDSHADING_SUNLIGHT_CUSTOM_COLOR_MULTIPLIER, - PARAM_CLOUDSHADING_SUNLIGHT_CUSTOM_COLOR_INFLUENCE, - - PARAM_SUN_SHAFTS_VISIBILITY, - PARAM_SUN_RAYS_VISIBILITY, - PARAM_SUN_RAYS_ATTENUATION, - PARAM_SUN_RAYS_SUNCOLORINFLUENCE, - PARAM_SUN_RAYS_CUSTOMCOLOR, - - PARAM_OCEANFOG_COLOR, // Remove when ocean related feature toggle is removed. - PARAM_OCEANFOG_COLOR_MULTIPLIER, // Remove when ocean related feature toggle is removed. - PARAM_OCEANFOG_DENSITY, // Remove when ocean related feature toggle is removed. - - PARAM_SKYBOX_MULTIPLIER, - - PARAM_HDR_FILMCURVE_SHOULDER_SCALE, - PARAM_HDR_FILMCURVE_LINEAR_SCALE, - PARAM_HDR_FILMCURVE_TOE_SCALE, - PARAM_HDR_FILMCURVE_WHITEPOINT, - - PARAM_HDR_COLORGRADING_COLOR_SATURATION, - PARAM_HDR_COLORGRADING_COLOR_BALANCE, - - PARAM_HDR_EYEADAPTATION_SCENEKEY, - PARAM_HDR_EYEADAPTATION_MIN_EXPOSURE, - PARAM_HDR_EYEADAPTATION_MAX_EXPOSURE, - PARAM_HDR_EYEADAPTATION_EV_MIN, - PARAM_HDR_EYEADAPTATION_EV_MAX, - PARAM_HDR_EYEADAPTATION_EV_AUTO_COMPENSATION, - PARAM_HDR_BLOOM_AMOUNT, - - PARAM_COLORGRADING_FILTERS_GRAIN, - PARAM_COLORGRADING_FILTERS_PHOTOFILTER_COLOR, - PARAM_COLORGRADING_FILTERS_PHOTOFILTER_DENSITY, - - PARAM_COLORGRADING_DOF_FOCUSRANGE, - PARAM_COLORGRADING_DOF_BLURAMOUNT, - - PARAM_SHADOWSC0_BIAS, - PARAM_SHADOWSC0_SLOPE_BIAS, - PARAM_SHADOWSC1_BIAS, - PARAM_SHADOWSC1_SLOPE_BIAS, - PARAM_SHADOWSC2_BIAS, - PARAM_SHADOWSC2_SLOPE_BIAS, - PARAM_SHADOWSC3_BIAS, - PARAM_SHADOWSC3_SLOPE_BIAS, - PARAM_SHADOWSC4_BIAS, - PARAM_SHADOWSC4_SLOPE_BIAS, - PARAM_SHADOWSC5_BIAS, - PARAM_SHADOWSC5_SLOPE_BIAS, - PARAM_SHADOWSC6_BIAS, - PARAM_SHADOWSC6_SLOPE_BIAS, - PARAM_SHADOWSC7_BIAS, - PARAM_SHADOWSC7_SLOPE_BIAS, - - PARAM_SHADOW_JITTERING, - - PARAM_HDR_DYNAMIC_POWER_FACTOR, - PARAM_TERRAIN_OCCL_MULTIPLIER, - PARAM_SUN_COLOR_MULTIPLIER, - - PARAM_TOTAL - }; - - struct SPresetInfo - { - const char* m_pName; - bool m_bCurrent; - }; - - enum EVariableType - { - TYPE_FLOAT, - TYPE_COLOR - }; - struct SVariableInfo - { - const char* name; //!< Variable name. - const char* displayName; //!< Variable user readable name. - const char* group; //!< Group name. - int nParamId; - EVariableType type; - float fValue[3]; //!< Value of the variable (3 needed for color type). - ISplineInterpolator* pInterpolator; //!< Splines that control variable value. - }; - struct SAdvancedInfo - { - float fStartTime; - float fEndTime; - float fAnimSpeed; - }; - struct SEnvironmentInfo - { - SEnvironmentInfo() - : bSunLinkedToTOD(true) - , sunRotationLatitude(0) - , sunRotationLongitude(0){} - bool bSunLinkedToTOD; - float sunRotationLatitude; - float sunRotationLongitude; - }; - - // - virtual ~ITimeOfDay(){} - - virtual int GetPresetCount() const = 0; - virtual bool GetPresetsInfos(SPresetInfo* resultArray, unsigned int arraySize) const = 0; - virtual bool SetCurrentPreset(const char* szPresetName) = 0; - virtual bool AddNewPreset(const char* szPresetName) = 0; - virtual bool RemovePreset(const char* szPresetName) = 0; - virtual bool SavePreset(const char* szPresetName) const = 0; - virtual bool LoadPreset(const char* szFilePath) = 0; - virtual void ResetPreset(const char* szPresetName) = 0; - - virtual bool ImportPreset(const char* szPresetName, const char* szFilePath) = 0; - virtual bool ExportPreset(const char* szPresetName, const char* szFilePath) const = 0; - - //! Access to variables that control time of the day appearance. - virtual int GetVariableCount() const = 0; - virtual bool GetVariableInfo(int nIndex, SVariableInfo& varInfo) const = 0; - virtual void SetVariableValue(int nIndex, float fValue[3]) = 0; - - //! Editor interface. - virtual bool InterpolateVarInRange(int nIndex, float fMin, float fMax, unsigned int nCount, Vec3* resultArray) const = 0; - virtual uint GetSplineKeysCount(int nIndex, int nSpline) const = 0; - virtual bool GetSplineKeysForVar(int nIndex, int nSpline, SBezierKey* keysArray, unsigned int keysArraySize) const = 0; - virtual bool SetSplineKeysForVar(int nIndex, int nSpline, const SBezierKey* keysArray, unsigned int keysArraySize) = 0; - virtual bool UpdateSplineKeyForVar(int nIndex, int nSpline, float fTime, float newValue) = 0; - - virtual void ResetVariables() = 0; - - //! Sets the time of the day specified in hours. - virtual void SetTime(float fHour, bool bForceUpdate = false, bool bForceEnvUpdate = true) = 0; - virtual float GetTime() = 0; - - //! Sun position. - virtual void SetSunPos(float longitude, float latitude) = 0; - virtual float GetSunLatitude() = 0; - virtual float GetSunLongitude() = 0; - - //! Updates the current ToD. - virtual void Tick() = 0; - - - virtual void SetPaused(bool paused) = 0; - - virtual void SetAdvancedInfo(const SAdvancedInfo& advInfo) = 0; - virtual void GetAdvancedInfo(SAdvancedInfo& advInfo) = 0; - - //! Updates engine parameters after variable values have been changed. - virtual void Update(bool bInterpolate = true, bool bForceUpdate = false, bool bForceEnvUpdate = true) = 0; - virtual void SetUpdateCallback(ITimeOfDayUpdateCallback* pCallback) = 0; - - virtual void BeginEditMode() = 0; - virtual void EndEditMode() = 0; - - virtual void Serialize(XmlNodeRef& node, bool bLoading) = 0; - virtual void Serialize(TSerialize ser) = 0; - - virtual void SetTimer(ITimer* pTimer) = 0; - virtual void SetEnvironmentSettings(const SEnvironmentInfo& envInfo) = 0; - virtual void LerpWith(const ITimeOfDay& other, float lerpValue, ITimeOfDay& output) const = 0; - - //! Multiplayer serialization. - static const int NETSER_FORCESET = BIT(0); - static const int NETSER_COMPENSATELAG = BIT(1); - static const int NETSER_STATICPROPS = BIT(2); - virtual void NetSerialize(TSerialize ser, float lag, uint32 flags) = 0; -}; - -struct ITimeOfDayUpdateCallback -{ - // - virtual ~ITimeOfDayUpdateCallback(){} - virtual void BeginUpdate() = 0; - virtual bool GetCustomValue(ITimeOfDay::ETimeOfDayParamID paramID, int dim, float* pValues, float& blendWeight) = 0; - virtual void EndUpdate() = 0; - // -}; - diff --git a/Code/CryEngine/CryCommon/Mocks/I3DEngineMock.h b/Code/CryEngine/CryCommon/Mocks/I3DEngineMock.h deleted file mode 100644 index b0936ddbdd..0000000000 --- a/Code/CryEngine/CryCommon/Mocks/I3DEngineMock.h +++ /dev/null @@ -1,528 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include - -#include -#include -#include - -// the following was generated using google's python script to autogenerate mocks. -// however, it needed some hand-editing to make it work, so if you add functions to I3DEngine, -// it will probably be better to just manually add them here than try to run the script again. - -class I3DEngineMock - : public I3DEngine -{ -public: - // From IProcess - MOCK_METHOD1(SetFlags, - void(int)); - MOCK_METHOD0(GetFlags, - int(void)); - - // From I3DEngine - MOCK_METHOD0(Init, - bool()); - MOCK_METHOD1(SetLevelPath, - void(const char* szFolderName)); - MOCK_METHOD1(CheckMinSpec, - bool(uint32 nMinSpec)); - MOCK_METHOD1(PrepareOcclusion, - void(const CCamera& rCamera)); - MOCK_METHOD0(EndOcclusion, - void()); - MOCK_METHOD2(LoadLevel, - bool(const char* szFolderName, const char* szMissionName)); - MOCK_METHOD2(InitLevelForEditor, - bool(const char* szFolderName, const char* szMissionName)); - MOCK_METHOD0(LevelLoadingInProgress, - bool()); - MOCK_METHOD0(OnFrameStart, - void()); - MOCK_METHOD0(PostLoadLevel, - void()); - MOCK_METHOD0(LoadEmptyLevel, - void()); - MOCK_METHOD0(UnloadLevel, - void()); - MOCK_METHOD0(Update, - void()); - MOCK_CONST_METHOD0(GetRenderingCamera, - const CCamera&()); - MOCK_CONST_METHOD0(GetZoomFactor, - float()); - MOCK_METHOD0(Tick, - void()); - MOCK_METHOD0(UpdateShaderItems, - void()); - MOCK_METHOD0(Release, - void()); - MOCK_METHOD3(RenderWorld, - void(int nRenderFlags, const SRenderingPassInfo& passInfo, const char* szDebugName)); - MOCK_METHOD2(RenderSceneReflection, - void(int nRenderFlags, const SRenderingPassInfo& passInfo)); - MOCK_METHOD1(PreWorldStreamUpdate, - void(const CCamera& cam)); - MOCK_METHOD0(WorldStreamUpdate, - void()); - MOCK_METHOD0(ShutDown, - void()); - MOCK_METHOD7(LoadStatObjUnsafeManualRef, - IStatObj*(const char* fileName, const char* geomName, IStatObj::SSubObject** subObject, - bool useStreaming, unsigned long loadingFlags, const void* data, int dataSize)); - MOCK_METHOD7(LoadStatObjAutoRef, - _smart_ptr(const char* fileName, const char* geomName, IStatObj::SSubObject** subObject, - bool useStreaming, unsigned long loadingFlags, const void* data, int dataSize)); - MOCK_METHOD0(ProcessAsyncStaticObjectLoadRequests, - void()); - MOCK_METHOD5(LoadStatObjAsync, - void(LoadStaticObjectAsyncResult resultCallback, const char* szFileName, const char* szGeomName, bool bUseStreaming, unsigned long nLoadingFlags)); - MOCK_METHOD1(FindStatObjectByFilename, - IStatObj*(const char* filename)); - MOCK_METHOD0(GetGSMRange, - const float()); - MOCK_METHOD0(GetGSMRangeStep, - const float()); - MOCK_METHOD0(GetLoadedObjectCount, - int()); - MOCK_METHOD2(GetLoadedStatObjArray, - void(IStatObj** pObjectsArray, int& nCount)); - MOCK_METHOD1(GetObjectsStreamingStatus, - void(SObjectsStreamingStatus& outStatus)); - MOCK_METHOD2(GetStreamingSubsystemData, - void(int subsystem, SStremaingBandwidthData& outData)); - MOCK_METHOD3(RegisterEntity, - void(IRenderNode* pEntity, int nSID, int nSIDConsideredSafe)); - MOCK_METHOD1(SelectEntity, - void(IRenderNode* pEntity)); - MOCK_METHOD0(IsSunShadows, - bool()); - MOCK_METHOD2(MakeSystemMaterialFromShaderHelper - , _smart_ptr(const char* sShaderName, SInputShaderResources* Res)); - MOCK_METHOD1(CheckMinSpecHelper - , bool(uint32 nMinSpec)); - MOCK_METHOD1(OnCasterDeleted - , void(IShadowCaster* pCaster)); - MOCK_METHOD4(GetStatObjAndMatTables, - void(DynArray* pStatObjTable, DynArray<_smart_ptr>* pMatTable, DynArray* pStatInstGroupTable, uint32 nObjTypeMask)); -#ifndef _RELEASE - MOCK_METHOD1(AddObjToDebugDrawList, - void(SObjectInfoToAddToDebugDrawList& objInfo)); - MOCK_CONST_METHOD0(IsDebugDrawListEnabled, - bool()); -#endif - MOCK_METHOD1(UnRegisterEntityDirect, - void(IRenderNode* pEntity)); - MOCK_METHOD1(UnRegisterEntityAsJob, - void(IRenderNode* pEnt)); - MOCK_CONST_METHOD1(IsUnderWater, - bool(const Vec3& vPos)); - MOCK_METHOD1(SetOceanRenderFlags, - void(uint8 nFlags)); - MOCK_CONST_METHOD0(GetOceanRenderFlags, - uint8()); - MOCK_CONST_METHOD0(GetOceanVisiblePixelsCount, - uint32()); - MOCK_METHOD3(GetBottomLevel, - float(const Vec3& referencePos, float maxRelevantDepth, int objtypes)); - MOCK_METHOD2(GetBottomLevel, - float(const Vec3& referencePos, float maxRelevantDepth)); - MOCK_METHOD2(GetBottomLevel, - float(const Vec3& referencePos, int objflags)); - MOCK_METHOD0(GetWaterLevel, - float()); - MOCK_METHOD3(GetWaterLevel, - float(const Vec3* pvPos, IPhysicalEntity* pent, bool bAccurate)); - MOCK_CONST_METHOD1(GetAccurateOceanHeight, - float(const Vec3& pCurrPos)); - MOCK_CONST_METHOD0(GetCausticsParams, - CausticsParams()); - MOCK_CONST_METHOD0(GetOceanAnimationParams, - OceanAnimationData()); - MOCK_CONST_METHOD1(GetHDRSetupParams, - void(Vec4 pParams[5])); - MOCK_METHOD0(ResetParticlesAndDecals, - void()); - MOCK_METHOD1(CreateDecal, - void(const CryEngineDecalInfo& Decal)); - MOCK_METHOD2(DeleteDecalsInRange, - void(AABB* pAreaBox, IRenderNode* pEntity)); - MOCK_METHOD1(SetSunColor, - void(Vec3 vColor)); - MOCK_METHOD0(GetSunAnimColor, - Vec3()); - MOCK_METHOD1(SetSunAnimColor, - void(const Vec3& color)); - MOCK_METHOD0(GetSunAnimSpeed, - float()); - MOCK_METHOD1(SetSunAnimSpeed, - void(float sunAnimSpeed)); - MOCK_METHOD0(GetSunAnimPhase, - AZ::u8()); - MOCK_METHOD1(SetSunAnimPhase, - void(AZ::u8 sunAnimPhase)); - MOCK_METHOD0(GetSunAnimIndex, - AZ::u8()); - MOCK_METHOD1(SetSunAnimIndex, - void(AZ::u8 sunAnimIndex)); - MOCK_METHOD1(SetRainParams, - void(const SRainParams& rainParams)); - MOCK_METHOD1(GetRainParams, - bool(SRainParams& rainParams)); - MOCK_METHOD5(SetSnowSurfaceParams, - void(const Vec3& vCenter, float fRadius, float fSnowAmount, float fFrostAmount, float fSurfaceFreezing)); - MOCK_METHOD5(GetSnowSurfaceParams, - bool(Vec3& vCenter, float& fRadius, float& fSnowAmount, float& fFrostAmount, float& fSurfaceFreezing)); - MOCK_METHOD7(SetSnowFallParams, - void(int nSnowFlakeCount, float fSnowFlakeSize, float fSnowFallBrightness, float fSnowFallGravityScale, float fSnowFallWindScale, float fSnowFallTurbulence, float fSnowFallTurbulenceFreq)); - MOCK_METHOD7(GetSnowFallParams, - bool(int& nSnowFlakeCount, float& fSnowFlakeSize, float& fSnowFallBrightness, float& fSnowFallGravityScale, float& fSnowFallWindScale, float& fSnowFallTurbulence, float& fSnowFallTurbulenceFreq)); - MOCK_METHOD1(SetMaxViewDistanceScale, - void(float fScale)); - MOCK_METHOD1(GetMaxViewDistance, - float(bool)); - MOCK_CONST_METHOD0(GetFrameLodInfo, - const SFrameLodInfo&()); - MOCK_METHOD1(SetFrameLodInfo, - void(const SFrameLodInfo& frameLodInfo)); - MOCK_METHOD1(SetFogColor, - void(const Vec3& vFogColor)); - MOCK_METHOD0(GetFogColor, - Vec3()); - MOCK_METHOD6(GetSkyLightParameters, - void(Vec3& sunDir, Vec3& sunIntensity, float& Km, float& Kr, float& g, Vec3& rgbWaveLengths)); - MOCK_METHOD7(SetSkyLightParameters, - void(const Vec3& sunDir, const Vec3& sunIntensity, float Km, float Kr, float g, const Vec3& rgbWaveLengths, bool forceImmediateUpdate)); - MOCK_CONST_METHOD0(GetLightsHDRDynamicPowerFactor, - float()); - MOCK_CONST_METHOD3(IsTessellationAllowed, - bool(const CRenderObject* pObj, const SRenderingPassInfo& passInfo, bool bIgnoreShadowPass)); - MOCK_METHOD3(SetRenderNodeMaterialAtPosition, - void(EERType eNodeType, const Vec3& vPos, _smart_ptr pMat)); - MOCK_METHOD1(OverrideCameraPrecachePoint, - void(const Vec3& vPos)); - MOCK_METHOD4(AddPrecachePoint, - int(const Vec3& vPos, const Vec3& vDir, float fTimeOut, float fImportanceFactor)); - MOCK_METHOD1(ClearPrecachePoint, - void(int id)); - MOCK_METHOD0(ClearAllPrecachePoints, - void()); - MOCK_METHOD1(GetPrecacheRoundIds, - void(int pRoundIds[MAX_STREAM_PREDICTION_ZONES])); - MOCK_METHOD5(TraceFogVolumes, - void(const Vec3& vPos, const AABB& objBBox, SFogVolumeData& fogVolData, const SRenderingPassInfo& passInfo, bool fogVolumeShadingQuality)); - - MOCK_METHOD1(RemoveAllStaticObjects, - void(int)); - MOCK_METHOD3(SetStatInstGroup, - bool(int nGroupId, const IStatInstGroup& siGroup, int nSID)); - MOCK_METHOD3(GetStatInstGroup, - bool(int, IStatInstGroup&, int)); - MOCK_METHOD3(OnExplosion, - void(Vec3, float, bool)); - MOCK_METHOD1(SetPhysMaterialEnumerator, - void(IPhysMaterialEnumerator* pPhysMaterialEnumerator)); - MOCK_METHOD0(GetPhysMaterialEnumerator, - IPhysMaterialEnumerator*()); - MOCK_METHOD0(SetupDistanceFog, - void()); - MOCK_METHOD1(LoadMissionDataFromXMLNode, - void(const char* szMissionName)); - MOCK_METHOD2(LoadEnvironmentSettingsFromXML, - void(XmlNodeRef, int)); - MOCK_METHOD0(LoadCompiledOctreeForEditor, - bool()); - MOCK_CONST_METHOD0(GetSunDir, - Vec3()); - MOCK_CONST_METHOD0(GetSunDirNormalized, - Vec3()); - MOCK_CONST_METHOD0(GetRealtimeSunDirNormalized, - Vec3()); - MOCK_METHOD0(GetDistanceToSectorWithWater, - float()); - MOCK_CONST_METHOD0(GetSunColor, - Vec3()); - MOCK_CONST_METHOD0(GetSSAOAmount, - float()); - MOCK_CONST_METHOD0(GetSSAOContrast, - float()); - MOCK_METHOD1(FreeRenderNodeState, - void(IRenderNode* pEntity)); - MOCK_METHOD1(GetLevelFilePath, - const char*(const char* szFileName)); - MOCK_METHOD4(DisplayInfo, - void(float& fTextPosX, float& fTextPosY, float& fTextStepY, bool bEnhanced)); - MOCK_METHOD0(DisplayMemoryStatistics, - void()); - - // Can't mock methods with variable parameters so just create empty bodies for them. - void DrawTextRightAligned([[maybe_unused]] const float x, [[maybe_unused]] const float y, [[maybe_unused]] const char* format, ...) override {} - void DrawTextRightAligned([[maybe_unused]] const float x, [[maybe_unused]] const float y, [[maybe_unused]] const float scale, [[maybe_unused]] const ColorF& color, [[maybe_unused]] const char* format, ...) override {} - - MOCK_METHOD3(DrawBBoxHelper - , void (const Vec3& vMin, const Vec3& vMax, ColorB col)); - MOCK_METHOD2(DrawBBoxHelper - , void (const AABB& box, ColorB col)); - - MOCK_METHOD3(ActivatePortal, - void(const Vec3& vPos, bool bActivate, const char* szEntityName)); - MOCK_CONST_METHOD1(GetMemoryUsage, - void(ICrySizer* pSizer)); - MOCK_METHOD2(GetResourceMemoryUsage, - void(ICrySizer* pSizer, const AABB& cstAABB)); - MOCK_METHOD1(CreateVisArea, - IVisArea*(uint64 visGUID)); - MOCK_METHOD1(DeleteVisArea, - void(IVisArea* pVisArea)); - MOCK_METHOD6(UpdateVisArea, - void(IVisArea* pArea, const Vec3* pPoints, int nCount, const char* szName, const SVisAreaInfo& info, bool bReregisterObjects)); - MOCK_METHOD4(IsVisAreasConnected, - bool(IVisArea* pArea1, IVisArea* pArea2, int nMaxRecursion, bool bSkipDisabledPortals)); - MOCK_METHOD0(CreateClipVolume, - IClipVolume*()); - MOCK_METHOD1(DeleteClipVolume, - void(IClipVolume* pClipVolume)); - MOCK_METHOD7(UpdateClipVolume, - void(IClipVolume* pClipVolume, _smart_ptr pRenderMesh, IBSPTree3D* pBspTree, const Matrix34& worldTM, bool bActive, uint32 flags, const char* szName)); - MOCK_METHOD1(CreateRenderNode, - IRenderNode*(EERType type)); - MOCK_METHOD1(DeleteRenderNode, - void(IRenderNode* pRenderNode)); - MOCK_METHOD1(SetWind, - void(const Vec3& vWind)); - MOCK_CONST_METHOD2(GetWind, - Vec3(const AABB& box, bool bIndoors)); - MOCK_CONST_METHOD1(GetGlobalWind, - Vec3(bool bIndoors)); - MOCK_CONST_METHOD4(SampleWind, - bool(Vec3* pSamples, int nSamples, const AABB& volume, bool bIndoors)); - MOCK_METHOD1(GetVisAreaFromPos, - IVisArea*(const Vec3& vPos)); - MOCK_METHOD2(IntersectsVisAreas, - bool(const AABB& box, void** pNodeCache)); - MOCK_METHOD4(ClipToVisAreas, - bool(IVisArea* pInside, Sphere& sphere, Vec3 const& vNormal, void* pNodeCache)); - MOCK_METHOD1(EnableOceanRendering, - void(bool bOcean)); - MOCK_METHOD1(AddTextureLoadHandler, - void(ITextureLoadHandler* pHandler)); - MOCK_METHOD1(RemoveTextureLoadHandler, - void(ITextureLoadHandler* pHandler)); - MOCK_METHOD1(GetTextureLoadHandlerForImage, - ITextureLoadHandler*(const char* ext)); - MOCK_METHOD0(CreateLightSource, - struct ILightSource*()); - MOCK_METHOD1(DeleteLightSource, - void(ILightSource* pLightSource)); - MOCK_METHOD0(GetLightEntities, - const PodArray* ()); - MOCK_METHOD3(GetLightVolumes, - void(threadID nThreadID, SLightVolume*& pLightVols, uint32& nNumVols)); - MOCK_METHOD4(RegisterVolumeForLighting, - uint16(const Vec3& vPos, f32 fRadius, uint8 nClipVolumeRef, const SRenderingPassInfo& passInfo)); - MOCK_METHOD1(RestoreTerrainFromDisk, - bool(int)); - MOCK_METHOD1(GetFilePath, - const char*(const char* szFileName)); - MOCK_CONST_METHOD0(GetPostEffectGroups, - class IPostEffectGroupManager*()); - MOCK_CONST_METHOD0(GetPostEffectBaseGroup, - class IPostEffectGroup*()); - MOCK_CONST_METHOD3(SetPostEffectParam, - void(const char* pParam, float fValue, bool bForceValue)); - MOCK_CONST_METHOD3(SetPostEffectParamVec4, - void(const char* pParam, const Vec4& pValue, bool bForceValue)); - MOCK_CONST_METHOD2(SetPostEffectParamString, - void(const char* pParam, const char* pszArg)); - MOCK_CONST_METHOD2(GetPostEffectParam, - void(const char* pParam, float& fValue)); - MOCK_CONST_METHOD2(GetPostEffectParamVec4, - void(const char* pParam, Vec4& pValue)); - MOCK_CONST_METHOD2(GetPostEffectParamString, - void(const char* pParam, const char*& pszArg)); - MOCK_METHOD1(GetPostEffectID, - int32(const char* pPostEffectName)); - MOCK_METHOD1(ResetPostEffects, - void(bool)); - MOCK_METHOD0(DisablePostEffects, - void()); - MOCK_METHOD1(SetShadowsGSMCache, - void(bool bCache)); - MOCK_METHOD2(SetCachedShadowBounds, - void(const AABB& shadowBounds, float fAdditionalCascadesScale)); - MOCK_METHOD1(SetRecomputeCachedShadows, - void(uint)); - MOCK_METHOD0(CheckMemoryHeap, - void()); - MOCK_METHOD1(DeleteEntityDecals, - void(IRenderNode* pEntity)); - MOCK_METHOD0(LockCGFResources, - void()); - MOCK_METHOD0(UnlockCGFResources, - void()); - MOCK_METHOD0(FreeUnusedCGFResources, - void()); - MOCK_METHOD0(CreateStatObj, - IStatObj*()); - MOCK_METHOD1(CreateStatObjOptionalIndexedMesh, - IStatObj*(bool createIndexedMesh)); - MOCK_METHOD0(CreateIndexedMesh, - IIndexedMesh*()); - MOCK_METHOD1(SerializeState, - void(TSerialize ser)); - MOCK_METHOD1(PostSerialize, - void(bool bReading)); - MOCK_METHOD0(GetMaterialHelpers, - IMaterialHelpers&()); - MOCK_METHOD0(GetMaterialManager, - IMaterialManager*()); - MOCK_METHOD0(GetObjManager, - IObjManager*()); - MOCK_METHOD1(CreateChunkfileContent, - CContentCGF*(const char* filename)); - MOCK_METHOD1(ReleaseChunkfileContent, - void(CContentCGF*)); - MOCK_METHOD4(LoadChunkFileContent, - bool(CContentCGF* pCGF, const char* filename, bool bNoWarningMode, bool bCopyChunkFile)); - MOCK_METHOD6(LoadChunkFileContentFromMem, - bool(CContentCGF* pCGF, const void* pData, size_t nDataLen, uint32 nLoadingFlags, bool bNoWarningMode, bool bCopyChunkFile)); - MOCK_METHOD1(CreateChunkFile, - IChunkFile*(bool)); - MOCK_CONST_METHOD3(CreateChunkFileWriter, - ChunkFile::IChunkFileWriter*(EChunkFileFormat eFormat, AZ::IO::IArchive* pPak, const char* filename)); - MOCK_CONST_METHOD1(ReleaseChunkFileWriter, - void(ChunkFile::IChunkFileWriter* p)); - MOCK_METHOD2(CreateOcean, - bool(_smart_ptr pTerrainWaterMat, float waterLevel)); - MOCK_METHOD0(DeleteOcean, - void()); - MOCK_METHOD1(ChangeOceanMaterial, - void(_smart_ptr pMat)); - MOCK_METHOD1(ChangeOceanWaterLevel, - void(float fWaterLevel)); - MOCK_METHOD1(InitMaterialDefautMappingAxis - , void(_smart_ptr pMat)); - MOCK_METHOD0(GetIVisAreaManager, - IVisAreaManager*()); - MOCK_METHOD3(PrecacheLevel, - void(bool bPrecacheAllVisAreas, Vec3* pPrecachePoints, int nPrecachePointsNum)); - MOCK_METHOD0(ProposeContentPrecache, - void()); - MOCK_METHOD0(GetTimeOfDay, - ITimeOfDay*()); - MOCK_METHOD1(SetSkyMaterialPath, - void(const string& skyMaterialPath)); - MOCK_METHOD1(SetSkyLowSpecMaterialPath, - void(const string& skyMaterialPath)); - MOCK_METHOD0(LoadSkyMaterial, - void()); - MOCK_METHOD0(GetSkyMaterial, - _smart_ptr()); - MOCK_METHOD1(SetSkyMaterial, - void(_smart_ptr pSkyMat)); - MOCK_METHOD2(SetGlobalParameter, - void(E3DEngineParameter param, const Vec3& v)); - MOCK_METHOD2(GetGlobalParameter, - void(E3DEngineParameter param, Vec3& v)); - MOCK_METHOD1(SetShadowMode, - void(EShadowMode shadowMode)); - MOCK_CONST_METHOD0(GetShadowMode, - EShadowMode()); - MOCK_METHOD6(AddPerObjectShadow, - void(IShadowCaster* pCaster, float fConstBias, float fSlopeBias, float fJitter, const Vec3& vBBoxScale, uint nTexSize)); - MOCK_METHOD1(RemovePerObjectShadow, - void(IShadowCaster* pCaster)); - MOCK_METHOD1(GetPerObjectShadow, - struct SPerObjectShadow*(IShadowCaster* pCaster)); - MOCK_METHOD2(GetCustomShadowMapFrustums, - void(struct ShadowMapFrustum*& arrFrustums, int& nFrustumCount)); - MOCK_METHOD2(SaveStatObj, - int(IStatObj* pStatObj, TSerialize ser)); - MOCK_METHOD1(LoadStatObj, - IStatObj*(TSerialize ser)); - MOCK_METHOD2(CheckIntersectClouds, - bool(const Vec3& p1, const Vec3& p2)); - MOCK_METHOD1(OnRenderMeshDeleted, - void(IRenderMesh* pRenderMesh)); - MOCK_METHOD0(DebugDraw_UpdateDebugNode, - void()); - MOCK_METHOD4(RayObjectsIntersection2D, - bool(Vec3 vStart, Vec3 vEnd, Vec3& vHitPoint, EERType eERType)); - MOCK_METHOD3(RenderMeshRayIntersection, - bool(IRenderMesh* pRenderMesh, SRayHitInfo& hitInfo, _smart_ptr pCustomMtl)); - MOCK_METHOD3(CheckCreateRNTmpData - , void(CRNTmpData** ppInfo, IRenderNode* pRNode, const SRenderingPassInfo& passInfo)); - MOCK_METHOD1(FreeRNTmpData, - void(CRNTmpData** ppInfo)); - MOCK_METHOD0(IsObjectTreeReady - , bool()); - MOCK_METHOD0(GetIObjectTree - , IOctreeNode*()); - MOCK_METHOD2(GetObjectsByType, - uint32(EERType, IRenderNode**)); - MOCK_METHOD4(GetObjectsByTypeInBox, - uint32(EERType objType, const AABB& bbox, IRenderNode** pObjects, ObjectTreeQueryFilterCallback filterCallback)); - MOCK_METHOD2(GetObjectsInBox, - uint32(const AABB& bbox, IRenderNode** pObjects)); - MOCK_METHOD2(GetObjectsByFlags, - uint32(uint, IRenderNode**)); - MOCK_METHOD4(GetObjectsByTypeInBox, - void(EERType objType, const AABB& bbox, PodArray* pLstObjects, ObjectTreeQueryFilterCallback filterCallback)); - MOCK_METHOD2(OnObjectModified, - void(IRenderNode* pRenderNode, uint dwFlags)); - MOCK_METHOD1(FillDebugFPSInfo, - void(SDebugFPSInfo&)); - MOCK_METHOD0(GetLevelFolder, - const char*()); - MOCK_METHOD0(IsAreaActivationInUse, - bool()); - MOCK_METHOD3(RenderRenderNode_ShadowPass, - void(IShadowCaster* pRNode, const SRenderingPassInfo& passInfo, AZ::LegacyJobExecutor* pJobExecutor)); - MOCK_METHOD0(GetOpticsManager, - IOpticsManager*()); - MOCK_METHOD0(SyncProcessStreamingUpdate, - void()); - MOCK_METHOD1(SetScreenshotCallback, - void(IScreenshotCallback* pCallback)); - MOCK_METHOD8(ActivateObjectsLayer, - void(uint16 nLayerId, bool bActivate, bool bPhys, bool bObjects, bool bStaticLights, const char* pLayerName, IGeneralMemoryHeap* pHeap, bool bCheckLayerActivation)); - MOCK_CONST_METHOD4(GetLayerMemoryUsage, - void(uint16 nLayerId, ICrySizer* pSizer, int* pNumBrushes, int* pNumDecals)); - MOCK_METHOD2(SkipLayerLoading, - void(uint16 nLayerId, bool bClearList)); - MOCK_METHOD2(PrecacheRenderNode, - void(IRenderNode* pObj, float fEntDistanceReal)); - MOCK_METHOD0(GetDeferredPhysicsEventManager, - IDeferredPhysicsEventManager*()); - MOCK_METHOD1(SetStreamableListener, - void(IStreamedObjectListener* pListener)); - MOCK_METHOD1(GetRenderingPassCamera, - CCamera*(const CCamera& rCamera)); - MOCK_METHOD3(GetSvoStaticTextures, - void(I3DEngine::SSvoStaticTexInfo& svoInfo, PodArray* pLightsTI_S, PodArray* pLightsTI_D)); - MOCK_METHOD2(GetSvoBricksForUpdate, - void(PodArray& arrNodeInfo, bool getDynamic)); -#if defined(USE_GEOM_CACHES) - MOCK_METHOD1(LoadGeomCache, - IGeomCache*(const char* szFileName)); - MOCK_METHOD1(FindGeomCacheByFilename, - IGeomCache*(const char* szFileName)); -#endif - MOCK_METHOD3(LoadDesignerObject, - IStatObj*(int nVersion, const char* szBinaryStream, int size)); - - MOCK_METHOD0(WaitForCullingJobsCompletion, - void()); -}; - diff --git a/Code/CryEngine/CryCommon/Mocks/IRendererMock.h b/Code/CryEngine/CryCommon/Mocks/IRendererMock.h index 2021e96172..757c586261 100644 --- a/Code/CryEngine/CryCommon/Mocks/IRendererMock.h +++ b/Code/CryEngine/CryCommon/Mocks/IRendererMock.h @@ -12,11 +12,15 @@ #pragma once #include -#include // needed for SRenderingPassInfo definition #include #include #include +struct SRendItemSorter {}; +struct SRenderingPassInfo {}; +struct SClipVolumeBlendInfo {}; +struct SFogVolumeData {}; + // the following was generated using google's python script to autogenerate mocks. // however, it needed some hand-editing to make it work, so if you add functions to IRenderer, // it will probably be better to just manually add them here than try to run the script again diff --git a/Code/CryEngine/CryCommon/Mocks/ISystemMock.h b/Code/CryEngine/CryCommon/Mocks/ISystemMock.h index 5edd84fd75..4d2e80a2f3 100644 --- a/Code/CryEngine/CryCommon/Mocks/ISystemMock.h +++ b/Code/CryEngine/CryCommon/Mocks/ISystemMock.h @@ -37,12 +37,6 @@ public: void()); MOCK_METHOD0(NeedDoWorkDuringOcclusionChecks, bool()); - MOCK_METHOD0(Render, - void()); - MOCK_METHOD0(RenderBegin, - void()); - MOCK_METHOD2(RenderEnd, - void(bool, bool)); MOCK_METHOD2(SynchronousLoadingTick, void(const char* pFunc, int line)); MOCK_METHOD0(RenderStatistics, @@ -124,8 +118,6 @@ public: IMovieSystem * ()); MOCK_METHOD0(GetIAudioSystem, Audio::IAudioSystem * ()); - MOCK_METHOD0(GetI3DEngine, - I3DEngine * ()); MOCK_METHOD0(GetIConsole, ::IConsole * ()); MOCK_METHOD0(GetIRemoteConsole, diff --git a/Code/CryEngine/CryCommon/Mocks/StubTimer.h b/Code/CryEngine/CryCommon/Mocks/StubTimer.h index fe3a11fb42..cd275ac17b 100644 --- a/Code/CryEngine/CryCommon/Mocks/StubTimer.h +++ b/Code/CryEngine/CryCommon/Mocks/StubTimer.h @@ -11,6 +11,8 @@ */ #pragma once +#include + //! Simple stub timer that exposes a single simple interface for setting the current time. class StubTimer : public ITimer diff --git a/Code/CryEngine/CryCommon/RendElement.h b/Code/CryEngine/CryCommon/RendElement.h index c3dc1c080d..41bcf2bf67 100644 --- a/Code/CryEngine/CryCommon/RendElement.h +++ b/Code/CryEngine/CryCommon/RendElement.h @@ -119,7 +119,7 @@ struct IRenderElement virtual void mfCenter(Vec3& centr, CRenderObject* pObj) = 0; virtual void mfGetBBox(Vec3& vMins, Vec3& vMaxs) = 0; virtual void mfReset() = 0; - virtual void mfGetPlane(Plane& pl) = 0; + virtual void mfGetPlane(Plane_tpl& pl) = 0; virtual void mfExport(struct SShaderSerializeContext& SC) = 0; virtual void mfImport(struct SShaderSerializeContext& SC, uint32& offset) = 0; virtual void mfPrecache(const SShaderItem& SH) = 0; @@ -265,7 +265,7 @@ public: void mfPrecache([[maybe_unused]] const SShaderItem& SH) override {} void mfExport([[maybe_unused]] struct SShaderSerializeContext& SC) override { CryFatalError("mfExport has not been implemented for this render element type"); } void mfImport([[maybe_unused]] struct SShaderSerializeContext& SC, [[maybe_unused]] uint32& offset) override { CryFatalError("mfImport has not been implemented for this render element type"); } - void mfGetPlane(Plane& pl) override; + void mfGetPlane(Plane_tpl& pl) override; void* mfGetPointer([[maybe_unused]] ESrcPointer ePT, [[maybe_unused]] int* Stride, [[maybe_unused]] EParamType Type, [[maybe_unused]] ESrcPointer Dst, [[maybe_unused]] int Flags) override { return nullptr; } uint16 mfGetFlags() override { return m_Flags; } diff --git a/Code/CryEngine/CryCommon/WindowsUtils.h b/Code/CryEngine/CryCommon/WindowsUtils.h deleted file mode 100644 index 96b3a86606..0000000000 --- a/Code/CryEngine/CryCommon/WindowsUtils.h +++ /dev/null @@ -1,215 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once - -#if defined(WIN32) -#include "CryWindows.h" -#include "IRenderer.h" -#include "IImage.h" -#include "smartptr.h" -#include "ImageExtensionHelper.h" - -// Types supported by CreateResourceFromTexture -enum EResourceType -{ - eResourceType_IconBig, - eResourceType_IconSmall, - eResourceType_Cursor, -}; - -// Loads a (DDS) texture resource from the renderer into a Win32 GDI resource. -// Returns a HICON that must be closed with DestroyIcon(), or NULL on failure. -static HICON CreateResourceFromTexture(IRenderer* pRenderer, const char* path, EResourceType type) -{ - if (!pRenderer || !path || !*path) - { - // Invalid parameter passed - return NULL; - } - - // Find the target dimensions of the GDI resource - const int nRequestedWidth = GetSystemMetrics(type == eResourceType_IconBig ? SM_CXICON : type == eResourceType_IconSmall ? SM_CXSMICON : SM_CXCURSOR); - const int nRequestedHeight = GetSystemMetrics(type == eResourceType_IconBig ? SM_CYICON : type == eResourceType_IconSmall ? SM_CYSMICON : SM_CYCURSOR); - if (nRequestedWidth != nRequestedHeight || nRequestedHeight <= 0 || nRequestedWidth <= 0) - { - // Don't support non-squares icons or cursors - return NULL; - } - - // Load texture. - // in this case, we want to fall back on a null, not substiture the missing texture. - _smart_ptr pImage = pRenderer->EF_LoadImage(path, FIM_NOFALLBACKS); - if (!pImage || pImage->mfGet_depth() != 1 || pImage->mfGet_NumSides() != 1 || pImage->mfGetTileMode() != eTM_None) - { - // Can't load texture, or texture is a cube-map or volume texture, or uses tiling of some kind - return NULL; - } - byte* pImgRaw = pImage->mfGet_image(0); - const ETEX_Format texFormat = pImage->mfGetFormat(); - - // Pick first mip level smaller than the GDI resource - int nMip = 0; - size_t offset = 0; - int nMipWidth = pImage->mfGet_width(); - int nMipHeight = pImage->mfGet_height(); - while (nMipWidth > nRequestedWidth) - { - ++nMip; - offset += pRenderer->GetTextureFormatDataSize(nMipWidth, nMipHeight, 1, 1, texFormat); - nMipWidth = max(nMipWidth / 2, 1); - nMipHeight = max(nMipHeight / 2, 1); - } - pImgRaw += offset; - if (nMip >= pImage->mfGet_numMips()) - { - // No appropriate mip in the texture - // Note: Consider creating a full mip-chain on the texture so this can't happen - return NULL; - } - const size_t nRawSize = pRenderer->GetTextureFormatDataSize(nMipWidth, nMipHeight, 1, 1, texFormat); - -#if 0 - // Check that DDS indexing is correct here - offset += nRawSize; - for (int nIdx = nMip + 1; nIdx < pImage->mfGet_numMips(); ++nIdx) - { - const int w = max(nMipWidth >> (nIdx - nMip), 1); - const int h = max(nMipHeight >> (nIdx - nMip), 1); - offset += pRenderer->GetTextureFormatDataSize(w, h, 1, 1, texFormat); - } - assert(offset == pImage->mfGet_ImageSize()); -#endif - - // Type of bitmap to create - BITMAPV5HEADER bi = { 0 }; - bi.bV5Size = sizeof(BITMAPV5HEADER); - bi.bV5Width = nRequestedWidth; - bi.bV5Height = -nRequestedHeight; - bi.bV5Planes = 1; - bi.bV5BitCount = 32; - bi.bV5Compression = BI_BITFIELDS; - // The following mask specification specifies a supported 32 BPP alpha format for Windows XP+ - bi.bV5AlphaMask = 0xFF000000; - bi.bV5RedMask = 0x00FF0000; - bi.bV5GreenMask = 0x0000FF00; - bi.bV5BlueMask = 0x000000FF; - - // Create the DIB section with an alpha channel - const HDC hdc = GetDC(NULL); - void* lpBits; - const HBITMAP hBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, &lpBits, NULL, 0); - ReleaseDC(NULL, hdc); - if (!hBitmap || !lpBits) - { - // Can't allocate OS bitmap - return NULL; - } - GdiFlush(); - - // Decompress texture - const bool bTryDecompress = texFormat != eTF_R8G8B8A8 && texFormat != eTF_B8G8R8A8 && texFormat != eTF_B8G8R8X8; - byte* const pImgDecomp = bTryDecompress ? new byte[nMipWidth * nMipHeight * sizeof(int32)] : pImgRaw; - const bool bImgDecompressed = bTryDecompress && pRenderer->DXTDecompress(pImgRaw, nRawSize, pImgDecomp, nMipWidth, nMipHeight, 1, texFormat, false, sizeof(int32)); - - // Check which conversions need to be performed - const bool bSRGB = (pImage->mfGet_Flags() & CImageExtensionHelper::EIF_SRGBRead) != 0; - const bool bSwap = (texFormat == eTF_R8G8B8A8) || bTryDecompress; - - HICON result = NULL; - if (!bTryDecompress || bImgDecompressed) - { - // Assign texture data with mismatching sizes - // Note: Any pixels not in the selected mip will become 100% transparent black, no resizing is performed - const size_t sourceRowStride = nMipWidth; - const size_t targetRowStride = nRequestedWidth; - const uint32* pSourceRow = (uint32*)pImgDecomp; - uint32* pTargetRow = (uint32*)lpBits; - - assert(sourceRowStride <= targetRowStride); - assert(nMipHeight <= nRequestedHeight); - assert(pSourceRow != pTargetRow); - assert(pSourceRow && pTargetRow); - - uint8 gammaTable[256]; - if (!bSRGB) - { - // Linear to sRGB table - const float gamma = 1.0f / 2.2f; - const float gammaMultiplier = 255.0f / powf(255.0f, gamma); - for (int i = 0; i < 256; ++i) - { - gammaTable[i] = uint8(powf(float(i), gamma) * gammaMultiplier); - } - } - else if (bSwap) - { - // sRGB to sRGB table (no change) - for (int i = 0; i < 256; ++i) - { - gammaTable[i] = uint8(i); - } - } - - for (int y = 0; y < nMipHeight; ++y, pSourceRow += sourceRowStride, pTargetRow += targetRowStride) - { - if (!bSwap && bSRGB) - { - memcpy(pTargetRow, pSourceRow, sourceRowStride * sizeof(uint32)); - } - else - { - const uint32* pSourceTexel = pSourceRow; - uint32* pTargetTexel = pTargetRow; - for (int x = 0; x < nMipWidth; ++x, ++pSourceTexel, ++pTargetTexel) - { - const uint8 red = gammaTable[uint8(*pSourceTexel >> 0)]; - const uint8 green = gammaTable[uint8(*pSourceTexel >> 8)]; - const uint8 blue = gammaTable[uint8(*pSourceTexel >> 16)]; - const uint32 alpha = *pSourceTexel & 0xFF000000; - *pTargetTexel = (red << (bSwap ? 16 : 0)) | (green << 8) | (blue << (bSwap ? 0 : 16)) | alpha; - } - } - - // Fill remaining columns with zeros - memset(pTargetRow + sourceRowStride, 0, (targetRowStride - sourceRowStride) * sizeof(uint32)); - } - - // Fill remaining rows with zeros - for (int y = nMipHeight; y < nRequestedHeight; ++y) - { - memset(pTargetRow, 0, targetRowStride * sizeof(uint32)); - pTargetRow += targetRowStride; - } - - // Convert to GDI icon - ICONINFO iconinfo = {0}; - iconinfo.fIcon = type == eResourceType_Cursor ? FALSE : TRUE; - iconinfo.hbmMask = ::CreateBitmap(nRequestedWidth, nRequestedHeight, 1, 1, NULL); - iconinfo.hbmColor = hBitmap; - result = ::CreateIconIndirect(&iconinfo); - DeleteObject(iconinfo.hbmMask); - } - - // Clean up - DeleteObject(hBitmap); - if (bTryDecompress) - { - delete[] pImgDecomp; - } - pImage.reset(); - - return result; -} - -#endif diff --git a/Code/CryEngine/CryCommon/crycommon_files.cmake b/Code/CryEngine/CryCommon/crycommon_files.cmake index ef49370c08..7d169c2643 100644 --- a/Code/CryEngine/CryCommon/crycommon_files.cmake +++ b/Code/CryEngine/CryCommon/crycommon_files.cmake @@ -14,9 +14,6 @@ set(FILES CryCommon.cpp Allocator.h FinalizingSpline.h - Gem.h - I3DEngine.h - I3DEngine_info.h IAudioInterfacesCommonData.h IAudioSystem.h IChunkFile.h @@ -86,7 +83,6 @@ set(FILES ITexture.h IThreadManager.h IThreadTask.h - ITimeOfDay.h ITimer.h IValidator.h IVideoRenderer.h @@ -143,7 +139,6 @@ set(FILES CryAssert.h CryCrc32.h CryCustomTypes.h - CryEngineDecalInfo.h CryFile.h CryFixedArray.h CryFixedString.h @@ -292,7 +287,6 @@ set(FILES platform_impl.cpp Win32specific.h Win64specific.h - WindowsUtils.h CryExtension/CryCreateClassInstance.h CryExtension/CryGUID.h CryExtension/CryTypeID.h @@ -317,7 +311,6 @@ set(FILES CryPool/STLWrapper.h CryPool/ThreadSafe.h stl/STLAlignedAlloc.h - ILocalMemoryUsage.h Serialization/Assert.h Serialization/BitVector.h Serialization/BitVectorImpl.h diff --git a/Code/CryEngine/CryCommon/crycommon_testing_files.cmake b/Code/CryEngine/CryCommon/crycommon_testing_files.cmake index ca133c2497..d20a33f791 100644 --- a/Code/CryEngine/CryCommon/crycommon_testing_files.cmake +++ b/Code/CryEngine/CryCommon/crycommon_testing_files.cmake @@ -10,7 +10,6 @@ # set(FILES - Mocks/I3DEngineMock.h Mocks/IAudioSystemMock.h Mocks/IConsoleMock.h Mocks/ICryPakMock.h diff --git a/Code/CryEngine/CryFont/CryFont.cpp b/Code/CryEngine/CryFont/CryFont.cpp deleted file mode 100644 index ab39a0fa4d..0000000000 --- a/Code/CryEngine/CryFont/CryFont.cpp +++ /dev/null @@ -1,845 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : CCryFont class. - - -#include "CryFont_precompiled.h" - -#if !defined(USE_NULLFONT_ALWAYS) - -#include "CryFont.h" -#include "CryPath.h" -#include "FFont.h" -#include "FontTexture.h" -#include "FontRenderer.h" -#include "ILocalizationManager.h" - -#include -#include - -// Static member definitions -const Vec2i CCryFont::defaultGlyphSize = Vec2i(ICryFont::defaultGlyphSizeX, ICryFont::defaultGlyphSizeY); - -#if !defined(_RELEASE) -static void DumpFontTexture(IConsoleCmdArgs* pArgs) -{ - if (pArgs->GetArgCount() != 2) - { - return; - } - - const char* pFontName = pArgs->GetArg(1); - - if (pFontName && *pFontName && *pFontName != '0') - { - string fontFile("@devroot@/"); - fontFile += pFontName; - fontFile += ".bmp"; - - CFFont* pFont = (CFFont*) gEnv->pCryFont->GetFont(pFontName); - if (pFont) - { - pFont->GetFontTexture()->WriteToFile(fontFile.c_str()); - gEnv->pLog->LogWithType(IMiniLog::eInputResponse, "Dumped \"%s\" texture to \"%s\"!", pFontName, fontFile.c_str()); - } - } -} - -static void DumpFontNames([[maybe_unused]] IConsoleCmdArgs* pArgs) -{ - string names = gEnv->pCryFont->GetLoadedFontNames(); - gEnv->pLog->LogWithType(IMiniLog::eInputResponse, "Currently loaded fonts: %s", names.c_str()); -} - -static void ReloadFonts([[maybe_unused]] IConsoleCmdArgs* pArgs) -{ - gEnv->pCryFont->ReloadAllFonts(); -} -#endif - -namespace -{ - //! Stores paths to styled font assets for a given set of languages - //! This struct stores the XML data contained within the tag of - //! an enclosing definition: - //! - //! - //! - //! - //! - //! - //! - //! - //! - struct FontTagXml - { - //! \return True if all font asset paths are non-empty, false otherwise - bool IsValid() const - { - // Note that "lang" can be empty - return !m_fontFilename.empty() - && !m_boldFontFilename.empty() - && !m_italicFontFilename.empty() - && !m_boldItalicFontFilename.empty(); - } - - string m_lang; //!< Stores a comma-separated list of languages this collection of fonts applies to. - //!< If this is an empty string, it implies that these set of fonts will be applied - //!< by default (when a language is being used but no fonts in the font family are - //!< mapped to that language). - - string m_fontFilename; //!< Font used when no styling is applied. - string m_boldFontFilename; //!< Bold-styled font - string m_italicFontFilename; //!< Italic-styled font - string m_boldItalicFontFilename; //!< Bold-italic-styled font - }; - - //! Stores parsed font family XML data. - //! This struct contains the name of the font family and a list of font - //! file XML data for all the language-specific mappings of this - //! font family. - //! - //! Example XML: - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - //! - struct FontFamilyTagXml - { - //! Returns true if all font file fields were parsed, false otherwise. - bool IsValid() const - { - for (const FontTagXml& fontTagXml : m_fontTagsXml) - { - if (!fontTagXml.IsValid()) - { - return false; - } - } - - // Every font family must have a name - return !m_fontFamilyName.empty(); - } - - string m_fontFamilyName; //!< Value of the "name" font-family tag attribute - AZStd::list m_fontTagsXml; //!< List of child tag data. - }; - - //! Returns true if the XML tree was traversed successfully, false otherwise. - //! - //! Note that, if this function returns true, it simply means that there were - //! no unexpected structure issues with the given XML tree, it doesn't - //! necessarily mean that all the required fields were parsed. - bool ParseFontFamilyXml(const XmlNodeRef& node, FontFamilyTagXml& xmlData) - { - if (!node) - { - return false; - } - - // - if (AZStd::string(node->getTag()) == "fontfamily") - { - const int numAttributes = node->getNumAttributes(); - - if (numAttributes <= 0) - { - // Expecting at least one attribute - return false; - } - - string name; - - for (int i = 0, count = node->getNumAttributes(); i < count; ++i) - { - const char* key = ""; - const char* value = ""; - if (node->getAttributeByIndex(i, &key, &value)) - { - if (string(key) == "name") - { - name = value; - } - else - { - // Unexpected font tag attribute - return false; - } - } - } - - name.Trim(); - if (!name.empty()) - { - xmlData.m_fontFamilyName = name; - } - else - { - // Font family must have a name - return false; - } - } - - // - if (AZStd::string(node->getTag()) == "font") - { - xmlData.m_fontTagsXml.push_back(FontTagXml()); - - string lang; - for (int i = 0, count = node->getNumAttributes(); i < count; ++i) - { - const char* key = ""; - const char* value = ""; - if (node->getAttributeByIndex(i, &key, &value)) - { - if (string(key) == "lang") - { - lang = value; - } - else - { - // Unexpected font tag attribute - return false; - } - } - } - - lang.Trim(); - if (!lang.empty()) - { - xmlData.m_fontTagsXml.back().m_lang = lang; - } - } - - // - else if (AZStd::string(node->getTag()) == "file") - { - const int numAttributes = node->getNumAttributes(); - - if (numAttributes <= 0) - { - // Expecting at least one attribute - return false; - } - - string path; - string tags; - - for (int i = 0, count = node->getNumAttributes(); i < count; ++i) - { - const char* key = ""; - const char* value = ""; - if (node->getAttributeByIndex(i, &key, &value)) - { - if (string(key) == "path") - { - path = value; - } - else if (string(key) == "tags") - { - tags = value; - } - else - { - // Unexpected font tag attribute - return false; - } - } - } - - tags.Trim(); - if (tags.empty()) - { - xmlData.m_fontTagsXml.back().m_fontFilename = path; - } - else if (tags == "b") - { - xmlData.m_fontTagsXml.back().m_boldFontFilename = path; - } - else if (tags == "i") - { - xmlData.m_fontTagsXml.back().m_italicFontFilename = path; - } - else - { - // We'll just assume any other tag indicates bold italic - xmlData.m_fontTagsXml.back().m_boldItalicFontFilename = path; - } - } - - for (int i = 0, count = node->getChildCount(); i < count; ++i) - { - XmlNodeRef child = node->getChild(i); - if (!ParseFontFamilyXml(child, xmlData)) - { - return false; - } - } - - return true; - } - - //! Only attempt XML file load if file exists. - //! There are use-cases where the XML path is not fully known (such as - //! when referencing font family names from font family XML files), and - //! attempting to load the XML files directly via ISystem() methods can - //! produce a lot of warning noise. - XmlNodeRef SafeLoadXmlFromFile(const string& xmlPath) - { - if (gEnv->pCryPak->IsFileExist(xmlPath.c_str())) - { - return GetISystem()->LoadXmlFromFile(xmlPath.c_str()); - } - - return XmlNodeRef(); - } - -} - -CCryFont::CCryFont(ISystem* pSystem) - : m_pSystem(pSystem) - , m_fonts() - , m_rndPropIsRGBA(false) - , m_rndPropHalfTexelOffset(0.5f) -{ - assert(m_pSystem); - - CryLogAlways("Using FreeType %d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH); - - // Persist fonts for application lifetime to prevent unnecessary work - REGISTER_CVAR(r_persistFontFamilies, r_persistFontFamilies, VF_NULL, "Persist loaded font families for lifetime of application."); - -#if !defined(_RELEASE) - REGISTER_COMMAND("r_DumpFontTexture", DumpFontTexture, 0, - "Dumps the specified font's texture to a bitmap file\n" - "Use r_DumpFontTexture to get the loaded font names\n" - "Usage: r_DumpFontTexture "); - REGISTER_COMMAND("r_DumpFontNames", DumpFontNames, 0, - "Logs a list of fonts currently loaded"); - REGISTER_COMMAND("r_ReloadFonts", ReloadFonts, VF_NULL, - "Reload all fonts"); -#endif -} - -CCryFont::~CCryFont() -{ - // Persist fonts for application lifetime to prevent unnecessary work - m_persistedFontFamilies.clear(); - - for (FontMapItor it = m_fonts.begin(), itEnd = m_fonts.end(); it != itEnd; ) - { - CFFont* pFont = it->second; - ++it; // iterate as Release() below will remove font from the map - SAFE_RELEASE(pFont); - } -} - -void CCryFont::Release() -{ - delete this; -} - -IFFont* CCryFont::NewFont(const char* pFontName) -{ - string name = pFontName; - name.MakeLower(); - - FontMapItor it = m_fonts.find(CONST_TEMP_STRING(name.c_str())); - if (it != m_fonts.end()) - { - return it->second; - } - - CFFont* pFont = new CFFont(m_pSystem, this, name.c_str()); - m_fonts.insert(FontMapItor::value_type(name, pFont)); - return pFont; -} - -IFFont* CCryFont::GetFont(const char* pFontName) const -{ - FontMapConstItor it = m_fonts.find(CONST_TEMP_STRING(string(pFontName).MakeLower())); - return it != m_fonts.end() ? it->second : 0; -} - -FontFamilyPtr CCryFont::LoadFontFamily(const char* pFontFamilyName) -{ - FontFamilyPtr fontFamily(nullptr); - string fontFamilyPath; - string fontFamilyFullPath; - - XmlNodeRef root = LoadFontFamilyXml(pFontFamilyName, fontFamilyPath, fontFamilyFullPath); - - if (root) - { - FontFamilyTagXml xmlData; - const bool parseSuccess = ParseFontFamilyXml(root, xmlData); - if (parseSuccess && xmlData.IsValid()) - { - const char* currentLanguage = gEnv->pSystem->GetLocalizationManager()->GetLanguage(); - FontTagXml* defaultFont = nullptr; - FontTagXml* langSpecificFont = nullptr; - - // Note that we don't break out of this for-loop early because we - // want to find both the default font family and the - // language-specific font family. We prefer the lang-specific - // family but will fall back on the default if it doesn't exist. - for (FontTagXml& fontTagXml : xmlData.m_fontTagsXml) - { - if (fontTagXml.m_lang.empty()) - { - defaultFont = &fontTagXml; - } - else - { - int searchPos = 0; - string langToken; - - // "lang" font-tag attribute could be comma-separated - while (!(langToken = fontTagXml.m_lang.Tokenize(",", searchPos)).empty()) - { - if (langToken.Trim() == currentLanguage) - { - langSpecificFont = &fontTagXml; - break; - } - } - } - } - - if (langSpecificFont || defaultFont) - { - // Prefer lang-specific font-family over default, if it exists - FontTagXml* fontTagXml = langSpecificFont ? langSpecificFont : defaultFont; - - // Pre-pend font family's path to make font family XML paths - // relative to font family file - fontTagXml->m_fontFilename = fontFamilyPath + fontTagXml->m_fontFilename; - fontTagXml->m_boldFontFilename = fontFamilyPath + fontTagXml->m_boldFontFilename; - fontTagXml->m_italicFontFilename = fontFamilyPath + fontTagXml->m_italicFontFilename; - fontTagXml->m_boldItalicFontFilename = fontFamilyPath + fontTagXml->m_boldItalicFontFilename; - - IFFont* normal = LoadFont(fontTagXml->m_fontFilename.c_str()); - IFFont* bold = LoadFont(fontTagXml->m_boldFontFilename.c_str()); - IFFont* italic = LoadFont(fontTagXml->m_italicFontFilename.c_str()); - IFFont* boldItalic = LoadFont(fontTagXml->m_boldItalicFontFilename.c_str()); - - // Only continue if all fonts were created successfully - if (normal && bold && italic && boldItalic) - { - fontFamily.reset(new FontFamily(), - [this](FontFamily* pFontFamily) - { - ReleaseFontFamily(pFontFamily); - }); - - // Map the font family name both by path and by name defined - // within the Font Family XML itself. This allows font - // families to also be referenced simply by name. - if (!AddFontFamilyToMaps(fontFamilyFullPath, xmlData.m_fontFamilyName, fontFamily)) - { - SAFE_RELEASE(normal); - SAFE_RELEASE(bold); - SAFE_RELEASE(italic); - SAFE_RELEASE(boldItalic); - - return nullptr; - } - - fontFamily->familyName = xmlData.m_fontFamilyName; - fontFamily->normal = normal; - fontFamily->bold = bold; - fontFamily->italic = italic; - fontFamily->boldItalic = boldItalic; - } - else - { - SAFE_RELEASE(normal); - SAFE_RELEASE(bold); - SAFE_RELEASE(italic); - SAFE_RELEASE(boldItalic); - } - } - } - } - - if (!fontFamily) - { - // Unable to load font family XML, so load font normally and associate - // it with a font family - IFFont* pFont = LoadFont(pFontFamilyName); - - if (pFont) - { - // Create a font family from a single font by assigning all the - // font family stylings to the same font - fontFamily.reset(new FontFamily(), - [this](FontFamily* pFontFamily) - { - ReleaseFontFamily(pFontFamily); - }); - - // Use filepath as familyName so font loading/unloading doesn't break with duplicate file names - fontFamily->familyName = pFontFamilyName; - - if (!AddFontFamilyToMaps(pFontFamilyName, fontFamily->familyName, fontFamily)) - { - SAFE_RELEASE(pFont); - - return nullptr; - } - - // Assign all stylings to the same font - fontFamily->normal = pFont; - fontFamily->bold = pFont; - fontFamily->italic = pFont; - fontFamily->boldItalic = pFont; - - // The other three stylings need to have their ref count - // incremented (even though in this particular case its all the - // same font) because when ReleaseFontFamily executes all fonts - // in the family will be (corresondingly) Release'd. - fontFamily->bold->AddRef(); - fontFamily->italic->AddRef(); - fontFamily->boldItalic->AddRef(); - } - } - - // Persist fonts for application lifetime to prevent unnecessary work - if (r_persistFontFamilies > 0) - { - m_persistedFontFamilies.emplace_back(FontFamilyPtr(fontFamily)); - } - - return fontFamily; -} - -FontFamilyPtr CCryFont::GetFontFamily(const char* pFontFamilyName) -{ - FontFamilyPtr fontFamily = nullptr; - - // The given string could either be: a font family name (defined in font - // family XML), a file path (for regular fonts mapped as font families), - // or just the filename of a font itself. Fonts are mapped by font family - // name or by filepath, so attempt lookup using the map first since it's - // the fastest. - string loweredName = string(pFontFamilyName).Trim().MakeLower(); - auto it = m_fontFamilies.find(PathUtil::MakeGamePath(loweredName).c_str()); - if (it != m_fontFamilies.end()) - { - fontFamily = FontFamilyPtr(it->second); - } - else - { - // Iterate through all fonts, returning the first match where simply - // the filename of a font could be a match. This case will likely be - // hit when text markup references a font that doesn't belong to a - // font family. - for (const auto& fontFamilyIter : m_fontFamilies) - { - const AZStd::string& mappedFontFamilyName = fontFamilyIter.first; - string mappedFilenameNoExtension = PathUtil::GetFileName(mappedFontFamilyName.c_str()); - - string searchStringFilenameNoExtension = PathUtil::GetFileName(loweredName); - - if (mappedFilenameNoExtension == searchStringFilenameNoExtension) - { - fontFamily = FontFamilyPtr(fontFamilyIter.second); - break; - } - } - } - - return fontFamily; -} - -void CCryFont::AddCharsToFontTextures(FontFamilyPtr pFontFamily, const char* pChars, int glyphSizeX, int glyphSizeY) -{ - pFontFamily->normal->AddCharsToFontTexture(pChars, glyphSizeX, glyphSizeY); - pFontFamily->bold->AddCharsToFontTexture(pChars, glyphSizeX, glyphSizeY); - pFontFamily->italic->AddCharsToFontTexture(pChars, glyphSizeX, glyphSizeY); - pFontFamily->boldItalic->AddCharsToFontTexture(pChars, glyphSizeX, glyphSizeY); -} - -void CCryFont::SetRendererProperties(IRenderer* pRenderer) -{ - if (pRenderer) - { - m_rndPropIsRGBA = (pRenderer->GetFeatures() & RFT_RGBA) != 0; - m_rndPropHalfTexelOffset = 0.0f; - } -} - -void CCryFont::GetMemoryUsage(ICrySizer* pSizer) const -{ - if (!pSizer->Add(*this)) - { - return; - } - - pSizer->AddObject(m_fonts); -} - -string CCryFont::GetLoadedFontNames() const -{ - string ret; - for (FontMapConstItor it = m_fonts.begin(), itEnd = m_fonts.end(); it != itEnd; ++it) - { - CFFont* pFont = it->second; - if (pFont) - { - if (!ret.empty()) - { - ret += ","; - } - ret += pFont->GetName(); - } - } - return ret; -} - -void CCryFont::OnLanguageChanged() -{ - ReloadAllFonts(); - - EBUS_EVENT(LanguageChangeNotificationBus, LanguageChanged); -} - -void CCryFont::ReloadAllFonts() -{ - // Persist fonts for application lifetime to prevent unnecessary work - m_persistedFontFamilies.clear(); - - AZStd::list fontFamilyFilenames; - AZStd::list fontFamilyWeakPtrs; - - // Iterate through all currently loaded font families - for (auto it : m_fontFamilyReverseLookup) - { - fontFamilyWeakPtrs.push_back(it.first); - fontFamilyFilenames.push_back(it.second->first); - } - - // Release font-family resources and unmap them - for (auto fontFamily : fontFamilyWeakPtrs) - { - ReleaseFontFamily(fontFamily); - } - - // Reload the font families - for (auto familyFilename : fontFamilyFilenames) - { - LoadFontFamily(familyFilename.c_str()); - } - - // All UI text components need to reload their font assets (both in-game - // and in-editor). - EBUS_EVENT(FontNotificationBus, OnFontsReloaded); -} - -void CCryFont::UnregisterFont(const char* pFontName) -{ - FontMapItor it = m_fonts.find(CONST_TEMP_STRING(pFontName)); - -#if defined(AZ_ENABLE_TRACING) - IFFont* fontPtr = it->second; -#endif - - if (it != m_fonts.end()) - { - m_fonts.erase(it); - } - -#if defined(AZ_ENABLE_TRACING) - // Make sure the font being released isn't currently in use by a font family. - // If it is, the FontFamily will have a dangling pointer and will cause a - // crash when the FontFamily eventually gets released. - for (auto reverseMapEntry : m_fontFamilyReverseLookup) - { - FontFamily* fontFamily = reverseMapEntry.first; - AZ_Assert(fontFamily->normal != fontPtr, - "The following font is being freed but still in use by a FontFamily: %s", - pFontName); - AZ_Assert(fontFamily->italic != fontPtr, - "The following font is being freed but still in use by a FontFamily: %s", - pFontName); - AZ_Assert(fontFamily->bold != fontPtr, - "The following font is being freed but still in use by a FontFamily: %s", - pFontName); - AZ_Assert(fontFamily->boldItalic != fontPtr, - "The following font is being freed but still in use by a FontFamily: %s", - pFontName); - } -#endif -} - -IFFont* CCryFont::LoadFont(const char* pFontName) -{ - string fontName = pFontName; - fontName.MakeLower(); - - IFFont* font = GetFont(fontName); - if (font) - { - font->AddRef(); // use existing loaded font - } - else - { - // attempt to create and load a new font, use the font pathname as the font name - font = NewFont(fontName); - if (!font) - { - string errorMsg = "Error creating a new font named "; - errorMsg += fontName; - errorMsg += "."; - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, errorMsg.c_str()); - } - else - { - // creating font adds one to its refcount so no need for AddRef here - if (!font->Load(fontName)) - { - string errorMsg = "Error loading a font from "; - errorMsg += fontName; - errorMsg += "."; - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, errorMsg); - font->Release(); - font = nullptr; - } - } - } - - return font; -} - -void CCryFont::ReleaseFontFamily(FontFamily* pFontFamily) -{ - // Ensure that Font Family was mapped prior to destruction - const bool isMapped = m_fontFamilyReverseLookup.find(pFontFamily) != m_fontFamilyReverseLookup.end(); - if (!isMapped) - { - return; - } - - // Note that the FontFamily is mapped both by filename and by "family name" - auto it = m_fontFamilyReverseLookup[pFontFamily]; - m_fontFamilies.erase(it); - string familyName(pFontFamily->familyName); - m_fontFamilies.erase(familyName.MakeLower().c_str()); - - // Reverse lookup is used to avoid needing to store filename path with - // the font family, so we need to remove that entry also. - m_fontFamilyReverseLookup.erase(pFontFamily); - - SAFE_RELEASE(pFontFamily->normal); - SAFE_RELEASE(pFontFamily->bold); - SAFE_RELEASE(pFontFamily->italic); - SAFE_RELEASE(pFontFamily->boldItalic); -} - -bool CCryFont::AddFontFamilyToMaps(const char* pFontFamilyFilename, const char* pFontFamilyName, FontFamilyPtr fontFamily) -{ - if (!pFontFamilyFilename || !pFontFamilyName || !fontFamily.get()) - { - return false; - } - - // We don't support "updating" mapped values. - AZStd::string loweredFilename(PathUtil::MakeGamePath(string(pFontFamilyFilename)).c_str()); - AZStd::to_lower(loweredFilename.begin(), loweredFilename.end()); - if (m_fontFamilies.find(loweredFilename) != m_fontFamilies.end()) - { - string warnMsg; - warnMsg.Format("Couldn't load Font Family '%s': already loaded", pFontFamilyFilename); - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, warnMsg.c_str()); - return false; - } - - // Similarly, we don't support Font Family XMLs that have the same font - // family name (we assume all Font Family names are unique). - AZStd::string loweredFontFamilyName(pFontFamilyName); - AZStd::to_lower(loweredFontFamilyName.begin(), loweredFontFamilyName.end()); - if (m_fontFamilies.find(loweredFontFamilyName) != m_fontFamilies.end()) - { - string warnMsg; - warnMsg.Format("Couldn't load Font Family '%s': already loaded", pFontFamilyName); - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, warnMsg.c_str()); - return false; - } - - // First, insert by filename - AZStd::pair> insertPair(loweredFilename, fontFamily); - auto iterPosition = m_fontFamilies.insert(insertPair).first; - m_fontFamilyReverseLookup[fontFamily.get()] = iterPosition; - - // Then, by Font Family name - AZStd::pair> nameInsertPair(loweredFontFamilyName, fontFamily); - m_fontFamilies.insert(nameInsertPair); - - return true; -} - -XmlNodeRef CCryFont::LoadFontFamilyXml(const char* pFontFamilyName, string& outputDirectory, string& outputFullPath) -{ - outputFullPath = pFontFamilyName; - outputDirectory = PathUtil::GetPath(pFontFamilyName); - XmlNodeRef root = SafeLoadXmlFromFile(outputFullPath); - - // When parsing a tag in markup, only the font name is given and - // not a path, so we try to build a "best guess" path from the name. - if (!root) - { - string fileNoExtension(PathUtil::GetFileName(pFontFamilyName)); - string fileExtension(PathUtil::GetExt(pFontFamilyName)); - - if (fileExtension.empty()) - { - fileExtension = ".fontfamily"; - } - - // Try: "fonts/fontName.fontfamily" - outputDirectory = string("fonts/"); - outputFullPath = outputDirectory + fileNoExtension + fileExtension; - root = SafeLoadXmlFromFile(outputFullPath); - - // Finally, try: "fonts/fontName/fontName.fontfamily" - if (!root) - { - outputDirectory = string("fonts/") + fileNoExtension + "/"; - outputFullPath = outputDirectory + fileNoExtension + fileExtension; - root = SafeLoadXmlFromFile(outputFullPath); - } - } - - return root; -} - -#endif - diff --git a/Code/CryEngine/CryFont/CryFont.def b/Code/CryEngine/CryFont/CryFont.def deleted file mode 100644 index 43bfe0b13d..0000000000 --- a/Code/CryEngine/CryFont/CryFont.def +++ /dev/null @@ -1,3 +0,0 @@ -EXPORTS - ModuleInitISystem @2 - CryModuleGetMemoryInfo @8 diff --git a/Code/CryEngine/CryFont/CryFont.h b/Code/CryEngine/CryFont/CryFont.h deleted file mode 100644 index 726818f5a7..0000000000 --- a/Code/CryEngine/CryFont/CryFont.h +++ /dev/null @@ -1,108 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYFONT_CRYFONT_H -#define CRYINCLUDE_CRYFONT_CRYFONT_H -#pragma once - - -#if !defined(USE_NULLFONT_ALWAYS) - -#include -#include -#include -#include - -class CFFont; - - -class CCryFont - : public ICryFont -{ - friend class CFFont; - -public: - - static const Vec2i defaultGlyphSize; //!< Default glyph size indicates that glyphs in the font texture - //!< should be rendered at the maximum resolution supported by - //!< the font texture's glyph cell/slot configuration (configured - //!< via font XML). - -public: - CCryFont(ISystem* pSystem); - virtual ~CCryFont(); - - virtual void Release(); - virtual IFFont* NewFont(const char* pFontName); - virtual IFFont* GetFont(const char* pFontName) const; - virtual FontFamilyPtr LoadFontFamily(const char* pFontFamilyName) override; - virtual FontFamilyPtr GetFontFamily(const char* pFontFamilyName) override; - virtual void AddCharsToFontTextures(FontFamilyPtr pFontFamily, const char* pChars, int glyphSizeX = ICryFont::defaultGlyphSizeX, int glyphSizeY = ICryFont::defaultGlyphSizeY) override; - virtual void SetRendererProperties(IRenderer* pRenderer); - virtual void GetMemoryUsage(ICrySizer* pSizer) const; - virtual string GetLoadedFontNames() const; - virtual void OnLanguageChanged() override; - virtual void ReloadAllFonts() override; - -public: - void UnregisterFont(const char* pFontName); - bool RndPropIsRGBA() const { return m_rndPropIsRGBA; } - float RndPropHalfTexelOffset() const { return m_rndPropHalfTexelOffset; } - -private: - typedef std::map FontMap; - typedef FontMap::iterator FontMapItor; - typedef FontMap::const_iterator FontMapConstItor; - - typedef AZStd::map> FontFamilyMap; - typedef AZStd::map FontFamilyReverseLookupMap; - -private: - //! Convenience method for loading fonts - IFFont* LoadFont(const char* fontName); - - //! Called when final FontFamily shared_ptr is destroyed; do not call directly. - void ReleaseFontFamily(FontFamily* pFontFamily); - - //! Adds new entries into both font family maps for the given font family - //! - //! Note that it's not possible to update Font Family mappings with this - //! method. The only way to do that would be to release the font family - //! and re-load it with the new values. - //! - //! \return True only if the Font Family was added to the maps, false for all other cases (such as - //! when the font family is already mapped). - bool AddFontFamilyToMaps(const char* pFontFamilyFilename, const char* pFontFamilyName, FontFamilyPtr fontFamily); - - //! Internal method that (possibly) makes several attempts at locating and loading a given font family XML. - //! \param pFontFamilyName The name of the font family, or path to a font family file. - //! \param outputDirectory Path to loaded font family (no filename), may need resolving with PathUtil::MakeGamePath. - //! \param outputFullPath Full path to loaded font family, may need resolving with PathUtil::MakeGamePath. - XmlNodeRef LoadFontFamilyXml(const char* pFontFamilyName, string& outputDirectory, string& outputFullPath); - -private: - FontMap m_fonts; - FontFamilyMap m_fontFamilies; //!< Map font family names to weak ptrs so we can construct shared_ptrs but not keep a ref ourselves. - FontFamilyReverseLookupMap m_fontFamilyReverseLookup; // m_persistedFontFamilies; //!< Stores persisted fonts (if "persist font families" is enabled) - -}; - -#endif - -#endif // CRYINCLUDE_CRYFONT_CRYFONT_H diff --git a/Code/CryEngine/CryFont/CryFont.rc b/Code/CryEngine/CryFont/CryFont.rc deleted file mode 100644 index 5730d0a537..0000000000 --- a/Code/CryEngine/CryFont/CryFont.rc +++ /dev/null @@ -1,111 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Russian resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -#ifdef _WIN32 -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT -#pragma code_page(1251) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""winres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -#endif // Russian resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// German (Germany) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU) -#ifdef _WIN32 -LANGUAGE LANG_GERMAN, SUBLANG_GERMAN -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,1 - PRODUCTVERSION 1,0,0,1 - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000904b0" - BEGIN - VALUE "CompanyName", "Amazon.com, Inc." - VALUE "FileVersion", "1, 0, 0, 1" - VALUE "LegalCopyright", "Portions of this file Copyright (c) Amazon.com, Inc. or its affiliates. All Rights Reserved. Original file Copyright (c) Crytek GMBH. Used under license by Amazon.com, Inc. and its affiliates." - VALUE "ProductName", "Lumberyard" - VALUE "ProductVersion", "1, 0, 0, 1" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x9, 1200 - END -END - -#endif // German (Germany) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/Code/CryEngine/CryFont/CryFont_precompiled.cpp b/Code/CryEngine/CryFont/CryFont_precompiled.cpp deleted file mode 100644 index 235fe8e053..0000000000 --- a/Code/CryEngine/CryFont/CryFont_precompiled.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CryFont_precompiled.h" diff --git a/Code/CryEngine/CryFont/CryFont_precompiled.h b/Code/CryEngine/CryFont/CryFont_precompiled.h deleted file mode 100644 index e37845aa35..0000000000 --- a/Code/CryEngine/CryFont/CryFont_precompiled.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once - -#include - -#define CRYFONT_EXPORTS - -#include - -#include - -#include -#include -#include -#include - -#define USE_NULLFONT - -#if defined(DEDICATED_SERVER) -#define USE_NULLFONT_ALWAYS 1 -#endif - diff --git a/Code/CryEngine/CryFont/FBitmap.h b/Code/CryEngine/CryFont/FBitmap.h deleted file mode 100644 index 93f5505726..0000000000 --- a/Code/CryEngine/CryFont/FBitmap.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -#ifndef CRYINCLUDE_CRYFONT_FBITMAP_H -#define CRYINCLUDE_CRYFONT_FBITMAP_H - - -class CFBitmap -{ -public: - CFBitmap(); - ~CFBitmap(); - - int Blur(int iIterations); - int Scale(float fScaleX, float fScaleY); - - int BlitFrom(CFBitmap* pSrc, int iSX, int iSY, int iDX, int iDY, int iW, int iH); - int BlitTo(CFBitmap* pDst, int iDX, int iDY, int iSX, int iSY, int iW, int iH); - - int Create(int iWidth, int iHeight); - int Release(); - - int SaveBitmap(const string& szFileName); - int Get32Bpp(unsigned int** pBuffer) - { - (*pBuffer) = new unsigned int[m_iWidth * m_iHeight]; - - if (!(*pBuffer)) - { - return 0; - } - - int iDataSize = m_iWidth * m_iHeight; - - for (int i = 0; i < iDataSize; i++) - { - (*pBuffer)[i] = (m_pData[i] << 24) | (m_pData[i] << 16) | (m_pData[i] << 8) | (m_pData[i]); - } - - return 1; - } - - int GetWidth() { return m_iWidth; } - int GetHeight() { return m_iHeight; } - - void SetRenderData(void* pRenderData) { m_pIRenderData = pRenderData; }; - void* GetRenderData() { return m_pIRenderData; }; - - void GetMemoryUsage (class ICrySizer* pSizer); - - unsigned char* GetData() { return m_pData; } - -public: - - int m_iWidth; - int m_iHeight; - - unsigned char* m_pData; - void* m_pIRenderData; -}; - - -#endif // CRYINCLUDE_CRYFONT_FBITMAP_H diff --git a/Code/CryEngine/CryFont/FFont.cpp b/Code/CryEngine/CryFont/FFont.cpp deleted file mode 100644 index c028a0827e..0000000000 --- a/Code/CryEngine/CryFont/FFont.cpp +++ /dev/null @@ -1,1550 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Font class. - - -#include "CryFont_precompiled.h" - -#if !defined(USE_NULLFONT_ALWAYS) - -#include "FFont.h" -#include "CryFont.h" -#include "FontTexture.h" -#include "UnicodeIterator.h" - -#include -#include - -static ColorB ColorTable[10] = -{ - ColorB(0x00, 0x00, 0x00), // black - ColorB(0xff, 0xff, 0xff), // white - ColorB(0x00, 0x00, 0xff), // blue - ColorB(0x00, 0xff, 0x00), // green - ColorB(0xff, 0x00, 0x00), // red - ColorB(0x00, 0xff, 0xff), // cyan - ColorB(0xff, 0xff, 0x00), // yellow - ColorB(0xff, 0x00, 0xff), // purple - ColorB(0xff, 0x80, 0x00), // orange - ColorB(0x8f, 0x8f, 0x8f), // grey -}; - -static const int TabCharCount = 4; -static const size_t MsgBufferSize = 1024; -static const size_t MaxDrawVBQuads = 128; - -CFFont::CFFont(ISystem* pSystem, CCryFont* pCryFont, const char* pFontName) - : m_name(pFontName) - , m_curPath("") - , m_pFontTexture(0) - , m_fontBufferSize(0) - , m_pFontBuffer(0) - , m_texID(-1) - , m_textureVersion(0) - , m_pSystem(pSystem) - , m_pCryFont(pCryFont) - , m_fontTexDirty(false) - , m_effects() - , m_pDrawVB(0) - , m_nRefCount(0) - , m_monospacedFont(false) -{ - assert(m_name.c_str()); - assert(m_pSystem); - assert(m_pCryFont); - - // create default effect - SEffect* pEffect = AddEffect("default"); - pEffect->AddPass(); - - m_pDrawVB = new SVF_P3F_C4B_T2F[MaxDrawVBQuads * 6]; - - AddRef(); -} - -CFFont::~CFFont() -{ - // The font should already be unregistered through a call to - // CFFont::Release() at this point. - CRY_ASSERT(m_pCryFont == nullptr); - - Free(); - - SAFE_DELETE_ARRAY(m_pDrawVB); -} - -int32 CFFont::AddRef() -{ - int32 nRef = CryInterlockedIncrement(&m_nRefCount); - return nRef; -} - -int32 CFFont::Release() -{ - if (m_nRefCount > 0) - { - int32 nRef = CryInterlockedDecrement(&m_nRefCount); - if (nRef < 0) - { - CryFatalError("CBaseResource::Release() called more than once!"); - } - - if (nRef <= 0) - { - if (m_pCryFont) - { - AZStd::lock_guard locker(m_fontMutex); - - // Unregister font so no one can increase it's ref count while it is queued for deletion - m_pCryFont->UnregisterFont(m_name); - m_pCryFont = nullptr; - } - - if (gEnv->pRenderer) - { - gEnv->pRenderer->DeleteFont(this); - } - return 0; - } - return nRef; - } - return 0; -} - -// Load a font from a TTF file -bool CFFont::Load(const char* pFontFilePath, unsigned int width, unsigned int height, unsigned int widthNumSlots, unsigned int heightNumSlots, unsigned int flags, float sizeRatio) -{ - if (!pFontFilePath) - { - return false; - } - - Free(); - - auto pPak = gEnv->pCryPak; - - string fullFile; - if (pPak->IsAbsPath(pFontFilePath)) - { - fullFile = pFontFilePath; - } - else - { - fullFile = m_curPath + pFontFilePath; - } - - int iSmoothMethod = (flags & TTFFLAG_SMOOTH_MASK) >> TTFFLAG_SMOOTH_SHIFT; - int iSmoothAmount = (flags & TTFFLAG_SMOOTH_AMOUNT_MASK) >> TTFFLAG_SMOOTH_AMOUNT_SHIFT; - - AZ::IO::HandleType fileHandle = pPak->FOpen(fullFile.c_str(), "rb"); - if (fileHandle == AZ::IO::InvalidHandle) - { - return false; - } - - size_t fileSize = pPak->FGetSize(fileHandle); - if (!fileSize) - { - pPak->FClose(fileHandle); - return false; - } - - unsigned char* pBuffer = new unsigned char[fileSize]; - if (!pPak->FReadRaw(pBuffer, fileSize, 1, fileHandle)) - { - pPak->FClose(fileHandle); - delete [] pBuffer; - return false; - } - - pPak->FClose(fileHandle); - - if (!m_pFontTexture) - { - m_pFontTexture = new CFontTexture(); - } - - if (!m_pFontTexture || !m_pFontTexture->CreateFromMemory(pBuffer, (int)fileSize, width, height, iSmoothMethod, iSmoothAmount, widthNumSlots, heightNumSlots, sizeRatio)) - { - delete [] pBuffer; - return false; - } - - m_monospacedFont = m_pFontTexture->GetMonospaced(); - m_pFontBuffer = pBuffer; - m_fontBufferSize = fileSize; - m_fontTexDirty = false; - m_sizeRatio = sizeRatio; - - InitCache(); - - return true; -} - - -void CFFont::Free() -{ - IRenderer* pRenderer = gEnv->pRenderer; - if (m_texID >= 0 && pRenderer) - { - pRenderer->RemoveTexture(m_texID); - m_texID = -1; - m_textureVersion = 0; - } - - delete m_pFontTexture; - m_pFontTexture = 0; - - delete [] m_pFontBuffer; - m_pFontBuffer = 0; -} - -void CFFont::DrawString(float x, float y, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - IF (!pStr, 0) - { - return; - } - - DrawStringUInternal(x, y, 1.0f, pStr, asciiMultiLine, ctx); -} - -void CFFont::DrawString(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - IF (!pStr, 0) - { - return; - } - - DrawStringUInternal(x, y, z, pStr, asciiMultiLine, ctx); -} - -void CFFont::DrawStringUInternal(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - IF (!pStr || !m_pFontTexture || ctx.m_fxIdx >= m_effects.size() || m_effects[ctx.m_fxIdx].m_passes.empty(), 0) - { - return; - } - - AZStd::lock_guard locker(m_fontMutex); - - IRenderer* pRenderer = gEnv->pRenderer; - AZ_Assert(pRenderer, "gEnv->pRenderer is NULL"); - - pRenderer->DrawStringU(this, x, y, z, pStr, asciiMultiLine, ctx); -} - -ILINE uint32 COLCONV(uint32 clr) -{ - return ((clr & 0xff00ff00) | ((clr & 0xff0000) >> 16) | ((clr & 0xff) << 16)); -} - -void CFFont::RenderCallback(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - AZStd::lock_guard locker(m_fontMutex); - - const size_t fxSize = m_effects.size(); - - IF (fxSize && m_texID == -1 && !InitTexture(), 0) - { - return; - } - - // if the font is about to be deleted then m_pCryFont can be nullptr - if (!m_pCryFont) - { - return; - } - - SVF_P3F_C4B_T2F* pVertex = m_pDrawVB; - size_t vbOffset = 0; - - bool isFontRenderStateSet = false; - TransformationMatrices backupSceneMatrices; - IRenderer* pRenderer = gEnv->pRenderer; - AZ_Assert(pRenderer, "gEnv->pRenderer is NULL"); - - int baseState = ctx.m_baseState; - bool overrideViewProjMatrices = ctx.m_overrideViewProjMatrices; - int texId = m_texID; - - // Local function to share code needed when we render the vertex buffer so far - AZStd::function RenderVB = [&pVertex, &vbOffset, pRenderer] - { - gEnv->pRenderer->DrawDynVB(pVertex, 0, vbOffset, 0, prtTriangleList); - vbOffset = 0; - }; - - // Local function that is passed into CreateQuadsForText as the AddQuad function - AddFunction AddQuad = [&pVertex, &vbOffset, RenderVB] - (const Vec3& v0, const Vec3& v1, const Vec3& v2, const Vec3& v3, const Vec2& tc0, const Vec2& tc1, const Vec2& tc2, const Vec2& tc3, uint32 packedColor) - { - // define char quad - pVertex[vbOffset].xyz = v0; - pVertex[vbOffset].color.dcolor = packedColor; - pVertex[vbOffset].st = tc0; - - pVertex[vbOffset + 1].xyz = v1; - pVertex[vbOffset + 1].color.dcolor = packedColor; - pVertex[vbOffset + 1].st = tc1; - - pVertex[vbOffset + 2].xyz = v2; - pVertex[vbOffset + 2].color.dcolor = packedColor; - pVertex[vbOffset + 2].st = tc2; - - pVertex[vbOffset + 3].xyz = v2; - pVertex[vbOffset + 3].color.dcolor = packedColor; - pVertex[vbOffset + 3].st = tc2; - - pVertex[vbOffset + 4].xyz = v3; - pVertex[vbOffset + 4].color.dcolor = packedColor; - pVertex[vbOffset + 4].st = tc3; - - pVertex[vbOffset + 5].xyz = v0; - pVertex[vbOffset + 5].color.dcolor = packedColor; - pVertex[vbOffset + 5].st = tc0; - - vbOffset += 6; - - if (vbOffset >= MaxDrawVBQuads * 6) - { - RenderVB(); - } - }; - - // Local function that is passed into CreateQuadsForText as the BeginPass function - BeginPassFunction BeginPass = [&pVertex, &vbOffset, &isFontRenderStateSet, &backupSceneMatrices, texId, pRenderer, baseState, RenderVB, overrideViewProjMatrices] - (const SRenderingPass* pPass) - { - // We don't want to set this state before the call to CreateQuadsForText since that calls Prepare, - // which is needed before FontSetTexture - if (!isFontRenderStateSet) - { - pRenderer->FontSetTexture(texId, FILTER_TRILINEAR); - pRenderer->FontSetRenderingState(overrideViewProjMatrices, backupSceneMatrices); - gEnv->pRenderer->FontSetBlending(pPass->m_blendSrc, pPass->m_blendDest, baseState); - isFontRenderStateSet = true; - } - - if (vbOffset > 0) - { - RenderVB(); - } - - gEnv->pRenderer->FontSetBlending(pPass->m_blendSrc, pPass->m_blendDest, baseState); - }; - - CreateQuadsForText(x, y, z, pStr, asciiMultiLine, ctx, AddQuad, BeginPass); - - if (vbOffset > 0) - { - RenderVB(); - } - - // restore the old states - if (isFontRenderStateSet) - { - pRenderer->FontRestoreRenderingState(overrideViewProjMatrices, backupSceneMatrices); - } -} - -Vec2 CFFont::GetTextSize(const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - IF (!pStr, 0) - { - return Vec2(0.0f, 0.0f); - } - - return GetTextSizeUInternal(pStr, asciiMultiLine, ctx); -} - -Vec2 CFFont::GetTextSizeUInternal(const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - const size_t fxSize = m_effects.size(); - - IF (!pStr || !m_pFontTexture || !fxSize, 0) - { - return Vec2(0, 0); - } - - AZStd::lock_guard locker(m_fontMutex); - - Prepare(pStr, false, ctx.m_requestSize); - - IRenderer* pRenderer = gEnv->pRenderer; - AZ_Assert(pRenderer, "gEnv->pRenderer is NULL"); - - // This is the "logical" size of the font (in pixels). The actual size of - // the glyphs in the font texture may have additional scaling applied or - // could have been re-rendered at a different size. - Vec2 size = ctx.m_size; - if (ctx.m_sizeIn800x600) - { - pRenderer->ScaleCoord(size.x, size.y); - } - - // This scaling takes into account the logical size of the font relative - // to any additional scaling applied (such as from "size ratio"). - const TextScaleInfoInternal scaleInfo(CalculateScaleInternal(ctx)); - - float maxW = 0; - float maxH = 0; - - const size_t fxIdx = ctx.m_fxIdx < fxSize ? ctx.m_fxIdx : 0; - const SEffect& fx = m_effects[fxIdx]; - - for (size_t i = 0, numPasses = fx.m_passes.size(); i < numPasses; ++i) - { - const SRenderingPass* pPass = &fx.m_passes[numPasses - i - 1]; - - // gather pass data - Vec2 offset = pPass->m_posOffset; - - float charX = offset.x; - float charY = offset.y + size.y; - - if (charY > maxH) - { - maxH = charY; - } - - // parse the string, ignoring control characters - uint32_t nextCh = 0; - Unicode::CIterator pChar(pStr); - while (uint32_t ch = *pChar) - { - ++pChar; - nextCh = *pChar; - switch (ch) - { - case '\\': - { - if (*pChar != 'n' || !asciiMultiLine) - { - break; - } - - ++pChar; - } - case '\n': - { - if (charX > maxW) - { - maxW = charX; - } - - charX = offset.x; - charY += size.y; - - if (charY > maxH) - { - maxH = charY; - } - - continue; - } - break; - case '\r': - { - if (charX > maxW) - { - maxW = charX; - } - - charX = offset.x; - continue; - } - break; - case '\t': - { - if (ctx.m_proportional) - { - charX += TabCharCount * size.x * FONT_SPACE_SIZE; - } - else - { - charX += TabCharCount * size.x * ctx.m_widthScale; - } - continue; - } - break; - case '$': - { - if (ctx.m_processSpecialChars) - { - if (*pChar == '$') - { - ++pChar; - } - else if (isdigit(*pChar)) - { - ++pChar; - continue; - } - else if (*pChar == 'O' || *pChar == 'o') - { - ++pChar; - continue; - } - } - } - break; - default: - break; - } - - const bool rerenderGlyphs = m_sizeBehavior == SizeBehavior::Rerender; - const Vec2i requestSize = rerenderGlyphs ? ctx.m_requestSize : CCryFont::defaultGlyphSize; - int horizontalAdvance = m_pFontTexture->GetHorizontalAdvance(ch, requestSize); - float advance; - - if (ctx.m_proportional) - { - advance = horizontalAdvance * scaleInfo.scale.x; - } - else - { - advance = size.x * ctx.m_widthScale; - } - - // Adjust "advance" here for kerning purposes - Vec2 kerningOffset(Vec2_Zero); - if (ctx.m_kerningEnabled && nextCh) - { - kerningOffset = m_pFontTexture->GetKerning(ch, nextCh) * scaleInfo.scale.x; - } - - // Adjust char width with tracking only if there is a next character - if (nextCh) - { - charX += ctx.m_tracking; - } - - charX += advance + kerningOffset.x; - } - - if (charX > maxW) - { - maxW = charX; - } - } - - return Vec2(maxW, maxH); -} - -uint32 CFFont::GetNumQuadsForText(const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - uint32 numQuads = 0; - - const size_t fxSize = m_effects.size(); - const size_t fxIdx = ctx.m_fxIdx < fxSize ? ctx.m_fxIdx : 0; - const SEffect& fx = m_effects[fxIdx]; - - for (size_t j = 0, numPasses = fx.m_passes.size(); j < numPasses; ++j) - { - size_t i = numPasses - j - 1; - bool drawFrame = ctx.m_framed && i == numPasses - 1; - - if (drawFrame) - { - ++numQuads; - } - - uint32_t nextCh = 0; - Unicode::CIterator pChar(pStr); - while (uint32_t ch = *pChar) - { - ++pChar; - nextCh = *pChar; - - switch (ch) - { - case '\\': - { - if (*pChar != 'n' || !asciiMultiLine) - { - break; - } - ++pChar; - } - case '\n': - { - continue; - } - break; - case '\r': - { - continue; - } - break; - case '\t': - { - continue; - } - break; - case '$': - { - if (ctx.m_processSpecialChars) - { - if (*pChar == '$') - { - ++pChar; - } - else if (isdigit(*pChar)) - { - ++pChar; - continue; - } - else if (*pChar == 'O' || *pChar == 'o') - { - ++pChar; - continue; - } - } - } - break; - default: - break; - } - - ++numQuads; - } - } - - return numQuads; -} - -uint32 CFFont::WriteTextQuadsToBuffers(SVF_P2F_C4B_T2F_F4B* verts, uint16* indices, uint32 maxQuads, float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx) -{ - AZStd::lock_guard locker(m_fontMutex); - - uint32 numQuadsWritten = 0; - - const size_t fxSize = m_effects.size(); - IF (fxSize && m_texID == -1 && !InitTexture(), 0) - { - return numQuadsWritten; - } - - // if the font is about to be deleted then m_pCryFont can be nullptr - if (!m_pCryFont) - { - return numQuadsWritten; - } - - SVF_P2F_C4B_T2F_F4B* pVertex = verts; - uint16* pIndex = indices; - size_t vbOffset = 0; - size_t ibOffset = 0; - - // Local function that is passed into CreateQuadsForText as the AddQuad function - AddFunction AddQuad = [&pVertex, &pIndex, &vbOffset, &ibOffset, maxQuads, &numQuadsWritten] - (const Vec3& v0, const Vec3& v1, const Vec3& v2, const Vec3& v3, const Vec2& tc0, const Vec2& tc1, const Vec2& tc2, const Vec2& tc3, uint32 packedColor) - { - Vec2 xy0(v0); - Vec2 xy1(v1); - Vec2 xy2(v2); - Vec2 xy3(v3); - - AZ_Assert(vbOffset + 3 < maxQuads * 4, "Vertex buffer overflow"); - AZ_Assert(ibOffset + 5 < maxQuads * 6, "Index buffer overflow"); - - // This should never happen but for safety make sure we never write off end of buffers (should hit asserts above if this is the case) - if (numQuadsWritten < maxQuads) - { - // define char quad - pVertex[vbOffset].xy = xy0; - pVertex[vbOffset].color.dcolor = packedColor; - pVertex[vbOffset].st = tc0; - pVertex[vbOffset].texIndex = 0; - pVertex[vbOffset].texHasColorChannel = 0; - pVertex[vbOffset].texIndex2 = 0; - pVertex[vbOffset].pad = 0; - - pVertex[vbOffset + 1].xy = xy1; - pVertex[vbOffset + 1].color.dcolor = packedColor; - pVertex[vbOffset + 1].st = tc1; - pVertex[vbOffset + 1].texIndex = 0; - pVertex[vbOffset + 1].texHasColorChannel = 0; - pVertex[vbOffset + 1].texIndex2 = 0; - pVertex[vbOffset + 1].pad = 0; - - pVertex[vbOffset + 2].xy = xy2; - pVertex[vbOffset + 2].color.dcolor = packedColor; - pVertex[vbOffset + 2].st = tc2; - pVertex[vbOffset + 2].texIndex = 0; - pVertex[vbOffset + 2].texHasColorChannel = 0; - pVertex[vbOffset + 2].texIndex2 = 0; - pVertex[vbOffset + 2].pad = 0; - - pVertex[vbOffset + 3].xy = xy3; - pVertex[vbOffset + 3].color.dcolor = packedColor; - pVertex[vbOffset + 3].st = tc3; - pVertex[vbOffset + 3].texIndex = 0; - pVertex[vbOffset + 3].texHasColorChannel = 0; - pVertex[vbOffset + 3].texIndex2 = 0; - pVertex[vbOffset + 3].pad = 0; - - pIndex[ibOffset] = vbOffset; - pIndex[ibOffset + 1] = vbOffset + 1; - pIndex[ibOffset + 2] = vbOffset + 2; - pIndex[ibOffset + 3] = vbOffset + 2; - pIndex[ibOffset + 4] = vbOffset + 3; - pIndex[ibOffset + 5] = vbOffset + 0; - - vbOffset += 4; - ibOffset += 6; - - ++numQuadsWritten; - } - }; - - // Local function that is passed into CreateQuadsForText as the BeginPass function - BeginPassFunction BeginPass = [] - (const SRenderingPass* /* pPass */) - { - }; - - - CreateQuadsForText(x, y, z, pStr, asciiMultiLine, ctx, AddQuad, BeginPass); - - return numQuadsWritten; -} - -int CFFont::GetFontTextureId() -{ - if (m_texID == -1 && !InitTexture()) - { - return -1; - } - - return m_texID; -} - -uint32 CFFont::GetFontTextureVersion() -{ - return m_textureVersion; -} - -void CFFont::CreateQuadsForText(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx, - AddFunction AddQuad, BeginPassFunction BeginPass) -{ - const size_t fxSize = m_effects.size(); - - Prepare(pStr, true, ctx.m_requestSize); - - const size_t fxIdx = ctx.m_fxIdx < fxSize ? ctx.m_fxIdx : 0; - const SEffect& fx = m_effects[fxIdx]; - - bool isRGB = m_pCryFont->RndPropIsRGBA(); - - float halfTexelShift = m_pCryFont->RndPropHalfTexelOffset(); - - bool passZeroColorOverridden = ctx.IsColorOverridden(); - - uint32 alphaBlend = passZeroColorOverridden ? ctx.m_colorOverride.a : fx.m_passes[0].m_color.a; - if (alphaBlend > 128) - { - ++alphaBlend; // 0..256 for proper blending - } - IRenderer* pRenderer = gEnv->pRenderer; - AZ_Assert(pRenderer, "gEnv->pRenderer is NULL"); - - // This is the "logical" size of the font (in pixels). The actual size of - // the glyphs in the font texture may have additional scaling applied or - // could have been re-rendered at a different size. - Vec2 size = ctx.m_size; - if (ctx.m_sizeIn800x600) - { - pRenderer->ScaleCoord(size.x, size.y); - } - - // This scaling takes into account the logical size of the font relative - // to any additional scaling applied (such as from "size ratio"). - const TextScaleInfoInternal scaleInfo(CalculateScaleInternal(ctx)); - - Vec2 baseXY = Vec2(x, y); // in pixels - if (ctx.m_sizeIn800x600) - { - pRenderer->ScaleCoord(baseXY.x, baseXY.y); - } - - // Apply overscan border - const int flags = ctx.GetFlags(); - if ((flags & eDrawText_2D) && !(flags & eDrawText_IgnoreOverscan)) - { - Vec2 overscanBorder = Vec2(0.0f, 0.0f); - pRenderer->EF_Query(EFQ_OverscanBorders, overscanBorder); - - const float screenWidth = (float)pRenderer->GetOverlayWidth(); - const float screenHeight = (float)pRenderer->GetOverlayHeight(); - Vec2 overscanBorderOffset = ZERO; - if (!(flags & eDrawText_Center)) - { - overscanBorderOffset.x = (overscanBorder.x * screenWidth); - } - if (!(flags & eDrawText_CenterV)) - { - overscanBorderOffset.y = (overscanBorder.y * screenHeight); - } - if (flags & eDrawText_Right) - { - overscanBorderOffset.x = -overscanBorderOffset.x; - } - if (flags & eDrawText_Bottom) - { - overscanBorderOffset.y = -overscanBorderOffset.y; - } - baseXY += overscanBorderOffset; - } - - // snap for pixel perfect rendering (better quality for text) - if (ctx.m_pixelAligned) - { - baseXY.x = floor(baseXY.x); - baseXY.y = floor(baseXY.y); - - // for smaller fonts (half res or less) it's better to average multiple pixels (we don't miss lines) - if (scaleInfo.scale.x < 0.9f) - { - baseXY.x += 0.5f; // try to average two columns (for exact half res) - } - if (scaleInfo.scale.y < 0.9f) - { - baseXY.y += 0.25f; // hand tweaked value to get a good result with tiny font (640x480 underscore in console) - } - } - - for (size_t j = 0, numPasses = fx.m_passes.size(); j < numPasses; ++j) - { - size_t i = numPasses - j - 1; - - const SRenderingPass* pPass = &fx.m_passes[i]; - - if (!i) - { - alphaBlend = 256; - } - - ColorB passColor = !i && passZeroColorOverridden ? ctx.m_colorOverride : fx.m_passes[i].m_color; - - // gather pass data - Vec2 offset = pPass->m_posOffset; // in pixels - - float charX = baseXY.x + offset.x; // in pixels - float charY = baseXY.y + offset.y; // in pixels - - ColorB color = passColor; - - bool drawFrame = ctx.m_framed && i == numPasses - 1; - - BeginPass(pPass); - - if (drawFrame) - { - ColorB tempColor(255, 255, 255, 255); - uint32 frameColor = tempColor.pack_abgr8888(); - if (!isRGB) - { - frameColor = COLCONV(frameColor); - } - - Vec2 textSize = GetTextSizeUInternal(pStr, asciiMultiLine, ctx); - - float x0 = baseXY.x - 12; - float y0 = baseXY.y - 6; - float x1 = baseXY.x + textSize.x + 12; - float y1 = baseXY.y + textSize.y + 6; - - bool culled = false; - IF (ctx.m_clippingEnabled, 0) - { - float clipX = ctx.m_clipX; - float clipY = ctx.m_clipY; - float clipR = ctx.m_clipX + ctx.m_clipWidth; - float clipB = ctx.m_clipY + ctx.m_clipHeight; - - if ((x0 >= clipR) || (y0 >= clipB) || (x1 < clipX) || (y1 < clipY)) - { - culled = true; - } - - x0 = max(clipX, x0); - y0 = max(clipY, y0); - x1 = min(clipR, x1); - y1 = min(clipB, y1); - - //if (!culled && ((x1 - x0 <= 0.0f) || (y1 - y0 <= 0.0f))) - // culled = true; - } - - IF (!culled, 1) - { - Vec3 v0(x0, y0, z); - Vec3 v2(x1, y1, z); - Vec3 v1(v2.x, v0.y, v0.z); // to avoid float->half conversion - Vec3 v3(v0.x, v2.y, v0.z); // to avoid float->half conversion - - if (ctx.m_drawTextFlags & eDrawText_UseTransform) - { - v0 = ctx.m_transform * v0; - v2 = ctx.m_transform * v2; - v1 = ctx.m_transform * v1; - v3 = ctx.m_transform * v3; - } - - Vec2 gradientUvMin, gradientUvMax; - GetGradientTextureCoord(gradientUvMin.x, gradientUvMin.y, gradientUvMax.x, gradientUvMax.y); - - // define the frame quad - Vec2 uv(gradientUvMin.x, gradientUvMax.y); - AddQuad(v0, v1, v2, v3, uv, uv, uv, uv, frameColor); - } - } - - // parse the string, ignoring control characters - uint32_t nextCh = 0; - Unicode::CIterator pChar(pStr); - while (uint32_t ch = *pChar) - { - ++pChar; - nextCh = *pChar; - - switch (ch) - { - case '\\': - { - if (*pChar != 'n' || !asciiMultiLine) - { - break; - } - ++pChar; - } - case '\n': - { - charX = baseXY.x + offset.x; - charY += size.y; - continue; - } - break; - case '\r': - { - charX = baseXY.x + offset.x; - continue; - } - break; - case '\t': - { - if (ctx.m_proportional) - { - charX += TabCharCount * size.x * FONT_SPACE_SIZE; - } - else - { - charX += TabCharCount * size.x * ctx.m_widthScale; - } - continue; - } - break; - case '$': - { - if (ctx.m_processSpecialChars) - { - if (*pChar == '$') - { - ++pChar; - } - else if (isdigit(*pChar)) - { - if (!i) - { - int colorIndex = (*pChar) - '0'; - ColorB newColor = ColorTable[colorIndex]; - color.r = newColor.r; - color.g = newColor.g; - color.b = newColor.b; - // Leave alpha at original value! - } - ++pChar; - continue; - } - else if (*pChar == 'O' || *pChar == 'o') - { - if (!i) - { - color = passColor; - } - ++pChar; - continue; - } - } - } - break; - default: - break; - } - - // get texture coordinates - float texCoord[4]; - - int charOffsetX, charOffsetY; // in font texels - int charSizeX, charSizeY; // in font texels - const bool rerenderGlyphs = m_sizeBehavior == SizeBehavior::Rerender; - const Vec2i requestSize = rerenderGlyphs ? ctx.m_requestSize : CCryFont::defaultGlyphSize; - m_pFontTexture->GetTextureCoord(m_pFontTexture->GetCharSlot(ch, requestSize), texCoord, charSizeX, charSizeY, charOffsetX, charOffsetY, requestSize); - - int horizontalAdvance = m_pFontTexture->GetHorizontalAdvance(ch, requestSize); - float advance; - - if (ctx.m_proportional) - { - advance = horizontalAdvance * scaleInfo.scale.x; - } - else - { - advance = size.x * ctx.m_widthScale; - } - - Vec2 kerningOffset(Vec2_Zero); - if (ctx.m_kerningEnabled && nextCh) - { - kerningOffset = m_pFontTexture->GetKerning(ch, nextCh) * scaleInfo.scale.x; - } - - float trackingOffset = 0.0f; - if (nextCh) - { - trackingOffset = ctx.m_tracking; - } - - float px = charX + charOffsetX * scaleInfo.scale.x; // in pixels - float py = charY + charOffsetY * scaleInfo.scale.y; // in pixels - float pr = px + charSizeX * scaleInfo.scale.x; - float pb = py + charSizeY * scaleInfo.scale.y; - - // compute clipping - float newX = px; // in pixels - float newY = py; // in pixels - float newR = pr; // in pixels - float newB = pb; // in pixels - - if (ctx.m_clippingEnabled) - { - float clipX = ctx.m_clipX; - float clipY = ctx.m_clipY; - float clipR = ctx.m_clipX + ctx.m_clipWidth; - float clipB = ctx.m_clipY + ctx.m_clipHeight; - - // clip non visible - if ((px >= clipR) || (py >= clipB) || (pr < clipX) || (pb < clipY)) - { - charX += advance + kerningOffset.x + trackingOffset; - continue; - } - // clip partially visible - else - { - float width = horizontalAdvance * scaleInfo.rcpCellWidth; - if ((width <= 0.0f) || (size.y <= 0.0f)) - { - charX += advance + kerningOffset.x + trackingOffset; - continue; - } - - // clip the image to the scissor rect - newX = max(clipX, px); - newY = max(clipY, py); - newR = min(clipR, pr); - newB = min(clipB, pb); - - float rcpWidth = 1.0f / width; - float rcpHeight = 1.0f / size.y; - - float texW = texCoord[2] - texCoord[0]; - float texH = texCoord[3] - texCoord[1]; - - // clip horizontal - texCoord[0] = texCoord[0] + texW * (newX - px) * rcpWidth; - texCoord[2] = texCoord[2] + texW * (newR - pr) * rcpWidth; - - // clip vertical - texCoord[1] = texCoord[1] + texH * (newY - py) * rcpHeight; - texCoord[3] = texCoord[3] + texH * (newB - pb) * rcpHeight; - } - } - - newX += halfTexelShift; - newY += halfTexelShift; - newR += halfTexelShift; - newB += halfTexelShift; - - //int offset = vbLen * 6; - - Vec3 v0(newX, newY, z); - Vec3 v2(newR, newB, z); - Vec3 v1(v2.x, v0.y, v0.z); // to avoid float->half conversion - Vec3 v3(v0.x, v2.y, v0.z); // to avoid float->half conversion - - Vec2 tc0(texCoord[0], texCoord[1]); - Vec2 tc2(texCoord[2], texCoord[3]); - Vec2 tc1(tc2.x, tc0.y); // to avoid float->half conversion - Vec2 tc3(tc0.x, tc2.y); // to avoid float->half conversion - - uint32 packedColor = 0; - { - ColorB tempColor = color; - tempColor.a = ((uint32) tempColor.a * alphaBlend) >> 8; - packedColor = tempColor.pack_abgr8888(); - - if (!isRGB) - { - packedColor = COLCONV(packedColor); - } - } - - if (ctx.m_drawTextFlags & eDrawText_UseTransform) - { - v0 = ctx.m_transform * v0; - v2 = ctx.m_transform * v2; - v1 = ctx.m_transform * v1; - v3 = ctx.m_transform * v3; - } - - AddQuad(v0, v1, v2, v3, tc0, tc1, tc2, tc3, packedColor); - - charX += advance + kerningOffset.x + trackingOffset; - } - } -} - -CFFont::TextScaleInfoInternal CFFont::CalculateScaleInternal(const STextDrawContext& ctx) const -{ - Vec2 size = GetRestoredFontSize(ctx); // in pixel - - IRenderer* pRenderer = gEnv->pRenderer; - AZ_Assert(pRenderer, "gEnv->pRenderer is NULL"); - - if (ctx.m_sizeIn800x600) - { - pRenderer->ScaleCoord(size.x, size.y); - } - - float rcpCellWidth; - Vec2 scale; - - int fontTextureCellWidth = GetFontTexture()->GetCellWidth(); - int fontTextureCellHeight = GetFontTexture()->GetCellHeight(); - - if (ctx.m_proportional) - { - rcpCellWidth = (1.0f / static_cast(fontTextureCellWidth)) * size.x; - scale = Vec2(rcpCellWidth * ctx.m_widthScale, size.y / static_cast(fontTextureCellHeight)); - } - else - { - rcpCellWidth = size.x / 16.0f; - scale = Vec2(rcpCellWidth * ctx.m_widthScale, size.y * ctx.m_widthScale / 16.0f); - } - - return TextScaleInfoInternal(scale, rcpCellWidth); -} - -size_t CFFont::GetTextLength(const char* pStr, const bool asciiMultiLine) const -{ - size_t len = 0; - - // parse the string, ignoring control characters - const char* pChar = pStr; - while (char ch = *pChar++) - { - if ((ch & 0xC0) == 0x80) - { - continue; // Skip UTF-8 continuation bytes, we count only the first byte of a code-point - } - switch (ch) - { - case '\\': - { - if (*pChar != 'n' || !asciiMultiLine) - { - break; - } - ++pChar; - } - case '\n': - case '\r': - case '\t': - { - continue; - } - break; - case '$': - { - if (*pChar == '$') - { - ++pChar; - } - else if (*pChar) - { - ++pChar; - continue; - } - } - break; - default: - break; - } - ++len; - } - - return len; -} - -void CFFont::WrapText(string& result, float maxWidth, const char* pStr, const STextDrawContext& ctx) -{ - result = pStr; - - if (ctx.m_sizeIn800x600) - { - maxWidth = gEnv->pRenderer->ScaleCoordX(maxWidth); - } - - Vec2 strSize = GetTextSizeUInternal(result.c_str(), true, ctx); - - if (strSize.x <= maxWidth) - { - return; - } - - // Assume a given string has multiple lines of text if it's height is - // greater than the height of its font. - const bool multiLine = strSize.y > GetRestoredFontSize(ctx).y; - - int lastSpace = -1; - const char* pLastSpace = NULL; - float lastSpaceWidth = 0.0f; - - float curCharWidth = 0.0f; - float curLineWidth = 0.0f; - float biggestLineWidth = 0.0f; - float widthSum = 0.0f; - - int curChar = 0; - Unicode::CIterator pChar(result.c_str()); - while (uint32_t ch = *pChar) - { - // Dollar sign escape codes. The following scenarios can happen with dollar signs embedded in a string. - // The following character is... - // 1. ... a digit, 'O' or 'o' which indicates a color code. Both characters a skipped in the width calculation. - // 2. ... another dollar sign. Only 1 dollar sign is skipped in the width calculation. - // 3. ... anything else. The dollar sign is processed in the width calculation. - if (ctx.m_processSpecialChars && ch == '$') - { - ++pChar; - char nextChar = *pChar; - - if (isdigit(nextChar) || nextChar == 'O' || nextChar == 'o') - { - ++pChar; - continue; - } - else if (nextChar != '$') - { - --pChar; - } - } - - // get char width and sum it to the line width - // Note: This is not unicode compatible, since char-width depends on surrounding context (ie, combining diacritics etc) - char codepoint[5]; - Unicode::Convert(codepoint, ch); - curCharWidth = GetTextSizeUInternal(codepoint, true, ctx).x; - - // keep track of spaces - // they are good for splitting the string - if (ch == ' ') - { - lastSpace = curChar; - lastSpaceWidth = curLineWidth + curCharWidth; - pLastSpace = pChar.GetPosition(); - assert(*pLastSpace == ' '); - } - - bool prevCharWasNewline = false; - const bool notFirstChar = pChar.GetPosition() != result.c_str(); - if (*pChar && notFirstChar) - { - const char* pPrevCharStr = pChar.GetPosition() - 1; - prevCharWasNewline = pPrevCharStr[0] == '\n'; - } - - // if line exceed allowed width, split it - if (prevCharWasNewline || (curLineWidth + curCharWidth >= maxWidth && (*pChar))) - { - if (prevCharWasNewline) - { - // Reset the current line width to account for newline - curLineWidth = curCharWidth; - widthSum += curLineWidth; - } - else if ((lastSpace > 0) && ((curChar - lastSpace) < 16) && (curChar - lastSpace >= 0)) // 16 is the default threshold - { - *(char*)pLastSpace = '\n'; // This is safe inside UTF-8 because space is single-byte codepoint - - if (lastSpaceWidth > biggestLineWidth) - { - biggestLineWidth = lastSpaceWidth; - } - - curLineWidth = curLineWidth - lastSpaceWidth + curCharWidth; - widthSum += curLineWidth; - } - else - { - const char* pBuf = pChar.GetPosition(); - size_t bytesProcessed = pBuf - result.c_str(); - result.insert(bytesProcessed, '\n'); // Insert the newline, this invalidates the iterator - pBuf = result.c_str() + bytesProcessed; // In case reallocation occurs, we ensure we are inside the new buffer - assert(*pBuf == '\n'); - pChar.SetPosition(pBuf); // pChar once again points inside the target string, at the current character - assert(*pChar == ch); - ++pChar; - ++curChar; - - if (curLineWidth > biggestLineWidth) - { - biggestLineWidth = curLineWidth; - } - - widthSum += curLineWidth; - curLineWidth = curCharWidth; - } - - // if we don't need any more line breaks, then just stop, but for - // multiple lines we can't assume that there aren't any more - // strings to wrap, so continue - if (strSize.x - widthSum <= maxWidth && !multiLine) - { - break; - } - - lastSpaceWidth = 0; - lastSpace = 0; - } - else - { - curLineWidth += curCharWidth; - } - - ++curChar; - ++pChar; - } -} - -void CFFont::GetMemoryUsage (ICrySizer* pSizer) const -{ - pSizer->AddObject(m_name); - pSizer->AddObject(m_curPath); - pSizer->AddObject(m_pFontTexture); - pSizer->AddObject(m_pFontBuffer, m_fontBufferSize); - pSizer->AddObject(m_effects); - pSizer->AddObject(m_pDrawVB, sizeof(SVF_P3F_C4B_T2F) * MaxDrawVBQuads * 6); -} - -void CFFont::GetGradientTextureCoord(float& minU, float& minV, float& maxU, float& maxV) const -{ - const CTextureSlot* pSlot = m_pFontTexture->GetGradientSlot(); - assert(pSlot); - - float invWidth = 1.0f / (float) m_pFontTexture->GetWidth(); - float invHeight = 1.0f / (float) m_pFontTexture->GetHeight(); - - // deflate by one pixel to avoid bilinear filtering on the borders - minU = pSlot->vTexCoord[0] + invWidth; - minV = pSlot->vTexCoord[1] + invHeight; - maxU = pSlot->vTexCoord[0] + (pSlot->iCharWidth - 1) * invWidth; - maxV = pSlot->vTexCoord[1] + (pSlot->iCharHeight - 1) * invHeight; -} - -unsigned int CFFont::GetEffectId(const char* pEffectName) const -{ - if (pEffectName) - { - for (size_t i = 0, numEffects = m_effects.size(); i < numEffects; ++i) - { - if (!strcmp(m_effects[i].m_name.c_str(), pEffectName)) - { - return i; - } - } - } - - return 0; -} - -unsigned int CFFont::GetNumEffects() const -{ - return m_effects.size(); -} - -const char* CFFont::GetEffectName(unsigned int effectId) const -{ - return (effectId < m_effects.size()) ? m_effects[effectId].m_name.c_str() : nullptr; -} - -Vec2 CFFont::GetMaxEffectOffset(unsigned int effectId) const -{ - Vec2 maxOffset(0.0f, 0.0f); - - if (effectId < m_effects.size()) - { - const SEffect& fx = m_effects[effectId]; - - for (size_t i = 0, numPasses = fx.m_passes.size(); i < numPasses; ++i) - { - const SRenderingPass* pPass = &fx.m_passes[numPasses - i - 1]; - - // gather pass data - Vec2 offset = pPass->m_posOffset; - - if (maxOffset.x < offset.x) - { - maxOffset.x = offset.x; - } - - if (maxOffset.y < offset.y) - { - maxOffset.y = offset.y; - } - } - } - - return maxOffset; -} - -bool CFFont::DoesEffectHaveTransparency(unsigned int effectId) const -{ - const size_t fxSize = m_effects.size(); - const size_t fxIdx = effectId < fxSize ? effectId : 0; - const SEffect& fx = m_effects[fxIdx]; - - for (auto& pass : fx.m_passes) - { - // if the alpha is not 255 then there is transparency - if (pass.m_color.a != 255) - { - return true; - } - } - - return false; -} - -void CFFont::AddCharsToFontTexture(const char* pChars, int glyphSizeX, int glyphSizeY) -{ - AZStd::lock_guard locker(m_fontMutex); - Vec2i glyphSize(glyphSizeX, glyphSizeY); - Prepare(pChars, false, glyphSize); -} - -Vec2 CFFont::GetKerning(uint32_t leftGlyph, uint32_t rightGlyph, const STextDrawContext& ctx) const -{ - const TextScaleInfoInternal scaleInfo(CalculateScaleInternal(ctx)); - return m_pFontTexture->GetKerning(leftGlyph, rightGlyph) * scaleInfo.scale.x; -} - -float CFFont::GetAscender(const STextDrawContext& ctx) const -{ - return (ctx.m_size.y * m_pFontTexture->GetAscenderToHeightRatio()); -} - -float CFFont::GetBaseline(const STextDrawContext& ctx) const -{ - const TextScaleInfoInternal scaleInfo(CalculateScaleInternal(ctx)); - // Calculate baseline the same way as the font renderer which uses the glyph height * size ratio. - // Adding 1 because FontTexture always adds 1 to the char height in GetTextureCoord - return (round(m_pFontTexture->GetCellHeight() * GetSizeRatio()) + 1.0f) * scaleInfo.scale.y; -} - -bool CFFont::InitTexture() -{ - m_texID = gEnv->pRenderer->FontCreateTexture(m_pFontTexture->GetWidth(), m_pFontTexture->GetHeight(), (uint8*)m_pFontTexture->GetBuffer(), eTF_A8, IRenderer::FontCreateTextureGenMipsDefaultValue, m_name.c_str()); - m_textureVersion = 0; - return m_texID >= 0; -} - -bool CFFont::InitCache() -{ - m_pFontTexture->CreateGradientSlot(); - - // precache (not required but for faster printout later) - const char first = ' '; - const char last = '~'; - char buf[last - first + 2]; - char* p = buf; - - // precache all [normal] printable characters to the string (missing ones are updated on demand) - for (int i = first; i <= last; ++i) - { - *p++ = i; - } - *p = 0; - - Prepare(buf, false); - - return true; -} - -CFFont::SEffect* CFFont::AddEffect(const char* pEffectName) -{ - m_effects.push_back(SEffect(pEffectName)); - return &m_effects[m_effects.size() - 1]; -} - -CFFont::SEffect* CFFont::GetDefaultEffect() -{ - return &m_effects[0]; -} - -void CFFont::Prepare(const char* pStr, bool updateTexture, const Vec2i& glyphSize) -{ - const bool rerenderGlyphs = m_sizeBehavior == SizeBehavior::Rerender; - const Vec2i usedGlyphSize = rerenderGlyphs ? glyphSize : CCryFont::defaultGlyphSize; - bool texUpdateNeeded = m_pFontTexture->PreCacheString(pStr, nullptr, m_sizeRatio, usedGlyphSize, m_fontHintParams) == 1 || m_fontTexDirty; - if (updateTexture && texUpdateNeeded && m_texID >= 0) - { - gEnv->pRenderer->FontUpdateTexture(m_texID, 0, 0, m_pFontTexture->GetWidth(), m_pFontTexture->GetHeight(), (unsigned char*)m_pFontTexture->GetBuffer()); - m_fontTexDirty = false; - ++m_textureVersion; - - // Let any listeners know that the font texture has changed - EBUS_EVENT(FontNotificationBus, OnFontTextureUpdated, this); - } - else - { - m_fontTexDirty = texUpdateNeeded; - } -} - -Vec2 CFFont::GetRestoredFontSize(const STextDrawContext& ctx) const -{ - // Calculate the scale that we need to apply to the text size to ensure - // it's on-screen size is the same regardless of the slot scaling needed - // to fit the glyphs of the font within the font texture slots. - float restoringScale = IFFontConstants::defaultSizeRatio / m_sizeRatio; - return Vec2(ctx.m_size.x * restoringScale, ctx.m_size.y * restoringScale); -} - -#endif - diff --git a/Code/CryEngine/CryFont/FFont.h b/Code/CryEngine/CryFont/FFont.h deleted file mode 100644 index c2eddd7b1d..0000000000 --- a/Code/CryEngine/CryFont/FFont.h +++ /dev/null @@ -1,234 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Font class. - - -#ifndef CRYINCLUDE_CRYFONT_FFONT_H -#define CRYINCLUDE_CRYFONT_FFONT_H -#pragma once - - -#if !defined(USE_NULLFONT_ALWAYS) - -#include -#include -#include -#include -#include "CryFont.h" - -#include - -struct ISystem; -class CFontTexture; - - -class CFFont - : public IFFont - , public IFFont_RenderProxy -{ -public: - //! Determines how characters of different sizes should be handled during render. - enum class SizeBehavior - { - Scale, //!< Default behavior; glyphs rendered at different sizes are rendered on scaled geometry - Rerender //!< Similar to Scale, but the glyph in the font texture is re-rendered to match the target - //!< size, as long as the size isn't greater than the maximum glyph/slot resolution as - //!< configured for the font texture in the font XML. - }; - - //! The hinting visual algorithm to be used (when hinting is enabled) - enum class HintStyle - { - Normal, //!< Default hinting behavior provided by font renderer - Light //!< Produces fuzzier glyphs but more accurately tracks glyph shape - }; - - //! Chooses whether hinting info should be obtained from the font, turned off entirely, or automatically generated - enum class HintBehavior - { - Default, //!< Obtain hinting data from font itself - AutoHint, //!< Procedurally derive hinting information from glyph - NoHinting, //!< Disable hinting entirely - }; - - //! Simple struct used to communicate font hinting parameters to font renderer. - struct FontHintParams - { - FontHintParams() : hintStyle(HintStyle::Normal), hintBehavior(HintBehavior::Default) { } - - HintStyle hintStyle; - HintBehavior hintBehavior; - }; - - struct SRenderingPass - { - ColorB m_color; - Vec2 m_posOffset; - int m_blendSrc; - int m_blendDest; - - SRenderingPass() - : m_color(255, 255, 255, 255) - , m_posOffset(0, 0) - , m_blendSrc(GS_BLSRC_SRCALPHA) - , m_blendDest(GS_BLDST_ONEMINUSSRCALPHA) - { - } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} - }; - - struct SEffect - { - string m_name; - std::vector m_passes; - - SEffect(const char* name) - : m_name(name) - { - assert(name); - } - - SRenderingPass* AddPass() - { - m_passes.push_back(SRenderingPass()); - return &m_passes[m_passes.size() - 1]; - } - - void ClearPasses() - { - m_passes.resize(0); - } - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(m_name); - pSizer->AddObject(m_passes); - } - }; - - typedef std::vector Effects; - typedef Effects::iterator EffectsIt; - -public: - virtual int32 AddRef() override; - virtual int32 Release() override; - virtual bool Load(const char* pFontFilePath, unsigned int width, unsigned int height, unsigned int widthNumSlots, unsigned int heightNumSlots, unsigned int flags, float sizeRatio); - virtual bool Load(const char* pXMLFile); - virtual void Free(); - virtual void DrawString(float x, float y, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - virtual void DrawString(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - virtual Vec2 GetTextSize(const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - virtual size_t GetTextLength(const char* pStr, const bool asciiMultiLine) const; - virtual void WrapText(string& result, float maxWidth, const char* pStr, const STextDrawContext& ctx); - virtual void GetMemoryUsage(ICrySizer* pSizer) const; - virtual void GetGradientTextureCoord(float& minU, float& minV, float& maxU, float& maxV) const; - virtual unsigned int GetEffectId(const char* pEffectName) const; - virtual unsigned int GetNumEffects() const; - virtual const char* GetEffectName(unsigned int effectId) const; - virtual Vec2 GetMaxEffectOffset(unsigned int effectId) const; - virtual bool DoesEffectHaveTransparency(unsigned int effectId) const; - virtual void AddCharsToFontTexture(const char* pChars, int glyphSizeX = ICryFont::defaultGlyphSizeX, int glyphSizeY = ICryFont::defaultGlyphSizeY) override; - virtual Vec2 GetKerning(uint32_t leftGlyph, uint32_t rightGlyph, const STextDrawContext& ctx) const override; - virtual float GetAscender(const STextDrawContext& ctx) const override; - virtual float GetBaseline(const STextDrawContext& ctx) const override; - - virtual uint32 GetNumQuadsForText(const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - virtual uint32 WriteTextQuadsToBuffers(SVF_P2F_C4B_T2F_F4B* verts, uint16* indices, uint32 maxQuads, float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - virtual int GetFontTextureId(); - virtual uint32 GetFontTextureVersion(); - - virtual float GetSizeRatio() const override { return m_sizeRatio; } - -public: - virtual void RenderCallback(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - -public: - CFFont(ISystem* pSystem, CCryFont* pCryFont, const char* pFontName); - - bool InitTexture(); - bool InitCache(); - - CFontTexture* GetFontTexture() const { return m_pFontTexture; } - const string& GetName() const { return m_name; } - - SEffect* AddEffect(const char* pEffectName); - SEffect* GetDefaultEffect(); - -private: - virtual ~CFFont(); - - void Prepare(const char* pStr, bool updateTexture, const Vec2i& glyphSize = CCryFont::defaultGlyphSize); - void DrawStringUInternal(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - Vec2 GetTextSizeUInternal(const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx); - - using AddFunction = AZStd::function; - using BeginPassFunction = AZStd::function; - - //! This function is used by both RenderCallback and WriteTextQuadsToBuffers - //! To do this is takes two function pointers that implement the appropriate AddQuad and BeginPass behavior - void CreateQuadsForText(float x, float y, float z, const char* pStr, const bool asciiMultiLine, const STextDrawContext& ctx, - AddFunction AddQuad, BeginPassFunction BeginPass); - - struct TextScaleInfoInternal - { - TextScaleInfoInternal(const Vec2& _scale, float _rcpCellWidth) - : scale(_scale), rcpCellWidth(_rcpCellWidth) { } - - Vec2 scale; - float rcpCellWidth; - }; - - TextScaleInfoInternal CalculateScaleInternal(const STextDrawContext& ctx) const; - - Vec2 GetRestoredFontSize(const STextDrawContext& ctx) const; - -private: - string m_name; - string m_curPath; - - CFontTexture* m_pFontTexture; - - size_t m_fontBufferSize; - unsigned char* m_pFontBuffer; - - int m_texID; - uint32 m_textureVersion; - - ISystem* m_pSystem; - - AZStd::recursive_mutex m_fontMutex; //!< Controls access between main and render threads. It's common for one thread - //!< to add un-cached glyphs to the font texture while another is accessing the - //!< font texture. - - CCryFont* m_pCryFont; - - bool m_fontTexDirty; - - Effects m_effects; - - SVF_P3F_C4B_T2F* m_pDrawVB; - - volatile int32 m_nRefCount; - - bool m_monospacedFont; //!< True if this font is fixed/monospaced, false otherwise (obtained from FreeType) - - float m_sizeRatio = IFFontConstants::defaultSizeRatio; - SizeBehavior m_sizeBehavior = SizeBehavior::Scale; //!< Changes how glyphs rendered at different sizes are rendered. - FontHintParams m_fontHintParams; //!< How the font should be hinted when its loaded and rendered to the font texture -}; - -#endif - -#endif // CRYINCLUDE_CRYFONT_FFONT_H diff --git a/Code/CryEngine/CryFont/FFontXML.cpp b/Code/CryEngine/CryFont/FFontXML.cpp deleted file mode 100644 index 1fdd84994e..0000000000 --- a/Code/CryEngine/CryFont/FFontXML.cpp +++ /dev/null @@ -1,448 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : XML parsing to load a font. - - -#include "CryFont_precompiled.h" - -#if !defined(USE_NULLFONT_ALWAYS) - -#include "FFont.h" -#include "FontTexture.h" -#include -#include - -#if defined(WIN32) || defined(WIN64) -# include -# include -#endif - -////////////////////////////////////////////////////////////////////////// -// Xml parser implementation - -enum -{ - - ELEMENT_UNKNOWN = 0, - ELEMENT_FONT = 1, - ELEMENT_EFFECT = 2, - ELEMENT_EFFECTFILE = 3, - ELEMENT_PASS = 4, - ELEMENT_PASS_COLOR = 5, - ELEMENT_PASS_POSOFFSET = 12, - ELEMENT_PASS_BLEND = 14 -}; - -static inline int GetBlendModeFromString(const string& str, bool dst) -{ - int blend = GS_BLSRC_ONE; - - if (str == "zero") - { - blend = dst ? GS_BLDST_ZERO : GS_BLSRC_ZERO; - } - else if (str == "one") - { - blend = dst ? GS_BLDST_ONE : GS_BLSRC_ONE; - } - else if (str == "srcalpha" || - str == "src_alpha") - { - blend = dst ? GS_BLDST_SRCALPHA : GS_BLSRC_SRCALPHA; - } - else if (str == "invsrcalpha" || - str == "inv_src_alpha") - { - blend = dst ? GS_BLDST_ONEMINUSSRCALPHA : GS_BLSRC_ONEMINUSSRCALPHA; - } - else if (str == "dstalpha" || - str == "dst_alpha") - { - blend = dst ? GS_BLDST_DSTALPHA : GS_BLSRC_DSTALPHA; - } - else if (str == "invdstalpha" || - str == "inv_dst_alpha") - { - blend = dst ? GS_BLDST_ONEMINUSDSTALPHA : GS_BLSRC_ONEMINUSDSTALPHA; - } - else if (str == "dstcolor" || - str == "dst_color") - { - blend = GS_BLSRC_DSTCOL; - } - else if (str == "srccolor" || - str == "src_color") - { - blend = GS_BLDST_SRCCOL; - } - else if (str == "invdstcolor" || - str == "inv_dst_color") - { - blend = GS_BLSRC_ONEMINUSDSTCOL; - } - else if (str == "invsrccolor" || - str == "inv_src_color") - { - blend = GS_BLDST_ONEMINUSSRCCOL; - } - - return blend; -} - -class CXmlFontShader -{ -public: - CXmlFontShader(CFFont* pFont) - { - m_pFont = pFont; - m_nElement = ELEMENT_UNKNOWN; - m_pEffect = NULL; - m_pPass = NULL; - m_FontTexSize.set(0, 0); - - static const int defaultSlotWidthSize = 16; - static const int defaultSlotHeightSize = 8; - m_SlotSizes.set(defaultSlotWidthSize, defaultSlotHeightSize); - - m_FontSmoothAmount = 0; - m_FontSmoothMethod = FONT_SMOOTH_NONE; - } - - ~CXmlFontShader() - { - } - - void ScanXmlNodesRecursively(XmlNodeRef node) - { - if (!node) - { - return; - } - - FoundElement(node->getTag()); - - for (int i = 0, count = node->getNumAttributes(); i < count; ++i) - { - const char* key = ""; - const char* value = ""; - if (node->getAttributeByIndex(i, &key, &value)) - { - FoundAttribute(key, value); - } - } - - for (int i = 0, count = node->getChildCount(); i < count; ++i) - { - XmlNodeRef child = node->getChild(i); - ScanXmlNodesRecursively(child); - } - } - -private: - // notify methods - void FoundElement(const string& name) - { - //MessageBox(NULL, string("[" + name + "]").c_str(), "FoundElement", MB_OK); - // process the previous element - switch (m_nElement) - { - case ELEMENT_FONT: - { - if (!m_FontTexSize.x || !m_FontTexSize.y) - { - m_FontTexSize.set(512, 512); - } - - bool fontLoaded = m_pFont->Load(m_strFontPath.c_str(), m_FontTexSize.x, m_FontTexSize.y, m_SlotSizes.x, m_SlotSizes.y, TTFFLAG_CREATE(m_FontSmoothMethod, m_FontSmoothAmount), m_SizeRatio); -#if defined(WIN32) || defined(WIN64) - if (!fontLoaded) - { - TCHAR sysFontPath[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(0, CSIDL_FONTS, 0, SHGFP_TYPE_DEFAULT, sysFontPath))) - { - const char* pFontPath = m_strFontPath.c_str(); - const char* pFontName = CryStringUtils::FindFileNameInPath(pFontPath); - - string newFontPath(sysFontPath); - newFontPath += "/"; - newFontPath += pFontName; - m_pFont->Load(newFontPath, m_FontTexSize.x, m_FontTexSize.y, m_SlotSizes.x, m_SlotSizes.y, TTFFLAG_CREATE(m_FontSmoothMethod, m_FontSmoothAmount), m_SizeRatio); - } - } -#endif - } - break; - - default: - break; - } - - // Translate the m_nElement name to a define - if (name == "font") - { - m_nElement = ELEMENT_FONT; - } - else if (name == "effect") - { - m_nElement = ELEMENT_EFFECT; - } - else if (name == "effectfile") - { - m_nElement = ELEMENT_EFFECTFILE; - } - else if (name == "pass") - { - m_pPass = NULL; - m_nElement = ELEMENT_PASS; - if (m_pEffect) - { - m_pPass = m_pEffect->AddPass(); - } - } - else if (name == "color") - { - m_nElement = ELEMENT_PASS_COLOR; - } - else if (name == "pos" || - name == "offset") - { - m_nElement = ELEMENT_PASS_POSOFFSET; - } - else if (name == "blend" || - name == "blending") - { - m_nElement = ELEMENT_PASS_BLEND; - } - else - { - m_nElement = ELEMENT_UNKNOWN; - } - } - - void FoundAttribute(const string& name, const string& value) - { - //MessageBox(NULL, string(name + "\n" + value).c_str(), "FoundAttribute", MB_OK); - switch (m_nElement) - { - case ELEMENT_FONT: - if (name == "path") - { - m_strFontPath = value; - } - else if (name == "w") - { - m_FontTexSize.x = (long)atof(value.c_str()); - } - else if (name == "h") - { - m_FontTexSize.y = (long)atof(value.c_str()); - } - else if (name == "widthslots") - { - m_SlotSizes.x = (int)atoi(value.c_str()); - } - else if (name == "heightslots") - { - m_SlotSizes.y = (int)atoi(value.c_str()); - } - else if (name == "sizeratio") - { - m_SizeRatio = static_cast(atof(value.c_str())); - } - else if (name == "smooth") - { - if (value == "blur") - { - m_FontSmoothMethod = FONT_SMOOTH_BLUR; - } - else if (value == "supersample") - { - m_FontSmoothMethod = FONT_SMOOTH_SUPERSAMPLE; - } - else if (value == "none") - { - m_FontSmoothMethod = FONT_SMOOTH_NONE; - } - } - else if (name == "smooth_amount") - { - m_FontSmoothAmount = (long)atof(value.c_str()); - } - break; - - case ELEMENT_EFFECT: - if (name == "name") - { - if (value == "default") - { - m_pEffect = m_pFont->GetDefaultEffect(); - m_pEffect->ClearPasses(); - } - else - { - m_pEffect = m_pFont->AddEffect(value.c_str()); - } - } - break; - - case ELEMENT_EFFECTFILE: - if (name == "path") - { - m_strFontEffectPath = value; - } - break; - - case ELEMENT_PASS_COLOR: - if (!m_pPass) - { - break; - } - if (name == "r") - { - m_pPass->m_color.r = (uint8)((float)atof(value.c_str()) * 255.0f); - } - else if (name == "g") - { - m_pPass->m_color.g = (uint8)((float)atof(value.c_str()) * 255.0f); - } - else if (name == "b") - { - m_pPass->m_color.b = (uint8)((float)atof(value.c_str()) * 255.0f); - } - else if (name == "a") - { - m_pPass->m_color.a = (uint8)((float)atof(value.c_str()) * 255.0f); - } - break; - - case ELEMENT_PASS_POSOFFSET: - if (!m_pPass) - { - break; - } - if (name == "x") - { - m_pPass->m_posOffset.x = (float)atoi(value.c_str()); - } - else if (name == "y") - { - m_pPass->m_posOffset.y = (float)atoi(value.c_str()); - } - break; - - case ELEMENT_PASS_BLEND: - if (!m_pPass) - { - break; - } - if (name == "src") - { - m_pPass->m_blendSrc = GetBlendModeFromString(value, false); - } - else if (name == "dst") - { - m_pPass->m_blendDest = GetBlendModeFromString(value, true); - } - else if (name == "type") - { - if (value == "modulate") - { - m_pPass->m_blendSrc = GS_BLSRC_SRCALPHA; - m_pPass->m_blendDest = GS_BLDST_ONEMINUSSRCALPHA; - } - else if (value == "additive") - { - m_pPass->m_blendSrc = GS_BLSRC_SRCALPHA; - m_pPass->m_blendDest = GS_BLDST_ONE; - } - } - break; - - default: - case ELEMENT_UNKNOWN: - break; - } - } - -public: - CFFont* m_pFont; - - unsigned long m_nElement; - - CFFont::SEffect* m_pEffect; - CFFont::SRenderingPass* m_pPass; - - string m_strFontPath; - string m_strFontEffectPath; - vector2l m_FontTexSize; - Vec2i m_SlotSizes; - float m_SizeRatio = IFFontConstants::defaultSizeRatio; - - int m_FontSmoothMethod; - int m_FontSmoothAmount; -}; - -////////////////////////////////////////////////////////////////////////// -// Main loading function -bool CFFont::Load(const char* pXMLFile) -{ - m_curPath = ""; - if (pXMLFile) - { - m_curPath = PathUtil::GetPath(pXMLFile); - } - - XmlNodeRef root = GetISystem()->LoadXmlFromFile(pXMLFile); - if (!root) - { - return false; - } - - CXmlFontShader xmlfs(this); - xmlfs.ScanXmlNodesRecursively(root); - - // if this was not a valid font XML file then return false - if (!m_pFontTexture || !m_pFontBuffer) - { - return false; - } - - // if there was a font effect file then parse that for effects - if (!xmlfs.m_strFontEffectPath.empty()) - { - XmlNodeRef fontEffectRoot = GetISystem()->LoadXmlFromFile(xmlfs.m_strFontEffectPath.c_str()); - if (!fontEffectRoot) - { - AZ_Warning("Font", false, "Error parsing font file %s, 'effectfile' pathname %s could not be found.", - pXMLFile, xmlfs.m_strFontEffectPath.c_str()); - return false; - } - - if (m_effects.size() > 1 || (m_effects.size() == 1 && (m_effects[0].m_name != "default" || m_effects[0].m_passes.size() > 1))) - { - AZ_Warning("Font", false, "Error parsing font file %s, 'effectfile' and 'effect' cannot both be used in the same font file.", - pXMLFile); - m_effects.clear(); - } - - // parse the font effects file, adding to this font object - CXmlFontShader xmlfsEffect(this); - xmlfsEffect.ScanXmlNodesRecursively(fontEffectRoot); - } - - return true; -} - -#endif - diff --git a/Code/CryEngine/CryFont/FontRenderer.cpp b/Code/CryEngine/CryFont/FontRenderer.cpp deleted file mode 100644 index 2cf160896b..0000000000 --- a/Code/CryEngine/CryFont/FontRenderer.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// -// Purpose: -// - Render a glyph outline into a bitmap using FreeType 2 - -#include "CryFont_precompiled.h" - -#if !defined(USE_NULLFONT_ALWAYS) - -#include "FontRenderer.h" - -#include -#include -#include - -#include - -// Sizes are defined in in 26.6 fixed float format (TT_F26Dot6), where -// 1 unit is 1/64 of a pixel. -static const int fractionalPixelUnits = 64; - -namespace -{ - FT_Int32 GetLoadFlags(CFFont::HintBehavior hintBehavior) - { - switch (hintBehavior) - { - case CFFont::HintBehavior::NoHinting: - { - return FT_LOAD_NO_HINTING; - break; - } - case CFFont::HintBehavior::AutoHint: - { - return FT_LOAD_FORCE_AUTOHINT; - break; - } - } - return FT_LOAD_DEFAULT; - } - - FT_Int32 GetLoadTarget(CFFont::HintStyle hintStyle) - { - if (hintStyle == CFFont::HintStyle::Light) - { - return FT_LOAD_TARGET_LIGHT; - } - - return FT_LOAD_TARGET_NORMAL; - } - - FT_Render_Mode GetRenderMode(CFFont::HintStyle hintStyle) - { - // We use the hint style to drive the render mode also. These should - // usually be correlated with each other for best results, even though - // they could technically be different. - if (hintStyle == CFFont::HintStyle::Light) - { - return FT_RENDER_MODE_LIGHT; - } - - return FT_RENDER_MODE_NORMAL; - } -} - -//------------------------------------------------------------------------------------------------- -CFontRenderer::CFontRenderer() - : m_pLibrary(0) - , m_pFace(0) - , m_pGlyph(0) - , m_fSizeRatio(IFFontConstants::defaultSizeRatio) - , m_pEncoding(FONT_ENCODING_UNICODE) - , m_iGlyphBitmapWidth(0) - , m_iGlyphBitmapHeight(0) -{ -} - -//------------------------------------------------------------------------------------------------- -CFontRenderer::~CFontRenderer() -{ - FT_Done_Face(m_pFace); - ; - FT_Done_FreeType(m_pLibrary); - m_pFace = NULL; - m_pLibrary = NULL; -} - -//------------------------------------------------------------------------------------------------- -int CFontRenderer::LoadFromFile(const string& szFileName) -{ - int iError = FT_Init_FreeType(&m_pLibrary); - - if (iError) - { - return 0; - } - - if (m_pFace) - { - FT_Done_Face(m_pFace); - m_pFace = 0; - } - - iError = FT_New_Face(m_pLibrary, szFileName.c_str(), 0, &m_pFace); - - if (iError) - { - return 0; - } - - SetEncoding(FONT_ENCODING_UNICODE); - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontRenderer::LoadFromMemory(unsigned char* pBuffer, int iBufferSize) -{ - int iError = FT_Init_FreeType(&m_pLibrary); - - if (iError) - { - return 0; - } - - if (m_pFace) - { - FT_Done_Face(m_pFace); - m_pFace = 0; - } - iError = FT_New_Memory_Face(m_pLibrary, pBuffer, iBufferSize, 0, &m_pFace); - - if (iError) - { - return 0; - } - - SetEncoding(FONT_ENCODING_UNICODE); - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontRenderer::Release() -{ - FT_Done_Face(m_pFace); - ; - FT_Done_FreeType(m_pLibrary); - m_pFace = NULL; - m_pLibrary = NULL; - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontRenderer::SetGlyphBitmapSize(int iWidth, int iHeight, float sizeRatio) -{ - m_iGlyphBitmapWidth = iWidth; - m_iGlyphBitmapHeight = iHeight; - - // Assign the given scale for texture slots as long as its positive - m_fSizeRatio = sizeRatio > 0.0f ? sizeRatio : m_fSizeRatio; - - FT_Set_Pixel_Sizes(m_pFace, (int)(m_iGlyphBitmapWidth * m_fSizeRatio), (int)(m_iGlyphBitmapHeight * m_fSizeRatio)); - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontRenderer::GetGlyphBitmapSize(int* pWidth, int* pHeight) -{ - if (pWidth) - { - *pWidth = m_iGlyphBitmapWidth; - } - - if (pHeight) - { - *pHeight = m_iGlyphBitmapHeight; - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontRenderer::SetEncoding(FT_Encoding pEncoding) -{ - if (FT_Select_Charmap(m_pFace, pEncoding)) - { - return 0; - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -//------------------------------------------------------------------------------------------------- -int CFontRenderer::GetGlyph(CGlyphBitmap* pGlyphBitmap, int* iHoriAdvance, uint8* iGlyphWidth, uint8* iGlyphHeight, AZ::s32& iCharOffsetX, AZ::s32& iCharOffsetY, int iX, int iY, int iCharCode, const CFFont::FontHintParams& fontHintParams) -{ - FT_Int32 loadFlags = GetLoadFlags(fontHintParams.hintBehavior); - loadFlags |= GetLoadTarget(fontHintParams.hintStyle); - - int iError = FT_Load_Char(m_pFace, iCharCode, loadFlags); - - if (iError) - { - return 0; - } - - FT_Render_Mode renderMode = GetRenderMode(fontHintParams.hintStyle); - - m_pGlyph = m_pFace->glyph; - - iError = FT_Render_Glyph(m_pGlyph, renderMode); - - if (iError) - { - return 0; - } - - if (iHoriAdvance) - { - *iHoriAdvance = m_pGlyph->metrics.horiAdvance / fractionalPixelUnits; - } - - if (iGlyphWidth) - { - *iGlyphWidth = m_pGlyph->bitmap.width; - } - - if (iGlyphHeight) - { - *iGlyphHeight = m_pGlyph->bitmap.rows; - } - - unsigned char* pBuffer = pGlyphBitmap->GetBuffer(); - AZ_Assert(pBuffer, "CGlyphBitmap: bad buffer"); - - uint32 dwGlyphWidth = pGlyphBitmap->GetWidth(); - iCharOffsetX = m_pGlyph->bitmap_left; - iCharOffsetY = (static_cast(round(m_iGlyphBitmapHeight * m_fSizeRatio)) - m_pGlyph->bitmap_top); - - const int textureSlotBufferWidth = pGlyphBitmap->GetWidth(); - const int textureSlotBufferHeight = pGlyphBitmap->GetHeight(); - - // might happen if font characters are too big or cache dimenstions in font.xml is too small "" - const bool charWidthFits = iX + m_pGlyph->bitmap.width <= textureSlotBufferWidth; - const bool charHeightFits = iY + m_pGlyph->bitmap.rows <= textureSlotBufferHeight; - const bool charFitsInSlot = charWidthFits && charHeightFits; - AZ_Error("Font", charFitsInSlot, "Character code %d doesn't fit in font texture; check 'sizeRatio' attribute in font XML or adjust this character's sizing in the font.", iCharCode); - - // Since we might be re-rendering/overwriting a glyph that already exists - // in the font texture, clear the contents of this particular slot so no - // artifacts of the previous glyph remain. - pGlyphBitmap->Clear(); - - // Restrict iteration to smallest of either the texture slot or glyph - // bitmap buffer ranges - const int bufferMaxIterWidth = AZStd::GetMin(textureSlotBufferWidth, m_pGlyph->bitmap.width); - const int bufferMaxIterHeight = AZStd::GetMin(textureSlotBufferHeight, m_pGlyph->bitmap.rows); - - for (int i = 0; i < bufferMaxIterHeight; i++) - { - int iNewY = i + iY; - - for (int j = 0; j < bufferMaxIterWidth; j++) - { - unsigned char cColor = m_pGlyph->bitmap.buffer[(i * m_pGlyph->bitmap.width) + j]; - int iOffset = iNewY * dwGlyphWidth + iX + j; - - if (iOffset >= (int)dwGlyphWidth * m_iGlyphBitmapHeight) - { - continue; - } - - pBuffer[iOffset] = cColor; - // pBuffer[iOffset] = cColor/2+32; // debug - visualize character in a block - } - } - - return 1; -} - -int CFontRenderer::GetGlyphScaled([[maybe_unused]] CGlyphBitmap* pGlyphBitmap, [[maybe_unused]] int* iGlyphWidth, [[maybe_unused]] int* iGlyphHeight, [[maybe_unused]] int iX, [[maybe_unused]] int iY, [[maybe_unused]] float fScaleX, [[maybe_unused]] float fScaleY, [[maybe_unused]] int iCharCode) -{ - return 1; -} - -Vec2 CFontRenderer::GetKerning(uint32_t leftGlyph, uint32_t rightGlyph) -{ - FT_Vector kerningOffsets; - kerningOffsets.x = kerningOffsets.y = 0; - - if (FT_HAS_KERNING(m_pFace)) - { - const FT_UInt leftGlyphIndex = FT_Get_Char_Index(m_pFace, leftGlyph); - const FT_UInt rightGlyphIndex = FT_Get_Char_Index(m_pFace, rightGlyph); - - [[maybe_unused]] FT_Error ftError = FT_Get_Kerning(m_pFace, leftGlyphIndex, rightGlyphIndex, FT_KERNING_DEFAULT, &kerningOffsets); - -#if !defined(_RELEASE) - if (0 != ftError) - { - string warnMsg; - warnMsg.Format("FT_Get_Kerning returned %d", ftError); - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, warnMsg.c_str()); - } -#endif - } - - return Vec2(azlossy_cast(kerningOffsets.x / fractionalPixelUnits), azlossy_cast(kerningOffsets.y / fractionalPixelUnits)); -} - -float CFontRenderer::GetAscenderToHeightRatio() -{ - return (static_cast(m_pFace->ascender) / static_cast(m_pFace->height)); -} - -//------------------------------------------------------------------------------------------------- -/* -int CFontRenderer::FT_GetIndex(int iCharCode) -{ -if (iCharCode < 256) -{ -int iIndex = 0; -int iUnicode; - -// try unicode -for (int i = 0; i < m_pFace->num_charmaps; i++) -{ -if ((m_pFace->charmaps[i]->platform_id == 3) && (m_pFace->charmaps[i]->encoding_id == 1)) -{ -iUnicode = i; - -FT_Set_Charmap(m_pFace, m_pFace->charmaps[i]); - -iIndex = FT_Get_Char_Index(m_pFace, iCharCode); - -// not unicode, try ascii -if (iIndex == 0) -{ -for (int i = 0; i < m_pFace->num_charmaps; i++) -{ -if ((m_pFace->charmaps[i]->platform_id == 0) && (m_pFace->charmaps[i]->encoding_id == 0)) -{ -FT_Set_Charmap(m_pFace, m_pFace->charmaps[i]); - -iIndex = FT_Get_Char_Index(m_pFace, iCharCode); - -// not ascii either, reuse unicode default "missing char" -if (iIndex == 0) -{ -FT_Set_Charmap(m_pFace, m_pFace->charmaps[iUnicode]); - -return FT_Get_Char_Index(m_pFace, iCharCode); -} -} -} -} - -return iIndex; -} -} - -return 0; -} -else -{ -for (int i = 0; i < m_pFace->num_charmaps; i++) -{ -if ((m_pFace->charmaps[i]->platform_id == 3) && (m_pFace->charmaps[i]->encoding_id == 1)) -{ -FT_Set_Charmap(m_pFace, m_pFace->charmaps[i]); - -return FT_Get_Char_Index(m_pFace, iCharCode); -} -} - -return 0; -} - -return 0; -} -*/ - -#endif // #if !defined(USE_NULLFONT_ALWAYS) diff --git a/Code/CryEngine/CryFont/FontRenderer.h b/Code/CryEngine/CryFont/FontRenderer.h deleted file mode 100644 index aca26a1e04..0000000000 --- a/Code/CryEngine/CryFont/FontRenderer.h +++ /dev/null @@ -1,113 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Render a glyph outline into a bitmap using FreeType 2 - -#if !defined(USE_NULLFONT_ALWAYS) - -#ifndef CRYINCLUDE_CRYFONT_FONTRENDERER_H -#define CRYINCLUDE_CRYFONT_FONTRENDERER_H -#pragma once - - - -#include "GlyphBitmap.h" -#include "FFont.h" -#include -#pragma push_macro("generic") -#define generic GenericFromFreeTypeLibrary -#include -#undef generic -#pragma pop_macro("generic") - - -// Corresponds to the Unicode character set. This value covers all versions of the Unicode repertoire, -// including ASCII and Latin-1. Most fonts include a Unicode charmap, but not all of them. -#define FONT_ENCODING_UNICODE (FT_ENCODING_UNICODE) - -// Corresponds to the Microsoft Symbol encoding, used to encode mathematical symbols in the 32..255 character code range. -// For more information, see `http://www.ceviz.net/symbol.htm'. -#define FONT_ENCODING_SYMBOL (FT_ENCODING_MS_SYMBOL) - -// Corresponds to Microsoft's Japanese SJIS encoding. -// More info at `http://langsupport.japanreference.com/encoding.shtml'. See note on multi-byte encodings below. -#define FONT_ENCODING_SJIS (FT_ENCODING_MS_SJIS) - -// Corresponds to the encoding system for Simplified Chinese, as used in China. Only found in some TrueType fonts. -#define FONT_ENCODING_GB2312 (FT_ENCODING_MS_GB2312) - -// Corresponds to the encoding system for Traditional Chinese, as used in Taiwan and Hong Kong. Only found in some TrueType fonts. -#define FONT_ENCODING_BIG5 (FT_ENCODING_MS_BIG5) - -// Corresponds to the Korean encoding system known as Wansung. -// This is a Microsoft encoding that is only found in some TrueType fonts. -// For more information, see `http://www.microsoft.com/typography/unicode/949.txt'. -#define FONT_ENCODING_WANSUNG (FT_ENCODING_MS_WANSUNG) - -// The Korean standard character set (KS C-5601-1992), which corresponds to Windows code page 1361. -// This character set includes all possible Hangeul character combinations. Only found on some rare TrueType fonts. -#define FONT_ENCODING_JOHAB (FT_ENCODING_MS_JOHAB) - - - -//------------------------------------------------------------------------------------ -class CFontRenderer -{ -public: - - CFontRenderer(); - ~CFontRenderer(); - - int LoadFromFile(const string& szFileName); - int LoadFromMemory(unsigned char* pBuffer, int iBufferSize); - int Release(); - - int SetGlyphBitmapSize(int iWidth, int iHeight, float sizeRatio); - int GetGlyphBitmapSize(int* pWidth, int* pHeight); - - int SetSizeRatio(float fSizeRatio) { m_fSizeRatio = fSizeRatio; return 1; }; - float GetSizeRatio() { return m_fSizeRatio; }; - - int SetEncoding(FT_Encoding pEncoding); - FT_Encoding GetEncoding() { return m_pEncoding; }; - - //! Populates the given pGlyphBitmap's buffer from the FreeType bitmap buffer - //! \param iCharCode Used as a character index to retrieve the FreeType glyph and it's associated bitmap buffer for the character - //! \param pGlyphBitmap The FreeType glyph buffer is essentially copied into this CGlyphBitmap buffer - int GetGlyph(CGlyphBitmap* pGlyphBitmap, int* iHoriAdvance, uint8* iGlyphWidth, uint8* iGlyphHeight, AZ::s32& iCharOffsetX, AZ::s32& iCharOffsetY, int iX, int iY, int iCharCode, const CFFont::FontHintParams& glyphFlags = CFFont::FontHintParams()); - int GetGlyphScaled(CGlyphBitmap* pGlyphBitmap, int* iGlyphWidth, int* iGlyphHeight, int iX, int iY, float fScaleX, float fScaleY, int iCharCode); - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} - - bool GetMonospaced() const { return FT_IS_FIXED_WIDTH(m_pFace) != 0; } - - Vec2 GetKerning(uint32_t leftGlyph, uint32_t rightGlyph); - - float GetAscenderToHeightRatio(); - -private: - - FT_Library m_pLibrary; - FT_Face m_pFace; - FT_GlyphSlot m_pGlyph; - float m_fSizeRatio; - - FT_Encoding m_pEncoding; - - int m_iGlyphBitmapWidth; - int m_iGlyphBitmapHeight; -}; - -#endif // CRYINCLUDE_CRYFONT_FONTRENDERER_H - -#endif // #if !defined(USE_NULLFONT_ALWAYS) diff --git a/Code/CryEngine/CryFont/FontTexture.cpp b/Code/CryEngine/CryFont/FontTexture.cpp deleted file mode 100644 index 8db7484d59..0000000000 --- a/Code/CryEngine/CryFont/FontTexture.cpp +++ /dev/null @@ -1,633 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Purpose: -// - Create and update a texture with the most recently used glyphs - -#include "CryFont_precompiled.h" - -#if !defined(USE_NULLFONT_ALWAYS) - -#include "FontTexture.h" -#include "UnicodeIterator.h" -#include - -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#undef GetCharWidth -#endif - -//------------------------------------------------------------------------------------------------- -CFontTexture::CFontTexture() - : m_wSlotUsage(1) - , m_iWidth(0) - , m_iHeight(0) - , m_fInvWidth(0.0f) - , m_fInvHeight(0.0f) - , m_iCellWidth(0) - , m_iCellHeight(0) - , m_fTextureCellWidth(0) - , m_fTextureCellHeight(0) - , m_iWidthCellCount(0) - , m_iHeightCellCount(0) - , m_nTextureSlotCount(0) - , m_pBuffer(0) - , m_iSmoothMethod(FONT_SMOOTH_NONE) - , m_iSmoothAmount(FONT_SMOOTH_AMOUNT_NONE) -{ -} - -//------------------------------------------------------------------------------------------------- -CFontTexture::~CFontTexture() -{ - Release(); -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::CreateFromFile(const string& szFileName, int iWidth, int iHeight, int iSmoothMethod, int iSmoothAmount, int iWidthCellCount, int iHeightCellCount) -{ - if (!m_pGlyphCache.LoadFontFromFile(szFileName)) - { - Release(); - - return 0; - } - - if (!Create(iWidth, iHeight, iSmoothMethod, iSmoothAmount, iWidthCellCount, iHeightCellCount)) - { - return 0; - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::CreateFromMemory(unsigned char* pFileData, int iDataSize, int iWidth, int iHeight, int iSmoothMethod, int iSmoothAmount, int iWidthCellCount, int iHeightCellCount, float sizeRatio) -{ - if (!m_pGlyphCache.LoadFontFromMemory(pFileData, iDataSize)) - { - Release(); - - return 0; - } - - if (!Create(iWidth, iHeight, iSmoothMethod, iSmoothAmount, iWidthCellCount, iHeightCellCount, sizeRatio)) - { - return 0; - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::Create(int iWidth, int iHeight, int iSmoothMethod, int iSmoothAmount, int iWidthCellCount, int iHeightCellCount, float sizeRatio) -{ - m_pBuffer = new FONT_TEXTURE_TYPE[iWidth * iHeight]; - if (!m_pBuffer) - { - return 0; - } - - memset(m_pBuffer, 0, iWidth * iHeight * sizeof(FONT_TEXTURE_TYPE)); - - if (!(iWidthCellCount * iHeightCellCount)) - { - return 0; - } - - m_iWidth = iWidth; - m_iHeight = iHeight; - m_fInvWidth = 1.0f / (float)iWidth; - m_fInvHeight = 1.0f / (float)iHeight; - - m_iWidthCellCount = iWidthCellCount; - m_iHeightCellCount = iHeightCellCount; - m_nTextureSlotCount = m_iWidthCellCount * m_iHeightCellCount; - - m_iSmoothMethod = iSmoothMethod; - m_iSmoothAmount = iSmoothAmount; - - m_iCellWidth = m_iWidth / m_iWidthCellCount; - m_iCellHeight = m_iHeight / m_iHeightCellCount; - - m_fTextureCellWidth = m_iCellWidth * m_fInvWidth; - m_fTextureCellHeight = m_iCellHeight * m_fInvHeight; - - if (!m_pGlyphCache.Create(FONT_GLYPH_CACHE_SIZE, m_iCellWidth, m_iCellHeight, iSmoothMethod, iSmoothAmount, sizeRatio)) - { - Release(); - - return 0; - } - - if (!CreateSlotList(m_nTextureSlotCount)) - { - Release(); - - return 0; - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::Release() -{ - delete[] m_pBuffer; - m_pBuffer = 0; - - ReleaseSlotList(); - - m_pSlotTable.clear(); - - m_pGlyphCache.Release(); - - m_iWidthCellCount = 0; - m_iHeightCellCount = 0; - m_nTextureSlotCount = 0; - - m_iWidth = 0; - m_iHeight = 0; - m_fInvWidth = 0.0f; - m_fInvHeight = 0.0f; - - m_iCellWidth = 0; - m_iCellHeight = 0; - - m_iSmoothMethod = 0; - m_iSmoothAmount = 0; - - m_fTextureCellWidth = 0.0f; - m_fTextureCellHeight = 0.0f; - - m_wSlotUsage = 1; - - return 1; -} - -//------------------------------------------------------------------------------------------------- -uint32 CFontTexture::GetSlotChar(int iSlot) const -{ - return m_pSlotList[iSlot]->cCurrentChar; -} - -//------------------------------------------------------------------------------------------------- -CTextureSlot* CFontTexture::GetCharSlot(uint32 cChar, const Vec2i& glyphSize) -{ - CryFont::FontTexture::CTextureSlotKey slotKey = GetTextureSlotKey(cChar, glyphSize); - CTextureSlotTableItor pItor = m_pSlotTable.find(slotKey); - - if (pItor != m_pSlotTable.end()) - { - return pItor->second; - } - - return 0; -} - -//------------------------------------------------------------------------------------------------- -CTextureSlot* CFontTexture::GetLRUSlot() -{ - uint16 wMaxSlotAge = 0; - CTextureSlot* pLRUSlot = 0; - CTextureSlot* pSlot; - - CTextureSlotListItor pItor = m_pSlotList.begin(); - - while (pItor != m_pSlotList.end()) - { - pSlot = *pItor; - - if (pSlot->wSlotUsage == 0) - { - return pSlot; - } - else - { - uint16 slotAge = m_wSlotUsage - pSlot->wSlotUsage; - if (slotAge > wMaxSlotAge) - { - pLRUSlot = pSlot; - wMaxSlotAge = slotAge; - } - } - - ++pItor; - } - - return pLRUSlot; -} - -//------------------------------------------------------------------------------------------------- -CTextureSlot* CFontTexture::GetMRUSlot() -{ - uint16 wMinSlotAge = 0xFFFF; - CTextureSlot* pMRUSlot = 0; - CTextureSlot* pSlot; - - CTextureSlotListItor pItor = m_pSlotList.begin(); - - while (pItor != m_pSlotList.end()) - { - pSlot = *pItor; - - if (pSlot->wSlotUsage != 0) - { - uint16 slotAge = m_wSlotUsage - pSlot->wSlotUsage; - if (slotAge > wMinSlotAge) - { - pMRUSlot = pSlot; - wMinSlotAge = slotAge; - } - } - - ++pItor; - } - - return pMRUSlot; -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::PreCacheString(const char* szString, int* pUpdated, float sizeRatio, const Vec2i& glyphSize, const CFFont::FontHintParams& fontHintParams) -{ - Vec2i clampedGlyphSize = ClampGlyphSize(glyphSize, m_iCellWidth, m_iCellHeight); - - uint16 wSlotUsage = m_wSlotUsage++; - int iUpdated = 0; - - uint32 cChar; - for (Unicode::CIterator it(szString); *it; ++it) - { - cChar = *it; - CTextureSlot* pSlot = GetCharSlot(cChar, clampedGlyphSize); - - if (!pSlot) - { - pSlot = GetLRUSlot(); - - if (!pSlot) - { - return 0; - } - - if (!UpdateSlot(pSlot->iTextureSlot, wSlotUsage, cChar, sizeRatio, clampedGlyphSize, fontHintParams)) - { - return 0; - } - - ++iUpdated; - } - else - { - pSlot->wSlotUsage = wSlotUsage; - } - } - - if (pUpdated) - { - *pUpdated = iUpdated; - } - - if (iUpdated) - { - return 1; - } - - return 2; -} - -//------------------------------------------------------------------------------------------------- -void CFontTexture::GetTextureCoord(CTextureSlot* pSlot, float texCoords[4], - int& iCharSizeX, int& iCharSizeY, int& iCharOffsetX, int& iCharOffsetY, - const Vec2i& glyphSize) const -{ - if (!pSlot) - { - return; // expected behavior - } - - // Re-rendered glyphs are stored at smaller sizes than glyphs rendered at - // the (maximum) font texture slot resolution. We scale the returned width - // and height of the (actual) rendered glyph sizes so its transparent to - // callers that the glyph is actually smaller (from being re-rendered). - const float requestSizeWidthScale = AZ::GetMin(1.0f, GetRequestSizeWidthScale(glyphSize)); - const float requestSizeHeightScale = AZ::GetMin(1.0f, GetRequestSizeHeightScale(glyphSize)); - const float invRequestSizeWidthScale = 1.0f / requestSizeWidthScale; - const float invRequestSizeHeightScale = 1.0f / requestSizeHeightScale; - - // The inverse scale grows as the glyph size decreases. Once the glyph size - // reaches the font texture's max slot dimensions, we cap width/height scale - // since the text draw context will apply normal (as opposed to re-rendered) - // scaling. - int iChWidth = static_cast(pSlot->iCharWidth * invRequestSizeWidthScale); - int iChHeight = static_cast(pSlot->iCharHeight * invRequestSizeHeightScale); - - float slotCoord0 = pSlot->vTexCoord[0]; - float slotCoord1 = pSlot->vTexCoord[1]; - texCoords[0] = slotCoord0 - m_fInvWidth; // extra pixel for nicer bilinear filter - texCoords[1] = slotCoord1 - m_fInvHeight; // extra pixel for nicer bilinear filter - - // UV coordinates also must be scaled relative to the re-rendered glyph size - // as well. Width scale must be capped at 1.0f since glyph can't grow - // beyond the slot's resolution. - texCoords[2] = slotCoord0 + (((float)iChWidth * m_fInvWidth) * requestSizeWidthScale); - texCoords[3] = slotCoord1 + (((float)iChHeight * m_fInvHeight) * requestSizeHeightScale); - - iCharSizeX = iChWidth + 1; // extra pixel for nicer bilinear filter - iCharSizeY = iChHeight + 1; // extra pixel for nicer bilinear filter - - // Offsets are scaled accordingly when the rendered glyph size is smaller - // than the glyph/slot dimensions, but otherwise we expect the text draw - // context to apply scaling beyond that. - iCharOffsetX = static_cast(pSlot->iCharOffsetX * invRequestSizeWidthScale); - iCharOffsetY = static_cast(pSlot->iCharOffsetY * invRequestSizeHeightScale); -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::GetCharacterWidth(uint32 cChar) const -{ - CTextureSlotTableItorConst pItor = m_pSlotTable.find(GetTextureSlotKey(cChar)); - - if (pItor == m_pSlotTable.end()) - { - return 0; - } - - const CTextureSlot& rSlot = *pItor->second; - - // For proportional fonts, add one pixel of spacing for aesthetic reasons - int proportionalOffset = GetMonospaced() ? 0 : 1; - - return rSlot.iCharWidth + proportionalOffset; -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::GetHorizontalAdvance(uint32 cChar, const Vec2i& glyphSize) const -{ - CTextureSlotTableItorConst pItor = m_pSlotTable.find(GetTextureSlotKey(cChar, glyphSize)); - - if (pItor == m_pSlotTable.end()) - { - return 0; - } - - const CTextureSlot& rSlot = *pItor->second; - - // Re-rendered glyphs are stored at smaller sizes than glyphs rendered at - // the (maximum) font texture slot resolution. We scale the returned width - // and height of the (actual) rendered glyph sizes so its transparent to - // callers that the glyph is actually smaller (from being re-rendered). - const float requestSizeWidthScale = GetRequestSizeWidthScale(glyphSize); - const float invRequestSizeWidthScale = 1.0f / requestSizeWidthScale; - - // Only multiply by 1.0f when glyphsize is greater than cell width because we assume that callers - // will use the font draw text context to scale the value appropriately. - return static_cast(rSlot.iHoriAdvance * AZ::GetMax(1.0f, invRequestSizeWidthScale)); -} - -//------------------------------------------------------------------------------------------------- -/* -int CFontTexture::GetCharHeightByChar(wchar_t cChar) -{ -CTextureSlotTableItor pItor = m_pSlotTable.find(cChar); - -if (pItor != m_pSlotTable.end()) -{ -return pItor->second->iCharHeight; -} - -return 0; -} -*/ - -//------------------------------------------------------------------------------------------------- -int CFontTexture::WriteToFile([[maybe_unused]] const string& szFileName) -{ -#ifdef WIN32 - AZ::IO::FileIOStream outputFile(szFileName.c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary); - - if (!outputFile.IsOpen()) - { - return 0; - } - - BITMAPFILEHEADER pHeader; - BITMAPINFOHEADER pInfoHeader; - - memset(&pHeader, 0, sizeof(BITMAPFILEHEADER)); - memset(&pInfoHeader, 0, sizeof(BITMAPINFOHEADER)); - - pHeader.bfType = 0x4D42; - pHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + m_iWidth * m_iHeight * 3; - pHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); - - pInfoHeader.biSize = sizeof(BITMAPINFOHEADER); - pInfoHeader.biWidth = m_iWidth; - pInfoHeader.biHeight = m_iHeight; - pInfoHeader.biPlanes = 1; - pInfoHeader.biBitCount = 24; - pInfoHeader.biCompression = 0; - pInfoHeader.biSizeImage = m_iWidth * m_iHeight * 3; - - outputFile.Write(sizeof(BITMAPFILEHEADER), &pHeader); - outputFile.Write(sizeof(BITMAPINFOHEADER), &pInfoHeader); - - unsigned char cRGB[3]; - - for (int i = m_iHeight - 1; i >= 0; i--) - { - for (int j = 0; j < m_iWidth; j++) - { - cRGB[0] = m_pBuffer[(i * m_iWidth) + j]; - cRGB[1] = *cRGB; - - cRGB[2] = *cRGB; - - outputFile.Write(3, cRGB); - } - } - -#endif - return 1; -} - -//------------------------------------------------------------------------------------------------- -Vec2 CFontTexture::GetKerning(uint32_t leftGlyph, uint32_t rightGlyph) -{ - return m_pGlyphCache.GetKerning(leftGlyph, rightGlyph); -} - -//------------------------------------------------------------------------------------------------- -float CFontTexture::GetAscenderToHeightRatio() -{ - return m_pGlyphCache.GetAscenderToHeightRatio(); -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::CreateSlotList(int iListSize) -{ - int y, x; - - for (int i = 0; i < iListSize; i++) - { - CTextureSlot* pTextureSlot = new CTextureSlot; - - if (!pTextureSlot) - { - return 0; - } - - pTextureSlot->iTextureSlot = i; - pTextureSlot->Reset(); - - y = i / m_iWidthCellCount; - x = i % m_iWidthCellCount; - - pTextureSlot->vTexCoord[0] = (float)(x * m_fTextureCellWidth) + (0.5f / (float)m_iWidth); - pTextureSlot->vTexCoord[1] = (float)(y * m_fTextureCellHeight) + (0.5f / (float)m_iHeight); - - m_pSlotList.push_back(pTextureSlot); - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::ReleaseSlotList() -{ - CTextureSlotListItor pItor = m_pSlotList.begin(); - - while (pItor != m_pSlotList.end()) - { - delete (*pItor); - - pItor = m_pSlotList.erase(pItor); - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CFontTexture::UpdateSlot(int iSlot, uint16 wSlotUsage, uint32 cChar, float sizeRatio, const Vec2i& glyphSize, const CFFont::FontHintParams& fontHintParams) -{ - CTextureSlot* pSlot = m_pSlotList[iSlot]; - - if (!pSlot) - { - return 0; - } - - CTextureSlotTableItor pItor = m_pSlotTable.find(GetTextureSlotKey(pSlot->cCurrentChar, pSlot->glyphSize)); - - if (pItor != m_pSlotTable.end()) - { - m_pSlotTable.erase(pItor); - } - m_pSlotTable.insert(AZStd::pair(GetTextureSlotKey(cChar, glyphSize), pSlot)); - pSlot->glyphSize = glyphSize; - pSlot->wSlotUsage = wSlotUsage; - pSlot->cCurrentChar = cChar; - - int iWidth = 0; - int iHeight = 0; - - // blit the char glyph into the texture - int x = pSlot->iTextureSlot % m_iWidthCellCount; - int y = pSlot->iTextureSlot / m_iWidthCellCount; - - CGlyphBitmap* pGlyphBitmap; - - if (glyphSize.x > 0 && glyphSize.y > 0) - { - m_pGlyphCache.SetGlyphBitmapSize(glyphSize.x, glyphSize.y, sizeRatio); - } - - if (!m_pGlyphCache.GetGlyph(&pGlyphBitmap, &pSlot->iHoriAdvance, &iWidth, &iHeight, pSlot->iCharOffsetX, pSlot->iCharOffsetY, cChar, glyphSize, fontHintParams)) - { - return 0; - } - - pSlot->iCharWidth = iWidth; - pSlot->iCharHeight = iHeight; - - // Add a pixel along width and height to avoid artifacts being rendered - // from a previous glyph in this slot due to bilinear filtering. The source - // glyph bitmap buffer is presumed to be cleared prior to FreeType rendering - // to the bitmap. - const int blitWidth = AZ::GetMin(iWidth + 1, m_iCellWidth); - const int blitHeight = AZ::GetMin(iHeight + 1, m_iCellHeight); - - pGlyphBitmap->BlitTo8(m_pBuffer, 0, 0, - blitWidth, blitHeight, x * m_iCellWidth, y * m_iCellHeight, m_iWidth); - - return 1; -} - -//------------------------------------------------------------------------------------------------- -void CFontTexture::CreateGradientSlot() -{ - CTextureSlot* pSlot = GetGradientSlot(); - assert(pSlot->cCurrentChar == (uint32)~0); // 0 needs to be unused spot - - pSlot->Reset(); - pSlot->iCharWidth = m_iCellWidth - 2; - pSlot->iCharHeight = m_iCellHeight - 2; - pSlot->SetNotReusable(); - - int x = pSlot->iTextureSlot % m_iWidthCellCount; - int y = pSlot->iTextureSlot / m_iWidthCellCount; - - assert(sizeof(*m_pBuffer) == sizeof(uint8)); - uint8* pBuffer = &m_pBuffer[x * m_iCellWidth + y * m_iCellHeight * m_iWidth]; - - for (uint32 dwY = 0; dwY < pSlot->iCharHeight; ++dwY) - { - for (uint32 dwX = 0; dwX < pSlot->iCharWidth; ++dwX) - { - pBuffer[dwX + dwY * m_iWidth] = dwY * 255 / (pSlot->iCharHeight - 1); - } - } -} - -//------------------------------------------------------------------------------------------------- -CTextureSlot* CFontTexture::GetGradientSlot() -{ - return m_pSlotList[0]; -} - -//------------------------------------------------------------------------------------------------- -CryFont::FontTexture::CTextureSlotKey CFontTexture::GetTextureSlotKey(uint32 cChar, const Vec2i& glyphSize) const -{ - const Vec2i clampedGlyphSize(ClampGlyphSize(glyphSize, m_iCellWidth, m_iCellHeight)); - return CryFont::FontTexture::CTextureSlotKey(clampedGlyphSize, cChar); -} - -Vec2i CFontTexture::ClampGlyphSize(const Vec2i& glyphSize, int cellWidth, int cellHeight) -{ - const Vec2i maxCellDimensions(cellWidth, cellHeight); - Vec2i clampedGlyphSize(glyphSize); - - const bool hasZeroDimension = glyphSize.x == 0 || glyphSize.y == 0; - const bool isDefaultSize = glyphSize == CCryFont::defaultGlyphSize; - const bool exceedsDimensions = glyphSize.x > cellWidth || glyphSize.y > cellHeight; - const bool useMaxCellDimension = hasZeroDimension || isDefaultSize || exceedsDimensions; - if (useMaxCellDimension) - { - clampedGlyphSize = maxCellDimensions; - } - - return clampedGlyphSize; -} - -#endif // #if !defined(USE_NULLFONT_ALWAYS) diff --git a/Code/CryEngine/CryFont/FontTexture.h b/Code/CryEngine/CryFont/FontTexture.h deleted file mode 100644 index 45d0403f47..0000000000 --- a/Code/CryEngine/CryFont/FontTexture.h +++ /dev/null @@ -1,301 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYFONT_FONTTEXTURE_H -#define CRYINCLUDE_CRYFONT_FONTTEXTURE_H -#pragma once - -#if !defined(USE_NULLFONT_ALWAYS) - -#include "GlyphCache.h" -#include "GlyphBitmap.h" -#include "CryFont.h" -#include "FFont.h" - -typedef uint8 FONT_TEXTURE_TYPE; - -// the number of slots in the glyph cache -// each slot ocupies ((glyph_bitmap_width * glyph_bitmap_height) + 24) bytes -#define FONT_GLYPH_CACHE_SIZE (1) - -// the glyph spacing in font texels between characters in proportional font mode (more correct would be to take the value in the character) -#define FONT_GLYPH_PROP_SPACING (1) - -// the size of a rendered space, this value gets multiplied by the default characted width -#define FONT_SPACE_SIZE (0.5f) - -// don't draw this char (used to avoid drawing color codes) -#define FONT_NOT_DRAWABLE_CHAR (0xffff) - -// smoothing methods -#define FONT_SMOOTH_NONE 0 -#define FONT_SMOOTH_BLUR 1 -#define FONT_SMOOTH_SUPERSAMPLE 2 - -// smoothing amounts -#define FONT_SMOOTH_AMOUNT_NONE 0 -#define FONT_SMOOTH_AMOUNT_2X 1 -#define FONT_SMOOTH_AMOUNT_4X 2 - -//! Stores glyph meta-data read from the font (FreeType). -//! -//! \sa CCacheSlot -typedef struct CTextureSlot -{ - Vec2i glyphSize = CCryFont::defaultGlyphSize; //!< Size of the rendered glyph stored in the font texture - uint16 wSlotUsage; //!< For LRU strategy, 0xffff is never released - uint32 cCurrentChar; //!< ~0 if not used for characters - int iTextureSlot; - int iHoriAdvance; //!< Advance width. See FT_Glyph_Metrics::horiAdvance. - float vTexCoord[2]; //!< Character position in the texture (not yet half texel corrected) - uint8 iCharWidth; //!< Glyph width (in pixel) - uint8 iCharHeight; //!< Glyph height (in pixel) - AZ::s32 iCharOffsetX; //!< Glyph's left-side bearing (in pixels). See FT_GlyphSlotRec::bitmap_left. - AZ::s32 iCharOffsetY; //!< Glyph's top bearing (in pixels). See FT_GlyphSlotRec::bitmap_top. - - void Reset() - { - wSlotUsage = 0; - cCurrentChar = ~0; - iHoriAdvance = 0; - iCharWidth = 0; - iCharHeight = 0; - iCharOffsetX = 0; - iCharOffsetY = 0; - } - - void SetNotReusable() - { - wSlotUsage = 0xffff; - } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} -} CTextureSlot; - - -typedef std::vector CTextureSlotList; -typedef std::vector::iterator CTextureSlotListItor; - -namespace CryFont -{ - namespace FontTexture - { - //! Height and width pair for glyph size mapping - typedef Vec2i CGlyphSizeType; - - //! Pair for mapping a height and width size to a UTF32 character/glyph - typedef AZStd::pair CTextureSlotKey; - - //! Hasher for texture slot table keys (glyphsize-char code pair) - //! - //! Instead of creating our own custom hash, the types are broken down to their - //! native types (ints) and passed to existing hashes that handle those types. - struct HashTextureSlotTableKey - { - typedef CTextureSlotKey ArgumentType; - typedef AZStd::size_t ResultType; - typedef AZStd::pair Int32Pair; - typedef AZStd::pair Int32PairU32Pair; - ResultType operator()(const ArgumentType& value) const - { - // Utiliize existing hash function for pairs of ints - AZStd::hash pairHash; - return pairHash(Int32PairU32Pair(Int32Pair(value.first.x, value.first.y), value.second)); - } - }; - } -} - -//! Maps size-speicifc UTF32 glyphs to their corresponding texture slots -typedef AZStd::unordered_map CTextureSlotTable; - -typedef CTextureSlotTable::iterator CTextureSlotTableItor; -typedef CTextureSlotTable::const_iterator CTextureSlotTableItorConst; - -#ifdef WIN64 -#undef GetCharWidth -#undef GetCharHeight -#endif - -//! Stores the glyphs of a font within a single texture. -//! -//! The texture resolution is configurable, as is the number of slots within -//! the texture. -//! -//! A texture slot contains a single glyph within the font and are uniform -//! size throughout the font texture (each slot occupies the same size -//! regardless of the size of a glyph being stored, so a '.' occupies the -//! same amount of space as a 'W', for example). -//! -//! Font glyph buffers are read from FreeType and copied into the texture. -//! -//! \sa CTextureSlot, CFontRenderer -class CFontTexture -{ -public: - CFontTexture(); - ~CFontTexture(); - - int CreateFromFile(const string& szFileName, int iWidth, int iHeight, int iSmoothMethod, int iSmoothAmount, int iWidthCharCount = 16, int iHeightCharCount = 16); - - //! Default texture slot width/height is 16x8 slots, allowing for 128 glyphs to be stored in the font texture. This was - //! previously 16x16, allowing 256 glyphs to be stored. For reference, there are 95 printable ASCII characters, so by - //! reducing the number of slots, the height of the font texture can be halved (for some nice memory savings). We may - //! want to make this configurable in the font XML (especially for languages with a large number of printable chars). - int CreateFromMemory(unsigned char* pFileData, int iDataSize, int iWidth, int iHeight, int iSmoothMethod, int iSmoothAmount, int iWidthCharCount, int iHeightCharCount, float sizeRatio); - - int Create(int iWidth, int iHeight, int iSmoothMethod, int iSmoothAmount, int iWidthCharCount = 16, int iHeightCharCount = 16, float sizeRatio = IFFontConstants::defaultSizeRatio); - int Release(); - - int SetEncoding(FT_Encoding pEncoding) { return m_pGlyphCache.SetEncoding(pEncoding); } - FT_Encoding GetEncoding() { return m_pGlyphCache.GetEncoding(); } - - int GetCellWidth() { return m_iCellWidth; } - int GetCellHeight() { return m_iCellHeight; } - - int GetWidth() { return m_iWidth; } - int GetHeight() { return m_iHeight; } - - int GetWidthCellCount() { return m_iWidthCellCount; } - int GetHeightCellCount() { return m_iHeightCellCount; } - - float GetTextureCellWidth() { return m_fTextureCellWidth; } - float GetTextureCellHeight() { return m_fTextureCellHeight; } - - FONT_TEXTURE_TYPE* GetBuffer() { return m_pBuffer; } - - uint32 GetSlotChar(int iSlot) const; - CTextureSlot* GetCharSlot(uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize); - CTextureSlot* GetGradientSlot(); - - CTextureSlot* GetLRUSlot(); - CTextureSlot* GetMRUSlot(); - - //! Returns 1 if texture updated, returns 2 if texture not updated, returns 0 on error - //! \param szString A string of glyphs (UTF8) to added to the font texture (if they don't already exist in the font texture) - //! \param pUpdated is the number of slots updated - //! \param sizeRatio A sizing scale that gets applied to all glyphs sizes before they are stored in the font texture. - //! \param glyphSize The resolution to render the glyphs in szString at. - //! \param glyphFlags Controls hinting behavior for glyphs rendered to the font texture. - int PreCacheString(const char* szString, int* pUpdated = 0, float sizeRatio = IFFontConstants::defaultSizeRatio, const Vec2i& glyphSize = CCryFont::defaultGlyphSize, const CFFont::FontHintParams& glyphFlags = CFFont::FontHintParams()); - // Arguments: - // pSlot - function does nothing if this pointer is 0 - void GetTextureCoord(CTextureSlot * pSlot, float texCoords[4], int& iCharSizeX, int& iCharSizeY, int& iCharOffsetX, int& iCharOffsetY, const Vec2i& glyphSize = CCryFont::defaultGlyphSize) const; - int GetCharacterWidth(uint32 cChar) const; - //! Gets the horizontal advance for the given glyph/char. - //! \param cChar The glyph (UTF32) to get the horizontal advance for. - //! \param glyphSize The rendered size of the glyph to get the advance for (the same glyph could be stored in the font texture at multiple sizes). - int GetHorizontalAdvance(uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize) const; - // int GetCharHeightByChar(wchar_t cChar); - - // useful for special feature rendering interleaved with fonts (e.g. box behind the text) - void CreateGradientSlot(); - - int WriteToFile(const string& szFileName); - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_pGlyphCache); - pSizer->AddObject(m_pSlotList); - //pSizer->AddContainer(m_pSlotTable); - pSizer->AddObject(m_pBuffer, m_iWidth * m_iHeight * sizeof(FONT_TEXTURE_TYPE)); - } - - bool GetMonospaced() const { return m_pGlyphCache.GetMonospaced(); } - - Vec2 GetKerning(uint32_t leftGlyph, uint32_t rightGlyph); - - float GetAscenderToHeightRatio(); - -public: // --------------------------------------------------------------- - - //! Clamps the given glyph size to the given max cell width and height dimensions. - static Vec2i ClampGlyphSize(const Vec2i& glyphSize, int cellWidth, int cellHeight); - -private: // --------------------------------------------------------------- - - int CreateSlotList(int iListSize); - int ReleaseSlotList(); - - //! Updates the given font texture slot with the given glyph (UTF8) with the given parameters. If the glyph doesn't - //! exist in the font texture at the given size, then the glyph will be rendered to the font texture with the given - //! parameters. - //! \param iSlot Index of the texture slot to update within the slot list. - //! \param wSlotUsage Used for LRU strategy to determine how many times a glyph is referenced for retention within the font texture (before eviction). - //! \param cChar UTF32 glyph to store within the slot. - //! \param sizeRatio A sizing scale that should be applied to the glyph before being stored within the font texture. - //! \param glyphSize The size of the glyph to be rendered at within the font texture. - //! \param glyphFlags Specifies hinting behavior that should be applied to the glyph when rendered to the font texture. - int UpdateSlot(int iSlot, uint16 wSlotUsage, uint32 cChar, float sizeRatio, const Vec2i& glyphSize = CCryFont::defaultGlyphSize, const CFFont::FontHintParams& glyphFlags = CFFont::FontHintParams()); - - CryFont::FontTexture::CTextureSlotKey GetTextureSlotKey(uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize) const; - - //! Calculates scaling info that should be applied when the rendered glyph size doesn't match the maximum glyph slot resolution. - //! - //! Glyphs can be re-rendered to glyph slots at smaller resolutions for pixel-perfect resolution (rather than applying a scale - //! to glyphs rendered at larger sizes). These scaling values allow clients of the font texture to use the glyphs without regard - //! to whether the glyphs have been re-rendered or not. - float GetRequestSizeWidthScale(const Vec2i& glyphSize) const - { - const int cellWidth = m_iCellWidth == 0 ? 1 : m_iCellWidth; - const float invCellWidth = 1.0f / cellWidth; - return glyphSize.x > 0 ? glyphSize.x * invCellWidth : 1.0f; - } - - //! Calculates scaling info that should be applied when the rendered glyph size doesn't match the maximum glyph slot resolution. - //! - //! Glyphs can be re-rendered to glyph slots at smaller resolutions for pixel-perfect resolution (rather than applying a scale - //! to glyphs rendered at larger sizes). These scaling values allow clients of the font texture to use the glyphs without regard - //! to whether the glyphs have been re-rendered or not. - float GetRequestSizeHeightScale(const Vec2i& glyphSize) const - { - const int cellHeight = m_iCellHeight == 0 ? 1 : m_iCellHeight; - const float invCellHeight = 1.0f / cellHeight; - return glyphSize.y > 0 ? glyphSize.y * invCellHeight : 1.0f; - } - - // -------------------------------- - - int m_iWidth; // whole texture cache width - int m_iHeight; // whole texture cache height - - float m_fInvWidth; - float m_fInvHeight; - - int m_iCellWidth; - int m_iCellHeight; - - float m_fTextureCellWidth; - float m_fTextureCellHeight; - - int m_iWidthCellCount; - int m_iHeightCellCount; - - int m_nTextureSlotCount; - - int m_iSmoothMethod; - int m_iSmoothAmount; - - CGlyphCache m_pGlyphCache; - CTextureSlotList m_pSlotList; - CTextureSlotTable m_pSlotTable; - - FONT_TEXTURE_TYPE* m_pBuffer; // [y*iWidth * x] x=0..iWidth-1, y=0..iHeight-1 - - uint16 m_wSlotUsage; -}; - -#endif // #if !defined(USE_NULLFONT_ALWAYS) - -#endif // CRYINCLUDE_CRYFONT_FONTTEXTURE_H diff --git a/Code/CryEngine/CryFont/GlyphBitmap.cpp b/Code/CryEngine/CryFont/GlyphBitmap.cpp deleted file mode 100644 index 8ae893c317..0000000000 --- a/Code/CryEngine/CryFont/GlyphBitmap.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Purpose: -// - Hold a glyph bitmap and blit it to the main texture - -#include "CryFont_precompiled.h" -#include "GlyphBitmap.h" -#include - - -//------------------------------------------------------------------------------------------------- -CGlyphBitmap::CGlyphBitmap() - : m_iWidth(0) - , m_iHeight(0) - , m_pBuffer(0) -{ -} - -//------------------------------------------------------------------------------------------------- -CGlyphBitmap::~CGlyphBitmap() -{ - Release(); -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::Create(int iWidth, int iHeight) -{ - Release(); - - m_pBuffer = new unsigned char[iWidth * iHeight]; - - if (!m_pBuffer) - { - return 0; - } - - m_iWidth = iWidth; - m_iHeight = iHeight; - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::Release() -{ - if (m_pBuffer) - { - delete[] m_pBuffer; - } - m_pBuffer = 0; - m_iWidth = m_iHeight = 0; - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::Blur(int iIterations) -{ - int cSum; - int yOffset; - int yupOffset; - int ydownOffset; - - for (int i = 0; i < iIterations; i++) - { - for (int y = 0; y < m_iHeight; y++) - { - yOffset = y * m_iWidth; - - if (y - 1 >= 0) - { - yupOffset = (y - 1) * m_iWidth; - } - else - { - yupOffset = (y) * m_iWidth; - } - - if (y + 1 < m_iHeight) - { - ydownOffset = (y + 1) * m_iWidth; - } - else - { - ydownOffset = (y) * m_iWidth; - } - - for (int x = 0; x < m_iWidth; x++) - { - cSum = m_pBuffer[yupOffset + x] + m_pBuffer[ydownOffset + x]; - - if (x - 1 >= 0) - { - cSum += m_pBuffer[yOffset + x - 1]; - } - else - { - cSum += m_pBuffer[yOffset + x]; - } - - if (x + 1 < m_iWidth) - { - cSum += m_pBuffer[yOffset + x + 1]; - } - else - { - cSum += m_pBuffer[yOffset + x]; - } - - m_pBuffer[yOffset + x] = cSum >> 2; - } - } - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::Scale(float fScaleX, float fScaleY) -{ - int iNewWidth = (int)(m_iWidth * fScaleX); - int iNewHeight = (int)(m_iHeight * fScaleY); - - unsigned char* pNewBuffer = new unsigned char[iNewWidth * iNewHeight]; - - if (!pNewBuffer) - { - return 0; - } - - float xFactor = m_iWidth / (float)iNewWidth; - float yFactor = m_iHeight / (float)iNewHeight; - - float xFractioned, yFractioned, xFraction, yFraction, oneMinusX, oneMinusY, fR0, fR1; - int xCeil, yCeil, xFloor, yFloor, yNewOffset; - - unsigned char c0, c1, c2, c3; - - for (int y = 0; y < iNewHeight; ++y) - { - yFractioned = y * yFactor; - yFloor = (int)floor_tpl(yFractioned); - yCeil = yFloor + 1; - - if (yCeil >= m_iHeight) - { - yCeil = yFloor; - } - - yFraction = yFractioned - yFloor; - oneMinusY = 1.0f - yFraction; - - yNewOffset = y * iNewWidth; - - for (int x = 0; x < iNewWidth; ++x) - { - xFractioned = x * xFactor; - xFloor = (int)floor_tpl(xFractioned); - xCeil = xFloor + 1; - - if (xCeil >= m_iWidth) - { - xCeil = xFloor; - } - - xFraction = xFractioned - xFloor; - oneMinusX = 1.0f - xFraction; - - c0 = m_pBuffer[yFloor * m_iWidth + xFloor]; - c1 = m_pBuffer[yFloor * m_iWidth + xCeil]; - c2 = m_pBuffer[yCeil * m_iWidth + xFloor]; - c3 = m_pBuffer[yCeil * m_iWidth + xCeil]; - - fR0 = (oneMinusX * c0 + xFraction * c1); - fR1 = (oneMinusX * c2 + xFraction * c3); - - pNewBuffer[yNewOffset + x] = (unsigned char)((oneMinusY * fR0) + (yFraction * fR1)); - } - } - - m_iWidth = iNewWidth; - m_iHeight = iNewHeight; - - delete[] m_pBuffer; - m_pBuffer = pNewBuffer; - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::Clear() -{ - memset(m_pBuffer, 0, m_iWidth * m_iHeight); - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::BlitTo8(unsigned char* pBuffer, int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, int iDestY, int iDestWidth) -{ - int ySrcOffset, yDestOffset; - - for (int y = 0; y < iSrcHeight; y++) - { - ySrcOffset = (iSrcY + y) * m_iWidth; - yDestOffset = (iDestY + y) * iDestWidth; - - for (int x = 0; x < iSrcWidth; x++) - { - pBuffer[yDestOffset + iDestX + x] = m_pBuffer[ySrcOffset + iSrcX + x]; - } - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::BlitTo32(unsigned int* pBuffer, int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, int iDestY, int iDestWidth) -{ - int ySrcOffset, yDestOffset; - char cColor; - - for (int y = 0; y < iSrcHeight; y++) - { - ySrcOffset = (iSrcY + y) * m_iWidth; - yDestOffset = (iDestY + y) * iDestWidth; - - for (int x = 0; x < iSrcWidth; x++) - { - cColor = m_pBuffer[ySrcOffset + iSrcX + x]; - - pBuffer[yDestOffset + iDestX + x] = (cColor << 24) | (255 << 16) | (255 << 8) | 255; - } - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::BlitScaledTo8(unsigned char* pBuffer, [[maybe_unused]] int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, [[maybe_unused]] int iDestY, int iDestWidth, int iDestHeight, int iDestBufferWidth) -{ - int iNewWidth = (int)iDestWidth; - int iNewHeight = (int)iDestHeight; - - unsigned char* pNewBuffer = pBuffer; - - float xFactor = iSrcWidth / (float)iNewWidth; - float yFactor = iSrcHeight / (float)iNewHeight; - - float xFractioned, yFractioned, xFraction, yFraction, oneMinusX, oneMinusY, fR0, fR1; - int xCeil, yCeil, xFloor, yFloor, yNewOffset; - - unsigned char c0, c1, c2, c3; - - for (int y = 0; y < iNewHeight; ++y) - { - yFractioned = y * yFactor; - yFloor = (int)floor_tpl(yFractioned); - yCeil = yFloor + 1; - - yFraction = yFractioned - yFloor; - oneMinusY = 1.0f - yFraction; - - yNewOffset = y * iDestBufferWidth; - - yFloor += iSrcY; - yCeil += iSrcY; - - if (yCeil >= m_iHeight) - { - yCeil = yFloor; - } - - for (int x = 0; x < iNewWidth; ++x) - { - xFractioned = x * xFactor; - xFloor = (int)floor_tpl(xFractioned); - xCeil = xFloor + 1; - - xFraction = xFractioned - xFloor; - oneMinusX = 1.0f - xFraction; - - xFloor += iSrcY; - xCeil += iSrcY; - - if (xCeil >= m_iWidth) - { - xCeil = xFloor; - } - - c0 = m_pBuffer[yFloor * m_iWidth + xFloor]; - c1 = m_pBuffer[yFloor * m_iWidth + xCeil]; - c2 = m_pBuffer[yCeil * m_iWidth + xFloor]; - c3 = m_pBuffer[yCeil * m_iWidth + xCeil]; - - fR0 = (oneMinusX * c0 + xFraction * c1); - fR1 = (oneMinusX * c2 + xFraction * c3); - - pNewBuffer[yNewOffset + x + iDestX] = (unsigned char)((oneMinusY * fR0) + (yFraction * fR1)); - } - } - - return 1; -} - - -#if defined(__GNUC__) -#if __GNUC__ >= 4 && __GNUC__MINOR__ < 7 -#pragma GCC diagnostic ignored "-Woverflow" -#endif -#endif -//------------------------------------------------------------------------------------------------- -int CGlyphBitmap::BlitScaledTo32(unsigned char* pBuffer, [[maybe_unused]] int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, [[maybe_unused]] int iDestY, int iDestWidth, int iDestHeight, int iDestBufferWidth) -{ - int iNewWidth = (int)iDestWidth; - int iNewHeight = (int)iDestHeight; - - unsigned char* pNewBuffer = pBuffer; - - float xFactor = iSrcWidth / (float)iNewWidth; - float yFactor = iSrcHeight / (float)iNewHeight; - - float xFractioned, yFractioned, xFraction, yFraction, oneMinusX, oneMinusY, fR0, fR1; - int xCeil, yCeil, xFloor, yFloor, yNewOffset; - - unsigned char c0, c1, c2, c3, cColor; - - for (int y = 0; y < iNewHeight; ++y) - { - yFractioned = y * yFactor; - yFloor = (int)floor_tpl(yFractioned); - yCeil = yFloor + 1; - - yFraction = yFractioned - yFloor; - oneMinusY = 1.0f - yFraction; - - yNewOffset = y * iDestBufferWidth; - - yFloor += iSrcY; - yCeil += iSrcY; - - if (yCeil >= m_iHeight) - { - yCeil = yFloor; - } - - for (int x = 0; x < iNewWidth; ++x) - { - xFractioned = x * xFactor; - xFloor = (int)floor_tpl(xFractioned); - xCeil = xFloor + 1; - - xFraction = xFractioned - xFloor; - oneMinusX = 1.0f - xFraction; - - xFloor += iSrcY; - xCeil += iSrcY; - - if (xCeil >= m_iWidth) - { - xCeil = xFloor; - } - - c0 = m_pBuffer[yFloor * m_iWidth + xFloor]; - c1 = m_pBuffer[yFloor * m_iWidth + xCeil]; - c2 = m_pBuffer[yCeil * m_iWidth + xFloor]; - c3 = m_pBuffer[yCeil * m_iWidth + xCeil]; - - fR0 = (oneMinusX * c0 + xFraction * c1); - fR1 = (oneMinusX * c2 + xFraction * c3); - - cColor = (unsigned char)((oneMinusY * fR0) + (yFraction * fR1)); - - pNewBuffer[yNewOffset + x + iDestX] = 0xffffff | (cColor << 24); - } - } - - return 1; -} -#if defined(__GNUC__) -#if __GNUC__ >= 4 && __GNUC__MINOR__ < 7 -#pragma GCC diagnostic error "-Woverflow" -#endif -#endif -//------------------------------------------------------------------------------------------------- diff --git a/Code/CryEngine/CryFont/GlyphBitmap.h b/Code/CryEngine/CryFont/GlyphBitmap.h deleted file mode 100644 index 3d04a36cf7..0000000000 --- a/Code/CryEngine/CryFont/GlyphBitmap.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Purpose : Hold a glyph bitmap and blit it to the main texture - -#ifndef CRYINCLUDE_CRYFONT_GLYPHBITMAP_H -#define CRYINCLUDE_CRYFONT_GLYPHBITMAP_H - -#pragma once - - -class CGlyphBitmap -{ -public: - CGlyphBitmap(); - ~CGlyphBitmap(); - - int Create(int iWidth, int iHeight); - int Release(); - - unsigned char* GetBuffer() { return m_pBuffer; }; - - int Blur(int iIterations); - int Scale(float fScaleX, float fScaleY); - - int Clear(); - - int BlitTo8(unsigned char* pBuffer, int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, int iDestY, int iDestWidth); - int BlitTo32(unsigned int* pBuffer, int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, int iDestY, int iDestWidth); - - int BlitScaledTo8(unsigned char* pBuffer, int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, int iDestY, int iDestWidth, int iDestHeight, int iDestBufferWidth); - int BlitScaledTo32(unsigned char* pBuffer, int iSrcX, int iSrcY, int iSrcWidth, int iSrcHeight, int iDestX, int iDestY, int iDestWidth, int iDestHeight, int iDestBufferWidth); - - int GetWidth() { return m_iWidth; } - int GetHeight() { return m_iHeight; } - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(m_pBuffer, m_iWidth * m_iHeight); - } - -private: - - unsigned char* m_pBuffer; - int m_iWidth; - int m_iHeight; -}; - -#endif // CRYINCLUDE_CRYFONT_GLYPHBITMAP_H diff --git a/Code/CryEngine/CryFont/GlyphCache.cpp b/Code/CryEngine/CryFont/GlyphCache.cpp deleted file mode 100644 index 96949009df..0000000000 --- a/Code/CryEngine/CryFont/GlyphCache.cpp +++ /dev/null @@ -1,433 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Purpose: -// - Manage and cache glyphs, retrieving them from the renderer as needed - -#include "CryFont_precompiled.h" - -#if !defined(USE_NULLFONT_ALWAYS) - -#include "GlyphCache.h" -#include "FontTexture.h" - - - -//------------------------------------------------------------------------------------------------- -CGlyphCache::CGlyphCache() - : m_dwUsage(1) - , m_iGlyphBitmapWidth(0) - , m_iGlyphBitmapHeight(0) - , m_pScaleBitmap(0) -{ - m_pCacheTable.clear(); - m_pSlotList.clear(); -} - -//------------------------------------------------------------------------------------------------- -CGlyphCache::~CGlyphCache() -{ -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::Create(int iCacheSize, int iGlyphBitmapWidth, int iGlyphBitmapHeight, int iSmoothMethod, int iSmoothAmount, float sizeRatio) -{ - m_iSmoothMethod = iSmoothMethod; - m_iSmoothAmount = iSmoothAmount; - - m_iGlyphBitmapWidth = iGlyphBitmapWidth; - m_iGlyphBitmapHeight = iGlyphBitmapHeight; - - - if (!CreateSlotList(iCacheSize)) - { - ReleaseSlotList(); - - return 0; - } - - int iScaledGlyphWidth = 0; - int iScaledGlyphHeight = 0; - - switch (m_iSmoothMethod) - { - case FONT_SMOOTH_SUPERSAMPLE: - { - switch (m_iSmoothAmount) - { - case FONT_SMOOTH_AMOUNT_2X: - iScaledGlyphWidth = m_iGlyphBitmapWidth << 1; - iScaledGlyphHeight = m_iGlyphBitmapHeight << 1; - break; - case FONT_SMOOTH_AMOUNT_4X: - iScaledGlyphWidth = m_iGlyphBitmapWidth << 2; - iScaledGlyphHeight = m_iGlyphBitmapHeight << 2; - break; - } - } - break; - } - - if (iScaledGlyphWidth) - { - m_pScaleBitmap = new CGlyphBitmap; - - if (!m_pScaleBitmap) - { - Release(); - - return 0; - } - - if (!m_pScaleBitmap->Create(iScaledGlyphWidth, iScaledGlyphHeight)) - { - Release(); - - return 0; - } - - m_pFontRenderer.SetGlyphBitmapSize(iScaledGlyphWidth, iScaledGlyphHeight, sizeRatio); - } - else - { - m_pFontRenderer.SetGlyphBitmapSize(m_iGlyphBitmapWidth, m_iGlyphBitmapHeight, sizeRatio); - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::Release() -{ - ReleaseSlotList(); - - m_pCacheTable.clear(); - - if (m_pScaleBitmap) - { - m_pScaleBitmap->Release(); - - delete m_pScaleBitmap; - - m_pScaleBitmap = 0; - } - - m_iGlyphBitmapWidth = 0; - m_iGlyphBitmapHeight = 0; - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::LoadFontFromFile(const string& szFileName) -{ - return m_pFontRenderer.LoadFromFile(szFileName); -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::LoadFontFromMemory(unsigned char* pFileBuffer, int iDataSize) -{ - return m_pFontRenderer.LoadFromMemory(pFileBuffer, iDataSize); -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::ReleaseFont() -{ - m_pFontRenderer.Release(); - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::GetGlyphBitmapSize(int* pWidth, int* pHeight) -{ - if (pWidth) - { - *pWidth = m_iGlyphBitmapWidth; - } - - if (pHeight) - { - *pHeight = m_iGlyphBitmapWidth; - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -void CGlyphCache::SetGlyphBitmapSize(int width, int height, float sizeRatio) -{ - m_pFontRenderer.SetGlyphBitmapSize(width, height, sizeRatio); -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::PreCacheGlyph(uint32 cChar, const Vec2i& glyphSize, const CFFont::FontHintParams& fontHintParams) -{ - CCacheTable::iterator pItor = m_pCacheTable.find(GetCacheSlotKey(cChar, glyphSize)); - - if (pItor != m_pCacheTable.end()) - { - pItor->second->dwUsage = m_dwUsage; - - return 1; - } - - CCacheSlot* pSlot = GetLRUSlot(); - - if (!pSlot) - { - return 0; - } - - if (pSlot->dwUsage > 0) - { - UnCacheGlyph(pSlot->cCurrentChar, pSlot->glyphSize); - } - - if (m_pScaleBitmap) - { - int iOffsetMult = 1; - - switch (m_iSmoothAmount) - { - case FONT_SMOOTH_AMOUNT_2X: - iOffsetMult = 2; - break; - case FONT_SMOOTH_AMOUNT_4X: - iOffsetMult = 4; - break; - } - - m_pScaleBitmap->Clear(); - - if (!m_pFontRenderer.GetGlyph(m_pScaleBitmap, &pSlot->iHoriAdvance, &pSlot->iCharWidth, &pSlot->iCharHeight, pSlot->iCharOffsetX, pSlot->iCharOffsetY, 0, 0, cChar, fontHintParams)) - { - return 0; - } - - pSlot->iCharWidth >>= iOffsetMult >> 1; - pSlot->iCharHeight >>= iOffsetMult >> 1; - - m_pScaleBitmap->BlitScaledTo8(pSlot->pGlyphBitmap.GetBuffer(), 0, 0, m_pScaleBitmap->GetWidth(), m_pScaleBitmap->GetHeight(), 0, 0, pSlot->pGlyphBitmap.GetWidth(), pSlot->pGlyphBitmap.GetHeight(), pSlot->pGlyphBitmap.GetWidth()); - } - else - { - if (!m_pFontRenderer.GetGlyph(&pSlot->pGlyphBitmap, &pSlot->iHoriAdvance, &pSlot->iCharWidth, &pSlot->iCharHeight, pSlot->iCharOffsetX, pSlot->iCharOffsetY, 0, 0, cChar, fontHintParams)) - { - return 0; - } - } - - if (m_iSmoothMethod == FONT_SMOOTH_BLUR) - { - pSlot->pGlyphBitmap.Blur(m_iSmoothAmount); - } - - pSlot->dwUsage = m_dwUsage; - pSlot->cCurrentChar = cChar; - pSlot->glyphSize = glyphSize; - - m_pCacheTable.insert(AZStd::pair(GetCacheSlotKey(cChar, glyphSize), pSlot)); - - return 1; -} - -int CGlyphCache::UnCacheGlyph(uint32 cChar, const Vec2i& glyphSize) -{ - CCacheTable::iterator pItor = m_pCacheTable.find(GetCacheSlotKey(cChar, glyphSize)); - - if (pItor != m_pCacheTable.end()) - { - CCacheSlot* pSlot = pItor->second; - - pSlot->Reset(); - - m_pCacheTable.erase(pItor); - - return 1; - } - - return 0; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::GlyphCached(uint32 cChar, const Vec2i& glyphSize) -{ - return (m_pCacheTable.find(GetCacheSlotKey(cChar, glyphSize)) != m_pCacheTable.end()); -} - -//------------------------------------------------------------------------------------------------- -CCacheSlot* CGlyphCache::GetLRUSlot() -{ - unsigned int dwMinUsage = 0xffffffff; - CCacheSlot* pLRUSlot = 0; - CCacheSlot* pSlot; - - CCacheSlotListItor pItor = m_pSlotList.begin(); - - while (pItor != m_pSlotList.end()) - { - pSlot = *pItor; - - if (pSlot->dwUsage == 0) - { - return pSlot; - } - else - { - if (pSlot->dwUsage < dwMinUsage) - { - pLRUSlot = pSlot; - dwMinUsage = pSlot->dwUsage; - } - } - - pItor++; - } - - return pLRUSlot; -} - -//------------------------------------------------------------------------------------------------- -CCacheSlot* CGlyphCache::GetMRUSlot() -{ - unsigned int dwMaxUsage = 0; - CCacheSlot* pMRUSlot = 0; - CCacheSlot* pSlot; - - CCacheSlotListItor pItor = m_pSlotList.begin(); - - while (pItor != m_pSlotList.end()) - { - pSlot = *pItor; - - if (pSlot->dwUsage != 0) - { - if (pSlot->dwUsage > dwMaxUsage) - { - pMRUSlot = pSlot; - dwMaxUsage = pSlot->dwUsage; - } - } - - pItor++; - } - - return pMRUSlot; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::GetGlyph(CGlyphBitmap** pGlyph, int* piHoriAdvance, int* piWidth, int* piHeight, AZ::s32& iCharOffsetX, AZ::s32& iCharOffsetY, uint32 cChar, const Vec2i& glyphSize, const CFFont::FontHintParams& fontHintParams) -{ - CCacheTable::iterator pItor = m_pCacheTable.find(GetCacheSlotKey(cChar, glyphSize)); - - if (pItor == m_pCacheTable.end()) - { - if (!PreCacheGlyph(cChar, glyphSize, fontHintParams)) - { - return 0; - } - } - - pItor = m_pCacheTable.find(GetCacheSlotKey(cChar, glyphSize)); - - pItor->second->dwUsage = m_dwUsage++; - (*pGlyph) = &pItor->second->pGlyphBitmap; - - if (piHoriAdvance) - { - *piHoriAdvance = pItor->second->iHoriAdvance; - } - - if (piWidth) - { - *piWidth = pItor->second->iCharWidth; - } - - if (piHeight) - { - *piHeight = pItor->second->iCharHeight; - } - - iCharOffsetX = pItor->second->iCharOffsetX; - iCharOffsetY = pItor->second->iCharOffsetY; - - return 1; -} - -//------------------------------------------------------------------------------------------------- -Vec2 CGlyphCache::GetKerning(uint32_t leftGlyph, uint32_t rightGlyph) -{ - return m_pFontRenderer.GetKerning(leftGlyph, rightGlyph); -} - -//------------------------------------------------------------------------------------------------- -float CGlyphCache::GetAscenderToHeightRatio() -{ - return m_pFontRenderer.GetAscenderToHeightRatio(); -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::CreateSlotList(int iListSize) -{ - for (int i = 0; i < iListSize; i++) - { - CCacheSlot* pCacheSlot = new CCacheSlot; - - if (!pCacheSlot) - { - return 0; - } - - if (!pCacheSlot->pGlyphBitmap.Create(m_iGlyphBitmapWidth, m_iGlyphBitmapHeight)) - { - delete pCacheSlot; - - return 0; - } - - pCacheSlot->Reset(); - - pCacheSlot->iCacheSlot = i; - - m_pSlotList.push_back(pCacheSlot); - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -int CGlyphCache::ReleaseSlotList() -{ - CCacheSlotListItor pItor = m_pSlotList.begin(); - - while (pItor != m_pSlotList.end()) - { - (*pItor)->pGlyphBitmap.Release(); - - delete (*pItor); - - pItor = m_pSlotList.erase(pItor); - } - - return 1; -} - -//------------------------------------------------------------------------------------------------- -CryFont::GlyphCache::CCacheTableKey CGlyphCache::GetCacheSlotKey(uint32 cChar, const Vec2i& glyphSize) const -{ - const Vec2i clampedGlyphSize = CFontTexture::ClampGlyphSize(glyphSize, m_iGlyphBitmapWidth, m_iGlyphBitmapHeight); - return CryFont::GlyphCache::CCacheTableKey(clampedGlyphSize, cChar); -} - -#endif // #if !defined(USE_NULLFONT_ALWAYS) diff --git a/Code/CryEngine/CryFont/GlyphCache.h b/Code/CryEngine/CryFont/GlyphCache.h deleted file mode 100644 index c0cc1db555..0000000000 --- a/Code/CryEngine/CryFont/GlyphCache.h +++ /dev/null @@ -1,200 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -// Purpose: -// - Manage and cache glyphs, retrieving them from the renderer as needed - -#ifndef CRYINCLUDE_CRYFONT_GLYPHCACHE_H -#define CRYINCLUDE_CRYFONT_GLYPHCACHE_H -#pragma once - -#if !defined(USE_NULLFONT_ALWAYS) - -#include -#include "GlyphBitmap.h" -#include "FontRenderer.h" -#include "CryFont.h" -#include - -//! Glyph cache slots store the bitmap buffer and glyph metadata from FreeType. -//! -//! This bitmap buffer is eventually copied to a CFontTexture texture buffer. -//! A glyph cache slot bitmap buffer only holds a single glyph, whereas the -//! CFontTexture stores multiple glyphs in a grid (row/col) format. -typedef struct CCacheSlot -{ - Vec2i glyphSize = CCryFont::defaultGlyphSize; //!< The render resolution of the glyph in the glyph bitmap - unsigned int dwUsage; - int iCacheSlot; - int iHoriAdvance; //!< Advance width. See FT_Glyph_Metrics::horiAdvance. - uint32 cCurrentChar; - - uint8 iCharWidth; //!< Glyph width (in pixel) - uint8 iCharHeight; //!< Glyph height (in pixel) - AZ::s32 iCharOffsetX; //!< Glyph's left-side bearing (in pixels). See FT_GlyphSlotRec::bitmap_left. - AZ::s32 iCharOffsetY; //!< Glyph's top bearing (in pixels). See FT_GlyphSlotRec::bitmap_top. - - CGlyphBitmap pGlyphBitmap; //!< Contains a buffer storing a copy of the glyph from FreeType - - void Reset() - { - dwUsage = 0; - cCurrentChar = ~0; - - iCharWidth = 0; - iCharHeight = 0; - iCharOffsetX = 0; - iCharOffsetY = 0; - - pGlyphBitmap.Clear(); - } - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(pGlyphBitmap); - } -} CCacheSlot; - -namespace CryFont -{ - namespace GlyphCache - { - //! Height and width pair for glyph size mapping - typedef Vec2i CCacheTableGlyphSizeType; - - //! Pair for mapping a height and width size to a UTF32 character/glyph - typedef AZStd::pair CCacheTableKey; - - //! Hasher for glyph cache table keys (glyphsize-char code pair) - //! - //! Instead of creating our own custom hash, the types are broken down to their - //! native types (ints) and passed to existing hashes that handle those types. - struct HashGlyphCacheTableKey - { - typedef CCacheTableKey ArgumentType; - typedef AZStd::size_t ResultType; - typedef AZStd::pair Int32Pair; - typedef AZStd::pair Int32PairU32Pair; - ResultType operator()(const ArgumentType& value) const - { - AZStd::hash pairHash; - return pairHash(Int32PairU32Pair(Int32Pair(value.first.x, value.first.y), value.second)); - } - }; - } -} - -//! Maps size-speicifc UTF32 glyphs to their corresponding cache slots -typedef AZStd::unordered_map CCacheTable; - -typedef std::vector CCacheSlotList; -typedef std::vector::iterator CCacheSlotListItor; - - -#ifdef WIN64 -#undef GetCharWidth -#undef GetCharHeight -#endif - -//! The glyph cache maps UTF32 codepoints to their corresponding FreeType data. -//! -//! This cache is used to associate font glyph info (read from FreeType) with -//! UTF32 codepoints. Ultimately the glyph info will be read into a font texture -//! (CFontTexture) to avoid future FreeType lookups. -//! -//! If a CFontTexture is missing a glyph that is currently stored in the glyph -//! cache, the cached data can be returned instead of having to be rendered from -//! FreeType again. -//! -//! \sa CFontTexture -class CGlyphCache -{ -public: - CGlyphCache(); - ~CGlyphCache(); - - int Create(int iCacheSize, int iGlyphBitmapWidth, int iGlyphBitmapHeight, int iSmoothMethod, int iSmoothAmount, float sizeRatio); - int Release(); - - int LoadFontFromFile(const string& szFileName); - int LoadFontFromMemory(unsigned char* pFileBuffer, int iDataSize); - int ReleaseFont(); - - int SetEncoding(FT_Encoding pEncoding) { return m_pFontRenderer.SetEncoding(pEncoding); }; - FT_Encoding GetEncoding() { return m_pFontRenderer.GetEncoding(); }; - - int GetGlyphBitmapSize(int* pWidth, int* pHeight); - void SetGlyphBitmapSize(int width, int height, float sizeRatio); - - int PreCacheGlyph(uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize, const CFFont::FontHintParams& glyphFlags = CFFont::FontHintParams()); - int UnCacheGlyph(uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize); - int GlyphCached(uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize); - - CCacheSlot* GetLRUSlot(); - CCacheSlot* GetMRUSlot(); - - //! Obtains glyph information for the given UTF32 codepoint. - //! This information is obtained from a CCacheSlot that corresponds to - //! the given codepoint. If the codepoint doesn't exist within the cache - //! table (m_pCacheTable), then the information is obtain from FreeType - //! directly via CFontRenderer. - //! - //! Ultimately the glyph bitmap is copied into a font texture - //! (CFontTexture). Once the glyph is copied into the font texture then - //! the font texture is referenced directly rather than relying on the - //! glyph cache or FreeType. - //! - //! \sa CFontRenderer::GetGlyph, CFontTexture::UpdateSlot - int GetGlyph(CGlyphBitmap** pGlyph, int* piHoriAdvance, int* piWidth, int* piHeight, AZ::s32& iCharOffsetX, AZ::s32& iCharOffsetY, uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize, const CFFont::FontHintParams& glyphFlags = CFFont::FontHintParams()); - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(m_pSlotList); - //pSizer->AddContainer(m_pCacheTable); - pSizer->AddObject(m_pScaleBitmap); - pSizer->AddObject(m_pFontRenderer); - } - - bool GetMonospaced() const { return m_pFontRenderer.GetMonospaced(); } - - Vec2 GetKerning(uint32_t leftGlyph, uint32_t rightGlyph); - - float GetAscenderToHeightRatio(); - -private: - - //! Returns a key for the cache table where the given char is mapped at the given size. - CryFont::GlyphCache::CCacheTableKey GetCacheSlotKey(uint32 cChar, const Vec2i& glyphSize = CCryFont::defaultGlyphSize) const; - - int CreateSlotList(int iListSize); - int ReleaseSlotList(); - - CCacheSlotList m_pSlotList; - CCacheTable m_pCacheTable; - - int m_iGlyphBitmapWidth; - int m_iGlyphBitmapHeight; - - int m_iSmoothMethod; - int m_iSmoothAmount; - - CGlyphBitmap* m_pScaleBitmap; - - CFontRenderer m_pFontRenderer; - - unsigned int m_dwUsage; -}; - -#endif // #if !defined(USE_NULLFONT_ALWAYS) - -#endif // CRYINCLUDE_CRYFONT_GLYPHCACHE_H diff --git a/Code/CryEngine/CryFont/ICryFont.cpp b/Code/CryEngine/CryFont/ICryFont.cpp deleted file mode 100644 index dfbaf65335..0000000000 --- a/Code/CryEngine/CryFont/ICryFont.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Create the font interface. - - -#include "CryFont_precompiled.h" - -#include -#include -#include - -#include "CryFont.h" -#if defined(USE_NULLFONT) -#include "NullFont.h" -#endif - -////////////////////////////////////////////////////////////////////////// -struct CSystemEventListner_Font - : public ISystemEventListener -{ -public: - virtual void OnSystemEvent(ESystemEvent event, [[maybe_unused]] UINT_PTR wparam, [[maybe_unused]] UINT_PTR lparam) - { - switch (event) - { - case ESYSTEM_EVENT_LEVEL_POST_UNLOAD: - { - STLALLOCATOR_CLEANUP; - break; - } - } - } -}; -static CSystemEventListner_Font g_system_event_listener_font; - -/////////////////////////////////////////////// -extern "C" ICryFont * CreateCryFontInterface(ISystem * pSystem) -{ - ModuleInitISystem(pSystem, "CryFont"); - - if (gEnv->IsDedicated()) - { -#if defined(USE_NULLFONT) - return new CCryNullFont(); -#else - // The NULL font implementation must be present for all platforms - // supporting running as a pure dedicated server. - pSystem->GetILog()->LogError("Missing NULL font implementation for dedicated server"); - return NULL; -#endif - } - else - { -#if defined(USE_NULLFONT) && defined(USE_NULLFONT_ALWAYS) - return new CCryNullFont(); -#else - pSystem->GetISystemEventDispatcher()->RegisterListener(&g_system_event_listener_font); - return new CCryFont(pSystem); -#endif - } -} - -////////////////////////////////////////////////////////////////////////// -class CEngineModule_CryFont - : public IEngineModule -{ - CRYINTERFACE_SIMPLE(IEngineModule) - CRYGENERATE_SINGLETONCLASS(CEngineModule_CryFont, "EngineModule_CryFont", 0x6758643f43214957, 0x9b920d898d31f434) - - ////////////////////////////////////////////////////////////////////////// - virtual const char* GetName() const { - return "CryFont"; - }; - virtual const char* GetCategory() const { return "CryEngine"; }; - - ////////////////////////////////////////////////////////////////////////// - virtual bool Initialize(SSystemGlobalEnvironment& env, [[maybe_unused]] const SSystemInitParams& initParams) - { - ISystem* pSystem = env.pSystem; - env.pCryFont = CreateCryFontInterface(pSystem); - return env.pCryFont != 0; - } -}; - -CRYREGISTER_SINGLETON_CLASS(CEngineModule_CryFont) - -CEngineModule_CryFont::CEngineModule_CryFont() -{ -}; - -CEngineModule_CryFont::~CEngineModule_CryFont() -{ -}; diff --git a/Code/CryEngine/CryFont/NullFont.cpp b/Code/CryEngine/CryFont/NullFont.cpp deleted file mode 100644 index bddca1bbed..0000000000 --- a/Code/CryEngine/CryFont/NullFont.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Dummy font implementation (dedicated server) - -#include "CryFont_precompiled.h" - -#if defined(USE_NULLFONT) - -#include "NullFont.h" - -CNullFont CCryNullFont::ms_nullFont; - -#endif // USE_NULLFONT diff --git a/Code/CryEngine/CryFont/NullFont.h b/Code/CryEngine/CryFont/NullFont.h deleted file mode 100644 index 94fceeb9b0..0000000000 --- a/Code/CryEngine/CryFont/NullFont.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Dummy font implementation (dedicated server) - - -#ifndef CRYINCLUDE_CRYFONT_NULLFONT_H -#define CRYINCLUDE_CRYFONT_NULLFONT_H -#pragma once - - -#if defined(USE_NULLFONT) - -#include - -class CNullFont - : public IFFont -{ -public: - CNullFont() {} - virtual ~CNullFont() {} - - virtual int32 AddRef() { return 0; }; - virtual int32 Release() { return 0; }; - - virtual bool Load([[maybe_unused]] const char* pFontFilePath, [[maybe_unused]] unsigned int width, [[maybe_unused]] unsigned int height, [[maybe_unused]] unsigned int widthNumSlots, [[maybe_unused]] unsigned int heightNumSlots, [[maybe_unused]] unsigned int flags, [[maybe_unused]] float sizeRatio) { return true; } - virtual bool Load([[maybe_unused]] const char* pXMLFile) { return true; } - virtual void Free() {} - - virtual void DrawString([[maybe_unused]] float x, [[maybe_unused]] float y, [[maybe_unused]] const char* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) {} - virtual void DrawString([[maybe_unused]] float x, [[maybe_unused]] float y, [[maybe_unused]] float z, [[maybe_unused]] const char* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) {} - - virtual void DrawStringW([[maybe_unused]] float x, [[maybe_unused]] float y, [[maybe_unused]] const wchar_t* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) {} - virtual void DrawStringW([[maybe_unused]] float x, [[maybe_unused]] float y, [[maybe_unused]] float z, [[maybe_unused]] const wchar_t* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) {} - - virtual Vec2 GetTextSize([[maybe_unused]] const char* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) { return Vec2(0.0f, 0.0f); } - virtual Vec2 GetTextSizeW([[maybe_unused]] const wchar_t* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) { return Vec2(0.0f, 0.0f); } - - virtual size_t GetTextLength([[maybe_unused]] const char* pStr, [[maybe_unused]] const bool asciiMultiLine) const { return 0; } - virtual size_t GetTextLengthW([[maybe_unused]] const wchar_t* pStr, [[maybe_unused]] const bool asciiMultiLine) const { return 0; } - - virtual void WrapText(string& result, [[maybe_unused]] float maxWidth, const char* pStr, [[maybe_unused]] const STextDrawContext& ctx) { result = pStr; } - virtual void WrapTextW(wstring& result, [[maybe_unused]] float maxWidth, const wchar_t* pStr, [[maybe_unused]] const STextDrawContext& ctx) { result = pStr; } - - virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} - - virtual void GetGradientTextureCoord([[maybe_unused]] float& minU, [[maybe_unused]] float& minV, [[maybe_unused]] float& maxU, [[maybe_unused]] float& maxV) const {} - - virtual unsigned int GetEffectId([[maybe_unused]] const char* pEffectName) const { return 0; } - virtual unsigned int GetNumEffects() const { return 0; } - virtual const char* GetEffectName([[maybe_unused]] unsigned int effectId) const { return nullptr; } - virtual Vec2 GetMaxEffectOffset([[maybe_unused]] unsigned int effectId) const { return Vec2(); } - virtual bool DoesEffectHaveTransparency([[maybe_unused]] unsigned int effectId) const { return false; } - - virtual void AddCharsToFontTexture([[maybe_unused]] const char* pChars, [[maybe_unused]] int glyphSizeX, [[maybe_unused]] int glyphSizeY) override {} - virtual Vec2 GetKerning([[maybe_unused]] uint32_t leftGlyph, [[maybe_unused]] uint32_t rightGlyph, [[maybe_unused]] const STextDrawContext& ctx) const override { return Vec2(); } - virtual float GetAscender([[maybe_unused]] const STextDrawContext& ctx) const override { return 0.0f; } - virtual float GetBaseline([[maybe_unused]] const STextDrawContext& ctx) const override { return 0.0f; } - virtual float GetSizeRatio() const override { return IFFontConstants::defaultSizeRatio; } - virtual uint32 GetNumQuadsForText([[maybe_unused]] const char* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) { return 0; } - virtual uint32 WriteTextQuadsToBuffers([[maybe_unused]] SVF_P2F_C4B_T2F_F4B* verts, [[maybe_unused]] uint16* indices, [[maybe_unused]] uint32 maxQuads, [[maybe_unused]] float x, [[maybe_unused]] float y, [[maybe_unused]] float z, [[maybe_unused]] const char* pStr, [[maybe_unused]] const bool asciiMultiLine, [[maybe_unused]] const STextDrawContext& ctx) { return 0; } - virtual int GetFontTextureId() { return -1; } - virtual uint32 GetFontTextureVersion() { return 0; } -}; - -class CCryNullFont - : public ICryFont -{ -public: - virtual void Release() {} - virtual IFFont* NewFont([[maybe_unused]] const char* pFontName) { return &ms_nullFont; } - virtual IFFont* GetFont([[maybe_unused]] const char* pFontName) const { return &ms_nullFont; } - virtual FontFamilyPtr LoadFontFamily([[maybe_unused]] const char* pFontFamilyName) override { CRY_ASSERT(false); return nullptr; } - virtual FontFamilyPtr GetFontFamily([[maybe_unused]] const char* pFontFamilyName) override { CRY_ASSERT(false); return nullptr; } - virtual void AddCharsToFontTextures(FontFamilyPtr pFontFamily, [[maybe_unused]] const char* pChars, [[maybe_unused]] int glyphSizeX, [[maybe_unused]] int glyphSizeY) override {}; - virtual void SetRendererProperties([[maybe_unused]] IRenderer* pRenderer) {} - virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} - virtual string GetLoadedFontNames() const { return ""; } - virtual void OnLanguageChanged() override { } - virtual void ReloadAllFonts() override { } - -private: - static CNullFont ms_nullFont; -}; - -#endif // USE_NULLFONT - -#endif // CRYINCLUDE_CRYFONT_NULLFONT_H diff --git a/Code/CryEngine/CryFont/Platform/Linux/platform_linux.cmake b/Code/CryEngine/CryFont/Platform/Linux/platform_linux.cmake deleted file mode 100644 index bafe20e506..0000000000 --- a/Code/CryEngine/CryFont/Platform/Linux/platform_linux.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -# Platform specific cmake file for configuring target compiler/link properties -# based on the active platform -# NOTE: functions in cmake are global, therefore adding functions to this file -# is being avoided to prevent overriding functions declared in other targets platfrom -# specific cmake files diff --git a/Code/CryEngine/CryFont/cryfont_files.cmake b/Code/CryEngine/CryFont/cryfont_files.cmake deleted file mode 100644 index f46a5b5b44..0000000000 --- a/Code/CryEngine/CryFont/cryfont_files.cmake +++ /dev/null @@ -1,33 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - CryFont.cpp - FFont.cpp - FFontXML.cpp - FontRenderer.cpp - FontTexture.cpp - GlyphBitmap.cpp - GlyphCache.cpp - ICryFont.cpp - NullFont.cpp - CryFont.h - FBitmap.h - FFont.h - FontRenderer.h - FontTexture.h - GlyphBitmap.h - GlyphCache.h - NullFont.h - resource.h - CryFont_precompiled.h - CryFont_precompiled.cpp -) diff --git a/Code/CryEngine/CryFont/resource.h b/Code/CryEngine/CryFont/resource.h deleted file mode 100644 index ed88839421..0000000000 --- a/Code/CryEngine/CryFont/resource.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#define VS_VERSION_INFO 1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/Code/CryEngine/CrySystem/CMakeLists.txt b/Code/CryEngine/CrySystem/CMakeLists.txt index e7816cc1cd..1a5593e5d8 100644 --- a/Code/CryEngine/CrySystem/CMakeLists.txt +++ b/Code/CryEngine/CrySystem/CMakeLists.txt @@ -90,8 +90,6 @@ ly_add_target( AZ::AzCore Legacy::CryCommon Legacy::CryCommon.EngineSettings.Static - RUNTIME_DEPENDENCIES - Legacy::CryFont ) ################################################################################ diff --git a/Code/CryEngine/CrySystem/CPUDetect.cpp b/Code/CryEngine/CrySystem/CPUDetect.cpp index 9af68a1854..6d924a1514 100644 --- a/Code/CryEngine/CrySystem/CPUDetect.cpp +++ b/Code/CryEngine/CrySystem/CPUDetect.cpp @@ -52,11 +52,7 @@ # define cpuid(op, eax, ebx, ecx, edx) __asm__("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (op) : "cc"); #endif -#if defined(AZ_MONOLITHIC_BUILD) -extern int g_CpuFlags; -#else int g_CpuFlags; -#endif struct SAutoMaxPriority { diff --git a/Code/CryEngine/CrySystem/CrySystem_precompiled.h b/Code/CryEngine/CrySystem/CrySystem_precompiled.h index 6cf4c6005a..b446199b4e 100644 --- a/Code/CryEngine/CrySystem/CrySystem_precompiled.h +++ b/Code/CryEngine/CrySystem/CrySystem_precompiled.h @@ -102,7 +102,6 @@ inline int RoundToClosestMB(size_t memSize) #include #include #include -#include #include #include #include @@ -127,7 +126,6 @@ namespace AZ::IO struct IArchive; } struct ICryFont; -struct I3DEngine; struct IMovieSystem; struct IAudioSystem; struct IPhysicalWorld; diff --git a/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp b/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp index 996dee7810..d31f122d9b 100644 --- a/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp +++ b/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp @@ -193,10 +193,6 @@ static void UnloadMap([[maybe_unused]] IConsoleCmdArgs* args) if (gEnv->pSystem && gEnv->pSystem->GetILevelSystem() && !gEnv->IsEditor()) { gEnv->pSystem->GetILevelSystem()->UnloadLevel(); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->LoadEmptyLevel(); - } } } @@ -674,18 +670,6 @@ ILevel* CLevelSystem::LoadLevelInternal(const char* _levelName) pSpamDelay->Set(0.0f); } - if (gEnv->p3DEngine) - { - bool is3DEngineLoaded = gEnv->IsEditor() ? gEnv->p3DEngine->InitLevelForEditor(pLevelInfo->GetPath(), pLevelInfo->m_defaultGameTypeName.c_str()) - : gEnv->p3DEngine->LoadLevel(pLevelInfo->GetPath(), pLevelInfo->m_defaultGameTypeName.c_str()); - if (!is3DEngineLoaded) - { - OnLoadingError(levelName, "3DEngine failed to handle loading the level"); - - return 0; - } - } - // Parse level specific config data. AZStd::string const sLevelNameOnly(PathUtil::GetFileName(levelName)); @@ -760,14 +744,6 @@ ILevel* CLevelSystem::LoadLevelInternal(const char* _levelName) gEnv->pSystem->SetSystemGlobalState(ESYSTEM_GLOBAL_STATE_LEVEL_LOAD_START_PRECACHE); - ////////////////////////////////////////////////////////////////////////// - // Notify 3D engine that loading finished - ////////////////////////////////////////////////////////////////////////// - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->PostLoadLevel(); - } - ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// gEnv->pConsole->SetScrollMax(600 / 2); @@ -991,18 +967,6 @@ void CLevelSystem::UnloadLevel() CTimeValue tBegin = gEnv->pTimer->GetAsyncTime(); - I3DEngine* p3DEngine = gEnv->p3DEngine; - if (p3DEngine) - { - IDeferredPhysicsEventManager* pPhysEventManager = p3DEngine->GetDeferredPhysicsEventManager(); - if (pPhysEventManager) - { - // clear deferred physics queues before renderer, since we could have jobs running - // which access a rendermesh - pPhysEventManager->ClearDeferredEvents(); - } - } - //AM: Flush render thread (Flush is not exposed - using EndFrame()) //We are about to delete resources that could be in use if (gEnv->pRenderer) @@ -1076,25 +1040,10 @@ void CLevelSystem::UnloadLevel() SAFE_RELEASE(m_pCurrentLevel); - /* - Force Lua garbage collection before p3DEngine->UnloadLevel() and pRenderer->FreeResources(flags) are called. - p3DEngine->UnloadLevel() will destroy particle emitters even if they're still referenced by Lua objects that are yet to be collected. - (as per comment in 3dEngineLoad.cpp (line 501) - "Force to clean all particles that are left, even if still referenced."). - Then, during the next GC cycle, Lua finally cleans up, the particle emitter smart pointers will be pointing to invalid memory). - Normally the GC step is triggered at the end of this method (by the ESYSTEM_EVENT_LEVEL_POST_UNLOAD event), which is too late - (after the render resources have been purged). - This extra GC step takes a few ms more level unload time, which is a small price for fixing nasty crashes. - If, however, we wanted to claim it back, we could potentially get rid of the GC step that is triggered by ESYSTEM_EVENT_LEVEL_POST_UNLOAD to break even. - */ - + // Force Lua garbage collection (may no longer be needed now the legacy renderer has been removed). + // Normally the GC step is triggered at the end of this method (by the ESYSTEM_EVENT_LEVEL_POST_UNLOAD event). EBUS_EVENT(AZ::ScriptSystemRequestBus, GarbageCollect); - // Delete engine resources - if (p3DEngine) - { - p3DEngine->UnloadLevel(); - - } // Force to clean render resources left after deleting all objects and materials. IRenderer* pRenderer = gEnv->pRenderer; if (pRenderer) diff --git a/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp b/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp index 67bf0a6c8e..4b6e210522 100644 --- a/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp +++ b/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp @@ -55,10 +55,6 @@ namespace LegacyLevelSystem if (gEnv->pSystem && gEnv->pSystem->GetILevelSystem() && !gEnv->IsEditor()) { gEnv->pSystem->GetILevelSystem()->UnloadLevel(); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->LoadEmptyLevel(); - } } } @@ -262,22 +258,6 @@ namespace LegacyLevelSystem pSpamDelay->Set(0.0f); } - if (gEnv->p3DEngine) - { - AZ::IO::PathView levelPath(levelName); - AZStd::string parentPath(levelPath.ParentPath().Native()); - - static constexpr const char* defaultGameTypeName = "Mission0"; - bool is3DEngineLoaded = gEnv->IsEditor() ? gEnv->p3DEngine->InitLevelForEditor(parentPath.c_str(), defaultGameTypeName) - : gEnv->p3DEngine->LoadLevel(parentPath.c_str(), defaultGameTypeName); - if (!is3DEngineLoaded) - { - OnLoadingError(levelName, "3DEngine failed to handle loading the level"); - - return 0; - } - } - // Parse level specific config data. AZStd::string const sLevelNameOnly(PathUtil::GetFileName(levelName)); @@ -340,14 +320,6 @@ namespace LegacyLevelSystem gEnv->pSystem->SetSystemGlobalState(ESYSTEM_GLOBAL_STATE_LEVEL_LOAD_START_PRECACHE); - ////////////////////////////////////////////////////////////////////////// - // Notify 3D engine that loading finished - ////////////////////////////////////////////////////////////////////////// - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->PostLoadLevel(); - } - ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// gEnv->pConsole->SetScrollMax(600 / 2); @@ -569,18 +541,6 @@ namespace LegacyLevelSystem CTimeValue tBegin = gEnv->pTimer->GetAsyncTime(); - I3DEngine* p3DEngine = gEnv->p3DEngine; - if (p3DEngine) - { - IDeferredPhysicsEventManager* pPhysEventManager = p3DEngine->GetDeferredPhysicsEventManager(); - if (pPhysEventManager) - { - // clear deferred physics queues before renderer, since we could have jobs running - // which access a rendermesh - pPhysEventManager->ClearDeferredEvents(); - } - } - // AM: Flush render thread (Flush is not exposed - using EndFrame()) // We are about to delete resources that could be in use if (gEnv->pRenderer) @@ -644,25 +604,10 @@ namespace LegacyLevelSystem GetISystem()->GetIResourceManager()->UnloadLevel(); - /* - Force Lua garbage collection before p3DEngine->UnloadLevel() and pRenderer->FreeResources(flags) are called. - p3DEngine->UnloadLevel() will destroy particle emitters even if they're still referenced by Lua objects that are yet to be - collected. (as per comment in 3dEngineLoad.cpp (line 501) - "Force to clean all particles that are left, even if still referenced."). - Then, during the next GC cycle, Lua finally cleans up, the particle emitter smart pointers will be pointing to invalid memory). - Normally the GC step is triggered at the end of this method (by the ESYSTEM_EVENT_LEVEL_POST_UNLOAD event), which is too late - (after the render resources have been purged). - This extra GC step takes a few ms more level unload time, which is a small price for fixing nasty crashes. - If, however, we wanted to claim it back, we could potentially get rid of the GC step that is triggered by - ESYSTEM_EVENT_LEVEL_POST_UNLOAD to break even. - */ - + // Force Lua garbage collection (may no longer be needed now the legacy renderer has been removed). + // Normally the GC step is triggered at the end of this method (by the ESYSTEM_EVENT_LEVEL_POST_UNLOAD event). EBUS_EVENT(AZ::ScriptSystemRequestBus, GarbageCollect); - // Delete engine resources - if (p3DEngine) - { - p3DEngine->UnloadLevel(); - } // Force to clean render resources left after deleting all objects and materials. IRenderer* pRenderer = gEnv->pRenderer; if (pRenderer) diff --git a/Code/CryEngine/CrySystem/PerfHUD.cpp b/Code/CryEngine/CrySystem/PerfHUD.cpp index 23a5fc0ced..2aeabe2650 100644 --- a/Code/CryEngine/CrySystem/PerfHUD.cpp +++ b/Code/CryEngine/CrySystem/PerfHUD.cpp @@ -22,7 +22,6 @@ #include "MiniGUI/MiniMenu.h" #include "MiniGUI/MiniTable.h" #include -#include #include #include "System.h" @@ -853,21 +852,6 @@ void CPerfHUD::SaveStatsCallback([[maybe_unused]] void* data, [[maybe_unused]] b // RENDER CALLBACKS ////////////////////////////////////////////////////////////////////////// -/* -void CPerfHUD::DisplayRenderInfoCallback(const Rect& rect) -{ - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface( cryiidof(),pGUI )) - { - //right aligned display - float x = rect.right; - float y = rect.top; - float step = 13.f; - - gEnv->p3DEngine->DisplayInfo(x, y, step, true); - } -}*/ - void CPerfHUD::EnableWidget(ICryPerfHUDWidget::EWidgetID id, int mode) { const int nWidgets = m_widgets.size(); @@ -1530,26 +1514,6 @@ void CRenderStatsWidget::Update() m_runtimeData.nFwdLights = 0; m_runtimeData.nFwdShadowLights = 0; - ////////////////////////////////////////////////////////////////////////// - if (gEnv->p3DEngine) - { - I3DEngine::SObjectsStreamingStatus objStats; - gEnv->p3DEngine->GetObjectsStreamingStatus(objStats); - - float fMeshRequiredMB = (float)(objStats.nMemRequired) / (1024 * 1024); - sprintf_s(entryBuffer, "Mesh Required: %.2f (%dMB)", fMeshRequiredMB, azlossy_cast(objStats.nMeshPoolSize)); - if (fMeshRequiredMB < objStats.nMeshPoolSize) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "Too Many Geometry: %.2fMB", fMeshRequiredMB); - } - } - - ////////////////////////////////////////////////////////////////////////// if (gEnv->pRenderer) { @@ -1727,25 +1691,6 @@ CStreamingStatsWidget::CStreamingStatsWidget(IMiniCtrl* pParentMenu, ICryPerfHUD ////////////////////////////////////////////////////////////////////////// void CStreamingStatsWidget::Update() { - char entryBuffer[CMiniInfoBox::MAX_TEXT_LENGTH] = {0}; - - //Clear old entries - m_pInfoBox->ClearEntries(); - - I3DEngine::SObjectsStreamingStatus objStats; - gEnv->p3DEngine->GetObjectsStreamingStatus(objStats); - - float fMeshRequiredMB = (float)(objStats.nMemRequired) / (1024 * 1024); - sprintf_s(entryBuffer, "Mesh Required: %.2f (%dMB)", fMeshRequiredMB, objStats.nMeshPoolSize); - if (fMeshRequiredMB < objStats.nMeshPoolSize) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "Too Many Geometry: %.2fMB", fMeshRequiredMB); - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/CryEngine/CrySystem/Statistics/LocalMemoryUsage.cpp b/Code/CryEngine/CrySystem/Statistics/LocalMemoryUsage.cpp deleted file mode 100644 index 7eb86de966..0000000000 --- a/Code/CryEngine/CrySystem/Statistics/LocalMemoryUsage.cpp +++ /dev/null @@ -1,1389 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Visual helper for checking a local memory usage on maps - -/* - TODO: - - Procedural vegetation - - - Permanent mip-map problem (streaming will collect a permanent mip-maps when travelling) - - ? Foliage render nodes - - must make a decision about the local / global problem: - - Particle effects (must check the calculation) - - Characters (calculation is DONE) - - - StatObj LOD streaming (I think that there is no LOD streaming, but i'm not sure about this) - - Terrain texture streaming (not detail textures!) //It's not needed because this system using a fix-size pool - - Animation streaming: completely different system, not need to measure now - - IsoMesh streaming: completely different system, not need to measure now -*/ - - -#include "CrySystem_precompiled.h" - -#include "LocalMemoryUsage.h" - -#include -#include -#include -#include - -#include - -//#define MAX_LODS 6 // I want an engine-wide const :-( -#define MAX_SLOTS 100 // GetSlotCount() is not working :-( -#define BIG_NUMBER 1e20f - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -namespace LocalMemoryUsageDrawHelper -{ - enum eDrawRectParams - { - DSP_YDIR = 0, - DSP_XDIR = 1, - DSP_REVERSE_TRIANGLES = 2, - DSP_REVERSE_ARROW = 4, - }; - - void DrawRect(IRenderer* pRenderer, const CCamera* camera, const Vec3& p1, const Vec3& p3, const ColorB& color, int params = 0) - { - Vec3 p2, p4, projectedPos; - if (!(params & DSP_REVERSE_TRIANGLES)) - { - if (params & DSP_XDIR) - { - p2 = Vec3(p1.x, p3.y, p1.z); - p4 = Vec3(p3.x, p1.y, p3.z); - } - else - { - p2 = Vec3(p1.x, p3.y, p3.z); - p4 = Vec3(p3.x, p1.y, p1.z); - } - } - else - { - if (params & DSP_XDIR) - { - p4 = Vec3(p1.x, p3.y, p1.z); - p2 = Vec3(p3.x, p1.y, p3.z); - } - else - { - p4 = Vec3(p1.x, p3.y, p3.z); - p2 = Vec3(p3.x, p1.y, p1.z); - } - } - - if (camera->Project(p1, projectedPos) || camera->Project(p2, projectedPos) || camera->Project(p3, projectedPos) || camera->Project(p4, projectedPos)) - { - IRenderAuxGeom* pRenderAuxGeom = pRenderer->GetIRenderAuxGeom(); - - pRenderAuxGeom->DrawTriangle(p1, color, p2, color, p3, color); - pRenderAuxGeom->DrawTriangle(p3, color, p4, color, p1, color); - } - } - - void DrawArrow(IRenderer* pRenderer, const CCamera* camera, Vec3 pStart, Vec3 pEnd, float width, float head, float lengthSub, const ColorB& color, int params = 0) - { - Vec3 p1, p2, p3, p4, p5, p6, p7, projectedPos; - - if (params & DSP_REVERSE_ARROW) - { - std::swap(pStart, pEnd); - } - - Vec3 vParallel((pEnd - pStart).GetNormalized()); - Vec3 vOrto = vParallel.Cross(Vec3(0, 0, 1)).GetNormalized(); - pStart += vParallel * lengthSub; - pEnd -= vParallel * lengthSub; - - p1 = pStart - (vOrto * width * 0.5f); - p2 = pStart + (vOrto * width * 0.5f); - p3 = (pEnd - vParallel * head) - (vOrto * width * 0.5f); - p4 = (pEnd - vParallel * head) + (vOrto * width * 0.5f); - p5 = (pEnd - vParallel * head * 1.5f) - (vOrto * head * 0.9f); - p6 = (pEnd - vParallel * head * 1.5f) + (vOrto * head * 0.9f); - p7 = pEnd; - - if (camera->Project(p1, projectedPos) || camera->Project(p7, projectedPos)) - { - IRenderAuxGeom* pRenderAuxGeom = pRenderer->GetIRenderAuxGeom(); - - pRenderAuxGeom->DrawTriangle(p1, color, p2, color, p4, color); - pRenderAuxGeom->DrawTriangle(p4, color, p3, color, p1, color); - pRenderAuxGeom->DrawTriangle(p3, color, p4, color, p7, color); - pRenderAuxGeom->DrawTriangle(p4, color, p6, color, p7, color); - pRenderAuxGeom->DrawTriangle(p5, color, p3, color, p7, color); - } - } - - #define DRAWHELPER_CIRCLE_POINT_NR 32 - - - static Vec3 s_CirclePoints[DRAWHELPER_CIRCLE_POINT_NR + 1]; - static bool s_CircleDataInited = false; - void InitCircleData() - { - s_CircleDataInited = true; - float angleDiff = 2.0f * 3.1415927f / DRAWHELPER_CIRCLE_POINT_NR; - - for (int i = 0; i < DRAWHELPER_CIRCLE_POINT_NR + 1; i++) - { - s_CirclePoints[i] = Vec3(cos(i * angleDiff), sin(i * angleDiff), 0.0f); - } - } - - void DrawCircle(IRenderer* pRenderer, [[maybe_unused]] const CCamera* camera, const Vec3& origo, float radius, float ratio, const ColorB& color1, const ColorB& color2) - { - if (!s_CircleDataInited) - { - InitCircleData(); - } - float radius2 = radius * 0.90f; - - IRenderAuxGeom* pRenderAuxGeom = pRenderer->GetIRenderAuxGeom(); - - Vec3 oldPoint = origo + s_CirclePoints[0] * radius; - Vec3 oldPoint2 = origo + s_CirclePoints[0] * radius2; - - for (int i = 0; i < DRAWHELPER_CIRCLE_POINT_NR; i++) - { - Vec3 newPoint = origo + s_CirclePoints[i + 1] * radius; - Vec3 newPoint2 = origo + s_CirclePoints[i + 1] * radius2; - if (i < ratio * DRAWHELPER_CIRCLE_POINT_NR) - { - pRenderAuxGeom->DrawTriangle(origo, color1, oldPoint, color1, newPoint, color1); - } - else - { - //pRenderAuxGeom->DrawTriangle( origo, color2, oldPoint, color2, newPoint, color2 ); - pRenderAuxGeom->DrawTriangle(oldPoint2, color2, oldPoint, color2, newPoint, color2); - pRenderAuxGeom->DrawTriangle(newPoint, color2, newPoint2, color2, oldPoint2, color2); - } - oldPoint = newPoint; - oldPoint2 = newPoint2; - } - } -} - -/* -namespace Distance -{ - // Distance: AABB_AABB - //---------------------------------------------------------------------------------- - // Calculate the closest distance of a AABB to an another AABB in 3d-space. - // The function returns the squared distance. - // optionally the closest point on the hull is calculated - // - // Example: - // float result = Distance::Point_AABBSq( aabb1, aabb2 ); - //---------------------------------------------------------------------------------- - - ILINE float AABB_AABBSq( const AABB& aabb1, const AABB& aabb2 ) - { - float fDist2 = 0; - for(int i=0; i<3; ++i) - { - float max1 = aabb1.max[i]; - if(max1 < aabb2.min[i]) - { - fDist2 += sqr(max1-aabb2.min[i]); - } - else - { - float min1 = aabb1.min[i]; - if(min1 > aabb2.max[i]) - { - fDist2 += sqr(aabb2.max[i]-min1); - } - } - } - return fDist2; - } - - // Distance: AABB_AABB_2D - //---------------------------------------------------------------------------------- - // Calculate the closest distance of a AABB to an another AABB in 2d-space. - // The function returns the squared distance. - // optionally the closest point on the hull is calculated - // - // Example: - // float result = Distance::AABB_AABB2DSq( aabb1, aabb2 ); - //---------------------------------------------------------------------------------- - - ILINE float AABB_AABB2DSq( const AABB& aabb1, const AABB& aabb2 ) - { - float fDist2 = 0; - for(int i=0; i<2; ++i) //We are using only 2 of the dimensions! - { - float max1 = aabb1.max[i]; - if(max1 < aabb2.min[i]) - { - fDist2 += sqr(max1-aabb2.min[i]); - } - else - { - float min1 = aabb1.min[i]; - if(min1 > aabb2.max[i]) - { - fDist2 += sqr(aabb2.max[i]-min1); - } - } - } - return fDist2; - } -} -*/ - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -int CLocalMemoryUsage::SResource::m_arrMemoryUsage[LOCALMEMORY_SECTOR_PER_PASS]; -int CLocalMemoryUsage::SResource::m_arrPieces[LOCALMEMORY_SECTOR_PER_PASS]; - - -CLocalMemoryUsage::SResource::SResource() -{ - m_used = true; -} - -void CLocalMemoryUsage::SResource::Init(CLocalMemoryUsage* pLocalMemoryUsage) -{ - m_pLocalMemoryUsage = pLocalMemoryUsage; - - StartChecking(); -} - -void CLocalMemoryUsage::SResource::StartChecking() -{ - const RectI& actProcessedSectors = m_pLocalMemoryUsage->m_actProcessedSectors; - - float* pMipFactor = m_arrMipFactor; - for (int i = 0; i < actProcessedSectors.w * actProcessedSectors.h; i++) - { - *pMipFactor = BIG_NUMBER; - pMipFactor++; - } - bool* pRowDirty = m_arrRowDirty; - for (int i = 0; i < LOCALMEMORY_SECTOR_PER_PASS; i++) - { - *pRowDirty = false; - pRowDirty++; - } -} - -void CLocalMemoryUsage::SResource::CheckOnAllSectorsP1(const AABB& bounding, float maxViewDist, float scale, float mipFactor) -{ - //FRAME_PROFILER("! CLocalMemoryUsage::SResource::CheckOnAllSectorsP1", GetISystem(), PROFILE_SYSTEM); - - float modifiedmaxViewDist = maxViewDist; - float modifiedmaxViewDistSqr = sqr(modifiedmaxViewDist); - - const RectI& actProcessedSectors = m_pLocalMemoryUsage->m_actProcessedSectors; - - int xMin = (int)max(0, int((bounding.min.x - modifiedmaxViewDist) / LOCALMEMORY_SECTOR_SIZE ) - actProcessedSectors.x); - int xMax = (int)min(actProcessedSectors.w, int((bounding.max.x + modifiedmaxViewDist) / LOCALMEMORY_SECTOR_SIZE + 1) - actProcessedSectors.x); - int yMin = (int)max(0, int((bounding.min.y - modifiedmaxViewDist) / LOCALMEMORY_SECTOR_SIZE ) - actProcessedSectors.y); - int yMax = (int)min(actProcessedSectors.h, int((bounding.max.y + modifiedmaxViewDist) / LOCALMEMORY_SECTOR_SIZE + 1) - actProcessedSectors.y); - - AABB sectorBounding(AABB::RESET); - float sectorDistanceSqr; - float fDistYSqr; - - for (int y = yMin; y < yMax; y++) - { - float* pMipFactor = &m_arrMipFactor[actProcessedSectors.w * y + xMin]; - - sectorBounding.min.y = (y + actProcessedSectors.y) * LOCALMEMORY_SECTOR_SIZE; - sectorBounding.max.y = sectorBounding.min.y + LOCALMEMORY_SECTOR_SIZE; - sectorBounding.min.x = (xMin + actProcessedSectors.x) * LOCALMEMORY_SECTOR_SIZE; - - assert(y < LOCALMEMORY_SECTOR_PER_PASS); - m_arrRowDirty[y] = true; - - //Calculating Y distance sqr - { - fDistYSqr = 0; - if (bounding.max.y < sectorBounding.min.y) - { - fDistYSqr += sqr(bounding.max.y - sectorBounding.min.y); - } - else - { - if (bounding.min.y > sectorBounding.max.y) - { - fDistYSqr += sqr(sectorBounding.max.y - bounding.min.y); - } - } - } - - for (int x = xMin; x < xMax; x++) - { - sectorBounding.max.x = sectorBounding.min.x + LOCALMEMORY_SECTOR_SIZE; - - //sectorDistanceSqr = Distance::AABB_AABB2DSq(bounding, sectorBounding); - - //Adding X distance sqr - { - sectorDistanceSqr = fDistYSqr; - if (bounding.max.x < sectorBounding.min.x) - { - sectorDistanceSqr += sqr(bounding.max.x - sectorBounding.min.x); - } - else - { - if (bounding.min.x > sectorBounding.max.x) - { - sectorDistanceSqr += sqr(sectorBounding.max.x - bounding.min.x); - } - } - } - - if (sectorDistanceSqr < modifiedmaxViewDistSqr) - { - *pMipFactor = min(*pMipFactor, sectorDistanceSqr * scale * scale * mipFactor); - } - - pMipFactor++; - - sectorBounding.min.x = sectorBounding.max.x; - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -CLocalMemoryUsage::STextureInfo::STextureInfo() -{ - m_pTexture = NULL; - - //m_size = 0; - //m_xSize = 0; - //m_ySize = 0; - //m_numMips = 0; -} - -CLocalMemoryUsage::STextureInfo::~STextureInfo() -{ - if (m_pTexture) - { - m_pTexture->Release(); - } -} - -void CLocalMemoryUsage::STextureInfo::CheckOnAllSectorsP2() -{ - int x, y, nMip, nStreamableMipNr, memoryUsage, xOldMemoryUsage, xOldPieces; - bool nonZero; - ITexture* pTexture; - - const RectI& actProcessedSectors = m_pLocalMemoryUsage->m_actProcessedSectors; - - bool wasDirty = false; - for (y = 0; y < actProcessedSectors.h; y++) - { - int* pMemoryUsage = m_arrMemoryUsage; - int* pPieces = m_arrPieces; - if (m_arrRowDirty[y] || (wasDirty)) - { - SSector* sector = &m_pLocalMemoryUsage->m_arrSectors[(y + actProcessedSectors.y) * LOCALMEMORY_SECTOR_NR_X + actProcessedSectors.x]; - float* pMipFactor = &m_arrMipFactor[y * actProcessedSectors.w ]; - xOldMemoryUsage = 0; - xOldPieces = 0; - for (x = 0; x < actProcessedSectors.w; x++) - { - nonZero = (*pMipFactor != BIG_NUMBER); - if (nonZero) // One more row - { - pTexture = m_pTexture; - if (!nonZero) - { - memoryUsage = 0; - nStreamableMipNr = 0; - } - else - { - nMip = max(0, pTexture->StreamCalculateMipsSigned(*pMipFactor)); - memoryUsage = pTexture->GetStreamableMemoryUsage(nMip); - nStreamableMipNr = pTexture->GetStreamableMipNumber() - nMip; - } - - sector->m_memoryUsage_Textures += memoryUsage; - - xOldMemoryUsage = memoryUsage; - *pMemoryUsage = memoryUsage; - xOldPieces = nStreamableMipNr; - *pPieces = nStreamableMipNr; - } - else - { - xOldMemoryUsage = 0; - *pMemoryUsage = 0; - xOldPieces = 0; - *pPieces = 0; - } - sector++; - pMipFactor++; - pMemoryUsage++; - pPieces++; - } - wasDirty = m_arrRowDirty[y]; - } - else - { - for (x = 0; x < actProcessedSectors.w; x++) - { - *pMemoryUsage = 0; - pMemoryUsage++; - *pPieces = 0; - pPieces++; - } - wasDirty = false; - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -CLocalMemoryUsage::SMaterialInfo::SMaterialInfo() -{ -} - -void CLocalMemoryUsage::SMaterialInfo::AddTextureInfo(STextureInfoAndTilingFactor textureInfo) -{ - m_textures.push_back(textureInfo); -} - -void CLocalMemoryUsage::SMaterialInfo::CheckOnAllSectorsP2() -{ - int x, y; - - const RectI& actProcessedSectors = m_pLocalMemoryUsage->m_actProcessedSectors; - - for (y = 0; y < actProcessedSectors.h; y++) - { - if (m_arrRowDirty[y]) - { - float* pMipFactor = &m_arrMipFactor[y * actProcessedSectors.w ]; - for (x = 0; x < actProcessedSectors.w; x++) - { - if (*pMipFactor != BIG_NUMBER) - { - //(Spidy) Send the material MinDistance values to textures - for (TTextureVector::iterator it = m_textures.begin(); it != m_textures.end(); ++it) - { - STextureInfoAndTilingFactor& textureInfo = *it; - textureInfo.m_pTextureInfo->m_arrRowDirty[y] = true; - - float& textureMipFactor = textureInfo.m_pTextureInfo->m_arrMipFactor[actProcessedSectors.w * y + x]; - textureMipFactor = min(textureMipFactor, *pMipFactor * textureInfo.m_tilingFactor); - } - } - pMipFactor++; - } - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -CLocalMemoryUsage::SStatObjInfo::SStatObjInfo() -{ - m_streamableContentMemoryUsage = 0; - - m_bSubObject = false; - /* - m_lodNr = 0; - m_vertices = 0; - m_indices = 0; - m_meshSize = 0; - m_physProxySize = 0; - m_physPrimitives = 0; - for( int i=0; i < MAX_LODS; i++) - { - m_indicesPerLod[i]=0; - } - */ -} - -void CLocalMemoryUsage::SStatObjInfo::CheckOnAllSectorsP2() -{ - int x, y, memoryUsage, pieces, xOldMemoryUsage, xOldPieces; - bool nonZero; - - const RectI& actProcessedSectors = m_pLocalMemoryUsage->m_actProcessedSectors; - - bool wasDirty = false; - for (y = 0; y < actProcessedSectors.h; y++) - { - int* pMemoryUsage = m_arrMemoryUsage; - int* pPieces = m_arrPieces; - if (m_arrRowDirty[y]) - { - SSector* sector = &m_pLocalMemoryUsage->m_arrSectors[(y + actProcessedSectors.y) * LOCALMEMORY_SECTOR_NR_X + actProcessedSectors.x]; - float* pMipFactor = &m_arrMipFactor[y * actProcessedSectors.w ]; - xOldMemoryUsage = 0; - xOldPieces = 0; - for (x = 0; x < actProcessedSectors.w; x++) - { - nonZero = (*pMipFactor != BIG_NUMBER); - if (nonZero) // One more row - { - /* - memoryUsage = 0; - float minDistance = sqrt_tpl(minDistanceSqr); - CStatObj* pStatObj = (CStatObj*)(m_pStatObj.get()); //(Spidy) Huh... - - //Iterate on all subobjects, like CStatObj::UpdateStreamableComponents - float fSubObjectScale = 1.0f; - //float fSubObjectScale = matSubObject.GetColumn0().GetLength(); //TODO - int lod = pStatObj->GetLodFromScale(1.0f, fSubObjectScale, minDistance, false); - //(Spidy) az objMatrix scale es a fLodRatioNorm mar bele vannak szamolva a minDistance-ba! - memoryUsage = m_streamableContentMemoryUsage; - */ - memoryUsage = m_streamableContentMemoryUsage; - pieces = 1; - - if (!nonZero) - { - memoryUsage = 0; - pieces = 0; - } - - sector->m_memoryUsage_Geometry += memoryUsage; - - xOldMemoryUsage = memoryUsage; - *pMemoryUsage = memoryUsage; - xOldPieces = pieces; - *pPieces = pieces; - } - else - { - xOldMemoryUsage = 0; - *pMemoryUsage = 0; - xOldPieces = 0; - *pPieces = 0; - } - sector++; - pMipFactor++; - pMemoryUsage++; - pPieces++; - } - wasDirty = m_arrRowDirty[y]; - } - else - { - for (x = 0; x < actProcessedSectors.w; x++) - { - *pMemoryUsage = 0; - pMemoryUsage++; - *pPieces = 0; - pPieces++; - } - wasDirty = false; - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -CLocalMemoryUsage::SSector::SSector() -{ - StartChecking(); -} - -void CLocalMemoryUsage::SSector::StartChecking() -{ - m_memoryUsage_Textures = 0; - m_memoryUsage_Geometry = 0; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -CLocalMemoryUsage::CLocalMemoryUsage() -{ - REGISTER_CVAR(sys_LocalMemoryTextureLimit, 64, VF_NULL, "LocalMemoryUsage tool: Set the texture memory limit to check streaming (Mb/sec)"); - REGISTER_CVAR(sys_LocalMemoryGeometryLimit, 32, VF_NULL, "LocalMemoryUsage tool: Set the statobj geometry memory limit to check streaming (Mb/sec)"); - REGISTER_CVAR(sys_LocalMemoryTextureStreamingSpeedLimit, 10, VF_NULL, "LocalMemoryUsage tool: Texture streaming speed limit (approx, Mb/sec)"); - REGISTER_CVAR(sys_LocalMemoryGeometryStreamingSpeedLimit, 10, VF_NULL, "LocalMemoryUsage tool: Stat object geometry streaming speed limit (approx, Mb/sec)"); - - REGISTER_CVAR(sys_LocalMemoryWarningRatio, 0.8f, VF_NULL, "LocalMemoryUsage tool: Warning ratio for streaming"); - REGISTER_CVAR(sys_LocalMemoryOuterViewDistance, 500.f, VF_NULL, "LocalMemoryUsage tool: View distance for debug draw"); - REGISTER_CVAR(sys_LocalMemoryInnerViewDistance, 100.f, VF_NULL, "LocalMemoryUsage tool: View distance for detailed debug draw"); - - REGISTER_CVAR(sys_LocalMemoryStreamingSpeedObjectLength, 10.f, VF_NULL, "LocalMemoryUsage tool: Length of the streaming speed debug object"); - REGISTER_CVAR(sys_LocalMemoryStreamingSpeedObjectWidth, 1.5f, VF_NULL, "LocalMemoryUsage tool: Width of the streaming speed debug object"); - REGISTER_CVAR(sys_LocalMemoryObjectWidth, 6.f, VF_NULL, "LocalMemoryUsage tool: Width of the streaming buffer debug object"); - REGISTER_CVAR(sys_LocalMemoryObjectHeight, 2.f, VF_NULL, "LocalMemoryUsage tool: Height of the streaming buffer debug object"); - REGISTER_CVAR(sys_LocalMemoryObjectAlpha, 128, VF_NULL, "LocalMemoryUsage tool: Color alpha of the debug objects"); - - REGISTER_CVAR(sys_LocalMemoryDiagramWidth, 0.5f, VF_NULL, "LocalMemoryUsage tool: Width of the diagrams OBSOLATE"); - - REGISTER_CVAR(sys_LocalMemoryDiagramRadius, 2.5f, VF_NULL, "LocalMemoryUsage tool: Radius of the diagram"); - REGISTER_CVAR(sys_LocalMemoryDiagramDistance, -5.5f, VF_NULL, "LocalMemoryUsage tool: Distance of the diagram from the main debug object"); - REGISTER_CVAR(sys_LocalMemoryDiagramStreamingSpeedRadius, 1.0f, VF_NULL, "LocalMemoryUsage tool: Radius of the streaming speed diagram"); - REGISTER_CVAR(sys_LocalMemoryDiagramStreamingSpeedDistance, 2.2f, VF_NULL, "LocalMemoryUsage tool: Distance of the streaming speed diagram from the streaming speed debug line"); - REGISTER_CVAR(sys_LocalMemoryDiagramAlpha, 255, VF_NULL, "LocalMemoryUsage tool: Color alpha of the diagrams"); - - REGISTER_CVAR(sys_LocalMemoryDrawText, 0, VF_NULL, "LocalMemoryUsage tool: If != 0, it will draw the numeric values"); - REGISTER_CVAR(sys_LocalMemoryLogText, 0, VF_NULL, "LocalMemoryUsage tool: If != 0, it will log the numeric values"); - - REGISTER_CVAR(sys_LocalMemoryOptimalMSecPerSec, 100, VF_NULL, "LocalMemoryUsage tool: Optimal calculation time (MSec) per secundum"); - REGISTER_CVAR(sys_LocalMemoryMaxMSecBetweenCalls, 1000, VF_NULL, "LocalMemoryUsage tool: Maximal time difference (MSec) between calls"); - - m_pStreamCgfPredicitionDistance = 0; - m_pDebugDraw = 0; - if (gEnv->pConsole) - { - m_pStreamCgfPredicitionDistance = gEnv->pConsole->GetCVar("e_StreamCgfPredicitionDistance"); - m_pDebugDraw = gEnv->pConsole->GetCVar("e_DebugDraw"); - } - - m_sectorNr.zero(); - - m_actProcessedSectors = RectI(0, 0, 0, 0); - m_actDrawedSectors = RectI(0, 0, 0, 0); - - m_AverageUpdateTime = 0.01f; - - m_sectorNr.x = LOCALMEMORY_SECTOR_NR_X; //TODO Check size of the world - m_sectorNr.y = LOCALMEMORY_SECTOR_NR_Y; -} - -CLocalMemoryUsage::~CLocalMemoryUsage() -{ - DeleteGlobalData(); -} - -void CLocalMemoryUsage::DeleteGlobalData() -{ - m_globalTextures.clear(); - m_globalMaterials.clear(); - m_globalStatObjs.clear(); -} - -void CLocalMemoryUsage::OnRender(IRenderer* pRenderer, const CCamera* camera) -{ - if (!m_pDebugDraw || (m_pDebugDraw->GetIVal() != 17)) - { - return; - } - - const Matrix34& mat = camera->GetMatrix(); - Vec3 pos; - Vec3 projectedPos; - SSector* sector; - - SAuxGeomRenderFlags auxGeomRenderFlagsClose(e_Mode3D | e_AlphaBlended | e_DrawInFrontOn | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOff); - SAuxGeomRenderFlags auxGeomRenderFlagsFar(e_Mode3D | e_AlphaBlended | e_DrawInFrontOff | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOn); - - IRenderAuxGeom* pRenderAuxGeom = pRenderer->GetIRenderAuxGeom(); - - Vec3 cameraPos = mat.GetTranslation(); - - int xMin = max(0, int((cameraPos.x - sys_LocalMemoryOuterViewDistance) / LOCALMEMORY_SECTOR_SIZE)); - int xMax = min(LOCALMEMORY_SECTOR_PER_PASS - 1, int((cameraPos.x + sys_LocalMemoryOuterViewDistance) / LOCALMEMORY_SECTOR_SIZE + 1)); - int yMin = max(0, int((cameraPos.y - sys_LocalMemoryOuterViewDistance) / LOCALMEMORY_SECTOR_SIZE)); - int yMax = min(LOCALMEMORY_SECTOR_PER_PASS - 1, int((cameraPos.y + sys_LocalMemoryOuterViewDistance) / LOCALMEMORY_SECTOR_SIZE + 1)); - m_actDrawedSectors.x = xMin; - m_actDrawedSectors.y = yMin; - m_actDrawedSectors.w = xMax - xMin + 1; - m_actDrawedSectors.h = yMax - yMin + 1; - - CTimeValue actTime = gEnv->pTimer->GetAsyncTime(); - float timeSin = sin_tpl(actTime.GetSeconds() * 10.0f) * 0.5f + 0.5f; - - ColorB color; - ColorB colorOK(LOCALMEMORY_COLOR_OK, sys_LocalMemoryObjectAlpha); - ColorB colorWarning(LOCALMEMORY_COLOR_WARNING, sys_LocalMemoryObjectAlpha); - ColorB colorError(LOCALMEMORY_COLOR_ERROR, uint8(sys_LocalMemoryObjectAlpha * timeSin)); - ColorB colorTexture(LOCALMEMORY_COLOR_TEXTURE, sys_LocalMemoryDiagramAlpha); - ColorB colorGeometry(LOCALMEMORY_COLOR_GEOMETRY, sys_LocalMemoryDiagramAlpha); - ColorB colorBlack(LOCALMEMORY_COLOR_BLACK); - f32 fColorOK[4] = {LOCALMEMORY_FCOLOR_OK, 1}; - f32 fColorWarning[4] = {LOCALMEMORY_FCOLOR_WARNING, 1}; - f32 fColorError[4] = {LOCALMEMORY_FCOLOR_ERROR, 1}; - f32 fColorOther[4] = {LOCALMEMORY_FCOLOR_OTHER, 1}; - - f32* pColor; - Vec3 v0, v1, v2, v3, v4, vTextureDiagram, vTextureDiagram2, vGeometryDiagram, vGeometryDiagram2; - - float localMemoryTextureLimit = sys_LocalMemoryTextureLimit * 1024.f * 1024.f; - float localMemoryGeometryLimit = sys_LocalMemoryGeometryLimit * 1024.f * 1024.f; - - //The assumption is that this is called on Main Thread, otherwise the loop - //Should be wrapped inside a EnumerateHandlers lambda. - auto terrain = AzFramework::Terrain::TerrainDataRequestBus::FindFirstHandler(); - const float defaultTerrainHeight = AzFramework::Terrain::TerrainDataRequests::GetDefaultTerrainHeight(); - - for (int y = yMin; y < yMax; y++) - { - sector = &m_arrSectors[xMin + y * LOCALMEMORY_SECTOR_NR_X]; - for (int x = xMin; x < xMax; x++) - { - pos.x = (x + 0.5f) * LOCALMEMORY_SECTOR_SIZE; - pos.y = (y + 0.5f) * LOCALMEMORY_SECTOR_SIZE; - pos.z = terrain ? terrain->GetHeightFromFloats(pos.x, pos.y) : defaultTerrainHeight; - - if (m_pDebugDraw->GetIVal() == 17) - { - float textureRatio = sector->m_memoryUsage_Textures / localMemoryTextureLimit; - float geometryRatio = sector->m_memoryUsage_Geometry / localMemoryGeometryLimit; - float maxRatio = max(textureRatio, geometryRatio); - - v0 = pos; - v1 = pos + Vec3(-sys_LocalMemoryObjectWidth, -sys_LocalMemoryObjectWidth, sys_LocalMemoryObjectHeight); - v2 = pos + Vec3(sys_LocalMemoryObjectWidth, -sys_LocalMemoryObjectWidth, sys_LocalMemoryObjectHeight); - v3 = pos + Vec3(sys_LocalMemoryObjectWidth, sys_LocalMemoryObjectWidth, sys_LocalMemoryObjectHeight); - v4 = pos + Vec3(-sys_LocalMemoryObjectWidth, sys_LocalMemoryObjectWidth, sys_LocalMemoryObjectHeight); - - if (camera->Project(v1, projectedPos) || camera->Project(v2, projectedPos) || camera->Project(v3, projectedPos) || camera->Project(v4, projectedPos)) - { - vTextureDiagram = pos + Vec3(0.f, sys_LocalMemoryObjectWidth + sys_LocalMemoryDiagramDistance + sys_LocalMemoryDiagramRadius, sys_LocalMemoryObjectHeight); - vGeometryDiagram = pos + Vec3(0.f, -sys_LocalMemoryObjectWidth - sys_LocalMemoryDiagramDistance - sys_LocalMemoryDiagramRadius, sys_LocalMemoryObjectHeight); - - if (maxRatio < sys_LocalMemoryWarningRatio) - { - color = colorOK; - pColor = fColorOK; - } - else if (maxRatio < 1.0f) - { - color = colorWarning; - pColor = fColorWarning; - } - else - { - color = colorError; - pColor = fColorError; - } - - bool close = (Distance::Point_Point2D(cameraPos, pos) < sys_LocalMemoryInnerViewDistance); - if (close) - { - pRenderAuxGeom->SetRenderFlags(auxGeomRenderFlagsClose); - - static int xDebug = 14; - static int yDebug = 19; - - if (sys_LocalMemoryDrawText) - { - camera->Project(pos, projectedPos); - - pRenderer->Draw2dLabel(projectedPos.x, projectedPos.y, 1.2f, pColor, true, "Text: %.2fMb Geom: %.2fMb", sector->m_memoryUsage_Textures / (1024.f * 1024.f), sector->m_memoryUsage_Geometry / (1024.f * 1024.f)); - /* For sector debugging - pRenderer->Draw2dLabel(projectedPos.x, projectedPos.y, 1.2f, pColor, true, "Text: %.1fMb Geom: %.1fMb - %d : %d", sector->m_memoryUsage_Textures/(1024.f*1024.f), sector->m_memoryUsage_Geometry/(1024.f*1024.f), x, y); - - if( xDebug == x && yDebug == y ) - { - float sx = projectedPos.x-80; - float sy = projectedPos.y; - - for( TStatObjMap::iterator it = m_globalStatObjs.begin(); it != m_globalStatObjs.end(); ++it ) - { - SStatObjInfo *statObjInfo = &it->second; - IStatObj* pStatObj = statObjInfo->m_pStatObj; - - int memoryUsage = 0; - float mipFactor = statObjInfo->m_arrMipFactor[y * m_actProcessedSectors.w + x]; - if( mipFactor != BIG_NUMBER ) - { - memoryUsage = statObjInfo->m_streamableContentMemoryUsage; - } - sy+=15.f; - pRenderer->Draw2dLabel(sx, sy, 1.2f, pColor, false, "Geom: %.2fMb %.4f Act:%s Orig:%s %s", memoryUsage/(1024.f*1024.f), mipFactor, pStatObj->GetFilePath(), statObjInfo->m_filePath, statObjInfo->m_bSubObject ? " SUBOBJECT" : ""); - //pRenderer->Draw2dLabel(sx, sy, 1.2f, pColor, false, "Geom: %.2fMb %.4f", memoryUsage/(1024.f*1024.f), mipFactor); - } - } - //*/ - } - if (sys_LocalMemoryLogText) - { - if (xDebug == x && yDebug == y) - { - for (TTextureMap::iterator it = m_globalTextures.begin(); it != m_globalTextures.end(); ++it) - { - STextureInfo* textureObjInfo = &it->second; - ITexture* pTexture = textureObjInfo->m_pTexture; - - float mipFactor = textureObjInfo->m_arrMipFactor[y * m_actProcessedSectors.w + x]; - if (mipFactor != BIG_NUMBER) - { - CryLog("Texture: %s %dX%d mipfactor:%.4f", pTexture->GetName(), pTexture->GetWidth(), pTexture->GetHeight(), mipFactor); - } - } - sys_LocalMemoryLogText = false; //Log only once! - } - } - } - else - { - pRenderAuxGeom->SetRenderFlags(auxGeomRenderFlagsFar); - } - - pRenderAuxGeom->DrawTriangle(v1, color, v2, color, v3, color); - pRenderAuxGeom->DrawTriangle(v3, color, v4, color, v1, color); - - pRenderAuxGeom->DrawTriangle(v0, color, v1, color, v4, color); - pRenderAuxGeom->DrawTriangle(v0, color, v2, color, v1, color); - pRenderAuxGeom->DrawTriangle(v0, color, v3, color, v2, color); - pRenderAuxGeom->DrawTriangle(v0, color, v4, color, v3, color); - - if (close) - { - LocalMemoryUsageDrawHelper::DrawCircle(pRenderer, camera, vTextureDiagram, sys_LocalMemoryDiagramRadius, textureRatio, colorTexture, colorBlack); - LocalMemoryUsageDrawHelper::DrawCircle(pRenderer, camera, vGeometryDiagram, sys_LocalMemoryDiagramRadius, geometryRatio, colorGeometry, colorBlack); - } - } - } - - sector++; - } - } -} - -void CLocalMemoryUsage::OnUpdate() -{ - if (!m_pDebugDraw || (m_pDebugDraw->GetIVal() != 17)) - { - return; - } - - //CryLogAlways("OnUpdate start-----------------------------------------"); - CTimeValue actTime = gEnv->pTimer->GetAsyncTime(); - - float callTimeDiff = (actTime - m_LastCallTime).GetSeconds(); - float neededCallTimeDiff = m_AverageUpdateTime / (sys_LocalMemoryOptimalMSecPerSec / 1000.f); - - if (callTimeDiff < neededCallTimeDiff && callTimeDiff < sys_LocalMemoryMaxMSecBetweenCalls / 1000.f) - { - return; - } - - DeleteUnusedResources(); - - m_LastCallTime = actTime; - - { - FRAME_PROFILER("! LocalMemoryUsege::Update - Start", GetISystem(), PROFILE_SYSTEM); - //StartChecking(RectI(0,0,m_sectorNr.x, m_sectorNr.y)); - StartChecking(m_actDrawedSectors); - } - - { - FRAME_PROFILER("! LocalMemoryUsege::Update - CollectGeometry P1", GetISystem(), PROFILE_SYSTEM); - CollectGeometryP1(); - } - - { - FRAME_PROFILER("! LocalMemoryUsege::Update - Materials P2", GetISystem(), PROFILE_SYSTEM); - //We must iterate on materials first - for (TMaterialMap::iterator it = m_globalMaterials.begin(); it != m_globalMaterials.end(); ++it) - { - it->second.CheckOnAllSectorsP2(); - } - } - { - FRAME_PROFILER("! LocalMemoryUsege::Update - Textures P2", GetISystem(), PROFILE_SYSTEM); - for (TTextureMap::iterator it = m_globalTextures.begin(); it != m_globalTextures.end(); ++it) - { - it->second.CheckOnAllSectorsP2(); - } - } - { - FRAME_PROFILER("! LocalMemoryUsege::Update - StatObjects P2", GetISystem(), PROFILE_SYSTEM); - for (TStatObjMap::iterator it = m_globalStatObjs.begin(); it != m_globalStatObjs.end(); ++it) - { - it->second.CheckOnAllSectorsP2(); - } - } - - CTimeValue endTime = gEnv->pTimer->GetAsyncTime(); - m_AverageUpdateTime = LERP(m_AverageUpdateTime, (endTime - actTime).GetSeconds(), 0.5f); - - //CryLogAlways("OnUpdate end***"); -} - -void CLocalMemoryUsage::DeleteUnusedResources() -{ - FRAME_PROFILER("! LocalMemoryUsege::Update - Deleting unused resources", GetISystem(), PROFILE_SYSTEM); - - // Clear the used flags - for (TStatObjMap::iterator it = m_globalStatObjs.begin(); it != m_globalStatObjs.end(); ++it) - { - it->second.m_used = false; - } - - // Iterate on used StatObjs - int nCount; - gEnv->p3DEngine->GetLoadedStatObjArray(NULL, nCount); - std::vector objectsArray; - objectsArray.resize(nCount); - if (nCount > 0) - { - gEnv->p3DEngine->GetLoadedStatObjArray(&objectsArray[0], nCount); - } - - for (std::vector::iterator it = objectsArray.begin(); it != objectsArray.end(); ++it) - { - IStatObj* pStatObj = *it; - TStatObjMap::iterator findIt = m_globalStatObjs.find((INT_PTR)pStatObj); - - if (findIt != m_globalStatObjs.end() && strcmp(pStatObj->GetFilePath(), findIt->second.m_filePath) == 0 && !findIt->second.m_bSubObject) - { - findIt->second.m_used = true; - } - - if (pStatObj->GetFlags() & STATIC_OBJECT_COMPOUND) - { - for (int k = 0; k < pStatObj->GetSubObjectCount(); k++) - { - if (!pStatObj->GetSubObject(k)) - { - continue; - } - - IStatObj* pSubStatObj = pStatObj->GetSubObject(k)->pStatObj; - - if (pSubStatObj) - { - findIt = m_globalStatObjs.find((INT_PTR)pSubStatObj); - - if (findIt != m_globalStatObjs.end() && strcmp(pSubStatObj->GetFilePath(), findIt->second.m_filePath) == 0 && findIt->second.m_bSubObject) - { - findIt->second.m_used = true; - } - } - } - } - } - - // Erase non-used StatObjs - bool changed = true; - while (changed) - { - changed = false; - for (TStatObjMap::iterator it = m_globalStatObjs.begin(); it != m_globalStatObjs.end(); ++it) - { - if (!it->second.m_used) - { - m_globalStatObjs.erase(it); - changed = true; - break; - } - } - } - /* - for( TTextureMap::iterator it = m_globalTextures.begin(); it != m_globalTextures.end(); ++it ) - it->second.m_used = false; - - bool changed = true; - while( changed ) - { - changed = false; - for( TTextureMap::iterator it = m_globalTextures.begin(); it != m_globalTextures.end(); ++it ) - { - if( !it->second.m_used ) - { - m_globalTextures.erase(it); - changed = true; - break; - } - } - } - - for( TMaterialMap::iterator it = m_globalMaterials.begin(); it != m_globalMaterials.end(); ++it ) - it->second.m_used = false; - - changed = true; - while( changed ) - { - changed = false; - for( TMaterialMap::iterator it = m_globalMaterials.begin(); it != m_globalMaterials.end(); ++it ) - { - if( !it->second.m_used ) - { - m_globalMaterials.erase(it); - changed = true; - break; - } - } - } - //*/ -} -void CLocalMemoryUsage::StartChecking(const RectI& actProcessedSectors) -{ - m_actProcessedSectors = actProcessedSectors; - - for (int y = 0; y < m_sectorNr.y; y++) - { - SSector* sector = &m_arrSectors[y * LOCALMEMORY_SECTOR_NR_X]; - for (int x = 0; x < m_sectorNr.x; x++) - { - sector->StartChecking(); - sector++; - } - } - - { - for (TTextureMap::iterator it = m_globalTextures.begin(); it != m_globalTextures.end(); ++it) - { - //FRAME_PROFILER("! LocalMemoryUsege::StartChecking - Textures", GetISystem(), PROFILE_SYSTEM); - it->second.StartChecking(); - } - } - { - for (TMaterialMap::iterator it = m_globalMaterials.begin(); it != m_globalMaterials.end(); ++it) - { - //FRAME_PROFILER("! LocalMemoryUsege::StartChecking - Materials", GetISystem(), PROFILE_SYSTEM); - it->second.StartChecking(); - } - } - { - for (TStatObjMap::iterator it = m_globalStatObjs.begin(); it != m_globalStatObjs.end(); ++it) - { - //FRAME_PROFILER("! LocalMemoryUsege::StartChecking - StatObjects", GetISystem(), PROFILE_SYSTEM); - it->second.StartChecking(); - } - } -} - -void CLocalMemoryUsage::CollectGeometryP1() -{ - ISystem* pSystem = GetISystem(); - I3DEngine* p3DEngine = pSystem->GetI3DEngine(); - - // iterate through all instances - std::vector renderNodes; - - uint32 dwCount = 0; - - dwCount += p3DEngine->GetObjectsByType(eERType_Light); - - dwCount += p3DEngine->GetObjectsByType(eERType_RenderComponent); - dwCount += p3DEngine->GetObjectsByType(eERType_SkinnedMeshRenderComponent); - dwCount += p3DEngine->GetObjectsByType(eERType_StaticMeshRenderComponent); - dwCount += p3DEngine->GetObjectsByType(eERType_DynamicMeshRenderComponent); - dwCount += p3DEngine->GetObjectsByType(eERType_Decal); - - if (dwCount > 0) - { - renderNodes.resize(dwCount + 1); - dwCount = 0; - - dwCount += p3DEngine->GetObjectsByType(eERType_Light, &renderNodes[dwCount]); - dwCount += p3DEngine->GetObjectsByType(eERType_RenderComponent, &renderNodes[dwCount]); - dwCount += p3DEngine->GetObjectsByType(eERType_StaticMeshRenderComponent, &renderNodes[dwCount]); - dwCount += p3DEngine->GetObjectsByType(eERType_DynamicMeshRenderComponent, &renderNodes[dwCount]); - dwCount += p3DEngine->GetObjectsByType(eERType_SkinnedMeshRenderComponent, &renderNodes[dwCount]); - dwCount += p3DEngine->GetObjectsByType(eERType_Decal, &renderNodes[dwCount]); - - AABB objBox; - - for (uint32 dwI = 0; dwI < dwCount; ++dwI) - { - IRenderNode* pRenderNode = renderNodes[dwI]; - - if (pRenderNode->m_fWSMaxViewDist < 0.01f) - { - continue; - } - - float objScale = 1.f; - if (pRenderNode->GetRenderNodeType() == eERType_Decal) - { - IDecalRenderNode* pDecal = (IDecalRenderNode*)pRenderNode; - objScale = max(0.001f, pDecal->GetMatrix().GetColumn0().GetLength()); - } - else if (pRenderNode->GetRenderNodeType() == eERType_FogVolume) - { - objScale = max(0.001f, ((IFogVolumeRenderNode*)pRenderNode)->GetMatrix().GetColumn0().GetLength()); - } - - float maxViewDist = pRenderNode->m_fWSMaxViewDist; - pRenderNode->FillBBox(objBox); - - _smart_ptr pRenderNodeMat = pRenderNode->GetMaterialOverride(); - - { - IStatObj* pStatObj = pRenderNode->GetEntityStatObj(); - - if (pStatObj != NULL) - { - CheckStatObjMaterialP1(pStatObj, pRenderNodeMat, objBox, maxViewDist, objScale); - } - else - { - CheckMeshMaterialP1(pRenderNode->GetRenderMesh(0), pRenderNodeMat, objBox, maxViewDist, objScale); - } - } - - for (int dwSlot = 0; dwSlot < pRenderNode->GetSlotCount(); ++dwSlot) - { - _smart_ptr pSlotMat = pRenderNode->GetEntitySlotMaterial(dwSlot); - if (!pSlotMat) - { - pSlotMat = pRenderNodeMat; - } - - Matrix34A matParent; - - if (IStatObj* pStatObj = pRenderNode->GetEntityStatObj(dwSlot, 0, &matParent, true)) - { - CheckStatObjP1(pStatObj, pRenderNode, objBox, maxViewDist, objScale); - - _smart_ptr pStatObjMat = pStatObj->GetMaterial(); - CheckStatObjMaterialP1(pStatObj, pSlotMat ? pSlotMat : pStatObjMat, objBox, maxViewDist, objScale); - } - } - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -PREFAST_SUPPRESS_WARNING(6262); -CLocalMemoryUsage::SStatObjInfo* CLocalMemoryUsage::CheckStatObjP1(IStatObj* pStatObj, [[maybe_unused]] IRenderNode* pRenderNode, AABB bounding, float maxViewDist, float scale) -{ - if (!pStatObj) - { - return NULL; - } - - if (strncmp(pStatObj->GetFilePath(), "%level%", 7) == 0) //HACK %LEVEL% brushes - { - return NULL; - } - - SStatObjInfo* pStatObjInfo = NULL; - - TStatObjMap::iterator iter = m_globalStatObjs.find((INT_PTR)pStatObj); - if (iter != m_globalStatObjs.end()) - { - pStatObjInfo = &iter->second; - pStatObjInfo->m_streamableContentMemoryUsage = pStatObj->GetStreamableContentMemoryUsage(); //TODO TEMP - } - else - { - { - FRAME_PROFILER("! CLocalMemoryUsage::CheckStatObjP1 HASH", GetISystem(), PROFILE_SYSTEM); - PREFAST_SUPPRESS_WARNING(6262) - pStatObjInfo = &m_globalStatObjs[(INT_PTR)pStatObj]; - } - - pStatObjInfo->Init(this); - pStatObjInfo->m_streamableContentMemoryUsage = pStatObj->GetStreamableContentMemoryUsage(); - //pStatObjInfo->m_pStatObj = pStatObj; - pStatObjInfo->m_filePath = pStatObj->GetFilePath(); - pStatObjInfo->m_bSubObject = pStatObj->IsSubObject(); - //CollectStatObjInfo_Recursive( pStatObjInfo, pStatObj ); - } - - pStatObjInfo->CheckOnAllSectorsP1(bounding, maxViewDist, scale, 1.0f); - - return pStatObjInfo; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -PREFAST_SUPPRESS_WARNING(6262); -void CLocalMemoryUsage::CheckMaterialP1(_smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale, float mipFactor) -{ - if (pMaterial) - { - SMaterialInfo* pMaterialInfo = NULL; - - TMaterialMap::iterator iter = m_globalMaterials.find((INT_PTR)pMaterial.get()); - if (iter != m_globalMaterials.end()) - { - pMaterialInfo = &iter->second; - } - else - { - { - FRAME_PROFILER("! CLocalMemoryUsage::CheckMaterialP1 HASH", GetISystem(), PROFILE_SYSTEM); - PREFAST_SUPPRESS_WARNING(6262) - pMaterialInfo = &m_globalMaterials[(INT_PTR)pMaterial.get()]; - } - pMaterialInfo->Init(this); - //pMaterialInfo->m_pMaterial=pMaterial; - CollectMaterialInfo_Recursive(pMaterialInfo, pMaterial); - } - - pMaterialInfo->CheckOnAllSectorsP1(bounding, maxViewDist, scale, mipFactor); - } -} - -PREFAST_SUPPRESS_WARNING(6262); -void CLocalMemoryUsage::CheckChunkMaterialP1(_smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale, CRenderChunk* pRenderChunk) -{ - _smart_ptr pCurrentMaterial = pMaterial; - - if (pRenderChunk != NULL) - { - if (pRenderChunk->m_nMatID < pMaterial->GetSubMtlCount()) - { - pCurrentMaterial = pMaterial->GetSubMtl(pRenderChunk->m_nMatID); - } - - if (pCurrentMaterial != NULL) - { - CheckMaterialP1(pCurrentMaterial, bounding, maxViewDist, scale, pRenderChunk->m_texelAreaDensity); - } - } - else - { - CheckMaterialP1(pCurrentMaterial, bounding, maxViewDist, scale, 1.f); - } -} - -PREFAST_SUPPRESS_WARNING(6262); -void CLocalMemoryUsage::CheckMeshMaterialP1(IRenderMesh* pRenderMesh, _smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale) -{ - if (pRenderMesh) - { - if (pMaterial) - { - TRenderChunkArray* pChunks = &pRenderMesh->GetChunks(); - - if (pChunks != NULL) - { - for (unsigned int i = 0; i < pChunks->size(); i++) - { - CheckChunkMaterialP1(pMaterial, bounding, maxViewDist, scale, &(*pChunks)[i]); - } - } - - pChunks = &pRenderMesh->GetChunksSkinned(); - for (unsigned int i = 0; i < pChunks->size(); i++) - { - CheckChunkMaterialP1(pMaterial, bounding, maxViewDist, scale, &(*pChunks)[i]); - } - } - } - else - { - if (pMaterial) - { - CheckChunkMaterialP1(pMaterial, bounding, maxViewDist, scale, NULL); - } - } -} - -void CLocalMemoryUsage::CheckStatObjMaterialP1(IStatObj* pStatObj, _smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale) -{ - if (pStatObj) - { - for (int i = 0; i < pStatObj->GetSubObjectCount(); i++) - { - CheckStatObjMaterialP1(pStatObj->GetSubObject(i)->pStatObj, pMaterial, bounding, scale, maxViewDist); - } - - CheckMeshMaterialP1(pStatObj->GetRenderMesh(), pMaterial, bounding, maxViewDist, scale); - } -} - -void CLocalMemoryUsage::CollectMaterialInfo_Recursive(SMaterialInfo* materialInfo, _smart_ptr pMaterial) -{ - SShaderItem& rItem = pMaterial->GetShaderItem(); - - uint32 dwSubMatCount = pMaterial->GetSubMtlCount(); - - for (uint32 dwSubMat = 0; dwSubMat < dwSubMatCount; ++dwSubMat) - { - _smart_ptr pSub = pMaterial->GetSubMtl(dwSubMat); - - if (pSub) - { - CollectMaterialInfo_Recursive(materialInfo, pSub); - } - } - - // this pMaterial - if (rItem.m_pShaderResources) - { - for (auto iter = rItem.m_pShaderResources->GetTexturesResourceMap()->begin(); - iter != rItem.m_pShaderResources->GetTexturesResourceMap()->end(); ++iter) - { - const SEfResTexture* pTextureRes = &iter->second; - - if (pTextureRes->m_Sampler.m_pITex) - { - ITexture* pTexture = pTextureRes->m_Sampler.m_pITex; - if (pTexture && pTexture->GetStreamableMipNumber() > 0) - { - STextureInfoAndTilingFactor textureInfo; - - textureInfo.m_pTextureInfo = GetTextureInfo(pTexture); - textureInfo.m_tilingFactor = pTextureRes->GetTiling(0) * pTextureRes->GetTiling(1); - - materialInfo->AddTextureInfo(textureInfo); - } - } - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -PREFAST_SUPPRESS_WARNING(6262) -CLocalMemoryUsage::STextureInfo * CLocalMemoryUsage::GetTextureInfo(ITexture * pTexture) -{ - if (!pTexture) - { - return NULL; - } - - TTextureMap::iterator iter = m_globalTextures.find((INT_PTR)pTexture); - if (iter != m_globalTextures.end()) - { - return &iter->second; - } - - //FUNCTION_PROFILER(GetISystem(), PROFILE_SYSTEM); - STextureInfo* pTextureInfo; - { - FRAME_PROFILER("! CLocalMemoryUsage::CheckStatObjP1 HASH", GetISystem(), PROFILE_SYSTEM); - PREFAST_SUPPRESS_WARNING(6262) - pTextureInfo = &m_globalTextures[(INT_PTR)pTexture]; - } - pTextureInfo->Init(this); - pTextureInfo->m_pTexture = pTexture; - pTexture->AddRef(); - - //Collect informations - //pTextureInfo->m_size = pTexture->GetDeviceDataSize(); - //pTextureInfo->m_xSize = pTexture->GetWidth(); - //pTextureInfo->m_ySize = pTexture->GetHeight(); - //pTextureInfo->m_numMips = pTexture->GetNumMips(); - - return pTextureInfo; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Code/CryEngine/CrySystem/Statistics/LocalMemoryUsage.h b/Code/CryEngine/CrySystem/Statistics/LocalMemoryUsage.h deleted file mode 100644 index 450e2eb2f9..0000000000 --- a/Code/CryEngine/CrySystem/Statistics/LocalMemoryUsage.h +++ /dev/null @@ -1,245 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Visual helper for checking a local memory usage on maps - - -#ifndef CRYINCLUDE_CRYSYSTEM_STATISTICS_LOCALMEMORYUSAGE_H -#define CRYINCLUDE_CRYSYSTEM_STATISTICS_LOCALMEMORYUSAGE_H -#pragma once - - -#include "../CryCommon/Cry_Geo.h" -#include "ILocalMemoryUsage.h" -#include "TimeValue.h" - -#define LOCALMEMORY_SECTOR_SIZE 32.f //Size of one sector -#define LOCALMEMORY_SECTOR_NR_X 128 //4096 / LOCALMEMORY_SECTOR_SIZE Sector number of the world (x) -#define LOCALMEMORY_SECTOR_NR_Y 128 //4096 / LOCALMEMORY_SECTOR_SIZE Sector number of the world (y) -#define LOCALMEMORY_SECTOR_PER_PASS 128 //4096 / 32 Sector nr for one calculation pass. Now it is the whole world; - -//Sector number must be = LOCALMEMORY_SECTOR_PER_PASS * n - -#define LOCALMEMORY_COLOR_OK 0, 255, 0 -#define LOCALMEMORY_COLOR_WARNING 255, 255, 0 -#define LOCALMEMORY_COLOR_ERROR 255, 0, 0 -#define LOCALMEMORY_COLOR_TEXTURE 0, 0, 255 -#define LOCALMEMORY_COLOR_GEOMETRY 0, 0, 0 -#define LOCALMEMORY_COLOR_BLACK 0, 0, 0, 192 -#define LOCALMEMORY_FCOLOR_OK 0, 1, 0 -#define LOCALMEMORY_FCOLOR_WARNING 1, 1, 0 -#define LOCALMEMORY_FCOLOR_ERROR 1, 0, 0 -#define LOCALMEMORY_FCOLOR_OTHER 0, 0, 1 - -struct IMaterial; -struct IStatObj; -struct IRenderMesh; -struct IRenderNode; -struct CRenderChunk; -class CCamera; - -#include - -struct CLocalMemoryUsage - : public ILocalMemoryUsage -{ -private: - - struct STextureInfo; - struct SMaterialInfo; - struct SStatObjInfo; - - typedef std__hash_map TTextureMap; // Type: hash map of textures - typedef std__hash_map TMaterialMap; // Type: hash map of materials - typedef std__hash_map TStatObjMap; // Type: hash map of stat objects - - //******************* - - struct SResource - { - CLocalMemoryUsage* m_pLocalMemoryUsage; // Inner pointer to the singleton (we can use gEnv->pLocalMemoryUsage with type cast instead this) - - float m_arrMipFactor[LOCALMEMORY_SECTOR_PER_PASS * LOCALMEMORY_SECTOR_PER_PASS]; // Mipmap factor based on minimum distance of the resource from the sector (bounding box distance) - bool m_arrRowDirty[LOCALMEMORY_SECTOR_PER_PASS]; // Dirty flag for m_arrMipFactor rows - bool m_used; - - static int m_arrMemoryUsage[LOCALMEMORY_SECTOR_PER_PASS]; // Memory usage of the resource in sectors (last row) - static int m_arrPieces[LOCALMEMORY_SECTOR_PER_PASS]; // Pieces nr of the resource in sectors (last row) - - virtual void StartChecking(); // Called every frame first - void CheckOnAllSectorsP1(const AABB& bounding, float maxViewDist, float viewDistMultiplierForLOD, float mipFactor); // Calculates the minimum of sector bounding vs renderobject bounding distances - - SResource(); - virtual void Init(CLocalMemoryUsage* pLocalMemoryUsage); - //If we will needed a destructor, it must be virtual! - }; - - //******************* - - struct STextureInfo - : public SResource - { - ITexture* m_pTexture; // Texture pointer - //int m_size; // For later use - Used memory - //int m_xSize; // For later use - Texture x size - //int m_ySize; // For later use - Texture y size - //int m_numMips; // For later use - Number of mip maps - - void CheckOnAllSectorsP2(); // Calculate memory usage using distances - - STextureInfo(); - ~STextureInfo(); - }; - - //******************* - - struct STextureInfoAndTilingFactor - { - STextureInfo* m_pTextureInfo; - float m_tilingFactor; - }; - - typedef std::vector TTextureVector; // Type: vector of textures - - struct SMaterialInfo - : public SResource - { - //_smart_ptr m_pMaterial; // For later use - TTextureVector m_textures; // Used textures - - SMaterialInfo(); - - void AddTextureInfo(STextureInfoAndTilingFactor texture);// Add a new texture (unique) - void CheckOnAllSectorsP2(); // Forward distance informations to textures - }; - - //******************* - - struct SStatObjInfo - : public SResource - { - int m_streamableContentMemoryUsage; // Total streamable memory usage - //IStatObj *m_pStatObj; //TODO kiszedni - string m_filePath; // The original file name and path of the StatObj - bool m_bSubObject; // Is the original StatObj a subobject? - /* - int m_lodNr; // For later use - int m_vertices; - int m_meshSize; - int m_physProxySize; - int m_physPrimitives; - int m_indices; - int m_indicesPerLod[MAX_LODS]; - */ - - SStatObjInfo(); - void CheckOnAllSectorsP2(); // Calculate memory usage using distances - }; - - //******************* - - struct SSector - { - SSector(); - - void StartChecking(); // Called every frame first - - int m_memoryUsage_Textures; // Sum of texture memory usage - - int m_memoryUsage_Geometry; // Sum of geometry memory usage - }; - - //******************* - PREFAST_SUPPRESS_WARNING(6262); - TTextureMap m_globalTextures; // Hash map of resources: textures - PREFAST_SUPPRESS_WARNING(6262); - TMaterialMap m_globalMaterials; // Hash map of resources: materials - PREFAST_SUPPRESS_WARNING(6262); - TStatObjMap m_globalStatObjs; // Hash map of resources: stat objects - - ICVar* m_pStreamCgfPredicitionDistance; // Config: additional object distance for streaming - ICVar* m_pDebugDraw; // Config: debug draw mode - - int sys_LocalMemoryTextureLimit; // Config: texture limit for streaming - int sys_LocalMemoryGeometryLimit; // Config: stat object geometry limit for streaming - int sys_LocalMemoryTextureStreamingSpeedLimit; // Config: texture streaming speed limit (approx) - int sys_LocalMemoryGeometryStreamingSpeedLimit; // Config: stat object geometry streaming speed limit (approx) - - float sys_LocalMemoryWarningRatio; // Config: Warning ratio for streaming - float sys_LocalMemoryOuterViewDistance; // Config: View distance for debug draw - float sys_LocalMemoryInnerViewDistance; // Config: View distance for detailed debug draw - - float sys_LocalMemoryObjectWidth; // Config: Width of the debug object - float sys_LocalMemoryObjectHeight; // Config: Height of the debug object - int sys_LocalMemoryObjectAlpha; // Config: Color alpha of the debug object - - float sys_LocalMemoryStreamingSpeedObjectLength; // Config: Length of the streaming speed debug object - float sys_LocalMemoryStreamingSpeedObjectWidth; // Config: Width of the streaming speed debug object - - float sys_LocalMemoryDiagramWidth; // Config: Width of the diagram - - float sys_LocalMemoryDiagramRadius; // Config: Radius of the diagram - float sys_LocalMemoryDiagramDistance; // Config: Distance of the diagram from the main debug object - float sys_LocalMemoryDiagramStreamingSpeedRadius; // Config: Radius of the streaming speed diagram - float sys_LocalMemoryDiagramStreamingSpeedDistance; // Config: Distance of the streaming speed diagram from the streaming speed debug line - int sys_LocalMemoryDiagramAlpha; // Config: Color alpha of the diagram - - int sys_LocalMemoryDrawText; // Config: If != 0, it will draw the numeric values - int sys_LocalMemoryLogText; // Config: If != 0, it will log the numeric values - - int sys_LocalMemoryOptimalMSecPerSec; // Config: Optimal calculation time (MSec) per secundum - int sys_LocalMemoryMaxMSecBetweenCalls; // Config: Maximal time difference (MSec) between calls - - RectI m_actProcessedSectors; // Processed sectors (now it is the whole world) - RectI m_actDrawedSectors; // Processed sectors (now it is the whole world) - - Vec2i m_sectorNr; // Sector x and y number - - float m_AverageUpdateTime; // Avarage Update() time (MSec) - CTimeValue m_LastCallTime; // Last call time of Update() - - SSector m_arrSectors[LOCALMEMORY_SECTOR_NR_X * LOCALMEMORY_SECTOR_NR_Y]; // Sectors - -public: - - CLocalMemoryUsage(); - ~CLocalMemoryUsage(); - - virtual void OnRender(IRenderer* pRenderer, const CCamera* camera); - virtual void OnUpdate(); - virtual void DeleteGlobalData(); // Deletes the m_globalXXX hash maps - -private: - void DeleteUnusedResources(); // Delete the non-used resources (especially StatObjs) - void StartChecking(const RectI& actProcessedSectors); // Called every frame first - void CollectGeometryP1(); // Calculates the minimum of sector bounding vs renderobject bounding distances - - // Get / create StatObjInfo then run Pass1 - SStatObjInfo* CheckStatObjP1(IStatObj* pStatObj, IRenderNode* pRenderNode, AABB bounding, float maxViewDist, float scale); - //void CollectStatObjInfo_Recursive( SStatObjInfo* statObjInfo, IStatObj *pStatObj ); - //void CollectGeometryInfo( SStatObjInfo* statObjInfo, IStatObj *pStatObj ); - - // Get / create MaterialInfo then run Pass1 - void CheckMaterialP1(_smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale, float mipFactor); - void CheckChunkMaterialP1(_smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale, CRenderChunk* pRenderChunk); - void CheckMeshMaterialP1(IRenderMesh* pRenderMesh, _smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale); - void CheckStatObjMaterialP1(IStatObj* pStatObj, _smart_ptr pMaterial, AABB bounding, float maxViewDist, float scale); - // Collects textures used by the material - void CollectMaterialInfo_Recursive(SMaterialInfo* materialInfo, _smart_ptr pMaterial); - - // Get / create TextureInfo - STextureInfo* GetTextureInfo(ITexture* pTexture); -}; - -#undef MAX_LODS -#endif // CRYINCLUDE_CRYSYSTEM_STATISTICS_LOCALMEMORYUSAGE_H diff --git a/Code/CryEngine/CrySystem/System.cpp b/Code/CryEngine/CrySystem/System.cpp index a48f63afdf..af9b674f6a 100644 --- a/Code/CryEngine/CrySystem/System.cpp +++ b/Code/CryEngine/CrySystem/System.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include @@ -120,8 +119,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) #include AZ_RESTRICTED_FILE(System_cpp) #endif - -#include #include #include #include @@ -132,7 +129,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) #include #include "VisRegTest.h" #include -#include #include @@ -155,7 +151,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) #include "Serialization/ArchiveHost.h" #include "SystemEventDispatcher.h" #include "ServerThrottle.h" -#include "ILocalMemoryUsage.h" #include "ResourceManager.h" #include "HMDBus.h" #include "OverloadSceneManager/OverloadSceneManager.h" @@ -683,15 +678,6 @@ void CSystem::ShutDown() // Shutdown any running VR devices. EBUS_EVENT(AZ::VR::HMDInitRequestBus, Shutdown); - - ////////////////////////////////////////////////////////////////////////// - // Clear 3D Engine resources. - if (m_env.p3DEngine) - { - m_env.p3DEngine->UnloadLevel(); - } - ////////////////////////////////////////////////////////////////////////// - // Shutdown resource manager. m_pResourceManager->Shutdown(); @@ -707,7 +693,6 @@ void CSystem::ShutDown() SAFE_DELETE(m_env.pServiceNetwork); SAFE_RELEASE(m_env.pLyShine); SAFE_RELEASE(m_env.pCryFont); - SAFE_RELEASE(m_env.p3DEngine); // depends on EntitySystem if (m_env.pConsole) { ((CXConsole*)m_env.pConsole)->FreeRenderResources(); @@ -1162,31 +1147,6 @@ void CSystem::SleepIfInactive() { return; } - -#if defined(WIN32) - if (!AZ::Interface::Get()) - { - WIN_HWND hRendWnd = GetIRenderer()->GetHWND(); - if (!hRendWnd) - { - return; - } - - AZ_TRACE_METHOD(); - // Loop here waiting for window to be activated. - for (int nLoops = 0; nLoops < 5; nLoops++) - { - WIN_HWND hActiveWnd = ::GetActiveWindow(); - if (hActiveWnd == hRendWnd) - { - break; - } - - AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::PumpSystemEventLoopUntilEmpty); - Sleep(5); - } - } -#endif } ////////////////////////////////////////////////////////////////////////// @@ -1257,8 +1217,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) return false; } - RenderBegin(); - #ifndef EXCLUDE_UPDATE_ON_CONSOLE // do the dedicated sleep earlier than the frame profiler to avoid having it counted if (gEnv->IsDedicated()) @@ -1321,11 +1279,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) GetIRemoteConsole()->Update(); #endif - if (gEnv->pLocalMemoryUsage != NULL) - { - gEnv->pLocalMemoryUsage->OnUpdate(); - } - if (!gEnv->IsEditor() && gEnv->pRenderer) { // If the dimensions of the render target change, @@ -1516,11 +1469,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) //update time subsystem m_Time.UpdateOnFrameStart(); - if (m_env.p3DEngine) - { - m_env.p3DEngine->OnFrameStart(); - } - ////////////////////////////////////////////////////////////////////// // update rate limiter for dedicated server if (m_pServerThrottle.get()) @@ -1677,7 +1625,7 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) } ////////////////////////////////////////////////////////////////////// -bool CSystem::UpdatePostTickBus(int updateFlags, int nPauseMode) +bool CSystem::UpdatePostTickBus(int updateFlags, int /*nPauseMode*/) { CTimeValue updateStart = gEnv->pTimer->GetAsyncTime(); @@ -1689,44 +1637,6 @@ bool CSystem::UpdatePostTickBus(int updateFlags, int nPauseMode) UpdateMovieSystem(updateFlags, fMovieFrameTime, false); } - ////////////////////////////////////////////////////////////////////// - //update process (3D engine) - if (!(updateFlags & ESYSUPDATE_EDITOR) && !m_bNoUpdate && m_env.p3DEngine) - { - FRAME_PROFILER("SysUpdate:Update3DEngine", this, PROFILE_SYSTEM); - - if (ITimeOfDay* pTOD = m_env.p3DEngine->GetTimeOfDay()) - { - pTOD->Tick(); - } - - if (m_env.p3DEngine) - { - m_env.p3DEngine->Tick(); // clear per frame temp data - } - if (m_pProcess && (m_pProcess->GetFlags() & PROC_3DENGINE)) - { - if ((nPauseMode != 1)) - { - if (!IsEquivalent(m_ViewCamera.GetPosition(), Vec3(0, 0, 0), VEC_EPSILON)) - { - if (m_env.p3DEngine) - { - // m_env.p3DEngine->SetCamera(m_ViewCamera); - m_pProcess->Update(); - } - } - } - } - else - { - if (m_pProcess) - { - m_pProcess->Update(); - } - } - } - ////////////////////////////////////////////////////////////////////// //update sound system part 2 if (!g_cvars.sys_deferAudioUpdateOptim && !m_bNoUpdate) @@ -1774,41 +1684,8 @@ bool CSystem::UpdatePostTickBus(int updateFlags, int nPauseMode) gEnv->pCryPak->DisableRuntimeFileAccess(true); } - // If it's in editing mode (in editor) the render is done in RenderViewport so we skip rendering here. - if (!gEnv->IsEditing() && gEnv->pRenderer && gEnv->p3DEngine) - { - if (GetIViewSystem()) - { - GetIViewSystem()->Update(min(gEnv->pTimer->GetFrameTime(), 0.1f)); - } - - // Begin occlusion job after setting the correct camera. - gEnv->p3DEngine->PrepareOcclusion(GetViewCamera()); - - CrySystemNotificationBus::Broadcast(&CrySystemNotifications::OnPreRender); - - // Also broadcast for anyone else that needs to draw global debug to do so now - AzFramework::DebugDisplayEventBus::Broadcast(&AzFramework::DebugDisplayEvents::DrawGlobalDebugInfo); - - Render(); - - gEnv->p3DEngine->EndOcclusion(); - - CrySystemNotificationBus::Broadcast(&CrySystemNotifications::OnPostRender); - - RenderEnd(); - - gEnv->p3DEngine->SyncProcessStreamingUpdate(); - - if (NeedDoWorkDuringOcclusionChecks()) - { - DoWorkDuringOcclusionChecks(); - } - - // Sync the work that must be done in the main thread by the end of frame. - gEnv->pRenderer->GetGenerateShadowRendItemJobExecutor()->WaitForCompletion(); - gEnv->pRenderer->GetGenerateRendItemJobExecutor()->WaitForCompletion(); - } + // Also broadcast for anyone else that needs to draw global debug to do so now + AzFramework::DebugDisplayEventBus::Broadcast(&AzFramework::DebugDisplayEvents::DrawGlobalDebugInfo); return !IsQuitting(); } diff --git a/Code/CryEngine/CrySystem/System.h b/Code/CryEngine/CrySystem/System.h index 47fdb362e9..f5235f2ea8 100644 --- a/Code/CryEngine/CrySystem/System.h +++ b/Code/CryEngine/CrySystem/System.h @@ -408,13 +408,6 @@ public: virtual void DoWorkDuringOcclusionChecks(); virtual bool NeedDoWorkDuringOcclusionChecks() { return m_bNeedDoWorkDuringOcclusionChecks; } - //! Begin rendering frame. - void RenderBegin(); - //! Render subsystems. - void Render(); - //! End rendering frame and swap back buffer. - void RenderEnd(bool bRenderStats = true, bool bMainWindow = true); - //Called when the renderer finishes rendering the scene void OnScene3DEnd() override; @@ -429,11 +422,6 @@ public: //! Update screen and call some important tick functions during loading. void SynchronousLoadingTick(const char* pFunc, int line); - //! Renders the statistics; this is called from RenderEnd, but if the - //! Host application (Editor) doesn't employ the Render cycle in ISystem, - //! it may call this method to render the essential statistics - void RenderStatistics() override; - uint32 GetUsedMemory(); virtual void DumpMemoryUsageStatistics(bool bUseKB); @@ -469,7 +457,6 @@ public: AZ::IO::IArchive* GetIPak() { return m_env.pCryPak; }; IConsole* GetIConsole() { return m_env.pConsole; }; IRemoteConsole* GetIRemoteConsole(); - I3DEngine* GetI3DEngine(){ return m_env.p3DEngine; } IMovieSystem* GetIMovieSystem() { return m_env.pMovieSystem; }; IMemoryManager* GetIMemoryManager(){ return m_pMemoryManager; } IThreadManager* GetIThreadManager() override {return m_env.pThreadManager; } @@ -676,17 +663,11 @@ private: //! @name Initialization routines //@{ bool InitConsole(); - bool InitRenderer(WIN_HINSTANCE hinst, WIN_HWND hwnd, const SSystemInitParams& initParams); - - bool InitFont(const SSystemInitParams& initParams); bool InitFileSystem(); bool InitFileSystem_LoadEngineFolders(const SSystemInitParams& initParams); bool InitStreamEngine(); - bool Init3DEngine(const SSystemInitParams& initParams); bool InitAudioSystem(const SSystemInitParams& initParams); bool InitShine(const SSystemInitParams& initParams); - bool OpenRenderLibrary(int type, const SSystemInitParams& initParams); - bool OpenRenderLibrary(const char* t_rend, const SSystemInitParams& initParams); //@} @@ -702,9 +683,6 @@ private: void CreateRendererVars(const SSystemInitParams& startupParams); void CreateSystemVars(); void CreateAudioVars(); - void RenderStats(); - void RenderOverscanBorders(); - void RenderMemStats(); AZStd::unique_ptr LoadDLL(const char* dllName); @@ -738,9 +716,6 @@ private: bool GetWinGameFolder(char* szMyDocumentsPath, int maxPathSize); #endif - //! \brief Initializes the given IFFont member variable with the given name (internal use only). - bool LoadFontInternal(IFFont*& font, const string& fontName); - public: void EnableFloatExceptions(int type); diff --git a/Code/CryEngine/CrySystem/SystemInit.cpp b/Code/CryEngine/CrySystem/SystemInit.cpp index fcbf0b8215..22445ec4a5 100644 --- a/Code/CryEngine/CrySystem/SystemInit.cpp +++ b/Code/CryEngine/CrySystem/SystemInit.cpp @@ -43,8 +43,6 @@ #include #include -#include "CryFontBus.h" - #include #include @@ -70,7 +68,6 @@ #include #include #include -#include #include #include @@ -89,7 +86,6 @@ #endif //WIN32 -#include #include #include #include @@ -110,7 +106,6 @@ #include "PhysRenderer.h" #include "LocalizedStringManager.h" #include "SystemEventDispatcher.h" -#include "Statistics/LocalMemoryUsage.h" #include "ThreadConfigManager.h" #include "Validator.h" #include "ServerThrottle.h" @@ -247,24 +242,6 @@ CUNIXConsole* pUnixConsole; #define LOCALIZATION_TRANSLATIONS_LIST_FILE_NAME "Libs/Localization/localization.xml" -#define LOAD_LEGACY_RENDERER_FOR_EDITOR false // If you set this to true you must also set 'ed_useAtomNativeViewport' to false (see /Code/Sandbox/Editor/ViewManager.cpp) -#define LOAD_LEGACY_RENDERER_FOR_LAUNCHER false - -////////////////////////////////////////////////////////////////////////// -// Where possible, these are defaults used to initialize cvars -// System.cfg can then be used to override them -// This includes the Game DLL, although it is loaded elsewhere - -#define DLL_FONT "CryFont" -#define DLL_3DENGINE "Cry3DEngine" -#define DLL_RENDERER_DX9 "CryRenderD3D9" -#define DLL_RENDERER_DX11 "CryRenderD3D11" -#define DLL_RENDERER_DX12 "CryRenderD3D12" -#define DLL_RENDERER_METAL "CryRenderMetal" -#define DLL_RENDERER_GL "CryRenderGL" -#define DLL_RENDERER_NULL "CryRenderNULL" -#define DLL_SHINE "LyShine" - ////////////////////////////////////////////////////////////////////////// #if defined(WIN32) || defined(LINUX) || defined(APPLE) # define DLL_MODULE_INIT_ISYSTEM "ModuleInitISystem" @@ -789,11 +766,6 @@ static void LoadDetectedSpec(ICVar* pVar) GetISystem()->SetConfigSpec(static_cast(spec), platform, false); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetMaterialManager()->RefreshMaterialRuntime(); - } - no_recursive = false; } @@ -1079,58 +1051,6 @@ void CSystem::ShutdownModuleLibraries() #endif // !defined(AZ_MONOLITHIC_BUILD) } -////////////////////////////////////////////////////////////////////////// -bool CSystem::OpenRenderLibrary([[maybe_unused]] const char* t_rend, const SSystemInitParams& initParams) -{ - LOADING_TIME_PROFILE_SECTION(GetISystem()); - -#if defined(AZ_RESTRICTED_PLATFORM) -#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_6 -#include AZ_RESTRICTED_FILE(SystemInit_cpp) -#endif -#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED) -#undef AZ_RESTRICTED_SECTION_IMPLEMENTED -#else - - if (gEnv->IsDedicated()) - { - return OpenRenderLibrary(R_NULL_RENDERER, initParams); - } - - if (AZ::Interface::Get()) - { - return OpenRenderLibrary(R_DX11_RENDERER, initParams); - } - else if (azstricmp(t_rend, "DX9") == 0) - { - return OpenRenderLibrary(R_DX9_RENDERER, initParams); - } - else if (azstricmp(t_rend, "DX11") == 0) - { - return OpenRenderLibrary(R_DX11_RENDERER, initParams); - } - else if (azstricmp(t_rend, "DX12") == 0) - { - return OpenRenderLibrary(R_DX12_RENDERER, initParams); - } - else if (azstricmp(t_rend, "GL") == 0) - { - return OpenRenderLibrary(R_GL_RENDERER, initParams); - } - else if (azstricmp(t_rend, "METAL") == 0) - { - return OpenRenderLibrary(R_METAL_RENDERER, initParams); - } - else if (azstricmp(t_rend, "NULL") == 0) - { - return OpenRenderLibrary(R_NULL_RENDERER, initParams); - } - - AZ_Assert(false, "Unknown renderer type: %s", t_rend); - return false; -#endif -} - ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// @@ -1220,126 +1140,6 @@ wstring GetErrorStringUnsupportedGPU(const char* gpuName, unsigned int gpuVendor } #endif -bool CSystem::OpenRenderLibrary(int type, const SSystemInitParams& initParams) -{ - LOADING_TIME_PROFILE_SECTION; -#if defined(WIN32) || defined(WIN64) - if (!gEnv->IsDedicated()) - { - unsigned int gpuVendorId = 0, gpuDeviceId = 0, totVidMem = 0; - char gpuName[256]; - Win32SysInspect::DXFeatureLevel featureLevel = Win32SysInspect::DXFL_Undefined; - Win32SysInspect::GetGPUInfo(gpuName, sizeof(gpuName), gpuVendorId, gpuDeviceId, totVidMem, featureLevel); - - if (m_env.IsEditor()) - { -#if defined(EXTERNAL_CRASH_REPORTING) - CrashHandler::CrashHandlerBase::AddAnnotation("dx.feature.level", Win32SysInspect::GetFeatureLevelAsString(featureLevel)); - CrashHandler::CrashHandlerBase::AddAnnotation("gpu.name", gpuName); - CrashHandler::CrashHandlerBase::AddAnnotation("gpu.vendorId", std::to_string(gpuVendorId)); - CrashHandler::CrashHandlerBase::AddAnnotation("gpu.deviceId", std::to_string(gpuDeviceId)); - CrashHandler::CrashHandlerBase::AddAnnotation("gpu.memory", std::to_string(totVidMem)); -#endif - } - else - { - if (featureLevel < Win32SysInspect::DXFL_11_0) - { - const char logMsgFmt[] ("Unsupported GPU configuration!\n- %s (vendor = 0x%.4x, device = 0x%.4x)\n- Dedicated video memory: %d MB\n- Feature level: %s\n"); - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, logMsgFmt, gpuName, gpuVendorId, gpuDeviceId, totVidMem >> 20, GetFeatureLevelAsString(featureLevel)); - -#if !defined(_RELEASE) - const bool allowPrompts = m_env.pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "noprompt") == 0; -#else - const bool allowPrompts = true; -#endif // !defined(_RELEASE) - if (allowPrompts) - { - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "Asking user if they wish to continue..."); - const int mbRes = MessageBoxW(0, GetErrorStringUnsupportedGPU(gpuName, gpuVendorId, gpuDeviceId).c_str(), L"Open 3D Engine", MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON2 | MB_DEFAULT_DESKTOP_ONLY); - if (mbRes == IDCANCEL) - { - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "User chose to cancel startup due to unsupported GPU."); - return false; - } - } - else - { -#if !defined(_RELEASE) - const bool obeyGPUCheck = m_env.pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "anygpu") == 0; -#else - const bool obeyGPUCheck = true; -#endif // !defined(_RELEASE) - if (obeyGPUCheck) - { - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "No prompts allowed and unsupported GPU check active. Treating unsupported GPU as error and exiting."); - return false; - } - } - - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "User chose to continue despite unsupported GPU!"); - } - } - } -#endif -#if defined(AZ_RESTRICTED_PLATFORM) -#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_7 -#include AZ_RESTRICTED_FILE(SystemInit_cpp) -#endif - - if (gEnv->IsDedicated()) - { - type = R_NULL_RENDERER; - } - const char* libname = ""; - if (AZ::Interface::Get()) - { - libname = DLL_RENDERER_NULL; - } - else if (type == R_DX9_RENDERER) - { - libname = DLL_RENDERER_DX9; - } - else if (type == R_DX11_RENDERER) - { - libname = DLL_RENDERER_DX11; - } - else if (type == R_DX12_RENDERER) - { - libname = DLL_RENDERER_DX12; - } - else if (type == R_NULL_RENDERER) - { - libname = DLL_RENDERER_NULL; - } - else if (type == R_GL_RENDERER) - { - libname = DLL_RENDERER_GL; - } - else if (type == R_METAL_RENDERER) - { - libname = DLL_RENDERER_METAL; - } - else - { - AZ_Assert(false, "Renderer did not initialize correctly; no valid renderer specified."); - return false; - } - - if (!InitializeEngineModule(libname, "EngineModule_CryRenderer", initParams)) - { - return false; - } - - if (!m_env.pRenderer) - { - AZ_Assert(false, "Renderer did not initialize correctly; it could not be found in the system environment."); - return false; - } - - return true; -} - ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// bool CSystem::InitConsole() @@ -1391,123 +1191,6 @@ ICVar* CSystem::attachVariable (const char* szVarName, int* pContainer, const ch return pVar; } -///////////////////////////////////////////////////////////////////////////////// -bool CSystem::InitRenderer(WIN_HINSTANCE hinst, WIN_HWND hwnd, const SSystemInitParams& initParams) -{ - LOADING_TIME_PROFILE_SECTION(GetISystem()); - - if (m_pUserCallback) - { - m_pUserCallback->OnInitProgress("Initializing Renderer..."); - } - - if (m_bEditor) - { - m_env.pConsole->GetCVar("r_Width"); - - // save current screen width/height/bpp, so they can be restored on shutdown - m_iWidth = m_env.pConsole->GetCVar("r_Width")->GetIVal(); - m_iHeight = m_env.pConsole->GetCVar("r_Height")->GetIVal(); - m_iColorBits = m_env.pConsole->GetCVar("r_ColorBits")->GetIVal(); - } - - if (!OpenRenderLibrary(m_rDriver->GetString(), initParams)) - { - return false; - } - -#if defined(AZ_PLATFORM_IOS) || defined(AZ_PLATFORM_ANDROID) - if (m_rWidthAndHeightAsFractionOfScreenSize->GetFlags() & VF_WASINCONFIG) - { - int displayWidth = 0; - int displayHeight = 0; - if (GetPrimaryPhysicalDisplayDimensions(displayWidth, displayHeight)) - { - // Ideally we would probably want to clamp this at the source, - // but I don't believe cvars support specifying a valid range. - float scaleFactor = 1.0f; - - if(IsTablet()) - { - scaleFactor = AZ::GetClamp(m_rTabletWidthAndHeightAsFractionOfScreenSize->GetFVal(), 0.1f, 1.0f); - } - else - { - scaleFactor = AZ::GetClamp(m_rWidthAndHeightAsFractionOfScreenSize->GetFVal(), 0.1f, 1.0f); - } - - displayWidth *= scaleFactor; - displayHeight *= scaleFactor; - - const int maxWidth = m_rMaxWidth->GetIVal(); - if (maxWidth > 0 && maxWidth < displayWidth) - { - const float widthScaleFactor = static_cast(maxWidth) / static_cast(displayWidth); - displayWidth *= widthScaleFactor; - displayHeight *= widthScaleFactor; - } - - const int maxHeight = m_rMaxHeight->GetIVal(); - if (maxHeight > 0 && maxHeight < displayHeight) - { - const float heightScaleFactor = static_cast(maxHeight) / static_cast(displayHeight); - displayWidth *= heightScaleFactor; - displayHeight *= heightScaleFactor; - } - - m_rWidth->Set(displayWidth); - m_rHeight->Set(displayHeight); - } - } -#endif // defined(AZ_PLATFORM_IOS) || defined(AZ_PLATFORM_ANDROID) - - if (m_env.pRenderer) - { - // This is crucial as textures suffix are hard coded to context and we need to initialize - // the texture semantics to look it up. - m_env.pRenderer->InitTexturesSemantics(); - -#ifdef WIN32 - SCustomRenderInitArgs args; - args.appStartedFromMediaCenter = strstr(initParams.szSystemCmdLine, "ReLaunchMediaCenter") != 0; - - m_hWnd = m_env.pRenderer->Init(0, 0, m_rWidth->GetIVal(), m_rHeight->GetIVal(), m_rColorBits->GetIVal(), m_rDepthBits->GetIVal(), m_rStencilBits->GetIVal(), m_rFullscreen->GetIVal() ? true : false, initParams.bEditor, hinst, hwnd, false, &args, initParams.bShaderCacheGen); - //Timur, Not very clean code, we need to push new hwnd value to the system init params, so other modules can used when initializing. - (const_cast(&initParams))->hWnd = m_hWnd; - - - bool retVal = (initParams.bShaderCacheGen || m_hWnd != 0); - AZ_Assert(retVal, "Renderer failed to initialize correctly."); - return retVal; -#else // WIN32 - WIN_HWND h = m_env.pRenderer->Init(0, 0, m_rWidth->GetIVal(), m_rHeight->GetIVal(), m_rColorBits->GetIVal(), m_rDepthBits->GetIVal(), m_rStencilBits->GetIVal(), m_rFullscreen->GetIVal() ? true : false, initParams.bEditor, hinst, hwnd, false, nullptr, initParams.bShaderCacheGen); - -#if (defined(LINUX) && !defined(AZ_PLATFORM_ANDROID)) - return true; -#define AZ_RESTRICTED_SECTION_IMPLEMENTED -#elif defined(AZ_RESTRICTED_PLATFORM) -#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_8 -#include AZ_RESTRICTED_FILE(SystemInit_cpp) -#endif -#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED) -#undef AZ_RESTRICTED_SECTION_IMPLEMENTED -#else - bool retVal = (initParams.bShaderCacheGen || h != 0); - if (retVal) - { - return true; - } - - AZ_Assert(false, "Renderer failed to initialize correctly."); - return false; -#endif -#endif - } - return true; -} - - - ///////////////////////////////////////////////////////////////////////////////// bool CSystem::InitFileSystem() { @@ -1662,68 +1345,6 @@ bool CSystem::InitStreamEngine() return true; } -///////////////////////////////////////////////////////////////////////////////// -bool CSystem::InitFont(const SSystemInitParams& initParams) -{ - LOADING_TIME_PROFILE_SECTION(GetISystem()); - - bool fontInited = false; - AZ::CryFontCreationRequestBus::BroadcastResult(fontInited, &AZ::CryFontCreationRequests::CreateCryFont, m_env, initParams); - if (!fontInited && !InitializeEngineModule(DLL_FONT, "EngineModule_CryFont", initParams)) - { - return false; - } - - if (!m_env.pCryFont) - { - AZ_Assert(false, "Font System did not initialize correctly; it could not be found in the system environment"); - return false; - } - - if (gEnv->IsDedicated()) - { - return true; - } - - if (!LoadFontInternal(m_pIFont, "default")) - { - return false; - } - - if (!LoadFontInternal(m_pIFontUi, "default-ui")) - { - return false; - } - - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CSystem::Init3DEngine(const SSystemInitParams& initParams) -{ - LOADING_TIME_PROFILE_SECTION(GetISystem()); - - if (!InitializeEngineModule(DLL_3DENGINE, "EngineModule_Cry3DEngine", initParams)) - { - return false; - } - - if (!m_env.p3DEngine) - { - AZ_Assert(false, "3D Engine did not initialize correctly; it could not be found in the system environment"); - return false; - } - - if (!m_env.p3DEngine->Init()) - { - return false; - } - m_pProcess = m_env.p3DEngine; - m_pProcess->SetFlags(PROC_3DENGINE); - - return true; -} - ////////////////////////////////////////////////////////////////////////// bool CSystem::InitAudioSystem(const SSystemInitParams& initParams) { @@ -2785,42 +2406,6 @@ AZ_POP_DISABLE_WARNING } InlineInitializationProcessing("CSystem::Init InitLocalizations"); - ////////////////////////////////////////////////////////////////////////// - // RENDERER - ////////////////////////////////////////////////////////////////////////// - const bool loadLegacyRenderer = gEnv->IsEditor() ? - LOAD_LEGACY_RENDERER_FOR_EDITOR : - LOAD_LEGACY_RENDERER_FOR_LAUNCHER; - if (loadLegacyRenderer && !startupParams.bSkipRenderer) - { - AZ_Assert(CryMemory::IsHeapValid(), "CryMemory must be valid before initializing renderer."); - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "Renderer initialization"); - - if (!InitRenderer(m_hInst, m_hWnd, startupParams)) - { - return false; - } - AZ_Assert(CryMemory::IsHeapValid(), "CryMemory must be valid after initializing renderer."); - if (m_env.pRenderer) - { - bool bMultiGPUEnabled = false; - m_env.pRenderer->EF_Query(EFQ_MultiGPUEnabled, bMultiGPUEnabled); - if (bMultiGPUEnabled) - { - LoadConfiguration("mgpu.cfg"); - } - } - - InlineInitializationProcessing("CSystem::Init InitRenderer"); - - if (m_env.pCryFont) - { - m_env.pCryFont->SetRendererProperties(m_env.pRenderer); - } - - AZ_Assert(m_env.pRenderer || startupParams.bSkipRenderer, "The renderer did not initialize correctly."); - } - #if !defined(AZ_RELEASE_BUILD) && defined(AZ_PLATFORM_ANDROID) m_thermalInfoHandler = AZStd::make_unique(); #endif @@ -2869,21 +2454,6 @@ AZ_POP_DISABLE_WARNING m_env.pRenderer->SetViewport(0, 0, screenWidth, screenHeight); - // Skip splash screen rendering - if (!AZ::Interface::Get()) - { - // make sure it's rendered in full screen mode when triple buffering is enabled as well - for (size_t n = 0; n < 3; n++) - { - m_env.pRenderer->BeginFrame(); - m_env.pRenderer->SetCullMode(R_CULL_NONE); - m_env.pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - m_env.pRenderer->Draw2dImageStretchMode(true); - m_env.pRenderer->Draw2dImage(x * vx, y * vy, w * vx, h * vy, pTex->GetTextureID(), 0.0f, 1.0f, 1.0f, 0.0f); - m_env.pRenderer->Draw2dImageStretchMode(false); - m_env.pRenderer->EndFrame(); - } - } #if defined(AZ_PLATFORM_IOS) || defined(AZ_PLATFORM_MAC) // Pump system events in order to update the screen AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::PumpSystemEventLoopUntilEmpty); @@ -2928,24 +2498,10 @@ AZ_POP_DISABLE_WARNING } } - ////////////////////////////////////////////////////////////////////////// - // FONT - ////////////////////////////////////////////////////////////////////////// - if (!startupParams.bSkipFont) - { - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "Font initialization"); - if (!InitFont(startupParams)) - { - return false; - } - } - - InlineInitializationProcessing("CSystem::Init InitFonts"); - // The last update to the loading screen message was 'Initializing CryFont...' // Compiling the default system textures can be the lengthiest portion of // editor initialization, so it is useful to inform users that they are waiting on - // the necessary default textures to compile, and that they are not waiting on CryFont. + // the necessary default textures to compile. if (m_pUserCallback) { m_pUserCallback->OnInitProgress("First time asset processing - may take a minute..."); @@ -3040,28 +2596,6 @@ AZ_POP_DISABLE_WARNING return false; } - ////////////////////////////////////////////////////////////////////////// - // Init 3d engine - ////////////////////////////////////////////////////////////////////////// - if (loadLegacyRenderer && !startupParams.bSkipRenderer && !startupParams.bShaderCacheGen) - { - AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "Initializing 3D Engine"); - INDENT_LOG_DURING_SCOPE(); - - if (!Init3DEngine(startupParams)) - { - return false; - } - - // try flush to keep renderer busy - if (m_env.pRenderer) - { - m_env.pRenderer->TryFlush(); - } - - InlineInitializationProcessing("CSystem::Init Init3DEngine"); - } - ////////////////////////////////////////////////////////////////////////// // SERVICE NETWORK ////////////////////////////////////////////////////////////////////////// @@ -3247,12 +2781,6 @@ AZ_POP_DISABLE_WARNING m_env.pRenderer->TryFlush(); } -#if !defined(RELEASE) - m_env.pLocalMemoryUsage = new CLocalMemoryUsage(); -#else - m_env.pLocalMemoryUsage = nullptr; -#endif - if (g_cvars.sys_float_exceptions > 0) { if (g_cvars.sys_float_exceptions == 3 && gEnv->IsEditor()) // Turn off float exceptions in editor if sys_float_exceptions = 3 @@ -4223,24 +3751,3 @@ void CSystem::SetAssertVisible(bool bAssertVisble) { m_bIsAsserting = bAssertVisble; } - -bool CSystem::LoadFontInternal(IFFont*& font, const string& fontName) -{ - font = m_env.pCryFont->NewFont(fontName); - if (!font) - { - AZ_Assert(false, "Could not instantiate the default font."); - return false; - } - - ////////////////////////////////////////////////////////////////////////// - string szFontPath = "Fonts/" + fontName + ".font"; - - if (!font->Load(szFontPath.c_str())) - { - AZ_Error(AZ_TRACE_SYSTEM_WINDOW, false, "Could not load font: %s. Make sure the program is running from the correct working directory.", szFontPath.c_str()); - return false; - } - - return true; -} diff --git a/Code/CryEngine/CrySystem/SystemRender.cpp b/Code/CryEngine/CrySystem/SystemRender.cpp index a544cef4a5..68045a86ea 100644 --- a/Code/CryEngine/CrySystem/SystemRender.cpp +++ b/Code/CryEngine/CrySystem/SystemRender.cpp @@ -31,7 +31,6 @@ #include #include "Log.h" #include "XConsole.h" -#include #include #include "PhysRenderer.h" #include @@ -222,92 +221,6 @@ void CSystem::CreateRendererVars(const SSystemInitParams& startupParams) "Usage: r_OverscanBordersDrawDebugView [0=off/1=show]"); } -////////////////////////////////////////////////////////////////////////// -void CSystem::RenderBegin() -{ - FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SYSTEM, g_bProfilerEnabled); - - if (m_bIgnoreUpdates) - { - return; - } - - bool rndAvail = m_env.pRenderer != 0; - - ////////////////////////////////////////////////////////////////////// - //start the rendering pipeline - if (rndAvail) - { - m_env.pRenderer->BeginFrame(); - } - - gEnv->nMainFrameID = (rndAvail) ? m_env.pRenderer->GetFrameID(false) : 0; -} - - -////////////////////////////////////////////////////////////////////////// -void CSystem::RenderEnd([[maybe_unused]] bool bRenderStats, bool bMainWindow) -{ - { - FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SYSTEM, g_bProfilerEnabled); - - if (m_bIgnoreUpdates) - { - return; - } - - if (!m_env.pRenderer) - { - return; - } - - if (bMainWindow) // we don't do this in UI Editor window for example - { -#if !defined (_RELEASE) - // Flush render data and swap buffers. - m_env.pRenderer->RenderDebug(bRenderStats); -#endif - -#if defined(USE_PERFHUD) - if (m_pPerfHUD) - { - m_pPerfHUD->Draw(); - } - if (m_pMiniGUI) - { - m_pMiniGUI->Draw(); - } -#endif - - if (!gEnv->pSystem->GetILevelSystem() || !gEnv->pSystem->GetILevelSystem()->IsLevelLoaded()) - { - IConsole* console = GetIConsole(); - - //Same goes for the console. When no level is loaded, it's okay to render it outside of the renderer - //so that users can load maps or change settings. - if (console != nullptr) - { - console->Draw(); - } - } - } - - m_env.pRenderer->ForceGC(); // XXX Rename this - m_env.pRenderer->EndFrame(); - - - if (IConsole* pConsole = GetIConsole()) - { - // if we have pending cvar calculation, execute it here - // since we know cvars will be correct here after ->EndFrame(). - if (!pConsole->IsHashCalculated()) - { - pConsole->CalcCheatVarHash(); - } - } - } -} - void CSystem::OnScene3DEnd() { //Render Console @@ -391,231 +304,3 @@ void CSystem::DisplayErrorMessage(const char* acMessage, #endif m_ErrorMessages.push_back(message); } - -//! Renders the statistics; this is called from RenderEnd, but if the -//! Host application (Editor) doesn't employ the Render cycle in ISystem, -//! it may call this method to render the essential statistics -////////////////////////////////////////////////////////////////////////// -void CSystem::RenderStatistics() -{ - RenderStats(); -} - -////////////////////////////////////////////////////////////////////// -void CSystem::Render() -{ - if (m_bIgnoreUpdates) - { - return; - } - - //check what is the current process - if (!m_pProcess) - { - return; //should never happen - } - //check if the game is in pause or - //in menu mode - //bool bPause=false; - //if (m_pProcess->GetFlags() & PROC_MENU) - // bPause=true; - - FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SYSTEM, g_bProfilerEnabled); - - ////////////////////////////////////////////////////////////////////// - //draw - m_env.p3DEngine->PreWorldStreamUpdate(m_ViewCamera); - - if (m_pProcess) - { - if (m_pProcess->GetFlags() & PROC_3DENGINE) - { - if (!gEnv->IsEditing()) // Editor calls it's own rendering update - { - if (m_env.p3DEngine && !m_env.IsFMVPlaying()) - { - if (!IsEquivalent(m_ViewCamera.GetPosition(), Vec3(0, 0, 0), VEC_EPSILON) || // never pass undefined camera to p3DEngine->RenderWorld() - gEnv->IsDedicated() || (gEnv->pRenderer && gEnv->pRenderer->IsPost3DRendererEnabled())) - { - GetIRenderer()->SetViewport(0, 0, GetIRenderer()->GetWidth(), GetIRenderer()->GetHeight()); - m_env.p3DEngine->RenderWorld(SHDF_ALLOW_WATER | SHDF_ALLOWPOSTPROCESS | SHDF_ALLOWHDR | SHDF_ZPASS | SHDF_ALLOW_AO, SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_ViewCamera), __FUNCTION__); - } - else - { - if (gEnv->pRenderer) - { - // force rendering of black screen to be sure we don't only render the clear color (which is the fog color by default) - gEnv->pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - gEnv->pRenderer->Draw2dImage(0, 0, 800, 600, -1, 0.0f, 0.0f, 1.0f, 1.0f, 0.f, - 0.0f, 0.0f, 0.0f, 1.0f, 0.f); - } - } - } -#if !defined(_RELEASE) - if (m_pVisRegTest) - { - m_pVisRegTest->AfterRender(); - } -#endif - - if (m_env.pMovieSystem) - { - m_env.pMovieSystem->Render(); - } - } - } - else - { - GetIRenderer()->SetViewport(0, 0, GetIRenderer()->GetWidth(), GetIRenderer()->GetHeight()); - m_pProcess->RenderWorld(SHDF_ALLOW_WATER | SHDF_ALLOWPOSTPROCESS | SHDF_ALLOWHDR | SHDF_ZPASS | SHDF_ALLOW_AO, SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_ViewCamera), __FUNCTION__); - } - } - - m_env.p3DEngine->WorldStreamUpdate(); - - gEnv->pRenderer->SwitchToNativeResolutionBackbuffer(); -} - - -////////////////////////////////////////////////////////////////////////// -void CSystem::RenderStats() -{ -#if defined(ENABLE_PROFILING_CODE) -#ifndef _RELEASE - // if we rendered an error message on screen during the last frame, then sleep now - // to force hard stall for 3sec - if (m_bHasRenderedErrorMessage && !gEnv->IsEditor() && !IsLoading()) - { - // DO NOT REMOVE OR COMMENT THIS OUT! - // If you hit this, then you most likely have invalid (synchronous) file accesses - // which must be fixed in order to not stall the entire game. - Sleep(3000); - m_bHasRenderedErrorMessage = false; - } -#endif - - // render info messages on screen - float fTextPosX = 5.0f; - float fTextPosY = -10; - float fTextStepY = 13; - - float fFrameTime = gEnv->pTimer->GetRealFrameTime(); - TErrorMessages::iterator itnext; - for (TErrorMessages::iterator it = m_ErrorMessages.begin(); it != m_ErrorMessages.end(); it = itnext) - { - itnext = it; - ++itnext; - SErrorMessage& message = *it; - - SDrawTextInfo ti; - ti.flags = eDrawText_FixedSize | eDrawText_2D | eDrawText_Monospace; - memcpy(ti.color, message.m_Color, 4 * sizeof(float)); - ti.xscale = ti.yscale = 1.4f; - m_env.pRenderer->DrawTextQueued(Vec3(fTextPosX, fTextPosY += fTextStepY, 1.0f), ti, message.m_Message.c_str()); - - if (!IsLoading()) - { - message.m_fTimeToShow -= fFrameTime; - } - - if (message.m_HardFailure) - { - m_bHasRenderedErrorMessage = true; - } - - if (message.m_fTimeToShow < 0.0f) - { - m_ErrorMessages.erase(it); - } - } -#endif - - if (!m_env.pConsole) - { - return; - } - -#ifndef _RELEASE - if (m_rOverscanBordersDrawDebugView) - { - RenderOverscanBorders(); - } -#endif - - int iDisplayInfo = m_rDisplayInfo->GetIVal(); - if (iDisplayInfo == 0) - { - return; - } - - // Draw engine stats - if (m_env.p3DEngine) - { - // Draw 3dengine stats and get last text cursor position - float nTextPosX = 101 - 20, nTextPosY = -2, nTextStepY = 3; - m_env.p3DEngine->DisplayInfo(nTextPosX, nTextPosY, nTextStepY, iDisplayInfo != 1); - - // Dump Open 3D Engine CPU and GPU memory statistics to screen - m_env.p3DEngine->DisplayMemoryStatistics(); - - #if defined(ENABLE_LW_PROFILERS) - if (m_rDisplayInfo->GetIVal() == 2) - { - m_env.pRenderer->TextToScreen(nTextPosX, nTextPosY += nTextStepY, "SysMem %.1f mb", - float(DumpMMStats(false)) / 1024.f); - } - #endif - - #if 0 - for (int i = 0; i < NUM_POOLS; ++i) - { - int used = (g_pPakHeap->m_iBigPoolUsed[i] ? (int)g_pPakHeap->m_iBigPoolSize[i] : 0); - int size = (int)g_pPakHeap->m_iBigPoolSize[i]; - float fC1[4] = {1, 1, 0, 1}; - m_env.pRenderer->Draw2dLabel(10, 100.0f + i * 16, 2.1f, fC1, false, "BigPool %d: %d bytes of %d bytes used", i, used, size); - } - #endif - } -} - -void CSystem::RenderOverscanBorders() -{ -#ifndef _RELEASE - - if (m_env.pRenderer && m_rOverscanBordersDrawDebugView) - { - int iOverscanBordersDrawDebugView = m_rOverscanBordersDrawDebugView->GetIVal(); - if (iOverscanBordersDrawDebugView) - { - const int texId = -1; - const float uv = 0.0f; - const float rot = 0.0f; - const int whiteTextureId = m_env.pRenderer->GetWhiteTextureId(); - - const float r = 1.0f; - const float g = 1.0f; - const float b = 1.0f; - const float a = 0.2f; - - Vec2 overscanBorders = Vec2(0.0f, 0.0f); - m_env.pRenderer->EF_Query(EFQ_OverscanBorders, overscanBorders); - - const float overscanBorderWidth = overscanBorders.x * VIRTUAL_SCREEN_WIDTH; - const float overscanBorderHeight = overscanBorders.y * VIRTUAL_SCREEN_HEIGHT; - - const float xPos = overscanBorderWidth; - const float yPos = overscanBorderHeight; - const float width = VIRTUAL_SCREEN_WIDTH - (2.0f * overscanBorderWidth); - const float height = VIRTUAL_SCREEN_HEIGHT - (2.0f * overscanBorderHeight); - - m_env.pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - m_env.pRenderer->Draw2dImage(xPos, yPos, - width, height, - whiteTextureId, - uv, uv, uv, uv, - rot, - r, g, b, a); - } - } -#endif -} diff --git a/Code/CryEngine/CrySystem/SystemWin32.cpp b/Code/CryEngine/CrySystem/SystemWin32.cpp index 974e578f38..ce352966ac 100644 --- a/Code/CryEngine/CrySystem/SystemWin32.cpp +++ b/Code/CryEngine/CrySystem/SystemWin32.cpp @@ -15,7 +15,6 @@ #include "System.h" #include -#include #include #include #include @@ -302,23 +301,6 @@ void CSystem::CollectMemStats (ICrySizer* pSizer, MemStatsPurposeEnum nPurpose, } } - - if (m_env.p3DEngine) - { - SIZER_COMPONENT_NAME(pSizer, "Cry3DEngine"); - { - m_env.p3DEngine->GetMemoryUsage (pSizer); - { - SIZER_COMPONENT_NAME (pSizer, "$Allocations waste"); - const SmallModuleInfo* info = FindModuleInfo(stats, "Cry3DEngine.dll"); - if (info) - { - pSizer->AddObject(info, info->memInfo.allocated - info->memInfo.requested); - } - } - } - } - if (m_env.pRenderer) { SIZER_COMPONENT_NAME(pSizer, "CryRenderer"); diff --git a/Code/CryEngine/CrySystem/ViewSystem/View.cpp b/Code/CryEngine/CrySystem/ViewSystem/View.cpp index 384d1c76f5..f8b84bea19 100644 --- a/Code/CryEngine/CrySystem/ViewSystem/View.cpp +++ b/Code/CryEngine/CrySystem/ViewSystem/View.cpp @@ -98,7 +98,7 @@ void CView::Update(float frameTime, bool isActive) //see if the view have to use a custom near clipping plane const float nearPlane = (m_viewParams.nearplane >= CAMERA_MIN_NEAR) ? (m_viewParams.nearplane) : fNearZ; - const float farPlane = (m_viewParams.farplane > 0.f) ? m_viewParams.farplane : gEnv->p3DEngine->GetMaxViewDistance(); + const float farPlane = (m_viewParams.farplane > 0.f) ? m_viewParams.farplane : DEFAULT_FAR; float fov = (m_viewParams.fov < 0.001f) ? DEFAULT_FOV : m_viewParams.fov; // [VR] specific diff --git a/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp b/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp index 65581662c3..13f7f5b82d 100644 --- a/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp +++ b/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp @@ -533,11 +533,6 @@ void CViewSystem::BeginCutScene(IAnimSequence* pSeq, [[maybe_unused]] unsigned l { m_cutsceneCount++; - if (m_cutsceneCount == 1) - { - gEnv->p3DEngine->ResetPostEffects(); - } - VS_CALL_LISTENERS(OnBeginCutScene(pSeq, bResetFX)); } @@ -546,11 +541,6 @@ void CViewSystem::EndCutScene(IAnimSequence* pSeq, [[maybe_unused]] unsigned lon { m_cutsceneCount -= (m_cutsceneCount > 0); - if (m_cutsceneCount == 0) - { - gEnv->p3DEngine->ResetPostEffects(); - } - ClearCutsceneViews(); VS_CALL_LISTENERS(OnEndCutScene(pSeq)); diff --git a/Code/CryEngine/CrySystem/VisRegTest.cpp b/Code/CryEngine/CrySystem/VisRegTest.cpp index 81ef205b47..206d8f349a 100644 --- a/Code/CryEngine/CrySystem/VisRegTest.cpp +++ b/Code/CryEngine/CrySystem/VisRegTest.cpp @@ -18,7 +18,6 @@ #include "VisRegTest.h" #include "ISystem.h" -#include "I3DEngine.h" #include "IRenderer.h" #include "IConsole.h" #include "ITimer.h" diff --git a/Code/CryEngine/CrySystem/crysystem_files.cmake b/Code/CryEngine/CrySystem/crysystem_files.cmake index 23ad644041..bfc7b092fd 100644 --- a/Code/CryEngine/CrySystem/crysystem_files.cmake +++ b/Code/CryEngine/CrySystem/crysystem_files.cmake @@ -57,7 +57,6 @@ set(FILES UnixConsole.h SystemInit.h Serialization/MemoryReader.h - Statistics/LocalMemoryUsage.h MemoryFragmentationProfiler.h XML/ReadWriteXMLSink.h Serialization/ArchiveHost.h @@ -151,7 +150,6 @@ set(FILES MiniGUI/MiniInfoBox.h MiniGUI/MiniMenu.h MiniGUI/MiniTable.h - Statistics/LocalMemoryUsage.cpp ZLibCompressor.cpp ZLibCompressor.h SoftCode/SoftCodeMgr.cpp diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetContainer.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetContainer.cpp index 4e7a19c197..2ff6143912 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetContainer.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetContainer.cpp @@ -239,8 +239,13 @@ namespace AZ return; } - CheckReady(); m_initComplete = true; + + // *After* setting initComplete to true, check to see if the assets are already ready. + // This check needs to wait until after setting initComplete because if they *are* ready, we want the final call to + // RemoveWaitingAsset to trigger the OnAssetContainerReady/Canceled event. If we call CheckReady() *before* setting + // initComplete, if all the assets are ready, the event will never get triggered. + CheckReady(); } bool AssetContainer::IsReady() const diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp index db8736b4a8..b89a73b5e8 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp @@ -1454,32 +1454,48 @@ namespace AZ //========================================================================= void AssetManager::ReloadAssetFromData(const Asset& asset) { - AZ_Assert(asset.Get(), "Asset data for reload is missing."); - AZStd::scoped_lock assetLock(m_assetMutex); - AZ_Assert(m_assets.find(asset.GetId()) != m_assets.end(), "Unable to reload asset %s because its not in the AssetManager's asset list.", asset.ToString().c_str()); - AZ_Assert(m_assets.find(asset.GetId()) == m_assets.end() || asset->RTTI_GetType() == m_assets.find(asset.GetId())->second->RTTI_GetType(), - "New and old data types are mismatched!"); + bool shouldAssignAssetData = false; - auto found = m_assets.find(asset.GetId()); - if ((found == m_assets.end()) || (asset->RTTI_GetType() != found->second->RTTI_GetType())) { - return; // this will just lead to crashes down the line and the above asserts cover this. - } - - AssetData* newData = asset.Get(); + AZ_Assert(asset.Get(), "Asset data for reload is missing."); + AZStd::scoped_lock assetLock(m_assetMutex); + AZ_Assert( + m_assets.find(asset.GetId()) != m_assets.end(), + "Unable to reload asset %s because it's not in the AssetManager's asset list.", asset.ToString().c_str()); + AZ_Assert( + m_assets.find(asset.GetId()) == m_assets.end() || + asset->RTTI_GetType() == m_assets.find(asset.GetId())->second->RTTI_GetType(), + "New and old data types are mismatched!"); + + auto found = m_assets.find(asset.GetId()); + if ((found == m_assets.end()) || (asset->RTTI_GetType() != found->second->RTTI_GetType())) + { + return; // this will just lead to crashes down the line and the above asserts cover this. + } - if (found->second != newData) - { - // Notify users that we are about to change asset - AssetBus::Event(asset.GetId(), &AssetBus::Events::OnAssetPreReload, asset); + AssetData* newData = asset.Get(); - // Resolve the asset handler and account for the new asset instance. + if (found->second != newData) { - AssetHandlerMap::iterator handlerIt = m_handlers.find(newData->GetType()); - AZ_Assert(handlerIt != m_handlers.end(), "No handler was registered for this asset [type:%s id:%s]!", - newData->GetType().ToString().c_str(), newData->GetId().ToString().c_str()); + // Notify users that we are about to change asset + AssetBus::Event(asset.GetId(), &AssetBus::Events::OnAssetPreReload, asset); + + // Resolve the asset handler and account for the new asset instance. + { + AssetHandlerMap::iterator handlerIt = m_handlers.find(newData->GetType()); + AZ_Assert( + handlerIt != m_handlers.end(), "No handler was registered for this asset [type:%s id:%s]!", + newData->GetType().ToString().c_str(), newData->GetId().ToString().c_str()); + } + + shouldAssignAssetData = true; } + } + // We specifically perform this outside of the m_assetMutex lock so that the lock isn't held at the point that + // OnAssetReload is triggered inside of AssignAssetData. Otherwise, we open up a high potential for deadlocks. + if (shouldAssignAssetData) + { AssignAssetData(asset); } } diff --git a/Code/Framework/AzCore/AzCore/Math/Matrix3x3.h b/Code/Framework/AzCore/AzCore/Math/Matrix3x3.h index e1736e1444..973bb52df3 100644 --- a/Code/Framework/AzCore/AzCore/Math/Matrix3x3.h +++ b/Code/Framework/AzCore/AzCore/Math/Matrix3x3.h @@ -142,27 +142,44 @@ namespace AZ void SetBasis(const Vector3& basisX, const Vector3& basisY, const Vector3& basisZ); //! @} - Matrix3x3 operator*(const Matrix3x3& rhs) const; - //! Calculates (this->GetTranspose() * rhs). Matrix3x3 TransposedMultiply(const Matrix3x3& rhs) const; //! Post-multiplies the matrix by a vector. Vector3 operator*(const Vector3& rhs) const; - Matrix3x3 operator+(const Matrix3x3& rhs) const; - Matrix3x3 operator-(const Matrix3x3& rhs) const; - - Matrix3x3 operator*(float multiplier) const; - Matrix3x3 operator/(float divisor) const; + //! Operator for matrix-matrix addition. + //! @{ + [[nodiscard]] Matrix3x3 operator+(const Matrix3x3& rhs) const; + Matrix3x3& operator+=(const Matrix3x3& rhs); + //! @} - Matrix3x3 operator-() const; + //! Operator for matrix-matrix substraction. + //! @{ + [[nodiscard]] Matrix3x3 operator-(const Matrix3x3& rhs) const; + Matrix3x3& operator-=(const Matrix3x3& rhs); + //! @} + //! Operator for matrix-matrix multiplication. + //! @{ + [[nodiscard]] Matrix3x3 operator*(const Matrix3x3& rhs) const; Matrix3x3& operator*=(const Matrix3x3& rhs); - Matrix3x3& operator+=(const Matrix3x3& rhs); - Matrix3x3& operator-=(const Matrix3x3& rhs); + //! @} + + //! Operator for multiplying all matrix's elements with a scalar + //! @{ + [[nodiscard]] Matrix3x3 operator*(float multiplier) const; Matrix3x3& operator*=(float multiplier); + //! @} + + //! Operator for dividing all matrix's elements with a scalar + //! @{ + [[nodiscard]] Matrix3x3 operator/(float divisor) const; Matrix3x3& operator/=(float divisor); + //! @} + + //! Operator for negating all matrix's elements + [[nodiscard]] Matrix3x3 operator-() const; bool operator==(const Matrix3x3& rhs) const; bool operator!=(const Matrix3x3& rhs) const; @@ -187,7 +204,10 @@ namespace AZ //! @} //! Gets the scale part of the transformation, i.e. the length of the scale components. - Vector3 RetrieveScale() const; + [[nodiscard]] Vector3 RetrieveScale() const; + + //! Gets the squared scale part of the transformation (the squared length of the basis vectors). + [[nodiscard]] Vector3 RetrieveScaleSq() const; //! Gets the scale part of the transformation as in RetrieveScale, and also removes this scaling from the matrix. Vector3 ExtractScale(); @@ -195,6 +215,9 @@ namespace AZ //! Quick multiplication by a scale matrix, equivalent to m*=Matrix3x3::CreateScale(scale). void MultiplyByScale(const Vector3& scale); + //! Returns a matrix with the reciprocal scale, keeping the same rotation and translation. + [[nodiscard]] Matrix3x3 GetReciprocalScaled() const; + //! Polar decomposition, M=U*H, U is orthogonal (unitary) and H is symmetric (hermitian). //! This function returns the orthogonal part only Matrix3x3 GetPolarDecomposition() const; @@ -241,7 +264,9 @@ namespace AZ //! Note that this is not the usual multiplication order for transformations. Vector3& operator*=(Vector3& lhs, const Matrix3x3& rhs); + //! Pre-multiplies the matrix by a scalar. Matrix3x3 operator*(float lhs, const Matrix3x3& rhs); -} + +} // namespace AZ #include diff --git a/Code/Framework/AzCore/AzCore/Math/Matrix3x3.inl b/Code/Framework/AzCore/AzCore/Math/Matrix3x3.inl index ff92da1398..6b4dccf3c1 100644 --- a/Code/Framework/AzCore/AzCore/Math/Matrix3x3.inl +++ b/Code/Framework/AzCore/AzCore/Math/Matrix3x3.inl @@ -392,14 +392,6 @@ namespace AZ } - AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator*(const Matrix3x3& rhs) const - { - Matrix3x3 result; - Simd::Vec3::Mat3x3Multiply(GetSimdValues(), rhs.GetSimdValues(), result.GetSimdValues()); - return result; - } - - AZ_MATH_INLINE Matrix3x3 Matrix3x3::TransposedMultiply(const Matrix3x3& rhs) const { Matrix3x3 result; @@ -416,44 +408,45 @@ namespace AZ AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator+(const Matrix3x3& rhs) const { - return Matrix3x3(Simd::Vec3::Add(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()) - , Simd::Vec3::Add(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()) - , Simd::Vec3::Add(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue())); + return Matrix3x3 + ( + Simd::Vec3::Add(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()), + Simd::Vec3::Add(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()), + Simd::Vec3::Add(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()) + ); } - AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator-(const Matrix3x3& rhs) const + AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator+=(const Matrix3x3& rhs) { - return Matrix3x3(Simd::Vec3::Sub(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()) - , Simd::Vec3::Sub(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()) - , Simd::Vec3::Sub(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue())); + *this = *this + rhs; + return *this; } - AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator*(float multiplier) const + AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator-(const Matrix3x3& rhs) const { - const Simd::Vec3::FloatType mulVec = Simd::Vec3::Splat(multiplier); - return Matrix3x3(Simd::Vec3::Mul(m_rows[0].GetSimdValue(), mulVec) - , Simd::Vec3::Mul(m_rows[1].GetSimdValue(), mulVec) - , Simd::Vec3::Mul(m_rows[2].GetSimdValue(), mulVec)); + return Matrix3x3 + ( + Simd::Vec3::Sub(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()), + Simd::Vec3::Sub(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()), + Simd::Vec3::Sub(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()) + ); } - AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator/(float divisor) const + AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator-=(const Matrix3x3& rhs) { - const Simd::Vec3::FloatType divVec = Simd::Vec3::Splat(divisor); - return Matrix3x3(Simd::Vec3::Div(m_rows[0].GetSimdValue(), divVec) - , Simd::Vec3::Div(m_rows[1].GetSimdValue(), divVec) - , Simd::Vec3::Div(m_rows[2].GetSimdValue(), divVec)); + *this = *this - rhs; + return *this; } - AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator-() const + AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator*(const Matrix3x3& rhs) const { - const Simd::Vec3::FloatType zeroVec = Simd::Vec3::ZeroFloat(); - return Matrix3x3(Simd::Vec3::Sub(zeroVec, m_rows[0].GetSimdValue()) - , Simd::Vec3::Sub(zeroVec, m_rows[1].GetSimdValue()) - , Simd::Vec3::Sub(zeroVec, m_rows[2].GetSimdValue())); + Matrix3x3 result; + Simd::Vec3::Mat3x3Multiply(GetSimdValues(), rhs.GetSimdValues(), result.GetSimdValues()); + return result; } @@ -464,24 +457,34 @@ namespace AZ } - AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator+=(const Matrix3x3& rhs) + AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator*(float multiplier) const { - *this = *this + rhs; - return *this; + const Simd::Vec3::FloatType mulVec = Simd::Vec3::Splat(multiplier); + return Matrix3x3 + ( + Simd::Vec3::Mul(m_rows[0].GetSimdValue(), mulVec), + Simd::Vec3::Mul(m_rows[1].GetSimdValue(), mulVec), + Simd::Vec3::Mul(m_rows[2].GetSimdValue(), mulVec) + ); } - AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator-=(const Matrix3x3& rhs) + AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator*=(float multiplier) { - *this = *this - rhs; + *this = *this * multiplier; return *this; } - AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator*=(float multiplier) + AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator/(float divisor) const { - *this = *this * multiplier; - return *this; + const Simd::Vec3::FloatType divVec = Simd::Vec3::Splat(divisor); + return Matrix3x3 + ( + Simd::Vec3::Div(m_rows[0].GetSimdValue(), divVec), + Simd::Vec3::Div(m_rows[1].GetSimdValue(), divVec), + Simd::Vec3::Div(m_rows[2].GetSimdValue(), divVec) + ); } @@ -492,6 +495,18 @@ namespace AZ } + AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator-() const + { + const Simd::Vec3::FloatType zeroVec = Simd::Vec3::ZeroFloat(); + return Matrix3x3 + ( + Simd::Vec3::Sub(zeroVec, m_rows[0].GetSimdValue()), + Simd::Vec3::Sub(zeroVec, m_rows[1].GetSimdValue()), + Simd::Vec3::Sub(zeroVec, m_rows[2].GetSimdValue()) + ); + } + + AZ_MATH_INLINE bool Matrix3x3::operator==(const Matrix3x3& rhs) const { return (Simd::Vec3::CmpAllEq(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()) @@ -552,6 +567,12 @@ namespace AZ } + AZ_MATH_INLINE Vector3 Matrix3x3::RetrieveScaleSq() const + { + return Vector3(GetBasisX().GetLengthSq(), GetBasisY().GetLengthSq(), GetBasisZ().GetLengthSq()); + } + + AZ_MATH_INLINE Vector3 Matrix3x3::ExtractScale() { const Vector3 x = GetBasisX(); @@ -584,6 +605,14 @@ namespace AZ } + AZ_MATH_INLINE Matrix3x3 Matrix3x3::GetReciprocalScaled() const + { + Matrix3x3 result = *this; + result.MultiplyByScale(RetrieveScaleSq().GetReciprocal()); + return result; + } + + AZ_MATH_INLINE void Matrix3x3::GetPolarDecomposition(Matrix3x3* orthogonalOut, Matrix3x3* symmetricOut) const { *orthogonalOut = GetPolarDecomposition(); @@ -679,8 +708,6 @@ namespace AZ AZ_MATH_INLINE Matrix3x3 operator*(float lhs, const Matrix3x3& rhs) { - const Simd::Vec3::FloatType lhsVec = Simd::Vec3::Splat(lhs); - const Simd::Vec3::FloatType* rows = rhs.GetSimdValues(); - return Matrix3x3(Simd::Vec3::Mul(lhsVec, rows[0]), Simd::Vec3::Mul(lhsVec, rows[1]), Simd::Vec3::Mul(lhsVec, rows[2])); + return rhs * lhs; } -} +} // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Math/Matrix3x4.h b/Code/Framework/AzCore/AzCore/Math/Matrix3x4.h index 8773d4ea6a..a18f1e7565 100644 --- a/Code/Framework/AzCore/AzCore/Math/Matrix3x4.h +++ b/Code/Framework/AzCore/AzCore/Math/Matrix3x4.h @@ -225,11 +225,38 @@ namespace AZ //! Sets the three basis vectors and the translation. void SetBasisAndTranslation(const Vector3& basisX, const Vector3& basisY, const Vector3& basisZ, const Vector3& translation); + //! Operator for matrix-matrix addition. + //! @{ + [[nodiscard]] Matrix3x4 operator+(const Matrix3x4& rhs) const; + Matrix3x4& operator+=(const Matrix3x4& rhs); + //! @} + + //! Operator for matrix-matrix substraction. + //! @{ + [[nodiscard]] Matrix3x4 operator-(const Matrix3x4& rhs) const; + Matrix3x4& operator-=(const Matrix3x4& rhs); + //! @} + //! Operator for matrix-matrix multiplication. + //! @{ [[nodiscard]] Matrix3x4 operator*(const Matrix3x4& rhs) const; - - //! Compound assignment operator for matrix-matrix multiplication. Matrix3x4& operator*=(const Matrix3x4& rhs); + //! @} + + //! Operator for multiplying all matrix's elements with a scalar + //! @{ + [[nodiscard]] Matrix3x4 operator*(float multiplier) const; + Matrix3x4& operator*=(float multiplier); + //! @} + + //! Operator for dividing all matrix's elements with a scalar + //! @{ + [[nodiscard]] Matrix3x4 operator/(float divisor) const; + Matrix3x4& operator/=(float divisor); + //! @} + + //! Operator for negating all matrix's elements + [[nodiscard]] Matrix3x4 operator-() const; //! Operator for transforming a Vector3. [[nodiscard]] Vector3 operator*(const Vector3& rhs) const; @@ -274,12 +301,18 @@ namespace AZ //! Gets the scale part of the transformation (the length of the basis vectors). [[nodiscard]] Vector3 RetrieveScale() const; + //! Gets the squared scale part of the transformation (the squared length of the basis vectors). + [[nodiscard]] Vector3 RetrieveScaleSq() const; + //! Gets the scale part of the transformation as in RetrieveScale, and also removes this scaling from the matrix. Vector3 ExtractScale(); //! Multiplies the basis vectors of the matrix by the elements of the scale specified. void MultiplyByScale(const Vector3& scale); + //! Returns a matrix with the reciprocal scale, keeping the same rotation and translation. + [[nodiscard]] Matrix3x4 GetReciprocalScaled() const; + //! Tests if the 3x3 part of the matrix is orthogonal. bool IsOrthogonal(float tolerance = Constants::Tolerance) const; @@ -335,6 +368,10 @@ namespace AZ Vector4 m_rows[RowCount]; }; + + //! Pre-multiplies the matrix by a scalar. + Matrix3x4 operator*(float lhs, const Matrix3x4& rhs); + } // namespace AZ #include diff --git a/Code/Framework/AzCore/AzCore/Math/Matrix3x4.inl b/Code/Framework/AzCore/AzCore/Math/Matrix3x4.inl index bd310d293e..781dcf9b66 100644 --- a/Code/Framework/AzCore/AzCore/Math/Matrix3x4.inl +++ b/Code/Framework/AzCore/AzCore/Math/Matrix3x4.inl @@ -472,6 +472,42 @@ namespace AZ } + AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator+(const Matrix3x4& rhs) const + { + return Matrix3x4 + ( + Simd::Vec4::Add(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()), + Simd::Vec4::Add(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()), + Simd::Vec4::Add(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()) + ); + } + + + AZ_MATH_INLINE Matrix3x4& Matrix3x4::operator+=(const Matrix3x4& rhs) + { + *this = *this + rhs; + return *this; + } + + + AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator-(const Matrix3x4& rhs) const + { + return Matrix3x4 + ( + Simd::Vec4::Sub(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()), + Simd::Vec4::Sub(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()), + Simd::Vec4::Sub(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()) + ); + } + + + AZ_MATH_INLINE Matrix3x4& Matrix3x4::operator-=(const Matrix3x4& rhs) + { + *this = *this - rhs; + return *this; + } + + AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator*(const Matrix3x4& rhs) const { Matrix3x4 result; @@ -487,6 +523,56 @@ namespace AZ } + AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator*(float multiplier) const + { + const Simd::Vec4::FloatType mulVec = Simd::Vec4::Splat(multiplier); + return Matrix3x4 + ( + Simd::Vec4::Mul(m_rows[0].GetSimdValue(), mulVec), + Simd::Vec4::Mul(m_rows[1].GetSimdValue(), mulVec), + Simd::Vec4::Mul(m_rows[2].GetSimdValue(), mulVec) + ); + } + + + AZ_MATH_INLINE Matrix3x4& Matrix3x4::operator*=(float multiplier) + { + *this = *this * multiplier; + return *this; + } + + + AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator/(float divisor) const + { + const Simd::Vec4::FloatType divVec = Simd::Vec4::Splat(divisor); + return Matrix3x4 + ( + Simd::Vec4::Div(m_rows[0].GetSimdValue(), divVec), + Simd::Vec4::Div(m_rows[1].GetSimdValue(), divVec), + Simd::Vec4::Div(m_rows[2].GetSimdValue(), divVec) + ); + } + + + AZ_MATH_INLINE Matrix3x4& Matrix3x4::operator/=(float divisor) + { + *this = *this / divisor; + return *this; + } + + + AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator-() const + { + const Simd::Vec4::FloatType zeroVec = Simd::Vec4::ZeroFloat(); + return Matrix3x4 + ( + Simd::Vec4::Sub(zeroVec, m_rows[0].GetSimdValue()), + Simd::Vec4::Sub(zeroVec, m_rows[1].GetSimdValue()), + Simd::Vec4::Sub(zeroVec, m_rows[2].GetSimdValue()) + ); + } + + AZ_MATH_INLINE Vector3 Matrix3x4::operator*(const Vector3& rhs) const { return Vector3 @@ -583,6 +669,12 @@ namespace AZ } + AZ_MATH_INLINE Vector3 Matrix3x4::RetrieveScaleSq() const + { + return Vector3(GetColumn(0).GetLengthSq(), GetColumn(1).GetLengthSq(), GetColumn(2).GetLengthSq()); + } + + AZ_MATH_INLINE Vector3 Matrix3x4::ExtractScale() { const Vector3 scale = RetrieveScale(); @@ -600,6 +692,14 @@ namespace AZ } + AZ_MATH_INLINE Matrix3x4 Matrix3x4::GetReciprocalScaled() const + { + Matrix3x4 result = *this; + result.MultiplyByScale(RetrieveScaleSq().GetReciprocal()); + return result; + } + + AZ_MATH_INLINE void Matrix3x4::Orthogonalize() { *this = GetOrthogonalized(); @@ -660,4 +760,10 @@ namespace AZ { return reinterpret_cast(m_rows); } + + + AZ_MATH_INLINE Matrix3x4 operator*(float lhs, const Matrix3x4& rhs) + { + return rhs * lhs; + } } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Math/Matrix4x4.h b/Code/Framework/AzCore/AzCore/Math/Matrix4x4.h index 1612f8c962..a94b3c7ae2 100644 --- a/Code/Framework/AzCore/AzCore/Math/Matrix4x4.h +++ b/Code/Framework/AzCore/AzCore/Math/Matrix4x4.h @@ -171,14 +171,38 @@ namespace AZ void SetTranslation(const Vector3& v); //! @} - Matrix4x4 operator+(const Matrix4x4& rhs) const; + //! Operator for matrix-matrix addition. + //! @{ + [[nodiscard]] Matrix4x4 operator+(const Matrix4x4& rhs) const; Matrix4x4& operator+=(const Matrix4x4& rhs); + //! @} - Matrix4x4 operator-(const Matrix4x4& rhs) const; + //! Operator for matrix-matrix substraction. + //! @{ + [[nodiscard]] Matrix4x4 operator-(const Matrix4x4& rhs) const; Matrix4x4& operator-=(const Matrix4x4& rhs); + //! @} - Matrix4x4 operator*(const Matrix4x4& rhs) const; + //! Operator for matrix-matrix multiplication. + //! @{ + [[nodiscard]] Matrix4x4 operator*(const Matrix4x4& rhs) const; Matrix4x4& operator*=(const Matrix4x4& rhs); + //! @} + + //! Operator for multiplying all matrix's elements with a scalar + //! @{ + [[nodiscard]] Matrix4x4 operator*(float multiplier) const; + Matrix4x4& operator*=(float multiplier); + //! @} + + //! Operator for dividing all matrix's elements with a scalar + //! @{ + [[nodiscard]] Matrix4x4 operator/(float divisor) const; + Matrix4x4& operator/=(float divisor); + //! @} + + //! Operator for negating all matrix's elements + [[nodiscard]] Matrix4x4 operator-() const; //! Post-multiplies the matrix by a vector. //! Assumes that the w-component of the Vector3 is 1.0. @@ -222,7 +246,10 @@ namespace AZ //! @} //! Gets the scale part of the transformation, i.e. the length of the scale components. - Vector3 RetrieveScale() const; + [[nodiscard]] Vector3 RetrieveScale() const; + + //! Gets the squared scale part of the transformation (the squared length of the basis vectors). + [[nodiscard]] Vector3 RetrieveScaleSq() const; //! Gets the scale part of the transformation as in RetrieveScale, and also removes this scaling from the matrix. Vector3 ExtractScale(); @@ -230,6 +257,9 @@ namespace AZ //! Quick multiplication by a scale matrix, equivalent to m*=Matrix4x4::CreateScale(scale). void MultiplyByScale(const Vector3& scale); + //! Returns a matrix with the reciprocal scale, keeping the same rotation and translation. + [[nodiscard]] Matrix4x4 GetReciprocalScaled() const; + bool IsClose(const Matrix4x4& rhs, float tolerance = Constants::Tolerance) const; bool operator==(const Matrix4x4& rhs) const; @@ -270,6 +300,10 @@ namespace AZ //! Pre-multiplies the matrix by a vector in-place. //! Note that this is not the usual multiplication order for transformations. Vector4& operator*=(Vector4& lhs, const Matrix4x4& rhs); -} + + //! Pre-multiplies the matrix by a scalar. + Matrix4x4 operator*(float lhs, const Matrix4x4& rhs); + +} // namespace AZ #include diff --git a/Code/Framework/AzCore/AzCore/Math/Matrix4x4.inl b/Code/Framework/AzCore/AzCore/Math/Matrix4x4.inl index 3c4572accd..e32ebe31af 100644 --- a/Code/Framework/AzCore/AzCore/Math/Matrix4x4.inl +++ b/Code/Framework/AzCore/AzCore/Math/Matrix4x4.inl @@ -480,20 +480,12 @@ namespace AZ AZ_MATH_INLINE Matrix4x4 Matrix4x4::operator+(const Matrix4x4& rhs) const { return Matrix4x4 - ( Simd::Vec4::Add(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()) - , Simd::Vec4::Add(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()) - , Simd::Vec4::Add(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()) - , Simd::Vec4::Add(m_rows[3].GetSimdValue(), rhs.m_rows[3].GetSimdValue())); - } - - - AZ_MATH_INLINE Matrix4x4 Matrix4x4::operator-(const Matrix4x4& rhs) const - { - return Matrix4x4 - ( Simd::Vec4::Sub(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()) - , Simd::Vec4::Sub(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()) - , Simd::Vec4::Sub(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()) - , Simd::Vec4::Sub(m_rows[3].GetSimdValue(), rhs.m_rows[3].GetSimdValue())); + ( + Simd::Vec4::Add(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()), + Simd::Vec4::Add(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()), + Simd::Vec4::Add(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()), + Simd::Vec4::Add(m_rows[3].GetSimdValue(), rhs.m_rows[3].GetSimdValue()) + ); } AZ_MATH_INLINE Matrix4x4& Matrix4x4::operator+=(const Matrix4x4& rhs) @@ -502,6 +494,18 @@ namespace AZ return *this; } + + AZ_MATH_INLINE Matrix4x4 Matrix4x4::operator-(const Matrix4x4& rhs) const + { + return Matrix4x4 + ( + Simd::Vec4::Sub(m_rows[0].GetSimdValue(), rhs.m_rows[0].GetSimdValue()), + Simd::Vec4::Sub(m_rows[1].GetSimdValue(), rhs.m_rows[1].GetSimdValue()), + Simd::Vec4::Sub(m_rows[2].GetSimdValue(), rhs.m_rows[2].GetSimdValue()), + Simd::Vec4::Sub(m_rows[3].GetSimdValue(), rhs.m_rows[3].GetSimdValue()) + ); + } + AZ_MATH_INLINE Matrix4x4& Matrix4x4::operator-=(const Matrix4x4& rhs) { *this = *this - rhs; @@ -523,6 +527,59 @@ namespace AZ } + AZ_MATH_INLINE Matrix4x4 Matrix4x4::operator*(float multiplier) const + { + const Simd::Vec4::FloatType mulVec = Simd::Vec4::Splat(multiplier); + return Matrix4x4 + ( + Simd::Vec4::Mul(m_rows[0].GetSimdValue(), mulVec), + Simd::Vec4::Mul(m_rows[1].GetSimdValue(), mulVec), + Simd::Vec4::Mul(m_rows[2].GetSimdValue(), mulVec), + Simd::Vec4::Mul(m_rows[3].GetSimdValue(), mulVec) + ); + } + + + AZ_MATH_INLINE Matrix4x4& Matrix4x4::operator*=(float multiplier) + { + *this = *this * multiplier; + return *this; + } + + + AZ_MATH_INLINE Matrix4x4 Matrix4x4::operator/(float divisor) const + { + const Simd::Vec4::FloatType divVec = Simd::Vec4::Splat(divisor); + return Matrix4x4 + ( + Simd::Vec4::Div(m_rows[0].GetSimdValue(), divVec), + Simd::Vec4::Div(m_rows[1].GetSimdValue(), divVec), + Simd::Vec4::Div(m_rows[2].GetSimdValue(), divVec), + Simd::Vec4::Div(m_rows[3].GetSimdValue(), divVec) + ); + } + + + AZ_MATH_INLINE Matrix4x4& Matrix4x4::operator/=(float divisor) + { + *this = *this / divisor; + return *this; + } + + + AZ_MATH_INLINE Matrix4x4 Matrix4x4::operator-() const + { + const Simd::Vec4::FloatType zeroVec = Simd::Vec4::ZeroFloat(); + return Matrix4x4 + ( + Simd::Vec4::Sub(zeroVec, m_rows[0].GetSimdValue()), + Simd::Vec4::Sub(zeroVec, m_rows[1].GetSimdValue()), + Simd::Vec4::Sub(zeroVec, m_rows[2].GetSimdValue()), + Simd::Vec4::Sub(zeroVec, m_rows[3].GetSimdValue()) + ); + } + + AZ_MATH_INLINE Vector3 Matrix4x4::operator*(const Vector3& rhs) const { return Vector3(Simd::Vec4::Mat4x4TransformPoint3(GetSimdValues(), rhs.GetSimdValue())); @@ -595,6 +652,12 @@ namespace AZ } + AZ_MATH_INLINE Vector3 Matrix4x4::RetrieveScaleSq() const + { + return Vector3(GetBasisX().GetLengthSq(), GetBasisY().GetLengthSq(), GetBasisZ().GetLengthSq()); + } + + AZ_MATH_INLINE Vector3 Matrix4x4::ExtractScale() { Vector4 x = GetBasisX(); @@ -619,6 +682,14 @@ namespace AZ } + AZ_MATH_INLINE Matrix4x4 Matrix4x4::GetReciprocalScaled() const + { + Matrix4x4 result = *this; + result.MultiplyByScale(RetrieveScaleSq().GetReciprocal()); + return result; + } + + AZ_MATH_INLINE bool Matrix4x4::IsClose(const Matrix4x4& rhs, float tolerance) const { const Simd::Vec4::FloatType vecTolerance = Simd::Vec4::Splat(tolerance); @@ -702,4 +773,10 @@ namespace AZ lhs = lhs * rhs; return lhs; } -} + + + AZ_MATH_INLINE Matrix4x4 operator*(float lhs, const Matrix4x4& rhs) + { + return rhs * lhs; + } +} // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl b/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl index ab92604266..079c70c878 100644 --- a/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl +++ b/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl @@ -816,7 +816,7 @@ namespace AZ template static void ReflectUnpackMethodFold(BehaviorContext::ClassBuilder& builder) { - AZStd::string methodName = AZStd::string::format("Get%ld", Index); + const AZStd::string methodName = AZStd::string::format("Get%zu", Index); builder->Method(methodName.data(), [](ContainerType& value) { return AZStd::get(value); }) ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All) ->Attribute(AZ::ScriptCanvasAttributes::TupleGetFunctionIndex, Index) diff --git a/Code/Framework/AzCore/AzCore/Serialization/Json/JsonDeserializer.cpp b/Code/Framework/AzCore/AzCore/Serialization/Json/JsonDeserializer.cpp index f2e9bb866f..8d0da9e54a 100644 --- a/Code/Framework/AzCore/AzCore/Serialization/Json/JsonDeserializer.cpp +++ b/Code/Framework/AzCore/AzCore/Serialization/Json/JsonDeserializer.cpp @@ -97,7 +97,8 @@ namespace AZ return context.Report(Tasks::RetrieveInfo, Outcomes::Unknown, AZStd::string::format("Failed to retrieve rtti information for %s.", classData->m_name)); } - AZ_Assert(classData->m_azRtti->GetTypeId() == typeId, "Type id mismatch during deserialization of a json file. (%s vs %s)"); + AZ_Assert(classData->m_azRtti->GetTypeId() == typeId, "Type id mismatch during deserialization of a json file. (%s vs %s)", + classData->m_azRtti->GetTypeId().ToString().c_str(), typeId.ToString().c_str()); void** objectPtr = reinterpret_cast(object); bool isNull = *objectPtr == nullptr; @@ -512,27 +513,24 @@ namespace AZ if (*object) { const AZ::Uuid& actualClassId = rtti.GetActualUuid(*object); - if (actualClassId != objectType) + const SerializeContext::ClassData* actualClassData = context.GetSerializeContext()->FindClassData(actualClassId); + if (!actualClassData) { - const SerializeContext::ClassData* actualClassData = context.GetSerializeContext()->FindClassData(actualClassId); - if (!actualClassData) - { - status = context.Report(Tasks::RetrieveInfo, Outcomes::Unknown, - AZStd::string::format("Unable to find serialization information for type %s.", actualClassId.ToString().c_str())); - return ResolvePointerResult::FullyProcessed; - } + status = context.Report(Tasks::RetrieveInfo, Outcomes::Unknown, + AZStd::string::format("Unable to find serialization information for type %s.", actualClassId.ToString().c_str())); + return ResolvePointerResult::FullyProcessed; + } - if (actualClassData->m_factory) - { - actualClassData->m_factory->Destroy(*object); - *object = nullptr; - } - else - { - status = context.Report(Tasks::RetrieveInfo, Outcomes::Catastrophic, - "Unable to find the factory needed to clear out the default value."); - return ResolvePointerResult::FullyProcessed; - } + if (actualClassData->m_factory) + { + actualClassData->m_factory->Destroy(*object); + *object = nullptr; + } + else + { + status = context.Report(Tasks::RetrieveInfo, Outcomes::Catastrophic, + "Unable to find the factory needed to clear out the default value."); + return ResolvePointerResult::FullyProcessed; } } status = ResultCode(Tasks::ReadField, Outcomes::Success); diff --git a/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h b/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h index 5746005832..cf73d8dc56 100644 --- a/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h +++ b/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h @@ -38,6 +38,20 @@ namespace AZ }; //! Core class to handle serialization to and from json documents. + //! The Json Serialization works by taking a default constructed object and then apply the information found in the JSON document + //! on top of that object. This allows the Json Serialization to avoid storing default values and helps guarantee that the final + //! object is in a valid state even if non-fatal issues are encountered. + //! Note on containers: Containers such as vector or map are always considered to be empty even if there's entries in the provided + //! default object. During deserialization entries will be appended to any existing values. A flag is provided to automatically + //! clear containers during deserialization. + //! Note on maps: If the key for map containers such as unordered_map can be interpret as a string the Json Serialization will use + //! a JSON Object to store the data in instead of an array with key/value objects. + //! Note on pointers: The Json Serialization assumes that are always constructed, so a default JSON value of "{}" is interpret as + //! creating a new default instance even if the default value is a null pointer. A JSON Null needs to be explicitly stored in + //! the JSON Document in order to default or explicitly set a pointer to null. + //! Note on pointer memory: Objects created/destroyed by the Json Serialization for pointers require that the AZ_CLASS_ALLOCATOR is + //! declared and the object is created using aznew or memory is allocated using azmalloc. Without these the application may + //! crash if the Json Serialization tries to create or destroy an object pointed to by a pointer. class JsonSerialization final { public: diff --git a/Code/Framework/AzCore/AzCore/Serialization/Json/SmartPointerSerializer.cpp b/Code/Framework/AzCore/AzCore/Serialization/Json/SmartPointerSerializer.cpp index 0180e99592..9e707f8644 100644 --- a/Code/Framework/AzCore/AzCore/Serialization/Json/SmartPointerSerializer.cpp +++ b/Code/Framework/AzCore/AzCore/Serialization/Json/SmartPointerSerializer.cpp @@ -23,13 +23,6 @@ namespace AZ { namespace JSR = JsonSerializationResult; - if (IsExplicitDefault(inputValue)) - { - // Do nothing if the input is an explicit default. - return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, - "Default value for smart pointer requested so no change was made."); - } - const SerializeContext::ClassData* containerClass = context.GetSerializeContext()->FindClassData(outputValueTypeId); if (!containerClass) { @@ -153,8 +146,7 @@ namespace AZ if (defaultValue) { - bool typesMatch = false; - auto defaultInputCallback = [&defaultValue, &inputPtrType, &typesMatch] + auto defaultInputCallback = [&defaultValue] (void* elementPtr, const Uuid&, const SerializeContext::ClassData*, const SerializeContext::ClassElement*) { defaultValue = elementPtr; @@ -164,11 +156,6 @@ namespace AZ } JSR::ResultCode result = ContinueStoring(outputValue, inputValue, defaultValue, inputPtrType, context, Flags::ResolvePointer); - if (result.GetOutcome() == JSR::Outcomes::DefaultsUsed) - { - outputValue = GetExplicitDefault(); - return context.Report(result, "Smart pointer used all defaults."); - } return context.Report(result, result.GetProcessing() != JSR::Processing::Halted ? "Successfully processed smart pointer." : "A problem occurred while processing a smart pointer."); } diff --git a/Code/Framework/AzCore/Tests/Asset/AssetManagerStreamingTests.cpp b/Code/Framework/AzCore/Tests/Asset/AssetManagerStreamingTests.cpp index 807288ff82..c55a95cf2a 100644 --- a/Code/Framework/AzCore/Tests/Asset/AssetManagerStreamingTests.cpp +++ b/Code/Framework/AzCore/Tests/Asset/AssetManagerStreamingTests.cpp @@ -330,4 +330,163 @@ namespace UnitTest } } -} + // The AssetManagerStreamerImmediateCompletionTests class adjusts the asset loading to force it to complete immediately, + // while still within the callstack for GetAsset(). This can be used to test various conditions in which the load thread + // completes more rapidly than expected, and can expose subtle race conditions. + // There are a few key things that this class does to make this work: + // - The file I/O streamer is mocked + // - The asset stream data is mocked to a 0-byte length for the asset so that the stream load will bypass the I/O streamer and + // just immediately return completion. + // - The number of JobManager threads is set to 0, forcing jobs to execute synchronously inline when they are started. + // With these changes, GetAssetInternal() will queue the stream, which will immediately call the callback that creates LoadAssetJob, + // which immediately executes in-place to process the asset due to the synchronous JobManager. + // Note that if we just created the asset in a Ready state, most of the asset loading code is completely bypassed, and so we + // wouldn't be able to test for race conditions in the AssetContainer. + // + // This class also unregisters the catalog and asset handler before shutting down the asset manager. This is done to catch + // any outstanding asset references that exist due to loads not completing and cleaning up successfully. + struct AssetManagerStreamerImmediateCompletionTests : public BaseAssetManagerTest, + public AZ::Data::AssetCatalogRequestBus::Handler, + public AZ::Data::AssetHandler, + public AZ::Data::AssetCatalog + { + static inline const AZ::Uuid TestAssetId{"{E970B177-5F45-44EB-A2C4-9F29D9A0B2A2}"}; + static inline constexpr AZStd::string_view TestAssetPath = "test"; + + void SetUp() override + { + BaseAssetManagerTest::SetUp(); + AssetManager::Descriptor desc; + AssetManager::Create(desc); + + // Register the handler and catalog after creation, because we intend to destroy them before AssetManager destruction. + // The specific asset we load is irrelevant, so register EmptyAsset. + AZ::Data::AssetManager::Instance().RegisterHandler(this, AZ::AzTypeInfo::Uuid()); + AZ::Data::AssetManager::Instance().RegisterCatalog(this, AZ::AzTypeInfo::Uuid()); + + // Intercept messages for finding assets by name so that we can mock out the asset we're loading. + AZ::Data::AssetCatalogRequestBus::Handler::BusConnect(); + } + + void TearDown() override + { + // Unregister before destroying AssetManager. + // This will catch any assets that got stuck in a loading state without getting cleaned up. + AZ::Data::AssetManager::Instance().UnregisterCatalog(this); + AZ::Data::AssetManager::Instance().UnregisterHandler(this); + + AZ::Data::AssetCatalogRequestBus::Handler::BusDisconnect(); + + AssetManager::Destroy(); + BaseAssetManagerTest::TearDown(); + } + + size_t GetNumJobManagerThreads() const override + { + // Return 0 threads so that the Job Manager executes jobs synchronously inline. This lets us finish a load while still + // in the callstack that initiates the load. + return 0; + } + + // Create a mock streamer instead of a real one, since we don't really want to load an asset. + IO::IStreamer* CreateStreamer() override + { + m_mockStreamer = AZStd::make_unique(); + return &(m_mockStreamer->m_mockStreamer); + } + + void DestroyStreamer([[maybe_unused]] IO::IStreamer* streamer) override + { + m_mockStreamer = nullptr; + } + + // AssetHandler implementation + + // Minimalist mock to create a new EmptyAsset with the desired asset ID. + AZ::Data::AssetPtr CreateAsset(const AZ::Data::AssetId& id, [[maybe_unused]] const AZ::Data::AssetType& type) override + { + return new EmptyAsset(id); + } + + void DestroyAsset(AZ::Data::AssetPtr ptr) override + { + delete ptr; + } + + // The mocked-out Asset Catalog handles EmptyAsset types. + void GetHandledAssetTypes(AZStd::vector& assetTypes) override + { + assetTypes.push_back(AZ::AzTypeInfo::Uuid()); + } + + // This is a mocked-out load, so just immediately return completion without doing anything. + AZ::Data::AssetHandler::LoadResult LoadAssetData( + [[maybe_unused]] const AZ::Data::Asset& asset, + [[maybe_unused]] AZStd::shared_ptr stream, + [[maybe_unused]] const AZ::Data::AssetFilterCB& assetLoadFilterCB) + { + return AZ::Data::AssetHandler::LoadResult::LoadComplete; + } + + // AssetCatalogRequestBus implementation + + // Minimalist mocks to provide our desired asset path or asset id + AZStd::string GetAssetPathById([[maybe_unused]] const AZ::Data::AssetId& id) override + { + return TestAssetPath; + } + AZ::Data::AssetId GetAssetIdByPath( + [[maybe_unused]] const char* path, [[maybe_unused]] const AZ::Data::AssetType& typeToRegister, + [[maybe_unused]] bool autoRegisterIfNotFound) override + { + return TestAssetId; + } + + // Return the mocked-out information for our test asset + AZ::Data::AssetInfo GetAssetInfoById([[maybe_unused]] const AZ::Data::AssetId& id) override + { + AZ::Data::AssetInfo assetInfo; + assetInfo.m_assetId = TestAssetId; + assetInfo.m_assetType = AZ::AzTypeInfo::Uuid(); + assetInfo.m_relativePath = TestAssetPath; + return assetInfo; + } + + // AssetCatalog implementation + + // Set the mocked-out asset load to have a 0-byte length so that the load skips I/O and immediately returns success + AZ::Data::AssetStreamInfo GetStreamInfoForLoad( + [[maybe_unused]] const AZ::Data::AssetId& id, const AZ::Data::AssetType& type) override + { + EXPECT_TRUE(type == AZ::AzTypeInfo::Uuid()); + AZ::Data::AssetStreamInfo info; + info.m_dataOffset = 0; + info.m_streamName = TestAssetPath; + info.m_dataLen = 0; + info.m_streamFlags = AZ::IO::OpenMode::ModeRead; + + return info; + } + + AZStd::unique_ptr m_mockStreamer; + }; + + // This test will verify that even if the asset loading stream/job returns immediately, all of the loading + // code works successfully. The test here is fairly simple - it just loads the asset and verifies that it + // loaded successfully. The bulk of the test is really in the setup class above, where the load is forced + // to complete immediately. Also, the true failure condition is caught in the setup class too, which is + // the presence of any assets at the point that the asset handler is unregistered. If they're present, then + // the immediate load wasn't truly successful, as it left around extra references to the asset that haven't + // been cleaned up. + TEST_F(AssetManagerStreamerImmediateCompletionTests, LoadAssetWithImmediateJobCompletion_WorksSuccessfully) + { + AZ::Data::AssetLoadParameters loadParams; + + auto testAsset = + AssetManager::Instance().GetAsset(TestAssetId, AZ::Data::AssetLoadBehavior::Default, loadParams); + + AZ::Data::AssetManager::Instance().DispatchEvents(); + EXPECT_TRUE(testAsset.IsReady()); + } + +} // namespace UnitTest diff --git a/Code/Framework/AzCore/Tests/Asset/TestAssetTypes.h b/Code/Framework/AzCore/Tests/Asset/TestAssetTypes.h index 83f3909676..d4267972ec 100644 --- a/Code/Framework/AzCore/Tests/Asset/TestAssetTypes.h +++ b/Code/Framework/AzCore/Tests/Asset/TestAssetTypes.h @@ -24,6 +24,13 @@ namespace UnitTest public: AZ_CLASS_ALLOCATOR(EmptyAsset, AZ::SystemAllocator, 0); AZ_RTTI(EmptyAsset, "{098E3F7F-13AC-414B-9B4E-49B5AD1BD7FE}", AZ::Data::AssetData); + + EmptyAsset( + const AZ::Data::AssetId& assetId = AZ::Data::AssetId(), + AZ::Data::AssetData::AssetStatus status = AZ::Data::AssetData::AssetStatus::NotLoaded) + : AZ::Data::AssetData(assetId, status) + { + } }; // EmptyAssetWithNoHandler: no data contained within, and no AssetHandler registered for this type diff --git a/Code/Framework/AzCore/Tests/Math/Matrix3x3Tests.cpp b/Code/Framework/AzCore/Tests/Math/Matrix3x3Tests.cpp index a849cfdaab..efa0ee531c 100644 --- a/Code/Framework/AzCore/Tests/Math/Matrix3x3Tests.cpp +++ b/Code/Framework/AzCore/Tests/Math/Matrix3x3Tests.cpp @@ -14,6 +14,7 @@ #include #include #include +#include using namespace AZ; @@ -251,19 +252,19 @@ namespace UnitTest m2.SetRow(2, 13.0f, 14.0f, 15.0f); Matrix3x3 m3 = m1 * m2; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(66.0f, 72.0f, 78.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(156.0f, 171.0f, 186.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(246.0f, 270.0f, 294.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(66.0f, 72.0f, 78.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(156.0f, 171.0f, 186.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(246.0f, 270.0f, 294.0f))); Matrix3x3 m4 = m1; m4 *= m2; - AZ_TEST_ASSERT(m4.GetRow(0).IsClose(Vector3(66.0f, 72.0f, 78.0f))); - AZ_TEST_ASSERT(m4.GetRow(1).IsClose(Vector3(156.0f, 171.0f, 186.0f))); - AZ_TEST_ASSERT(m4.GetRow(2).IsClose(Vector3(246.0f, 270.0f, 294.0f))); + EXPECT_THAT(m4.GetRow(0), IsClose(Vector3(66.0f, 72.0f, 78.0f))); + EXPECT_THAT(m4.GetRow(1), IsClose(Vector3(156.0f, 171.0f, 186.0f))); + EXPECT_THAT(m4.GetRow(2), IsClose(Vector3(246.0f, 270.0f, 294.0f))); m3 = m1.TransposedMultiply(m2); - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(138.0f, 150.0f, 162.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(168.0f, 183.0f, 198.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(198.0f, 216.0f, 234.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(138.0f, 150.0f, 162.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(168.0f, 183.0f, 198.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(198.0f, 216.0f, 234.0f))); } TEST(MATH_Matrix3x3, TestVectorMultiplication) @@ -277,11 +278,11 @@ namespace UnitTest m2.SetRow(1, 10.0f, 11.0f, 12.0f); m2.SetRow(2, 13.0f, 14.0f, 15.0f); - AZ_TEST_ASSERT((m1 * Vector3(1.0f, 2.0f, 3.0f)).IsClose(Vector3(14.0f, 32.0f, 50.0f))); + EXPECT_THAT((m1 * Vector3(1.0f, 2.0f, 3.0f)), IsClose(Vector3(14.0f, 32.0f, 50.0f))); Vector3 v1(1.0f, 2.0f, 3.0f); - AZ_TEST_ASSERT((v1 * m1).IsClose(Vector3(30.0f, 36.0f, 42.0f))); + EXPECT_THAT((v1 * m1), IsClose(Vector3(30.0f, 36.0f, 42.0f))); v1 *= m1; - AZ_TEST_ASSERT(v1.IsClose(Vector3(30.0f, 36.0f, 42.0f))); + EXPECT_THAT(v1, IsClose(Vector3(30.0f, 36.0f, 42.0f))); } TEST(MATH_Matrix3x3, TestSum) @@ -296,15 +297,15 @@ namespace UnitTest m2.SetRow(2, 13.0f, 14.0f, 15.0f); Matrix3x3 m3 = m1 + m2; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(8.0f, 10.0f, 12.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(14.0f, 16.0f, 18.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(20.0f, 22.0f, 24.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(8.0f, 10.0f, 12.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(14.0f, 16.0f, 18.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(20.0f, 22.0f, 24.0f))); m3 = m1; m3 += m2; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(8.0f, 10.0f, 12.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(14.0f, 16.0f, 18.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(20.0f, 22.0f, 24.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(8.0f, 10.0f, 12.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(14.0f, 16.0f, 18.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(20.0f, 22.0f, 24.0f))); } TEST(MATH_Matrix3x3, TestDifference) @@ -319,14 +320,14 @@ namespace UnitTest m2.SetRow(2, 13.0f, 14.0f, 15.0f); Matrix3x3 m3 = m1 - m2; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(-6.0f, -6.0f, -6.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(-6.0f, -6.0f, -6.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(-6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(-6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(-6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(-6.0f, -6.0f, -6.0f))); m3 = m1; m3 -= m2; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(-6.0f, -6.0f, -6.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(-6.0f, -6.0f, -6.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(-6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(-6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(-6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(-6.0f, -6.0f, -6.0f))); } TEST(MATH_Matrix3x3, TestScalarMultiplication) @@ -341,18 +342,18 @@ namespace UnitTest m2.SetRow(2, 13.0f, 14.0f, 15.0f); Matrix3x3 m3 = m1 * 2.0f; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(2.0f, 4.0f, 6.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(8.0f, 10.0f, 12.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(14.0f, 16.0f, 18.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(2.0f, 4.0f, 6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(8.0f, 10.0f, 12.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(14.0f, 16.0f, 18.0f))); m3 = m1; m3 *= 2.0f; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(2.0f, 4.0f, 6.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(8.0f, 10.0f, 12.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(14.0f, 16.0f, 18.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(2.0f, 4.0f, 6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(8.0f, 10.0f, 12.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(14.0f, 16.0f, 18.0f))); m3 = 2.0f * m1; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(2.0f, 4.0f, 6.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(8.0f, 10.0f, 12.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(14.0f, 16.0f, 18.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(2.0f, 4.0f, 6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(8.0f, 10.0f, 12.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(14.0f, 16.0f, 18.0f))); } TEST(MATH_Matrix3x3, TestScalarDivision) @@ -367,18 +368,32 @@ namespace UnitTest m2.SetRow(2, 13.0f, 14.0f, 15.0f); Matrix3x3 m3 = m1 / 0.5f; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(2.0f, 4.0f, 6.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(8.0f, 10.0f, 12.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(14.0f, 16.0f, 18.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(2.0f, 4.0f, 6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(8.0f, 10.0f, 12.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(14.0f, 16.0f, 18.0f))); m3 = m1; m3 /= 0.5f; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(2.0f, 4.0f, 6.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(8.0f, 10.0f, 12.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(14.0f, 16.0f, 18.0f))); - m3 = -m1; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector3(-1.0f, -2.0f, -3.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector3(-4.0f, -5.0f, -6.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector3(-7.0f, -8.0f, -9.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector3(2.0f, 4.0f, 6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector3(8.0f, 10.0f, 12.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector3(14.0f, 16.0f, 18.0f))); + } + + TEST(MATH_Matrix3x3, TestNegation) + { + Matrix3x3 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f); + m1.SetRow(1, 4.0f, 5.0f, 6.0f); + m1.SetRow(2, 7.0f, 8.0f, 9.0f); + EXPECT_THAT(-(-m1), IsClose(m1)); + EXPECT_THAT(-Matrix3x3::CreateZero(), IsClose(Matrix3x3::CreateZero())); + + Matrix3x3 m2 = -m1; + EXPECT_THAT(m2.GetRow(0), IsClose(Vector3(-1.0f, -2.0f, -3.0f))); + EXPECT_THAT(m2.GetRow(1), IsClose(Vector3(-4.0f, -5.0f, -6.0f))); + EXPECT_THAT(m2.GetRow(2), IsClose(Vector3(-7.0f, -8.0f, -9.0f))); + + Matrix3x3 m3 = m1 + (-m1); + EXPECT_THAT(m3, IsClose(Matrix3x3::CreateZero())); } TEST(MATH_Matrix3x3, TestTranspose) @@ -425,11 +440,33 @@ namespace UnitTest TEST(MATH_Matrix3x3, TestScaleAccess) { Matrix3x3 m1 = Matrix3x3::CreateRotationX(DegToRad(40.0f)) * Matrix3x3::CreateScale(Vector3(2.0f, 3.0f, 4.0f)); - AZ_TEST_ASSERT(m1.RetrieveScale().IsClose(Vector3(2.0f, 3.0f, 4.0f))); - AZ_TEST_ASSERT(m1.ExtractScale().IsClose(Vector3(2.0f, 3.0f, 4.0f))); - AZ_TEST_ASSERT(m1.RetrieveScale().IsClose(Vector3::CreateOne())); + EXPECT_THAT(m1.RetrieveScale(), IsClose(Vector3(2.0f, 3.0f, 4.0f))); + EXPECT_THAT(m1.ExtractScale(), IsClose(Vector3(2.0f, 3.0f, 4.0f))); + EXPECT_THAT(m1.RetrieveScale(), IsClose(Vector3::CreateOne())); m1.MultiplyByScale(Vector3(3.0f, 4.0f, 5.0f)); - AZ_TEST_ASSERT(m1.RetrieveScale().IsClose(Vector3(3.0f, 4.0f, 5.0f))); + EXPECT_THAT(m1.RetrieveScale(), IsClose(Vector3(3.0f, 4.0f, 5.0f))); + } + + TEST(MATH_Matrix3x3, TestScaleSqAccess) + { + Matrix3x3 m1 = Matrix3x3::CreateRotationX(DegToRad(40.0f)) * Matrix3x3::CreateScale(Vector3(2.0f, 3.0f, 4.0f)); + EXPECT_THAT(m1.RetrieveScaleSq(), IsClose(Vector3(4.0f, 9.0f, 16.0f))); + m1.ExtractScale(); + EXPECT_THAT(m1.RetrieveScaleSq(), IsClose(Vector3::CreateOne())); + m1.MultiplyByScale(Vector3(3.0f, 4.0f, 5.0f)); + EXPECT_THAT(m1.RetrieveScaleSq(), IsClose(Vector3(9.0f, 16.0f, 25.0f))); + } + + TEST(MATH_Matrix3x3, TestReciprocalScaled) + { + Matrix3x3 orthogonalMatrix = Matrix3x3::CreateRotationX(DegToRad(40.0f)); + EXPECT_THAT(orthogonalMatrix.GetReciprocalScaled(), IsClose(orthogonalMatrix)); + const AZ::Vector3 scale(2.8f, 0.7f, 1.3f); + AZ::Matrix3x3 scaledMatrix = orthogonalMatrix; + scaledMatrix.MultiplyByScale(scale); + AZ::Matrix3x3 reciprocalScaledMatrix = orthogonalMatrix; + reciprocalScaledMatrix.MultiplyByScale(scale.GetReciprocal()); + EXPECT_THAT(scaledMatrix.GetReciprocalScaled(), IsClose(reciprocalScaledMatrix)); } TEST(MATH_Matrix3x3, TestPolarDecomposition) diff --git a/Code/Framework/AzCore/Tests/Math/Matrix3x4Tests.cpp b/Code/Framework/AzCore/Tests/Math/Matrix3x4Tests.cpp index f61b633fc2..0bb64411e6 100644 --- a/Code/Framework/AzCore/Tests/Math/Matrix3x4Tests.cpp +++ b/Code/Framework/AzCore/Tests/Math/Matrix3x4Tests.cpp @@ -467,21 +467,136 @@ namespace UnitTest EXPECT_THAT(matrix.Multiply3x3(axisDirection), IsClose(forwardDirection)); } - TEST(MATH_Matrix3x4, MultiplyByMatrix3x4) - { - const AZ::Matrix3x4 matrix1 = AZ::Matrix3x4::CreateFromValue(1.2f); - const AZ::Matrix3x4 matrix2 = AZ::Matrix3x4::CreateDiagonal(AZ::Vector3(1.3f, 1.5f, 0.4f)); - const AZ::Matrix3x4 matrix3 = AZ::Matrix3x4::CreateFromQuaternionAndTranslation( - AZ::Quaternion(0.42f, 0.46f, -0.66f, 0.42f), AZ::Vector3(2.8f, -3.7f, 1.6f)); - const AZ::Matrix3x4 matrix4 = AZ::Matrix3x4::CreateRotationX(-0.7f) * AZ::Matrix3x4::CreateScale(AZ::Vector3(0.6f, 1.3f, 0.7f)); - AZ::Matrix3x4 matrix5 = matrix1; - matrix5 *= matrix4; - const AZ::Vector3 vector(1.9f, 2.3f, 0.2f); - EXPECT_TRUE((matrix1 * (matrix2 * matrix3)).IsClose((matrix1 * matrix2) * matrix3)); - EXPECT_THAT((matrix3 * matrix4) * vector, IsClose(matrix3 * (matrix4 * vector))); - EXPECT_TRUE((matrix2 * AZ::Matrix3x4::Identity()).IsClose(matrix2)); - EXPECT_TRUE((matrix3 * AZ::Matrix3x4::Identity()).IsClose(AZ::Matrix3x4::Identity() * matrix3)); - EXPECT_TRUE(matrix5.IsClose(matrix1 * matrix4)); + TEST(MATH_Matrix3x4, TestMatrixMultiplication) + { + AZ::Matrix3x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + AZ::Matrix3x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + AZ::Matrix3x4 m3 = m1 * m2; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(74.0f, 80.0f, 86.0f, 96.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(206.0f, 224.0f, 242.0f, 268.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(338.0f, 368.0f, 398.0f, 440.0f))); + AZ::Matrix3x4 m4 = m1; + m4 *= m2; + EXPECT_THAT(m4.GetRow(0), IsClose(AZ::Vector4(74.0f, 80.0f, 86.0f, 96.0f))); + EXPECT_THAT(m4.GetRow(1), IsClose(AZ::Vector4(206.0f, 224.0f, 242.0f, 268.0f))); + EXPECT_THAT(m4.GetRow(2), IsClose(AZ::Vector4(338.0f, 368.0f, 398.0f, 440.0f))); + } + + TEST(MATH_Matrix3x4, TestSum) + { + AZ::Matrix3x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + AZ::Matrix3x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + + AZ::Matrix3x4 m3 = m1 + m2; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(8.0f, 10.0f, 12.0f, 14.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(16.0f, 18.0f, 20.0f, 22.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(24.0f, 26.0f, 28.0f, 30.0f))); + + m3 = m1; + m3 += m2; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(8.0f, 10.0f, 12.0f, 14.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(16.0f, 18.0f, 20.0f, 22.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(24.0f, 26.0f, 28.0f, 30.0f))); + } + + TEST(MATH_Matrix3x4, TestDifference) + { + AZ::Matrix3x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + AZ::Matrix3x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + + AZ::Matrix3x4 m3 = m1 - m2; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + m3 = m1; + m3 -= m2; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + } + + TEST(MATH_Matrix3x4, TestScalarMultiplication) + { + AZ::Matrix3x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + AZ::Matrix3x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + + AZ::Matrix3x4 m3 = m1 * 2.0f; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + m3 = m1; + m3 *= 2.0f; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + m3 = 2.0f * m1; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + } + + TEST(MATH_Matrix3x4, TestScalarDivision) + { + AZ::Matrix3x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + AZ::Matrix3x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + + AZ::Matrix3x4 m3 = m1 / 0.5f; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + m3 = m1; + m3 /= 0.5f; + EXPECT_THAT(m3.GetRow(0), IsClose(AZ::Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(AZ::Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(AZ::Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + } + + TEST(MATH_Matrix3x4, TestNegation) + { + AZ::Matrix3x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + EXPECT_THAT(-(-m1), IsClose(m1)); + EXPECT_THAT(-AZ::Matrix3x4::CreateZero(), IsClose(AZ::Matrix3x4::CreateZero())); + + AZ::Matrix3x4 m2 = -m1; + EXPECT_THAT(m2.GetRow(0), IsClose(AZ::Vector4(-1.0f, -2.0f, -3.0f, -4.0f))); + EXPECT_THAT(m2.GetRow(1), IsClose(AZ::Vector4(-5.0f, -6.0f, -7.0f, -8.0f))); + EXPECT_THAT(m2.GetRow(2), IsClose(AZ::Vector4(-9.0f, -10.0f, -11.0f, -12.0f))); + + AZ::Matrix3x4 m3 = m1 + (-m1); + EXPECT_THAT(m3, IsClose(AZ::Matrix3x4::CreateZero())); } TEST(MATH_Matrix3x4, MultiplyByVector3) @@ -652,6 +767,34 @@ namespace UnitTest EXPECT_THAT(scaledMatrix.RetrieveScale(), IsClose(AZ::Vector3::CreateOne())); } + TEST_P(Matrix3x4ScaleFixture, ScaleSq) + { + const AZ::Matrix3x4 orthogonalMatrix = GetParam(); + EXPECT_THAT(orthogonalMatrix.RetrieveScaleSq(), IsClose(AZ::Vector3::CreateOne())); + AZ::Matrix3x4 unscaledMatrix = orthogonalMatrix; + unscaledMatrix.ExtractScale(); + EXPECT_THAT(unscaledMatrix.RetrieveScaleSq(), IsClose(AZ::Vector3::CreateOne())); + const AZ::Vector3 scale(2.8f, 0.7f, 1.3f); + AZ::Matrix3x4 scaledMatrix = orthogonalMatrix; + scaledMatrix.MultiplyByScale(scale); + EXPECT_THAT(scaledMatrix.RetrieveScaleSq(), IsClose(scale * scale)); + EXPECT_THAT(scaledMatrix.RetrieveScaleSq(), IsClose(scaledMatrix.RetrieveScale() * scaledMatrix.RetrieveScale())); + scaledMatrix.ExtractScale(); + EXPECT_THAT(scaledMatrix.RetrieveScaleSq(), IsClose(AZ::Vector3::CreateOne())); + } + + TEST_P(Matrix3x4ScaleFixture, GetReciprocalScaled) + { + const AZ::Matrix3x4 orthogonalMatrix = GetParam(); + EXPECT_THAT(orthogonalMatrix.GetReciprocalScaled(), IsClose(orthogonalMatrix)); + const AZ::Vector3 scale(2.8f, 0.7f, 1.3f); + AZ::Matrix3x4 scaledMatrix = orthogonalMatrix; + scaledMatrix.MultiplyByScale(scale); + AZ::Matrix3x4 reciprocalScaledMatrix = orthogonalMatrix; + reciprocalScaledMatrix.MultiplyByScale(scale.GetReciprocal()); + EXPECT_THAT(scaledMatrix.GetReciprocalScaled(), IsClose(reciprocalScaledMatrix)); + } + INSTANTIATE_TEST_CASE_P(MATH_Matrix3x4, Matrix3x4ScaleFixture, ::testing::ValuesIn(MathTestData::OrthogonalMatrix3x4s)); TEST(MATH_Matrix3x4, IsOrthogonal) diff --git a/Code/Framework/AzCore/Tests/Math/Matrix4x4Tests.cpp b/Code/Framework/AzCore/Tests/Math/Matrix4x4Tests.cpp index 851de490d0..a9baa3ddea 100644 --- a/Code/Framework/AzCore/Tests/Math/Matrix4x4Tests.cpp +++ b/Code/Framework/AzCore/Tests/Math/Matrix4x4Tests.cpp @@ -246,16 +246,16 @@ namespace UnitTest m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); m2.SetRow(3, 19.0f, 20.0f, 21.0f, 22.0f); Matrix4x4 m3 = m1 * m2; - AZ_TEST_ASSERT(m3.GetRow(0).IsClose(Vector4(150.0f, 160.0f, 170.0f, 180.0f))); - AZ_TEST_ASSERT(m3.GetRow(1).IsClose(Vector4(358.0f, 384.0f, 410.0f, 436.0f))); - AZ_TEST_ASSERT(m3.GetRow(2).IsClose(Vector4(566.0f, 608.0f, 650.0f, 692.0f))); - AZ_TEST_ASSERT(m3.GetRow(3).IsClose(Vector4(774.0f, 832.0f, 890.0f, 948.0f))); + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(150.0f, 160.0f, 170.0f, 180.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(358.0f, 384.0f, 410.0f, 436.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(566.0f, 608.0f, 650.0f, 692.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(774.0f, 832.0f, 890.0f, 948.0f))); Matrix4x4 m4 = m1; m4 *= m2; - AZ_TEST_ASSERT(m4.GetRow(0).IsClose(Vector4(150.0f, 160.0f, 170.0f, 180.0f))); - AZ_TEST_ASSERT(m4.GetRow(1).IsClose(Vector4(358.0f, 384.0f, 410.0f, 436.0f))); - AZ_TEST_ASSERT(m4.GetRow(2).IsClose(Vector4(566.0f, 608.0f, 650.0f, 692.0f))); - AZ_TEST_ASSERT(m4.GetRow(3).IsClose(Vector4(774.0f, 832.0f, 890.0f, 948.0f))); + EXPECT_THAT(m4.GetRow(0), IsClose(Vector4(150.0f, 160.0f, 170.0f, 180.0f))); + EXPECT_THAT(m4.GetRow(1), IsClose(Vector4(358.0f, 384.0f, 410.0f, 436.0f))); + EXPECT_THAT(m4.GetRow(2), IsClose(Vector4(566.0f, 608.0f, 650.0f, 692.0f))); + EXPECT_THAT(m4.GetRow(3), IsClose(Vector4(774.0f, 832.0f, 890.0f, 948.0f))); } TEST(MATH_Matrix4x4, TestVectorMultiplication) @@ -265,18 +265,148 @@ namespace UnitTest m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); m1.SetRow(3, 13.0f, 14.0f, 15.0f, 16.0f); - AZ_TEST_ASSERT((m1 * Vector3(1.0f, 2.0f, 3.0f)).IsClose(Vector3(18.0f, 46.0f, 74.0f))); - AZ_TEST_ASSERT((m1 * Vector4(1.0f, 2.0f, 3.0f, 4.0f)).IsClose(Vector4(30.0f, 70.0f, 110.0f, 150.0f))); - AZ_TEST_ASSERT(m1.TransposedMultiply3x3(Vector3(1.0f, 2.0f, 3.0f)).IsClose(Vector3(38.0f, 44.0f, 50.0f))); - AZ_TEST_ASSERT(m1.Multiply3x3(Vector3(1.0f, 2.0f, 3.0f)).IsClose(Vector3(14.0f, 38.0f, 62.0f))); + EXPECT_THAT((m1 * Vector3(1.0f, 2.0f, 3.0f)), IsClose(Vector3(18.0f, 46.0f, 74.0f))); + EXPECT_THAT((m1 * Vector4(1.0f, 2.0f, 3.0f, 4.0f)), IsClose(Vector4(30.0f, 70.0f, 110.0f, 150.0f))); + EXPECT_THAT(m1.TransposedMultiply3x3(Vector3(1.0f, 2.0f, 3.0f)), IsClose(Vector3(38.0f, 44.0f, 50.0f))); + EXPECT_THAT(m1.Multiply3x3(Vector3(1.0f, 2.0f, 3.0f)), IsClose(Vector3(14.0f, 38.0f, 62.0f))); Vector3 v1(1.0f, 2.0f, 3.0f); - AZ_TEST_ASSERT((v1 * m1).IsClose(Vector3(51.0f, 58.0f, 65.0f))); + EXPECT_THAT((v1 * m1), IsClose(Vector3(51.0f, 58.0f, 65.0f))); v1 *= m1; - AZ_TEST_ASSERT(v1.IsClose(Vector3(51.0f, 58.0f, 65.0f))); + EXPECT_THAT(v1, IsClose(Vector3(51.0f, 58.0f, 65.0f))); Vector4 v2(1.0f, 2.0f, 3.0f, 4.0f); - AZ_TEST_ASSERT((v2 * m1).IsClose(Vector4(90.0f, 100.0f, 110.0f, 120.0f))); + EXPECT_THAT((v2 * m1), IsClose(Vector4(90.0f, 100.0f, 110.0f, 120.0f))); v2 *= m1; - AZ_TEST_ASSERT(v2.IsClose(Vector4(90.0f, 100.0f, 110.0f, 120.0f))); + EXPECT_THAT(v2, IsClose(Vector4(90.0f, 100.0f, 110.0f, 120.0f))); + } + + TEST(MATH_Matrix4x4, TestSum) + { + Matrix4x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + m1.SetRow(3, 13.0f, 14.0f, 15.0f, 16.0f); + Matrix4x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + m2.SetRow(3, 19.0f, 20.0f, 21.0f, 22.0f); + + Matrix4x4 m3 = m1 + m2; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(8.0f, 10.0f, 12.0f, 14.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(16.0f, 18.0f, 20.0f, 22.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(24.0f, 26.0f, 28.0f, 30.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(32.0f, 34.0f, 36.0f, 38.0f))); + + m3 = m1; + m3 += m2; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(8.0f, 10.0f, 12.0f, 14.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(16.0f, 18.0f, 20.0f, 22.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(24.0f, 26.0f, 28.0f, 30.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(32.0f, 34.0f, 36.0f, 38.0f))); + } + + TEST(MATH_Matrix4x4, TestDifference) + { + Matrix4x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + m1.SetRow(3, 13.0f, 14.0f, 15.0f, 16.0f); + Matrix4x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + m2.SetRow(3, 19.0f, 20.0f, 21.0f, 22.0f); + + Matrix4x4 m3 = m1 - m2; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + m3 = m1; + m3 -= m2; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(-6.0f, -6.0f, -6.0f, -6.0f))); + } + + TEST(MATH_Matrix4x4, TestScalarMultiplication) + { + Matrix4x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + m1.SetRow(3, 13.0f, 14.0f, 15.0f, 16.0f); + Matrix4x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + m2.SetRow(3, 19.0f, 20.0f, 21.0f, 22.0f); + + Matrix4x4 m3 = m1 * 2.0f; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(26.0f, 28.0f, 30.0f, 32.0f))); + m3 = m1; + m3 *= 2.0f; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(26.0f, 28.0f, 30.0f, 32.0f))); + m3 = 2.0f * m1; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(26.0f, 28.0f, 30.0f, 32.0f))); + } + + TEST(MATH_Matrix4x4, TestScalarDivision) + { + Matrix4x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + m1.SetRow(3, 13.0f, 14.0f, 15.0f, 16.0f); + Matrix4x4 m2; + m2.SetRow(0, 7.0f, 8.0f, 9.0f, 10.0f); + m2.SetRow(1, 11.0f, 12.0f, 13.0f, 14.0f); + m2.SetRow(2, 15.0f, 16.0f, 17.0f, 18.0f); + m2.SetRow(3, 19.0f, 20.0f, 21.0f, 22.0f); + + Matrix4x4 m3 = m1 / 0.5f; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(26.0f, 28.0f, 30.0f, 32.0f))); + m3 = m1; + m3 /= 0.5f; + EXPECT_THAT(m3.GetRow(0), IsClose(Vector4(2.0f, 4.0f, 6.0f, 8.0f))); + EXPECT_THAT(m3.GetRow(1), IsClose(Vector4(10.0f, 12.0f, 14.0f, 16.0f))); + EXPECT_THAT(m3.GetRow(2), IsClose(Vector4(18.0f, 20.0f, 22.0f, 24.0f))); + EXPECT_THAT(m3.GetRow(3), IsClose(Vector4(26.0f, 28.0f, 30.0f, 32.0f))); + } + + TEST(MATH_Matrix4x4, TestNegation) + { + Matrix4x4 m1; + m1.SetRow(0, 1.0f, 2.0f, 3.0f, 4.0f); + m1.SetRow(1, 5.0f, 6.0f, 7.0f, 8.0f); + m1.SetRow(2, 9.0f, 10.0f, 11.0f, 12.0f); + m1.SetRow(3, 13.0f, 14.0f, 15.0f, 16.0f); + EXPECT_THAT(-(-m1), IsClose(m1)); + EXPECT_THAT(-Matrix4x4::CreateZero(), IsClose(Matrix4x4::CreateZero())); + + Matrix4x4 m2 = -m1; + EXPECT_THAT(m2.GetRow(0), IsClose(Vector4(-1.0f, -2.0f, -3.0f, -4.0f))); + EXPECT_THAT(m2.GetRow(1), IsClose(Vector4(-5.0f, -6.0f, -7.0f, -8.0f))); + EXPECT_THAT(m2.GetRow(2), IsClose(Vector4(-9.0f, -10.0f, -11.0f, -12.0f))); + EXPECT_THAT(m2.GetRow(3), IsClose(Vector4(-13.0f, -14.0f, -15.0f, -16.0f))); + + Matrix4x4 m3 = m1 + (-m1); + EXPECT_THAT(m3, IsClose(Matrix4x4::CreateZero())); } TEST(MATH_Matrix4x4, TestTranspose) @@ -368,4 +498,36 @@ namespace UnitTest m1.SetRow(3, 13.0f, 14.0f, 15.0f, 16.0f); AZ_TEST_ASSERT(m1.GetDiagonal() == Vector4(1.0f, 6.0f, 11.0f, 16.0f)); } + + TEST(MATH_Matrix4x4, TestScaleAccess) + { + Matrix4x4 m1 = Matrix4x4::CreateRotationX(DegToRad(40.0f)) * Matrix4x4::CreateScale(Vector3(2.0f, 3.0f, 4.0f)); + EXPECT_THAT(m1.RetrieveScale(), IsClose(Vector3(2.0f, 3.0f, 4.0f))); + EXPECT_THAT(m1.ExtractScale(), IsClose(Vector3(2.0f, 3.0f, 4.0f))); + EXPECT_THAT(m1.RetrieveScale(), IsClose(Vector3::CreateOne())); + m1.MultiplyByScale(Vector3(3.0f, 4.0f, 5.0f)); + EXPECT_THAT(m1.RetrieveScale(), IsClose(Vector3(3.0f, 4.0f, 5.0f))); + } + + TEST(MATH_Matrix4x4, TestScaleSqAccess) + { + Matrix4x4 m1 = Matrix4x4::CreateRotationX(DegToRad(40.0f)) * Matrix4x4::CreateScale(Vector3(2.0f, 3.0f, 4.0f)); + EXPECT_THAT(m1.RetrieveScaleSq(), IsClose(Vector3(4.0f, 9.0f, 16.0f))); + m1.ExtractScale(); + EXPECT_THAT(m1.RetrieveScaleSq(), IsClose(Vector3::CreateOne())); + m1.MultiplyByScale(Vector3(3.0f, 4.0f, 5.0f)); + EXPECT_THAT(m1.RetrieveScaleSq(), IsClose(Vector3(9.0f, 16.0f, 25.0f))); + } + + TEST(MATH_Matrix4x4, TestReciprocalScaled) + { + Matrix4x4 orthogonalMatrix = Matrix4x4::CreateRotationX(DegToRad(40.0f)); + EXPECT_THAT(orthogonalMatrix.GetReciprocalScaled(), IsClose(orthogonalMatrix)); + const AZ::Vector3 scale(2.8f, 0.7f, 1.3f); + AZ::Matrix4x4 scaledMatrix = orthogonalMatrix; + scaledMatrix.MultiplyByScale(scale); + AZ::Matrix4x4 reciprocalScaledMatrix = orthogonalMatrix; + reciprocalScaledMatrix.MultiplyByScale(scale.GetReciprocal()); + EXPECT_THAT(scaledMatrix.GetReciprocalScaled(), IsClose(reciprocalScaledMatrix)); + } } diff --git a/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp b/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp index 417cb10c8c..08de21b54f 100644 --- a/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp +++ b/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp @@ -110,7 +110,7 @@ namespace JsonSerializationTests EXPECT_EQ(42, value); } - TEST_F(BaseJsonSerializerTests, ContinueLoading_PointerInstance_ValueLoadedCorrectly) + TEST_F(BaseJsonSerializerTests, ContinueLoading_ToPointerInstance_ValueLoadedCorrectly) { using namespace AZ::JsonSerializationResult; @@ -126,6 +126,51 @@ namespace JsonSerializationTests EXPECT_EQ(42, value); } + TEST_F(BaseJsonSerializerTests, ContinueLoading_ToNullPointer_ValueLoadedCorrectly) + { + using namespace AZ::JsonSerializationResult; + + rapidjson::Value json; + json.Set(42); + int* ptrValue = nullptr; + + ResultCode result = ContinueLoading(&ptrValue, azrtti_typeid(), json, *m_jsonDeserializationContext, Flags::ResolvePointer); + + EXPECT_EQ(Processing::Completed, result.GetProcessing()); + ASSERT_NE(nullptr, ptrValue); + EXPECT_EQ(42, *ptrValue); + + azfree(ptrValue, AZ::SystemAllocator, sizeof(int), alignof(int)); + } + + TEST_F(BaseJsonSerializerTests, ContinueLoading_DefaultToNullPointer_ValueLoadedCorrectly) + { + using namespace AZ::JsonSerializationResult; + + rapidjson::Value json(rapidjson::kObjectType); + int* ptrValue = nullptr; + + ResultCode result = ContinueLoading(&ptrValue, azrtti_typeid(), json, *m_jsonDeserializationContext, Flags::ResolvePointer); + + EXPECT_EQ(Processing::Completed, result.GetProcessing()); + ASSERT_NE(nullptr, ptrValue); + + azfree(ptrValue, AZ::SystemAllocator, sizeof(int), alignof(int)); + } + + TEST_F(BaseJsonSerializerTests, ContinueLoading_NullDeletesObject_ValueLoadedCorrectly) + { + using namespace AZ::JsonSerializationResult; + + rapidjson::Value json(rapidjson::kNullType); + int* ptrValue = reinterpret_cast(azmalloc(sizeof(int), alignof(int), AZ::SystemAllocator)); + + ResultCode result = ContinueLoading(&ptrValue, azrtti_typeid(), json, *m_jsonDeserializationContext, Flags::ResolvePointer); + + EXPECT_EQ(Processing::Completed, result.GetProcessing()); + ASSERT_EQ(nullptr, ptrValue); + } + // // ContinueStoring // @@ -156,6 +201,64 @@ namespace JsonSerializationTests Expect_DocStrEq("42"); } + TEST_F(BaseJsonSerializerTests, ContinueStoring_StorePointerToFullDefaultedInstance_ValueStoredCorrectly) + { + using namespace AZ::JsonSerializationResult; + + int value = 42; + int* ptrValue = &value; + int value2 = 42; + int* defaultPtrValue = &value2; + + ResultCode result = + ContinueStoring(*m_jsonDocument, &ptrValue, &defaultPtrValue, azrtti_typeid(), *m_jsonSerializationContext, Flags::ResolvePointer); + + EXPECT_EQ(Processing::Completed, result.GetProcessing()); + Expect_DocStrEq("{}"); + } + + TEST_F(BaseJsonSerializerTests, ContinueStoring_StorePointerToNullptr_ValueStoredCorrectly) + { + using namespace AZ::JsonSerializationResult; + + int* ptrValue = nullptr; + + ResultCode result = ContinueStoring( + *m_jsonDocument, &ptrValue, nullptr, azrtti_typeid(), *m_jsonSerializationContext, Flags::ResolvePointer); + + EXPECT_EQ(Processing::Completed, result.GetProcessing()); + Expect_DocStrEq("null"); + } + + TEST_F(BaseJsonSerializerTests, ContinueStoring_StorePointerToNullptrWithValueDefault_ValueStoredCorrectly) + { + using namespace AZ::JsonSerializationResult; + + int* ptrValue = nullptr; + int value2 = 42; + int* defaultPtrValue = &value2; + + ResultCode result = + ContinueStoring(*m_jsonDocument, &ptrValue, &defaultPtrValue, azrtti_typeid(), *m_jsonSerializationContext, Flags::ResolvePointer); + + EXPECT_EQ(Processing::Completed, result.GetProcessing()); + Expect_DocStrEq("null"); + } + + TEST_F(BaseJsonSerializerTests, ContinueStoring_StorePointerToNullptrWithNullPtrDefault_NullPtrIsStored) + { + using namespace AZ::JsonSerializationResult; + + int* ptrValue = nullptr; + int* defaultPtrValue = nullptr; + + ResultCode result = + ContinueStoring(*m_jsonDocument, &ptrValue, &defaultPtrValue, azrtti_typeid(), *m_jsonSerializationContext, Flags::ResolvePointer); + + EXPECT_EQ(Processing::Completed, result.GetProcessing()); + Expect_DocStrEq("null"); + } + TEST_F(BaseJsonSerializerTests, ContinueStoring_ReplaceDefault_ValueStoredCorrectly) { using namespace AZ::JsonSerializationResult; diff --git a/Code/Framework/AzCore/Tests/Serialization/Json/SmartPointerSerializerTests.cpp b/Code/Framework/AzCore/Tests/Serialization/Json/SmartPointerSerializerTests.cpp index df340a2e61..2fc131aae2 100644 --- a/Code/Framework/AzCore/Tests/Serialization/Json/SmartPointerSerializerTests.cpp +++ b/Code/Framework/AzCore/Tests/Serialization/Json/SmartPointerSerializerTests.cpp @@ -32,11 +32,6 @@ namespace JsonSerializationTests return AZStd::make_shared(); } - AZStd::shared_ptr CreateDefaultInstance() override - { - return AZStd::make_shared(); - } - void Reflect(AZStd::unique_ptr& context) override { context->RegisterGenericType(); @@ -51,6 +46,13 @@ namespace JsonSerializationTests using SmartPointer = T; using Base = SmartPointerBaseTestDescription; + AZStd::shared_ptr CreateDefaultInstance() override + { + auto result = AZStd::make_shared(); + *result = SmartPointer(aznew SimpleClass()); + return result; + } + AZStd::shared_ptr CreateFullySetInstance() override { auto result = AZStd::make_shared(); @@ -107,27 +109,19 @@ namespace JsonSerializationTests }; template class T> - class SmartPointerSimpleClassWithInstanceTestDescription : - public SmartPointerSimpleClassTestDescription + class SmartPointerSimpleDerivedClassTestDescription : + public SmartPointerBaseTestDescription> { public: - using SmartPointer = typename SmartPointerSimpleClassTestDescription::SmartPointer; + using SmartPointer = T; + using Base = SmartPointerBaseTestDescription; AZStd::shared_ptr CreateDefaultInstance() override { auto result = AZStd::make_shared(); - *result = SmartPointer(aznew SimpleClass()); + *result = SmartPointer(aznew BaseClass()); return result; } - }; - - template class T> - class SmartPointerSimpleDerivedClassTestDescription : - public SmartPointerBaseTestDescription> - { - public: - using SmartPointer = T; - using Base = SmartPointerBaseTestDescription; AZStd::shared_ptr CreateFullySetInstance() override { @@ -272,6 +266,13 @@ namespace JsonSerializationTests using SmartPointer = T; using Base = SmartPointerBaseTestDescription; + AZStd::shared_ptr CreateDefaultInstance() override + { + auto result = AZStd::make_shared(); + *result = SmartPointer(aznew BaseClass2()); + return result; + } + AZStd::shared_ptr CreateFullySetInstance() override { auto* instance = aznew MultipleInheritence(); @@ -424,9 +425,6 @@ namespace JsonSerializationTests SmartPointerSimpleClassTestDescription, SmartPointerSimpleClassTestDescription, SmartPointerSimpleClassTestDescription, - SmartPointerSimpleClassWithInstanceTestDescription, - SmartPointerSimpleClassWithInstanceTestDescription, - SmartPointerSimpleClassWithInstanceTestDescription, // Simple derived class, include single inheritance. SmartPointerSimpleDerivedClassTestDescription, SmartPointerSimpleDerivedClassTestDescription, @@ -551,6 +549,37 @@ namespace JsonSerializationTests EXPECT_EQ(nullptr, *instance); } + TEST_F(JsonSmartPointerSerializerTests, Load_DefaultInstanceToNullptr_ReturnsSuccess) + { + namespace JSR = AZ::JsonSerializationResult; + + SmartPointer instance; + AZStd::shared_ptr compare = m_description.CreateDefaultInstance(); + m_jsonDocument->SetObject(); + + JSR::ResultCode result = + m_serializer.Load(&instance, azrtti_typeid(), *m_jsonDocument, *m_jsonDeserializationContext); + + EXPECT_EQ(JSR::Processing::Completed, result.GetProcessing()); + EXPECT_NE(nullptr, instance); + EXPECT_TRUE(m_description.AreEqual(instance, *compare)); + } + + TEST_F(JsonSmartPointerSerializerTests, Load_DefaultObjectDoesNotUpdateInstance_ReturnsSuccess) + { + namespace JSR = AZ::JsonSerializationResult; + + AZStd::shared_ptr instance = m_description.CreateFullySetInstance(); + AZStd::shared_ptr compare = m_description.CreateFullySetInstance(); + m_jsonDocument->SetObject(); + + JSR::ResultCode result = + m_serializer.Load(instance.get(), azrtti_typeid(), *m_jsonDocument, *m_jsonDeserializationContext); + + EXPECT_EQ(JSR::Processing::Completed, result.GetProcessing()); + EXPECT_TRUE(m_description.AreEqual(*instance, *compare)); + } + TEST_F(JsonSmartPointerSerializerTests, Load_InstanceBeingReplacedWithDifferentType_ReturnsSuccess) { namespace JSR = AZ::JsonSerializationResult; @@ -720,13 +749,66 @@ namespace JsonSerializationTests namespace JSR = AZ::JsonSerializationResult; AZStd::shared_ptr instance = m_description.CreateFullySetInstance(); - SmartPointer nullPtr; - JSR::ResultCode result = m_serializer.Store(*m_jsonDocument, instance.get(), &nullPtr, + SmartPointer defaultInstance; + JSR::ResultCode result = m_serializer.Store( + *m_jsonDocument, instance.get(), &defaultInstance, azrtti_typeid(), *m_jsonSerializationContext); EXPECT_EQ(JSR::Outcomes::Success, result.GetOutcome()); } + TEST_F(JsonSmartPointerSerializerTests, Store_ValuePointerIsNullPtr_ReturnsSuccessAndStoresNull) + { + namespace JSR = AZ::JsonSerializationResult; + + SmartPointer instance; + AZStd::shared_ptr defaultInstance = m_description.CreateFullySetInstance(); + JSR::ResultCode result = m_serializer.Store( + *m_jsonDocument, &instance, defaultInstance.get(), azrtti_typeid(), *m_jsonSerializationContext); + + EXPECT_EQ(JSR::Outcomes::Success, result.GetOutcome()); + EXPECT_TRUE(m_jsonDocument->IsNull()); + } + + TEST_F(JsonSmartPointerSerializerTests, Store_ValueAndDefaultPointersAreNullPtr_ReturnsSuccessAndStoresNull) + { + namespace JSR = AZ::JsonSerializationResult; + + SmartPointer instance; + SmartPointer defaultInstance; + JSR::ResultCode result = + m_serializer.Store(*m_jsonDocument, &instance, &defaultInstance, azrtti_typeid(), *m_jsonSerializationContext); + + EXPECT_EQ(JSR::Outcomes::DefaultsUsed, result.GetOutcome()); + EXPECT_TRUE(m_jsonDocument->IsNull()); + } + + TEST_F(JsonSmartPointerSerializerTests, Store_ValueAndDefaultPointersAreBothDefault_ReturnsSuccess) + { + namespace JSR = AZ::JsonSerializationResult; + + AZStd::shared_ptr instance = m_description.CreateDefaultInstance(); + AZStd::shared_ptr defaultInstance = m_description.CreateDefaultInstance(); + JSR::ResultCode result = + m_serializer.Store(*m_jsonDocument, instance.get(), defaultInstance.get(), azrtti_typeid(), *m_jsonSerializationContext); + + EXPECT_EQ(JSR::Outcomes::DefaultsUsed, result.GetOutcome()); + Expect_ExplicitDefault(*m_jsonDocument); + } + + TEST_F(JsonSmartPointerSerializerTests, Store_ValueHasDefaultValuesAndDefaultHasNullPointer_ReturnsSuccess) + { + namespace JSR = AZ::JsonSerializationResult; + + AZStd::shared_ptr instance = m_description.CreateDefaultInstance(); + SmartPointer defaultInstance; + JSR::ResultCode result = m_serializer.Store( + *m_jsonDocument, instance.get(), &defaultInstance, azrtti_typeid(), *m_jsonSerializationContext); + + EXPECT_EQ(JSR::Outcomes::DefaultsUsed, result.GetOutcome()); + Expect_ExplicitDefault(*m_jsonDocument); + } + TEST_F(JsonSmartPointerSerializerTests, Store_DefaultPointerIsOtherClass_CompletesButDoesNotReturnDefaults) { namespace JSR = AZ::JsonSerializationResult; @@ -749,7 +831,7 @@ namespace JsonSerializationTests EXPECT_EQ(JSR::Processing::Completed, result.GetProcessing()); } - TEST_F(JsonSmartPointerSerializerTests, Store_SaveAnClassThatIsNotReflected_ReturnsUnknown) + TEST_F(JsonSmartPointerSerializerTests, Store_ClassThatIsNotReflected_ReturnsUnknown) { namespace JSR = AZ::JsonSerializationResult; diff --git a/Code/Framework/AzFramework/AzFramework/Entity/EntityDebugDisplayBus.h b/Code/Framework/AzFramework/AzFramework/Entity/EntityDebugDisplayBus.h index f84f0276e1..fb6b8d7d72 100644 --- a/Code/Framework/AzFramework/AzFramework/Entity/EntityDebugDisplayBus.h +++ b/Code/Framework/AzFramework/AzFramework/Entity/EntityDebugDisplayBus.h @@ -34,6 +34,8 @@ class ITexture; namespace AzFramework { + inline constexpr AZ::s32 g_defaultSceneEntityDebugDisplayId = AZ_CRC_CE("MainViewportEntityDebugDisplayId"); // default id to draw to all viewports in the default scene + /// DebugDisplayRequests provides a debug draw api to be used by components and viewport features. class DebugDisplayRequests : public AZ::EBusTraits diff --git a/Code/Framework/AzFramework/AzFramework/ProjectManager/ProjectManager.cpp b/Code/Framework/AzFramework/AzFramework/ProjectManager/ProjectManager.cpp index ea8fd75cfd..985bc4665d 100644 --- a/Code/Framework/AzFramework/AzFramework/ProjectManager/ProjectManager.cpp +++ b/Code/Framework/AzFramework/AzFramework/ProjectManager/ProjectManager.cpp @@ -137,7 +137,7 @@ namespace AzFramework::ProjectManager } AZ::IO::FixedMaxPath pythonPath = engineRootPath / "python"; pythonPath /= AZ_TRAIT_AZFRAMEWORK_PYTHON_SHELL; - auto cmdPath = AZ::IO::FixedMaxPathString::format("%s %s%s --executable_path=%s --parent_pid=%" PRId64, pythonPath.Native().c_str(), + auto cmdPath = AZ::IO::FixedMaxPathString::format("%s %s%s --executable_path=%s --parent_pid=%" PRIu32, pythonPath.Native().c_str(), debugOption.c_str(), (projectManagerPath / projectsScript).c_str(), executablePath.c_str(), AZ::Platform::GetCurrentProcessId()); AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo; diff --git a/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl b/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl index b0c1a18b08..360ab93436 100644 --- a/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl +++ b/Code/Framework/AzFramework/AzFramework/Scene/Scene.inl @@ -51,7 +51,7 @@ namespace AzFramework } template - bool Scene::UnsetSubsystem(const T& system) + bool Scene::UnsetSubsystem([[maybe_unused]] const T& system) { const AZ::TypeId& targetType = azrtti_typeid(); const size_t systemKeysCount = m_systemKeys.size(); diff --git a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesInterface.h b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesInterface.h index ea19b3a0be..95d0b9e3a7 100644 --- a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesInterface.h +++ b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesInterface.h @@ -148,6 +148,12 @@ namespace AzFramework //! Blocks until all operations made on the provided ticket before the barrier call have completed. virtual void Barrier(EntitySpawnTicket& ticket, BarrierCallback completionCallback) = 0; + //! Register a handler for OnSpawned events. + virtual void AddOnSpawnedHandler(AZ::Event>::Handler& handler) = 0; + + //! Register a handler for OnDespawned events. + virtual void AddOnDespawnedHandler(AZ::Event>::Handler& handler) = 0; + protected: [[nodiscard]] virtual void* CreateTicket(AZ::Data::Asset&& spawnable) = 0; virtual void DestroyTicket(void* ticket) = 0; diff --git a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp index 4e98616ef1..3ab004b516 100644 --- a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp +++ b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.cpp @@ -114,6 +114,16 @@ namespace AzFramework } } + void SpawnableEntitiesManager::AddOnSpawnedHandler(AZ::Event>::Handler& handler) + { + handler.Connect(m_onSpawnedEvent); + } + + void SpawnableEntitiesManager::AddOnDespawnedHandler(AZ::Event>::Handler& handler) + { + handler.Connect(m_onDespawnedEvent); + } + auto SpawnableEntitiesManager::ProcessQueue() -> CommandQueueStatus { AZStd::queue pendingRequestQueue; @@ -223,6 +233,8 @@ namespace AzFramework ticket.m_spawnedEntities.begin() + spawnedEntitiesCount, ticket.m_spawnedEntities.end())); } + m_onSpawnedEvent.Signal(ticket.m_spawnable); + ticket.m_currentTicketId++; return true; } @@ -257,6 +269,8 @@ namespace AzFramework ticket.m_spawnedEntities.begin() + spawnedEntitiesCount, ticket.m_spawnedEntities.end())); } + m_onSpawnedEvent.Signal(ticket.m_spawnable); + ticket.m_currentTicketId++; return true; } @@ -289,6 +303,8 @@ namespace AzFramework request.m_completionCallback(*request.m_ticket); } + m_onDespawnedEvent.Signal(ticket.m_spawnable); + ticket.m_currentTicketId++; return true; } @@ -315,6 +331,8 @@ namespace AzFramework &GameEntityContextRequestBus::Events::DestroyGameEntityAndDescendants, entity->GetId()); } } + + m_onDespawnedEvent.Signal(ticket.m_spawnable); // Rebuild the list of entities. ticket.m_spawnedEntities.clear(); @@ -350,6 +368,9 @@ namespace AzFramework } ticket.m_currentTicketId++; + + m_onSpawnedEvent.Signal(ticket.m_spawnable); + return true; } else diff --git a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.h b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.h index 29e9ed797b..c70b9ccaa6 100644 --- a/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.h +++ b/Code/Framework/AzFramework/AzFramework/Spawnable/SpawnableEntitiesManager.h @@ -60,6 +60,9 @@ namespace AzFramework void Barrier(EntitySpawnTicket& spawnInfo, BarrierCallback completionCallback) override; + void AddOnSpawnedHandler(AZ::Event>::Handler& handler) override; + void AddOnDespawnedHandler(AZ::Event>::Handler& handler) override; + // // The following function is thread safe but intended to be run from the main thread. // @@ -156,5 +159,8 @@ namespace AzFramework AZStd::deque m_delayedQueue; //!< Requests that were processed before, but couldn't be completed. AZStd::queue m_pendingRequestQueue; AZStd::mutex m_pendingRequestQueueMutex; + + AZ::Event> m_onSpawnedEvent; + AZ::Event> m_onDespawnedEvent; }; } // namespace AzFramework diff --git a/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.cpp b/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.cpp index ee49a95b23..e9dace3433 100644 --- a/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.cpp +++ b/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.cpp @@ -12,14 +12,150 @@ #include "CameraInput.h" +#include #include #include +#include #include #include namespace AzFramework { - void CameraSystem::HandleEvents(const InputEvent& event) + AZ_CVAR( + float, ed_cameraSystemDefaultPlaneHeight, 34.0f, nullptr, AZ::ConsoleFunctorFlags::Null, + "The default height of the ground plane to do intersection tests against when orbiting"); + AZ_CVAR(float, ed_cameraSystemBoostMultiplier, 3.0f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemTranslateSpeed, 10.0f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemOrbitDollyScrollSpeed, 0.02f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemOrbitDollyCursorSpeed, 0.01f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemScrollTranslateSpeed, 0.02f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemDefaultOrbitDistance, 60.0f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemMaxOrbitDistance, 100.0f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemLookSmoothness, 5.0f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemTranslateSmoothness, 5.0f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemRotateSpeed, 0.005f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(float, ed_cameraSystemPanSpeed, 0.01f, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(bool, ed_cameraSystemPanInvertX, true, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(bool, ed_cameraSystemPanInvertY, true, nullptr, AZ::ConsoleFunctorFlags::Null, ""); + + AZ_CVAR( + AZ::CVarFixedString, ed_cameraSystemTranslateForwardKey, "keyboard_key_alphanumeric_W", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR( + AZ::CVarFixedString, ed_cameraSystemTranslateBackwardKey, "keyboard_key_alphanumeric_S", nullptr, AZ::ConsoleFunctorFlags::Null, + ""); + AZ_CVAR( + AZ::CVarFixedString, ed_cameraSystemTranslateLeftKey, "keyboard_key_alphanumeric_A", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR( + AZ::CVarFixedString, ed_cameraSystemTranslateRightKey, "keyboard_key_alphanumeric_D", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(AZ::CVarFixedString, ed_cameraSystemTranslateUpKey, "keyboard_key_alphanumeric_E", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR( + AZ::CVarFixedString, ed_cameraSystemTranslateDownKey, "keyboard_key_alphanumeric_Q", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR( + AZ::CVarFixedString, ed_cameraSystemTranslateBoostKey, "keyboard_key_modifier_shift_l", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(AZ::CVarFixedString, ed_cameraSystemOrbitKey, "keyboard_key_modifier_alt_l", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + + AZ_CVAR(AZ::CVarFixedString, ed_cameraSystemFreeLookButton, "mouse_button_right", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(AZ::CVarFixedString, ed_cameraSystemFreePanButton, "mouse_button_middle", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(AZ::CVarFixedString, ed_cameraSystemOrbitLookButton, "mouse_button_left", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(AZ::CVarFixedString, ed_cameraSystemOrbitDollyButton, "mouse_button_right", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + AZ_CVAR(AZ::CVarFixedString, ed_cameraSystemOrbitPanButton, "mouse_button_middle", nullptr, AZ::ConsoleFunctorFlags::Null, ""); + + static InputChannelId CameraTranslateForwardId; + static InputChannelId CameraTranslateBackwardId; + static InputChannelId CameraTranslateLeftId; + static InputChannelId CameraTranslateRightId; + static InputChannelId CameraTranslateDownId; + static InputChannelId CameraTranslateUpId; + static InputChannelId CameraTranslateBoostId; + static InputChannelId CameraOrbitId; + + // externed elsewhere + InputChannelId CameraFreeLookButton; + InputChannelId CameraFreePanButton; + InputChannelId CameraOrbitLookButton; + InputChannelId CameraOrbitDollyButton; + InputChannelId CameraOrbitPanButton; + + void ReloadCameraKeyBindings() + { + const AZ::CVarFixedString& forward = ed_cameraSystemTranslateForwardKey; + CameraTranslateForwardId = InputChannelId(forward.c_str()); + const AZ::CVarFixedString& backward = ed_cameraSystemTranslateBackwardKey; + CameraTranslateBackwardId = InputChannelId(backward.c_str()); + const AZ::CVarFixedString& left = ed_cameraSystemTranslateLeftKey; + CameraTranslateLeftId = InputChannelId(left.c_str()); + const AZ::CVarFixedString& right = ed_cameraSystemTranslateRightKey; + CameraTranslateRightId = InputChannelId(right.c_str()); + const AZ::CVarFixedString& down = ed_cameraSystemTranslateDownKey; + CameraTranslateDownId = InputChannelId(down.c_str()); + const AZ::CVarFixedString& up = ed_cameraSystemTranslateUpKey; + CameraTranslateUpId = InputChannelId(up.c_str()); + const AZ::CVarFixedString& boost = ed_cameraSystemTranslateBoostKey; + CameraTranslateBoostId = InputChannelId(boost.c_str()); + const AZ::CVarFixedString& orbit = ed_cameraSystemOrbitKey; + CameraOrbitId = InputChannelId(orbit.c_str()); + const AZ::CVarFixedString& freeLook = ed_cameraSystemFreeLookButton; + CameraFreeLookButton = InputChannelId(freeLook.c_str()); + const AZ::CVarFixedString& freePan = ed_cameraSystemFreePanButton; + CameraFreePanButton = InputChannelId(freePan.c_str()); + const AZ::CVarFixedString& orbitLook = ed_cameraSystemOrbitLookButton; + CameraOrbitLookButton = InputChannelId(orbitLook.c_str()); + const AZ::CVarFixedString& orbitDolly = ed_cameraSystemOrbitDollyButton; + CameraOrbitDollyButton = InputChannelId(orbitDolly.c_str()); + const AZ::CVarFixedString& orbitPan = ed_cameraSystemOrbitPanButton; + CameraOrbitPanButton = InputChannelId(orbitPan.c_str()); + } + + static void ReloadCameraKeyBindingsConsole(const AZ::ConsoleCommandContainer&) + { + ReloadCameraKeyBindings(); + } + + AZ_CONSOLEFREEFUNC(ReloadCameraKeyBindingsConsole, AZ::ConsoleFunctorFlags::Null, "Reload keybindings for the modern camera system"); + + // Based on paper by David Eberly - https://www.geometrictools.com/Documentation/EulerAngles.pdf + AZ::Vector3 EulerAngles(const AZ::Matrix3x3& orientation) + { + float x; + float y; + float z; + + // 2.4 Factor as RzRyRx + if (orientation.GetElement(2, 0) < 1.0f) + { + if (orientation.GetElement(2, 0) > -1.0f) + { + x = std::atan2(orientation.GetElement(2, 1), orientation.GetElement(2, 2)); + y = std::asin(-orientation.GetElement(2, 0)); + z = std::atan2(orientation.GetElement(1, 0), orientation.GetElement(0, 0)); + } + else + { + x = 0.0f; + y = AZ::Constants::Pi * 0.5f; + z = -std::atan2(-orientation.GetElement(2, 1), orientation.GetElement(1, 1)); + } + } + else + { + x = 0.0f; + y = -AZ::Constants::Pi * 0.5f; + z = std::atan2(-orientation.GetElement(1, 2), orientation.GetElement(1, 1)); + } + + return {x, y, z}; + } + + void UpdateCameraFromTransform(Camera& camera, const AZ::Transform& transform) + { + const auto eulerAngles = AzFramework::EulerAngles(AZ::Matrix3x3::CreateFromTransform(transform)); + + camera.m_lookAt = transform.GetTranslation(); + camera.m_pitch = eulerAngles.GetX(); + camera.m_yaw = eulerAngles.GetZ(); + } + + bool CameraSystem::HandleEvents(const InputEvent& event) { if (const auto& cursor_motion = AZStd::get_if(&event)) { @@ -30,10 +166,10 @@ namespace AzFramework m_scrollDelta = scroll->m_delta; } - m_cameras.HandleEvents(event); + return m_cameras.HandleEvents(event); } - Camera CameraSystem::StepCamera(const Camera& targetCamera, float deltaTime) + Camera CameraSystem::StepCamera(const Camera& targetCamera, const float deltaTime) { const auto cursorDelta = m_currentCursorPosition.has_value() && m_lastCursorPosition.has_value() ? m_currentCursorPosition.value() - m_lastCursorPosition.value() @@ -51,36 +187,41 @@ namespace AzFramework return nextCamera; } - void Cameras::AddCamera(AZStd::shared_ptr camera_input) + void Cameras::AddCamera(AZStd::shared_ptr cameraInput) { - m_idleCameraInputs.push_back(AZStd::move(camera_input)); + m_idleCameraInputs.push_back(AZStd::move(cameraInput)); } - void Cameras::HandleEvents(const InputEvent& event) + bool Cameras::HandleEvents(const InputEvent& event) { - for (auto& camera_input : m_activeCameraInputs) + bool handling = false; + for (auto& cameraInput : m_activeCameraInputs) { - camera_input->HandleEvents(event); + cameraInput->HandleEvents(event); + handling = !cameraInput->Idle() || handling; } - for (auto& camera_input : m_idleCameraInputs) + for (auto& cameraInput : m_idleCameraInputs) { - camera_input->HandleEvents(event); + cameraInput->HandleEvents(event); } + + return handling; } - Camera Cameras::StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, const float deltaTime) + Camera Cameras::StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, const float scrollDelta, const float deltaTime) { for (int i = 0; i < m_idleCameraInputs.size();) { - auto& camera_input = m_idleCameraInputs[i]; - const bool can_begin = camera_input->Beginning() && + auto& cameraInput = m_idleCameraInputs[i]; + const bool canBegin = cameraInput->Beginning() && std::all_of(m_activeCameraInputs.cbegin(), m_activeCameraInputs.cend(), [](const auto& input) { return !input->Exclusive(); }) && - (!camera_input->Exclusive() || (camera_input->Exclusive() && m_activeCameraInputs.empty())); - if (can_begin) + (!cameraInput->Exclusive() || (cameraInput->Exclusive() && m_activeCameraInputs.empty())); + + if (canBegin) { - m_activeCameraInputs.push_back(camera_input); + m_activeCameraInputs.push_back(cameraInput); using AZStd::swap; swap(m_idleCameraInputs[i], m_idleCameraInputs[m_idleCameraInputs.size() - 1]); m_idleCameraInputs.pop_back(); @@ -93,25 +234,25 @@ namespace AzFramework // accumulate Camera nextCamera = targetCamera; - for (auto& camera_input : m_activeCameraInputs) + for (auto& cameraInput : m_activeCameraInputs) { - nextCamera = camera_input->StepCamera(nextCamera, cursorDelta, scrollDelta, deltaTime); + nextCamera = cameraInput->StepCamera(nextCamera, cursorDelta, scrollDelta, deltaTime); } for (int i = 0; i < m_activeCameraInputs.size();) { - auto& camera_input = m_activeCameraInputs[i]; - if (camera_input->Ending()) + auto& cameraInput = m_activeCameraInputs[i]; + if (cameraInput->Ending()) { - camera_input->ClearActivation(); - m_idleCameraInputs.push_back(camera_input); + cameraInput->ClearActivation(); + m_idleCameraInputs.push_back(cameraInput); using AZStd::swap; swap(m_activeCameraInputs[i], m_activeCameraInputs[m_activeCameraInputs.size() - 1]); m_activeCameraInputs.pop_back(); } else { - camera_input->ContinueActivation(); + cameraInput->ContinueActivation(); i++; } } @@ -134,7 +275,7 @@ namespace AzFramework { if (const auto& input = AZStd::get_if(&event)) { - if (input->m_channelId == m_channelId) + if (input->m_channelId == m_rotateChannelId) { if (input->m_state == InputChannel::State::Began) { @@ -154,14 +295,14 @@ namespace AzFramework { Camera nextCamera = targetCamera; - nextCamera.m_pitch += float(cursorDelta.m_y) * m_props.m_rotateSpeed; - nextCamera.m_yaw += float(cursorDelta.m_x) * m_props.m_rotateSpeed; + nextCamera.m_pitch -= float(cursorDelta.m_y) * ed_cameraSystemRotateSpeed; + nextCamera.m_yaw -= float(cursorDelta.m_x) * ed_cameraSystemRotateSpeed; - auto clamp_rotation = [](const float angle) { return std::fmod(angle + AZ::Constants::TwoOverPi, AZ::Constants::TwoOverPi); }; + const auto clampRotation = [](const float angle) { return std::fmod(angle + AZ::Constants::TwoPi, AZ::Constants::TwoPi); }; - nextCamera.m_yaw = clamp_rotation(nextCamera.m_yaw); + nextCamera.m_yaw = clampRotation(nextCamera.m_yaw); // clamp pitch to be +-90 degrees - nextCamera.m_pitch = AZ::GetClamp(nextCamera.m_pitch, -AZ::Constants::Pi * 0.5f, AZ::Constants::Pi * 0.5f); + nextCamera.m_pitch = AZ::GetClamp(nextCamera.m_pitch, -AZ::Constants::HalfPi, AZ::Constants::HalfPi); return nextCamera; } @@ -170,7 +311,7 @@ namespace AzFramework { if (const auto& input = AZStd::get_if(&event)) { - if (input->m_channelId == InputDeviceMouse::Button::Middle) + if (input->m_channelId == m_panChannelId) { if (input->m_state == InputChannel::State::Began) { @@ -190,51 +331,50 @@ namespace AzFramework { Camera nextCamera = targetCamera; - const auto pan_axes = m_panAxesFn(nextCamera); + const auto panAxes = m_panAxesFn(nextCamera); - const auto delta_pan_x = float(cursorDelta.m_x) * pan_axes.m_horizontalAxis * m_props.m_panSpeed; - const auto delta_pan_y = float(cursorDelta.m_y) * pan_axes.m_verticalAxis * m_props.m_panSpeed; + const auto deltaPanX = float(cursorDelta.m_x) * panAxes.m_horizontalAxis * ed_cameraSystemPanSpeed; + const auto deltaPanY = float(cursorDelta.m_y) * panAxes.m_verticalAxis * ed_cameraSystemPanSpeed; const auto inv = [](const bool invert) { constexpr float Dir[] = {1.0f, -1.0f}; return Dir[static_cast(invert)]; }; - nextCamera.m_lookAt += delta_pan_x * inv(m_props.m_panInvertX); - nextCamera.m_lookAt += delta_pan_y * -inv(m_props.m_panInvertY); + nextCamera.m_lookAt += deltaPanX * inv(ed_cameraSystemPanInvertX); + nextCamera.m_lookAt += deltaPanY * -inv(ed_cameraSystemPanInvertY); return nextCamera; } TranslateCameraInput::TranslationType TranslateCameraInput::translationFromKey(InputChannelId channelId) { - // note: remove hard-coded InputDevice keys - if (channelId == InputDeviceKeyboard::Key::AlphanumericW) + if (channelId == CameraTranslateForwardId) { return TranslationType::Forward; } - if (channelId == InputDeviceKeyboard::Key::AlphanumericS) + if (channelId == CameraTranslateBackwardId) { return TranslationType::Backward; } - if (channelId == InputDeviceKeyboard::Key::AlphanumericA) + if (channelId == CameraTranslateLeftId) { return TranslationType::Left; } - if (channelId == InputDeviceKeyboard::Key::AlphanumericD) + if (channelId == CameraTranslateRightId) { return TranslationType::Right; } - if (channelId == InputDeviceKeyboard::Key::AlphanumericQ) + if (channelId == CameraTranslateDownId) { return TranslationType::Down; } - if (channelId == InputDeviceKeyboard::Key::AlphanumericE) + if (channelId == CameraTranslateUpId) { return TranslationType::Up; } @@ -259,19 +399,19 @@ namespace AzFramework BeginActivation(); } - if (input->m_channelId == InputDeviceKeyboard::Key::ModifierShiftL) + if (input->m_channelId == CameraTranslateBoostId) { m_boost = true; } } else if (input->m_state == InputChannel::State::Ended) { - m_translation ^= translationFromKey(input->m_channelId); + m_translation &= ~(translationFromKey(input->m_channelId)); if (m_translation == TranslationType::Nil) { EndActivation(); } - if (input->m_channelId == InputDeviceKeyboard::Key::ModifierShiftL) + if (input->m_channelId == CameraTranslateBoostId) { m_boost = false; } @@ -285,13 +425,13 @@ namespace AzFramework { Camera nextCamera = targetCamera; - const auto translation_basis = m_translationAxesFn(nextCamera); - const auto axisX = translation_basis.GetBasisX(); - const auto axisY = translation_basis.GetBasisY(); - const auto axisZ = translation_basis.GetBasisZ(); + const auto translationBasis = m_translationAxesFn(nextCamera); + const auto axisX = translationBasis.GetBasisX(); + const auto axisY = translationBasis.GetBasisY(); + const auto axisZ = translationBasis.GetBasisZ(); - const float speed = [boost = m_boost, props = m_props]() { - return props.m_translateSpeed * (boost ? props.m_boostMultiplier : 1.0f); + const float speed = [boost = m_boost]() { + return ed_cameraSystemTranslateSpeed * (boost ? ed_cameraSystemBoostMultiplier : 1.0f); }(); if ((m_translation & TranslationType::Forward) == TranslationType::Forward) @@ -342,12 +482,8 @@ namespace AzFramework { if (const auto* input = AZStd::get_if(&event)) { - if (input->m_channelId == InputDeviceKeyboard::Key::ModifierAltL) + if (input->m_channelId == CameraOrbitId) { - if (input->m_state == InputChannel::State::Updated) - { - goto end; - } if (input->m_state == InputChannel::State::Began) { BeginActivation(); @@ -358,7 +494,7 @@ namespace AzFramework } } } - end: + if (Active()) { m_orbitCameras.HandleEvents(event); @@ -366,29 +502,29 @@ namespace AzFramework } Camera OrbitCameraInput::StepCamera( - const Camera& targetCamera, const ScreenVector& cursorDelta, const float scrollDelta, float deltaTime) + const Camera& targetCamera, const ScreenVector& cursorDelta, const float scrollDelta, const float deltaTime) { Camera nextCamera = targetCamera; if (Beginning()) { float hit_distance = 0.0f; - if (AZ::Plane::CreateFromNormalAndPoint(AZ::Vector3::CreateAxisZ(), AZ::Vector3::CreateZero()) - .CastRay(targetCamera.Translation(), targetCamera.Rotation().GetBasisY() * m_props.m_maxOrbitDistance, hit_distance)) + if (AZ::Plane::CreateFromNormalAndPoint(AZ::Vector3::CreateAxisZ(), AZ::Vector3::CreateAxisZ(ed_cameraSystemDefaultPlaneHeight)) + .CastRay(targetCamera.Translation(), targetCamera.Rotation().GetBasisY(), hit_distance)) { + hit_distance = AZStd::min(hit_distance, ed_cameraSystemMaxOrbitDistance); nextCamera.m_lookDist = -hit_distance; nextCamera.m_lookAt = targetCamera.Translation() + targetCamera.Rotation().GetBasisY() * hit_distance; } else { - nextCamera.m_lookDist = -m_props.m_defaultOrbitDistance; - nextCamera.m_lookAt = targetCamera.Translation() + targetCamera.Rotation().GetBasisY() * m_props.m_defaultOrbitDistance; + nextCamera.m_lookDist = -ed_cameraSystemMaxOrbitDistance; + nextCamera.m_lookAt = targetCamera.Translation() + targetCamera.Rotation().GetBasisY() * ed_cameraSystemMaxOrbitDistance; } } if (Active()) { - // todo: need to return nested cameras to idle state when ending nextCamera = m_orbitCameras.StepCamera(nextCamera, cursorDelta, scrollDelta, deltaTime); } @@ -413,10 +549,10 @@ namespace AzFramework Camera OrbitDollyScrollCameraInput::StepCamera( const Camera& targetCamera, [[maybe_unused]] const ScreenVector& cursorDelta, const float scrollDelta, - [[maybe_unused]] float deltaTime) + [[maybe_unused]] const float deltaTime) { Camera nextCamera = targetCamera; - nextCamera.m_lookDist = AZ::GetMin(nextCamera.m_lookDist + scrollDelta * m_props.m_dollySpeed, 0.0f); + nextCamera.m_lookDist = AZ::GetMin(nextCamera.m_lookDist + scrollDelta * ed_cameraSystemOrbitDollyScrollSpeed, 0.0f); EndActivation(); return nextCamera; } @@ -425,7 +561,7 @@ namespace AzFramework { if (const auto& input = AZStd::get_if(&event)) { - if (input->m_channelId == InputDeviceMouse::Button::Right) + if (input->m_channelId == m_dollyChannelId) { if (input->m_state == InputChannel::State::Began) { @@ -444,7 +580,7 @@ namespace AzFramework [[maybe_unused]] const float deltaTime) { Camera nextCamera = targetCamera; - nextCamera.m_lookDist = AZ::GetMin(nextCamera.m_lookDist + float(cursorDelta.m_y) * m_props.m_dollySpeed, 0.0f); + nextCamera.m_lookDist = AZ::GetMin(nextCamera.m_lookDist + float(cursorDelta.m_y) * ed_cameraSystemOrbitDollyCursorSpeed, 0.0f); return nextCamera; } @@ -457,7 +593,7 @@ namespace AzFramework } Camera ScrollTranslationCameraInput::StepCamera( - const Camera& targetCamera, [[maybe_unused]] const ScreenVector& cursorDelta, float scrollDelta, + const Camera& targetCamera, [[maybe_unused]] const ScreenVector& cursorDelta, const float scrollDelta, [[maybe_unused]] const float deltaTime) { Camera nextCamera = targetCamera; @@ -465,38 +601,39 @@ namespace AzFramework const auto translation_basis = LookTranslation(nextCamera); const auto axisY = translation_basis.GetBasisY(); - nextCamera.m_lookAt += axisY * scrollDelta * m_props.m_translateSpeed; + nextCamera.m_lookAt += axisY * scrollDelta * ed_cameraSystemScrollTranslateSpeed; EndActivation(); return nextCamera; } - Camera SmoothCamera(const Camera& currentCamera, const Camera& targetCamera, const SmoothProps& props, const float deltaTime) + Camera SmoothCamera(const Camera& currentCamera, const Camera& targetCamera, const float deltaTime) { const auto clamp_rotation = [](const float angle) { return std::fmod(angle + AZ::Constants::TwoPi, AZ::Constants::TwoPi); }; // keep yaw in 0 - 360 range - float target_yaw = clamp_rotation(targetCamera.m_yaw); - const float current_yaw = clamp_rotation(currentCamera.m_yaw); + float targetYaw = clamp_rotation(targetCamera.m_yaw); + const float currentYaw = clamp_rotation(currentCamera.m_yaw); - auto sign = [](const float value) { return static_cast((0.0f < value) - (value < 0.0f)); }; + // return the sign of the float input (-1, 0, 1) + const auto sign = [](const float value) { return aznumeric_cast((0.0f < value) - (value < 0.0f)); }; // ensure smooth transition when moving across 0 - 360 boundary - const float yaw_delta = target_yaw - current_yaw; - if (std::abs(yaw_delta) >= AZ::Constants::Pi) + const float yawDelta = targetYaw - currentYaw; + if (std::abs(yawDelta) >= AZ::Constants::Pi) { - target_yaw -= AZ::Constants::TwoPi * sign(yaw_delta); + targetYaw -= AZ::Constants::TwoPi * sign(yawDelta); } Camera camera; - // note: the math for the lerp smoothing implementation for camera rotation and translation was inspired by this excellent + // note: the math for the lerp smoothing implementation for camera rotation and translation was inspired by this excellent // article by Scott Lembcke: https://www.gamasutra.com/blogs/ScottLembcke/20180404/316046/Improved_Lerp_Smoothing.php - const float lookRate = std::exp2(props.m_lookSmoothness); + const float lookRate = std::exp2(ed_cameraSystemLookSmoothness); const float lookT = std::exp2(-lookRate * deltaTime); camera.m_pitch = AZ::Lerp(targetCamera.m_pitch, currentCamera.m_pitch, lookT); - camera.m_yaw = AZ::Lerp(target_yaw, current_yaw, lookT); - const float moveRate = std::exp2(props.m_moveSmoothness); + camera.m_yaw = AZ::Lerp(targetYaw, currentYaw, lookT); + const float moveRate = std::exp2(ed_cameraSystemTranslateSmoothness); const float moveT = std::exp2(-moveRate * deltaTime); camera.m_lookDist = AZ::Lerp(targetCamera.m_lookDist, currentCamera.m_lookDist, moveT); camera.m_lookAt = targetCamera.m_lookAt.Lerp(currentCamera.m_lookAt, moveT); @@ -508,20 +645,24 @@ namespace AzFramework const auto& inputChannelId = inputChannel.GetInputChannelId(); const auto& inputDeviceId = inputChannel.GetInputDevice().GetInputDeviceId(); - if (inputChannelId == InputDeviceMouse::SystemCursorPosition) + const bool wasMouseButton = + AZStd::any_of(InputDeviceMouse::Button::All.begin(), InputDeviceMouse::Button::All.end(), [inputChannelId](const auto& button) { + return button == inputChannelId; + }); + + if (inputChannelId == InputDeviceMouse::Movement::X || inputChannelId == InputDeviceMouse::Movement::Y) { - AZ::Vector2 systemCursorPositionNormalized = AZ::Vector2::CreateZero(); - InputSystemCursorRequestBus::EventResult( - systemCursorPositionNormalized, inputDeviceId, &InputSystemCursorRequestBus::Events::GetSystemCursorPositionNormalized); + const auto* position = inputChannel.GetCustomData(); + AZ_Assert(position, "Expected PositionData2D but found nullptr"); return CursorMotionEvent{ScreenPoint( - systemCursorPositionNormalized.GetX() * windowSize.m_width, systemCursorPositionNormalized.GetY() * windowSize.m_height)}; + position->m_normalizedPosition.GetX() * windowSize.m_width, position->m_normalizedPosition.GetY() * windowSize.m_height)}; } else if (inputChannelId == InputDeviceMouse::Movement::Z) { return ScrollEvent{inputChannel.GetValue()}; } - else if (InputDeviceMouse::IsMouseDevice(inputDeviceId) || InputDeviceKeyboard::IsKeyboardDevice(inputDeviceId)) + else if (wasMouseButton || InputDeviceKeyboard::IsKeyboardDevice(inputDeviceId)) { return DiscreteInputEvent{inputChannelId, inputChannel.GetState()}; } diff --git a/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.h b/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.h index 736e2404d9..6ccd7c43eb 100644 --- a/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.h +++ b/Code/Framework/AzFramework/AzFramework/Viewport/CameraInput.h @@ -17,13 +17,16 @@ #include #include #include -#include -#include #include +#include namespace AzFramework { - struct WindowSize; + //! Update camera key bindings that can be overridden with AZ console vars (invoke from console to update) + void ReloadCameraKeyBindings(); + + //! Return Euler angles (pitch, roll, yaw) for the incoming orientation. + AZ::Vector3 EulerAngles(const AZ::Matrix3x3& orientation); struct Camera { @@ -51,8 +54,8 @@ namespace AzFramework inline AZ::Transform Camera::Transform() const { - return AZ::Transform::CreateTranslation(m_lookAt) * AZ::Transform::CreateRotationX(m_pitch) * - AZ::Transform::CreateRotationZ(m_yaw) * AZ::Transform::CreateTranslation(AZ::Vector3::CreateAxisZ(m_lookDist)); + return AZ::Transform::CreateTranslation(m_lookAt) * AZ::Transform::CreateRotationZ(m_yaw) * + AZ::Transform::CreateRotationX(m_pitch) * AZ::Transform::CreateTranslation(AZ::Vector3::CreateAxisY(m_lookDist)); } inline AZ::Matrix3x3 Camera::Rotation() const @@ -65,6 +68,8 @@ namespace AzFramework return Transform().GetTranslation(); } + void UpdateCameraFromTransform(Camera& camera, const AZ::Transform& transform); + struct CursorMotionEvent { ScreenPoint m_position; @@ -159,19 +164,13 @@ namespace AzFramework Activation m_activation = Activation::Idle; }; - struct SmoothProps - { - float m_lookSmoothness = 5.0f; - float m_moveSmoothness = 5.0f; - }; - - Camera SmoothCamera(const Camera& currentCamera, const Camera& targetCamera, const SmoothProps& props, float deltaTime); + Camera SmoothCamera(const Camera& currentCamera, const Camera& targetCamera, float deltaTime); class Cameras { public: void AddCamera(AZStd::shared_ptr cameraInput); - void HandleEvents(const InputEvent& event); + bool HandleEvents(const InputEvent& event); Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime); void Reset(); @@ -183,7 +182,7 @@ namespace AzFramework class CameraSystem { public: - void HandleEvents(const InputEvent& event); + bool HandleEvents(const InputEvent& event); Camera StepCamera(const Camera& targetCamera, float deltaTime); Cameras m_cameras; @@ -197,19 +196,16 @@ namespace AzFramework class RotateCameraInput : public CameraInput { public: - explicit RotateCameraInput(const InputChannelId channelId) - : m_channelId(channelId) + explicit RotateCameraInput(const InputChannelId rotateChannelId) + : m_rotateChannelId(rotateChannelId) { } + void HandleEvents(const InputEvent& event) override; Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override; - InputChannelId m_channelId; - - struct Props - { - float m_rotateSpeed = 0.005f; - } m_props; + private: + InputChannelId m_rotateChannelId; }; struct PanAxes @@ -242,22 +238,17 @@ namespace AzFramework class PanCameraInput : public CameraInput { public: - explicit PanCameraInput(PanAxesFn panAxesFn) + PanCameraInput(const InputChannelId panChannelId, PanAxesFn panAxesFn) : m_panAxesFn(AZStd::move(panAxesFn)) + , m_panChannelId(panChannelId) { } void HandleEvents(const InputEvent& event) override; Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override; - struct Props - { - float m_panSpeed = 0.01f; - bool m_panInvertX = true; - bool m_panInvertY = true; - } m_props; - private: PanAxesFn m_panAxesFn; + InputChannelId m_panChannelId; }; using TranslationAxesFn = AZStd::function; @@ -298,17 +289,11 @@ namespace AzFramework Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override; void ResetImpl() override; - struct Props - { - float m_translateSpeed = 10.0f; - float m_boostMultiplier = 3.0f; - } m_props; - private: enum class TranslationType { // clang-format off - Nil = 0, + Nil = 0, Forward = 1 << 0, Backward = 1 << 1, Left = 1 << 2, @@ -354,6 +339,11 @@ namespace AzFramework return lhs; } + friend TranslationType operator~(const TranslationType lhs) + { + return static_cast(~static_cast>(lhs)); + } + static TranslationType translationFromKey(InputChannelId channelId); TranslationType m_translation = TranslationType::Nil; @@ -366,23 +356,19 @@ namespace AzFramework public: void HandleEvents(const InputEvent& event) override; Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override; - - struct Props - { - float m_dollySpeed = 0.2f; - } m_props; }; class OrbitDollyCursorMoveCameraInput : public CameraInput { public: + explicit OrbitDollyCursorMoveCameraInput(const InputChannelId dollyChannelId) + : m_dollyChannelId(dollyChannelId) {} + void HandleEvents(const InputEvent& event) override; Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override; - struct Props - { - float m_dollySpeed = 0.1f; - } m_props; + private: + InputChannelId m_dollyChannelId; }; class ScrollTranslationCameraInput : public CameraInput @@ -390,11 +376,6 @@ namespace AzFramework public: void HandleEvents(const InputEvent& event) override; Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override; - - struct Props - { - float m_translateSpeed = 0.2f; - } m_props; }; class OrbitCameraInput : public CameraInput @@ -408,13 +389,10 @@ namespace AzFramework } Cameras m_orbitCameras; - - struct Props - { - float m_defaultOrbitDistance = 15.0f; - float m_maxOrbitDistance = 100.0f; - } m_props; }; + struct WindowSize; + + //! Map from a generic InputChannel event to a camera specific InputEvent. InputEvent BuildInputEvent(const InputChannel& inputChannel, const WindowSize& windowSize); } // namespace AzFramework diff --git a/Code/Framework/AzFramework/AzFramework/azframework_files.cmake b/Code/Framework/AzFramework/AzFramework/azframework_files.cmake index b126a192ac..88f68d8bab 100644 --- a/Code/Framework/AzFramework/AzFramework/azframework_files.cmake +++ b/Code/Framework/AzFramework/AzFramework/azframework_files.cmake @@ -14,7 +14,6 @@ set(FILES AzFrameworkModule.h AzFrameworkModule.cpp API/ApplicationAPI.h - API/AtomActiveInterface.h Application/Application.cpp Application/Application.h Archive/Archive.cpp diff --git a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ViewportInteraction.h b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ViewportInteraction.h index 56ff2010cd..884562d7e8 100644 --- a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ViewportInteraction.h +++ b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ViewportInteraction.h @@ -38,8 +38,9 @@ namespace AzManipulatorTestFramework void SetGridSize(float size) override; void SetAngularStep(float step) override; int GetViewportId() const override; - AZStd::optional ViewportScreenToWorld(const QPoint& screenPosition, float depth) override; - AZStd::optional ViewportScreenToWorldRay(const QPoint& screenPosition) override; + AZStd::optional ViewportScreenToWorld(const AzFramework::ScreenPoint& screenPosition, float depth) override; + AZStd::optional ViewportScreenToWorldRay( + const AzFramework::ScreenPoint& screenPosition) override; private: // ViewportInteractionRequestBus ... bool GridSnappingEnabled(); @@ -47,7 +48,7 @@ namespace AzManipulatorTestFramework bool ShowGrid(); bool AngleSnappingEnabled(); float AngleStep(); - QPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition); + AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition); private: AZStd::unique_ptr m_nullDebugDisplayRequests; const int m_viewportId = 1234; // Arbitrary viewport id for manipulator tests diff --git a/Code/Framework/AzManipulatorTestFramework/Source/ViewportInteraction.cpp b/Code/Framework/AzManipulatorTestFramework/Source/ViewportInteraction.cpp index 11f2a32441..ebef9dea30 100644 --- a/Code/Framework/AzManipulatorTestFramework/Source/ViewportInteraction.cpp +++ b/Code/Framework/AzManipulatorTestFramework/Source/ViewportInteraction.cpp @@ -66,10 +66,9 @@ namespace AzManipulatorTestFramework return m_angularStep; } - QPoint ViewportInteraction::ViewportWorldToScreen(const AZ::Vector3& worldPosition) + AzFramework::ScreenPoint ViewportInteraction::ViewportWorldToScreen(const AZ::Vector3& worldPosition) { - auto pos = AzFramework::WorldToScreen(worldPosition, m_cameraState); - return QPoint(pos.m_x, pos.m_y); + return AzFramework::WorldToScreen(worldPosition, m_cameraState); } void ViewportInteraction::SetCameraState(const AzFramework::CameraState& cameraState) @@ -117,12 +116,14 @@ namespace AzManipulatorTestFramework return m_viewportId; } - AZStd::optional ViewportInteraction::ViewportScreenToWorld([[maybe_unused]]const QPoint& screenPosition, [[maybe_unused]]float depth) + AZStd::optional ViewportInteraction::ViewportScreenToWorld( + [[maybe_unused]] const AzFramework::ScreenPoint& screenPosition, [[maybe_unused]] float depth) { return {}; } - AZStd::optional ViewportInteraction::ViewportScreenToWorldRay([[maybe_unused]]const QPoint& screenPosition) + AZStd::optional ViewportInteraction::ViewportScreenToWorldRay( + [[maybe_unused]] const AzFramework::ScreenPoint& screenPosition) { return {}; } diff --git a/Code/Framework/AzQtComponents/Platform/Windows/AzQtComponents/Utilities/HandleDpiAwareness_Windows.cpp b/Code/Framework/AzQtComponents/Platform/Windows/AzQtComponents/Utilities/HandleDpiAwareness_Windows.cpp index 9ffe06f7e3..b834995bd9 100644 --- a/Code/Framework/AzQtComponents/Platform/Windows/AzQtComponents/Utilities/HandleDpiAwareness_Windows.cpp +++ b/Code/Framework/AzQtComponents/Platform/Windows/AzQtComponents/Utilities/HandleDpiAwareness_Windows.cpp @@ -16,7 +16,6 @@ #include #include -#include #include namespace AzQtComponents diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/API/EditorPythonConsoleBus.h b/Code/Framework/AzToolsFramework/AzToolsFramework/API/EditorPythonConsoleBus.h index 4f5a349518..de4ff396b2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/API/EditorPythonConsoleBus.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/API/EditorPythonConsoleBus.h @@ -13,6 +13,12 @@ #include #include +#include + +namespace AZ +{ + struct BehaviorParameter; +} namespace AzToolsFramework { @@ -40,6 +46,8 @@ namespace AzToolsFramework }; using GlobalFunctionCollection = AZStd::vector; virtual void GetGlobalFunctionList(GlobalFunctionCollection& globalFunctionCollection) const = 0; + + virtual AZStd::string FetchPythonTypeName(const AZ::BehaviorParameter& param) = 0; }; //! Interface to signal the phases for the Python virtual machine diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Thumbnails/FolderThumbnail.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Thumbnails/FolderThumbnail.cpp index 78681f3b4b..71bac86c0a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Thumbnails/FolderThumbnail.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Thumbnails/FolderThumbnail.cpp @@ -10,8 +10,8 @@ * */ +#include #include -#include #include #include #include @@ -50,8 +50,8 @@ namespace AzToolsFramework ////////////////////////////////////////////////////////////////////////// // FolderThumbnail ////////////////////////////////////////////////////////////////////////// - static constexpr const char* FolderIconPath = "Icons/AssetBrowser/Folder_16.svg"; - static constexpr const char* GemIconPath = "Icons/AssetBrowser/GemFolder_16.svg"; + static constexpr const char* FolderIconPath = "Assets/Editor/Icons/AssetBrowser/Folder_16.svg"; + static constexpr const char* GemIconPath = "Assets/Editor/Icons/AssetBrowser/GemFolder_16.svg"; FolderThumbnail::FolderThumbnail(SharedThumbnailKey key) : Thumbnail(key) @@ -62,13 +62,8 @@ namespace AzToolsFramework auto folderKey = azrtti_cast(m_key.data()); AZ_Assert(folderKey, "Incorrect key type, excpected FolderThumbnailKey"); - const char* engineRoot = nullptr; - AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot); - AZ_Assert(engineRoot, "Engine Root not initialized"); const char* folderIcon = folderKey->IsGem() ? GemIconPath : FolderIconPath; - AZStd::string absoluteIconPath; - AZ::StringFunc::Path::Join(engineRoot, folderIcon, absoluteIconPath); - + auto absoluteIconPath = AZ::IO::FixedMaxPath(AZ::Utils::GetEnginePath()) / folderIcon; m_pixmap.load(absoluteIconPath.c_str()); m_state = m_pixmap.isNull() ? State::Failed : State::Ready; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp index 61e144d338..95319d2e6b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -250,7 +250,7 @@ namespace AzToolsFramework AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance(); AZ_Assert(fileIO != nullptr, "AZ::IO::FileIOBase must be ready for use.\n"); - AZStd::string bundleFilePath = assetBundleSettings.m_bundleFilePath; + AZ::IO::Path bundleFilePath = AZ::IO::Path(AZStd::string_view{ AZ::Utils::GetEnginePath() }) / assetBundleSettings.m_bundleFilePath; AzFramework::PlatformId platformId = static_cast(AzFramework::PlatformHelper::GetPlatformIndexFromName(assetBundleSettings.m_platform.c_str())); @@ -259,22 +259,13 @@ namespace AzToolsFramework return false; } - const char* appRoot = nullptr; - AzFramework::ApplicationRequests::Bus::BroadcastResult(appRoot, &AzFramework::ApplicationRequests::GetAppRoot); - - if (AzFramework::StringFunc::Path::IsRelative(bundleFilePath.c_str())) - { - AzFramework::StringFunc::Path::ConstructFull(appRoot, bundleFilePath.c_str(), bundleFilePath, true); - } - AZ::u64 maxSizeInBytes = static_cast(assetBundleSettings.m_maxBundleSizeInMB * NumOfBytesInMB); AZ::u64 assetCatalogFileSizeBuffer = static_cast(AssetCatalogFileSizeBufferPercentage * assetBundleSettings.m_maxBundleSizeInMB * NumOfBytesInMB) / 100; AZ::u64 bundleSize = 0; AZ::u64 totalFileSize = 0; int bundleIndex = 0; - AZStd::string bundleFullPath = bundleFilePath; - AZStd::string tempBundleFilePath = bundleFullPath + "_temp"; + AZStd::string tempBundleFilePath = bundleFilePath.Native() + "_temp"; AZStd::vector dependentBundleNames; AZStd::vector levelDirs; @@ -301,7 +292,7 @@ namespace AzToolsFramework if (fileIO->Exists(bundleFilePath.c_str())) { // This will delete both the parent bundle as well as all the dependent bundles mentioned in the manifest file of the parent bundle. - if (!DeleteBundleFiles(bundleFilePath)) + if (!DeleteBundleFiles(bundleFilePath.Native())) { return false; } @@ -390,7 +381,7 @@ namespace AzToolsFramework // we need to find a bundle which does not exist on disk; bundleIndex++; numOfTries--; - dependentBundleFileName = CreateAssetBundleFileName(bundleFilePath, bundleIndex); + dependentBundleFileName = CreateAssetBundleFileName(bundleFilePath.Native(), bundleIndex); AzFramework::StringFunc::Path::ReplaceFullName(tempBundleFilePath, (dependentBundleFileName + tempBundleFileSuffix).c_str()); } while (numOfTries && fileIO->Exists(tempBundleFilePath.c_str())); @@ -463,15 +454,7 @@ namespace AzToolsFramework AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance(); - AZStd::string assetFileInfoListPath = assetBundleSettings.m_assetFileInfoListPath; - - const char* appRoot = nullptr; - AzFramework::ApplicationRequests::Bus::BroadcastResult(appRoot, &AzFramework::ApplicationRequests::GetAppRoot); - - if (AzFramework::StringFunc::Path::IsRelative(assetFileInfoListPath.c_str())) - { - AzFramework::StringFunc::Path::ConstructFull(appRoot, assetFileInfoListPath.c_str(), assetFileInfoListPath, true); - } + AZ::IO::Path assetFileInfoListPath = AZ::IO::Path{ AZStd::string_view{AZ::Utils::GetEnginePath()} } / assetBundleSettings.m_assetFileInfoListPath; if (!fileIO->Exists(assetFileInfoListPath.c_str())) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp index e7037c8936..373787e7dd 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFrameworkModule.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include namespace AzToolsFramework @@ -93,7 +92,6 @@ namespace AzToolsFramework AzToolsFramework::SliceDependencyBrowserComponent::CreateDescriptor(), AzToolsFramework::Thumbnailer::ThumbnailerComponent::CreateDescriptor(), AzToolsFramework::AssetBrowser::AssetBrowserComponent::CreateDescriptor(), - AzToolsFramework::MaterialBrowser::MaterialBrowserComponent::CreateDescriptor(), AzToolsFramework::EditorInteractionSystemComponent::CreateDescriptor(), AzToolsFramework::Components::EditorComponentAPIComponent::CreateDescriptor(), AzToolsFramework::Components::EditorLevelComponentAPIComponent::CreateDescriptor(), diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.cpp index 9caca69b34..ef6d0fe1f8 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.cpp @@ -117,8 +117,6 @@ namespace AzToolsFramework { EditorEntityModel::EditorEntityModel() { - AzFramework::ApplicationRequests::Bus::BroadcastResult(m_isPrefabEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); - EntityCompositionNotificationBus::Handler::BusConnect(); EditorOnlyEntityComponentNotificationBus::Handler::BusConnect(); EditorEntityRuntimeActivationChangeNotificationBus::Handler::BusConnect(); @@ -565,7 +563,7 @@ namespace AzToolsFramework { //retrieve or add an entity entry to the table //the entry must exist, even if not connected, so children and other data can be assigned - [[maybe_unused]] auto [it, inserted] = m_entityInfoTable.try_emplace(entityId, m_isPrefabEnabled); + [[maybe_unused]] auto [it, inserted] = m_entityInfoTable.try_emplace(entityId); auto& entityInfo = it->second; //the entity id defaults to invalid and must be set to match the requested id @@ -882,11 +880,6 @@ namespace AzToolsFramework } } - EditorEntityModel::EditorEntityModelEntry::EditorEntityModelEntry(bool isPrefabEnabled) - : m_isPrefabEnabled(isPrefabEnabled) - { - } - EditorEntityModel::EditorEntityModelEntry::~EditorEntityModelEntry() { Disconnect(); @@ -1213,29 +1206,15 @@ namespace AzToolsFramework auto childItr = m_childIndexCache.find(childId); if (childItr != m_childIndexCache.end()) { - if (m_isPrefabEnabled) - { - // Take the last entry and move it into the removed spot instead of deleting the entry and having to move all - // following entries one step down. - AZ::EntityId backEntity = m_children.back(); - m_children[childItr->second] = backEntity; - // Update cached index for the moved id to the new index. - m_childIndexCache[backEntity] = childItr->second; - // Now remove the deleted id from the children and cache. - m_childIndexCache.erase(childId); - m_children.erase(m_children.end() - 1); - } - else - { - m_children.erase(m_children.begin() + childItr->second); - - // rebuild index cache for faster lookup - m_childIndexCache.clear(); - for (auto childIdToCache : m_children) - { - m_childIndexCache[childIdToCache] = static_cast(m_childIndexCache.size()); - } - } + // Take the last entry and move it into the removed spot instead of deleting the entry and having to move all + // following entries one step down. + AZ::EntityId backEntity = m_children.back(); + m_children[childItr->second] = backEntity; + // Update cached index for the moved id to the new index. + m_childIndexCache[backEntity] = childItr->second; + // Now remove the deleted id from the children and cache. + m_childIndexCache.erase(childId); + m_children.erase(m_children.end() - 1); } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.h index b6cceb85fe..72965b4017 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityModel.h @@ -171,7 +171,6 @@ namespace AzToolsFramework , public PropertyEditorEntityChangeNotificationBus::Handler { public: - explicit EditorEntityModelEntry(bool isPrefabEnabled); ~EditorEntityModelEntry(); // Separately connect to EditorEntityInfoRequestBus and refresh Entity @@ -336,7 +335,6 @@ namespace AzToolsFramework bool m_visible = true; bool m_locked = false; bool m_connected = false; - bool m_isPrefabEnabled = false; AZStd::string m_name; AZStd::string m_sliceAssetName; AZStd::unordered_map m_childIndexCache; @@ -375,6 +373,5 @@ namespace AzToolsFramework AZ::EntityId m_postInstantiateBeforeEntity; AZ::EntityId m_postInstantiateSliceParent; bool m_gotInstantiateSliceDetails = false; - bool m_isPrefabEnabled = false; }; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/EditorVertexSelection.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/EditorVertexSelection.cpp index 089037bbf3..4d10a4c171 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/EditorVertexSelection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/EditorVertexSelection.cpp @@ -127,8 +127,7 @@ namespace AzToolsFramework ViewportInteraction::MainEditorViewportInteractionRequestBus::EventResult( worldSurfacePosition, viewportId, &ViewportInteraction::MainEditorViewportInteractionRequestBus::Events::PickTerrain, - ViewportInteraction::QPointFromScreenPoint( - mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates)); + mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates); AZ::Transform worldFromLocal; AZ::TransformBus::EventResult(worldFromLocal, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); @@ -402,10 +401,10 @@ namespace AzToolsFramework vertexIndex, localVertex); const AZ::Vector3 worldVertex = worldFromLocal.TransformPoint(AZ::AdaptVertexOut(localVertex)); - const QPoint screenPosition = GetScreenPosition(viewportId, worldVertex); + const AzFramework::ScreenPoint screenPosition = GetScreenPosition(viewportId, worldVertex); // check if a vertex is inside the box select region - if (editorBoxSelect.BoxRegion()->contains(screenPosition)) + if (editorBoxSelect.BoxRegion()->contains(ViewportInteraction::QPointFromScreenPoint(screenPosition))) { // see if vertexIndex is in active selection auto vertexIt = AZStd::find( diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/SurfaceManipulator.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/SurfaceManipulator.cpp index e4d0cd59dd..f570c20a7e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/SurfaceManipulator.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/SurfaceManipulator.cpp @@ -103,8 +103,7 @@ namespace AzToolsFramework ViewportInteraction::MainEditorViewportInteractionRequestBus::EventResult( worldSurfacePosition, interaction.m_interactionId.m_viewportId, &ViewportInteraction::MainEditorViewportInteractionRequestBus::Events::PickTerrain, - ViewportInteraction::QPointFromScreenPoint( - interaction.m_mousePick.m_screenCoordinates)); + interaction.m_mousePick.m_screenCoordinates); m_startInternal = CalculateManipulationDataStart( worldFromLocalUniformScale, worldSurfacePosition, GetLocalPosition(), @@ -129,8 +128,7 @@ namespace AzToolsFramework ViewportInteraction::MainEditorViewportInteractionRequestBus::EventResult( worldSurfacePosition, interaction.m_interactionId.m_viewportId, &ViewportInteraction::MainEditorViewportInteractionRequestBus::Events::PickTerrain, - ViewportInteraction::QPointFromScreenPoint( - interaction.m_mousePick.m_screenCoordinates)); + interaction.m_mousePick.m_screenCoordinates); const GridSnapParameters gridSnapParams = GridSnapSettings(interaction.m_interactionId.m_viewportId); @@ -150,8 +148,7 @@ namespace AzToolsFramework ViewportInteraction::MainEditorViewportInteractionRequestBus::EventResult( worldSurfacePosition, interaction.m_interactionId.m_viewportId, &ViewportInteraction::MainEditorViewportInteractionRequestBus::Events::PickTerrain, - ViewportInteraction::QPointFromScreenPoint( - interaction.m_mousePick.m_screenCoordinates)); + interaction.m_mousePick.m_screenCoordinates); const GridSnapParameters gridSnapParams = GridSnapSettings(interaction.m_interactionId.m_viewportId); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserBus.h b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserBus.h deleted file mode 100644 index b0d625b6e4..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserBus.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include - -namespace AZ -{ - namespace Data - { - struct AssetId; - } -} - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - class MaterialBrowserRequests - : public AZ::EBusTraits - { - public: - - // Only a single handler is allowed - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - - virtual bool HasRecord(const AZ::Data::AssetId& assetId) = 0; - virtual bool IsMultiMaterial(const AZ::Data::AssetId& assetId) = 0; - }; - - using MaterialBrowserRequestBus = AZ::EBus; - } // namespace MaterialBrowser -} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.cpp deleted file mode 100644 index f64d4af23d..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include - -#include -#include -#include -#include -#include -#include - -#include -AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: 'QBrush::d': class 'QScopedPointer' needs to have dll-interface to be used by clients of class 'QBrush' -#include -AZ_POP_DISABLE_WARNING - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - MaterialBrowserComponent::MaterialBrowserComponent() - { - } - - void MaterialBrowserComponent::Activate() - { - using namespace Thumbnailer; - using namespace AssetBrowser; - const char* contextName = "MaterialBrowser"; - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterContext, contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(FolderThumbnailCache), contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SourceThumbnailCache), contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(MaterialThumbnailCache), contextName); - ThumbnailerRequestsBus::Broadcast(&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SourceControlThumbnailCache), contextName); - } - - void MaterialBrowserComponent::Deactivate() - { - } - - void MaterialBrowserComponent::Reflect(AZ::ReflectContext* context) - { - AZ::SerializeContext* serialize = azrtti_cast(context); - if (serialize) - { - serialize->Class(); - } - } - - void MaterialBrowserComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) - { - required.push_back(AZ_CRC("ThumbnailerService", 0x65422b97)); - } - } // namespace MaterialBrowser -} // namespace AzToolsFramework - diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.h deleted file mode 100644 index 93a48cf22c..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialBrowserComponent.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include -#include - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - //! MaterialBrowserComponent allows initialization of MaterialBrowser systems, such as thumbnails - class MaterialBrowserComponent - : public AZ::Component - { - public: - AZ_COMPONENT(MaterialBrowserComponent, "{121F3F3B-2412-490D-9E3E-C205C677F476}") - - MaterialBrowserComponent(); - virtual ~MaterialBrowserComponent() = default; - - ////////////////////////////////////////////////////////////////////////// - // AZ::Component - ////////////////////////////////////////////////////////////////////////// - void Activate() override; - void Deactivate() override; - static void Reflect(AZ::ReflectContext* context); - - static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); - }; - } // namespace MaterialBrowser -} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.cpp deleted file mode 100644 index e04df8937c..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include - -#include - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - static constexpr const char* SimpleMaterialIconPath = ":/MaterialBrowser/images/material_04.png"; - static constexpr const char* MultiMaterialIconPath = ":/MaterialBrowser/images/material_06.png"; - - ////////////////////////////////////////////////////////////////////////// - // MaterialThumbnail - ////////////////////////////////////////////////////////////////////////// - MaterialThumbnail::MaterialThumbnail(Thumbnailer::SharedThumbnailKey key) - : Thumbnail(key) - { - auto productKey = azrtti_cast(m_key.data()); - AZ_Assert(productKey, "Incorrect key type, excpected ProductThumbnailKey"); - - bool multiMat = false; - MaterialBrowserRequestBus::BroadcastResult(multiMat, &MaterialBrowserRequests::IsMultiMaterial, productKey->GetAssetId()); - - QString iconPath = multiMat ? MultiMaterialIconPath : SimpleMaterialIconPath; - m_pixmap.load(iconPath); - m_state = m_pixmap.isNull() ? State::Failed : State::Ready; - } - - ////////////////////////////////////////////////////////////////////////// - // MaterialThumbnailCache - ////////////////////////////////////////////////////////////////////////// - MaterialThumbnailCache::MaterialThumbnailCache() - : ThumbnailCache() {} - - MaterialThumbnailCache::~MaterialThumbnailCache() = default; - - int MaterialThumbnailCache::GetPriority() const - { - return 1; - } - - const char* MaterialThumbnailCache::GetProviderName() const - { - return ProviderName; - } - - bool MaterialThumbnailCache::IsSupportedThumbnail(Thumbnailer::SharedThumbnailKey key) const - { - return azrtti_istypeof(key.data()); - } - - } // namespace MaterialBrowser -} // namespace AzToolsFramework - -#include "MaterialBrowser/moc_MaterialThumbnail.cpp" diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.h b/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.h deleted file mode 100644 index 60a2bb11e5..0000000000 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/MaterialBrowser/MaterialThumbnail.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include -#include -#endif - -namespace AzToolsFramework -{ - namespace MaterialBrowser - { - //! Material Browser uses only 2 thumbnails: simple and multimaterial - class MaterialThumbnail - : public Thumbnailer::Thumbnail - { - Q_OBJECT - public: - MaterialThumbnail(Thumbnailer::SharedThumbnailKey key); - }; - - namespace - { - class MaterialKeyHash - { - public: - size_t operator()(const Thumbnailer::SharedThumbnailKey& /*val*/) const - { - return 0; // there is only 2 thumbnails in this cache - } - }; - - class MaterialKeyEqual - { - public: - bool operator()(const Thumbnailer::SharedThumbnailKey& val1, const Thumbnailer::SharedThumbnailKey& val2) const - { - auto productThumbnailKey1 = azrtti_cast(val1.data()); - auto productThumbnailKey2 = azrtti_cast(val2.data()); - if (!productThumbnailKey1 || !productThumbnailKey2) - { - return false; - } - - // check whether keys point to single or multimaterial asset type - bool multiMat1 = false; - bool multiMat2 = false; - MaterialBrowserRequestBus::BroadcastResult(multiMat1, &MaterialBrowserRequests::IsMultiMaterial, productThumbnailKey1->GetAssetId()); - MaterialBrowserRequestBus::BroadcastResult(multiMat2, &MaterialBrowserRequests::IsMultiMaterial, productThumbnailKey2->GetAssetId()); - return multiMat1 == multiMat2; - } - }; - } - - //! MaterialBrowserEntry thumbnails - class MaterialThumbnailCache - : public Thumbnailer::ThumbnailCache - { - public: - MaterialThumbnailCache(); - ~MaterialThumbnailCache() override; - - int GetPriority() const override; - const char* GetProviderName() const override; - - static constexpr const char* ProviderName = "CryMaterial Thumbnails"; - - protected: - bool IsSupportedThumbnail(Thumbnailer::SharedThumbnailKey key) const override; - }; - } // namespace MaterialBrowser -} // namespace AzToolsFramework - - diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 1e9cc35230..475510c52f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -96,9 +96,7 @@ namespace AzToolsFramework // target templates of the other instances. for (auto& nestedInstance : instances) { - PrefabUndoHelpers::RemoveLink( - nestedInstance->GetTemplateId(), commonRootEntityOwningInstance->get().GetTemplateId(), - nestedInstance->GetInstanceAlias(), nestedInstance->GetLinkId(), undoBatch.GetUndoBatch()); + RemoveLink(nestedInstance, commonRootEntityOwningInstance->get().GetTemplateId(), undoBatch.GetUndoBatch()); } PrefabUndoHelpers::UpdatePrefabInstance( @@ -238,14 +236,9 @@ namespace AzToolsFramework // Retrieve the owning instance of the common root entity, which will be our new instance's parent instance. commonRootEntityOwningInstance = GetOwnerInstanceByEntityId(commonRootEntityId); - if (!commonRootEntityOwningInstance) - { - AZ_Assert( - false, - "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided"); - return AZ::Failure(AZStd::string( - "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided")); - } + AZ_Assert( + commonRootEntityOwningInstance.has_value(), + "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided"); return AZ::Success(); } @@ -287,6 +280,34 @@ namespace AzToolsFramework m_prefabUndoCache.Store(containerEntityId, AZStd::move(containerEntityDomAfter)); } + void PrefabPublicHandler::RemoveLink( + AZStd::unique_ptr& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch) + { + LinkReference nestedInstanceLink = m_prefabSystemComponentInterface->FindLink(sourceInstance->GetLinkId()); + AZ_Assert( + nestedInstanceLink.has_value(), + "A valid link was not found for one of the instances provided as input for the CreatePrefab operation."); + + PrefabDomReference nestedInstanceLinkDom = nestedInstanceLink->get().GetLinkDom(); + AZ_Assert( + nestedInstanceLinkDom.has_value(), + "A valid DOM was not found for the link corresponding to one of the instances provided as input for the " + "CreatePrefab operation."); + + PrefabDomValueReference nestedInstanceLinkPatches = + PrefabDomUtils::FindPrefabDomValue(nestedInstanceLinkDom->get(), PrefabDomUtils::PatchesName); + AZ_Assert( + nestedInstanceLinkPatches.has_value(), + "A valid DOM for patches was not found for the link corresponding to one of the instances provided as input for the " + "CreatePrefab operation."); + + PrefabDom patchesCopyForUndoSupport; + patchesCopyForUndoSupport.CopyFrom(nestedInstanceLinkPatches->get(), patchesCopyForUndoSupport.GetAllocator()); + PrefabUndoHelpers::RemoveLink( + sourceInstance->GetTemplateId(), targetTemplateId, sourceInstance->GetInstanceAlias(), sourceInstance->GetLinkId(), + patchesCopyForUndoSupport, undoBatch); + } + PrefabOperationResult PrefabPublicHandler::SavePrefab(AZ::IO::Path filePath) { auto templateId = m_prefabSystemComponentInterface->GetTemplateIdFromFilePath(filePath.c_str()); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h index e83513dbff..5ade666a40 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h @@ -82,6 +82,16 @@ namespace AzToolsFramework const EntityList& topLevelEntities, Instance& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId); + /** + * Removes the link between template of the sourceInstance and the template corresponding to targetTemplateId. + * + * \param sourceInstance The instance corresponding to the source template of the link to be removed. + * \param targetTemplateId The id of the target template of the link to be removed. + * \param undoBatch The undo batch to set as parent for this remove link action. + */ + void RemoveLink( + AZStd::unique_ptr& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch); + /** * Given a list of entityIds, finds the prefab instance that owns the common root entity of the entityIds. * diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index 3f660bb73b..4413586e77 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -663,8 +663,9 @@ namespace AzToolsFramework newLink.SetSourceTemplateId(linkSourceId); newLink.SetInstanceName(instanceAlias.c_str()); newLink.GetLinkDom().SetObject(); - newLink.GetLinkDom().AddMember(rapidjson::StringRef(PrefabDomUtils::SourceName), - rapidjson::StringRef(sourceTemplate.GetFilePath().c_str()), newLink.GetLinkDom().GetAllocator()); + newLink.GetLinkDom().AddMember( + rapidjson::StringRef(PrefabDomUtils::SourceName), rapidjson::StringRef(sourceTemplate.GetFilePath().c_str()), + newLink.GetLinkDom().GetAllocator()); if (linkPatch && linkPatch->get().IsArray() && !(linkPatch->get().Empty())) { @@ -770,8 +771,8 @@ namespace AzToolsFramework return false; } - Template& sourceTemplate = sourceTemplateReference->get(); #if defined(AZ_ENABLE_TRACING) + Template& sourceTemplate = sourceTemplateReference->get(); Template& targetTemplate = targetTemplateReference->get(); #endif diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp index ea3fa5d84d..ad0cdc166a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp @@ -113,7 +113,7 @@ namespace AzToolsFramework , m_sourceId(InvalidTemplateId) , m_instanceAlias("") , m_linkId(InvalidLinkId) - , m_linkDom(PrefabDom()) + , m_linkPatches(PrefabDom()) , m_linkStatus(LinkStatus::LINKSTATUS) { m_prefabSystemComponentInterface = AZ::Interface::Get(); @@ -124,7 +124,7 @@ namespace AzToolsFramework const TemplateId& targetId, const TemplateId& sourceId, const InstanceAlias& instanceAlias, - PrefabDomReference linkDom, + PrefabDomReference linkPatches, const LinkId linkId) { m_targetId = targetId; @@ -132,9 +132,9 @@ namespace AzToolsFramework m_instanceAlias = instanceAlias; m_linkId = linkId; - if (linkDom.has_value()) + if (linkPatches.has_value()) { - m_linkDom = AZStd::move(linkDom->get()); + m_linkPatches = AZStd::move(linkPatches->get()); } //if linkId is invalid, set as ADD @@ -193,7 +193,7 @@ namespace AzToolsFramework void PrefabUndoInstanceLink::AddLink() { - m_linkId = m_prefabSystemComponentInterface->CreateLink(m_targetId, m_sourceId, m_instanceAlias, m_linkDom, m_linkId); + m_linkId = m_prefabSystemComponentInterface->CreateLink(m_targetId, m_sourceId, m_instanceAlias, m_linkPatches, m_linkId); } void PrefabUndoInstanceLink::RemoveLink() diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h index 0d15d707d2..49bae4eda0 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h @@ -101,7 +101,7 @@ namespace AzToolsFramework const TemplateId& targetId, const TemplateId& sourceId, const InstanceAlias& instanceAlias, - PrefabDomReference linkDom = PrefabDomReference(), + PrefabDomReference linkPatches = PrefabDomReference(), const LinkId linkId = InvalidLinkId); void Undo() override; @@ -120,7 +120,7 @@ namespace AzToolsFramework InstanceAlias m_instanceAlias; LinkId m_linkId; - PrefabDom m_linkDom; //data for delete/update + PrefabDom m_linkPatches; //data for delete/update LinkStatus m_linkStatus; PrefabSystemComponentInterface* m_prefabSystemComponentInterface = nullptr; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp index 2062e8b12c..24eb71e055 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp @@ -46,13 +46,11 @@ namespace AzToolsFramework } void RemoveLink( - TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias, - LinkId linkId, UndoSystem::URSequencePoint* undoBatch) + TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias, LinkId linkId, + PrefabDomReference linkPatches, UndoSystem::URSequencePoint* undoBatch) { auto linkRemoveUndo = aznew PrefabUndoInstanceLink("Remove Link"); - PrefabDom emptyLinkDom; - linkRemoveUndo->Capture( - targetTemplateId, sourceTemplateId, instanceAlias, emptyLinkDom, linkId); + linkRemoveUndo->Capture(targetTemplateId, sourceTemplateId, instanceAlias, linkPatches, linkId); linkRemoveUndo->SetParent(undoBatch); linkRemoveUndo->Redo(); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h index 74532b87a2..6429df3b04 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.h @@ -25,8 +25,8 @@ namespace AzToolsFramework TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch, const InstanceAlias& instanceAlias, UndoSystem::URSequencePoint* undoBatch); void RemoveLink( - TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias, - LinkId linkId, UndoSystem::URSequencePoint* undoBatch); + TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias, LinkId linkId, + PrefabDomReference linkPatches, UndoSystem::URSequencePoint* undoBatch); } } // namespace Prefab } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/LoadingThumbnail.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/LoadingThumbnail.cpp index fb9d156b20..c29a9e4c6b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/LoadingThumbnail.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/LoadingThumbnail.cpp @@ -10,7 +10,7 @@ * */ -#include +#include #include #include @@ -23,18 +23,14 @@ namespace AzToolsFramework ////////////////////////////////////////////////////////////////////////// // LoadingThumbnail ////////////////////////////////////////////////////////////////////////// - static const char* LoadingIconPath = "Icons/AssetBrowser/in_progress.gif"; + static constexpr const char* LoadingIconPath = "Assets/Editor/Icons/AssetBrowser/in_progress.gif"; LoadingThumbnail::LoadingThumbnail() : Thumbnail(MAKE_TKEY(ThumbnailKey)) , m_angle(0) { - const char* engineRoot = nullptr; - AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot); - AZ_Assert(engineRoot, "Engine Root not initialized"); - AZStd::string iconPath; - AZ::StringFunc::Path::Join(engineRoot, LoadingIconPath, iconPath); - m_loadingMovie.setFileName(iconPath.c_str()); + auto absoluteIconPath = AZ::IO::FixedMaxPath(AZ::Utils::GetEnginePath()) / LoadingIconPath; + m_loadingMovie.setFileName(absoluteIconPath.c_str()); m_loadingMovie.setCacheMode(QMovie::CacheMode::CacheAll); m_loadingMovie.setScaledSize(QSize(LoadingThumbnailSize, LoadingThumbnailSize)); m_loadingMovie.start(); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/MissingThumbnail.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/MissingThumbnail.cpp index 270a5b113f..39af7d9293 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/MissingThumbnail.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Thumbnails/MissingThumbnail.cpp @@ -10,18 +10,21 @@ * */ +#include +#include #include namespace AzToolsFramework { namespace Thumbnailer { - static const char* MISSING_ICON_PATH = "Icons/AssetBrowser/Default_16.svg"; + static constexpr const char* MissingIconPath = "Assets/Editor/Icons/AssetBrowser/Default_16.svg"; MissingThumbnail::MissingThumbnail() : Thumbnail(MAKE_TKEY(ThumbnailKey)) { - m_pixmap.load(MISSING_ICON_PATH); + auto absoluteIconPath = AZ::IO::FixedMaxPath(AZ::Utils::GetEnginePath()) / MissingIconPath; + m_pixmap.load(absoluteIconPath.c_str()); m_state = m_pixmap.isNull() ? State::Failed : State::Ready; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportMessages.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportMessages.h index a9949d382e..6ceb175fe4 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportMessages.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportMessages.h @@ -21,8 +21,6 @@ #include #include -class QPoint; // LYN-2315 in-progress, remove this - namespace AzFramework { struct ScreenPoint; @@ -167,14 +165,14 @@ namespace AzToolsFramework /// Return the angle snapping/step size. virtual float AngleStep() = 0; /// Transform a point in world space to screen space coordinates. - virtual QPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) = 0; + virtual AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) = 0; /// Transform a point in screen space coordinates to a vector in world space based on clip space depth. /// Depth specifies a relative camera depth to project in the range of [0.f, 1.f]. /// Returns the world space position if successful. - virtual AZStd::optional ViewportScreenToWorld(const QPoint& screenPosition, float depth) = 0; + virtual AZStd::optional ViewportScreenToWorld(const AzFramework::ScreenPoint& screenPosition, float depth) = 0; /// Casts a point in screen space to a ray in world space originating from the viewport camera frustum's near plane. /// Returns a ray containing the ray's origin and a direction normal, if successful. - virtual AZStd::optional ViewportScreenToWorldRay(const QPoint& screenPosition) = 0; + virtual AZStd::optional ViewportScreenToWorldRay(const AzFramework::ScreenPoint& screenPosition) = 0; protected: ~ViewportInteractionRequests() = default; @@ -207,9 +205,9 @@ namespace AzToolsFramework public: /// Given a point in screen space, return the picked entity (if any). /// Picked EntityId will be returned, InvalidEntityId will be returned on failure. - virtual AZ::EntityId PickEntity(const QPoint& point) = 0; + virtual AZ::EntityId PickEntity(const AzFramework::ScreenPoint& point) = 0; /// Given a point in screen space, return the terrain position in world space. - virtual AZ::Vector3 PickTerrain(const QPoint& point) = 0; + virtual AZ::Vector3 PickTerrain(const AzFramework::ScreenPoint& point) = 0; /// Return the terrain height given a world position in 2d (xy plane). virtual float TerrainHeight(const AZ::Vector2& position) = 0; /// Given the current view frustum (viewport) return all visible entities. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.cpp index 12a0d6a8ab..8d26054562 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.cpp @@ -19,8 +19,6 @@ namespace AzToolsFramework { namespace ViewportInteraction { - const AZ::s32 g_mainViewportEntityDebugDisplayId = AZ_CRC("MainViewportEntityDebugDisplayId", 0x58ae7fe8); - void ViewportInteractionReflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.h index 161ca2d79f..d59044e68f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Viewport/ViewportTypes.h @@ -256,9 +256,5 @@ namespace AzToolsFramework /// Reflect all viewport related types. void ViewportInteractionReflect(AZ::ReflectContext* context); - - /// The Id the main DebugDisplayRequestBus will be connected on. - extern const AZ::s32 g_mainViewportEntityDebugDisplayId; - } // namespace ViewportInteraction } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp index f3abc70fba..68a5b43d73 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp @@ -141,16 +141,16 @@ namespace AzToolsFramework const AZ::Vector3& entityPosition = m_entityDataCache->GetVisibleEntityPosition(entityCacheIndex); // selecting based on 2d icon - should only do it when visible and not selected - const QPoint screenPosition = GetScreenPosition(viewportId, entityPosition); + const AzFramework::ScreenPoint screenPosition = GetScreenPosition(viewportId, entityPosition); const float distSqFromCamera = cameraState.m_position.GetDistanceSq(entityPosition); const auto iconRange = static_cast(GetIconScale(distSqFromCamera) * s_iconSize * 0.5f); const auto screenCoords = mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates; - if ( screenCoords.m_x >= screenPosition.x() - iconRange - && screenCoords.m_x <= screenPosition.x() + iconRange - && screenCoords.m_y >= screenPosition.y() - iconRange - && screenCoords.m_y <= screenPosition.y() + iconRange) + if ( screenCoords.m_x >= screenPosition.m_x - iconRange + && screenCoords.m_x <= screenPosition.m_x + iconRange + && screenCoords.m_y >= screenPosition.m_y - iconRange + && screenCoords.m_y <= screenPosition.m_y + iconRange) { entityIdUnderCursor = entityId; break; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.cpp index 95095bd3c8..3be4bc9db2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.cpp @@ -53,11 +53,11 @@ namespace AzToolsFramework return AZ::GetMax(projectedCameraDistance, cameraState.m_nearClip) / apparentDistance; } - QPoint GetScreenPosition(const int viewportId, const AZ::Vector3& worldTranslation) + AzFramework::ScreenPoint GetScreenPosition(const int viewportId, const AZ::Vector3& worldTranslation) { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzToolsFramework); - QPoint screenPosition = QPoint(); + auto screenPosition = AzFramework::ScreenPoint(0, 0); ViewportInteraction::ViewportInteractionRequestBus::EventResult( screenPosition, viewportId, &ViewportInteraction::ViewportInteractionRequestBus::Events::ViewportWorldToScreen, diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.h index 65e0a99bfe..9936fb9afd 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorSelectionUtil.h @@ -45,7 +45,7 @@ namespace AzToolsFramework const AZ::Vector3& worldPosition, const AzFramework::CameraState& cameraState); /// Map from world space to screen space. - QPoint GetScreenPosition(int viewportId, const AZ::Vector3& worldTranslation); + AzFramework::ScreenPoint GetScreenPosition(int viewportId, const AZ::Vector3& worldTranslation); /// Given a mouse interaction, determine if the pick ray from its position /// in screen space intersected an aabb in world space. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp index ec22a2f7c8..9388f3f5f0 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp @@ -316,14 +316,14 @@ namespace AzToolsFramework template static void BoxSelectAddRemoveToEntitySelection( - const AZStd::optional& boxSelect, const QPoint& screenPosition, const AZ::EntityId visibleEntityId, + const AZStd::optional& boxSelect, const AzFramework::ScreenPoint& screenPosition, const AZ::EntityId visibleEntityId, const EntityIdContainer& incomingEntityIds, EntityIdContainer& outgoingEntityIds, EditorTransformComponentSelection& entityTransformComponentSelection, EntitySelectFuncType selectFunc1, EntitySelectFuncType selectFunc2, Compare outgoingCheck) { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzToolsFramework); - if (boxSelect->contains(screenPosition)) + if (boxSelect->contains(ViewportInteraction::QPointFromScreenPoint(screenPosition))) { const auto entityIt = incomingEntityIds.find(visibleEntityId); @@ -389,7 +389,7 @@ namespace AzToolsFramework const AZ::EntityId entityId = entityDataCache.GetVisibleEntityId(entityCacheIndex); const AZ::Vector3& entityPosition = entityDataCache.GetVisibleEntityPosition(entityCacheIndex); - const QPoint screenPosition = GetScreenPosition(viewportId, entityPosition); + const AzFramework::ScreenPoint screenPosition = GetScreenPosition(viewportId, entityPosition); if (currentKeyboardModifiers.Ctrl()) { @@ -927,7 +927,7 @@ namespace AzToolsFramework ViewportInteraction::MainEditorViewportInteractionRequestBus::EventResult( worldSurfacePosition, viewportId, &ViewportInteraction::MainEditorViewportInteractionRequestBus::Events::PickTerrain, - ViewportInteraction::QPointFromScreenPoint(mouseInteraction.m_mousePick.m_screenCoordinates)); + mouseInteraction.m_mousePick.m_screenCoordinates); // convert to local space - snap if enabled const GridSnapParameters gridSnapParams = GridSnapSettings(viewportId); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake index 4cf121c517..a7fcf2e711 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake @@ -70,11 +70,6 @@ set(FILES AssetCatalog/PlatformAddressedAssetCatalog.cpp AssetCatalog/PlatformAddressedAssetCatalogManager.h AssetCatalog/PlatformAddressedAssetCatalogManager.cpp - MaterialBrowser/MaterialBrowserBus.h - MaterialBrowser/MaterialBrowserComponent.cpp - MaterialBrowser/MaterialBrowserComponent.h - MaterialBrowser/MaterialThumbnail.cpp - MaterialBrowser/MaterialThumbnail.h Thumbnails/ThumbnailerComponent.cpp Thumbnails/ThumbnailerComponent.h Thumbnails/LoadingThumbnail.cpp diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp index c81db58c95..d1bd2a488e 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp @@ -78,7 +78,7 @@ namespace Benchmark } BENCHMARK_REGISTER_F(BM_PrefabUpdateInstances, UpdateInstances_SingeEntityInstances) ->RangeMultiplier(10) - ->Range(100, 1000) + ->Range(100, 10000) ->Unit(benchmark::kMillisecond) ->Complexity(); diff --git a/Code/LauncherUnified/StaticModules.in b/Code/LauncherUnified/StaticModules.in index 629973bdf4..03b22b076a 100644 --- a/Code/LauncherUnified/StaticModules.in +++ b/Code/LauncherUnified/StaticModules.in @@ -20,15 +20,6 @@ #include -#define DECLARE_CRYREGISTER_SINGLETON_CLASS(implclassname) \ - void* Get##implclassname##Factory(); - -DECLARE_CRYREGISTER_SINGLETON_CLASS(CEngineModule_Cry3DEngine) -DECLARE_CRYREGISTER_SINGLETON_CLASS(CEngineModule_CryFont) -DECLARE_CRYREGISTER_SINGLETON_CLASS(CEngineModule_CryRenderer) - -#undef DECLARE_CRYREGISTER_SINGLETON_CLASS - namespace AZ { class Module; @@ -39,14 +30,6 @@ ${extern_module_declarations} extern "C" void CreateStaticModules(AZStd::vector& modulesOut) { ${module_invocations} - // Call methods to avoid symbol striping -#define NON_STRIPPING_CALL(Module) \ - AZ_UNUSED(Get##Module##Factory()) - - NON_STRIPPING_CALL(CEngineModule_Cry3DEngine); - NON_STRIPPING_CALL(CEngineModule_CryFont); - NON_STRIPPING_CALL(CEngineModule_CryRenderer); -#undef NON_STRIPPING_CALL } #endif // AZ_MONOLITHIC_BUILD diff --git a/Code/LauncherUnified/launcher_generator.cmake b/Code/LauncherUnified/launcher_generator.cmake index 08ddd538fc..28429729e1 100644 --- a/Code/LauncherUnified/launcher_generator.cmake +++ b/Code/LauncherUnified/launcher_generator.cmake @@ -66,7 +66,6 @@ foreach(project_name project_path IN ZIP_LISTS LY_PROJECTS_TARGET_NAME LY_PROJEC set(game_build_dependencies ${game_gem_dependencies} Legacy::CrySystem - Legacy::CryFont ) if(PAL_TRAIT_BUILD_SERVER_SUPPORTED) @@ -95,7 +94,6 @@ foreach(project_name project_path IN ZIP_LISTS LY_PROJECTS_TARGET_NAME LY_PROJEC set(server_build_dependencies ${game_gem_dependencies} Legacy::CrySystem - Legacy::CryFont ) endif() @@ -103,7 +101,6 @@ foreach(project_name project_path IN ZIP_LISTS LY_PROJECTS_TARGET_NAME LY_PROJEC set(game_runtime_dependencies Legacy::CrySystem - Legacy::CryFont ) endif() diff --git a/Code/Sandbox/Editor/2DViewport.cpp b/Code/Sandbox/Editor/2DViewport.cpp index d86ea03bdf..0487c9381f 100644 --- a/Code/Sandbox/Editor/2DViewport.cpp +++ b/Code/Sandbox/Editor/2DViewport.cpp @@ -650,114 +650,6 @@ void Q2DViewport::OnDestroy() ////////////////////////////////////////////////////////////////////////// void Q2DViewport::Render() { - if (GetIEditor()->IsInGameMode()) - { - return; - } - - if (!m_renderer) - { - return; - } - - if (!isVisible()) - { - return; - } - - if (!GetIEditor()->GetDocument()->IsDocumentReady()) - { - return; - } - - if (m_renderer->IsStereoEnabled()) - { - return; - } - - FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); - - QRect rc = rect(); - if (rc.isEmpty()) - { - return; - } - - CalculateViewTM(); - - // Render - WIN_HWND priorContext = m_renderer->GetCurrentContextHWND(); - - m_renderer->SetCurrentContext(renderOverlayHWND()); - m_renderer->BeginFrame(); - m_renderer->ChangeViewport(0, 0, rc.right(), rc.bottom(), true); - - CScopedWireFrameMode scopedWireFrame(m_renderer, R_SOLID_MODE); - auto colorf = Rgb2ColorF(m_colorBackground); - m_renderer->ClearTargetsLater(FRT_CLEAR, colorf); - - ////////////////////////////////////////////////////////////////////////// - // 2D Mode. - ////////////////////////////////////////////////////////////////////////// - if (rc.right() != 0 && rc.bottom() != 0) - { - TransformationMatrices backupSceneMatrices; - - m_renderer->Set2DMode(rc.right(), rc.bottom(), backupSceneMatrices); - - ////////////////////////////////////////////////////////////////////////// - // Draw viewport elements here. - ////////////////////////////////////////////////////////////////////////// - // Calc world bounding box for objects rendering. - m_displayBounds = GetWorldBounds(QPoint(0, 0), QPoint(rc.width(), rc.height())); - - // Draw all objects. - DisplayContext& dc = m_displayContext; - dc.settings = GetIEditor()->GetDisplaySettings(); - dc.view = this; - dc.renderer = m_renderer; - dc.engine = GetIEditor()->Get3DEngine(); - dc.flags = DISPLAY_2D; - dc.box = m_displayBounds; - dc.camera = &GetIEditor()->GetSystem()->GetViewCamera(); - - if (!dc.settings->IsDisplayLabels() || !dc.settings->IsDisplayHelpers()) - { - dc.flags |= DISPLAY_HIDENAMES; - } - if (dc.settings->IsDisplayLinks() && dc.settings->IsDisplayHelpers()) - { - dc.flags |= DISPLAY_LINKS; - } - if (m_bDegradateQuality) - { - dc.flags |= DISPLAY_DEGRADATED; - } - - SRenderingPassInfo passInfo = SRenderingPassInfo::CreateGeneralPassRenderingInfo(GetIEditor()->GetSystem()->GetViewCamera()); - - m_renderer->BeginSpawningGeneratingRendItemJobs(passInfo.ThreadID()); - m_renderer->BeginSpawningShadowGeneratingRendItemJobs(passInfo.ThreadID()); - m_renderer->EF_StartEf(passInfo); - - dc.SetState(e_Mode3D | e_AlphaBlended | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOn); - Draw(dc); - - m_renderer->EF_EndEf3D(SHDF_STREAM_SYNC, -1, -1, passInfo); - - m_renderer->EF_RenderTextMessages(); - - // Return back from 2D mode. - m_renderer->Unset2DMode(backupSceneMatrices); - - m_renderer->RenderDebug(false); - - ProcessRenderLisneters(m_displayContext); - - m_renderer->EndFrame(); - } - - GetIEditor()->GetRenderer()->SetCurrentContext(priorContext); } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.cpp b/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.cpp index 0c99e63c47..c8bd157b65 100644 --- a/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.cpp +++ b/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.cpp @@ -50,8 +50,6 @@ #include "Include/IObjectManager.h" #include "CryEditDoc.h" #include "QtViewPaneManager.h" -#include "AzAssetBrowser/Preview/LegacyPreviewerFactory.h" - namespace AzAssetBrowserRequestHandlerPrivate { @@ -230,18 +228,15 @@ namespace AzAssetBrowserRequestHandlerPrivate } AzAssetBrowserRequestHandler::AzAssetBrowserRequestHandler() - : m_previewerFactory(aznew LegacyPreviewerFactory) { using namespace AzToolsFramework::AssetBrowser; AssetBrowserInteractionNotificationBus::Handler::BusConnect(); AzQtComponents::DragAndDropEventsBus::Handler::BusConnect(AzQtComponents::DragAndDropContexts::EditorViewport); - AzToolsFramework::AssetBrowser::PreviewerRequestBus::Handler::BusConnect(); } AzAssetBrowserRequestHandler::~AzAssetBrowserRequestHandler() { - AzToolsFramework::AssetBrowser::PreviewerRequestBus::Handler::BusDisconnect(); AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); AzQtComponents::DragAndDropEventsBus::Handler::BusDisconnect(); } @@ -527,15 +522,6 @@ void AzAssetBrowserRequestHandler::Drop(QDropEvent* event, AzQtComponents::DragA } } -const AzToolsFramework::AssetBrowser::PreviewerFactory* AzAssetBrowserRequestHandler::GetPreviewerFactory(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const -{ - if (m_previewerFactory->IsEntrySupported(entry)) - { - return m_previewerFactory.get(); - } - return nullptr; -} - void AzAssetBrowserRequestHandler::AddSourceFileOpeners(const char* fullSourceFileName, const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) { using namespace AzToolsFramework; diff --git a/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.h b/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.h index 5b7e10f2a1..707b9041ae 100644 --- a/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.h +++ b/Code/Sandbox/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.h @@ -37,12 +37,9 @@ namespace AzToolsFramework } } -class LegacyPreviewerFactory; - class AzAssetBrowserRequestHandler : protected AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler , protected AzQtComponents::DragAndDropEventsBus::Handler - , protected AzToolsFramework::AssetBrowser::PreviewerRequestBus::Handler { public: AzAssetBrowserRequestHandler(); @@ -66,16 +63,8 @@ protected: void DragLeave(QDragLeaveEvent* event) override; void Drop(QDropEvent* event, AzQtComponents::DragAndDropContextBase& context) override; - ////////////////////////////////////////////////////////////////////////// - // PreviewerRequestBus::Handler - ////////////////////////////////////////////////////////////////////////// - const AzToolsFramework::AssetBrowser::PreviewerFactory* GetPreviewerFactory(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const override; - bool CanAcceptDragAndDropEvent( QDropEvent* event, AzQtComponents::DragAndDropContextBase& context, AZStd::optional*> outSources = AZStd::nullopt, AZStd::optional*> outProducts = AZStd::nullopt) const; - -private: - AZStd::unique_ptr m_previewerFactory; }; diff --git a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.cpp b/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.cpp deleted file mode 100644 index 19938db676..0000000000 --- a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.cpp +++ /dev/null @@ -1,409 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "LegacyPreviewer.h" - -// AzToolsFramework -#include -#include -#include - -// Editor -#include "Util/Image.h" -#include "Util/ImageUtil.h" - -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -#include -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - -static const int s_CharWidth = 6; -const QString LegacyPreviewer::Name{ QStringLiteral("LegacyPreviewer") }; - -LegacyPreviewer::LegacyPreviewer(QWidget* parent) - : Previewer(parent) - , m_ui(new Ui::LegacyPreviewerClass()) - , m_textureType(TextureType::RGB) -{ - m_ui->setupUi(this); - m_ui->m_comboBoxRGB->addItems(QStringList() << "RGB" << "RGBA" << "Alpha"); - m_ui->m_previewCtrl->SetAspectRatio(4.0f / 3.0f); - connect(m_ui->m_comboBoxRGB, static_cast(&QComboBox::activated), this, - [=](int index) - { - m_textureType = static_cast(index); - UpdateTextureType(); - }); - Clear(); -} - -LegacyPreviewer::~LegacyPreviewer() -{ -} - -void LegacyPreviewer::Clear() const -{ - m_ui->m_previewCtrl->ReleaseObject(); - m_ui->m_modelPreviewWidget->hide(); - m_ui->m_texturePreviewWidget->hide(); - m_ui->m_fileInfoCtrl->hide(); -} - -void LegacyPreviewer::Display(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) -{ - using namespace AzToolsFramework::AssetBrowser; - - if (!entry) - { - Clear(); - return; - } - - switch (entry->GetEntryType()) - { - case AssetBrowserEntry::AssetEntryType::Source: - { - const SourceAssetBrowserEntry* sourceEntry = azrtti_cast(entry); - DisplaySource(sourceEntry); - break; - } - case AssetBrowserEntry::AssetEntryType::Product: - DisplayProduct(static_cast(entry)); - break; - default: - Clear(); - } -} - -const QString& LegacyPreviewer::GetName() const -{ - return Name; -} - -void LegacyPreviewer::resizeEvent(QResizeEvent* /*event*/) -{ - m_ui->m_fileInfoCtrl->setText(WordWrap(m_fileinfo, m_ui->m_fileInfoCtrl->width() / s_CharWidth)); -} - -bool LegacyPreviewer::DisplayProduct(const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry* product) -{ - m_ui->m_fileInfoCtrl->show(); - - m_fileinfo = QString::fromUtf8(product->GetName().c_str()); - - m_fileinfo += GetFileSize(product->GetRelativePath().c_str()); - - EBusFindAssetTypeByName meshAssetTypeResult("Static Mesh"); - AZ::AssetTypeInfoBus::BroadcastResult(meshAssetTypeResult, &AZ::AssetTypeInfo::GetAssetType); - - QString filename(product->GetRelativePath().c_str()); - - // Find item. - if (product->GetAssetType() == meshAssetTypeResult.GetAssetType()) - { - m_ui->m_modelPreviewWidget->show(); - m_ui->m_texturePreviewWidget->hide(); - m_ui->m_previewCtrl->LoadFile(filename); - - int nVertexCount = m_ui->m_previewCtrl->GetVertexCount(); - int nFaceCount = m_ui->m_previewCtrl->GetFaceCount(); - int nMaxLod = m_ui->m_previewCtrl->GetMaxLod(); - int nMtls = m_ui->m_previewCtrl->GetMtlCount(); - if (nFaceCount > 0) - { - m_fileinfo += tr("\r\n%1 Faces\r\n%2 Verts\r\n%3 MaxLod\r\n%4 Materials").arg(nFaceCount).arg(nVertexCount).arg(nMaxLod).arg(nMtls); - } - m_ui->m_fileInfoCtrl->setText(WordWrap(m_fileinfo, m_ui->m_fileInfoCtrl->width() / s_CharWidth)); - updateGeometry(); - return true; - } - - EBusFindAssetTypeByName textureAssetTypeResult("Texture"); - AZ::AssetTypeInfoBus::BroadcastResult(textureAssetTypeResult, &AZ::AssetTypeInfo::GetAssetType); - - if (product->GetAssetType() == textureAssetTypeResult.GetAssetType()) - { - // Get full product file path - const char* assetCachePath = AZ::IO::FileIOBase::GetInstance()->GetAlias("@assets@"); - AZStd::string productFullPath; - AzFramework::StringFunc::Path::Join(assetCachePath, product->GetRelativePath().c_str(), productFullPath); - if (AZ::IO::FileIOBase::GetInstance()->Exists(productFullPath.c_str())) - { - // Try to display it in modern dds image loader, if no one exists, use the legacy image loader - bool foundPixmap = DisplayTextureProductModern(productFullPath.c_str()); - return foundPixmap ? foundPixmap : DisplayTextureLegacy(productFullPath.c_str()); - } - else - { - // If we cannot find the product file, means it's not treated as an asset, display its source - return DisplayTextureLegacy(product->GetFullPath().c_str()); - } - } - - Clear(); - return false; -} - -void LegacyPreviewer::DisplaySource(const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* source) -{ - using namespace AzToolsFramework::AssetBrowser; - - EBusFindAssetTypeByName textureAssetType("Texture"); - AZ::AssetTypeInfoBus::BroadcastResult(textureAssetType, &AZ::AssetTypeInfo::GetAssetType); - - if (source->GetPrimaryAssetType() == textureAssetType.GetAssetType()) - { - m_ui->m_fileInfoCtrl->show(); - m_fileinfo = QString::fromUtf8(source->GetName().c_str()); - m_fileinfo += GetFileSize(source->GetFullPath().c_str()); - const char* fullSourcePath = source->GetFullPath().c_str(); - // If it's a source dds file, try to display it using modern way - if (AzFramework::StringFunc::Path::IsExtension(fullSourcePath, "dds", false)) - { - if (DisplayTextureProductModern(fullSourcePath)) - { - return; - } - } - DisplayTextureLegacy(source->GetFullPath().c_str()); - } - else - { - AZStd::vector products; - source->GetChildrenRecursively(products); - if (products.empty()) - { - Clear(); - } - else - { - for (auto* product : products) - { - if (DisplayProduct(product)) - { - break; - } - } - } - } -} - -QString LegacyPreviewer::GetFileSize(const char* path) -{ - QString fileSizeStr; - AZ::u64 fileSizeResult = 0; - if (AZ::IO::FileIOBase::GetInstance()->Size(path, fileSizeResult)) - { - static double kb = 1024.0f; - static double mb = kb * 1024.0; - static double gb = mb * 1024.0; - - static QString byteStr = "B"; - static QString kbStr = "KB"; - static QString mbStr = "MB"; - static QString gbStr = "GB"; - -#if AZ_TRAIT_OS_PLATFORM_APPLE - kb = 1000.0; - mb = kb * 1000.0; - gb = mb * 1000.0; - - kbStr = "kB"; - mbStr = "mB"; - gbStr = "gB"; -#endif // AZ_TRAIT_OS_PLATFORM_APPLE - - if (fileSizeResult < kb) - { - fileSizeStr += tr("\r\nFile Size: %1%2").arg(QString::number(fileSizeResult), byteStr); - } - else if (fileSizeResult < mb) - { - double size = fileSizeResult / kb; - fileSizeStr += tr("\r\nFile Size: %1%2").arg(QString::number(size, 'f', 2), kbStr); - } - else if (fileSizeResult < gb) - { - double size = fileSizeResult / mb; - fileSizeStr += tr("\r\nFile Size: %1%2").arg(QString::number(size, 'f', 2), mbStr); - } - else - { - double size = fileSizeResult / gb; - fileSizeStr += tr("\r\nFile Size: %1%2").arg(QString::number(size, 'f', 2), gbStr); - } - } - return fileSizeStr; -} - -bool LegacyPreviewer::DisplayTextureLegacy(const char* fullImagePath) -{ - m_ui->m_modelPreviewWidget->hide(); - m_ui->m_texturePreviewWidget->show(); - - bool foundPixmap = false; - if (!AZ::IO::FileIOBase::GetInstance()->IsDirectory(fullImagePath)) - { - QString strLoadFilename = QString(fullImagePath); - if (CImageUtil::LoadImage(strLoadFilename, m_previewImageSource)) - { - m_fileinfo += QStringLiteral("\r\n%1x%2\r\n%3") - .arg(m_previewImageSource.GetWidth()) - .arg(m_previewImageSource.GetHeight()) - .arg(m_previewImageSource.GetFormatDescription()); - - m_fileinfoAlphaTexture = m_fileinfo; - UpdateTextureType(); - foundPixmap = true; - } - } - - if (!foundPixmap) - { - m_ui->m_previewImageCtrl->setPixmap(QPixmap()); - m_ui->m_fileInfoCtrl->setText(WordWrap(m_fileinfo, m_ui->m_fileInfoCtrl->width() / s_CharWidth)); - } - - updateGeometry(); - - return foundPixmap; -} - -bool LegacyPreviewer::DisplayTextureProductModern(const char* fullProductImagePath) -{ - m_ui->m_modelPreviewWidget->hide(); - m_ui->m_texturePreviewWidget->show(); - - bool foundPixmap = false; - QImage previewImage; - AZStd::string productInfo; - AZStd::string productAlphaInfo; - AzToolsFramework::AssetBrowser::AssetBrowserTexturePreviewRequestsBus::BroadcastResult(foundPixmap, &AzToolsFramework::AssetBrowser::AssetBrowserTexturePreviewRequests::GetProductTexturePreview, fullProductImagePath, previewImage, productInfo, productAlphaInfo); - - if (foundPixmap) - { - QPixmap pix = QPixmap::fromImage(previewImage); - m_ui->m_previewImageCtrl->setPixmap(pix); - m_ui->m_previewImageCtrl->updateGeometry(); - CImageUtil::QImageToImage(previewImage, m_previewImageSource); - - m_fileinfo += QStringLiteral("\r\n%1x%2\r\n%3") - .arg(m_previewImageSource.GetWidth()) - .arg(m_previewImageSource.GetHeight()) - .arg(m_previewImageSource.GetFormatDescription()); - - m_fileinfoAlphaTexture = m_fileinfo; - - m_fileinfo += QString(productInfo.c_str()); - if (productAlphaInfo.empty()) - { - // If there is no separate info for alpha, use the image info - m_fileinfoAlphaTexture += QString(productInfo.c_str()); - } - else - { - m_fileinfoAlphaTexture += QString(productAlphaInfo.c_str()); - } - - - UpdateTextureType(); - } - else - { - m_ui->m_previewImageCtrl->setPixmap(QPixmap()); - m_ui->m_fileInfoCtrl->setText(WordWrap(m_fileinfo, m_ui->m_fileInfoCtrl->width() / s_CharWidth)); - } - - updateGeometry(); - return foundPixmap; -} - -void LegacyPreviewer::UpdateTextureType() -{ - m_previewImageUpdated.Copy(m_previewImageSource); - - switch (m_textureType) - { - case TextureType::RGB: - { - m_previewImageUpdated.SwapRedAndBlue(); - m_previewImageUpdated.FillAlpha(); - break; - } - case TextureType::RGBA: - { - m_previewImageUpdated.SwapRedAndBlue(); - break; - } - case TextureType::Alpha: - { - for (int h = 0; h < m_previewImageUpdated.GetHeight(); h++) - { - for (int w = 0; w < m_previewImageUpdated.GetWidth(); w++) - { - int a = m_previewImageUpdated.ValueAt(w, h) >> 24; - m_previewImageUpdated.ValueAt(w, h) = RGB(a, a, a) | 0xFF000000; - } - } - break; - } - } - // note that Qt will not deep copy the data, so WE MUST KEEP THE IMAGE DATA AROUND! - QPixmap qtPixmap = QPixmap::fromImage( - QImage(reinterpret_cast(m_previewImageUpdated.GetData()), m_previewImageUpdated.GetWidth(), m_previewImageUpdated.GetHeight(), QImage::Format_ARGB32)); - m_ui->m_previewImageCtrl->setPixmap(qtPixmap); - m_ui->m_fileInfoCtrl->setText(WordWrap(m_textureType == TextureType::Alpha? m_fileinfoAlphaTexture: m_fileinfo, m_ui->m_fileInfoCtrl->width() / s_CharWidth)); - m_ui->m_previewImageCtrl->updateGeometry(); -} - -bool LegacyPreviewer::FileInfoCompare(const FileInfo& f1, const FileInfo& f2) -{ - if ((f1.attrib & _A_SUBDIR) && !(f2.attrib & _A_SUBDIR)) - { - return true; - } - if (!(f1.attrib & _A_SUBDIR) && (f2.attrib & _A_SUBDIR)) - { - return false; - } - - return QString::compare(f1.filename, f2.filename, Qt::CaseInsensitive) < 0; -} - -QString LegacyPreviewer::WordWrap(const QString& string, int maxLength) -{ - QString result; - int length = 0; - - for (auto c : string) - { - if (c == '\n') - { - length = 0; - } - else if (length > maxLength) - { - result.append('\n'); - length = 0; - } - else - { - length++; - } - result.append(c); - } - return result; -} - -#include diff --git a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.h b/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.h deleted file mode 100644 index 0035f23442..0000000000 --- a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include -#include - -#include -#include -#endif - -namespace Ui -{ - class LegacyPreviewerClass; -} - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - class ProductAssetBrowserEntry; - class SourceAssetBrowserEntry; - class AssetBrowserEntry; - } -} - -class QResizeEvent; - -class LegacyPreviewer - : public AzToolsFramework::AssetBrowser::Previewer -{ - Q_OBJECT -public: - AZ_CLASS_ALLOCATOR(LegacyPreviewer, AZ::SystemAllocator, 0); - - explicit LegacyPreviewer(QWidget* parent = nullptr); - ~LegacyPreviewer(); - - ////////////////////////////////////////////////////////////////////////// - // AzToolsFramework::AssetBrowser::Previewer - ////////////////////////////////////////////////////////////////////////// - void Clear() const override; - void Display(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) override; - const QString& GetName() const override; - - static const QString Name; - -protected: - void resizeEvent(QResizeEvent * event) override; - -private: - struct FileInfo - { - QString filename; - unsigned attrib; - time_t time_create; /* -1 for FAT file systems */ - time_t time_access; /* -1 for FAT file systems */ - time_t time_write; - _fsize_t size; - }; - - enum class TextureType - { - RGB, - RGBA, - Alpha - }; - - QScopedPointer m_ui; - CImageEx m_previewImageSource; - CImageEx m_previewImageUpdated; - TextureType m_textureType; - QString m_fileinfo; - QString m_fileinfoAlphaTexture; - - bool DisplayProduct(const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry* product); - void DisplaySource(const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* source); - - QString GetFileSize(const char* path); - - bool DisplayTextureLegacy(const char* fullImagePath); - bool DisplayTextureProductModern(const char* fullProductImagePath); - - void UpdateTextureType(); - - static bool FileInfoCompare(const FileInfo& f1, const FileInfo& f2); - //! QLabel word wrap does not break long words such as filenames, so manual word wrap needed - static QString WordWrap(const QString& string, int maxLength); -}; diff --git a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.ui b/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.ui deleted file mode 100644 index 649192d60f..0000000000 --- a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewer.ui +++ /dev/null @@ -1,176 +0,0 @@ - - - LegacyPreviewerClass - - - - 0 - 0 - 148 - 282 - - - - Preview - - - - 0 - - - 5 - - - 0 - - - 5 - - - 0 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - Qt::AutoText - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - CPreviewModelCtrl - QWidget -
Controls/PreviewModelCtrl.h
- 1 -
- - AzToolsFramework::AspectRatioAwarePixmapWidget - QWidget -
AzToolsFramework/UI/UICore/AspectRatioAwarePixmapWidget.hxx
- 1 -
-
- - -
diff --git a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewerFactory.cpp b/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewerFactory.cpp deleted file mode 100644 index 93620d26a6..0000000000 --- a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewerFactory.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "LegacyPreviewerFactory.h" - -// AzToolsFramework -#include // for AssetBrowserEntry::AssetEntryType -#include // for EBusFindAssetTypeByName - -// Editor -#include "LegacyPreviewer.h" - - -AzToolsFramework::AssetBrowser::Previewer* LegacyPreviewerFactory::CreatePreviewer(QWidget* parent) const -{ - return new LegacyPreviewer(parent); -} - -bool LegacyPreviewerFactory::IsEntrySupported(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const -{ - using namespace AzToolsFramework::AssetBrowser; - - EBusFindAssetTypeByName meshAssetTypeResult("Static Mesh"); - AZ::AssetTypeInfoBus::BroadcastResult(meshAssetTypeResult, &AZ::AssetTypeInfo::GetAssetType); - EBusFindAssetTypeByName textureAssetTypeResult("Texture"); - AZ::AssetTypeInfoBus::BroadcastResult(textureAssetTypeResult, &AZ::AssetTypeInfo::GetAssetType); - - switch (entry->GetEntryType()) - { - case AssetBrowserEntry::AssetEntryType::Source: - { - const auto* source = azrtti_cast < const SourceAssetBrowserEntry * > (entry); - if (source->GetPrimaryAssetType() == textureAssetTypeResult.GetAssetType()) - { - return true; - } - AZStd::vector < const ProductAssetBrowserEntry * > products; - source->GetChildrenRecursively < ProductAssetBrowserEntry > (products); - for (auto* product : products) - { - if (product->GetAssetType() == textureAssetTypeResult.GetAssetType() || - product->GetAssetType() == meshAssetTypeResult.GetAssetType()) - { - return true; - } - } - break; - } - case AssetBrowserEntry::AssetEntryType::Product: - const auto* product = azrtti_cast < const ProductAssetBrowserEntry * > (entry); - return product->GetAssetType() == textureAssetTypeResult.GetAssetType() || - product->GetAssetType() == meshAssetTypeResult.GetAssetType(); - } - return false; -} - -const QString& LegacyPreviewerFactory::GetName() const -{ - return LegacyPreviewer::Name; -} diff --git a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewerFactory.h b/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewerFactory.h deleted file mode 100644 index e6b133cb97..0000000000 --- a/Code/Sandbox/Editor/AzAssetBrowser/Preview/LegacyPreviewerFactory.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include -#include - -class QString; - -class LegacyPreviewerFactory final - : public AzToolsFramework::AssetBrowser::PreviewerFactory -{ -public: - AZ_CLASS_ALLOCATOR(LegacyPreviewerFactory, AZ::SystemAllocator, 0); - - LegacyPreviewerFactory() = default; - ~LegacyPreviewerFactory() = default; - - ////////////////////////////////////////////////////////////////////////// - // AzToolsFramework::AssetBrowser::PreviewerFactory - ////////////////////////////////////////////////////////////////////////// - AzToolsFramework::AssetBrowser::Previewer* CreatePreviewer(QWidget* parent = nullptr) const override; - bool IsEntrySupported(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const override; - const QString& GetName() const override; -}; diff --git a/Code/Sandbox/Editor/BaseLibraryManager.cpp b/Code/Sandbox/Editor/BaseLibraryManager.cpp index 61c6354b1a..d9017c1be8 100644 --- a/Code/Sandbox/Editor/BaseLibraryManager.cpp +++ b/Code/Sandbox/Editor/BaseLibraryManager.cpp @@ -826,9 +826,6 @@ void CBaseLibraryManager::OnEditorNotifyEvent(EEditorNotifyEvent event) SetSelectedItem(0); ClearAll(); break; - case eNotify_OnMissionChange: - SetSelectedItem(0); - break; case eNotify_OnCloseScene: SetSelectedItem(0); ClearAll(); diff --git a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.cpp b/Code/Sandbox/Editor/Controls/PreviewModelCtrl.cpp deleted file mode 100644 index 5746e9db2f..0000000000 --- a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.cpp +++ /dev/null @@ -1,1229 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "PreviewModelCtrl.h" - -// AzQtComponents -#include - -// Editor -#include "Settings.h" -#include "Util/Image.h" -#include "Include/IIconManager.h" - -struct CPreviewModelCtrl::SPreviousContext -{ - CCamera renderCamera; - CCamera systemCamera; - int width; - int height; - HWND window; - bool isMainViewport; -}; - -CPreviewModelCtrl::CPreviewModelCtrl(QWidget* parent, Qt::WindowFlags f) - : QWidget(parent, f) -{ - OnCreate(); -} - -void CPreviewModelCtrl::OnCreate() -{ - m_bShowObject = true; - m_pRenderer = 0; - m_pObj = 0; - m_pEntity = 0; - m_nTimer = 0; - m_size = Vec3(0, 0, 0); - - m_bRotate = false; - m_rotateAngle = 0; - - m_backgroundTextureId = 0; - - m_pRenderer = GetIEditor()->GetRenderer(); - - m_fov = 60; - m_camera.SetFrustum(800, 600, DEG2RAD(m_fov), 0.02f, 10000.0f); - - m_bInRotateMode = false; - m_bInMoveMode = false; - - CDLight l; - - float L = 1.0f; - l.m_fRadius = 10000; - l.m_Flags |= DLF_SUN | DLF_DIRECTIONAL; - l.SetLightColor(ColorF(L, L, L, 1)); - l.SetPosition(Vec3(100, 100, 100)); - m_lights.push_back(l); - - m_bUseBacklight = false; - m_bContextCreated = false; - m_bHaveAnythingToRender = false; - m_bGrid = true; - m_bAxis = true; - m_bAxisParticleEditor = false; - m_bUpdate = false; - m_bShowNormals = false; - m_bShowPhysics = false; - m_bShowRenderInfo = false; - - m_cameraAngles.Set(0, 0, 0); - - m_clearColor.Set(0.5f, 0.5f, 0.5f); - m_ambientColor.Set(1.0f, 1.0f, 1.0f); - m_ambientMultiplier = 0.5f; - - m_cameraChangeCallback = NULL; - m_bPrecacheMaterial = false; - m_bDrawWireFrame = false; - - m_tileX = 0.0f; - m_tileY = 0.0f; - m_tileSizeX = 1.0f; - m_tileSizeY = 1.0f; - - m_aabb = AABB(2); - FitToScreen(); - - setAttribute(Qt::WA_NativeWindow); - setAttribute(Qt::WA_PaintOnScreen); - setAttribute(Qt::WA_OpaquePaintEvent); - - GetIEditor()->RegisterNotifyListener(this); -} - -CPreviewModelCtrl::~CPreviewModelCtrl() -{ - OnDestroy(); - ReleaseObject(); - GetIEditor()->UnregisterNotifyListener(this); -} - -bool CPreviewModelCtrl::CreateContext() -{ - // Create context. - if (m_pRenderer && !m_bContextCreated) - { - StorePreviousContext(); - m_bContextCreated = true; - - // save the old context, because CreateContext sets it, and we don't actually want that: - StorePreviousContext(); - m_pRenderer->CreateContext(m_hWnd); - - RestorePreviousContext(); - return true; - } - return false; -} - -void CPreviewModelCtrl::ReleaseObject() -{ - m_pObj = NULL; - m_pEntity = 0; - m_bHaveAnythingToRender = false; -} - -void CPreviewModelCtrl::LoadFile(const QString& modelFile, bool changeCamera) -{ - m_bHaveAnythingToRender = false; - if (!m_hWnd) - { - return; - } - if (!m_pRenderer) - { - return; - } - - ReleaseObject(); - - if (modelFile.isEmpty()) - { - if (m_nTimer != 0) - { - killTimer(m_nTimer); - } - m_nTimer = 0; - update(); - return; - } - - m_loadedFile = modelFile; - - QString strFileExt = QFileInfo(modelFile).suffix(); - const bool isSKEL = strFileExt.compare(QStringLiteral(CRY_SKEL_FILE_EXT), Qt::CaseInsensitive) == 0; - const bool isSKIN = strFileExt.compare(QStringLiteral(CRY_SKIN_FILE_EXT), Qt::CaseInsensitive) == 0; - const bool isCDF = strFileExt.compare(QStringLiteral(CRY_CHARACTER_DEFINITION_FILE_EXT), Qt::CaseInsensitive) == 0; - const bool isCGA = strFileExt.compare(QStringLiteral(CRY_ANIM_GEOMETRY_FILE_EXT), Qt::CaseInsensitive) == 0; - const bool isCGF = strFileExt.compare(QStringLiteral(CRY_GEOMETRY_FILE_EXT), Qt::CaseInsensitive) == 0; - - if (isCGF) - { - // Load object. - m_pObj = GetIEditor()->Get3DEngine()->LoadStatObjAutoRef(modelFile.toUtf8().data(), NULL, NULL, false); - if (!m_pObj) - { - Warning("Loading of geometry object %s failed.", modelFile.toUtf8().constData()); - if (m_nTimer != 0) - { - killTimer(m_nTimer); - } - m_nTimer = 0; - update(); - return; - } - m_aabb.min = m_pObj->GetBoxMin(); - m_aabb.max = m_pObj->GetBoxMax(); - } - else - { - if (m_nTimer != 0) - { - killTimer(m_nTimer); - } - m_nTimer = 0; - update(); - return; - } - - m_bHaveAnythingToRender = true; - - if (changeCamera) - { - FitToScreen(); - } - - update(); -} - -void CPreviewModelCtrl::SetAspectRatio(float aspectRatio) -{ - if (aspectRatio != m_aspectRatio) - { - m_aspectRatio = aspectRatio; - m_useAspectRatio = true; - updateGeometry(); - } -} - -bool CPreviewModelCtrl::hasHeightForWidth() const -{ - return m_useAspectRatio; -} - -int CPreviewModelCtrl::heightForWidth(int w) const -{ - if (m_useAspectRatio) - { - return static_cast(static_cast(w) / m_aspectRatio); - } - - return QWidget::heightForWidth(w); -} - -void CPreviewModelCtrl::SetEntity(IRenderNode* entity) -{ - m_bHaveAnythingToRender = false; - if (m_pEntity != entity) - { - m_pEntity = entity; - if (m_pEntity) - { - m_bHaveAnythingToRender = true; - m_aabb = m_pEntity->GetBBox(); - } - update(); - } -} - -void CPreviewModelCtrl::SetObject(IStatObj* pObject) -{ - if (m_pObj != pObject) - { - m_bHaveAnythingToRender = false; - m_pObj = pObject; - if (m_pObj) - { - m_bHaveAnythingToRender = true; - m_aabb = m_pObj->GetAABB(); - } - update(); - } -} - -void CPreviewModelCtrl::SetCameraRadius(float fRadius) -{ - m_cameraRadius = fRadius; - - Matrix34 m = m_camera.GetMatrix(); - Vec3 dir = m.TransformVector(Vec3(0, 1, 0)); - Matrix34 tm = Matrix33::CreateRotationVDir(dir, 0); - tm.SetTranslation(m_cameraTarget - dir * m_cameraRadius); - m_camera.SetMatrix(tm); - if (m_cameraChangeCallback) - { - m_cameraChangeCallback(m_pCameraChangeUserData, this); - } -} - -void CPreviewModelCtrl::SetCameraLookAt(float fRadiusScale, const Vec3& fromDir) -{ - m_cameraTarget = m_aabb.GetCenter(); - m_cameraRadius = m_aabb.GetRadius() * fRadiusScale; - - Vec3 dir = fromDir.GetNormalized(); - Matrix34 tm = Matrix33::CreateRotationVDir(dir, 0); - tm.SetTranslation(m_cameraTarget - dir * m_cameraRadius); - m_camera.SetMatrix(tm); - if (m_cameraChangeCallback) - { - m_cameraChangeCallback(m_pCameraChangeUserData, this); - } -} - -CCamera& CPreviewModelCtrl::GetCamera() -{ - return m_camera; -} - -void CPreviewModelCtrl::UseBackLight(bool bEnable) -{ - if (bEnable) - { - m_lights.resize(1); - CDLight l; - l.SetPosition(Vec3(-100, 100, -100)); - float L = 0.5f; - l.SetLightColor(ColorF(L, L, L, 1)); - l.m_fRadius = 1000; - l.m_Flags |= DLF_POINT; - m_lights.push_back(l); - } - else - { - m_lights.resize(1); - } - m_bUseBacklight = bEnable; -} - -void CPreviewModelCtrl::SetCamera(CCamera& cam) -{ - m_camera.SetPosition(cam.GetPosition()); - -#if defined(AZ_PLATFORM_WINDOWS) - // Needed for high DPI mode on windows - const qreal ratio = devicePixelRatioF(); -#else - const qreal ratio = 1.0f; -#endif - const int w = width() * ratio * m_tileSizeX; - const int h = height() * ratio * m_tileSizeY; - m_camera.SetFrustum(w, h, DEG2RAD(m_fov), m_camera.GetNearPlane(), m_camera.GetFarPlane()); - - if (m_cameraChangeCallback) - { - m_cameraChangeCallback(m_pCameraChangeUserData, this); - } -} - -void CPreviewModelCtrl::SetOrbitAngles([[maybe_unused]] const Ang3& ang) -{ - assert(0); -} - -bool CPreviewModelCtrl::Render() -{ - const int w = width(); - const int h = height(); - - if (h < 2 || w < 2) - { - return false; - } - - if (!m_bContextCreated) - { - if (!CreateContext()) - { - return false; - } - } - - _smart_ptr pMaterial; - if (m_pCurrentMaterial) - { - pMaterial = m_pCurrentMaterial->GetMatInfo(); - } - - if (m_bPrecacheMaterial) - { - // Precache material - This loads/creates the material, shader and textures - // Moving this to the top of Render() so precaching precedes current and future - // rendering code - - _smart_ptr pCurMat = pMaterial; - - if (!pCurMat) - { - pCurMat = GetCurrentMaterial(); - } - - if (pCurMat) - { - pCurMat->PrecacheMaterial(0.0f, NULL, true, true); - } - } - - SetCamera(m_camera); - - m_pRenderer->SetClearColor(Vec3(m_clearColor.r, m_clearColor.g, m_clearColor.b)); - m_pRenderer->BeginFrame(); - SetCurrentContext(); - m_pRenderer->SetRenderTile(m_tileX, m_tileY, m_tileSizeX, m_tileSizeY); - - // Render grid. Explicitly clear color and depth buffer first - // (otherwise ->EndEf3D() will do that and thereby clear the grid). - m_pRenderer->ClearTargetsImmediately(FRT_CLEAR, m_clearColor); - - DrawBackground(); - if (m_bGrid || m_bAxis) - { - DrawGrid(); - } - - // save some cvars - int showNormals = gEnv->pConsole->GetCVar("r_ShowNormals")->GetIVal(); - int showInfo = gEnv->pConsole->GetCVar("r_displayInfo")->GetIVal(); - - gEnv->pConsole->GetCVar("r_ShowNormals")->Set((int)m_bShowNormals); - gEnv->pConsole->GetCVar("r_displayInfo")->Set((int)m_bShowRenderInfo); - - // Render object. - SRenderingPassInfo passInfo = SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_camera, SRenderingPassInfo::DEFAULT_FLAGS, true); - m_pRenderer->BeginSpawningGeneratingRendItemJobs(passInfo.ThreadID()); - m_pRenderer->BeginSpawningShadowGeneratingRendItemJobs(passInfo.ThreadID()); - m_pRenderer->EF_StartEf(passInfo); - m_pRenderer->ResetToDefault(); - - - { - CScopedWireFrameMode scopedWireFrame(m_pRenderer, m_bDrawWireFrame ? R_WIREFRAME_MODE : R_SOLID_MODE); - - // Add lights. - for (size_t i = 0; i < m_lights.size(); i++) - { - m_pRenderer->EF_ADDDlight(&m_lights[i], passInfo); - } - - if (m_pCurrentMaterial) - { - m_pCurrentMaterial->DisableHighlightForFrame(); - } - - if (m_bShowObject) - { - RenderObject(pMaterial, passInfo); - } - - m_pRenderer->EF_EndEf3D(SHDF_NOASYNC | SHDF_STREAM_SYNC, -1, -1, passInfo); - } - - m_pRenderer->EF_RenderTextMessages(); - m_pRenderer->RenderDebug(false); - m_pRenderer->EndFrame(); - m_pRenderer->SetRenderTile(); - - // Restore main context. - RestorePreviousContext(); - - gEnv->pConsole->GetCVar("r_ShowNormals")->Set(showNormals); - gEnv->pConsole->GetCVar("r_displayInfo")->Set(showInfo); - - return true; -} - -void CPreviewModelCtrl::RenderObject(_smart_ptr pMaterial, SRenderingPassInfo& passInfo) -{ - SRendParams rp; - rp.dwFObjFlags = 0; - rp.AmbientColor = m_ambientColor * m_ambientMultiplier; - rp.dwFObjFlags |= FOB_NO_FOG; - rp.pMaterial = pMaterial; - - Matrix34 tm; - tm.SetIdentity(); - rp.pMatrix = &tm; - - if (m_bRotate) - { - tm.SetRotationXYZ(Ang3(0, 0, m_rotateAngle)); - m_rotateAngle += 0.1f; - } - - if (m_pObj) - { - m_pObj->Render(rp, passInfo); - } - - if (m_pEntity) - { - m_pEntity->Render(rp, passInfo); - } -} - -void CPreviewModelCtrl::DrawGrid() -{ - // Draw grid. - float step = 0.1f; - float XR = 5; - float YR = 5; - - IRenderAuxGeom* pRag = m_pRenderer->GetIRenderAuxGeom(); - SAuxGeomRenderFlags nRendFlags = pRag->GetRenderFlags(); - - pRag->SetRenderFlags(e_Def3DPublicRenderflags); - SAuxGeomRenderFlags nNewFlags = pRag->GetRenderFlags(); - nNewFlags.SetAlphaBlendMode(e_AlphaBlended); - pRag->SetRenderFlags(nNewFlags); - - int nGridAlpha = 40; - if (m_bGrid) - { - // Draw grid. - for (float x = -XR; x < XR; x += step) - { - if (fabs(x) > 0.01) - { - pRag->DrawLine(Vec3(x, -YR, 0), ColorB(150, 150, 150, nGridAlpha), Vec3(x, YR, 0), ColorB(150, 150, 150, nGridAlpha)); - } - } - for (float y = -YR; y < YR; y += step) - { - if (fabs(y) > 0.01) - { - pRag->DrawLine(Vec3(-XR, y, 0), ColorB(150, 150, 150, nGridAlpha), Vec3(XR, y, 0), ColorB(150, 150, 150, nGridAlpha)); - } - } - } - - nGridAlpha = 60; - if (m_bAxis) - { - // Draw axis. - pRag->DrawLine(Vec3(0, 0, 0), ColorB(255, 0, 0, nGridAlpha), Vec3(XR, 0, 0), ColorB(255, 0, 0, nGridAlpha)); - pRag->DrawLine(Vec3(0, 0, 0), ColorB(0, 255, 0, nGridAlpha), Vec3(0, YR, 0), ColorB(0, 255, 0, nGridAlpha)); - pRag->DrawLine(Vec3(0, 0, 0), ColorB(0, 0, 255, nGridAlpha), Vec3(0, 0, YR), ColorB(0, 0, 255, nGridAlpha)); - } - pRag->Flush(); - pRag->SetRenderFlags(nRendFlags); -} - -void CPreviewModelCtrl::timerEvent(QTimerEvent* event) -{ - if (isVisible()) - { - if (m_bHaveAnythingToRender) - { - update(); - } - } - - QWidget::timerEvent(event); -} - -void CPreviewModelCtrl::SetCameraTM(const Matrix34& cameraTM) -{ - m_camera.SetMatrix(cameraTM); - if (m_cameraChangeCallback) - { - m_cameraChangeCallback(m_pCameraChangeUserData, this); - } -} - -void CPreviewModelCtrl::GetCameraTM(Matrix34& cameraTM) -{ - cameraTM = m_camera.GetMatrix(); -} - -void CPreviewModelCtrl::DeleteRenderContex() -{ - ReleaseObject(); - - // Destroy render context. - if (m_pRenderer && m_bContextCreated) - { - m_pRenderer->DeleteContext(m_hWnd); - m_bContextCreated = false; - } -} - -void CPreviewModelCtrl::OnDestroy() -{ - DeleteRenderContex(); - - if (m_nTimer) - { - killTimer(m_nTimer); - } -} - -void CPreviewModelCtrl::OnLButtonDown(QPoint point) -{ - m_bInRotateMode = true; - m_mousePosition = point; - m_previousMousePosition = m_mousePosition; - - setFocus(); - update(); -} - -void CPreviewModelCtrl::OnLButtonUp(QPoint point) -{ - m_bInRotateMode = false; - update(); - m_mousePosition = point; - m_previousMousePosition = m_mousePosition; -} - -void CPreviewModelCtrl::OnMButtonDown(QPoint point) -{ - m_bInPanMode = true; - update(); - m_mousePosition = point; - m_previousMousePosition = m_mousePosition; -} - -void CPreviewModelCtrl::OnMButtonUp(QPoint point) -{ - m_bInPanMode = false; - update(); - m_mousePosition = point; - m_previousMousePosition = m_mousePosition; -} - -void CPreviewModelCtrl::mouseMoveEvent(QMouseEvent* event) -{ - // TODO: Add your message handler code here and/or call default - QWidget::mouseMoveEvent(event); - - const QPoint& point = event->pos(); - if (point == m_previousMousePosition) - { - return; - } - - if (m_bInMoveMode) - { - // Zoom. - Matrix34 m = m_camera.GetMatrix(); - Vec3 xdir(0, 0, 0); - Vec3 zdir = m.GetColumn1().GetNormalized(); - - float step = 0.002f; - float dx = (point.x() - m_previousMousePosition.x()); - float dy = (point.y() - m_previousMousePosition.y()); - m_camera.SetPosition(m_camera.GetPosition() + step * xdir * dx + step * zdir * dy); - SetCamera(m_camera); - - if (gSettings.stylusMode) - { - m_previousMousePosition = point; - } - else - { - AzQtComponents::SetCursorPos(mapToGlobal(m_previousMousePosition)); - } - - update(); - } - else if (m_bInRotateMode) - { - Vec3 pos = m_camera.GetMatrix().GetTranslation(); - m_cameraRadius = Vec3(m_camera.GetMatrix().GetTranslation() - m_cameraTarget).GetLength(); - // Look - Ang3 angles(-point.y() + m_previousMousePosition.y(), 0, -point.x() + m_previousMousePosition.x()); - angles = angles * 0.002f; - - Matrix34 camtm = m_camera.GetMatrix(); - Matrix33 Rz = Matrix33::CreateRotationXYZ(Ang3(0, 0, angles.z)); // Rotate around vertical axis. - Matrix33 Rx = Matrix33::CreateRotationAA(angles.x, camtm.GetColumn0()); // Rotate with angle around x axis in camera space. - - Vec3 dir = camtm.TransformVector(Vec3(0, 1, 0)); - Vec3 newdir = (Rx * Rz).TransformVector(dir).GetNormalized(); - camtm = Matrix34(Matrix33::CreateRotationVDir(newdir, 0), m_cameraTarget - newdir * m_cameraRadius); - m_camera.SetMatrix(camtm); - if (m_cameraChangeCallback) - { - m_cameraChangeCallback(m_pCameraChangeUserData, this); - } - - if (gSettings.stylusMode) - { - m_previousMousePosition = point; - } - else - { - AzQtComponents::SetCursorPos(mapToGlobal(m_previousMousePosition)); - } - - update(); - } - else if (m_bInPanMode) - { - // Slide. - float speedScale = 0.001f; - Matrix34 m = m_camera.GetMatrix(); - Vec3 xdir = m.GetColumn0().GetNormalized(); - Vec3 zdir = m.GetColumn2().GetNormalized(); - - Vec3 pos = m_cameraTarget; - pos += 0.1f * xdir * (point.x() - m_previousMousePosition.x()) * speedScale + 0.1f * zdir * (m_previousMousePosition.y() - point.y()) * speedScale; - m_cameraTarget = pos; - - Vec3 dir = m.TransformVector(Vec3(0, 1, 0)); - m.SetTranslation(m_cameraTarget - dir * m_cameraRadius); - m_camera.SetMatrix(m); - if (m_cameraChangeCallback) - { - m_cameraChangeCallback(m_pCameraChangeUserData, this); - } - - if (gSettings.stylusMode) - { - m_previousMousePosition = point; - } - else - { - AzQtComponents::SetCursorPos(mapToGlobal(m_previousMousePosition)); - } - - update(); - } -} - -void CPreviewModelCtrl::OnRButtonDown(QPoint point) -{ - m_bInMoveMode = true; - m_mousePosition = point; - m_previousMousePosition = point; - update(); -} - -void CPreviewModelCtrl::OnRButtonUp(QPoint point) -{ - m_bInMoveMode = false; - - m_mousePosition = point; - m_previousMousePosition = point; - - update(); -} - -void CPreviewModelCtrl::wheelEvent(QWheelEvent* event) -{ - const short zDelta = event->angleDelta().y(); - // TODO: Add your message handler code here and/or call default - Matrix34 m = m_camera.GetMatrix(); - Vec3 zdir = m.GetColumn1().GetNormalized(); - - //m_camera.SetPosition( m_camera.GetPos() + ydir*(m_mousePos.y-point.y),xdir*(m_mousePos.x-point.x) ); - m_camera.SetPosition(m_camera.GetPosition() + 0.002f * zdir * (zDelta)); - SetCamera(m_camera); - update(); -} - -void CPreviewModelCtrl::EnableUpdate(bool bUpdate) -{ - m_bUpdate = bUpdate; - if (m_bUpdate && !m_nTimer) - { - m_nTimer = startTimer(1000); - } - else if (!m_bUpdate && m_nTimer) - { - killTimer(m_nTimer), m_nTimer = 0; - } -} - -void CPreviewModelCtrl::Update(bool bForceUpdate) -{ - ProcessKeys(); - - if (m_bUpdate && m_bHaveAnythingToRender || bForceUpdate) - { - if (isVisible()) - { - update(); - } - } -} - -void CPreviewModelCtrl::SetRotation(bool bEnable) -{ - m_bRotate = bEnable; -} - -void CPreviewModelCtrl::SetMaterial(CMaterial* pMaterial) -{ - if (pMaterial) - { - if ((pMaterial->GetFlags() & MTL_FLAG_NOPREVIEW)) - { - m_pCurrentMaterial = 0; - if (isVisible()) - { - update(); - } - return; - } - } - m_pCurrentMaterial = pMaterial; - if (isVisible()) - { - update(); - } -} - -CMaterial* CPreviewModelCtrl::GetMaterial() -{ - return m_pCurrentMaterial; -} - -void CPreviewModelCtrl::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnIdleUpdate: - Update(); - break; - } -} - -void CPreviewModelCtrl::GetImageOffscreen(CImageEx& image, const QSize& customSize) -{ - // hiding a window can cause this to be dropped, since it no longer associates with - // an actual operating system window handle. - if (!m_hWnd) - { - return; - } - if (!m_pRenderer) - { - return; - } - - m_pRenderer->EnableSwapBuffers(false); - Render(); - m_pRenderer->EnableSwapBuffers(true); - - int w; - int h; - - if (customSize.isValid()) - { - w = customSize.width(); - h = customSize.height(); - } - else - { - w = width(); - h = height(); - } - - image.Allocate(w, h); - - // the renderer will read the frame buffer of the current render context, so we need to set ours as the current before we execute this command. - SetCurrentContext(); - m_pRenderer->ReadFrameBufferFast(image.GetData(), w, h); - RestorePreviousContext(); -} - -void CPreviewModelCtrl::SetClearColor(const ColorF& color) -{ - m_clearColor = color; -} - - -namespace PreviewModelControl -{ - struct MaterialId - { - const void* ptr; - int id; - - MaterialId(const void* a_ptr, int a_id) - : ptr(a_ptr) - , id(a_id) - { - } - - bool operator<(const MaterialId& a) const - { - return ptr < a.ptr || id < a.id; - } - }; - - static int GetFaceCountRecursively(IStatObj* p) - { - if (!p) - { - return 0; - } - int n = 0; - if (p->GetRenderMesh()) - { - n += p->GetRenderMesh()->GetIndicesCount() / 3; - } - for (int i = 0; i < p->GetSubObjectCount(); ++i) - { - IStatObj::SSubObject* const pS = p->GetSubObject(i); - if (pS) - { - n += GetFaceCountRecursively(pS->pStatObj); - } - } - return n; - } - - static int GetVertexCountRecursively(IStatObj* p) - { - if (!p) - { - return 0; - } - int n = 0; - if (p->GetRenderMesh()) - { - n += p->GetRenderMesh()->GetVerticesCount(); - } - for (int i = 0; i < p->GetSubObjectCount(); ++i) - { - IStatObj::SSubObject* const pS = p->GetSubObject(i); - if (pS) - { - n += GetVertexCountRecursively(pS->pStatObj); - } - } - return n; - } - - static int GetMaxLodRecursively(IStatObj* p) - { - if (!p) - { - return 0; - } - int n = 0; - for (int i = 1; i < 10; i++) - { - if (p->GetLodObject(i)) - { - n = i; - } - } - for (int i = 0; i < p->GetSubObjectCount(); ++i) - { - IStatObj::SSubObject* const pS = p->GetSubObject(i); - if (pS) - { - const int n2 = GetMaxLodRecursively(pS->pStatObj); - n = (n < n2) ? n2 : n; - } - } - return n; - } - - static void CollectMaterialsRecursively(std::set& mats, IStatObj* p) - { - if (!p) - { - return; - } - if (p->GetRenderMesh()) - { - TRenderChunkArray& ch = p->GetRenderMesh()->GetChunks(); - for (size_t i = 0; i < ch.size(); ++i) - { - mats.insert(PreviewModelControl::MaterialId(p->GetMaterial(), ch[i].m_nMatID)); - } - } - for (int i = 0; i < p->GetSubObjectCount(); ++i) - { - IStatObj::SSubObject* const pS = p->GetSubObject(i); - if (pS) - { - CollectMaterialsRecursively(mats, pS->pStatObj); - } - } - } -} - - -int CPreviewModelCtrl::GetFaceCount() -{ - if (m_pObj) - { - return PreviewModelControl::GetFaceCountRecursively(m_pObj); - } - return 0; -} - -int CPreviewModelCtrl::GetVertexCount() -{ - if (m_pObj) - { - return PreviewModelControl::GetVertexCountRecursively(m_pObj); - } - return 0; -} - -int CPreviewModelCtrl::GetMaxLod() -{ - if (m_pObj) - { - return PreviewModelControl::GetMaxLodRecursively(m_pObj); - } - return 0; -} - -int CPreviewModelCtrl::GetMtlCount() -{ - if (m_pObj) - { - std::set mats; - CollectMaterialsRecursively(mats, m_pObj); - return (int)mats.size(); - } - return 0; -} - -void CPreviewModelCtrl::FitToScreen() -{ - SetCameraLookAt(2.0f, Vec3(1, 1, -0.5)); -} - -void CPreviewModelCtrl::ProcessKeys() -{ - if (!hasFocus()) - { - return; - } - - int moveSpeed = 1; - - Matrix34 m = m_camera.GetMatrix(); - - Vec3 ydir = m.GetColumn2().GetNormalized(); - Vec3 xdir = m.GetColumn0().GetNormalized(); - - Vec3 pos = m.GetTranslation(); - - float speedScale = 60.0f * GetIEditor()->GetSystem()->GetITimer()->GetFrameTime(); - if (speedScale > 20) - { - speedScale = 20; - } - - speedScale *= 0.04f; - - if (CheckVirtualKey(Qt::Key_Shift)) - { - speedScale *= gSettings.cameraFastMoveSpeed; - } - - bool isDirty = false; - - if (CheckVirtualKey(Qt::Key_Up) || CheckVirtualKey(Qt::Key_W)) - { - // move forward - m_camera.SetPosition(pos + speedScale * moveSpeed * ydir); - SetCamera(m_camera); - isDirty = true; - } - - if (CheckVirtualKey(Qt::Key_Down) || CheckVirtualKey(Qt::Key_S)) - { - // move backward - m_camera.SetPosition(pos - speedScale * moveSpeed * ydir); - SetCamera(m_camera); - isDirty = true; - } - - if (isDirty) - { - if (!m_bUpdate) - { - // if we're not going to be autoupdating then we need to do a one-time invalidation here. - update(); - } - } -} - -void CPreviewModelCtrl::SetBackgroundTexture(const QString& textureFilename) -{ - m_backgroundTextureId = GetIEditor()->GetIconManager()->GetIconTexture(textureFilename.toUtf8().constData()); -} - -void CPreviewModelCtrl::DrawBackground() -{ - if (!m_backgroundTextureId) - { - return; - } - - int rcw = width(); - int rch = height(); - - TransformationMatrices backupSceneMatrices; - - m_pRenderer->Set2DMode(rcw, rch, backupSceneMatrices, 0.0f, 1.0f); - - m_pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - - float uvs[4], uvt[4]; - uvs[3] = 0; - uvt[3] = 1; - uvs[2] = 1; - uvt[2] = 1; - uvs[1] = 1; - uvt[1] = 0; - uvs[0] = 0; - uvt[0] = 0; - - float color[4] = {1, 1, 1, 1}; - - m_pRenderer->DrawImageWithUV(0, 0, 0.5f, rcw, rch, m_backgroundTextureId, uvs, uvt, color[0], color[1], color[2], color[3]); - m_pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA); - - m_pRenderer->Unset2DMode(backupSceneMatrices); -} - -_smart_ptr CPreviewModelCtrl::GetCurrentMaterial() -{ - if (m_pObj) - { - return m_pObj->GetMaterial(); - } - else if (m_pEntity) - { - return m_pEntity->GetMaterial(); - } - - return NULL; -} - -void CPreviewModelCtrl::StorePreviousContext() -{ - SPreviousContext previous; - previous.width = m_pRenderer->GetWidth(); - previous.height = m_pRenderer->GetHeight(); - previous.window = (HWND)m_pRenderer->GetCurrentContextHWND(); - previous.renderCamera = m_pRenderer->GetCamera(); - previous.systemCamera = gEnv->pSystem->GetViewCamera(); - previous.isMainViewport = m_pRenderer->IsCurrentContextMainVP(); - m_previousContexts.push_back(previous); -} - -// Copied from the non-crashing QViewport.cpp -void CPreviewModelCtrl::SetCurrentContext() -{ - StorePreviousContext(); - - m_pRenderer->SetCurrentContext(m_hWnd); - -#if defined(AZ_PLATFORM_WINDOWS) - // Needed for high DPI mode on windows - const qreal ratio = devicePixelRatioF(); -#else - const qreal ratio = 1.0f; -#endif - m_pRenderer->ChangeViewport(0, 0, width() * ratio, height() * ratio); - m_pRenderer->SetCamera(m_camera); - gEnv->pSystem->SetViewCamera(m_camera); -} - -void CPreviewModelCtrl::RestorePreviousContext() -{ - if (m_previousContexts.empty()) - { - assert(0); - return; - } - - SPreviousContext x = m_previousContexts.back(); - m_previousContexts.pop_back(); - m_pRenderer->SetCurrentContext(x.window); - m_pRenderer->ChangeViewport(0, 0, x.width, x.height, x.isMainViewport); - m_pRenderer->SetCamera(x.renderCamera); - gEnv->pSystem->SetViewCamera(x.systemCamera); -} - -void CPreviewModelCtrl::showEvent([[maybe_unused]] QShowEvent* event) -{ - m_hWnd = reinterpret_cast(effectiveWinId()); -} - -QSize CPreviewModelCtrl::minimumSizeHint() const -{ - return QSize(50, 50); -} - -QPaintEngine* CPreviewModelCtrl::paintEngine() const -{ - return nullptr; -} - -void CPreviewModelCtrl::paintEvent(QPaintEvent* event) -{ - event->accept(); - Render(); -} - -void CPreviewModelCtrl::mousePressEvent(QMouseEvent* event) -{ - switch (event->button()) - { - case Qt::LeftButton: - OnLButtonDown(event->pos()); - break; - case Qt::MiddleButton: - OnMButtonDown(event->pos()); - break; - case Qt::RightButton: - OnRButtonDown(event->pos()); - break; - } -} - -void CPreviewModelCtrl::mouseReleaseEvent(QMouseEvent* event) -{ - switch (event->button()) - { - case Qt::LeftButton: - OnLButtonUp(event->pos()); - break; - case Qt::MiddleButton: - OnMButtonUp(event->pos()); - break; - case Qt::RightButton: - OnRButtonUp(event->pos()); - break; - } -} - -#include diff --git a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.h b/Code/Sandbox/Editor/Controls/PreviewModelCtrl.h deleted file mode 100644 index 73839612af..0000000000 --- a/Code/Sandbox/Editor/Controls/PreviewModelCtrl.h +++ /dev/null @@ -1,204 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_CONTROLS_PREVIEWMODELCTRL_H -#define CRYINCLUDE_EDITOR_CONTROLS_PREVIEWMODELCTRL_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include -#include - -#include - -#include - -#endif - -struct IRenderNode; -class CImageEx; - -class CPreviewModelCtrl - : public QWidget - , public IEditorNotifyListener -{ - Q_OBJECT -public: - explicit CPreviewModelCtrl(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - - QSize minimumSizeHint() const override; - -public: - void LoadFile(const QString& modelFile, bool changeCamera = true); - Vec3 GetSize() const { return m_size; }; - QString GetLoadedFile() const { return m_loadedFile; } - - void SetEntity(IRenderNode* entity); - void SetObject(IStatObj* pObject); - IStatObj* GetObject() { return m_pObj; } - void SetCameraLookAt(float fRadiusScale, const Vec3& dir = Vec3(0, 1, 0)); - void SetCameraRadius(float fRadius); - CCamera& GetCamera(); - void SetGrid(bool bEnable) { m_bGrid = bEnable; } - void SetAxis(bool bEnable, bool forParticleEditor = false) { m_bAxis = bEnable; m_bAxisParticleEditor = forParticleEditor; } - void SetRotation(bool bEnable); - void SetClearColor(const ColorF& color); - void SetBackgroundTexture(const QString& textureFilename); - void UseBackLight(bool bEnable); - bool UseBackLight() const { return m_bUseBacklight; } - void SetShowNormals(bool bShow) { m_bShowNormals = bShow; } - void SetShowPhysics(bool bShow) { m_bShowPhysics = bShow; } - void SetShowRenderInfo(bool bShow) { m_bShowRenderInfo = bShow; } - - void EnableUpdate(bool bEnable); - bool IsUpdateEnabled() const { return m_bUpdate; } - void Update(bool bForceUpdate = false); - void ProcessKeys(); - - // this turns on and off aspect-ratio-maintaining. Use it when the widget is free to resize itself. - void SetAspectRatio(float newAspectRatio); - int heightForWidth(int w) const override; - bool hasHeightForWidth() const override; - - void SetMaterial(CMaterial* pMaterial); - CMaterial* GetMaterial(); - - void GetImageOffscreen(CImageEx& image, const QSize& customSize = QSize(0, 0)); - - void GetCameraTM(Matrix34& cameraTM); - void SetCameraTM(const Matrix34& cameraTM); - - // Place camera so that whole object fits on screen. - void FitToScreen(); - - // Get information about the preview model. - int GetFaceCount(); - int GetVertexCount(); - int GetMaxLod(); - int GetMtlCount(); - - void SetShowObject(bool bShowObject) {m_bShowObject = bShowObject; } - bool GetShowObject() {return m_bShowObject; } - - void SetAmbient(ColorF amb) { m_ambientColor = amb; } - void SetAmbientMultiplier(f32 multiplier) { m_ambientMultiplier = multiplier; } - - typedef void (* CameraChangeCallback)(void* m_userData, CPreviewModelCtrl* m_currentCamera); - void SetCameraChangeCallback(CameraChangeCallback callback, void* userData) { m_cameraChangeCallback = callback, m_pCameraChangeUserData = userData; } - - void EnableMaterialPrecaching(bool bPrecacheMaterial) { m_bPrecacheMaterial = bPrecacheMaterial; } - void EnableWireframeRendering(bool bDrawWireframe) { m_bDrawWireFrame = bDrawWireframe; } - -public: - ~CPreviewModelCtrl(); - - bool CreateContext(); - void ReleaseObject(); - void DeleteRenderContex(); - -protected: - void OnCreate(); - void OnDestroy(); - void OnLButtonDown(QPoint point); - void OnLButtonUp(QPoint point); - void OnMButtonDown(QPoint point); - void OnMButtonUp(QPoint point); - void OnRButtonUp(QPoint point); - void OnRButtonDown(QPoint point); - - QPaintEngine* paintEngine() const override; - void showEvent(QShowEvent* event) override; - void paintEvent(QPaintEvent* event) override; - void timerEvent(QTimerEvent* event) override; - void mouseMoveEvent(QMouseEvent* event) override; - void mousePressEvent(QMouseEvent* event) override; - void mouseReleaseEvent(QMouseEvent* event) override; - void wheelEvent(QWheelEvent* event) override; - - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event); - -protected: - virtual bool Render(); - virtual void SetCamera(CCamera& cam); - - virtual void RenderObject(_smart_ptr pMaterial, SRenderingPassInfo& passInfo); - - HWND m_hWnd; - CCamera m_camera; - float m_fov; - - struct SPreviousContext; - std::vector m_previousContexts; - - void SetOrbitAngles(const Ang3& ang); - void DrawGrid(); - void DrawBackground(); - _smart_ptr GetCurrentMaterial(); - - _smart_ptr m_pObj; - - IRenderer* m_pRenderer; - bool m_bContextCreated; - - Vec3 m_size; - Vec3 m_pos; - int m_nTimer; - bool m_useAspectRatio = false; - float m_aspectRatio = 1.0f; - - QString m_loadedFile; - std::vector m_lights; - - AABB m_aabb; - Vec3 m_cameraTarget; - float m_cameraRadius; - Vec3 m_cameraAngles; - bool m_bInRotateMode; - bool m_bInMoveMode; - bool m_bInPanMode; - QPoint m_mousePosition; - QPoint m_previousMousePosition; - IRenderNode* m_pEntity; - bool m_bHaveAnythingToRender; - bool m_bGrid; - bool m_bAxis; - bool m_bAxisParticleEditor; - bool m_bUpdate; - bool m_bRotate; - float m_rotateAngle; - ColorF m_clearColor; - ColorF m_ambientColor; - f32 m_ambientMultiplier; - bool m_bUseBacklight; - bool m_bShowObject; - bool m_bPrecacheMaterial; - bool m_bDrawWireFrame; - bool m_bShowNormals; - bool m_bShowPhysics; - bool m_bShowRenderInfo; - int m_backgroundTextureId; - float m_tileX; - float m_tileY; - float m_tileSizeX; - float m_tileSizeY; - _smart_ptr m_pCurrentMaterial; - CameraChangeCallback m_cameraChangeCallback; - void* m_pCameraChangeUserData; - -protected: - void StorePreviousContext(); - void SetCurrentContext(); - void RestorePreviousContext(); -}; -#endif // CRYINCLUDE_EDITOR_CONTROLS_PREVIEWMODELCTRL_H diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp index b777bb6930..f0367ffdc1 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp @@ -29,14 +29,12 @@ void RegisterReflectedVarHandlers() EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew AnimationPropertyWidgetHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew FileResourceSelectorWidgetHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ShaderPropertyHandler()); - EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew MaterialPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ReverbPresetPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew SequencePropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew SequenceIdPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew LocalStringPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew LightAnimationPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew UserPopupWidgetHandler()); - EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew LensFlareHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ColorCurveHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew FloatCurveHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew MotionPropertyWidgetHandler()); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp index 3d17e77bb0..75344b2172 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp @@ -27,7 +27,6 @@ // Editor #include "ShadersDialog.h" -#include "Material/MaterialManager.h" #include "SelectLightAnimationDialog.h" #include "SelectSequenceDialog.h" #include "SelectEAXPresetDlg.h" @@ -88,25 +87,6 @@ void ShaderPropertyEditor::onEditClicked() } } -void MaterialPropertyEditor::onEditClicked() -{ -} - -void MaterialPropertyEditor::onButton2Clicked() -{ - // Open material browser dialog. - IDataBaseItem *pItem = GetIEditor()->GetMaterialManager()->GetSelectedItem(); - if (pItem) - { - QString value = pItem->GetName(); - value.replace('\\', '/'); - if (value.length() >= MAX_PATH) - value = value.left(MAX_PATH); - SetValue(value); - } - else - SetValue(QString()); -} void ReverbPresetPropertyEditor::onEditClicked() { diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h index d5ec0045c4..cdbb18ae12 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h @@ -109,16 +109,6 @@ public: void onEditClicked() override; }; -class MaterialPropertyEditor - : public GenericPopupPropertyEditor -{ -public: - MaterialPropertyEditor(QWidget* pParent = nullptr) - : GenericPopupPropertyEditor(pParent, true){} - void onEditClicked() override; - void onButton2Clicked() override; -}; - class ReverbPresetPropertyEditor : public GenericPopupPropertyEditor { @@ -179,7 +169,6 @@ public: #define CONST_AZ_CRC(name, value) AZ::u32(value) using ShaderPropertyHandler = GenericPopupWidgetHandler; -using MaterialPropertyHandler = GenericPopupWidgetHandler; using ReverbPresetPropertyHandler = GenericPopupWidgetHandler; using MissionObjPropertyHandler = GenericPopupWidgetHandler; using SequencePropertyHandler = GenericPopupWidgetHandler; diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp index bce244e06b..89bb66b08a 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp @@ -25,7 +25,6 @@ // Editor #include "GenericSelectItemDialog.h" #include "QtViewPaneManager.h" -#include "LensFlareEditor/LensFlareEditor.h" UserPropertyEditor::UserPropertyEditor(QWidget *pParent /*= nullptr*/) @@ -147,79 +146,6 @@ bool UserPopupWidgetHandler::ReadValuesIntoGUI(size_t index, UserPropertyEditor* #include -LensFlarePropertyWidget::LensFlarePropertyWidget(QWidget *pParent /*= nullptr*/) - :QWidget(pParent) -{ - m_valueEdit = new QLineEdit; - - QToolButton *mainButton = new QToolButton; - mainButton->setText("D"); - connect(mainButton, &QToolButton::clicked, this, &LensFlarePropertyWidget::OnEditClicked); - connect(m_valueEdit, &QLineEdit::editingFinished, m_valueEdit, [this] () {emit ValueChanged(m_valueEdit->text());}); - - QHBoxLayout *mainLayout = new QHBoxLayout(this); - mainLayout->addWidget(m_valueEdit, 1); - mainLayout->addWidget(mainButton); - mainLayout->setContentsMargins(1, 1, 1, 1); -} - -void LensFlarePropertyWidget::SetValue(const QString &value) -{ - m_valueEdit->setText(value); -} - -QString LensFlarePropertyWidget::GetValue() const -{ - return m_valueEdit->text(); -} - -void LensFlarePropertyWidget::OnEditClicked() -{ - const QtViewPane *lensFlarePane = GetIEditor()->OpenView(CLensFlareEditor::s_pLensFlareEditorClassName); - if (!lensFlarePane) - return; - - CLensFlareEditor *editor = FindViewPane(QtUtil::ToQString(CLensFlareEditor::s_pLensFlareEditorClassName)); - if (editor) - QTimer::singleShot(0, editor, SLOT(OnUpdateTreeCtrl())); -} - -QWidget* LensFlareHandler::CreateGUI(QWidget *pParent) -{ - LensFlarePropertyWidget* newCtrl = aznew LensFlarePropertyWidget(pParent); - connect(newCtrl, &LensFlarePropertyWidget::ValueChanged, newCtrl, [newCtrl]() - { - EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl); - }); - - return newCtrl; -} - -void LensFlareHandler::ConsumeAttribute(LensFlarePropertyWidget* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) -{ - Q_UNUSED(GUI); Q_UNUSED(attrib); Q_UNUSED(attrValue); Q_UNUSED(debugName); -} - -void LensFlareHandler::WriteGUIValuesIntoProperty(size_t index, LensFlarePropertyWidget* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) -{ - Q_UNUSED(index); - Q_UNUSED(node); - CReflectedVarGenericProperty val = instance; - val.m_value = GUI->GetValue().toUtf8().data(); - instance = static_cast(val); -} - -bool LensFlareHandler::ReadValuesIntoGUI(size_t index, LensFlarePropertyWidget* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) -{ - Q_UNUSED(index); - Q_UNUSED(node); - CReflectedVarGenericProperty val = instance; - GUI->SetValue(val.m_value.c_str()); - return false; -} - - - QWidget* FloatCurveHandler::CreateGUI(QWidget *pParent) { CSplineCtrl *cSpline = new CSplineCtrl(pParent); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h index 00fb8e5f98..7ddbf6a338 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h @@ -70,39 +70,6 @@ public: }; - -class LensFlarePropertyWidget : public QWidget -{ - Q_OBJECT -public: - AZ_CLASS_ALLOCATOR(LensFlarePropertyWidget, AZ::SystemAllocator, 0); - LensFlarePropertyWidget(QWidget *pParent = nullptr); - - void SetValue(const QString &value); - QString GetValue() const; - - void OnEditClicked(); - -signals: - void ValueChanged(const QString &value); - -private: - QLineEdit *m_valueEdit; -}; - -class LensFlareHandler : public QObject, public AzToolsFramework::PropertyHandler < CReflectedVarGenericProperty, LensFlarePropertyWidget> -{ -public: - AZ_CLASS_ALLOCATOR(LensFlareHandler, AZ::SystemAllocator, 0); - bool IsDefaultHandler() const override { return false; } - QWidget* CreateGUI(QWidget *pParent) override; - - AZ::u32 GetHandlerName(void) const override { return AZ_CRC("ePropertyFlare", 0x5ce803df); } - void ConsumeAttribute(LensFlarePropertyWidget* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override; - void WriteGUIValuesIntoProperty(size_t index, LensFlarePropertyWidget* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override; - bool ReadValuesIntoGUI(size_t index, LensFlarePropertyWidget* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override; -}; - class FloatCurveHandler : public QObject, public AzToolsFramework::PropertyHandler < CReflectedVarSpline, CSplineCtrl> { public: diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp index a66a73eaa4..e698b86341 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyResourceCtrl.cpp @@ -111,14 +111,12 @@ private: { case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: newPath.replace("\\\\", "/"); } switch (m_propertyType) { case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: case ePropertyFile: if (newPath.size() > MAX_PATH) { diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp index 92610021b9..a188ee117b 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp @@ -361,16 +361,6 @@ void ReflectedPropertyControl::CreateItems(XmlNodeRef node, CVarBlockPtr& outBlo textureVar->Set(textureName); } } - else if (!azstricmp(type, "material")) - { - CSmartVariable materialVar; - AddVariable(group, materialVar, child->getTag(), humanReadableName.toUtf8().data(), strDescription.toUtf8().data(), func, pUserData, IVariable::DT_MATERIAL); - const char* materialName; - if (child->getAttr("value", &materialName)) - { - materialVar->Set(materialName); - } - } else if (!azstricmp(type, "color")) { CSmartVariable colorVar; diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp index b759b46ceb..13584d9b82 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp @@ -269,7 +269,6 @@ void ReflectedPropertyItem::SetVariable(IVariable *var) m_reflectedVarAdapter = new ReflectedVarUserAdapter; break; case ePropertyShader: - case ePropertyMaterial: case ePropertyEquip: case ePropertyReverbPreset: case ePropertyGameToken: @@ -279,7 +278,6 @@ void ReflectedPropertyItem::SetVariable(IVariable *var) case ePropertyLocalString: case ePropertyLightAnimation: case ePropertyParticleName: - case ePropertyFlare: m_reflectedVarAdapter = new ReflectedVarGenericPropertyAdapter(desc.m_type); break; case ePropertyTexture: @@ -577,7 +575,6 @@ void ReflectedPropertyItem::SetValue(const QString& sValue, bool bRecordUndo, bo case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: value.replace('\\', '/'); break; } @@ -587,7 +584,6 @@ void ReflectedPropertyItem::SetValue(const QString& sValue, bool bRecordUndo, bo { case ePropertyTexture: case ePropertyModel: - case ePropertyMaterial: case ePropertyFile: if (value.length() >= MAX_PATH) { diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp index e0f7f29524..12165d2be8 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp @@ -286,8 +286,6 @@ AZ::u32 CReflectedVarGenericProperty::handler() { case ePropertyShader: return AZ_CRC("ePropertyShader", 0xc40932f1); - case ePropertyMaterial: - return AZ_CRC("ePropertyMaterial", 0xf324dffa); case ePropertyEquip: return AZ_CRC("ePropertyEquip", 0x66ffd290); case ePropertyReverbPreset: @@ -308,8 +306,6 @@ AZ::u32 CReflectedVarGenericProperty::handler() return AZ_CRC("ePropertyLightAnimation", 0x277097da); case ePropertyParticleName: return AZ_CRC("ePropertyParticleName", 0xf44c7133); - case ePropertyFlare: - return AZ_CRC("ePropertyFlare", 0x5ce803df); default: AZ_Assert(false, "No property handlers defined for the property type"); return AZ_CRC("Default", 0xe35e00df); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp index 84a7f8c26f..b2fc07073f 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp @@ -455,8 +455,6 @@ void ReflectedVarGenericPropertyAdapter::SyncReflectedVarToIVar(IVariable *pVari { QString value; pVariable->Get(value); - if (m_reflectedVar->m_propertyType == ePropertyMaterial) - value.replace('\\', '/'); m_reflectedVar->m_value = value.toUtf8().data(); } diff --git a/Code/Sandbox/Editor/Controls/TimeOfDaySlider.cpp b/Code/Sandbox/Editor/Controls/TimeOfDaySlider.cpp deleted file mode 100644 index 9b2b62d6f5..0000000000 --- a/Code/Sandbox/Editor/Controls/TimeOfDaySlider.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : implementation file - - -#include "EditorDefs.h" - -#include "TimeOfDaySlider.h" - -QString TimeOfDaySlider::hoverValueText(int sliderValue) const -{ - return QString::fromLatin1("%1:%2").arg(static_cast(sliderValue / 60)).arg(sliderValue % 60, 2, 10, QLatin1Char('0')); -} - -#include diff --git a/Code/Sandbox/Editor/Core/LevelEditorMenuHandler.cpp b/Code/Sandbox/Editor/Core/LevelEditorMenuHandler.cpp index 3f396894ff..869fa2fe25 100644 --- a/Code/Sandbox/Editor/Core/LevelEditorMenuHandler.cpp +++ b/Code/Sandbox/Editor/Core/LevelEditorMenuHandler.cpp @@ -23,7 +23,6 @@ #include "Objects/SelectionGroup.h" #include "ViewManager.h" -#include #include // Qt diff --git a/Code/Sandbox/Editor/CryEdit.cpp b/Code/Sandbox/Editor/CryEdit.cpp index e118104687..b88aee8bd9 100644 --- a/Code/Sandbox/Editor/CryEdit.cpp +++ b/Code/Sandbox/Editor/CryEdit.cpp @@ -78,7 +78,6 @@ AZ_POP_DISABLE_WARNING #include // CryCommon -#include #include #include #include @@ -99,10 +98,8 @@ AZ_POP_DISABLE_WARNING #include "GridSettingsDialog.h" #include "LayoutConfigDialog.h" #include "ViewManager.h" -#include "ModelViewport.h" #include "FileTypeUtils.h" #include "PluginManager.h" -#include "Material/MaterialManager.h" #include "IEditorImpl.h" #include "StartupLogoDialog.h" @@ -110,14 +107,12 @@ AZ_POP_DISABLE_WARNING #include "GameEngine.h" #include "StartupTraceHandler.h" -#include "ThumbnailGenerator.h" #include "ToolsConfigPage.h" #include "Objects/SelectionGroup.h" #include "Include/IObjectManager.h" #include "WaitProgress.h" #include "ToolBox.h" -#include "Geometry/EdMesh.h" #include "LevelInfo.h" #include "EditorPreferencesDialog.h" #include "GraphicsSettingsDialog.h" @@ -157,9 +152,6 @@ AZ_POP_DISABLE_WARNING #include "Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h" -// LmbrCentral -#include - // AWSNativeSDK #include #include @@ -396,7 +388,6 @@ void CCryEditApp::RegisterActionHandlers() ON_COMMAND(ID_FILE_RESAVESLICES, OnFileResaveSlices) ON_COMMAND(ID_FILE_EDITEDITORINI, OnFileEditEditorini) ON_COMMAND(ID_PREFERENCES, OnPreferences) - ON_COMMAND(ID_RELOAD_GEOMETRY, OnReloadGeometry) ON_COMMAND(ID_REDO, OnRedo) ON_COMMAND(ID_TOOLBAR_WIDGET_REDO, OnRedo) ON_COMMAND(ID_RELOAD_TEXTURES, OnReloadTextures) @@ -405,7 +396,6 @@ void CCryEditApp::RegisterActionHandlers() ON_COMMAND(ID_FILE_NEW_SLICE, OnCreateSlice) ON_COMMAND(ID_FILE_OPEN_SLICE, OnOpenSlice) #endif - ON_COMMAND(ID_RESOURCES_GENERATECGFTHUMBNAILS, OnGenerateCgfThumbnails) ON_COMMAND(ID_SWITCH_PHYSICS, OnSwitchPhysics) ON_COMMAND(ID_GAME_SYNCPLAYER, OnSyncPlayer) ON_COMMAND(ID_RESOURCES_REDUCEWORKINGSET, OnResourcesReduceworkingset) @@ -455,17 +445,12 @@ void CCryEditApp::RegisterActionHandlers() #endif ON_COMMAND(ID_DISPLAY_GOTOPOSITION, OnDisplayGotoPosition) ON_COMMAND(ID_SNAPANGLE, OnSnapangle) - ON_COMMAND(ID_EDIT_RENAMEOBJECT, OnEditRenameobject) ON_COMMAND(ID_CHANGEMOVESPEED_INCREASE, OnChangemovespeedIncrease) ON_COMMAND(ID_CHANGEMOVESPEED_DECREASE, OnChangemovespeedDecrease) ON_COMMAND(ID_CHANGEMOVESPEED_CHANGESTEP, OnChangemovespeedChangestep) - ON_COMMAND(ID_MATERIAL_ASSIGNCURRENT, OnMaterialAssigncurrent) - ON_COMMAND(ID_MATERIAL_RESETTODEFAULT, OnMaterialResettodefault) - ON_COMMAND(ID_MATERIAL_GETMATERIAL, OnMaterialGetmaterial) ON_COMMAND(ID_FILE_SAVELEVELRESOURCES, OnFileSavelevelresources) ON_COMMAND(ID_CLEAR_REGISTRY, OnClearRegistryData) ON_COMMAND(ID_VALIDATELEVEL, OnValidatelevel) - ON_COMMAND(ID_TOOLS_VALIDATEOBJECTPOSITIONS, OnValidateObjectPositions) ON_COMMAND(ID_TOOLS_PREFERENCES, OnToolsPreferences) ON_COMMAND(ID_GRAPHICS_SETTINGS, OnGraphicsSettings) ON_COMMAND(ID_SWITCHCAMERA_DEFAULTCAMERA, OnSwitchToDefaultCamera) @@ -479,8 +464,6 @@ void CCryEditApp::RegisterActionHandlers() ON_COMMAND(ID_DISPLAY_SHOWHELPERS, OnShowHelpers) ON_COMMAND(ID_OPEN_TRACKVIEW, OnOpenTrackView) ON_COMMAND(ID_OPEN_UICANVASEDITOR, OnOpenUICanvasEditor) - ON_COMMAND(ID_TERRAIN_TIMEOFDAY, OnTimeOfDay) - ON_COMMAND(ID_TERRAIN_TIMEOFDAYBUTTON, OnTimeOfDay) ON_COMMAND_RANGE(ID_GAME_PC_ENABLELOWSPEC, ID_GAME_PC_ENABLEVERYHIGHSPEC, OnChangeGameSpec) @@ -1920,11 +1903,6 @@ void CCryEditApp::LoadFile(QString fileName) { return; } - CViewport* vp = GetIEditor()->GetViewManager()->GetView(0); - if (CModelViewport* mvp = viewport_cast(vp)) - { - mvp->LoadObject(fileName, 1); - } LoadTagLocations(); @@ -2960,43 +2938,6 @@ void CCryEditApp::OnReloadTextures() GetIEditor()->GetRenderer()->EF_ReloadTextures(); } -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnReloadGeometry() -{ - CErrorsRecorder errRecorder(GetIEditor()); - CWaitProgress wait("Reloading static geometry"); - - CLogFile::WriteLine("Reloading Static objects geometries."); - CEdMesh::ReloadAllGeometries(); - - GetIEditor()->GetObjectManager()->SendEvent(EVENT_UNLOAD_GEOM); - - GetIEditor()->GetObjectManager()->SendEvent(EVENT_RELOAD_GEOM); - GetIEditor()->Notify(eNotify_OnReloadTrackView); - - // Rephysicalize viewport meshes - for (int i = 0; i < GetIEditor()->GetViewManager()->GetViewCount(); ++i) - { - CViewport* vp = GetIEditor()->GetViewManager()->GetView(i); - if (CModelViewport* mvp = viewport_cast(vp)) - { - mvp->RePhysicalize(); - } - } - - IRenderNode** plist = new IRenderNode*[ - gEnv->p3DEngine->GetObjectsByType(eERType_StaticMeshRenderComponent,0) - ]; - for (const EERType type : AZStd::array{eERType_Dummy_10, eERType_StaticMeshRenderComponent}) - { - for (int j = gEnv->p3DEngine->GetObjectsByType(type, plist) - 1; j >= 0; j--) - { - plist[j]->Physicalize(true); - } - } - delete[] plist; -} - ////////////////////////////////////////////////////////////////////////// void CCryEditApp::OnUndo() { @@ -3161,15 +3102,6 @@ void CCryEditApp::OnSyncPlayerUpdate(QAction* action) action->setChecked(!GetIEditor()->GetGameEngine()->IsSyncPlayerPosition()); } -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnGenerateCgfThumbnails() -{ - qApp->setOverrideCursor(Qt::BusyCursor); - CThumbnailGenerator gen; - gen.GenerateForDirectory("Objects\\"); - qApp->restoreOverrideCursor(); -} - void CCryEditApp::OnUpdateNonGameMode(QAction* action) { action->setEnabled(!GetIEditor()->IsInGameMode()); @@ -3268,10 +3200,9 @@ CCryEditApp::ECreateLevelResult CCryEditApp::CreateLevel(const QString& levelNam m_bIsExportingLegacyData = false; } - GetIEditor()->GetGameEngine()->LoadLevel(GetIEditor()->GetGameEngine()->GetMissionName(), true, true); + GetIEditor()->GetGameEngine()->LoadLevel(true, true); GetIEditor()->GetSystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_PRECACHE_START, 0, 0); - GetIEditor()->GetGameEngine()->ReloadEnvironment(); GetIEditor()->GetSystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_PRECACHE_END, 0, 0); } @@ -3831,59 +3762,6 @@ void CCryEditApp::OnUpdateSnapangle(QAction* action) action->setChecked(gSettings.pGrid->IsAngleSnapEnabled()); } -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnEditRenameobject() -{ - CSelectionGroup* pSelection = GetIEditor()->GetSelection(); - if (pSelection->IsEmpty()) - { - QMessageBox::critical(AzToolsFramework::GetActiveWindow(), QString(), QObject::tr("No Selected Objects!")); - return; - } - - IObjectManager* pObjMan = GetIEditor()->GetObjectManager(); - - if (!pObjMan) - { - return; - } - - StringDlg dlg(QObject::tr("Rename Object(s)")); - if (dlg.exec() == QDialog::Accepted) - { - CUndo undo("Rename Objects"); - QString newName; - QString str = dlg.GetString(); - int num = 0; - - for (int i = 0; i < pSelection->GetCount(); ++i) - { - CBaseObject* pObject = pSelection->GetObject(i); - - if (pObject) - { - if (pObjMan->IsDuplicateObjectName(str)) - { - pObjMan->ShowDuplicationMsgWarning(pObject, str, true); - return; - } - } - } - - for (int i = 0; i < pSelection->GetCount(); ++i) - { - newName = QStringLiteral("%1%2").arg(str).arg(num); - ++num; - CBaseObject* pObject = pSelection->GetObject(i); - - if (pObject) - { - pObjMan->ChangeObjectName(pObject, newName); - } - } - } -} - ////////////////////////////////////////////////////////////////////////// void CCryEditApp::OnChangemovespeedIncrease() { @@ -3943,119 +3821,6 @@ void CCryEditApp::OnValidatelevel() levelInfo.Validate(); } -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnValidateObjectPositions() -{ - IObjectManager* objMan = GetIEditor()->GetObjectManager(); - - if (!objMan) - { - return; - } - - CErrorReport errorReport; - errorReport.SetCurrentFile(""); - errorReport.SetImmediateMode(false); - - int objCount = objMan->GetObjectCount(); - AABB bbox1; - AABB bbox2; - int bugNo = 0; - QString statTxt(""); - - std::vector objects; - objMan->GetObjects(objects); - - std::vector foundObjects; - - std::vector objIDs; - - for (int i1 = 0; i1 < objCount; ++i1) - { - CBaseObject* pObj1 = objects[i1]; - - if (!pObj1) - { - continue; - } - - // Object must have geometry - if (!pObj1->GetGeometry()) - { - continue; - } - - pObj1->GetBoundBox(bbox1); - - // Check if object has other objects inside its bbox - foundObjects.clear(); - objMan->FindObjectsInAABB(bbox1, foundObjects); - - for (int i2 = 0; i2 < foundObjects.size(); ++i2) - { - CBaseObject* pObj2 = objects[i2]; - if (!pObj2) - { - continue; - } - - if (pObj2->GetId() == pObj1->GetId()) - { - continue; - } - - if (pObj2->GetParent()) - { - continue; - } - - if (stl::find(objIDs, pObj2->GetId())) - { - continue; - } - - if (!pObj2->GetGeometry()) - { - continue; - } - - pObj2->GetBoundBox(bbox2); - - if (!bbox1.IsContainPoint(bbox2.max)) - { - continue; - } - - if (!bbox1.IsContainPoint(bbox2.min)) - { - continue; - } - - objIDs.push_back(pObj2->GetId()); - - CErrorRecord error; - error.pObject = pObj2; - error.count = bugNo; - error.error = tr("%1 inside %2 object").arg(pObj2->GetName(), pObj1->GetName()); - error.description = "Object left inside other object"; - errorReport.ReportError(error); - ++bugNo; - } - - statTxt = tr("%1/%2 [Reported Objects: %3]").arg(i1).arg(objCount).arg(bugNo); - GetIEditor()->SetStatusText(statTxt); - } - - if (errorReport.GetErrorCount() == 0) - { - QMessageBox::critical(AzToolsFramework::GetActiveWindow(), QString(), QObject::tr("No Errors Found")); - } - else - { - errorReport.Display(); - } -} - ////////////////////////////////////////////////////////////////////////// void CCryEditApp::OnToolsPreferences() { @@ -4180,25 +3945,6 @@ void CCryEditApp::OnSwitchcameraNext() } } -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnMaterialAssigncurrent() -{ - CUndo undo("Assign Material To Selection"); - GetIEditor()->GetMaterialManager()->Command_AssignToSelection(); -} - -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnMaterialResettodefault() -{ - GetIEditor()->GetMaterialManager()->Command_ResetSelection(); -} - -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnMaterialGetmaterial() -{ - GetIEditor()->GetMaterialManager()->Command_SelectFromObject(); -} - ////////////////////////////////////////////////////////////////////////// void CCryEditApp::OnOpenAssetBrowserView() { @@ -4223,12 +3969,6 @@ void CCryEditApp::OnOpenUICanvasEditor() QtViewPaneManager::instance()->OpenPane(LyViewPane::UiEditor); } -////////////////////////////////////////////////////////////////////////// -void CCryEditApp::OnTimeOfDay() -{ - GetIEditor()->OpenView("Time Of Day"); -} - ////////////////////////////////////////////////////////////////////////// void CCryEditApp::SetGameSpecCheck(ESystemConfigSpec spec, ESystemConfigPlatform platform, int &nCheck, bool &enable) { diff --git a/Code/Sandbox/Editor/CryEdit.h b/Code/Sandbox/Editor/CryEdit.h index 8c0c4bd59b..c0b26a9405 100644 --- a/Code/Sandbox/Editor/CryEdit.h +++ b/Code/Sandbox/Editor/CryEdit.h @@ -230,11 +230,9 @@ public: void OnFileEditEditorini(); void OnPreferences(); void OnReloadTextures(); - void OnReloadGeometry(); void OnRedo(); void OnUpdateRedo(QAction* action); void OnUpdateUndo(QAction* action); - void OnGenerateCgfThumbnails(); void OnSwitchPhysics(); void OnSwitchPhysicsUpdate(QAction* action); void OnSyncPlayer(); @@ -413,17 +411,12 @@ private: void OnDisplayGotoPosition(); void OnSnapangle(); void OnUpdateSnapangle(QAction* action); - void OnEditRenameobject(); void OnChangemovespeedIncrease(); void OnChangemovespeedDecrease(); void OnChangemovespeedChangestep(); - void OnMaterialAssigncurrent(); - void OnMaterialResettodefault(); - void OnMaterialGetmaterial(); void OnFileSavelevelresources(); void OnClearRegistryData(); void OnValidatelevel(); - void OnValidateObjectPositions(); void OnToolsPreferences(); void OnGraphicsSettings(); void OnSwitchToDefaultCamera(); @@ -438,7 +431,6 @@ private: void OnOpenTrackView(); void OnOpenAudioControlsEditor(); void OnOpenUICanvasEditor(); - void OnTimeOfDay(); void OnChangeGameSpec(UINT nID); void SetGameSpecCheck(ESystemConfigSpec spec, ESystemConfigPlatform platform, int &nCheck, bool &enable); void OnUpdateGameSpec(QAction* action); diff --git a/Code/Sandbox/Editor/CryEditDoc.cpp b/Code/Sandbox/Editor/CryEditDoc.cpp index 8819c8b382..ffcbd00a5f 100644 --- a/Code/Sandbox/Editor/CryEditDoc.cpp +++ b/Code/Sandbox/Editor/CryEditDoc.cpp @@ -27,7 +27,6 @@ // AzFramework #include #include -#include // AzToolsFramework #include @@ -43,7 +42,6 @@ #include "Settings.h" #include "PluginManager.h" -#include "Mission.h" #include "ViewManager.h" #include "DisplaySettings.h" #include "GameEngine.h" @@ -51,8 +49,6 @@ #include "CryEdit.h" #include "ActionManager.h" #include "Include/IObjectManager.h" -#include "Material/MaterialManager.h" -#include "LensFlareEditor/LensFlareManager.h" #include "ErrorReportDialog.h" #include "SurfaceTypeValidator.h" #include "ShaderCache.h" @@ -60,11 +56,13 @@ #include "CheckOutDialog.h" #include "GameExporter.h" #include "MainWindow.h" -#include "ITimeOfDay.h" #include "LevelFileDialog.h" #include "StatObjBus.h" // LmbrCentral +#include +#include +#include #include // for LmbrCentral::EditorLightComponentRequestBus @@ -123,7 +121,6 @@ CCryEditDoc::CCryEditDoc() // The right way would require us to save to the level folder the export status of the // level. , m_boLevelExported(true) - , m_mission(NULL) , m_modified(false) , m_envProbeHeight(200.0f) , m_envProbeSliceRelativePath("EngineAssets/Slices/DefaultLevelSetup.slice") @@ -158,7 +155,6 @@ CCryEditDoc::CCryEditDoc() CCryEditDoc::~CCryEditDoc() { GetIEditor()->SetDocument(nullptr); - ClearMissions(); delete m_pLevelShaderCache; @@ -255,17 +251,6 @@ bool CCryEditDoc::Save() return OnSaveDocument(GetActivePathName()); } -void CCryEditDoc::ChangeMission() -{ - GetIEditor()->Notify(eNotify_OnMissionChange); - - // Notify listeners. - for (std::list::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) - { - (*it)->OnMissionChange(); - } -} - void CCryEditDoc::DeleteContents() { m_hasErrors = false; @@ -295,10 +280,6 @@ void CCryEditDoc::DeleteContents() // Delete all objects from Object Manager. GetIEditor()->GetObjectManager()->DeleteAllObjects(); - ClearMissions(); - - GetIEditor()->GetGameEngine()->ResetResources(); - // Load scripts data SetModifiedFlag(FALSE); SetModifiedModules(eModifiedNothing); @@ -341,7 +322,6 @@ void CCryEditDoc::Save(TDocMultiArchive& arrXmlAr) if (!isPrefabEnabled) { CAutoDocNotReady autoDocNotReady; - QString currentMissionName; if (arrXmlAr[DMAS_GENERAL] != NULL) { @@ -356,12 +336,6 @@ void CCryEditDoc::Save(TDocMultiArchive& arrXmlAr) // Fog settings /////////////////////////////////////////////////////// SerializeFogSettings((*arrXmlAr[DMAS_GENERAL])); - // Serialize Missions ////////////////////////////////////////////////// - SerializeMissions(arrXmlAr, currentMissionName, false); - //! Serialize material manager. - GetIEditor()->GetMaterialManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); - //! Serialize LensFlare manager. - GetIEditor()->GetLensFlareManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); SerializeShaderCache((*arrXmlAr[DMAS_GENERAL_NAMED_DATA])); SerializeNameSelection((*arrXmlAr[DMAS_GENERAL])); @@ -408,7 +382,6 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename) HEAP_CHECK CLogFile::FormatLine("Loading from %s...", szFilename.toUtf8().data()); - QString currentMissionName; QString szLevelPath = Path::GetPath(szFilename); { @@ -486,27 +459,9 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename) Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); } - HEAP_CHECK - - if (!isPrefabEnabled) - { - // multiple missions are no longer supported, only load the current mission (last used) - SerializeMissions(arrXmlAr, currentMissionName, false); - } - - HEAP_CHECK - - if (GetIEditor()->Get3DEngine()) - { - if (!isPrefabEnabled) - { - GetIEditor()->Get3DEngine()->LoadCompiledOctreeForEditor(); - } - } - { CAutoLogTime logtime("Game Engine level load"); - GetIEditor()->GetGameEngine()->LoadLevel(currentMissionName, true, true); + GetIEditor()->GetGameEngine()->LoadLevel(true, true); } if (!isPrefabEnabled) @@ -516,22 +471,6 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename) ////////////////////////////////////////////////////////////////////////// (*arrXmlAr[DMAS_GENERAL]).root->getAttr("WaterColor", m_waterColor); - ////////////////////////////////////////////////////////////////////////// - // Load materials. - ////////////////////////////////////////////////////////////////////////// - { - CAutoLogTime logtime("Load MaterialManager"); - GetIEditor()->GetMaterialManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); - } - - ////////////////////////////////////////////////////////////////////////// - // Load LensFlares. - ////////////////////////////////////////////////////////////////////////// - { - CAutoLogTime logtime("Load Flares"); - GetIEditor()->GetLensFlareManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); - } - ////////////////////////////////////////////////////////////////////////// // Load View Settings ////////////////////////////////////////////////////////////////////////// @@ -543,27 +482,6 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename) SerializeFogSettings((*arrXmlAr[DMAS_GENERAL])); } - { - QByteArray str; - str = tr("Activating Mission %1").arg(currentMissionName).toUtf8(); - - CAutoLogTime logtime(str.data()); - - // Select current mission. - m_mission = FindMission(currentMissionName); - - if (m_mission) - { - SyncCurrentMissionContent(true); - } - else - { - GetCurrentMission(); - } - } - - ForceSkyUpdate(); - if (!isPrefabEnabled) { // Serialize Shader Cache. @@ -669,6 +587,7 @@ void CCryEditDoc::SerializeViewSettings(CXmlArchive& xmlAr) CViewport* pVP = GetIEditor()->GetViewManager()->GetView(i); + if (pVP) { Matrix34 tm = Matrix34::CreateRotationXYZ(va); @@ -749,94 +668,6 @@ void CCryEditDoc::SerializeFogSettings(CXmlArchive& xmlAr) } } -void CCryEditDoc::SerializeMissions(TDocMultiArchive& arrXmlAr, QString& currentMissionName, bool bPartsInXml) -{ - bool bLoading = IsLoadingXmlArArray(arrXmlAr); - - if (bLoading) - { - // Loading - CLogFile::WriteLine("Loading missions..."); - // Clear old layers - ClearMissions(); - // Load shared objects and layers. - XmlNodeRef objectsNode = arrXmlAr[DMAS_GENERAL]->root->findChild("Objects"); - XmlNodeRef objectLayersNode = arrXmlAr[DMAS_GENERAL]->root->findChild("ObjectLayers"); - // Load the layer count - XmlNodeRef node = arrXmlAr[DMAS_GENERAL]->root->findChild("Missions"); - - if (!node) - { - return; - } - - QString current; - node->getAttr("Current", current); - currentMissionName = current; - - // Read all node - for (int i = 0; i < node->getChildCount(); i++) - { - CXmlArchive ar(*arrXmlAr[DMAS_GENERAL]); - ar.root = node->getChild(i); - CMission* mission = new CMission(this); - mission->Serialize(ar); - if (bPartsInXml) - { - mission->SerializeTimeOfDay(*arrXmlAr[DMAS_TIME_OF_DAY]); - mission->SerializeEnvironment(*arrXmlAr[DMAS_ENVIRONMENT]); - } - else - { - mission->LoadParts(); - } - - // Timur[9/11/2002] For backward compatibility with shared objects - if (objectsNode) - { - mission->AddObjectsNode(objectsNode); - } - if (objectLayersNode) - { - mission->SetLayersNode(objectLayersNode); - } - - AddMission(mission); - } - } - else - { - // Storing - CLogFile::WriteLine("Storing missions..."); - // Save contents of current mission. - SyncCurrentMissionContent(false); - - XmlNodeRef node = arrXmlAr[DMAS_GENERAL]->root->newChild("Missions"); - - //! Store current mission name. - currentMissionName = GetCurrentMission()->GetName(); - node->setAttr("Current", currentMissionName.toUtf8().data()); - - // Write all surface types. - for (int i = 0; i < m_missions.size(); i++) - { - CXmlArchive ar(*arrXmlAr[DMAS_GENERAL]); - ar.root = node->newChild("Mission"); - m_missions[i]->Serialize(ar, false); - if (bPartsInXml) - { - m_missions[i]->SerializeTimeOfDay(*arrXmlAr[DMAS_TIME_OF_DAY]); - m_missions[i]->SerializeEnvironment(*arrXmlAr[DMAS_ENVIRONMENT]); - } - else - { - m_missions[i]->SaveParts(); - } - } - CLogFile::WriteString("Done"); - } -} - void CCryEditDoc::SerializeShaderCache(CXmlArchive& xmlAr) { if (xmlAr.bLoading) @@ -2108,58 +1939,6 @@ void CCryEditDoc::SaveAutoBackup(bool bForce) isInProgress = false; } - -CMission* CCryEditDoc::GetCurrentMission(bool bSkipLoadingAIWhenSyncingContent /* = false */) -{ - if (m_mission) - { - return m_mission; - } - - if (!m_missions.empty()) - { - // Choose first available mission. - SetCurrentMission(m_missions[0]); - return m_mission; - } - - // Create initial mission. - m_mission = new CMission(this); - m_mission->SetName("Mission0"); - AddMission(m_mission); - m_mission->SyncContent(true, false, bSkipLoadingAIWhenSyncingContent); - return m_mission; -} - -void CCryEditDoc::SetCurrentMission(CMission* mission) -{ - if (mission != m_mission) - { - QWaitCursor wait; - - if (m_mission) - { - m_mission->SyncContent(false, false); - } - - m_mission = mission; - m_mission->SyncContent(true, false); - - GetIEditor()->GetGameEngine()->LoadMission(m_mission->GetName()); - } -} - -void CCryEditDoc::ClearMissions() -{ - for (int i = 0; i < m_missions.size(); i++) - { - delete m_missions[i]; - } - - m_missions.clear(); - m_mission = 0; -} - bool CCryEditDoc::IsLevelExported() const { return m_boLevelExported; @@ -2170,37 +1949,6 @@ void CCryEditDoc::SetLevelExported(bool boExported) m_boLevelExported = boExported; } -CMission* CCryEditDoc::FindMission(const QString& name) const -{ - for (int i = 0; i < m_missions.size(); i++) - { - if (QString::compare(name, m_missions[i]->GetName(), Qt::CaseInsensitive) == 0) - { - return m_missions[i]; - } - } - return 0; -} - -void CCryEditDoc::AddMission(CMission* mission) -{ - assert(std::find(m_missions.begin(), m_missions.end(), mission) == m_missions.end()); - m_missions.push_back(mission); - GetIEditor()->Notify(eNotify_OnInvalidateControls); -} - -void CCryEditDoc::RemoveMission(CMission* mission) -{ - // if deleting current mission. - if (mission == m_mission) - { - m_mission = 0; - } - - m_missions.erase(std::find(m_missions.begin(), m_missions.end(), mission)); - GetIEditor()->Notify(eNotify_OnInvalidateControls); -} - void CCryEditDoc::RegisterListener(IDocListener* listener) { if (listener == nullptr) @@ -2306,19 +2054,6 @@ void CCryEditDoc::OnStartLevelResourceList() gEnv->pCryPak->GetResourceList(AZ::IO::IArchive::RFOM_Level)->Clear(); } -void CCryEditDoc::ForceSkyUpdate() -{ - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine ? gEnv->p3DEngine->GetTimeOfDay() : nullptr; - CMission* pCurMission = GetIEditor()->GetDocument()->GetCurrentMission(); - - if (pTimeOfDay && pCurMission) - { - pTimeOfDay->SetTime(pCurMission->GetTime(), gSettings.bForceSkyUpdate); - pCurMission->SetTime(pCurMission->GetTime()); - GetIEditor()->Notify(eNotify_OnTimeOfDayChange); - } -} - BOOL CCryEditDoc::DoFileSave() { if (GetEditMode() == CCryEditDoc::DocumentEditingMode::LevelEdit) @@ -2380,27 +2115,11 @@ void CCryEditDoc::InitEmptyLevel(int /*resolution*/, int /*unitSize*/, bool /*bU ////////////////////////////////////////////////////////////////////////// if (!GetIEditor()->IsInPreviewMode()) { - // Make new mission. GetIEditor()->ReloadTemplates(); m_environmentTemplate = GetIEditor()->FindTemplate("Environment"); - GetCurrentMission(true); // true = skip loading the AI in case the content needs to get synchronized (otherwise it would attempt to load AI stuff from the previously loaded level (!) which might give confusing warnings) - GetIEditor()->GetGameEngine()->SetMissionName(GetCurrentMission()->GetName()); GetIEditor()->GetGameEngine()->SetLevelCreated(true); - GetIEditor()->GetGameEngine()->ReloadEnvironment(); GetIEditor()->GetGameEngine()->SetLevelCreated(false); - - // Default time of day. - auto defaultTimeOfDayPath = AZ::IO::FixedMaxPath(AZ::Utils::GetEnginePath()) / "Assets" / "Editor" / "default_time_of_day.xml"; - XmlNodeRef root = GetISystem()->LoadXmlFromFile(defaultTimeOfDayPath.c_str()); - if (root) - { - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine ? gEnv->p3DEngine->GetTimeOfDay() : nullptr; - if (pTimeOfDay) - { - pTimeOfDay->Serialize(root, true); - } - } } { @@ -2426,44 +2145,9 @@ void CCryEditDoc::InitEmptyLevel(int /*resolution*/, int /*unitSize*/, bool /*bU GetIEditor()->SetStatusText("Ready"); } -void CCryEditDoc::CreateDefaultLevelAssets(int resolution, int unitSize) +void CCryEditDoc::CreateDefaultLevelAssets([[maybe_unused]] int resolution, [[maybe_unused]] int unitSize) { - if (AZ::Interface::Get()) - { - AzToolsFramework::EditorLevelNotificationBus::Broadcast(&AzToolsFramework::EditorLevelNotificationBus::Events::OnNewLevelCreated); - } - else - { - bool isPrefabSystemEnabled = false; - AzFramework::ApplicationRequests::Bus::BroadcastResult( - isPrefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); - - if (!isPrefabSystemEnabled) - { - AZ::Data::AssetCatalogRequestBus::BroadcastResult( - m_envProbeSliceAssetId, &AZ::Data::AssetCatalogRequests::GetAssetIdByPath, m_envProbeSliceRelativePath, - azrtti_typeid(), false); - - if (m_envProbeSliceAssetId.IsValid()) - { - AZ::Data::Asset asset = AZ::Data::AssetManager::Instance().FindOrCreateAsset( - m_envProbeSliceAssetId, AZ::Data::AssetLoadBehavior::Default); - if (asset) - { - m_terrainSize = resolution * unitSize; - const float halfTerrainSize = m_terrainSize / 2.0f; - - AZ::Transform worldTransform = AZ::Transform::CreateIdentity(); - worldTransform = AZ::Transform::CreateTranslation(AZ::Vector3(halfTerrainSize, halfTerrainSize, m_envProbeHeight / 2)); - - AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler::BusConnect(); - GetIEditor()->SuspendUndo(); - AzToolsFramework::SliceEditorEntityOwnershipServiceRequestBus::Broadcast( - &AzToolsFramework::SliceEditorEntityOwnershipServiceRequests::InstantiateEditorSlice, asset, worldTransform); - } - } - } - } + AzToolsFramework::EditorLevelNotificationBus::Broadcast(&AzToolsFramework::EditorLevelNotificationBus::Events::OnNewLevelCreated); } void CCryEditDoc::OnEnvironmentPropertyChanged(IVariable* pVar) @@ -2523,8 +2207,6 @@ void CCryEditDoc::OnEnvironmentPropertyChanged(IVariable* pVar) pVar->Get(value); childNode->setAttr("value", value.toUtf8().data()); } - - GetIEditor()->GetGameEngine()->ReloadEnvironment(); } QString CCryEditDoc::GetCryIndexPath(const LPCTSTR levelFilePath) @@ -2577,12 +2259,6 @@ void CCryEditDoc::ReleaseXmlArchiveArray(TDocMultiArchive& arrXmlAr) SAFE_DELETE(arrXmlAr[0]); } - -void CCryEditDoc::SyncCurrentMissionContent(bool bRetrieve) -{ - GetCurrentMission()->SyncContent(bRetrieve, false); -} - ////////////////////////////////////////////////////////////////////////// // AzToolsFramework::EditorEntityContextNotificationBus interface implementation void CCryEditDoc::OnSliceInstantiated(const AZ::Data::AssetId& sliceAssetId, AZ::SliceComponent::SliceInstanceAddress& sliceAddress, const AzFramework::SliceInstantiationTicket& /*ticket*/) diff --git a/Code/Sandbox/Editor/CryEditDoc.h b/Code/Sandbox/Editor/CryEditDoc.h index 481e9fa046..be8a5fcec7 100644 --- a/Code/Sandbox/Editor/CryEditDoc.h +++ b/Code/Sandbox/Editor/CryEditDoc.h @@ -22,7 +22,6 @@ #include #endif -class CMission; class CLevelShaderCache; class CClouds; struct LightingSettings; @@ -124,18 +123,6 @@ public: // Create from serialization only const char* GetTemporaryLevelName() const; void DeleteTemporaryLevel(); - void ChangeMission(); - //! Return currently active Mission. - CMission* GetCurrentMission(bool bSkipLoadingAIWhenSyncingContent = false); - //! Get number of missions on Map. - int GetMissionCount() const { return m_missions.size(); } - //! Get Mission by index. - CMission* GetMission(int index) const { return m_missions[index]; } - //! Find Mission by name. - CMission* FindMission(const QString& name) const; - //! Makes specified mission current. - void SetCurrentMission(CMission* mission); - CLevelShaderCache* GetShaderCache() { return m_pLevelShaderCache; } CClouds* GetClouds() { return m_pClouds; } void SetWaterColor(const QColor& col) { m_waterColor = col; } @@ -167,7 +154,6 @@ protected: virtual void Load(TDocMultiArchive& arrXmlAr, const QString& szFilename); virtual void StartStreamingLoad(){} - virtual void SyncCurrentMissionContent(bool bRetrieve); void Save(CXmlArchive& xmlAr); void Load(CXmlArchive& xmlAr, const QString& szFilename); @@ -179,14 +165,8 @@ protected: bool LoadEntitiesFromSlice(const QString& sliceFile); void SerializeFogSettings(CXmlArchive& xmlAr); virtual void SerializeViewSettings(CXmlArchive& xmlAr); - void SerializeMissions(TDocMultiArchive& arrXmlAr, QString& currentMission, bool bPartsInXml); void SerializeShaderCache(CXmlArchive& xmlAr); void SerializeNameSelection(CXmlArchive& xmlAr); - void ForceSkyUpdate(); - //! Add new mission to map. - void AddMission(CMission* mission); - //! Remove existing mission from map. - void RemoveMission(CMission* mission); void LogLoadTime(int time); struct TSaveDocContext @@ -200,10 +180,8 @@ protected: virtual bool OnSaveDocument(const QString& lpszPathName); virtual void OnFileSaveAs(); - void LoadTemplates(); //! called immediately after saving the level. void AfterSave(); - void ClearMissions(); void RegisterConsoleVariables(); void OnStartLevelResourceList(); static void OnValidateSurfaceTypesChanged(ICVar*); @@ -220,9 +198,7 @@ protected: QColor m_waterColor; XmlNodeRef m_fogTemplate; XmlNodeRef m_environmentTemplate; - CMission* m_mission; CClouds* m_pClouds; - std::vector m_missions; std::list m_listeners; bool m_bDocumentReady; CLevelShaderCache* m_pLevelShaderCache; diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.cpp b/Code/Sandbox/Editor/DatabaseFrameWnd.cpp deleted file mode 100644 index 89843c8247..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.cpp +++ /dev/null @@ -1,1491 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "DatabaseFrameWnd.h" - -// Qt -#include -#include -#include -#include - -// AzToolsFramework -#include - -// Editor -#include "BaseLibraryManager.h" -#include "BaseLibraryItem.h" -#include "StringDlg.h" -#include "QtViewPaneManager.h" -#include "Undo/Undo.h" - -#include "ui_DatabaseFrameWnd.h" - - -class CUndoSelectLibraryUndo - : public IUndoObject -{ -public: - CUndoSelectLibraryUndo(const QString& libraryName, const QString& wndClssName) - { - m_LibraryName = libraryName; - m_WndClassName = wndClssName; - } - ~CUndoSelectLibraryUndo(){} - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return "Select database library."; }; - void Undo(bool bUndo) - { - SelectLibrary(bUndo); - } - void Redo() - { - SelectLibrary(true); - } - -private: - - void SelectLibrary(bool bUndo) - { - CDatabaseFrameWnd* pDatabaseEditor = FindViewPane(m_WndClassName); - if (!pDatabaseEditor) - { - return; - } - - QString libraryNameForUndo(m_LibraryName); - if (bUndo) - { - m_LibraryName = pDatabaseEditor->GetSelectedLibraryName(); - } - pDatabaseEditor->SelectLibrary(libraryNameForUndo); - } - - QString m_LibraryName; - QString m_WndClassName; -}; - -static const int LIBRARY_CB_WIDTH(150); - -CDatabaseFrameWnd::CDatabaseFrameWnd(CBaseLibraryManager* pItemManager, QWidget* pParent) - : AzQtComponents::DockMainWindow(pParent) - , m_pItemManager(pItemManager) - , ui(new Ui::DatabaseFrameWnd) - , m_initialized(false) - , m_pLibraryItemTreeModel(nullptr) -{ - ui->setupUi(this); - m_sortRecursionType = SORT_RECURSION_FULL; - m_pLibrary = NULL; - m_bLibsLoaded = false; - m_pCurrentItem = NULL; - - GetIEditor()->RegisterNotifyListener(this); - GetIEditor()->GetUndoManager()->AddListener(this); - - m_pLibraryListComboBox = new QComboBox; - m_pLibraryListComboBox->setFixedSize(LIBRARY_CB_WIDTH, 16); - ui->m_toolBar->insertWidget(ui->m_toolBar->actions()[4], m_pLibraryListComboBox); - connect(m_pLibraryListComboBox, static_cast(&QComboBox::currentIndexChanged), this, &CDatabaseFrameWnd::OnChangedLibrary); - - m_pLibraryListModel = new LibraryListModel(m_pItemManager, this); - m_pLibraryListComboBox->setModel(m_pLibraryListModel); - - connect(ui->actionDBAddLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnAddLibrary); - connect(ui->actionDBDelLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnRemoveLibrary); - connect(ui->actionDBRemove, &QAction::triggered, this, &CDatabaseFrameWnd::OnRemoveItem); - connect(ui->actionDBSave, &QAction::triggered, this, &CDatabaseFrameWnd::OnSave); - connect(ui->actionDBLoadLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnLoadLibrary); - connect(ui->actionDBReload, &QAction::triggered, this, &CDatabaseFrameWnd::OnReloadLib); - connect(ui->actionDBReloadLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnReloadLib); - connect(ui->actionDBCopy, &QAction::triggered, this, &CDatabaseFrameWnd::OnCopy); - connect(ui->actionDBPaste, &QAction::triggered, this, &CDatabaseFrameWnd::OnPaste); - connect(ui->actionDBClone, &QAction::triggered, this, &CDatabaseFrameWnd::OnClone); - connect(ui->actionUndo, &QAction::triggered, this, &CDatabaseFrameWnd::OnUndo); - connect(ui->actionRedo, &QAction::triggered, this, &CDatabaseFrameWnd::OnRedo); -} - -CDatabaseFrameWnd::~CDatabaseFrameWnd() -{ - // Block Signals to prevent changes in the m_pLibraryListComboBox - // from triggering OnChangedLibrary on teardown. - m_pLibraryListComboBox->blockSignals(true); - - m_pLibraryListModel->clear(); - - GetIEditor()->UnregisterNotifyListener(this); - GetIEditor()->GetUndoManager()->RemoveListener(this); -} - -void CDatabaseFrameWnd::InitTreeCtrl() -{ - QTreeView* treeView = GetTreeCtrl(); - - connect(treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &CDatabaseFrameWnd::OnSelChangedItemTree); - treeView->installEventFilter(this); -} - -void CDatabaseFrameWnd::ReloadLibs() -{ - if (!m_pItemManager) - { - return; - } - - SelectItem(0); - - m_pLibraryListModel->Reload(); - - if (m_pLibraryListComboBox) - { - SelectLibrary(m_pLibraryListComboBox->itemData(0, Qt::UserRole).value()); - } - - m_bLibsLoaded = true; -} - -void CDatabaseFrameWnd::ReloadItems() -{ - SelectItem(0); - m_selectedGroup = ""; - m_pCurrentItem = 0; - m_cpoSelectedLibraryItems.clear(); - if (m_pItemManager) - { - m_pItemManager->SetSelectedItem(0); - } - ReleasePreviewControl(); - - if (m_pLibrary && m_pLibraryItemTreeModel) - { - m_pLibraryItemTreeModel->Reload(m_pLibrary); - GetTreeCtrl()->expandAll(); - } -} - -void CDatabaseFrameWnd::SelectLibrary(const QString& library, bool bForceSelect) -{ - QWaitCursor wait; - if (GetSelectedLibraryName() != library || bForceSelect) - { - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoSelectLibraryUndo(GetSelectedLibraryName(), GetClassName())); - } - - SelectItem(0); - m_pLibrary = FindLibrary(library); - ReloadItems(); - } - if (m_pLibraryListComboBox) - { - m_pLibraryListComboBox->setCurrentIndex(GetComboBoxIndex(m_pLibrary)); - } -} - -void CDatabaseFrameWnd::SelectLibrary(CBaseLibrary* pItem, bool bForceSelect) -{ - QWaitCursor wait; - if (m_pLibrary != pItem || bForceSelect) - { - if (CUndo::IsRecording() && m_pLibrary) - { - CUndo::Record(new CUndoSelectLibraryUndo(GetSelectedLibraryName(), GetClassName())); - } - - SelectItem(0); - m_pLibrary = pItem; - ReloadItems(); - } - if (m_pLibraryListComboBox) - { - m_pLibraryListComboBox->setCurrentIndex(GetComboBoxIndex(pItem)); - } -} - -void CDatabaseFrameWnd::SelectItem(CBaseLibraryItem* item, bool bForceReload) -{ - if (item == m_pCurrentItem && !bForceReload) - { - return; - } - - QModelIndex index = m_pLibraryItemTreeModel->index(item); - if (index.isValid()) - { - GetTreeCtrl()->expand(index.parent()); - GetTreeCtrl()->setCurrentIndex(index); - } - else - { - GetTreeCtrl()->selectionModel()->clearCurrentIndex(); - } -} - -CBaseLibrary* CDatabaseFrameWnd::FindLibrary(const QString& libraryName) -{ - return (CBaseLibrary*)m_pItemManager->FindLibrary(libraryName); -} - -int CDatabaseFrameWnd::GetComboBoxIndex(CBaseLibrary* pLibrary) -{ - return m_pLibraryListComboBox->findData(QVariant::fromValue(pLibrary)); -} - -CBaseLibrary* CDatabaseFrameWnd::NewLibrary(const QString& libraryName) -{ - return (CBaseLibrary*)m_pItemManager->AddLibrary(libraryName, false); -} - -void CDatabaseFrameWnd::DeleteLibrary(CBaseLibrary* pLibrary) -{ - m_pItemManager->DeleteLibrary(pLibrary->GetName()); -} - -void CDatabaseFrameWnd::DeleteItem(CBaseLibraryItem* pItem) -{ - m_pItemManager->DeleteItem(pItem); -} - -void CDatabaseFrameWnd::OnAddLibrary() -{ - StringDlg dlg(tr("New Library Name"), this); - CUndo undo(tr("Add Database Library").toUtf8()); - if (dlg.exec() == QDialog::Accepted) - { - if (!dlg.GetString().isEmpty()) - { - SelectItem(0); - // Make new library. - QString library = dlg.GetString(); - NewLibrary(library); - ReloadLibs(); - SelectLibrary(library); - GetIEditor()->SetModifiedFlag(); - } - } -} - -void CDatabaseFrameWnd::OnRemoveLibrary() -{ - QString library = GetSelectedLibraryName(); - if (library.isEmpty()) - { - return; - } - if (m_pLibrary->IsModified()) - { - QString ask = tr("Save changes to the library %1?").arg(library); - if (QMessageBox::question(this, tr("Editor"), ask) == QMessageBox::Yes) - { - OnSave(); - } - } - QString ask = tr("When removing library All items contained in this library will be deleted.\r\nAre you sure you want to remove libarary %1?\r\n(Note: Library file will not be deleted from the disk)").arg(library); - if (QMessageBox::question(this, tr("Editor"), ask) == QMessageBox::Yes) - { - SelectItem(0); - DeleteLibrary(m_pLibrary); - m_pLibrary = 0; - ReleasePreviewControl(); - ReloadLibs(); - GetIEditor()->SetModifiedFlag(); - } -} - -void CDatabaseFrameWnd::OnAddItem() -{ -} - -void CDatabaseFrameWnd::OnRemoveItem() -{ - // When we have no set of selected items, it may be the case that we are - // dealing with old fashioned selection. If such is the case, let's deal - // with it using the old code system, which should be deprecated. - if (m_cpoSelectedLibraryItems.empty()) - { - if (m_pCurrentItem) - { - // Remove prototype from prototype manager and library. - QString str = tr("Delete %1?").arg(m_pCurrentItem->GetName()); - if (QMessageBox::question(this, tr("Delete Confirmation"), str) == QMessageBox::Yes) - { - CUndo undo(tr("Remove library item").toUtf8()); - TSmartPtr pCurrent = m_pCurrentItem; - DeleteItem(pCurrent); - m_pLibraryItemTreeModel->Remove(m_pCurrentItem); - GetIEditor()->SetModifiedFlag(); - SelectItem(0); - } - } - } - else // This is to be used when deleting multiple items... - { - QString strMessageString = tr("Delete the following items:\n"); - int nItemCount(0); - std::set::iterator itCurrentIterator; - std::set::iterator itEnd; - - itEnd = m_cpoSelectedLibraryItems.end(); - itCurrentIterator = m_cpoSelectedLibraryItems.begin(); - // For now, we have a maximum limit of 7 items per messagebox... - for (nItemCount = 0; nItemCount < 7; ++nItemCount, itCurrentIterator++) - { - if (itCurrentIterator == itEnd) - { - // As there were less than 7 items selected, we got to put them all - // into the formated string for the messagebox. - break; - } - strMessageString += QStringLiteral("%1\n").arg((*itCurrentIterator)->GetName()); - } - if (itCurrentIterator != itEnd) - { - strMessageString += QStringLiteral("..."); - } - - if (QMessageBox::question(this, tr("Delete Confirmation"), strMessageString) == QMessageBox::Yes) - { - for (itCurrentIterator = m_cpoSelectedLibraryItems.begin(); itCurrentIterator != itEnd; itCurrentIterator++) - { - CBaseLibraryItem* pCurrent = *itCurrentIterator; - DeleteItem(pCurrent); - m_pLibraryItemTreeModel->Remove(pCurrent); - } - m_cpoSelectedLibraryItems.clear(); - GetIEditor()->SetModifiedFlag(); - SelectItem(0); - } - } -} - -void CDatabaseFrameWnd::OnRenameItem() -{ - if (m_pCurrentItem) - { - StringGroupDlg dlg; - dlg.SetGroup(m_pCurrentItem->GetGroupName()); - dlg.SetString(m_pCurrentItem->GetShortName()); - if (dlg.exec() == QDialog::Accepted) - { - static bool warn = true; - if (warn) - { - warn = false; - QMessageBox::warning(this, tr("Warning"), tr("Levels referencing this archetype will need to be exported.")); - } - - CUndo undo(tr("Rename library item").toUtf8()); - TSmartPtr curItem = m_pCurrentItem; - SetItemName(curItem, dlg.GetGroup(), dlg.GetString()); - ReloadItems(); - SelectItem(curItem, true); - curItem->SetModified(); - //m_pCurrentItem->Update(); - } - GetIEditor()->SetModifiedFlag(); - } -} - -void CDatabaseFrameWnd::OnChangedLibrary() -{ - CBaseLibrary* pBaseLibrary = NULL; - if (m_pLibraryListComboBox) - { - pBaseLibrary = m_pLibraryListComboBox->currentData(Qt::UserRole).value(); - } - - if (pBaseLibrary && pBaseLibrary != m_pLibrary) - { - CUndo undo("Change database library"); - SelectLibrary(pBaseLibrary); - } -} - -void CDatabaseFrameWnd::OnExportLibrary() -{ - if (!m_pLibrary) - { - return; - } - - QString filename; - if (CFileUtil::SelectSaveFile("Library XML Files (*.xml)", "xml", (Path::GetEditingGameDataFolder() + "/Materials").c_str(), filename)) - { - XmlNodeRef libNode = XmlHelpers::CreateXmlNode("MaterialLibrary"); - m_pLibrary->Serialize(libNode, false); - XmlHelpers::SaveXmlNode(GetIEditor()->GetFileUtil(), libNode, filename.toStdString().c_str()); - } -} - -void CDatabaseFrameWnd::OnSave() -{ - if (m_bLibsLoaded) - { - m_pLibrary->SetModified(true); - m_pItemManager->SaveAllLibs(); - m_pLibrary->SetModified(false); - } -} - -void CDatabaseFrameWnd::OnReloadLib() -{ - if (!m_pLibrary) - { - return; - } - - QString libname = m_pLibrary->GetName(); - QString file = m_pLibrary->GetFilename(); - - //If the file we want to reload does not exist (and isn't the level library), we can't reload it - //Just display a warning to the user and stop the reload process - if (!CFileUtil::Exists(file, false) && !m_pLibrary->IsLevelLibrary()) - { - QString str = tr("Layer %1 does not exist on disk yet. Have you ever saved it?\nReloading layer is not possible!"). - arg(libname); - if (QMessageBox::information(this, tr("Editor"), str)) - { - return; - } - } - - if (m_pLibrary->IsModified()) - { - QString str = tr("Layer %1 was modified.\nReloading layer will discard all modifications to this library!"). - arg(libname); - if (QMessageBox::question(this, tr("Editor"), str) != QMessageBox::Yes) - { - return; - } - } - - //Don't try to delete/load level library from disk. - //It's managed by the level and there doesn't seem to be a way to "reload" it - if (!m_pLibrary->IsLevelLibrary()) - { - m_pItemManager->DeleteLibrary(libname); - m_pItemManager->LoadLibrary(file, true); - } - - ReloadLibs(); - SelectLibrary(libname); -} - -void CDatabaseFrameWnd::OnLoadLibrary() -{ - assert(m_pItemManager); - CUndo undo(tr("Load Database Library").toUtf8()); - LoadLibrary(); -} - -void CDatabaseFrameWnd::LoadLibrary() -{ - AssetSelectionModel selection = GetAssetSelectionModel(); - - AzToolsFramework::EditorRequests::Bus::Broadcast( - &AzToolsFramework::EditorRequests::BrowseForAssets, - selection); - if (selection.IsValid()) - { - GetIEditor()->SuspendUndo(); - IDataBaseLibrary* matLib = m_pItemManager->LoadLibrary(Path::FullPathToGamePath( - selection.GetResult()->GetFullPath().c_str()).c_str()); - GetIEditor()->ResumeUndo(); - ReloadLibs(); - if (matLib) - { - SelectLibrary((CBaseLibrary*)matLib); - } - } -} - -bool CDatabaseFrameWnd::SetItemName(CBaseLibraryItem* item, const QString& groupName, const QString& itemName) -{ - assert(item); - // Make prototype name. - QString name; - if (!groupName.isEmpty()) - { - name = groupName + "."; - } - name += itemName; - QString fullName = name; - if (item->GetLibrary()) - { - fullName = item->GetLibrary()->GetName() + "." + name; - } - IDataBaseItem* pOtherItem = m_pItemManager->FindItemByName(fullName); - if (pOtherItem && pOtherItem != item) - { - // Ensure uniqness of name. - Warning("Duplicate Item Name %s", name.toUtf8().data()); - return false; - } - else - { - item->SetName(name); - } - return true; -} - -void CDatabaseFrameWnd::OnSelChangedItemTree(const QModelIndex& index) -{ - CBaseLibraryItem* item = index.data(Qt::UserRole).value(); - - if (item) - { - if (item->GetLibrary() != m_pLibrary && item->GetLibrary()) - { - SelectLibrary((CBaseLibrary*)item->GetLibrary()); - } - } - - m_pCurrentItem = item; - - if (item) - { - m_selectedGroup = item->GetGroupName(); - } - else - { - m_selectedGroup = ""; - } - - m_pItemManager->SetSelectedItem(item); -} - -bool CDatabaseFrameWnd::eventFilter(QObject* watched, QEvent* event) -{ - if (event->type() != QEvent::KeyPress || watched != GetTreeCtrl()) - { - return QMainWindow::eventFilter(watched, event); - } - - QKeyEvent* keyEvent = static_cast(event); - - bool bCtrl = keyEvent->modifiers() == Qt::ControlModifier; - - if (keyEvent->matches(QKeySequence::Copy)) - { - OnCopy(); // Ctrl+C - } - else if (keyEvent->matches(QKeySequence::Paste)) - { - OnPaste(); // Ctrl+V - } - else if (keyEvent->matches(QKeySequence::Cut)) - { - OnCut(); // Ctrl+X - } - else if (bCtrl && keyEvent->key() == Qt::Key_D) - { - OnClone(); // Ctrl+D - } - else if (keyEvent->matches(QKeySequence::Delete)) - { - OnRemoveItem(); - } - else if (keyEvent->key() == Qt::Key_F2) - { - OnRenameItem(); - } - else if (keyEvent->key() == Qt::Key_Insert) - { - OnAddItem(); - } - else - { - return QMainWindow::eventFilter(watched, event); - } - - return true; -} - -void CDatabaseFrameWnd::OnUndo() -{ - GetIEditor()->Undo(); -} - -void CDatabaseFrameWnd::OnRedo() -{ - GetIEditor()->Redo(); -} - -void CDatabaseFrameWnd::OnCut() -{ - if (m_pCurrentItem) - { - OnCopy(); - OnRemoveItem(); - } -} - -void CDatabaseFrameWnd::OnClone() -{ - OnCopy(); - OnPaste(); -} - -void CDatabaseFrameWnd::DoesItemExist(const QString& itemName, bool& bOutExist) const -{ - for (int i = 0, iItemCount(m_pLibrary->GetItemCount()); i < iItemCount; ++i) - { - IDataBaseItem* pItem = m_pLibrary->GetItem(i); - if (pItem == NULL) - { - continue; - } - if (pItem->GetName() == itemName) - { - bOutExist = true; - return; - } - } - bOutExist = false; -} - -QString CDatabaseFrameWnd::MakeValidName(const QString& candidateName, AZStd::function FuncForCheck) const -{ - bool bCheck = false; - FuncForCheck(candidateName, bCheck); - if (!bCheck) - { - return candidateName; - } - - int nCounter = 0; - const int nEnoughBigNumber = 1000000; - do - { - QString counterBuffer; - counterBuffer = QString::number(nCounter); - QString newName = candidateName + counterBuffer; - FuncForCheck(newName, bCheck); - if (!bCheck) - { - return newName; - } - } while (nCounter++ < nEnoughBigNumber); - - assert(0 && "CDatabaseFrameWnd::MakeValidName()"); - return candidateName; -} - -void CDatabaseFrameWnd::DoesGroupExist(const QString& groupName, bool& bOutExist) const -{ - bOutExist = m_pLibraryItemTreeModel->DoesGroupExist(groupName); -} - -QString CDatabaseFrameWnd::GetSelectedLibraryName() const -{ - return m_pLibrary ? m_pLibrary->GetName() : ""; -} - -void CDatabaseFrameWnd::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnBeginNewScene: - m_bLibsLoaded = false; - // Clear all prototypes and libraries. - SelectItem(0); - if (m_pLibraryListComboBox) - { - m_pLibraryListComboBox->clear(); - } - m_pLibrary = nullptr; - break; - - case eNotify_OnEndSceneOpen: - m_bLibsLoaded = false; - ReloadLibs(); - break; - - case eNotify_OnCloseScene: - { - m_bLibsLoaded = false; - CUndo undo(tr("Close Database Library").toUtf8()); - GetTreeCtrl()->selectionModel()->clear(); - GetTreeCtrl()->clearSelection(); - m_pLibraryItemTreeModel->Clear(); - m_pCurrentItem = nullptr; - m_cpoSelectedLibraryItems.clear(); - } - break; - - case eNotify_OnDataBaseUpdate: - if (m_pLibrary && m_pLibrary->IsModified()) - { - ReloadItems(); - } - break; - } -} - -void CDatabaseFrameWnd::SignalNumUndoRedo(const unsigned int& numUndo, const unsigned int& numRedo) -{ - ui->actionUndo->setEnabled(numUndo > 0); - ui->actionRedo->setEnabled(numRedo > 0); -} - -void CDatabaseFrameWnd::showEvent(QShowEvent* event) -{ - if (!m_initialized) - { - OnInitDialog(); - m_initialized = true; - } - - QMainWindow::showEvent(event); -} - -LibraryListModel::LibraryListModel(CBaseLibraryManager* itemManager, QObject* pParent) - : QAbstractListModel(pParent) - , m_pItemManager(itemManager) -{ -} - -int LibraryListModel::rowCount(const QModelIndex& parent) const -{ - return parent.isValid() ? 0 : m_pItemManager->GetLibraryCount(); -} - -QVariant LibraryListModel::data(const QModelIndex& index, int role) const -{ - const int row = index.row(); - - if (row < 0 || row >= m_pItemManager->GetLibraryCount()) - { - return {}; - } - - auto library = static_cast(m_pItemManager->GetLibrary(row)); - - switch (role) - { - case Qt::DisplayRole: - { - QString name = library->GetName(); - if (library->IsModified()) - { - name += "*"; - } - return name; - } - - case Qt::UserRole: - return QVariant::fromValue(library); - } - - return {}; -} - -void LibraryListModel::Reload() -{ - beginResetModel(); - - const int count = m_pItemManager->GetLibraryCount(); - - for (int i = 0; i < count; i++) - { - CBaseLibrary* pLibrary = static_cast(m_pItemManager->GetLibrary(i)); - connect(pLibrary, &CBaseLibrary::Modified, this, &LibraryListModel::LibraryModified); - } - - endResetModel(); -} - -void LibraryListModel::clear() -{ - beginResetModel(); - endResetModel(); -} - -void LibraryListModel::LibraryModified(bool) -{ - CBaseLibrary* library = qobject_cast(sender()); - - const int count = m_pItemManager->GetLibraryCount(); - - for (int i = 0; i < count; i++) - { - CBaseLibrary* pLibrary = static_cast(m_pItemManager->GetLibrary(i)); - if (pLibrary == library) - { - emit dataChanged(index(i, 0), index(i, 0)); - } - } -} - -LibraryItemTreeModel::LibraryItemTreeModel(CDatabaseFrameWnd* pParent) - : QAbstractItemModel(pParent) - , m_dialog(pParent) -{ -} - -Qt::ItemFlags LibraryItemTreeModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return Qt::ItemFlags(); - } - - Qt::ItemFlags flags = QAbstractItemModel::flags(index); - - flags |= Qt::ItemIsEditable; - - if (!index.internalPointer()) - { - flags |= Qt::ItemIsDropEnabled; - } - else - { - flags |= Qt::ItemIsDragEnabled; - } - - return flags; -} - -int LibraryItemTreeModel::columnCount(const QModelIndex&) const -{ - return 1; -} - -int LibraryItemTreeModel::rowCount(const QModelIndex& parent) const -{ - if (!parent.isValid()) - { - return m_groups.size(); - } - else - { - if (!parent.internalPointer() && parent.row() >= 0 && parent.row() < m_groups.size()) - { - auto entry = std::begin(m_groups); - std::advance(entry, parent.row()); - return entry->second->second.size(); - } - } - - return 0; -} - -QModelIndex LibraryItemTreeModel::parent(const QModelIndex& index) const -{ - if (index.isValid() && index.internalPointer()) - { - auto group = static_cast(index.internalPointer()); - auto entry = m_groups.find(group->first); - return createIndex(std::distance(std::begin(m_groups), entry), 0, nullptr); - } - - return {}; -} - -QModelIndex LibraryItemTreeModel::index(int row, int column, const QModelIndex& parent) const -{ - if (column > 0) - { - return {}; - } - - if (!parent.isValid()) - { - if (row >= 0 && row < m_groups.size()) - { - return createIndex(row, 0, nullptr); - } - } - else - { - if (!parent.internalPointer() && parent.row() >= 0 && parent.row() < m_groups.size()) - { - auto entry = std::begin(m_groups); - std::advance(entry, parent.row()); - - if (row >= 0 && row < entry->second->second.size()) - { - return createIndex(row, 0, const_cast(entry->second.get())); - } - } - } - - return {}; -} - -QVariant LibraryItemTreeModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - { - return {}; - } - - if (!index.internalPointer()) - { - switch (role) - { - case Qt::DisplayRole: - { - auto entry = std::begin(m_groups); - std::advance(entry, index.row()); - return entry->first; - } - case Qt::UserRole: - return QVariant::fromValue(nullptr); - } - } - else - { - auto group = static_cast(index.internalPointer()); - auto item = group->second[index.row()]; - - switch (role) - { - case Qt::DisplayRole: - return item->GetShortName(); - case Qt::UserRole: - return QVariant::fromValue(item); - } - } - - return {}; -} - -void LibraryItemTreeModel::RenameItem(CBaseLibraryItem* item, const QString& fullName) -{ - QString prevFullName = item->GetFullName(); - item->SetName(fullName); - item->SetModified(); - emit itemRenamed(item, prevFullName); -} - -bool LibraryItemTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid() || role != Qt::EditRole) - { - return false; - } - - QString text = value.toString(); - - if (text.isEmpty()) - { - return false; - } - - if (text.contains(QLatin1Char('.'))) - { - QMessageBox::warning(AzToolsFramework::GetActiveWindow(), tr("Warning"), tr("The name must not contain \".\"")); - return false; - } - - if (!index.internalPointer()) - { - // rename group - - auto sourceEntry = std::begin(m_groups); - std::advance(sourceEntry, index.row()); - - if (text == sourceEntry->first) - { - return false; - } - - if (m_groups.find(text) != std::end(m_groups)) - { - QMessageBox::warning(AzToolsFramework::GetActiveWindow(), tr("Warning"), tr("The identical name exists.")); - return false; - } - - int sourceRow = index.row(); - int targetRow = std::distance(std::begin(m_groups), m_groups.lower_bound(text)); - - if (targetRow < sourceRow || targetRow > sourceRow + 1) - { - beginMoveRows({}, sourceRow, sourceRow, {}, targetRow); - } - - auto targetEntry = m_groups.insert({ text, sourceEntry->second }).first; - targetEntry->second->first = text; - m_groups.erase(sourceEntry); - - if (targetRow < sourceRow || targetRow > sourceRow + 1) - { - endMoveRows(); - } - else - { - emit dataChanged(index, index); - } - - CUndo undo(tr("Rename FlareGroupItem").toUtf8()); - - auto group = targetEntry->second.get(); - - for (int row = 0; row < group->second.size(); row++) - { - auto item = group->second[row]; - QString name = QString("%1.%2").arg(text).arg(item->GetShortName()); - RenameItem(item, name); - } - } - else - { - // rename single item - - auto group = static_cast(index.internalPointer()); - auto& items = group->second; - - auto item = items[index.row()]; - - if (text == item->GetShortName()) - { - return false; - } - - QString name = QString("%1.%2").arg(item->GetGroupName(), text); - - if (std::find_if(std::begin(items), std::end(items), - [&](const CBaseLibraryItem* item) - { - return item->GetName() == name; - }) != std::end(items)) - { - QMessageBox::warning(AzToolsFramework::GetActiveWindow(), tr("Warning"), tr("The identical name exists.")); - return false; - } - - CUndo undo(tr("Rename FlareGroupItem").toUtf8()); - RenameItem(item, name); - - emit dataChanged(index, index); - } - - return true; -} - -QModelIndex LibraryItemTreeModel::index(CBaseLibraryItem* item) const -{ - if (!item) - { - return {}; - } - - auto entry = m_groups.find(item->GetGroupName()); - if (entry == std::end(m_groups)) - { - return {}; - } - - auto& items = entry->second->second; - - auto it = std::find(std::begin(items), std::end(items), item); - if (it == std::end(items)) - { - return {}; - } - - return createIndex(std::distance(std::begin(items), it), 0, const_cast(entry->second.get())); -} - -bool LibraryItemTreeModel::removeRows(int row, int count, const QModelIndex& parent) -{ - if (!parent.isValid()) - { - beginRemoveRows({}, row, row + count - 1); - - auto first = std::begin(m_groups); - std::advance(first, row); - - auto last = std::begin(m_groups); - std::advance(last, row + count); - - m_groups.erase(first, last); - - endRemoveRows(); - } - else - { - beginRemoveRows(parent, row, row + count - 1); - - auto entry = std::begin(m_groups); - std::advance(entry, parent.row()); - - auto& items = entry->second->second; - items.erase(std::begin(items) + row, std::begin(items) + row + count); - - endRemoveRows(); - - if (items.empty()) - { - beginRemoveRows({}, parent.row(), parent.row()); - m_groups.erase(entry); - endRemoveRows(); - } - } - - return true; -} - -static bool LibraryItemLess(const CBaseLibraryItem* left, const CBaseLibraryItem* right) -{ - QString leftName = left->GetName(); - QString rightName = right->GetName(); - return leftName.compare(rightName) < 0; -} - -void LibraryItemTreeModel::Clear() -{ - beginResetModel(); - - m_groups.clear(); - - endResetModel(); -} - -void LibraryItemTreeModel::Reload(CBaseLibrary* pLibrary) -{ - beginResetModel(); - - m_groups.clear(); - - for (int i = 0; i < pLibrary->GetItemCount(); i++) - { - auto item = static_cast(pLibrary->GetItem(i)); - - QString itemName = item->GetName(); - QString groupName = item->GetGroupName(); - - auto entry = m_groups.find(groupName); - - if (entry == std::end(m_groups)) - { - entry = m_groups.insert({ groupName, std::make_shared(groupName, std::vector()) }).first; - } - - auto& items = entry->second->second; - items.insert(std::upper_bound(std::begin(items), std::end(items), item, LibraryItemLess), item); - } - - endResetModel(); -} - -QString LibraryItemTreeModel::GetFullName(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return QString(); - } - - if (!index.internalPointer()) - { - auto entry = std::begin(m_groups); - std::advance(entry, index.row()); - return entry->first; - } - else - { - auto group = static_cast(index.internalPointer()); - auto item = group->second[index.row()]; - return item->GetName(); - } -} - -void LibraryItemTreeModel::Add(CBaseLibraryItem* item) -{ - QString groupName = item->GetGroupName(); - - auto entry = m_groups.find(groupName); - if (entry == std::end(m_groups)) - { - int row = std::distance(std::begin(m_groups), m_groups.lower_bound(groupName)); - - emit beginInsertRows({}, row, row); - entry = m_groups.insert({ groupName, std::make_shared(groupName, std::vector()) }).first; - emit endInsertRows(); - } - - QModelIndex parentIndex = createIndex(std::distance(std::begin(m_groups), entry), 0, nullptr); - auto& items = entry->second->second; - - if (std::find(std::begin(items), std::end(items), item) == std::end(items)) - { - auto it = std::upper_bound(std::begin(items), std::end(items), item, LibraryItemLess); - int row = std::distance(std::begin(items), it); - - emit beginInsertRows(parentIndex, row, row); - items.insert(it, item); - emit endInsertRows(); - } -} - -std::vector LibraryItemTreeModel::ChildItems(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return {}; - } - - if (!index.internalPointer()) - { - auto entry = std::begin(m_groups); - std::advance(entry, index.row()); - return entry->second->second; - } - else - { - auto group = static_cast(index.internalPointer()); - return { - group->second[index.row()] - }; - } -} - -bool LibraryItemTreeModel::Remove(CBaseLibraryItem* pItem) -{ - QModelIndex itemIndex = index(pItem); - if (!itemIndex.isValid()) - { - return false; - } - return removeRow(itemIndex.row(), itemIndex.parent()); -} - -void LibraryItemTreeModel::Rename(CBaseLibraryItem* item, const QString& groupName, const QString& shortName) -{ - if (groupName != item->GetGroupName()) - { - auto entry = m_groups.find(groupName); - - if (entry == std::end(m_groups)) - { - int row = std::distance(std::begin(m_groups), m_groups.lower_bound(groupName)); - - emit beginInsertRows({}, row, row); - entry = m_groups.insert({ groupName, std::make_shared(groupName, std::vector()) }).first; - emit endInsertRows(); - } - - MoveItem(item, createIndex(std::distance(std::begin(m_groups), entry), 0, nullptr)); - } - - QString name = QString("%1.%2").arg(groupName).arg(shortName); - RenameItem(item, name); - - QModelIndex itemIndex = index(item); - emit dataChanged(itemIndex, itemIndex); -} - -QModelIndex LibraryItemTreeModel::FindLibraryItemByFullName(const QString& fullName) const -{ - for (auto& entry : m_groups) - { - auto& group = *entry.second; - auto& items = group.second; - - auto it = std::find_if(std::begin(items), std::end(items), - [&](CBaseLibraryItem* item) - { - return item->GetName() == fullName; - }); - - if (it != std::end(items)) - { - return createIndex(std::distance(std::begin(items), it), 0, &group); - } - } - - return {}; -} - -bool LibraryItemTreeModel::DoesGroupExist([[maybe_unused]] const QString& groupName) const -{ -#if 0 - auto it = std::find_if( - std::begin(m_root->m_children), - std::end(m_root->m_children), - [&](const TreeNode* node) - { - return node->m_text.compare(groupName, Qt::CaseInsensitive) == 0; - }); - - return it != std::end(m_root->m_children); -#else - return false; -#endif -} - -QStringList LibraryItemTreeModel::mimeTypes() const -{ - QStringList mimeTypes; - mimeTypes << QStringLiteral("application/x-o3de-libraryitems"); - return mimeTypes; -} - -QString LibraryItemTreeModel::MakeValidName(const Group& group, const QString& baseName) const -{ - auto& items = group.second; - - QString name = baseName; - - int counter = 0; - - while (std::find_if(std::begin(items), std::end(items), - [&](CBaseLibraryItem* item) - { - return item->GetShortName() == name; - }) != std::end(items)) - { - name = QString("%1%2").arg(baseName).arg(counter); - ++counter; - } - - return name; -} - -bool LibraryItemTreeModel::MoveItem(CBaseLibraryItem* item, const QModelIndex& targetParent) -{ - if (!targetParent.isValid() || targetParent.internalPointer()) - { - return false; - } - - auto sourceEntry = m_groups.find(item->GetGroupName()); - - auto targetEntry = std::begin(m_groups); - std::advance(targetEntry, targetParent.row()); - - if (sourceEntry == targetEntry) - { - return false; - } - - auto& sourceItems = sourceEntry->second->second; - auto sourceIt = std::find(std::begin(sourceItems), std::end(sourceItems), item); - int sourceRow = std::distance(std::begin(sourceItems), sourceIt); - - auto& targetItems = targetEntry->second->second; - auto targetIt = std::upper_bound( - std::begin(targetItems), - std::end(targetItems), - item, - [](CBaseLibraryItem* left, CBaseLibraryItem* right) - { - QString leftShortName = left->GetShortName(); - QString rightShortName = right->GetShortName(); - return leftShortName.compare(rightShortName) < 0; - }); - int targetRow = std::distance(std::begin(targetItems), targetIt); - - QModelIndex sourceParent = createIndex(std::distance(std::begin(m_groups), sourceEntry), 0, nullptr); - - beginMoveRows(sourceParent, sourceRow, sourceRow, targetParent, targetRow); - targetItems.insert(targetIt, item); - sourceItems.erase(sourceIt); - endMoveRows(); - - if (sourceItems.empty()) - { - removeRow(sourceParent.row(), {}); - } - - return true; -} - -bool LibraryItemTreeModel::dropMimeData(const QMimeData* data, [[maybe_unused]] Qt::DropAction action, [[maybe_unused]] int row, [[maybe_unused]] int column, const QModelIndex& index) -{ - if (data->hasFormat("application/x-o3de-libraryitems")) - { - QByteArray array = data->data("application/x-o3de-libraryitems"); - - QModelIndex targetParent = index; - - if (!targetParent.isValid()) - { - return false; - } - - if (targetParent.internalPointer()) - { - targetParent = parent(targetParent); - } - - int count = array.size() / sizeof(CBaseLibraryItem*); - auto items = reinterpret_cast(array.data()); - - auto entry = std::begin(m_groups); - std::advance(entry, targetParent.row()); - - CUndo undo(tr("Copy/Cut & Paste for Lens Flare").toUtf8()); - - for (int i = 0; i < count; i++) - { - auto item = items[i]; - - QString shortName = MakeValidName(*entry->second, item->GetShortName()); - - if (MoveItem(item, targetParent)) - { - RenameItem(item, QString("%1.%2").arg(entry->first).arg(shortName)); - } - } - - return true; - } - - return false; -} - -QMimeData* LibraryItemTreeModel::mimeData(const QModelIndexList& indexes) const -{ - QByteArray array; - - for (auto& index : indexes) - { - auto item = static_cast(index.data(Qt::UserRole).value()); - - if (item) - { - array.append(reinterpret_cast(&item), sizeof(CBaseLibraryItem*)); - } - } - - if (array.isEmpty()) - { - return nullptr; - } - - QMimeData* data = new QMimeData; - data->setData(QStringLiteral("application/x-o3de-libraryitems"), array); - return data; -} - -Qt::DropActions LibraryItemTreeModel::supportedDragActions() const -{ - return Qt::MoveAction; -} - -Qt::DropActions LibraryItemTreeModel::supportedDropActions() const -{ - return Qt::MoveAction; -} - -#include diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.h b/Code/Sandbox/Editor/DatabaseFrameWnd.h deleted file mode 100644 index 71ef50191c..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.h +++ /dev/null @@ -1,250 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -//////////////////////////////////////////////////////////////////////////// -// Crytek Engine Source File. -// Copyright (C), Crytek Studios, 2011. -// ------------------------------------------------------------------------- -// File name: DatabaseFrameWnd.h -// Created: 10/Dec/2012 by Jaesik. -//////////////////////////////////////////////////////////////////////////// -#ifndef CRYINCLUDE_EDITOR_DATABASEFRAMEWND_H -#define CRYINCLUDE_EDITOR_DATABASEFRAMEWND_H - -#if !defined(Q_MOC_RUN) -#include -#include -#include "Undo/IUndoManagerListener.h" -#include "BaseLibrary.h" - -#include -#include -#include -#include -#endif - -class QComboBox; -class QTreeView; -class QMimeData; - -class CBaseLibraryItem; -class CBaseLibraryManager; - -class LibraryListModel; -class LibraryItemTreeModel; - -namespace Ui { - class DatabaseFrameWnd; -} - -class CDatabaseFrameWnd - : public AzQtComponents::DockMainWindow - , public IEditorNotifyListener - , public IUndoManagerListener -{ - Q_OBJECT -public: - CDatabaseFrameWnd(CBaseLibraryManager* pItemManager, QWidget* pParent = nullptr); - virtual ~CDatabaseFrameWnd(); - - enum SortRecursionType - { - SORT_RECURSION_NONE = 1, - SORT_RECURSION_ITEM = 2, - SORT_RECURSION_FULL = 9999 - }; - - virtual void ReloadLibs(); - virtual void ReloadItems(); - virtual void SelectLibrary(const QString& library, bool bForceSelect = false); - virtual void SelectLibrary(CBaseLibrary* pItem, bool bForceSelect = false); - virtual void SelectItem(CBaseLibraryItem* item, bool bForceReload = false); - - virtual CBaseLibrary* FindLibrary(const QString& libraryName); - virtual CBaseLibrary* NewLibrary(const QString& libraryName); - virtual void DeleteLibrary(CBaseLibrary* pLibrary); - virtual void DeleteItem(CBaseLibraryItem* pItem); - - virtual void ReleasePreviewControl(){} - - virtual bool SetItemName(CBaseLibraryItem* item, const QString& groupName, const QString& itemName); - - void DoesItemExist(const QString& itemName, bool& bOutExist) const; - void DoesGroupExist(const QString& groupName, bool& bOutExist) const; - - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event) override; - - void SignalNumUndoRedo(const unsigned int& numUndo, const unsigned int& numRedo) override; - - QString GetSelectedLibraryName() const; - - virtual const char* GetClassName() = 0; - -protected: - int GetComboBoxIndex(CBaseLibrary* pLibrary); - - virtual void OnInitDialog() = 0; - - void showEvent(QShowEvent* event) override; - - void OnUndo(); - void OnRedo(); - - virtual void OnAddLibrary(); - virtual void OnRemoveLibrary(); - virtual void OnAddItem(); - virtual void OnRemoveItem(); - virtual void OnRenameItem(); - virtual void OnChangedLibrary(); - virtual void OnExportLibrary(); - virtual void OnSave(); - virtual void OnReloadLib(); - virtual void OnLoadLibrary(); - - void OnSelChangedItemTree(const QModelIndex& index); - bool eventFilter(QObject* watched, QEvent* event); - - virtual void OnCopy() = 0; - virtual void OnPaste() = 0; - virtual void OnCut(); - virtual void OnClone(); - - void InitTreeCtrl(); - - virtual AssetSelectionModel GetAssetSelectionModel() const = 0; - - void LoadLibrary(); - - QString MakeValidName(const QString& candidateName, AZStd::function cb) const; - - virtual QTreeView* GetTreeCtrl() = 0; - virtual const QTreeView* GetTreeCtrl() const = 0; - -private: - LibraryListModel* m_pLibraryListModel; - QComboBox* m_pLibraryListComboBox; - - bool m_bLibsLoaded; - -protected: - LibraryItemTreeModel* m_pLibraryItemTreeModel; - - //! Selected library. - _smart_ptr m_pLibrary; - - //! Last selected Item. (kept here for compatibility reasons) - // See comments on m_cpoSelectedLibraryItems for more details. - _smart_ptr m_pCurrentItem; - - // A set containing all the currently selected items - // (it's disabled for MOST, but not ALL cases). - // This should be the new standard way of storing selections as - // opposed to the former mean, it allows us to store multiple selections. - // The migration to this new style should be done according to the needs - // for multiple selection. - std::set m_cpoSelectedLibraryItems; - - //! Pointer to item manager. - CBaseLibraryManager* m_pItemManager; - SortRecursionType m_sortRecursionType; - QString m_selectedGroup; - - QScopedPointer ui; - - bool m_initialized; -}; - -class LibraryListModel - : public QAbstractListModel -{ - Q_OBJECT - -public: - LibraryListModel(CBaseLibraryManager* itemManager, QObject* pParent = nullptr); - - int rowCount(const QModelIndex& parent = {}) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - - void Reload(); - - void clear(); - -private: - void LibraryModified(bool bModified); - - CBaseLibraryManager* m_pItemManager; -}; - -class LibraryItemTreeModel - : public QAbstractItemModel -{ - Q_OBJECT - - using Group = std::pair >; - -public: - LibraryItemTreeModel(CDatabaseFrameWnd* pParent); - - QModelIndex parent(const QModelIndex& index) const override; - QModelIndex index(int row, int column, const QModelIndex& parent = {}) const override; - QModelIndex index(CBaseLibraryItem* pItem) const; - - int rowCount(const QModelIndex& parent) const override; - int columnCount(const QModelIndex& parent) const override; - - Qt::ItemFlags flags(const QModelIndex& index) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; - - bool removeRows(int row, int count, const QModelIndex& parent = {}) override; - - QStringList mimeTypes() const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - QMimeData* mimeData(const QModelIndexList& indexes) const override; - - Qt::DropActions supportedDragActions() const override; - Qt::DropActions supportedDropActions() const override; - - void Clear(); - - void Reload(CBaseLibrary* library); - - void Add(CBaseLibraryItem* item); - bool Remove(CBaseLibraryItem* item); - - void Rename(CBaseLibraryItem* item, const QString& groupName, const QString& shortName); - - std::vector ChildItems(const QModelIndex& index) const; - - QString GetFullName(const QModelIndex& index) const; - - QModelIndex FindLibraryItemByFullName(const QString& fullName) const; - bool DoesGroupExist(const QString& groupName) const; - -signals: - void itemRenamed(CBaseLibraryItem* item, const QString& prevFullName); - -protected: - void RenameItem(CBaseLibraryItem* item, const QString& fullName); - QString MakeValidName(const Group& group, const QString& baseName) const; - bool MoveItem(CBaseLibraryItem* item, const QModelIndex& parent); - - CDatabaseFrameWnd* m_dialog; - - std::map > m_groups; -}; - -Q_DECLARE_METATYPE(CBaseLibrary*) - -#endif // CRYINCLUDE_EDITOR_DATABASEFRAMEWND_H diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.qrc b/Code/Sandbox/Editor/DatabaseFrameWnd.qrc deleted file mode 100644 index 37d97f5c9f..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.qrc +++ /dev/null @@ -1,35 +0,0 @@ - - - res/db_library_bar_00.png - res/db_library_bar_01.png - res/db_library_bar_02.png - res/db_library_bar_03.png - res/db_library_bar_04.png - res/db_library_bar_05.png - res/db_standart_00.png - res/db_standart_01.png - res/db_standart_02.png - res/db_standart_03.png - res/db_library_item_bar_00.png - res/db_library_item_bar_01.png - res/db_library_item_bar_02.png - res/db_library_item_bar_03.png - res/db_library_item_bar_04.png - res/db_library_item_bar_05.png - res/db_library_open.svg - res/db_library_save.svg - res/db_library_add.svg - res/db_library_delete.svg - res/db_library_refresh.svg - res/db_library_undo.svg - res/db_library_redo.svg - res/db_library_copy.svg - res/db_library_paste.svg - res/db_library_additem.svg - res/db_library_cloneitem.svg - res/db_library_removeitem.svg - res/db_library_assignitem.svg - res/db_library_getproperties.svg - res/db_library_reload.svg - - diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.ui b/Code/Sandbox/Editor/DatabaseFrameWnd.ui deleted file mode 100644 index 655de74a6e..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.ui +++ /dev/null @@ -1,279 +0,0 @@ - - - DatabaseFrameWnd - - - - 0 - 0 - 633 - 42 - - - - - Lens Flare Toolbar - - - - 32 - 32 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - StandartToolBar - - - - 32 - 32 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - ItemToolBar - - - - 32 - 32 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - - - :/DatabaseFrameWnd/db_library_open.svg:/DatabaseFrameWnd/db_library_open.svg - - - Load Library - - - Load Library - - - - - - :/DatabaseFrameWnd/db_library_save.svg:/DatabaseFrameWnd/db_library_save.svg - - - Save Modified Libraries - - - Save Modified Libraries - - - - - - :/DatabaseFrameWnd/db_library_add.svg:/DatabaseFrameWnd/db_library_add.svg - - - Add Library - - - Add Library - - - - - - :/DatabaseFrameWnd/db_library_delete.svg:/DatabaseFrameWnd/db_library_delete.svg - - - Remove Library - - - Remove Library - - - - - - :/DatabaseFrameWnd/db_library_refresh.svg:/DatabaseFrameWnd/db_library_refresh.svg - - - Reload Library - - - Reload Library - - - - - false - - - - :/DatabaseFrameWnd/db_library_undo.svg:/DatabaseFrameWnd/db_library_undo.svg - - - Undo last operation - - - Undo - - - - - false - - - - :/DatabaseFrameWnd/db_library_redo.svg:/DatabaseFrameWnd/db_library_redo.svg - - - Redo last undo operation - - - Redo - - - - - - :/DatabaseFrameWnd/db_library_copy.svg:/DatabaseFrameWnd/db_library_copy.svg - - - Copy Item - - - Copy Item - - - - - - :/DatabaseFrameWnd/db_library_paste.svg:/DatabaseFrameWnd/db_library_paste.svg - - - Paste Item - - - Paste Item - - - - - - :/DatabaseFrameWnd/db_library_additem.svg:/DatabaseFrameWnd/db_library_additem.svg - - - Add New Item - - - Add New Item - - - - - - :/DatabaseFrameWnd/db_library_cloneitem.svg:/DatabaseFrameWnd/db_library_cloneitem.svg - - - Clone Library Item - - - Clone Library Item - - - - - - :/DatabaseFrameWnd/db_library_removeitem.svg:/DatabaseFrameWnd/db_library_removeitem.svg - - - Remove Item - - - Remove Item - - - - - - :/DatabaseFrameWnd/db_library_assignitem.svg:/DatabaseFrameWnd/db_library_assignitem.svg - - - Assign Item to Selected Objects - - - Assign Item to Selected Objects - - - - - - :/DatabaseFrameWnd/db_library_getproperties.svg:/DatabaseFrameWnd/db_library_getproperties.svg - - - Get Properties From Selection - - - Get Properties From Selection - - - - - - :/DatabaseFrameWnd/db_library_reload.svg:/DatabaseFrameWnd/db_library_reload.svg - - - Reload Item - - - Reload Item - - - - - - diff --git a/Code/Sandbox/Editor/DisplaySettings.cpp b/Code/Sandbox/Editor/DisplaySettings.cpp index bd4372ae70..6454471a80 100644 --- a/Code/Sandbox/Editor/DisplaySettings.cpp +++ b/Code/Sandbox/Editor/DisplaySettings.cpp @@ -22,7 +22,6 @@ // Editor #include "Settings.h" -#include "Material/MaterialManager.h" @@ -87,11 +86,6 @@ void CDisplaySettings::PostInitApply() void CDisplaySettings::SetRenderFlags(int flags) { m_renderFlags = flags; - - if (!GetIEditor()->Get3DEngine()) - { - return; - } } ////////////////////////////////////////////////////////////////////////// @@ -112,30 +106,6 @@ void CDisplaySettings::SetDebugFlags(int flags) //SetCVarInt( "sys_enable_budgetmonitoring",(m_debugFlags&DBG_BUDGET_MONITORING) ? 4:0 ); //SetCVarInt( "Profile",(m_debugFlags&DBG_FRAMEPROFILE) ? 1:0 ); - - if (CMaterialManager* pMaterialManager = GetIEditor()->GetMaterialManager()) - { - int mask = pMaterialManager->GetHighlightMask(); - if (m_debugFlags & DBG_HIGHLIGHT_BREAKABLE) - { - mask |= eHighlight_Breakable; - } - else - { - mask &= ~eHighlight_Breakable; - } - - if (m_debugFlags & DBG_HIGHLIGHT_MISSING_SURFACE_TYPE) - { - mask |= eHighlight_NoSurfaceType; - } - else - { - mask &= ~eHighlight_NoSurfaceType; - } - - pMaterialManager->SetHighlightMask(mask); - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/EditorDefs.h b/Code/Sandbox/Editor/EditorDefs.h index dd86bdf07a..8c78e9644f 100644 --- a/Code/Sandbox/Editor/EditorDefs.h +++ b/Code/Sandbox/Editor/EditorDefs.h @@ -132,7 +132,6 @@ #include #include #include -#include #include #include #include diff --git a/Code/Sandbox/Editor/EditorToolsApplication.cpp b/Code/Sandbox/Editor/EditorToolsApplication.cpp index 97caaf612a..2e3d70795a 100644 --- a/Code/Sandbox/Editor/EditorToolsApplication.cpp +++ b/Code/Sandbox/Editor/EditorToolsApplication.cpp @@ -21,14 +21,12 @@ #include #include #include -#include // Editor #include "MainWindow.h" #include "CryEdit.h" #include "DisplaySettingsPythonFuncs.h" #include "GameEngine.h" -#include "Material/MaterialPythonFuncs.h" #include "PythonEditorFuncs.h" #include "TrackView/TrackViewPythonFuncs.h" #include "Include/IObjectManager.h" @@ -65,7 +63,6 @@ namespace EditorInternal RegisterComponentDescriptor(AzToolsFramework::DisplaySettingsPythonFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::MainWindowEditorFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::ObjectManagerFuncsHandler::CreateDescriptor()); - RegisterComponentDescriptor(AzToolsFramework::MaterialPythonFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::PythonEditorComponent::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::PythonEditorFuncsHandler::CreateDescriptor()); RegisterComponentDescriptor(AzToolsFramework::DisplaySettingsComponent::CreateDescriptor()); @@ -81,7 +78,6 @@ namespace EditorInternal components.emplace_back(azrtti_typeid()); components.emplace_back(azrtti_typeid()); - components.emplace_back(azrtti_typeid()); // Add new Bus-based Python Bindings components.emplace_back(azrtti_typeid()); diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index 9165809c7f..d9344746a2 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -40,7 +40,6 @@ # include #endif // defined(AZ_PLATFORM_WINDOWS) #include // for AzFramework::InputDeviceMouse -#include #include // AzQtComponents @@ -55,7 +54,6 @@ #include // CryCommon -#include #include // AzFramework @@ -98,6 +96,10 @@ #include +#include +#include +#include + AZ_CVAR( bool, ed_visibility_logTiming, false, nullptr, AZ::ConsoleFunctorFlags::Null, "Output the timing of the new IVisibilitySystem query"); @@ -251,11 +253,6 @@ void EditorViewportWidget::resizeEvent(QResizeEvent* event) gEnv->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RESIZE, width(), height()); - if (gEnv->pRenderer) - { - gEnv->pRenderer->EF_DisableTemporalEffects(); - } - // We queue the window resize event because the render overlay may be hidden. // If the render overlay is not visible, the native window that is backing it will // also be hidden, and it will not resize until it becomes visible. @@ -321,8 +318,8 @@ AzToolsFramework::ViewportInteraction::MousePick EditorViewportWidget::BuildMous using namespace AzToolsFramework::ViewportInteraction; MousePick mousePick; - mousePick.m_screenCoordinates = AzFramework::ScreenPoint(point.x(), point.y()); - const auto& ray = m_renderViewport->ViewportScreenToWorldRay(point); + mousePick.m_screenCoordinates = ScreenPointFromQPoint(point); + const auto& ray = m_renderViewport->ViewportScreenToWorldRay(mousePick.m_screenCoordinates); if (ray.has_value()) { mousePick.m_rayOrigin = ray.value().origin; @@ -521,9 +518,6 @@ void EditorViewportWidget::Update() // Render { // TODO: Move out this logic to a controller and refactor to work with Atom - // m_renderer->SetClearColor(Vec3(0.4f, 0.4f, 0.4f)); - // 3D engine stats - GetIEditor()->GetSystem()->RenderBegin(); OnRender(); @@ -548,8 +542,6 @@ void EditorViewportWidget::Update() } } - GetIEditor()->GetSystem()->RenderEnd(m_bRenderStats); - gEnv->pSystem->SetViewCamera(CurCamera); } @@ -1132,14 +1124,14 @@ float EditorViewportWidget::AngleStep() return GetViewManager()->GetGrid()->GetAngleSnap(); } -AZ::Vector3 EditorViewportWidget::PickTerrain(const QPoint& point) +AZ::Vector3 EditorViewportWidget::PickTerrain(const AzFramework::ScreenPoint& point) { FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); - return LYVec3ToAZVec3(ViewToWorld(point, nullptr, true)); + return LYVec3ToAZVec3(ViewToWorld(AzToolsFramework::ViewportInteraction::QPointFromScreenPoint(point), nullptr, true)); } -AZ::EntityId EditorViewportWidget::PickEntity(const QPoint& point) +AZ::EntityId EditorViewportWidget::PickEntity(const AzFramework::ScreenPoint& point) { FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); @@ -1148,7 +1140,7 @@ AZ::EntityId EditorViewportWidget::PickEntity(const QPoint& point) AZ::EntityId entityId; HitContext hitInfo; hitInfo.view = this; - if (HitTest(point, hitInfo)) + if (HitTest(AzToolsFramework::ViewportInteraction::QPointFromScreenPoint(point), hitInfo)) { if (hitInfo.object && (hitInfo.object->GetType() == OBJTYPE_AZENTITY)) { @@ -1174,7 +1166,7 @@ void EditorViewportWidget::FindVisibleEntities(AZStd::vector& visi visibleEntitiesOut.assign(m_entityVisibilityQuery.Begin(), m_entityVisibilityQuery.End()); } -QPoint EditorViewportWidget::ViewportWorldToScreen(const AZ::Vector3& worldPosition) +AzFramework::ScreenPoint EditorViewportWidget::ViewportWorldToScreen(const AZ::Vector3& worldPosition) { return m_renderViewport->ViewportWorldToScreen(worldPosition); } @@ -1234,6 +1226,7 @@ void EditorViewportWidget::SetViewportId(int id) if (ed_useNewCameraSystem) { + AzFramework::ReloadCameraKeyBindings(); m_renderViewport->GetControllerList()->Add(AZStd::make_shared()); } else @@ -1305,26 +1298,8 @@ namespace AZ::ViewportHelpers ////////////////////////////////////////////////////////////////////////// void EditorViewportWidget::OnTitleMenu(QMenu* menu) { - const int nWireframe = gEnv->pConsole->GetCVar("r_wireframe")->GetIVal(); - QAction* action = menu->addAction(tr("Wireframe")); - connect(action, &QAction::triggered, action, []() - { - ICVar* piVar(gEnv->pConsole->GetCVar("r_wireframe")); - int nRenderMode = piVar->GetIVal(); - if (nRenderMode != R_WIREFRAME_MODE) - { - piVar->Set(R_WIREFRAME_MODE); - } - else - { - piVar->Set(R_SOLID_MODE); - } - }); - action->setCheckable(true); - action->setChecked(nWireframe == R_WIREFRAME_MODE); - const bool bDisplayLabels = GetIEditor()->GetDisplaySettings()->IsDisplayLabels(); - action = menu->addAction(tr("Labels")); + QAction* action = menu->addAction(tr("Labels")); connect(action, &QAction::triggered, this, [bDisplayLabels] {GetIEditor()->GetDisplaySettings()->DisplayLabels(!bDisplayLabels); }); action->setCheckable(true); @@ -1556,7 +1531,6 @@ void EditorViewportWidget::ToggleCameraObject() { if (m_viewSourceType == ViewSourceType::SequenceCamera) { - gEnv->p3DEngine->GetPostEffectBaseGroup()->SetParam("Dof_Active", 0.0f); ResetToViewSourceType(ViewSourceType::LegacyCamera); } else @@ -1626,8 +1600,8 @@ void EditorViewportWidget::keyPressEvent(QKeyEvent* event) QCoreApplication::sendEvent(GetIEditor()->GetEditorMainWindow(), event); } - // NOTE: we keep track of keypresses and releases explicitly because the OS/Qt will insert a slight delay between sending - // keyevents when the key is held down. This is standard, but makes responding to key events for game style input silly + // NOTE: we keep track of key presses and releases explicitly because the OS/Qt will insert a slight delay between sending + // key events when the key is held down. This is standard, but makes responding to key events for game style input silly // because we want the movement to be butter smooth. if (!event->isAutoRepeat()) { @@ -2001,7 +1975,7 @@ Vec3 EditorViewportWidget::WorldToView3D(const Vec3& wp, [[maybe_unused]] int nF ////////////////////////////////////////////////////////////////////////// QPoint EditorViewportWidget::WorldToView(const Vec3& wp) const { - return m_renderViewport->ViewportWorldToScreen(LYVec3ToAZVec3(wp)); + return AzToolsFramework::ViewportInteraction::QPointFromScreenPoint(m_renderViewport->ViewportWorldToScreen(LYVec3ToAZVec3(wp))); } ////////////////////////////////////////////////////////////////////////// QPoint EditorViewportWidget::WorldToViewParticleEditor(const Vec3& wp, int width, int height) const @@ -2023,7 +1997,8 @@ QPoint EditorViewportWidget::WorldToViewParticleEditor(const Vec3& wp, int width } ////////////////////////////////////////////////////////////////////////// -Vec3 EditorViewportWidget::ViewToWorld(const QPoint& vp, bool* collideWithTerrain, bool onlyTerrain, bool bSkipVegetation, bool bTestRenderMesh, bool* collideWithObject) const +Vec3 EditorViewportWidget::ViewToWorld( + const QPoint& vp, bool* collideWithTerrain, bool onlyTerrain, bool bSkipVegetation, bool bTestRenderMesh, bool* collideWithObject) const { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Editor); @@ -2034,7 +2009,7 @@ Vec3 EditorViewportWidget::ViewToWorld(const QPoint& vp, bool* collideWithTerrai AZ_UNUSED(bSkipVegetation) AZ_UNUSED(collideWithObject) - auto ray = m_renderViewport->ViewportScreenToWorldRay(vp); + auto ray = m_renderViewport->ViewportScreenToWorldRay(AzToolsFramework::ViewportInteraction::ScreenPointFromQPoint(vp)); if (!ray.has_value()) { return Vec3(0, 0, 0); @@ -2135,23 +2110,29 @@ bool EditorViewportWidget::AdjustObjectPosition(const ray_hit& hit, Vec3& outNor ////////////////////////////////////////////////////////////////////////// bool EditorViewportWidget::RayRenderMeshIntersection(IRenderMesh* pRenderMesh, const Vec3& vInPos, const Vec3& vInDir, Vec3& vOutPos, Vec3& vOutNormal) const { - SRayHitInfo hitInfo; + AZ_UNUSED(pRenderMesh); + AZ_UNUSED(vInPos); + AZ_UNUSED(vInDir); + AZ_UNUSED(vOutPos); + AZ_UNUSED(vOutNormal); + return false; + /*SRayHitInfo hitInfo; hitInfo.bUseCache = false; hitInfo.bInFirstHit = false; hitInfo.inRay.origin = vInPos; hitInfo.inRay.direction = vInDir.GetNormalized(); hitInfo.inReferencePoint = vInPos; hitInfo.fMaxHitDistance = 0; - bool bRes = GetIEditor()->Get3DEngine()->RenderMeshRayIntersection(pRenderMesh, hitInfo, nullptr); + bool bRes = ???->RenderMeshRayIntersection(pRenderMesh, hitInfo, nullptr); vOutPos = hitInfo.vHitPos; vOutNormal = hitInfo.vHitNormal; - return bRes; + return bRes;*/ } void EditorViewportWidget::UnProjectFromScreen(float sx, float sy, float sz, float* px, float* py, float* pz) const { AZ::Vector3 wp; - wp = m_renderViewport->ViewportScreenToWorld({(int)sx, m_rcClient.bottom() - ((int)sy)}, sz).value_or(wp); + wp = m_renderViewport->ViewportScreenToWorld(AzFramework::ScreenPoint{(int)sx, m_rcClient.bottom() - ((int)sy)}, sz).value_or(wp); *px = wp.GetX(); *py = wp.GetY(); *pz = wp.GetZ(); @@ -2159,9 +2140,9 @@ void EditorViewportWidget::UnProjectFromScreen(float sx, float sy, float sz, flo void EditorViewportWidget::ProjectToScreen(float ptx, float pty, float ptz, float* sx, float* sy, float* sz) const { - QPoint screenPosition = m_renderViewport->ViewportWorldToScreen(AZ::Vector3{ptx, pty, ptz}); - *sx = screenPosition.x(); - *sy = screenPosition.y(); + AzFramework::ScreenPoint screenPosition = m_renderViewport->ViewportWorldToScreen(AZ::Vector3{ptx, pty, ptz}); + *sx = screenPosition.m_x; + *sy = screenPosition.m_y; *sz = 0.f; } @@ -2416,10 +2397,6 @@ void EditorViewportWidget::SetDefaultCamera() return; } ResetToViewSourceType(ViewSourceType::None); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetPostEffectBaseGroup()->SetParam("Dof_Active", 0.0f); - } GetViewManager()->SetCameraObjectId(m_cameraObjectId); SetName(m_defaultViewName); SetViewTM(m_defaultViewTM); diff --git a/Code/Sandbox/Editor/EditorViewportWidget.h b/Code/Sandbox/Editor/EditorViewportWidget.h index 472f7e3c62..09474200f1 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.h +++ b/Code/Sandbox/Editor/EditorViewportWidget.h @@ -196,15 +196,15 @@ public: bool ShowGrid(); bool AngleSnappingEnabled(); float AngleStep(); - QPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition); + AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition); // AzToolsFramework::ViewportFreezeRequestBus bool IsViewportInputFrozen() override; void FreezeViewportInput(bool freeze) override; // AzToolsFramework::MainEditorViewportInteractionRequestBus - AZ::EntityId PickEntity(const QPoint& point) override; - AZ::Vector3 PickTerrain(const QPoint& point) override; + AZ::EntityId PickEntity(const AzFramework::ScreenPoint& point) override; + AZ::Vector3 PickTerrain(const AzFramework::ScreenPoint& point) override; float TerrainHeight(const AZ::Vector2& position) override; void FindVisibleEntities(AZStd::vector& visibleEntitiesOut) override; bool ShowingWorldSpace() override; @@ -481,10 +481,6 @@ protected: OBB m_GroundOBB; Vec3 m_GroundOBBPos; - //------------------------------------------- - // Render options. - bool m_bRenderStats = true; - // Index of camera objects. mutable GUID m_cameraObjectId; mutable AZ::EntityId m_viewEntityId; @@ -557,8 +553,7 @@ private: void PushDisableRendering(); void PopDisableRendering(); bool IsRenderingDisabled() const; - AzToolsFramework::ViewportInteraction::MousePick BuildMousePickInternal( - const QPoint& point) const; + AzToolsFramework::ViewportInteraction::MousePick BuildMousePickInternal(const QPoint& point) const; void RestoreViewportAfterGameMode(); void UpdateCameraFromViewportContext(); diff --git a/Code/Sandbox/Editor/EnvironmentPanel.cpp b/Code/Sandbox/Editor/EnvironmentPanel.cpp deleted file mode 100644 index f71babbff6..0000000000 --- a/Code/Sandbox/Editor/EnvironmentPanel.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "EnvironmentPanel.h" - -// Editor -#include "GameEngine.h" -#include "CryEditDoc.h" - -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -#include -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - -///////////////////////////////////////////////////////////////////////////// -// CEnvironmentPanel dialog - -CEnvironmentPanel::CEnvironmentPanel(QWidget* pParent /*=nullptr*/) - : QWidget(pParent) - , ui(new Ui::CEnvironmentPanel) -{ - XmlNodeRef node = GetIEditor()->GetDocument()->GetEnvironmentTemplate(); - - m_onSetCallback = AZStd::bind(&CCryEditDoc::OnEnvironmentPropertyChanged, GetIEditor()->GetDocument(), AZStd::placeholders::_1); - - ui->setupUi(this); - ui->m_wndProps->Setup(); - ui->m_wndProps->CreateItems(node, m_varBlock, &m_onSetCallback, true); - ui->m_wndProps->RebuildCtrl(false); - ui->m_wndProps->ExpandAll(); - connect(ui->APPLYBTN, &QPushButton::clicked, this, &CEnvironmentPanel::OnBnClickedApply); -} - -CEnvironmentPanel::~CEnvironmentPanel() -{ -} - -////////////////////////////////////////////////////////////////////////// -void CEnvironmentPanel::OnBnClickedApply() -{ - GetIEditor()->GetGameEngine()->ReloadEnvironment(); -} diff --git a/Code/Sandbox/Editor/EnvironmentPanel.h b/Code/Sandbox/Editor/EnvironmentPanel.h deleted file mode 100644 index ff4594a502..0000000000 --- a/Code/Sandbox/Editor/EnvironmentPanel.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_ENVIRONMENTPANEL_H -#define CRYINCLUDE_EDITOR_ENVIRONMENTPANEL_H - -#pragma once -// EnvironmentPanel.h : header file -// - -#include "Util/Variable.h" - -#include -#include - -///////////////////////////////////////////////////////////////////////////// -// CEnvironmentPanel dialog -namespace Ui { - class CEnvironmentPanel; -} - -class CEnvironmentPanel - : public QWidget -{ - // Construction -public: - CEnvironmentPanel(QWidget* pParent = nullptr); // standard constructor - ~CEnvironmentPanel(); - - // Implementation -protected: - CVarBlockPtr m_varBlock; - -public: - void OnBnClickedApply(); - -private: - QScopedPointer ui; - - IVariable::OnSetCallback m_onSetCallback; -}; - -#endif // CRYINCLUDE_EDITOR_ENVIRONMENTPANEL_H diff --git a/Code/Sandbox/Editor/EnvironmentPanel.ui b/Code/Sandbox/Editor/EnvironmentPanel.ui deleted file mode 100644 index b808fc93fc..0000000000 --- a/Code/Sandbox/Editor/EnvironmentPanel.ui +++ /dev/null @@ -1,56 +0,0 @@ - - - CEnvironmentPanel - - - - 0 - 0 - 264 - 259 - - - - - - - - 0 - 200 - - - - - - - - Apply - - - - - - - Qt::Horizontal - - - - 162 - 20 - - - - - - - - - ReflectedPropertyControl - QWidget -
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.h
- 1 -
-
- - -
diff --git a/Code/Sandbox/Editor/ErrorReport.h b/Code/Sandbox/Editor/ErrorReport.h index f78410be62..b13f8ae120 100644 --- a/Code/Sandbox/Editor/ErrorReport.h +++ b/Code/Sandbox/Editor/ErrorReport.h @@ -19,7 +19,6 @@ #pragma once // forward declarations. -class CMaterial; class CParticleItem; #include "BaseLibraryItem.h" diff --git a/Code/Sandbox/Editor/Export/ExportManager.cpp b/Code/Sandbox/Editor/Export/ExportManager.cpp index b41872595a..2d0f784647 100644 --- a/Code/Sandbox/Editor/Export/ExportManager.cpp +++ b/Code/Sandbox/Editor/Export/ExportManager.cpp @@ -22,8 +22,6 @@ #include // Editor -#include "Geometry/EdGeometry.h" -#include "Material/Material.h" #include "ViewManager.h" #include "OBJExporter.h" #include "OCMExporter.h" @@ -42,6 +40,9 @@ #include "Resource.h" #include "Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h" +#include +#include + namespace { void SetTexture(Export::TPath& outName, IRenderShaderResources* pRes, int nSlot) @@ -79,47 +80,6 @@ Export::CMesh::CMesh() } -void Export::CMesh::SetMaterial(CMaterial* pMtl, CBaseObject* pBaseObj) -{ - if (!pMtl) - { - cry_strcpy(material.name, pBaseObj->GetName().toUtf8().data()); - return; - } - - cry_strcpy(material.name, pMtl->GetFullName().toUtf8().data()); - - _smart_ptr matInfo = pMtl->GetMatInfo(); - IRenderShaderResources* pRes = matInfo->GetShaderItem().m_pShaderResources; - if (!pRes) - { - return; - } - - ColorF difColor = pRes->GetColorValue(EFTT_DIFFUSE); - material.diffuse.r = difColor.r; - material.diffuse.g = difColor.g; - material.diffuse.b = difColor.b; - material.diffuse.a = difColor.a; - - ColorF specColor = pRes->GetColorValue(EFTT_SPECULAR); - material.specular.r = specColor.r; - material.specular.g = specColor.g; - material.specular.b = specColor.b; - material.specular.a = specColor.a; - - material.opacity = pRes->GetStrengthValue(EFTT_OPACITY); - material.smoothness = pRes->GetStrengthValue(EFTT_SMOOTHNESS); - - SetTexture(material.mapDiffuse, pRes, EFTT_DIFFUSE); - SetTexture(material.mapSpecular, pRes, EFTT_SPECULAR); - SetTexture(material.mapOpacity, pRes, EFTT_OPACITY); - SetTexture(material.mapNormals, pRes, EFTT_NORMALS); - SetTexture(material.mapDecal, pRes, EFTT_DECAL_OVERLAY); - SetTexture(material.mapDisplacement, pRes, EFTT_HEIGHT); -} - - ////////////////////////////////////////////////////////// // CObject Export::CObject::CObject(const char* pName) @@ -416,18 +376,6 @@ void CExportManager::AddMesh(Export::CObject* pObj, const IIndexedMesh* pIndMesh pObj->m_texCoords.push_back(tc); } - CMaterial* pMtl = 0; - - if (m_pBaseObj) - { - pMtl = m_pBaseObj->GetRenderMaterial(); - } - - if (pMtl) - { - pObj->SetMaterialName(pMtl->GetFullName().toUtf8().data()); - } - if (pIndMesh->GetSubSetCount() && !(pIndMesh->GetSubSetCount() == 1 && pIndMesh->GetSubSet(0).nNumIndices == 0)) { for (int i = 0; i < pIndMesh->GetSubSetCount(); ++i) @@ -447,23 +395,6 @@ void CExportManager::AddMesh(Export::CObject* pObj, const IIndexedMesh* pIndMesh pMesh->m_faces.push_back(face); } - if (pMtl) - { - if (pMtl->IsMultiSubMaterial()) - { - CMaterial* pSubMtl = 0; - if (sms.nMatID < pMtl->GetSubMaterialCount()) - { - pSubMtl = pMtl->GetSubMaterial(sms.nMatID); - } - pMesh->SetMaterial(pSubMtl, m_pBaseObj); - } - else - { - pMesh->SetMaterial(pMtl, m_pBaseObj); - } - } - pObj->m_meshes.push_back(pMesh); } } @@ -497,10 +428,6 @@ void CExportManager::AddMesh(Export::CObject* pObj, const IIndexedMesh* pIndMesh } } - if (m_pBaseObj && pMtl) - { - pMesh->SetMaterial(pMtl, m_pBaseObj); - } pObj->m_meshes.push_back(pMesh); } } @@ -569,53 +496,6 @@ bool CExportManager::AddStatObj(Export::CObject* pObj, IStatObj* pStatObj, Matri bool CExportManager::AddMeshes(Export::CObject* pObj) { - CEdGeometry* pEdGeom = m_pBaseObj->GetGeometry(); - IIndexedMesh* pIndMesh = 0; - - if (pEdGeom) - { - size_t idx = 0; - size_t nextIdx = 0; - do - { - pIndMesh = 0; - if (m_isOccluder) - { - if (pEdGeom->GetIStatObj() && pEdGeom->GetIStatObj()->GetLodObject(2)) - { - pIndMesh = pEdGeom->GetIStatObj()->GetLodObject(2)->GetIndexedMesh(true); - } - if (!pIndMesh && pEdGeom->GetIStatObj() && pEdGeom->GetIStatObj()->GetLodObject(1)) - { - pIndMesh = pEdGeom->GetIStatObj()->GetLodObject(1)->GetIndexedMesh(true); - } - } - - if (!pIndMesh) - { - pIndMesh = pEdGeom->GetIndexedMesh(idx); - nextIdx++; - } - - if (!pIndMesh) - { - break; - } - - Matrix34 tm; - pEdGeom->GetTM(&tm, idx); - Matrix34A objTM = tm; - AddMesh(pObj, pIndMesh, &objTM); - idx = nextIdx; - } - while (pIndMesh && idx); - - if (idx > 0) - { - return true; - } - } - if (m_pBaseObj->GetType() == OBJTYPE_AZENTITY) { CEntityObject* pEntityObject = (CEntityObject*)m_pBaseObj; @@ -623,11 +503,7 @@ bool CExportManager::AddMeshes(Export::CObject* pObj) if (pEngineNode) { - if (m_isPrecaching) - { - GetIEditor()->Get3DEngine()->PrecacheRenderNode(pEngineNode, 0); - } - else + if (!m_isPrecaching) { for (int i = 0; i < pEngineNode->GetSlotCount(); ++i) { @@ -1166,35 +1042,6 @@ bool CExportManager::AddSelectedEntityObjects() return true; } - -bool CExportManager::AddSelectedObjects() -{ - CSelectionGroup* pSelection = GetIEditor()->GetSelection(); - - int numObjects = pSelection->GetCount(); - if (numObjects > m_data.m_objects.size()) - { - m_data.m_objects.reserve(numObjects + 1); // +1 for terrain - } - // First run pipeline to precache geometry - m_isPrecaching = true; - for (int i = 0; i < numObjects; i++) - { - AddObject(pSelection->GetObject(i)); - } - - GetIEditor()->Get3DEngine()->ProposeContentPrecache(); - - // Repeat pipeline to collect geometry - m_isPrecaching = false; - for (int i = 0; i < numObjects; i++) - { - AddObject(pSelection->GetObject(i)); - } - - return true; -} - bool CExportManager::AddSelectedRegionObjects() { AABB box; @@ -1219,8 +1066,6 @@ bool CExportManager::AddSelectedRegionObjects() AddObject(objects[i]); } - GetIEditor()->Get3DEngine()->ProposeContentPrecache(); - // Repeat pipeline to collect geometry m_isPrecaching = false; for (size_t i = 0; i < numObjects; ++i) @@ -1260,7 +1105,7 @@ bool CExportManager::ExportToFile(const char* filename, bool bClearDataAfterExpo } -bool CExportManager::Export(const char* defaultName, const char* defaultExt, const char* defaultPath, bool isSelectedObjects, bool isSelectedRegionObjects, bool isOccluder, bool bAnimationExport) +bool CExportManager::Export(const char* defaultName, const char* defaultExt, const char* defaultPath, [[maybe_unused]] bool isSelectedObjects, bool isSelectedRegionObjects, bool isOccluder, bool bAnimationExport) { m_bAnimationExport = bAnimationExport; @@ -1304,10 +1149,6 @@ bool CExportManager::Export(const char* defaultName, const char* defaultExt, con if (m_bAnimationExport || CFileUtil::SelectSaveFile(filters, defaultExt, defaultPath, newFilename)) { WaitCursor wait; - if (isSelectedObjects) - { - AddSelectedObjects(); - } if (isSelectedRegionObjects) { AddSelectedRegionObjects(); diff --git a/Code/Sandbox/Editor/Export/ExportManager.h b/Code/Sandbox/Editor/Export/ExportManager.h index 8904ef08ed..04ee5f73ca 100644 --- a/Code/Sandbox/Editor/Export/ExportManager.h +++ b/Code/Sandbox/Editor/Export/ExportManager.h @@ -43,8 +43,6 @@ namespace Export virtual int GetFaceCount() const { return m_faces.size(); } virtual const Face* GetFaceBuffer() const { return m_faces.size() ? &m_faces[0] : 0; } - void SetMaterial(CMaterial* pMtl, CBaseObject* pBaseObj); - private: std::vector m_faces; @@ -130,10 +128,6 @@ public: bool Export(const char* defaultName, const char* defaultExt = "", const char* defaultPath = "", bool isSelectedObjects = true, bool isSelectedRegionObjects = false, bool isOccluder = false, bool bAnimationExport = false); - //! Add to Export Data geometry from selected objects - //! return true if succeed, otherwise false - bool AddSelectedObjects(); - bool AddSelectedEntityObjects(); //! Add to Export Data geometry from objects inside selected region volume diff --git a/Code/Sandbox/Editor/GameEngine.cpp b/Code/Sandbox/Editor/GameEngine.cpp index d5aec9e7d4..073684eaad 100644 --- a/Code/Sandbox/Editor/GameEngine.cpp +++ b/Code/Sandbox/Editor/GameEngine.cpp @@ -34,15 +34,11 @@ // Editor #include "IEditorImpl.h" #include "CryEditDoc.h" -#include "Geometry/EdMesh.h" -#include "Mission.h" #include "Settings.h" // CryCommon -#include #include #include -#include #include #include @@ -283,7 +279,6 @@ AZ_POP_DISABLE_WARNING AZ::Interface::Unregister(this); GetIEditor()->UnregisterNotifyListener(this); m_pISystem->GetIMovieSystem()->SetCallback(NULL); - CEdMesh::ReleaseAll(); if (m_gameDll) { @@ -493,13 +488,6 @@ AZ::Outcome CGameEngine::Init( SetEditorCoreEnvironment(gEnv); - if (gEnv - && gEnv->p3DEngine - && gEnv->p3DEngine->GetTimeOfDay()) - { - gEnv->p3DEngine->GetTimeOfDay()->BeginEditMode(); - } - if (gEnv && gEnv->pMovieSystem) { gEnv->pMovieSystem->EnablePhysicsEvents(m_bSimulationMode); @@ -549,26 +537,14 @@ void CGameEngine::SetLevelPath(const QString& path) { m_levelExtension = defaultExtension; } - - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->SetLevelPath(m_levelPath.toUtf8().data()); - } -} - -void CGameEngine::SetMissionName(const QString& mission) -{ - m_missionName = mission; } bool CGameEngine::LoadLevel( - const QString& mission, [[maybe_unused]] bool bDeleteAIGraph, bool bReleaseResources) { LOADING_TIME_PROFILE_SECTION(GetIEditor()->GetSystem()); m_bLevelLoaded = false; - m_missionName = mission; CLogFile::FormatLine("Loading map '%s' into engine...", m_levelPath.toUtf8().data()); // Switch the current directory back to the Primary CD folder first. // The engine might have trouble to find some files when the current @@ -607,92 +583,26 @@ bool CGameEngine::LoadLevel( } - // Load level in 3d engine. - if (gEnv->p3DEngine && !gEnv->p3DEngine->InitLevelForEditor(m_levelPath.toUtf8().data(), m_missionName.toUtf8().data())) - { - CLogFile::WriteLine("ERROR: Can't load level !"); - QMessageBox::critical(QApplication::activeWindow(), QString(), QObject::tr("ERROR: Can't load level !")); - return false; - } - // Audio: notify audio of level loading start? GetIEditor()->GetObjectManager()->SendEvent(EVENT_REFRESH); m_bLevelLoaded = true; - if (!bReleaseResources) - { - ReloadEnvironment(); - } - return true; } bool CGameEngine::ReloadLevel() { - if (!LoadLevel(GetMissionName(), false, false)) - { - return false; - } - - return true; -} - -bool CGameEngine::LoadMission(const QString& mission) -{ - if (!IsLevelLoaded()) - { - return false; - } - - if (mission != m_missionName) - { - m_missionName = mission; - gEnv->p3DEngine->LoadMissionDataFromXMLNode(m_missionName.toUtf8().data()); - } - - return true; -} - -bool CGameEngine::ReloadEnvironment() -{ - if (!gEnv->p3DEngine) + if (!LoadLevel(false, false)) { return false; } - if (!IsLevelLoaded() && !m_bJustCreated) - { - return false; - } - - if (!GetIEditor()->GetDocument()) - { - return false; - } - - XmlNodeRef env = XmlHelpers::CreateXmlNode("Environment"); - CXmlTemplate::SetValues(GetIEditor()->GetDocument()->GetEnvironmentTemplate(), env); - - // Notify mission that environment may be changed. - GetIEditor()->GetDocument()->GetCurrentMission()->OnEnvironmentChange(); - - QString xmlStr = QString::fromLatin1(env->getXML()); - - // Reload level data in engine. - gEnv->p3DEngine->LoadEnvironmentSettingsFromXML(env); - return true; } void CGameEngine::SwitchToInGame() { - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->DisablePostEffects(); - gEnv->p3DEngine->ResetPostEffects(); - } - auto streamer = AZ::Interface::Get(); if (streamer) { @@ -707,11 +617,6 @@ void CGameEngine::SwitchToInGame() m_pISystem->SetThreadState(ESubsys_Physics, false); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->ResetParticlesAndDecals(); - } - m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(true); m_bInGameMode = true; @@ -721,10 +626,6 @@ void CGameEngine::SwitchToInGame() pRuler->SetActive(false); } - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetTimeOfDay()->EndEditMode(); - } gEnv->pSystem->GetViewCamera().SetMatrix(m_playerViewTM); // Disable accelerators. @@ -760,24 +661,9 @@ void CGameEngine::SwitchToInEditor() m_pISystem->SetThreadState(ESubsys_Physics, false); - if (gEnv->p3DEngine) - { - // Reset 3d engine effects - gEnv->p3DEngine->DisablePostEffects(); - gEnv->p3DEngine->ResetPostEffects(); - gEnv->p3DEngine->ResetParticlesAndDecals(); - } - CViewport* pGameViewport = GetIEditor()->GetViewManager()->GetGameViewport(); m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(m_bSimulationMode); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetTimeOfDay()->BeginEditMode(); - - // this has to be done before the RemoveSink() call, or else some entities may not be removed - gEnv->p3DEngine->GetDeferredPhysicsEventManager()->ClearDeferredEvents(); - } // Enable accelerators. GetIEditor()->EnableAcceleratos(true); @@ -865,7 +751,6 @@ void CGameEngine::SetGameMode(bool bInGame) // Ignore updates while changing in and out of game mode m_bIgnoreUpdates = true; - LockResources(); // Switching modes will destroy the current AzFramework::EntityConext which may contain // data the queued events hold on to, so execute all queued events before switching. @@ -891,7 +776,6 @@ void CGameEngine::SetGameMode(bool bInGame) GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_EDITOR_GAME_MODE_CHANGED, bInGame, 0); - UnlockResources(); m_bIgnoreUpdates = false; GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_GAME_MODE_SWITCH_END, bInGame, 0); @@ -906,11 +790,6 @@ void CGameEngine::SetSimulationMode(bool enabled, bool bOnlyPhysics) m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(enabled); - if (!bOnlyPhysics) - { - LockResources(); - } - if (enabled) { CRuler* pRuler = GetIEditor()->GetRuler(); @@ -935,35 +814,12 @@ void CGameEngine::SetSimulationMode(bool enabled, bool bOnlyPhysics) if (m_bSimulationMode) { - if (!bOnlyPhysics) - { - if (m_pISystem->GetI3DEngine()) - { - m_pISystem->GetI3DEngine()->ResetPostEffects(); - } - - GetIEditor()->SetConsoleVar("ai_ignoreplayer", 1); - //GetIEditor()->SetConsoleVar( "ai_soundperception",0 ); - } - // [Anton] the order of the next 3 calls changed, since, EVENT_INGAME loads physics state (if any), // and Reset should be called before it GetIEditor()->GetObjectManager()->SendEvent(EVENT_INGAME); } else { - if (!bOnlyPhysics) - { - GetIEditor()->SetConsoleVar("ai_ignoreplayer", 0); - //GetIEditor()->SetConsoleVar( "ai_soundperception",1 ); - - if (m_pISystem->GetI3DEngine()) - { - m_pISystem->GetI3DEngine()->ResetPostEffects(); - } - } - - GetIEditor()->GetObjectManager()->SendEvent(EVENT_OUTOFGAME); } @@ -983,23 +839,9 @@ void CGameEngine::SetSimulationMode(bool enabled, bool bOnlyPhysics) AzToolsFramework::EditorEntityContextRequestBus::Broadcast(&AzToolsFramework::EditorEntityContextRequestBus::Events::StartPlayInEditor); } - if (!bOnlyPhysics) - { - UnlockResources(); - } - AzFramework::InputChannelRequestBus::Broadcast(&AzFramework::InputChannelRequests::ResetState); } -void CGameEngine::ResetResources() -{ - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->UnloadLevel(); - } - -} - void CGameEngine::SetPlayerViewMatrix(const Matrix34& tm, [[maybe_unused]] bool bEyePos) { m_playerViewTM = tm; @@ -1107,24 +949,6 @@ void CGameEngine::OnEditorNotifyEvent(EEditorNotifyEvent event) { switch (event) { - case eNotify_OnBeginNewScene: - case eNotify_OnBeginSceneOpen: - { - ResetResources(); - } - break; - case eNotify_OnEndSceneOpen: - case eNotify_OnEndTerrainRebuild: - { - } - case eNotify_OnEndNewScene: // intentional fall-through? - { - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->PostLoadLevel(); - } - } - break; case eNotify_OnSplashScreenDestroyed: { if (m_pSystemUserCallback != NULL) @@ -1136,22 +960,6 @@ void CGameEngine::OnEditorNotifyEvent(EEditorNotifyEvent event) } } -void CGameEngine::LockResources() -{ - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->LockCGFResources(); - } -} - -void CGameEngine::UnlockResources() -{ - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->UnlockCGFResources(); - } -} - void CGameEngine::OnTerrainModified(const Vec2& modPosition, float modAreaRadius, bool fullTerrain) { INavigationSystem* pNavigationSystem = nullptr; // INavigationSystem will be converted to an AZInterface (LY-111343) diff --git a/Code/Sandbox/Editor/GameEngine.h b/Code/Sandbox/Editor/GameEngine.h index 366ec42f72..b59e2c9ac8 100644 --- a/Code/Sandbox/Editor/GameEngine.h +++ b/Code/Sandbox/Editor/GameEngine.h @@ -89,15 +89,10 @@ public: //! Load new terrain level into 3d engine. //! Also load AI triangulation for this level. bool LoadLevel( - const QString& mission, bool bDeleteAIGraph, bool bReleaseResources); //!* Reload level if it was already loaded. bool ReloadLevel(); - //! Load new mission. - bool LoadMission(const QString& mission); - //! Reload environment settings in currently loaded level. - bool ReloadEnvironment(); //! Request to switch In/Out of game mode on next update. //! The switch will happen when no sub systems are currently being updated. //! @param inGame When true editor switch to game mode. @@ -111,14 +106,10 @@ public: bool IsLevelLoaded() const { return m_bLevelLoaded; }; //! Assign new level path name. void SetLevelPath(const QString& path); - //! Assign new current mission name. - void SetMissionName(const QString& mission); //! Return name of currently loaded level. const QString& GetLevelName() const { return m_levelName; }; //! Return extension of currently loaded level. const QString& GetLevelExtension() const { return m_levelExtension; }; - //! Return name of currently active mission. - const QString& GetMissionName() const { return m_missionName; }; //! Get fully specified level path. const QString& GetLevelPath() const { return m_levelPath; }; //! Query if engine is in game mode. @@ -142,9 +133,6 @@ public: //! Called every frame. void Update(); virtual void OnEditorNotifyEvent(EEditorNotifyEvent event); - void LockResources(); - void UnlockResources(); - void ResetResources(); void OnTerrainModified(const Vec2& modPosition, float modAreaRadius, bool fullTerrain); void OnAreaModified(const AABB& modifiedArea); @@ -179,7 +167,6 @@ private: CLogFile m_logFile; QString m_levelName; QString m_levelExtension; - QString m_missionName; QString m_levelPath; QString m_MOD; bool m_bLevelLoaded; diff --git a/Code/Sandbox/Editor/GameExporter.cpp b/Code/Sandbox/Editor/GameExporter.cpp index 8a93dbedce..31f3fafe84 100644 --- a/Code/Sandbox/Editor/GameExporter.cpp +++ b/Code/Sandbox/Editor/GameExporter.cpp @@ -24,19 +24,13 @@ #include "GameExporter.h" #include "GameEngine.h" #include "CryEditDoc.h" -#include "Mission.h" #include "ShaderCache.h" #include "UsedResources.h" -#include "Material/MaterialManager.h" -#include "Material/MaterialLibrary.h" #include "WaitProgress.h" #include "Util/CryMemFile.h" #include "Objects/ObjectManager.h" #include "Objects/EntityObject.h" -#include "LensFlareEditor/LensFlareManager.h" -#include "LensFlareEditor/LensFlareLibrary.h" -#include "LensFlareEditor/LensFlareItem.h" #include @@ -136,13 +130,6 @@ bool CGameExporter::Export(unsigned int flags, [[maybe_unused]] EEndian eExportE m_levelPath = Path::RemoveBackslash(sLevelPath); QString rootLevelPath = Path::AddSlash(pGameEngine->GetLevelPath()); - // Make sure we unload any unused CGFs before exporting so that they don't end up in - // the level data. - if (pEditor->Get3DEngine()) - { - pEditor->Get3DEngine()->FreeUnusedCGFResources(); - } - CCryEditDoc* pDocument = pEditor->GetDocument(); if (flags & eExp_Fast) @@ -196,8 +183,6 @@ bool CGameExporter::Export(unsigned int flags, [[maybe_unused]] EEndian eExportE //////////////////////////////////////////////////////////////////////// if (exportSuccessful) { - ExportVisAreas(sLevelPath.toUtf8().data(), eExportEndian); - //////////////////////////////////////////////////////////////////////// // Exporting map setttings //////////////////////////////////////////////////////////////////////// @@ -210,7 +195,6 @@ bool CGameExporter::Export(unsigned int flags, [[maybe_unused]] EEndian eExportE ExportLevelInfo(sLevelPath); - ExportLevelLensFlares(sLevelPath); ExportLevelResourceList(sLevelPath); ExportLevelUsedResourceList(sLevelPath); ExportLevelShaderCache(sLevelPath); @@ -260,47 +244,6 @@ bool CGameExporter::Export(unsigned int flags, [[maybe_unused]] EEndian eExportE return exportSuccessful; } - -////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportVisAreas(const char* pszGamePath, EEndian eExportEndian) -{ - char szFileOutputPath[_MAX_PATH]; - - // export visareas - IEditor* pEditor = GetIEditor(); - - // remove old files - sprintf_s(szFileOutputPath, "%s%s", pszGamePath, COMPILED_VISAREA_MAP_FILE_NAME); - m_levelPak.m_pakFile.RemoveFile(szFileOutputPath); - - SHotUpdateInfo exportInfo; - I3DEngine* p3DEngine = pEditor->Get3DEngine(); - - if (p3DEngine && (eExportEndian == GetPlatformEndian())) // skip second export, this data is common for PC and consoles - { - std::vector* pTempBrushTable = NULL; - std::vector<_smart_ptr>* pTempMatsTable = NULL; - std::vector* pTempVegGroupTable = NULL; - - // export visareas - CLogFile::WriteLine("Exporting indoors..."); - pEditor->SetStatusText("Exporting indoors..."); - if (IVisAreaManager* pVisAreaManager = p3DEngine->GetIVisAreaManager()) - { - if (int nSize = pVisAreaManager->GetCompiledDataSize()) - { // get visareas data from 3dengine and save it into file - uint8* pData = new uint8[nSize]; - pVisAreaManager->GetCompiledData(pData, nSize, &pTempBrushTable, &pTempMatsTable, &pTempVegGroupTable, eExportEndian); - sprintf_s(szFileOutputPath, "%s%s", pszGamePath, COMPILED_VISAREA_MAP_FILE_NAME); - CCryMemFile visareasCompiledFile; - visareasCompiledFile.Write(pData, nSize); - m_levelPak.m_pakFile.UpdateFile(szFileOutputPath, visareasCompiledFile); - delete[] pData; - } - } - } -} - ////////////////////////////////////////////////////////////////////////// void CGameExporter::ExportOcclusionMesh(const char* pszGamePath) { @@ -325,7 +268,7 @@ void CGameExporter::ExportOcclusionMesh(const char* pszGamePath) } ////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportLevelData(const QString& path, bool bExportMission) +void CGameExporter::ExportLevelData(const QString& path, bool /*bExportMission*/) { IEditor* pEditor = GetIEditor(); pEditor->SetStatusText(QObject::tr("Exporting LevelData.xml...")); @@ -338,54 +281,6 @@ void CGameExporter::ExportLevelData(const QString& path, bool bExportMission) XmlNodeRef rootAction = XmlHelpers::CreateXmlNode("LevelDataAction"); rootAction->setAttr("SandboxVersion", versionString); - ExportMapInfo(root); - - ////////////////////////////////////////////////////////////////////////// - // Export materials. - ExportMaterials(root, path); - ////////////////////////////////////////////////////////////////////////// - - CCryEditDoc* pDocument = pEditor->GetDocument(); - CMission* pCurrentMission = 0; - - if (bExportMission) - { - pCurrentMission = pDocument->GetCurrentMission(); - // Save contents of current mission. - } - - ////////////////////////////////////////////////////////////////////////// - // Export missions tag. - ////////////////////////////////////////////////////////////////////////// - XmlNodeRef missionsNode = rootAction->newChild("Missions"); - QString missionFileName; - QString currentMissionFileName; - I3DEngine* p3DEngine = pEditor->Get3DEngine(); - if (p3DEngine) - { - for (int i = 0; i < pDocument->GetMissionCount(); i++) - { - CMission* pMission = pDocument->GetMission(i); - - QString name = pMission->GetName(); - name.replace(' ', '_'); - missionFileName = QStringLiteral("Mission_%1.xml").arg(name); - - XmlNodeRef missionDescNode = missionsNode->newChild("Mission"); - missionDescNode->setAttr("Name", pMission->GetName().toUtf8().data()); - missionDescNode->setAttr("File", missionFileName.toUtf8().data()); - missionDescNode->setAttr("CGFCount", p3DEngine->GetLoadedObjectCount()); - - int nProgressBarRange = m_numExportedMaterials / 10 + p3DEngine->GetLoadedObjectCount(); - missionDescNode->setAttr("ProgressBarRange", nProgressBarRange); - - if (pMission == pCurrentMission) - { - currentMissionFileName = missionFileName; - } - } - } - ////////////////////////////////////////////////////////////////////////// // Save Level Data XML ////////////////////////////////////////////////////////////////////////// @@ -400,41 +295,6 @@ void CGameExporter::ExportLevelData(const QString& path, bool bExportMission) CCryMemFile fileAction; fileAction.Write(xmlDataAction.c_str(), xmlDataAction.length()); m_levelPak.m_pakFile.UpdateFile(levelDataActionFile.toUtf8().data(), fileAction); - - if (bExportMission) - { - XmlNodeRef objectsNode = NULL; - ////////////////////////////////////////////////////////////////////////// - // Export current mission file. - ////////////////////////////////////////////////////////////////////////// - XmlNodeRef missionNode = rootAction->createNode("Mission"); - pCurrentMission->Export(missionNode, objectsNode); - - if (p3DEngine) - { - missionNode->setAttr("CGFCount", p3DEngine->GetLoadedObjectCount()); - } - - //if (!CFileUtil::OverwriteFile( path+currentMissionFileName )) - // return; - - AZStd::vector entitySaveBuffer; - AZ::IO::ByteContainerStream > entitySaveStream(&entitySaveBuffer); - bool savedEntities = false; - EBUS_EVENT_RESULT(savedEntities, AzToolsFramework::EditorEntityContextRequestBus, SaveToStreamForGame, entitySaveStream, AZ::DataStream::ST_BINARY); - if (savedEntities) - { - QString entitiesFile; - entitiesFile = QStringLiteral("%1%2.entities_xml").arg(path, pCurrentMission ? pCurrentMission->GetName() : ""); - m_levelPak.m_pakFile.UpdateFile(entitiesFile.toUtf8().data(), entitySaveBuffer.begin(), entitySaveBuffer.size()); - } - - _smart_ptr pXmlStrData = missionNode->getXMLData(5000000); - - CCryMemFile fileMission; - fileMission.Write(pXmlStrData->GetString(), pXmlStrData->GetStringLength()); - m_levelPak.m_pakFile.UpdateFile((path + currentMissionFileName).toUtf8().data(), fileMission); - } } ////////////////////////////////////////////////////////////////////////// @@ -457,18 +317,6 @@ void CGameExporter::ExportLevelInfo(const QString& path) const int compiledHeightmapSize = static_cast(terrainAabb.GetXExtent() / terrainGridResolution.GetX()); root->setAttr("HeightmapSize", compiledHeightmapSize); - // Save all missions in this level. - XmlNodeRef missionsNode = root->newChild("Missions"); - int numMissions = pEditor->GetDocument()->GetMissionCount(); - for (int i = 0; i < numMissions; i++) - { - CMission* pMission = pEditor->GetDocument()->GetMission(i); - XmlNodeRef missionNode = missionsNode->newChild("Mission"); - missionNode->setAttr("Name", pMission->GetName().toUtf8().data()); - missionNode->setAttr("Description", pMission->GetDescription().toUtf8().data()); - } - - ////////////////////////////////////////////////////////////////////////// // Save LevelInfo file. ////////////////////////////////////////////////////////////////////////// @@ -480,141 +328,6 @@ void CGameExporter::ExportLevelInfo(const QString& path) m_levelPak.m_pakFile.UpdateFile(filename.toUtf8().data(), file); } -////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportMapInfo(XmlNodeRef& node) -{ - if (!GetIEditor()->Get3DEngine()) - { - return; - } - - XmlNodeRef info = node->newChild("LevelInfo"); - - IEditor* pEditor = GetIEditor(); - info->setAttr("Name", QFileInfo(pEditor->GetDocument()->GetTitle()).completeBaseName()); - - auto terrain = AzFramework::Terrain::TerrainDataRequestBus::FindFirstHandler(); - const AZ::Aabb terrainAabb = terrain ? terrain->GetTerrainAabb() : AZ::Aabb::CreateFromPoint(AZ::Vector3::CreateZero()); - const AZ::Vector2 terrainGridResolution = terrain ? terrain->GetTerrainGridResolution() : AZ::Vector2::CreateOne(); - - const int terrainSizeInMeters = static_cast(terrainAabb.GetXExtent()); - const int terrainUnitSizeInMeters = static_cast(terrainGridResolution.GetX()); - info->setAttr("HeightmapSize", terrainSizeInMeters / terrainUnitSizeInMeters); - info->setAttr("HeightmapUnitSize", terrainUnitSizeInMeters); - //! Default Max Height value. - constexpr int HEIGHTMAP_MAX_HEIGHT = 150; //This is the default max height in CHeightmap - info->setAttr("HeightmapMaxHeight", HEIGHTMAP_MAX_HEIGHT); - info->setAttr("WaterLevel", pEditor->Get3DEngine()->GetWaterLevel()); - - // Serialize surface types. - CXmlArchive xmlAr; - xmlAr.bLoading = false; - xmlAr.root = node; -} - -////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportMaterials(XmlNodeRef& levelDataNode, const QString& path) -{ - ////////////////////////////////////////////////////////////////////////// - // Export materials manager. - CMaterialManager* pManager = GetIEditor()->GetMaterialManager(); - pManager->Export(levelDataNode); - - QString filename = Path::Make(path, MATERIAL_LEVEL_LIBRARY_FILE); - - bool bHaveItems = true; - - int numMtls = 0; - - XmlNodeRef nodeMaterials = XmlHelpers::CreateXmlNode("MaterialsLibrary"); - // Export Materials local level library. - for (int i = 0; i < pManager->GetLibraryCount(); i++) - { - XmlNodeRef nodeLib = nodeMaterials->newChild("Library"); - CMaterialLibrary* pLib = (CMaterialLibrary*)pManager->GetLibrary(i); - if (pLib->GetItemCount() > 0) - { - bHaveItems = false; - // Export this library. - numMtls += pManager->ExportLib(pLib, nodeLib); - } - } - if (!bHaveItems) - { - XmlString xmlData = nodeMaterials->getXML(); - - CCryMemFile file; - file.Write(xmlData.c_str(), xmlData.length()); - m_levelPak.m_pakFile.UpdateFile(filename.toUtf8().data(), file); - } - else - { - m_levelPak.m_pakFile.RemoveFile(filename.toUtf8().data()); - } - m_numExportedMaterials = numMtls; -} - -////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportLevelLensFlares(const QString& path) -{ - GetIEditor()->SetStatusText(QObject::tr("Exporting Lens Flares...")); - std::vector objects; - GetIEditor()->GetObjectManager()->FindObjectsOfType(&CEntityObject::staticMetaObject, objects); - std::set flareNameSet; - for (int i = 0, iObjectSize(objects.size()); i < iObjectSize; ++i) - { - CEntityObject* pEntity = (CEntityObject*)objects[i]; - if (!pEntity->IsLight()) - { - continue; - } - QString flareName = pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName); - if (flareName.isEmpty() || flareName == "@root") - { - continue; - } - flareNameSet.insert(flareName); - } - - XmlNodeRef pRootNode = GetIEditor()->GetSystem()->CreateXmlNode("LensFlareList"); - pRootNode->setAttr("Version", FLARE_EXPORT_FILE_VERSION); - - CLensFlareManager* pLensManager = GetIEditor()->GetLensFlareManager(); - - if (CLensFlareLibrary* pLevelLib = (CLensFlareLibrary*)pLensManager->GetLevelLibrary()) - { - for (int i = 0; i < pLevelLib->GetItemCount(); i++) - { - CLensFlareItem* pItem = (CLensFlareItem*)pLevelLib->GetItem(i); - - if (flareNameSet.find(pItem->GetFullName()) == flareNameSet.end()) - { - continue; - } - - CBaseLibraryItem::SerializeContext ctx(pItem->CreateXmlData(), false); - pRootNode->addChild(ctx.node); - pItem->Serialize(ctx); - flareNameSet.erase(pItem->GetFullName()); - } - } - - std::set::iterator iFlareNameSet = flareNameSet.begin(); - for (; iFlareNameSet != flareNameSet.end(); ++iFlareNameSet) - { - QString flareName = *iFlareNameSet; - XmlNodeRef pFlareNode = GetIEditor()->GetSystem()->CreateXmlNode("LensFlare"); - pFlareNode->setAttr("name", flareName.toUtf8().data()); - pRootNode->addChild(pFlareNode); - } - - CCryMemFile lensFlareNames; - lensFlareNames.Write(pRootNode->getXMLData()->GetString(), pRootNode->getXMLData()->GetStringLength()); - - QString exportPathName = path + FLARE_EXPORT_FILE; - m_levelPak.m_pakFile.UpdateFile(exportPathName.toUtf8().data(), lensFlareNames); -} - ////////////////////////////////////////////////////////////////////////// void CGameExporter::ExportLevelResourceList(const QString& path) { diff --git a/Code/Sandbox/Editor/GameExporter.h b/Code/Sandbox/Editor/GameExporter.h index 87e24ef844..18ec79189a 100644 --- a/Code/Sandbox/Editor/GameExporter.h +++ b/Code/Sandbox/Editor/GameExporter.h @@ -91,15 +91,11 @@ private: void ExportLevelData(const QString& path, bool bExportMission = true); void ExportLevelInfo(const QString& path); - void ExportVisAreas(const char* pszGamePath, EEndian eExportEndian); void ExportOcclusionMesh(const char* pszGamePath); - void ExportMapInfo(XmlNodeRef& node); - void ExportLevelLensFlares(const QString& path); void ExportLevelResourceList(const QString& path); void ExportLevelUsedResourceList(const QString& path); void ExportLevelShaderCache(const QString& path); - void ExportMaterials(XmlNodeRef& levelDataNode, const QString& path); void ExportGameData(const QString& path); void ExportFileList(const QString& path, const QString& levelName); diff --git a/Code/Sandbox/Editor/GameResourcesExporter.cpp b/Code/Sandbox/Editor/GameResourcesExporter.cpp index 564396d090..8a6c547dca 100644 --- a/Code/Sandbox/Editor/GameResourcesExporter.cpp +++ b/Code/Sandbox/Editor/GameResourcesExporter.cpp @@ -21,7 +21,6 @@ // Editor #include "UsedResources.h" #include "GameEngine.h" -#include "Material/MaterialManager.h" #include "Include/IObjectManager.h" #include "WaitProgress.h" @@ -51,7 +50,7 @@ void CGameResourcesExporter::ChooseDirectory() void CGameResourcesExporter::GatherAllLoadedResources() { m_files.clear(); - m_files.reserve(100000); // count from GetResourceList, GetFilesFromObjects, GetFilesFromMaterials ... is unknown + m_files.reserve(100000); // count from GetResourceList, GetFilesFromObjects ... is unknown auto pResList = gEnv->pCryPak->GetResourceList(AZ::IO::IArchive::RFOM_Level); { @@ -62,7 +61,6 @@ void CGameResourcesExporter::GatherAllLoadedResources() } GetFilesFromObjects(); - GetFilesFromMaterials(); } ////////////////////////////////////////////////////////////////////////// @@ -158,12 +156,3 @@ void CGameResourcesExporter::GetFilesFromObjects() Append(m_files, rs.files); } - -////////////////////////////////////////////////////////////////////////// -void CGameResourcesExporter::GetFilesFromMaterials() -{ - CUsedResources rs; - GetIEditor()->GetMaterialManager()->GatherUsedResources(rs); - Append(m_files, rs.files); -} - diff --git a/Code/Sandbox/Editor/GameResourcesExporter.h b/Code/Sandbox/Editor/GameResourcesExporter.h index b408cbb42f..8236458cb3 100644 --- a/Code/Sandbox/Editor/GameResourcesExporter.h +++ b/Code/Sandbox/Editor/GameResourcesExporter.h @@ -44,7 +44,6 @@ private: void GetFilesFromObjects(); void GetFilesFromVarBlock(CVarBlock* pVB); void GetFilesFromVariable(IVariable* pVar); - void GetFilesFromMaterials(); }; #endif // CRYINCLUDE_EDITOR_GAMERESOURCESEXPORTER_H diff --git a/Code/Sandbox/Editor/Geometry/EdGeometry.h b/Code/Sandbox/Editor/Geometry/EdGeometry.h deleted file mode 100644 index 3def344a35..0000000000 --- a/Code/Sandbox/Editor/Geometry/EdGeometry.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_GEOMETRY_EDGEOMETRY_H -#define CRYINCLUDE_EDITOR_GEOMETRY_EDGEOMETRY_H -#pragma once - -struct IIndexedMesh; -struct DisplayContext; -struct HitContext; -struct SSubObjSelectionModifyContext; -class CObjectArchive; - -// Basic supported geometry types. -enum EEdGeometryType -{ - GEOM_TYPE_MESH = 0, // Mesh geometry. - GEOM_TYPE_BRUSH, // Solid brush geometry. - GEOM_TYPE_PATCH, // Bezier patch surface geometry. - GEOM_TYPE_NURB, // Nurbs surface geometry. -}; - -////////////////////////////////////////////////////////////////////////// -// Description: -// CEdGeometry is a base class for all supported editable geometries. -////////////////////////////////////////////////////////////////////////// -class CRYEDIT_API CEdGeometry - : public CRefCountBase -{ -public: - CEdGeometry() {}; - - // Query the type of the geometry mesh. - virtual EEdGeometryType GetType() const = 0; - - // Serialize geometry. - virtual void Serialize(CObjectArchive& ar) = 0; - - // Return geometry axis aligned bounding box. - virtual void GetBounds(AABB& box) = 0; - - // Clones Geometry, returns exact copy of the original geometry. - virtual CEdGeometry* Clone() = 0; - - // Access to the indexed mesh. - // Return false if geometry can not be represented by an indexed mesh. - virtual IIndexedMesh* GetIndexedMesh(size_t idx = 0) = 0; - virtual IStatObj* GetIStatObj() const = 0; - virtual void GetTM(Matrix34* pTM, size_t idx = 0) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Advanced geometry interface for SubObject selection and modification. - ////////////////////////////////////////////////////////////////////////// - virtual void SetModified(bool bModified = true) = 0; - virtual bool IsModified() const = 0; - virtual bool StartSubObjSelection(const Matrix34& nodeWorldTM, int elemType, int nFlags) = 0; - virtual void EndSubObjSelection() = 0; - - // Display geometry for sub object selection. - virtual void Display(DisplayContext& dc) = 0; - - // Sub geometry hit testing and selection. - virtual bool HitTest(HitContext& hit) = 0; - - ////////////////////////////////////////////////////////////////////////// - virtual void ModifySelection(SSubObjSelectionModifyContext& modCtx, bool isUndo = true) = 0; - // Called when selection modification is accepted. - virtual void AcceptModifySelection() = 0; - -protected: - ~CEdGeometry() {}; -}; - -#endif // CRYINCLUDE_EDITOR_GEOMETRY_EDGEOMETRY_H diff --git a/Code/Sandbox/Editor/Geometry/EdMesh.cpp b/Code/Sandbox/Editor/Geometry/EdMesh.cpp deleted file mode 100644 index 466c07ece7..0000000000 --- a/Code/Sandbox/Editor/Geometry/EdMesh.cpp +++ /dev/null @@ -1,1548 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Implementation of CEdMesh class. - - -#include "EditorDefs.h" - -// CryCommon -#include - -// Editor -#include "EdMesh.h" -#include "Viewport.h" -#include "ViewManager.h" -#include "Util/PakFile.h" -#include "Include/HitContext.h" -#include "Include/ITransformManipulator.h" -#include "Objects/ObjectLoader.h" -#include "Undo/IUndoObject.h" -#include "Util/fastlib.h" - - -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -//! Undo object for Editable Mesh. -class CUndoEdMesh - : public IUndoObject -{ -public: - CUndoEdMesh(CEdMesh* pEdMesh, int nCopyFlags, const char* undoDescription) - { - // Stores the current state of this object. - assert(pEdMesh != 0); - m_nCopyFlags = nCopyFlags; - m_undoDescription = undoDescription; - m_pEdMesh = pEdMesh; - pEdMesh->CopyToMesh(undoMesh, nCopyFlags); - } -protected: - virtual int GetSize() - { - // sizeof(undoMesh) + sizeof(redoMesh); - return sizeof(*this); - } - virtual QString GetDescription() { return m_undoDescription; }; - - virtual void Undo(bool bUndo) - { - if (bUndo) - { - m_pEdMesh->CopyToMesh(redoMesh, m_nCopyFlags); - } - // Undo object state. - m_pEdMesh->CopyFromMesh(undoMesh, m_nCopyFlags, bUndo); - } - virtual void Redo() - { - m_pEdMesh->CopyFromMesh(redoMesh, m_nCopyFlags, true); - } - -private: - QString m_undoDescription; - int m_nCopyFlags; - _smart_ptr m_pEdMesh; - CTriMesh undoMesh; - CTriMesh redoMesh; -}; - -////////////////////////////////////////////////////////////////////////// -// Static member of CEdMesh. -////////////////////////////////////////////////////////////////////////// -CEdMesh::MeshMap CEdMesh::m_meshMap; - -////////////////////////////////////////////////////////////////////////// -CEdMesh::CEdMesh() -{ - m_pStatObj = 0; - m_pSubObjCache = 0; - m_nUserCount = 0; - m_bModified = false; -} - - -////////////////////////////////////////////////////////////////////////// -CEdMesh::CEdMesh(IStatObj* pGeom) -{ - assert(pGeom); - if (pGeom) - { - m_pStatObj = pGeom; - m_pStatObj->AddRef(); - } - m_pSubObjCache = 0; - m_nUserCount = 0; - m_bModified = false; -} - -////////////////////////////////////////////////////////////////////////// -CEdMesh::~CEdMesh() -{ - for (auto ppIndexedMeshes = m_tempIndexedMeshes.begin(); ppIndexedMeshes != m_tempIndexedMeshes.end(); ++ppIndexedMeshes) - { - SAFE_RELEASE(*ppIndexedMeshes); - } - - SAFE_RELEASE(m_pStatObj); - // Remove this object from map. - m_meshMap.erase(m_filename); - if (m_pSubObjCache) - { - if (m_pSubObjCache->pTriMesh) - { - delete m_pSubObjCache->pTriMesh; - } - delete m_pSubObjCache; - } -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::Serialize(CObjectArchive& ar) -{ - if (ar.bUndo) - { - return; - } - if (ar.bLoading) - { - } - else - { - if (m_bModified) - { - CBaseObject* pObj = ar.GetCurrentObject(); - if (pObj) - { - QString levelPath = Path::AddPathSlash(GetIEditor()->GetLevelFolder()); - CPakFile* pPakFile = ar.GetGeometryPak((levelPath + "\\Geometry.pak").toUtf8().data()); - if (pPakFile) - { - SaveToCGF(m_filename.toUtf8().data(), pPakFile); - } - } - SetModified(false); - } - } -} - -////////////////////////////////////////////////////////////////////////// -// CEdMesh implementation. -////////////////////////////////////////////////////////////////////////// -CEdMesh* CEdMesh::LoadMesh(const char* filename) -{ - if (strlen(filename) == 0) - { - return 0; - } - - // If object created see if its not yet registered. - CEdMesh* pMesh = stl::find_in_map(m_meshMap, filename, (CEdMesh*)0); - if (pMesh) - { - // Found, return it. - return pMesh; - } - - // Make new. - IStatObj* pGeom = GetIEditor()->Get3DEngine()->LoadStatObjUnsafeManualRef(filename); - if (!pGeom) - { - return 0; - } - - // Not found, Make new. - pMesh = new CEdMesh(pGeom); - pMesh->m_filename = filename; - m_meshMap[filename] = pMesh; - return pMesh; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::AddUser() -{ - m_nUserCount++; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::RemoveUser() -{ - m_nUserCount--; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::ReloadAllGeometries() -{ - for (MeshMap::iterator it = m_meshMap.begin(); it != m_meshMap.end(); ++it) - { - CEdMesh* pMesh = it->second; - if (pMesh) - { - pMesh->ReloadGeometry(); - } - } -} - -void CEdMesh::ReleaseAll() -{ - m_meshMap.clear(); -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::ReloadGeometry() -{ - // Reload mesh. - if (m_pStatObj) - { - m_pStatObj->Refresh(FRO_GEOMETRY); - } -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::IsSameObject(const char* filename) -{ - return QString::compare(m_filename, filename, Qt::CaseInsensitive) == 0; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::GetBounds(AABB& box) -{ - assert(m_pStatObj); - - if (m_pStatObj) - { - box.min = m_pStatObj->GetBoxMin(); - box.max = m_pStatObj->GetBoxMax(); - } -} - -////////////////////////////////////////////////////////////////////////// -CEdGeometry* CEdMesh::Clone() -{ - if (m_pStatObj) - { - // Clone StatObj. - IStatObj* pStatObj = m_pStatObj->Clone(true, true, false); - pStatObj->AddRef(); - CEdMesh* pNewMesh = new CEdMesh(pStatObj); - return pNewMesh; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::SetFilename(const QString& filename) -{ - if (!m_filename.isEmpty()) - { - m_meshMap.erase(m_filename); - } - m_filename = Path::MakeGamePath(filename); - m_meshMap[m_filename] = this; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::Render(SRendParams& rp, const SRenderingPassInfo& passInfo) -{ - if (m_pStatObj) - { - m_pStatObj->Render(rp, passInfo); - } -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::IsDefaultObject() -{ - if (m_pStatObj) - { - return m_pStatObj->IsDefaultObject(); - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -IIndexedMesh* CEdMesh::GetIndexedMesh(size_t idx) -{ - if (m_tempIndexedMeshes.size() == 0 && m_pStatObj) - { - if (m_pStatObj->GetIndexedMesh()) - { - if (idx == 0) - { - return m_pStatObj->GetIndexedMesh(); - } - - return nullptr; - } - else - { - // Load from CGF. - QString sFilename = m_pStatObj->GetFilePath(); - CContentCGF cgf(sFilename.toUtf8().data()); - if (gEnv->p3DEngine->LoadChunkFileContent(&cgf, sFilename.toUtf8().data())) - { - for (int i = 0; i < cgf.GetNodeCount(); ++i) - { - CNodeCGF* pNode = cgf.GetNode(i); - if (pNode->type == CNodeCGF::NODE_MESH) - { - CMesh* pMesh = pNode->pMesh; - if (pMesh) - { - IIndexedMesh* pTempIndexedMesh = GetIEditor()->Get3DEngine()->CreateIndexedMesh(); - pTempIndexedMesh->SetMesh(*pMesh); - m_tempIndexedMeshes.push_back(pTempIndexedMesh); - - Matrix34 tm = pNode->localTM; - CNodeCGF* pParent = pNode->pParent; - while (pParent) - { - tm = pParent->localTM * tm; - pParent = pParent->pParent; - } - m_tempMatrices.push_back(tm); - } - } - } - } - } - } - - if (idx < m_tempIndexedMeshes.size()) - { - return m_tempIndexedMeshes[idx]; - } - - return nullptr; -} - -void CEdMesh::GetTM(Matrix34* pTM, size_t idx) -{ - if (idx < m_tempMatrices.size()) - { - *pTM = m_tempMatrices[idx]; - } - else - { - pTM->SetIdentity(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::AcceptModifySelection() -{ - // Implement - UpdateIndexedMeshFromCache(true); -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::UpdateIndexedMeshFromCache(bool bFast) -{ - // Implement - if (m_pSubObjCache) - { - if (bFast) - { - if (g_SubObjSelOptions.displayType == SO_DISPLAY_GEOMETRY) - { - m_pSubObjCache->pTriMesh->UpdateIndexedMesh(GetIndexedMesh()); - if (m_pStatObj) - { - m_pStatObj->Invalidate(); - } - } - } - else - { - m_pSubObjCache->pTriMesh->UpdateIndexedMesh(GetIndexedMesh()); - if (m_pStatObj) - { - m_pStatObj->Invalidate(); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::StartSubObjSelection(const Matrix34& nodeWorldTM, int elemType, [[maybe_unused]] int nFlags) -{ - IIndexedMesh* pIndexedMesh = GetIndexedMesh(); - if (!pIndexedMesh) - { - return false; - } - CMesh& mesh = *pIndexedMesh->GetMesh(); - - if (!m_pSubObjCache) - { - m_pSubObjCache = new SubObjCache; - } - m_pSubObjCache->worldTM = nodeWorldTM; - m_pSubObjCache->invWorldTM = nodeWorldTM.GetInverted(); - - if (!m_pSubObjCache->pTriMesh) - { - m_pSubObjCache->pTriMesh = new CTriMesh; - m_pSubObjCache->pTriMesh->SetFromMesh(mesh); - } - UpdateSubObjCache(); - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - triMesh.selectionType = elemType; - - m_pSubObjCache->bNoDisplay = false; - - return true; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::SetModified(bool bModified) -{ - if (m_pSubObjCache && bModified) - { - // Update xformed vertices. - UpdateSubObjCache(); - } - m_bModified = bModified; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::UpdateSubObjCache() -{ - Matrix34& wtm = m_pSubObjCache->worldTM; - - SetWorldTM(wtm); -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::EndSubObjSelection() -{ - if (!m_pSubObjCache) - { - return; - } - - UpdateIndexedMeshFromCache(false); - - if (m_pSubObjCache->pTriMesh) - { - delete m_pSubObjCache->pTriMesh; - } - delete m_pSubObjCache; - m_pSubObjCache = 0; - - if (m_pStatObj) - { - if (m_bModified) - { - m_pStatObj->Invalidate(true); - } - // Clear hidden flag from geometry. - m_pStatObj->SetFlags(m_pStatObj->GetFlags() & (~STATIC_OBJECT_HIDDEN)); - } -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::Display(DisplayContext& dc) -{ - if (!m_pSubObjCache || m_pSubObjCache->bNoDisplay) - { - return; - } - - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - if (!triMesh.pWSVertices) - { - return; - } - - if (m_pStatObj) - { - int nStatObjFlags = m_pStatObj->GetFlags(); - if (g_SubObjSelOptions.displayType == SO_DISPLAY_GEOMETRY) - { - nStatObjFlags &= ~STATIC_OBJECT_HIDDEN; - } - else - { - nStatObjFlags |= STATIC_OBJECT_HIDDEN; - } - m_pStatObj->SetFlags(nStatObjFlags); - } - - const Matrix34& worldTM = m_pSubObjCache->worldTM; - Vec3 vWSCameraVector = m_pSubObjCache->worldTM.GetTranslation() - dc.view->GetViewTM().GetTranslation(); - Vec3 vOSCameraVector = m_pSubObjCache->invWorldTM.TransformVector(vWSCameraVector).GetNormalized(); // Object space camera vector. - - // Render geometry vertices. - uint32 nPrevState = dc.GetState(); - - ////////////////////////////////////////////////////////////////////////// - // Calculate front facing vertices. - ////////////////////////////////////////////////////////////////////////// - triMesh.frontFacingVerts.resize(triMesh.GetVertexCount()); - triMesh.frontFacingVerts.clear(); - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - CTriFace& face = triMesh.pFaces[i]; - if (vOSCameraVector.Dot(face.normal) < 0) - { - triMesh.frontFacingVerts[face.v[0]] = true; - triMesh.frontFacingVerts[face.v[1]] = true; - triMesh.frontFacingVerts[face.v[2]] = true; - } - } - - ////////////////////////////////////////////////////////////////////////// - // Display flat shaded object. - ////////////////////////////////////////////////////////////////////////// - if (g_SubObjSelOptions.displayType == SO_DISPLAY_FLAT) - { - ColorB faceColor(0, 250, 250, 255); - ColorB col = faceColor; - dc.SetDrawInFrontMode(false); - dc.SetFillMode(e_FillModeSolid); - dc.CullOn(); - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - CTriFace& face = triMesh.pFaces[i]; - if (triMesh.selectionType != SO_ELEM_FACE || !triMesh.faceSel[i]) - { - ColorB col2 = faceColor; - float dt = -face.normal.Dot(vOSCameraVector); - dt = max(0.4f, dt); - dt = min(1.0f, dt); - col2.r = ftoi(faceColor.r * dt); - col2.g = ftoi(faceColor.g * dt); - col2.b = ftoi(faceColor.b * dt); - col2.a = faceColor.a; - dc.pRenderAuxGeom->DrawTriangle( - triMesh.pWSVertices[face.v[0]], col2, - triMesh.pWSVertices[face.v[1]], col2, - triMesh.pWSVertices[face.v[2]], col2 - ); - } - } - } - - // Draw selected triangles. - ColorB edgeColor(255, 255, 255, 155); - if (triMesh.StreamHaveSelection(CTriMesh::FACES)) - { - if (g_SubObjSelOptions.bDisplayBackfacing) - { - dc.CullOff(); - } - else - { - dc.CullOn(); - } - dc.SetDrawInFrontMode(true); - dc.SetFillMode(e_FillModeWireframe); - // Draw triangles. - //dc.pRenderAuxGeom->DrawTriangles( triMesh.pVertices,triMesh.GetVertexCount(), mesh.m_pIndices,mesh.GetIndexCount(),edgeColor ); - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - CTriFace& face = triMesh.pFaces[i]; - if (!triMesh.faceSel[i]) - { - dc.pRenderAuxGeom->DrawTriangle( - triMesh.pWSVertices[face.v[0]], edgeColor, - triMesh.pWSVertices[face.v[1]], edgeColor, - triMesh.pWSVertices[face.v[2]], edgeColor - ); - } - } - } - - if (g_SubObjSelOptions.bDisplayNormals) - { - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - CTriFace& face = triMesh.pFaces[i]; - Vec3 p1 = triMesh.pWSVertices[face.v[0]]; - Vec3 p2 = triMesh.pWSVertices[face.v[1]]; - Vec3 p3 = triMesh.pWSVertices[face.v[2]]; - Vec3 midp = (p1 + p2 + p3) * (1.0f / 3.0f); - dc.pRenderAuxGeom->DrawLine(midp, edgeColor, midp + worldTM.TransformVector(face.normal) * g_SubObjSelOptions.fNormalsLength, edgeColor); - } - } - - if (triMesh.selectionType == SO_ELEM_VERTEX || triMesh.StreamHaveSelection(CTriMesh::VERTICES)) - { - ColorB pointColor(0, 255, 255, 255); - - float fClrAdd = (g_SubObjSelOptions.bSoftSelection) ? 0 : 1; - for (int i = 0; i < triMesh.GetVertexCount(); i++) - { - bool bSelected = triMesh.vertSel[i] || triMesh.pWeights[i] != 0; - if (bSelected) - { - int clr = (triMesh.pWeights[i] + fClrAdd) * 255; - dc.pRenderAuxGeom->DrawPoint(triMesh.pWSVertices[i], ColorB(clr, 255 - clr, 255 - clr, 255), 8); - } - else if (!g_SubObjSelOptions.bDisplayBackfacing || triMesh.frontFacingVerts[i]) - { - dc.pRenderAuxGeom->DrawPoint(triMesh.pWSVertices[i], pointColor, 5); - } - } - } - - // Draw edges. - if (triMesh.selectionType == SO_ELEM_EDGE || triMesh.StreamHaveSelection(CTriMesh::EDGES)) - { - ColorB edgeColor2(200, 255, 200, 255); - ColorB selEdgeColor(255, 0, 0, 255); - - // Draw selected edges. - for (int i = 0; i < triMesh.GetEdgeCount(); i++) - { - CTriEdge& edge = triMesh.pEdges[i]; - if (triMesh.edgeSel[i]) - { - const Vec3& p1 = triMesh.pWSVertices[edge.v[0]]; - const Vec3& p2 = triMesh.pWSVertices[edge.v[1]]; - dc.pRenderAuxGeom->DrawLine(p1, selEdgeColor, p2, selEdgeColor, 6); - } - else if (!g_SubObjSelOptions.bDisplayBackfacing || ( - triMesh.frontFacingVerts[edge.v[0]] && triMesh.frontFacingVerts[edge.v[1]])) - { - const Vec3& p1 = triMesh.pWSVertices[edge.v[0]]; - const Vec3& p2 = triMesh.pWSVertices[edge.v[1]]; - dc.pRenderAuxGeom->DrawLine(p1, edgeColor2, p2, edgeColor2); - } - } - } - - if (triMesh.selectionType == SO_ELEM_FACE) - { - ColorB pointColor(0, 255, 255, 255); - ColorB selFaceColor(255, 0, 0, 180); - - // Draw selected faces and face points. - dc.CullOff(); - dc.SetFillMode(e_FillModeSolid); - - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - CTriFace& face = triMesh.pFaces[i]; - const Vec3& p1 = triMesh.pWSVertices[face.v[0]]; - const Vec3& p2 = triMesh.pWSVertices[face.v[1]]; - const Vec3& p3 = triMesh.pWSVertices[face.v[2]]; - if (triMesh.faceSel[i]) - { - dc.pRenderAuxGeom->DrawTriangle(p1, selFaceColor, p2, selFaceColor, p3, selFaceColor); - } - - if (!g_SubObjSelOptions.bDisplayBackfacing && vOSCameraVector.Dot(face.normal) > 0) - { - continue; // Backfacing. - } - Vec3 midp = (p1 + p2 + p3) * (1.0f / 3.0f); - dc.pRenderAuxGeom->DrawPoint(midp, pointColor, 4); - } - } - else if (triMesh.StreamHaveSelection(CTriMesh::FACES)) - { - ColorB pointColor(0, 255, 255, 255); - ColorB selFaceColor(255, 0, 0, 180); - - // Draw selected faces and face points. - dc.CullOff(); - dc.SetFillMode(e_FillModeSolid); - - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - CTriFace& face = triMesh.pFaces[i]; - const Vec3& p1 = triMesh.pWSVertices[face.v[0]]; - const Vec3& p2 = triMesh.pWSVertices[face.v[1]]; - const Vec3& p3 = triMesh.pWSVertices[face.v[2]]; - if (triMesh.faceSel[i]) - { - dc.pRenderAuxGeom->DrawTriangle(p1, selFaceColor, p2, selFaceColor, p3, selFaceColor); - } - } - } - - dc.SetState(nPrevState); // Restore render state. -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::HitTestVertex(HitContext& hit, SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result) -{ - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - - // This make sure that bit array size matches num vertices, front facing should be calculated in Display method. - triMesh.frontFacingVerts.resize(triMesh.GetVertexCount()); - - float minDist = FLT_MAX; - int closestElem = -1; - - for (int i = 0; i < triMesh.GetVertexCount(); i++) - { - if (env.bIgnoreBackfacing && !triMesh.frontFacingVerts[i]) - { - continue; - } - QPoint p = hit.view->WorldToView(triMesh.pWSVertices[i]); - if (p.x() >= hit.rect.left() && p.x() <= hit.rect.right() && - p.y() >= hit.rect.top() && p.y() <= hit.rect.bottom()) - { - if (env.bHitTestNearest) - { - float dist = env.vWSCameraPos.GetDistance(triMesh.pWSVertices[i]); - if (dist < minDist) - { - closestElem = i; - minDist = dist; - } - } - else - { - result.elems.push_back(i); - } - } - } - ////////////////////////////////////////////////////////////////////////// - if (closestElem >= 0) - { - result.minDistance = minDist; - result.elems.push_back(closestElem); - } - return !result.elems.empty(); -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::HitTestEdge(HitContext& hit, SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result) -{ - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - // This make sure that bit array size matches num vertices, front facing should be calculated in Display method. - triMesh.frontFacingVerts.resize(triMesh.GetVertexCount()); - - float minDist = FLT_MAX; - int closestElem = -1; - - for (int i = 0; i < triMesh.GetEdgeCount(); i++) - { - CTriEdge& edge = triMesh.pEdges[i]; - if (!env.bIgnoreBackfacing || - (triMesh.frontFacingVerts[edge.v[0]] && triMesh.frontFacingVerts[edge.v[1]])) - { - if (hit.view->HitTestLine(triMesh.pWSVertices[edge.v[0]], triMesh.pWSVertices[edge.v[1]], hit.point2d, 5)) - { - if (env.bHitTestNearest) - { - float dist = env.vWSCameraPos.GetDistance(triMesh.pWSVertices[edge.v[0]]); - if (dist < minDist) - { - closestElem = i; - minDist = dist; - } - } - else - { - result.elems.push_back(i); - } - } - } - } - ////////////////////////////////////////////////////////////////////////// - if (closestElem >= 0) - { - result.minDistance = minDist; - result.elems.push_back(closestElem); - } - return !result.elems.empty(); -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::HitTestFace(HitContext& hit, SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result) -{ - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - float minDist = FLT_MAX; - int closestElem = -1; - - Vec3 vOut(0, 0, 0); - Ray hitRay(hit.raySrc, hit.rayDir); - - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - CTriFace& face = triMesh.pFaces[i]; - - if (env.bIgnoreBackfacing && env.vOSCameraVector.Dot(face.normal) > 0) - { - continue; // Back facing. - } - Vec3 p1 = triMesh.pWSVertices[face.v[0]]; - Vec3 p2 = triMesh.pWSVertices[face.v[1]]; - Vec3 p3 = triMesh.pWSVertices[face.v[2]]; - - if (!env.bHitTestNearest) - { - // Hit test face middle point in rectangle. - Vec3 midp = (p1 + p2 + p3) * (1.0f / 3.0f); - - QPoint p = hit.view->WorldToView(midp); - if (p.x() >= hit.rect.left() && p.x() <= hit.rect.right() && - p.y() >= hit.rect.top() && p.y() <= hit.rect.bottom()) - { - result.elems.push_back(i); - } - } - else - { - // Hit test ray/triangle. - if (Intersect::Ray_Triangle(hitRay, p1, p3, p2, vOut)) - { - float dist = hitRay.origin.GetSquaredDistance(vOut); - if (dist < minDist) - { - closestElem = i; - minDist = dist; - } - } - } - } - ////////////////////////////////////////////////////////////////////////// - if (closestElem >= 0) - { - result.minDistance = (float)sqrt(minDist); - result.elems.push_back(closestElem); - } - return !result.elems.empty(); -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::SelectSubObjElements(SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result) -{ - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - - bool bSelChanged = false; - if (env.bSelectOnHit && !result.elems.empty()) - { - CBitArray* streamSel = triMesh.GetStreamSelection(result.stream); - if (streamSel) - { - // Select on hit. - for (int i = 0, num = result.elems.size(); i < num; i++) - { - int elem = result.elems[i]; - if ((*streamSel)[elem] != env.bSelectValue) - { - bSelChanged = true; - (*streamSel)[elem] = env.bSelectValue; - } - } - if (bSelChanged) - { - if (env.bSelectValue) - { - triMesh.streamSelMask |= (1 << result.stream); - } - else if (!env.bSelectValue && streamSel->is_zero()) - { - triMesh.streamSelMask &= ~(1 << result.stream); - } - } - } - } - return bSelChanged; -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::IsHitTestResultSelected(SSubObjHitTestResult& result) -{ - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - - if (!result.elems.empty()) - { - CBitArray* streamSel = triMesh.GetStreamSelection(result.stream); - if (streamSel) - { - // check if first result element is selected. - if ((*streamSel)[ result.elems[0] ]) - { - return true; - } - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::HitTest(HitContext& hit) -{ - if (hit.nSubObjFlags & SO_HIT_NO_EDIT) - // This is for a 'move-by-face-normal'. Prepare the mesh and set the 'bNoDisplay'to true - // so that the normal rendering happens instead of the edit-mode rendering. - { - StartSubObjSelection(hit.object->GetWorldTM(), SO_ELEM_FACE, 0); - m_pSubObjCache->bNoDisplay = true; - } - - if (!m_pSubObjCache) - { - return false; - } - - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - - SSubObjHitTestEnvironment env; - env.vWSCameraPos = hit.view->GetViewTM().GetTranslation(); - env.vWSCameraVector = m_pSubObjCache->worldTM.GetTranslation() - hit.view->GetViewTM().GetTranslation(); - env.vOSCameraVector = m_pSubObjCache->invWorldTM.TransformVector(env.vWSCameraVector).GetNormalized(); // Object space camera vector. - - env.bHitTestNearest = hit.nSubObjFlags & SO_HIT_POINT; - env.bHitTestSelected = hit.nSubObjFlags & SO_HIT_TEST_SELECTED; - env.bSelectOnHit = hit.nSubObjFlags & SO_HIT_SELECT; - env.bAdd = hit.nSubObjFlags & SO_HIT_SELECT_ADD; - env.bRemove = hit.nSubObjFlags & SO_HIT_SELECT_REMOVE; - env.bSelectValue = !env.bRemove; - env.bHighlightOnly = hit.nSubObjFlags & SO_HIT_HIGHLIGHT_ONLY; - env.bIgnoreBackfacing = g_SubObjSelOptions.bIgnoreBackfacing && !env.bHitTestNearest; - - int nHitTestWhat = (hit.nSubObjFlags & SO_HIT_ELEM_ALL); - if (nHitTestWhat == 0) - { - if (g_SubObjSelOptions.bSelectByVertex) - { - nHitTestWhat |= SO_HIT_ELEM_VERTEX; - } - switch (triMesh.selectionType) - { - case SO_ELEM_VERTEX: - nHitTestWhat |= SO_HIT_ELEM_VERTEX; - break; - case SO_ELEM_EDGE: - nHitTestWhat |= SO_HIT_ELEM_EDGE; - break; - case SO_ELEM_FACE: - nHitTestWhat |= SO_HIT_ELEM_FACE; - break; - case SO_ELEM_POLYGON: - nHitTestWhat |= SO_HIT_ELEM_POLYGON; - break; - } - } - - IUndoObject* pUndoObj = NULL; - if (env.bSelectOnHit) - { - if (CUndo::IsRecording() && !(hit.nSubObjFlags & SO_HIT_NO_EDIT)) - { - switch (triMesh.selectionType) - { - case SO_ELEM_VERTEX: - pUndoObj = new CUndoEdMesh(this, CTriMesh::COPY_VERT_SEL | CTriMesh::COPY_WEIGHTS, "Select Vertex(s)"); - break; - case SO_ELEM_EDGE: - pUndoObj = new CUndoEdMesh(this, CTriMesh::COPY_EDGE_SEL | CTriMesh::COPY_WEIGHTS, "Select Edge(s)"); - break; - case SO_ELEM_FACE: - pUndoObj = new CUndoEdMesh(this, CTriMesh::COPY_FACE_SEL | CTriMesh::COPY_WEIGHTS, "Select Face(s)"); - break; - } - } - } - - bool bSelChanged = false; - bool bAnyHit = false; - ////////////////////////////////////////////////////////////////////////// - if (env.bSelectOnHit && !env.bAdd && !env.bRemove) - { - bSelChanged = triMesh.ClearSelection(); - } - ////////////////////////////////////////////////////////////////////////// - - SSubObjHitTestResult result[4]; - result[0].stream = CTriMesh::VERTICES; - result[1].stream = CTriMesh::EDGES; - result[2].stream = CTriMesh::FACES; - - if (nHitTestWhat & SO_HIT_ELEM_VERTEX) - { - if (HitTestVertex(hit, env, result[0])) - { - bAnyHit = true; - } - } - - if (nHitTestWhat & SO_HIT_ELEM_EDGE) - { - if (HitTestEdge(hit, env, result[1])) - { - bAnyHit = true; - } - } - - if (nHitTestWhat & SO_HIT_ELEM_FACE) - { - if (HitTestFace(hit, env, result[2])) - { - bAnyHit = true; - } - } - - if (bAnyHit && !env.bSelectOnHit && !env.bHitTestSelected) - { - // Return distance to the first hit element. - hit.dist = min(min(result[0].minDistance, result[1].minDistance), result[2].minDistance); - return true; - } - if (bAnyHit && !env.bSelectOnHit && env.bHitTestSelected) - { - // check if we hit selected item. - if (IsHitTestResultSelected(result[0]) || - IsHitTestResultSelected(result[1]) || - IsHitTestResultSelected(result[2])) - { - hit.dist = min(min(result[0].minDistance, result[1].minDistance), result[2].minDistance); - return true; - } - // If not hit selected. - return false; - } - if (bAnyHit) - { - // Find closest hit. - int n = 0; - if (!result[0].elems.empty()) - { - n = 0; - } - else if (!result[1].elems.empty()) - { - n = 1; - } - else if (!result[2].elems.empty()) - { - n = 2; - } - - hit.dist = result[n].minDistance; - - if (env.bSelectOnHit && - g_SubObjSelOptions.bSelectByVertex && - !result[0].elems.empty() && - !env.bHighlightOnly && - triMesh.selectionType != SO_HIT_ELEM_VERTEX) - { - // When selecting elements by vertex. - switch (triMesh.selectionType) - { - case SO_ELEM_EDGE: - n = 1; - triMesh.GetEdgesByVertex(result[0].elems, result[1].elems); - break; - case SO_ELEM_FACE: - n = 2; - triMesh.GetFacesByVertex(result[0].elems, result[2].elems); - break; - case SO_ELEM_POLYGON: - n = 2; - triMesh.GetFacesByVertex(result[0].elems, result[2].elems); - break; - } - } - if (env.bSelectOnHit && SelectSubObjElements(env, result[n])) - { - bSelChanged = true; - } - } - if (bSelChanged) - { - hit.nSubObjFlags |= SO_HIT_SELECTION_CHANGED; - } - else - { - hit.nSubObjFlags &= ~SO_HIT_SELECTION_CHANGED; - } - - bool bSelectionNotEmpty = false; - if (env.bSelectOnHit && bSelChanged && !env.bHighlightOnly) - { - if (CUndo::IsRecording() && pUndoObj) - { - CUndo::Record(pUndoObj); - } - - bSelectionNotEmpty = triMesh.UpdateSelection(); - if (g_SubObjSelOptions.bSoftSelection) - { - triMesh.SoftSelection(g_SubObjSelOptions); - } - - OnSelectionChange(); - } - else - { - if (pUndoObj) - { - pUndoObj->Release(); - } - } - - return bSelectionNotEmpty; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::OnSelectionChange() -{ - Matrix34 localRefFrame; - if (!GetSelectionReferenceFrame(localRefFrame)) - { - GetIEditor()->ShowTransformManipulator(false); - } - else - { - ITransformManipulator* pManipulator = GetIEditor()->ShowTransformManipulator(true); - - // In local space orient axis gizmo by first object. - localRefFrame = m_pSubObjCache->worldTM * localRefFrame; - - Matrix34 parentTM = m_pSubObjCache->worldTM; - Matrix34 userTM = GetIEditor()->GetViewManager()->GetGrid()->GetMatrix(); - parentTM.SetTranslation(localRefFrame.GetTranslation()); - userTM.SetTranslation(localRefFrame.GetTranslation()); - //tm.SetTranslation( m_selectionCenter ); - pManipulator->SetTransformation(COORDS_LOCAL, localRefFrame); - pManipulator->SetTransformation(COORDS_PARENT, parentTM); - pManipulator->SetTransformation(COORDS_USERDEFINED, userTM); - } -} - -////////////////////////////////////////////////////////////////////////// -bool CEdMesh::GetSelectionReferenceFrame(Matrix34& refFrame) -{ - if (!m_pSubObjCache) - { - return false; - } - - bool bAnySelected = false; - - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - - Vec3 normal(0, 0, 0); - - refFrame.SetIdentity(); - - if (triMesh.selectionType == SO_ELEM_VERTEX) - { - // Average all selected vertex normals. - int numNormals = 0; - int nFaces = triMesh.GetFacesCount(); - for (int i = 0; i < triMesh.GetVertexCount(); i++) - { - if (triMesh.vertSel[i]) - { - bAnySelected = true; - int nVertexIndex = i; - for (int j = 0; j < nFaces; j++) - { - CTriFace& face = triMesh.pFaces[j]; - for (int k = 0; k < 3; k++) - { - if (face.v[k] == nVertexIndex) - { - normal += face.n[k]; - numNormals++; - } - } - } - } - } - if (numNormals > 0) - { - normal = normal / numNormals; - if (!normal.IsZero()) - { - normal.Normalize(); - } - } - } - else if (triMesh.selectionType == SO_ELEM_EDGE) - { - int nNormals = 0; - // Average face normals of a the selected edges. - for (int i = 0; i < triMesh.GetEdgeCount(); i++) - { - if (triMesh.edgeSel[i]) - { - bAnySelected = true; - CTriEdge& edge = triMesh.pEdges[i]; - for (int j = 0; j < 2; j++) - { - if (edge.face[j] >= 0) - { - normal = normal + triMesh.pFaces[edge.face[j]].normal; - nNormals++; - } - } - } - } - if (nNormals > 0) - { - normal = normal / nNormals; - if (!normal.IsZero()) - { - normal.Normalize(); - } - } - } - else if (triMesh.selectionType == SO_ELEM_FACE) - { - // Average all face normals. - int nNormals = 0; - for (int i = 0; i < triMesh.GetFacesCount(); i++) - { - if (triMesh.faceSel[i]) - { - bAnySelected = true; - CTriFace& face = triMesh.pFaces[i]; - normal = normal + face.normal; - nNormals++; - } - } - if (nNormals > 0) - { - normal = normal / nNormals; - if (!normal.IsZero()) - { - normal.Normalize(); - } - } - } - - if (bAnySelected) - { - Vec3 pos(0, 0, 0); - int numSel = 0; - for (int i = 0; i < triMesh.GetVertexCount(); i++) - { - if (triMesh.pWeights[i] == 1.0f) - { - pos = pos + triMesh.pVertices[i].pos; - numSel++; - } - } - if (numSel > 0) - { - pos = pos / numSel; // Average position. - } - refFrame.SetTranslation(pos); - - if (!normal.IsZero()) - { - Vec3 xAxis(1, 0, 0), yAxis(0, 1, 0), zAxis(0, 0, 1); - if (normal.IsEquivalent(zAxis) || normal.IsEquivalent(-zAxis)) - { - zAxis = xAxis; - } - xAxis = normal.Cross(zAxis).GetNormalized(); - yAxis = xAxis.Cross(normal).GetNormalized(); - refFrame.SetFromVectors(xAxis, yAxis, normal, pos); - } - } - - return bAnySelected; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::ModifySelection(SSubObjSelectionModifyContext& modCtx, [[maybe_unused]] bool isUndo) -{ - if (!m_pSubObjCache) - { - return; - } - - IIndexedMesh* pIndexedMesh = GetIndexedMesh(); - if (!pIndexedMesh) - { - return; - } - - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - - if (modCtx.type == SO_MODIFY_UNSELECT) - { - IUndoObject* pUndoObj = NULL; - if (CUndo::IsRecording()) - { - pUndoObj = new CUndoEdMesh(this, CTriMesh::COPY_VERT_SEL | CTriMesh::COPY_WEIGHTS, "Move Vertices"); - } - bool bChanged = triMesh.ClearSelection(); - if (bChanged) - { - OnSelectionChange(); - } - if (CUndo::IsRecording() && bChanged) - { - CUndo::Record(pUndoObj); - } - else if (pUndoObj) - { - pUndoObj->Release(); - } - return; - } - - Matrix34 worldTM = m_pSubObjCache->worldTM; - Matrix34 invTM = worldTM.GetInverted(); - - // Change modify reference frame to object space. - Matrix34 modRefFrame = invTM * modCtx.worldRefFrame; - Matrix34 modRefFrameInverse = modCtx.worldRefFrame.GetInverted() * worldTM; - - if (modCtx.type == SO_MODIFY_MOVE) - { - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoEdMesh(this, CTriMesh::COPY_VERTICES, "Move Vertices")); - } - - Vec3 vOffset = modCtx.vValue; - vOffset = modCtx.worldRefFrame.GetInverted().TransformVector(vOffset); // Offset in local space. - - for (int i = 0; i < triMesh.GetVertexCount(); i++) - { - CTriVertex& vtx = triMesh.pVertices[i]; - if (triMesh.pWeights[i] != 0) - { - Matrix34 tm = modRefFrame * Matrix34::CreateTranslationMat(vOffset * triMesh.pWeights[i]) * modRefFrameInverse; - vtx.pos = tm.TransformPoint(vtx.pos); - } - } - OnSelectionChange(); - } - else if (modCtx.type == SO_MODIFY_ROTATE) - { - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoEdMesh(this, CTriMesh::COPY_VERTICES, "Rotate Vertices")); - } - - Ang3 angles = Ang3(modCtx.vValue); - for (int i = 0; i < triMesh.GetVertexCount(); i++) - { - CTriVertex& vtx = triMesh.pVertices[i]; - if (triMesh.pWeights[i] != 0) - { - Matrix34 tm = modRefFrame * Matrix33::CreateRotationXYZ(angles * triMesh.pWeights[i]) * modRefFrameInverse; - vtx.pos = tm.TransformPoint(vtx.pos); - } - } - } - else if (modCtx.type == SO_MODIFY_SCALE) - { - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoEdMesh(this, CTriMesh::COPY_VERTICES, "Scale Vertices")); - } - - Vec3 vScale = modCtx.vValue; - for (int i = 0; i < triMesh.GetVertexCount(); i++) - { - CTriVertex& vtx = triMesh.pVertices[i]; - if (triMesh.pWeights[i] != 0) - { - Vec3 scl = Vec3(1.0f, 1.0f, 1.0f) * (1.0f - triMesh.pWeights[i]) + vScale * triMesh.pWeights[i]; - Matrix34 tm = modRefFrame * Matrix33::CreateScale(scl) * modRefFrameInverse; - vtx.pos = tm.TransformPoint(vtx.pos); - } - } - } - - SetModified(); -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::CopyToMesh(CTriMesh& toMesh, int nCopyFlags) -{ - if (!m_pSubObjCache) - { - return; - } - - toMesh.Copy(*m_pSubObjCache->pTriMesh, nCopyFlags); -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::CopyFromMesh(CTriMesh& fromMesh, int nCopyFlags, bool bUndo) -{ - if (m_pSubObjCache) - { - m_pSubObjCache->pTriMesh->Copy(fromMesh, nCopyFlags); - } - else - { - /* - CMesh mesh; - CTriMesh triMesh; - triMesh.Copy( fromMesh ); - trimesh.void CopyToMeshFast( CMesh &mesh ); - */ - } - if (bUndo) - { - UpdateIndexedMeshFromCache(true); - OnSelectionChange(); - } - - if (m_pSubObjCache) - { - UpdateSubObjCache(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::SaveToCGF(const char* sFilename, CPakFile* pPakFile, _smart_ptr pMaterial) -{ - if (m_pStatObj) - { - // Save this EdMesh to CGF file. - m_filename = Path::MakeGamePath(sFilename); - - _smart_ptr pOriginalMaterial = m_pStatObj->GetMaterial(); - if (pMaterial) - { - m_pStatObj->SetMaterial(pMaterial); - } - - if (!pPakFile) - { - m_pStatObj->SaveToCGF(sFilename); - } - else - { - IChunkFile* pChunkFile = NULL; - if (m_pStatObj->SaveToCGF(sFilename, &pChunkFile)) - { - void* pMemFile = NULL; - int nFileSize = 0; - - pChunkFile->WriteToMemoryBuffer(&pMemFile, &nFileSize); - pPakFile->UpdateFile(sFilename, pMemFile, nFileSize, true, AZ::IO::INestedArchive::LEVEL_FASTER); - pChunkFile->Release(); - } - } - - // Restore original material. - if (pMaterial) - { - m_pStatObj->SetMaterial(pOriginalMaterial); - } - } -} - -////////////////////////////////////////////////////////////////////////// -CTriMesh* CEdMesh::GetMesh() -{ - if (m_pSubObjCache) - { - return m_pSubObjCache->pTriMesh; - } - return 0; -} - -////////////////////////////////////////////////////////////////////////// -CEdMesh* CEdMesh::CreateMesh(const char* name) -{ - IStatObj* pStatObj = gEnv->p3DEngine->CreateStatObj(); - if (pStatObj) - { - CEdMesh* pEdMesh = new CEdMesh; - pEdMesh->m_pStatObj = pStatObj; - pEdMesh->m_pStatObj->AddRef(); - - // Force create of indexed mesh. - pEdMesh->m_pStatObj->GetIndexedMesh(true); - - // Not found, Make new. - pEdMesh->m_filename = name; - - if (!pEdMesh->m_pSubObjCache) - { - pEdMesh->m_pSubObjCache = new SubObjCache; - pEdMesh->m_pSubObjCache->pTriMesh = new CTriMesh; - pEdMesh->m_pSubObjCache->worldTM.SetIdentity(); - pEdMesh->m_pSubObjCache->invWorldTM.SetIdentity(); - } - return pEdMesh; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::InvalidateMesh() -{ - if (m_pSubObjCache) - { - UpdateIndexedMeshFromCache(false); - } - if (m_pStatObj) - { - m_pStatObj->Invalidate(true); - } -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::SetWorldTM(const Matrix34& worldTM) -{ - if (!m_pSubObjCache) - { - return; - } - - m_pSubObjCache->worldTM = worldTM; - m_pSubObjCache->invWorldTM = worldTM.GetInverted(); - - ////////////////////////////////////////////////////////////////////////// - // Transform vertices and normals to world space and store in cached mesh. - ////////////////////////////////////////////////////////////////////////// - CTriMesh& triMesh = *m_pSubObjCache->pTriMesh; - int nVerts = triMesh.GetVertexCount(); - triMesh.ReallocStream(CTriMesh::WS_POSITIONS, nVerts); - for (int i = 0; i < nVerts; i++) - { - triMesh.pWSVertices[i] = worldTM.TransformPoint(triMesh.pVertices[i].pos); - } -} - -////////////////////////////////////////////////////////////////////////// -void CEdMesh::DebugDraw(const SGeometryDebugDrawInfo& info, float fExtrdueScale) -{ - if (m_pStatObj) - { - m_pStatObj->DebugDraw(info, fExtrdueScale); - } -} diff --git a/Code/Sandbox/Editor/Geometry/EdMesh.h b/Code/Sandbox/Editor/Geometry/EdMesh.h deleted file mode 100644 index 52dc1fc25d..0000000000 --- a/Code/Sandbox/Editor/Geometry/EdMesh.h +++ /dev/null @@ -1,194 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Editor structure that wraps access to IStatObj - - -#ifndef CRYINCLUDE_EDITOR_GEOMETRY_EDMESH_H -#define CRYINCLUDE_EDITOR_GEOMETRY_EDMESH_H -#pragma once - -#include "EdGeometry.h" -#include "Objects/SubObjSelection.h" -#include "TriMesh.h" - -// Flags that can be set on CEdMesh. -enum CEdMeshFlags -{ -}; - -////////////////////////////////////////////////////////////////////////// -// Description: -// CEdMesh is a Geometry kind representing simple mesh. -// Holds IStatObj interface from the 3D Engine. -////////////////////////////////////////////////////////////////////////// -class CRYEDIT_API CEdMesh - : public CEdGeometry -{ -public: - ////////////////////////////////////////////////////////////////////////// - // CEdGeometry implementation. - ////////////////////////////////////////////////////////////////////////// - virtual EEdGeometryType GetType() const { return GEOM_TYPE_MESH; }; - virtual void Serialize(CObjectArchive& ar); - - virtual void GetBounds(AABB& box); - virtual CEdGeometry* Clone(); - virtual IIndexedMesh* GetIndexedMesh(size_t idx = 0); - virtual void GetTM(Matrix34* pTM, size_t idx = 0); - virtual void SetModified(bool bModified = true); - virtual bool IsModified() const { return m_bModified; }; - virtual bool StartSubObjSelection(const Matrix34& nodeWorldTM, int elemType, int nFlags); - virtual void EndSubObjSelection(); - virtual void Display(DisplayContext& dc); - virtual bool HitTest(HitContext& hit); - bool GetSelectionReferenceFrame(Matrix34& refFrame); - virtual void ModifySelection(SSubObjSelectionModifyContext& modCtx, bool isUndo = true); - virtual void AcceptModifySelection(); - ////////////////////////////////////////////////////////////////////////// - - ~CEdMesh(); - - // Return filename of mesh. - const QString& GetFilename() const { return m_filename; }; - void SetFilename(const QString& filename); - - //! Reload geometry of mesh. - void ReloadGeometry(); - void AddUser(); - void RemoveUser(); - int GetUserCount() const { return m_nUserCount; }; - - ////////////////////////////////////////////////////////////////////////// - void SetFlags(int nFlags) { m_nFlags = nFlags; }; - int GetFlags() { return m_nFlags; } - ////////////////////////////////////////////////////////////////////////// - - //! Access stored IStatObj. - IStatObj* GetIStatObj() const { return m_pStatObj; } - - //! Returns true if filename and geomname refer to the same object as this one. - bool IsSameObject(const char* filename); - - //! RenderMesh. - void Render(SRendParams& rp, const SRenderingPassInfo& passInfo); - - //! Make new CEdMesh, if same IStatObj loaded, and CEdMesh for this IStatObj is allocated. - //! This instance of CEdMesh will be returned. - static CEdMesh* LoadMesh(const char* filename); - - // Creates a new mesh not from a file. - // Create a new StatObj and IndexedMesh. - static CEdMesh* CreateMesh(const char* name); - - //! Reload all geometries. - static void ReloadAllGeometries(); - static void ReleaseAll(); - - //! Check if default object was loaded. - bool IsDefaultObject(); - - ////////////////////////////////////////////////////////////////////////// - // Copy EdMesh data to the specified mesh. - void CopyToMesh(CTriMesh& toMesh, int nCopyFlags); - // Copy EdMesh data from the specified mesh. - void CopyFromMesh(CTriMesh& fromMesh, int nCopyFlags, bool bUndo); - - // Retrieve mesh class. - CTriMesh* GetMesh(); - - ////////////////////////////////////////////////////////////////////////// - void InvalidateMesh(); - void SetWorldTM(const Matrix34& worldTM); - - // Save mesh into the file. - // Optionally can provide pointer to the pak file where to save files into. - void SaveToCGF(const char* sFilename, CPakFile* pPakFile = NULL, _smart_ptr pMaterial = NULL); - - // Draw debug representation of this mesh. - void DebugDraw(const SGeometryDebugDrawInfo& info, float fExtrdueScale = 0.01f); - -private: - ////////////////////////////////////////////////////////////////////////// - CEdMesh(IStatObj* pGeom); - CEdMesh(); - void UpdateSubObjCache(); - void UpdateIndexedMeshFromCache(bool bFast); - void OnSelectionChange(); - - ////////////////////////////////////////////////////////////////////////// - struct SSubObjHitTestEnvironment - { - Vec3 vWSCameraPos; - Vec3 vWSCameraVector; - Vec3 vOSCameraVector; - - bool bHitTestNearest; - bool bHitTestSelected; - bool bSelectOnHit; - bool bAdd; - bool bRemove; - bool bSelectValue; - bool bHighlightOnly; - bool bIgnoreBackfacing; - }; - struct SSubObjHitTestResult - { - CTriMesh::EStream stream; // To What stream of the TriMesh this result apply. - MeshElementsArray elems; // List of hit elements. - float minDistance; // Minimal distance to the hit. - SSubObjHitTestResult() { minDistance = FLT_MAX; } - }; - bool HitTestVertex(HitContext& hit, SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result); - bool HitTestEdge(HitContext& hit, SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result); - bool HitTestFace(HitContext& hit, SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result); - - // Return`s true if selection changed. - bool SelectSubObjElements(SSubObjHitTestEnvironment& env, SSubObjHitTestResult& result); - bool IsHitTestResultSelected(SSubObjHitTestResult& result); - - ////////////////////////////////////////////////////////////////////////// - //! CGF filename. - QString m_filename; - IStatObj* m_pStatObj; - int m_nUserCount; - int m_nFlags; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - typedef std::map > MeshMap; - static MeshMap m_meshMap; - - // This cache is created when sub object selection is needed. - struct SubObjCache - { - // Cache of data in geometry. - // World space mesh. - CTriMesh* pTriMesh; - Matrix34 worldTM; - Matrix34 invWorldTM; - CBitArray m_tempBitArray; - bool bNoDisplay; - - SubObjCache() - : pTriMesh(0) - , bNoDisplay(false) {}; - }; - SubObjCache* m_pSubObjCache; - bool m_bModified; - - std::vector m_tempIndexedMeshes; - std::vector m_tempMatrices; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_GEOMETRY_EDMESH_H diff --git a/Code/Sandbox/Editor/Grid.cpp b/Code/Sandbox/Editor/Grid.cpp index aa9e980069..50702f8cb2 100644 --- a/Code/Sandbox/Editor/Grid.cpp +++ b/Code/Sandbox/Editor/Grid.cpp @@ -136,31 +136,10 @@ Matrix34 CGrid::GetMatrix() const Ang3 angles = Ang3(rotationAngles.x * gf_PI / 180.0, rotationAngles.y * gf_PI / 180.0, rotationAngles.z * gf_PI / 180.0); tm = Matrix33::CreateRotationXYZ(angles); - - if (gSettings.snap.bGridGetFromSelected) - { - CSelectionGroup* sel = GetIEditor()->GetSelection(); - if (sel->GetCount() > 0) - { - CBaseObject* obj = sel->GetObject(0); - tm = obj->GetWorldTM(); - tm.OrthonormalizeFast(); - tm.SetTranslation(Vec3(0, 0, 0)); - } - } } else if (GetIEditor()->GetReferenceCoordSys() == COORDS_LOCAL) { tm.SetIdentity(); - - CSelectionGroup* sel = GetIEditor()->GetSelection(); - if (sel->GetCount() > 0) - { - CBaseObject* obj = sel->GetObject(0); - tm = obj->GetWorldTM(); - tm.OrthonormalizeFast(); - tm.SetTranslation(Vec3(0, 0, 0)); - } } else { diff --git a/Code/Sandbox/Editor/GridSettingsDialog.cpp b/Code/Sandbox/Editor/GridSettingsDialog.cpp index b16dbe4197..ecabdc4e6a 100644 --- a/Code/Sandbox/Editor/GridSettingsDialog.cpp +++ b/Code/Sandbox/Editor/GridSettingsDialog.cpp @@ -39,8 +39,6 @@ CGridSettingsDialog::CGridSettingsDialog(QWidget* pParent /*=NULL*/) connect(ui->m_userDefined, &QCheckBox::clicked, this, &CGridSettingsDialog::OnBnUserDefined); connect(ui->m_getFromObject, &QCheckBox::clicked, this, &CGridSettingsDialog::OnBnGetFromObject); - connect(ui->m_getAnglesFromObject, &QPushButton::clicked, this, &CGridSettingsDialog::OnBnGetAngles); - connect(ui->m_getTranslationFromObject, &QPushButton::clicked, this, &CGridSettingsDialog::OnBnGetTranslation); auto doubleSpinBoxValueChanged = static_cast(&QDoubleSpinBox::valueChanged); @@ -115,39 +113,6 @@ void CGridSettingsDialog::OnBnGetFromObject() EnableGridPropertyControls(ui->m_userDefined->isChecked(), ui->m_getFromObject->isChecked()); } -void CGridSettingsDialog::OnBnGetAngles() -{ - CSelectionGroup* sel = GetIEditor()->GetSelection(); - if (sel->GetCount() > 0) - { - CBaseObject* obj = sel->GetObject(0); - Matrix34 tm = obj->GetWorldTM(); - AffineParts ap; - ap.SpectralDecompose(tm); - - Vec3 rotation = Vec3(RAD2DEG(Ang3::GetAnglesXYZ(Matrix33(ap.rot)))); - - ui->m_angleX->setValue(rotation.x); - ui->m_angleY->setValue(rotation.y); - ui->m_angleZ->setValue(rotation.z); - } -} - -void CGridSettingsDialog::OnBnGetTranslation() -{ - CSelectionGroup* sel = GetIEditor()->GetSelection(); - if (sel->GetCount() > 0) - { - CBaseObject* obj = sel->GetObject(0); - Matrix34 tm = obj->GetWorldTM(); - Vec3 translation = tm.GetTranslation(); - - ui->m_translationX->setValue(translation.x); - ui->m_translationY->setValue(translation.y); - ui->m_translationZ->setValue(translation.z); - } -} - void CGridSettingsDialog::EnableGridPropertyControls(const bool isUserDefined, const bool isGetFromObject) { ui->m_getFromObject->setEnabled(isUserDefined == true); diff --git a/Code/Sandbox/Editor/GridSettingsDialog.h b/Code/Sandbox/Editor/GridSettingsDialog.h index f82278ccb7..fe5934ec7e 100644 --- a/Code/Sandbox/Editor/GridSettingsDialog.h +++ b/Code/Sandbox/Editor/GridSettingsDialog.h @@ -51,8 +51,6 @@ private slots: void accept() override; void OnBnUserDefined(); void OnBnGetFromObject(); - void OnBnGetAngles(); - void OnBnGetTranslation(); void OnValueUpdate(); private: diff --git a/Code/Sandbox/Editor/IEditor.h b/Code/Sandbox/Editor/IEditor.h index e1f41b9f41..f11beacf10 100644 --- a/Code/Sandbox/Editor/IEditor.h +++ b/Code/Sandbox/Editor/IEditor.h @@ -46,11 +46,8 @@ class CGameEngine; struct IIconManager; class CToolBoxManager; class CClassFactory; -class CMaterialManager; class CMusicManager; -class CMaterail; struct IEditorParticleManager; -class CLensFlareManager; class CEAXPresetManager; class CErrorReport; class CBaseLibraryItem; @@ -88,7 +85,6 @@ namespace WinWidget } struct ISystem; -struct I3DEngine; struct IRenderer; struct AABB; struct IEventLoopHook; @@ -140,7 +136,6 @@ enum EEditorNotifyEvent eNotify_OnEndLayerExport, // Sent after a layer have been exported. eNotify_OnCloseScene, // Send when the document is about to close. eNotify_OnSceneClosed, // Send when the document is closed. - eNotify_OnMissionChange, // Send when the current mission changes. eNotify_OnBeginLoad, // Sent when the document is start to load. eNotify_OnEndLoad, // Sent when the document loading is finished @@ -183,8 +178,6 @@ enum EEditorNotifyEvent eNotify_OnDisplayRenderUpdate, // Sent when editor finish terrain texture generation. - eNotify_OnTimeOfDayChange, // Time of day parameters where modified. - eNotify_OnDataBaseUpdate, // DataBase Library was modified. eNotify_OnLayerImportBegin, //layer import was started @@ -244,8 +237,6 @@ struct IDocListener virtual void OnLoadDocument() = 0; //! Called when document is being closed. virtual void OnCloseDocument() = 0; - //! Called when mission changes. - virtual void OnMissionChange() = 0; }; //! Derive from this class if you want to register for getting global editor notifications. @@ -434,7 +425,6 @@ struct IEditor virtual void DeleteThis() = 0; //! Access to Editor ISystem interface. virtual ISystem* GetSystem() = 0; - virtual I3DEngine* Get3DEngine() = 0; virtual IRenderer* GetRenderer() = 0; //! Access to class factory. virtual IEditorClassFactory* GetClassFactory() = 0; @@ -545,8 +535,6 @@ struct IEditor virtual CSettingsManager* GetSettingsManager() = 0; //! Get DB manager that own items of specified type. virtual IDataBaseManager* GetDBItemManager(EDataBaseItemType itemType) = 0; - //! Get Manager of Materials. - virtual CMaterialManager* GetMaterialManager() = 0; virtual IBaseLibraryManager* GetMaterialManagerLibrary() = 0; // Vladimir@conffx virtual IEditorMaterialManager* GetIEditorMaterialManager() = 0; // Vladimir@Conffx //! Returns IconManager. @@ -555,8 +543,6 @@ struct IEditor virtual IEditorPanelUtils* GetEditorPanelUtils() = 0; //! Get Music Manager. virtual CMusicManager* GetMusicManager() = 0; - //! Get Lens Flare Manager. - virtual CLensFlareManager* GetLensFlareManager() = 0; virtual float GetTerrainElevation(float x, float y) = 0; virtual Editor::EditorQtApplication* GetEditorQtApplication() = 0; virtual const QColor& GetColorByName(const QString& name) = 0; @@ -746,8 +732,6 @@ struct IEditor typedef AZStd::function TContextMenuExtensionFunc; virtual void RegisterObjectContextMenuExtension(TContextMenuExtensionFunc func) = 0; - virtual void SetCurrentMissionTime(float time) = 0; - virtual SSystemGlobalEnvironment* GetEnv() = 0; virtual IImageUtil* GetImageUtil() = 0; // Vladimir@conffx virtual SEditorSettings* GetEditorSettings() = 0; diff --git a/Code/Sandbox/Editor/IEditorImpl.cpp b/Code/Sandbox/Editor/IEditorImpl.cpp index a81aff86a9..53a2c120c4 100644 --- a/Code/Sandbox/Editor/IEditorImpl.cpp +++ b/Code/Sandbox/Editor/IEditorImpl.cpp @@ -53,14 +53,12 @@ AZ_POP_DISABLE_WARNING #include "KeyboardCustomizationSettings.h" #include "Export/ExportManager.h" #include "LevelIndependentFileMan.h" -#include "Material/MaterialManager.h" #include "TrackView/TrackViewSequenceManager.h" #include "AnimationContext.h" #include "GameEngine.h" #include "ToolBox.h" #include "MainWindow.h" #include "Alembic/AlembicCompiler.h" -#include "LensFlareEditor/LensFlareManager.h" #include "UIEnumsDatabase.h" #include "Util/Ruler.h" #include "RenderHelpers/AxisHelper.h" @@ -73,7 +71,6 @@ AZ_POP_DISABLE_WARNING #include "BackgroundTaskManager.h" #include "BackgroundScheduleManager.h" #include "EditorFileMonitor.h" -#include "Mission.h" #include "MainStatusBar.h" #include "SettingsBlock.h" @@ -118,29 +115,6 @@ static CCryEditDoc * theDocument; #undef GetCommandLine -namespace -{ - bool SelectionContainsComponentEntities() - { - bool result = false; - CSelectionGroup* pSelection = GetIEditor()->GetObjectManager()->GetSelection(); - if (pSelection) - { - CBaseObject* selectedObj = nullptr; - for (int selectionCounter = 0; selectionCounter < pSelection->GetCount(); ++selectionCounter) - { - selectedObj = pSelection->GetObject(selectionCounter); - if (selectedObj->GetType() == OBJTYPE_AZENTITY) - { - result = true; - break; - } - } - } - return result; - } -} - const char* CEditorImpl::m_crashLogFileName = "SessionStatus/editor_statuses.json"; CEditorImpl::CEditorImpl() @@ -168,9 +142,7 @@ CEditorImpl::CEditorImpl() , m_pAnimationContext(nullptr) , m_pSequenceManager(nullptr) , m_pToolBoxManager(nullptr) - , m_pMaterialManager(nullptr) , m_pMusicManager(nullptr) - , m_pLensFlareManager(nullptr) , m_pErrorReport(nullptr) , m_pLasLoadedLevelErrorReport(nullptr) , m_pErrorsDlg(nullptr) @@ -224,13 +196,11 @@ CEditorImpl::CEditorImpl() m_pIconManager = new CIconManager; m_pUndoManager = new CUndoManager; m_pToolBoxManager = new CToolBoxManager; - m_pMaterialManager = new CMaterialManager(regCtx); m_pAlembicCompiler = new CAlembicCompiler(); m_pSequenceManager = new CTrackViewSequenceManager; m_pAnimationContext = new CAnimationContext; m_pImageUtil = new CImageUtil_impl(); - m_pLensFlareManager = new CLensFlareManager; m_pResourceSelectorHost.reset(CreateResourceSelectorHost()); m_pRuler = new CRuler; m_selectedRegion.min = Vec3(0, 0, 0); @@ -345,7 +315,6 @@ CEditorImpl::~CEditorImpl() m_bExiting = true; // Can't save level after this point (while Crash) SAFE_RELEASE(m_pSourceControl); - SAFE_DELETE(m_pMaterialManager) SAFE_DELETE(m_pAlembicCompiler) SAFE_DELETE(m_pIconManager) SAFE_DELETE(m_pViewManager) @@ -415,7 +384,6 @@ void CEditorImpl::SetGameEngine(CGameEngine* ge) m_pObjectManager->LoadClassTemplates("Editor"); m_pObjectManager->RegisterCVars(); - m_pMaterialManager->Set3DEngine(); m_pAnimationContext->Init(); } @@ -472,15 +440,6 @@ ISystem* CEditorImpl::GetSystem() return m_pSystem; } -I3DEngine* CEditorImpl::Get3DEngine() -{ - if (gEnv) - { - return gEnv->p3DEngine; - } - return nullptr; -} - IRenderer* CEditorImpl::GetRenderer() { if (gEnv) @@ -1003,13 +962,8 @@ void CEditorImpl::CloseView(const GUID& classId) } } -IDataBaseManager* CEditorImpl::GetDBItemManager(EDataBaseItemType itemType) +IDataBaseManager* CEditorImpl::GetDBItemManager([[maybe_unused]] EDataBaseItemType itemType) { - switch (itemType) - { - case EDB_TYPE_MATERIAL: - return m_pMaterialManager; - } return 0; } @@ -1752,13 +1706,6 @@ void CEditorImpl::RegisterObjectContextMenuExtension(TContextMenuExtensionFunc f m_objectContextMenuExtensions.push_back(func); } -void CEditorImpl::SetCurrentMissionTime(float time) -{ - if (CMission* pMission = GetIEditor()->GetDocument()->GetCurrentMission()) - { - pMission->SetTime(time); - } -} // Vladimir@Conffx SSystemGlobalEnvironment* CEditorImpl::GetEnv() { @@ -1775,13 +1722,13 @@ SEditorSettings* CEditorImpl::GetEditorSettings() // Vladimir@Conffx IBaseLibraryManager* CEditorImpl::GetMaterialManagerLibrary() { - return m_pMaterialManager; + return nullptr; } // Vladimir@Conffx IEditorMaterialManager* CEditorImpl::GetIEditorMaterialManager() { - return m_pMaterialManager; + return nullptr; } IImageUtil* CEditorImpl::GetImageUtil() diff --git a/Code/Sandbox/Editor/IEditorImpl.h b/Code/Sandbox/Editor/IEditorImpl.h index 908136297b..bbef338cb2 100644 --- a/Code/Sandbox/Editor/IEditorImpl.h +++ b/Code/Sandbox/Editor/IEditorImpl.h @@ -42,7 +42,6 @@ class CUndoManager; class CGameEngine; class CExportManager; class CErrorsDlg; -class CLensFlareManager; class CIconManager; class CBackgroundTaskManager; class CTrackViewSequenceManager; @@ -117,7 +116,6 @@ public: bool IsInitialized() const{ return m_bInitialized; } bool SaveDocument(); ISystem* GetSystem(); - I3DEngine* Get3DEngine(); IRenderer* GetRenderer(); void WriteToConsole(const char* string) { CLogFile::WriteLine(string); }; void WriteToConsole(const QString& string) { CLogFile::WriteLine(string); }; @@ -181,9 +179,7 @@ public: bool IsSelectionLocked(); IDataBaseManager* GetDBItemManager(EDataBaseItemType itemType); - CMaterialManager* GetMaterialManager() { return m_pMaterialManager; } CMusicManager* GetMusicManager() { return m_pMusicManager; }; - CLensFlareManager* GetLensFlareManager() { return m_pLensFlareManager; }; IBackgroundTaskManager* GetBackgroundTaskManager() override; IBackgroundScheduleManager* GetBackgroundScheduleManager() override; @@ -324,7 +320,6 @@ public: void OnObjectContextMenuOpened(QMenu* pMenu, const CBaseObject* pObject); virtual void RegisterObjectContextMenuExtension(TContextMenuExtensionFunc func) override; - virtual void SetCurrentMissionTime(float time); virtual SSystemGlobalEnvironment* GetEnv() override; virtual IBaseLibraryManager* GetMaterialManagerLibrary() override; // Vladimir@Conffx virtual IEditorMaterialManager* GetIEditorMaterialManager() override; // Vladimir@Conffx @@ -381,10 +376,8 @@ protected: CAnimationContext* m_pAnimationContext; CTrackViewSequenceManager* m_pSequenceManager; CToolBoxManager* m_pToolBoxManager; - CMaterialManager* m_pMaterialManager; CAlembicCompiler* m_pAlembicCompiler; CMusicManager* m_pMusicManager; - CLensFlareManager* m_pLensFlareManager; CErrorReport* m_pErrorReport; //! Contains the error reports for the last loaded level. CErrorReport* m_pLasLoadedLevelErrorReport; diff --git a/Code/Sandbox/Editor/IconManager.cpp b/Code/Sandbox/Editor/IconManager.cpp index 09c2d41035..e06b89b38e 100644 --- a/Code/Sandbox/Editor/IconManager.cpp +++ b/Code/Sandbox/Editor/IconManager.cpp @@ -15,7 +15,6 @@ #include "IconManager.h" -#include #include // AzToolsFramework @@ -26,6 +25,7 @@ #include "Util/Image.h" #include "Util/ImageUtil.h" +#include #define HELPER_MATERIAL "Objects/Helper" @@ -77,12 +77,11 @@ void CIconManager::Done() ////////////////////////////////////////////////////////////////////////// void CIconManager::Reset() { - I3DEngine* pEngine = GetIEditor()->Get3DEngine(); // Do not unload objects. but clears them. int i; for (i = 0; i < sizeof(m_objects) / sizeof(m_objects[0]); i++) { - if (m_objects[i] && pEngine) + if (m_objects[i]) { m_objects[i]->Release(); } @@ -115,71 +114,6 @@ int CIconManager::GetIconTexture(const char* iconName) return 0; } - if (AZ::Interface::Get()) - { - ITexture* texture = GetIEditor()->GetRenderer() ? GetIEditor()->GetRenderer()->EF_LoadTexture(iconName) : nullptr; - if (texture) - { - id = texture->GetTextureID(); - m_textures[iconName] = id; - } - } - else - { - QString ext = Path::GetExt(iconName); - QString actualName = iconName; - - char iconPath[AZ_MAX_PATH_LEN] = { 0 }; - gEnv->pFileIO->ResolvePath(actualName.toUtf8().data(), iconPath, AZ_MAX_PATH_LEN); - - // if we can't find it at the resolved path, try the devroot if necessary: - if (!gEnv->pFileIO->Exists(iconPath)) - { - if (iconName[0] != '@') // it has no specified alias - { - if (QString::compare(ext, "dds", Qt::CaseInsensitive) != 0) // if its a DDS, it comes out of processed files in @assets@, and assets is assumed by default (legacy renderer) - { - // check for a source file - AZStd::string iconFullPath; - bool pathFound = false; - using AssetSysReqBus = AzToolsFramework::AssetSystemRequestBus; - AssetSysReqBus::BroadcastResult(pathFound, &AssetSysReqBus::Events::GetFullSourcePathFromRelativeProductPath, iconName, iconFullPath); - - if (pathFound) - { - azstrncpy(iconPath, AZ_MAX_PATH_LEN, iconFullPath.c_str(), iconFullPath.length() + 1); - } - } - } - } - - CImageEx image; - // Load icon. - if (CImageUtil::LoadImage(iconPath, image)) - { - IRenderer* pRenderer(GetIEditor()->GetRenderer()); - if (pRenderer->GetRenderType() != eRT_DX11) - { - image.SwapRedAndBlue(); - } - - if (QString::compare(ext, "bmp", Qt::CaseInsensitive) == 0 || QString::compare(ext, "jpg", Qt::CaseInsensitive) == 0) - { - int sz = image.GetWidth() * image.GetHeight(); - uint8* buf = (uint8*)image.GetData(); - for (int i = 0; i < sz; i++) - { - uint32 alpha = max(max(buf[i * 4], buf[i * 4 + 1]), buf[i * 4 + 2]); - alpha *= 2; - buf[i * 4 + 3] = (alpha > 255) ? 255 : alpha; - } - } - - id = pRenderer->DownLoadToVideoMemory((unsigned char*)image.GetData(), image.GetWidth(), image.GetHeight(), eTF_R8G8B8A8, eTF_R8G8B8A8, 0, 0, 0); - m_textures[iconName] = id; - } - } - return id; } @@ -196,39 +130,10 @@ int CIconManager::GetIconTexture(EIcon icon) return m_icons[icon]; } - -////////////////////////////////////////////////////////////////////////// -_smart_ptr CIconManager::GetHelperMaterial() -{ - if (!m_pHelperMtl) - { - m_pHelperMtl = GetIEditor()->Get3DEngine()->GetMaterialManager()->LoadMaterial(HELPER_MATERIAL); - } - return m_pHelperMtl; -}; - ////////////////////////////////////////////////////////////////////////// -IStatObj* CIconManager::GetObject(EStatObject object) +IStatObj* CIconManager::GetObject(EStatObject) { - assert(object >= 0 && object < eStatObject_COUNT); - - if (m_objects[object]) - { - return m_objects[object]; - } - - // Try to load this object. - m_objects[object] = GetIEditor()->Get3DEngine()->LoadStatObjUnsafeManualRef(g_ObjectNames[object], NULL, NULL, false); - if (!m_objects[object]) - { - CLogFile::FormatLine("Error: Load Failed: %s", g_ObjectNames[object]); - } - m_objects[object]->AddRef(); - if (GetHelperMaterial()) - { - m_objects[object]->SetMaterial(GetHelperMaterial()); - } - return m_objects[object]; + return nullptr; } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/IconManager.h b/Code/Sandbox/Editor/IconManager.h index 641e3f70a7..6c86627f3a 100644 --- a/Code/Sandbox/Editor/IconManager.h +++ b/Code/Sandbox/Editor/IconManager.h @@ -51,7 +51,6 @@ public: virtual IStatObj* GetObject(EStatObject object); virtual int GetIconTexture(const char* iconName); - virtual _smart_ptr GetHelperMaterial(); ////////////////////////////////////////////////////////////////////////// // Icon bitmaps. @@ -64,14 +63,11 @@ public: virtual void OnNewDocument() { Reset(); }; virtual void OnLoadDocument() { Reset(); }; virtual void OnCloseDocument() { Reset(); }; - virtual void OnMissionChange() { Reset(); }; ////////////////////////////////////////////////////////////////////////// private: StdMap m_textures; - _smart_ptr m_pHelperMtl; - IStatObj* m_objects[eStatObject_COUNT]; int m_icons[eIcon_COUNT]; diff --git a/Code/Sandbox/Editor/Include/IErrorReport.h b/Code/Sandbox/Editor/Include/IErrorReport.h index 8afe269324..f25a1163a3 100644 --- a/Code/Sandbox/Editor/Include/IErrorReport.h +++ b/Code/Sandbox/Editor/Include/IErrorReport.h @@ -21,7 +21,6 @@ #include // forward declarations. -class CMaterial; class CParticleItem; class CBaseObject; class CBaseLibraryItem; diff --git a/Code/Sandbox/Editor/Include/IIconManager.h b/Code/Sandbox/Editor/Include/IIconManager.h index 115d998be3..15ef37e23b 100644 --- a/Code/Sandbox/Editor/Include/IIconManager.h +++ b/Code/Sandbox/Editor/Include/IIconManager.h @@ -61,7 +61,6 @@ struct IIconManager virtual IStatObj* GetObject(EStatObject object) = 0; virtual int GetIconTexture(EIcon icon) = 0; virtual int GetIconTexture(const char* iconName) = 0; - virtual _smart_ptr GetHelperMaterial() = 0; virtual QImage* GetIconBitmap(const char* filename, bool& haveAlpha, uint32 effects = 0) = 0; // Register an Icon for the specific command virtual void RegisterCommandIcon([[maybe_unused]] const char* filename, [[maybe_unused]] int nCommandId) {} diff --git a/Code/Sandbox/Editor/LayoutWnd.cpp b/Code/Sandbox/Editor/LayoutWnd.cpp index 34a96bca53..54389f30c1 100644 --- a/Code/Sandbox/Editor/LayoutWnd.cpp +++ b/Code/Sandbox/Editor/LayoutWnd.cpp @@ -24,7 +24,6 @@ #include #include -#include #include // for AzQtComponents::Style // Editor diff --git a/Code/Sandbox/Editor/LensFlareEditor/ILensFlareListener.h b/Code/Sandbox/Editor/LensFlareEditor/ILensFlareListener.h deleted file mode 100644 index 913faf2bb3..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/ILensFlareListener.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_ILENSFLARELISTENER_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_ILENSFLARELISTENER_H -#pragma once - -class CLensFlareItem; -class CLensFlareElement; - -class ILensFlareChangeItemListener -{ -public: - virtual void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) = 0; - virtual void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem) = 0; -}; - -class ILensFlareChangeElementListener -{ -public: - virtual void OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement) = 0; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_ILENSFLARELISTENER_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.cpp deleted file mode 100644 index d30db3f5f3..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareAtomicList.h" - -// Qt -#include -#include - -// Editor -#include "LensFlareUtil.h" -#include "Util/Image.h" -#include "Util/ImageUtil.h" - - -struct QLensFlareAtomicListModel::Item -{ - QString text; - QSize size; - QPixmap pixmap; - EFlareType flareType; -}; - -CLensFlareAtomicList::CLensFlareAtomicList(QWidget* parent) - : CImageListCtrl(parent) - , m_model(new QLensFlareAtomicListModel(this)) -{ - setDragEnabled(true); - setDragDropMode(DragOnly); - setModel(m_model.data()); -} - -CLensFlareAtomicList::~CLensFlareAtomicList() -{ -} - -QModelIndex QLensFlareAtomicListModel::InsertItem(const FlareInfo& flareInfo) -{ - Item* pPreviewItem = new Item; - - if (flareInfo.imagename) - { - CImageEx* pImage = new CImageEx(); - if (CImageUtil::LoadImage(flareInfo.imagename, *pImage)) - { - pImage->SwapRedAndBlue(); - pPreviewItem->size = QSize(pImage->GetWidth(), pImage->GetHeight()); - QImage img(reinterpret_cast(pImage->GetData()), pImage->GetWidth(), pImage->GetHeight(), QImage::Format_RGB32); - pPreviewItem->pixmap = QPixmap::fromImage(img.copy()); - } - - delete pImage; - } - - if (pPreviewItem->pixmap.isNull()) - { - pPreviewItem->pixmap = QPixmap(":/water.png"); - pPreviewItem->size = QSize(64, 64); - } - - pPreviewItem->text = flareInfo.name; - pPreviewItem->flareType = flareInfo.type; - - const int row = m_items.count(); - beginInsertRows(QModelIndex(), row, row); - m_items.append(pPreviewItem); - endInsertRows(); - - return index(row, 0); -} - -void QLensFlareAtomicListModel::Populate() -{ - Clear(); - const FlareInfoArray::Props array = FlareInfoArray::Get(); - for (size_t i = 0; i < array.size; ++i) - { - const FlareInfo& flareInfo(array.p[i]); - if (LensFlareUtil::IsElement(flareInfo.type)) - { - InsertItem(flareInfo); - } - } -} - -void CLensFlareAtomicList::FillAtomicItems() -{ - if (m_model) - { - m_model->Populate(); - } -} - -void CLensFlareAtomicList::updateGeometries() -{ - ClearItemGeometries(); - - if (!model()) - { - return; - } - - const int rowCount = model()->rowCount(); - - const int nPageHorz = viewport()->width(); - const int nPageVert = viewport()->height(); - - if (nPageHorz == 0 || nPageVert == 0 || rowCount <= 0) - { - return; - } - - const QSize& borderSize = BorderSize(); - int x = borderSize.width(); - int y = borderSize.height(); - - QSize itemSize = ItemSize(); - const int nTextHeight = fontMetrics().height(); - const int xMax = nPageHorz - borderSize.width(); - int itemHeightMax = 0; - - for (int row = 0; row < rowCount; ++row) - { - QModelIndex index = m_model->index(row, 0); - itemSize = index.data(Qt::SizeHintRole).toSize(); - - if ((x + itemSize.width()) > xMax) - { - y += itemHeightMax + borderSize.height() + nTextHeight; - x = borderSize.width(); - itemHeightMax = 0; - } - - if (itemSize.height() > itemHeightMax) - { - itemHeightMax = itemSize.height(); - } - - SetItemGeometry(index, QRect(QPoint(x, y), itemSize)); - - x += itemSize.width() + borderSize.width(); - } - - verticalScrollBar()->setPageStep(viewport()->height()); - verticalScrollBar()->setRange(0, (y + itemHeightMax - viewport()->height())); -} - -QLensFlareAtomicListModel::QLensFlareAtomicListModel(QObject* parent) - : QAbstractListModel(parent) -{ -} - -QLensFlareAtomicListModel::~QLensFlareAtomicListModel() -{ -} - -void QLensFlareAtomicListModel::Clear() -{ - qDeleteAll(m_items); - m_items.clear(); -} - -int QLensFlareAtomicListModel::rowCount(const QModelIndex& parent) const -{ - if (parent.isValid()) - { - return 0; - } - - return m_items.count(); -} - -QVariant QLensFlareAtomicListModel::data(const QModelIndex& index, int role) const -{ - Item* item; - if (!index.isValid()) - { - return QVariant(); - } - else - { - item = ItemFromIndex(index); - if (!item) - { - return QVariant(); - } - } - - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - return item->text; - - case Qt::SizeHintRole: - return item->size; - - case Qt::DecorationRole: - return item->pixmap; - - case Qt::UserRole: - return item->flareType; - } - - return QVariant(); -} - -bool QLensFlareAtomicListModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - Item* item; - if (index.isValid()) - { - return false; - } - else - { - item = ItemFromIndex(index); - if (!item) - { - return false; - } - } - - switch (role) - { - case Qt::EditRole: - item->text = value.toString(); - break; - - case Qt::DecorationRole: - item->pixmap = value.value(); - break; - - case Qt::SizeHintRole: - item->size = value.toSize(); - break; - - default: - return false; - } - - emit dataChanged(index, index, QVector() << role); - return false; -} - -Qt::ItemFlags QLensFlareAtomicListModel::flags(const QModelIndex& index) const -{ - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled; -} - -EFlareType QLensFlareAtomicListModel::FlareTypeFromIndex(QModelIndex index) const -{ - Item* item; - if (!index.isValid()) - { - return eFT_Max; - } - else - { - item = ItemFromIndex(index); - if (!item) - { - return eFT_Max; - } - } - - return item->flareType; -} - -QLensFlareAtomicListModel::Item* QLensFlareAtomicListModel::ItemFromIndex(QModelIndex index) const -{ - if (!index.isValid()) - { - return nullptr; - } - - return m_items.at(index.row()); -} - -QStringList QLensFlareAtomicListModel::mimeTypes() const -{ - return { - QStringLiteral("application/x-o3de-flaretypes") - }; -} - -QMimeData* QLensFlareAtomicListModel::mimeData(const QModelIndexList& indexes) const -{ - QMimeData* data = new QMimeData(); - - QByteArray encoded; - QDataStream stream(&encoded, QIODevice::WriteOnly); - - for (const QModelIndex& index : indexes) - { - stream << static_cast(FlareTypeFromIndex(index)); - } - - data->setData(QStringLiteral("application/x-o3de-flaretypes"), encoded); - - return data; -} - -bool QLensFlareAtomicListModel::dropMimeData([[maybe_unused]] const QMimeData* data, [[maybe_unused]] Qt::DropAction action, [[maybe_unused]] int row, [[maybe_unused]] int column, [[maybe_unused]] const QModelIndex& parent) -{ - return false; -} - -Qt::DropActions QLensFlareAtomicListModel::supportedDragActions() const -{ - return Qt::CopyAction; -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.h deleted file mode 100644 index 5748ff07f7..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREATOMICLIST_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREATOMICLIST_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "Controls/ImageListCtrl.h" -#endif - -#if !defined(Q_MOC_RUN) -#include -#include -#endif - -class CLensFlareEditor; -class QLensFlareAtomicListModel; - -class CLensFlareAtomicList - : public CImageListCtrl -{ - Q_OBJECT -public: - CLensFlareAtomicList(QWidget* parent = nullptr); - virtual ~CLensFlareAtomicList(); - - void FillAtomicItems(); - -protected: - void updateGeometries() override; - -private: - QScopedPointer m_model; -}; - -class QLensFlareAtomicListModel - : public QAbstractListModel -{ - struct Item; - Q_OBJECT -public: - QLensFlareAtomicListModel(QObject* parent = nullptr); - ~QLensFlareAtomicListModel(); - - void Clear(); - void Populate(); - - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex& index) const override; - - QStringList mimeTypes() const override; - QMimeData* mimeData(const QModelIndexList& indexes) const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - Qt::DropActions supportedDragActions() const override; - - EFlareType FlareTypeFromIndex(QModelIndex index) const; - -protected: - QModelIndex InsertItem(const FlareInfo& flareInfo); - Item* ItemFromIndex(QModelIndex index) const; - -private: - QVector m_items; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREATOMICLIST_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.cpp deleted file mode 100644 index 763b5bf19b..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.cpp +++ /dev/null @@ -1,1225 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareEditor.h" - -// Qt -#include -#include - -// AzToolsFramework -#include -#include - -// AzQtComponents -#include -#include -#include - -// LmbrCentral -#include // for LmbrCentral::LensFlareAsset - -// Editor -#include "Clipboard.h" -#include "StringDlg.h" -#include "Settings.h" -#include "Include/IObjectManager.h" -#include "LensFlareView.h" -#include "LensFlareAtomicList.h" -#include "LensFlareElementTree.h" -#include "LensFlareManager.h" -#include "LensFlareItem.h" -#include "LensFlareLibrary.h" -#include "LensFlareUndo.h" -#include "LensFlareLightEntityTree.h" -#include "Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.h" -#include "ui_DatabaseFrameWnd.h" -#include "LyViewPaneNames.h" - - - - -CLensFlareEditor* CLensFlareEditor::s_pLensFlareEditor = NULL; -const char* CLensFlareEditor::s_pLensFlareEditorClassName = LyViewPane::LensFlareEditor; - -#define DISABLE_REFERENCETREE - -CLensFlareEditor::CLensFlareEditor(QWidget* pParent) - : CDatabaseFrameWnd(GetIEditor()->GetLensFlareManager(), pParent) - , m_pLensFlareView(NULL) - , m_pLensFlareAtomicList(NULL) - , m_pLensFlareElementTree(NULL) - , m_pWndProps(NULL) - , m_pLensFlareLightEntityTree(NULL) - , m_pLensFlareReferenceTree(NULL) - , m_LensFlareItemTree(NULL) -{ - assert(!s_pLensFlareEditor); - s_pLensFlareEditor = this; - - m_pLensFlareView = new CLensFlareView(this); - m_pLensFlareAtomicList = new CLensFlareAtomicList(this); - m_pLensFlareElementTree = new CLensFlareElementTree(this); - m_pWndProps = new ReflectedPropertyControl(this); - m_pWndProps->Setup(); - m_pLensFlareLightEntityTree = new CLensFlareLightEntityTree(this); -#ifndef DISABLE_REFERENCETREE - m_pLensFlareReferenceTree = new CLensFlareReferenceTree; -#endif - m_LensFlareItemTree = new CLensFlareItemTree(this); - - m_pLibraryItemTreeModel = new LensFlareItemTreeModel(this); - m_LensFlareItemTree->setModel(m_pLibraryItemTreeModel); - - setCentralWidget(m_pLensFlareView); - - setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); - setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - - m_advancedDockManager = new AzQtComponents::FancyDocking(this, "lensFlareEditor"); - - addDockWidget(Qt::LeftDockWidgetArea, m_LensFlareItemTree, tr("Lens Flare Tree"), false); - addDockWidget(Qt::LeftDockWidgetArea, m_pLensFlareElementTree, tr("Element Tree"), false); - - addDockWidget(Qt::BottomDockWidgetArea, m_pLensFlareAtomicList, tr("Basic Set"), false); -#ifndef DISABLE_REFERENCETREE - addDockWidget(Qt::TopDockWidgetArea, m_pLensFlareReferenceTree, tr("Reference Tree"), false); -#endif - - addDockWidget(Qt::RightDockWidgetArea, m_pWndProps, tr("Properties"), false); - addDockWidget(Qt::RightDockWidgetArea, m_pLensFlareLightEntityTree, tr("Light Entities"), false); - - m_pLensFlareElementTree->RegisterListener(this); - m_pLensFlareElementTree->RegisterListener(m_pLensFlareView); - - m_pWndProps->ExpandAll(); - m_pWndProps->SetUpdateCallback(AZStd::bind(&CLensFlareEditor::OnUpdateProperties, this, AZStd::placeholders::_1)); - m_pWndProps->SetCallbackOnNonModified(false); - - connect(ui->actionDBAdd, &QAction::triggered, this, &CLensFlareEditor::OnAddItem); - connect(ui->actionDBAssignToSelection, &QAction::triggered, this, &CLensFlareEditor::OnAssignFlareToLightEntities); - connect(ui->actionDBGetFromSelection, &QAction::triggered, this, &CLensFlareEditor::OnGetFlareFromSelection); - - connect(m_pLibraryItemTreeModel, &LibraryItemTreeModel::itemRenamed, this, &CLensFlareEditor::OnItemTreeDataRenamed); - - AzQtComponents::StyleManager::setStyleSheet(this, "style:LensFlareEditor.qss"); -} - -CLensFlareEditor::~CLensFlareEditor() -{ - if (m_pLensFlareElementTree) - { - m_pLensFlareElementTree->UnregisterListener(this); - m_pLensFlareElementTree->UnregisterListener(m_pLensFlareView); - } - - ReleaseWindowsToBePutIntoPanels(); - s_pLensFlareEditor = NULL; -} - -QMenu* CLensFlareEditor::createPopupMenu() -{ - return QMainWindow::createPopupMenu(); -} - -void CLensFlareEditor::OnInitDialog() -{ - InitTreeCtrl(); - - connect(m_LensFlareItemTree->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CLensFlareEditor::OnTvnItemSelChanged); - connect(m_LensFlareItemTree, &QWidget::customContextMenuRequested, this, &CLensFlareEditor::OnNotifyTreeRClick); - - m_pLensFlareAtomicList->FillAtomicItems(); - - ReloadLibs(); -} - -void CLensFlareEditor::addDockWidget(Qt::DockWidgetArea area, QWidget* widget, const QString& title, bool closable) -{ - QDockWidget* w = new AzQtComponents::StyledDockWidget(title); - w->setObjectName(widget->metaObject()->className()); - widget->setParent(w); - w->setWidget(widget); - if (!closable) - { - w->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); - } - QMainWindow::addDockWidget(area, w); -} - -void CLensFlareEditor::ReleaseWindowsToBePutIntoPanels() -{ - SAFE_DELETE(m_pWndProps); - SAFE_DELETE(m_pLensFlareAtomicList); - SAFE_DELETE(m_pLensFlareView); - SAFE_DELETE(m_pLensFlareElementTree); - SAFE_DELETE(m_pLensFlareLightEntityTree); -#ifndef DISABLE_REFERENCETREE - SAFE_DELETE(m_pLensFlareReferenceTree); -#endif -} - -const GUID& CLensFlareEditor::GetClassID() -{ - // {7e7a40e0-f0b8-4918-b94f-8cdd6c55f30b} - static const GUID guid = { - 0x7e7a40e0, 0xf0b8, 0x4918, { 0xb9, 0x4f, 0x8c, 0xdd, 0x6c, 0x55, 0xf3, 0x0b } - }; - return guid; -} - -void CLensFlareEditor::RegisterViewClass() -{ - AzToolsFramework::ViewPaneOptions options; - AzToolsFramework::RegisterViewPane(s_pLensFlareEditorClassName, LyViewPane::CategoryOther, options); - GetIEditor()->GetSettingsManager()->AddToolName("LensFlareEditor", "Lens Flare"); -} - -CLensFlareItem* CLensFlareEditor::GetSelectedLensFlareItem() const -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return nullptr; - } - return static_cast(selected.first().data(Qt::UserRole).value()); -} - -void CLensFlareEditor::ResetElementTreeControl() -{ - m_pLensFlareElementTree->InvalidateLensFlareItem(); -} - -void CLensFlareEditor::SelectItem(CBaseLibraryItem* item, bool bForceReload) -{ - if (item != m_pCurrentItem || bForceReload) - { - //Ensure that the property window is emptied out whenever the selected library changes - m_pWndProps->RemoveAllItems(); - } - - CDatabaseFrameWnd::SelectItem(item, bForceReload); -} - -void CLensFlareEditor::OnTvnItemSelChanged(const QItemSelection& selected, const QItemSelection& deselected) -{ - QModelIndex hItem; - - QModelIndexList selectedIndexes = selected.indexes(); - if (!selectedIndexes.isEmpty()) - { - hItem = selectedIndexes.first(); - } - - QModelIndex hPrevItem; - - QModelIndexList deselectedIndexes = deselected.indexes(); - if (!deselectedIndexes.isEmpty()) - { - hPrevItem = deselectedIndexes.first(); - } - - SelectLensFlareItem(hItem, hPrevItem); - UpdateLensFlareItem(GetSelectedLensFlareItem()); -} - -void CLensFlareEditor::SelectLensFlareItem(const QModelIndex& hItem, const QModelIndex& hPrevItem) -{ - if (hPrevItem.isValid() && CUndo::IsRecording()) - { - QString fullItemName = m_pLibraryItemTreeModel->GetFullName(hPrevItem); - if (!fullItemName.isEmpty()) - { - CUndo::Record(new CUndoLensFlareItemSelectionChange(fullItemName)); - } - } - m_pWndProps->RemoveAllItems(); - if (!hItem.isValid()) - { - return; - } - CLensFlareItem* pSelectedLensFlareItem = static_cast(hItem.data(Qt::UserRole).value()); - SelectItem(pSelectedLensFlareItem); -} - -void CLensFlareEditor::SelectLensFlareItem(const QModelIndex& hItem) -{ - QModelIndex hPrevItem; - - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (!selected.isEmpty()) - { - hPrevItem = selected.first(); - } - - SelectLensFlareItem(hItem, hPrevItem); -} - -void CLensFlareEditor::SelectLensFlareItem(const QString& fullItemName) -{ - QModelIndex hNewItem = m_pLibraryItemTreeModel->FindLibraryItemByFullName(fullItemName); - if (!hNewItem.isValid()) - { - return; - } - - SelectLensFlareItem(hNewItem); -} - -void CLensFlareEditor::RemovePropertyItems() -{ - m_pWndProps->RemoveAllItems(); -} - -bool CLensFlareEditor::IsExistTreeItem(const QString& name, bool bExclusiveSelectedItem) -{ - CBaseLibraryItem* pSelectedItem = GetSelectedLensFlareItem(); - - for (int i = 0; i < m_pLibrary->GetItemCount(); i++) - { - CBaseLibraryItem* pItem = static_cast(m_pLibrary->GetItem(i)); - - if (!bExclusiveSelectedItem || pItem != pSelectedItem) - { - if (pItem->GetName() == name) - { - return true; - } - } - } - - return false; -} - -void CLensFlareEditor::RenameLensFlareItem(CLensFlareItem* pLensFlareItem, const QString& newGroupName, const QString& newShortName) -{ - if (pLensFlareItem == NULL || newShortName.isEmpty() || newGroupName.isEmpty()) - { - return; - } - - m_pLibraryItemTreeModel->Rename(pLensFlareItem, newGroupName, newShortName); -} - -IOpticsElementBasePtr CLensFlareEditor::FindOptics(const QString& itemPath, const QString& opticsPath) -{ - CLensFlareItem* pItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(itemPath); - if (pItem == NULL) - { - return NULL; - } - - IOpticsElementBasePtr pOptics = pItem->GetOptics(); - if (pOptics == NULL) - { - return NULL; - } - - return LensFlareUtil::FindOptics(pOptics, opticsPath); -} - -void CLensFlareEditor::UpdateLensOpticsNames(const QString& oldFullName, const QString& newFullName) -{ - std::vector pEntityObjects; - GetIEditor()->GetObjectManager()->FindObjectsOfType(&CEntityObject::staticMetaObject, pEntityObjects); - for (int i = 0, iObjectSize(pEntityObjects.size()); i < iObjectSize; ++i) - { - CEntityObject* pEntity = (CEntityObject*)pEntityObjects[i]; - if (pEntity == NULL) - { - continue; - } - if (pEntity->CheckFlags(OBJFLAG_DELETED)) - { - continue; - } - if (!pEntity->IsLight()) - { - continue; - } - if (oldFullName == pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName)) - { - pEntity->SetOpticsName(newFullName); - } - } -} - -void CLensFlareEditor::OnCopy() -{ - UpdateClipboard(FLARECLIPBOARDTYPE_COPY); -} - -void CLensFlareEditor::OnPaste() -{ - if (!m_pLibrary) - { - return; - } - - CClipboard clipboard(this); - if (clipboard.IsEmpty()) - { - return; - } - - XmlNodeRef clipboardXML = clipboard.Get(); - if (clipboardXML == NULL) - { - return; - } - - Paste(clipboardXML); -} - -void CLensFlareEditor::Paste(XmlNodeRef node) -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - Paste(selected.first(), node); -} - -void CLensFlareEditor::Paste(const QModelIndex& hSelectedTreeItem, XmlNodeRef node) -{ - if (!m_pLibrary || node == NULL) - { - return; - } - - QString type; - node->getAttr("Type", type); - - QString sourceGroupName; - node->getAttr("GroupName", sourceGroupName); - - if (m_pLibrary == NULL) - { - return; - } - - bool bShouldCreateNewGroup(false); - if (!sourceGroupName.isEmpty()) - { - unsigned int nAnswer = CryMessageBox("Do you want to create a new group(YES) or add to the selected group(NO)?", "Question", MB_YESNOCANCEL); - if (nAnswer == IDCANCEL) - { - return; - } - bShouldCreateNewGroup = nAnswer == IDYES; - } - - QString targetGroupName; - - if (bShouldCreateNewGroup) - { - using namespace AZStd::placeholders; - targetGroupName = MakeValidName("NewGroup", AZStd::bind(&CDatabaseFrameWnd::DoesGroupExist, this, _1, _2)); - } - else - { - QModelIndex hTargetItem; - if (!m_pLibraryItemTreeModel->hasChildren(hSelectedTreeItem)) - { - hTargetItem = m_pLibraryItemTreeModel->parent(hSelectedTreeItem); - } - else - { - hTargetItem = hSelectedTreeItem; - } - - if (!hTargetItem.isValid()) - { - return; - } - - targetGroupName = m_pLibraryItemTreeModel->GetFullName(hTargetItem); - } - - CUndo undo(tr("Copy/Cut & Paste for Lens Flare").toUtf8()); - CLensFlareItem* pNewItem = NULL; - - for (int i = 0, iChildCount(node->getChildCount()); i < iChildCount; ++i) - { - LensFlareUtil::SClipboardData clipboardData; - clipboardData.FillThisFromXmlNode(node->getChild(i)); - - _smart_ptr pSourceItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(clipboardData.m_LensFlareFullPath); - if (pSourceItem == NULL) - { - continue; - } - - IOpticsElementBasePtr pSourceOptics = FindOptics(clipboardData.m_LensFlareFullPath, clipboardData.m_LensOpticsPath); - if (pSourceOptics == NULL) - { - continue; - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (clipboardData.m_From == LENSFLARE_ELEMENT_TREE) - { - LensFlareUtil::RemoveOptics(pSourceOptics); - } - else - { - DeleteItem(pSourceItem); - } - } - - QString sourceName; - if (clipboardData.m_From == LENSFLARE_ELEMENT_TREE) - { - sourceName = LensFlareUtil::GetShortName(pSourceOptics->GetName().c_str()); - } - else - { - sourceName = pSourceItem->GetShortName(); - } - - QString candidateName = targetGroupName + QString(".") + sourceName; - QString validName = MakeValidName(candidateName, - AZStd::bind(&CDatabaseFrameWnd::DoesItemExist, this, AZStd::placeholders::_1, AZStd::placeholders::_2)); - QString validShortName = LensFlareUtil::GetShortName(validName); - pNewItem = AddNewLensFlareItem(targetGroupName, validShortName); - assert(pNewItem); - if (pNewItem == NULL) - { - continue; - } - - if (LensFlareUtil::IsGroup(pSourceOptics->GetType())) - { - LensFlareUtil::CopyOptics(pSourceOptics, pNewItem->GetOptics(), true); - } - else - { - IOpticsElementBasePtr pNewOptics = LensFlareUtil::CreateOptics(pSourceOptics); - if (pNewOptics) - { - pNewItem->GetOptics()->AddElement(pNewOptics); - } - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (clipboardData.m_From == LENSFLARE_ITEM_TREE) - { - UpdateLensOpticsNames(pSourceItem->GetFullName(), pNewItem->GetFullName()); - } - if (pSourceItem != GetSelectedLensFlareItem()) - { - pSourceItem->UpdateLights(); - } - } - - LensFlareUtil::UpdateOpticsName(pNewItem->GetOptics()); - LensFlareUtil::ChangeOpticsRootName(pNewItem->GetOptics(), validShortName); - - ReloadItems(); - SelectLensFlareItem(m_pLibraryItemTreeModel->index(pNewItem), {}); - } -} - -void CLensFlareEditor::OnCut() -{ - UpdateClipboard(FLARECLIPBOARDTYPE_CUT); -} - -XmlNodeRef CLensFlareEditor::CreateXML(const char* type) const -{ - std::vector clipboardDataList; - QString groupName; - if (!GetClipboardDataList(clipboardDataList, groupName)) - { - return NULL; - } - return LensFlareUtil::CreateXMLFromClipboardData(type, groupName, false, clipboardDataList); -} - -void CLensFlareEditor::UpdateClipboard(const char* type) const -{ - std::vector clipboardDataList; - QString groupName; - if (!GetClipboardDataList(clipboardDataList, groupName)) - { - return; - } - LensFlareUtil::UpdateClipboard(type, groupName, false, clipboardDataList); -} - -bool CLensFlareEditor::GetClipboardDataList(std::vector& outList, QString& outGroupName) const -{ - CLensFlareLibrary* pLibrary = GetCurrentLibrary(); - if (pLibrary == NULL) - { - return false; - } - - std::vector clipboardDataList; - - CLensFlareItem* pLensFlareItem = GetSelectedLensFlareItem(); - if (pLensFlareItem) - { - clipboardDataList.push_back(LensFlareUtil::SClipboardData(LENSFLARE_ITEM_TREE, pLensFlareItem->GetFullName(), pLensFlareItem->GetShortName())); - } - else if (GetSelectedItemStatus() == eSIS_Group) - { - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return false; - } - outGroupName = selected.first().data(Qt::DisplayRole).toString(); - for (CBaseLibraryItem* pItem : m_pLibraryItemTreeModel->ChildItems(selected.first())) - { - pLensFlareItem = static_cast(pItem); - clipboardDataList.push_back(LensFlareUtil::SClipboardData(LENSFLARE_ITEM_TREE, pLensFlareItem->GetFullName(), pLensFlareItem->GetShortName())); - } - } - else - { - return false; - } - - outList = clipboardDataList; - - return true; -} - -void CLensFlareEditor::OnAddItem() -{ - if (!m_pLibrary) - { - return; - } - - StringGroupDlg dlg(tr("New Flare Name"), this); - dlg.SetGroup(m_selectedGroup); - - if (dlg.exec() != QDialog::Accepted || dlg.GetString().isEmpty()) - { - return; - } - - QString fullName = m_pItemManager->MakeFullItemName(m_pLibrary, dlg.GetGroup(), dlg.GetString()); - if (m_pItemManager->FindItemByName(fullName)) - { - Warning("Item with name %s already exist", fullName.toUtf8().data()); - return; - } - - CUndo undo(tr("Add flare library item").toUtf8()); - - CLensFlareItem* pNewLensFlare = AddNewLensFlareItem(dlg.GetGroup(), dlg.GetString()); - if (pNewLensFlare) - { - m_pLibraryItemTreeModel->Add(pNewLensFlare); - SelectItem(pNewLensFlare); - } -} - -CLensFlareItem* CLensFlareEditor::AddNewLensFlareItem(const QString& groupName, const QString& shortName) -{ - CLensFlareItem* pNewFlare = (CLensFlareItem*)m_pItemManager->CreateItem(m_pLibrary); - if (pNewFlare == NULL) - { - return NULL; - } - if (!SetItemName(pNewFlare, groupName, shortName)) - { - m_pItemManager->DeleteItem(pNewFlare); - return NULL; - } - pNewFlare->GetOptics()->SetName(pNewFlare->GetShortName().toUtf8().data()); - return pNewFlare; -} - -QModelIndex CLensFlareEditor::GetTreeLensFlareItem(CLensFlareItem* pItem) const -{ - return m_pLibraryItemTreeModel->index(pItem); -} - -void CLensFlareEditor::OnCopyNameToClipboard() -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - QString itemName = m_pLibraryItemTreeModel->GetFullName(selected.first()); - CClipboard clipboard(this); - clipboard.PutString(itemName); -} - -void CLensFlareEditor::OnAssignFlareToLightEntities() -{ - CLensFlareItem* pLensFlareItem = GetSelectedLensFlareItem(); - if (pLensFlareItem == NULL) - { - return; - } - std::vector entityList; - LensFlareUtil::GetSelectedLightEntities(entityList); - - for (int i = 0, iEntityCount(entityList.size()); i < iEntityCount; ++i) - { - entityList[i]->ApplyOptics(pLensFlareItem->GetFullName(), pLensFlareItem->GetOptics()); - } - - m_pLensFlareLightEntityTree->OnLensFlareChangeItem(pLensFlareItem); -} - -void CLensFlareEditor::OnSelectAssignedObjects() -{ - std::vector lightEntities; - LensFlareUtil::GetLightEntityObjects(lightEntities); - - CLensFlareItem* pLensFlareItem = GetSelectedLensFlareItem(); - if (pLensFlareItem == NULL) - { - return; - } - - int iLightSize(lightEntities.size()); - std::vector assignedObjects; - assignedObjects.reserve(iLightSize); - - for (int i = 0; i < iLightSize; ++i) - { - CEntityObject* pLightEntity = lightEntities[i]; - if (pLightEntity == NULL) - { - continue; - } - - IOpticsElementBasePtr pTargetOptics = pLightEntity->GetOpticsElement(); - if (pTargetOptics == NULL) - { - continue; - } - - if (QString::compare(pLensFlareItem->GetFullName(), pTargetOptics->GetName().c_str(), Qt::CaseInsensitive)) - { - continue; - } - - assignedObjects.push_back(pLightEntity); - } - - if (assignedObjects.empty()) - { - return; - } - - GetIEditor()->ClearSelection(); - for (int i = 0, iAssignedObjectsSize(assignedObjects.size()); i < iAssignedObjectsSize; ++i) - { - GetIEditor()->SelectObject(assignedObjects[i]); - } -} - -void CLensFlareEditor::OnGetFlareFromSelection() -{ - CEntityObject* pEntity = LensFlareUtil::GetSelectedLightEntity(); - if (pEntity == NULL) - { - QMessageBox::warning(this, tr("Warning"), tr("Please select a light entity first.")); - return; - } - if (m_pLibrary == NULL) - { - return; - } - - QString fullFlareName = pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName); - int nDotPosition = fullFlareName.indexOf("."); - if (nDotPosition == -1) - { - return; - } - - QString libraryName = fullFlareName.left(nDotPosition); - if (m_pLibrary->GetName() != libraryName) - { - GetIEditor()->GetLensFlareManager()->LoadItemByName(fullFlareName); - SelectLibrary(libraryName); - } - - SelectItemByName(fullFlareName); -} - -void CLensFlareEditor::OnUpdateTreeCtrl() -{ - OnGetFlareFromSelection(); -} - -void CLensFlareEditor::OnNotifyTreeRClick() -{ - CLensFlareItem* pLensFlareItem = 0; - - QModelIndex hItem = LensFlareUtil::GetTreeItemByHitTest(*GetTreeCtrl()); - if (hItem.isValid()) - { - pLensFlareItem = static_cast(hItem.data(Qt::UserRole).value()); - } - - SelectItem(pLensFlareItem); - - bool bGrayedFlag = false; - if (!pLensFlareItem) - { - bGrayedFlag = true; - } - - CClipboard clipboard(this); - bool bPasteFlags = true; - if (clipboard.IsEmpty()) - { - bPasteFlags = false; - } - - bool bCopyPasteCloneFlag = true; - if (GetSelectedItemStatus() != eSIS_Flare && GetSelectedItemStatus() != eSIS_Group) - { - bCopyPasteCloneFlag = false; - } - - QMenu menu; - - QAction* actionDBCut = menu.addAction(tr("Cut")); - actionDBCut->setEnabled(bCopyPasteCloneFlag); - connect(actionDBCut, &QAction::triggered, this, &CLensFlareEditor::OnCut); - - QAction* actionDBCopy = menu.addAction(tr("Copy")); - actionDBCopy->setEnabled(bCopyPasteCloneFlag); - connect(actionDBCopy, &QAction::triggered, this, &CLensFlareEditor::OnCopy); - - QAction* actionDBPaste = menu.addAction(tr("Paste")); - actionDBPaste->setEnabled(bPasteFlags); - connect(actionDBPaste, &QAction::triggered, this, &CLensFlareEditor::OnPaste); - - QAction* actionDBClone = menu.addAction(tr("Clone")); - actionDBClone->setEnabled(bCopyPasteCloneFlag); - connect(actionDBClone, &QAction::triggered, this, &CLensFlareEditor::OnClone); - - menu.addSeparator(); - - QAction* actionDBRename = menu.addAction(tr("Rename\tF2")); - connect(actionDBRename, &QAction::triggered, this, &CLensFlareEditor::OnRenameItem); - - QAction* actionDBRemove = menu.addAction(tr("Delete\tDel")); - connect(actionDBRemove, &QAction::triggered, this, &CLensFlareEditor::OnRemoveItem); - - menu.addSeparator(); - - QAction* actionDBAssignToSelection = menu.addAction(tr("Assign to Selected Objects")); - actionDBAssignToSelection->setEnabled(!bGrayedFlag); - connect(actionDBAssignToSelection, &QAction::triggered, this, &CLensFlareEditor::OnAssignFlareToLightEntities); - - QAction* actionDBSelectAssignedObjects = menu.addAction(tr("Select Assigned Objects")); - actionDBSelectAssignedObjects->setEnabled(!bGrayedFlag); - connect(actionDBSelectAssignedObjects, &QAction::triggered, this, &CLensFlareEditor::OnSelectAssignedObjects); - - QAction* actionDBCopyNameToClipboard = menu.addAction(tr("Copy Name to ClipBoard")); - connect(actionDBCopyNameToClipboard, &QAction::triggered, this, &CLensFlareEditor::OnCopyNameToClipboard); - - menu.exec(QCursor::pos()); -} - -bool CLensFlareEditor::SelectItemByName(const QString& itemName) -{ - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(itemName); - if (pLensFlareItem == NULL) - { - return false; - } - - GetIEditor()->GetLensFlareManager()->SetSelectedItem(pLensFlareItem); - - SelectLensFlareItem(m_pLibraryItemTreeModel->index(pLensFlareItem)); - - return true; -} - - -void CLensFlareEditor::StartEditItem(const QModelIndex& hItem) -{ - if (!hItem.isValid()) - { - return; - } - GetTreeCtrl()->edit(hItem); -} - -bool CLensFlareEditor::GetFullLensFlareItemName(const QModelIndex& hItem, QString& outFullName) const -{ - if (!hItem.isValid()) - { - return false; - } - - outFullName = m_pLibraryItemTreeModel->GetFullName(hItem); - - return true; -} - -CLensFlareEditor::ESelectedItemStatus CLensFlareEditor::GetSelectedItemStatus() const -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return eSIS_Unselected; - } - if (m_pLibraryItemTreeModel->hasChildren(selected.first())) - { - return eSIS_Group; - } - return eSIS_Flare; -} - -void CLensFlareEditor::SelectItemInLensFlareElementTreeByName(const QString& name) -{ - m_pLensFlareElementTree->SelectTreeItemByName(name); -} - -bool CLensFlareEditor::GetSelectedLensFlareName(QString& outName) const -{ - const CLensFlareElement* pElement = m_pLensFlareElementTree->GetCurrentLensFlareElement(); - if (pElement == NULL) - { - return false; - } - return pElement->GetName(outName); -} - -void CLensFlareEditor::ReloadItems() -{ - CDatabaseFrameWnd::ReloadItems(); - ResetElementTreeControl(); -} - -void CLensFlareEditor::OnRemoveItem() -{ - CLensFlareItem* pSelectedLensFlareItem = GetSelectedLensFlareItem(); - CUndo undo(tr("Remove Flare Group Item").toUtf8()); - - if (pSelectedLensFlareItem == NULL) - { - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex hLensFlareItem = selected.first(); - - QString fullLensFlareItemName = m_pLibraryItemTreeModel->GetFullName(hLensFlareItem); - - if (!fullLensFlareItemName.isEmpty()) - { - QString deleteMsgStr = tr("Delete %1?").arg(fullLensFlareItemName); - if (QMessageBox::question(this, tr("Confirmation"), deleteMsgStr) == QMessageBox::Yes) - { - CLensFlareLibrary* pLensFlareLibrary = GetCurrentLibrary(); - if (pLensFlareLibrary) - { - std::vector< _smart_ptr > deletedItems; - for (int i = 0, iItemCount(pLensFlareLibrary->GetItemCount()); i < iItemCount; ++i) - { - CLensFlareItem* pItem = (CLensFlareItem*)pLensFlareLibrary->GetItem(i); - if (pItem == NULL) - { - continue; - } - if (pItem->GetName().indexOf(fullLensFlareItemName) == -1) - { - continue; - } - QModelIndex hFlareItem = m_pLibraryItemTreeModel->index(pItem); - if (hFlareItem.isValid()) - { - UpdateLensOpticsNames(pItem->GetFullName(), ""); - deletedItems.push_back(pItem); - } - } - for (int i = 0, iDeleteItemSize(deletedItems.size()); i < iDeleteItemSize; ++i) - { - m_pLensFlareLightEntityTree->OnLensFlareDeleteItem(deletedItems[i]); - DeleteItem(deletedItems[i]); - } - - m_pLibraryItemTreeModel->removeRow(hLensFlareItem.row(), hLensFlareItem.parent()); - } - GetIEditor()->SetModifiedFlag(); - } - } - } - else - { - QString deleteMsgStr = tr("Delete %1?").arg(pSelectedLensFlareItem->GetName()); - // Remove prototype from prototype manager and library. - if (QMessageBox::question(this, tr("Confirmation"), deleteMsgStr) == QMessageBox::Yes) - { - m_pLensFlareLightEntityTree->OnLensFlareDeleteItem(pSelectedLensFlareItem); - - DeleteItem(pSelectedLensFlareItem); - - UpdateLensOpticsNames(pSelectedLensFlareItem->GetFullName(), ""); - - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (!selected.isEmpty()) - { - QModelIndex hLensFlareItem = selected.first(); - m_pLibraryItemTreeModel->removeRow(hLensFlareItem.row(), hLensFlareItem.parent()); - } - - m_pCurrentItem = NULL; - - GetIEditor()->SetModifiedFlag(); - SelectItem(0); - } - } -} - -void CLensFlareEditor::OnAddLibrary() -{ - StringDlg dlg(tr("Library Name"), this); - - dlg.SetCheckCallback([this](QString library) -> bool - { - QString path = m_pItemManager->MakeFilename(library); - if (CFileUtil::FileExists(path)) - { - QMessageBox::warning(this, tr("Library exists"), tr("Library '%1' already exists.").arg(library)); - return false; - } - return true; - }); - - if (dlg.exec() == QDialog::Accepted) - { - if (!dlg.GetString().isEmpty()) - { - SelectItem(0); - // Make new library. - QString library = dlg.GetString(); - NewLibrary(library); - ReloadLibs(); - SelectLibrary(library); - GetIEditor()->SetModifiedFlag(); - } - } -} - -void CLensFlareEditor::OnRenameItem() -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - StartEditItem(selected.first()); -} - -void CLensFlareEditor::OnReloadLib() -{ - CDatabaseFrameWnd::OnReloadLib(); - CLensFlareLibrary* pLibrary = GetCurrentLibrary(); - if (pLibrary == NULL) - { - return; - } - for (int i = 0, iItemCount(pLibrary->GetItemCount()); i < iItemCount; ++i) - { - CLensFlareItem* pItem = (CLensFlareItem*)pLibrary->GetItem(i); - if (pItem == NULL) - { - continue; - } - pItem->UpdateLights(NULL); - } -} - -void CLensFlareEditor::RegisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener) -{ - for (int i = 0, iSize(m_LensFlareChangeItemListenerList.size()); i < iSize; ++i) - { - if (m_LensFlareChangeItemListenerList[i] == pListener) - { - return; - } - } - m_LensFlareChangeItemListenerList.push_back(pListener); -} - -void CLensFlareEditor::UnregisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener) -{ - auto iter = m_LensFlareChangeItemListenerList.begin(); - for (; iter != m_LensFlareChangeItemListenerList.end(); ++iter) - { - if (*iter == pListener) - { - m_LensFlareChangeItemListenerList.erase(iter); - return; - } - } -} - -void CLensFlareEditor::OnItemTreeDataRenamed(CBaseLibraryItem* pItem, const QString& prevFullName) -{ - CLensFlareItem* pLensFlareItem = static_cast(pItem); - - UpdateLensOpticsNames(prevFullName, pLensFlareItem->GetFullName()); - LensFlareUtil::ChangeOpticsRootName(pLensFlareItem->GetOptics(), pLensFlareItem->GetShortName()); - - if (pLensFlareItem == GetSelectedLensFlareItem()) - { - UpdateLensFlareItem(pLensFlareItem); - } - - GetIEditor()->GetLensFlareManager()->Modified(); -} - -void CLensFlareEditor::UpdateLensFlareItem(CLensFlareItem* pLensFlareItem) -{ - for (int i = 0, iSize(m_LensFlareChangeItemListenerList.size()); i < iSize; ++i) - { - m_LensFlareChangeItemListenerList[i]->OnLensFlareChangeItem(pLensFlareItem); - } -} - -void CLensFlareEditor::OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement) -{ - ReflectedPropertyControl* pPropertyCtrl = m_pWndProps; - pPropertyCtrl->RemoveAllItems(); - - if (pLensFlareElement == NULL) - { - return; - } - - // Update properties in a property panel - if (pLensFlareElement && pLensFlareElement->GetProperties()) - { - pPropertyCtrl->AddVarBlock(pLensFlareElement->GetProperties()); - pPropertyCtrl->ExpandAllChildren(pPropertyCtrl->GetRootItem(), false); - pPropertyCtrl->setEnabled(true); - } -} - -void CLensFlareEditor::AddNewItemByAtomicOptics(const QModelIndex& hSelectedItem, EFlareType flareType) -{ - if (!LensFlareUtil::IsValidFlare(flareType)) - { - return; - } - - QString groupName; - QModelIndex hParentItem = hSelectedItem.parent(); - if (hParentItem.isValid()) - { - groupName = hParentItem.data(Qt::DisplayRole).toString(); - } - else - { - groupName = hSelectedItem.data(Qt::DisplayRole).toString(); - } - - FlareInfoArray::Props flareProps = FlareInfoArray::Get(); - QString itemName = MakeValidName(groupName + QString(".") + flareProps.p[flareType].name, - AZStd::bind(&CDatabaseFrameWnd::DoesItemExist, this, AZStd::placeholders::_1, AZStd::placeholders::_2)); - CLensFlareItem* pNewItem = AddNewLensFlareItem(groupName, LensFlareUtil::GetShortName(itemName)); - - if (pNewItem) - { - pNewItem->GetOptics()->AddElement(gEnv->pOpticsManager->Create(flareType)); - ReloadItems(); - SelectLensFlareItem(GetTreeLensFlareItem(pNewItem), {}); - } -} - -void CLensFlareEditor::OnUpdateProperties([[maybe_unused]] IVariable* var) -{ - GetIEditor()->GetLensFlareManager()->Modified(); -} - -AssetSelectionModel CLensFlareEditor::GetAssetSelectionModel() const -{ - return AssetSelectionModel::AssetTypeSelection(AZ::AzTypeInfo::Uuid()); -} - -LensFlareItemTreeModel::LensFlareItemTreeModel(CDatabaseFrameWnd* pParent) - : LibraryItemTreeModel(pParent) -{ -} - -QStringList LensFlareItemTreeModel::mimeTypes() const -{ - QStringList mimeTypes = LibraryItemTreeModel::mimeTypes(); - mimeTypes << QStringLiteral("application/x-o3de-flaretypes"); - return mimeTypes; -} - -bool LensFlareItemTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) -{ - if (LibraryItemTreeModel::dropMimeData(data, action, row, column, parent)) - { - return true; - } - - if (data->hasFormat(QStringLiteral("application/x-o3de-flaretypes"))) - { - QByteArray encoded = data->data(QStringLiteral("application/x-o3de-flaretypes")); - QDataStream stream(&encoded, QIODevice::ReadOnly); - - while (!stream.atEnd()) - { - int flareType; - stream >> flareType; - static_cast(m_dialog)->AddNewItemByAtomicOptics(parent, static_cast(flareType)); - } - - return true; - } - - return false; -} - -Qt::ItemFlags LensFlareItemTreeModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return Qt::ItemFlags(); - } - - return LibraryItemTreeModel::flags(index) | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled; -} - -Qt::DropActions LensFlareItemTreeModel::supportedDragActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -Qt::DropActions LensFlareItemTreeModel::supportedDropActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.h deleted file mode 100644 index d5753fa332..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.h +++ /dev/null @@ -1,233 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREEDITOR_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREEDITOR_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "DatabaseFrameWnd.h" -#include "LensFlareUtil.h" -#include "ILensFlareListener.h" -#include "LensFlareItemTree.h" -#include "UserMessageDefines.h" -#endif - -#include - -namespace AzQtComponents -{ - class FancyDocking; -} - -class CLensFlareView; -class CLensFlareElementTree; -class CLensFlareAtomicList; -class CLensFlareElementPropertyView; -class CLensFlareItem; -class CLensFlareLibrary; -class ReflectedPropertyControl; -class CLensFlareLightEntityTree; -class CLensFlareReferenceTree; - -class CLensFlareEditor - : public CDatabaseFrameWnd - , public ILensFlareChangeElementListener -{ - Q_OBJECT - -public: - static const GUID& GetClassID(); - static void RegisterViewClass(); - - CLensFlareEditor(QWidget* pParent = nullptr); - ~CLensFlareEditor(); - - QMenu* createPopupMenu() override; - - // CDatabaseFrameWnd overrides... - virtual void SelectItem(CBaseLibraryItem* item, bool bForceReload = false) override; - - CLensFlareItem* GetSelectedLensFlareItem() const; - bool GetSelectedLensFlareName(QString& outName) const; - void UpdateLensFlareItem(CLensFlareItem* pLensFlareItem); - void ResetElementTreeControl(); - - CLensFlareLibrary* GetCurrentLibrary() const - { - if (m_pLibrary == NULL) - { - return NULL; - } - return (CLensFlareLibrary*)&(*m_pLibrary); - } - - bool IsExistTreeItem(const QString& name, bool bExclusiveSelectedItem = false); - void RenameLensFlareItem(CLensFlareItem* pLensFlareItem, const QString& newGroupName, const QString& newShortName); - - IOpticsElementBasePtr FindOptics(const QString& itemPath, const QString& opticsPath); - - CLensFlareElementTree* GetLensFlareElementTree() - { - return m_pLensFlareElementTree; - } - - CLensFlareView* GetLensFlareView() const - { - return m_pLensFlareView; - } - - CLensFlareItemTree* GetLensFlareItemTree() - { - return m_LensFlareItemTree; - } - - void RemovePropertyItems(); - - ReflectedPropertyControl* GetPropertyCtrl() - { - return m_pWndProps; - } - - void UpdateLensOpticsNames(const QString& oldFullName, const QString& newFullName); - void SelectItemInLensFlareElementTreeByName(const QString& name); - void ReloadItems(); - - void RegisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener); - void UnregisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener); - - bool SelectItemByName(const QString& itemName); - - static CLensFlareEditor* GetLensFlareEditor() - { - return s_pLensFlareEditor; - } - - bool GetFullSelectedFlareItemName(QString& outFullName) const - { - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return false; - } - return GetFullLensFlareItemName(selected.first(), outFullName); - } - - void SelectLensFlareItem(const QString& fullItemName); - - const char* GetClassName() - { - return s_pLensFlareEditorClassName; - } - - void Paste(XmlNodeRef node); - void Paste(const QModelIndex& index, XmlNodeRef node); - XmlNodeRef CreateXML(const char* type) const; - - static const char* s_pLensFlareEditorClassName; - - QTreeView* GetTreeCtrl() override - { - return m_LensFlareItemTree; - } - - const QTreeView* GetTreeCtrl() const override - { - return m_LensFlareItemTree; - } - - void AddNewItemByAtomicOptics(const QModelIndex& hSelectedItem, EFlareType flareType); - -public slots: - void OnUpdateTreeCtrl(); - -protected: - static CLensFlareEditor* s_pLensFlareEditor; - - void OnInitDialog() override; - - void OnCopy(); - void OnPaste(); - void OnCut(); - - void UpdateClipboard(const char* type) const; - bool GetClipboardDataList(std::vector& outList, QString& outGroupName) const; - void OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement); - - void OnAddLibrary(); - void OnAssignFlareToLightEntities(); - void OnSelectAssignedObjects(); - void OnGetFlareFromSelection(); - void OnRenameItem(); - void OnAddItem(); - void OnRemoveItem(); - void OnCopyNameToClipboard(); - void OnNotifyTreeRClick(); - - void OnTvnItemSelChanged(const QItemSelection& selected, const QItemSelection& deselected); - void OnReloadLib(); - void ReleaseWindowsToBePutIntoPanels(); - void SelectLensFlareItem(const QModelIndex& hItem); - void SelectLensFlareItem(const QModelIndex& hItem, const QModelIndex& hPrevItem); - - void StartEditItem(const QModelIndex& hItem); - bool GetFullLensFlareItemName(const QModelIndex& hItem, QString& outFullName) const; - AssetSelectionModel GetAssetSelectionModel() const override; - - CLensFlareItem* AddNewLensFlareItem(const QString& groupName, const QString& shortName); - QModelIndex GetTreeLensFlareItem(CLensFlareItem* pItem) const; - - void OnItemTreeDataRenamed(CBaseLibraryItem* pItem, const QString& prevFullName); - - enum ESelectedItemStatus - { - eSIS_Unselected, - eSIS_Group, - eSIS_Flare - }; - ESelectedItemStatus GetSelectedItemStatus() const; - - void addDockWidget(Qt::DockWidgetArea area, QWidget* widget, const QString& title, bool closable = true); - void OnUpdateProperties(IVariable* var); - -private: - - CLensFlareView* m_pLensFlareView; - CLensFlareAtomicList* m_pLensFlareAtomicList; - CLensFlareElementTree* m_pLensFlareElementTree; - ReflectedPropertyControl* m_pWndProps; - CLensFlareLightEntityTree* m_pLensFlareLightEntityTree; - CLensFlareReferenceTree* m_pLensFlareReferenceTree; - CLensFlareItemTree* m_LensFlareItemTree; - - std::vector m_LensFlareChangeItemListenerList; - AzQtComponents::FancyDocking* m_advancedDockManager = nullptr; -}; - -class LensFlareItemTreeModel - : public LibraryItemTreeModel -{ - Q_OBJECT - -public: - LensFlareItemTreeModel(CDatabaseFrameWnd* pParent); - - Qt::ItemFlags flags(const QModelIndex& index) const override; - - QStringList mimeTypes() const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - Qt::DropActions supportedDragActions() const override; - Qt::DropActions supportedDropActions() const override; -}; - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREEDITOR_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.cpp deleted file mode 100644 index a51c788a8b..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareElement.h" - -// Editor -#include "LensFlareElementTree.h" -#include "LensFlareUtil.h" -#include "LensFlareItem.h" -#include "LensFlareEditor.h" -#include "LensFlareView.h" -#include "LensFlareLibrary.h" - - -CLensFlareElement::CLensFlareElement() - : m_vars(NULL) - , m_pOpticsElement(NULL) - , m_pParent(NULL) -{ -} - -CLensFlareElement::~CLensFlareElement() -{ -} - -void CLensFlareElement::OnInternalVariableChange(IVariable* pVar) -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return; - } - - IFuncVariable* pFuncVar = LensFlareUtil::GetFuncVariable(pOptics, pVar->GetUserData().toInt()); - if (pFuncVar == NULL) - { - return; - } - - switch (pVar->GetType()) - { - case IVariable::INT: - { - int var(0); - pVar->Get(var); - if (pFuncVar->paramType == e_COLOR) - { - ColorF color(pFuncVar->GetColorF()); - color.a = (float)var / 255.0f; - pFuncVar->InvokeSetter((void*)&color); - } - else if (pFuncVar->paramType == e_INT) - { - if (LensFlareUtil::HaveParameterLowBoundary(pFuncVar->name.c_str())) - { - LensFlareUtil::BoundaryProcess(var); - } - pFuncVar->InvokeSetter((void*)&var); - if (pFuncVar->GetInt() != var) - { - pVar->Set(pFuncVar->GetInt()); - } - } - } - break; - case IVariable::BOOL: - { - if (pFuncVar->paramType == e_BOOL) - { - bool var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::FLOAT: - { - if (pFuncVar->paramType == e_FLOAT) - { - float var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::VECTOR2: - { - if (pFuncVar->paramType == e_VEC2) - { - Vec2 var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::VECTOR: - { - Vec3 var; - pVar->Get(var); - if (pFuncVar->paramType == e_COLOR) - { - ColorF color(pFuncVar->GetColorF()); - color.r = var.x; - color.g = var.y; - color.b = var.z; - pFuncVar->InvokeSetter((void*)&color); - } - else if (pFuncVar->paramType == e_VEC3) - { - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::VECTOR4: - { - if (pFuncVar->paramType == e_VEC4) - { - Vec4 var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::STRING: - { - QString var; - pVar->Get(var); - if (pFuncVar->paramType == e_TEXTURE2D || pFuncVar->paramType == e_TEXTURE3D || pFuncVar->paramType == e_TEXTURE_CUBE) - { - var = var.trimmed(); - ITexture* pTexture = NULL; - if (!var.isEmpty()) - { - pTexture = GetIEditor()->GetRenderer()->EF_LoadTexture(var.toUtf8().data()); - } - pFuncVar->InvokeSetter((void*)pTexture); - if (pTexture) - { - pTexture->Release(); - } - } - } - break; - } - - UpdateLights(); -} - -bool CLensFlareElement::IsEnable() -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return false; - } - return pOptics->IsEnabled(); -} - -void CLensFlareElement::SetEnable(bool bEnable) -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return; - } - pOptics->SetEnabled(bEnable); - UpdateLights(); -} - -EFlareType CLensFlareElement::GetOpticsType() -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return eFT__Base__; - } - return pOptics->GetType(); -} - -bool CLensFlareElement::GetShortName(QString& outName) const -{ - QString fullName; - if (!GetName(fullName)) - { - return false; - } - int nPos = fullName.lastIndexOf('.'); - if (nPos == -1) - { - outName = fullName; - return true; - } - outName = fullName.right(fullName.length() - nPos - 1); - return true; -} - -void CLensFlareElement::UpdateLights() -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return; - } - if (GetLensFlareTree()) - { - if (GetLensFlareTree()->GetLensFlareItem()) - { - GetLensFlareTree()->GetLensFlareItem()->UpdateLights(pOptics); - } - } -} - -void CLensFlareElement::UpdateProperty(IOpticsElementBasePtr pOptics) -{ - std::vector funcs; - - if (CLensFlareElementTree* lensFlareTree = GetLensFlareTree(); lensFlareTree) - { - auto callbackItr = m_callbackCache.find(lensFlareTree); - if (callbackItr == m_callbackCache.end()) - { - IVariable::OnSetCallback callback = - AZStd::bind(&CLensFlareElementTree::OnInternalVariableChange, lensFlareTree, AZStd::placeholders::_1); - - auto result = m_callbackCache.insert(AZStd::make_pair(lensFlareTree, callback)); - callbackItr = result.first; - } - - funcs.push_back(&(callbackItr->second)); - } - - if (CLensFlareView* lensFlareView = GetLensFlareView(); lensFlareView) - { - auto callbackItr = m_callbackCache.find(lensFlareView); - if (callbackItr == m_callbackCache.end()) - { - IVariable::OnSetCallback callback = - AZStd::bind(&CLensFlareView::OnInternalVariableChange, lensFlareView, AZStd::placeholders::_1); - - auto result = m_callbackCache.insert(AZStd::make_pair(lensFlareView, callback)); - callbackItr = result.first; - } - - funcs.push_back(&(callbackItr->second)); - } - - if (CLensFlareLibrary* lensFlareLibrary = GetLensFlareLibrary(); lensFlareLibrary) - { - auto callbackItr = m_callbackCache.find(lensFlareLibrary); - if (callbackItr == m_callbackCache.end()) - { - IVariable::OnSetCallback callback = - AZStd::bind(&CLensFlareLibrary::OnInternalVariableChange, lensFlareLibrary, AZStd::placeholders::_1); - - auto result = m_callbackCache.insert(AZStd::make_pair(lensFlareLibrary, callback)); - callbackItr = result.first; - } - - funcs.push_back(&(callbackItr->second)); - } - - LensFlareUtil::SetVariablesTemplateFromOptics(pOptics, m_vars, funcs); -} - -CLensFlareElementTree* CLensFlareElement::GetLensFlareTree() const -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return NULL; - } - return pEditor->GetLensFlareElementTree(); -} - -CLensFlareView* CLensFlareElement::GetLensFlareView() const -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return NULL; - } - return pEditor->GetLensFlareView(); -} - -CLensFlareLibrary* CLensFlareElement::GetLensFlareLibrary() const -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return NULL; - } - return pEditor->GetCurrentLibrary(); -} - -CLensFlareElement* CLensFlareElement::GetParent() const -{ - return m_pParent; -} - -void CLensFlareElement::SetParent(CLensFlareElement* pParent) -{ - m_pParent = pParent; -} - -int CLensFlareElement::GetChildCount() const -{ - return m_children.size(); -} - -CLensFlareElement* CLensFlareElement::GetChildAt(int nPos) const -{ - if (nPos < 0 || nPos >= m_children.size()) - { - return nullptr; - } - return m_children[nPos]; -} - -void CLensFlareElement::AddChild(CLensFlareElement* pElement) -{ - pElement->SetParent(this); - m_children.push_back(pElement); -} - -void CLensFlareElement::InsertChild(int nPos, CLensFlareElement* pElement) -{ - pElement->SetParent(this); - m_children.insert(std::begin(m_children) + nPos, pElement); -} - -void CLensFlareElement::RemoveChild(int nPos) -{ - m_children.erase(std::begin(m_children) + nPos); -} - -void CLensFlareElement::SwapChildren(int nPos1, int nPos2) -{ - std::swap(m_children[nPos1], m_children[nPos2]); -} - -void CLensFlareElement::RemoveAllChildren() -{ - m_children.clear(); -} - -int CLensFlareElement::GetChildIndex(const CLensFlareElement* pElement) const -{ - auto it = std::find_if( - std::begin(m_children), - std::end(m_children), - [=](const LensFlareElementPtr& pChild) - { - return pChild.get() == pElement; - }); - - if (it != std::end(m_children)) - { - return std::distance(std::begin(m_children), it); - } - else - { - return -1; - } -} - -int CLensFlareElement::GetRow() const -{ - return m_pParent ? m_pParent->GetChildIndex(this) : 0; -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.h deleted file mode 100644 index 9860fa597e..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENT_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENT_H -#pragma once - -#include "IFlares.h" - -#include "Util/Variable.h" - -class CLensFlareElementTree; -class CLensFlareView; -class CLensFlareLibrary; - -class CLensFlareElement - : public CRefCountBase -{ -public: - - typedef _smart_ptr LensFlareElementPtr; - typedef std::vector LensFlareElementList; - - CLensFlareElement(); - virtual ~CLensFlareElement(); - - CVarBlock* GetProperties() const - { - return m_vars; - } - - void OnInternalVariableChange(IVariable* pVar); - - bool IsEnable(); - void SetEnable(bool bEnable); - EFlareType GetOpticsType(); - - bool GetName(QString& outName) const - { - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return false; - } - outName = pOptics->GetName(); - return true; - } - - bool GetShortName(QString& outName) const; - IOpticsElementBasePtr GetOpticsElement() const - { - return m_pOpticsElement; - } - void SetOpticsElement(IOpticsElementBasePtr pOptics) - { - m_pOpticsElement = pOptics; - UpdateProperty(m_pOpticsElement); - } - - CLensFlareElement* GetParent() const; - void SetParent(CLensFlareElement* pParent); - - int GetChildCount() const; - CLensFlareElement* GetChildAt(int nPos) const; - - void AddChild(CLensFlareElement* pElement); - void InsertChild(int nPos, CLensFlareElement* pElement); - - void RemoveChild(int nPos); - void RemoveAllChildren(); - - void SwapChildren(int nPos1, int nPos2); - - int GetChildIndex(const CLensFlareElement* pChild) const; - int GetRow() const; - -private: - - void UpdateLights(); - void UpdateProperty(IOpticsElementBasePtr pOptics); - - CLensFlareElementTree* GetLensFlareTree() const; - CLensFlareView* GetLensFlareView() const; - CLensFlareLibrary* GetLensFlareLibrary() const; - -private: - - IOpticsElementBasePtr m_pOpticsElement; - CVarBlockPtr m_vars; - - CLensFlareElement* m_pParent; - LensFlareElementList m_children; - - AZStd::map m_callbackCache; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENT_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.cpp deleted file mode 100644 index be687a5469..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.cpp +++ /dev/null @@ -1,1393 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareElementTree.h" - -// Qt -#include -#include -#include - -// Editor -#include "Clipboard.h" -#include "LensFlareItem.h" -#include "LensFlareManager.h" -#include "LensFlareUndo.h" -#include "LensFlareEditor.h" -#include "LensFlareLibrary.h" - - -template -static CLensFlareElement* FindLensFlareElement(CLensFlareElement* pRoot, Predicate pred) -{ - if (pred(pRoot)) - { - return pRoot; - } - - for (int i = 0, childCount = pRoot->GetChildCount(); i < childCount; i++) - { - if (CLensFlareElement* pElement = FindLensFlareElement(pRoot->GetChildAt(i), pred)) - { - return pElement; - } - } - - return nullptr; -} - -CLensFlareElementTree::CLensFlareElementTree(QWidget* pParent) - : QTreeView(pParent) - , m_model(new LensFlareElementTreeModel(this)) -{ - setHeaderHidden(true); - setContextMenuPolicy(Qt::CustomContextMenu); - setDragEnabled(true); - setAcceptDrops(true); - setDropIndicatorShown(true); - setDragDropMode(DragDrop); - - setModel(m_model.data()); - - connect(this, &QWidget::customContextMenuRequested, this, &CLensFlareElementTree::OnNotifyTreeRClick); - connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, &CLensFlareElementTree::OnTvnSelchangedTree); - connect(model(), &QAbstractItemModel::dataChanged, this, &CLensFlareElementTree::OnDataChanged); - connect(model(), &QAbstractItemModel::rowsInserted, this, &CLensFlareElementTree::OnRowsInserted); - connect(model(), &QAbstractItemModel::rowsRemoved, this, &CLensFlareElementTree::OnRowsRemoved); - connect(model(), &QAbstractItemModel::modelReset, this, &QTreeView::expandAll); -} - -void CLensFlareElementTree::OnInternalVariableChange(IVariable* pVar) -{ - CLensFlareElement::LensFlareElementPtr pCurrentElement = GetCurrentLensFlareElement(); - if (pCurrentElement == NULL) - { - return; - } - pCurrentElement->OnInternalVariableChange(pVar); -} - -CLensFlareElement* CLensFlareElementTree::GetCurrentLensFlareElement() const -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return nullptr; - } - return selected.first().data(Qt::UserRole).value(); -} - -void CLensFlareElementTree::OnNotifyTreeRClick() -{ - CLensFlareElement* pElement = GetCurrentLensFlareElement(); - - // Copy, Cut and Clone can't be done about a Root item so those menus should be disable when the selected item is a root item. - bool bGrayed = false; - if (!pElement || pElement->GetOpticsType() == eFT_Root) - { - bGrayed = true; - } - - QMenu menu; - - QAction* actionDBFlareAddGroup = menu.addAction(tr("Add Group")); - connect(actionDBFlareAddGroup, &QAction::triggered, this, &CLensFlareElementTree::OnAddGroup); - - menu.addSeparator(); - - QAction* actionDBFlareCopy = menu.addAction(tr("Copy")); - connect(actionDBFlareCopy, &QAction::triggered, this, &CLensFlareElementTree::OnCopy); - - QAction* actionDBFlareCut = menu.addAction(tr("Cut")); - actionDBFlareCut->setEnabled(!bGrayed); - connect(actionDBFlareCut, &QAction::triggered, this, &CLensFlareElementTree::OnCut); - - QAction* actionDBFlarePaste = menu.addAction(tr("Paste")); - connect(actionDBFlarePaste, &QAction::triggered, this, &CLensFlareElementTree::OnPaste); - - QAction* actionDBFlareClone = menu.addAction(tr("Clone")); - connect(actionDBFlareClone, &QAction::triggered, this, &CLensFlareElementTree::OnClone); - - menu.addSeparator(); - - QAction* actionDBFlareRename = menu.addAction(tr("Rename\tF2")); - connect(actionDBFlareRename, &QAction::triggered, this, &CLensFlareElementTree::OnRenameItem); - - QAction* actionDBFlareRemove = menu.addAction(tr("Delete\tDel")); - connect(actionDBFlareRemove, &QAction::triggered, this, &CLensFlareElementTree::OnRemoveItem); - - QAction* actionDBFlareRemoveAll = menu.addAction(tr("Delete All")); - connect(actionDBFlareRemoveAll, &QAction::triggered, this, &CLensFlareElementTree::OnRemoveAll); - - menu.addSeparator(); - - QAction* actionDBFlareItemUp = menu.addAction(tr("Up")); - connect(actionDBFlareItemUp, &QAction::triggered, this, &CLensFlareElementTree::OnItemUp); - - QAction* actionDBFlareItemDown = menu.addAction(tr("Down")); - connect(actionDBFlareItemDown, &QAction::triggered, this, &CLensFlareElementTree::OnItemDown); - - menu.exec(QCursor::pos()); -} - -void CLensFlareElementTree::OnTvnSelchangedTree([[maybe_unused]] const QItemSelection& selected, const QItemSelection& deselected) -{ - QModelIndexList deselectedIndices = deselected.indexes(); - if (!deselectedIndices.isEmpty()) - { - CLensFlareElement* pPrevLensFlareElement = deselectedIndices.first().data(Qt::UserRole).value(); - ElementChanged(pPrevLensFlareElement); - } - - CallChangeListeners(); -} - -void CLensFlareElementTree::ElementChanged(CLensFlareElement* pPrevLensFlareElement) -{ - if (!pPrevLensFlareElement) - { - return; - } - QString itemName; - if (pPrevLensFlareElement->GetName(itemName)) - { - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoLensFlareElementSelection(m_model->GetLensFlareItem(), itemName)); - } - } -} - -void CLensFlareElementTree::OnDataChanged([[maybe_unused]] const QModelIndex& index) -{ - CallChangeListeners(); -} - -void CLensFlareElementTree::OnRowsInserted(const QModelIndex& parent, int first, [[maybe_unused]] int last) -{ - if (parent.isValid()) - { - expand(parent); - SelectItem(parent.model()->index(first, 0, parent)); - CallChangeListeners(); - } -} - -void CLensFlareElementTree::OnRowsRemoved(const QModelIndex& parent, int first, [[maybe_unused]] int last) -{ - if (parent.isValid()) - { - SelectItem(parent.model()->index(first, 0, parent)); - CallChangeListeners(); - } -} - -void CLensFlareElementTree::keyPressEvent(QKeyEvent* event) -{ - if (event->key() == Qt::Key_F2) - { - OnRenameItem(); - event->accept(); - return; - } - else if (event->matches(QKeySequence::Delete)) - { - OnRemoveItem(); - event->accept(); - return; - } - - QTreeView::keyPressEvent(event); -} - -XmlNodeRef CLensFlareElementTree::CreateXML(const char* type) const -{ - std::vector clipboardData; - if (GetClipboardList(type, clipboardData)) - { - return LensFlareUtil::CreateXMLFromClipboardData(type, "", false, clipboardData); - } - return NULL; -} - -void CLensFlareElementTree::UpdateClipboard(const char* type, bool bPasteAtSameLevel) -{ - std::vector clipboardData; - if (GetClipboardList(type, clipboardData)) - { - LensFlareUtil::UpdateClipboard(type, "", bPasteAtSameLevel, clipboardData); - } -} - -bool CLensFlareElementTree::GetClipboardList([[maybe_unused]] const char* type, std::vector& outList) const -{ - CLensFlareElement::LensFlareElementPtr pElement = GetCurrentLensFlareElement(); - if (pElement == NULL) - { - return false; - } - QString name; - if (!pElement->GetName(name)) - { - return false; - } - - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return false; - } - - CLensFlareItem* pLensFlareItem = pEditor->GetSelectedLensFlareItem(); - if (pLensFlareItem == NULL) - { - return false; - } - - outList.push_back(LensFlareUtil::SClipboardData(LENSFLARE_ELEMENT_TREE, pLensFlareItem->GetFullName(), name)); - - return true; -} - -void CLensFlareElementTree::OnAddGroup() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - CUndo undo(tr("Add library item").toUtf8()); - m_model->AddElement(selected.first(), 0, eFT_Group); - GetIEditor()->GetLensFlareManager()->Modified(); -} - -void CLensFlareElementTree::OnCopy() -{ - UpdateClipboard(FLARECLIPBOARDTYPE_COPY, false); -} - -void CLensFlareElementTree::OnCut() -{ - Cut(false); -} - -void CLensFlareElementTree::Cut(bool bPasteAtSameLevel) -{ - UpdateClipboard(FLARECLIPBOARDTYPE_CUT, bPasteAtSameLevel); -} - -CLensFlareItem* CLensFlareElementTree::GetLensFlareItem() const -{ - return m_model->GetLensFlareItem(); -} - -void CLensFlareElementTree::OnPaste() -{ - CClipboard clipboard(this); - if (clipboard.IsEmpty()) - { - return; - } - - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - XmlNodeRef xmlNode = clipboard.Get(); - if (xmlNode == NULL) - { - return; - } - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - m_model->Paste(selected.first(), xmlNode); -} - -void CLensFlareElementTree::OnClone() -{ - OnCopy(); - OnPaste(); -} - -void CLensFlareElementTree::OnRenameItem() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - edit(selected.first()); -} - -void CLensFlareElementTree::OnRemoveItem() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex index = selected.first(); - - // A root item must not be removed. - if (!index.parent().isValid()) - { - return; - } - - CLensFlareElement::LensFlareElementPtr pCurrentElement = m_model->GetLensFlareElement(index); - if (pCurrentElement == NULL) - { - return; - } - - QString name; - pCurrentElement->GetName(name); - - QString str = tr("Delete %1?").arg(name); - if (QMessageBox::question(this, tr("Delete Confirmation"), str) == QMessageBox::Yes) - { - CUndo undo(tr("Remove an optics element").toUtf8()); - m_model->removeRow(index.row(), index.parent()); - } -} - -void CLensFlareElementTree::OnRemoveAll() -{ - CUndo undo(tr("Remove All in FlareTreeCtrl").toUtf8()); - - if (QMessageBox::question(this, tr("Delete Confirmation"), tr("Do you want delete all?")) == QMessageBox::Yes) - { - m_model->RemoveAllElements(); - GetIEditor()->GetLensFlareManager()->Modified(); - } -} - -void CLensFlareElementTree::OnItemUp() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex index = selected.first(); - int row = index.row(); - if (row == 0) - { - return; - } - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - - CLensFlareElement* pElement = index.data(Qt::UserRole).value(); - m_model->MoveElement(pElement, row - 1, index.parent()); -} - -void CLensFlareElementTree::OnItemDown() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex index = selected.first(); - int row = index.row(); - if (row == m_model->rowCount(index.parent()) - 1) - { - return; - } - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - - CLensFlareElement* pElement = index.data(Qt::UserRole).value(); - m_model->MoveElement(pElement, row + 2, index.parent()); -} - -void CLensFlareElementTree::SelectItem(const QModelIndex& index) -{ - if (index.isValid()) - { - expand(index.parent()); - selectionModel()->select(index, QItemSelectionModel::ClearAndSelect); - } - else - { - selectionModel()->clear(); - } -} - -void CLensFlareElementTree::SelectTreeItemByName(const QString& name) -{ - SelectItem(m_model->GetTreeItemByName(name)); -} - -void CLensFlareElementTree::CallChangeListeners() -{ - CLensFlareElement* pElement = GetCurrentLensFlareElement(); - for (int i = 0, iSize(m_LensFlaresElementListeners.size()); i < iSize; ++i) - { - m_LensFlaresElementListeners[i]->OnLensFlareChangeElement(pElement); - } -} - -void CLensFlareElementTree::mousePressEvent(QMouseEvent* event) -{ - if (event->button() == Qt::LeftButton) - { - CUndo undo(tr("Changed Lens flares element").toUtf8()); - QTreeView::mousePressEvent(event); - } - else - { - QTreeView::mousePressEvent(event); - } -} - -void CLensFlareElementTree::InvalidateLensFlareItem() -{ - m_model->InvalidateLensFlareItem(); -} - -LensFlareElementTreeModel::LensFlareElementTreeModel(QObject* pParent) - : QAbstractItemModel(pParent) - , m_pRootElement(new CLensFlareElement) -{ - CLensFlareEditor::GetLensFlareEditor()->RegisterLensFlareItemChangeListener(this); -} - -LensFlareElementTreeModel::~LensFlareElementTreeModel() -{ - CLensFlareEditor::GetLensFlareEditor()->UnregisterLensFlareItemChangeListener(this); -} - -int LensFlareElementTreeModel::columnCount(const QModelIndex&) const -{ - return 1; -} - -QVariant LensFlareElementTreeModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - { - return {}; - } - - auto pElement = static_cast(index.internalPointer()); - - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - { - QString shortName; - pElement->GetShortName(shortName); - return shortName; - } - - case Qt::CheckStateRole: - return pElement->IsEnable() ? Qt::Checked : Qt::Unchecked; - - case Qt::UserRole: - return QVariant::fromValue(pElement); - } - - return {}; -} - -void LensFlareElementTreeModel::EnableElement(CLensFlareElement* pLensFlareElement, bool bEnable) -{ - StoreUndo(); - pLensFlareElement->SetEnable(bEnable); -} - -void LensFlareElementTreeModel::RenameElement(CLensFlareElement* pLensFlareElement, const QString& newName) -{ - StoreUndo(); - IOpticsElementBasePtr pOptics = pLensFlareElement->GetOpticsElement(); - if (pOptics) - { - pOptics->SetName(newName.toUtf8().data()); - LensFlareUtil::UpdateOpticsName(pOptics); - } -} - -QModelIndex LensFlareElementTreeModel::GetRootItem() const -{ - if (m_pRootElement->GetChildCount() == 0) - { - return {}; - } - - auto pRootElement = m_pRootElement->GetChildAt(0); - assert(pRootElement->GetOpticsType() == eFT_Root); - - return createIndex(0, 0, pRootElement); -} - -bool LensFlareElementTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid()) - { - return false; - } - - auto pElement = static_cast(index.internalPointer()); - - switch (role) - { - case Qt::CheckStateRole: - { - CUndo undo(tr("Update an enable checkbox for tree ctrl.").toUtf8()); - EnableElement(pElement, value.toInt() == Qt::Checked); - emit dataChanged(index, index); - return true; - } - - case Qt::EditRole: - { - QString text = value.toString(); - - CUndo undo(tr("Rename library item").toUtf8()); - - if (IsExistElement(text)) - { - QMessageBox::warning(0, tr("Warning"), tr("The identical name exists in a database")); - return false; - } - else if (text.contains(QLatin1Char('.'))) - { - QMessageBox::warning(0, tr("Warning"), tr("The name must not contain \".\"")); - return false; - } - else - { - CLensFlareElement* pLensFlareElement = GetLensFlareElement(index); - - QString prevName; - if (pLensFlareElement && pLensFlareElement->GetName(prevName)) - { - QString parentName(prevName); - int offset = parentName.lastIndexOf('.'); - if (offset == -1) - { - parentName = ""; - } - else - { - parentName.remove(offset + 1, parentName.length() - offset); - } - - if (index == GetRootItem()) - { - CLensFlareEditor* pLensFlareEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pLensFlareEditor) - { - CLensFlareItem* pLensFlareItem = pLensFlareEditor->GetSelectedLensFlareItem(); - if (pLensFlareItem) - { - QString candidateName = LensFlareUtil::ReplaceLastName(pLensFlareItem->GetName(), text); - if (pLensFlareEditor->IsExistTreeItem(candidateName, true)) - { - QMessageBox::warning(0, tr("Warning"), tr("The identical name exists in a database")); - return false; - } - pLensFlareEditor->RenameLensFlareItem(pLensFlareItem, pLensFlareItem->GetGroupName(), text); - } - } - else - { - QMessageBox::warning(0, tr("Warning"), tr("Renaming is not possible.")); - return false; - } - } - - RenameElement(pLensFlareElement, parentName + text); - emit dataChanged(index, index); - - GetIEditor()->GetLensFlareManager()->Modified(); - } - - return true; - } - } - } - - return false; -} - -Qt::ItemFlags LensFlareElementTreeModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return Qt::ItemFlags(); - } - - auto pElement = index.data(Qt::UserRole).value(); - - Qt::ItemFlags flags = QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled; - - if (pElement->GetOpticsType() != eFT_Root) - { - flags |= Qt::ItemIsDragEnabled; - } - - return flags; -} - -QModelIndex LensFlareElementTreeModel::index(int row, int column, const QModelIndex& parent) const -{ - if (!hasIndex(row, column, parent)) - { - return {}; - } - - auto parentNode = GetLensFlareElement(parent); - auto childNode = parentNode->GetChildAt(row); - - if (childNode) - { - return createIndex(row, column, childNode); - } - else - { - return {}; - } -} - -QModelIndex LensFlareElementTreeModel::parent(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return {}; - } - - auto childNode = static_cast(index.internalPointer()); - auto parentNode = childNode->GetParent(); - - if (parentNode == m_pRootElement.get()) - { - return {}; - } - - return createIndex(parentNode->GetRow(), 0, parentNode); -} - -int LensFlareElementTreeModel::rowCount(const QModelIndex& parent) const -{ - if (parent.column() > 0) - { - return 0; - } - return GetLensFlareElement(parent)->GetChildCount(); -} - -bool LensFlareElementTreeModel::removeRows(int row, int count, const QModelIndex& parent) -{ - if (!parent.isValid()) - { - return false; - } - - auto pParent = static_cast(parent.internalPointer()); - - beginRemoveRows(parent, row, row + count - 1); - - for (int i = 0; i < count; i++) - { - CLensFlareElement* pChild = pParent->GetChildAt(row); - - IOpticsElementBasePtr pOptics = pChild->GetOpticsElement(); - if (pOptics) - { - LensFlareUtil::RemoveOptics(pOptics); - } - - pParent->RemoveChild(row); - } - - endRemoveRows(); - - GetIEditor()->GetLensFlareManager()->Modified(); // XXX - - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } - - return true; -} - -QStringList LensFlareElementTreeModel::mimeTypes() const -{ - QStringList types; - types << QStringLiteral("application/x-o3de-flareelements"); - types << QStringLiteral("application/x-o3de-flaretypes"); - return types; -} - -QMimeData* LensFlareElementTreeModel::mimeData(const QModelIndexList& indexes) const -{ - QMimeData* data = new QMimeData(); - - QByteArray array; - - for (auto& index : indexes) - { - auto pElement = static_cast(index.data(Qt::UserRole).value()); - array.append(reinterpret_cast(&pElement), sizeof(CLensFlareElement*)); - } - - data->setData(QStringLiteral("application/x-o3de-flareelements"), array); - - return data; -} - -void LensFlareElementTreeModel::RemoveAllElements() -{ - QModelIndex index = GetRootItem(); - if (!index.isValid()) - { - return; - } - - auto pElement = index.data(Qt::UserRole).value(); - - beginResetModel(); - - pElement->RemoveAllChildren(); - pElement->GetOpticsElement()->RemoveAll(); - - endResetModel(); - - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } -} - -bool LensFlareElementTreeModel::AddElement(const QModelIndex& parentIndex, int row, EFlareType flareType) -{ - if (!parentIndex.isValid()) - { - return false; - } - - auto pElement = GetLensFlareElement(parentIndex); - - int nIndex; - - if (LensFlareUtil::IsGroup(pElement->GetOpticsType())) - { - if (row != -1) - { - nIndex = row; - } - else - { - nIndex = pElement->GetChildCount(); - } - } - else - { - CLensFlareElement* pParentElement = GetLensFlareElement(parentIndex.parent()); - if (!pParentElement) - { - return false; - } - - if (!LensFlareUtil::IsGroup(pParentElement->GetOpticsType())) - { - return false; - } - - nIndex = LensFlareUtil::FindOpticsIndexUnderParentOptics(pElement->GetOpticsElement(), pParentElement->GetOpticsElement()); - if (nIndex == -1) - { - return false; - } - - pElement = pParentElement; - } - - CLensFlareElement::LensFlareElementPtr pNewElement = InsertAtomicElement(nIndex, flareType, pElement); - if (!pNewElement) - { - return false; - } - - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } - - return true; -} - -CLensFlareElement::LensFlareElementPtr LensFlareElementTreeModel::InsertAtomicElement(int nIndex, EFlareType flareType, CLensFlareElement* pParentElement) -{ - IOpticsElementBasePtr pParent = pParentElement->GetOpticsElement(); - if (pParent == NULL) - { - return NULL; - } - - IOpticsElementBasePtr pNewOptics = gEnv->pOpticsManager->Create(flareType); - if (pNewOptics == NULL) - { - return NULL; - } - - if (nIndex < 0) - { - return NULL; - } - - CLensFlareElement::LensFlareElementPtr pElement = AddElement(pNewOptics, pParentElement); - if (pElement == NULL) - { - return NULL; - } - - pParent->InsertElement(nIndex, pNewOptics); - - emit beginInsertRows(createIndex(pParentElement->GetRow(), 0, pParentElement), nIndex, nIndex); - pParentElement->InsertChild(nIndex, pElement); - emit endInsertRows(); - - return pElement; -} - -void LensFlareElementTreeModel::MakeValidElementName(const QString& seedName, QString& outValidName) const -{ - if (!IsExistElement(seedName)) - { - outValidName = seedName; - return; - } - - int counter = 0; - do - { - QString numberString; - numberString = QString::number(counter); - QString candidateName = seedName + numberString; - if (!IsExistElement(candidateName)) - { - outValidName = candidateName; - return; - } - } while (++counter < 100000); // prevent from infinite loop -} - -bool LensFlareElementTreeModel::IsExistElement(const QString& name) const -{ - const auto predicate = [&](CLensFlareElement* pElement) - { - QString flareName; - return pElement->GetName(flareName) && !QString::compare(flareName, name, Qt::CaseInsensitive); - }; - auto pElement = ::FindLensFlareElement(m_pRootElement.get(), predicate); - return pElement != nullptr; -} - -CLensFlareElement::LensFlareElementPtr LensFlareElementTreeModel::AddElement(IOpticsElementBasePtr pOptics, CLensFlareElement* pParentElement) -{ - if (pOptics == NULL) - { - return NULL; - } - - IOpticsElementBasePtr pParent = pParentElement->GetOpticsElement(); - - CLensFlareElement* pLensFlareElement = NULL; - - if (pParent == NULL) - { - if (pOptics->GetType() != eFT_Root) - { - assert(0 && "CFlareManager::AddItem() - pOptics must be a root optics if the parent doesn't exist."); - return NULL; - } - } - else - { - if (!LensFlareUtil::IsGroup(pParent->GetType())) - { - return NULL; - } - - QString fullElementName; - if (!pParentElement->GetName(fullElementName)) - { - return NULL; - } - if (!fullElementName.isEmpty()) - { - fullElementName += "."; - } - fullElementName += LensFlareUtil::GetShortName(pOptics->GetName().c_str()).toLower(); - - QString validName; - MakeValidElementName(fullElementName, validName); - pOptics->SetName(validName.toUtf8().data()); - } - - pLensFlareElement = CreateElement(pOptics); - - if (LensFlareUtil::IsGroup(pOptics->GetType())) - { - for (int i = 0, iElementCount(pOptics->GetElementCount()); i < iElementCount; ++i) - { - CLensFlareElement::LensFlareElementPtr pChild = AddElement(pOptics->GetElementAt(i), pLensFlareElement); - pLensFlareElement->AddChild(pChild); - } - } - - GetIEditor()->GetLensFlareManager()->Modified(); - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } - - return pLensFlareElement; -} - -bool LensFlareElementTreeModel::MoveElement(CLensFlareElement* pElement, int row, const QModelIndex& index) -{ - if (!index.isValid()) - { - return false; - } - - QModelIndex sourceParentIndex = parent(createIndex(0, 0, pElement)); - if (!sourceParentIndex.isValid()) - { - return false; - } - - QModelIndex targetParentIndex = index; - CLensFlareElement* pTargetParent = targetParentIndex.data(Qt::UserRole).value(); - - QString fullElementName; - if (!pTargetParent->GetName(fullElementName)) - { - return false; - } - if (!fullElementName.isEmpty()) - { - fullElementName += "."; - } - fullElementName += LensFlareUtil::GetShortName(pElement->GetOpticsElement()->GetName().c_str()).toLower(); - - QString validName; - MakeValidElementName(fullElementName, validName); - - int targetRow; - - if (!LensFlareUtil::IsGroup(pTargetParent->GetOpticsElement()->GetType())) - { - targetParentIndex = targetParentIndex.parent(); - pTargetParent = targetParentIndex.data(Qt::UserRole).value(); - targetRow = index.row(); - } - else - { - if (row != -1) - { - targetRow = row; - } - else - { - targetRow = pTargetParent->GetChildCount(); - } - } - - CLensFlareElement* pSourceParent = pElement->GetParent(); - int sourceRow = pElement->GetRow(); - - if (!beginMoveRows(sourceParentIndex, sourceRow, sourceRow, targetParentIndex, targetRow)) - { - return false; - } - - StoreUndo(); - - // insert before removing to increase reference count - - pTargetParent->InsertChild(targetRow, pElement); - pTargetParent->GetOpticsElement()->InsertElement(targetRow, pElement->GetOpticsElement()); - - if (pTargetParent == pSourceParent && targetRow < sourceRow) - { - ++sourceRow; - } - - pSourceParent->RemoveChild(sourceRow); - pSourceParent->GetOpticsElement()->Remove(sourceRow); - - pElement->GetOpticsElement()->SetName(validName.toUtf8().data()); - LensFlareUtil::UpdateOpticsName(pElement->GetOpticsElement()); - - endMoveRows(); - - return true; -} - -bool LensFlareElementTreeModel::dropMimeData(const QMimeData* data, [[maybe_unused]] Qt::DropAction action, int row, [[maybe_unused]] int column, const QModelIndex& parent) -{ - if (data->hasFormat(QStringLiteral("application/x-o3de-flaretypes"))) - { - // drop from atomic list - - QByteArray encoded = data->data(QStringLiteral("application/x-o3de-flaretypes")); - QDataStream stream(&encoded, QIODevice::ReadOnly); - - while (!stream.atEnd()) - { - int flareType; - stream >> flareType; - - CUndo undo(tr("Add Atomic Lens Flare Item").toUtf8()); - AddElement(parent, row, static_cast(flareType)); - } - - return true; - } - else if (data->hasFormat(QStringLiteral("application/x-o3de-flareelements"))) - { - QByteArray array = data->data("application/x-o3de-flareelements"); - - int count = array.size() / sizeof(CLensFlareElement*); - auto ppElements = reinterpret_cast(array.data()); - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - - for (int i = 0; i < count; i++) - { - MoveElement(ppElements[i], row, parent); - } - - return true; - } - else - { - return false; - } -} - -CLensFlareElement* LensFlareElementTreeModel::FindLensFlareElement(IOpticsElementBasePtr pOptics) const -{ - return ::FindLensFlareElement(m_pRootElement.get(), [&](CLensFlareElement* pElement) - { - return pElement->GetOpticsElement() == pOptics; - }); -} - -Qt::DropActions LensFlareElementTreeModel::supportedDragActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -Qt::DropActions LensFlareElementTreeModel::supportedDropActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -void LensFlareElementTreeModel::UpdateLensFlareItem(CLensFlareItem* pLensFlareItem) -{ - m_pLensFlareItem = pLensFlareItem; - - m_pRootElement.reset(new CLensFlareElement); - - if (pLensFlareItem != NULL) - { - auto pChild = UpdateLensFlareElementsRecusively(m_pLensFlareItem->GetOptics()); - if (pChild) - { - m_pRootElement->AddChild(pChild); - } - } -} - -CLensFlareElement* LensFlareElementTreeModel::UpdateLensFlareElementsRecusively(IOpticsElementBasePtr pOptics) -{ - auto pElement = new CLensFlareElement; - pElement->SetOpticsElement(pOptics); - - for (int i = 0, iCount(pOptics->GetElementCount()); i < iCount; i++) - { - auto pChild = UpdateLensFlareElementsRecusively(pOptics->GetElementAt(i)); - if (pElement) - { - pElement->AddChild(pChild); - } - } - - return pElement; -} - -CLensFlareElement* LensFlareElementTreeModel::CreateElement(IOpticsElementBasePtr pOptics) -{ - StoreUndo(); - CLensFlareElement* pElement = new CLensFlareElement; - pElement->SetOpticsElement(pOptics); - return pElement; -} - -void LensFlareElementTreeModel::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - beginResetModel(); - UpdateLensFlareItem(pLensFlareItem); - endResetModel(); -} - -void LensFlareElementTreeModel::OnLensFlareDeleteItem([[maybe_unused]] CLensFlareItem* pLensFlareItem) -{ -} - -CLensFlareElement* LensFlareElementTreeModel::GetLensFlareElement(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return m_pRootElement.get(); - } - else - { - return static_cast(index.internalPointer()); - } -} - -void LensFlareElementTreeModel::Paste(const QModelIndex& hItem, XmlNodeRef xmlNode) -{ - if (!hItem.isValid()) - { - return; - } - - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - - QString type; - xmlNode->getAttr("Type", type); - - bool bPasteAtSameLevel = false; - xmlNode->getAttr("PasteAtSameLevel", bPasteAtSameLevel); - - QModelIndex hParentItem; - - IOpticsElementBasePtr pSelectedOptics = GetOpticsElementByTreeItem(hItem); - if (pSelectedOptics == NULL) - { - return; - } - - if (!LensFlareUtil::IsGroup(pSelectedOptics->GetType())) - { - hParentItem = hItem.parent(); - } - else - { - if (bPasteAtSameLevel) - { - hParentItem = hItem.parent(); - } - else - { - hParentItem = hItem; - } - } - - IOpticsElementBasePtr pParentOptics = GetOpticsElementByTreeItem(hParentItem); - if (pParentOptics == NULL) - { - return; - } - - for (int i = 0, iChildCount(xmlNode->getChildCount()); i < iChildCount; ++i) - { - LensFlareUtil::SClipboardData clipboardData; - clipboardData.FillThisFromXmlNode(xmlNode->getChild(i)); - - if (clipboardData.m_LensFlareFullPath == m_pLensFlareItem->GetFullName() && clipboardData.m_From == LENSFLARE_ITEM_TREE) - { - QString msg; - msg = tr("[%1] lens item can be pasted into the same item").arg(clipboardData.m_LensFlareFullPath); - CryMessageBox(msg.toUtf8().data(), "Warning", MB_OK); - continue; - } - - IOpticsElementBasePtr pSourceOptics = pEditor->FindOptics(clipboardData.m_LensFlareFullPath, clipboardData.m_LensOpticsPath); - if (pSourceOptics == NULL) - { - continue; - } - - CLensFlareItem* pSourceLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(clipboardData.m_LensFlareFullPath); - if (pSourceLensFlareItem == NULL) - { - continue; - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (m_pLensFlareItem->GetFullName() == clipboardData.m_LensFlareFullPath && LensFlareUtil::FindOptics(pSourceOptics, pSelectedOptics->GetName().c_str())) - { - QMessageBox::warning(0, tr("Warning"), tr("You can't paste this item here.")); - return; - } - } - - // if the copied optics type is root, the type should be converted to group type. - bool bForceConvertType = false; - if (pSourceOptics->GetType() == eFT_Root) - { - bForceConvertType = true; - } - - IOpticsElementBasePtr pNewOptics = LensFlareUtil::CreateOptics(pSourceOptics, bForceConvertType); - if (pNewOptics == NULL) - { - return; - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (pSourceLensFlareItem == m_pLensFlareItem) - { - QModelIndex hSourceItem = GetTreeItemByOpticsElement(pSourceOptics); - if (hSourceItem.isValid()) - { - removeRow(hSourceItem.row(), hSourceItem.parent()); - } - } - else if (clipboardData.m_From == LENSFLARE_ITEM_TREE) - { - CLensFlareLibrary* pLibrary = pEditor->GetCurrentLibrary(); - if (pLibrary) - { - QString lensFlareFullName = m_pLensFlareItem ? m_pLensFlareItem->GetFullName() : ""; - pLibrary->RemoveItem(pSourceLensFlareItem); - pEditor->ReloadItems(); - pSourceLensFlareItem->UpdateLights(); - pEditor->UpdateLensOpticsNames(pSourceLensFlareItem->GetFullName(), ""); - if (!lensFlareFullName.isEmpty()) - { - pEditor->SelectItemByName(lensFlareFullName); - } - } - - LensFlareUtil::RemoveOptics(pSourceOptics); - } - } - - CLensFlareElement* pParentElement = FindLensFlareElement(pParentOptics); - - // The children optics items were already added in a creation phase so we don't need to update the optics object. - CLensFlareElement::LensFlareElementPtr pNewElement = AddElement(pNewOptics, pParentElement); - assert(pNewElement); - if (!pNewElement) - { - return; - } - - int nInsertedPos; - if (hParentItem == hItem) - { - nInsertedPos = 0; - } - else - { - nInsertedPos = LensFlareUtil::FindOpticsIndexUnderParentOptics(pSelectedOptics, pParentOptics); - if (nInsertedPos > pParentOptics->GetElementCount() || nInsertedPos == -1) - { - nInsertedPos = pParentOptics->GetElementCount(); - } - } - - pParentOptics->InsertElement(nInsertedPos, pNewOptics); - LensFlareUtil::UpdateOpticsName(pNewOptics); - - emit beginInsertRows(createIndex(pParentElement->GetRow(), 0, pParentElement), nInsertedPos, nInsertedPos); - pParentElement->InsertChild(nInsertedPos, pNewElement); - emit endInsertRows(); - - // pSelectedLensFlareItem->UpdateLights(); - } -} - -IOpticsElementBasePtr LensFlareElementTreeModel::GetOpticsElementByTreeItem(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return nullptr; - } - return GetLensFlareElement(index)->GetOpticsElement(); -} - -QModelIndex LensFlareElementTreeModel::GetTreeItemByName(const QString& name) const -{ - auto pElement = ::FindLensFlareElement(m_pRootElement.get(), [&](CLensFlareElement* pElement) - { - QString flareName; - return pElement->GetName(flareName) && flareName == name; - }); - - if (!pElement) - { - return {}; - } - - return createIndex(pElement->GetRow(), 0, pElement); -} - -QModelIndex LensFlareElementTreeModel::GetTreeItemByOpticsElement(const IOpticsElementBasePtr pOptics) const -{ - auto pElement = FindLensFlareElement(pOptics); - if (!pElement) - { - return {}; - } - return createIndex(pElement->GetRow(), 0, pElement); -} - -void LensFlareElementTreeModel::InvalidateLensFlareItem() -{ - OnLensFlareChangeItem(nullptr); -} - -void LensFlareElementTreeModel::StoreUndo(const QString& undoDescription) -{ - if (CUndo::IsRecording()) - { - if (undoDescription.isEmpty()) - { - CUndo::Record(new CUndoLensFlareItem(GetLensFlareItem())); - } - else - { - CUndo::Record(new CUndoLensFlareItem(GetLensFlareItem(), undoDescription)); - } - } -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.h deleted file mode 100644 index d2b0051032..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.h +++ /dev/null @@ -1,197 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENTTREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENTTREE_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "LensFlareElement.h" -#include "LensFlareUtil.h" -#include "ILensFlareListener.h" - -#include -#include -#endif - -class CLensFlareItem; -class LensFlareElementTreeModel; -class QMouseEvent; - -class CLensFlareElementTree - : public QTreeView -{ - Q_OBJECT - -public: - - CLensFlareElementTree(QWidget* pParent = nullptr); - - void RegisterListener(ILensFlareChangeElementListener* pListener) - { - if (pListener) - { - m_LensFlaresElementListeners.push_back(pListener); - } - } - - void UnregisterListener(ILensFlareChangeElementListener* pListener) - { - if (pListener == NULL) - { - return; - } - std::vector::iterator ii = m_LensFlaresElementListeners.begin(); - for (; ii != m_LensFlaresElementListeners.end(); ) - { - if (*ii == pListener) - { - ii = m_LensFlaresElementListeners.erase(ii); - } - else - { - ++ii; - } - } - } - - CLensFlareElement::LensFlareElementPtr FindLensFlareElement(IOpticsElementBasePtr pElement) const; - - void OnInternalVariableChange(IVariable* pVar); - - CLensFlareElement* GetCurrentLensFlareElement() const; - void UpdateProperty(); - void UpdateClipboard(const char* type, bool bPasteAtSameLevel); - - void SelectTreeItemByName(const QString& name); - - CLensFlareItem* GetLensFlareItem() const; - void InvalidateLensFlareItem(); - -protected: - void CallChangeListeners(); - - void OnDataChanged(const QModelIndex& index); - void OnRowsInserted(const QModelIndex& index, int first, int last); - void OnRowsRemoved(const QModelIndex& index, int first, int last); - - void OnNotifyTreeRClick(); - void OnTvnSelchangedTree(const QItemSelection& selected, const QItemSelection& deselected); - - XmlNodeRef CreateXML(const char* type) const; - bool GetClipboardList(const char* type, std::vector& outList) const; - - //! Only the basic operations like following methods must have routine for undoing. - void ElementChanged(CLensFlareElement* pPrevLensFlareElement); - ///////////////////////////////////////////////////////////////////////////////////////// - - void OnAddGroup(); - void OnCopy(); - void OnCut(); - void OnPaste(); - void OnClone(); - void OnRenameItem(); - void OnRemoveItem(); - void OnRemoveAll(); - void OnItemUp(); - void OnItemDown(); - void mousePressEvent(QMouseEvent* event); - void keyPressEvent(QKeyEvent* event); - - void Cut(bool bPasteAtSameLevel); - -private: - void SelectItem(const QModelIndex& index); - - std::vector m_LensFlaresElementListeners; - - QScopedPointer m_model; -}; - -class LensFlareElementTreeModel - : public QAbstractItemModel - , public ILensFlareChangeItemListener -{ - Q_OBJECT - -public: - LensFlareElementTreeModel(QObject* pParent = nullptr); - ~LensFlareElementTreeModel(); - - int rowCount(const QModelIndex& parent = {}) const override; - int columnCount(const QModelIndex& parent = {}) const override; - - Qt::ItemFlags flags(const QModelIndex& index) const override; - QVariant data(const QModelIndex& index, int role) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - - QModelIndex index(int row, int column, const QModelIndex& parent = {}) const override; - QModelIndex parent(const QModelIndex& index) const override; - - bool removeRows(int row, int count, const QModelIndex& parent = {}) override; - - QStringList mimeTypes() const override; - QMimeData* mimeData(const QModelIndexList& indexes) const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - Qt::DropActions supportedDragActions() const override; - Qt::DropActions supportedDropActions() const override; - - CLensFlareElement* GetLensFlareElement(const QModelIndex& index) const; - - QModelIndex GetTreeItemByName(const QString& name) const; - - void Paste(const QModelIndex& index, XmlNodeRef xmlNode); - void Cut(const QModelIndex& index, bool bPasteAtSameLevel); - - CLensFlareItem* GetLensFlareItem() const - { - return m_pLensFlareItem; - } - - void InvalidateLensFlareItem(); - - void RemoveAllElements(); - bool AddElement(const QModelIndex& index, int row, EFlareType flareType); - - bool MoveElement(CLensFlareElement* pElement, int row, const QModelIndex& parentIndex); - -private: - QModelIndex GetRootItem() const; - IOpticsElementBasePtr GetOpticsElementByTreeItem(const QModelIndex& index) const; - - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - - void UpdateLensFlareItem(CLensFlareItem* pLensFlareItem); - CLensFlareElement* UpdateLensFlareElementsRecusively(IOpticsElementBasePtr pOptics); - CLensFlareElement* CreateElement(IOpticsElementBasePtr pOptics); - void Reload(); - - void MakeValidElementName(const QString& seedName, QString& outValidName) const; - bool IsExistElement(const QString& name) const; - CLensFlareElement::LensFlareElementPtr InsertAtomicElement(int nIndex, EFlareType flareType, CLensFlareElement* pParentElement); - CLensFlareElement::LensFlareElementPtr AddElement(IOpticsElementBasePtr pOptics, CLensFlareElement* pParentElement); - CLensFlareElement* FindLensFlareElement(IOpticsElementBasePtr pOptics) const; - - QModelIndex GetTreeItemByOpticsElement(const IOpticsElementBasePtr pOptics) const; - void EnableElement(CLensFlareElement* pLensFlareElement, bool bEnable); - void RenameElement(CLensFlareElement* pLensFlareElement, const QString& newName); - void StoreUndo(const QString& undoDescription = ""); - - CLensFlareElement::LensFlareElementPtr m_pRootElement; - CLensFlareItem* m_pLensFlareItem; -}; - -Q_DECLARE_METATYPE(CLensFlareElement*) - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENTTREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.cpp deleted file mode 100644 index e20f1ac7cb..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareItem.h" - -// Editor -#include "LensFlareUtil.h" -#include "LensFlareEditor.h" -#include "LensFlareUndo.h" -#include "Objects/EntityObject.h" - - -CLensFlareItem::CLensFlareItem() -{ - m_pOptics = NULL; - CreateOptics(); -} - -CLensFlareItem::~CLensFlareItem() -{ -} - -void CLensFlareItem::Serialize(SerializeContext& ctx) -{ - if (ctx.bLoading) - { - CreateOptics(); - LensFlareUtil::FillOpticsFromXML(m_pOptics, ctx.node); - - for (int i = 0, iChildCount(ctx.node->getChildCount()); i < iChildCount; ++i) - { - AddChildOptics(m_pOptics, ctx.node->getChild(i)); - } - - CBaseLibraryItem::Serialize(ctx); - } - else - { - CBaseLibraryItem::Serialize(ctx); - } -} - -void CLensFlareItem::AddChildOptics(IOpticsElementBasePtr pParentOptics, const XmlNodeRef& pNode) -{ - if (pNode == NULL) - { - return; - } - - if (pNode->getTag() && strcmp(pNode->getTag(), "FlareItem")) - { - return; - } - - IOpticsElementBasePtr pOptics = LensFlareUtil::CreateOptics(pNode); - if (pOptics == NULL) - { - return; - } - - pParentOptics->AddElement(pOptics); - - for (int i = 0, iChildCount(pNode->getChildCount()); i < iChildCount; ++i) - { - AddChildOptics(pOptics, pNode->getChild(i)); - } -} - -void CLensFlareItem::CreateOptics() -{ - m_pOptics = gEnv->pOpticsManager->Create(eFT_Root); -} - -XmlNodeRef CLensFlareItem::CreateXmlData() const -{ - XmlNodeRef pRootNode = NULL; - if (LensFlareUtil::CreateXmlData(m_pOptics, pRootNode)) - { - pRootNode->setAttr("Name", m_pOptics->GetName().c_str()); - return pRootNode; - } - return NULL; -} - -void CLensFlareItem::SetName(const QString& name) -{ - QString newNameWithGroup; - QString newFullName; - LensFlareUtil::GetExpandedItemNames(this, LensFlareUtil::GetGroupNameFromName(name), LensFlareUtil::GetShortName(name), newNameWithGroup, newFullName); - - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoRenameLensFlareItem(GetFullName(), newFullName)); - } - - CBaseLibraryItem::SetName(name); - - if (m_pOptics) - { - m_pOptics->SetName(GetShortName().toUtf8().data()); - } -} - -void CLensFlareItem::UpdateLights(IOpticsElementBasePtr pSrcOptics) -{ - QString srcFullOpticsName = GetFullName(); - bool bUpdateChildren = false; - if (pSrcOptics == NULL) - { - if (m_pOptics == NULL) - { - return; - } - pSrcOptics = m_pOptics; - bUpdateChildren = true; - } - - std::vector lightEntities; - LensFlareUtil::GetLightEntityObjects(lightEntities); - - for (int i = 0, iLightSize(lightEntities.size()); i < iLightSize; ++i) - { - CEntityObject* pLightEntity = lightEntities[i]; - if (pLightEntity == NULL) - { - continue; - } - - IOpticsElementBasePtr pTargetOptics = pLightEntity->GetOpticsElement(); - if (pTargetOptics == NULL) - { - continue; - } - - QString targetFullOpticsName(pTargetOptics->GetName().c_str()); - if (srcFullOpticsName != targetFullOpticsName) - { - continue; - } - - QString srcOpticsName(pSrcOptics->GetName().c_str()); - IOpticsElementBasePtr pFoundOptics = NULL; - if (LensFlareUtil::GetShortName(targetFullOpticsName) == srcOpticsName) - { - pFoundOptics = pTargetOptics; - } - else - { - pFoundOptics = LensFlareUtil::FindOptics(pTargetOptics, srcOpticsName); - } - - if (pFoundOptics == NULL) - { - continue; - } - if (pFoundOptics->GetType() != pSrcOptics->GetType()) - { - continue; - } - - LensFlareUtil::CopyOptics(pSrcOptics, pFoundOptics, bUpdateChildren); - } -} - -void CLensFlareItem::ReplaceOptics(IOpticsElementBasePtr pNewData) -{ - if (pNewData == NULL) - { - return; - } - if (pNewData->GetType() != eFT_Root) - { - return; - } - CreateOptics(); - LensFlareUtil::CopyOptics(pNewData, m_pOptics); - m_pOptics->SetName(GetFullName().toUtf8().data()); - UpdateLights(); - - CLensFlareEditor* pLensFlareEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pLensFlareEditor == NULL) - { - return; - } - if (this != pLensFlareEditor->GetSelectedLensFlareItem()) - { - return; - } - pLensFlareEditor->UpdateLensFlareItem(this); - pLensFlareEditor->RemovePropertyItems(); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.h deleted file mode 100644 index 6d1eedb5f9..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEM_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEM_H -#pragma once - -class IOpticsElementBase; -class CEntityObject; - -#include "BaseLibraryItem.h" -#include "Include/IDataBaseItem.h" - -class CLensFlareItem - : public CBaseLibraryItem -{ -public: - - CLensFlareItem(); - ~CLensFlareItem(); - - EDataBaseItemType GetType() const - { - return EDB_TYPE_FLARE; - } - - void SetName(const QString& name); - void Serialize(SerializeContext& ctx); - - void CreateOptics(); - - IOpticsElementBasePtr GetOptics() const - { - return m_pOptics; - } - - void ReplaceOptics(IOpticsElementBasePtr pNewData); - - XmlNodeRef CreateXmlData() const; - void UpdateLights(IOpticsElementBasePtr pSrcOptics = NULL); - -private: - - void GetLightEntityObjects(std::vector& outEntityLights) const; - static void AddChildOptics(IOpticsElementBasePtr pParentOptics, const XmlNodeRef& pNode); - - IOpticsElementBasePtr m_pOptics; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEM_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.cpp deleted file mode 100644 index 34cb442a38..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareItemTree.h" - -// Editor -#include "LensFlareItem.h" -#include "ViewManager.h" -#include "Objects/EntityObject.h" - - -CLensFlareItemTree::CLensFlareItemTree(QWidget* pParent) - : QTreeView(pParent) -{ - setHeaderHidden(true); - setSelectionMode(QAbstractItemView::SingleSelection); - setContextMenuPolicy(Qt::CustomContextMenu); - setDragEnabled(true); - setAcceptDrops(true); - setDropIndicatorShown(true); - setDragDropMode(DragDrop); -} - -CLensFlareItemTree::~CLensFlareItemTree() -{ -} - -void CLensFlareItemTree::startDrag(Qt::DropActions supportedDropActions) -{ - QTreeView::startDrag(supportedDropActions); -} - -void CLensFlareItemTree::mousePressEvent(QMouseEvent* event) -{ - if (event->button() == Qt::LeftButton) - { - CUndo undo(tr("Changed lens flare item").toUtf8()); - QTreeView::mousePressEvent(event); - } - else - { - QTreeView::mousePressEvent(event); - } -} - -void CLensFlareItemTree::AssignLensFlareToLightEntity(CViewport* pViewport) const -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - CLensFlareItem* pLensFlareItem = static_cast(selected.first().data(Qt::UserRole).value()); - - QPoint viewportPos = QCursor::pos(); - pViewport->ScreenToClient(viewportPos); - HitContext hit; - if (!pViewport->HitTest(viewportPos, hit)) - { - return; - } - - if (hit.object && qobject_cast(hit.object)) - { - CEntityObject* pEntity = (CEntityObject*)hit.object; - if (pEntity->IsLight()) - { - CUndo undo(tr("Assign a lens flare item to a light entity").toUtf8()); - pEntity->ApplyOptics(pLensFlareItem->GetFullName(), pLensFlareItem->GetOptics()); - } - } -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.h deleted file mode 100644 index 1139604163..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEMTREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEMTREE_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "LensFlareElement.h" -#include "ILensFlareListener.h" - -#include -#endif - -class QMouseEvent; -class CLensFlareItem; - -class CLensFlareItemTree - : public QTreeView -{ - Q_OBJECT - -public: - CLensFlareItemTree(QWidget* pParent = nullptr); - ~CLensFlareItemTree(); - -protected: - void startDrag(Qt::DropActions supportedDropActions) override; - void mousePressEvent(QMouseEvent* event) override; - -private: - - void AssignLensFlareToLightEntity(CViewport* pViewport) const; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEMTREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.cpp deleted file mode 100644 index b575b4595c..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareLibrary.h" - -// Editor -#include "LensFlareItem.h" - - -bool CLensFlareLibrary::Save() -{ - return SaveLibrary("LensFlareLibrary"); -} - -bool CLensFlareLibrary::Load(const QString& filename) -{ - if (filename.isEmpty()) - { - return false; - } - SetFilename(filename); - XmlNodeRef root = XmlHelpers::LoadXmlFromFile(filename.toUtf8().data()); - if (!root) - { - return false; - } - Serialize(root, true); - return true; -} - -void CLensFlareLibrary::Serialize(XmlNodeRef& root, bool bLoading) -{ - if (bLoading) - { - RemoveAllItems(); - QString name = GetName(); - root->getAttr("Name", name); - SetName(name); - for (int i = 0; i < root->getChildCount(); i++) - { - XmlNodeRef itemNode = root->getChild(i); - CLensFlareItem* pLensFlareItem = new CLensFlareItem; - AddItem(pLensFlareItem); - CBaseLibraryItem::SerializeContext ctx(itemNode, bLoading); - pLensFlareItem->Serialize(ctx); - } - SetModified(false); - m_bNewLibrary = false; - } - else - { - root->setAttr("Name", GetName().toUtf8().data()); - - for (int i = 0; i < GetItemCount(); i++) - { - CLensFlareItem* pItem = (CLensFlareItem*)GetItem(i); - if(pItem) - { - CBaseLibraryItem::SerializeContext ctx(pItem->CreateXmlData(), bLoading); - root->addChild(ctx.node); - pItem->Serialize(ctx); - } - } - } -} - -IOpticsElementBasePtr CLensFlareLibrary::GetOpticsOfItem(const char* szflareName) -{ - IOpticsElementBasePtr pOptics = NULL; - for (int i = 0; i < GetItemCount(); i++) - { - CLensFlareItem* pItem = (CLensFlareItem*)GetItem(i); - - if (pItem->GetFullName() == szflareName) - { - pOptics = pItem->GetOptics(); - break; - } - } - - return pOptics; -} - - -void CLensFlareLibrary::OnInternalVariableChange([[maybe_unused]] IVariable* pVar) -{ - SetModified(true); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.h deleted file mode 100644 index 484ad3740a..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIBRARY_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIBRARY_H -#pragma once -#include "BaseLibrary.h" - -struct IVariable; - -class CRYEDIT_API CLensFlareLibrary - : public CBaseLibrary -{ -public: - CLensFlareLibrary(IBaseLibraryManager* pManager) - : CBaseLibrary(pManager) {}; - virtual bool Save(); - virtual bool Load(const QString& filename); - virtual void Serialize(XmlNodeRef& node, bool bLoading); - - IOpticsElementBasePtr GetOpticsOfItem(const char* szflareName); - - void OnInternalVariableChange(IVariable* pVar); -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIBRARY_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.cpp deleted file mode 100644 index 307364ea4f..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareLightEntityTree.h" - -// Editor -#include "Viewport.h" -#include "Include/IObjectManager.h" -#include "Objects/SelectionGroup.h" -#include "LensFlareItem.h" -#include "LensFlareEditor.h" - - -CLensFlareLightEntityTree::CLensFlareLightEntityTree(QWidget* pParent) - : QTreeView(pParent) - , m_model(new LensFlareLightEntityModel) -{ - setHeaderHidden(true); - - setModel(m_model.data()); - - connect(this, &QTreeView::doubleClicked, this, &CLensFlareLightEntityTree::OnTvnItemDoubleClicked); -} - -CLensFlareLightEntityTree::~CLensFlareLightEntityTree() -{ -} - -void CLensFlareLightEntityTree::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - m_model->OnLensFlareChangeItem(pLensFlareItem); -} - -void CLensFlareLightEntityTree::OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem) -{ - m_model->OnLensFlareDeleteItem(pLensFlareItem); -} - -void CLensFlareLightEntityTree::OnTvnItemDoubleClicked(const QModelIndex& index) -{ - CEntityObject* pObject = index.data(Qt::UserRole).value(); - - if (!qobject_cast(pObject)) - { - return; - } - - CSelectionGroup* pSelection = GetIEditor()->GetObjectManager()->GetSelection(); - if (pSelection) - { - int iSelectionCount(pSelection->GetCount()); - if (iSelectionCount == 1) - { - if (pSelection->GetObject(0) == pObject) - { - CViewport* vp = GetIEditor()->GetActiveView(); - if (vp) - { - vp->CenterOnSelection(); - } - return; - } - } - } - - GetIEditor()->GetObjectManager()->ClearSelection(); - GetIEditor()->GetObjectManager()->SelectObject(pObject); -} - -LensFlareLightEntityModel::LensFlareLightEntityModel(QObject* pParent) - : QAbstractListModel(pParent) -{ - CLensFlareEditor::GetLensFlareEditor()->RegisterLensFlareItemChangeListener(this); - GetIEditor()->GetObjectManager()->AddObjectEventListener(this); -} - -LensFlareLightEntityModel::~LensFlareLightEntityModel() -{ - CLensFlareEditor::GetLensFlareEditor()->UnregisterLensFlareItemChangeListener(this); - GetIEditor()->GetObjectManager()->RemoveObjectEventListener(this); -} - -void LensFlareLightEntityModel::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - beginResetModel(); - - m_pLensFlareItem = pLensFlareItem; - m_lightEntities.clear(); - - if (m_pLensFlareItem) - { - std::vector lightEntities; - LensFlareUtil::GetLightEntityObjects(lightEntities); - - for (int i = 0, iEntitySize(lightEntities.size()); i < iEntitySize; ++i) - { - AddLightEntity(lightEntities[i]); - } - } - - endResetModel(); -} - -void LensFlareLightEntityModel::OnLensFlareDeleteItem([[maybe_unused]] CLensFlareItem* pLensFlareItem) -{ - beginResetModel(); - - m_lightEntities.clear(); - m_pLensFlareItem = NULL; - - endResetModel(); -} - -void LensFlareLightEntityModel::OnObjectEvent(CBaseObject* pObject, int nEvent) -{ - if (!qobject_cast(pObject)) - { - return; - } - - switch (nEvent) - { - case CBaseObject::ON_RENAME: - case CBaseObject::ON_DELETE: - { - auto it = std::find(std::begin(m_lightEntities), std::end(m_lightEntities), pObject); - if (it == std::end(m_lightEntities)) - { - return; - } - int row = std::distance(std::begin(m_lightEntities), it); - if (nEvent == CBaseObject::ON_RENAME) - { - emit dataChanged(index(row, 0), index(row, 0)); - } - else - { - beginRemoveRows({}, row, row); - m_lightEntities.erase(it); - endRemoveRows(); - } - } - break; - - case CBaseObject::ON_ADD: - if (AddLightEntity((CEntityObject*)pObject)) - { - int row = m_lightEntities.size() - 1; - beginInsertRows({}, row, row); - endInsertRows(); - } - break; - } -} - -bool LensFlareLightEntityModel::AddLightEntity(CEntityObject* pEntity) -{ - if (pEntity == NULL || m_pLensFlareItem == NULL) - { - return false; - } - - QString lensFlareName = pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName); - if (lensFlareName.isEmpty()) - { - return false; - } - - QString fullName = m_pLensFlareItem->GetFullName(); - if (fullName.isEmpty()) - { - return false; - } - - if (QString::compare(lensFlareName, fullName, Qt::CaseInsensitive)) - { - return false; - } - - m_lightEntities.push_back(pEntity); - - return true; -} - -int LensFlareLightEntityModel::rowCount(const QModelIndex&) const -{ - return m_lightEntities.size(); -} - -QVariant LensFlareLightEntityModel::data(const QModelIndex& index, int role) const -{ - const int row = index.row(); - - if (row < 0 || row >= m_lightEntities.size()) - { - return {}; - } - - auto pEntity = m_lightEntities[row]; - - switch (role) - { - case Qt::DisplayRole: - return pEntity->GetName(); - - case Qt::UserRole: - return QVariant::fromValue(pEntity); - } - - return {}; -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.h deleted file mode 100644 index 21a271c08f..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIGHTENTITYTREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIGHTENTITYTREE_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "ILensFlareListener.h" - -#include -#include -#include "IObjectManager.h" // for IObjectManager::EventListener -#include "Objects/EntityObject.h" -#endif - -class LensFlareLightEntityModel; - -class CLensFlareLightEntityTree - : public QTreeView -{ - Q_OBJECT - -public: - CLensFlareLightEntityTree(QWidget* pParent = nullptr); - ~CLensFlareLightEntityTree(); - - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - -protected: - void OnTvnItemDoubleClicked(const QModelIndex& index); - - QScopedPointer m_model; -}; - -class LensFlareLightEntityModel - : public QAbstractListModel - , public ILensFlareChangeItemListener - , public IObjectManager::EventListener -{ - Q_OBJECT - -public: - LensFlareLightEntityModel(QObject* pParent = nullptr); - ~LensFlareLightEntityModel(); - - int rowCount(const QModelIndex& parent = {}) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - -protected: - void OnObjectEvent(CBaseObject* pObject, int nEvent) override; - - bool AddLightEntity(CEntityObject* pEntity); - - std::vector m_lightEntities; - _smart_ptr m_pLensFlareItem; -}; - -Q_DECLARE_METATYPE(CEntityObject*) - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIGHTENTITYTREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.cpp deleted file mode 100644 index c28832898f..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareManager.h" - -// AzCore -#include -#include - -// Editor -#include "LensFlareEditor.h" -#include "LensFlareItem.h" -#include "LensFlareLibrary.h" -#include "LensFlareUtil.h" - - -////////////////////////////////////////////////////////////////////////// -// CLensFlareManager implementation. -////////////////////////////////////////////////////////////////////////// -CLensFlareManager::CLensFlareManager() - : CBaseLibraryManager() -{ - m_bUniqNameMap = true; - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); - AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect(); -} - -////////////////////////////////////////////////////////////////////////// -CLensFlareManager::~CLensFlareManager() -{ - AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); -} - -////////////////////////////////////////////////////////////////////////// -void CLensFlareManager::ClearAll() -{ - CBaseLibraryManager::ClearAll(); - - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); -} - -////////////////////////////////////////////////////////////////////////// -CBaseLibraryItem* CLensFlareManager::MakeNewItem() -{ - return new CLensFlareItem; -} - -////////////////////////////////////////////////////////////////////////// -CBaseLibrary* CLensFlareManager::MakeNewLibrary() -{ - return new CLensFlareLibrary(this); -} - -////////////////////////////////////////////////////////////////////////// -QString CLensFlareManager::GetRootNodeName() -{ - return "FlareLibs"; -} - -////////////////////////////////////////////////////////////////////////// -QString CLensFlareManager::GetLibsPath() -{ - if (m_libsPath.isEmpty()) - { - m_libsPath += FLARE_LIBS_PATH; - } - - return m_libsPath; -} - -////////////////////////////////////////////////////////////////////////// -bool CLensFlareManager::LoadFlareItemByName(const QString& fullItemName, IOpticsElementBasePtr pDestOptics) -{ - if (pDestOptics == NULL) - { - return false; - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)LoadItemByName(fullItemName); - if (pLensFlareItem == NULL) - { - return false; - } - - LensFlareUtil::CopyOptics(pLensFlareItem->GetOptics(), pDestOptics, true); - return true; -} - -////////////////////////////////////////////////////////////////////////// -void CLensFlareManager::Modified() -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - if (pEditor->GetCurrentLibrary()) - { - pEditor->GetCurrentLibrary()->SetModified(true); - } -} - -////////////////////////////////////////////////////////////////////////// -IDataBaseLibrary* CLensFlareManager::LoadLibrary(const QString& filename, [[maybe_unused]] bool bReload) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - - QString fileNameWithGameFolder(filename); - - fileNameWithGameFolder.replace('\\', '/'); - - int nGamePathLength = static_cast(Path::GetEditingGameDataFolder().size()); - QString gamePathName; - if (nGamePathLength < filename.length()) - { - gamePathName = filename.left(nGamePathLength); - } - if (gamePathName != Path::GetEditingGameDataFolder().c_str()) - { - fileNameWithGameFolder.insert(0, "/"); - fileNameWithGameFolder.insert(0, Path::GetEditingGameDataFolder().c_str()); - } - - int nLibraryIndex(-1); - bool bSameAsCurrentLibrary(false); - - for (int i = 0; i < m_libs.size(); i++) - { - if (QString::compare(fileNameWithGameFolder, m_libs[i]->GetFilename(), Qt::CaseInsensitive) == 0) - { - IDataBaseLibrary* pExistingLib = m_libs[i]; - for (int j = 0; j < pExistingLib->GetItemCount(); j++) - { - UnregisterItem((CBaseLibraryItem*)pExistingLib->GetItem(j)); - } - pExistingLib->RemoveAllItems(); - nLibraryIndex = i; - if (pEditor) - { - bSameAsCurrentLibrary = pEditor->GetCurrentLibrary() == pExistingLib; - } - break; - } - } - - TSmartPtr pLib = MakeNewLibrary(); - if (!pLib->Load(filename)) - { - Error(QObject::tr("Failed to Load Item Library: %1").arg(filename).toUtf8().data()); - return NULL; - } - - if (nLibraryIndex != -1) - { - m_libs[nLibraryIndex] = pLib; - if (bSameAsCurrentLibrary && pEditor) - { - pEditor->ResetElementTreeControl(); - pEditor->SelectLibrary(pLib, true); - } - } - else - { - m_libs.push_back(pLib); - } - - pLib->SetFilename(filename); - - return pLib; -} - - -bool CLensFlareManager::IsLensFlareLibraryXML(const char* fileSourceFilePath) -{ - if ((!fileSourceFilePath) || (!AZStd::wildcard_match("*.xml", fileSourceFilePath))) - { - return false; - } - - using namespace AZ::IO; - - bool isLensFlareLibrary = false; - - // we are forced to read the asset to discover its type since "xml" was the chosen extension. - SystemFile::SizeType fileSize = SystemFile::Length(fileSourceFilePath); - if (fileSize > 0) - { - AZStd::vector buffer(fileSize + 1); - buffer[fileSize] = 0; - if (!AZ::IO::SystemFile::Read(fileSourceFilePath, buffer.data(), fileSize)) - { - return false; - } - - AZ::rapidxml::xml_document* xmlDoc = azcreate(AZ::rapidxml::xml_document, (), AZ::SystemAllocator, "LensFlareLibrary Temp XML Reader"); - if (xmlDoc->parse(buffer.data())) - { - AZ::rapidxml::xml_node* xmlRootNode = xmlDoc->first_node(); - if (xmlRootNode) - { - if (azstricmp(xmlRootNode->name(), "LensFlareLibrary") == 0) - { - isLensFlareLibrary = true; - } - } - } - - azdestroy(xmlDoc, AZ::SystemAllocator, AZ::rapidxml::xml_document); - } - - return isLensFlareLibrary; -} - - -AzToolsFramework::AssetBrowser::SourceFileDetails CLensFlareManager::GetSourceFileDetails(const char* fullSourceFileName) -{ - if (IsLensFlareLibraryXML(fullSourceFileName)) - { - return AzToolsFramework::AssetBrowser::SourceFileDetails("Icons/AssetBrowser/LensFlare_16.png"); - } - return AzToolsFramework::AssetBrowser::SourceFileDetails(); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.h deleted file mode 100644 index 9cc7c6fad2..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREMANAGER_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREMANAGER_H -#pragma once - -#include "BaseLibraryManager.h" -#include - -class IOpticsElementBase; -class CLensFlareEditor; - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -class CRYEDIT_API CLensFlareManager - : public CBaseLibraryManager - , private AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - -{ -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - CLensFlareManager(); - virtual ~CLensFlareManager(); - - void ClearAll(); - - virtual bool LoadFlareItemByName(const QString& fullItemName, IOpticsElementBasePtr pDestOptics); - void Modified(); - //! Path to libraries in this manager. - QString GetLibsPath(); - IDataBaseLibrary* LoadLibrary(const QString& filename, bool bReload = false); - - static bool IsLensFlareLibraryXML(const char* fullFilePath); - -private: - CBaseLibraryItem* MakeNewItem(); - CBaseLibrary* MakeNewLibrary(); - - //! Root node where this library will be saved. - QString GetRootNodeName(); - QString m_libsPath; - - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - // AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - AzToolsFramework::AssetBrowser::SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override; - virtual AZ::s32 GetPriority() const override { return 1; } // get our priority in before others. - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -}; - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREMANAGER_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.h deleted file mode 100644 index 77ca781a30..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREREFERENCETREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREREFERENCETREE_H -#pragma once - -class CLensFlareReferenceTree - : public CXTTreeCtrl -{ -public: - - CLensFlareReferenceTree(); - ~CLensFlareReferenceTree(); - -private: - - DECLARE_MESSAGE_MAP() -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREREFERENCETREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.cpp deleted file mode 100644 index a6b35eba13..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareUndo.h" - -// Editor -#include "LensFlareEditor.h" -#include "LensFlareItem.h" -#include "LensFlareManager.h" -#include "LensFlareElementTree.h" - - -void RestoreLensFlareItem(CLensFlareItem* pLensFlareItem, IOpticsElementBasePtr pOptics, const QString& flarePathName) -{ - pLensFlareItem->ReplaceOptics(pOptics); - - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor) - { - if (pOptics->GetType() == eFT_Root) - { - pEditor->RenameLensFlareItem(pLensFlareItem, pLensFlareItem->GetGroupName(), LensFlareUtil::GetShortName(flarePathName)); - pEditor->UpdateLensFlareItem(pLensFlareItem); - } - } -} - -void ActivateLensFlareItem(CLensFlareItem* pLensFlareItem, bool bRestoreSelectInfo, const QString& selectedFlareItemName) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - if (pLensFlareItem == pEditor->GetLensFlareElementTree()->GetLensFlareItem()) - { - pEditor->UpdateLensFlareItem(pLensFlareItem); - if (bRestoreSelectInfo) - { - pEditor->SelectItemInLensFlareElementTreeByName(selectedFlareItemName); - } - } -} - -CUndoLensFlareItem::CUndoLensFlareItem(CLensFlareItem* pLensFlareItem, const QString& undoDescription) -{ - if (pLensFlareItem) - { - m_Undo.m_pOptics = LensFlareUtil::CreateOptics(pLensFlareItem->GetOptics()); - m_flarePathName = pLensFlareItem->GetFullName(); - m_Undo.m_bRestoreSelectInfo = false; - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor) - { - m_Undo.m_bRestoreSelectInfo = pEditor->GetSelectedLensFlareName(m_Undo.m_selectedFlareItemName); - } - m_undoDescription = undoDescription; - } -} - -CUndoLensFlareItem::~CUndoLensFlareItem() -{ -} - -void CUndoLensFlareItem::Undo(bool bUndo) -{ - if (bUndo) - { - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathName); - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor && pLensFlareItem) - { - m_Redo.m_bRestoreSelectInfo = false; - m_Redo.m_pOptics = LensFlareUtil::CreateOptics(pLensFlareItem->GetOptics()); - m_Redo.m_bRestoreSelectInfo = pEditor->GetSelectedLensFlareName(m_Redo.m_selectedFlareItemName); - } - } - Restore(m_Undo); -} - -void CUndoLensFlareItem::Redo() -{ - Restore(m_Redo); -} - -void CUndoLensFlareItem::Restore(const SData& data) -{ - if (data.m_pOptics == NULL) - { - return; - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathName); - if (pLensFlareItem == NULL) - { - return; - } - RestoreLensFlareItem(pLensFlareItem, data.m_pOptics, m_flarePathName); - ActivateLensFlareItem(pLensFlareItem, data.m_bRestoreSelectInfo, data.m_selectedFlareItemName); -} - -CUndoRenameLensFlareItem::CUndoRenameLensFlareItem(const QString& oldFullName, const QString& newFullName) -{ - m_undo.m_oldFullItemName = oldFullName; - m_undo.m_newFullItemName = newFullName; -} - -void CUndoRenameLensFlareItem::Undo(bool bUndo) -{ - if (bUndo) - { - m_redo.m_oldFullItemName = m_undo.m_newFullItemName; - m_redo.m_newFullItemName = m_undo.m_oldFullItemName; - } - - Rename(m_undo); -} - -void CUndoRenameLensFlareItem::Redo() -{ - Rename(m_redo); -} - -void CUndoRenameLensFlareItem::Rename(const SUndoDataStruct& data) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(data.m_newFullItemName); - if (pLensFlareItem == NULL) - { - return; - } - - int nDotPos = data.m_oldFullItemName.indexOf("."); - if (nDotPos == -1) - { - return; - } - - QString shortName(LensFlareUtil::GetShortName(data.m_oldFullItemName)); - QString groupName(LensFlareUtil::GetGroupNameFromFullName(data.m_oldFullItemName)); - pEditor->RenameLensFlareItem(pLensFlareItem, groupName, shortName); - if (pLensFlareItem->GetOptics()) - { - pLensFlareItem->GetOptics()->SetName(shortName.toUtf8().data()); - LensFlareUtil::UpdateOpticsName(pLensFlareItem->GetOptics()); - } - pEditor->UpdateLensFlareItem(pLensFlareItem); -} - -CUndoLensFlareElementSelection::CUndoLensFlareElementSelection(CLensFlareItem* pLensFlareItem, const QString& flareTreeItemFullName, const QString& undoDescription) -{ - if (pLensFlareItem) - { - m_flarePathNameForUndo = pLensFlareItem->GetFullName(); - m_flareTreeItemFullNameForUndo = flareTreeItemFullName; - m_undoDescription = undoDescription; - } -} - -void CUndoLensFlareElementSelection::Undo(bool bUndo) -{ - if (bUndo) - { - m_flarePathNameForRedo = m_flarePathNameForUndo; - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor) - { - pEditor->GetSelectedLensFlareName(m_flareTreeItemFullNameForRedo); - } - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathNameForUndo); - if (pLensFlareItem == NULL) - { - return; - } - ActivateLensFlareItem(pLensFlareItem, true, m_flareTreeItemFullNameForUndo); -} - -void CUndoLensFlareElementSelection::Redo() -{ - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathNameForRedo); - if (pLensFlareItem == NULL) - { - return; - } - ActivateLensFlareItem(pLensFlareItem, true, m_flareTreeItemFullNameForRedo); -} - -CUndoLensFlareItemSelectionChange::CUndoLensFlareItemSelectionChange(const QString& fullLensFlareItemName, const QString& undoDescription) -{ - m_FullLensFlareItemNameForUndo = fullLensFlareItemName; - m_undoDescription = undoDescription; -} - -void CUndoLensFlareItemSelectionChange::Undo(bool bUndo) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - - if (bUndo) - { - QString currentFullName; - pEditor->GetFullSelectedFlareItemName(currentFullName); - m_FullLensFlareItemNameForRedo = currentFullName; - } - - pEditor->SelectLensFlareItem(m_FullLensFlareItemNameForUndo); -} - -void CUndoLensFlareItemSelectionChange::Redo() -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - pEditor->SelectLensFlareItem(m_FullLensFlareItemNameForRedo); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.h deleted file mode 100644 index cf8f76c321..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.h +++ /dev/null @@ -1,143 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUNDO_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUNDO_H -#pragma once - -#include "Undo/IUndoObject.h" - -class CLensFlareItem; - -class CUndoLensFlareItem - : public IUndoObject -{ -public: - CUndoLensFlareItem(CLensFlareItem* pGroupItem, const QString& undoDescription = "Undo Lens Flare Tree"); - ~CUndoLensFlareItem(); - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - void Undo(bool bUndo); - void Redo(); - -private: - - QString m_undoDescription; - - struct SData - { - SData() - { - m_pOptics = NULL; - } - - QString m_selectedFlareItemName; - bool m_bRestoreSelectInfo; - IOpticsElementBasePtr m_pOptics; - }; - - QString m_flarePathName; - SData m_Undo; - SData m_Redo; - - void Restore(const SData& data); -}; - -class CUndoRenameLensFlareItem - : public IUndoObject -{ -public: - - CUndoRenameLensFlareItem(const QString& oldFullName, const QString& newFullName); - -protected: - - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - void Undo(bool bUndo); - void Redo(); - -private: - - QString m_undoDescription; - - struct SUndoDataStruct - { - QString m_oldFullItemName; - QString m_newFullItemName; - }; - - void Rename(const SUndoDataStruct& data); - - SUndoDataStruct m_undo; - SUndoDataStruct m_redo; -}; - -class CUndoLensFlareElementSelection - : public IUndoObject -{ -public: - CUndoLensFlareElementSelection(CLensFlareItem* pLensFlareItem, const QString& flareTreeItemFullName, const QString& undoDescription = "Undo Lens Flare Element Tree"); - ~CUndoLensFlareElementSelection(){} - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - void Undo(bool bUndo); - void Redo(); - -private: - - QString m_undoDescription; - - QString m_flarePathNameForUndo; - QString m_flareTreeItemFullNameForUndo; - - QString m_flarePathNameForRedo; - QString m_flareTreeItemFullNameForRedo; -}; - -class CUndoLensFlareItemSelectionChange - : public IUndoObject -{ -public: - CUndoLensFlareItemSelectionChange(const QString& fullLensFlareItemName, const QString& undoDescription = "Undo Lens Flare element selection"); - ~CUndoLensFlareItemSelectionChange(){} - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - - void Undo(bool bUndo); - void Redo(); - -private: - QString m_undoDescription; - QString m_FullLensFlareItemNameForUndo; - QString m_FullLensFlareItemNameForRedo; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUNDO_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.cpp deleted file mode 100644 index e8ff29f987..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.cpp +++ /dev/null @@ -1,1012 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareUtil.h" - -// Editor -#include "Clipboard.h" -#include "Objects/EntityObject.h" -#include "Objects/SelectionGroup.h" -#include "Include/IObjectManager.h" - - -namespace LensFlareUtil -{ - IOpticsElementBasePtr CreateOptics(const XmlNodeRef& xmlNode) - { - IOpticsElementBasePtr pOpticsElement = NULL; - - const char* typeName; - if (!xmlNode->getAttr("Type", &typeName)) - { - return NULL; - } - - bool bEnable(true); - xmlNode->getAttr("Enable", bEnable); - - EFlareType flareType; - if (!GetFlareType(typeName, flareType)) - { - return NULL; - } - - pOpticsElement = gEnv->pOpticsManager->Create(flareType); - if (pOpticsElement == NULL) - { - return NULL; - } - - pOpticsElement->SetEnabled(bEnable); - - if (!FillOpticsFromXML(pOpticsElement, xmlNode)) - { - return NULL; - } - - return pOpticsElement; - } - - IOpticsElementBasePtr CreateOptics(IOpticsElementBasePtr pOptics, bool bForceTypeToGroup) - { - if (pOptics == NULL) - { - return NULL; - } - IOpticsElementBasePtr pNewOptics = NULL; - if (bForceTypeToGroup) - { - if (pOptics->GetType() == eFT_Root) - { - pNewOptics = gEnv->pOpticsManager->Create(eFT_Group); - } - } - if (pNewOptics == NULL) - { - pNewOptics = gEnv->pOpticsManager->Create(pOptics->GetType()); - if (pNewOptics == NULL) - { - return NULL; - } - } - CopyOptics(pOptics, pNewOptics, true); - return pNewOptics; - } - - bool FillOpticsFromXML(IOpticsElementBasePtr pOpticsElement, const XmlNodeRef& xmlNode) - { - if (!pOpticsElement) - { - return false; - } - - const char* name; - if (!xmlNode->getAttr("Name", &name)) - { - return false; - } - - const char* typeName; - if (!xmlNode->getAttr("Type", &typeName)) - { - return false; - } - EFlareType flareType; - if (!GetFlareType(typeName, flareType)) - { - return false; - } - if (flareType != pOpticsElement->GetType()) - { - return false; - } - - pOpticsElement->SetName(name); - - bool bEnable(true); - xmlNode->getAttr("Enable", bEnable); - pOpticsElement->SetEnabled(bEnable); - - XmlNodeRef pParamNode = xmlNode->findChild("Params"); - if (pParamNode == NULL) - { - return false; - } - - LensFlareUtil::FillParams(pParamNode, pOpticsElement); - return true; - } - - bool CreateXmlData(IOpticsElementBasePtr pOptics, XmlNodeRef& pOutNode) - { - pOutNode = gEnv->pSystem->CreateXmlNode("FlareItem"); - - if (pOptics == NULL || pOutNode == NULL) - { - return false; - } - - QString typeName; - if (!GetFlareTypeName(typeName, pOptics)) - { - return false; - } - - pOutNode->setAttr("Name", pOptics->GetName().c_str()); - pOutNode->setAttr("Type", typeName.toUtf8().data()); - pOutNode->setAttr("Enable", pOptics->IsEnabled()); - - XmlNodeRef pParamNode = pOutNode->createNode("Params"); - - CVarBlockPtr pVar; - SetVariablesTemplateFromOptics(pOptics, pVar); - - pVar->Serialize(pParamNode, false); - pOutNode->addChild(pParamNode); - - for (int i = 0, iElementCount(pOptics->GetElementCount()); i < iElementCount; ++i) - { - XmlNodeRef pNode = NULL; - IOpticsElementBasePtr pChildOptics = pOptics->GetElementAt(i); - if (!CreateXmlData(pChildOptics, pNode)) - { - continue; - } - - pOutNode->addChild(pNode); - } - - return true; - } - - void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar, std::vector& funcs) - { - if (pOptics == NULL) - { - return; - } - - SetVariablesTemplateFromOptics(pOptics, pRootVar); - - for (int i = 0, iNumVariables(pRootVar->GetNumVariables()); i < iNumVariables; ++i) - { - IVariable* pVariable = pRootVar->GetVariable(i); - if (pVariable == NULL) - { - continue; - } - for (int k = 0, iNumVariables2(pVariable->GetNumVariables()); k < iNumVariables2; ++k) - { - IVariable* pChildVariable(pVariable->GetVariable(k)); - if (pChildVariable == NULL) - { - continue; - } - for (int ii = 0, iSize(funcs.size()); ii < iSize; ++ii) - { - pChildVariable->AddOnSetCallback(funcs[ii]); - } - } - } - } - - extern void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar) - { - if (pOptics == NULL) - { - return; - } - - AZStd::vector paramGroups = pOptics->GetEditorParamGroups(); - pRootVar = new CVarBlock; - - for (int i = 0; i < paramGroups.size(); ++i) - { - CSmartVariableArray variableArray; - FuncVariableGroup* pGroup = ¶mGroups[i]; - if (pGroup == NULL) - { - continue; - } - - QString displayGroupName(pGroup->GetHumanName()); - if (displayGroupName == "Common") - { - FlareInfoArray::Props flareInfo = FlareInfoArray::Get(); - int nTypeIndex = (int)pOptics->GetType(); - if (nTypeIndex >= 0 && nTypeIndex < flareInfo.size) - { - displayGroupName += " : "; - displayGroupName += flareInfo.p[nTypeIndex].name; - } - } - - AddVariable(pRootVar, variableArray, pGroup->GetName(), displayGroupName.toUtf8().data(), ""); - - for (int k = 0; k < pGroup->GetVariableCount(); ++k) - { - IFuncVariable* pFuncVar = pGroup->GetVariable(k); - bool bHardMinLimitation = false; - - const std::pair range(pFuncVar->GetMin(), pFuncVar->GetMax()); - - if (pFuncVar->paramType == e_FLOAT) - { - CSmartVariable floatVar; - AddVariable(variableArray, floatVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - floatVar->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - floatVar->Set(pFuncVar->GetFloat()); - floatVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_INT) - { - CSmartVariable intVar; - AddVariable(variableArray, intVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - - bHardMinLimitation = HaveParameterLowBoundary(pFuncVar->name.c_str()); - intVar->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - - intVar->Set(pFuncVar->GetInt()); - intVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_BOOL) - { - CSmartVariable boolVar; - AddVariable(variableArray, boolVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - boolVar->Set(pFuncVar->GetBool()); - boolVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_VEC2) - { - CSmartVariable vec2Var; - AddVariable(variableArray, vec2Var, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - vec2Var->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - vec2Var->Set(pFuncVar->GetVec2()); - vec2Var->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_VEC3) - { - CSmartVariable vec3Var; - AddVariable(variableArray, vec3Var, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - vec3Var->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - vec3Var->Set(pFuncVar->GetVec3()); - vec3Var->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_VEC4) - { - CSmartVariable vec4Var; - AddVariable(variableArray, vec4Var, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - vec4Var->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - vec4Var->Set(pFuncVar->GetVec4()); - vec4Var->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_COLOR) - { - CSmartVariable colorVar; - AddVariable(variableArray, colorVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str(), IVariable::DT_COLOR); - ColorF color(pFuncVar->GetColorF()); - Vec3 colorVec3(color.r, color.g, color.b); - colorVar->Set(colorVec3); - colorVar->SetUserData(MakeFuncKey(i, k)); - - CSmartVariable alphaVar; - QString alphaName(pFuncVar->name.c_str()); - alphaName += ".alpha"; - QString alphaHumanName(pFuncVar->humanName.c_str()); - alphaHumanName += " [alpha]"; - AddVariable(variableArray, alphaVar, alphaName.toUtf8().data(), alphaHumanName.toUtf8().data(), pFuncVar->description.c_str()); - alphaVar->SetLimits(0, 255, 0, bHardMinLimitation, false); - alphaVar->Set(color.a * 255.0f); - alphaVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_MATRIX33) - { - // Reserved part - // This part is for future because Matrix33 type is suppose to be provided in a renderer side - } - else if (pFuncVar->paramType == e_TEXTURE2D || pFuncVar->paramType == e_TEXTURE3D || pFuncVar->paramType == e_TEXTURE_CUBE) - { - CSmartVariable textureVar; - ITexture* pTexture = pFuncVar->GetTexture(); - if (pTexture) - { - QString textureName = pTexture->GetName(); - textureVar->Set(textureName); - } - AddVariable(variableArray, textureVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str(), IVariable::DT_TEXTURE); - textureVar->SetUserData(MakeFuncKey(i, k)); - } - } - } - } - - void AddOptics(IOpticsElementBasePtr pParentOptics, const XmlNodeRef& xmlNode) - { - if (xmlNode == NULL) - { - return; - } - - if (strcmp(xmlNode->getTag(), "FlareItem")) - { - return; - } - - IOpticsElementBasePtr pOptics = CreateOptics(xmlNode); - if (pOptics == NULL) - { - return; - } - pParentOptics->AddElement(pOptics); - - for (int i = 0, iChildCount(xmlNode->getChildCount()); i < iChildCount; ++i) - { - AddOptics(pOptics, xmlNode->getChild(i)); - } - } - - void CopyVariable(IFuncVariable* pSrcVar, IFuncVariable* pDestVar) - { - if (!pSrcVar || !pDestVar) - { - return; - } - - if (pSrcVar->paramType != pDestVar->paramType) - { - return; - } - - if (pSrcVar->paramType == e_FLOAT) - { - float value = pSrcVar->GetFloat(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_BOOL) - { - bool value = pSrcVar->GetBool(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_INT) - { - int value = pSrcVar->GetInt(); - if (HaveParameterLowBoundary(pSrcVar->name.c_str())) - { - BoundaryProcess(value); - } - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_VEC2) - { - Vec2 value = pSrcVar->GetVec2(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_VEC3) - { - Vec3 value = pSrcVar->GetVec3(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_VEC4) - { - Vec4 value = pSrcVar->GetVec4(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_COLOR) - { - ColorF value = pSrcVar->GetColorF(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_MATRIX33) - { - Matrix33 value = pSrcVar->GetMatrix33(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_TEXTURE2D || pSrcVar->paramType == e_TEXTURE3D || pSrcVar->paramType == e_TEXTURE_CUBE) - { - ITexture* value = pSrcVar->GetTexture(); - pDestVar->InvokeSetter((void*)value); - } - } - - void CopyOpticsAboutSameOpticsType(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics) - { - if (pSrcOptics->GetType() != pDestOptics->GetType()) - { - return; - } - - AZStd::vector srcVarGroups = pSrcOptics->GetEditorParamGroups(); - AZStd::vector destVarGroups = pDestOptics->GetEditorParamGroups(); - - if (srcVarGroups.size() != destVarGroups.size()) - { - return; - } - - pDestOptics->SetEnabled(pSrcOptics->IsEnabled()); - - for (int i = 0, iVarGroupSize(srcVarGroups.size()); i < iVarGroupSize; ++i) - { - FuncVariableGroup srcVarGroup = srcVarGroups[i]; - FuncVariableGroup destVarGroup = destVarGroups[i]; - - if (srcVarGroup.GetVariableCount() != destVarGroup.GetVariableCount()) - { - continue; - } - - for (int k = 0, iVarSize(srcVarGroup.GetVariableCount()); k < iVarSize; ++k) - { - IFuncVariable* pSrcVar = srcVarGroup.GetVariable(k); - IFuncVariable* pDestVar = destVarGroup.GetVariable(k); - CopyVariable(pSrcVar, pDestVar); - } - } - } - - bool FindGroupByName(AZStd::vector& groupList, const QString& name, int& outIndex) - { - for (int i = 0, iVarGroupSize(groupList.size()); i < iVarGroupSize; ++i) - { - if (name == groupList[i].GetName()) - { - outIndex = i; - return true; - } - } - return false; - } - - void CopyOpticsAboutDifferentOpticsType(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics) - { - if (pSrcOptics->GetType() == pDestOptics->GetType()) - { - return; - } - - AZStd::vector srcVarGroups = pSrcOptics->GetEditorParamGroups(); - AZStd::vector destVarGroups = pDestOptics->GetEditorParamGroups(); - - pDestOptics->SetEnabled(pSrcOptics->IsEnabled()); - - for (int i = 0, iVarGroupSize(destVarGroups.size()); i < iVarGroupSize; ++i) - { - FuncVariableGroup destVarGroup = destVarGroups[i]; - int nIndex = 0; - if (!FindGroupByName(srcVarGroups, destVarGroup.GetName(), nIndex)) - { - continue; - } - FuncVariableGroup srcVarGroup = srcVarGroups[nIndex]; - - for (int k = 0, iVarSize(destVarGroup.GetVariableCount()); k < iVarSize; ++k) - { - IFuncVariable* pDestVar = destVarGroup.GetVariable(k); - IFuncVariable* pSrcVar = srcVarGroup.FindVariable(pDestVar->name.c_str()); - CopyVariable(pSrcVar, pDestVar); - } - } - } - - void CopyOptics(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics, bool bReculsiveCopy) - { - if (pSrcOptics->GetType() == pDestOptics->GetType()) - { - CopyOpticsAboutSameOpticsType(pSrcOptics, pDestOptics); - } - else - { - CopyOpticsAboutDifferentOpticsType(pSrcOptics, pDestOptics); - } - - if (bReculsiveCopy) - { - pDestOptics->RemoveAll(); - for (int i = 0, iChildCount(pSrcOptics->GetElementCount()); i < iChildCount; ++i) - { - IOpticsElementBasePtr pSrcChildOptics = pSrcOptics->GetElementAt(i); - IOpticsElementBasePtr pNewOptics = gEnv->pOpticsManager->Create(pSrcChildOptics->GetType()); - if (pNewOptics == NULL) - { - continue; - } - pNewOptics->SetName(pSrcChildOptics->GetName().c_str()); - CopyOptics(pSrcChildOptics, pNewOptics, bReculsiveCopy); - pDestOptics->AddElement(pNewOptics); - } - } - } - - CEntityObject* GetSelectedLightEntity() - { - CBaseObject* pSelectedObj = GetIEditor()->GetSelectedObject(); - if (pSelectedObj == NULL) - { - return NULL; - } - if (!qobject_cast(pSelectedObj)) - { - return NULL; - } - CEntityObject* pEntity = (CEntityObject*)pSelectedObj; - if (!pEntity->IsLight()) - { - return NULL; - } - return pEntity; - } - - void GetSelectedLightEntities(std::vector& outLightEntities) - { - CSelectionGroup* pSelectionGroup = GetIEditor()->GetSelection(); - if (pSelectionGroup == NULL) - { - return; - } - int nSelectionCount = pSelectionGroup->GetCount(); - outLightEntities.reserve(nSelectionCount); - for (int i = 0; i < nSelectionCount; ++i) - { - CBaseObject* pSelectedObj = pSelectionGroup->GetObject(i); - if (!qobject_cast(pSelectedObj)) - { - continue; - } - CEntityObject* pEntity = (CEntityObject*)pSelectedObj; - if (!pEntity->IsLight()) - { - continue; - } - outLightEntities.push_back(pEntity); - } - } - - IOpticsElementBasePtr GetSelectedLightOptics() - { - CEntityObject* pEntity = GetSelectedLightEntity(); - if (pEntity == NULL) - { - return NULL; - } - IOpticsElementBasePtr pEntityOptics = pEntity->GetOpticsElement(); - if (pEntityOptics == NULL) - { - return NULL; - } - return pEntityOptics; - } - - IOpticsElementBasePtr FindOptics(IOpticsElementBasePtr pStartOptics, const QString& name) - { - if (pStartOptics == NULL) - { - return NULL; - } - - if (!QString::compare(pStartOptics->GetName().c_str(), name)) - { - return pStartOptics; - } - - for (int i = 0, iElementCount(pStartOptics->GetElementCount()); i < iElementCount; ++i) - { - IOpticsElementBasePtr pFoundOptics = FindOptics(pStartOptics->GetElementAt(i), name); - if (pFoundOptics) - { - return pFoundOptics; - } - } - - return NULL; - } - - void RemoveOptics(IOpticsElementBasePtr pOptics) - { - if (pOptics == NULL) - { - return; - } - - IOpticsElementBasePtr pParent = pOptics->GetParent(); - if (pParent == NULL) - { - return; - } - - for (int i = 0, iElementCount(pParent->GetElementCount()); i < iElementCount; ++i) - { - if (pOptics == pParent->GetElementAt(i)) - { - pParent->Remove(i); - break; - } - } - } - - void ChangeOpticsRootName(IOpticsElementBasePtr pOptics, const QString& newRootName) - { - if (pOptics == NULL) - { - return; - } - - QString opticsName = pOptics->GetName().c_str(); - QString opticsRootName; - - int nPos = opticsName.indexOf("."); - if (nPos == -1) - { - opticsRootName = opticsName; - } - else - { - opticsRootName = opticsName.left(nPos); - } - - opticsName.replace(opticsRootName, newRootName); - pOptics->SetName(opticsName.toUtf8().data()); - - for (int i = 0, iElementSize(pOptics->GetElementCount()); i < iElementSize; ++i) - { - ChangeOpticsRootName(pOptics->GetElementAt(i), newRootName); - } - } - - void UpdateClipboard(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList) - { - XmlNodeRef rootNode = CreateXMLFromClipboardData(type, groupName, bPasteAtSameLevel, dataList); - CClipboard clipboard(nullptr); - clipboard.Put(rootNode); - } - - XmlNodeRef CreateXMLFromClipboardData(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList) - { - XmlNodeRef rootNode = gEnv->pSystem->CreateXmlNode(); - rootNode->setTag("FlareDB"); - rootNode->setAttr("Type", type.toUtf8().data()); - rootNode->setAttr("GroupName", groupName.toUtf8().data()); - rootNode->setAttr("PasteAtSameLevel", bPasteAtSameLevel); - - for (int i = 0, iDataSize(dataList.size()); i < iDataSize; ++i) - { - XmlNodeRef xmlNode = gEnv->pSystem->CreateXmlNode(); - xmlNode->setTag("Data"); - dataList[i].FillXmlNode(xmlNode); - rootNode->addChild(xmlNode); - } - - return rootNode; - } - - void UpdateOpticsName(IOpticsElementBasePtr pOptics) - { - if (pOptics == NULL) - { - return; - } - - IOpticsElementBasePtr pParent = pOptics->GetParent(); - if (pParent) - { - QString oldName = pOptics->GetName().c_str(); - QString parentName = pParent->GetName().c_str(); - QString updatedName = parentName + QString(".") + GetShortName(oldName); - pOptics->SetName(updatedName.toUtf8().data()); - } - - for (int i = 0, iElementCount(pOptics->GetElementCount()); i < iElementCount; ++i) - { - UpdateOpticsName(pOptics->GetElementAt(i)); - } - } - - QString ReplaceLastName(const QString& fullName, const QString& shortName) - { - int nPos = fullName.lastIndexOf('.'); - if (nPos == -1) - { - return shortName; - } - QString newName = fullName.left(nPos + 1); - newName += shortName; - return newName; - } - - IFuncVariable* GetFuncVariable(IOpticsElementBasePtr pOptics, int nFuncKey) - { - if (pOptics == NULL) - { - return NULL; - } - - int nGroupIndex = (nFuncKey & 0xFFFF0000) >> 16; - int nVarIndex = (nFuncKey & 0x0000FFFF); - - AZStd::vector paramGroups = pOptics->GetEditorParamGroups(); - - if (nGroupIndex >= paramGroups.size()) - { - return NULL; - } - - FuncVariableGroup* pGroup = ¶mGroups[nGroupIndex]; - if (pGroup == NULL) - { - return NULL; - } - - if (nVarIndex >= pGroup->GetVariableCount()) - { - return NULL; - } - - return pGroup->GetVariable(nVarIndex); - } - - void GetLightEntityObjects(std::vector& outEntityLights) - { - std::vector pEntityObjects; - GetIEditor()->GetObjectManager()->FindObjectsOfType(&CEntityObject::staticMetaObject, pEntityObjects); - for (int i = 0, iObjectSize(pEntityObjects.size()); i < iObjectSize; ++i) - { - CEntityObject* pEntity = (CEntityObject*)pEntityObjects[i]; - if (pEntity == NULL) - { - continue; - } - if (pEntity->CheckFlags(OBJFLAG_DELETED)) - { - continue; - } - if (!pEntity->IsLight()) - { - continue; - } - outEntityLights.push_back(pEntity); - } - } - - void OutputOpticsDebug(IOpticsElementBasePtr pOptics) - { - QString opticsName; - opticsName = QStringLiteral("Optics Name : %1\n").arg(pOptics->GetName().c_str()); - OutputDebugString(opticsName.toUtf8().data()); - - AZStd::vector groupArray(pOptics->GetEditorParamGroups()); - for (int i = 0, iGroupCount(groupArray.size()); i < iGroupCount; ++i) - { - FuncVariableGroup* pGroup = &groupArray[i]; - - QString groupStr; - groupStr = QStringLiteral("\tGroup : %1\n").arg(pGroup->GetName()); - OutputDebugString(groupStr.toUtf8().data()); - - for (int k = 0, iParamCount(pGroup->GetVariableCount()); k < iParamCount; ++k) - { - IFuncVariable* pVar = pGroup->GetVariable(k); - if (pVar == NULL) - { - continue; - } - QString str; - if (pVar->paramType == e_FLOAT) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str()).arg(pVar->GetFloat()); - } - else if (pVar->paramType == e_INT) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str()).arg(pVar->GetInt()); - } - else if (pVar->paramType == e_BOOL) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str(), pVar->GetBool() ? "TRUE" : "FALSE"); - } - else if (pVar->paramType == e_VEC2) - { - str = QStringLiteral("\t\t%1 : %2,%3\n").arg(pVar->name.c_str()).arg(pVar->GetVec2().x).arg(pVar->GetVec2().y); - } - else if (pVar->paramType == e_VEC3) - { - str = QStringLiteral("\t\t%1 : %2,%3,%4\n").arg(pVar->name.c_str()).arg(pVar->GetVec3().x).arg(pVar->GetVec3().y).arg(pVar->GetVec3().z); - } - else if (pVar->paramType == e_VEC4) - { - str = QStringLiteral("\t\t%1 : %2,%3,%4,%5\n").arg(pVar->name.c_str()).arg(pVar->GetVec4().x).arg(pVar->GetVec4().y).arg(pVar->GetVec4().z); - } - else if (pVar->paramType == e_COLOR) - { - str = QStringLiteral("\t\t%1 : %2,%3,%4,%5\n").arg(pVar->name.c_str()).arg(pVar->GetColorF().r).arg(pVar->GetColorF().g).arg(pVar->GetColorF().b).arg(pVar->GetColorF().a); - } - else if (pVar->paramType == e_TEXTURE2D || pVar->paramType == e_TEXTURE3D || pVar->paramType == e_TEXTURE_CUBE) - { - if (pVar->GetTexture()) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str(), pVar->GetTexture()->GetName()); - } - else - { - str = QStringLiteral("\t\t%1 : NULL\n").arg(pVar->name.c_str()); - } - } - OutputDebugString(str.toUtf8().data()); - } - } - - for (int i = 0, iChildCount(pOptics->GetElementCount()); i < iChildCount; ++i) - { - OutputOpticsDebug(pOptics->GetElementAt(i)); - } - } - - void FillParams(XmlNodeRef& paramNode, IOpticsElementBase* pOptics) - { - if (pOptics == NULL) - { - return; - } - AZStd::vector groupArray(pOptics->GetEditorParamGroups()); - for (int i = 0, iGroupCount(paramNode->getChildCount()); i < iGroupCount; ++i) - { - XmlNodeRef groupNode = paramNode->getChild(i); - if (groupNode == NULL) - { - continue; - } - - int nGroupIndex(0); - if (!FindGroup(groupNode->getTag(), pOptics, nGroupIndex)) - { - continue; - } - - FuncVariableGroup* pGroup = &groupArray[nGroupIndex]; - for (int k = 0, iParamCount(pGroup->GetVariableCount()); k < iParamCount; ++k) - { - IFuncVariable* pVar = pGroup->GetVariable(k); - if (pVar == NULL) - { - continue; - } - - if (pVar->paramType == e_FLOAT) - { - float fValue(0); - if (groupNode->getAttr(pVar->name.c_str(), fValue)) - { - pVar->InvokeSetter((void*)&fValue); - } - } - else if (pVar->paramType == e_INT) - { - int nValue(0); - if (groupNode->getAttr(pVar->name.c_str(), nValue)) - { - pVar->InvokeSetter((void*)&nValue); - } - } - else if (pVar->paramType == e_BOOL) - { - bool bValue(false); - if (groupNode->getAttr(pVar->name.c_str(), bValue)) - { - pVar->InvokeSetter((void*)&bValue); - } - } - else if (pVar->paramType == e_VEC2) - { - Vec2 vec2Value; - if (groupNode->getAttr(pVar->name.c_str(), vec2Value)) - { - pVar->InvokeSetter((void*)&vec2Value); - } - } - else if (pVar->paramType == e_VEC3) - { - Vec3 vec3Value; - if (groupNode->getAttr(pVar->name.c_str(), vec3Value)) - { - pVar->InvokeSetter((void*)&vec3Value); - } - } - else if (pVar->paramType == e_VEC4) - { - const char* strVec4Value; - if (groupNode->getAttr(pVar->name.c_str(), &strVec4Value)) - { - Vec4 vec4Value; - ExtractVec4FromString(strVec4Value, vec4Value); - pVar->InvokeSetter((void*)&vec4Value); - } - } - else if (pVar->paramType == e_COLOR) - { - Vec3 vec3Value; - if (!groupNode->getAttr(pVar->name.c_str(), vec3Value)) - { - continue; - } - string alphaStr = string(pVar->name.c_str()) + ".alpha"; - int alpha; - if (!groupNode->getAttr(alphaStr.c_str(), alpha)) - { - continue; - } - ColorF color; - color.r = vec3Value.x; - color.g = vec3Value.y; - color.b = vec3Value.z; - color.a = (float)alpha / 255.0f; - pVar->InvokeSetter((void*)&color); - } - else if (pVar->paramType == e_MATRIX33) - { - //reserved - } - else if (pVar->paramType == e_TEXTURE2D || pVar->paramType == e_TEXTURE3D || pVar->paramType == e_TEXTURE_CUBE) - { - const char* textureName; - if (!groupNode->getAttr(pVar->name.c_str(), &textureName)) - { - continue; - } - ITexture* pTexture = NULL; - if (textureName && strlen(textureName) > 0) - { - pTexture = gEnv->pRenderer->EF_LoadTexture(textureName); - } - pVar->InvokeSetter((void*)pTexture); - if (pTexture) - { - pTexture->Release(); - } - } - } - } - } - - void GetExpandedItemNames(CBaseLibraryItem* item, const QString& groupName, const QString& itemName, QString& outNameWithGroup, QString& outFullName) - { - QString name; - if (!groupName.isEmpty()) - { - name = groupName + "."; - } - name += itemName; - QString fullName = name; - if (item->GetLibrary()) - { - fullName = item->GetLibrary()->GetName() + "." + name; - } - outNameWithGroup = name; - outFullName = fullName; - } - - QModelIndex GetTreeItemByHitTest(QTreeView& treeCtrl) - { - return treeCtrl.indexAt(treeCtrl.mapFromGlobal(QCursor::pos())); - } - - int FindOpticsIndexUnderParentOptics(IOpticsElementBasePtr pOptics, IOpticsElementBasePtr pParentOptics) - { - for (int i = 0, iElementSize(pParentOptics->GetElementCount()); i < iElementSize; ++i) - { - if (pParentOptics->GetElementAt(i) == pOptics) - { - return i + 1; - } - } - return -1; - } -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.h deleted file mode 100644 index d9fb3e380c..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.h +++ /dev/null @@ -1,363 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUTIL_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUTIL_H -#pragma once - -#include -#include - -#include "Util/Variable.h" - -#include "IFlares.h" -class CEntityObject; - -class QTreeView; - -#define LENSFLARE_ELEMENT_TREE "LensFlareElementTree" -#define LENSFLARE_ITEM_TREE "LensFlareItemTree" -#define FLARECLIPBOARDTYPE_COPY "Copy" -#define FLARECLIPBOARDTYPE_CUT "Cut" - -namespace LensFlareUtil -{ - inline bool IsElement(EFlareType type) - { - return type != eFT__Base__ && type != eFT_Root && type != eFT_Group; - } - inline bool IsGroup(EFlareType type) - { - return type == eFT_Root || type == eFT_Group; - } - inline bool IsValidFlare(EFlareType type) - { - return type >= eFT__Base__ && type < eFT_Max; - } - - inline void AddVariable(CVariableBase& varArray, CVariableBase& var, const char* varName, const char* humanVarName, const char* description, char dataType = IVariable::DT_SIMPLE) - { - if (varName) - { - var.SetName(varName); - } - if (humanVarName) - { - var.SetHumanName(humanVarName); - } - if (description) - { - var.SetDescription(description); - } - var.SetDataType(dataType); - varArray.AddVariable(&var); - } - - inline void AddVariable(CVarBlock* vars, CVariableBase& var, const char* varName, const char* humanVarName, const char* description, unsigned char dataType = IVariable::DT_SIMPLE) - { - if (varName) - { - var.SetName(varName); - } - if (humanVarName) - { - var.SetHumanName(humanVarName); - } - if (description) - { - var.SetDescription(description); - } - var.SetDataType(dataType); - vars->AddVariable(&var); - } - - inline bool GetFlareType(const QString& typeName, EFlareType& outType) - { - FlareInfoArray::Props array = FlareInfoArray::Get(); - for (size_t i = 0; i < array.size; ++i) - { - if (typeName == array.p[i].name) - { - outType = array.p[i].type; - return true; - } - } - return false; - } - - inline bool GetFlareTypeName(QString& outTypeName, IOpticsElementBasePtr pOptics) - { - if (pOptics == NULL) - { - return false; - } - - const FlareInfoArray::Props array = FlareInfoArray::Get(); - for (size_t i = 0; i < array.size; ++i) - { - if (array.p[i].type == pOptics->GetType()) - { - outTypeName = array.p[i].name; - return true; - } - } - - return false; - } - - inline QString GetShortName(const QString& name) - { - int nPos = name.lastIndexOf('.'); - if (nPos == -1) - { - return name; - } - return name.right(name.length() - nPos - 1); - } - - inline QString GetGroupNameFromName(const QString& name) - { - int nPos = name.lastIndexOf('.'); - if (nPos == -1) - { - return name; - } - return name.left(nPos); - } - - inline QString GetGroupNameFromFullName(const QString& fullItemName) - { - int nLastDotPos = fullItemName.lastIndexOf('.'); - if (nLastDotPos == -1) - { - return fullItemName; - } - - QString name = GetGroupNameFromName(fullItemName); - - int nFirstDotPos = name.indexOf('.'); - if (nFirstDotPos == -1) - { - return name; - } - - return name.right(name.length() - nFirstDotPos - 1); - } - - inline bool HaveParameterLowBoundary(const QString& paramName) - { - if (!QString::compare(paramName, "Noiseseed", Qt::CaseInsensitive) || !QString::compare(paramName, "translation", Qt::CaseInsensitive) || !QString::compare(paramName, "position", Qt::CaseInsensitive) || !QString::compare(paramName, "rotation", Qt::CaseInsensitive)) - { - return false; - } - return true; - } - - inline int MakeFuncKey(int nGroupIndex, int nVarIndex) - { - return (nGroupIndex << 16) | nVarIndex; - } - - template - inline void BoundaryProcess(T& fValue) - { - if (fValue < 0) - { - fValue = 0; - } - } - - inline void BoundaryProcess(Vec2& v) - { - if (v.x < 0) - { - v.x = 0; - } - if (v.y < 0) - { - v.y = 0; - } - } - - inline void BoundaryProcess(Vec3& v) - { - if (v.x < 0) - { - v.x = 0; - } - if (v.y < 0) - { - v.y = 0; - } - if (v.z < 0) - { - v.z = 0; - } - } - - inline void BoundaryProcess(Vec4& v) - { - if (v.x < 0) - { - v.x = 0; - } - if (v.y < 0) - { - v.y = 0; - } - if (v.z < 0) - { - v.z = 0; - } - if (v.w < 0) - { - v.w = 0; - } - } - - inline bool ExtractVec4FromString(const string& buffer, Vec4& outVec4) - { - int nCount(0); - string copiedBuffer(buffer); - int commaPos(0); - while (nCount < 4 || commaPos != -1) - { - commaPos = copiedBuffer.find(","); - string strV; - if (commaPos == -1) - { - strV = copiedBuffer; - } - else - { - strV = copiedBuffer.Left(commaPos); - strV += ","; - } - copiedBuffer.replace(0, commaPos + 1, ""); - outVec4[nCount++] = (float)atof(strV.c_str()); - } - return nCount == 4; - } - - void FillParams(XmlNodeRef& paramNode, IOpticsElementBase* pOptics); - - inline bool FindGroup(const char* groupName, IOpticsElementBase* pOptics, int& nOutGroupIndex) - { - if (groupName == NULL) - { - return false; - } - - AZStd::vector groupArray = pOptics->GetEditorParamGroups(); - for (int i = 0, iCount(groupArray.size()); i < iCount; ++i) - { - if (!_stricmp(groupArray[i].GetName(), groupName)) - { - nOutGroupIndex = i; - return true; - } - } - return false; - } - - struct SClipboardData - { - SClipboardData(){} - ~SClipboardData(){} - SClipboardData(const QString& from, const QString& lensFlareFullPath, const QString& lensOpticsPath) - : m_From(from) - , m_LensFlareFullPath(lensFlareFullPath) - , m_LensOpticsPath(lensOpticsPath) - { - } - - void FillXmlNode(XmlNodeRef node) - { - if (node == NULL) - { - return; - } - node->setAttr("From", m_From.toUtf8().data()); - node->setAttr("FlareFullPath", m_LensFlareFullPath.toUtf8().data()); - node->setAttr("OpticsPath", m_LensOpticsPath.toUtf8().data()); - } - - void FillThisFromXmlNode(XmlNodeRef node) - { - if (node == NULL) - { - return; - } - node->getAttr("From", m_From); - node->getAttr("FlareFullPath", m_LensFlareFullPath); - node->getAttr("OpticsPath", m_LensOpticsPath); - } - - QString m_From; - QString m_LensFlareFullPath; - QString m_LensOpticsPath; - }; - - struct SDragAndDropInfo - { - SDragAndDropInfo() - { - m_XMLContents = NULL; - m_bDragging = false; - } - ~SDragAndDropInfo() - { - Reset(); - } - void Reset() - { - m_XMLContents = NULL; - m_bDragging = false; - } - bool m_bDragging; - XmlNodeRef m_XMLContents; - }; - - inline SDragAndDropInfo& GetDragDropInfo() - { - static SDragAndDropInfo dragDropInfo; - return dragDropInfo; - } - - int FindOpticsIndexUnderParentOptics(IOpticsElementBasePtr pOptics, IOpticsElementBasePtr pParentOptics); - bool IsPointInWindow(const QWidget* pWindow, const QPoint& screenPos); - QModelIndex GetTreeItemByHitTest(QTreeView& treeCtrl); - QPoint GetDragCursorPos(QWidget* pWnd, const QPoint& point); - void GetExpandedItemNames(CBaseLibraryItem* item, const QString& groupName, const QString& itemName, QString& outNameWithGroup, QString& outFullName); - void GetSelectedLightEntities(std::vector& outLightEntities); - void GetLightEntityObjects(std::vector& outEntityLights); - IFuncVariable* GetFuncVariable(IOpticsElementBasePtr pOptics, int nFuncKey); - QString ReplaceLastName(const QString& fullName, const QString& shortName); - void UpdateOpticsName(IOpticsElementBasePtr pOptics); - XmlNodeRef CreateXMLFromClipboardData(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList); - void UpdateClipboard(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList); - void ChangeOpticsRootName(IOpticsElementBasePtr pOptics, const QString& newRootName); - void RemoveOptics(IOpticsElementBasePtr pOptics); - IOpticsElementBasePtr FindOptics(IOpticsElementBasePtr pStartOptics, const QString& name); - CEntityObject* GetSelectedLightEntity(); - IOpticsElementBasePtr GetSelectedLightOptics(); - IOpticsElementBasePtr CreateOptics(const XmlNodeRef& xmlNode); - IOpticsElementBasePtr CreateOptics(IOpticsElementBasePtr pOptics, bool bForceTypeToGroup = false); - bool FillOpticsFromXML(IOpticsElementBasePtr pOptics, const XmlNodeRef& xmlNode); - bool CreateXmlData(IOpticsElementBasePtr pOptics, XmlNodeRef& pOutNode); - void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar, std::vector& funcs); - void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar); - void CopyOptics(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics, bool bReculsiveCopy = true); - void OutputOpticsDebug(IOpticsElementBasePtr pOptics); -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUTIL_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.cpp deleted file mode 100644 index 05248b32f5..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareView.h" - -// Editor -#include "LensFlareItem.h" -#include "LensFlareEditor.h" -#include "Objects/EntityObject.h" -#include "Material/MaterialManager.h" - - -CLensFlareView::CLensFlareView(QWidget* parent, Qt::WindowFlags f) - : CPreviewModelCtrl(parent, f) -{ - InitDialog(); -} - -CLensFlareView::~CLensFlareView() -{ - CLensFlareEditor::GetLensFlareEditor()->UnregisterLensFlareItemChangeListener(this); -} - -void CLensFlareView::InitDialog() -{ - CLensFlareEditor::GetLensFlareEditor()->RegisterLensFlareItemChangeListener(this); - - SetClearColor(ColorF(0, 0, 0, 0)); - SetGrid(true); - SetAxis(true); - EnableUpdate(true); - m_pLensFlareMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(CEntityObject::s_LensFlareMaterialName); - m_InitCameraPos = m_camera.GetPosition(); -} - -void CLensFlareView::RenderObject(_smart_ptr pMaterial, [[maybe_unused]] SRenderingPassInfo& passInfo) -{ - if (m_pLensFlareItem) - { - IOpticsElementBasePtr pOptics = m_pLensFlareItem->GetOptics(); - if (pOptics && m_pLensFlareMaterial) - { - _smart_ptr pMaterial = m_pLensFlareMaterial->GetMatInfo(); - if (pMaterial) - { - m_pRenderer->ForceUpdateGlobalShaderParameters(); - m_pRenderer->SetViewport(1, 1, m_pRenderer->GetWidth(), m_pRenderer->GetHeight()); - SShaderItem& shaderItem = pMaterial->GetShaderItem(); - SLensFlareRenderParam param; - param.pCamera = &m_camera; - param.pShader = shaderItem.m_pShader; - pOptics->Render(¶m, Vec3(0, 0, 0)); - } - } - } -} - -void CLensFlareView::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - if (m_pLensFlareItem != pLensFlareItem) - { - m_pLensFlareItem = pLensFlareItem; - Update(true); - m_bHaveAnythingToRender = m_pLensFlareItem != NULL; - } -} - -void CLensFlareView::OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem) -{ - if (m_pLensFlareItem == pLensFlareItem) - { - m_pLensFlareItem = NULL; - Update(); - m_bHaveAnythingToRender = false; - } -} - -void CLensFlareView::OnInternalVariableChange([[maybe_unused]] IVariable* pVar) -{ - Update(); -} - -void CLensFlareView::OnLensFlareChangeElement([[maybe_unused]] CLensFlareElement* pLensFlareElement) -{ - Update(); -} - -void CLensFlareView::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnCloseScene: - ReleaseObject(); - break; - } -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.h deleted file mode 100644 index f514211046..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREVIEW_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREVIEW_H -#pragma once - -#include "ILensFlareListener.h" -#include "Controls/PreviewModelCtrl.h" - -class CLensFlareView - : public CPreviewModelCtrl - , public ILensFlareChangeItemListener - , public ILensFlareChangeElementListener -{ -public: - explicit CLensFlareView(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~CLensFlareView(); - - void OnInternalVariableChange(IVariable* pVar); - void OnEditorNotifyEvent(EEditorNotifyEvent event); - -protected: - - void InitDialog(); - void ProcessKeys(){} - void RenderObject(_smart_ptr pMaterial, SRenderingPassInfo& passInfo); - - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement); - -private: - - QPoint m_prevPoint; - Vec3 m_InitCameraPos; - - _smart_ptr m_pLensFlareMaterial; - _smart_ptr m_pLensFlareItem; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREVIEW_H diff --git a/Code/Sandbox/Editor/LevelInfo.cpp b/Code/Sandbox/Editor/LevelInfo.cpp index 4b8a6d5cac..81441a3797 100644 --- a/Code/Sandbox/Editor/LevelInfo.cpp +++ b/Code/Sandbox/Editor/LevelInfo.cpp @@ -20,7 +20,6 @@ // Editor #include "Util/fastlib.h" -#include "Material/MaterialManager.h" // for CMaterialManager #include @@ -67,7 +66,6 @@ void CLevelInfo::Validate() // Validate level. ValidateObjects(); - ValidateMaterials(); if (m_pReport->GetErrorCount() == 0) { @@ -186,11 +184,3 @@ void CLevelInfo::ValidateObjects() } } } - -////////////////////////////////////////////////////////////////////////// -void CLevelInfo::ValidateMaterials() -{ - // Validate all objects - CBaseObjectsArray objects; - GetIEditor()->GetMaterialManager()->Validate(); -} diff --git a/Code/Sandbox/Editor/LevelInfo.h b/Code/Sandbox/Editor/LevelInfo.h index 0611ad652e..515a21886e 100644 --- a/Code/Sandbox/Editor/LevelInfo.h +++ b/Code/Sandbox/Editor/LevelInfo.h @@ -27,7 +27,6 @@ public: private: void ValidateObjects(); - void ValidateMaterials(); IErrorReport* m_pReport; }; diff --git a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h index 27ac7e8a46..4a20bd6b60 100644 --- a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h +++ b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h @@ -32,7 +32,6 @@ public: public: MOCK_METHOD0(DeleteThis, void()); MOCK_METHOD0(GetSystem, ISystem*()); - MOCK_METHOD0(Get3DEngine, I3DEngine* ()); MOCK_METHOD0(GetRenderer, IRenderer* ()); MOCK_METHOD0(GetClassFactory, IEditorClassFactory* ()); MOCK_METHOD0(GetCommandManager, CEditorCommandManager*()); @@ -91,12 +90,10 @@ public: MOCK_METHOD0(GetObjectManager, struct IObjectManager* ()); MOCK_METHOD0(GetSettingsManager, CSettingsManager* ()); MOCK_METHOD1(GetDBItemManager, IDataBaseManager* (EDataBaseItemType)); - MOCK_METHOD0(GetMaterialManager, CMaterialManager* ()); MOCK_METHOD0(GetMaterialManagerLibrary, IBaseLibraryManager* ()); MOCK_METHOD0(GetIEditorMaterialManager, IEditorMaterialManager* ()); MOCK_METHOD0(GetIconManager, IIconManager* ()); MOCK_METHOD0(GetMusicManager, CMusicManager* ()); - MOCK_METHOD0(GetLensFlareManager, CLensFlareManager* ()); MOCK_METHOD2(GetTerrainElevation, float(float , float )); MOCK_METHOD0(GetVegetationMap, class CVegetationMap* ()); MOCK_METHOD0(GetEditorQtApplication, Editor::EditorQtApplication* ()); @@ -193,7 +190,6 @@ public: MOCK_METHOD0(GetBackgroundScheduleManager, struct IBackgroundScheduleManager* ()); MOCK_METHOD1(ShowStatusText, void(bool )); MOCK_METHOD1(RegisterObjectContextMenuExtension, void(TContextMenuExtensionFunc )); - MOCK_METHOD1(SetCurrentMissionTime, void(float )); MOCK_METHOD0(GetEnv, SSystemGlobalEnvironment* ()); MOCK_METHOD0(GetImageUtil, IImageUtil* ()); MOCK_METHOD0(GetEditorSettings, SEditorSettings* ()); diff --git a/Code/Sandbox/Editor/Lib/Tests/test_MaterialPythonFuncs.cpp b/Code/Sandbox/Editor/Lib/Tests/test_MaterialPythonFuncs.cpp deleted file mode 100644 index c27608b695..0000000000 --- a/Code/Sandbox/Editor/Lib/Tests/test_MaterialPythonFuncs.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "EditorDefs.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace MaterialPythonFuncsUnitTests -{ - - class MaterialPythonBindingsFixture - : public testing::Test - { - public: - AzToolsFramework::ToolsApplication m_app; - - void SetUp() override - { - AzFramework::Application::Descriptor appDesc; - appDesc.m_enableDrilling = false; - - m_app.Start(appDesc); - // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is - // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash - // in the unit tests. - AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize); - m_app.RegisterComponentDescriptor(AzToolsFramework::MaterialPythonFuncsHandler::CreateDescriptor()); - } - - void TearDown() override - { - m_app.Stop(); - } - }; - - TEST_F(MaterialPythonBindingsFixture, MaterialEditorCommands_ApiExists) - { - AZ::BehaviorContext* behaviorContext = m_app.GetBehaviorContext(); - ASSERT_TRUE(behaviorContext); - - EXPECT_TRUE(behaviorContext->m_methods.find("create") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("create_multi") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("convert_to_multi") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("duplicate_current") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("merge_selection") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("delete_current") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("get_submaterial") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("get_property") != behaviorContext->m_methods.end()); - EXPECT_TRUE(behaviorContext->m_methods.find("set_property") != behaviorContext->m_methods.end()); - } -} diff --git a/Code/Sandbox/Editor/LyViewPaneNames.h b/Code/Sandbox/Editor/LyViewPaneNames.h index 3ea793b9c7..e95191ce06 100644 --- a/Code/Sandbox/Editor/LyViewPaneNames.h +++ b/Code/Sandbox/Editor/LyViewPaneNames.h @@ -44,8 +44,6 @@ namespace LyViewPane static const char* const TerrainTool = "Terrain Tool"; static const char* const TerrainTextureLayers = "Terrain Texture Layers"; static const char* const ParticleEditor = "Particle Editor"; - static const char* const LensFlareEditor = "Lens Flare Editor"; - static const char* const TimeOfDayEditor = "Time Of Day"; static const char* const AudioControlsEditor = "Audio Controls Editor"; static const char* const SubstanceEditor = "Substance Editor"; static const char* const VegetationEditor = "Vegetation Editor"; diff --git a/Code/Sandbox/Editor/MainWindow.cpp b/Code/Sandbox/Editor/MainWindow.cpp index 0ac7da33a7..e9bfd96a1d 100644 --- a/Code/Sandbox/Editor/MainWindow.cpp +++ b/Code/Sandbox/Editor/MainWindow.cpp @@ -42,7 +42,6 @@ AZ_POP_DISABLE_WARNING #include #include #include -#include // AzToolsFramework #include @@ -91,17 +90,13 @@ AZ_POP_DISABLE_WARNING #include "TrackView/TrackViewDialog.h" #include "ErrorReportDialog.h" -#include "LensFlareEditor/LensFlareEditor.h" -#include "TimeOfDayDialog.h" #include "Dialogs/PythonScriptsDialog.h" -#include "Material/MaterialManager.h" #include "EngineSettingsManager.h" #include "AzAssetBrowser/AzAssetBrowserWindow.h" #include "AssetEditor/AssetEditorWindow.h" #include "GridSettingsDialog.h" -#include "MaterialSender.h" #include "ActionManager.h" // uncomment this to show thumbnail demo widget @@ -888,9 +883,6 @@ void MainWindow::InitActions() .SetStatusTip(tr("Restore saved state (Fetch)")); // Modify actions - am->AddAction(ID_EDIT_RENAMEOBJECT, tr("Rename Object(s)...")) - .SetStatusTip(tr("Rename Object")); - am->AddAction(ID_EDITMODE_MOVE, tr("Move")) .SetIcon(Style::icon("Move")) .SetApplyHoverEffect() @@ -1085,8 +1077,6 @@ void MainWindow::InitActions() // Tools actions am->AddAction(ID_RELOAD_TEXTURES, tr("Reload Textures/Shaders")) .SetStatusTip(tr("Reload all textures.")); - am->AddAction(ID_RELOAD_GEOMETRY, tr("Reload Geometry")) - .SetStatusTip(tr("Reload all geometries.")); am->AddAction(ID_TOOLS_ENABLEFILECHANGEMONITORING, tr("Enable File Change Monitoring")); am->AddAction(ID_CLEAR_REGISTRY, tr("Clear Registry Data")) .SetStatusTip(tr("Clear Registry Data")); @@ -1096,7 +1086,7 @@ void MainWindow::InitActions() QAction* saveLevelStatsAction = am->AddAction(ID_TOOLS_LOGMEMORYUSAGE, tr("Save Level Statistics")) .SetStatusTip(tr("Logs Editor memory usage.")); - if( saveLevelStatsAction && AZ::Interface::Get()) + if( saveLevelStatsAction ) { saveLevelStatsAction->setEnabled(false); } @@ -1192,13 +1182,6 @@ void MainWindow::InitActions() .SetIcon(Style::icon("Audio")) .SetApplyHoverEffect(); - if (!AZ::Interface::Get()) - { - am->AddAction(ID_TERRAIN_TIMEOFDAYBUTTON, tr("Time of Day Editor")) - .SetToolTip(tr("Open Time of Day")) - .SetApplyHoverEffect(); - } - am->AddAction(ID_OPEN_UICANVASEDITOR, tr(LyViewPane::UiEditor)) .SetToolTip(tr("Open UI Editor")) .SetApplyHoverEffect(); @@ -1344,7 +1327,7 @@ QToolButton* MainWindow::CreateDebugModeButton() QWidget* MainWindow::CreateSpacerRightWidget() { - QWidget* spacer = new QWidget(); + QWidget* spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); spacer->setVisible(true); return spacer; @@ -1366,12 +1349,6 @@ void MainWindow::InitEnvironmentModeMenu(CVarMenu* environmentModeMenu) environmentModeMenu->AddCVarToggleItem({ "r_ssdo", tr("Hide Screen Space Directional Occlusion"), 0, 1 }); environmentModeMenu->AddCVarToggleItem({ "e_DynamicLights", tr("Hide All Dynamic Lights"), 0, 1 }); environmentModeMenu->AddSeparator(); - environmentModeMenu->AddCVarValuesItem("e_TimeOfDay", tr("Time of Day"), - { - {tr("Day (1:00 pm)"), 13}, - {tr("Night (9:00 pm)"), 21} - }, 9); - environmentModeMenu->AddSeparator(); environmentModeMenu->AddCVarToggleItem({ "e_Entities", tr("Hide Entities"), 0, 1 }); environmentModeMenu->AddSeparator(); environmentModeMenu->AddCVarToggleItem({ "e_Vegetation", tr("Hide Vegetation"), 0, 1 }); @@ -1655,11 +1632,6 @@ void MainWindow::RegisterStdViewClasses() AzAssetBrowserWindow::RegisterViewClass(); AssetEditorWindow::RegisterViewClass(); - if (!AZ::Interface::Get()) - { - CLensFlareEditor::RegisterViewClass(); - CTimeOfDayDialog::RegisterViewClass(); - } #ifdef ThumbnailDemo ThumbnailsSampleWidget::RegisterViewClass(); #endif diff --git a/Code/Sandbox/Editor/MatEditPreviewDlg.cpp b/Code/Sandbox/Editor/MatEditPreviewDlg.cpp deleted file mode 100644 index 4bac9b5e76..0000000000 --- a/Code/Sandbox/Editor/MatEditPreviewDlg.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MatEditPreviewDlg.h" - -// Qt -#include -#include -#include - -// Editor -#include "Material/MaterialManager.h" -#include "Material/MaterialPreviewModelView.h" - - -///////////////////////////////////////////////////////////////////////////// -// CMatEditPreviewDlg dialog - - -CMatEditPreviewDlg::CMatEditPreviewDlg(QWidget* parent) - : QDialog(parent) -{ - setAttribute(Qt::WA_DeleteOnClose); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - - setWindowTitle(tr("Material Preview")); - - /* create sub controls */ - m_previewCtrl.reset(new MaterialPreviewModelView(this)); - m_menubar.reset(new QMenuBar); - - /* configure layout */ - QVBoxLayout* layout = new QVBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(m_menubar.data()); - layout->addWidget(m_previewCtrl.data()); - layout->setStretchFactor(m_previewCtrl.data(), 1); - setLayout(layout); - - GetIEditor()->GetMaterialManager()->AddListener(this); - - SetupMenuBar(); - - OnPreviewPlane(); - m_previewCtrl->SetMaterial(GetIEditor()->GetMaterialManager()->GetCurrentMaterial() ? GetIEditor()->GetMaterialManager()->GetCurrentMaterial()->GetMatInfo() : nullptr); - m_previewCtrl->Update(); -} - -CMatEditPreviewDlg::~CMatEditPreviewDlg() -{ - GetIEditor()->GetMaterialManager()->RemoveListener(this); -} - -QSize CMatEditPreviewDlg::sizeHint() const -{ - return QSize(450, 400); -} - -void CMatEditPreviewDlg::showEvent(QShowEvent* e) -{ - QDialog::showEvent(e); - resize(sizeHint()); // Because WindowDecorationWrapper resizes it to the minimum for some reason. -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::SetupMenuBar() -{ - QMenu* menu; - QAction* action; - - menu = m_menubar->addMenu(tr("Preview")); - action = menu->addAction(tr("&Plane")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewPlane); - action = menu->addAction(tr("&Sphere")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewSphere); - action = menu->addAction(tr("&Box")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewBox); - action = menu->addAction(tr("&Teapot")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewTeapot); - action = menu->addAction(tr("&Custom")); - connect(action, &QAction::triggered, this, &CMatEditPreviewDlg::OnPreviewCustom); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewSphere() -{ - m_previewCtrl->LoadModelFile("Objects/MtlSphere.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewBox() -{ - m_previewCtrl->LoadModelFile("Objects/MtlBox.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewTeapot() -{ - m_previewCtrl->LoadModelFile("Objects/MtlTeapot.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewPlane() -{ - m_previewCtrl->LoadModelFile("Objects/MtlPlane.cgf"); -} - -////////////////////////////////////////////////////////////////////////// -void CMatEditPreviewDlg::OnPreviewCustom() -{ - const QString fullFileName = - QFileDialog::getOpenFileName(this, tr("Custom Model"), QString(), tr("Objects (*.cgf);;All files (*.*)")); - if (!fullFileName.isNull()) - { - m_previewCtrl->LoadModelFile(fullFileName); - } -} - -///////////////////////////////////////////////////////////////////////////// -// CMatEditPreviewDlg message handlers - -void CMatEditPreviewDlg::OnDataBaseItemEvent([[maybe_unused]] IDataBaseItem* pItem, EDataBaseItemEvent event) -{ - switch (event) - { - case EDB_ITEM_EVENT_SELECTED: - case EDB_ITEM_EVENT_ADD: - case EDB_ITEM_EVENT_CHANGED: - m_previewCtrl->SetMaterial(GetIEditor()->GetMaterialManager()->GetCurrentMaterial() ? GetIEditor()->GetMaterialManager()->GetCurrentMaterial()->GetMatInfo() : nullptr); - break; - case EDB_ITEM_EVENT_DELETE: - m_previewCtrl->SetMaterial(nullptr); - break; - } -} - -#include diff --git a/Code/Sandbox/Editor/MatEditPreviewDlg.h b/Code/Sandbox/Editor/MatEditPreviewDlg.h deleted file mode 100644 index 870d1b901e..0000000000 --- a/Code/Sandbox/Editor/MatEditPreviewDlg.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATEDITPREVIEWDLG_H -#define CRYINCLUDE_EDITOR_MATEDITPREVIEWDLG_H - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include - -#include "IDataBaseManager.h" -#endif - -class MaterialPreviewModelView; -class QMenuBar; - -// MatEditPreviewDlg.h : header file -// - -///////////////////////////////////////////////////////////////////////////// -// CMatEditPreviewDlg dialog -class CMatEditPreviewDlg - : public QDialog - , public IDataBaseManagerListener -{ - Q_OBJECT - // Construction -public: - CMatEditPreviewDlg(QWidget* parent); // standard constructor - ~CMatEditPreviewDlg(); - - QSize sizeHint() const override; - void showEvent(QShowEvent*) override; - - //Functions - - virtual void OnDataBaseItemEvent(IDataBaseItem* pItem, EDataBaseItemEvent event); - -protected: - void SetupMenuBar(); - -private slots: - void OnPreviewSphere(); - void OnPreviewPlane(); - void OnPreviewBox(); - void OnPreviewTeapot(); - void OnPreviewCustom(); - -private: - QScopedPointer m_previewCtrl; - QScopedPointer m_menubar; -}; - -#endif // CRYINCLUDE_EDITOR_MATEDITPREVIEWDLG_H diff --git a/Code/Sandbox/Editor/Material/Material.cpp b/Code/Sandbox/Editor/Material/Material.cpp deleted file mode 100644 index 3d642a53dd..0000000000 --- a/Code/Sandbox/Editor/Material/Material.cpp +++ /dev/null @@ -1,1982 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "Material.h" - -// Editor -#include "MaterialHelpers.h" -#include "MaterialManager.h" -#include "UsedResources.h" -#include "ErrorReport.h" -#include "Include/ISourceControl.h" -#include "Undo/IUndoObject.h" - - -static SInputShaderResources defaultShaderResource; - -////////////////////////////////////////////////////////////////////////// -CMaterial::CMaterial(const QString& name, int nFlags) - : m_highlightFlags(0) - , m_dccMaterialHash(0) -{ - m_scFileAttributes = SCC_FILE_ATTRIBUTE_NORMAL; - - m_pParent = 0; - - m_shaderResources = defaultShaderResource; - m_shaderResources.m_LMaterial.m_Opacity = 1; - m_shaderResources.m_LMaterial.m_Diffuse.Set(1.0f, 1.0f, 1.0f, 1.0f); - m_shaderResources.m_LMaterial.m_Specular.Set(0.045f, 0.045f, 0.045f, 1.0f); // default 59 spec + div by Gamma exponent -> lin - m_shaderResources.m_LMaterial.m_Smoothness = 10.0f; - - m_mtlFlags = nFlags; - ZeroStruct(m_shaderItem); - - // Default shader. - m_shaderName = "Illum"; - m_nShaderGenMask = 0; - - m_name = name; - m_bRegetPublicParams = true; - m_bKeepPublicParamsValues = false; - m_bIgnoreNotifyChange = false; - m_bDummyMaterial = false; - - m_pMatInfo = NULL; - m_propagationFlags = 0; - - m_allowLayerActivation = true; -} - -CMaterial::CMaterial(const CMaterial& rhs) - : m_scFileAttributes{rhs.m_scFileAttributes} - , m_pParent{nullptr} - , m_shaderResources{rhs.m_shaderResources} - , m_mtlFlags{rhs.m_mtlFlags} - , m_shaderName{rhs.m_shaderName} - , m_nShaderGenMask{rhs.m_nShaderGenMask} - , m_bRegetPublicParams{rhs.m_bRegetPublicParams} - , m_bKeepPublicParamsValues{rhs.m_bKeepPublicParamsValues} - , m_bDummyMaterial{rhs.m_bDummyMaterial} - , m_pMatInfo{nullptr} - , m_propagationFlags{rhs.m_propagationFlags} - , m_allowLayerActivation{rhs.m_allowLayerActivation} - , m_dccMaterialHash(rhs.m_dccMaterialHash) -{ - ZeroStruct(m_shaderItem); - m_name = rhs.m_name; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial::~CMaterial() -{ - if (IsModified()) - { - Save(false); - } - - // Release used shader. - SAFE_RELEASE(m_shaderItem.m_pShader); - SAFE_RELEASE(m_shaderItem.m_pShaderResources); - - if (m_pMatInfo) - { - m_pMatInfo->SetUserData(0); - m_pMatInfo = 0; - } - - if (!m_subMaterials.empty()) - { - for (int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_subMaterials[i]->m_pParent = NULL; - } - } - - m_subMaterials.clear(); - } - - if (!IsPureChild() && !(GetFlags() & MTL_FLAG_UIMATERIAL)) - { - // Unregister this material from manager. - // Don't use here local variable m_pManager. Manager can be destroyed. - if (GetIEditor()->GetMaterialManager()) - { - GetIEditor()->GetMaterialManager()->DeleteItem(this); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetName(const QString& name) -{ - if (name != m_name) - { - QString oldName = GetFullName(); - m_name = name; - - if (!IsPureChild()) - { - if (GetIEditor()->GetMaterialManager()) - { - GetIEditor()->GetMaterialManager()->OnRenameItem(this, oldName); - } - - if (m_pMatInfo) - { - GetIEditor()->Get3DEngine()->GetMaterialManager()->RenameMaterial(m_pMatInfo, GetName().toUtf8().data()); - } - } - else - { - if (m_pMatInfo) - { - m_pMatInfo->SetName(m_name.toUtf8().data()); - } - } - - NotifyChanged(); - } - - if (m_shaderItem.m_pShaderResources) - { - // Only for correct warning message purposes. - m_shaderItem.m_pShaderResources->SetMaterialName(m_name.toUtf8().data()); - } -} - - -////////////////////////////////////////////////////////////////////////// -QString CMaterial::GetFilename() const -{ - return GetIEditor()->GetMaterialManager()->MaterialToFilename(IsPureChild() && m_pParent ? m_pParent->m_name : m_name); -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::GetTextureFilenames(QStringList& outFilenames) const -{ - for (auto& iter : m_shaderResources.m_TexturesResourcesMap ) - { - const SEfResTexture* pTexture = (const SEfResTexture*) &(iter.second); - QString name = QtUtil::ToQString(pTexture->m_Name); - if (name.isEmpty()) - { - AZ_Warning("Shaders System", false, "Error: CMaterial::GetTextureFilenames - texture slot name does not exist for slot %d", iter.first ); - continue; - } - - // Collect image filenames - if (IResourceCompilerHelper::IsSourceImageFormatSupported(name.toUtf8().data())) - { - stl::push_back_unique(outFilenames, Path::GamePathToFullPath(name)); - } - - // collect source files used in DCC tools - QString dccFilename; - if (CFileUtil::CalculateDccFilename(name, dccFilename)) - { - stl::push_back_unique(outFilenames, Path::GamePathToFullPath(dccFilename)); - } - } - - if (IsMultiSubMaterial()) - { - for (int i = 0; i < GetSubMaterialCount(); ++i) - { - CMaterial* pSubMtl = GetSubMaterial(i); - if (pSubMtl) - { - pSubMtl->GetTextureFilenames(outFilenames); - } - } - } - - return outFilenames.size(); -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::GetAnyTextureFilenames(QStringList& outFilenames) const -{ - for ( auto& iter : m_shaderResources.m_TexturesResourcesMap ) - { - QString name = QtUtil::ToQString( iter.second.m_Name); - if (name.isEmpty()) - { - continue; - } - - // Collect any filenames - stl::push_back_unique(outFilenames, Path::GamePathToFullPath(name)); - } - - if (IsMultiSubMaterial()) - { - for (int i = 0; i < GetSubMaterialCount(); ++i) - { - CMaterial* pSubMtl = GetSubMaterial(i); - if (pSubMtl) - { - pSubMtl->GetAnyTextureFilenames(outFilenames); - } - } - } - - return outFilenames.size(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::UpdateFileAttributes(bool useSourceControl) -{ - QString filename = GetFilename(); - if (filename.isEmpty()) - { - return; - } - - m_scFileAttributes = CFileUtil::GetAttributes(filename.toUtf8().data(), useSourceControl); -} - -////////////////////////////////////////////////////////////////////////// -uint32 CMaterial::GetFileAttributes() -{ - if (IsDummy()) - { - return m_scFileAttributes; - } - - if (IsPureChild() && m_pParent) - { - return m_pParent->GetFileAttributes(); - } - - UpdateFileAttributes(); - return m_scFileAttributes; -}; - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetShaderName(const QString& shaderName) -{ - if (m_shaderName != shaderName) - { - m_bRegetPublicParams = true; - m_bKeepPublicParamsValues = false; - - RecordUndo("Change Shader"); - } - - m_shaderName = shaderName; - if (QString::compare(m_shaderName, "nodraw", Qt::CaseInsensitive) == 0) - { - m_mtlFlags |= MTL_FLAG_NODRAW; - } - else - { - m_mtlFlags &= ~MTL_FLAG_NODRAW; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::CheckSpecialConditions() -{ - if (QString::compare(m_shaderName, "nodraw", Qt::CaseInsensitive) == 0) - { - m_mtlFlags |= MTL_FLAG_NODRAW; - } - else - { - m_mtlFlags &= ~MTL_FLAG_NODRAW; - } - - // If environment texture name have auto/nearest cubemap in it, force material to use auto cube-map for it. - SEfResTexture* pTextureRes = m_shaderResources.GetTextureResource(EFTT_ENV); - if (!pTextureRes) - return; - - if (!pTextureRes->m_Name.empty()) - { - const char* sAtPos; - sAtPos = strstr(pTextureRes->m_Name.c_str(), "auto_2d"); - if (sAtPos) - { - pTextureRes->m_Sampler.m_eTexType = eTT_Auto2D; // Force Auto-2D - } - sAtPos = strstr(pTextureRes->m_Name.c_str(), "nearest_cubemap"); - if (sAtPos) - { - pTextureRes->m_Sampler.m_eTexType = eTT_NearestCube; // Force Nearest Cubemap - } - } - - // Force auto 2D map if user sets texture type - if (pTextureRes->m_Sampler.m_eTexType == eTT_Auto2D) - { - pTextureRes->m_Name = "auto_2d"; - } - - // Force nearest cube map if user sets texture type - if (pTextureRes->m_Sampler.m_eTexType == eTT_NearestCube) - { - pTextureRes->m_Name = "nearest_cubemap"; - m_mtlFlags |= MTL_FLAG_REQUIRE_NEAREST_CUBEMAP; - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::LoadShader() -{ - if (m_bDummyMaterial) - { - return true; - } - - CheckSpecialConditions(); - - GetIEditor()->GetErrorReport()->SetCurrentValidatorItem(this); - - m_shaderResources.m_ResFlags = m_mtlFlags; - - QString sShader = m_shaderName; - if (sShader.isEmpty()) - { - sShader = ""; - } - - QByteArray n = m_name.toUtf8(); - m_shaderResources.m_szMaterialName = n.data(); - SShaderItem newShaderItem = GetIEditor()->GetRenderer()->EF_LoadShaderItem(sShader.toUtf8().data(), false, 0, &m_shaderResources, m_nShaderGenMask); - - // Shader not found - if (newShaderItem.m_pShader && (newShaderItem.m_pShader->GetFlags() & EF_NOTFOUND) != 0) - { - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "Failed to load shader \"%s\" in material \"%s\"", newShaderItem.m_pShader->GetName(), m_name.toUtf8().constData()); - } - - // Release previously used shader (Must be After new shader is loaded, for speed). - SAFE_RELEASE(m_shaderItem.m_pShader); - SAFE_RELEASE(m_shaderItem.m_pShaderResources); - - m_shaderItem = newShaderItem; - if (!m_shaderItem.m_pShader) - { - CErrorRecord err; - - err.error = QObject::tr("Failed to Load Shader %1").arg(m_shaderName); - err.pItem = this; - - GetIEditor()->GetErrorReport()->ReportError(err); - GetIEditor()->GetErrorReport()->SetCurrentValidatorItem(NULL); - return false; - } - - IShader* pShader = m_shaderItem.m_pShader; - m_nShaderGenMask = pShader->GetGenerationMask(); - if (pShader->GetFlags() & EF_NOPREVIEW) - { - m_mtlFlags |= MTL_FLAG_NOPREVIEW; - } - else - { - m_mtlFlags &= ~MTL_FLAG_NOPREVIEW; - } - - ////////////////////////////////////////////////////////////////////////// - // Reget shader parms. - ////////////////////////////////////////////////////////////////////////// - if (m_bRegetPublicParams) - { - if (m_bKeepPublicParamsValues) - { - m_bKeepPublicParamsValues = false; - m_publicVarsCache = XmlHelpers::CreateXmlNode("PublicParams"); - - MaterialHelpers::SetXmlFromShaderParams(m_shaderResources, m_publicVarsCache); - } - - m_shaderResources.m_ShaderParams = pShader->GetPublicParams(); - m_bRegetPublicParams = false; - } - - ////////////////////////////////////////////////////////////////////////// - // If we have XML node with public parameters loaded, apply it on shader parms. - ////////////////////////////////////////////////////////////////////////// - if (m_publicVarsCache) - { - MaterialHelpers::SetShaderParamsFromXml(m_shaderResources, m_publicVarsCache); - GetIEditor()->GetMaterialManager()->OnUpdateProperties(this, false); - m_publicVarsCache = 0; - } - - ////////////////////////////////////////////////////////////////////////// - // Set shader parms. - if (m_shaderItem.m_pShaderResources) - { - m_shaderItem.m_pShaderResources->SetShaderParams(&m_shaderResources, m_shaderItem.m_pShader); - } - ////////////////////////////////////////////////////////////////////////// - - gEnv->pRenderer->UpdateShaderItem(&m_shaderItem, nullptr); - - ////////////////////////////////////////////////////////////////////////// - // Set Shader Params for material layers - ////////////////////////////////////////////////////////////////////////// - if (m_pMatInfo) - { - UpdateMatInfo(); - } - - GetIEditor()->GetMaterialManager()->OnLoadShader(this); - GetIEditor()->GetErrorReport()->SetCurrentValidatorItem(NULL); - - return true; -} - -bool CMaterial::LoadMaterialLayers() -{ - if (!m_pMatInfo) - { - return false; - } - - if (m_shaderItem.m_pShader && m_shaderItem.m_pShaderResources) - { - // mask generation for base material shader - uint32 nMaskGenBase = m_shaderItem.m_pShader->GetGenerationMask(); - SShaderGen* pShaderGenBase = m_shaderItem.m_pShader->GetGenerationParams(); - - for (uint32 l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - SMaterialLayerResources* pCurrLayer = &m_pMtlLayerResources[l]; - pCurrLayer->m_nFlags |= MTL_FLAG_NODRAW; - if (!pCurrLayer->m_shaderName.isEmpty()) - { - if (QString::compare(pCurrLayer->m_shaderName, "nodraw", Qt::CaseInsensitive) == 0) - { - // no shader = skip layer - pCurrLayer->m_shaderName.clear(); - continue; - } - - IShader* pNewShader = GetIEditor()->GetRenderer()->EF_LoadShader(pCurrLayer->m_shaderName.toUtf8().data(), 0); - - // Check if shader loaded - if (!pNewShader || (pNewShader->GetFlags() & EF_NOTFOUND) != 0) - { - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "Failed to load material layer shader \"%s\" in material \"%s\"", pCurrLayer->m_shaderName.toUtf8().constData(), m_pMatInfo->GetName()); - if (!pNewShader) - { - continue; - } - } - - if (!pCurrLayer->m_pMatLayer) - { - pCurrLayer->m_pMatLayer = m_pMatInfo->CreateLayer(); - } - - // mask generation for base material shader - uint64 nMaskGenLayer = 0; - SShaderGen* pShaderGenLayer = pNewShader->GetGenerationParams(); - if (pShaderGenBase && pShaderGenLayer) - { - for (int nLayerBit(0); nLayerBit < pShaderGenLayer->m_BitMask.size(); ++nLayerBit) - { - SShaderGenBit* pLayerBit = pShaderGenLayer->m_BitMask[nLayerBit]; - - for (int nBaseBit(0); nBaseBit < pShaderGenBase->m_BitMask.size(); ++nBaseBit) - { - SShaderGenBit* pBaseBit = pShaderGenBase->m_BitMask[nBaseBit]; - - // Need to check if flag name is common to both shaders (since flags values can be different), if so activate it on this layer - if (nMaskGenBase & pBaseBit->m_Mask) - { - if (!pLayerBit->m_ParamName.empty() && !pBaseBit->m_ParamName.empty()) - { - if (pLayerBit->m_ParamName == pBaseBit->m_ParamName) - { - nMaskGenLayer |= pLayerBit->m_Mask; - break; - } - } - } - } - } - } - - // Reload with proper flags - SShaderItem newShaderItem = GetIEditor()->GetRenderer()->EF_LoadShaderItem(pCurrLayer->m_shaderName.toUtf8().data(), false, 0, &pCurrLayer->m_shaderResources, nMaskGenLayer); - if (!newShaderItem.m_pShader || (newShaderItem.m_pShader->GetFlags() & EF_NOTFOUND) != 0) - { - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "Failed to load material layer shader \"%s\" in material \"%s\"", pCurrLayer->m_shaderName.toUtf8().data(), m_pMatInfo->GetName()); - if (!newShaderItem.m_pShader) - { - continue; - } - } - - SShaderItem& pCurrShaderItem = pCurrLayer->m_pMatLayer->GetShaderItem(); - - if (newShaderItem.m_pShader) - { - newShaderItem.m_pShader->AddRef(); - } - - // Release previously used shader (Must be After new shader is loaded, for speed). - SAFE_RELEASE(pCurrShaderItem.m_pShader); - SAFE_RELEASE(pCurrShaderItem.m_pShaderResources); - SAFE_RELEASE(newShaderItem.m_pShaderResources); - - pCurrShaderItem.m_pShader = newShaderItem.m_pShader; - // Copy resources from base material - pCurrShaderItem.m_pShaderResources = m_shaderItem.m_pShaderResources->Clone(); - pCurrShaderItem.m_nTechnique = newShaderItem.m_nTechnique; - pCurrShaderItem.m_nPreprocessFlags = newShaderItem.m_nPreprocessFlags; - - // set default params - if (pCurrLayer->m_bRegetPublicParams) - { - pCurrLayer->m_shaderResources.m_ShaderParams = pCurrShaderItem.m_pShader->GetPublicParams(); - } - - pCurrLayer->m_bRegetPublicParams = false; - - if (pCurrLayer->m_publicVarsCache) - { - MaterialHelpers::SetShaderParamsFromXml(pCurrLayer->m_shaderResources, pCurrLayer->m_publicVarsCache); - pCurrLayer->m_publicVarsCache = 0; - } - - if (pCurrShaderItem.m_pShaderResources) - { - pCurrShaderItem.m_pShaderResources->SetShaderParams(&pCurrLayer->m_shaderResources, pCurrShaderItem.m_pShader); - } - - // Activate layer - pCurrLayer->m_nFlags &= ~MTL_FLAG_NODRAW; - } - } - - return true; - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// - -void CMaterial::UpdateMaterialLayers() -{ - if (m_pMatInfo && m_shaderItem.m_pShaderResources) - { - m_pMatInfo->SetLayerCount(MTL_LAYER_MAX_SLOTS); - - uint8 nMaterialLayerFlags = 0; - - for (int l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - SMaterialLayerResources* pCurrLayer = &m_pMtlLayerResources[l]; - if (pCurrLayer && !pCurrLayer->m_shaderName.isEmpty() && pCurrLayer->m_pMatLayer) - { - pCurrLayer->m_pMatLayer->SetFlags(pCurrLayer->m_nFlags); - m_pMatInfo->SetLayer(l, pCurrLayer->m_pMatLayer); - - if ((pCurrLayer->m_nFlags & MTL_LAYER_USAGE_NODRAW)) - { - if (!QString::compare(pCurrLayer->m_shaderName, "frozenlayerwip", Qt::CaseInsensitive)) - { - nMaterialLayerFlags |= MTL_LAYER_FROZEN; - } - } - } - } - - if (m_shaderItem.m_pShaderResources) - { - m_shaderItem.m_pShaderResources->SetMtlLayerNoDrawFlags(nMaterialLayerFlags); - } - } -} - -void CMaterial::UpdateMatInfo() -{ - if (m_pMatInfo) - { - // Mark material invalid. - m_pMatInfo->SetFlags(m_mtlFlags); - m_pMatInfo->SetShaderItem(m_shaderItem); - m_pMatInfo->SetShaderName(m_shaderName.toUtf8().constData()); - m_pMatInfo->SetSurfaceType(m_surfaceType.toUtf8().constData()); - - LoadMaterialLayers(); - UpdateMaterialLayers(); - - m_pMatInfo->SetMaterialLinkName(m_linkedMaterial.toUtf8().data()); - - if (IsMultiSubMaterial()) - { - m_pMatInfo->SetSubMtlCount(m_subMaterials.size()); - for (unsigned int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_pMatInfo->SetSubMtl(i, m_subMaterials[i]->GetMatInfo()); - } - else - { - m_pMatInfo->SetSubMtl(i, NULL); - } - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -CVarBlock* CMaterial::GetPublicVars(SInputShaderResources& pShaderResources) -{ - return MaterialHelpers::GetPublicVars(pShaderResources); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetShaderParamPublicScript() -{ - IShader* pShader = m_shaderItem.m_pShader; - - if (!pShader) - { - return; - } - - if (m_shaderResources.m_ShaderParams.size() == 0 || pShader->GetPublicParams().size() == 0) - { - return; - } - - // We want to inspect public shader param and paste the m_script into our shader resource param script - for (int i = 0; i < m_shaderResources.m_ShaderParams.size(); ++i) - { - SShaderParam ¤tShaderParam = m_shaderResources.m_ShaderParams.at(i); - for (int j = 0; j < pShader->GetPublicParams().size(); ++j) - { - const SShaderParam &publicShaderParam = pShader->GetPublicParams().at(j); - if ((currentShaderParam.m_Name == publicShaderParam.m_Name) && (currentShaderParam.m_Type == publicShaderParam.m_Type)) - { - currentShaderParam.m_Script = publicShaderParam.m_Script; - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetPublicVars(CVarBlock* pPublicVars, CMaterial* pMtl) -{ - if (!pMtl->GetShaderResources().m_ShaderParams.empty()) - { - RecordUndo("Set Public Vars"); - } - - MaterialHelpers::SetPublicVars(pPublicVars, pMtl->GetShaderResources(), pMtl->GetShaderItem().m_pShaderResources, pMtl->GetShaderItem().m_pShader); - - GetIEditor()->GetMaterialManager()->OnUpdateProperties(this, false); -} - -////////////////////////////////////////////////////////////////////////// -CVarBlock* CMaterial::GetShaderGenParamsVars() -{ - return MaterialHelpers::GetShaderGenParamsVars(GetShaderItem().m_pShader, m_nShaderGenMask); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetShaderGenParamsVars(CVarBlock* pBlock) -{ - RecordUndo("Change Shader GenMask"); - - uint64 nGenMask = MaterialHelpers::SetShaderGenParamsVars(GetShaderItem().m_pShader, pBlock); - if (m_nShaderGenMask != nGenMask) - { - m_bRegetPublicParams = true; - m_bKeepPublicParamsValues = true; - m_nShaderGenMask = nGenMask; - } -} - -////////////////////////////////////////////////////////////////////////// -unsigned int CMaterial::GetTexmapUsageMask() const -{ - int mask = 0; - if (m_shaderItem.m_pShader) - { - IShader* pTempl = m_shaderItem.m_pShader; - if (pTempl) - { - mask = pTempl->GetUsedTextureTypes(); - } - } - return mask; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::Update() -{ - // Reload shader item with new resources and shader. - LoadShader(); - - // Mark library as modified. - SetModified(); - - GetIEditor()->SetModifiedFlag(); - - // When modifying pure child, mark his parent as modified. - if (IsPureChild() && m_pParent) - { - m_pParent->SetModified(); - } -} - -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -void CMaterial::Serialize(SerializeContext& ctx) -{ - //CBaseLibraryItem::Serialize( ctx ); - - XmlNodeRef node = ctx.node; - if (ctx.bLoading) - { - m_bIgnoreNotifyChange = true; - m_bRegetPublicParams = true; - - SInputShaderResources& sr = m_shaderResources; - m_shaderResources = defaultShaderResource; - - // Loading - int flags = m_mtlFlags; - if (node->getAttr("MtlFlags", flags)) - { - m_mtlFlags &= ~(MTL_FLAGS_SAVE_MASK); - m_mtlFlags |= (flags & (MTL_FLAGS_SAVE_MASK)); - } - - uint32 dccMaterialHash = 0; - node->getAttr("DccMaterialHash", dccMaterialHash); - SetDccMaterialHash(dccMaterialHash); - - if (!IsMultiSubMaterial()) - { - node->getAttr("Shader", m_shaderName); - node->getAttr("GenMask", m_nShaderGenMask); - - if (!(m_mtlFlags & MTL_64BIT_SHADERGENMASK)) - { - uint32 nShaderGenMask = 0; - node->getAttr("GenMask", nShaderGenMask); - m_nShaderGenMask = nShaderGenMask; - } - else - { - node->getAttr("GenMask", m_nShaderGenMask); - } - - // Remap flags if needed - if (!(m_mtlFlags & MTL_64BIT_SHADERGENMASK)) - { - m_nShaderGenMask = GetIEditor()->GetRenderer()->EF_GetRemapedShaderMaskGen(m_shaderName.toUtf8().data(), m_nShaderGenMask); - m_mtlFlags |= MTL_64BIT_SHADERGENMASK; - } - - if (node->getAttr("StringGenMask", m_pszShaderGenMask)) - { - m_nShaderGenMask = GetIEditor()->GetRenderer()->EF_GetShaderGlobalMaskGenFromString(m_shaderName.toUtf8().data(), m_pszShaderGenMask.toUtf8().data(), m_nShaderGenMask); // get common mask gen - } - else - { - // version doens't has string gen mask yet ? Remap flags if needed - m_nShaderGenMask = GetIEditor()->GetRenderer()->EF_GetRemapedShaderMaskGen(m_shaderName.toUtf8().data(), m_nShaderGenMask, ((m_mtlFlags & MTL_64BIT_SHADERGENMASK) != 0)); - } - m_mtlFlags |= MTL_64BIT_SHADERGENMASK; - - node->getAttr("SurfaceType", m_surfaceType); - node->getAttr("LayerAct", m_allowLayerActivation); - - MaterialHelpers::SetLightingFromXml(sr, node); - - MaterialHelpers::SetTexturesFromXml(sr, node); - MaterialHelpers::MigrateXmlLegacyData(sr, node); - } - - ////////////////////////////////////////////////////////////////////////// - // Check if we have a link name and if any propagation settings were - // present - ////////////////////////////////////////////////////////////////////////// - XmlNodeRef pLinkName = node->findChild("MaterialLinkName"); - if (pLinkName) - { - m_linkedMaterial = pLinkName->getAttr("name"); - } - else - { - m_linkedMaterial = QString(); - } - - XmlNodeRef pPropagationFlags = node->findChild("MaterialPropagationFlags"); - if (pPropagationFlags) - { - pPropagationFlags->getAttr("flags", m_propagationFlags); - } - else - { - m_propagationFlags = 0; - } - - ////////////////////////////////////////////////////////////////////////// - // Check if we have vertex deform. - ////////////////////////////////////////////////////////////////////////// - MaterialHelpers::SetVertexDeformFromXml(m_shaderResources, node); - - // Serialize sub materials. - - const auto ResizeSubMaterials = [this](size_t count) - { - for (size_t i = count; i < m_subMaterials.size(); ++i) - { - if (auto& pSubMtl = m_subMaterials[i]) - { - pSubMtl->m_pParent = nullptr; - } - } - m_subMaterials.resize(count); - }; - - XmlNodeRef childsNode = node->findChild("SubMaterials"); - if (childsNode && !ctx.bIgnoreChilds) - { - QString name; - int nSubMtls = childsNode->getChildCount(); - ResizeSubMaterials(nSubMtls); - for (int i = 0; i < nSubMtls; i++) - { - auto& pSubMtl = m_subMaterials[i]; - XmlNodeRef mtlNode = childsNode->getChild(i); - if (mtlNode->isTag("Material")) - { - mtlNode->getAttr("Name", name); - if (pSubMtl && pSubMtl->IsPureChild()) - { - pSubMtl->SetName(name); - } - else - { - if (pSubMtl) - { - pSubMtl->m_pParent = nullptr; - } - - pSubMtl = new CMaterial(name, MTL_FLAG_PURE_CHILD); - pSubMtl->m_pParent = this; - } - - SerializeContext childCtx(ctx); - childCtx.node = mtlNode; - pSubMtl->Serialize(childCtx); - - pSubMtl->m_shaderResources.m_SortPrio = nSubMtls - i - 1; - } - else - { - if (pSubMtl) - { - pSubMtl->m_pParent = nullptr; - pSubMtl = nullptr; - } - - if (mtlNode->getAttr("Name", name)) - { - CMaterial* pMtl = GetIEditor()->GetMaterialManager()->LoadMaterial(name); - if (pMtl && !pMtl->IsMultiSubMaterial()) - { - pSubMtl = pMtl; - } - } - } - } - - m_subMaterials.erase(std::remove(m_subMaterials.begin(), m_subMaterials.end(), nullptr), m_subMaterials.end()); - } - else - { - ResizeSubMaterials(0); - } - - UpdateMatInfo(); - - ////////////////////////////////////////////////////////////////////////// - // Load public parameters. - ////////////////////////////////////////////////////////////////////////// - m_publicVarsCache = node->findChild("PublicParams"); - - ////////////////////////////////////////////////////////////////////////// - // Load material layers data - ////////////////////////////////////////////////////////////////////////// - XmlNodeRef mtlLayersNode = node->findChild("MaterialLayers"); - if (mtlLayersNode) - { - int nChildCount = min((int) MTL_LAYER_MAX_SLOTS, (int) mtlLayersNode->getChildCount()); - for (int l = 0; l < nChildCount; ++l) - { - XmlNodeRef layerNode = mtlLayersNode->getChild(l); - if (layerNode) - { - if (layerNode->getAttr("Name", m_pMtlLayerResources[l].m_shaderName)) - { - m_pMtlLayerResources[l].m_bRegetPublicParams = true; - - bool bNoDraw = false; - layerNode->getAttr("NoDraw", bNoDraw); - - m_pMtlLayerResources[l].m_publicVarsCache = layerNode->findChild("PublicParams"); - - if (bNoDraw) - { - m_pMtlLayerResources[l].m_nFlags |= MTL_LAYER_USAGE_NODRAW; - } - else - { - m_pMtlLayerResources[l].m_nFlags &= ~MTL_LAYER_USAGE_NODRAW; - } - - - bool bFadeOut = false; - layerNode->getAttr("FadeOut", bFadeOut); - if (bFadeOut) - { - m_pMtlLayerResources[l].m_nFlags |= MTL_LAYER_USAGE_FADEOUT; - } - else - { - m_pMtlLayerResources[l].m_nFlags &= ~MTL_LAYER_USAGE_FADEOUT; - } - } - } - } - } - - if (ctx.bUndo) - { - LoadShader(); - UpdateMatInfo(); - } - - m_bIgnoreNotifyChange = false; - - // If copy pasting or undo send update event. - if (ctx.bCopyPaste || ctx.bUndo) - { - NotifyChanged(); - } - - // NotifyChanged calls SetModified but since we just loaded it, its not actually changed. - SetModified(false); - } - else // If !ctx.bLoading - { - int extFlags = MTL_64BIT_SHADERGENMASK; - { - const QString& name = GetName(); - const size_t len = name.length(); - if (len > 4 && strstri(name.toUtf8().data() + (len - 4), "_con")) - { - extFlags |= MTL_FLAG_CONSOLE_MAT; - } - } - - // Saving. - node->setAttr("MtlFlags", m_mtlFlags | extFlags); - node->setAttr("DccMaterialHash", GetDccMaterialHash()); - - if (!IsMultiSubMaterial()) - { - // store shader gen bit mask string - m_pszShaderGenMask = GetIEditor()->GetRenderer()->EF_GetStringFromShaderGlobalMaskGen(m_shaderName.toUtf8().data(), m_nShaderGenMask).c_str(); - - node->setAttr("Shader", m_shaderName.toUtf8().data()); - node->setAttr("GenMask", m_nShaderGenMask); - node->setAttr("StringGenMask", m_pszShaderGenMask.toUtf8().data()); - node->setAttr("SurfaceType", m_surfaceType.toUtf8().data()); - - //if (!m_shaderName.IsEmpty() && (stricmp(m_shaderName,"nodraw") != 0)) - { - MaterialHelpers::SetXmlFromLighting(m_shaderResources, node); - MaterialHelpers::SetXmlFromTextures(m_shaderResources, node); - } - } - - ////////////////////////////////////////////////////////////////////////// - // Save out the link name if present and the propagation flags - ////////////////////////////////////////////////////////////////////////// - if (!m_linkedMaterial.isEmpty()) - { - XmlNodeRef pLinkName = node->newChild("MaterialLinkName"); - pLinkName->setAttr("name", m_linkedMaterial.toUtf8().data()); - } - - if (m_propagationFlags) - { - XmlNodeRef pPropagationFlags = node->newChild("MaterialPropagationFlags"); - pPropagationFlags->setAttr("flags", m_propagationFlags); - } - - ////////////////////////////////////////////////////////////////////////// - // Check if we have vertex deform. - ////////////////////////////////////////////////////////////////////////// - MaterialHelpers::SetXmlFromVertexDeform(m_shaderResources, node); - - if (GetSubMaterialCount() > 0) - { - // Serialize sub materials. - - // Let's not serialize empty submaterials at the end of the list. - // Note that IDs of the remaining submaterials stay intact. - int count = GetSubMaterialCount(); - while (count > 0 && !GetSubMaterial(count - 1)) - { - --count; - } - - XmlNodeRef childsNode = node->newChild("SubMaterials"); - - for (int i = 0; i < count; ++i) - { - CMaterial* const pSubMtl = GetSubMaterial(i); - if (pSubMtl && pSubMtl->IsPureChild()) - { - XmlNodeRef mtlNode = childsNode->newChild("Material"); - mtlNode->setAttr("Name", pSubMtl->GetName().toUtf8().data()); - SerializeContext childCtx(ctx); - childCtx.node = mtlNode; - pSubMtl->Serialize(childCtx); - } - else - { - XmlNodeRef mtlNode = childsNode->newChild("MaterialRef"); - if (pSubMtl) - { - mtlNode->setAttr("Name", pSubMtl->GetName().toUtf8().data()); - } - } - } - } - - ////////////////////////////////////////////////////////////////////////// - // Save public parameters. - ////////////////////////////////////////////////////////////////////////// - if (m_publicVarsCache) - { - node->addChild(m_publicVarsCache); - } - else if (!m_shaderResources.m_ShaderParams.empty()) - { - XmlNodeRef publicsNode = node->newChild("PublicParams"); - MaterialHelpers::SetXmlFromShaderParams(m_shaderResources, publicsNode); - } - - ////////////////////////////////////////////////////////////////////////// - // Save material layers data - ////////////////////////////////////////////////////////////////////////// - - bool bMaterialLayers = false; - for (int l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - if (!m_pMtlLayerResources[l].m_shaderName.isEmpty()) - { - bMaterialLayers = true; - break; - } - } - - if (bMaterialLayers) - { - XmlNodeRef mtlLayersNode = node->newChild("MaterialLayers"); - for (int l(0); l < MTL_LAYER_MAX_SLOTS; ++l) - { - XmlNodeRef layerNode = mtlLayersNode->newChild("Layer"); - if (!m_pMtlLayerResources[l].m_shaderName.isEmpty()) - { - layerNode->setAttr("Name", m_pMtlLayerResources[l].m_shaderName.toUtf8().data()); - layerNode->setAttr("NoDraw", m_pMtlLayerResources[l].m_nFlags & MTL_LAYER_USAGE_NODRAW); - layerNode->setAttr("FadeOut", m_pMtlLayerResources[l].m_nFlags & MTL_LAYER_USAGE_FADEOUT); - - if (m_pMtlLayerResources[l].m_publicVarsCache) - { - layerNode->addChild(m_pMtlLayerResources[l].m_publicVarsCache); - } - else if (!m_pMtlLayerResources[l].m_shaderResources.m_ShaderParams.empty()) - { - XmlNodeRef publicsNode = layerNode->newChild("PublicParams"); - MaterialHelpers::SetXmlFromShaderParams(m_pMtlLayerResources[l].m_shaderResources, publicsNode); - } - } - } - } - - if (GetSubMaterialCount() == 0 || GetParent()) - { - node->setAttr("LayerAct", m_allowLayerActivation); - } - } -} - -/* -////////////////////////////////////////////////////////////////////////// -void CMaterial::SerializePublics( XmlNodeRef &node,bool bLoading ) -{ -if (bLoading) -{ -} -else -{ -if (m_shaderParams.empty()) -return; -XmlNodeRef publicsNode = node->newChild( "PublicParams" ); - -for (int i = 0; i < m_shaderParams.size(); i++) -{ -XmlNodeRef paramNode = node->newChild( "Param" ); -SShaderParam *pParam = &m_shaderParams[i]; -paramNode->setAttr( "Name",pParam->m_Name ); -switch (pParam->m_Type) -{ -case eType_BYTE: -paramNode->setAttr( "Value",(int)pParam->m_Value.m_Byte ); -paramNode->setAttr( "Type",(int)pParam->m_Value.m_Byte ); -break; -case eType_SHORT: -paramNode->setAttr( "Value",(int)pParam->m_Value.m_Short ); -break; -case eType_INT: -paramNode->setAttr( "Value",(int)pParam->m_Value.m_Int ); -break; -case eType_FLOAT: -paramNode->setAttr( "Value",pParam->m_Value.m_Float ); -break; -case eType_STRING: -paramNode->setAttr( "Value",pParam->m_Value.m_String ); -break; -case eType_FCOLOR: -paramNode->setAttr( "Value",Vec3(pParam->m_Value.m_Color[0],pParam->m_Value.m_Color[1],pParam->m_Value.m_Color[2]) ); -break; -case eType_VECTOR: -paramNode->setAttr( "Value",Vec3(pParam->m_Value.m_Vector[0],pParam->m_Value.m_Vector[1],pParam->m_Value.m_Vector[2]) ); -break; -} -} -} -} -*/ - -////////////////////////////////////////////////////////////////////////// -void CMaterial::AssignToEntity(IRenderNode* pEntity) -{ - assert(pEntity); - pEntity->SetMaterial(GetMatInfo()); -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::IsBreakable2D() const -{ - if ((GetFlags() & MTL_FLAG_NODRAW) != 0) - { - return false; - } - - const QString& surfaceTypeName = GetSurfaceTypeName(); - if (ISurfaceTypeManager* pSurfaceManager = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetSurfaceTypeManager()) - { - ISurfaceType* pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(surfaceTypeName.toUtf8().data()); - if (pSurfaceType && pSurfaceType->GetBreakable2DParams() != 0) - { - return true; - } - } - - int count = GetSubMaterialCount(); - for (int i = 0; i < count; ++i) - { - const CMaterial* pSub = GetSubMaterial(i); - if (!pSub) - { - continue; - } - if (pSub->IsBreakable2D()) - { - return true; - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetFromMatInfo(_smart_ptr pMatInfo) -{ - assert(pMatInfo); - - m_shaderName = ""; - - ClearMatInfo(); - SetModified(true); - - m_mtlFlags = pMatInfo->GetFlags(); - if (m_mtlFlags & MTL_FLAG_MULTI_SUBMTL) - { - // Create sub materials. - SetSubMaterialCount(pMatInfo->GetSubMtlCount()); - for (int i = 0; i < GetSubMaterialCount(); i++) - { - _smart_ptr pChildMatInfo = pMatInfo->GetSubMtl(i); - if (!pChildMatInfo) - { - continue; - } - - if (pChildMatInfo->GetFlags() & MTL_FLAG_PURE_CHILD) - { - CMaterial* existingChild = GetSubMaterial(i); - if (existingChild) - { - existingChild->SetFromMatInfo(pChildMatInfo); - } - else - { - CMaterial* pChild = new CMaterial(pChildMatInfo->GetName(), pChildMatInfo->GetFlags()); - pChild->SetFromMatInfo(pChildMatInfo); - SetSubMaterial(i, pChild); - } - } - else - { - CMaterial* pChild = GetIEditor()->GetMaterialManager()->LoadMaterial(pChildMatInfo->GetName()); - pChild->SetFromMatInfo(pChildMatInfo); - SetSubMaterial(i, pChild); - } - } - } - else - { - SetShaderItem(pMatInfo->GetShaderItem()); - - if (m_shaderItem.m_pShaderResources) - { - m_shaderResources = SInputShaderResources(m_shaderItem.m_pShaderResources); - } - if (m_shaderItem.m_pShader) - { - // Get name of template. - IShader* pTemplShader = m_shaderItem.m_pShader; - if (pTemplShader) - { - m_nShaderGenMask = pTemplShader->GetGenerationMask(); - } - } - m_shaderName = pMatInfo->GetShaderName(); - ISurfaceType* pSurfaceType = pMatInfo->GetSurfaceType(); - if (pSurfaceType) - { - m_surfaceType = pSurfaceType->GetName(); - } - else - { - m_surfaceType = ""; - } - } - - // Mark as not modified. - SetModified(false); - - // Material link names - if (const char* szLinkName = pMatInfo->GetMaterialLinkName()) - { - m_linkedMaterial = szLinkName; - } - - ////////////////////////////////////////////////////////////////////////// - // Assign mat info. - m_pMatInfo = pMatInfo; - m_pMatInfo->SetUserData(this); - AddRef(); // Let IMaterial keep a reference to us. -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::GetSubMaterialCount() const -{ - return m_subMaterials.size(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetSubMaterialCount(int nSubMtlsCount) -{ - RecordUndo("Multi Material Change"); - m_subMaterials.resize(nSubMtlsCount); - UpdateMatInfo(); - NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterial::GetSubMaterial(int index) const -{ - const int nSubMats = m_subMaterials.size(); - assert(index >= 0 && index < nSubMats); - - if (index < 0 || index >= nSubMats) - { - return NULL; - } - - return m_subMaterials[index]; -} - -////////////////////////////////////////////////////////////////////////// -int CMaterial::FindMaterialIndex(const QString& name) -{ - for (int i = 0; i < m_subMaterials.size(); ++i) - { - if (m_subMaterials[i]->GetName().compare(name) == 0) - { - return i; - } - } - - return -1; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetSubMaterial(int nSlot, CMaterial* mtl) -{ - RecordUndo("Multi Material Change"); - assert(nSlot >= 0 && nSlot < m_subMaterials.size()); - if (mtl) - { - if (mtl->IsMultiSubMaterial()) - { - return; - } - if (mtl->IsPureChild()) - { - mtl->m_pParent = this; - } - } - - if (m_subMaterials[nSlot]) - { - m_subMaterials[nSlot]->m_pParent = NULL; - } - m_subMaterials[nSlot] = mtl; - - if (!m_subMaterials[nSlot]) - { - m_subMaterials.erase(m_subMaterials.begin() + nSlot); - } - - UpdateMatInfo(); - NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -// This method will populate for the material editor the name and tool tip of the -// different textures of the current material -//CVarBlock* CMaterial::UpdateTextureNames(AZStd::unordered_map& textureVarsMap) -CVarBlock* CMaterial::UpdateTextureNames(CSmartVariableArray textureVars[EFTT_MAX]) -{ - CVarBlock* pTextureSlots = new CVarBlock; - IShader* pTemplShader = m_shaderItem.m_pShader; - int nTech = max(0, m_shaderItem.m_nTechnique); - SShaderTexSlots* pShaderSlots = pTemplShader ? pTemplShader->GetUsedTextureSlots(nTech) : nullptr; - - for (EEfResTextures nTexSlot = EEfResTextures(0); nTexSlot < EFTT_MAX; nTexSlot = EEfResTextures(nTexSlot + 1)) - { - if (!MaterialHelpers::IsAdjustableTexSlot((EEfResTextures)nTexSlot)) - { // do not take into account virtual slots (such as smoothness - normal's alpha) - // in theory this case should not happen as it is filtered from the source list. - continue; - } - - IVariable* pVar = textureVars[nTexSlot].GetVar(); - SShaderTextureSlot* pSlot = pShaderSlots ? pShaderSlots->m_UsedTextureSlots[nTexSlot] : nullptr; - - // If slot is NULL, fall back to default name - name here is the context name (i.e. diffuse, normal..) - // and not the actual texture file name - pVar->SetName(pSlot && pSlot->m_Name.length() ? pSlot->m_Name.c_str() : MaterialHelpers::LookupTexName((EEfResTextures) nTexSlot)); - pVar->SetDescription(pSlot && pSlot->m_Description.length() ? pSlot->m_Description.c_str() : MaterialHelpers::LookupTexDesc((EEfResTextures)nTexSlot)); - - int flags = pVar->GetFlags(); - - // TODO: slot->m_TexType gives expected sampler type (2D vs Cube etc). Could check/extract this here. - - // Not sure why this needs COLLAPSED added again, but without this all the slots expand - flags |= IVariable::UI_COLLAPSED; - - //clear the auto-expand flag if there is no texture assigned. - SEfResTexture* pTextureRes = m_shaderResources.GetTextureResource(nTexSlot); - bool noTextureName = (!pTextureRes ? true : pTextureRes->m_Name.empty()); - - if (noTextureName) - { - flags &= ~IVariable::UI_AUTO_EXPAND; - } - - // if slot is NULL, but we have reflection information, this slot isn't used - make the variable invisible - // unless there's a texture in the slot - if (pShaderSlots && !pSlot && noTextureName) - { - flags |= IVariable::UI_INVISIBLE; - } - else - { - flags &= ~IVariable::UI_INVISIBLE; - } - - pVar->SetFlags(flags); - - pTextureSlots->AddVariable(pVar); - } - - return pTextureSlots; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::ClearAllSubMaterials() -{ - RecordUndo("Multi Material Change"); - for (int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_subMaterials[i]->m_pParent = NULL; - m_subMaterials[i] = NULL; - } - } - UpdateMatInfo(); - NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::Validate() -{ - if (IsDummy()) - { - CErrorRecord err; - err.error = QObject::tr("Material %1 file not found").arg(GetName()); - err.pItem = this; - GetIEditor()->GetErrorReport()->ReportError(err); - } - // Reload shader. - LoadShader(); - - // Validate sub materials. - for (int i = 0; i < m_subMaterials.size(); i++) - { - if (m_subMaterials[i]) - { - m_subMaterials[i]->Validate(); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::GatherUsedResources(CUsedResources& resources) -{ - if (!IsUsed()) - { - return; - } - - SInputShaderResources& sr = GetShaderResources(); - for (auto iter = sr.m_TexturesResourcesMap.begin(); iter != sr.m_TexturesResourcesMap.end(); ++iter) - { - SEfResTexture* pTexture = &iter->second; - if (!pTexture->m_Name.empty()) - { - resources.Add(pTexture->m_Name.c_str()); - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::CanModify(bool bSkipReadOnly) -{ - if (m_bDummyMaterial) - { - return false; - } - - if (IsPureChild() && GetParent()) - { - return GetParent()->CanModify(bSkipReadOnly); - } - - if (bSkipReadOnly) - { - // If read only or in pack, do not save. - if (m_scFileAttributes & (SCC_FILE_ATTRIBUTE_READONLY | SCC_FILE_ATTRIBUTE_INPAK)) - { - return false; - } - - // Managed file must be checked out. - if ((m_scFileAttributes & SCC_FILE_ATTRIBUTE_MANAGED) && !(m_scFileAttributes & SCC_FILE_ATTRIBUTE_CHECKEDOUT)) - { - return false; - } - } - else - { - // Only if in pack. - if (m_scFileAttributes & (SCC_FILE_ATTRIBUTE_INPAK)) - { - return false; - } - } - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterial::Save(bool bSkipReadOnly, const QString& fullPath) -{ - // Save our parent - if (IsPureChild()) - { - if (m_pParent) - { - return m_pParent->Save(bSkipReadOnly); - } - return false; - } - - if (m_mtlFlags & MTL_FLAG_UIMATERIAL) - { - return false; - } - - GetFileAttributes(); - - if (bSkipReadOnly && IsModified()) - { - // If read only or in pack, do not save. - if (m_scFileAttributes & (SCC_FILE_ATTRIBUTE_READONLY | SCC_FILE_ATTRIBUTE_INPAK)) - { - gEnv->pLog->LogError("Can't save material %s (read-only)", GetName().toUtf8().constData()); - } - - // Managed file must be checked out. - if ((m_scFileAttributes & SCC_FILE_ATTRIBUTE_MANAGED) && !(m_scFileAttributes & SCC_FILE_ATTRIBUTE_CHECKEDOUT)) - { - gEnv->pLog->LogError("Can't save material %s (need to check out)", GetName().toUtf8().constData()); - } - } - - if (!CanModify(bSkipReadOnly)) - { - return false; - } - - - // If filename is empty do not not save. - if (GetFilename().isEmpty()) - { - return false; - } - - // Save material XML to a file that corresponds to the material name with extension .mtl. - XmlNodeRef mtlNode = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(mtlNode, false); - Serialize(ctx); - - bool saveSucceeded = false; - if (fullPath.isEmpty()) - { - // If no filepath was specified, get the filename using the relative path/unique identifier of this material - saveSucceeded = XmlHelpers::SaveXmlNode(GetIEditor()->GetFileUtil(), mtlNode, GetFilename().toUtf8().data()); - } - else - { - // If a filepath was specified, save to the specified location - saveSucceeded = XmlHelpers::SaveXmlNode(GetIEditor()->GetFileUtil(), mtlNode, fullPath.toUtf8().data()); - } - - if (saveSucceeded) - { - // If material successfully saved, clear modified flag. - SetModified(false); - for (int i = 0; i < GetSubMaterialCount(); ++i) - { - CMaterial* pSubMaterial = GetSubMaterial(i); - if (pSubMaterial) - { - pSubMaterial->SetModified(false); - } - } - } - else - { - AZ_Warning("Material Editor", false, "Material '%s' failed to save successfully. Check that the file is writable and has been successfully checked out in source control.", m_name.toUtf8().data()); - } - - return saveSucceeded; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::ClearMatInfo() -{ - m_pMatInfo = nullptr; -} - -////////////////////////////////////////////////////////////////////////// -_smart_ptr CMaterial::GetMatInfo(bool bUseExistingEngineMaterial) -{ - if (!m_pMatInfo) - { - if (m_bDummyMaterial) - { - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetDefaultMaterial(); - AddRef(); // Always keep dummy materials. - return m_pMatInfo; - } - - if (!IsMultiSubMaterial() && !m_shaderItem.m_pShader) - { - LoadShader(); - } - - if (!IsPureChild()) - { - if (bUseExistingEngineMaterial) - { - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->FindMaterial(GetName().toUtf8().data()); - } - - if (!m_pMatInfo) - { - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->CreateMaterial(GetName().toUtf8().data(), m_mtlFlags); - } - } - else - { - // Pure child should not be registered with the name. - m_pMatInfo = GetIEditor()->Get3DEngine()->GetMaterialManager()->CreateMaterial("", m_mtlFlags); - m_pMatInfo->SetName(GetName().toUtf8().data()); - } - m_mtlFlags = m_pMatInfo->GetFlags(); - UpdateMatInfo(); - - if (m_pMatInfo->GetUserData() != this) - { - m_pMatInfo->SetUserData(this); - AddRef(); // Let IMaterial keep a reference to us. - } - } - - return m_pMatInfo; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::NotifyChanged() -{ - if (m_bIgnoreNotifyChange) - { - return; - } - - if (!CanModify() && !IsModified() && CUndo::IsRecording()) - { - // Display Warning message. - Warning("Modifying read only material %s\r\nChanges will not be saved!", GetName().toUtf8().data()); - } - - SetModified(); - - GetIEditor()->GetMaterialManager()->OnItemChanged(this); -} - -////////////////////////////////////////////////////////////////////////// -class CUndoMaterial - : public IUndoObject -{ -public: - CUndoMaterial(CMaterial* pMaterial, const char* undoDescription, bool bForceUpdate) - { - assert(pMaterial); - - // Stores the current state of this object. - m_undoDescription = undoDescription; - - m_bIsSubMaterial = pMaterial->IsPureChild(); - - if (m_bIsSubMaterial) - { - CMaterial* pParentMaterial = pMaterial->GetParent(); - assert(pParentMaterial && !pParentMaterial->IsPureChild()); - if (pParentMaterial && !pParentMaterial->IsPureChild()) - { - bool bFound = false; - const int subMaterialCount = pParentMaterial->GetSubMaterialCount(); - for (int i = 0; i < subMaterialCount; ++i) - { - CMaterial* pSubMaterial = pParentMaterial->GetSubMaterial(i); - if (pSubMaterial == pMaterial) - { - bFound = true; - m_subMaterialName = pSubMaterial->GetName(); - break; - } - } - assert(bFound); - m_mtlName = pParentMaterial->GetName(); - } - } - else - { - m_mtlName = pMaterial->GetName(); - } - - // Save material XML to a file that corresponds to the material name with extension .mtl. - m_undo = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(m_undo, false); - pMaterial->Serialize(ctx); - m_bForceUpdate = bForceUpdate; - } - -protected: - virtual void Release() { delete this; }; - - virtual int GetSize() - { - return sizeof(*this) + m_undoDescription.length() + m_mtlName.length(); - } - - virtual QString GetDescription() { return m_undoDescription; }; - - virtual void Undo(bool bUndo) - { - CMaterial* pMaterial = GetMaterial(); - - assert(pMaterial); - if (!pMaterial) - { - return; - } - - if (bUndo) - { - // Save current object state. - m_redo = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(m_redo, false); - pMaterial->Serialize(ctx); - } - - CBaseLibraryItem::SerializeContext ctx(m_undo, true); - ctx.bUndo = bUndo; - pMaterial->Serialize(ctx); - - if (m_bForceUpdate && bUndo) - { - GetIEditor()->GetMaterialManager()->OnUpdateProperties(pMaterial, true); - } - } - - virtual void Redo() - { - CMaterial* pMaterial = GetMaterial(); - - if (!pMaterial) - { - return; - } - - CBaseLibraryItem::SerializeContext ctx(m_redo, true); - ctx.bUndo = true; - pMaterial->Serialize(ctx); - - if (m_bForceUpdate) - { - GetIEditor()->GetMaterialManager()->OnUpdateProperties(pMaterial, true); - } - } - -private: - CMaterial* GetMaterial() - { - CMaterial* pMaterial = (CMaterial*)GetIEditor()->GetMaterialManager()->FindItemByName(m_mtlName); - assert(pMaterial); - - if (pMaterial && m_bIsSubMaterial) - { - bool bFound = false; - const int subMaterialCount = pMaterial->GetSubMaterialCount(); - for (int i = 0; i < subMaterialCount; ++i) - { - CMaterial* pSubMaterial = pMaterial->GetSubMaterial(i); - if (pSubMaterial && (pSubMaterial->GetName() == m_subMaterialName)) - { - bFound = true; - pMaterial = pSubMaterial; - break; - } - } - assert(bFound && pMaterial); - } - - return pMaterial; - } - - QString m_undoDescription; - QString m_mtlName; - bool m_bIsSubMaterial; - QString m_subMaterialName; - XmlNodeRef m_undo; - XmlNodeRef m_redo; - bool m_bForceUpdate; -}; - -////////////////////////////////////////////////////////////////////////// -void CMaterial::RecordUndo(const char* sText, bool bForceUpdate) -{ - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoMaterial(this, sText, bForceUpdate)); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::OnMakeCurrent() -{ - UpdateFileAttributes(false); - - // If Shader not yet loaded, load it now. - if (!m_shaderItem.m_pShader) - { - LoadShader(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetSurfaceTypeName(const QString& surfaceType) -{ - m_surfaceType = surfaceType; - UpdateMatInfo(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::Reload() -{ - if (IsPureChild()) - { - if (m_pParent) - { - m_pParent->Reload(); - } - return; - } - if (IsDummy()) - { - return; - } - - XmlNodeRef mtlNode = GetISystem()->LoadXmlFromFile(GetFilename().toUtf8().data()); - if (!mtlNode) - { - return; - } - CBaseLibraryItem::SerializeContext serCtx(mtlNode, true); - serCtx.bUndo = true; // Simulate undo. - Serialize(serCtx); - - // was called by Simulate undo. - //UpdateMatInfo(); - //NotifyChanged(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::LinkToMaterial(const QString& name) -{ - m_linkedMaterial = name; - UpdateMatInfo(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::DisableHighlightForFrame() -{ - SetHighlightFlags(0); -} - -static ColorF Interpolate(const ColorF& a, const ColorF& b, float phase) -{ - const float oneMinusPhase = 1.0f - phase; - return ColorF(b.r * phase + a.r * oneMinusPhase, - b.g * phase + a.g * oneMinusPhase, - b.b * phase + a.b * oneMinusPhase, - b.a * phase + a.a * oneMinusPhase); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::UpdateHighlighting() -{ - if (!(GetFlags() & MTL_FLAG_NODRAW)) - { - const CInputLightMaterial& original = m_shaderResources.m_LMaterial; - CInputLightMaterial lm = original; - - ColorF highlightColor(0.0f, 0.0f, 0.0f, 1.0f); - float highlightIntensity = 0.0f; - - MAKE_SURE(GetIEditor()->GetMaterialManager(), return ); - GetIEditor()->GetMaterialManager()->GetHighlightColor(&highlightColor, &highlightIntensity, m_highlightFlags); - - if (m_shaderItem.m_pShaderResources) - { - ColorF diffuseColor = Interpolate(original.m_Diffuse, highlightColor, highlightIntensity); - ColorF emissiveColor = Interpolate(original.m_Emittance, highlightColor, highlightIntensity); - ColorF specularColor = Interpolate(original.m_Specular, highlightColor, highlightIntensity); - - // [Shader System TO DO] remove this hard coded association! - m_shaderItem.m_pShaderResources->SetColorValue(EFTT_DIFFUSE, diffuseColor); - m_shaderItem.m_pShaderResources->SetColorValue(EFTT_SPECULAR, specularColor); - m_shaderItem.m_pShaderResources->SetColorValue(EFTT_EMITTANCE, emissiveColor); - - m_shaderItem.m_pShaderResources->UpdateConstants(m_shaderItem.m_pShader); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterial::SetHighlightFlags(int highlightFlags) -{ - m_highlightFlags = highlightFlags; - - UpdateHighlighting(); -} - - -void CMaterial::SetShaderItem(const SShaderItem& shaderItem) -{ - SAFE_RELEASE(m_shaderItem.m_pShader); - SAFE_RELEASE(m_shaderItem.m_pShaderResources); - - m_shaderItem = shaderItem; - if (m_shaderItem.m_pShader) - { - m_shaderItem.m_pShader->AddRef(); - } - if (m_shaderItem.m_pShaderResources) - { - m_shaderItem.m_pShaderResources->AddRef(); - } -} diff --git a/Code/Sandbox/Editor/Material/Material.h b/Code/Sandbox/Editor/Material/Material.h deleted file mode 100644 index b311744e14..0000000000 --- a/Code/Sandbox/Editor/Material/Material.h +++ /dev/null @@ -1,315 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIAL_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIAL_H -#pragma once - -#include -#include -#include "BaseLibraryItem.h" -#include "Include/IEditorMaterial.h" -#include "Util/Variable.h" -#include - -// forward declarations, -class CMaterialManager; -class CVarBlock; - -enum eMTL_PROPAGATION -{ - MTL_PROPAGATE_OPACITY = 1 << 0, - MTL_PROPAGATE_LIGHTING = 1 << 1, - MTL_PROPAGATE_ADVANCED = 1 << 2, - MTL_PROPAGATE_TEXTURES = 1 << 3, - MTL_PROPAGATE_SHADER_PARAMS = 1 << 4, - MTL_PROPAGATE_SHADER_GEN = 1 << 5, - MTL_PROPAGATE_VERTEX_DEF = 1 << 6, - MTL_PROPAGATE_LAYER_PRESETS = 1 << 7, - MTL_PROPAGATE_MATERIAL_SETTINGS = 1 << 8, - MTL_PROPAGATE_ALL = ( - MTL_PROPAGATE_OPACITY | - MTL_PROPAGATE_LIGHTING | - MTL_PROPAGATE_ADVANCED | - MTL_PROPAGATE_TEXTURES | - MTL_PROPAGATE_SHADER_PARAMS | - MTL_PROPAGATE_SHADER_GEN | - MTL_PROPAGATE_VERTEX_DEF | - MTL_PROPAGATE_LAYER_PRESETS | - MTL_PROPAGATE_MATERIAL_SETTINGS), - MTL_PROPAGATE_RESERVED = 1 << 9 -}; - -/** CMaterial class - Every Material is a member of material library. - Materials can have child sub materials, - Sub materials are applied to the same geometry of the parent material in the other material slots. -*/ - -struct SMaterialLayerResources -{ - SMaterialLayerResources() - : m_nFlags(MTL_LAYER_USAGE_REPLACEBASE) - , m_bRegetPublicParams(true) - , m_pMatLayer(0) - { - } - - uint8 m_nFlags; - bool m_bRegetPublicParams; - QString m_shaderName; - - _smart_ptr< IMaterialLayer > m_pMatLayer; - SInputShaderResources m_shaderResources; - XmlNodeRef m_publicVarsCache; -}; - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -class CRYEDIT_API CMaterial - : public IEditorMaterial -{ -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - ////////////////////////////////////////////////////////////////////////// - CMaterial(const QString& name, int nFlags = 0); - CMaterial(const CMaterial& rhs); - ~CMaterial(); - - virtual EDataBaseItemType GetType() const { return EDB_TYPE_MATERIAL; }; - - void SetName(const QString& name); - - ////////////////////////////////////////////////////////////////////////// - QString GetFullName() const { return m_name; }; - - ////////////////////////////////////////////////////////////////////////// - // File properties of the material. - ////////////////////////////////////////////////////////////////////////// - QString GetFilename() const; - - //! Collect filenames of texture sources used in material - //! Return number of filenames - int GetTextureFilenames(QStringList& outFilenames) const; - int GetAnyTextureFilenames(QStringList& outFilenames) const; - - void UpdateFileAttributes(bool useSourceControl = true); - uint32 GetFileAttributes(); - ////////////////////////////////////////////////////////////////////////// - - //! Sets one or more material flags from EMaterialFlags enum. - void SetFlags(int flags) { m_mtlFlags = flags; }; - //! Query this material flags. - virtual int GetFlags() const { return m_mtlFlags; } - bool IsMultiSubMaterial() const { return (m_mtlFlags & MTL_FLAG_MULTI_SUBMTL) != 0; }; - bool IsPureChild() const { return (m_mtlFlags & MTL_FLAG_PURE_CHILD) != 0; } - - // Check if material is used. - bool IsUsed() const { /*return m_nUseCount > 0 || (m_mtlFlags & MTL_FLAG_ALWAYS_USED);*/ return true; }; - - virtual void GatherUsedResources(CUsedResources& resources); - - //! Set name of shader used by this material. - void SetShaderName(const QString& shaderName); - //! Get name of shader used by this material. - QString GetShaderName() const { return m_shaderName; }; - - virtual SInputShaderResources& GetShaderResources() { return m_shaderResources; }; - - //! Get public parameters of material in variable block. - CVarBlock* GetPublicVars(SInputShaderResources& pShaderResources); - - //! Set the shader public param m_script variable into our own m_script, script contains min/max for a given shader param value - void SetShaderParamPublicScript(); - - //! Sets variable block of public shader parameters. - //! VarBlock must be in same format as returned by GetPublicVars(). - void SetPublicVars(CVarBlock* pPublicVars, CMaterial* pMtl); - - //! Update names/descriptions in this variable array, return a variable block for replacing - CVarBlock* UpdateTextureNames(CSmartVariableArray textureVars[EFTT_MAX]); -// [Shader System] - Do To: add back with map usage: CVarBlock* UpdateTextureNames(AZStd::unordered_map& textureVarsMap); - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetShaderGenParamsVars(); - void SetShaderGenParamsVars(CVarBlock* pBlock); - uint64 GetShaderGenMask() { return m_nShaderGenMask; } - void SetShaderGenMask(uint64 mask) { m_nShaderGenMask = mask; } - - //! Return variable block of shader params. - SShaderItem& GetShaderItem() { return m_shaderItem; }; - - //! Return material layers resources - SMaterialLayerResources* GetMtlLayerResources() { return m_pMtlLayerResources; }; - - //! Get texture map usage mask for shader in this material. - unsigned int GetTexmapUsageMask() const; - - //! Load new shader. - bool LoadShader(); - - //! Reload shader, update all shader parameters. - virtual void Update(); - - // Reload material settings from file. - // NOTICE: The function will remove all the sub-materials and recreate them! - void Reload(); - - //! Serialize material settings to xml. - virtual void Serialize(SerializeContext& ctx); - - //! Assign this material to static geometry. - void AssignToEntity(IRenderNode* pEntity); - - ////////////////////////////////////////////////////////////////////////// - // Surface types. - ////////////////////////////////////////////////////////////////////////// - virtual void SetSurfaceTypeName(const QString& surfaceType); - virtual const QString& GetSurfaceTypeName() const { return m_surfaceType; }; - bool IsBreakable2D() const; - - ////////////////////////////////////////////////////////////////////////// - // Child Sub materials. - ////////////////////////////////////////////////////////////////////////// - //! Get number of sub materials childs. - int GetSubMaterialCount() const; - //! Set number of sub materials childs. - void SetSubMaterialCount(int nSubMtlsCount); - //! Get sub material child by index. - CMaterial* GetSubMaterial(int index) const; - //! Find sub material index by name - int FindMaterialIndex(const QString& name); - // Set a material to the sub materials slot. - // Use NULL material pointer to clear slot. - void SetSubMaterial(int nSlot, CMaterial* mtl); - //! Remove all sub materials, does not change number of sub material slots. - void ClearAllSubMaterials(); - - //! Return pointer to engine material. - virtual _smart_ptr GetMatInfo(bool bUseExistingEngineMaterial = true); - // Clear stored pointer to engine material. - void ClearMatInfo(); - - //! Validate materials for errors. - void Validate(); - - // Check if material file can be modified. - // Will check file attributes if it is not read only. - bool CanModify(bool bSkipReadOnly = true); - - // Save material to file. - virtual bool Save(bool bSkipReadOnly = true, const QString& fullPath = ""); - - // Dummy material is just a placeholder item for materials that have not been found on disk. - void SetDummy(bool bDummy) { m_bDummyMaterial = bDummy; } - bool IsDummy() const { return m_bDummyMaterial != 0; } - - // Called by material manager when material selected as a current material. - void OnMakeCurrent(); - - void SetFromMatInfo(_smart_ptr pMatInfo); - - // Link a submaterial by name (used for value propagation in CMaterialUI) - void LinkToMaterial(const QString& name); - const QString& GetLinkedMaterialName() { return m_linkedMaterial; } - - // Return parent material for submaterial - CMaterial* GetParent() const {return m_pParent; } - - //! Loads material layers - bool LoadMaterialLayers(); - //! Updates material layers - void UpdateMaterialLayers(); - - void SetHighlightFlags(int highlightFlags); - void UpdateHighlighting(); - virtual void DisableHighlightForFrame(); - void RecordUndo(const char* sText, bool bForceUpdate = false); - - int GetPropagationFlags() const { return m_propagationFlags; } - void SetPropagationFlags(const int flags) { m_propagationFlags = flags; } - - bool LayerActivationAllowed() const { return m_allowLayerActivation; } - void SetLayerActivation(bool allowed) { m_allowLayerActivation = allowed; } - - uint32 GetDccMaterialHash() const { return m_dccMaterialHash; } - void SetDccMaterialHash(AZ::u32 hash) { m_dccMaterialHash = hash; } - void SetShaderItem(const SShaderItem& shaderItem); - -private: - void UpdateMatInfo(); - void CheckSpecialConditions(); - - void NotifyChanged(); - -private: - ////////////////////////////////////////////////////////////////////////// - // Variables. - ////////////////////////////////////////////////////////////////////////// - QString m_shaderName; - QString m_surfaceType; - QString m_linkedMaterial; - - //! Material flags. - int m_mtlFlags; - - // Hash for DCC material attributes, used to check if .dccmtl has changed - // If so, the source .mtl file will need to be rebuilt - uint32 m_dccMaterialHash; - - // Parent material, Only valid for Pure Childs. - CMaterial* m_pParent; - - ////////////////////////////////////////////////////////////////////////// - // Shader resources. - ////////////////////////////////////////////////////////////////////////// - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - SShaderItem m_shaderItem; - SInputShaderResources m_shaderResources; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - //CVarBlockPtr m_shaderParamsVar; - //! Common shader flags. - uint64 m_nShaderGenMask; - QString m_pszShaderGenMask; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - SMaterialLayerResources m_pMtlLayerResources[MTL_LAYER_MAX_SLOTS]; - - _smart_ptr m_pMatInfo; - - XmlNodeRef m_publicVarsCache; - - //! Array of sub materials. - std::vector<_smart_ptr > m_subMaterials; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - int m_nUseCount; - uint32 m_scFileAttributes; - - unsigned char m_highlightFlags; - - // The propagation flags are a bit combination of the MTL_PROPAGATION enum above - // and determine which properties get propagated to an optional linked material - // during ui editing - int m_propagationFlags; - - //! Material Used in level. - unsigned int m_bDummyMaterial : 1; // Dummy material, name specified but material file not found. - unsigned int m_bIgnoreNotifyChange : 1; // Do not send notifications about changes. - unsigned int m_bRegetPublicParams : 1; - unsigned int m_bKeepPublicParamsValues : 1; - - bool m_allowLayerActivation; -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIAL_H diff --git a/Code/Sandbox/Editor/Material/MaterialBrowser.cpp b/Code/Sandbox/Editor/Material/MaterialBrowser.cpp deleted file mode 100644 index e39a29a47d..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowser.cpp +++ /dev/null @@ -1,1792 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialBrowser.h" - -// Qt -#include - -// AzQtComponents -#include - -// AzToolsFramework -#include - -// Editor -#include "MaterialManager.h" -#include "Clipboard.h" -#include "MaterialImageListCtrl.h" -#include "StringDlg.h" - -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -#include -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - -enum -{ - MENU_UNDEFINED = CMaterialImageListCtrl::MaterialBrowserWidgetActionsStart, - MENU_CUT, - MENU_COPY, - MENU_COPY_NAME, - MENU_PASTE, - MENU_EXPLORE, - MENU_DUPLICATE, - MENU_EXTRACT, - MENU_RENAME, - MENU_DELETE, - MENU_RESET, - MENU_ASSIGNTOSELECTION, - MENU_SELECTASSIGNEDOBJECTS, - MENU_NUM_SUBMTL, - MENU_ADDNEW, - MENU_ADDNEW_MULTI, - MENU_CONVERT_TO_MULTI, - MENU_SUBMTL_MAKE, - MENU_SUBMTL_CLEAR, - MENU_SAVE_TO_FILE, - MENU_SAVE_TO_FILE_MULTI, - MENU_MERGE, - - MENU_SCM_ADD, - MENU_SCM_CHECK_OUT, - MENU_SCM_UNDO_CHECK_OUT, - MENU_SCM_GET_LATEST, - MENU_SCM_GET_LATEST_TEXTURES, -}; - -static QAction* CreateTreeViewAction(const char* text, const QKeySequence& shortcut, QWidget* shortcutContext, MaterialBrowserWidget* widget, void (MaterialBrowserWidget::*slot)()) -{ - QAction* action = new QAction(text, shortcutContext); - action->setShortcut(shortcut); - QObject::connect(action, &QAction::triggered, widget, slot); - widget->addAction(action); - return action; -} - -////////////////////////////////////////////////////////////////////////// -MaterialBrowserWidget::MaterialBrowserWidget(QWidget* parent) - : QWidget(parent) - , m_ui(new Ui::MaterialBrowser) - , m_filterModel(new MaterialBrowserFilterModel(this)) -{ - using namespace AzToolsFramework::AssetBrowser; - - m_ui->setupUi(this); - - // create some permanent (for the life of this widget) actions for shortcut handling - m_cutAction = CreateTreeViewAction("Cut", QKeySequence::Cut, m_ui->treeView, this, &MaterialBrowserWidget::OnCut); - m_copyAction = CreateTreeViewAction("Copy", QKeySequence::Copy, m_ui->treeView, this, &MaterialBrowserWidget::OnCopy); - m_pasteAction = CreateTreeViewAction("Paste", QKeySequence::Paste, m_ui->treeView, this, &MaterialBrowserWidget::OnPaste); - m_duplicateAction = CreateTreeViewAction("Duplicate", QKeySequence(Qt::CTRL + Qt::Key_D), m_ui->treeView, this, &MaterialBrowserWidget::OnDuplicate); - m_deleteAction = CreateTreeViewAction("Delete", QKeySequence::Delete, m_ui->treeView, this, &MaterialBrowserWidget::DeleteItem); - m_renameItemAction = CreateTreeViewAction("Rename", Qt::Key_F2, m_ui->treeView, this, &MaterialBrowserWidget::OnRenameItem); - m_addNewMaterialAction = CreateTreeViewAction("Add New Material", Qt::Key_Insert, m_ui->treeView, this, &MaterialBrowserWidget::OnAddNewMaterial); - - MaterialBrowserWidgetBus::Handler::BusConnect(); - - // Get the asset browser model - AssetBrowserComponentRequestBus::BroadcastResult(m_assetBrowserModel, &AssetBrowserComponentRequests::GetAssetBrowserModel); - AZ_Assert(m_assetBrowserModel, "Failed to get filebrowser model"); - - // Set up the filter model - m_filterModel->setSourceModel(m_assetBrowserModel); - m_ui->treeView->setModel(m_filterModel.data()); - m_ui->treeView->SetThumbnailContext("MaterialBrowser"); - m_ui->treeView->SetShowSourceControlIcons(true); - - m_ui->m_searchWidget->Setup(true, false); - m_filterModel->SetSearchFilter(m_ui->m_searchWidget); - connect(m_ui->m_searchWidget->GetFilter().data(), &AssetBrowserEntryFilter::updatedSignal, m_filterModel.data(), &MaterialBrowserFilterModel::SearchFilterUpdated); - - // Call LoadState to initialize the AssetBrowserTreeView's QTreeViewStateSaver - // This must be done BEFORE StartRecordUpdateJobs(). A race condition from the update jobs was causing a 5-10% crash/hang when opening the Material Editor. - m_ui->treeView->SetName("MaterialBrowserTreeView"); - - // Override the AssetBrowserTreeView's custom context menu - disconnect(m_ui->treeView, &QWidget::customContextMenuRequested, 0, 0); - connect(m_ui->treeView, &QWidget::customContextMenuRequested, this, [=](const QPoint& point) - { - CMaterialBrowserRecord record; - TryGetSelectedRecord(record); - ShowContextMenu(record, point); - }); - - connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MaterialBrowserWidget::OnSelectionChanged); - //Wait for the signal emitted on record update jobs finished, then we can restore the selection for the previous selected item - connect(this, SIGNAL(refreshSelection()), this, SLOT(OnRefreshSelection())); - - connect(this, SIGNAL(materialAdded()), this, SLOT(OnMaterialAdded())); - - m_bIgnoreSelectionChange = false; - m_bItemsValid = true; - - m_pMatMan = GetIEditor()->GetMaterialManager(); - m_pMatMan->AddListener(this); - m_pListener = NULL; - - m_viewType = VIEW_LEVEL; - m_pMaterialImageListCtrl = NULL; - m_pLastActiveMultiMaterial = 0; - - m_bNeedReload = false; - - m_bHighlightMaterial = false; - m_timeOfHighlight = 0; - - m_bShowOnlyCheckedOut = false; - - GetIEditor()->RegisterNotifyListener(this); -} - -////////////////////////////////////////////////////////////////////////// -MaterialBrowserWidget::~MaterialBrowserWidget() -{ - m_filterModel->CancelRecordUpdateJobs(); - m_filterModel->deleteLater(); - m_ui->treeView->SaveState(); - GetIEditor()->UnregisterNotifyListener(this); - - m_pMaterialImageListCtrl = NULL; - m_pMatMan->RemoveListener(this); - ClearItems(); - - if (m_bHighlightMaterial) - { - m_pMatMan->SetHighlightedMaterial(0); - } - - MaterialBrowserWidgetBus::Handler::BusDisconnect(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::ClearItems() -{ - m_bIgnoreSelectionChange = true; - - if (m_pMaterialImageListCtrl) - { - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - materialModel->DeleteAllItems(); - } - - m_pLastActiveMultiMaterial = nullptr; - m_delayedSelection = nullptr; - - m_bIgnoreSelectionChange = false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::TryLoadRecordMaterial(CMaterialBrowserRecord& record) -{ - // If material already loaded ignore. - if (record.m_material) - { - return; - } - - m_bIgnoreSelectionChange = true; - // Try to load material for it. - record.m_material = m_pMatMan->LoadMaterial(record.GetRelativeFilePath().c_str(), false); - - m_filterModel->SetRecord(record); - m_bIgnoreSelectionChange = false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::TickRefreshMaterials() -{ - if (m_bHighlightMaterial) - { - uint32 t = GetTickCount(); - if ((t - m_timeOfHighlight) > 300) - { - m_bHighlightMaterial = false; - m_pMatMan->SetHighlightedMaterial(0); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnIdleUpdate: - { - TickRefreshMaterials(); - } - break; - case eNotify_OnBeginLoad: - { - //Need to make sure the selection is cleared before clearing the record map - SetSelectedItem(nullptr, nullptr, true); - m_filterModel->ClearRecordMap(); - } - break; - case eNotify_OnCloseScene: - { - m_filterModel->ShowOnlyLevelMaterials(false, true); - ClearItems(); - m_ui->treeView->SaveState(); - //Need to make sure the selection is cleared before clearing the record map - SetSelectedItem(nullptr, nullptr, true); - m_filterModel->ClearRecordMap(); - } - break; - case eNotify_OnEndNewScene: - case eNotify_OnEndSceneOpen: - { - m_filterModel->ShowOnlyLevelMaterials(false, true); - m_filterModel->StartRecordUpdateJobs(); - if (m_ui->treeView->IsTreeViewSavingReady()) - { - m_ui->treeView->ApplyTreeViewSnapshot(); - } - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SetSelectedItem(_smart_ptr material, const TMaterialBrowserRecords* pMarkedRecords, bool selectInTreeView) -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - m_bIgnoreSelectionChange = true; - if (pMarkedRecords) - { - m_markedRecords = *pMarkedRecords; - } - else - { - m_markedRecords.clear(); - } - - m_pMatMan->SetCurrentFolder(""); - - _smart_ptr selectedMaterial = material; - if (material && material->IsPureChild()) - { - selectedMaterial = material->GetParent(); - } - - // Clear the delayed selection whenever a new material is selected - m_delayedSelection = nullptr; - - // In some cases, such as when SetSelectedItem is called from the material picker or the rollup bar, - // the material has not yet been selected in the tree-view, so that item must be selected here - bool validSelection = false; - if (selectInTreeView) - { - if (!selectedMaterial) - { - // Clear the current selection so that the upcoming call to RefreshSelected() - // doesn't try to refresh the previously selected material which may be invalid - m_ui->treeView->clearSelection(); - m_ui->treeView->setCurrentIndex(QModelIndex()); - } - else if (m_markedRecords.size() > 0) - { - QItemSelection selection; - for (CMaterialBrowserRecord record : m_markedRecords) - { - QModelIndex currentIndex = m_filterModel->GetIndexFromMaterial(record.m_material); - if (currentIndex.isValid()) - { - selection.push_back(QItemSelectionRange(currentIndex)); - validSelection = true; - } - } - m_ui->treeView->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect); - } - else - { - QModelIndex currentIndex = m_filterModel->GetIndexFromMaterial(selectedMaterial); - if (currentIndex.isValid()) - { - m_ui->treeView->selectionModel()->setCurrentIndex(currentIndex, QItemSelectionModel::ClearAndSelect); - validSelection = true; - - // Now that the parent material is selected in the browser, - // select the appropriate sub-material in the material preview window - if (selectedMaterial == material->GetParent()) - { - for (int i = 0; i < selectedMaterial->GetSubMaterialCount(); ++i) - { - if (material == selectedMaterial->GetSubMaterial(i)) - { - m_selectedSubMaterialIndex = i; - break; - } - } - } - } - else - { - // Hold on to a pointer to this material, listen for the MaterialFinishedProcessing event, - // and attempt to re-select this material if it finishes processing in the background - m_delayedSelection = selectedMaterial; - } - } - } - - RefreshSelected(); - - if (!selectedMaterial) - { - QModelIndex current = m_ui->treeView->currentIndex(); - QString path; - while (current.isValid()) - { - path = '/' + current.data().toString() + path; - current = current.parent(); - } - m_pMatMan->SetCurrentFolder((Path::GetEditingGameDataFolder() + path.toUtf8().data()).c_str()); - } - else - { - if (selectedMaterial->IsMultiSubMaterial() && m_selectedSubMaterialIndex >= 0) - { - selectedMaterial = selectedMaterial->GetSubMaterial(m_selectedSubMaterialIndex); - } - } - - if (m_pListener) - { - // Don't call the listener event if we attempted to select an item in the tree view and failed - // to prevent the material parameter editor from switching to a new material if it wasn't actually selected - if (!selectInTreeView || validSelection) - { - m_pListener->OnBrowserSelectItem(selectedMaterial, false); - } - //Update the selected item if no material is selected in tree view - else if (!selectedMaterial && selectInTreeView) - { - m_pListener->OnBrowserSelectItem(nullptr, false); - } - } - - m_timeOfHighlight = GetTickCount(); - m_pMatMan->SetHighlightedMaterial(selectedMaterial); - if (selectedMaterial) - { - m_bHighlightMaterial = true; - } - - std::vector<_smart_ptr > markedMaterials; - if (pMarkedRecords) - { - for (size_t i = 0; i < pMarkedRecords->size(); ++i) - { - markedMaterials.push_back((*pMarkedRecords)[i].m_material); - } - } - m_pMatMan->SetMarkedMaterials(markedMaterials); - - m_bIgnoreSelectionChange = false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SelectItem(IDataBaseItem* pItem, [[maybe_unused]] IDataBaseItem* pParentItem) -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - if (!pItem) - { - return; - } - - _smart_ptr material = static_cast(pItem); - SetSelectedItem(material, 0, true); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnDuplicate() -{ - GetIEditor()->GetMaterialManager()->Command_Merge(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnCut() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found) - { - OnCopy(); - DeleteItem(record); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnCopyName() -{ - _smart_ptr pMtl = GetCurrentMaterial(); - if (pMtl) - { - CClipboard clipboard(this); - clipboard.PutString(pMtl->GetName(), "Material Name"); - } -} - -void MaterialBrowserWidget::ShowOnlyLevelMaterials(bool levelOnly) -{ - m_filterModel->ShowOnlyLevelMaterials(levelOnly); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnCopy() -{ - _smart_ptr pMtl = GetCurrentMaterial(); - if (pMtl) - { - CClipboard clipboard(this); - XmlNodeRef node = XmlHelpers::CreateXmlNode("Material"); - node->setAttr("Name", pMtl->GetName().toUtf8().data()); - CBaseLibraryItem::SerializeContext ctx(node, false); - ctx.bCopyPaste = true; - pMtl->Serialize(ctx); - clipboard.Put(node); - } -} - -////////////////////////////////////////////////////////////////////////// -bool MaterialBrowserWidget::CanPaste() const -{ - CClipboard clipboard(nullptr); - if (clipboard.IsEmpty()) - { - return false; - } - XmlNodeRef node = clipboard.Get(); - if (!node) - { - return false; - } - - if (strcmp(node->getTag(), "Material") == 0) - { - return true; - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnPaste() -{ - CClipboard clipboard(this); - if (clipboard.IsEmpty()) - { - return; - } - XmlNodeRef node = clipboard.Get(); - if (!node) - { - return; - } - - if (strcmp(node->getTag(), "Material") == 0) - { - if (!m_pMatMan->GetCurrentMaterial()) - { - GetIEditor()->GetMaterialManager()->Command_Create(); - } - - _smart_ptr pMtl = m_pMatMan->GetCurrentMaterial(); - if (pMtl) - { - // This is material node. - CBaseLibraryItem::SerializeContext serCtx(node, true); - serCtx.bCopyPaste = true; - serCtx.bUniqName = true; - pMtl->Serialize(serCtx); - - SelectItem(pMtl, NULL); - pMtl->Save(); - pMtl->Reload(); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnAddNewMaterial() -{ - GetIEditor()->GetMaterialManager()->Command_Create(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnAddNewMultiMaterial() -{ - GetIEditor()->GetMaterialManager()->Command_CreateMulti(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnMergeMaterials() -{ - GetIEditor()->GetMaterialManager()->Command_Merge(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnConvertToMulti() -{ - GetIEditor()->GetMaterialManager()->Command_ConvertToMulti(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::DeleteItem() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found) - { - DeleteItem(record); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnResetItem() -{ - if (QMessageBox::question(this, tr("Reset Material"), tr("Reset Material to default?")) == QMessageBox::Yes) - { - _smart_ptr pMtl = GetCurrentMaterial(); - int index; - - pMtl->GetSubMaterialCount() > 0 ? index = pMtl->GetSubMaterialCount() : index = 1; - - if (pMtl) - { - for (int i = 0; i < index; i++) - { - pMtl->GetSubMaterialCount() > 0 ? pMtl->GetSubMaterial(i)->Reload() : pMtl->Reload(); - TickRefreshMaterials(); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::DeleteItem(const CMaterialBrowserRecord& record) -{ - _smart_ptr pMtl = record.m_material; - if (pMtl) - { - if (m_selectedSubMaterialIndex >= 0) - { - pMtl = pMtl->GetSubMaterial(m_selectedSubMaterialIndex); - OnClearSubMtlSlot(pMtl); - } - else - { - GetIEditor()->GetMaterialManager()->Command_Delete(); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnRenameItem() -{ - _smart_ptr pMtl = GetCurrentMaterial(); - if (!pMtl) - { - return; - } - - if (pMtl->IsPureChild()) - { - StringDlg dlg(tr("Enter New Sub-Material Name"), this); - dlg.SetString(pMtl->GetName()); - dlg.SetCheckCallback([this](QString name) -> bool - { - static const int MAX_REASONABLE_MATERIAL_NAME = 128; - if (name.length() >= MAX_REASONABLE_MATERIAL_NAME) - { - QMessageBox::warning(this, tr("Name too long"), tr("Please enter a name less than %1 characters").arg(MAX_REASONABLE_MATERIAL_NAME)); - return false; - } - return true; - }); - - if (dlg.exec() == QDialog::Accepted) - { - pMtl->SetName(dlg.GetString()); - pMtl->Save(); - pMtl->Reload(); - } - } - else - { - if ((pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_MANAGED) && - !(pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_CHECKEDOUT)) - { - if (QMessageBox::Cancel == QMessageBox::information(this, tr("Confirm"), tr("Only checked-out files can be renamed. Check out and mark for delete before rename it?"), QMessageBox::Ok | QMessageBox::Cancel)) - { - return; - } - } - - QFileInfo info(pMtl->GetFilename()); - QString filename = info.fileName(); - if (!CFileUtil::SelectSaveFile("Material Files (*.mtl)", "mtl", info.path(), filename)) - { - return; - } - - QString itemName = m_pMatMan->FilenameToMaterial(Path::GetRelativePath(filename)); - if (itemName.isEmpty()) - { - return; - } - - if (m_pMatMan->FindItemByName(itemName)) - { - Warning("Material with name %s already exist", itemName.toUtf8().data()); - return; - } - - if (pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_MANAGED) - { - if (pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_CHECKEDOUT) - { - if (QMessageBox::Cancel == QMessageBox::information(this, tr("Confirm"), tr("The original file will be marked for delete and the new named file will be marked for integration."), QMessageBox::Ok | QMessageBox::Cancel)) - { - return; - } - } - else - { - CFileUtil::CheckoutFile(pMtl->GetFilename().toUtf8().data(), this); - } - - if (!CFileUtil::RenameFile(pMtl->GetFilename().toUtf8().data(), filename.toUtf8().data())) - { - QMessageBox::critical(this, tr("Error"), tr("Could not rename file in Source Control.")); - } - } - - - // Delete file on disk. - if (!pMtl->GetFilename().isEmpty()) - { - QFile::remove(pMtl->GetFilename()); - } - pMtl->SetName(itemName); - pMtl->Save(); - SetSelectedItem(pMtl, 0, true); - } -} - - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnSetSubMtlCount(const CMaterialBrowserRecord& record) -{ - _smart_ptr pMtl = record.m_material; - if (!pMtl) - { - return; - } - - if (!pMtl->IsMultiSubMaterial()) - { - return; - } - - int num = pMtl->GetSubMaterialCount(); - bool ok = false; - num = QInputDialog::getInt(this, tr("Number of Sub Materials"), QStringLiteral(""), num, 0, MAX_SUB_MATERIALS, 1, &ok); - if (ok) - { - if (num != pMtl->GetSubMaterialCount()) - { - if (m_selectedSubMaterialIndex >= num) - { - m_selectedSubMaterialIndex = num - 1; - } - - CUndo undo("Set SubMtl Count"); - pMtl->SetSubMaterialCount(num); - - for (int i = 0; i < num; i++) - { - if (pMtl->GetSubMaterial(i) == 0) - { - // Allocate pure childs for all empty slots. - QString name; - name = QStringLiteral("SubMtl%1").arg(i + 1); - _smart_ptr pChild = new CMaterial(name, MTL_FLAG_PURE_CHILD); - pMtl->SetSubMaterial(i, pChild); - } - } - } - } -} - - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::DoSourceControlOp(CMaterialBrowserRecord& record, ESourceControlOp scmOp) -{ - if (!GetIEditor()->IsSourceControlAvailable()) - { - return; - } - - _smart_ptr pMtl = record.m_material; - - if (pMtl && pMtl->IsPureChild()) - { - pMtl = pMtl->GetParent(); - } - - if (scmOp == ESCM_IMPORT) // don't save unless you're doing an operation which writes. - { - if (pMtl && pMtl->IsModified()) - { - pMtl->Save(); - } - } - - QString path = pMtl ? pMtl->GetFilename() : QString(); - - if (path.isEmpty()) - { - return; - } - - bool bRes = true; - switch (scmOp) - { - case ESCM_IMPORT: - if (pMtl) - { - QStringList filenames; - int nTextures = pMtl->GetTextureFilenames(filenames); - for (int i = 0; i < nTextures; ++i) - { - CFileUtil::CheckoutFile(filenames[i].toUtf8().data(), this); - } - - bRes = CFileUtil::CheckoutFile(path.toUtf8().data(), this); - } - break; - case ESCM_CHECKOUT: - { - if (pMtl && (pMtl->GetFileAttributes() & SCC_FILE_ATTRIBUTE_BYANOTHER)) - { - AZStd::string otherUser("another user"); - AzToolsFramework::SourceControlFileInfo fileInfo; - if (CFileUtil::GetFileInfoFromSourceControl(pMtl->GetFilename().toUtf8().data(), fileInfo, this)) - { - // Sanity check the source control api reports the file is checked out by another - AZ_Assert(fileInfo.HasFlag(AzToolsFramework::SCF_OtherOpen), "File attributes reporting incorrectly"); - otherUser = fileInfo.m_StatusUser; - } - - if (QMessageBox::question(this, QString(), tr("This file is checked out by %1. Try to continue?").arg(otherUser.c_str())) != QMessageBox::Yes) - { - return; - } - } - bRes = CFileUtil::GetLatestFromSourceControl(path.toUtf8().data(), this); - if (bRes) - { - bRes = CFileUtil::CheckoutFile(path.toUtf8().data(), this); - } - } - break; - case ESCM_UNDO_CHECKOUT: - bRes = CFileUtil::RevertFile(path.toUtf8().data(), this); - break; - case ESCM_GETLATEST: - bRes = CFileUtil::GetLatestFromSourceControl(path.toUtf8().data(), this); - break; - case ESCM_GETLATESTTEXTURES: - if (pMtl) - { - QString message; - QStringList filenames; - int nTextures = pMtl->GetTextureFilenames(filenames); - for (int i = 0; i < nTextures; ++i) - { - bRes = CFileUtil::GetLatestFromSourceControl(filenames[i].toUtf8().data(), this); - message += Path::GetRelativePath(filenames[i], true) + (bRes ? " [OK]" : " [Fail]") + "\n"; - } - QMessageBox::information(this, QString(), message.isEmpty() ? tr("No files are affected") : message); - } - return; - } - - if (!bRes) - { - QMessageBox::critical(this, tr("Error"), tr("Source Control Operation Failed.\r\nCheck if Source Control Provider correctly setup and working directory is correct.")); - return; - } - - // force the cache to be rebuilt next time we repaint - record.InitializeSourceControlAttributes(); - m_filterModel->SetRecord(record); - - if (pMtl) - { - pMtl->Reload(); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnMakeSubMtlSlot(const CMaterialBrowserRecord& record) -{ - if (m_selectedSubMaterialIndex >= 0) - { - _smart_ptr parentMaterial = record.m_material; - if (parentMaterial && parentMaterial->IsMultiSubMaterial()) - { - const QString str = tr("Making new material will override material currently assigned to the slot %1 of %2\r\nMake new sub material?") - .arg(m_selectedSubMaterialIndex).arg(parentMaterial->GetName()); - if (QMessageBox::question(this, tr("Confirm Override"), str) == QMessageBox::Yes) - { - QString name = tr("SubMtl%1") - .arg(m_selectedSubMaterialIndex + 1); - _smart_ptr pMtl = new CMaterial(name, MTL_FLAG_PURE_CHILD); - parentMaterial->SetSubMaterial(m_selectedSubMaterialIndex, pMtl); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnClearSubMtlSlot(_smart_ptr subMaterial) -{ - if (subMaterial && m_selectedSubMaterialIndex >= 0) - { - _smart_ptr parentMaterial = subMaterial->GetParent(); - if (parentMaterial && parentMaterial->IsMultiSubMaterial()) - { - const QString str = tr("Clear Sub-Material Slot %1 of %2?").arg(m_selectedSubMaterialIndex).arg(parentMaterial->GetName()); - if (QMessageBox::question(this, tr("Clear Sub-Material"), str) == QMessageBox::Yes) - { - CUndo undo("Material Change"); - SetSubMaterial(parentMaterial, m_selectedSubMaterialIndex, 0); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SetSubMaterial(_smart_ptr parentMaterial, int slot, _smart_ptr subMaterial) -{ - if (parentMaterial && parentMaterial->IsMultiSubMaterial()) - { - // If the last sub-material is being removed, select the 2nd to last sub-material - if (!subMaterial && slot == parentMaterial->GetSubMaterialCount() - 1) - { - m_selectedSubMaterialIndex = slot - 1; - } - parentMaterial->SetSubMaterial(slot, subMaterial); - } -} - - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnDataBaseItemEvent(IDataBaseItem* pItem, EDataBaseItemEvent event) -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - if (!pItem) - { - return; - } - - - switch (event) - { - case EDB_ITEM_EVENT_ADD: - break; - case EDB_ITEM_EVENT_DELETE: - { - if (pItem) - { - //If the deleted item is selected, remove selection - CMaterial* pMtl = static_cast(pItem); - CMaterial* selectedMaterial = GetCurrentMaterial(); - if (selectedMaterial && selectedMaterial->IsPureChild()) - { - selectedMaterial = selectedMaterial->GetParent(); - } - if (pMtl == selectedMaterial) - { - SetSelectedItem(nullptr, nullptr, true); - } - } - } - break; - case EDB_ITEM_EVENT_CHANGED: - { - CMaterial* pMtl = static_cast(pItem); - CMaterial* selectedMaterial = GetCurrentMaterial(); - if (selectedMaterial && selectedMaterial->IsPureChild()) - { - selectedMaterial = selectedMaterial->GetParent(); - } - // If this is a sub material, refresh parent - if (pMtl->IsPureChild()) - { - pMtl = pMtl->GetParent(); - } - - if (pMtl == selectedMaterial) - { - if (pMtl->IsMultiSubMaterial()) - { - m_pLastActiveMultiMaterial = NULL; - } - RefreshSelected(); - } - m_bItemsValid = false; - } - break; - case EDB_ITEM_EVENT_SELECTED: - { - SelectItem(pItem, NULL); - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::SetImageListCtrl(CMaterialImageListCtrl* pCtrl) -{ - m_pMaterialImageListCtrl = pCtrl; - if (m_pMaterialImageListCtrl) - { - connect(m_pMaterialImageListCtrl->selectionModel(), &QItemSelectionModel::currentChanged, - this, &MaterialBrowserWidget::OnSubMaterialSelectedInPreviewPane); - - connect(m_pMaterialImageListCtrl, &QAbstractItemView::clicked, - this, &MaterialBrowserWidget::OnSubMaterialSelectedInPreviewPane); - - m_pMaterialImageListCtrl->SetMaterialBrowserWidget(this); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnSaveToFile(bool bMulti) -{ - _smart_ptr pCurrentMaterial = GetCurrentMaterial(); - if (pCurrentMaterial) - { - QString startPath = GetIEditor()->GetSearchPath(EDITOR_PATH_MATERIALS); - QString filename; - if (!CFileUtil::SelectSaveFile("Material Files (*.mtl)", "mtl", startPath, filename)) - { - return; - } - QFileInfo info(filename); - QString itemName = info.baseName(); - itemName = Path::MakeGamePath(itemName); - - if (m_pMatMan->FindItemByName(itemName)) - { - Warning("Material with name %s already exist", itemName.toUtf8().data()); - return; - } - int flags = pCurrentMaterial->GetFlags(); - if (bMulti) - { - flags |= MTL_FLAG_MULTI_SUBMTL; - } - - pCurrentMaterial->SetFlags(flags); - - if (pCurrentMaterial->IsDummy()) - { - pCurrentMaterial->ClearMatInfo(); - pCurrentMaterial->SetDummy(false); - } - pCurrentMaterial->SetModified(true); - pCurrentMaterial->Save(); - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::RefreshSelected() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - _smart_ptr pMtl = nullptr; - if (!found) - { - ClearImageListControlSelection(); - return; - } - else - { - pMtl = record.m_material; - } - - if (m_pMaterialImageListCtrl) - { - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - - materialModel->InvalidateMaterial(pMtl); - if (pMtl) - { - _smart_ptr pMultiMtl = nullptr; - if (pMtl->IsMultiSubMaterial()) - { - // It's possible that the currently selected sub-material index is beyond the range of the current multi-material if, for example, - // the last sub-material was selected but then the source .mtl file was changed to have fewer total sub-materials - if (m_selectedSubMaterialIndex >= pMtl->GetSubMaterialCount()) - { - // If that's the case, select the last sub-material - // If the sub-material count has dropped to 0, setting m_selectedSubMaterialIndex to -1 will cause the parent material to be selected - m_selectedSubMaterialIndex = pMtl->GetSubMaterialCount() - 1; - } - - pMultiMtl = pMtl; - if (m_selectedSubMaterialIndex >= 0) - { - pMtl = pMtl->GetSubMaterial(m_selectedSubMaterialIndex); - } - } - - if (m_pLastActiveMultiMaterial != pMultiMtl || pMultiMtl == nullptr) - { - // A new material was selected, so the previewer needs to be cleared - materialModel->DeleteAllItems(); - // If the new material was not a multi-material, add it to the previewer - if (pMultiMtl == nullptr) - { - materialModel->AddMaterial(pMtl); - } - } - - // If a new multi-material was selected - if (m_pLastActiveMultiMaterial != pMultiMtl && pMultiMtl != nullptr) - { - // Add all of its submaterials to the previewer - for (size_t i = 0; i < pMultiMtl->GetSubMaterialCount(); i++) - { - if (pMultiMtl->GetSubMaterial(i)) - { - materialModel->AddMaterial(pMultiMtl->GetSubMaterial(i), reinterpret_cast(i)); - } - } - m_pMaterialImageListCtrl->selectionModel()->clear(); - - // If a sub-material was selected in the material browser, select it in the previewer - QModelIndex modelIndex; - if (m_selectedSubMaterialIndex >= 0) - { - modelIndex = materialModel->index(m_selectedSubMaterialIndex, 0); - } - m_pMaterialImageListCtrl->selectionModel()->select(modelIndex, QItemSelectionModel::SelectCurrent); - } - - m_pMaterialImageListCtrl->SelectMaterial(pMtl); - m_pLastActiveMultiMaterial = pMultiMtl; - } - else - { - ClearSelection(materialModel); - } - } -} - -void MaterialBrowserWidget::ClearImageListControlSelection() -{ - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - - ClearSelection(materialModel); -} - -void MaterialBrowserWidget::ClearSelection(QMaterialImageListModel* materialModel) -{ - materialModel->DeleteAllItems(); - m_pLastActiveMultiMaterial = nullptr; -} - -////////////////////////////////////////////////////////////////////////// - -void MaterialBrowserWidget::AddContextMenuActionsMultiSelect(QMenu& menu) const -{ - int numMaterialsSelected = 0; - for (int i = 0; i < m_markedRecords.size(); ++i) - { - if (m_markedRecords[i].m_material) - { - ++numMaterialsSelected; - } - } - const QString itemsSelected = tr(" (%1 Materials Selected)").arg(numMaterialsSelected); - menu.addAction(itemsSelected)->setEnabled(false); - menu.addSeparator(); - - if (numMaterialsSelected >= 2) // ... and at least two materials - { - menu.addAction(tr("Merge"))->setData(MENU_MERGE); - } - else - { - menu.addAction(tr("Merge (Select two or more)"))->setEnabled(false); - } -} - -void MaterialBrowserWidget::AddContextMenuActionsNoSelection(QMenu& menu) const -{ - QAction* action = menu.addAction(tr("Paste")); - action->setShortcut(QKeySequence::Paste); - action->setData(MENU_PASTE); - action->setEnabled(CanPaste()); - - menu.addSeparator(); - menu.addAction(tr("Add New Material"))->setData(MENU_ADDNEW); - menu.addAction(tr("Add New Multi Material"))->setData(MENU_ADDNEW_MULTI); - if (GetIEditor()->IsSourceControlAvailable()) - { - menu.addSeparator(); - menu.addAction(tr("Source Control"))->setEnabled(false); - menu.addAction(tr("Check Out"))->setData(MENU_SCM_CHECK_OUT); - menu.addAction(tr("Undo Check Out"))->setData(MENU_SCM_UNDO_CHECK_OUT); - menu.addAction(tr("Get Latest Version"))->setData(MENU_SCM_GET_LATEST); - } -} - -void MaterialBrowserWidget::AddContextMenuActionsSingleSelection(QMenu& menu, _smart_ptr material) const -{ - if (material) - { - if (material->IsMultiSubMaterial()) - { - if (m_selectedSubMaterialIndex >= 0) - { - AddContextMenuActionsSubMaterial(menu, material, material->GetSubMaterial(m_selectedSubMaterialIndex)); - } - else - { - AddContextMenuActionsMultiMaterial(menu); - AddContextMenuActionsCommon(menu, material); - } - } - else if (material->IsPureChild()) - { - AddContextMenuActionsSubMaterial(menu, material->GetParent(), material); - } - else - { - AddContextMenuActionsSingleMaterial(menu); - AddContextMenuActionsCommon(menu, material); - } - } -} - -void MaterialBrowserWidget::AddContextMenuActionsSubMaterial(QMenu& menu, _smart_ptr parentMaterial, _smart_ptr subMaterial) const -{ - bool enabled = true; - - if (parentMaterial) - { - uint32 nFileAttr = parentMaterial->GetFileAttributes(); - if (nFileAttr & SCC_FILE_ATTRIBUTE_READONLY) - { - enabled = false; - } - } - - QAction* action = menu.addAction(tr("Reset sub-material to default")); - action->setData(MENU_SUBMTL_MAKE); - action->setEnabled(enabled); - - menu.addSeparator(); - - action = menu.addAction(tr("Cut")); - action->setShortcut(QKeySequence::Cut); - action->setData(MENU_CUT); - action->setEnabled(enabled); - - action = menu.addAction(tr("Copy")); - action->setShortcut(QKeySequence::Copy); - action->setData(MENU_COPY); - - action = menu.addAction(tr("Paste")); - action->setShortcut(QKeySequence::Paste); - action->setData(MENU_PASTE); - action->setEnabled(CanPaste() && enabled); - - action = menu.addAction(tr("Rename\tF2")); - action->setData(MENU_RENAME); - action->setEnabled(enabled); - - action = menu.addAction(tr("Delete")); - action->setData(MENU_SUBMTL_CLEAR); - action->setEnabled(enabled); -} - -void MaterialBrowserWidget::AddContextMenuActionsMultiMaterial(QMenu& menu) const -{ - menu.addAction(tr("Set Number of Sub-Materials"))->setData(MENU_NUM_SUBMTL); - menu.addSeparator(); -} - -void MaterialBrowserWidget::AddContextMenuActionsSingleMaterial(QMenu& menu) const -{ - menu.addAction(tr("Convert To Multi Material"))->setData(MENU_CONVERT_TO_MULTI); - menu.addSeparator(); -} - -void MaterialBrowserWidget::AddContextMenuActionsCommon(QMenu& menu, _smart_ptr material) const -{ - uint32 fileAttributes = material->GetFileAttributes(); - - bool modificationsEnabled = true; - if (fileAttributes & SCC_FILE_ATTRIBUTE_READONLY) - { - modificationsEnabled = false; - } - - QAction* action = menu.addAction(tr("Cut")); - action->setShortcut(QKeySequence::Cut); - action->setData(MENU_CUT); - action = menu.addAction(tr("Copy")); - action->setShortcut(QKeySequence::Copy); - action->setData(MENU_COPY); - action = menu.addAction(tr("Paste")); - action->setShortcut(QKeySequence::Paste); - action->setData(MENU_PASTE); - action->setEnabled(CanPaste() && modificationsEnabled); - menu.addAction(tr("Copy Path to Clipboard"))->setData(MENU_COPY_NAME); - if (fileAttributes & SCC_FILE_ATTRIBUTE_INPAK) - { - menu.addAction(tr("Extract"))->setData(MENU_EXTRACT); - } - else - { - menu.addAction(tr("Explore"))->setData(MENU_EXPLORE); - } - menu.addSeparator(); - action = menu.addAction(tr("Duplicate")); - action->setShortcut(tr("Ctrl+D")); - action->setData(MENU_DUPLICATE); - menu.addAction(tr("Rename\tF2"))->setData(MENU_RENAME); - action = menu.addAction(tr("Delete")); - action->setShortcut(QKeySequence::Delete); - action->setData(MENU_DELETE); - menu.addSeparator(); - menu.addAction(tr("Assign to Selected Objects"))->setData(MENU_ASSIGNTOSELECTION); - menu.addAction(tr("Select Assigned Objects"))->setData(MENU_SELECTASSIGNEDOBJECTS); - menu.addSeparator(); - - menu.addAction(tr("Add New Material"))->setData(MENU_ADDNEW); - menu.addAction(tr("Add New Multi Material"))->setData(MENU_ADDNEW_MULTI); - menu.addAction(tr("Merge (Select two or more)"))->setEnabled(false); - - AddContextMenuActionsSourceControl(menu, material, fileAttributes); -} - -void MaterialBrowserWidget::AddContextMenuActionsSourceControl(QMenu& menu, _smart_ptr material, uint32 fileAttributes) const -{ - if (GetIEditor()->IsSourceControlAvailable()) - { - menu.addSeparator(); - - if (fileAttributes & SCC_FILE_ATTRIBUTE_INPAK) - { - menu.addAction(tr(" Material In Pak (Read Only)"))->setEnabled(false); - } - else - { - menu.addAction(tr(" Source Control"))->setEnabled(false); - if (!(fileAttributes & SCC_FILE_ATTRIBUTE_MANAGED)) - { - menu.addAction(tr("Add To Source Control"))->setData(MENU_SCM_ADD); - } - } - QAction* action = nullptr; - if (fileAttributes & SCC_FILE_ATTRIBUTE_MANAGED) - { - action = menu.addAction(tr("Check Out")); - action->setData(MENU_SCM_CHECK_OUT); - action->setEnabled(fileAttributes & SCC_FILE_ATTRIBUTE_READONLY || fileAttributes & SCC_FILE_ATTRIBUTE_INPAK); - action = menu.addAction(tr("Undo Check Out")); - action->setData(MENU_SCM_UNDO_CHECK_OUT); - action->setEnabled(fileAttributes & SCC_FILE_ATTRIBUTE_CHECKEDOUT); - menu.addAction(tr("Get Latest Version"))->setData(MENU_SCM_GET_LATEST); - } - - if (material) - { - QStringList filenames; - int nTextures = material->GetTextureFilenames(filenames); - action = menu.addAction(tr("Get Textures")); - action->setData(MENU_SCM_GET_LATEST_TEXTURES); - action->setEnabled(nTextures > 0); - } - } -} - -void MaterialBrowserWidget::ShowContextMenu(const CMaterialBrowserRecord& record, const QPoint& point) -{ - _smart_ptr material = record.m_material; - - // Create pop up menu. - QMenu menu; - if (m_markedRecords.size() >= 2) // it makes sense when we have at least two items selected - { - AddContextMenuActionsMultiSelect(menu); - } - else if (!material) // click on root, background or folder - { - AddContextMenuActionsNoSelection(menu); - } - else - { - // When right-clicking a single item in the material browser, select the parent material that was clicked, rather than the currently selected sub-material - // The context menu for sub-materials will be handled by the image list control rather than the material browser widget - m_selectedSubMaterialIndex = -1; - SetSelectedItem(material, nullptr, true); - AddContextMenuActionsSingleSelection(menu, material); - } - QAction* action = menu.exec(m_ui->treeView->mapToGlobal(point)); - const int cmd = action ? action->data().toInt() : 0; - - OnContextMenuAction(cmd, material); -} - -void MaterialBrowserWidget::OnContextMenuAction(int command, _smart_ptr material) -{ - CMaterialBrowserRecord record; - TryGetSelectedRecord(record); - switch (command) - { - case MENU_UNDEFINED: - return; // do nothing - case MENU_CUT: - OnCut(); - break; - case MENU_COPY: - OnCopy(); - break; - case MENU_COPY_NAME: - OnCopyName(); - break; - case MENU_PASTE: - OnPaste(); - break; - case MENU_EXPLORE: - { - if (material && material->IsPureChild()) - { - material = material->GetParent(); - } - - if (material) - { - QString fullPath = material->GetFilename(); - AzQtComponents::ShowFileOnDesktop(fullPath); - } - } - break; - case MENU_EXTRACT: - { - if (material && material->IsPureChild()) - { - material = material->GetParent(); - } - - if (material) - { - QString fullPath = material->GetFilename(); - if (CFileUtil::ExtractFile(fullPath, true, fullPath.toUtf8().data())) - { - AzQtComponents::ShowFileOnDesktop(fullPath); - } - } - } - break; - case MENU_DUPLICATE: - OnDuplicate(); - break; - case MENU_RENAME: - OnRenameItem(); - break; - case MENU_DELETE: - DeleteItem(record); - break; - case MENU_RESET: - OnResetItem(); - break; - case MENU_ASSIGNTOSELECTION: - { - CUndo undo("Assign Material To Selection"); - GetIEditor()->GetMaterialManager()->Command_AssignToSelection(); - break; - } - case MENU_SELECTASSIGNEDOBJECTS: - { - CUndo undo("Select Objects With Current Material"); - GetIEditor()->GetMaterialManager()->Command_SelectAssignedObjects(); - break; - } - case MENU_NUM_SUBMTL: - OnSetSubMtlCount(record); - break; - case MENU_ADDNEW: - OnAddNewMaterial(); - break; - case MENU_ADDNEW_MULTI: - OnAddNewMultiMaterial(); - break; - case MENU_CONVERT_TO_MULTI: - OnConvertToMulti(); - break; - case MENU_MERGE: - OnMergeMaterials(); - break; - - case MENU_SUBMTL_MAKE: - OnMakeSubMtlSlot(record); - break; - case MENU_SUBMTL_CLEAR: - OnClearSubMtlSlot(material); - break; - - case MENU_SCM_ADD: - DoSourceControlOp(record, ESCM_IMPORT); - break; - case MENU_SCM_CHECK_OUT: - DoSourceControlOp(record, ESCM_CHECKOUT); - break; - case MENU_SCM_UNDO_CHECK_OUT: - DoSourceControlOp(record, ESCM_UNDO_CHECKOUT); - break; - case MENU_SCM_GET_LATEST: - DoSourceControlOp(record, ESCM_GETLATEST); - break; - case MENU_SCM_GET_LATEST_TEXTURES: - DoSourceControlOp(record, ESCM_GETLATESTTEXTURES); - break; - - case MENU_SAVE_TO_FILE: - OnSaveToFile(false); - break; - case MENU_SAVE_TO_FILE_MULTI: - OnSaveToFile(true); - break; - //case MENU_MAKE_SUBMTL: OnAddNewMultiMaterial(); break; - } -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::PopulateItems() -{ - if (m_bIgnoreSelectionChange) - { - return; - } - - if (m_bItemsValid) - { - return; - } - - m_bItemsValid = true; - m_bIgnoreSelectionChange = true; - - IDataBaseItem* pSelection = m_pMatMan->GetSelectedItem(); - IDataBaseItem* pSelectionParent = m_pMatMan->GetSelectedParentItem(); - - m_bIgnoreSelectionChange = false; - - if (pSelection) - { - SelectItem(pSelection, pSelectionParent); - if (m_bHighlightMaterial) - { - m_bHighlightMaterial = false; - m_pMatMan->SetHighlightedMaterial(0); - } - } -} - -void MaterialBrowserWidget::StartRecordUpdateJobs() -{ - m_filterModel->StartRecordUpdateJobs(); -} - -////////////////////////////////////////////////////////////////////////// -uint32 MaterialBrowserWidget::MaterialNameToCrc32(const QString& str) -{ - return CCrc32::ComputeLowercase(str.toUtf8()); -} - -////////////////////////////////////////////////////////////////////////// -bool MaterialBrowserWidget::TryGetSelectedRecord(CMaterialBrowserRecord& record) -{ - QVariant variant = m_filterModel->data(m_ui->treeView->currentIndex(), Qt::UserRole); - if (variant.isValid()) - { - record = variant.value(); - return true; - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -_smart_ptr MaterialBrowserWidget::GetCurrentMaterial() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found && record.m_material) - { - if (record.m_material->IsMultiSubMaterial() && m_selectedSubMaterialIndex >= 0) - { - return record.m_material->GetSubMaterial(m_selectedSubMaterialIndex); - } - else - { - return record.m_material; - } - } - - return m_pMatMan->GetCurrentMaterial(); -} - -////////////////////////////////////////////////////////////////////////// -AZStd::string MaterialBrowserWidget::GetSelectedMaterialID() -{ - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (found) - { - return record.GetRelativeFilePath(); - } - return AZStd::string(); -} - -////////////////////////////////////////////////////////////////////////// -void MaterialBrowserWidget::OnSelectionChanged() -{ - m_selectedSubMaterialIndex = -1; - TMaterialBrowserRecords markedRecords; - - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - for (const QModelIndex& row : m_ui->treeView->selectionModel()->selectedRows()) - { - QVariant userRole = row.data(Qt::UserRole); - if (userRole.isValid()) - { - CMaterialBrowserRecord currentRecord = userRole.value(); - markedRecords.push_back(currentRecord); - } - } - - if (!found && !markedRecords.empty()) - { - record = markedRecords.front(); - found = true; - } - if (found) - { - // Since the call to SetSelectedItem is coming from an OnSelectionChanged event, the appropriate - // element of the tree view has already been selected. Pass in false for the selectInTreeView argument - // to prevent SetSelectedItem from trying to re-select the material in the browser - SetSelectedItem(record.m_material, &markedRecords, false); - } -} - -void MaterialBrowserWidget::OnRefreshSelection() -{ - // force RefreshSelected to repopulate by setting m_pLastActiveMultiMaterial to null - // so it thinks we selected a new material. - m_pLastActiveMultiMaterial = nullptr; - - //If no material is selected, clear preview. - if (!GetCurrentMaterial()) - { - if (m_pMaterialImageListCtrl) - { - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - materialModel->DeleteAllItems(); - } - } - - RefreshSelected(); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } -} - -void MaterialBrowserWidget::OnMaterialAdded() -{ - if (m_delayedSelection) - { - SetSelectedItem(m_delayedSelection, nullptr, true); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } - } -} - -void MaterialBrowserWidget::OnSubMaterialSelectedInPreviewPane(const QModelIndex& current) -{ - if (!m_pMaterialImageListCtrl) - { - return; - } - - QMaterialImageListModel* materialModel = - qobject_cast(m_pMaterialImageListCtrl->model()); - Q_ASSERT(materialModel); - - int nSlot = (INT_PTR)materialModel->UserDataFromIndex(current); - if (nSlot < 0) - { - return; - } - - CMaterialBrowserRecord record; - bool found = TryGetSelectedRecord(record); - if (!found || !record.m_material) - { - return; - } - - if (!record.m_material->IsMultiSubMaterial()) - { - return; // must be multi sub material. - } - if (nSlot >= record.m_material->GetSubMaterialCount()) - { - return; - } - - if (nSlot == m_selectedSubMaterialIndex) - { - return; - } - - m_selectedSubMaterialIndex = nSlot; - - SetSelectedItem(record.m_material, nullptr, false); -} - -void MaterialBrowserWidget::SaveCurrentMaterial() -{ - // Saving might open a modal dialog asking to overwrite, therefore don't run this from DTOR, might crash - - _smart_ptr pCurrentMtl = GetCurrentMaterial(); - if (pCurrentMtl && pCurrentMtl->IsModified()) - { - pCurrentMtl->Save(); - } -} - -void MaterialBrowserWidget::expandAllNotMatchingIndexes(const QModelIndex& parent) -{ - if (!parent.isValid()) - { - m_ui->treeView->collapseAll(); - } - - const int rowCount = m_ui->treeView->model()->rowCount(parent); - for (int row = 0; row < rowCount; ++row) - { - const QModelIndex index = m_ui->treeView->model()->index(row, 0, parent); - const QString text = index.data().toString(); - bool contains = true; - m_ui->treeView->setExpanded(index, !contains); - if (!contains) - { - expandAllNotMatchingIndexes(index); - } - } -} - -void MaterialBrowserWidget::MaterialAddFinished() -{ - emit materialAdded(); -} - -void MaterialBrowserWidget::MaterialFinishedProcessing(_smart_ptr material, const QPersistentModelIndex& filterModelIndex) -{ - // If the currently selected material finished processing - if (filterModelIndex.isValid() && filterModelIndex == m_ui->treeView->currentIndex()) - { - // Stash the delayed selection so that it is not cleared just because the currently selected material finished processing - _smart_ptr tempDelayedSelection = m_delayedSelection; - - // Re-select the material to update the material dialogue - // but ignore the tree-view selection since the current index is already the correct one for this material - SetSelectedItem(material, nullptr, false); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } - - if (material != m_delayedSelection) - { - // If the current selection that just finished processing was not the delayed selection, restore the delayed selection - m_delayedSelection = tempDelayedSelection; - } - } - // If there was a failed attempt to select the material before it finished processing - else if (m_delayedSelection && m_delayedSelection == material) - { - // Re-select the material to update the material dialogue - // and also select the material in the tree-view - SetSelectedItem(material, nullptr, true); - - // Force update the material dialog - if (m_pListener) - { - m_pListener->OnBrowserSelectItem(GetCurrentMaterial(), true); - } - } -} - -void MaterialBrowserWidget::MaterialRecordUpdateFinished() -{ - //The event is sent by a AZJob working thread, need to emit a signal here for qt to catch later. - //It can make sure all the qt functions need to be called at this point are only executed in the qt thread. - emit refreshSelection(); -} - - -#include diff --git a/Code/Sandbox/Editor/Material/MaterialBrowser.h b/Code/Sandbox/Editor/Material/MaterialBrowser.h deleted file mode 100644 index d02045bacd..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowser.h +++ /dev/null @@ -1,248 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALBROWSER_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALBROWSER_H -#pragma once - - -#if !defined(Q_MOC_RUN) -#include "Include/IDataBaseManager.h" -#include "Material/Material.h" -#include "Material/MaterialBrowserFilterModel.h" - -#include -#include -#include -#include - -#include -#endif - -class CMaterial; - -class MaterialBrowserWidget; -class CMaterialImageListCtrl; -class QMaterialImageListModel; - -class QTreeView; -class QAction; - -struct IDataBaseItem; -class CMaterialBrowserRecord; -typedef std::vector TMaterialBrowserRecords; - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - class AssetBrowserModel; - class AssetBrowserFilterModel; - class AssetTypeFilter; - } -} - -enum ESccFileAttributes; - -namespace Ui -{ - class MaterialBrowser; -} - - -////////////////////////////////////////////////////////////////////////// -struct IMaterialBrowserListener -{ - virtual void OnBrowserSelectItem(IDataBaseItem* pItem, bool bForce) = 0; -}; - -////////////////////////////////////////////////////////////////////////// -// MaterialBrowserWidget -////////////////////////////////////////////////////////////////////////// -class MaterialBrowserFilterModel; - -class MaterialBrowserWidget - : public QWidget - , public IDataBaseManagerListener - , public IEditorNotifyListener - , public MaterialBrowserWidgetBus::Handler -{ - Q_OBJECT - -public: - enum EViewType - { - VIEW_LEVEL = 0, - VIEW_ALL = 1, - }; - - enum EFilter - { - eFilter_Materials = 0x01, - eFilter_Textures = 0x02, - eFilter_Materials_And_Textures = 0x03, - eFilter_Submaterials = 0x04 - }; - - MaterialBrowserWidget(QWidget* parent); - ~MaterialBrowserWidget(); - - void SetListener(IMaterialBrowserListener* pListener) { m_pListener = pListener; } - - EViewType GetViewType() const { return m_viewType; }; - - void ClearItems(); - - void SelectItem(IDataBaseItem* pItem, IDataBaseItem* pParentItem); - void DeleteItem(); - - void PopulateItems(); - void StartRecordUpdateJobs(); - - bool ShowCheckedOutRecursive(TMaterialBrowserRecords* pRecords); - - void ShowOnlyLevelMaterials(bool levelOnly); - - void OnCopy(); - void OnCopyName(); - void OnPaste(); - void OnCut(); - void OnDuplicate(); - void OnAddNewMaterial(); - void OnAddNewMultiMaterial(); - void OnConvertToMulti(); - void OnMergeMaterials(); - -public slots: - void OnSelectionChanged(); - void OnSubMaterialSelectedInPreviewPane(const QModelIndex& current); - void SaveCurrentMaterial(); - void OnRefreshSelection(); - void OnMaterialAdded(); - -signals: - void refreshSelection(); - void materialAdded(); - -public: - void OnUpdateShowCheckedOut(); - bool CanPaste() const; - - void SetImageListCtrl(CMaterialImageListCtrl* pCtrl); - - ////////////////////////////////////////////////////////////////////////// - // IDataBaseManagerListener implementation. - ////////////////////////////////////////////////////////////////////////// - virtual void OnDataBaseItemEvent(IDataBaseItem* pItem, EDataBaseItemEvent event); - ////////////////////////////////////////////////////////////////////////// - - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event); - void AddContextMenuActionsSingleSelection(QMenu &menu, _smart_ptr material) const; - void OnContextMenuAction(int command, _smart_ptr material); - - // MaterialBrowserWidgetBus event handlers - void MaterialAddFinished() override; - void MaterialFinishedProcessing(_smart_ptr material, const QPersistentModelIndex &filterModelIndex) override; - void MaterialRecordUpdateFinished() override; - -protected: - // Item definition. - enum ESourceControlOp - { - ESCM_IMPORT, - ESCM_CHECKOUT, - ESCM_UNDO_CHECKOUT, - ESCM_GETLATEST, - ESCM_GETLATESTTEXTURES, - }; - - void DeleteItem(const CMaterialBrowserRecord &record); - void SetSelectedItem(_smart_ptr material, const TMaterialBrowserRecords* pMarkedRecords, bool selectInTreeView); - void OnAddSubMtl(); - void OnSelectAssignedObjects(); - void OnAssignMaterialToSelection(); - void OnRenameItem(); - void OnResetItem(); - void OnSetSubMtlCount(const CMaterialBrowserRecord &record); - - void DoSourceControlOp(CMaterialBrowserRecord &record, ESourceControlOp); - - void OnMakeSubMtlSlot(const CMaterialBrowserRecord &record); - void OnClearSubMtlSlot(_smart_ptr subMaterial); - void SetSubMaterial(_smart_ptr parentMaterial, int slot, _smart_ptr subMaterial); - - void OnSaveToFile(bool bMulti); - - void RefreshSelected(); - - void TickRefreshMaterials(); - void TryLoadRecordMaterial(CMaterialBrowserRecord &record); - - void ShowContextMenu(const CMaterialBrowserRecord &record, const QPoint& point); - _smart_ptr GetCurrentMaterial(); - - uint32 MaterialNameToCrc32(const QString& str); - - bool TryGetSelectedRecord(CMaterialBrowserRecord &record); - AZStd::string GetSelectedMaterialID(); - -private: - void expandAllNotMatchingIndexes(const QModelIndex& parent = QModelIndex()); - void ClearImageListControlSelection(); - void ClearSelection(QMaterialImageListModel* materialModel); - QMenu *InitializeSearchMenu(); - - void AddContextMenuActionsMultiSelect(QMenu &menu) const; - void AddContextMenuActionsNoSelection(QMenu &menu) const; - void AddContextMenuActionsSubMaterial(QMenu &menu, _smart_ptr parentMaterial, _smart_ptr subMaterial) const; - void AddContextMenuActionsMultiMaterial(QMenu &menu) const; - void AddContextMenuActionsSingleMaterial(QMenu &menu) const; - void AddContextMenuActionsCommon(QMenu &menu, _smart_ptr material) const; - void AddContextMenuActionsSourceControl(QMenu &menu, _smart_ptr material, uint32 fileAttributes) const; - - QScopedPointer m_ui; - - AzToolsFramework::AssetBrowser::AssetBrowserModel* m_assetBrowserModel; - QSharedPointer m_filterModel; - int m_selectedSubMaterialIndex = -1; - - bool m_bIgnoreSelectionChange; - bool m_bItemsValid; - - CMaterialManager* m_pMatMan; - IMaterialBrowserListener* m_pListener; - CMaterialImageListCtrl* m_pMaterialImageListCtrl; - - EViewType m_viewType; - bool m_bNeedReload; - - bool m_bHighlightMaterial; - uint32 m_timeOfHighlight; - - TMaterialBrowserRecords m_markedRecords; - - _smart_ptr m_pLastActiveMultiMaterial; - _smart_ptr m_delayedSelection; - - bool m_bShowOnlyCheckedOut; - - QAction* m_cutAction; - QAction* m_copyAction; - QAction* m_pasteAction; - QAction* m_duplicateAction; - QAction* m_deleteAction; - QAction* m_renameItemAction; - QAction* m_addNewMaterialAction; -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALBROWSER_H diff --git a/Code/Sandbox/Editor/Material/MaterialBrowser.ui b/Code/Sandbox/Editor/Material/MaterialBrowser.ui deleted file mode 100644 index 44e4e135ef..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowser.ui +++ /dev/null @@ -1,87 +0,0 @@ - - - MaterialBrowser - - - - 0 - 0 - 250 - 400 - - - - Form - - - - 0 - - - 2 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - - 147 - 22 - - - - - - - - - - - 0 - 0 - - - - Qt::CustomContextMenu - - - QAbstractItemView::ExtendedSelection - - - false - - - - - - - - AzToolsFramework::AssetBrowser::SearchWidget - QWidget -
AzToolsFramework/AssetBrowser/Search/SearchWidget.h
- 1 -
- - AzToolsFramework::AssetBrowser::AssetBrowserTreeView - QTreeView -
AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.h
-
-
- - - - -
diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.cpp b/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.cpp deleted file mode 100644 index 9f145c4daf..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.cpp +++ /dev/null @@ -1,652 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "MaterialBrowserFilterModel.h" - -// AzFramework -#include - -// AzToolsFramework -#include -#include -#include -#include - -// Editor -#include "MaterialBrowserSearchFilters.h" -#include "MaterialManager.h" - - -namespace -{ - // how often to re-query source control status of an item after querying it, in seconds. - // note that using a source control operation on an item invalidates the cache and will immediately - // refresh its status regardless of this value, so it can be pretty high. - qint64 g_timeRefreshSCCStatus = 60; -} - -#define IDC_MATERIAL_TREECTRL 3 - -////////////////////////////////////////////////////////////////////////// -#define ITEM_IMAGE_SHARED_MATERIAL 0 -#define ITEM_IMAGE_SHARED_MATERIAL_SELECTED 1 -#define ITEM_IMAGE_FOLDER 2 -#define ITEM_IMAGE_FOLDER_OPEN 3 -#define ITEM_IMAGE_MATERIAL 4 -#define ITEM_IMAGE_MATERIAL_SELECTED 5 -#define ITEM_IMAGE_MULTI_MATERIAL 6 -#define ITEM_IMAGE_MULTI_MATERIAL_SELECTED 7 - - -#define ITEM_IMAGE_OVERLAY_CGF 8 -#define ITEM_IMAGE_OVERLAY_INPAK 9 -#define ITEM_IMAGE_OVERLAY_READONLY 10 -#define ITEM_IMAGE_OVERLAY_ONDISK 11 -#define ITEM_IMAGE_OVERLAY_LOCKED 12 -#define ITEM_IMAGE_OVERLAY_CHECKEDOUT 13 -#define ITEM_IMAGE_OVERLAY_NO_CHECKOUT 14 -////////////////////////////////////////////////////////////////////////// - -AZ::Data::AssetId GetMaterialProductAssetIdFromAssetBrowserEntry(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry) -{ - using namespace AzToolsFramework::AssetBrowser; - - if (assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Source || - assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product) - { - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - // Cache the material asset type because this function is called for every submaterial when searching. - // AssetType is a POD struct so it should be fine to leave it as a static that gets destroyed during library unload/program termination. - static AZ::Data::AssetType materialAssetType = AZ::Data::AssetType::CreateNull(); - if (materialAssetType.IsNull()) - { - EBusFindAssetTypeByName materialAssetTypeResult("Material"); - AZ::AssetTypeInfoBus::BroadcastResult(materialAssetTypeResult, &AZ::AssetTypeInfo::GetAssetType); - AZ_Assert(materialAssetTypeResult.Found(), "Could not find asset type for material asset"); - materialAssetType = materialAssetTypeResult.GetAssetType(); - } - - for (const auto* product : products) - { - if (product->GetAssetType() == materialAssetType) - { - return product->GetAssetId(); - } - } - } - return AZ::Data::AssetId(); -} - -MaterialBrowserFilterModel::MaterialBrowserFilterModel(QObject* parent) - : AzToolsFramework::AssetBrowser::AssetBrowserFilterModel(parent) -{ - using namespace AzToolsFramework::AssetBrowser; - using namespace AzToolsFramework::MaterialBrowser; - - MaterialBrowserSourceControlBus::Handler::BusConnect(); - AssetBrowserModelNotificationBus::Handler::BusConnect(); - MaterialBrowserRequestBus::Handler::BusConnect(); - AzFramework::AssetCatalogEventBus::Handler::BusConnect(); - - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_00.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_01.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_02.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_03.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_04.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_05.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_06.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/material_07.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_00.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_01.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_02.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_03.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_04.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_05.png")); - m_imageList.push_back(QPixmap(":/MaterialBrowser/images/filestatus_06.png")); - - - // Create an asset type filter for materials - AssetTypeFilter* assetTypeFilter = new AssetTypeFilter(); - assetTypeFilter->SetAssetType("Material"); - assetTypeFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Down); //this will make sure folders that contain materials are displayed - m_assetTypeFilter = FilterConstType(assetTypeFilter); - - // Create search filters. SetSearchFilter stores these filters so that they are deleted when this object is deleted. - m_subMaterialSearchFilter = new SubMaterialSearchFilter(this); - m_levelMaterialSearchFilter = new LevelMaterialSearchFilter(this); - - InitializeRecordUpdateJob(); -} - -MaterialBrowserFilterModel::~MaterialBrowserFilterModel() -{ - SAFE_DELETE(m_jobCancelGroup); - SAFE_DELETE(m_jobContext); - SAFE_DELETE(m_jobManager); - - AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler::BusDisconnect(); - MaterialBrowserSourceControlBus::Handler::BusDisconnect(); - AzToolsFramework::MaterialBrowser::MaterialBrowserRequestBus::Handler::BusDisconnect(); - AzFramework::AssetCatalogEventBus::Handler::BusDisconnect(); -} - -void MaterialBrowserFilterModel::UpdateRecord(const QModelIndex& filterModelIndex) -{ - using namespace AzToolsFramework::AssetBrowser; - - if (filterModelIndex.isValid()) - { - QModelIndex modelIndex = mapToSource(filterModelIndex); - - AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - if (assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Source || - assetEntry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product) - { - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - for (const auto* product : products) - { - if (!m_assetTypeFilter->Match(product)) - { - continue; - } - MaterialBrowserRecordAssetBrowserData assetBrowserData; - assetBrowserData.assetId = product->GetAssetId(); - assetBrowserData.relativeFilePath = product->GetRelativePath(); - assetBrowserData.fullSourcePath = product->GetFullPath(); - assetBrowserData.modelIndex = modelIndex; - assetBrowserData.filterModelIndex = filterModelIndex; - UpdateRecord(assetBrowserData); - } - } - } -} - -void MaterialBrowserFilterModel::UpdateRecord(const MaterialBrowserRecordAssetBrowserData& assetBrowserData) -{ - CMaterialBrowserRecord record; - record.SetAssetBrowserData(assetBrowserData); - record.m_material = GetIEditor()->GetMaterialManager()->LoadMaterial(record.GetRelativeFilePath().c_str()); - SetRecord(record); -} - -void MaterialBrowserFilterModel::UpdateSourceControlFileInfoCallback(const AZ::Data::AssetId& assetId, const AzToolsFramework::SourceControlFileInfo& info) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - // Update the cached source control attributes for the record - record.m_lastCachedSCCAttributes = info; - record.m_lastCachedFileAttributes = static_cast(CFileUtil::GetAttributes(record.GetFullSourcePath().c_str(), false)); - record.m_lastCheckedSCCAttributes = QDateTime::currentDateTime(); - - // Update the record - m_materialRecordMap.erase(assetId); - m_materialRecordMap.insert(AZStd::pair(record.GetAssetId(), record)); - - QueueDataChangedEvent(record.GetFilterModelIndex()); - } -} - -void MaterialBrowserFilterModel::UpdateSourceControlLastCheckedTime(const AZ::Data::AssetId& assetId, const QDateTime& dateTime) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - // Update the record - record.m_lastCheckedSCCAttributes = dateTime; - m_materialRecordMap.erase(assetId); - m_materialRecordMap.insert(AZStd::pair(record.GetAssetId(), record)); - } -} - -QVariant MaterialBrowserFilterModel::data(const QModelIndex& index, int role /* = Qt::DisplayRole*/) const -{ - // Should return data from an AssetBrowserEntry, or get material specific info from that data - if (index.isValid()) - { - // Use the base AssetBrowserFilterModel::data function for display role - if (role != AzToolsFramework::AssetBrowser::AssetBrowserModel::Roles::EntryRole) - { - QModelIndex modelIndex = mapToSource(index); - AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - AZ::Data::AssetId assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(assetEntry); - if (assetId.IsValid()) - { - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - - if (role == Qt::UserRole) - { - if (found) - { - return QVariant::fromValue(record); - } - else - { - return QVariant(); - } - } - } - } - } - // If the role is Qt::DisplayRole, the item a folder, or the material has not been parsed yet, fall back on the default data result from the underlying AssetBrowserModel - return AzToolsFramework::AssetBrowser::AssetBrowserFilterModel::data(index, role); -} - -void MaterialBrowserFilterModel::GetRelativeFilePaths(AZStd::vector& files) const -{ - GetRelativeFilePathsRecursive(files, this); -} - -void MaterialBrowserFilterModel::GetRelativeFilePathsRecursive(AZStd::vector& files, - const MaterialBrowserFilterModel* model, const QModelIndex& parent) const -{ - using namespace AzToolsFramework::AssetBrowser; - - for (int r = 0; r < model->rowCount(parent); ++r) - { - QModelIndex index = model->index(r, 0, parent); - QModelIndex modelIndex = model->mapToSource(index); - - if (model->hasChildren(index)) - { - GetRelativeFilePathsRecursive(files, model, index); - } - else - { - AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - for (const auto* product : products) - { - if (!m_assetTypeFilter->Match(product)) - { - continue; - } - MaterialBrowserRecordAssetBrowserData item; - item.assetId = product->GetAssetId(); - item.fullSourcePath = product->GetFullPath(); - item.relativeFilePath = product->GetRelativePath(); - item.modelIndex = modelIndex; - item.filterModelIndex = index; - files.push_back(item); - } - } - } -} - -QModelIndex MaterialBrowserFilterModel::GetIndexFromMaterial(_smart_ptr material) const -{ - CMaterialBrowserRecord record; - bool found = TryGetRecordFromMaterial(material, record); - if (found) - { - return record.GetFilterModelIndex(); - } - return QModelIndex(); -} - -QModelIndex MaterialBrowserFilterModel::GetFilterModelIndex(const AZ::Data::AssetId& assetId) const -{ - QModelIndex filterModelIndex; - if (TryGetFilterModelIndexRecursive(filterModelIndex, assetId, this)) - { - return filterModelIndex; - } - - return QModelIndex(); -} - -bool MaterialBrowserFilterModel::TryGetFilterModelIndexRecursive(QModelIndex& filterModelIndex, - const AZ::Data::AssetId& assetId, const MaterialBrowserFilterModel* model, const QModelIndex& parent) const -{ - using namespace AzToolsFramework::AssetBrowser; - - // Walk through the filter model to find the product entry with the corresponding assetId - for (int r = 0; r < model->rowCount(parent); ++r) - { - QModelIndex index = model->index(r, 0, parent); - QModelIndex modelIndex = model->mapToSource(index); - - if (model->hasChildren(index)) - { - if (TryGetFilterModelIndexRecursive(filterModelIndex, assetId, model, index)) - { - return true; - } - } - else - { - // Check to see if the current entry is the one we're looking for - AssetBrowserEntry* assetEntry = static_cast(modelIndex.internalPointer()); - - AZStd::vector products; - assetEntry->GetChildrenRecursively(products); - - for (const auto* product : products) - { - if (assetId == product->GetAssetId()) - { - filterModelIndex = index; - return true; - } - } - } - } - - return false; -} - -void MaterialBrowserFilterModel::EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) -{ - // If the entry is a product material - if (entry->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Product && m_assetTypeFilter->Match(entry)) - { - // capture the data here, so that entry cannot disappear before we actually get to the job. - MaterialBrowserRecordAssetBrowserData assetBrowserData; - assetBrowserData.assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(entry); - assetBrowserData.relativeFilePath = entry->GetRelativePath(); - assetBrowserData.fullSourcePath = entry->GetFullPath(); - assetBrowserData.filterModelIndex = GetFilterModelIndex(assetBrowserData.assetId); - - // Create a job to add/update the entry in the underlying map - AZ::Job* updateEntryJob = AZ::CreateJobFunction([this, assetBrowserData]() - { - CMaterialBrowserRecord record; - record.SetAssetBrowserData(assetBrowserData); - record.m_material = GetIEditor()->GetMaterialManager()->LoadMaterialWithFullSourcePath(record.GetRelativeFilePath().c_str(), record.GetFullSourcePath().c_str()); - SetRecord(record); - MaterialBrowserWidgetBus::Broadcast(&MaterialBrowserWidgetEvents::MaterialAddFinished); - }, true, m_jobContext); - - // Start the job immediately - AZ::Job* currentJob = m_jobContext->GetJobManager().GetCurrentJob(); - if (currentJob) - { - // Suspend the current job until the new job completes so that - // if a new material is created by the user it's ready to use sooner - currentJob->StartAsChild(updateEntryJob); - currentJob->WaitForChildren(); - } - else - { - updateEntryJob->Start(); - } - } -} - - -void MaterialBrowserFilterModel::OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - record.m_material->Reload(); - //Send out event to notify UI update if it's currently selected - MaterialBrowserWidgetBus::Broadcast(&MaterialBrowserWidgetEvents::MaterialFinishedProcessing, record.m_material, record.GetFilterModelIndex()); - } -} - -bool MaterialBrowserFilterModel::HasRecord(const AZ::Data::AssetId& assetId) -{ - return m_materialRecordMap.find(assetId); -} - -bool MaterialBrowserFilterModel::IsMultiMaterial(const AZ::Data::AssetId& assetId) -{ - CMaterialBrowserRecord record; - bool found = m_materialRecordMap.find(assetId, &record); - if (found) - { - if (record.m_material && record.m_material->IsMultiSubMaterial()) - { - return true; - } - } - return false; -} - -bool MaterialBrowserFilterModel::TryGetRecordFromMaterial(_smart_ptr material, CMaterialBrowserRecord& record) const -{ - if (material) - { - // Get the relative path for the material - bool pathFound = false; - AZStd::string relativePath; - AzToolsFramework::AssetSystemRequestBus::BroadcastResult(pathFound, &AzToolsFramework::AssetSystem::AssetSystemRequest::GetRelativeProductPathFromFullSourceOrProductPath, material->GetFilename().toUtf8().data(), relativePath); - AZ_Assert(pathFound, "Failed to get engine relative path from %s", material->GetFilename().toUtf8().data()); - - // Get the assetId from the relative path - AZ::Data::AssetId assetId; - - AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetId, &AZ::Data::AssetCatalogRequests::GetAssetIdByPath, relativePath.c_str(), GetIEditor()->GetMaterialManager()->GetMaterialAssetType(), false); - - return TryGetRecordFromAssetId(assetId, record); - } - - return false; -} - -bool MaterialBrowserFilterModel::TryGetRecordFromAssetId(const AZ::Data::AssetId& assetId, CMaterialBrowserRecord& record) const -{ - bool recordFound = m_materialRecordMap.find(assetId, &record); - return recordFound; -} - -void MaterialBrowserFilterModel::SetRecord(const CMaterialBrowserRecord& record) -{ - m_materialRecordMap.erase(record.GetAssetId()); - m_materialRecordMap.insert({ record.GetAssetId(), record }); - - QueueDataChangedEvent(record.GetFilterModelIndex()); -} - -void MaterialBrowserFilterModel::SetSearchFilter(const AzToolsFramework::AssetBrowser::SearchWidget* searchWidget) -{ - /* - * The filter matches the following rule: - * A. If the entry is a material - * 1. The material's name matches the search text - * 2. The sub material's name matches the search text - * B. If the entry is a folder: - * 1. The folder's name matches the search text - * 2. The folder contains a material matching A - * 3. The folder contains a folder matching B.1 & B.2 - */ - - using namespace AzToolsFramework::AssetBrowser; - - m_searchWidget = searchWidget; - - // Create a search filter where a search text either matches entry/entry parent's name or sub material name - CompositeFilter* nameFilter = new CompositeFilter(CompositeFilter::LogicOperatorType::OR); - QSharedPointer searchWidgetFilter = m_searchWidget->GetFilter(); - // The default setting for search widget filter is Down - // Since now we only need to match for the entry itself in this filter, set back to None - searchWidgetFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::None); - nameFilter->AddFilter(FilterConstType(m_subMaterialSearchFilter)); - nameFilter->AddFilter(FilterConstType(searchWidgetFilter)); - - EntryTypeFilter* productsFilter = new EntryTypeFilter(); - productsFilter->SetEntryType(AssetBrowserEntry::AssetEntryType::Product); - InverseFilter* noProductsFilter = new InverseFilter(); - noProductsFilter->SetFilter(FilterConstType(productsFilter)); - - // Create a filter where the entry needs to match the previous name filter and it needs to be material itself or it contains material. - CompositeFilter* isMaterialAndMatchesSearchFilter = new CompositeFilter(CompositeFilter::LogicOperatorType::AND); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(nameFilter)); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(m_assetTypeFilter)); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(noProductsFilter)); - isMaterialAndMatchesSearchFilter->AddFilter(FilterConstType(m_levelMaterialSearchFilter)); - // Make sure any folder contains the matching result is included - isMaterialAndMatchesSearchFilter->SetFilterPropagation(AssetBrowserEntryFilter::PropagateDirection::Down); - - // Set the filter for the MaterialBrowserFilterModel - SetFilter(FilterConstType(isMaterialAndMatchesSearchFilter)); -} - -void MaterialBrowserFilterModel::ShowOnlyLevelMaterials(bool levelOnly, bool invalidateFilterNow) -{ - m_levelMaterialSearchFilter->ShowOnlyLevelMaterials(levelOnly); - if (levelOnly) - { - m_levelMaterialSearchFilter->CacheLoadedMaterials(); - } - - if (invalidateFilterNow) - { - // we need to invalid the filter immediately, for example this is used when we are changing level, otherwise - // the current filter is used when getting file paths for all of the materials as part of StartRecordUpdateJobs. - invalidateFilter(); - } - else - { - filterUpdatedSlot(); - } -} - -void MaterialBrowserFilterModel::SearchFilterUpdated() -{ - m_subMaterialSearchFilter->SetFilterString(m_searchWidget->textFilter()); - filterUpdatedSlot(); -} - -void MaterialBrowserFilterModel::QueueDataChangedEvent(const QPersistentModelIndex& filterModelIndex) -{ - // Queue a data changed event to be executed on the main thread - AZStd::function emitDataChanged = - [this, filterModelIndex]() - { - if (filterModelIndex.isValid()) - { - Q_EMIT dataChanged(filterModelIndex, filterModelIndex); - } - }; - - AZ::TickBus::QueueFunction(emitDataChanged); -} - -void MaterialBrowserFilterModel::InitializeRecordUpdateJob() -{ - AZ::JobManagerDesc desc; - AZ::JobManagerThreadDesc threadDesc; - for (size_t i = 0; i < AZStd::thread::hardware_concurrency(); ++i) - { - desc.m_workerThreads.push_back(threadDesc); - } - - // Check to ensure these have not already been initialized. - AZ_Error("Material Browser", !m_jobManager && !m_jobCancelGroup && !m_jobContext, "MaterialBrowserFilterModel::InitializeRecordUpdateJob is being called again after it has already been initialized"); - m_jobManager = aznew AZ::JobManager(desc); - m_jobCancelGroup = aznew AZ::JobCancelGroup(); - m_jobContext = aznew AZ::JobContext(*m_jobManager, *m_jobCancelGroup); -} - -void MaterialBrowserFilterModel::StartRecordUpdateJobs() -{ - // Generate a list of file paths, assetId's, and asset browser model indices - // This must be done on the main thread, otherwise it can lead to a crash when the tree view UI is being initialized - AZStd::vector files; - GetRelativeFilePaths(files); - - // Kick off the background process that will iterate over the list of file paths and update the material record map - m_mainUpdateRecordJob = aznew MaterialBrowserUpdateJobCreator(this, files, m_jobContext); - m_mainUpdateRecordJob->Start(); -} - -void MaterialBrowserFilterModel::CancelRecordUpdateJobs() -{ - m_jobContext->GetCancelGroup()->Cancel(); - m_jobContext->GetCancelGroup()->Reset(); -} - -void MaterialBrowserFilterModel::ClearRecordMap() -{ - CancelRecordUpdateJobs(); - m_materialRecordMap.clear(); -} - -MaterialBrowserUpdateJobCreator::MaterialBrowserUpdateJobCreator(MaterialBrowserFilterModel* model, AZStd::vector& files, AZ::JobContext* context /*= NULL*/) - : Job(true, context) - , m_files(files) - , m_filterModel(model) -{ -} - -void MaterialBrowserUpdateJobCreator::Process() -{ - // Split the files to be processed evenly among threads - int numJobs = GetContext()->GetJobManager().GetNumWorkerThreads(); - int materialsPerJob = (m_files.size() / numJobs) + 1; - - for (auto it = m_files.begin(); it <= m_files.end(); it += materialsPerJob) - { - // Create a subset of the list of material files to be processed by another job - auto start = it; - auto end = it + materialsPerJob; - if (end > m_files.end()) - { - end = m_files.end(); - } - AZStd::vector subset(start, end); - - if (subset.size() > 0) - { - AZ::Job* materialBrowserUpdateJob = aznew MaterialBrowserUpdateJob(m_filterModel, subset, GetContext()); - StartAsChild(materialBrowserUpdateJob); - } - } - - WaitForChildren(); - - MaterialBrowserWidgetBus::Broadcast(&MaterialBrowserWidgetEvents::MaterialRecordUpdateFinished); -} - -MaterialBrowserUpdateJob::MaterialBrowserUpdateJob(MaterialBrowserFilterModel* model, AZStd::vector& files, AZ::JobContext* context /*= NULL*/) - : Job(true, context) - , m_filterModel(model) - , m_files(files) -{ -} - -void MaterialBrowserUpdateJob::Process() -{ - for (size_t i = 0; i < m_files.size(); ++i) - { - // Early out when the job is cancelled - if (IsCancelled()) - { - return; - } - CMaterialBrowserRecord record; - record.SetAssetBrowserData(m_files[i]); - - // Get the writable status of the file, but don't update source control status until it is actually needed - record.m_lastCachedFileAttributes = static_cast(CFileUtil::GetAttributes(record.GetFullSourcePath().c_str(), false)); - - record.m_material = GetIEditor()->GetMaterialManager()->LoadMaterialWithFullSourcePath(record.GetRelativeFilePath().c_str(), record.GetFullSourcePath().c_str()); - m_filterModel->SetRecord(record); - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.h b/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.h deleted file mode 100644 index afb7f8a7ce..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserFilterModel.h +++ /dev/null @@ -1,240 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - - -#include -#include - -namespace AZ -{ - class Job; - class JobManager; - class JobCancelGroup; - class JobContext; -} - -class SubMaterialSearchFilter; -class LevelMaterialSearchFilter; - -////////////////////////////////////////////////////////////////////////// -// Item class for browser. -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -struct MaterialBrowserRecordAssetBrowserData -{ - AZ::Data::AssetId assetId; - AZStd::string relativeFilePath; - AZStd::string fullSourcePath; - QPersistentModelIndex modelIndex; - QPersistentModelIndex filterModelIndex; -}; - -class CMaterialBrowserRecord -{ -public: - CMaterialBrowserRecord() - { - InitializeSourceControlAttributes(); - } - - CMaterialBrowserRecord(const CMaterialBrowserRecord &rhs) - : m_material(rhs.m_material) - , m_lastCachedSCCAttributes(rhs.m_lastCachedSCCAttributes) - , m_lastCachedFileAttributes(rhs.m_lastCachedFileAttributes) - , m_lastCheckedSCCAttributes(rhs.m_lastCheckedSCCAttributes) - , m_assetBrowserData(rhs.m_assetBrowserData) - { - } - - AZ::Data::AssetId GetAssetId() const { return m_assetBrowserData.assetId; } - AZStd::string GetRelativeFilePath() const { return m_assetBrowserData.relativeFilePath; } - AZStd::string GetFullSourcePath() const { return m_assetBrowserData.fullSourcePath; } - QPersistentModelIndex GetModelIndex() const { return m_assetBrowserData.modelIndex; } - QPersistentModelIndex GetFilterModelIndex() const { return m_assetBrowserData.filterModelIndex; } - void SetAssetBrowserData(const MaterialBrowserRecordAssetBrowserData &assetBrowserData) { m_assetBrowserData = assetBrowserData; } - void InitializeSourceControlAttributes() - { - // Force an update by setting the last update time to 1 / 1 / 1 - m_lastCachedSCCAttributes = AzToolsFramework::SourceControlFileInfo(); - m_lastCachedFileAttributes = SCC_FILE_ATTRIBUTE_INVALID; - m_lastCheckedSCCAttributes = QDate(1, 1, 1).startOfDay(); - } -public: - _smart_ptr m_material = nullptr; - AzToolsFramework::SourceControlFileInfo m_lastCachedSCCAttributes; - ESccFileAttributes m_lastCachedFileAttributes; - QDateTime m_lastCheckedSCCAttributes; - -private: - MaterialBrowserRecordAssetBrowserData m_assetBrowserData; -}; -Q_DECLARE_METATYPE(CMaterialBrowserRecord) - - -//! MaterialBrowserSourceControlEvents -//! This bus informs the material browser filter model -//! when an ASYNC source control command has completed -class MaterialBrowserSourceControlEvents - : public AZ::EBusTraits -{ -public: - typedef AZStd::recursive_mutex MutexType; - - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // there's only one listener - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; // theres only one listener - virtual ~MaterialBrowserSourceControlEvents() {} - - //! Signals the callback for the GetFileInfo source control op - virtual void UpdateSourceControlFileInfoCallback(const AZ::Data::AssetId &assetId, const AzToolsFramework::SourceControlFileInfo& fileInfo) = 0; - //! Updates the timestamp for when the source control status was last checked - virtual void UpdateSourceControlLastCheckedTime(const AZ::Data::AssetId &assetId, const QDateTime &dateTime) = 0; -}; - -using MaterialBrowserSourceControlBus = AZ::EBus; - -//! MaterialBrowserWidgetEvents -//! This bus is used to send events to the material browser widget -class MaterialBrowserWidgetEvents - : public AZ::EBusTraits -{ -public: - typedef AZStd::recursive_mutex MutexType; - - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // there's only one listener - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; // theres only one listener - virtual ~MaterialBrowserWidgetEvents() {} - - //! Indicates that a material has finished being processed by the asset processor - virtual void MaterialFinishedProcessing(_smart_ptr material, const QPersistentModelIndex &filterModelIndex) = 0; - - //! Indicates that a material has finished being added to the material browser - virtual void MaterialAddFinished() = 0; - - //! Indicates that the material record update for initially populating the material browser has finished - virtual void MaterialRecordUpdateFinished() = 0; -}; - -using MaterialBrowserWidgetBus = AZ::EBus; - -/** -* Get the product material assetId for a given AssetBrowserEntry -* If there is no valid product material, the material has not been processed, or there are multiple product materials -* and thus there is not an individual material that can be assumed based on the source, an invalid assetId is returned -* @param assetEntry An asset entry that may be a source or a product -* @return The assetId of the product material. -*/ -AZ::Data::AssetId GetMaterialProductAssetIdFromAssetBrowserEntry(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry); - -class MaterialBrowserFilterModel - : public AzToolsFramework::AssetBrowser::AssetBrowserFilterModel - , public MaterialBrowserSourceControlBus::Handler - , public AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler - , public AzToolsFramework::MaterialBrowser::MaterialBrowserRequestBus::Handler - , private AzFramework::AssetCatalogEventBus::Handler -{ -public: - AZ_CLASS_ALLOCATOR(MaterialBrowserFilterModel, AZ::SystemAllocator, 0); - MaterialBrowserFilterModel(QObject* parent); - ~MaterialBrowserFilterModel(); - void UpdateRecord(const QModelIndex& filterModelIndex); - void UpdateRecord(const MaterialBrowserRecordAssetBrowserData &assetBrowserData); - void UpdateSourceControlFileInfoCallback(const AZ::Data::AssetId &assetId, const AzToolsFramework::SourceControlFileInfo& info) override; - void UpdateSourceControlLastCheckedTime(const AZ::Data::AssetId &assetId, const QDateTime &dateTime) override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool TryGetRecordFromMaterial(_smart_ptr material, CMaterialBrowserRecord& record) const; - bool TryGetRecordFromAssetId(const AZ::Data::AssetId &assetId, CMaterialBrowserRecord& record) const; - void SetRecord(const CMaterialBrowserRecord& record); - void SetSearchFilter(const AzToolsFramework::AssetBrowser::SearchWidget* searchWidget); - void StartRecordUpdateJobs(); - void CancelRecordUpdateJobs(); - void ClearRecordMap(); - void GetRelativeFilePaths(AZStd::vector &files) const; - QModelIndex GetIndexFromMaterial(_smart_ptr material) const; - QModelIndex GetFilterModelIndex(const AZ::Data::AssetId &assetId) const; - - // AssetBrowserModelNotificationBus event handlers - void EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) override; - - void OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) override; - // MaterialBrowserRequestBus - bool HasRecord(const AZ::Data::AssetId& assetId) override; - bool IsMultiMaterial(const AZ::Data::AssetId& assetId) override; - - void ShowOnlyLevelMaterials(bool levelOnly, bool invalidateFilterNow = false); - - public Q_SLOTS: - void SearchFilterUpdated(); - -private: - void GetRelativeFilePathsRecursive(AZStd::vector &files, const MaterialBrowserFilterModel* model, const QModelIndex &parent = QModelIndex()) const; - bool TryGetFilterModelIndexRecursive(QModelIndex &filterModelIndex, const AZ::Data::AssetId &assetId, const MaterialBrowserFilterModel* model, const QModelIndex &parent = QModelIndex()) const; - void QueueDataChangedEvent(const QPersistentModelIndex &filterModelIndex); - AZStd::concurrent_unordered_map m_materialRecordMap; - QVector m_imageList; - AzToolsFramework::AssetBrowser::FilterConstType m_assetTypeFilter; - SubMaterialSearchFilter* m_subMaterialSearchFilter; - LevelMaterialSearchFilter* m_levelMaterialSearchFilter; - const AzToolsFramework::AssetBrowser::SearchWidget* m_searchWidget; - - void InitializeRecordUpdateJob(); - AZ::JobManager* m_jobManager = nullptr; - AZ::JobCancelGroup* m_jobCancelGroup = nullptr; - AZ::JobContext* m_jobContext = nullptr; - AZ::Job* m_mainUpdateRecordJob = nullptr; -}; - -/** -* Job that walks through a MaterialBrowserFilterModel to generate a list of files, -* then divides the list amongst child jobs for processing -*/ -class MaterialBrowserUpdateJobCreator - : public AZ::Job -{ -public: - AZ_CLASS_ALLOCATOR(MaterialBrowserUpdateJobCreator, AZ::ThreadPoolAllocator, 0); - - MaterialBrowserUpdateJobCreator(MaterialBrowserFilterModel* model, AZStd::vector& files, AZ::JobContext* context = nullptr); - void Process() override; -private: - MaterialBrowserFilterModel* m_filterModel; - AZStd::vector m_files; -}; - -/** -* Job that walks through a list of material files, loads them, and then populates -* the MaterialBrowserFilterModel's map of material data -*/ -class MaterialBrowserUpdateJob - : public AZ::Job -{ -public: - AZ_CLASS_ALLOCATOR(MaterialBrowserUpdateJob, AZ::ThreadPoolAllocator, 0); - - MaterialBrowserUpdateJob(MaterialBrowserFilterModel* model, AZStd::vector &files, AZ::JobContext* context = nullptr); - void Process() override; -private: - MaterialBrowserFilterModel* m_filterModel; - AZStd::vector m_files; -}; - diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.cpp b/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.cpp deleted file mode 100644 index cf2d3449d1..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "MaterialBrowserSearchFilters.h" - -// Editor -#include "MaterialBrowserFilterModel.h" -#include "Material.h" - - -SubMaterialSearchFilter::SubMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel) - : m_filterModel(filterModel) -{ - AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::SetFilterPropagation(AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::PropagateDirection::Down); -} - -void SubMaterialSearchFilter::SetFilterString(const QString& filterString) -{ - m_filterString = filterString; -} - -QString SubMaterialSearchFilter::GetNameInternal() const -{ - return "SubMaterialSearchFilter"; -} - -bool SubMaterialSearchFilter::MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const -{ - // All entries match if there is no search string - if (m_filterString.isEmpty()) - { - return true; - } - - if (m_filterModel) - { - // Get the product material for the given asset browser entry - AZ::Data::AssetId assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(entry); - if (assetId.IsValid()) - { - CMaterialBrowserRecord record; - bool found = m_filterModel->TryGetRecordFromAssetId(assetId, record); - if (found) - { - // If there is a valid product material, check to see if any of its sub-materials match the search string - if (record.m_material) - { - for (int i = 0; i < record.m_material->GetSubMaterialCount(); ++i) - { - CMaterial* subMaterial = record.m_material->GetSubMaterial(i); - if (subMaterial) - { - // If any of the product sub-materials matches the string, return true for this entry - if (subMaterial->GetName().contains(m_filterString, Qt::CaseInsensitive)) - { - return true; - } - } - } - } - } - } - } - return false; -} - -LevelMaterialSearchFilter::LevelMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel) - : m_filterModel(filterModel) -{ - AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::SetFilterPropagation(AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter::PropagateDirection::Down); -} - -QString LevelMaterialSearchFilter::GetNameInternal() const -{ - return "LoadedMaterialSearchFilter"; -} - -void LevelMaterialSearchFilter::CacheLoadedMaterials() -{ - m_localMap.clear(); - - AZStd::vector foundRenderNodes; - unsigned int numFoundObjects = 0; - - numFoundObjects = GetIEditor()->Get3DEngine()->GetObjectsByFlags(0); - foundRenderNodes.resize(numFoundObjects, nullptr); - GetIEditor()->Get3DEngine()->GetObjectsByFlags(0, foundRenderNodes.data()); - - AZStd::vector<_smart_ptr> materials; - materials.reserve(foundRenderNodes.size()); - for (IRenderNode* renderNode : foundRenderNodes) - { - renderNode->GetMaterials(materials); - } - - for (size_t i = 0; i < materials.size(); ++i) - { - if (materials[i]) - { - m_localMap[materials[i]->GetName()] = materials[i]; - } - } -} - -bool LevelMaterialSearchFilter::MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const -{ - // All entries match if show level materials isn't selected - if (!m_onlyShowLevelMaterials) - { - return true; - } - - // Get the product material for the given asset browser entry - AZ::Data::AssetId assetId = GetMaterialProductAssetIdFromAssetBrowserEntry(entry); - if (assetId.IsValid() && m_filterModel) - { - CMaterialBrowserRecord record; - bool found = m_filterModel->TryGetRecordFromAssetId(assetId, record); - if (found && record.m_material) - { - // If there is a valid product material, check to see if it is used by the level - return m_localMap.find(record.m_material->GetName()) != m_localMap.end(); - } - } - - return false; -} - -#include diff --git a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.h b/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.h deleted file mode 100644 index 4326e66218..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialBrowserSearchFilters.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include -#endif - -class MaterialBrowserFilterModel; - -//! Filter that checks the name of each sub-material in a material to see if it contains the filter string -class SubMaterialSearchFilter - : public AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter -{ - Q_OBJECT -public: - SubMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel); - ~SubMaterialSearchFilter() override = default; - - void SetFilterString(const QString& filterString); - -protected: - QString GetNameInternal() const override; - bool MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const override; - -private: - bool TextMatchesFilter(const QString &text) const; - QString m_filterString = ""; - const MaterialBrowserFilterModel* m_filterModel = nullptr; -}; - -class LevelMaterialSearchFilter - : public AzToolsFramework::AssetBrowser::AssetBrowserEntryFilter -{ - Q_OBJECT -public: - LevelMaterialSearchFilter(const MaterialBrowserFilterModel* filterModel); - ~LevelMaterialSearchFilter() override = default; - - void ShowOnlyLevelMaterials(bool onlyLevel) { m_onlyShowLevelMaterials = onlyLevel; } - - void CacheLoadedMaterials(); - -protected: - QString GetNameInternal() const override; - bool MatchInternal(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const override; - -private: - bool m_onlyShowLevelMaterials = false; - const MaterialBrowserFilterModel* m_filterModel = nullptr; - using MaterialMap = QHash >; - MaterialMap m_localMap; -}; diff --git a/Code/Sandbox/Editor/Material/MaterialDialog.qrc b/Code/Sandbox/Editor/Material/MaterialDialog.qrc deleted file mode 100644 index c99e5b052a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialDialog.qrc +++ /dev/null @@ -1,23 +0,0 @@ - - - images/material_browser_00.png - images/material_browser_01.png - images/material_browser_02.png - images/material_browser_03.png - images/material_00.png - images/material_01.png - images/material_02.png - images/material_03.png - images/material_04.png - images/material_05.png - images/material_06.png - images/material_07.png - images/filestatus_00.png - images/filestatus_01.png - images/filestatus_02.png - images/filestatus_03.png - images/filestatus_04.png - images/filestatus_05.png - images/filestatus_06.png - - diff --git a/Code/Sandbox/Editor/Material/MaterialHelpers.cpp b/Code/Sandbox/Editor/Material/MaterialHelpers.cpp deleted file mode 100644 index 8f9311a27a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialHelpers.cpp +++ /dev/null @@ -1,372 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialHelpers.h" - -namespace MaterialHelpers -{ - ////////////////////////////////////////////////////////////////////////// - static void ParsePublicParamsScript(const char* sUIScript, IVariable* pVar) - { - string uiscript = sUIScript; - string element[3]; - int p1 = 0; - string itemToken = uiscript.Tokenize(";", p1); - while (!itemToken.empty()) - { - int nElements = 0; - int p2 = 0; - string token = itemToken.Tokenize(" \t\r\n=", p2); - while (!token.empty()) - { - element[nElements++] = token; - if (nElements == 2) - { - element[nElements] = itemToken.substr(p2); - element[nElements].Trim(" =\t\""); - break; - } - token = itemToken.Tokenize(" \t\r\n=", p2); - } - - float minLimit, maxLimit; - pVar->GetLimits(minLimit, maxLimit); - - if (azstricmp(element[1], "UIWidget") == 0) - { - if (azstricmp(element[2], "Color") == 0) - { - pVar->SetDataType(IVariable::DT_COLOR); - } - } - else if (azstricmp(element[1], "UIHelp") == 0) - { - string help = element[2]; - help.replace("\\n", "\n"); - pVar->SetDescription(help); - } - else if (azstricmp(element[1], "UIName") == 0) - { - pVar->SetHumanName(element[2].c_str()); - } - else if (azstricmp(element[1], "UIMin") == 0) - { - pVar->SetLimits(atof(element[2]), maxLimit); - } - else if (azstricmp(element[1], "UIMax") == 0) - { - pVar->SetLimits(minLimit, atof(element[2])); - } - else if (azstricmp(element[1], "UIStep") == 0) - { - } - - itemToken = uiscript.Tokenize(";", p1); - } - } - - ////////////////////////////////////////////////////////////////////////// - static void AddRealNameToDescription(IVariable* pIVar, const SShaderParam* pParam) - { - // In order to help the user discover the true names of parameters, info they need using certain script functions, - // we embed the real parameter name in the description. - QString description = pIVar->GetDescription(); - if (!description.isEmpty()) - { - description += "\n"; - } - description += "(Script Param Name = "; - description += pParam->m_Name.c_str(); - description += ")"; - pIVar->SetDescription(description); - } - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetPublicVars(SInputShaderResources& pShaderResources) - { - if (pShaderResources.m_ShaderParams.empty()) - { - return 0; - } - - CVarBlock* pPublicVars = new CVarBlock; - for (int i = 0; i < pShaderResources.m_ShaderParams.size(); i++) - { - IVariable* pIVar = NULL; - SShaderParam* pParam = &pShaderResources.m_ShaderParams[i]; - - switch (pParam->m_Type) - { - case eType_BYTE: - pIVar = new CVariable(pParam->m_Value.m_Byte); - break; - case eType_SHORT: - pIVar = new CVariable(pParam->m_Value.m_Short); - break; - case eType_INT: - pIVar = new CVariable(pParam->m_Value.m_Int); - break; - case eType_FLOAT: - pIVar = new CVariable(pParam->m_Value.m_Float); - break; - /* case eType_STRING: - pIVar = new CVariable(pParam->m_Value.m_String); - break; */ - case eType_FCOLOR: - pIVar = new CVariable(Vec3(pParam->m_Value.m_Color[0], pParam->m_Value.m_Color[1], pParam->m_Value.m_Color[2])); - pIVar->SetDataType(IVariable::DT_COLOR); - break; - case eType_FCOLORA: - pIVar = new CVariable(Vec4(pParam->m_Value.m_Color[0], pParam->m_Value.m_Color[1], pParam->m_Value.m_Color[2], pParam->m_Value.m_Color[3])); - pIVar->SetDataType(IVariable::DT_COLORA); - break; - case eType_VECTOR: - pIVar = new CVariable(Vec3(pParam->m_Value.m_Vector[0], pParam->m_Value.m_Vector[1], pParam->m_Value.m_Vector[2])); - break; - default: - break; - } - - if (pIVar) - { - pIVar->SetName(pParam->m_Name.c_str()); - pPublicVars->AddVariable(pIVar); - - if (pParam->m_Script.size()) - { - ParsePublicParamsScript(pParam->m_Script.c_str(), pIVar); - } - - AddRealNameToDescription(pIVar, pParam); - } - } - - return pPublicVars; - } - - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources) - { - assert(pPublicVars); - - if (pInputShaderResources.m_ShaderParams.empty()) - { - return; - } - - int numVars = pPublicVars->GetNumVariables(); - - for (int i = 0; i < numVars; i++) - { - if (i >= numVars) - { - break; - } - - IVariable* pVar = pPublicVars->GetVariable(i); - SShaderParam* pParam = NULL; - for (int j = 0; j < pInputShaderResources.m_ShaderParams.size(); j++) - { - if (QString::compare(pVar->GetName(), pInputShaderResources.m_ShaderParams[j].m_Name.c_str()) == 0) - { - pParam = &pInputShaderResources.m_ShaderParams[j]; - break; - } - } - if (!pParam) - { - continue; - } - - switch (pParam->m_Type) - { - case eType_BYTE: - if (pVar->GetType() == IVariable::INT) - { - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Byte = val; - } - break; - case eType_SHORT: - if (pVar->GetType() == IVariable::INT) - { - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Short = val; - } - break; - case eType_INT: - if (pVar->GetType() == IVariable::INT) - { - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Int = val; - } - break; - case eType_FLOAT: - if (pVar->GetType() == IVariable::FLOAT) - { - float val = 0; - pVar->Get(val); - pParam->m_Value.m_Float = val; - } - break; - /* - case eType_STRING: - if (pVar->GetType() == IVariable::STRING) - { - CString str; - int val = 0; - pVar->Get(val); - pParam->m_Value.m_Byte = val; - } - break; - */ - case eType_FCOLOR: - case eType_FCOLORA: - if (pVar->GetType() == IVariable::VECTOR4 && (pVar->GetDataType() == IVariable::DT_COLOR || pVar->GetDataType() == IVariable::DT_COLORA)) - { - Vec4 val(0, 0, 0, 0); - pVar->Get(val); - pParam->m_Value.m_Color[0] = val.x; - pParam->m_Value.m_Color[1] = val.y; - pParam->m_Value.m_Color[2] = val.z; - pParam->m_Value.m_Color[3] = val.w; - } - else if (pVar->GetType() == IVariable::VECTOR && (pVar->GetDataType() == IVariable::DT_COLOR || pVar->GetDataType() == IVariable::DT_COLORA)) - { - Vec3 val(0, 0, 0); - pVar->Get(val); - pParam->m_Value.m_Color[0] = val.x; - pParam->m_Value.m_Color[1] = val.y; - pParam->m_Value.m_Color[2] = val.z; - } - break; - case eType_VECTOR: - if (pVar->GetType() == IVariable::VECTOR) - { - Vec3 val(0, 0, 0); - pVar->Get(val); - pParam->m_Value.m_Vector[0] = val.x; - pParam->m_Value.m_Vector[1] = val.y; - pParam->m_Value.m_Vector[2] = val.z; - } - break; - default: - break; - } - } - } - - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources, IRenderShaderResources* pRenderShaderResources, IShader* pShader) - { - SetPublicVars(pPublicVars, pInputShaderResources); - - // Set shader params. - if (pRenderShaderResources) - { - pRenderShaderResources->SetShaderParams(&pInputShaderResources, pShader); - } - } - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetShaderGenParamsVars(IShader* pShader, uint64 nShaderGenMask) - { - IShader* pTemplShader = pShader; - if (!pTemplShader) - { - return 0; - } - - SShaderGen* pShaderGen = pTemplShader->GetGenerationParams(); - if (!pShaderGen) - { - return 0; - } - - CVarBlock* pBlock = new CVarBlock; - for (int i = 0; i < pShaderGen->m_BitMask.size(); i++) - { - SShaderGenBit* pGenBit = pShaderGen->m_BitMask[i]; - if (pGenBit->m_Flags & SHGF_HIDDEN) - { - continue; - } - if (!pGenBit->m_ParamProp.empty()) - { - CVariable* pVar = new CVariable; - pBlock->AddVariable(pVar); - pVar->SetName(pGenBit->m_ParamProp.c_str()); - *pVar = (pGenBit->m_Mask & nShaderGenMask) != 0; - pVar->SetDescription(pGenBit->m_ParamDesc.c_str()); - } - } - - /* - // make sure if no valid generation parameters to not create new tab - if (!pBlock->GetVarsCount()) - { - SAFE_DELETE(pBlock); - return 0; - } - */ - - return pBlock; - } - - ////////////////////////////////////////////////////////////////////////// - uint64 SetShaderGenParamsVars(IShader* pShader, CVarBlock* pBlock) - { - IShader* pTemplShader = pShader; - if (!pTemplShader) - { - return 0; - } - - SShaderGen* pShaderGen = pTemplShader->GetGenerationParams(); - if (!pShaderGen) - { - return 0; - } - - uint64 nGenMask = 0; - - for (int i = 0; i < pShaderGen->m_BitMask.size(); i++) - { - SShaderGenBit* pGenBit = pShaderGen->m_BitMask[i]; - if (pGenBit->m_Flags & SHGF_HIDDEN) - { - continue; - } - - if (!pGenBit->m_ParamProp.empty()) - { - IVariable* pVar = pBlock->FindVariable(pGenBit->m_ParamProp.c_str()); - if (!pVar) - { - continue; - } - bool bFlagOn = false; - pVar->Get(bFlagOn); - if (bFlagOn) - { - nGenMask |= pGenBit->m_Mask; - } - } - } - - return nGenMask; - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialHelpers.h b/Code/Sandbox/Editor/Material/MaterialHelpers.h deleted file mode 100644 index 0f0228db7a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialHelpers.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once - -#include "Material.h" - -namespace MaterialHelpers -{ - ////////////////////////////////////////////////////////////////////////// - //! Get public parameters of material in variable block. - CVarBlock* GetPublicVars(SInputShaderResources& pShaderResources); - - //! Sets variable block of public shader parameters. - //! VarBlock must be in same format as returned by GetPublicVars(). - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources); - void SetPublicVars(CVarBlock* pPublicVars, SInputShaderResources& pInputShaderResources, IRenderShaderResources* pRenderShaderResources, IShader* pShader); - - ////////////////////////////////////////////////////////////////////////// - CVarBlock* GetShaderGenParamsVars(IShader* pShader, uint64 nShaderGenMask); - uint64 SetShaderGenParamsVars(IShader* pShader, CVarBlock* pBlock); - - ////////////////////////////////////////////////////////////////////////// - // [Shader System TO DO] change the usage of these functions to retrieve by slot name - inline EEfResTextures FindTexSlot(const char* texName) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().FindTexSlot(texName); } - inline const char* FindTexName(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().FindTexName(texSlot); } - inline const char* LookupTexName(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().LookupTexName(texSlot); } - inline const char* LookupTexDesc(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().LookupTexDesc(texSlot); } - - //-------------------------------------------------------------------------- - // Adjustable means that the slot is not virtual, i.e. using a sub-channel from another - // slot (for example - smoothness that uses the normal's alpha) - inline bool IsAdjustableTexSlot(EEfResTextures texSlot) { return GetIEditor()->Get3DEngine()->GetMaterialHelpers().IsAdjustableTexSlot(texSlot); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetTexModFromXml(SEfTexModificator& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetTexModFromXml(pShaderResources, node); } - inline void SetXmlFromTexMod(const SEfTexModificator& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromTexMod(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetTexturesFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetTexturesFromXml(pShaderResources, node); } - inline void SetXmlFromTextures( SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromTextures(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetVertexDeformFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetVertexDeformFromXml(pShaderResources, node); } - inline void SetXmlFromVertexDeform(const SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromVertexDeform(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetLightingFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetLightingFromXml(pShaderResources, node); } - inline void SetXmlFromLighting(const SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromLighting(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void SetShaderParamsFromXml(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetShaderParamsFromXml(pShaderResources, node); } - inline void SetXmlFromShaderParams(const SInputShaderResources& pShaderResources, XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().SetXmlFromShaderParams(pShaderResources, node); } - - ////////////////////////////////////////////////////////////////////////// - inline void MigrateXmlLegacyData(SInputShaderResources& pShaderResources, const XmlNodeRef& node) { GetIEditor()->Get3DEngine()->GetMaterialHelpers().MigrateXmlLegacyData(pShaderResources, node); } -} diff --git a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.cpp b/Code/Sandbox/Editor/Material/MaterialImageListCtrl.cpp deleted file mode 100644 index 6ebc85c1bc..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.cpp +++ /dev/null @@ -1,834 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialImageListCtrl.h" - -// Qt -#include - -// Editor -#include "Material.h" -#include "MaterialManager.h" -#include "MaterialPreviewModelView.h" -#include "MaterialBrowser.h" -#include "Util/Image.h" - -#define ME_BG_TEXTURE "Materials/Stripes.dds" - - -#define MATERIAL_EDITOR_SPHERE_MODEL_FILE "Objects/MtlSphere.cgf" -#define MATERIAL_EDITOR_SPHERE_CAMERA_RADIUS 1.6f -#define MATERIAL_EDITOR_SPHERE_CAMERA_FROM_DIRECTION Vec3(0.1f, -1.0f, -0.1f) - -#define MATERIAL_EDITOR_BOX_MODEL_FILE "Objects/MtlBox.cgf" -#define MATERIAL_EDITOR_BOX_CAMERA_RADIUS 2.0f -#define MATERIAL_EDITOR_BOX_CAMERA_FROM_DIRECTION Vec3(0.75f, -0.75f, -0.5f) - -#define MATERIAL_EDITOR_TEAPOT_MODEL_FILE "Objects/MtlTeapot.cgf" -#define MATERIAL_EDITOR_TEAPOT_CAMERA_RADIUS 1.6f -#define MATERIAL_EDITOR_TEAPOT_CAMERA_FROM_DIRECTION Vec3(0.1f, -0.75f, -0.25f) - -#define MATERIAL_EDITOR_PLANE_MODEL_FILE "Objects/MtlPlane.cgf" -#define MATERIAL_EDITOR_PLANE_CAMERA_RADIUS 1.6f -#define MATERIAL_EDITOR_PLANE_CAMERA_FROM_DIRECTION Vec3(-0.5f, 0.5f, -0.5f) - -#define MATERIAL_EDITOR_SWATCH_MODEL_FILE "Objects/MtlSwatch.cgf" -#define MATERIAL_EDITOR_SWATCH_CAMERA_RADIUS 1.0f -#define MATERIAL_EDITOR_SWATCH_CAMERA_FROM_DIRECTION Vec3(0.0f, 0.0f, -1.0f) - - -_smart_ptr ResolveTerrainLayerPreviewMaterial(_smart_ptr material, _smart_ptr pMatPreview) -{ - if (!QString::compare(material->GetShaderName(), "Terrain.Layer")) - { - XmlNodeRef node = XmlHelpers::CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(node, false); - material->Serialize(ctx); - - if (!pMatPreview) - { - int flags = 0; - if (node->getAttr("MtlFlags", flags)) - { - flags |= MTL_FLAG_UIMATERIAL; - node->setAttr("MtlFlags", flags); - } - pMatPreview = GetIEditor()->GetMaterialManager()->CreateMaterial("_NewPreview_", node); - } - else - { - CBaseLibraryItem::SerializeContext ctx2(node, true); - pMatPreview->Serialize(ctx2); - } - pMatPreview->SetShaderName("Illum"); - pMatPreview->Update(); - return pMatPreview; - } - else - { - return material; - } -} - -struct QMaterialImageListModel::Item -{ - QImage image; - void* pUserData; - QPoint position; - QSize size; - _smart_ptr pMaterial; - QStringList vVisibleTextures; -}; - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::OnCreate() -{ - // m_largePreviewCtrl is used to draw the 3D preview for the selected material - m_largePreviewCtrl.reset(new MaterialPreviewModelView(this)); - m_largePreviewCtrl->hide(); - // m_renderCtrl is used to draw all the sub-materials - m_renderCtrl.reset(new MaterialPreviewModelView(this, false /* disable idle updates since this is only used to create the preview list images */)); - m_renderCtrl->UnSetFlag(CPreviewModelView::PreviewModelViewFlag::SHOW_GRID); - m_renderCtrl->UnSetFlag(CPreviewModelView::PreviewModelViewFlag::SHOW_GRID_AXIS); - - if (gEnv->pSystem) - { - gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener(this); - } - - // m_resizeTimer is used to stall updateGeometries being called via resizeEvents until RESIZE_TIMEOUT ms after resizing - // This prevents an Editor freeze caused by constant resizing of the Material Editor when viewing - // a high sub-material count material (LY-58389) - m_resizeTimer = new QTimer(this); - connect(m_resizeTimer, &QTimer::timeout, this, &CMaterialImageListCtrl::ResizeTimeout); -} - -void CMaterialImageListCtrl::resizeEvent([[maybe_unused]] QResizeEvent* event) -{ - m_resizeTimer->stop(); - m_resizeTimer->start(RESIZE_TIMEOUT); -} - -void CMaterialImageListCtrl::ResizeTimeout() -{ - m_resizeTimer->stop(); - updateGeometries(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::OnDestroy() -{ - if (gEnv->pSystem) - { - gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener(this); - } -} - -////////////////////////////////////////////////////////////////////////// -CMaterialImageListCtrl::CMaterialImageListCtrl(QWidget* parent) - : CImageListCtrl(parent) -{ - OnCreate(); -} - -////////////////////////////////////////////////////////////////////////// -CMaterialImageListCtrl::~CMaterialImageListCtrl() -{ - OnDestroy(); -} - -////////////////////////////////////////////////////////////////////////// -QModelIndex QMaterialImageListModel::AddMaterial(CMaterial* pMaterial, void* pUserData) -{ - Item* pItem = new Item; - pItem->pMaterial = pMaterial; - pItem->pUserData = pUserData; - pMaterial->GetAnyTextureFilenames(pItem->vVisibleTextures); - - const int row = m_items.count(); - beginInsertRows(QModelIndex(), row, row); - m_items.insert(row, pItem); - endInsertRows(); - - return index(row, 0); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::SetMaterial(int nItemIndex, CMaterial* pMaterial, void* pUserData) -{ - assert(nItemIndex <= (int)m_items.size()); - Item* pItem = m_items.at(nItemIndex); - - pItem->vVisibleTextures.clear(); - pItem->pMaterial = pMaterial; - pItem->pUserData = pUserData; - pMaterial->GetAnyTextureFilenames(pItem->vVisibleTextures); - pItem->image = QImage(); - - QModelIndex idx = index(nItemIndex, 0); - emit dataChanged(idx, idx, QVector() << Qt::DisplayRole << Qt::DecorationRole); -} - -////////////////////////////////////////////////////////////////////////// -QModelIndex QMaterialImageListModel::FindMaterial(CMaterial* const pMaterial) -{ - for (int i = 0; i < m_items.count(); i++) - { - Item* item = m_items[i]; - if (pMaterial == item->pMaterial) - { - return index(i, 0); - } - } - return QModelIndex(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::SelectMaterial(CMaterial* pMaterial) -{ - // Force the material to load the highest resolution textures - pMaterial->GetMatInfo()->DisableTextureStreaming(); - - selectionModel()->clearSelection(); - - QMaterialImageListModel* materialModel = qobject_cast(model()); - Q_ASSERT(materialModel); - - QModelIndex index = materialModel->FindMaterial(pMaterial); - if (index.isValid()) - { - selectionModel()->select(index, QItemSelectionModel::SelectCurrent); - m_largePreviewMaterial = pMaterial; - } - else - { - // If the parent material was selected, set the first sub-material as the large preview's material so it has something to render - if (pMaterial->GetSubMaterialCount() > 0) - { - m_largePreviewMaterial = pMaterial->GetSubMaterial(0); - } - } - - GenerateAllImages(); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::InvalidateMaterial(CMaterial* pMaterial) -{ - QModelIndex idx = FindMaterial(pMaterial); - Item* pItem = ItemFromIndex(idx); - if ((pItem) && (m_renderCtrl)) - { - if (pMaterial) - { - // Ensure the full resolution textures are loaded for the material editor - pMaterial->GetMatInfo()->DisableTextureStreaming(); - } - - pItem->vVisibleTextures.clear(); - pMaterial->GetAnyTextureFilenames(pItem->vVisibleTextures); - pItem->image = QImage(); - GenerateImage(pItem); - - emit dataChanged(idx, idx, QVector() << Qt::DecorationRole); - } -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::DeleteAllItems() -{ - if (m_renderCtrl) - { - m_renderCtrl->SetMaterial(nullptr); - } - beginResetModel(); - qDeleteAll(m_items); - m_items.clear(); - endResetModel(); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::GenerateImage(Item* pItem) -{ - // Make a bitmap from image. - Q_ASSERT(pItem); - if (!m_renderCtrl || !pItem->size.isValid()) - { - return; - } - if (pItem->image.size() == pItem->size) - { - return; - } - - Item* pMtlItem = pItem; - - CImageEx image; - - bool bPreview = false; - if (pMtlItem->pMaterial) - { - if (!(pMtlItem->pMaterial->GetFlags() & MTL_FLAG_NOPREVIEW)) - { - if (!m_renderCtrl->GetStaticModel()) - { - AZ_Warning("Material Editor", false, "Preview renderer has no object loaded!"); - return; - } - - // keep m_renderCtrl off screen, but visible - m_renderCtrl->setGeometry(QRect(-QPoint(pItem->size.width(), pItem->size.height()), pItem->size)); - - _smart_ptr matPreview = ResolveTerrainLayerPreviewMaterial(pItem->pMaterial, m_pMatPreview); - - m_renderCtrl->SetMaterial(matPreview->GetMatInfo()); - m_renderCtrl->GetImageOffscreen(image, pMtlItem->size); - } - bPreview = true; - } - - if (!bPreview) - { - image.Allocate(pItem->size.width(), pItem->size.height()); - image.Clear(); - } - - pItem->image = QImage(image.GetWidth(), image.GetHeight(), QImage::Format_RGB32); - memcpy(pItem->image.bits(), image.GetData(), image.GetSize()); -} - - -#define MENU_USE_DEFAULT 1 -#define MENU_USE_BOX 2 -#define MENU_USE_PLANE 3 -#define MENU_USE_SPHERE 4 -#define MENU_USE_TEAPOT 5 -#define MENU_BG_BLACK 6 -#define MENU_BG_GRAY 7 -#define MENU_BG_WHITE 8 -#define MENU_BG_TEXTURE 9 -#define MENU_USE_BACKLIGHT 10 - - - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::contextMenuEvent(QContextMenuEvent* event) -{ - QAction* action; - QMenu menu; - - action = menu.addAction(tr("Use Default Object")); - action->setData(ModelDefault); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Default); - - action = menu.addAction(tr("Use Plane")); - action->setData(ModelPlane); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Plane); - - action = menu.addAction(tr("Use Box")); - action->setData(ModelBox); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Box); - - action = menu.addAction(tr("Use Sphere")); - action->setData(ModelSphere); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Sphere); - - action = menu.addAction(tr("Use Teapot")); - action->setData(ModelTeapot); - action->setCheckable(true); - action->setChecked(m_modelType == ModelType::Teapot); - - menu.addSeparator(); - - // If there is a currently selected material - if (m_materialBrowserWidget && m_largePreviewMaterial) - { - // Add context menu actions that are common to both the material browser and the preview swatches - m_materialBrowserWidget->AddContextMenuActionsSingleSelection(menu, m_largePreviewMaterial); - } - - action = menu.exec(mapToGlobal(event->pos())); - if (!action) - { - return; - } - - int cmd = action->data().toInt(); - switch (cmd) - { - case ModelDefault: - m_modelType = ModelType::Default; - LoadModel(); - break; - case ModelPlane: - m_modelType = ModelType::Plane; - LoadModel(); - break; - case ModelBox: - m_modelType = ModelType::Box; - LoadModel(); - break; - case ModelSphere: - m_modelType = ModelType::Sphere; - LoadModel(); - break; - case ModelTeapot: - m_modelType = ModelType::Teapot; - LoadModel(); - break; - default: - // If there is a currently selected material - if (m_materialBrowserWidget && m_largePreviewMaterial) - { - // Handle context menu actions that are common to both the material browser and the preview swatches - m_materialBrowserWidget->OnContextMenuAction(cmd, m_largePreviewMaterial); - } - break; - } - - QMaterialImageListModel* materialModel = - qobject_cast(model()); - Q_ASSERT(materialModel); - - materialModel->GenerateImages(); - update(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::LoadModel() -{ - switch (m_modelType) - { - case ModelType::Default: - case ModelType::Sphere: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_SPHERE_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_SPHERE_CAMERA_RADIUS, MATERIAL_EDITOR_SPHERE_CAMERA_FROM_DIRECTION); - break; - case ModelType::Box: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_BOX_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_BOX_CAMERA_RADIUS, MATERIAL_EDITOR_BOX_CAMERA_FROM_DIRECTION); - break; - case ModelType::Teapot: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_TEAPOT_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_TEAPOT_CAMERA_RADIUS, MATERIAL_EDITOR_TEAPOT_CAMERA_FROM_DIRECTION); - break; - case ModelType::Plane: - m_largePreviewCtrl->LoadModelFile(MATERIAL_EDITOR_PLANE_MODEL_FILE); - m_largePreviewCtrl->SetCameraLookAt(MATERIAL_EDITOR_PLANE_CAMERA_RADIUS, MATERIAL_EDITOR_PLANE_CAMERA_FROM_DIRECTION); - break; - } - - GenerateAllImages(); -} - - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::updateGeometries() -{ - ClearItemGeometries(); - m_updatingGeometries = true; - - if (!model()) - { - return; - } - - const int rowCount = model()->rowCount(); - if (!rowCount) - { - m_largePreviewCtrl->hide(); - m_largePreviewMaterial = nullptr; - return; - } - m_largePreviewCtrl->setParent(nullptr); - m_largePreviewCtrl->setParent(this); - m_largePreviewCtrl->show(); - - const int bwidth = BorderSize().width(); - const int bheight = BorderSize().height(); - m_largePreviewCtrl->move(bwidth, bheight); - - QRect rc = viewport()->contentsRect() - .adjusted(bwidth, bheight, -bwidth, -bheight); - - int cy = rc.height(); - - // Preview item is big. - if (model()->rowCount() > 0) - { - QSize size(cy, rc.height()); - m_largePreviewCtrl->SetSize(size); - m_largePreviewCtrl->resize(size); - rc.setLeft(rc.left() + cy + bwidth * 2); - m_largePreviewCtrl->show(); - } - - int cx = rc.width() - bwidth; - - int itemSize = cy; - - // Adjust all other bitmaps as tight as possible. - int numItems = model()->rowCount(); - int div = 0; - for (div = 1; div < 1000 && itemSize > 0; div++) - { - int nX = cx / (itemSize + 2); - if (nX >= numItems) - { - break; - } - if (nX > 0) - { - int nY = numItems / nX + 1; - if (nY * (itemSize + 2) < cy) - { - //itemSize = itemSize -= 2; - break; - } - } - itemSize = itemSize -= 2; - } - if (itemSize < 0) - { - itemSize = 0; - } - - QPoint pos(rc.topLeft()); - const QSize size(itemSize, itemSize); - m_renderCtrl->SetSize(size); - for (int row = 0; row < numItems; ++row) - { - QModelIndex index = model()->index(row, 0); - SetItemGeometry(index, QRect(pos, size)); - model()->setData(index, pos, QMaterialImageListModel::PositionRole); - model()->setData(index, size, Qt::SizeHintRole); - pos.rx() += itemSize + 2; - if (pos.rx() + itemSize >= rc.right()) - { - pos.rx() = rc.left(); - pos.ry() += itemSize + 2; - } - } - - m_updatingGeometries = false; - update(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::setModel(QAbstractItemModel* model) -{ - QMaterialImageListModel* materialModel = qobject_cast(model); - if (materialModel) - { - materialModel->SetPreviewModelCtrl(m_renderCtrl.data()); - } - - CImageListCtrl::setModel(model); - - auto delegate = qobject_cast(itemDelegate()); - // in case the delegate misses a pixmap we can generate it (done only once not at every painting) - connect(delegate, SIGNAL(invalidPixmapGenerated(const QModelIndex&)), materialModel, SLOT(GenerateImage(const QModelIndex&))); - connect(model, &QAbstractItemModel::dataChanged, this, &CMaterialImageListCtrl::ModelDataChanged); -} - -void CMaterialImageListCtrl::ModelDataChanged(const QModelIndex& index) -{ - // Prevent the hundreads of resize calls done in a row - // to trigger a new image computation that we already have - if (m_updatingGeometries) - { - return; - } - - GenerateImage(index); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::showEvent(QShowEvent* event) -{ - CImageListCtrl::showEvent(event); - - if (!m_largePreviewCtrl->GetStaticModel()) - { - LoadModel(); - } - if (!m_renderCtrl->GetStaticModel()) - { - m_renderCtrl->LoadModelFile(MATERIAL_EDITOR_SWATCH_MODEL_FILE); - m_renderCtrl->SetCameraLookAt(MATERIAL_EDITOR_SWATCH_CAMERA_RADIUS, MATERIAL_EDITOR_SWATCH_CAMERA_FROM_DIRECTION); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialImageListCtrl::OnSystemEvent(ESystemEvent event, UINT_PTR wparam, [[maybe_unused]] UINT_PTR lparam) -{ - switch (event) - { - // Toggle visibility of this control whenever the main editor window has a change of focus. - case ESYSTEM_EVENT_CHANGE_FOCUS: - { - setAttribute(Qt::WA_WState_Visible, (wparam != 0)); - break; - } - } - ; -} - -void CMaterialImageListCtrl::UpdateLargePreview() -{ - if (m_largePreviewMaterial) - { - m_largePreviewCtrl->SetMaterial(ResolveTerrainLayerPreviewMaterial(m_largePreviewMaterial, m_tempTerrainMaterial)->GetMatInfo()); - m_largePreviewCtrl->show(); - m_largePreviewCtrl->update(); - } -} - -void CMaterialImageListCtrl::GenerateImage(const QModelIndex& index) -{ - QMaterialImageListModel* materialModel = - qobject_cast(model()); - Q_ASSERT(materialModel); - if (m_largePreviewMaterial == materialModel->MaterialFromIndex(index)) - { - UpdateLargePreview(); - } - - materialModel->SetPreviewModelCtrl(m_renderCtrl.data()); - materialModel->GenerateImage(index); - update(); -} - -void CMaterialImageListCtrl::GenerateAllImages() -{ - QMaterialImageListModel* materialModel = - qobject_cast(model()); - Q_ASSERT(materialModel); - - UpdateLargePreview(); - - materialModel->SetPreviewModelCtrl(m_renderCtrl.data()); - materialModel->GenerateImages(); - update(); -} - -////////////////////////////////////////////////////////////////////////// -QMaterialImageListModel::QMaterialImageListModel(QObject* parent) - : QAbstractListModel(parent) - , m_renderCtrl(nullptr) -{ - BusConnect(AZ_CRC("dds", 0x780234cb)); -} - -////////////////////////////////////////////////////////////////////////// -QMaterialImageListModel::~QMaterialImageListModel() -{ - BusDisconnect(); - - qDeleteAll(m_items); -} - -////////////////////////////////////////////////////////////////////////// -MaterialPreviewModelView* QMaterialImageListModel::PreviewModelCtrl() const -{ - return m_renderCtrl; -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::SetPreviewModelCtrl(MaterialPreviewModelView* ctrl) -{ - if (m_renderCtrl) - { - disconnect(m_renderCtrl, &MaterialPreviewModelView::destroyed, - this, &QMaterialImageListModel::ClearPreviewModelCtrl); - } - - m_renderCtrl = ctrl; - - if (m_renderCtrl) - { - connect(m_renderCtrl, &MaterialPreviewModelView::destroyed, - this, &QMaterialImageListModel::ClearPreviewModelCtrl); - } -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::ClearPreviewModelCtrl() -{ - m_renderCtrl = nullptr; -} - -////////////////////////////////////////////////////////////////////////// -int QMaterialImageListModel::rowCount(const QModelIndex& parent) const -{ - if (parent.isValid()) - { - return 0; - } - - return m_items.count(); -} - -////////////////////////////////////////////////////////////////////////// -QVariant QMaterialImageListModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - { - return QVariant(); - } - - Item* pItem = m_items.at(index.row()); - Q_ASSERT(pItem); - - switch (role) - { - case Qt::DisplayRole: - return pItem->pMaterial->GetShortName(); - - case Qt::DecorationRole: - return QPixmap::fromImage(pItem->image); - - case PositionRole: - return pItem->position; - - case Qt::SizeHintRole: - return pItem->size; - - default: - break; - } - - return QVariant(); -} - -////////////////////////////////////////////////////////////////////////// -bool QMaterialImageListModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid()) - { - return false; - } - - Item* pItem = ItemFromIndex(index); - if (!pItem) - { - return false; - } - - if (Qt::SizeHintRole == role) - { - pItem->size = value.toSize(); - emit dataChanged(index, index, QVector() << Qt::DecorationRole << Qt::SizeHintRole); - return true; - } - - if (PositionRole == role) - { - pItem->position = value.toPoint(); - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -Qt::ItemFlags QMaterialImageListModel::flags(const QModelIndex& index) const -{ - return QAbstractListModel::flags(index); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* QMaterialImageListModel::MaterialFromIndex(QModelIndex index) const -{ - Item* pItem = ItemFromIndex(index); - if (!pItem) - { - return nullptr; - } - - return pItem->pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -void* QMaterialImageListModel::UserDataFromIndex(QModelIndex index) const -{ - Item* pItem = ItemFromIndex(index); - if (!pItem) - { - return nullptr; - } - - return pItem->pUserData; -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::GenerateImages() -{ - if ((!m_renderCtrl) || (m_items.isEmpty())) - { - return; - } - - for (Item* materialImageListItem : m_items) - { - GenerateImage(materialImageListItem); - } -} - -void QMaterialImageListModel::GenerateImage(const QModelIndex& index) -{ - if ((!m_renderCtrl) || (m_items.isEmpty())) - { - return; - } - - GenerateImage(ItemFromIndex(index)); -} - -////////////////////////////////////////////////////////////////////////// -QMaterialImageListModel::Item* QMaterialImageListModel::ItemFromIndex(QModelIndex index) const -{ - if (!index.isValid()) - { - return nullptr; - } - - return m_items.at(index.row()); -} - -////////////////////////////////////////////////////////////////////////// -void QMaterialImageListModel::OnFileChanged(AZStd::string assetPath) -{ - const int rowCount = m_items.count(); - - // update all previews who's texture(s) changed - for (int row = 0; row < rowCount; ++row) - { - Item* pItem = m_items.at(row); - - QStringList::const_iterator textureIt = std::find(pItem->vVisibleTextures.begin(), pItem->vVisibleTextures.end(), assetPath.c_str()); - if (textureIt != pItem->vVisibleTextures.end()) - { - pItem->image = QImage(); - QModelIndex idx = index(row, 0); - emit dataChanged(idx, idx, QVector() << Qt::DecorationRole); - } - } -} - -#include diff --git a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.h b/Code/Sandbox/Editor/Material/MaterialImageListCtrl.h deleted file mode 100644 index fe9742fb53..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialImageListCtrl.h +++ /dev/null @@ -1,164 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALIMAGELISTCTRL_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALIMAGELISTCTRL_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "Controls/ImageListCtrl.h" -#include -#include "Material.h" -#include "IRenderer.h" // IAsyncTextureCompileListener -#include "IResourceCompilerHelper.h" -#include - -#include -#include -#endif - -class MaterialPreviewModelView; -class MaterialBrowserWidget; - -////////////////////////////////////////////////////////////////////////// -class CMaterialImageListCtrl - : public CImageListCtrl - , public ISystemEventListener -{ - Q_OBJECT -public: - - enum class ModelType - { - Default, - Box, - Sphere, - Teapot, - Plane - }; - - enum MenuAction - { - ModelDefault = 0, - ModelPlane, - ModelBox, - ModelSphere, - ModelTeapot, - // Context menu actions that are common to both the material browser and the preview swatches - // are handled by the same switch statement, so they need to be unique. This sets the starting point for the common actions - MaterialBrowserWidgetActionsStart - }; - - CMaterialImageListCtrl(QWidget* parent = nullptr); - ~CMaterialImageListCtrl(); - - void setModel(QAbstractItemModel* model) override; - - void EnableAutoRefresh(bool autoRefreshState, unsigned int refreshInterval); - void SelectMaterial(CMaterial* pMaterial); - void LoadModel(); - void SetMaterialBrowserWidget(MaterialBrowserWidget* materialBrowserWidget){ m_materialBrowserWidget = materialBrowserWidget; } - // ISystemEventListener - // Due to the material editor working on a ProcessEvents -> Timer based system, rather than the OnIdle update event loops - // that the other editor windows use, make sure that when the editor loses focus that the Material Editor itself loses focus. - // This will pause updates/renderings in the material editor when it does not have focus. - // This prevents certain materials from re-creating themselves and eventually overflowing a few resource buffers. - // The main window cleans up those resources during its main update, which is bypassed when the window does not have focus. - virtual void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam); - // ~ISystemEventListener - - // Override resizeEvent and use this const to rate limit it such that it only fires RESIZE_TIMEOUT ms after resizing stops - static const int RESIZE_TIMEOUT = 100; - void resizeEvent(QResizeEvent* event) override; - -public slots: - void ModelDataChanged(const QModelIndex& index); - void ResizeTimeout(); -protected: - void OnCreate(); - void OnDestroy(); - - void contextMenuEvent(QContextMenuEvent* event) override; - void showEvent(QShowEvent* event) override; - void updateGeometries() override; - -private: - void GenerateImage(const QModelIndex& index); - void GenerateAllImages(); - void UpdateLargePreview(); - - QScopedPointer m_largePreviewCtrl; // Used to draw the main 3D preview viewport for the selected sub-material - _smart_ptr m_largePreviewMaterial; - _smart_ptr m_tempTerrainMaterial; - QScopedPointer m_renderCtrl; // Used to draw the swatches for all the sub-materials - int m_nColor; - bool m_updatingGeometries = false; - ModelType m_modelType = ModelType::Default; - MaterialBrowserWidget* m_materialBrowserWidget; - QTimer* m_resizeTimer; // Used to stall a resizeEvent from firing until RESIZE_TIMEOUT ms have passed since resizing stopped -}; - -class QMaterialImageListModel - : public QAbstractListModel - , public AzFramework::LegacyAssetEventBus::Handler -{ - struct Item; - Q_OBJECT - -public: - enum CustomRoles - { - PositionRole = Qt::UserRole - }; - - QMaterialImageListModel(QObject* parent = nullptr); - ~QMaterialImageListModel(); - - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex& index) const override; - - QModelIndex AddMaterial(CMaterial* pMaterial, void* pUserData = nullptr); - void SetMaterial(int nItemIndex, CMaterial* pMaterial, void* pUserData = nullptr); - QModelIndex FindMaterial(CMaterial* pMaterial); - void InvalidateMaterial(CMaterial* pMaterial); - void DeleteAllItems(); - - MaterialPreviewModelView* PreviewModelCtrl() const; - void SetPreviewModelCtrl(MaterialPreviewModelView* ctrl); - - CMaterial* MaterialFromIndex(QModelIndex index) const; - void* UserDataFromIndex(QModelIndex index) const; - -public slots: - void GenerateImages(); - void GenerateImage(const QModelIndex& index); - -protected: - void GenerateImage(Item* pItem); - Item* ItemFromIndex(QModelIndex index) const; - -private slots: - void ClearPreviewModelCtrl(); - -private: - void OnFileChanged(AZStd::string assetPath) override; - -private: - _smart_ptr m_pMatPreview; - QPointer m_renderCtrl; - QVector m_items; -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALIMAGELISTCTRL_H diff --git a/Code/Sandbox/Editor/Material/MaterialLibrary.cpp b/Code/Sandbox/Editor/Material/MaterialLibrary.cpp deleted file mode 100644 index 351eee5c63..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialLibrary.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialLibrary.h" - -// Editor -#include "BaseLibraryItem.h" - - -////////////////////////////////////////////////////////////////////////// -// CMaterialLibrary implementation. -////////////////////////////////////////////////////////////////////////// -bool CMaterialLibrary::Save() -{ - return SaveLibrary("MaterialLibrary"); -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialLibrary::Load(const QString& filename) -{ - if (filename.isEmpty()) - { - return false; - } - SetFilename(filename); - XmlNodeRef root = XmlHelpers::LoadXmlFromFile(filename.toUtf8().data()); - if (!root) - { - return false; - } - - Serialize(root, true); - return true; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::Serialize([[maybe_unused]] XmlNodeRef& root, [[maybe_unused]] bool bLoading) -{ - /* - if (bLoading) - { - // Loading. - CString name = GetName(); - root->getAttr( "Name",name ); - SetName( name ); - for (int i = 0; i < root->getChildCount(); i++) - { - XmlNodeRef itemNode = root->getChild(i); - CMaterial *material = new CMaterial(itemNode->getAttr("Name")); - AddItem( material ); - CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading ); - material->Serialize( ctx ); - } - SetModified(false); - } - else - { - // Saving. - root->setAttr( "Name",GetName() ); - root->setAttr( "SandboxVersion",(const char*)GetIEditor()->GetFileVersion().ToFullString() ); - // Serialize prototypes. - for (int i = 0; i < GetItemCount(); i++) - { - CMaterial *pMtl = (CMaterial*)GetItem(i); - // Save materials with parents under thier parent xml node. - if (pMtl->GetParent()) - continue; - - XmlNodeRef itemNode = root->newChild( "Material" ); - CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading ); - GetItem(i)->Serialize( ctx ); - } - } - */ -} - -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::AddItem(IDataBaseItem* item, bool bRegister) -{ - CBaseLibraryItem* pLibItem = (CBaseLibraryItem*)item; - // Check if item is already assigned to this library. - if (pLibItem->GetLibrary() != this) - { - pLibItem->SetLibrary(this); - if (bRegister) - { - m_pManager->RegisterItem(pLibItem); - } - m_items.push_back(pLibItem); - } -} - -////////////////////////////////////////////////////////////////////////// -IDataBaseItem* CMaterialLibrary::GetItem(int index) -{ - assert(index >= 0 && index < m_items.size()); - return m_items[index]; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::RemoveItem(IDataBaseItem* item) -{ - for (int i = 0; i < m_items.size(); i++) - { - if (m_items[i] == item) - { - m_items.erase(m_items.begin() + i); - SetModified(); - break; - } - } -} - -////////////////////////////////////////////////////////////////////////// -IDataBaseItem* CMaterialLibrary::FindItem(const QString& name) -{ - for (int i = 0; i < m_items.size(); i++) - { - if (QString::compare(m_items[i]->GetName(), name, Qt::CaseInsensitive) == 0) - { - return m_items[i]; - } - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialLibrary::RemoveAllItems() -{ - AddRef(); - for (int i = 0; i < m_items.size(); i++) - { - // Clear library item. - m_items[i]->SetLibrary(NULL); - } - m_items.clear(); - Release(); -} diff --git a/Code/Sandbox/Editor/Material/MaterialLibrary.h b/Code/Sandbox/Editor/Material/MaterialLibrary.h deleted file mode 100644 index 5a80500e94..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialLibrary.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALLIBRARY_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALLIBRARY_H -#pragma once - -#include "BaseLibrary.h" - -/** Library of prototypes. -*/ -class CRYEDIT_API CMaterialLibrary - : public CBaseLibrary -{ -public: - CMaterialLibrary(IBaseLibraryManager* pManager) - : CBaseLibrary(pManager) {}; - virtual bool Save(); - virtual bool Load(const QString& filename); - virtual void Serialize(XmlNodeRef& node, bool bLoading); - - ////////////////////////////////////////////////////////////////////////// - // CBaseLibrary override. - ////////////////////////////////////////////////////////////////////////// - void AddItem(IDataBaseItem* item, bool bRegister = true); - int GetItemCount() const { return m_items.size(); } - IDataBaseItem* GetItem(int index); - void RemoveItem(IDataBaseItem* item); - void RemoveAllItems(); - IDataBaseItem* FindItem(const QString& name); -private: - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - std::vector m_items; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALLIBRARY_H diff --git a/Code/Sandbox/Editor/Material/MaterialManager.cpp b/Code/Sandbox/Editor/Material/MaterialManager.cpp deleted file mode 100644 index 51460ff34a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialManager.cpp +++ /dev/null @@ -1,2095 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "MaterialManager.h" - -// Qt -#include - -// AzCore -#include - -// AzFramework -#include - -// AzToolsFramework -#include -#include -#include - -// Editor -#include "MainWindow.h" -#include "MaterialLibrary.h" -#include "MaterialSender.h" -#include "MaterialUtils.h" -#include "ModelViewport.h" -#include "ISourceControl.h" -#include "UsedResources.h" -#include "Viewport.h" -#include "Commands/CommandManager.h" -#include "Include/IObjectManager.h" -#include "Objects/BaseObject.h" -#include "Objects/SelectionGroup.h" - - -static const char* MATERIALS_LIBS_PATH = "Materials/"; -static unsigned int s_highlightUpdateCounter = 0; - -// Convert a material name into a material identifier (no extension, no gamename, etc) so that it can be compared -// in the hash. -static QString UnifyMaterialName(const QString& source) -{ - char tempBuffer[AZ_MAX_PATH_LEN]; - azstrncpy(tempBuffer, AZ_ARRAY_SIZE(tempBuffer), source.toUtf8().data(), AZ_ARRAY_SIZE(tempBuffer) - 1); - MaterialUtils::UnifyMaterialName(tempBuffer); - return QString(tempBuffer); -} - -struct SHighlightMode -{ - float m_colorHue; - float m_period; - bool m_continuous; -}; - -static SHighlightMode g_highlightModes[] = { - { 0.70f, 0.8f, true }, // purple - { 0.25f, 0.75f, false }, // green - { 0.0, 0.75f, true } // red -}; - -class CMaterialHighlighter -{ -public: - void Start(CMaterial* pMaterial, int modeFlag); - void Stop(CMaterial* pMaterial, int modeFlag); - void GetHighlightColor(ColorF* color, float* intensity, int flags); - - void ClearMaterials() { m_materials.clear(); }; - void RestoreMaterials(); - void Update(); -private: - struct SHighlightOptions - { - int m_modeFlags; - }; - - typedef std::map Materials; - Materials m_materials; -}; - -AZStd::string DccMaterialToSourcePath(const AZStd::string& relativeDccMaterialPath) -{ - AZStd::string fullSourcePath; - bool sourcePathFound = false; - - // Get source path using relative .dccmtl path - AzToolsFramework::AssetSystemRequestBus::BroadcastResult(sourcePathFound, &AzToolsFramework::AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, relativeDccMaterialPath, fullSourcePath); - - if (sourcePathFound) - { - // Set source path extension to ".mtl" - AzFramework::StringFunc::Path::ReplaceExtension(fullSourcePath, MATERIAL_FILE_EXT); - } - return fullSourcePath; -} - - -void CMaterialHighlighter::Start(CMaterial* pMaterial, int modeFlag) -{ - Materials::iterator it = m_materials.find(pMaterial); - if (it == m_materials.end()) - { - SHighlightOptions& options = m_materials[pMaterial]; - options.m_modeFlags = modeFlag; - } - else - { - SHighlightOptions& options = it->second; - options.m_modeFlags |= modeFlag; - } -} - -void CMaterialHighlighter::Stop(CMaterial* pMaterial, int modeFlag) -{ - if (pMaterial) - { - pMaterial->SetHighlightFlags(0); - } - - Materials::iterator it = m_materials.find(pMaterial); - if (it == m_materials.end()) - { - return; - } - - SHighlightOptions& options = it->second; - MAKE_SURE((options.m_modeFlags & modeFlag) != 0, return ); - - options.m_modeFlags &= ~modeFlag; - if (options.m_modeFlags == 0) - { - m_materials.erase(it); - } -} - -void CMaterialHighlighter::RestoreMaterials() -{ - for (Materials::iterator it = m_materials.begin(); it != m_materials.end(); ++it) - { - if (it->first) - { - it->first->SetHighlightFlags(0); - } - } -} - -void CMaterialHighlighter::Update() -{ - unsigned int counter = s_highlightUpdateCounter; - - Materials::iterator it; - for (it = m_materials.begin(); it != m_materials.end(); ++it) - { - // Only update each material every 4 frames - if (counter++ % 4 == 0) - { - it->first->SetHighlightFlags(it->second.m_modeFlags); - } - } - - s_highlightUpdateCounter = (s_highlightUpdateCounter + 1) % 4; -} - -void CMaterialHighlighter::GetHighlightColor(ColorF* color, float* intensity, int flags) -{ - MAKE_SURE(color != 0, return ); - MAKE_SURE(intensity != 0, return ); - - *intensity = 0.0f; - - if (flags == 0) - { - return; - } - - int flagIndex = 0; - while (flags) - { - if ((flags & 1) != 0) - { - break; - } - flags = flags >> 1; - ++flagIndex; - } - - MAKE_SURE(flagIndex < sizeof(g_highlightModes) / sizeof(g_highlightModes[0]), return ); - - const SHighlightMode& mode = g_highlightModes[flagIndex]; - float t = GetTickCount() / 1000.0f; - float h = mode.m_colorHue; - float s = 1.0f; - float v = 1.0f; - - color->fromHSV(h + sinf(t * g_PI2 * 5.0f) * 0.025f, s, v); - color->a = 1.0f; - - if (mode.m_continuous) - { - *intensity = fabsf(sinf(t * g_PI2 / mode.m_period)); - } - else - { - *intensity = max(0.0f, sinf(t * g_PI2 / mode.m_period)); - } -} - - -////////////////////////////////////////////////////////////////////////// -// CMaterialManager implementation. -////////////////////////////////////////////////////////////////////////// -CMaterialManager::CMaterialManager(CRegistrationContext& regCtx) - : m_pHighlighter(new CMaterialHighlighter) - , m_highlightMask(eHighlight_All) - , m_currentFolder("") - , m_joinThreads(false) -{ - m_bUniqGuidMap = false; - m_bUniqNameMap = true; - - m_bEditorUiReady = false; - m_bSourceControlErrorReported = false; - m_sourceControlFunctionQueued = false; - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); - - m_MatSender = new CMaterialSender(true); - - EBusFindAssetTypeByName materialResult("Material"); //from MaterialAssetTypeInfo.cpp, case insensitive - AZ::AssetTypeInfoBus::BroadcastResult(materialResult, &AZ::AssetTypeInfo::GetAssetType); - m_materialAssetType = materialResult.GetAssetType(); - - EBusFindAssetTypeByName dccMaterialResult("DccMaterial"); //from MaterialAssetTypeInfo.cpp, case insensitive - AZ::AssetTypeInfoBus::BroadcastResult(dccMaterialResult, &AZ::AssetTypeInfo::GetAssetType); - m_dccMaterialAssetType = dccMaterialResult.GetAssetType(); - - RegisterCommands(regCtx); - AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect(); - AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler::BusConnect(); - AzFramework::AssetCatalogEventBus::Handler::BusConnect(); - AzToolsFramework::EditorEvents::Bus::Handler::BusConnect(); -} - -////////////////////////////////////////////////////////////////////////// -CMaterialManager::~CMaterialManager() -{ - AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler::BusDisconnect(); - AzFramework::AssetCatalogEventBus::Handler::BusDisconnect(); - AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect(); - - delete m_pHighlighter; - m_pHighlighter = 0; - - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetMaterialManager()->SetListener(NULL); - } - - if (m_MatSender) - { - delete m_MatSender; - m_MatSender = 0; - } - - // Terminate thread that saves dcc materials. - m_joinThreads = true; - if (m_bEditorUiReady) - { - m_dccMaterialSaveSemaphore.release(); - m_dccMaterialSaveThread.join(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Set3DEngine() -{ - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetMaterialManager()->SetListener(this); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::ClearAll() -{ - SetCurrentMaterial(NULL); - CBaseLibraryManager::ClearAll(); - - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::CreateMaterial(const QString& sMaterialName,const XmlNodeRef& node, int nMtlFlags, [[maybe_unused]] unsigned long nLoadingFlags) -{ - CMaterial* pMaterial = new CMaterial(sMaterialName, nMtlFlags); - - if (node) - { - CBaseLibraryItem::SerializeContext serCtx(node, true); - serCtx.bUniqName = true; - pMaterial->Serialize(serCtx); - } - if (!pMaterial->IsPureChild() && !(pMaterial->GetFlags() & MTL_FLAG_UIMATERIAL)) - { - RegisterItem(pMaterial); - } - - return pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::CreateMaterial(const char* sMaterialName,const XmlNodeRef& node, int nMtlFlags, unsigned long nLoadingFlags) -{ - return CreateMaterial(QString(sMaterialName), node, nMtlFlags, nLoadingFlags); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Export(XmlNodeRef& node) -{ - XmlNodeRef libs = node->newChild("MaterialsLibrary"); - for (int i = 0; i < GetLibraryCount(); i++) - { - IDataBaseLibrary* pLib = GetLibrary(i); - // Level libraries are saved in in level. - XmlNodeRef libNode = libs->newChild("Library"); - - // Export library. - libNode->setAttr("Name", pLib->GetName().toUtf8().data()); - } -} - -////////////////////////////////////////////////////////////////////////// -int CMaterialManager::ExportLib(CMaterialLibrary* pLib, XmlNodeRef& libNode) -{ - int num = 0; - // Export library. - libNode->setAttr("Name", pLib->GetName().toUtf8().data()); - libNode->setAttr("File", pLib->GetFilename().toUtf8().data()); - char version[50]; - GetIEditor()->GetFileVersion().ToString(version, AZ_ARRAY_SIZE(version)); - libNode->setAttr("SandboxVersion", version); - - // Serialize prototypes. - for (int j = 0; j < pLib->GetItemCount(); j++) - { - CMaterial* pMtl = (CMaterial*)pLib->GetItem(j); - - // Only export real used materials. - if (pMtl->IsDummy() || !pMtl->IsUsed() || pMtl->IsPureChild()) - { - continue; - } - - XmlNodeRef itemNode = libNode->newChild("Material"); - itemNode->setAttr("Name", pMtl->GetName().toUtf8().data()); - num++; - } - return num; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetSelectedItem(IDataBaseItem* pItem) -{ - m_pSelectedItem = (CBaseLibraryItem*)pItem; - SetCurrentMaterial((CMaterial*)pItem); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetCurrentMaterial(CMaterial* pMtl) -{ - if (m_pCurrentMaterial) - { - // Changing current material. save old one. - if (m_pCurrentMaterial->IsModified()) - { - m_pCurrentMaterial->Save(); - } - } - - m_pCurrentMaterial = pMtl; - if (m_pCurrentMaterial) - { - m_pCurrentMaterial->OnMakeCurrent(); - m_pCurrentEngineMaterial = m_pCurrentMaterial->GetMatInfo(); - } - else - { - m_pCurrentEngineMaterial = 0; - } - - m_pSelectedItem = pMtl; - m_pSelectedParent = pMtl ? pMtl->GetParent() : NULL; - - NotifyItemEvent(m_pCurrentMaterial, EDB_ITEM_EVENT_SELECTED); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetCurrentFolder(const QString& folder) -{ - m_currentFolder = folder; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetMarkedMaterials(const std::vector<_smart_ptr >& markedMaterials) -{ - m_markedMaterials = markedMaterials; -} - -void CMaterialManager::OnLoadShader(CMaterial* pMaterial) -{ - RemoveFromHighlighting(pMaterial, eHighlight_All); - AddForHighlighting(pMaterial); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::GetCurrentMaterial() const -{ - return m_pCurrentMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CBaseLibraryItem* CMaterialManager::MakeNewItem() -{ - CMaterial* pMaterial = new CMaterial("", 0); - return pMaterial; -} -////////////////////////////////////////////////////////////////////////// -CBaseLibrary* CMaterialManager::MakeNewLibrary() -{ - return new CMaterialLibrary(this); -} -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::GetRootNodeName() -{ - return "MaterialsLibs"; -} -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::GetLibsPath() -{ - if (m_libsPath.isEmpty()) - { - m_libsPath = MATERIALS_LIBS_PATH; - } - return m_libsPath; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::ReportDuplicateItem(CBaseLibraryItem* pItem, CBaseLibraryItem* pOldItem) -{ - QString sLibName; - if (pOldItem->GetLibrary()) - { - sLibName = pOldItem->GetLibrary()->GetName(); - } - CErrorRecord err; - err.pItem = (CMaterial*)pOldItem; - err.error = QObject::tr("Material %1 with the duplicate name to the loaded material %2 ignored").arg(pItem->GetName(), pOldItem->GetName()); - GetIEditor()->GetErrorReport()->ReportError(err); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Serialize([[maybe_unused]] XmlNodeRef& node, bool bLoading) -{ - //CBaseLibraryManager::Serialize( node,bLoading ); - if (bLoading) - { - } - else - { - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - CBaseLibraryManager::OnEditorNotifyEvent(event); - switch (event) - { - case eNotify_OnInit: - InitMatSender(); - break; - case eNotify_OnIdleUpdate: - m_pHighlighter->Update(); - break; - case eNotify_OnBeginGameMode: - m_pHighlighter->RestoreMaterials(); - break; - case eNotify_OnEndGameMode: - ReloadDirtyMaterials(); - break; - case eNotify_OnBeginNewScene: - SetCurrentMaterial(0); - break; - case eNotify_OnBeginSceneOpen: - SetCurrentMaterial(0); - break; - case eNotify_OnMissionChange: - SetCurrentMaterial(0); - break; - case eNotify_OnCloseScene: - SetCurrentMaterial(0); - m_pHighlighter->ClearMaterials(); - break; - case eNotify_OnQuit: - SetCurrentMaterial(0); - if (gEnv->p3DEngine) - { - gEnv->p3DEngine->GetMaterialManager()->SetListener(NULL); - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::ReloadDirtyMaterials() -{ - if (!GetIEditor()->Get3DEngine()) - { - return; - } - - IMaterialManager* runtimeMaterialManager = GetIEditor()->Get3DEngine()->GetMaterialManager(); - - uint32 mtlCount = 0; - - runtimeMaterialManager->GetLoadedMaterials(NULL, mtlCount); - - if (mtlCount > 0) - { - AZStd::vector<_smart_ptr> allMaterials; - - allMaterials.reserve(mtlCount); - - [[maybe_unused]] uint32 mtlCountPrev = mtlCount; - runtimeMaterialManager->GetLoadedMaterials(&allMaterials, mtlCount); - AZ_Assert(mtlCountPrev == mtlCount && mtlCount == allMaterials.size(), "It appears GetLoadedMaterials was not used correctly."); - - for (size_t i = 0; i < mtlCount; ++i) - { - _smart_ptr pMtl = allMaterials[i]; - if (pMtl && pMtl->IsDirty()) - { - runtimeMaterialManager->ReloadMaterial(pMtl); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterial(const QString& sMaterialName, bool bMakeIfNotFound) -{ - LOADING_TIME_PROFILE_SECTION(GetISystem()); - - QString sMaterialNameClear = UnifyMaterialName(sMaterialName); - QString fullSourcePath = MaterialToFilename(sMaterialNameClear); - QString relativePath = PathUtil::ReplaceExtension(sMaterialNameClear.toUtf8().data(), MATERIAL_FILE_EXT).c_str(); - - return LoadMaterialInternal(sMaterialNameClear, fullSourcePath, relativePath, bMakeIfNotFound); -} - -////////////////////////////////////////////////////////////////////////// -XmlNodeRef CMaterialManager::LoadXmlNode(const QString &fullSourcePath, const QString &relativeFilePath) -{ - XmlNodeRef materialNode = GetISystem()->LoadXmlFromFile(fullSourcePath.toUtf8().data()); - if (!materialNode) - { - // try again with the product file in case its present - materialNode = GetISystem()->LoadXmlFromFile(relativeFilePath.toUtf8().data()); - } - return materialNode; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterialWithFullSourcePath(const QString& relativeFilePath, const QString& fullSourcePath, bool makeIfNotFound /*= true*/) -{ - QString materialNameClear = UnifyMaterialName(relativeFilePath); - return LoadMaterialInternal(materialNameClear, fullSourcePath, relativeFilePath, makeIfNotFound); -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterialInternal(const QString &materialNameClear, const QString &fullSourcePath, const QString &relativeFilePath, bool makeIfNotFound) -{ - // Note: We are loading from source files here, not from compiled assets, so there is no need to query the asset system for compilation status, etc. - - // Load material with this name if not yet loaded. - CMaterial* pMaterial = (CMaterial*)FindItemByName(materialNameClear); - if (pMaterial) - { - // If this is a dummy material that was created before for not found mtl file - // try reload the mtl file again to get valid material data. - if (pMaterial->IsDummy()) - { - XmlNodeRef mtlNode = GetISystem()->LoadXmlFromFile(fullSourcePath.toUtf8().data()); - if (mtlNode) - { - DeleteMaterial(pMaterial); - pMaterial = CreateMaterial(materialNameClear, mtlNode); - } - } - return pMaterial; - } - - XmlNodeRef mtlNode = LoadXmlNode(fullSourcePath, relativeFilePath); - - if (mtlNode) - { - pMaterial = CreateMaterial(materialNameClear, mtlNode); - } - else - { - if (makeIfNotFound) - { - pMaterial = new CMaterial(materialNameClear); - pMaterial->SetDummy(true); - RegisterItem(pMaterial); - - CErrorRecord err; - err.error = QObject::tr("Material %1 not found").arg(materialNameClear); - GetIEditor()->GetErrorReport()->ReportError(err); - } - } - - return pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::LoadMaterial(const char* sMaterialName, bool bMakeIfNotFound) -{ - return LoadMaterial(QString(sMaterialName), bMakeIfNotFound); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::AddSourceFileOpeners(const char* fullSourceFileName, [[maybe_unused]] const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) -{ - using namespace AzToolsFramework; - using namespace AzToolsFramework::AssetBrowser; - - // disable if other project is active - if (AzFramework::Render::RenderSystemRequestBus::HasHandlers()) - { - return; - } - - if (AZStd::wildcard_match("*.mtl", fullSourceFileName)) - { - // we can handle these! - auto materialCallback = [this](const char* fullSourceFileNameInCall, const AZ::Uuid& sourceUUIDInCall) - { - const SourceAssetBrowserEntry* fullDetails = SourceAssetBrowserEntry::GetSourceByUuid(sourceUUIDInCall); - if (fullDetails) - { - CMaterial* materialFile = LoadMaterialWithFullSourcePath(QString::fromUtf8(fullDetails->GetRelativePath().c_str()), QString::fromUtf8(fullSourceFileNameInCall), false); - if (materialFile) - { - OpenViewPane("Material Editor"); - SetCurrentMaterial(materialFile); // the material browser pane should be able to deal with this. - } - } - }; - - openers.push_back({ "O3DE_MaterialEditor", "Open In Material Editor...", QIcon(), materialCallback }); - } -} - -////////////////////////////////////////////////////////////////////////// -static bool MaterialRequiresSurfaceType(CMaterial* pMaterial) -{ - // Do not enforce Surface Type... - - // ...over editor UI materials - if ((pMaterial->GetFlags() & MTL_FLAG_UIMATERIAL) != 0) - { - return false; - } - - // ...over SKY - if (pMaterial->GetShaderName() == "DistanceCloud" || - pMaterial->GetShaderName() == "Sky" || - pMaterial->GetShaderName() == "SkyHDR") - { - return false; - } - // ...over terrain materials - if (pMaterial->GetShaderName() == "Terrain.Layer") - { - return false; - } - // ...over vegetation - if (pMaterial->GetShaderName() == "Vegetation") - { - return false; - } - - // ...over decals - bool requiresSurfaceType = true; - CVarBlock* pShaderGenParams = pMaterial->GetShaderGenParamsVars(); - if (pShaderGenParams) - { - if (IVariable* pVar = pShaderGenParams->FindVariable("Decal")) - { - int value = 0; - pVar->Get(value); - if (value) - { - requiresSurfaceType = false; - } - } - // The function GetShaderGenParamsVars allocates a new CVarBlock object, so let's clean it up here - delete pShaderGenParams; - } - return requiresSurfaceType; -} - -////////////////////////////////////////////////////////////////////////// -int CMaterialManager::GetHighlightFlags(CMaterial* pMaterial) const -{ - if (pMaterial == NULL) - { - return 0; - } - - if ((pMaterial->GetFlags() & MTL_FLAG_NODRAW) != 0) - { - return 0; - } - - int result = 0; - - if (pMaterial == m_pHighlightMaterial) - { - result |= eHighlight_Pick; - } - - const QString& surfaceTypeName = pMaterial->GetSurfaceTypeName(); - if (surfaceTypeName.isEmpty() && MaterialRequiresSurfaceType(pMaterial)) - { - result |= eHighlight_NoSurfaceType; - } - - if (GetIEditor()->Get3DEngine()) - { - if (ISurfaceTypeManager* pSurfaceManager = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetSurfaceTypeManager()) - { - const ISurfaceType* pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(surfaceTypeName.toUtf8().data()); - if (pSurfaceType && pSurfaceType->GetBreakability() != 0) - { - result |= eHighlight_Breakable; - } - } - } - - return result; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::AddForHighlighting(CMaterial* pMaterial) -{ - if (pMaterial == NULL) - { - return; - } - - int highlightFlags = (GetHighlightFlags(pMaterial) & m_highlightMask); - if (highlightFlags != 0) - { - m_pHighlighter->Start(pMaterial, highlightFlags); - } - - int count = pMaterial->GetSubMaterialCount(); - for (int i = 0; i < count; ++i) - { - CMaterial* pChild = pMaterial->GetSubMaterial(i); - if (!pChild) - { - continue; - } - - AddForHighlighting(pChild); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::RemoveFromHighlighting(CMaterial* pMaterial, int mask) -{ - if (pMaterial == NULL) - { - return; - } - - m_pHighlighter->Stop(pMaterial, mask); - - int count = pMaterial->GetSubMaterialCount(); - for (int i = 0; i < count; ++i) - { - CMaterial* pChild = pMaterial->GetSubMaterial(i); - if (!pChild) - { - continue; - } - - RemoveFromHighlighting(pChild, mask); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::UpdateHighlightedMaterials() -{ - IDataBaseItemEnumerator* pEnum = CBaseLibraryManager::GetItemEnumerator(); - if (!pEnum) - { - return; - } - - CMaterial* pMaterial = (CMaterial*)pEnum->GetFirst(); - while (pMaterial) - { - RemoveFromHighlighting(pMaterial, eHighlight_All); - AddForHighlighting(pMaterial); - pMaterial = (CMaterial*)pEnum->GetNext(); - } - - pEnum->Release(); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnRequestMaterial(_smart_ptr pMatInfo) -{ - const char* pcName = pMatInfo->GetName(); - CMaterial* pMaterial = (CMaterial*) pMatInfo->GetUserData(); - - if (!pMaterial && pcName && *pcName) - { - pMaterial = LoadMaterial(pcName, false); - } - - if (pMaterial) - { - _smart_ptr pNewMatInfo = pMaterial->GetMatInfo(true); - assert(pNewMatInfo == pMatInfo); - //Only register if the material is not registered - if (!pMaterial->IsRegistered()) - { - RegisterItem(pMaterial); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnCreateMaterial(_smart_ptr pMatInfo) -{ - CMaterial* existingMaterial = static_cast(FindItemByName(UnifyMaterialName(pMatInfo->GetName()))); - bool materialAlreadyExists = existingMaterial != nullptr; - - // If its not a sub-material or a UI material - if (!(pMatInfo->GetFlags() & MTL_FLAG_PURE_CHILD) && !(pMatInfo->GetFlags() & MTL_FLAG_UIMATERIAL)) - { - // Create a new editor material if it doesn't exist - if (!materialAlreadyExists) - { - CMaterial* pMaterial = new CMaterial(pMatInfo->GetName()); - pMaterial->SetFromMatInfo(pMatInfo); - RegisterItem(pMaterial); - - AddForHighlighting(pMaterial); - } - else - { - // If the material already exists, re-set its values from the engine material that was just re-loaded - existingMaterial->SetFromMatInfo(pMatInfo); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::OnDeleteMaterial(_smart_ptr pMaterial) -{ - CMaterial* pMtl = (CMaterial*)pMaterial->GetUserData(); - if (pMtl) - { - RemoveFromHighlighting(pMtl, eHighlight_All); - DeleteMaterial(pMtl); - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialManager::IsCurrentMaterial(_smart_ptr pMaterial) const -{ - if (!pMaterial) - { - return false; - } - - CMaterial* pMtl = static_cast(pMaterial->GetUserData()); - bool currentMaterial = (pMtl == m_pCurrentMaterial); - - if (pMtl->GetParent()) - { - currentMaterial |= (pMtl->GetParent() == m_pCurrentMaterial); - } - - for (size_t subMatIdx = 0; subMatIdx < pMtl->GetMatInfo()->GetSubMtlCount(); ++subMatIdx) - { - if (static_cast(pMtl->GetMatInfo()->GetSubMtl(subMatIdx)->GetUserData()) == m_pCurrentMaterial) - { - currentMaterial = true; - break; - } - } - - return currentMaterial; -} - - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::FromIMaterial(_smart_ptr engineMaterial) -{ - if (!engineMaterial) - { - return nullptr; - } - CMaterial* editorMaterial = (CMaterial*)engineMaterial->GetUserData(); - if (!editorMaterial) - { - // If the user data isn't set, check for an existing material with the same name - editorMaterial = static_cast(FindItemByName(UnifyMaterialName(engineMaterial->GetName()))); - } - return editorMaterial; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SaveAllLibs() -{ -} - -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::FilenameToMaterial(const QString& filename) -{ - // Convert a full or relative path to a normalized name that can be used in a hash (so lowercase, relative path, correct slashes, remove extension) - // note that it may already be an asset path, if so, don't add the overhead of calling into the AP and convert it. - // if it starts with an alias (@) or if its an absolute file path, we need to convert it. Otherwise we really don't... - QString name = filename; - if (name.startsWith(QChar('@')) || AZ::IO::PathView(name.toUtf8().data()).IsAbsolute()) - { - name = Path::FullPathToGamePath(filename); // convert any full path to a relative path instead. - } - QByteArray n = name.toUtf8(); - MaterialUtils::UnifyMaterialName(n.data()); // Utility function used by all other parts of the code to unify slashes, lowercase, and remove extension - - return QString::fromUtf8(n); -} - -////////////////////////////////////////////////////////////////////////// -QString CMaterialManager::MaterialToFilename(const QString& sMaterialName) -{ - QString materialWithExtension = Path::ReplaceExtension(sMaterialName, MATERIAL_FILE_EXT); - QString fileName = Path::GamePathToFullPath(materialWithExtension); - const int mtlExtensionLength = strlen(MATERIAL_FILE_EXT); - if (fileName.right(mtlExtensionLength).toLower() != MATERIAL_FILE_EXT) - { - // we got something back which is not a mtl, fall back heuristic: - AZStd::string pathName(fileName.toUtf8().data()); - AZStd::string fileNameOfMaterial; - AzFramework::StringFunc::Path::StripFullName(pathName); // remove the filename of the path to the FBX file so now it just contains the folder of the fbx file. - AzFramework::StringFunc::Path::GetFullFileName(materialWithExtension.toUtf8().data(), fileNameOfMaterial); // remove the path part of the material so it only contains the file name - AZStd::string finalName; - AzFramework::StringFunc::Path::Join(pathName.c_str(), fileNameOfMaterial.c_str(), finalName); - fileName = finalName.c_str(); - } - return fileName; -} - -////////////////////////////////////////////////////////////////////////// -const AZ::Data::AssetType& CMaterialManager::GetMaterialAssetType() -{ - return m_materialAssetType; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::DeleteMaterial(CMaterial* pMtl) -{ - assert(pMtl); - _smart_ptr _ref(pMtl); - if (pMtl == GetCurrentMaterial()) - { - SetCurrentMaterial(NULL); - } - - DeleteItem(pMtl); - - // Delete it from all sub materials. - for (int i = 0; i < m_pLevelLibrary->GetItemCount(); i++) - { - CMaterial* pMultiMtl = (CMaterial*)m_pLevelLibrary->GetItem(i); - if (pMultiMtl->IsMultiSubMaterial()) - { - for (int slot = 0; slot < pMultiMtl->GetSubMaterialCount(); slot++) - { - if (pMultiMtl->GetSubMaterial(slot) == pMultiMtl) - { - // Clear this sub material slot. - pMultiMtl->SetSubMaterial(slot, 0); - } - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::RemoveMaterialFromDisk(const char * fileName) -{ - using namespace AzToolsFramework; - if (fileName) - { - SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::RequestDelete, fileName, - [](bool success, const SourceControlFileInfo& info) - { - //If the file is not managed by source control, delete it locally - if (!success && !info.IsManaged()) - { - QFile::remove(info.m_filePath.c_str()); - } - } - ); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::RegisterCommands(CRegistrationContext& regCtx) -{ - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "duplicate", "", "", AZStd::bind(&CMaterialManager::Command_Duplicate, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "merge", "", "", AZStd::bind(&CMaterialManager::Command_Merge, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "delete", "", "", AZStd::bind(&CMaterialManager::Command_Delete, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "assign_to_selection", "", "", AZStd::bind(&CMaterialManager::Command_AssignToSelection, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "select_assigned_objects", "", "", AZStd::bind(&CMaterialManager::Command_SelectAssignedObjects, this)); - CommandManagerHelper::RegisterCommand(regCtx.pCommandManager, "material", "select_from_object", "", "", AZStd::bind(&CMaterialManager::Command_SelectFromObject, this)); -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialManager::SelectSaveMaterial(QString& itemName, QString& fullSourcePath, const char* defaultStartPath) -{ - QString startPath; - if (defaultStartPath && defaultStartPath[0] != '\0') - { - startPath = defaultStartPath; - } - else - { - startPath = GetIEditor()->GetSearchPath(EDITOR_PATH_MATERIALS); - } - - if (!CFileUtil::SelectSaveFile("Material Files (*.mtl)", "mtl", startPath, fullSourcePath)) - { - return false; - } - - itemName = FilenameToMaterial(fullSourcePath); - if (itemName.isEmpty()) - { - return false; - } - - return true; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::SelectNewMaterial(int nMtlFlags, [[maybe_unused]] const char* sStartPath) -{ - QString path = m_pCurrentMaterial ? Path::GetPath(m_pCurrentMaterial->GetFilename()) : m_currentFolder; - QString itemName; - QString fullPath; - if (!SelectSaveMaterial(itemName, fullPath, path.toUtf8().data())) - { - return 0; - } - - if (FindItemByName(itemName)) - { - Warning("Material with name %s already exist", itemName.toUtf8().data()); - return 0; - } - - _smart_ptr mtl = CreateMaterial(itemName, XmlNodeRef(), nMtlFlags); - mtl->Update(); - bool skipReadOnly = true; - mtl->Save(skipReadOnly, fullPath); - SetCurrentMaterial(mtl); - return mtl; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Create() -{ - SelectNewMaterial(0); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_CreateMulti() -{ - SelectNewMaterial(MTL_FLAG_MULTI_SUBMTL); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_ConvertToMulti() -{ - CMaterial* pMaterial = GetCurrentMaterial(); - - if (pMaterial && pMaterial->GetSubMaterialCount() == 0) - { - CMaterial* pSubMat = new CMaterial(*pMaterial); - pSubMat->SetName(pSubMat->GetShortName()); - pSubMat->SetFlags(pSubMat->GetFlags() | MTL_FLAG_PURE_CHILD); - - pMaterial->SetFlags(MTL_FLAG_MULTI_SUBMTL); - pMaterial->SetSubMaterialCount(1); - pMaterial->SetSubMaterial(0, pSubMat); - - pMaterial->Save(); - pMaterial->Reload(); - SetSelectedItem(pSubMat); - } - else - { - Warning(pMaterial ? "azlmbr.legacy.material.convert_to_multi called on invalid material setup" : "azlmbr.legacy.material.convert_to_multi called while no material selected"); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Duplicate() -{ - CMaterial* pSrcMtl = GetCurrentMaterial(); - - if (!pSrcMtl) - { - CErrorRecord err; - err.error = "azlmbr.legacy.material.duplicate called while no materials selected"; - GetIEditor()->GetErrorReport()->ReportError(err); - return; - } - - if (GetIEditor()->IsSourceControlAvailable()) - { - uint32 attrib = pSrcMtl->GetFileAttributes(); - - if ((attrib & SCC_FILE_ATTRIBUTE_INPAK) && (attrib & SCC_FILE_ATTRIBUTE_MANAGED) && !(attrib & SCC_FILE_ATTRIBUTE_NORMAL)) - { - // Get latest for making folders with right case - CFileUtil::GetLatestFromSourceControl(pSrcMtl->GetFilename().toUtf8().data()); - } - } - - if (pSrcMtl != 0 && !pSrcMtl->IsPureChild()) - { - QString newUniqueRelativePath = MakeUniqueItemName(pSrcMtl->GetName()); - - // Create a new material. - _smart_ptr pMtl = DuplicateMaterial(newUniqueRelativePath.toUtf8().data(), pSrcMtl); - if (pMtl) - { - // Get the new filename from the relative path - AZStd::string newFileName; - AzFramework::StringFunc::Path::GetFileName(newUniqueRelativePath.toUtf8().data(), newFileName); - - // Get the full path to the original material, so we know which folder to put the new material in - AZStd::string newFullFilePath = pSrcMtl->GetFilename().toUtf8().data(); - - // Replace the original material filename with the filename from the new relative path + the material file extension to get the new full file path - AzFramework::StringFunc::Path::ReplaceFullName(newFullFilePath, newFileName.c_str(), MATERIAL_FILE_EXT); - - AzFramework::StringFunc::Path::Normalize(newFullFilePath); - - const bool skipReadOnly = true; - pMtl->Save(skipReadOnly, newFullFilePath.c_str()); - SetSelectedItem(pMtl); - } - } -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CMaterialManager::DuplicateMaterial(const char* newName, CMaterial* pOriginal) -{ - if (!newName) - { - assert(0 && "NULL newName passed into CMaterialManager::DuplicateMaterial"); - return 0; - } - if (!pOriginal) - { - assert(0 && "NULL pOriginal passed into CMaterialManager::DuplicateMaterial"); - return 0; - } - - - XmlNodeRef node = GetISystem()->CreateXmlNode("Material"); - CBaseLibraryItem::SerializeContext ctx(node, false); - ctx.bCopyPaste = true; - pOriginal->Serialize(ctx); - - return CreateMaterial(newName, node, pOriginal->GetFlags()); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GenerateUniqueSubmaterialName(const CMaterial* pSourceMaterial, const CMaterial* pTargetMaterial, QString& uniqueSubmaterialName) const -{ - QString sourceMaterialName = pSourceMaterial->GetName(); - - // We don't need the whole path to the material, just the base name - QFileInfo filename(sourceMaterialName); - sourceMaterialName = filename.baseName(); - - uniqueSubmaterialName = sourceMaterialName; - size_t nameIndex = 0; - - bool nameUpdated = true; - while (nameUpdated) - { - nameUpdated = false; - for (size_t k = 0; k < pTargetMaterial->GetSubMaterialCount(); ++k) - { - CMaterial* pSubMaterial = pTargetMaterial->GetSubMaterial(k); - if (pSubMaterial && pSubMaterial->GetName() == uniqueSubmaterialName) - { - ++nameIndex; - uniqueSubmaterialName = QStringLiteral("%1%2").arg(sourceMaterialName).arg(nameIndex, 2, 10, QLatin1Char('0')); - nameUpdated = true; - break; - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMaterialManager::DuplicateAsSubMaterialAtIndex(CMaterial* pSourceMaterial, CMaterial* pTargetMaterial, int subMaterialIndex) -{ - if (pSourceMaterial && pTargetMaterial && pTargetMaterial->GetSubMaterialCount() > subMaterialIndex) - { - // Resolve name collisions between the source material and the submaterials in the target material - QString newSubMaterialName; - GenerateUniqueSubmaterialName(pSourceMaterial, pTargetMaterial, newSubMaterialName); - - // Mark the material to be duplicated as a PURE_CHILD since it is being duplicated as a submaterial - int sourceMaterialFlags = pSourceMaterial->GetFlags(); - pSourceMaterial->SetFlags(sourceMaterialFlags | MTL_FLAG_PURE_CHILD); - - CMaterial* pNewSubMaterial = DuplicateMaterial(newSubMaterialName.toUtf8().data(), pSourceMaterial); - pTargetMaterial->SetSubMaterial(subMaterialIndex, pNewSubMaterial); - - // Reset the flags of the source material to their original values - pSourceMaterial->SetFlags(sourceMaterialFlags); - return true; - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Merge() -{ - QString itemName; - QString fullPath; - QString defaultMaterialPath; - if (m_pCurrentMaterial) - { - defaultMaterialPath = Path::GetPath(m_pCurrentMaterial->GetFilename()); - } - if (!SelectSaveMaterial(itemName, fullPath, defaultMaterialPath.toUtf8().data())) - { - return; - } - - _smart_ptr pNewMaterial = CreateMaterial(itemName, XmlNodeRef(), MTL_FLAG_MULTI_SUBMTL); - - size_t totalSubMaterialCount = 0; - for (_smart_ptr pMaterial : m_markedMaterials) - { - if (pMaterial->IsMultiSubMaterial()) - { - totalSubMaterialCount += pMaterial->GetSubMaterialCount(); - } - else - { - totalSubMaterialCount++; - } - } - pNewMaterial->SetSubMaterialCount(totalSubMaterialCount); - - size_t subMaterialIndex = 0; - for (_smart_ptr pMaterial : m_markedMaterials) - { - if (pMaterial->IsMultiSubMaterial()) - { - // Loop through each submaterial and duplicate it as a submaterial in the new material - for (size_t j = 0; j < pMaterial->GetSubMaterialCount(); ++j) - { - CMaterial* pSubMaterial = pMaterial->GetSubMaterial(j); - if (DuplicateAsSubMaterialAtIndex(pSubMaterial, pNewMaterial, subMaterialIndex)) - { - ++subMaterialIndex; - } - } - } - else - { - // Duplicate the material as a submaterial in the new material - if (DuplicateAsSubMaterialAtIndex(pMaterial, pNewMaterial, subMaterialIndex)) - { - ++subMaterialIndex; - } - } - } - - pNewMaterial->Update(); - const bool skipReadOnly = true; - pNewMaterial->Save(skipReadOnly, fullPath); - SetCurrentMaterial(pNewMaterial); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_Delete() -{ - CMaterial* pMtl = GetCurrentMaterial(); - if (pMtl) - { - CUndo undo("Delete Material"); - QString str = QObject::tr("Delete Material %1?\r\nNote: Material file %2 will also be deleted.") - .arg(pMtl->GetName(), pMtl->GetFilename()); - if (QMessageBox::question(QApplication::activeWindow(), QObject::tr("Delete Confirmation"), str) == QMessageBox::Yes) - { - AZStd::string matName = pMtl->GetFilename().toUtf8().data(); - DeleteMaterial(pMtl); - RemoveMaterialFromDisk(matName.c_str()); - SetCurrentMaterial(0); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_AssignToSelection() -{ - CMaterial* pMtl = GetCurrentMaterial(); - if (pMtl) - { - CUndo undo("Assign Material"); - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - if (pMtl->IsPureChild()) - { - const QString title = QObject::tr("Assign Submaterial"); - const QString message = QObject::tr("You can assign submaterials to objects only for preview purpose. This assignment will not be saved with the level and will not be exported to the game."); - if (QMessageBox::information(QApplication::activeWindow(), title, message, QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) - { - return; - } - } - if (!pSel->IsEmpty()) - { - for (int i = 0; i < pSel->GetCount(); i++) - { - pSel->GetObject(i)->SetMaterial(pMtl); - } - } - } - CViewport* pViewport = GetIEditor()->GetActiveView(); - if (pViewport) - { - pViewport->Drop(QPoint(-1, -1), pMtl); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_ResetSelection() -{ - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - if (!pSel->IsEmpty()) - { - CUndo undo("Reset Material"); - for (int i = 0; i < pSel->GetCount(); i++) - { - pSel->GetObject(i)->SetMaterial(0); - } - } - CViewport* pViewport = GetIEditor()->GetActiveView(); - if (pViewport) - { - pViewport->Drop(QPoint(-1, -1), 0); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_SelectAssignedObjects() -{ - CMaterial* pMtl = GetCurrentMaterial(); - if (pMtl) - { - CUndo undo("Select Object(s)"); - CBaseObjectsArray objects; - GetIEditor()->GetObjectManager()->GetObjects(objects); - for (int i = 0; i < objects.size(); i++) - { - CBaseObject* pObject = objects[i]; - if (pObject->GetMaterial() == pMtl || pObject->GetRenderMaterial() == pMtl) - { - if (pObject->IsHidden() || pObject->IsFrozen()) - { - continue; - } - GetIEditor()->GetObjectManager()->SelectObject(pObject); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::Command_SelectFromObject() -{ - if (GetIEditor()->IsInPreviewMode()) - { - CViewport* pViewport = GetIEditor()->GetActiveView(); - if (CModelViewport* p = viewport_cast(pViewport)) - { - CMaterial* pMtl = p->GetMaterial(); - SetCurrentMaterial(pMtl); - } - return; - } - - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - if (pSel->IsEmpty()) - { - return; - } - - for (int i = 0; i < pSel->GetCount(); i++) - { - CMaterial* pMtl = pSel->GetObject(i)->GetRenderMaterial(); - if (pMtl) - { - SetCurrentMaterial(pMtl); - return; - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::PickPreviewMaterial() -{ - XmlNodeRef data = XmlHelpers::CreateXmlNode("ExportMaterial"); - CMaterial* pMtl = GetCurrentMaterial(); - if (!pMtl) - { - return; - } - - if (pMtl->IsPureChild() && pMtl->GetParent()) - { - pMtl = pMtl->GetParent(); - } - - if (pMtl->GetFlags() & MTL_FLAG_WIRE) - { - data->setAttr("Flag_Wire", 1); - } - if (pMtl->GetFlags() & MTL_FLAG_2SIDED) - { - data->setAttr("Flag_2Sided", 1); - } - - data->setAttr("Name", pMtl->GetName().toUtf8().data()); - data->setAttr("FileName", pMtl->GetFilename().toUtf8().data()); - - XmlNodeRef node = data->newChild("Material"); - - CBaseLibraryItem::SerializeContext serCtx(node, false); - pMtl->Serialize(serCtx); - - - if (!pMtl->IsMultiSubMaterial()) - { - XmlNodeRef texturesNode = node->findChild("Textures"); - if (texturesNode) - { - for (int i = 0; i < texturesNode->getChildCount(); i++) - { - XmlNodeRef texNode = texturesNode->getChild(i); - QString file; - if (texNode->getAttr("File", file)) - { - texNode->setAttr("File", Path::GamePathToFullPath(file).toUtf8().data()); - } - } - } - } - else - { - XmlNodeRef childsNode = node->findChild("SubMaterials"); - if (childsNode) - { - int nSubMtls = childsNode->getChildCount(); - for (int i = 0; i < nSubMtls; i++) - { - XmlNodeRef node2 = childsNode->getChild(i); - XmlNodeRef texturesNode = node2->findChild("Textures"); - if (texturesNode) - { - for (int ii = 0; ii < texturesNode->getChildCount(); ii++) - { - XmlNodeRef texNode = texturesNode->getChild(ii); - QString file; - if (texNode->getAttr("File", file)) - { - texNode->setAttr("File", Path::GamePathToFullPath(file).toUtf8().data()); - } - } - } - } - } - } - - - m_MatSender->SendMessage(eMSM_GetSelectedMaterial, data); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SyncMaterialEditor() -{ -#if defined(AZ_PLATFORM_WINDOWS) - if (!m_MatSender) - { - return; - } - - if (!m_MatSender->GetMessage()) - { - return; - } - - if (m_MatSender->m_h.msg == eMSM_Create) - { - XmlNodeRef node = m_MatSender->m_node->findChild("Material"); - if (!node) - { - return; - } - - QString sMtlName; - QString sMaxFile; - - XmlNodeRef root = m_MatSender->m_node; - root->getAttr("Name", sMtlName); - root->getAttr("MaxFile", sMaxFile); - - int IsMulti = 0; - root->getAttr("IsMulti", IsMulti); - - int nMtlFlags = 0; - if (IsMulti) - { - nMtlFlags |= MTL_FLAG_MULTI_SUBMTL; - } - - if (root->haveAttr("Flag_Wire")) - { - nMtlFlags |= MTL_FLAG_WIRE; - } - if (root->haveAttr("Flag_2Sided")) - { - nMtlFlags |= MTL_FLAG_2SIDED; - } - - _smart_ptr pMtl = SelectNewMaterial(nMtlFlags, Path::GetPath(sMaxFile).toUtf8().data()); - - if (!pMtl) - { - return; - } - - if (!IsMulti) - { - node->delAttr("Shader"); // Remove shader attribute. - XmlNodeRef texturesNode = node->findChild("Textures"); - if (texturesNode) - { - for (int i = 0; i < texturesNode->getChildCount(); i++) - { - XmlNodeRef texNode = texturesNode->getChild(i); - QString file; - if (texNode->getAttr("File", file)) - { - //make path relative to the project specific game folder - QString newfile = Path::MakeGamePath(file); - if (!newfile.isEmpty()) - { - file = newfile; - } - texNode->setAttr("File", file.toUtf8().data()); - } - } - } - } - else - { - XmlNodeRef childsNode = node->findChild("SubMaterials"); - if (childsNode) - { - int nSubMtls = childsNode->getChildCount(); - for (int i = 0; i < nSubMtls; i++) - { - XmlNodeRef node2 = childsNode->getChild(i); - node2->delAttr("Shader"); // Remove shader attribute. - XmlNodeRef texturesNode = node2->findChild("Textures"); - if (texturesNode) - { - for (int ii = 0; ii < texturesNode->getChildCount(); ii++) - { - XmlNodeRef texNode = texturesNode->getChild(ii); - QString file; - if (texNode->getAttr("File", file)) - { - //make path relative to the project specific game folder - QString newfile = Path::MakeGamePath(file); - if (!newfile.isEmpty()) - { - file = newfile; - } - texNode->setAttr("File", file.toUtf8().data()); - } - } - } - } - } - } - - CBaseLibraryItem::SerializeContext ctx(node, true); - ctx.bUndo = true; - pMtl->Serialize(ctx); - - pMtl->Update(); - - SetCurrentMaterial(0); - SetCurrentMaterial(pMtl); - } - - if (m_MatSender->m_h.msg == eMSM_GetSelectedMaterial) - { - PickPreviewMaterial(); - } -#endif -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::InitMatSender() -{ - //MatSend(true); - m_MatSender->Create(); - QWidget* mainWindow = MainWindow::instance(); - m_MatSender->SetupWindows(mainWindow, mainWindow); - XmlNodeRef node = XmlHelpers::CreateXmlNode("Temp"); - m_MatSender->SendMessage(eMSM_Init, node); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GotoMaterial([[maybe_unused]] CMaterial* pMaterial) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GotoMaterial([[maybe_unused]] _smart_ptr pMtl) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetHighlightedMaterial(CMaterial* pMtl) -{ - if (m_pHighlightMaterial) - { - RemoveFromHighlighting(m_pHighlightMaterial, eHighlight_Pick); - } - - m_pHighlightMaterial = pMtl; - if (m_pHighlightMaterial) - { - AddForHighlighting(m_pHighlightMaterial); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::HighlightedMaterialChanged(CMaterial* pMtl) -{ - if (!pMtl) - { - return; - } - - RemoveFromHighlighting(pMtl, eHighlight_All); - AddForHighlighting(pMtl); -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::SetHighlightMask(int highlightMask) -{ - if (m_highlightMask != highlightMask) - { - m_highlightMask = highlightMask; - - UpdateHighlightedMaterials(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GatherResources(_smart_ptr pMaterial, CUsedResources& resources) -{ - if (!pMaterial) - { - return; - } - - int nSubMtlCount = pMaterial->GetSubMtlCount(); - if (nSubMtlCount > 0) - { - for (int i = 0; i < nSubMtlCount; i++) - { - GatherResources(pMaterial->GetSubMtl(i), resources); - } - } - else - { - SShaderItem& shItem = pMaterial->GetShaderItem(); - if (shItem.m_pShaderResources) - { - SInputShaderResources res; - shItem.m_pShaderResources->ConvertToInputResource(&res); - - for (auto& iter : res.m_TexturesResourcesMap ) - { - SEfResTexture* pTexture = &(iter.second); - if (!pTexture->m_Name.empty()) - { - resources.Add(pTexture->m_Name.c_str()); - } - } - gEnv->pRenderer->EF_ReleaseInputShaderResource(&res); - } - } -} - -/////////////////////////////////////////////////////////////////////////// -void CMaterialManager::GetHighlightColor(ColorF* color, float* intensity, int flags) -{ - MAKE_SURE(m_pHighlighter, return ); - m_pHighlighter->GetHighlightColor(color, intensity, flags); -} - -/////////////////////////////////////////////////////////////////////////// -// This will be called when the editor welcome screen is displayed. -// At this point the editor is ready for UI events, which means we can -// process .dccmtl paths and display error to the user if necessary -bool CMaterialManager::SkipEditorStartupUI() -{ - // Editor started - m_bEditorUiReady = true; - - // If we have any file paths buffered - if (m_sourceControlBuffer.size() > 0) - { - // Start queuing - QueueSourceControlTick(); - } - - // Launch thread responsible for saving cached - // .dccmtl files as source .mtl files - StartDccMaterialSaveThread(); - - // Never want to skip Startup UI - return false; -} - -/////////////////////////////////////////////////////////////////////////// -// Queues the function TickSourceControl() to be exectued next frame -void CMaterialManager::QueueSourceControlTick() -{ - // If TickSourceControl is not currently queued - if (!m_sourceControlFunctionQueued) - { - // Queue it - AZStd::function tickFunction = [this]() - { - TickSourceControl(); - }; - AZ::SystemTickBus::QueueFunction(tickFunction); - - // Stop further queues as TickSourceControl will queue itself - // until there are no more paths in the buffer to process - m_sourceControlFunctionQueued = true; - } -} - -/////////////////////////////////////////////////////////////////////////// -// Takes a single path from m_sourceControlBuffer and passes it to -// DccMaterialSourceControlCheck(). Then if there are more paths -// remaining in the buffer, it will queue itself for execution next -// frame. The reason for doing only one material every tick is to avoid -// flooding source control with too many requests and stalling the editor -void CMaterialManager::TickSourceControl() -{ - m_sourceControlFunctionQueued = false; - AZStd::string filePath; - bool moreRemaining = false; - - { - AZStd::lock_guard lock(m_sourceControlBufferMutex); - - if (m_sourceControlBuffer.size() < 1) - { - return; - } - - filePath = m_sourceControlBuffer.back(); - m_sourceControlBuffer.pop_back(); - moreRemaining = !m_sourceControlBuffer.empty(); - } - - // Process it - DccMaterialSourceControlCheck(filePath); - - // If there are more paths to check - if (moreRemaining) - { - // Queue again - QueueSourceControlTick(); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Launches new thread running the DccMaterialSaveThreadFunc() function -void CMaterialManager::StartDccMaterialSaveThread() -{ - AZStd::thread_desc threadDesc; - threadDesc.m_name = "Dcc Material Save Thread"; - - m_dccMaterialSaveThread = AZStd::thread( - [this]() - { - DccMaterialSaveThreadFunc(); - }, - &threadDesc); -} - -/////////////////////////////////////////////////////////////////////////// -// Will save all the .dccmtl file paths in the buffer to source .mtl -// Runs on a separate thread so as not to stall the main thread -void CMaterialManager::DccMaterialSaveThreadFunc() -{ - while (true) - { - m_dccMaterialSaveSemaphore.acquire(); - - // Exit condition, set to true in destructor - if (m_joinThreads) - { - return; - } - - AZStd::vector dccMaterialPaths; - - // Lock the buffer and copy file paths locally - { - AZStd::lock_guard lock(m_dccMaterialSaveMutex); - dccMaterialPaths.reserve(m_dccMaterialSaveBuffer.size()); - for (AZStd::string& fileName : m_dccMaterialSaveBuffer) - { - dccMaterialPaths.push_back(fileName); - } - m_dccMaterialSaveBuffer.clear(); - } - - // Save all the buffered .dccmtl files - for (AZStd::string& fileName : dccMaterialPaths) - { - SaveDccMaterial(fileName); - } - - // Clear local strings - dccMaterialPaths.clear(); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Async source control request. If successful, the callback will add the -// file name to the buffer for processing by the Dcc Material Save Thread -void CMaterialManager::DccMaterialSourceControlCheck(const AZStd::string& relativeDccMaterialPath) -{ - AZStd::string fullSourcePath = DccMaterialToSourcePath(relativeDccMaterialPath); - - if (!DccMaterialRequiresSave(relativeDccMaterialPath, fullSourcePath)) - { - // Source .mtl update not required, early out - return; - } - - // Create callback for source control operation (see SCCommandBus::Broadcast below) - AzToolsFramework::SourceControlResponseCallback callback = - [this, relativeDccMaterialPath, fullSourcePath](bool success, const AzToolsFramework::SourceControlFileInfo& info) - { - if (success || !info.IsReadOnly()) - { - // File needs saving, add it to the buffer for processing by the dcc material thread - - // Lock access to the buffer - AZStd::lock_guard lock(m_dccMaterialSaveMutex); - - // Add file path - m_dccMaterialSaveBuffer.push_back(relativeDccMaterialPath); - - // Notify thread there's work to do - m_dccMaterialSaveSemaphore.release(); - } - else - { - QString errorMessage = QObject::tr("Could not check out read-only file %1 in source control. Either check your source control configuration or disable source control.").arg(QString::fromUtf8(fullSourcePath.c_str())); - - // Alter error message slightly if source control is disabled - bool isSourceControlActive = false; - AzToolsFramework::SourceControlConnectionRequestBus::BroadcastResult(isSourceControlActive, &AzToolsFramework::SourceControlConnectionRequestBus::Events::IsActive); - - if (!isSourceControlActive) - { - errorMessage = QObject::tr("Could not check out read-only file %1 because source control is disabled. Either enable source control or check out the file manually to make it writable.").arg(QString::fromUtf8(fullSourcePath.c_str())); - } - - // Pop open an error message box if this is the first error we encounter - if (!m_bSourceControlErrorReported) - { - // Report warning in message box - QString errorTitle = QStringLiteral("Dcc Material Error"); - QMessageBox::warning(QApplication::activeWindow(), errorTitle, errorMessage, QMessageBox::Cancel); - - // Only report source control error box to the user once, - // no need to spam them for every material - m_bSourceControlErrorReported = true; - } - - AZ_Error("Rendering", false, errorMessage.toUtf8().data()); - } - }; - - // Request edit from source control (happens asynchronously) - using SCCommandBus = AzToolsFramework::SourceControlCommandBus; - SCCommandBus::Broadcast(&SCCommandBus::Events::RequestEdit, fullSourcePath.c_str(), true, callback); -} - -/////////////////////////////////////////////////////////////////////////// -// Handles when .dccmtl is created -void CMaterialManager::EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* assetEntry) -{ - if (assetEntry->GetEntryType() != AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Product) - { - // Ignore non-product entries - return; - } - const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry* productAssetEntry = azrtti_cast(assetEntry); - if (productAssetEntry && productAssetEntry->GetAssetType() != m_dccMaterialAssetType) - { - // Ignore types that aren't .dccmtl - return; - } - - AddDccMaterialPath(productAssetEntry->GetRelativePath()); -} - -/////////////////////////////////////////////////////////////////////////// -// Handles when .dccmtl is edited -void CMaterialManager::OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) -{ - AZ::Data::AssetInfo assetInfo; - EBUS_EVENT_RESULT(assetInfo, AZ::Data::AssetCatalogRequestBus, GetAssetInfoById, assetId); - - if (assetInfo.m_assetType != m_dccMaterialAssetType) - { - // Ignore types that aren't .dccmtl - return; - } - - AddDccMaterialPath(assetInfo.m_relativePath); -} - -/////////////////////////////////////////////////////////////////////////// -void CMaterialManager::AddDccMaterialPath(const AZStd::string relativeDccMaterialPath) -{ - if (relativeDccMaterialPath.empty()) - { - return; - } - - // Lock access to the buffer - AZStd::lock_guard lock(m_sourceControlBufferMutex); - - // Add file path - m_sourceControlBuffer.push_back(relativeDccMaterialPath); - - if (m_bEditorUiReady) - { - QueueSourceControlTick(); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Given the path of a .dccmtl in cache, save it as a source .mtl -void CMaterialManager::SaveDccMaterial(const AZStd::string& relativeDccMaterialPath) -{ - // __________________________________________________ - // Load .dccmtl - - XmlNodeRef dccNode = GetISystem()->LoadXmlFromFile(relativeDccMaterialPath.c_str()); - - if (!dccNode) - { - AZ_Error("MaterialManager", false, "CMaterialManager::SaveDccMaterial: Failed to load XML node from .dccmtl file: %s", relativeDccMaterialPath.c_str()); - return; - } - - // __________________________________________________ - // Save as source .mtl file - - AZStd::string fullSourcePath = DccMaterialToSourcePath(relativeDccMaterialPath); - bool saveSuccessful = dccNode->saveToFile(fullSourcePath.c_str()); - - if (!saveSuccessful) - { - AZ_Error("MaterialManager", false, "CMaterialManager::SaveDccMaterial: Failed to save source .mtl from .dccmtl file: %s", relativeDccMaterialPath.c_str()); - } -} - -/////////////////////////////////////////////////////////////////////////// -// Compares the hash values from .dccmtl and source .mtl to determine if -// .dccmtl has changed and needs to be saved. -bool CMaterialManager::DccMaterialRequiresSave(const AZStd::string& relativeDccMaterialPath, const AZStd::string& fullSourcePath) -{ - // __________________________________________________ - // Get Source Hash - - AZ::u32 sourceHash = 0; - - // Check if material is already loaded - QString unifiedName = UnifyMaterialName(QString(relativeDccMaterialPath.c_str())); - CMaterial* sourceMaterial = (CMaterial*)FindItemByName(unifiedName); - - if (sourceMaterial && !sourceMaterial->IsDummy()) - { - sourceHash = sourceMaterial->GetDccMaterialHash(); - } - else - { - XmlNodeRef sourceNode = GetISystem()->LoadXmlFromFile(fullSourcePath.c_str()); - if (sourceNode) - { - sourceNode->getAttr("DccMaterialHash", sourceHash); - } - else - { - // Couldn't find source node or material, so we need to save the dcc material as a source material - // No need to check the dcc material hash, just return true - return true; - } - } - - // __________________________________________________ - // Get DCC material Hash - - AZ::u32 dccHash = 0; - XmlNodeRef dccNode = GetISystem()->LoadXmlFromFile(relativeDccMaterialPath.c_str()); - - if (!dccNode) - { - AZ_Error("MaterialManager", false, "CMaterialManager::DccMaterialRequiresSave: Failed to load XML node from .dccmtl file: %s", relativeDccMaterialPath.c_str()); - return false; - } - - dccNode->getAttr("DccMaterialHash", dccHash); - - // __________________________________________________ - // Compare hash values - - // Only update if .dccmtl hash is different from the source hash - return (dccHash != sourceHash); -} - diff --git a/Code/Sandbox/Editor/Material/MaterialManager.h b/Code/Sandbox/Editor/Material/MaterialManager.h deleted file mode 100644 index a9dcabfa40..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialManager.h +++ /dev/null @@ -1,300 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H -#define CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H -#pragma once - -#include "BaseLibraryManager.h" -#include "Material.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -class CMaterial; -class CMaterialLibrary; -class CMaterialHighlighter; - -namespace AZ -{ - struct Uuid; -} - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - struct SourceFileOpenerDetails; - typedef AZStd::vector SourceFileOpenerList; - } -} - -enum EHighlightMode -{ - eHighlight_Pick = BIT(0), - eHighlight_Breakable = BIT(1), - eHighlight_NoSurfaceType = BIT(2), - eHighlight_All = 0xFFFFFFFF -}; - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -/** Manages all entity prototypes and material libraries. -*/ -class CRYEDIT_API CMaterialManager - : public IEditorMaterialManager - , public CBaseLibraryManager - , public IMaterialManagerListener - , protected AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - , public AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationBus::Handler - , public AzFramework::AssetCatalogEventBus::Handler - , public AzToolsFramework::EditorEvents::Bus::Handler -{ -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - - //! Notification callback. - typedef AZStd::function NotifyCallback; - - CMaterialManager(CRegistrationContext& regCtx); - ~CMaterialManager(); - - void Set3DEngine(); - - // Clear all prototypes and material libraries. - void ClearAll(); - - ////////////////////////////////////////////////////////////////////////// - // Materials. - ////////////////////////////////////////////////////////////////////////// - - // Loads material. - CMaterial* LoadMaterial(const QString& sMaterialName, bool bMakeIfNotFound = true); - XmlNodeRef LoadXmlNode(const QString &fullSourcePath, const QString &relativeFilePath); - //! Loads a material, avoiding a call to CMaterialManager::MaterialToFilename if the full path is already known - CMaterial* LoadMaterialWithFullSourcePath(const QString& relativeFilePath, const QString& fullSourcePath, bool makeIfNotFound = true); - virtual CMaterial* LoadMaterial(const char* sMaterialName, bool bMakeIfNotFound = true); - virtual void OnRequestMaterial(_smart_ptr pMaterial); - // Creates a new material from a xml node. - CMaterial* CreateMaterial(const QString& sMaterialName, const XmlNodeRef& node = XmlNodeRef(), int nMtlFlags = 0, unsigned long nLoadingFlags = 0); - virtual CMaterial* CreateMaterial(const char* sMaterialName, const XmlNodeRef& node = XmlNodeRef(), int nMtlFlags = 0, unsigned long nLoadingFlags = 0); - - // Duplicate material and do nothing more. - CMaterial* DuplicateMaterial(const char* newName, CMaterial* pOriginal); - - // Delete specified material, erases material file, and unassigns from all objects. - virtual void DeleteMaterial(CMaterial* pMtl); - virtual void RemoveMaterialFromDisk(const char* fileName); - - - //! Export property manager to game. - void Export(XmlNodeRef& node); - int ExportLib(CMaterialLibrary* pLib, XmlNodeRef& libNode); - - virtual void SetSelectedItem(IDataBaseItem* pItem); - void SetCurrentMaterial(CMaterial* pMtl); - //! Get currently active material. - CMaterial* GetCurrentMaterial() const; - - void SetCurrentFolder(const QString& folder); - - // This material will be highlighted - void SetHighlightedMaterial(CMaterial* pMtl); - void GetHighlightColor(ColorF* color, float* intensity, int flags); - void HighlightedMaterialChanged(CMaterial* pMtl); - // highlightMask is a combination of EHighlightMode flags - void SetHighlightMask(int highlightMask); - int GetHighlightMask() const{ return m_highlightMask; } - void SetMarkedMaterials(const std::vector<_smart_ptr >& markedMaterials); - void OnLoadShader(CMaterial* pMaterial); - - //! Serialize property manager. - virtual void Serialize(XmlNodeRef& node, bool bLoading); - - virtual void SaveAllLibs(); - - ////////////////////////////////////////////////////////////////////////// - // IMaterialManagerListener implementation - ////////////////////////////////////////////////////////////////////////// - // Called when material manager tries to load a material. - virtual void OnCreateMaterial(_smart_ptr pMaterial); - virtual void OnDeleteMaterial(_smart_ptr pMaterial); - virtual bool IsCurrentMaterial(_smart_ptr pMaterial) const; - ////////////////////////////////////////////////////////////////////////// - - // Convert filename of material file into the name of the material. - QString FilenameToMaterial(const QString& filename); - - // Convert name of the material to the filename. - QString MaterialToFilename(const QString& sMaterialName); - - //! Get the full file path of the source material - const AZ::Data::AssetType& GetMaterialAssetType(); - - ////////////////////////////////////////////////////////////////////////// - // Convert 3DEngine IMaterial to Editor's CMaterial pointer. - CMaterial* FromIMaterial(_smart_ptr pMaterial); - - // Open File selection dialog to create a new material. - CMaterial* SelectNewMaterial(int nMtlFlags, const char* sStartPath = NULL); - - // Synchronize material between 3dsMax and editor. - void SyncMaterialEditor(); - - ////////////////////////////////////////////////////////////////////////// - void GotoMaterial(CMaterial* pMaterial); - void GotoMaterial(_smart_ptr pMaterial); - - // Gather resources from the game material. - static void GatherResources(_smart_ptr pMaterial, CUsedResources& resources); - - void Command_Create(); - void Command_CreateMulti(); - void Command_ConvertToMulti(); - void Command_Duplicate(); - void Command_Merge(); - void Command_Delete(); - void Command_AssignToSelection(); - void Command_ResetSelection(); - void Command_SelectAssignedObjects(); - void Command_SelectFromObject(); - -protected: - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // protected AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - void AddSourceFileOpeners(const char* fullSourceFileName, const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) override; - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // public AzToolsFramework::AssetBrowser::AssetBrowserModelNotificationsBus::Handler - void EntryAdded(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // AssetCatalogEventBus Functions - void OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) override; - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // EditorEventsBus Functions - bool SkipEditorStartupUI() override; - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - void SaveDccMaterial(const AZStd::string& relativeDccMaterialPath); - bool DccMaterialRequiresSave(const AZStd::string& relativeDccMaterialPath, const AZStd::string& fullSourcePath); - void DccMaterialSourceControlCheck(const AZStd::string& relativeDccMaterialPath); - void AddDccMaterialPath(const AZStd::string relativeDccMaterialPath); - void TickSourceControl(); - void QueueSourceControlTick(); - - // Duplicate the source material and set it as a submaterial of the target material at subMaterialIndex. Returns true if successful. - bool DuplicateAsSubMaterialAtIndex(CMaterial* pSourceMaterial, CMaterial* pTargetMaterial, int subMaterialIndex); - // Generates a unique variant of the name of the source material to resolve name collisions with the names of the submaterials in the target material. - void GenerateUniqueSubmaterialName(const CMaterial* pSourceMaterial, const CMaterial* pTargetMaterial, QString& uniqueSubmaterialName) const; - - // Open save as dialog for saving materials. - bool SelectSaveMaterial(QString& itemName, QString& fullPath, const char* defaultStartPath); - - void OnEditorNotifyEvent(EEditorNotifyEvent event); - - virtual CBaseLibraryItem* MakeNewItem(); - virtual CBaseLibrary* MakeNewLibrary(); - //! Root node where this library will be saved. - virtual QString GetRootNodeName(); - //! Path to libraries in this manager. - virtual QString GetLibsPath(); - virtual void ReportDuplicateItem(CBaseLibraryItem* pItem, CBaseLibraryItem* pOldItem); - - void RegisterCommands(CRegistrationContext& regCtx); - - void UpdateHighlightedMaterials(); - void AddForHighlighting(CMaterial* pMaterial); - void RemoveFromHighlighting(CMaterial* pMaterial, int mask); - int GetHighlightFlags(CMaterial* pMaterial) const; - - // For material syncing with 3dsMax. - void PickPreviewMaterial(); - void InitMatSender(); - - //! Reloads any registered materials that have been modified by the runtime. - void ReloadDirtyMaterials(); - -protected: - QString m_libsPath; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - // Currently selected (focused) material, in material browser. - _smart_ptr m_pCurrentMaterial; - // current selected folder - QString m_currentFolder; - // List of materials selected in material browser tree. - std::vector<_smart_ptr > m_markedMaterials; - // IMaterial is needed to not let 3Dengine release selected IMaterial - _smart_ptr m_pCurrentEngineMaterial; - - // Paths of .dccmtl that might require saving. They will be fed to - // DccMaterialSourceControlCheck() and if saving is required, they - // will be added to m_dccMaterialSaveBuffer - AZStd::vector m_sourceControlBuffer; - AZStd::mutex m_sourceControlBufferMutex; - AZStd::atomic_bool m_sourceControlFunctionQueued; - - // Paths of .dccmtl that require saving. These paths have - // gone through DccMaterialSourceControlCheck() and will - // be saved by the dcc material save thread - AZStd::vector m_dccMaterialSaveBuffer; - AZStd::mutex m_dccMaterialSaveMutex; - - // Material highlighting - _smart_ptr m_pHighlightMaterial; - CMaterialHighlighter* m_pHighlighter; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - int m_highlightMask; - - bool m_bHighlightingMaterial; - - // Only begin processing .dccmtl filepaths once editor is ready - // and we can display appropriate error messages - bool m_bEditorUiReady; - - // Only report source control error to the user once, - // no need to spam them for every material - bool m_bSourceControlErrorReported; - - class CMaterialSender* m_MatSender; - -private: - CMaterial* LoadMaterialInternal(const QString &materialNameClear, const QString &fullSourcePath, const QString &relativeFilePath, bool bMakeIfNotFound); - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - AZ::Data::AssetType m_materialAssetType; - AZ::Data::AssetType m_dccMaterialAssetType; - - void StartDccMaterialSaveThread(); - void DccMaterialSaveThreadFunc(); - AZStd::thread m_dccMaterialSaveThread; - AZStd::atomic_bool m_joinThreads; - AZStd::binary_semaphore m_dccMaterialSaveSemaphore; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H diff --git a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.cpp b/Code/Sandbox/Editor/Material/MaterialPreviewModelView.cpp deleted file mode 100644 index 3e1bc37c6a..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -#include "MaterialPreviewModelView.h" - - - -MaterialPreviewModelView::MaterialPreviewModelView(QWidget* parent, bool enableIdleUpdate) - : CPreviewModelView(parent) - , m_enableIdleUpdate(enableIdleUpdate) -{} - -MaterialPreviewModelView::~MaterialPreviewModelView() -{} - -void MaterialPreviewModelView::SetCameraLookAt(float fRadiusScale, const Vec3& fromDir) -{ - IStatObj* target = GetStaticModel(); - if (target) - { - Vec3 dir = fromDir.GetNormalized(); - - // Calculate the camera matrix - Matrix34 tm = Matrix33::CreateRotationVDir(dir, 0); - Vec3 translation = target->GetAABB().GetCenter() - dir * target->GetAABB().GetRadius() * fRadiusScale; - tm.SetTranslation(translation); - - // Convert it to a quaternion and move the viewport's camera - QuatT quat(tm); - CameraMoved(quat, true); - } -} - -void MaterialPreviewModelView::SetMaterial(_smart_ptr material) -{ - IStatObj* staticModel = GetStaticModel(); - if (staticModel) - { - staticModel->SetMaterial(material); - } -} - -void MaterialPreviewModelView::resizeEvent(QResizeEvent* event) -{ - if (m_enableIdleUpdate) - { - CPreviewModelView::resizeEvent(event); - } -} - -void MaterialPreviewModelView::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnIdleUpdate: - { - if (m_enableIdleUpdate) - { - Update(); - } - break; - } - default: - break; - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.h b/Code/Sandbox/Editor/Material/MaterialPreviewModelView.h deleted file mode 100644 index 0df7c1767f..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPreviewModelView.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include "PreviewModelView.h" - -class MaterialPreviewModelView - : public CPreviewModelView -{ -public: - // set enableIdleUpdate to false if you don't want the view to update itself during - // application idle notification (and resize events). That makes sense when this view - // is only used to render into memory bitmaps. Note that the view has to been visible - // for that, but can be somewhere of-screen. - MaterialPreviewModelView(QWidget* parent, bool enableIdleUpdate = true); - virtual ~MaterialPreviewModelView(); - void SetCameraLookAt(float fRadiusScale, const Vec3& fromDir); - void SetMaterial(_smart_ptr material); - void OnEditorNotifyEvent(EEditorNotifyEvent event) override; - -protected: - void resizeEvent(QResizeEvent* event) override; - -private: - bool m_enableIdleUpdate; -}; diff --git a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.cpp b/Code/Sandbox/Editor/Material/MaterialPythonFuncs.cpp deleted file mode 100644 index 5de75a7c39..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.cpp +++ /dev/null @@ -1,2208 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Material support for Python - -#include "EditorDefs.h" - -#include "MaterialPythonFuncs.h" - -// Editor -#include "MaterialManager.h" -#include "ShaderEnum.h" - - -namespace -{ - void PyMaterialCreate() - { - GetIEditor()->GetMaterialManager()->Command_Create(); - } - - void PyMaterialCreateMulti() - { - GetIEditor()->GetMaterialManager()->Command_CreateMulti(); - } - - void PyMaterialConvertToMulti() - { - GetIEditor()->GetMaterialManager()->Command_ConvertToMulti(); - } - - void PyMaterialDuplicateCurrent() - { - GetIEditor()->GetMaterialManager()->Command_Duplicate(); - } - - void PyMaterialMergeSelection() - { - GetIEditor()->GetMaterialManager()->Command_Merge(); - } - - void PyMaterialDeleteCurrent() - { - GetIEditor()->GetMaterialManager()->Command_Delete(); - } - - void PyMaterialAssignCurrentToSelection() - { - CUndo undo("Assign Material To Selection"); - GetIEditor()->GetMaterialManager()->Command_AssignToSelection(); - } - - void PyMaterialResetSelection() - { - GetIEditor()->GetMaterialManager()->Command_ResetSelection(); - } - - void PyMaterialSelectObjectsWithCurrent() - { - CUndo undo("Select Objects With Current Material"); - GetIEditor()->GetMaterialManager()->Command_SelectAssignedObjects(); - } - - void PyMaterialSetCurrentFromObject() - { - GetIEditor()->GetMaterialManager()->Command_SelectFromObject(); - } - - AZStd::vector PyGetSubMaterial(const char* pMaterialPath) - { - QString materialPath = pMaterialPath; - CMaterial* pMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(pMaterialPath, false); - if (!pMaterial) - { - throw std::runtime_error("Invalid multi material."); - } - - AZStd::vector result; - for (int i = 0; i < pMaterial->GetSubMaterialCount(); i++) - { - if (pMaterial->GetSubMaterial(i)) - { - result.push_back((materialPath + "\\" + pMaterial->GetSubMaterial(i)->GetName()).toUtf8().data()); - } - } - return result; - } - - CMaterial* TryLoadingMaterial(const char* pPathAndMaterialName) - { - QString varMaterialPath = pPathAndMaterialName; - std::deque splittedMaterialPath; - for (auto token : varMaterialPath.split(QRegularExpression(R"([\\/])"), Qt::SkipEmptyParts)) - { - splittedMaterialPath.push_back(token); - } - - CMaterial* pMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(varMaterialPath, false); - if (!pMaterial) - { - QString subMaterialName = splittedMaterialPath.back(); - bool isSubMaterialExist(false); - - varMaterialPath.remove((varMaterialPath.length() - subMaterialName.length() - 1), varMaterialPath.length()); - QString test = varMaterialPath; - pMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(varMaterialPath, false); - - if (!pMaterial) - { - throw std::runtime_error("Invalid multi material."); - } - - for (int i = 0; i < pMaterial->GetSubMaterialCount(); i++) - { - if (pMaterial->GetSubMaterial(i)->GetName() == subMaterialName) - { - pMaterial = pMaterial->GetSubMaterial(i); - isSubMaterialExist = true; - } - } - - if (!pMaterial || !isSubMaterialExist) - { - throw std::runtime_error((QString("\"") + subMaterialName + "\" is an invalid sub material.").toUtf8().data()); - } - } - GetIEditor()->GetMaterialManager()->SetCurrentMaterial(pMaterial); - return pMaterial; - } - - std::deque PreparePropertyPath(const char* pPathAndPropertyName) - { - QString varPathProperty = pPathAndPropertyName; - std::deque splittedPropertyPath; - for (auto token : varPathProperty.split(QRegularExpression(R"([\\/])"), Qt::SkipEmptyParts)) - { - splittedPropertyPath.push_back(token); - } - - return splittedPropertyPath; - } - - ////////////////////////////////////////////////////////////////////////// - // Converter: Enum -> CString (human readable) - ////////////////////////////////////////////////////////////////////////// - - QString TryConvertingSEFResTextureToCString(SEfResTexture* pResTexture) - { - if (pResTexture) - { - return pResTexture->m_Name.c_str(); - } - return ""; - } - - QString TryConvertingETEX_TypeToCString(const uint8& texTypeName) - { - switch (texTypeName) - { - case eTT_2D: - return "2D"; - case eTT_Cube: - return "Cube-Map"; - case eTT_NearestCube: - return "Nearest Cube-Map probe for alpha blended"; - case eTT_Auto2D: - return "Auto 2D-Map"; - case eTT_Dyn2D: - return "Dynamic 2D-Map"; - case eTT_User: - return "From User Params"; - default: - throw std::runtime_error("Invalid tex type."); - } - } - - QString TryConvertingTexFilterToCString(const int& iFilterName) - { - switch (iFilterName) - { - case FILTER_NONE: - return "Default"; - case FILTER_POINT: - return "Point"; - case FILTER_LINEAR: - return "Linear"; - case FILTER_BILINEAR: - return "Bilinear"; - case FILTER_TRILINEAR: - return "Trilinear"; - case FILTER_ANISO2X: - return "Anisotropic 2x"; - case FILTER_ANISO4X: - return "Anisotropic 4x"; - case FILTER_ANISO8X: - return "Anisotropic 8x"; - case FILTER_ANISO16X: - return "Anisotropic 16x"; - default: - throw std::runtime_error("Invalid tex filter."); - } - } - - QString TryConvertingETexGenTypeToCString(const uint8& texGenType) - { - switch (texGenType) - { - case ETG_Stream: - return "Stream"; - case ETG_World: - return "World"; - case ETG_Camera: - return "Camera"; - default: - throw std::runtime_error("Invalid tex gen type."); - } - } - - QString TryConvertingETexModRotateTypeToCString(const uint8& rotateType) - { - switch (rotateType) - { - case ETMR_NoChange: - return "No Change"; - case ETMR_Fixed: - return "Fixed Rotation"; - case ETMR_Constant: - return "Constant Rotation"; - case ETMR_Oscillated: - return "Oscillated Rotation"; - default: - throw std::runtime_error("Invalid rotate type."); - } - } - - QString TryConvertingETexModMoveTypeToCString(const uint8& oscillatorType) - { - switch (oscillatorType) - { - case ETMM_NoChange: - return "No Change"; - case ETMM_Fixed: - return "Fixed Moving"; - case ETMM_Constant: - return "Constant Moving"; - case ETMM_Jitter: - return "Jitter Moving"; - case ETMM_Pan: - return "Pan Moving"; - case ETMM_Stretch: - return "Stretch Moving"; - case ETMM_StretchRepeat: - return "Stretch-Repeat Moving"; - default: - throw std::runtime_error("Invalid oscillator type."); - } - } - - QString TryConvertingEDeformTypeToCString(const EDeformType& deformType) - { - switch (deformType) - { - case eDT_Unknown: - return "None"; - case eDT_SinWave: - return "Sin Wave"; - case eDT_SinWaveUsingVtxColor: - return "Sin Wave using vertex color"; - case eDT_Bulge: - return "Bulge"; - case eDT_Squeeze: - return "Squeeze"; - case eDT_Perlin2D: - return "Perlin 2D"; - case eDT_Perlin3D: - return "Perlin 3D"; - case eDT_FromCenter: - return "From Center"; - case eDT_Bending: - return "Bending"; - case eDT_ProcFlare: - return "Proc. Flare"; - case eDT_AutoSprite: - return "Auto sprite"; - case eDT_Beam: - return "Beam"; - case eDT_FixedOffset: - return "FixedOffset"; - default: - throw std::runtime_error("Invalid deform type."); - } - } - - QString TryConvertingEWaveFormToCString(const EWaveForm& waveForm) - { - switch (waveForm) - { - case eWF_None: - return "None"; - case eWF_Sin: - return "Sin"; - case eWF_HalfSin: - return "Half Sin"; - case eWF_Square: - return "Square"; - case eWF_Triangle: - return "Triangle"; - case eWF_SawTooth: - return "Saw Tooth"; - case eWF_InvSawTooth: - return "Inverse Saw Tooth"; - case eWF_Hill: - return "Hill"; - case eWF_InvHill: - return "Inverse Hill"; - default: - throw std::runtime_error("Invalid wave form."); - } - } - - ////////////////////////////////////////////////////////////////////////// - // Converter: CString -> Enum - ////////////////////////////////////////////////////////////////////////// - - template - // [Shader System TO DO] remove once dynamic slots assingment is in place - EEfResTextures TryConvertingCStringToEEfResTextures(const STRING& resTextureName) - { - if (resTextureName == "Diffuse") - { - return EFTT_DIFFUSE; - } - else if (resTextureName == "Specular") - { - return EFTT_SPECULAR; - } - else if (resTextureName == "Bumpmap") - { - return EFTT_NORMALS; - } - else if (resTextureName == "Heightmap") - { - return EFTT_HEIGHT; - } - else if (resTextureName == "Environment") - { - return EFTT_ENV; - } - else if (resTextureName == "Detail") - { - return EFTT_DETAIL_OVERLAY; - } - else if (resTextureName == "Opacity") - { - return EFTT_OPACITY; - } - else if (resTextureName == "Decal") - { - return EFTT_DECAL_OVERLAY; - } - else if (resTextureName == "SubSurface") - { - return EFTT_SUBSURFACE; - } - else if (resTextureName == "Custom") - { - return EFTT_CUSTOM; - } - else if (resTextureName == "[1] Custom") - { - return EFTT_DIFFUSE; - } - else if (resTextureName == "Emittance") - { - return EFTT_EMITTANCE; - } - else if (resTextureName == "Occlusion") - { - return EFTT_OCCLUSION; - } - else if (resTextureName == "Specular2") - { - return EFTT_SPECULAR_2; - } - throw std::runtime_error("Invalid texture name."); - } - - template - ETEX_Type TryConvertingCStringToETEX_Type(const STRING& texTypeName) - { - if (texTypeName == "2D") - { - return eTT_2D; - } - else if (texTypeName == "Cube-Map") - { - return eTT_Cube; - } - else if (texTypeName == "Nearest Cube-Map probe for alpha blended") - { - return eTT_NearestCube; - } - else if (texTypeName == "Auto 2D-Map") - { - return eTT_Auto2D; - } - else if (texTypeName == "Dynamic 2D-Map") - { - return eTT_Dyn2D; - } - else if (texTypeName == "From User Params") - { - return eTT_User; - } - throw std::runtime_error("Invalid tex type name."); - } - - template - signed char TryConvertingCStringToTexFilter(const STRING& filterName) - { - if (filterName == "Default") - { - return FILTER_NONE; - } - else if (filterName == "Point") - { - return FILTER_POINT; - } - else if (filterName == "Linear") - { - return FILTER_LINEAR; - } - else if (filterName == "Bilinear") - { - return FILTER_BILINEAR; - } - else if (filterName == "Trilinear") - { - return FILTER_TRILINEAR; - } - else if (filterName == "Anisotropic 2x") - { - return FILTER_ANISO2X; - } - else if (filterName == "Anisotropic 4x") - { - return FILTER_ANISO4X; - } - else if (filterName == "Anisotropic 8x") - { - return FILTER_ANISO8X; - } - else if (filterName == "Anisotropic 16x") - { - return FILTER_ANISO16X; - } - throw std::runtime_error("Invalid filter name."); - } - - template - ETexGenType TryConvertingCStringToETexGenType(const STRING& texGenType) - { - if (texGenType == "Stream") - { - return ETG_Stream; - } - else if (texGenType == "World") - { - return ETG_World; - } - else if (texGenType == "Camera") - { - return ETG_Camera; - } - throw std::runtime_error("Invalid tex gen type name."); - } - - template - ETexModRotateType TryConvertingCStringToETexModRotateType(const STRING& rotateType) - { - if (rotateType == "No Change") - { - return ETMR_NoChange; - } - else if (rotateType == "Fixed Rotation") - { - return ETMR_Fixed; - } - else if (rotateType == "Constant Rotation") - { - return ETMR_Constant; - } - else if (rotateType == "Oscillated Rotation") - { - return ETMR_Oscillated; - } - throw std::runtime_error("Invalid rotate type name."); - } - - template - ETexModMoveType TryConvertingCStringToETexModMoveType(const STRING& oscillatorType) - { - if (oscillatorType == "No Change") - { - return ETMM_NoChange; - } - else if (oscillatorType == "Fixed Moving") - { - return ETMM_Fixed; - } - else if (oscillatorType == "Constant Moving") - { - return ETMM_Constant; - } - else if (oscillatorType == "Jitter Moving") - { - return ETMM_Jitter; - } - else if (oscillatorType == "Pan Moving") - { - return ETMM_Pan; - } - else if (oscillatorType == "Stretch Moving") - { - return ETMM_Stretch; - } - else if (oscillatorType == "Stretch-Repeat Moving") - { - return ETMM_StretchRepeat; - } - throw std::runtime_error("Invalid oscillator type."); - } - - template - EDeformType TryConvertingCStringToEDeformType(const STRING& deformType) - { - if (deformType == "None") - { - return eDT_Unknown; - } - else if (deformType == "Sin Wave") - { - return eDT_SinWave; - } - else if (deformType == "Sin Wave using vertex color") - { - return eDT_SinWaveUsingVtxColor; - } - else if (deformType == "Bulge") - { - return eDT_Bulge; - } - else if (deformType == "Squeeze") - { - return eDT_Squeeze; - } - else if (deformType == "Perlin 2D") - { - return eDT_Perlin2D; - } - else if (deformType == "Perlin 3D") - { - return eDT_Perlin3D; - } - else if (deformType == "From Center") - { - return eDT_FromCenter; - } - else if (deformType == "Bending") - { - return eDT_Bending; - } - else if (deformType == "Proc. Flare") - { - return eDT_ProcFlare; - } - else if (deformType == "Auto sprite") - { - return eDT_AutoSprite; - } - else if (deformType == "Beam") - { - return eDT_Beam; - } - else if (deformType == "FixedOffset") - { - return eDT_FixedOffset; - } - throw std::runtime_error("Invalid deform type."); - } - - template - EWaveForm TryConvertingCStringToEWaveForm(const STRING& waveForm) - { - if (waveForm == "None") - { - return eWF_None; - } - else if (waveForm == "Sin") - { - return eWF_Sin; - } - else if (waveForm == "Half Sin") - { - return eWF_HalfSin; - } - else if (waveForm == "Square") - { - return eWF_Square; - } - else if (waveForm == "Triangle") - { - return eWF_Triangle; - } - else if (waveForm == "Saw Tooth") - { - return eWF_SawTooth; - } - else if (waveForm == "Inverse Saw Tooth") - { - return eWF_InvSawTooth; - } - else if (waveForm == "Hill") - { - return eWF_Hill; - } - else if (waveForm == "Inverse Hill") - { - return eWF_InvHill; - } - throw std::runtime_error("Invalid wave form."); - } - - ////////////////////////////////////////////////////////////////////////// - // Script parser - ////////////////////////////////////////////////////////////////////////// - - QString ParseUINameFromPublicParamsScript(const char* sUIScript) - { - string uiscript = sUIScript; - string element[3]; - int p1 = 0; - string itemToken = uiscript.Tokenize(";", p1); - while (!itemToken.empty()) - { - int nElements = 0; - int p2 = 0; - string token = itemToken.Tokenize(" \t\r\n=", p2); - while (!token.empty()) - { - element[nElements++] = token; - if (nElements == 2) - { - element[nElements] = itemToken.substr(p2); - element[nElements].Trim(" =\t\""); - break; - } - token = itemToken.Tokenize(" \t\r\n=", p2); - } - - if (_stricmp(element[1], "UIName") == 0) - { - return element[2].c_str(); - } - itemToken = uiscript.Tokenize(";", p1); - } - return ""; - } - - std::map ParseValidRangeFromPublicParamsScript(const char* sUIScript) - { - string uiscript = sUIScript; - std::map result; - bool isUIMinExist(false); - bool isUIMaxExist(false); - string element[3]; - int p1 = 0; - string itemToken = uiscript.Tokenize(";", p1); - while (!itemToken.empty()) - { - int nElements = 0; - int p2 = 0; - string token = itemToken.Tokenize(" \t\r\n=", p2); - while (!token.empty()) - { - element[nElements++] = token; - if (nElements == 2) - { - element[nElements] = itemToken.substr(p2); - element[nElements].Trim(" =\t\""); - break; - } - token = itemToken.Tokenize(" \t\r\n=", p2); - } - - if (_stricmp(element[1], "UIMin") == 0) - { - result["UIMin"] = atof(element[2]); - isUIMinExist = true; - } - if (_stricmp(element[1], "UIMax") == 0) - { - result["UIMax"] = atof(element[2]); - isUIMaxExist = true; - } - itemToken = uiscript.Tokenize(";", p1); - } - if (!isUIMinExist || !isUIMaxExist) - { - throw std::runtime_error("Invalid range for shader param."); - } - return result; - } - - ////////////////////////////////////////////////////////////////////////// - // Set Flags - ////////////////////////////////////////////////////////////////////////// - - void SetMaterialFlag(CMaterial* pMaterial, const EMaterialFlags& eFlag, const bool& bFlag) - { - if (pMaterial->GetFlags() & eFlag && bFlag == false) - { - pMaterial->SetFlags(pMaterial->GetFlags() - eFlag); - } - else if (!(pMaterial->GetFlags() & eFlag) && bFlag == true) - { - pMaterial->SetFlags(pMaterial->GetFlags() | eFlag); - } - } - - void SetPropagationFlag(CMaterial* pMaterial, const eMTL_PROPAGATION& eFlag, const bool& bFlag) - { - if (pMaterial->GetPropagationFlags() & eFlag && bFlag == false) - { - pMaterial->SetPropagationFlags(pMaterial->GetPropagationFlags() - eFlag); - } - else if (!(pMaterial->GetPropagationFlags() & eFlag) && bFlag == true) - { - pMaterial->SetPropagationFlags(pMaterial->GetPropagationFlags() | eFlag); - } - } - - ////////////////////////////////////////////////////////////////////////// - template - bool IsAnyValidRange(const AZStd::any& value, const T& low, const T& high, const QString& invalidTypeMessage, const QString& invalidValueMessage) - { - static_assert(AZStd::is_arithmetic::value, "This function only works with numbers."); - - if (!value.is()) - { - throw std::runtime_error(invalidTypeMessage.toUtf8().data()); - } - - T valueData; - AZStd::any_numeric_cast(&value, valueData); - if (valueData < low || valueData > high) - { - throw std::runtime_error(invalidValueMessage.toUtf8().data()); - } - return true; - } - - template <> - bool IsAnyValidRange(const AZStd::any& value, const AZ::Color& low, const AZ::Color& high, const QString& invalidTypeMessage, const QString& invalidValueMessage) - { - if (!value.is()) - { - throw std::runtime_error(invalidTypeMessage.toUtf8().data()); - } - - const AZ::Color* valueData = AZStd::any_cast(&value); - if (!valueData) - { - throw std::runtime_error(invalidValueMessage.toUtf8().data()); - } - - if (valueData->IsLessThan(low) || valueData->IsGreaterThan(high)) - { - throw std::runtime_error(invalidValueMessage.toUtf8().data()); - } - return true; - } - - bool ValidateProperty(CMaterial* pMaterial, const std::deque& splittedPropertyPathParam, const AZStd::any& value) - { - std::deque splittedPropertyPath = splittedPropertyPathParam; - std::deque splittedPropertyPathSubCategory = splittedPropertyPathParam; - QString categoryName = splittedPropertyPath.front(); - QString subCategoryName = ""; - QString subSubCategoryName = ""; - QString currentPath = ""; - QString propertyName = splittedPropertyPath.back(); - - QString errorMsgInvalidValue = QString("Invalid value for property \"") + propertyName + "\""; - QString errorMsgInvalidDataType = QString("Invalid data type for property \"") + propertyName + "\""; - QString errorMsgInvalidPropertyPath = QString("Invalid property path"); - - const int iMinColorValue = 0; - const int iMaxColorValue = 255; - - if (splittedPropertyPathSubCategory.size() == 3) - { - splittedPropertyPathSubCategory.pop_back(); - subCategoryName = splittedPropertyPathSubCategory.back(); - currentPath = QString("") + categoryName + "/" + subCategoryName; - - if ( - subCategoryName != "TexType" && - subCategoryName != "Filter" && - subCategoryName != "IsProjectedTexGen" && - subCategoryName != "TexGenType" && - subCategoryName != "Wave X" && - subCategoryName != "Wave Y" && - subCategoryName != "Wave Z" && - subCategoryName != "Wave W" && - subCategoryName != "Shader1" && - subCategoryName != "Shader2" && - subCategoryName != "Shader3" && - subCategoryName != "Tiling" && - subCategoryName != "Rotator" && - subCategoryName != "Oscillator" && - subCategoryName != "Diffuse" && - subCategoryName != "Specular" && - subCategoryName != "Bumpmap" && - subCategoryName != "Heightmap" && - subCategoryName != "Environment" && - subCategoryName != "Detail" && - subCategoryName != "Opacity" && - subCategoryName != "Decal" && - subCategoryName != "SubSurface" && - subCategoryName != "Custom" && - subCategoryName != "[1] Custom" - ) - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - } - else if (splittedPropertyPathSubCategory.size() == 4) - { - splittedPropertyPathSubCategory.pop_back(); - subCategoryName = splittedPropertyPathSubCategory.back(); - splittedPropertyPathSubCategory.pop_back(); - subSubCategoryName = splittedPropertyPathSubCategory.back(); - currentPath = categoryName + "/" + subSubCategoryName + "/" + subCategoryName; - - if ( - subSubCategoryName != "Diffuse" && - subSubCategoryName != "Specular" && - subSubCategoryName != "Bumpmap" && - subSubCategoryName != "Heightmap" && - subSubCategoryName != "Environment" && - subSubCategoryName != "Detail" && - subSubCategoryName != "Opacity" && - subSubCategoryName != "Decal" && - subSubCategoryName != "SubSurface" && - subSubCategoryName != "Custom" && - subSubCategoryName != "[1] Custom" - ) - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - else if (subCategoryName != "Tiling" && subCategoryName != "Rotator" && subCategoryName != "Oscillator") - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - } - else - { - currentPath = categoryName; - } - - if ( - categoryName == "Material Settings" || - categoryName == "Opacity Settings" || - categoryName == "Lighting Settings" || - categoryName == "Advanced" || - categoryName == "Texture Maps" || - categoryName == "Vertex Deformation" || - categoryName == "Layer Presets") - { - if (propertyName == "Opacity" || propertyName == "AlphaTest" || propertyName == "Glow Amount") - { - // int: 0 < x < 100 - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - - AZ::s64 valueData; - AZStd::any_numeric_cast(&value, valueData); - if (valueData < 0 || valueData > 100) - { - throw std::runtime_error(errorMsgInvalidValue.toUtf8().data()); - } - return true; - } - else if (propertyName == "Smoothness" || propertyName == "Glossiness") - { - // int: 0 < x < 255 - return IsAnyValidRange(value, 0, 255, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Specular Level") - { - // float: 0.0 < x < 4.0 - return IsAnyValidRange(value, 0.0, 4.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if ( - propertyName == "TileU" || - propertyName == "TileV" || - propertyName == "OffsetU" || - propertyName == "OffsetV" || - propertyName == "RotateU" || - propertyName == "RotateV" || - propertyName == "RotateW" || - propertyName == "Rate" || - propertyName == "Phase" || - propertyName == "Amplitude" || - propertyName == "CenterU" || - propertyName == "CenterV" || - propertyName == "RateU" || - propertyName == "RateV" || - propertyName == "PhaseU" || - propertyName == "PhaseV" || - propertyName == "AmplitudeU" || - propertyName == "AmplitudeV" || - propertyName == "Wave Length X" || - propertyName == "Wave Length Y" || - propertyName == "Wave Length Z" || - propertyName == "Wave Length W" || - propertyName == "Level" || - propertyName == "Amplitude" || - propertyName == "Phase" || - propertyName == "Frequency") - { - // float: 0.0 < x < 100.0 - return IsAnyValidRange(value, 0.0, 100.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Voxel Coverage") - { - // float: 0.0 < x < 1.0 - return IsAnyValidRange(value, 0.0, 1.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Emissive Intensity") - { - // float: 0.0 < x < 200.0 - return IsAnyValidRange(value, 0.0, 200.0, errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if (propertyName == "Diffuse Color" || propertyName == "Specular Color" || propertyName == "Emissive Color") - { - // intVector(RGB): 0 < x < 255 - return IsAnyValidRange(value, AZ::Color::CreateZero(), AZ::Color::CreateOne(), errorMsgInvalidDataType, errorMsgInvalidValue); - } - else if ( - propertyName == "Link to Material" || - propertyName == "Surface Type" || - propertyName == "Diffuse" || - propertyName == "Specular" || - propertyName == "Bumpmap" || - propertyName == "Heightmap" || - propertyName == "Environment" || - propertyName == "Detail" || - propertyName == "Opacity" || - propertyName == "Decal" || - propertyName == "SubSurface" || - propertyName == "Custom" || - propertyName == "[1] Custom" || - propertyName == "TexType" || - propertyName == "Filter" || - propertyName == "TexGenType" || - propertyName == "Type" || - propertyName == "TypeU" || - propertyName == "TypeV") - { - // string - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - else if ( - propertyName == "Additive" || - propertyName == "Allow layer activation" || - propertyName == "2 Sided" || - propertyName == "No Shadow" || - propertyName == "Use Scattering" || - propertyName == "Hide After Breaking" || - propertyName == "Fog Volume Shading Quality High" || - propertyName == "Blend Terrain Color" || - propertyName == "Propagate Material Settings" || - propertyName == "Propagate Opacity Settings" || - propertyName == "Propagate Lighting Settings" || - propertyName == "Propagate Advanced Settings" || - propertyName == "Propagate Texture Maps" || - propertyName == "Propagate Shader Params" || - propertyName == "Propagate Shader Generation" || - propertyName == "Propagate Vertex Deformation" || - propertyName == "Propagate Layer Presets" || - propertyName == "IsProjectedTexGen" || - propertyName == "IsTileU" || - propertyName == "IsTileV" || - propertyName == "No Draw") - { - // bool - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - else if (propertyName == "Shader" || propertyName == "Shader1" || propertyName == "Shader2" || propertyName == "Shader3") - { - // string && valid shader - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - - CShaderEnum* pShaderEnum = GetIEditor()->GetShaderEnum(); - if (!pShaderEnum) - { - throw std::runtime_error("Shader enumerator corrupted."); - } - pShaderEnum->EnumShaders(); - for (int i = 0; i < pShaderEnum->GetShaderCount(); i++) - { - if (pShaderEnum->GetShader(i) == AZStd::any_cast(value).data()) - { - return true; - } - } - } - else if (propertyName == "Noise Scale") - { - // FloatVec: undefined < x < undefined - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - } - else if (categoryName == "Shader Params") - { - auto& shaderParams = pMaterial->GetShaderResources().m_ShaderParams; - for (int i = 0; i < shaderParams.size(); i++) - { - if (propertyName == ParseUINameFromPublicParamsScript(shaderParams[i].m_Script.c_str())) - { - if (shaderParams[i].m_Type == eType_FLOAT) - { - // float: valid range (from script) - float floatValue; - if (!AZStd::any_numeric_cast(&value, floatValue)) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - std::map range = ParseValidRangeFromPublicParamsScript(shaderParams[i].m_Script.c_str()); - if (floatValue < range["UIMin"] || floatValue > range["UIMax"]) - { - QString errorMsg; - errorMsg = QStringLiteral("Invalid value for shader param \"%1\" (min: %2, max: %3)").arg(propertyName).arg(range["UIMin"]).arg(range["UIMax"]); - throw std::runtime_error(errorMsg.toUtf8().data()); - } - return true; - } - else if (shaderParams[i].m_Type == eType_FCOLOR) - { - return IsAnyValidRange(value, AZ::Color::CreateZero(), AZ::Color::CreateOne(), errorMsgInvalidDataType, errorMsgInvalidValue); - } - } - } - } - else if (categoryName == "Shader Generation Params") - { - for (int i = 0; i < pMaterial->GetShaderGenParamsVars()->GetNumVariables(); i++) - { - if (propertyName == pMaterial->GetShaderGenParamsVars()->GetVariable(i)->GetHumanName()) - { - if (!value.is()) - { - throw std::runtime_error(errorMsgInvalidDataType.toUtf8().data()); - } - return true; - } - } - } - else - { - throw std::runtime_error((errorMsgInvalidPropertyPath + " (" + currentPath + ")").toUtf8().data()); - } - return false; - } - - ////////////////////////////////////////////////////////////////////////// - template - T PyFetchNumericType(const AZStd::any& value) - { - T numericValue; - AZStd::any_numeric_cast(&value, numericValue); - return numericValue; - } - - AZStd::any PyGetProperty(const char* pPathAndMaterialName, const char* pPathAndPropertyName) - { - CMaterial* pMaterial = TryLoadingMaterial(pPathAndMaterialName); - std::deque splittedPropertyPath = PreparePropertyPath(pPathAndPropertyName); - std::deque splittedPropertyPathCategory = splittedPropertyPath; - QString categoryName = splittedPropertyPath.front(); - QString subCategoryName = "None"; - QString subSubCategoryName = "None"; - QString propertyName = splittedPropertyPath.back(); - QString errorMsgInvalidPropertyPath = "Invalid property path."; - - if (splittedPropertyPathCategory.size() == 3) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - } - else if (splittedPropertyPathCategory.size() == 4) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - splittedPropertyPathCategory.pop_back(); - subSubCategoryName = splittedPropertyPathCategory.back(); - } - - // ########## Material Settings ########## - if (categoryName == "Material Settings") - { - if (propertyName == "Shader") - { - return AZStd::make_any(pMaterial->GetShaderName().toUtf8().data()); - } - else if (propertyName == "Surface Type") - { - QString stringValue = pMaterial->GetSurfaceTypeName(); - if (stringValue.startsWith("mat_")) - { - stringValue.remove(0, 4); - } - return AZStd::make_any(stringValue.toLatin1().data()); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid material setting.").toUtf8().data()); - } - } - // ########## Opacity Settings ########## - else if (categoryName == "Opacity Settings") - { - if (propertyName == "Opacity") - { - AZ::s64 intValue = aznumeric_cast(pMaterial->GetShaderResources().m_LMaterial.m_Opacity * 100.0f); - return AZStd::make_any(intValue); - } - else if (propertyName == "AlphaTest") - { - AZ::s64 intValue = aznumeric_cast(pMaterial->GetShaderResources().m_AlphaRef * 100.0f); - return AZStd::make_any(intValue); - } - else if (propertyName == "Additive") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_ADDITIVE); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid opacity setting.").toUtf8().data()); - } - } - // ########## Lighting Settings ########## - else if (categoryName == "Lighting Settings") - { - if (propertyName == "Diffuse Color") - { - QColor col = ColorLinearToGamma(ColorF( - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse.r, - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse.g, - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse.b)); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - else if (propertyName == "Specular Color") - { - QColor col = ColorLinearToGamma(ColorF( - pMaterial->GetShaderResources().m_LMaterial.m_Specular.r / pMaterial->GetShaderResources().m_LMaterial.m_Specular.a, - pMaterial->GetShaderResources().m_LMaterial.m_Specular.g / pMaterial->GetShaderResources().m_LMaterial.m_Specular.a, - pMaterial->GetShaderResources().m_LMaterial.m_Specular.b / pMaterial->GetShaderResources().m_LMaterial.m_Specular.a)); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - else if (propertyName == "Glossiness") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_LMaterial.m_Smoothness); - } - else if (propertyName == "Specular Level") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_LMaterial.m_Specular.a); - } - else if (propertyName == "Emissive Color") - { - QColor col = ColorLinearToGamma(ColorF( - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.r, - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.g, - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.b)); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - else if (propertyName == "Emissive Intensity") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid lighting setting.").toUtf8().data()); - } - } - // ########## Advanced ########## - else if (categoryName == "Advanced") - { - if (propertyName == "Allow layer activation") - { - return AZStd::make_any(pMaterial->LayerActivationAllowed()); - } - else if (propertyName == "2 Sided") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_2SIDED); - } - else if (propertyName == "No Shadow") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_NOSHADOW); - } - else if (propertyName == "Use Scattering") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_SCATTER); - } - else if (propertyName == "Hide After Breaking") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_HIDEONBREAK); - } - else if (propertyName == "Fog Volume Shading Quality High") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_FOG_VOLUME_SHADING_QUALITY_HIGH); - } - else if (propertyName == "Blend Terrain Color") - { - return AZStd::make_any(pMaterial->GetFlags() & MTL_FLAG_BLEND_TERRAIN); - } - else if (propertyName == "Voxel Coverage") - { - return AZStd::make_any(aznumeric_cast(pMaterial->GetShaderResources().m_VoxelCoverage) / 255.0f); - } - else if (propertyName == "Link to Material") - { - return AZStd::make_any(pMaterial->GetMatInfo()->GetMaterialLinkName()); - } - else if (propertyName == "Propagate Material Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_MATERIAL_SETTINGS); - } - else if (propertyName == "Propagate Opacity Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_OPACITY); - } - else if (propertyName == "Propagate Lighting Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_LIGHTING); - } - else if (propertyName == "Propagate Advanced Settings") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_ADVANCED); - } - else if (propertyName == "Propagate Texture Maps") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_TEXTURES); - } - else if (propertyName == "Propagate Shader Params") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_SHADER_PARAMS); - } - else if (propertyName == "Propagate Shader Generation") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_SHADER_GEN); - } - else if (propertyName == "Propagate Vertex Deformation") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_VERTEX_DEF); - } - else if (propertyName == "Propagate Layer Presets") - { - return AZStd::make_any(pMaterial->GetPropagationFlags() & MTL_PROPAGATE_LAYER_PRESETS); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid advanced setting.").toUtf8().data()); - } - } - // ########## Texture Maps ########## - else if (categoryName == "Texture Maps") - { - SInputShaderResources& shaderResources = pMaterial->GetShaderResources(); - // ########## Texture Maps / [name] ########## - if (splittedPropertyPath.size() == 2) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(propertyName)); - SEfResTexture* pTextureRes = shaderResources.GetTextureResource(nSlot); - if (!pTextureRes || pTextureRes->m_Name.empty()) - { - AZ_Warning("ShadersSystem", false, "PyGetProperty - Error: empty texture slot [%d] (or missing name) for material %s", - nSlot, pMaterial->GetName().toStdString().c_str()); - return AZStd::any(); - } - else - { - return AZStd::make_any(pTextureRes->m_Name); - } - } - // ########## Texture Maps / [TexType | Filter | IsProjectedTexGen | TexGenType ] ########## - else if (splittedPropertyPath.size() == 3) - { - SEfResTexture* pTextureRes = shaderResources.GetTextureResource(TryConvertingCStringToEEfResTextures(subCategoryName)); - if (pTextureRes) - { - if (propertyName == "TexType") - { - return AZStd::make_any(TryConvertingETEX_TypeToCString(pTextureRes->m_Sampler.m_eTexType).toLatin1().data()); - } - else if (propertyName == "Filter") - { - return AZStd::make_any(TryConvertingTexFilterToCString(pTextureRes->m_Filter).toLatin1().data()); - } - else if (propertyName == "IsProjectedTexGen") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_bTexGenProjected); - } - else if (propertyName == "TexGenType") - { - return AZStd::make_any(TryConvertingETexGenTypeToCString(pTextureRes->AddModificator()->m_eTGType).toLatin1().data()); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else - { - AZ_Warning("ShadersSystem", false, "PyGetProperty - Error: empty 'subCategoryName' texture slot [%d] for material %s", - aznumeric_cast(TryConvertingCStringToEEfResTextures(subCategoryName)), - pMaterial->GetName().toStdString().c_str()); - } - } - // ########## Texture Maps / [Tiling | Rotator | Oscillator] ########## - else if (splittedPropertyPath.size() == 4) - { - SEfResTexture* pTextureRes = shaderResources.GetTextureResource(TryConvertingCStringToEEfResTextures(subSubCategoryName)); - if (pTextureRes) - { - if (subCategoryName == "Tiling") - { - if (propertyName == "IsTileU") - { - return AZStd::make_any(pTextureRes->m_bUTile); - } - else if (propertyName == "IsTileV") - { - return AZStd::make_any(pTextureRes->m_bVTile); - } - else if (propertyName == "TileU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Tiling[0]); - } - else if (propertyName == "TileV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Tiling[1]); - } - else if (propertyName == "OffsetU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Offs[0]); - } - else if (propertyName == "OffsetV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Offs[1]); - } - else if (propertyName == "RotateU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Rot[0]); - } - else if (propertyName == "RotateV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Rot[1]); - } - else if (propertyName == "RotateW") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_Rot[2]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else if (subCategoryName == "Rotator") - { - if (propertyName == "Type") - { - return AZStd::make_any(TryConvertingETexModRotateTypeToCString(pTextureRes->AddModificator()->m_eRotType).toLatin1().data()); - } - else if (propertyName == "Rate") - { - return AZStd::make_any(Word2Degr(pTextureRes->AddModificator()->m_RotOscRate[2])); - } - else if (propertyName == "Phase") - { - return AZStd::make_any(Word2Degr(pTextureRes->AddModificator()->m_RotOscPhase[2])); - } - else if (propertyName == "Amplitude") - { - return AZStd::make_any(Word2Degr(pTextureRes->AddModificator()->m_RotOscAmplitude[2])); - } - else if (propertyName == "CenterU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_RotOscCenter[0]); - } - else if (propertyName == "CenterV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_RotOscCenter[1]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else if (subCategoryName == "Oscillator") - { - if (propertyName == "TypeU") - { - return AZStd::make_any(TryConvertingETexModMoveTypeToCString(pTextureRes->AddModificator()->m_eMoveType[0]).toLatin1().data()); - } - else if (propertyName == "TypeV") - { - return AZStd::make_any(TryConvertingETexModMoveTypeToCString(pTextureRes->AddModificator()->m_eMoveType[1]).toLatin1().data()); - } - else if (propertyName == "RateU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscRate[0]); - - } - else if (propertyName == "RateV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscRate[1]); - } - else if (propertyName == "PhaseU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscPhase[0]); - } - else if (propertyName == "PhaseV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscPhase[1]); - } - else if (propertyName == "AmplitudeU") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscAmplitude[0]); - } - else if (propertyName == "AmplitudeV") - { - return AZStd::make_any(pTextureRes->AddModificator()->m_OscAmplitude[1]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else - { - throw std::runtime_error((QString("\"") + subCategoryName + "\" is an invalid sub category.").toUtf8().data()); - } - } - else - { - AZ_Warning("ShadersSystem", false, "PyGetProperty - Error: empty 'subSubCategoryName' texture slot [%d] for material %s", - aznumeric_cast(TryConvertingCStringToEEfResTextures(subSubCategoryName)), - pMaterial->GetName().toStdString().c_str()); - } - } - else - { - throw std::runtime_error(errorMsgInvalidPropertyPath.toUtf8().data()); - } - } - // ########## Shader Params ########## - else if (categoryName == "Shader Params") - { - auto& shaderParams = pMaterial->GetShaderResources().m_ShaderParams; - - for (int i = 0; i < shaderParams.size(); i++) - { - if (propertyName == ParseUINameFromPublicParamsScript(shaderParams[i].m_Script.c_str())) - { - if (shaderParams[i].m_Type == eType_FLOAT) - { - return AZStd::make_any(shaderParams[i].m_Value.m_Float); - } - else if (shaderParams[i].m_Type == eType_FCOLOR) - { - QColor col = ColorLinearToGamma(ColorF( - shaderParams[i].m_Value.m_Vector[0], - shaderParams[i].m_Value.m_Vector[1], - shaderParams[i].m_Value.m_Vector[2])); - return AZStd::make_any(col.red(), col.green(), col.blue(), 1.0f); - } - } - } - - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid shader param.").toUtf8().data()); - } - // ########## Shader Generation Params ########## - else if (categoryName == "Shader Generation Params") - { - for (int i = 0; i < pMaterial->GetShaderGenParamsVars()->GetNumVariables(); i++) - { - if (propertyName == pMaterial->GetShaderGenParamsVars()->GetVariable(i)->GetHumanName()) - { - // get the current Boolean value for this shader variable and return so that the std::runtime_error() will not throw to indicate failure - bool boolValue = false; - pMaterial->GetShaderGenParamsVars()->GetVariable(i)->Get(boolValue); - return AZStd::make_any(boolValue); - } - } - - // not matching property was found, so throw a std::runtime_error() to indcate an error - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid shader generation param.").toUtf8().data()); - } - // ########## Vertex Deformation ########## - else if (categoryName == "Vertex Deformation") - { - // ########## Vertex Deformation / [ Type | Wave Length X | Wave Length Y | Wave Length Z | Wave Length W | Noise Scale ] ########## - if (splittedPropertyPath.size() == 2) - { - if (propertyName == "Type") - { - return AZStd::make_any(TryConvertingEDeformTypeToCString(pMaterial->GetShaderResources().m_DeformInfo.m_eType).toLatin1().data()); - } - else if (propertyName == "Wave Length X") - { - return AZStd::make_any(pMaterial->GetShaderResources().m_DeformInfo.m_fDividerX); - } - else if (propertyName == "Noise Scale") - { - return AZStd::make_any( - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[0], - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[1], - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[2]); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - // ########## Vertex Deformation / [ Wave X ] ########## - else if (splittedPropertyPath.size() == 3) - { - if (subCategoryName == "Wave X") - { - SWaveForm2 currentWaveForm; - if (subCategoryName == "Wave X") - { - currentWaveForm = pMaterial->GetShaderResources().m_DeformInfo.m_WaveX; - } - - if (propertyName == "Type") - { - return AZStd::make_any(TryConvertingEWaveFormToCString(currentWaveForm.m_eWFType).toLatin1().data()); - } - else if (propertyName == "Level") - { - return AZStd::make_any(currentWaveForm.m_Level); - } - else if (propertyName == "Amplitude") - { - return AZStd::make_any(currentWaveForm.m_Amp); - } - else if (propertyName == "Phase") - { - return AZStd::make_any(currentWaveForm.m_Phase); - } - else if (propertyName == "Frequency") - { - return AZStd::make_any(currentWaveForm.m_Freq); - } - else - { - throw std::runtime_error((QString("\"") + propertyName + "\" is an invalid property.").toUtf8().data()); - } - } - else - { - throw std::runtime_error((QString("\"") + categoryName + "\" is an invalid category.").toUtf8().data()); - } - } - else - { - throw std::runtime_error(errorMsgInvalidPropertyPath.toUtf8().data()); - } - } - // ########## Layer Presets ########## - else if (categoryName == "Layer Presets") - { - // names are "Shader1", "Shader2" and "Shader3", because all have the name "Shader" in material editor - if (splittedPropertyPath.size() == 2) - { - int shaderNumber = -1; - if (propertyName == "Shader1") - { - shaderNumber = 0; - } - else if (propertyName == "Shader2") - { - shaderNumber = 1; - } - else if (propertyName == "Shader3") - { - shaderNumber = 2; - } - else - { - throw std::runtime_error("Invalid shader."); - } - - return AZStd::make_any(pMaterial->GetMtlLayerResources()[shaderNumber].m_shaderName.toLatin1().data()); - } - else if (splittedPropertyPath.size() == 3) - { - if (propertyName == "No Draw") - { - int shaderNumber = -1; - if (subCategoryName == "Shader1") - { - shaderNumber = 0; - } - else if (subCategoryName == "Shader2") - { - shaderNumber = 1; - } - else if (subCategoryName == "Shader3") - { - shaderNumber = 2; - } - else - { - throw std::runtime_error("Invalid shader."); - } - return AZStd::make_any(pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags & MTL_LAYER_USAGE_NODRAW); - } - } - } - - throw std::runtime_error(errorMsgInvalidPropertyPath.toUtf8().data()); - return AZStd::any(); - } - - void PySetProperty(const char* pPathAndMaterialName, const char* pPathAndPropertyName, const AZStd::any& value) - { - CMaterial* pMaterial = TryLoadingMaterial(pPathAndMaterialName); - std::deque splittedPropertyPath = PreparePropertyPath(pPathAndPropertyName); - std::deque splittedPropertyPathCategory = splittedPropertyPath; - QString categoryName = splittedPropertyPath.front(); - QString subCategoryName = "None"; - QString subSubCategoryName = "None"; - QString propertyName = splittedPropertyPath.back(); - QString errorMsgInvalidPropertyPath = "Invalid property path."; - - if (!ValidateProperty(pMaterial, splittedPropertyPath, value)) - { - throw std::runtime_error("Invalid property."); - } - - QString undoMsg = "Set Material Property"; - CUndo undo(undoMsg.toUtf8().data()); - pMaterial->RecordUndo(undoMsg.toUtf8().data(), true); - - if (splittedPropertyPathCategory.size() == 3) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - } - else if (splittedPropertyPathCategory.size() == 4) - { - splittedPropertyPathCategory.pop_back(); - subCategoryName = splittedPropertyPathCategory.back(); - splittedPropertyPathCategory.pop_back(); - subSubCategoryName = splittedPropertyPathCategory.back(); - } - - // ########## Material Settings ########## - if (categoryName == "Material Settings") - { - if (propertyName == "Shader") - { - pMaterial->SetShaderName(AZStd::any_cast(value).data()); - } - else if (propertyName == "Surface Type") - { - bool isSurfaceExist(false); - QString realSurfacename = ""; - ISurfaceTypeEnumerator* pSurfaceTypeEnum = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager()->GetEnumerator(); - if (pSurfaceTypeEnum) - { - for (ISurfaceType* pSurfaceType = pSurfaceTypeEnum->GetFirst(); pSurfaceType; pSurfaceType = pSurfaceTypeEnum->GetNext()) - { - QString surfaceName = pSurfaceType->GetName(); - realSurfacename = surfaceName; - if (surfaceName.left(4) == "mat_") - { - surfaceName.remove(0, 4); - } - if (surfaceName == AZStd::any_cast(value).data()) - { - isSurfaceExist = true; - pMaterial->SetSurfaceTypeName(realSurfacename); - } - } - - if (!isSurfaceExist) - { - throw std::runtime_error("Invalid surface type name."); - } - } - else - { - throw std::runtime_error("Surface Type Enumerator corrupted."); - } - } - } - // ########## Opacity Settings ########## - else if (categoryName == "Opacity Settings") - { - if (propertyName == "Opacity") - { - pMaterial->GetShaderResources().m_LMaterial.m_Opacity = PyFetchNumericType(value) / 100.0f; - } - else if (propertyName == "AlphaTest") - { - pMaterial->GetShaderResources().m_AlphaRef = PyFetchNumericType(value) / 100.0f; - } - else if (propertyName == "Additive") - { - SetMaterialFlag(pMaterial, MTL_FLAG_ADDITIVE, PyFetchNumericType(value)); - } - } - // ########## Lighting Settings ########## - else if (categoryName == "Lighting Settings") - { - if (propertyName == "Diffuse Color") - { - const AZ::Color* color = AZStd::any_cast(&value); - pMaterial->GetShaderResources().m_LMaterial.m_Diffuse = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - } - else if (propertyName == "Specular Color") - { - const AZ::Color* color = AZStd::any_cast(&value); - ColorF colorFloat = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - colorFloat.a = pMaterial->GetShaderResources().m_LMaterial.m_Specular.a; - colorFloat.r *= colorFloat.a; - colorFloat.g *= colorFloat.a; - colorFloat.b *= colorFloat.a; - pMaterial->GetShaderResources().m_LMaterial.m_Specular = colorFloat; - } - else if (propertyName == "Glossiness" || propertyName == "Smoothness") - { - pMaterial->GetShaderResources().m_LMaterial.m_Smoothness = PyFetchNumericType(value); - } - else if (propertyName == "Specular Level") - { - const float localVariableAlpha = PyFetchNumericType(value); - ColorF colorFloat = pMaterial->GetShaderResources().m_LMaterial.m_Specular; - colorFloat.r *= localVariableAlpha; - colorFloat.g *= localVariableAlpha; - colorFloat.b *= localVariableAlpha; - colorFloat.a = 1.0f; - pMaterial->GetShaderResources().m_LMaterial.m_Specular = colorFloat; - } - else if (propertyName == "Emissive Color") - { - const AZ::Color* color = AZStd::any_cast(&value); - float emissiveIntensity = pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a; - pMaterial->GetShaderResources().m_LMaterial.m_Emittance = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a = emissiveIntensity; - } - else if (propertyName == "Emissive Intensity") - { - pMaterial->GetShaderResources().m_LMaterial.m_Emittance.a = PyFetchNumericType(value); - } - } - // ########## Advanced ########## - else if (categoryName == "Advanced") - { - if (propertyName == "Allow layer activation") - { - pMaterial->SetLayerActivation(PyFetchNumericType(value)); - } - else if (propertyName == "2 Sided") - { - SetMaterialFlag(pMaterial, MTL_FLAG_2SIDED, PyFetchNumericType(value)); - } - else if (propertyName == "No Shadow") - { - SetMaterialFlag(pMaterial, MTL_FLAG_NOSHADOW, PyFetchNumericType(value)); - } - else if (propertyName == "Use Scattering") - { - SetMaterialFlag(pMaterial, MTL_FLAG_SCATTER, PyFetchNumericType(value)); - } - else if (propertyName == "Hide After Breaking") - { - SetMaterialFlag(pMaterial, MTL_FLAG_HIDEONBREAK, PyFetchNumericType(value)); - } - else if (propertyName == "Fog Volume Shading Quality High") - { - SetMaterialFlag(pMaterial, MTL_FLAG_FOG_VOLUME_SHADING_QUALITY_HIGH, PyFetchNumericType(value)); - } - else if (propertyName == "Blend Terrain Color") - { - SetMaterialFlag(pMaterial, MTL_FLAG_BLEND_TERRAIN, PyFetchNumericType(value)); - } - else if (propertyName == "Voxel Coverage") - { - pMaterial->GetShaderResources().m_VoxelCoverage = aznumeric_cast(PyFetchNumericType(value) * 255.0f); - } - else if (propertyName == "Link to Material") - { - pMaterial->GetMatInfo()->SetMaterialLinkName(AZStd::any_cast(value).data()); - } - else if (propertyName == "Propagate Material Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_MATERIAL_SETTINGS, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Opacity Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_OPACITY, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Lighting Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_LIGHTING, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Advanced Settings") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_ADVANCED, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Texture Maps") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_TEXTURES, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Shader Params") - { - if (PyFetchNumericType(value)) - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_MATERIAL_SETTINGS, true); - } - SetPropagationFlag(pMaterial, MTL_PROPAGATE_SHADER_PARAMS, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Shader Generation") - { - if (PyFetchNumericType(value)) - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_MATERIAL_SETTINGS, true); - } - SetPropagationFlag(pMaterial, MTL_PROPAGATE_SHADER_GEN, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Vertex Deformation") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_VERTEX_DEF, PyFetchNumericType(value)); - } - else if (propertyName == "Propagate Layer Presets") - { - SetPropagationFlag(pMaterial, MTL_PROPAGATE_LAYER_PRESETS, PyFetchNumericType(value)); - } - } - // ########## Texture Maps ########## - else if (categoryName == "Texture Maps") - { - // ########## Texture Maps / [name] ########## - SInputShaderResources& shaderResources = pMaterial->GetShaderResources(); - if (splittedPropertyPath.size() == 2) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(propertyName)); - auto stringValue = AZStd::any_cast(value); - if (stringValue.empty()) - { - AZ_Warning("ShadersSystem", false, "PySetProperty - Error: empty texture [%d] name for material %s", - nSlot, pMaterial->GetName().toStdString().c_str()); - } - // notice that the following is an insertion operation if the index did not exist in the map - shaderResources.m_TexturesResourcesMap[nSlot].m_Name = stringValue.data(); - } - // ########## Texture Maps / [TexType | Filter | IsProjectedTexGen | TexGenType ] ########## - else if (splittedPropertyPath.size() == 3) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(subCategoryName)); - // notice that each of the following will add the texture slot if did not exist yet - if (propertyName == "TexType") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_Sampler.m_eTexType = TryConvertingCStringToETEX_Type(AZStd::any_cast(value)); - } - else if (propertyName == "Filter") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_Filter = TryConvertingCStringToTexFilter(AZStd::any_cast(value)); - } - else if (propertyName == "IsProjectedTexGen") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_bTexGenProjected = PyFetchNumericType(value); - } - else if (propertyName == "TexGenType") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eTGType = TryConvertingCStringToETexGenType(AZStd::any_cast(value)); - } - } - // ########## Texture Maps / [Tiling | Rotator | Oscillator] ########## - else if (splittedPropertyPath.size() == 4) - { - uint16 nSlot = aznumeric_cast(TryConvertingCStringToEEfResTextures(subSubCategoryName)); - if (subCategoryName == "Tiling") - { - if (propertyName == "IsTileU") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_bUTile = PyFetchNumericType(value); - } - else if (propertyName == "IsTileV") - { - shaderResources.m_TexturesResourcesMap[nSlot].m_bVTile = PyFetchNumericType(value); - } - else if (propertyName == "TileU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Tiling[0] = PyFetchNumericType(value); - } - else if (propertyName == "TileV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Tiling[1] = PyFetchNumericType(value); - } - else if (propertyName == "OffsetU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Offs[0] = PyFetchNumericType(value); - } - else if (propertyName == "OffsetV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Offs[1] = PyFetchNumericType(value); - } - else if (propertyName == "RotateU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Rot[0] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "RotateV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Rot[1] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "RotateW") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_Rot[2] = Degr2Word(PyFetchNumericType(value)); - } - } - else if (subCategoryName == "Rotator") - { - if (propertyName == "Type") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eRotType = TryConvertingCStringToETexModRotateType(AZStd::any_cast(value)); - } - else if (propertyName == "Rate") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscRate[2] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "Phase") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscPhase[2] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "Amplitude") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscAmplitude[2] = Degr2Word(PyFetchNumericType(value)); - } - else if (propertyName == "CenterU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscCenter[0] = PyFetchNumericType(value); - } - else if (propertyName == "CenterV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_RotOscCenter[1] = PyFetchNumericType(value); - } - } - else if (subCategoryName == "Oscillator") - { - if (propertyName == "TypeU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eMoveType[0] = TryConvertingCStringToETexModMoveType(AZStd::any_cast(value)); - } - else if (propertyName == "TypeV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_eMoveType[1] = TryConvertingCStringToETexModMoveType(AZStd::any_cast(value)); - } - else if (propertyName == "RateU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscRate[0] = PyFetchNumericType(value); - } - else if (propertyName == "RateV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscRate[1] = PyFetchNumericType(value); - } - else if (propertyName == "PhaseU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscPhase[0] = PyFetchNumericType(value); - } - else if (propertyName == "PhaseV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscPhase[1] = PyFetchNumericType(value); - } - else if (propertyName == "AmplitudeU") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscAmplitude[0] = PyFetchNumericType(value); - } - else if (propertyName == "AmplitudeV") - { - shaderResources.m_TexturesResourcesMap[nSlot].AddModificator()->m_OscAmplitude[1] = PyFetchNumericType(value); - } - } - } - } - // ########## Shader Params ########## - else if (categoryName == "Shader Params") - { - auto& shaderParams = pMaterial->GetShaderResources().m_ShaderParams; - - for (int i = 0; i < shaderParams.size(); i++) - { - if (propertyName == ParseUINameFromPublicParamsScript(shaderParams[i].m_Script.c_str())) - { - if (shaderParams[i].m_Type == eType_FLOAT) - { - shaderParams[i].m_Value.m_Float = PyFetchNumericType(value); - break; - } - else if (shaderParams[i].m_Type == eType_FCOLOR) - { - const AZ::Color* color = AZStd::any_cast(&value); - ColorF colorLinear = ColorGammaToLinear(QColor(color->GetR8(), color->GetG8(), color->GetB8())); - shaderParams[i].m_Value.m_Vector[0] = colorLinear.r; - shaderParams[i].m_Value.m_Vector[1] = colorLinear.g; - shaderParams[i].m_Value.m_Vector[2] = colorLinear.b; - break; - } - else - { - throw std::runtime_error("Invalid data type (Shader Params)"); - } - } - } - } - // ########## Shader Generation Params ########## - else if (categoryName == "Shader Generation Params") - { - for (int i = 0; i < pMaterial->GetShaderGenParamsVars()->GetNumVariables(); i++) - { - if (propertyName == pMaterial->GetShaderGenParamsVars()->GetVariable(i)->GetHumanName()) - { - CVarBlock* shaderGenBlock = pMaterial->GetShaderGenParamsVars(); - shaderGenBlock->GetVariable(i)->Set(PyFetchNumericType(value)); - pMaterial->SetShaderGenParamsVars(shaderGenBlock); - break; - } - } - } - // ########## Vertex Deformation ########## - else if (categoryName == "Vertex Deformation") - { - // ########## Vertex Deformation / [ Type | Wave Length X | Noise Scale ] ########## - if (splittedPropertyPath.size() == 2) - { - if (propertyName == "Type") - { - pMaterial->GetShaderResources().m_DeformInfo.m_eType = TryConvertingCStringToEDeformType(AZStd::any_cast(value)); - } - else if (propertyName == "Wave Length X") - { - pMaterial->GetShaderResources().m_DeformInfo.m_fDividerX = PyFetchNumericType(value); - } - else if (propertyName == "Noise Scale") - { - const AZ::Vector3* vecValue = AZStd::any_cast(&value); - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[0] = vecValue->GetX(); - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[1] = vecValue->GetY(); - pMaterial->GetShaderResources().m_DeformInfo.m_vNoiseScale[2] = vecValue->GetZ(); - } - } - // ########## Vertex Deformation / [ Wave X ] ########## - else if (splittedPropertyPath.size() == 3) - { - if (subCategoryName == "Wave X") - { - SWaveForm2& currentWaveForm = pMaterial->GetShaderResources().m_DeformInfo.m_WaveX; - - if (propertyName == "Type") - { - currentWaveForm.m_eWFType = TryConvertingCStringToEWaveForm(AZStd::any_cast(value)); - } - else if (propertyName == "Level") - { - currentWaveForm.m_Level = PyFetchNumericType(value); - } - else if (propertyName == "Amplitude") - { - currentWaveForm.m_Amp = PyFetchNumericType(value); - } - else if (propertyName == "Phase") - { - currentWaveForm.m_Phase = PyFetchNumericType(value); - } - else if (propertyName == "Frequency") - { - currentWaveForm.m_Freq = PyFetchNumericType(value); - } - } - } - } - // ########## Layer Presets ########## - else if (categoryName == "Layer Presets") - { - // names are "Shader1", "Shader2" and "Shader3", because all have the name "Shader" in material editor - if (splittedPropertyPath.size() == 2) - { - int shaderNumber = -1; - if (propertyName == "Shader1") - { - shaderNumber = 0; - } - else if (propertyName == "Shader2") - { - shaderNumber = 1; - } - else if (propertyName == "Shader3") - { - shaderNumber = 2; - } - - pMaterial->GetMtlLayerResources()[shaderNumber].m_shaderName = AZStd::any_cast(value).data(); - } - else if (splittedPropertyPath.size() == 3) - { - if (propertyName == "No Draw") - { - int shaderNumber = -1; - if (subCategoryName == "Shader1") - { - shaderNumber = 0; - } - else if (subCategoryName == "Shader2") - { - shaderNumber = 1; - } - else if (subCategoryName == "Shader3") - { - shaderNumber = 2; - } - - if (pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags & MTL_LAYER_USAGE_NODRAW && PyFetchNumericType(value) == false) - { - pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags = pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags - MTL_LAYER_USAGE_NODRAW; - } - else if (!(pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags & MTL_LAYER_USAGE_NODRAW) && PyFetchNumericType(value) == true) - { - pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags = pMaterial->GetMtlLayerResources()[shaderNumber].m_nFlags | MTL_LAYER_USAGE_NODRAW; - } - } - } - } - - pMaterial->Update(); - pMaterial->Save(); - GetIEditor()->GetMaterialManager()->OnUpdateProperties(pMaterial, true); - } -} - -namespace AzToolsFramework -{ - void MaterialPythonFuncsHandler::Reflect(AZ::ReflectContext* context) - { - if (auto behaviorContext = azrtti_cast(context)) - { - // this will put these methods into the 'azlmbr.legacy.material' module - auto addLegacyMaterial = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder) - { - methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation) - ->Attribute(AZ::Script::Attributes::Category, "Legacy/Material") - ->Attribute(AZ::Script::Attributes::Module, "legacy.material"); - }; - addLegacyMaterial(behaviorContext->Method("create", PyMaterialCreate, nullptr, "Creates a material.")); - addLegacyMaterial(behaviorContext->Method("create_multi", PyMaterialCreateMulti, nullptr, "Creates a multi-material.")); - addLegacyMaterial(behaviorContext->Method("convert_to_multi", PyMaterialConvertToMulti, nullptr, "Converts the selected material to a multi-material.")); - addLegacyMaterial(behaviorContext->Method("duplicate_current", PyMaterialDuplicateCurrent, nullptr, "Duplicates the current material.")); - addLegacyMaterial(behaviorContext->Method("merge_selection", PyMaterialMergeSelection, nullptr, "Merges the selected materials.")); - addLegacyMaterial(behaviorContext->Method("delete_current", PyMaterialDeleteCurrent, nullptr, "Deletes the current material.")); - addLegacyMaterial(behaviorContext->Method("get_submaterial", PyGetSubMaterial, nullptr, "Gets sub materials of a material.")); - addLegacyMaterial(behaviorContext->Method("get_property", PyGetProperty, nullptr, "Gets a property of a material.")); - addLegacyMaterial(behaviorContext->Method("set_property", PySetProperty, nullptr, "Sets a property of a material.")); - } - } -} diff --git a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.h b/Code/Sandbox/Editor/Material/MaterialPythonFuncs.h deleted file mode 100644 index f04542f466..0000000000 --- a/Code/Sandbox/Editor/Material/MaterialPythonFuncs.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AzToolsFramework -{ - //! A component to reflect scriptable commands for materials in the Editor - class MaterialPythonFuncsHandler - : public AZ::Component - { - public: - AZ_COMPONENT(MaterialPythonFuncsHandler, "{E437BCF2-DE71-43E1-A7EC-DD243EB41F0B}") - - SANDBOX_API static void Reflect(AZ::ReflectContext* context); - - // AZ::Component ... - void Activate() override {} - void Deactivate() override {} - }; - -} // namespace AzToolsFramework diff --git a/Code/Sandbox/Editor/Material/PreviewModelView.cpp b/Code/Sandbox/Editor/Material/PreviewModelView.cpp deleted file mode 100644 index 41a50436d1..0000000000 --- a/Code/Sandbox/Editor/Material/PreviewModelView.cpp +++ /dev/null @@ -1,416 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "EditorDefs.h" - -//AZCore -#include - -//CRY -#include -#include - -//Editor -#include -#include -#include -#include -#include -#include -#include -#include - -//EditorCommon -#include - -//Local -#include "PreviewModelView.h" - -//QT -#include - - - -CPreviewModelView::CPreviewModelView(QWidget* parent) - : QViewport(parent, QViewport::StartupMode_Manual) // Manual since we need to set WA_DontCreateNativeAncestors before QViewport::Startup() creates the internal native window and propagates - , m_Flags(0) - , m_GridColor(150, 150, 150, 40) - , m_BackgroundColor(0.5f, 0.5f, 0.5f) - , m_TimeScale(1.0f) - , m_PlayState(PlayState::NONE) - , m_pStaticModel(nullptr) - , m_PostUpdateCallback(nullptr) - , m_ContextMenuCallback(nullptr) -{ -#ifdef Q_OS_MACOS - // Don't propagate the nativeness up, as dockwidgets on macOS don't like it - setAttribute(Qt::WA_DontCreateNativeAncestors); -#endif - Startup(); - - ////////////////////////////////////////////////////////// - //QViewport - AddConsumer(this); - ////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////// - //IEditorNotifyListener - GetIEditor()->RegisterNotifyListener(this); - ////////////////////////////////////////////////////////// - - FocusOnScreen();//update the camera ... - SetDefaultFlags(); - UpdateSettings(); -} - -CPreviewModelView::~CPreviewModelView() -{ - CRY_ASSERT(GetIEditor()); - - ////////////////////////////////////////////////////////// - //IEditorNotifyListener - GetIEditor()->UnregisterNotifyListener(this); - ////////////////////////////////////////////////////////// - - ReleaseModel(); -} - - -bool CPreviewModelView::IsFlagSet(PreviewModelViewFlag flag) const -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - return (m_Flags & (1 << static_cast(flag))); -} - -void CPreviewModelView::ToggleFlag(PreviewModelViewFlag flag) -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - if (IsFlagSet(flag)) - { - UnSetFlag(flag); - } - else - { - SetFlag(flag); - } -} - -void CPreviewModelView::SetFlag(PreviewModelViewFlag flag) -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - m_Flags |= (1 << static_cast(flag)); -} - -void CPreviewModelView::UnSetFlag(PreviewModelViewFlag flag) -{ - CRY_ASSERT(flag < PreviewModelViewFlag::END_POSSIBLE_ITEMS); - m_Flags &= ~(1 << static_cast(flag)); -} - -void CPreviewModelView::ResetPlaybackControls() -{ - UnSetFlag(CPreviewModelView::PreviewModelViewFlag::LOOPING_PLAY); - m_TimeScale = 1.0f; -} - -void CPreviewModelView::ResetBackgroundColor() -{ - SetBackgroundColor(ColorF(0.5f, 0.5f, 0.5f)); -} - -void CPreviewModelView::ResetGridColor() -{ - SetGridColor(ColorF(150, 150, 150, 40)); -} - -void CPreviewModelView::ResetCamera() -{ - FocusOnScreen(); -} - -void CPreviewModelView::ResetAll() -{ - ResetPlaybackControls(); - ResetGridColor(); - ResetBackgroundColor(); - ReleaseModel(); - SetDefaultFlags(); -} - -void CPreviewModelView::SetGridColor(ColorF color) -{ - m_GridColor = color; -} - -void CPreviewModelView::SetBackgroundColor(ColorF color) -{ - m_BackgroundColor = color; -} - -void CPreviewModelView::SetPlayState(PlayState state) -{ - m_PlayState = state; -} - -void CPreviewModelView::SetTimeScale(float scale) -{ - m_TimeScale = scale; -} - -CPreviewModelView::PlayState CPreviewModelView::GetPlayState() const -{ - return m_PlayState; -} - -float CPreviewModelView::GetTimeScale() const -{ - return m_TimeScale; -} - - -ColorF CPreviewModelView::GetGridColor() const -{ - return m_GridColor; -} - -ColorF CPreviewModelView::GetBackgroundColor() const -{ - return m_BackgroundColor; -} - -void CPreviewModelView::ImportModel() -{ - SResourceSelectorContext x; - x.typeName = Prop::GetPropertyTypeToResourceType(ePropertyModel); - - QString currPath = m_ModelFilename.toLower(); - QString selected = GetIEditor()->GetResourceSelectorHost()->SelectResource(x, currPath); - LoadModelFile(selected); -} - -void CPreviewModelView::SetPostUpdateCallback(PostUpdateCallback callback) -{ - m_PostUpdateCallback = callback; -} - -void CPreviewModelView::SetContextMenuCallback(ContextMenuCallback callback) -{ - m_ContextMenuCallback = callback; -} - -//////////////////////////////////////////////////////// -//QViewportConsumer -void CPreviewModelView::OnViewportRender(const SRenderContext& rc) -{ - ///UPDATE - UpdateSettings();//Some changes may take effect next frame ... - - //External updating ... - if (m_PostUpdateCallback) - { - m_PostUpdateCallback(); - } - - //RENDER - CRY_ASSERT(rc.renderParams); - CRY_ASSERT(rc.passInfo); - RenderModels(*rc.renderParams, *rc.passInfo); -} - -void CPreviewModelView::OnViewportKey([[maybe_unused]] const SKeyEvent& ev) -{ -} - -void CPreviewModelView::OnViewportMouse([[maybe_unused]] const SMouseEvent& ev) -{ -} -//////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////// -//IEditorNotifyListener -void CPreviewModelView::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnCloseScene: - { - ResetAll(); - break; - } - case eNotify_OnIdleUpdate: - { - Update(); - } - break; - default: - break; - } -} -/////////////////////////////////////////////////////// - - -void CPreviewModelView::UpdateSettings() -{ - //Update the settings - SViewportSettings allsettings; - - allsettings.background.topColor = m_BackgroundColor; - allsettings.background.useGradient = false; - - allsettings.grid.showGrid = IsFlagSet(PreviewModelViewFlag::SHOW_GRID); - allsettings.grid.middleColor = m_BackgroundColor; - allsettings.grid.mainColor = m_GridColor; - - allsettings.rendering.wireframe = IsFlagSet(PreviewModelViewFlag::DRAW_WIREFRAME); - allsettings.rendering.sunlight = IsFlagSet(PreviewModelViewFlag::ENABLE_TIME_OF_DAY); - allsettings.rendering.fps = false; - - - // Set zoom speed to 1.0f for better UI workflow, instead of the default 0.1f - allsettings.camera.zoomSpeed = 1.0f; - allsettings.camera.moveSpeed = GetIEditor()->GetEditorSettings()->cameraMoveSpeed; - allsettings.camera.fastMoveMultiplier = GetIEditor()->GetEditorSettings()->cameraFastMoveSpeed; - allsettings.camera.rotationSpeed = GetIEditor()->GetEditorSettings()->cameraRotateSpeed; - allsettings.camera.showViewportOrientation = IsFlagSet(PreviewModelViewFlag::SHOW_GRID_AXIS); - - //Set them ... - SetSettings(allsettings); -} - - - -void CPreviewModelView::RenderModels(SRendParams& rendParams, SRenderingPassInfo& passInfo) -{ - if (m_pStaticModel) - { - if (IsFlagSet(PreviewModelViewFlag::PRECACHE_MATERIAL)) - { - _smart_ptr pCurMat = m_pStaticModel->GetMaterial(); - if (pCurMat) - { - pCurMat->PrecacheMaterial(0.0f, nullptr, true, true); - } - } - m_pStaticModel->Render(rendParams, passInfo); - } -} - -void CPreviewModelView::ReleaseModel() -{ - m_ModelFilename = ""; - SAFE_RELEASE(m_pStaticModel); -} - -void CPreviewModelView::SetDefaultFlags() -{ - UnSetFlag(PreviewModelViewFlag::SHOW_OVERDRAW); - - m_Flags = 0; - - SetFlag(PreviewModelViewFlag::SHOW_GRID); - SetFlag(PreviewModelViewFlag::SHOW_GRID_AXIS); -} - -void CPreviewModelView::LoadModelFile(const QString& modelFile) -{ - //Something to load - if (!modelFile.isEmpty()) - { - //Make sure we are not loading the same thing ... - if (m_ModelFilename != modelFile) - { - ReleaseModel();//release any old mesh - - QString strFileExt = Path::GetExt(modelFile); - bool isCGF = (QString::compare(strFileExt, CRY_GEOMETRY_FILE_EXT, Qt::CaseInsensitive) == 0); - - // NOTE: have to create a local buffer and evaluate the full message here due to calling into another address space to evaluate va_args - // this prevents passing of random data to the log system ... any plugin that does not do it this way is rolling the dice each time. - char buffer[2046]; - CRY_ASSERT(GetIEditor()); - if (isCGF) - { - CRY_ASSERT(GetIEditor()->Get3DEngine()); - // Load object. - m_pStaticModel = GetIEditor()->Get3DEngine()->LoadStatObjUnsafeManualRef(modelFile.toUtf8().data(), nullptr, nullptr, false); - if (m_pStaticModel) - { - m_pStaticModel->AddRef(); - } - else - { - CRY_ASSERT(GetIEditor()->GetLogFile()); - azsprintf(buffer, "Loading of geometry object %s failed.", modelFile.toUtf8().data()); - GetIEditor()->GetLogFile()->Warning(buffer); - } - } - else - { - CRY_ASSERT(GetIEditor()->GetLogFile()); - azsprintf(buffer, "Unknown model file (%s) attempting to be loaded.", modelFile.toUtf8().data()); - GetIEditor()->GetLogFile()->Warning(buffer); - } - - //if something was loaded then we store off the model path for the future - if (m_pStaticModel) - { - m_ModelFilename = modelFile; - } - } - } -} - -IStatObj* CPreviewModelView::GetStaticModel() -{ - return m_pStaticModel; -} - -void CPreviewModelView::FocusOnScreen() -{ - CCamera* camera = Camera(); - if (camera) - { - AABB accumulated(2); - - if (m_pStaticModel) - { - AABB temp; - temp.min = m_pStaticModel->GetBoxMin(); - temp.max = m_pStaticModel->GetBoxMax(); - accumulated.Add(temp); - } - - Vec3 fromDir(1.0f, 1.0f, -0.5f); - Vec3 target = accumulated.GetCenter(); - float bbRadius = accumulated.GetRadius(); - - Vec3 dir = fromDir.GetNormalized(); - Matrix34 tm = Matrix33::CreateRotationVDir(dir, 0); - tm.SetTranslation(target - dir * bbRadius); - CameraMoved(QuatT(tm), true); - } -} - -float CPreviewModelView::GetSpeedScale() const -{ - CRY_ASSERT(GetIEditor()); - CRY_ASSERT(GetIEditor()->GetSystem()); - CRY_ASSERT(GetIEditor()->GetSystem()->GetITimer()); - //Taken from CRenderViewport to mirror controls from there ... - float speedScale = 60.0f * GetIEditor()->GetSystem()->GetITimer()->GetFrameTime(); - if (speedScale > 20.0f) - { - speedScale = 20.0f; - } - return speedScale; -} - diff --git a/Code/Sandbox/Editor/Material/PreviewModelView.h b/Code/Sandbox/Editor/Material/PreviewModelView.h deleted file mode 100644 index 3d27983be1..0000000000 --- a/Code/Sandbox/Editor/Material/PreviewModelView.h +++ /dev/null @@ -1,173 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -//Editor -#if !defined(Q_MOC_RUN) -#include "IEditor.h" -#include "../EditorCommon/QViewport.h" -#include "../EditorCommon/QViewportConsumer.h" - -#endif - -struct IStatObj; -struct SRenderingPassInfo; -struct SRendParams; -class CParticleItem; -class CAxisHelper; -struct HitContext; -struct IGizmoMouseDragHandler; -struct SLodInfo; - -namespace RotationDrawHelper -{ - class Axis; -} - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -class CPreviewModelView - : public QViewport - , public QViewportConsumer - , public IEditorNotifyListener -{ -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - enum class PlayState - { - NONE, - PLAY, - PAUSE, - STEP, - RESET - }; - enum class SplineMode - { - NONE, - LINE, - SINEWAVE, - COIL - }; - - //NOTE: these need to be limited to 32 as these are being used for bit wise operations. - enum class PreviewModelViewFlag - { - DRAW_WIREFRAME = 0, - - SHOW_BOUNDINGBOX, - SHOW_GIZMO, - SHOW_GRID, - SHOW_GRID_AXIS, - SHOW_EMITTER_SHAPE, - SHOW_OVERDRAW, - SHOW_FIRST_CONTAINER, - - LOOPING_PLAY, - - //Spline - SPLINE_LOOPING, - SPLINE_PINGPONG, - - PRECACHE_MATERIAL, - - ENABLE_TIME_OF_DAY, - - END_POSSIBLE_ITEMS = 32, - }; - - explicit CPreviewModelView(QWidget* parent); - virtual ~CPreviewModelView(); - - //Flags - bool IsFlagSet(PreviewModelViewFlag flag) const; - void ToggleFlag(PreviewModelViewFlag flag); - virtual void SetFlag(PreviewModelViewFlag flag); - virtual void UnSetFlag(PreviewModelViewFlag flag); - - //Resets - void ResetPlaybackControls(); - void ResetBackgroundColor(); - void ResetGridColor(); - virtual void ResetCamera(); - virtual void ResetAll(); - - void SetGridColor(ColorF color); - void SetBackgroundColor(ColorF color); - void SetPlayState(PlayState state); - void SetTimeScale(float scale); - - PlayState GetPlayState() const; - float GetTimeScale() const; - ColorF GetGridColor() const; - ColorF GetBackgroundColor() const; - - void ImportModel(); - - void LoadModelFile(const QString& modelFile); - IStatObj* GetStaticModel(); - - typedef std::function PostUpdateCallback; - void SetPostUpdateCallback(PostUpdateCallback callback); - - typedef std::function ContextMenuCallback; - void SetContextMenuCallback(ContextMenuCallback callback); - - //////////////////////////////////////////////////////// - //QViewportConsumer - virtual void OnViewportRender(const SRenderContext& rc) override; - virtual void OnViewportKey(const SKeyEvent& ev) override; - virtual void OnViewportMouse(const SMouseEvent& ev) override; - //////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////// - //IEditorNotifyListener - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event) override; - //////////////////////////////////////////////////////// - -private: - - //Update - void UpdateSettings(); -protected: -private: - //Render - void RenderModels(SRendParams& rendParams, SRenderingPassInfo& passInfo); - - //Misc - void ReleaseModel(); - void SetDefaultFlags(); -protected: - void FocusOnScreen(); -private: - float GetSpeedScale() const; - -private: - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - ColorF m_GridColor; - ColorF m_BackgroundColor; - - QString m_ModelFilename; - - - IStatObj* m_pStaticModel; - -protected: - PostUpdateCallback m_PostUpdateCallback; - ContextMenuCallback m_ContextMenuCallback; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - -protected: - PlayState m_PlayState; - float m_TimeScale; -private: - unsigned int m_Flags; -}; diff --git a/Code/Sandbox/Editor/Material/images/filestatus_00.png b/Code/Sandbox/Editor/Material/images/filestatus_00.png deleted file mode 100644 index 414609f486..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_00.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3e5d226d043630028a1fe88af240b627a08966066b605294cc79ff8273588166 -size 194 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_01.png b/Code/Sandbox/Editor/Material/images/filestatus_01.png deleted file mode 100644 index d644fcfe12..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_01.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f80544a0537398979dd423ffdc8e99c08e47dbe814cd4225646761cbe281eecc -size 206 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_02.png b/Code/Sandbox/Editor/Material/images/filestatus_02.png deleted file mode 100644 index da155a1d2a..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_02.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bee8a3d1d5571e5afe0bd02edf0fc58d8297f96494a7c074fd2a37ecda7ae4dc -size 208 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_03.png b/Code/Sandbox/Editor/Material/images/filestatus_03.png deleted file mode 100644 index a047cb4599..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_03.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d3d0fc234e3154c06abd4e3b8d3d7e52a75f80d527b1d05541f55221cba199d7 -size 183 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_04.png b/Code/Sandbox/Editor/Material/images/filestatus_04.png deleted file mode 100644 index 519b68d500..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_04.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ffb3586ef4309d8bfa93a581c38fe970e8b0411f170955921054522b0bf52bd3 -size 182 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_05.png b/Code/Sandbox/Editor/Material/images/filestatus_05.png deleted file mode 100644 index f4f548cdc9..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_05.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f258e9617a1d4c7be16fcab12533a4f0bfe4072151f2140ca41364ef1a3cea62 -size 196 diff --git a/Code/Sandbox/Editor/Material/images/filestatus_06.png b/Code/Sandbox/Editor/Material/images/filestatus_06.png deleted file mode 100644 index 7b7412b19d..0000000000 --- a/Code/Sandbox/Editor/Material/images/filestatus_06.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:68c609d7bde1796f281690148c19694afddcc2cf4ea306116b546327cb50aad2 -size 249 diff --git a/Code/Sandbox/Editor/Material/images/material_00.png b/Code/Sandbox/Editor/Material/images/material_00.png deleted file mode 100644 index a7f48148f1..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_00.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bd5106eebb6cf264fdac5f3568977fc8f944df4a4d4de6b0e9f35b3a001a3001 -size 206 diff --git a/Code/Sandbox/Editor/Material/images/material_01.png b/Code/Sandbox/Editor/Material/images/material_01.png deleted file mode 100644 index e6c26f748a..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_01.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2b08a8d94c64aed944901b76afcb921c3df2c122c9eac6d52140552c2eb4e5cc -size 227 diff --git a/Code/Sandbox/Editor/Material/images/material_02.png b/Code/Sandbox/Editor/Material/images/material_02.png deleted file mode 100644 index a116e84295..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_02.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:623a937f09f1de3ebb889d7ac9e042f91bf67bef34695801b3603f4517166c8e -size 223 diff --git a/Code/Sandbox/Editor/Material/images/material_03.png b/Code/Sandbox/Editor/Material/images/material_03.png deleted file mode 100644 index a116e84295..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_03.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:623a937f09f1de3ebb889d7ac9e042f91bf67bef34695801b3603f4517166c8e -size 223 diff --git a/Code/Sandbox/Editor/Material/images/material_04.png b/Code/Sandbox/Editor/Material/images/material_04.png deleted file mode 100644 index 1d83e3526a..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_04.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0ad56ab7be0a5a40b644045ac01c90fed6e70433a693e80c5b4b88d63801d75f -size 14604 diff --git a/Code/Sandbox/Editor/Material/images/material_05.png b/Code/Sandbox/Editor/Material/images/material_05.png deleted file mode 100644 index 8d953a6ae4..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_05.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9cc845c4eb0ed6fb772064d73f1c679e3b28288411a02f0cafaf248b83b44ca2 -size 221 diff --git a/Code/Sandbox/Editor/Material/images/material_06.png b/Code/Sandbox/Editor/Material/images/material_06.png deleted file mode 100644 index 7e5159a2fc..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_06.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:966fd5ef5c1e0fe6e920511952d7aea98ad0f165f9ce0197f000f9f48ccd338b -size 14628 diff --git a/Code/Sandbox/Editor/Material/images/material_07.png b/Code/Sandbox/Editor/Material/images/material_07.png deleted file mode 100644 index 7e5159a2fc..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_07.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:966fd5ef5c1e0fe6e920511952d7aea98ad0f165f9ce0197f000f9f48ccd338b -size 14628 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_00.png b/Code/Sandbox/Editor/Material/images/material_browser_00.png deleted file mode 100644 index f1e7a2ffce..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_00.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c4a8dc85c9928faacd184148aaf0f17ef7b68c185b04b0b5f16e942fb11c528e -size 209 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_01.png b/Code/Sandbox/Editor/Material/images/material_browser_01.png deleted file mode 100644 index 1ff2ea213f..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_01.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d9047378404e0893b79bafaad9e6b312d467033daab2191a8c8839e4ff494bd8 -size 321 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_02.png b/Code/Sandbox/Editor/Material/images/material_browser_02.png deleted file mode 100644 index edd5148133..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_02.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2e79122edef52c3f9a31fd662f9f5cfd08b06e44e861c7379d8869635fd1d245 -size 168 diff --git a/Code/Sandbox/Editor/Material/images/material_browser_03.png b/Code/Sandbox/Editor/Material/images/material_browser_03.png deleted file mode 100644 index bfbcc6ce98..0000000000 --- a/Code/Sandbox/Editor/Material/images/material_browser_03.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8cc16bbb4c4c0c1bea14c94d0609f4b11a7cd0ead4af3d236d329a404e8223a8 -size 200 diff --git a/Code/Sandbox/Editor/MaterialSender.cpp b/Code/Sandbox/Editor/MaterialSender.cpp deleted file mode 100644 index 2123eadb31..0000000000 --- a/Code/Sandbox/Editor/MaterialSender.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "EditorDefs.h" - -#include "MaterialSender.h" - -bool CMaterialSender::SendMessage(int msg, const XmlNodeRef& node) -{ - bool bRet = false; - -#if defined(AZ_PLATFORM_WINDOWS) - if (!CheckWindows()) - { - return false; - } - - m_h.msg = msg; - - int nDataSize = sizeof(SMaterialMapFileHeader) + strlen(node->getXML().c_str()) + 1; - - //hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, nDataSize, "EditMatMappingObject"); - - HANDLE mapFileHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "EditMatMappingObject"); - if (mapFileHandle) - { - void* pMes = MapViewOfFile(mapFileHandle, FILE_MAP_ALL_ACCESS, 0, 0, nDataSize); - if (pMes) - { - memcpy(pMes, &m_h, sizeof(SMaterialMapFileHeader)); - azstrcpy(((char*)pMes) + sizeof(SMaterialMapFileHeader), nDataSize - sizeof(SMaterialMapFileHeader), node->getXML().c_str()); - UnmapViewOfFile(pMes); - if (m_bIsMatEditor) - { - ::SendMessage(m_h.GetMaxHWND(), WM_MATEDITSEND, msg, 0); - } - else - { - ::SendMessage(m_h.GetEditorHWND(), WM_MATEDITSEND, msg, 0); - } - bRet = true; - } - CloseHandle(mapFileHandle); - } - else - { - CryLog("No File Map"); - } -#endif - - return bRet; -} diff --git a/Code/Sandbox/Editor/MaterialSender.h b/Code/Sandbox/Editor/MaterialSender.h deleted file mode 100644 index 0123223821..0000000000 --- a/Code/Sandbox/Editor/MaterialSender.h +++ /dev/null @@ -1,175 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_MATERIALSENDER_H -#define CRYINCLUDE_EDITOR_MATERIALSENDER_H -#pragma once - -#ifndef WM_MATEDITSEND -// Value copied from Code/Tools/MaxCryExport/CryShader/MaterialSender.h -# define WM_MATEDITSEND (WM_USER + 315) -#endif - -enum EMaterialSenderMessage -{ - eMSM_Create = 1, - eMSM_GetSelectedMaterial = 2, - eMSM_Init = 3, -}; - -#if defined(AZ_PLATFORM_WINDOWS) -struct SMaterialMapFileHeader -{ - // max - void SetMaxHWND(HWND hWnd) - { - hwndMax = (int64)hWnd; - } - HWND GetMaxHWND() const - { - return (HWND)hwndMax; - } - // editor - void SetEditorHWND(HWND hWnd) - { - hwndMatEdit = (int64)hWnd; - } - HWND GetEditorHWND() const - { - return (HWND)hwndMatEdit; - } - int64 msg;// 64bits for both 32 and 64 - int64 Reserved;// 64bits for both 32 and 64 -protected: - uint64 hwndMax;// HWND for 32 and 64 is different - uint64 hwndMatEdit;// HWND for 32 and 64 is different -}; -#endif // AZ_PLATFORM_WINDOWS - - -class CMaterialSender -{ -public: - - CMaterialSender(bool bIsMatEditor) - : m_bIsMatEditor(bIsMatEditor) - { -#if defined(AZ_PLATFORM_WINDOWS) - m_h.SetEditorHWND(0); - m_h.SetMaxHWND(0); - m_h.msg = 0; - hMapFile = 0; -#endif - } - - ~CMaterialSender() - { -#if defined(AZ_PLATFORM_WINDOWS) - if (hMapFile) - { - CloseHandle(hMapFile); - } - hMapFile = 0; -#endif - } - - bool GetMessage() - { - LoadMapFile(); - return true; - } - - bool CheckWindows() - { -#if defined(AZ_PLATFORM_WINDOWS) - if (!m_h.GetMaxHWND() || !m_h.GetEditorHWND() || !::IsWindow(m_h.GetMaxHWND()) || !::IsWindow(m_h.GetEditorHWND())) - { - LoadMapFile(); - } - if (!m_h.GetMaxHWND() || !m_h.GetEditorHWND() || !::IsWindow(m_h.GetMaxHWND()) || !::IsWindow(m_h.GetEditorHWND())) - { - return false; - } -#endif - return true; - } - - bool Create() - { -#if defined(AZ_PLATFORM_WINDOWS) - hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1024 * 1024, "EditMatMappingObject"); - if (hMapFile) - { - return true; - } - CryLog("Can't create File Map"); - - return false; -#else - return true; -#endif - } - - bool SendMessage(int msg, const XmlNodeRef& node); - - void SetupWindows(QWidget* hwndMax, QWidget* hwndMatEdit) - { -#if defined(AZ_PLATFORM_WINDOWS) - m_h.SetMaxHWND(reinterpret_cast(hwndMax->winId())); - m_h.SetEditorHWND(reinterpret_cast(hwndMatEdit->winId())); -#endif - } - -private: - - bool LoadMapFile() - { -#if defined(AZ_PLATFORM_WINDOWS) - bool bRet = false; - const HANDLE mapFileHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "EditMatMappingObject"); - if (mapFileHandle) - { - void* const pMes = MapViewOfFile(mapFileHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); - - if (pMes) - { - memcpy(&m_h, pMes, sizeof(SMaterialMapFileHeader)); - const char* const pXml = ((const char*)pMes) + sizeof(SMaterialMapFileHeader); - m_node = XmlHelpers::LoadXmlFromBuffer(pXml, strlen(pXml)); - UnmapViewOfFile(pMes); - bRet = true; - } - - CloseHandle(mapFileHandle); - } - - return bRet; -#else - return false; -#endif - } - -public: -#if defined(AZ_PLATFORM_WINDOWS) - SMaterialMapFileHeader m_h; -#endif - XmlNodeRef m_node; -private: - bool m_bIsMatEditor; -#if defined(AZ_PLATFORM_WINDOWS) - HANDLE hMapFile; -#endif -}; - - -#endif // CRYINCLUDE_EDITOR_MATERIALSENDER_H diff --git a/Code/Sandbox/Editor/Mission.cpp b/Code/Sandbox/Editor/Mission.cpp deleted file mode 100644 index b9668f1c80..0000000000 --- a/Code/Sandbox/Editor/Mission.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : CMission class implementation. - -#include "EditorDefs.h" - -#include "Mission.h" - -// cryCommon -#include -#include - -// Editor -#include "CryEditDoc.h" -#include "GameEngine.h" -#include "Include/IObjectManager.h" - - -namespace -{ - const char* kTimeOfDayFile = "TimeOfDay.xml"; - const char* kTimeOfDayRoot = "TimeOfDay"; - const char* kEnvironmentFile = "Environment.xml"; - const char* kEnvironmentRoot = "Environment"; -}; - - -////////////////////////////////////////////////////////////////////////// -CMission::CMission(CCryEditDoc* doc) -{ - m_doc = doc; - m_objects = XmlHelpers::CreateXmlNode("Objects"); - m_layers = XmlHelpers::CreateXmlNode("ObjectLayers"); - //m_exportData = XmlNodeRef( "ExportData" ); - m_timeOfDay = XmlHelpers::CreateXmlNode("TimeOfDay"); - m_environment = XmlHelpers::CreateXmlNode("Environment"); - CXmlTemplate::SetValues(m_doc->GetEnvironmentTemplate(), m_environment); - - m_time = 12; // 12 PM by default. - - m_numCGFObjects = 0; - - m_reentrancyProtector = false; -} - -////////////////////////////////////////////////////////////////////////// -CMission::~CMission() -{ -} - -////////////////////////////////////////////////////////////////////////// -CMission* CMission::Clone() -{ - CMission* m = new CMission(m_doc); - m->SetName(m_name); - m->SetDescription(m_description); - m->m_objects = m_objects->clone(); - m->m_layers = m_layers->clone(); - m->m_environment = m_environment->clone(); - m->m_time = m_time; - return m; -} - -////////////////////////////////////////////////////////////////////////// -void CMission::Serialize(CXmlArchive& ar, bool bParts) -{ - if (ar.bLoading) - { - // Load. - ar.root->getAttr("Name", m_name); - ar.root->getAttr("Description", m_description); - - XmlNodeRef objects = ar.root->findChild("Objects"); - if (objects) - { - m_objects = objects; - } - - XmlNodeRef layers = ar.root->findChild("ObjectLayers"); - if (layers) - { - m_layers = layers; - } - - SerializeTimeOfDay(ar); - - m_Animations = ar.root->findChild("MovieData"); - - SerializeEnvironment(ar); - } - else - { - ar.root->setAttr("Name", m_name.toUtf8().data()); - ar.root->setAttr("Description", m_description.toUtf8().data()); - - QString timeStr; - int nHour = floor(m_time); - int nMins = (m_time - floor(m_time)) * 60.0f; - timeStr = QStringLiteral("%1:%2").arg(nHour, 2, 10, QLatin1Char('0')).arg(nMins, 2, 10, QLatin1Char('0')); - ar.root->setAttr("MissionTime", timeStr.toUtf8().data()); - - // Saving. - XmlNodeRef layers = m_layers->clone(); - layers->setTag("ObjectLayers"); - ar.root->addChild(layers); - - ///XmlNodeRef objects = m_objects->clone(); - m_objects->setTag("Objects"); - ar.root->addChild(m_objects); - - if (bParts) - { - SerializeTimeOfDay(ar); - SerializeEnvironment(ar); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMission::Export(XmlNodeRef& root, XmlNodeRef& objectsNode) -{ - // Also save exported objects data. - root->setAttr("Name", m_name.toUtf8().data()); - root->setAttr("Description", m_description.toUtf8().data()); - - QString timeStr; - int nHour = floor(m_time); - int nMins = (m_time - floor(m_time)) * 60.0f; - timeStr = QStringLiteral("%1:%2").arg(nHour, 2, 10, QLatin1Char('0')).arg(nMins, 2, 10, QLatin1Char('0')); - root->setAttr("Time", timeStr.toUtf8().data()); - - // Saving. - //XmlNodeRef objects = m_exportData->clone(); - //objects->setTag( "Objects" ); - //root->addChild( objects ); - - XmlNodeRef envNode = m_environment->clone(); - root->addChild(envNode); - - m_timeOfDay->setAttr("Time", m_time); - root->addChild(m_timeOfDay); - - IObjectManager* pObjMan = GetIEditor()->GetObjectManager(); - - ////////////////////////////////////////////////////////////////////////// - // Serialize objects. - ////////////////////////////////////////////////////////////////////////// - QString path = QDir::toNativeSeparators(QFileInfo(m_doc->GetLevelPathName()).absolutePath()); - if (!path.endsWith(QDir::separator())) - path += QDir::separator(); - - objectsNode = root->newChild("Objects"); - pObjMan->Export(path, objectsNode, true); // Export shared. - pObjMan->Export(path, objectsNode, false); // Export not shared. -} - -////////////////////////////////////////////////////////////////////////// -void CMission::SyncContent(bool bRetrieve, bool bIgnoreObjects, [[maybe_unused]] bool bSkipLoadingAI /* = false */) -{ - // The function may take a longer time when executing objMan->Serialize, which uses CWaitProgress internally - // Adding a sync flag to prevent the function from being re-entered after the data is modified by OnEnvironmentChange - if (m_reentrancyProtector) - { - return; - } - m_reentrancyProtector = true; - - // Save data from current Document to Mission. - IObjectManager* objMan = GetIEditor()->GetObjectManager(); - if (bRetrieve) - { - // Activating this mission. - CGameEngine* gameEngine = GetIEditor()->GetGameEngine(); - - if (!bIgnoreObjects) - { - // Retrieve data from Mission and put to document. - XmlNodeRef root = XmlHelpers::CreateXmlNode("Root"); - root->addChild(m_objects); - root->addChild(m_layers); - objMan->Serialize(root, true, SERIALIZE_ONLY_NOTSHARED); - } - - m_doc->GetFogTemplate() = m_environment; - - CXmlTemplate::GetValues(m_doc->GetEnvironmentTemplate(), m_environment); - - gameEngine->ReloadEnvironment(); - - objMan->SendEvent(EVENT_MISSION_CHANGE); - m_doc->ChangeMission(); - - if (GetIEditor()->Get3DEngine()) - { - m_numCGFObjects = GetIEditor()->Get3DEngine()->GetLoadedObjectCount(); - - // Load time of day. - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_timeOfDay, true); - } - } - else - { - // Save time of day. - if (GetIEditor()->Get3DEngine()) - { - m_timeOfDay = XmlHelpers::CreateXmlNode("TimeOfDay"); - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_timeOfDay, false); - } - - if (!bIgnoreObjects) - { - XmlNodeRef root = XmlHelpers::CreateXmlNode("Root"); - objMan->Serialize(root, false, SERIALIZE_ONLY_NOTSHARED); - m_objects = root->findChild("Objects"); - XmlNodeRef layers = root->findChild("ObjectLayers"); - if (layers) - { - m_layers = layers; - } - } - } - - m_reentrancyProtector = false; -} - -////////////////////////////////////////////////////////////////////////// -void CMission::OnEnvironmentChange() -{ - // Only execute the reload function if there is no ongoing SyncContent. - if (m_reentrancyProtector) - { - return; - } - m_reentrancyProtector = true; - m_environment = XmlHelpers::CreateXmlNode("Environment"); - CXmlTemplate::SetValues(m_doc->GetEnvironmentTemplate(), m_environment); - m_reentrancyProtector = false; -} - -////////////////////////////////////////////////////////////////////////// -void CMission::AddObjectsNode(XmlNodeRef& node) -{ - for (int i = 0; i < node->getChildCount(); i++) - { - m_objects->addChild(node->getChild(i)->clone()); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMission::SetLayersNode(XmlNodeRef& node) -{ - m_layers = node->clone(); -} - -////////////////////////////////////////////////////////////////////////// -void CMission::SaveParts() -{ - // Save Time of Day - { - CTempFileHelper helper((GetIEditor()->GetLevelDataFolder() + kTimeOfDayFile).toUtf8().data()); - - m_timeOfDay->saveToFile(helper.GetTempFilePath().toUtf8().data()); - - if (!helper.UpdateFile(false)) - { - return; - } - } - - - // Save Environment - { - CTempFileHelper helper((GetIEditor()->GetLevelDataFolder() + kEnvironmentFile).toUtf8().data()); - - XmlNodeRef root = m_environment->clone(); - root->setTag(kEnvironmentRoot); - root->saveToFile(helper.GetTempFilePath().toUtf8().data()); - - if (!helper.UpdateFile(false)) - { - return; - } - } -} - - -////////////////////////////////////////////////////////////////////////// -void CMission::LoadParts() -{ - // Load Time of Day - { - QString filename = GetIEditor()->GetLevelDataFolder() + kTimeOfDayFile; - XmlNodeRef root = XmlHelpers::LoadXmlFromFile(filename.toUtf8().data()); - if (root && !_stricmp(root->getTag(), kTimeOfDayRoot)) - { - m_timeOfDay = root; - m_timeOfDay->getAttr("Time", m_time); - } - } - - // Load Environment - { - QString filename = GetIEditor()->GetLevelDataFolder() + kEnvironmentFile; - XmlNodeRef root = XmlHelpers::LoadXmlFromFile(filename.toUtf8().data()); - if (root && !_stricmp(root->getTag(), kEnvironmentRoot)) - { - m_environment = root; - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMission::SerializeTimeOfDay(CXmlArchive& ar) -{ - if (ar.bLoading) - { - XmlNodeRef todNode = ar.root->findChild("TimeOfDay"); - if (todNode) - { - m_timeOfDay = todNode; - todNode->getAttr("Time", m_time); - } - else - { - m_timeOfDay = XmlHelpers::CreateXmlNode("TimeOfDay"); - } - } - else - { - m_timeOfDay->setAttr("Time", m_time); - ar.root->addChild(m_timeOfDay); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMission::SerializeEnvironment(CXmlArchive& ar) -{ - if (ar.bLoading) - { - XmlNodeRef env = ar.root->findChild("Environment"); - if (env) - { - m_environment = env; - } - } - else - { - XmlNodeRef env = m_environment->clone(); - env->setTag("Environment"); - ar.root->addChild(env); - } -} - diff --git a/Code/Sandbox/Editor/Mission.h b/Code/Sandbox/Editor/Mission.h deleted file mode 100644 index f0773a0be7..0000000000 --- a/Code/Sandbox/Editor/Mission.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Mission class definition. - -#pragma once - - -/*! - CMission represent single Game Mission on same map. - Multiple Missions share same map, and stored in one .cry or .ly file. - - */ -class CMission -{ -public: - //! Ctor of mission. - CMission(CCryEditDoc* doc); - //! Dtor of mission. - virtual ~CMission(); - - void SetName(const QString& name) { m_name = name; } - const QString& GetName() const { return m_name; } - - void SetDescription(const QString& dsc) { m_description = dsc; } - const QString& GetDescription() const { return m_description; } - - XmlNodeRef GetEnvironment() { return m_environment; }; - - void SetTime(float time) { m_time = time; }; - float GetTime() const { return m_time; }; - - //! Called when this mission must be synchonized with current data in Document. - //! if bRetrieve is true, data is retrieved from Mission to global structures. - void SyncContent(bool bRetrieve, bool bIgnoreObjects, bool bSkipLoadingAI = false); - - //! Create clone of this mission. - CMission* Clone(); - - //! Serialize mission. - void Serialize(CXmlArchive& ar, bool bParts = true); - - //! Serialize time of day - void SerializeTimeOfDay(CXmlArchive& ar); - - //! Serialize environment - void SerializeEnvironment(CXmlArchive& ar); - - //! Save some elements of mission to separate files - void SaveParts(); - - //! Load some elements of mission from separate files - void LoadParts(); - - //! Export mission to game. - void Export(XmlNodeRef& root, XmlNodeRef& objectsNode); - - //! Add shared objects to mission objects. - void AddObjectsNode(XmlNodeRef& node); - void SetLayersNode(XmlNodeRef& node); - - void OnEnvironmentChange(); - int GetNumCGFObjects() const { return m_numCGFObjects; }; - -private: - //! Document owner of this mission. - CCryEditDoc* m_doc; - - QString m_name; - QString m_description; - - //! Mission time; - float m_time; - - //! Root node of objects defined only in this mission. - XmlNodeRef m_objects; - - //! Object layers. - XmlNodeRef m_layers; - - //! Exported data of this mission. - XmlNodeRef m_exportData; - - //! Environment settings of this mission. - XmlNodeRef m_environment; - - XmlNodeRef m_Animations; // backward compatibility. - - XmlNodeRef m_timeOfDay; - - int m_numCGFObjects; - - bool m_reentrancyProtector; -}; - diff --git a/Code/Sandbox/Editor/ModelViewport.cpp b/Code/Sandbox/Editor/ModelViewport.cpp deleted file mode 100644 index bf15f2fbaf..0000000000 --- a/Code/Sandbox/Editor/ModelViewport.cpp +++ /dev/null @@ -1,1006 +0,0 @@ - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "ModelViewport.h" - -// Qt -#include -#include - -// CryCommon -#include - -#include "CryPhysicsDeprecation.h" - - -// Editor -#include "ThumbnailGenerator.h" // for CThumbnailGenerator -#include "FileTypeUtils.h" // for IsPreviewableFileType -#include "Material/MaterialManager.h" // for CMaterialManager -#include "ErrorRecorder.h" - - - - - -uint32 g_ypos = 0; - -#define SKYBOX_NAME "InfoRedGal" - -///////////////////////////////////////////////////////////////////////////// -// CModelViewport - -CModelViewport::CModelViewport(const char* settingsPath, QWidget* parent) - : CRenderViewport(tr("Model View"), parent) -{ - m_settingsPath = QString::fromLatin1(settingsPath); - - m_bPaused = false; - - m_Camera.SetFrustum(800, 600, 3.14f / 4.0f, 0.02f, 10000); - - m_bInRotateMode = false; - m_bInMoveMode = false; - - m_object = 0; - - - m_weaponModel = 0; - - m_camRadius = 10; - - m_moveSpeed = 0.1f; - m_LightRotationRadian = 0.0f; - - m_weaponIK = false; - - m_pRESky = 0; - m_pSkyboxName = 0; - m_pSkyBoxShader = NULL; - - m_attachBone = QStringLiteral("weapon_bone"); - - // Init variable. - mv_objectAmbientColor = Vec3(0.25f, 0.25f, 0.25f); - mv_backgroundColor = Vec3(0.25f, 0.25f, 0.25f); - - mv_lightDiffuseColor = Vec3(0.70f, 0.70f, 0.70f); - mv_lightMultiplier = 3.0f; - mv_lightOrbit = 15.0f; - mv_lightRadius = 400.0f; - mv_lightSpecMultiplier = 1.0f; - - mv_showPhysics = false; - - m_GridOrigin = Vec3(ZERO); - m_arrAnimatedCharacterPath.resize(0x200, ZERO); - m_arrSmoothEntityPath.resize(0x200, ZERO); - - m_arrRunStrafeSmoothing.resize(0x100); - SetPlayerPos(); - - // cache all the variable callbacks, must match order of enum defined in header - m_onSetCallbacksCache.push_back(AZStd::bind(&CModelViewport::OnCharPhysics, this, AZStd::placeholders::_1)); - m_onSetCallbacksCache.push_back(AZStd::bind(&CModelViewport::OnLightColor, this, AZStd::placeholders::_1)); - m_onSetCallbacksCache.push_back(AZStd::bind(&CModelViewport::OnLightMultiplier, this, AZStd::placeholders::_1)); - m_onSetCallbacksCache.push_back(AZStd::bind(&CModelViewport::OnShowShaders, this, AZStd::placeholders::_1)); - - //-------------------------------------------------- - // Register variables. - //-------------------------------------------------- - m_vars.AddVariable(mv_showPhysics, "Display Physics"); - m_vars.AddVariable(mv_useCharPhysics, "Use Character Physics", &m_onSetCallbacksCache[VariableCallbackIndex::OnCharPhysics]); - mv_useCharPhysics = true; - m_vars.AddVariable(mv_showGrid, "ShowGrid"); - mv_showGrid = true; - m_vars.AddVariable(mv_showBase, "ShowBase"); - mv_showBase = false; - m_vars.AddVariable(mv_showLocator, "ShowLocator"); - mv_showLocator = 0; - m_vars.AddVariable(mv_InPlaceMovement, "InPlaceMovement"); - mv_InPlaceMovement = false; - m_vars.AddVariable(mv_StrafingControl, "StrafingControl"); - mv_StrafingControl = false; - - m_vars.AddVariable(mv_lighting, "Lighting"); - mv_lighting = true; - m_vars.AddVariable(mv_animateLights, "AnimLights"); - - m_vars.AddVariable(mv_backgroundColor, "BackgroundColor", &m_onSetCallbacksCache[VariableCallbackIndex::OnLightColor], IVariable::DT_COLOR); - m_vars.AddVariable(mv_objectAmbientColor, "ObjectAmbient", &m_onSetCallbacksCache[VariableCallbackIndex::OnLightColor], IVariable::DT_COLOR); - - m_vars.AddVariable(mv_lightDiffuseColor, "LightDiffuse", &m_onSetCallbacksCache[VariableCallbackIndex::OnLightColor], IVariable::DT_COLOR); - m_vars.AddVariable(mv_lightMultiplier, "Light Multiplier", &m_onSetCallbacksCache[VariableCallbackIndex::OnLightMultiplier], IVariable::DT_SIMPLE); - m_vars.AddVariable(mv_lightSpecMultiplier, "Light Specular Multiplier", &m_onSetCallbacksCache[VariableCallbackIndex::OnLightMultiplier], IVariable::DT_SIMPLE); - m_vars.AddVariable(mv_lightRadius, "Light Radius", &m_onSetCallbacksCache[VariableCallbackIndex::OnLightMultiplier], IVariable::DT_SIMPLE); - m_vars.AddVariable(mv_lightOrbit, "Light Orbit", &m_onSetCallbacksCache[VariableCallbackIndex::OnLightMultiplier], IVariable::DT_SIMPLE); - - m_vars.AddVariable(mv_showWireframe1, "ShowWireframe1"); - m_vars.AddVariable(mv_showWireframe2, "ShowWireframe2"); - m_vars.AddVariable(mv_showTangents, "ShowTangents"); - m_vars.AddVariable(mv_showBinormals, "ShowBinormals"); - m_vars.AddVariable(mv_showNormals, "ShowNormals"); - - m_vars.AddVariable(mv_showSkeleton, "ShowSkeleton"); - m_vars.AddVariable(mv_showJointNames, "ShowJointNames"); - m_vars.AddVariable(mv_showJointsValues, "ShowJointsValues"); - m_vars.AddVariable(mv_showStartLocation, "ShowInvStartLocation"); - m_vars.AddVariable(mv_showMotionParam, "ShowMotionParam"); - m_vars.AddVariable(mv_printDebugText, "PrintDebugText"); - - m_vars.AddVariable(mv_UniformScaling, "UniformScaling"); - mv_UniformScaling = 1.0f; - mv_UniformScaling.SetLimits(0.01f, 2.0f); - m_vars.AddVariable(mv_forceLODNum, "ForceLODNum"); - mv_forceLODNum = 0; - mv_forceLODNum.SetLimits(0, 10); - m_vars.AddVariable(mv_showShaders, "ShowShaders", &m_onSetCallbacksCache[VariableCallbackIndex::OnShowShaders]); - m_vars.AddVariable(mv_AttachCamera, "AttachCamera"); - - m_vars.AddVariable(mv_fov, "FOV"); - mv_fov = 60; - mv_fov.SetLimits(1, 120); - - RestoreDebugOptions(); - - m_camRadius = 10; - - //YPR_Angle = Ang3(0,-1.0f,0); - //SetViewTM( Matrix34(CCamera::CreateOrientationYPR(YPR_Angle), Vec3(0,-m_camRadius,0)) ); - Vec3 camPos = Vec3(10, 10, 10); - Matrix34 tm = Matrix33::CreateRotationVDir((Vec3(0, 0, 0) - camPos).GetNormalized()); - tm.SetTranslation(camPos); - SetViewTM(tm); - - - m_AABB.Reset(); -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::SaveDebugOptions() const -{ - QSettings settings; - for (auto g : m_settingsPath.split('\\')) - settings.beginGroup(g); - - CVarBlock* vb = GetVarObject()->GetVarBlock(); - int32 vbCount = vb->GetNumVariables(); - - settings.setValue("iDebugOptionCount", vbCount); - - char keyType[64], keyValue[64]; - for (int32 i = 0; i < vbCount; ++i) - { - IVariable* var = vb->GetVariable(i); - IVariable::EType vType = var->GetType(); - sprintf_s(keyType, "DebugOption_%s_type", var->GetName().toUtf8().data()); - sprintf_s(keyValue, "DebugOption_%s_value", var->GetName().toUtf8().data()); - switch (vType) - { - case IVariable::UNKNOWN: - { - break; - } - case IVariable::INT: - { - int32 value = 0; - var->Get(value); - settings.setValue(keyType, IVariable::INT); - settings.setValue(keyValue, value); - - break; - } - case IVariable::BOOL: - { - bool value = 0; - var->Get(value); - settings.setValue(keyType, IVariable::BOOL); - settings.setValue(keyValue, value); - break; - } - case IVariable::FLOAT: - { - f32 value = 0; - var->Get(value); - settings.setValue(keyType, IVariable::FLOAT); - settings.setValue(keyValue, value); - break; - } - case IVariable::VECTOR: - { - Vec3 value; - var->Get(value); - f32 valueArray[3]; - valueArray[0] = value.x; - valueArray[1] = value.y; - valueArray[2] = value.z; - settings.setValue(keyType, IVariable::VECTOR); - settings.setValue(keyValue, QByteArray(reinterpret_cast(&value), 3 * sizeof(f32))); - - break; - } - case IVariable::QUAT: - { - Quat value; - var->Get(value); - f32 valueArray[4]; - valueArray[0] = value.w; - valueArray[1] = value.v.x; - valueArray[2] = value.v.y; - valueArray[3] = value.v.z; - - settings.setValue(keyType, IVariable::QUAT); - settings.setValue(keyValue, QByteArray(reinterpret_cast(&value), 4 * sizeof(f32))); - - break; - } - case IVariable::STRING: - { - QString value; - var->Get(value); - settings.setValue(keyType, IVariable::STRING); - settings.setValue(keyValue, value); - - break; - } - case IVariable::ARRAY: - { - break; - } - default: - break; - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::RestoreDebugOptions() -{ - QSettings settings; - for (auto g : m_settingsPath.split('\\')) - settings.beginGroup(g); - - QString strRead = ""; - int32 iRead = 0; - BOOL bRead = FALSE; - f32 fRead = .0f; - QByteArray pbtData; - - CVarBlock* vb = m_vars.GetVarBlock(); - int32 vbCount = vb->GetNumVariables(); - - char keyType[64], keyValue[64]; - for (int32 i = 0; i < vbCount; ++i) - { - IVariable* var = vb->GetVariable(i); - sprintf_s(keyType, "DebugOption_%s_type", var->GetName().toUtf8().data()); - - int32 iType = settings.value(keyType, 0).toInt(); - - sprintf_s(keyValue, "DebugOption_%s_value", var->GetName().toUtf8().data()); - switch (iType) - { - case IVariable::UNKNOWN: - { - break; - } - case IVariable::INT: - { - iRead = settings.value(keyValue, 0).toInt(); - var->Set(iRead); - break; - } - case IVariable::BOOL: - { - bRead = settings.value(keyValue, FALSE).toBool(); - var->Set(bRead); - break; - } - case IVariable::FLOAT: - { - fRead = settings.value(keyValue).toDouble(); - var->Set(fRead); - break; - } - case IVariable::VECTOR: - { - pbtData = settings.value(keyValue).toByteArray(); - assert(pbtData.count() == 3 * sizeof(f32)); - f32* pfRead = reinterpret_cast(pbtData.data()); - - Vec3 vecRead(pfRead[0], pfRead[1], pfRead[2]); - var->Set(vecRead); - break; - } - case IVariable::QUAT: - { - pbtData = settings.value(keyValue).toByteArray(); - assert(pbtData.count() == 4 * sizeof(f32)); - f32* pfRead = reinterpret_cast(pbtData.data()); - - Quat valueRead(pfRead[0], pfRead[1], pfRead[2], pfRead[3]); - var->Set(valueRead); - break; - } - case IVariable::STRING: - { - strRead = settings.value(keyValue, "").toString(); - var->Set(strRead); - break; - } - case IVariable::ARRAY: - { - break; - } - default: - break; - } - } -} - -////////////////////////////////////////////////////////////////////////// -CModelViewport::~CModelViewport() -{ - OnDestroy(); - ReleaseObject(); - - GetIEditor()->FlushUndo(); - - SaveDebugOptions(); - - // helper offset?? - CRY_PHYSICS_REPLACEMENT_ASSERT(); - GetIEditor()->SetConsoleVar("ca_UsePhysics", 1); -} - -///////////////////////////////////////////////////////////////////////////// -// CModelViewport message handlers -///////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -void CModelViewport::ReleaseObject() -{ - if (m_object) - { - m_object->Release(); - m_object = NULL; - } - - if (m_weaponModel) - { - m_weaponModel->Release(); - m_weaponModel = NULL; - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::LoadObject(const QString& fileName, [[maybe_unused]] float scale) -{ - m_bPaused = false; - - // Load object. - QString file = Path::MakeGamePath(fileName); - - bool reload = false; - if (m_loadedFile == file) - { - reload = true; - } - m_loadedFile = file; - - SetName(tr("Model View - %1").arg(file)); - - ReleaseObject(); - - // Enables display of warning after model have been loaded. - CErrorsRecorder errRecorder; - - if (IsPreviewableFileType(file.toUtf8().data())) - { - const QString fileExt = QFileInfo(file).completeSuffix(); - // Try Load character. - const bool isSKEL = (0 == fileExt.compare(CRY_SKEL_FILE_EXT, Qt::CaseInsensitive)); - const bool isSKIN = (0 == fileExt.compare(CRY_SKIN_FILE_EXT, Qt::CaseInsensitive)); - const bool isCGA = (0 == fileExt.compare(CRY_ANIM_GEOMETRY_FILE_EXT, Qt::CaseInsensitive)); - const bool isCDF = (0 == fileExt.compare(CRY_CHARACTER_DEFINITION_FILE_EXT, Qt::CaseInsensitive)); - if (isSKEL || isSKIN || isCGA || isCDF) - { - } - else - { - LoadStaticObject(file); - } - } - else - { - QMessageBox::warning(this, tr("Preview Error"), tr("Preview of this file type not supported.")); - return; - } - - //-------------------------------------------------------------------------------- - - if (!reload) - { - Vec3 v = m_AABB.max - m_AABB.min; - float radius = v.GetLength() / 2.0f; - m_camRadius = radius * 2; - } - - if (GetIEditor()->IsInPreviewMode()) - { - Physicalize(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::LoadStaticObject(const QString& file) -{ - if (m_object) - { - m_object->Release(); - } - - // Load Static object. - m_object = m_engine->LoadStatObjUnsafeManualRef(file.toUtf8().data(), 0, 0, false); - - if (!m_object) - { - CLogFile::WriteLine("Loading of object failed."); - return; - } - m_object->AddRef(); - - // Generate thumbnail for this cgf. - CThumbnailGenerator thumbGen; - thumbGen.GenerateForFile(file); - - m_AABB.min = m_object->GetBoxMin(); - m_AABB.max = m_object->GetBoxMax(); -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnRender() -{ - FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); - - const QRect rc = contentsRect(); - ProcessKeys(); - if (m_renderer) - { - PreWidgetRendering(); - - m_Camera.SetFrustum(m_Camera.GetViewSurfaceX(), m_Camera.GetViewSurfaceZ(), m_Camera.GetFov(), 0.02f, 10000, m_Camera.GetPixelAspectRatio()); - const int w = rc.width(); - const int h = rc.height(); - m_Camera.SetFrustum(w, h, DEG2RAD(mv_fov), 0.0101f, 10000.0f); - - if (GetIEditor()->IsInPreviewMode()) - { - GetISystem()->SetViewCamera(m_Camera); - } - - Vec3 clearColor = mv_backgroundColor; - m_renderer->SetClearColor(clearColor); - m_renderer->SetCamera(m_Camera); - - auto colorf = ColorF(clearColor, 1.0f); - m_renderer->ClearTargetsImmediately(FRT_CLEAR | FRT_CLEAR_IMMEDIATE, colorf); - m_renderer->ResetToDefault(); - - SRenderingPassInfo passInfo = SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_Camera, SRenderingPassInfo::DEFAULT_FLAGS, true); - - { - CScopedWireFrameMode scopedWireFrame(m_renderer, mv_showWireframe1 ? R_WIREFRAME_MODE : R_SOLID_MODE); - DrawModel(passInfo); - } - - PostWidgetRendering(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::DrawSkyBox(const SRenderingPassInfo& passInfo) -{ - CRenderObject* pObj = m_renderer->EF_GetObject_Temp(passInfo.ThreadID()); - pObj->m_II.m_Matrix.SetTranslationMat(GetViewTM().GetTranslation()); - - if (m_pSkyboxName) - { - SShaderItem skyBoxShaderItem(m_pSkyBoxShader); - m_renderer->EF_AddEf(m_pRESky, skyBoxShaderItem, pObj, passInfo, EFSLIST_GENERAL, 1, SRendItemSorter::CreateRendItemSorter(passInfo)); - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnAnimBack() -{ - // TODO: Add your command handler code here -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnAnimFastBack() -{ - // TODO: Add your command handler code here -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnAnimFastForward() -{ - // TODO: Add your command handler code here -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnAnimFront() -{ - // TODO: Add your command handler code here -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnAnimPlay() -{ - // TODO: Add your command handler code here -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::mouseDoubleClickEvent(QMouseEvent* event) -{ - // TODO: Add your message handler code here and/or call default - - CRenderViewport::mouseDoubleClickEvent(event); - if (event->button() != Qt::LeftButton) - { - return; - } - Matrix34 tm; - tm.SetIdentity(); - SetViewTM(tm); -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnLightColor([[maybe_unused]] IVariable* var) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnShowNormals([[maybe_unused]] IVariable* var) -{ - bool enable = mv_showNormals; - GetIEditor()->SetConsoleVar("r_ShowNormals", (enable) ? 1 : 0); -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnShowTangents([[maybe_unused]] IVariable* var) -{ - bool enable = mv_showTangents; - GetIEditor()->SetConsoleVar("r_ShowTangents", (enable) ? 1 : 0); -} - - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnCharPhysics([[maybe_unused]] IVariable* var) -{ - bool enable = mv_useCharPhysics; - GetIEditor()->SetConsoleVar("ca_UsePhysics", enable); -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnShowShaders([[maybe_unused]] IVariable* var) -{ - bool bEnable = mv_showShaders; - GetIEditor()->SetConsoleVar("r_ProfileShaders", bEnable); -} - -void CModelViewport::OnDestroy() -{ - ReleaseObject(); - if (m_pRESky) - { - m_pRESky->Release(false); - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnActivate() -{ -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnDeactivate() -{ -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::Update() -{ - FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); - - CRenderViewport::Update(); - - DrawInfo(); -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::DrawInfo() const -{ - if (GetIEditor()->Get3DEngine()) - { - ICVar* pDisplayInfo = gEnv->pConsole->GetCVar("r_DisplayInfo"); - if (pDisplayInfo && pDisplayInfo->GetIVal() != 0) - { - const float fps = gEnv->pTimer->GetFrameRate(); - const float x = (float)gEnv->pRenderer->GetWidth() - 5.0f; - - gEnv->p3DEngine->DrawTextRightAligned(x, 1, "FPS: %.2f", fps); - - int nPolygons, nShadowVolPolys; - gEnv->pRenderer->GetPolyCount(nPolygons, nShadowVolPolys); - int nDrawCalls = gEnv->pRenderer->GetCurrentNumberOfDrawCalls(); - gEnv->p3DEngine->DrawTextRightAligned(x, 20, "Tris:%2d,%03d - DP:%d", nPolygons / 1000, nPolygons % 1000, nDrawCalls); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::SetCustomMaterial(CMaterial* pMaterial) -{ - m_pCurrentMaterial = pMaterial; -} - -////////////////////////////////////////////////////////////////////////// -CMaterial* CModelViewport::GetMaterial() -{ - if (m_pCurrentMaterial) - { - return m_pCurrentMaterial; - } - else - { - _smart_ptr pMtl = 0; - if (m_object) - { - pMtl = m_object->GetMaterial(); - } - - CMaterial* pCMaterial = GetIEditor()->GetMaterialManager()->FromIMaterial(pMtl); - return pCMaterial; - } -} - -////////////////////////////////////////////////////////////////////////// -bool CModelViewport::CanDrop([[maybe_unused]] const QPoint& point, IDataBaseItem* pItem) -{ - if (!pItem) - { - return false; - } - - if (pItem->GetType() == EDB_TYPE_MATERIAL) - { - SetCustomMaterial((CMaterial*)pItem); - } - return true; -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::Drop([[maybe_unused]] const QPoint& point, IDataBaseItem* pItem) -{ - if (!pItem) - { - SetCustomMaterial(NULL); - return; - } - - if (pItem->GetType() == EDB_TYPE_MATERIAL) - { - SetCustomMaterial((CMaterial*)pItem); - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::Physicalize() -{ -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::RePhysicalize() -{ - Physicalize(); -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::SetPaused(bool bPaused) -{ - //return; - if (m_bPaused != bPaused) - { - m_bPaused = bPaused; - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::DrawModel(const SRenderingPassInfo& passInfo) -{ - FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); - - m_vCamPos = GetCamera().GetPosition(); - const QRect rc = contentsRect(); - //GetISystem()->SetViewCamera( m_Camera ); - IRenderAuxGeom* pAuxGeom = m_renderer->GetIRenderAuxGeom(); - m_renderer->BeginSpawningGeneratingRendItemJobs(passInfo.ThreadID()); - m_renderer->BeginSpawningShadowGeneratingRendItemJobs(passInfo.ThreadID()); - m_renderer->EF_ClearSkinningDataPool(); - m_renderer->EF_StartEf(passInfo); - - ////////////////////////////////////////////////////////////////////////// - // Draw lights. - ////////////////////////////////////////////////////////////////////////// - if (mv_lighting == true) - { - pAuxGeom->DrawSphere(m_VPLight.m_Origin, 0.2f, ColorB(255, 255, 0, 255)); - } - - gEnv->pConsole->GetCVar("ca_DrawWireframe")->Set(mv_showWireframe2); - gEnv->pConsole->GetCVar("ca_DrawTangents")->Set(mv_showTangents); - gEnv->pConsole->GetCVar("ca_DrawBinormals")->Set(mv_showBinormals); - gEnv->pConsole->GetCVar("ca_DrawNormals")->Set(mv_showNormals); - - DrawLights(passInfo); - - - //----------------------------------------------------------------------------- - //----- Render Static Object (handled by 3DEngine) ---- - //----------------------------------------------------------------------------- - // calculate LOD - - f32 fDistance = GetViewTM().GetTranslation().GetLength(); - SRendParams rp; - rp.fDistance = fDistance; - - Matrix34 tm; - tm.SetIdentity(); - rp.pMatrix = &tm; - rp.pPrevMatrix = &tm; - - Vec3 vAmbient; - mv_objectAmbientColor.Get(vAmbient); - - rp.AmbientColor.r = vAmbient.x * mv_lightMultiplier; - rp.AmbientColor.g = vAmbient.y * mv_lightMultiplier; - rp.AmbientColor.b = vAmbient.z * mv_lightMultiplier; - rp.AmbientColor.a = 1; - - rp.nDLightMask = 7; - if (mv_lighting == false) - { - rp.nDLightMask = 0; - } - - rp.dwFObjFlags = 0; - if (m_pCurrentMaterial) - { - rp.pMaterial = m_pCurrentMaterial->GetMatInfo(); - } - - //----------------------------------------------------------------------------- - //----- Render Static Object (handled by 3DEngine) ---- - //----------------------------------------------------------------------------- - if (m_object) - { - m_object->Render(rp, passInfo); - if (mv_showGrid) - { - DrawFloorGrid(Quat(IDENTITY), Vec3(ZERO), Matrix33(IDENTITY)); - } - - if (mv_showBase) - { - DrawCoordSystem(IDENTITY, 10.0f); - } - } - - m_renderer->EF_EndEf3D(SHDF_STREAM_SYNC, -1, -1, passInfo); -} - - -void CModelViewport::DrawLights(const SRenderingPassInfo& passInfo) -{ - if (mv_animateLights) - { - m_LightRotationRadian += m_AverageFrameTime; - } - - if (m_LightRotationRadian > gf_PI) - { - m_LightRotationRadian = -gf_PI; - } - - Matrix33 LightRot33 = Matrix33::CreateRotationZ(m_LightRotationRadian); - - Vec3 LPos0 = Vec3(-mv_lightOrbit, mv_lightOrbit, mv_lightOrbit); - m_VPLight.SetPosition(LightRot33 * LPos0 + m_PhysicalLocation.t); - Vec3 d = mv_lightDiffuseColor; - m_VPLight.SetLightColor(ColorF(d.x * mv_lightMultiplier, d.y * mv_lightMultiplier, d.z * mv_lightMultiplier, 0)); - m_VPLight.SetSpecularMult(mv_lightSpecMultiplier); - m_VPLight.m_fRadius = mv_lightRadius; - m_VPLight.m_Flags = DLF_SUN | DLF_DIRECTIONAL; - - if (mv_lighting == true) - { - m_renderer->EF_ADDDlight(&m_VPLight, passInfo); - } -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::PlayAnimation([[maybe_unused]] const char* szName) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::DrawFloorGrid(const Quat& m33, const Vec3& vPhysicalLocation, const Matrix33& rGridRot) -{ - if (!m_renderer) - { - return; - } - - float XR = 45; - float YR = 45; - - - - - - IRenderAuxGeom* pAuxGeom = m_renderer->GetIRenderAuxGeom(); - pAuxGeom->SetRenderFlags(e_Def3DPublicRenderflags); - - Vec3 axis = m33.GetColumn0(); - - Matrix33 SlopeMat33 = rGridRot; - uint32 GroundAlign = 1; - if (GroundAlign == 0) - { - SlopeMat33 = Matrix33::CreateRotationAA(m_absCurrentSlope, axis); - } - - - m_GridOrigin = Vec3(floorf(vPhysicalLocation.x), floorf(vPhysicalLocation.y), vPhysicalLocation.z); - - - Matrix33 ScaleMat33 = IDENTITY; - Vec3 rh = Matrix33::CreateRotationY(m_absCurrentSlope) * Vec3(1.0f, 0.0f, 0.0f); - if (rh.x) - { - Vec3 xback = SlopeMat33.GetRow(0); - Vec3 yback = SlopeMat33.GetRow(1); - f32 ratiox = 1.0f / Vec3(xback.x, xback.y, 0.0f).GetLength(); - f32 ratioy = 1.0f / Vec3(yback.x, yback.y, 0.0f).GetLength(); - - f32 ratio = 1.0f / rh.x; - // Vec3 h=Vec3((m_GridOrigin.x-vPhysicalLocation.x)*ratiox,(m_GridOrigin.y-vPhysicalLocation.y)*ratioy,0.0f); - Vec3 h = Vec3(m_GridOrigin.x - vPhysicalLocation.x, m_GridOrigin.y - vPhysicalLocation.y, 0.0f); - Vec3 nh = SlopeMat33 * h; - m_GridOrigin.z += nh.z * ratio; - - ScaleMat33 = Matrix33::CreateScale(Vec3(ratiox, ratioy, 0.0f)); - - // float color1[4] = {0,1,0,1}; - // m_renderer->Draw2dLabel(12,g_ypos,1.6f,color1,false,"h: %f %f %f h.z: %f ratio: %f ratiox: %f ratioy: %f",h.x,h.y,h.z, nh.z,ratio,ratiox,ratioy); - // g_ypos+=18; - } - - Matrix33 _m33; - _m33.SetIdentity(); - AABB aabb1 = AABB(Vec3(-0.03f, -YR, -0.001f), Vec3(0.03f, YR, 0.001f)); - OBB _obb1 = OBB::CreateOBBfromAABB(SlopeMat33, aabb1); - AABB aabb2 = AABB(Vec3(-XR, -0.03f, -0.001f), Vec3(XR, 0.03f, 0.001f)); - OBB _obb2 = OBB::CreateOBBfromAABB(SlopeMat33, aabb2); - - SlopeMat33 = SlopeMat33 * ScaleMat33; - // Draw grid. - float step = 0.25f; - for (float x = -XR; x < XR; x += step) - { - Vec3 p0 = Vec3(x, -YR, 0); - Vec3 p1 = Vec3(x, YR, 0); - //pAuxGeom->DrawLine( SlopeMat33*p0,RGBA8(0x7f,0x7f,0x7f,0x00), SlopeMat33*p1,RGBA8(0x7f,0x7f,0x7f,0x00) ); - int32 intx = int32(x); - if (fabsf(intx - x) < 0.001f) - { - pAuxGeom->DrawOBB(_obb1, SlopeMat33 * Vec3(x, 0.0f, 0.0f) + m_GridOrigin, 1, RGBA8(0x9f, 0x9f, 0x9f, 0x00), eBBD_Faceted); - } - else - { - pAuxGeom->DrawLine(SlopeMat33 * p0 + m_GridOrigin, RGBA8(0x7f, 0x7f, 0x7f, 0x00), SlopeMat33 * p1 + m_GridOrigin, RGBA8(0x7f, 0x7f, 0x7f, 0x00)); - } - } - - for (float y = -YR; y < YR; y += step) - { - Vec3 p0 = Vec3(-XR, y, 0); - Vec3 p1 = Vec3(XR, y, 0); - // pAuxGeom->DrawLine( SlopeMat33*p0,RGBA8(0x7f,0x7f,0x7f,0x00), SlopeMat33*p1,RGBA8(0x7f,0x7f,0x7f,0x00) ); - int32 inty = int32(y); - if (fabsf(inty - y) < 0.001f) - { - pAuxGeom->DrawOBB(_obb2, SlopeMat33 * Vec3(0.0f, y, 0.0f) + m_GridOrigin, 1, RGBA8(0x9f, 0x9f, 0x9f, 0x00), eBBD_Faceted); - } - else - { - pAuxGeom->DrawLine(SlopeMat33 * p0 + m_GridOrigin, RGBA8(0x7f, 0x7f, 0x7f, 0x00), SlopeMat33 * p1 + m_GridOrigin, RGBA8(0x7f, 0x7f, 0x7f, 0x00)); - } - } - - // TODO - the grid should probably be an IRenderNode at some point - // flushing grid geometry now so it will not override transparent - // objects later in the render pipeline. - pAuxGeom->Commit(); -} - - -//-------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------- -void CModelViewport::DrawCoordSystem(const QuatT& location, f32 length) -{ - IRenderAuxGeom* pAuxGeom = m_renderer->GetIRenderAuxGeom(); - SAuxGeomRenderFlags renderFlags(e_Def3DPublicRenderflags); - pAuxGeom->SetRenderFlags(renderFlags); - - Vec3 absAxisX = location.q.GetColumn0(); - Vec3 absAxisY = location.q.GetColumn1(); - Vec3 absAxisZ = location.q.GetColumn2(); - - const f32 scale = 3.0f; - const f32 size = 0.009f; - AABB xaabb = AABB(Vec3(-length * scale, -size * scale, -size * scale), Vec3(length * scale, size * scale, size * scale)); - AABB yaabb = AABB(Vec3(-size * scale, -length * scale, -size * scale), Vec3(size * scale, length * scale, size * scale)); - AABB zaabb = AABB(Vec3(-size * scale, -size * scale, -length * scale), Vec3(size * scale, size * scale, length * scale)); - - OBB obb; - obb = OBB::CreateOBBfromAABB(Matrix33(location.q), xaabb); - pAuxGeom->DrawOBB(obb, location.t, 1, RGBA8(0xff, 0x00, 0x00, 0xff), eBBD_Extremes_Color_Encoded); - pAuxGeom->DrawCone(location.t + absAxisX * length * scale, absAxisX, 0.03f * scale, 0.15f * scale, RGBA8(0xff, 0x00, 0x00, 0xff)); - - obb = OBB::CreateOBBfromAABB(Matrix33(location.q), yaabb); - pAuxGeom->DrawOBB(obb, location.t, 1, RGBA8(0x00, 0xff, 0x00, 0xff), eBBD_Extremes_Color_Encoded); - pAuxGeom->DrawCone(location.t + absAxisY * length * scale, absAxisY, 0.03f * scale, 0.15f * scale, RGBA8(0x00, 0xff, 0x00, 0xff)); - - obb = OBB::CreateOBBfromAABB(Matrix33(location.q), zaabb); - pAuxGeom->DrawOBB(obb, location.t, 1, RGBA8(0x00, 0x00, 0xff, 0xff), eBBD_Extremes_Color_Encoded); - pAuxGeom->DrawCone(location.t + absAxisZ * length * scale, absAxisZ, 0.03f * scale, 0.15f * scale, RGBA8(0x00, 0x00, 0xff, 0xff)); -} - - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::OnLightMultiplier([[maybe_unused]] IVariable* var) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CModelViewport::SetSelected(bool const bSelect) -{ - // If a modelviewport gets activated, and listeners will be activated, disable the main viewport listener and re-enable when you lose focus. - if (gEnv->pSystem) - { - IViewSystem* const pIViewSystem = gEnv->pSystem->GetIViewSystem(); - - if (pIViewSystem) - { - pIViewSystem->SetControlAudioListeners(!bSelect); - } - } -} - -#include diff --git a/Code/Sandbox/Editor/ModelViewport.h b/Code/Sandbox/Editor/ModelViewport.h deleted file mode 100644 index d9b119c5d5..0000000000 --- a/Code/Sandbox/Editor/ModelViewport.h +++ /dev/null @@ -1,268 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -//////////////////////////////////////////////////////////////////////////// -// -// Crytek Engine Source File. -// Copyright (C), Crytek Studios, 2001. -// ------------------------------------------------------------------------- -// File name: ModelViewport.h -// Version: v1.00 -// Created: 8/10/2001 by Timur. -// Compilers: Visual C++ 6.0 -// Description: -// ------------------------------------------------------------------------- -// History: -// -//////////////////////////////////////////////////////////////////////////// -#ifndef CRYINCLUDE_EDITOR_MODELVIEWPORT_H -#define CRYINCLUDE_EDITOR_MODELVIEWPORT_H - -#if !defined(Q_MOC_RUN) -#include "RenderViewport.h" -#include "Material/Material.h" -#include "Util/Variable.h" -#endif - -struct IPhysicalEntity; - -///////////////////////////////////////////////////////////////////////////// -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -// CModelViewport window -class SANDBOX_API CModelViewport - : public CRenderViewport -{ -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING - Q_OBJECT - // Construction -public: - CModelViewport(const char* settingsPath = "Settings\\CharacterEditorUserOptions", QWidget* parent = nullptr); - virtual ~CModelViewport(); - - virtual EViewportType GetType() const { return ET_ViewportModel; } - virtual void SetType([[maybe_unused]] EViewportType type) { assert(type == ET_ViewportModel); }; - - virtual void LoadObject(const QString& obj, float scale); - - virtual void OnActivate(); - virtual void OnDeactivate(); - - virtual bool CanDrop(const QPoint& point, IDataBaseItem* pItem); - virtual void Drop(const QPoint& point, IDataBaseItem* pItem); - - virtual void SetSelected(bool const bSelect); - - // Callbacks. - void OnShowShaders(IVariable* var); - void OnShowNormals(IVariable* var); - void OnShowTangents(IVariable* var); - - void OnShowPortals(IVariable* var); - void OnShowShadowVolumes(IVariable* var); - void OnShowTextureUsage(IVariable* var); - void OnCharPhysics(IVariable* var); - void OnShowOcclusion(IVariable* var); - - void OnLightColor(IVariable* var); - void OnLightMultiplier(IVariable* var); - void OnDisableVisibility(IVariable* var); - - IStatObj* GetStaticObject(){ return m_object; } - - void GetOnDisableVisibility(IVariable* var); - - const CVarObject* GetVarObject() const { return &m_vars; } - CVarObject* GetVarObject() { return &m_vars; } - - virtual void Update(); - - - void UseWeaponIK([[maybe_unused]] bool val) { m_weaponIK = true; } - - // Set current material to render object. - void SetCustomMaterial(CMaterial* pMaterial); - // Get custom material that object is rendered with. - CMaterial* GetCustomMaterial() { return m_pCurrentMaterial; }; - - // Get material the object is actually rendered with. - CMaterial* GetMaterial(); - - void ReleaseObject(); - void RePhysicalize(); - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - Vec3 m_GridOrigin; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - void SetPaused(bool bPaused); - bool GetPaused() {return m_bPaused; } - - bool IsCameraAttached() const{ return mv_AttachCamera; } - - virtual void PlayAnimation(const char* szName); - - const QString& GetLoadedFileName() const { return m_loadedFile; } - - void Physicalize(); - -protected: - - void LoadStaticObject(const QString& file); - - // Called to render stuff. - virtual void OnRender(); - - virtual void DrawFloorGrid(const Quat& tmRotation, const Vec3& MotionTranslation, const Matrix33& rGridRot); - void DrawCoordSystem(const QuatT& q, f32 length); - - void SaveDebugOptions() const; - void RestoreDebugOptions(); - - virtual void DrawModel(const SRenderingPassInfo& passInfo); - virtual void DrawLights(const SRenderingPassInfo& passInfo); - virtual void DrawSkyBox(const SRenderingPassInfo& passInfo); - - void DrawInfo() const; - - void SetConsoleVar(const char* var, int value); - - void OnEditorNotifyEvent(EEditorNotifyEvent event) - { - if (event != eNotify_OnBeginGameMode) - { - // the base class responds to this by forcing itself to be the current context. - // we don't want that to be the case for previewer viewports. - CRenderViewport::OnEditorNotifyEvent(event); - } - } - - IStatObj* m_object; - IStatObj* m_weaponModel; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - - QString m_attachBone; - AABB m_AABB; - - struct BBox - { - OBB obb; - Vec3 pos; - ColorB col; - }; - std::vector m_arrBBoxes; - - // Camera control. - float m_camRadius; - - // True to show grid. - bool m_bGrid; - bool m_bBase; - - QString m_settingsPath; - - bool m_weaponIK; - - QString m_loadedFile; - CDLight m_VPLight; - - f32 m_LightRotationRadian; - - class CRESky* m_pRESky; - struct ICVar* m_pSkyboxName; - IShader* m_pSkyBoxShader; - _smart_ptr m_pCurrentMaterial; - - //--------------------------------------------------- - //--- debug options --- - //--------------------------------------------------- - CVariable mv_showGrid; - CVariable mv_showBase; - CVariable mv_showLocator; - CVariable mv_InPlaceMovement; - CVariable mv_StrafingControl; - - CVariable mv_showWireframe1; //draw wireframe instead of solid-geometry. - CVariable mv_showWireframe2; //this one is software-wireframe rendered on top of the solid geometry - CVariable mv_showTangents; - CVariable mv_showBinormals; - CVariable mv_showNormals; - - CVariable mv_showSkeleton; - CVariable mv_showJointNames; - CVariable mv_showJointsValues; - CVariable mv_showStartLocation; - CVariable mv_showMotionParam; - CVariable mv_UniformScaling; - - CVariable mv_printDebugText; - CVariable mv_AttachCamera; - - CVariable mv_showShaders; - - CVariable mv_lighting; - CVariable mv_animateLights; - - CVariable mv_backgroundColor; - CVariable mv_objectAmbientColor; - - CVariable mv_lightDiffuseColor; - CVariable mv_lightMultiplier; - CVariable mv_lightSpecMultiplier; - CVariable mv_lightRadius; - CVariable mv_lightOrbit; - - CVariable mv_fov; - CVariable mv_showPhysics; - CVariable mv_useCharPhysics; - CVariable mv_showPhysicsTetriders; - CVariable mv_forceLODNum; - - CVariableArray mv_advancedTable; - - CVarObject m_vars; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - -public slots: - virtual void OnAnimPlay(); - virtual void OnAnimBack(); - virtual void OnAnimFastBack(); - virtual void OnAnimFastForward(); - virtual void OnAnimFront(); -protected: - bool m_bPaused; - - void OnDestroy(); - void mouseDoubleClickEvent(QMouseEvent* event) override; - -private: - struct VariableCallbackIndex - { - enum : unsigned char - { - OnCharPhysics = 0, - OnLightColor, - OnLightMultiplier, - OnShowShaders, - - // must be at the end - Count, - }; - }; -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - AZStd::fixed_vector< IVariable::OnSetCallback, VariableCallbackIndex::Count > m_onSetCallbacksCache; -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_MODELVIEWPORT_H diff --git a/Code/Sandbox/Editor/ModelViewportDC.cpp b/Code/Sandbox/Editor/ModelViewportDC.cpp deleted file mode 100644 index 9424a12c0c..0000000000 --- a/Code/Sandbox/Editor/ModelViewportDC.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - - - - - - - - - - diff --git a/Code/Sandbox/Editor/ModernViewportCameraController.cpp b/Code/Sandbox/Editor/ModernViewportCameraController.cpp index 6fda0381e8..4725721f0e 100644 --- a/Code/Sandbox/Editor/ModernViewportCameraController.cpp +++ b/Code/Sandbox/Editor/ModernViewportCameraController.cpp @@ -14,12 +14,35 @@ #include #include +#include #include +#include +#include #include #include +#include + +namespace AzFramework +{ + extern InputChannelId CameraFreeLookButton; + extern InputChannelId CameraFreePanButton; + extern InputChannelId CameraOrbitLookButton; + extern InputChannelId CameraOrbitDollyButton; + extern InputChannelId CameraOrbitPanButton; +} namespace SandboxEditor { + static void DrawPreviewAxis(AzFramework::DebugDisplayRequests& display, const AZ::Transform& transform, const float axisLength) + { + display.SetColor(AZ::Colors::Red); + display.DrawLine(transform.GetTranslation(), transform.GetTranslation() + transform.GetBasisX().GetNormalizedSafe() * axisLength); + display.SetColor(AZ::Colors::Green); + display.DrawLine(transform.GetTranslation(), transform.GetTranslation() + transform.GetBasisY().GetNormalizedSafe() * axisLength); + display.SetColor(AZ::Colors::Blue); + display.DrawLine(transform.GetTranslation(), transform.GetTranslation() + transform.GetBasisZ().GetNormalizedSafe() * axisLength); + } + static AZ::RPI::ViewportContextPtr RetrieveViewportContext(const AzFramework::ViewportId viewportId) { auto viewportContextManager = AZ::Interface::Get(); @@ -37,49 +60,56 @@ namespace SandboxEditor return viewportContext; } - AzFramework::Cameras ModernViewportCameraController::GetCameras() const + ModernViewportCameraControllerInstance::ModernViewportCameraControllerInstance(const AzFramework::ViewportId viewportId) + : MultiViewportControllerInstanceInterface(viewportId) { - AzFramework::Cameras cameras; - auto firstPersonRotateCamera = AZStd::make_shared(AzFramework::InputDeviceMouse::Button::Right); - auto firstPersonPanCamera = AZStd::make_shared(AzFramework::LookPan); + // LYN-2315 TODO - move setup out of constructor, pass cameras in + auto firstPersonRotateCamera = AZStd::make_shared(AzFramework::CameraFreeLookButton); + auto firstPersonPanCamera = + AZStd::make_shared(AzFramework::CameraFreePanButton, AzFramework::LookPan); auto firstPersonTranslateCamera = AZStd::make_shared(AzFramework::LookTranslation); auto firstPersonWheelCamera = AZStd::make_shared(); auto orbitCamera = AZStd::make_shared(); - auto orbitRotateCamera = AZStd::make_shared(AzFramework::InputDeviceMouse::Button::Left); + auto orbitRotateCamera = AZStd::make_shared(AzFramework::CameraOrbitLookButton); auto orbitTranslateCamera = AZStd::make_shared(AzFramework::OrbitTranslation); auto orbitDollyWheelCamera = AZStd::make_shared(); - auto orbitDollyMoveCamera = AZStd::make_shared(); - auto orbitPanCamera = AZStd::make_shared(AzFramework::OrbitPan); + auto orbitDollyMoveCamera = + AZStd::make_shared(AzFramework::CameraOrbitDollyButton); + auto orbitPanCamera = + AZStd::make_shared(AzFramework::CameraOrbitPanButton, AzFramework::OrbitPan); + orbitCamera->m_orbitCameras.AddCamera(orbitRotateCamera); orbitCamera->m_orbitCameras.AddCamera(orbitTranslateCamera); orbitCamera->m_orbitCameras.AddCamera(orbitDollyWheelCamera); orbitCamera->m_orbitCameras.AddCamera(orbitDollyMoveCamera); orbitCamera->m_orbitCameras.AddCamera(orbitPanCamera); - cameras.AddCamera(firstPersonRotateCamera); - cameras.AddCamera(firstPersonPanCamera); - cameras.AddCamera(firstPersonTranslateCamera); - cameras.AddCamera(firstPersonWheelCamera); - cameras.AddCamera(orbitCamera); - return AZStd::move(cameras); - } + m_cameraSystem.m_cameras.AddCamera(firstPersonRotateCamera); + m_cameraSystem.m_cameras.AddCamera(firstPersonPanCamera); + m_cameraSystem.m_cameras.AddCamera(firstPersonTranslateCamera); + m_cameraSystem.m_cameras.AddCamera(firstPersonWheelCamera); + m_cameraSystem.m_cameras.AddCamera(orbitCamera); - ModernViewportCameraControllerInstance::ModernViewportCameraControllerInstance(const AzFramework::ViewportId viewportId, ModernViewportCameraController* controller) - : MultiViewportControllerInstanceInterface(viewportId, controller) - { - // LYN-2315 TODO - move setup out of constructor, pass cameras in - m_cameraSystem.m_cameras = controller->GetCameras(); - - if (const auto viewportContext = RetrieveViewportContext(viewportId)) + if (auto viewportContext = RetrieveViewportContext(GetViewportId())) { - // set position but not orientation - m_targetCamera.m_lookAt = viewportContext->GetCameraTransform().GetTranslation(); + auto handleCameraChange = [this](const AZ::Matrix4x4& matrix) { + UpdateCameraFromTransform( + m_targetCamera, + AZ::Transform::CreateFromMatrix3x3AndTranslation(AZ::Matrix3x3::CreateFromMatrix4x4(matrix), matrix.GetTranslation())); + }; - // LYN-2315 TODO https://www.geometrictools.com/Documentation/EulerAngles.pdf + m_cameraViewMatrixChangeHandler = AZ::RPI::ViewportContext::MatrixChangedEvent::Handler(handleCameraChange); - m_camera = m_targetCamera; + viewportContext->ConnectViewMatrixChangedHandler(m_cameraViewMatrixChangeHandler); } + + AzFramework::ViewportDebugDisplayEventBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId()); + } + + ModernViewportCameraControllerInstance::~ModernViewportCameraControllerInstance() + { + AzFramework::ViewportDebugDisplayEventBus::Handler::BusDisconnect(); } bool ModernViewportCameraControllerInstance::HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) @@ -87,18 +117,78 @@ namespace SandboxEditor AzFramework::WindowSize windowSize; AzFramework::WindowRequestBus::EventResult( windowSize, event.m_windowHandle, &AzFramework::WindowRequestBus::Events::GetClientAreaSize); - m_cameraSystem.HandleEvents(AzFramework::BuildInputEvent(event.m_inputChannel, windowSize)); - return true; // consume event + + if (m_cameraMode == CameraMode::Control) + { + if (AzFramework::InputDeviceKeyboard::IsKeyboardDevice(event.m_inputChannel.GetInputDevice().GetInputDeviceId())) + { + if (event.m_inputChannel.GetInputChannelId() == AzFramework::InputDeviceKeyboard::Key::AlphanumericR) + { + m_transformEnd = m_camera.Transform(); + + return true; + } + else if (event.m_inputChannel.GetInputChannelId() == AzFramework::InputDeviceKeyboard::Key::AlphanumericP) + { + m_animationT = 0.0f; + m_cameraMode = CameraMode::Animation; + m_transformStart = m_camera.Transform(); + + return true; + } + } + } + + return m_cameraSystem.HandleEvents(AzFramework::BuildInputEvent(event.m_inputChannel, windowSize)); } void ModernViewportCameraControllerInstance::UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event) { if (auto viewportContext = RetrieveViewportContext(GetViewportId())) { - m_targetCamera = m_cameraSystem.StepCamera(m_targetCamera, event.m_deltaTime.count()); - m_camera = AzFramework::SmoothCamera(m_camera, m_targetCamera, m_smoothProps, event.m_deltaTime.count()); + if (m_cameraMode == CameraMode::Control) + { + m_targetCamera = m_cameraSystem.StepCamera(m_targetCamera, event.m_deltaTime.count()); + m_camera = AzFramework::SmoothCamera(m_camera, m_targetCamera, event.m_deltaTime.count()); + + viewportContext->SetCameraTransform(m_camera.Transform()); + } + else if (m_cameraMode == CameraMode::Animation) + { + const auto smootherStepFn = [](const float t) { return t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f); }; + const float transitionT = smootherStepFn(m_animationT); + + const AZ::Transform current = AZ::Transform::CreateFromQuaternionAndTranslation( + m_transformStart.GetRotation().Slerp(m_transformEnd.GetRotation(), transitionT), + m_transformStart.GetTranslation().Lerp(m_transformEnd.GetTranslation(), transitionT)); + + const AZ::Vector3 eulerAngles = AzFramework::EulerAngles(AZ::Matrix3x3::CreateFromTransform(current)); + m_camera.m_pitch = eulerAngles.GetX(); + m_camera.m_yaw = eulerAngles.GetZ(); + m_camera.m_lookAt = current.GetTranslation(); + m_targetCamera = m_camera; - viewportContext->SetCameraTransform(m_camera.Transform()); + if (m_animationT >= 1.0f) + { + m_cameraMode = CameraMode::Control; + } + + m_animationT = AZ::GetClamp(m_animationT + event.m_deltaTime.count(), 0.0f, 1.0f); + + viewportContext->SetCameraTransform(current); + } + } + } + + void ModernViewportCameraControllerInstance::DisplayViewport( + [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) + { + if (const float alpha = AZStd::min(-m_camera.m_lookDist / 5.0f, 1.0f); alpha > AZ::Constants::FloatEpsilon) + { + debugDisplay.SetColor(1.0f, 1.0f, 1.0f, alpha); + debugDisplay.DrawWireSphere(m_camera.m_lookAt, 0.5f); } + + DrawPreviewAxis(debugDisplay, m_transformEnd, 2.0f); } } // namespace SandboxEditor diff --git a/Code/Sandbox/Editor/ModernViewportCameraController.h b/Code/Sandbox/Editor/ModernViewportCameraController.h index 9cb2fe45f7..2d753669f2 100644 --- a/Code/Sandbox/Editor/ModernViewportCameraController.h +++ b/Code/Sandbox/Editor/ModernViewportCameraController.h @@ -12,17 +12,22 @@ #pragma once +#include +#include #include #include namespace SandboxEditor { class ModernViewportCameraControllerInstance; - class ModernViewportCameraController : public AzFramework::MultiViewportController + class ModernViewportCameraController + : public AzFramework::MultiViewportController + , private AzFramework::ViewportDebugDisplayEventBus::Handler { public: AzFramework::Cameras GetCameras() const; }; + ~ModernViewportCameraControllerInstance(); class ModernViewportCameraControllerInstance final : public AzFramework::MultiViewportControllerInstanceInterface { @@ -33,10 +38,25 @@ namespace SandboxEditor bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override; void UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event) override; + // AzFramework::ViewportDebugDisplayEventBus overrides ... + void DisplayViewport(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override; + private: + enum class CameraMode + { + Control, + Animation + }; + AzFramework::Camera m_camera; AzFramework::Camera m_targetCamera; - AzFramework::SmoothProps m_smoothProps; AzFramework::CameraSystem m_cameraSystem; + + AZ::Transform m_transformStart = AZ::Transform::CreateIdentity(); + AZ::Transform m_transformEnd = AZ::Transform::CreateIdentity(); + float m_animationT = 0.0f; + CameraMode m_cameraMode = CameraMode::Control; + + AZ::RPI::ViewportContext::MatrixChangedEvent::Handler m_cameraViewMatrixChangeHandler; }; } // namespace SandboxEditor diff --git a/Code/Sandbox/Editor/Objects/AxisGizmo.cpp b/Code/Sandbox/Editor/Objects/AxisGizmo.cpp index 40970838c1..ef2b91685a 100644 --- a/Code/Sandbox/Editor/Objects/AxisGizmo.cpp +++ b/Code/Sandbox/Editor/Objects/AxisGizmo.cpp @@ -22,7 +22,6 @@ #include "ViewManager.h" #include "Settings.h" #include "RenderHelpers/AxisHelper.h" -#include "RenderHelpers/AxisHelperExtended.h" #include "IObjectManager.h" ////////////////////////////////////////////////////////////////////////// @@ -36,7 +35,6 @@ CAxisGizmo::CAxisGizmo(CBaseObject* object) assert(object != 0); m_object = object; m_pAxisHelper.reset(new CAxisHelper); - m_pAxisHelperExtended.reset(new CAxisHelperExtended); // Set selectable flag. SetFlags(EGIZMO_SELECTABLE | EGIZMO_TRANSFORM_MANIPULATOR); @@ -60,7 +58,6 @@ CAxisGizmo::CAxisGizmo() SetFlags(EGIZMO_SELECTABLE); m_axisGizmoCount++; m_pAxisHelper.reset(new CAxisHelper); - m_pAxisHelperExtended.reset(new CAxisHelperExtended); m_bDragging = false; m_bAlwaysUseLocal = false; m_coordSysBackUp = COORDS_VIEW; diff --git a/Code/Sandbox/Editor/Objects/AxisGizmo.h b/Code/Sandbox/Editor/Objects/AxisGizmo.h index 55506ed6b5..689b011972 100644 --- a/Code/Sandbox/Editor/Objects/AxisGizmo.h +++ b/Code/Sandbox/Editor/Objects/AxisGizmo.h @@ -22,7 +22,6 @@ // forward declarations. struct DisplayContext; class CAxisHelper; -class CAxisHelperExtended; /** Gizmo of Objects animation track. */ @@ -75,7 +74,6 @@ private: CBaseObjectPtr m_object; AABB m_bbox; std::unique_ptr m_pAxisHelper; - std::unique_ptr m_pAxisHelperExtended; bool m_bDragging; QPoint m_cMouseDownPos; diff --git a/Code/Sandbox/Editor/Objects/BaseObject.cpp b/Code/Sandbox/Editor/Objects/BaseObject.cpp index a579f303a9..3ec505172e 100644 --- a/Code/Sandbox/Editor/Objects/BaseObject.cpp +++ b/Code/Sandbox/Editor/Objects/BaseObject.cpp @@ -30,8 +30,6 @@ #include "DisplaySettings.h" #include "Undo/Undo.h" #include "UsedResources.h" -#include "Material/Material.h" -#include "Material/MaterialManager.h" #include "GizmoManager.h" #include "Include/IIconManager.h" #include "Objects/SelectionGroup.h" @@ -39,6 +37,8 @@ #include "ViewManager.h" #include "IEditorImpl.h" #include "GameEngine.h" +#include +#include // To use the Andrew's algorithm in order to make convex hull from the points, this header is needed. #include "Util/GeometryUtil.h" @@ -398,7 +398,6 @@ CBaseObject::CBaseObject() , m_classDesc(nullptr) , m_numRefs(0) , m_parent(nullptr) - , m_pMaterial(nullptr) , m_bInSelectionBox(false) , m_pTransformDelegate(nullptr) , m_bMatrixInWorldSpace(false) @@ -438,7 +437,6 @@ bool CBaseObject::Init([[maybe_unused]] IEditor* ie, CBaseObject* prev, [[maybe_ SetArea(prev->GetArea()); SetColor(prev->GetColor()); m_nMaterialLayersMask = prev->m_nMaterialLayersMask; - SetMaterial(prev->GetMaterial()); SetMinSpec(prev->GetMinSpec(), false); // Copy all basic variables. @@ -485,12 +483,6 @@ void CBaseObject::Done() NotifyListeners(CBaseObject::ON_DELETE); m_eventListeners.clear(); - - if (m_pMaterial) - { - m_pMaterial->Release(); - m_pMaterial = NULL; - } } ////////////////////////////////////////////////////////////////////////// @@ -831,9 +823,8 @@ void CBaseObject::GetLocalBounds(AABB& box) } ////////////////////////////////////////////////////////////////////////// -void CBaseObject::SetModified(bool boModifiedTransformOnly) +void CBaseObject::SetModified(bool) { - ((CObjectManager*)GetObjectManager())->OnObjectModified(this, false, boModifiedTransformOnly); } void CBaseObject::DrawDefault(DisplayContext& dc, const QColor& labelColor) @@ -1838,11 +1829,6 @@ void CBaseObject::Serialize(CObjectArchive& ar) SetFrozen(bFrozen); SetHidden(bHidden); - ////////////////////////////////////////////////////////////////////////// - // Load material. - ////////////////////////////////////////////////////////////////////////// - SetMaterial(mtlName); - ar.SetResolveCallback(this, parentId, AZStd::bind(&CBaseObject::ResolveParent, this, AZStd::placeholders::_1 )); ar.SetResolveCallback(this, lookatId, AZStd::bind(&CBaseObject::SetLookAt, this, AZStd::placeholders::_1)); @@ -1912,11 +1898,6 @@ void CBaseObject::Serialize(CObjectArchive& ar) xmlNode->setAttr("Flags", flags); } - if (m_pMaterial) - { - xmlNode->setAttr("Material", GetMaterialName().toUtf8().data()); - } - if (m_nMinSpec != 0) { xmlNode->setAttr("MinSpec", (uint32)m_nMinSpec); @@ -1937,11 +1918,6 @@ XmlNodeRef CBaseObject::Export([[maybe_unused]] const QString& levelPath, XmlNod objNode->setAttr("Type", GetTypeName().toUtf8().data()); objNode->setAttr("Name", GetName().toUtf8().data()); - if (m_pMaterial) - { - objNode->setAttr("Material", m_pMaterial->GetName().toUtf8().data()); - } - Vec3 pos, scale; Quat rotate; if (m_parent) @@ -2926,7 +2902,6 @@ bool CBaseObject::ConvertFromObject(CBaseObject* object) { object->GetParent()->AttachChild(this); } - SetMaterial(object->GetMaterial()); return true; } @@ -2981,14 +2956,6 @@ void CBaseObject::Validate(IErrorReport* report) report->ReportError(err); } ////////////////////////////////////////////////////////////////////////// - - if (GetMaterial() != NULL && GetMaterial()->IsDummy()) - { - CErrorRecord err; - err.error = QStringLiteral("Material: %1 for object: %2 not found,").arg(GetMaterial()->GetName(), GetName()); - err.pObject = this; - report->ReportError(err); - } }; ////////////////////////////////////////////////////////////////////////// @@ -3055,10 +3022,6 @@ void CBaseObject::GatherUsedResources(CUsedResources& resources) { GetVarBlock()->GatherUsedResources(resources); } - if (m_pMaterial) - { - m_pMaterial->GatherUsedResources(resources); - } } ////////////////////////////////////////////////////////////////////////// @@ -3071,50 +3034,6 @@ bool CBaseObject::IsSimilarObject(CBaseObject* pObject) return false; } -////////////////////////////////////////////////////////////////////////// -void CBaseObject::SetMaterial(CMaterial* mtl) -{ - if (m_pMaterial == mtl) - { - return; - } - - StoreUndo("Assign Material"); - if (m_pMaterial) - { - m_pMaterial->Release(); - } - m_pMaterial = mtl; - if (m_pMaterial) - { - m_pMaterial->AddRef(); - } - - OnMaterialChanged(MATERIALCHANGE_ALL); -} - -////////////////////////////////////////////////////////////////////////// -QString CBaseObject::GetMaterialName() const -{ - if (m_pMaterial) - { - return m_pMaterial->GetName(); - } - return ""; -} - -////////////////////////////////////////////////////////////////////////// -void CBaseObject::SetMaterial(const QString& materialName) -{ - CMaterial* pMaterial = NULL; - CMaterialManager* pManager = GetIEditor()->GetMaterialManager(); - if (!materialName.isEmpty() && pManager != NULL) - { - pMaterial = pManager->LoadMaterial(materialName); - } - SetMaterial(pMaterial); -} - ////////////////////////////////////////////////////////////////////////// void CBaseObject::SetMinSpec(uint32 nSpec, bool bSetChildren) { diff --git a/Code/Sandbox/Editor/Objects/BaseObject.h b/Code/Sandbox/Editor/Objects/BaseObject.h index d62e0bed5f..5d6f800a58 100644 --- a/Code/Sandbox/Editor/Objects/BaseObject.h +++ b/Code/Sandbox/Editor/Objects/BaseObject.h @@ -35,8 +35,6 @@ class CUndoBaseObject; class CObjectManager; class CGizmo; class CObjectArchive; -class CMaterial; -class CEdGeometry; struct SSubObjSelectionModifyContext; struct SRayHitInfo; class ISubObjectSelectionReferenceFrameCalculator; @@ -135,13 +133,6 @@ enum ObjectEditFlags OBJECT_COLLAPSE_OBJECTPANEL = 0x004 }; -/////////////////////////////////////////////////////////////////////////// -enum MaterialChangeFlags -{ - MATERIALCHANGE_SURFACETYPE = 0x001, - MATERIALCHANGE_ALL = 0xFFFFFFFF, -}; - ////////////////////////////////////////////////////////////////////////// //! Return values from CBaseObject::MouseCreateCallback method. enum MouseCreateResult @@ -554,22 +545,6 @@ public: //! Remove event listener callback. void RemoveEventListener(EventListener* listener); - ////////////////////////////////////////////////////////////////////////// - //! Material handling for this base object. - //! Override in derived classes. - ////////////////////////////////////////////////////////////////////////// - //! Assign new material to this object. - virtual void SetMaterial(CMaterial* mtl); - //! Assign new material to this object as a material name. - virtual void SetMaterial(const QString& materialName); - //! Get assigned material for this object. - virtual CMaterial* GetMaterial() const { return m_pMaterial; }; - // Get actual rendering material for this object. - virtual CMaterial* GetRenderMaterial() const { return m_pMaterial; }; - // Get the material name. Even though the material pointer is null, the material name can exist separately. - virtual QString GetMaterialName() const; - virtual void OnMaterialChanged([[maybe_unused]] MaterialChangeFlags change) {} - ////////////////////////////////////////////////////////////////////////// //! Analyze errors for this object. virtual void Validate(IErrorReport* report); @@ -604,10 +579,6 @@ public: virtual void ModifySubObjSelection([[maybe_unused]] SSubObjSelectionModifyContext& modCtx) {}; virtual void AcceptSubObjectModify() {}; - // Request a geometry pointer from the object. - // Return NULL if geometry can not be retrieved or object does not support geometries. - virtual CEdGeometry* GetGeometry() { return 0; }; - //! In This function variables of the object must be initialized. virtual void InitVariables() {}; @@ -861,9 +832,6 @@ private: //! Pointer to parent node. mutable CBaseObject* m_parent; - //! Material of this object. - CMaterial* m_pMaterial; - AABB m_worldBounds; // The transform delegate diff --git a/Code/Sandbox/Editor/Objects/DisplayContext.h b/Code/Sandbox/Editor/Objects/DisplayContext.h index a8181e1d1b..13363a923e 100644 --- a/Code/Sandbox/Editor/Objects/DisplayContext.h +++ b/Code/Sandbox/Editor/Objects/DisplayContext.h @@ -33,7 +33,6 @@ struct IDisplayViewport; struct IRenderer; struct IRenderAuxGeom; struct IIconManager; -struct I3DEngine; class CDisplaySettings; class CCamera; @@ -70,7 +69,6 @@ struct SANDBOX_API DisplayContext IRenderer* renderer; IRenderAuxGeom* pRenderAuxGeom; IIconManager* pIconManager; - I3DEngine* engine; CCamera* camera; AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING AABB box; // Bounding box of volume that need to be repainted. diff --git a/Code/Sandbox/Editor/Objects/DisplayContextShared.inl b/Code/Sandbox/Editor/Objects/DisplayContextShared.inl index dd5c248357..4d284faea7 100644 --- a/Code/Sandbox/Editor/Objects/DisplayContextShared.inl +++ b/Code/Sandbox/Editor/Objects/DisplayContextShared.inl @@ -18,8 +18,6 @@ #include "Include/IIconManager.h" #include "Include/IDisplayViewport.h" -#include - #include #include @@ -32,7 +30,6 @@ DisplayContext::DisplayContext() { view = 0; renderer = 0; - engine = 0; flags = 0; settings = 0; pIconManager = 0; @@ -981,27 +978,8 @@ void DisplayContext::RenderObject(int objectType, const Vec3& pos, float scale) } ////////////////////////////////////////////////////////////////////////// -void DisplayContext::RenderObject(int objectType, const Matrix34& tm) +void DisplayContext::RenderObject(int, const Matrix34&) { - IStatObj* object = pIconManager ? pIconManager->GetObject((EStatObject)objectType) : 0; - if (object) - { - float color[4]; - color[0] = m_color4b.r * (1.0f / 255.0f); - color[1] = m_color4b.g * (1.0f / 255.0f); - color[2] = m_color4b.b * (1.0f / 255.0f); - color[3] = m_color4b.a * (1.0f / 255.0f); - - SRenderingPassInfo passInfo = SRenderingPassInfo::CreateGeneralPassRenderingInfo(GetIEditor()->GetSystem()->GetViewCamera()); - - Matrix34 xform = m_matrixStack[m_currentMatrix] * tm; - SRendParams rp; - rp.pMatrix = &xform; - rp.AmbientColor = ColorF(color[0], color[1], color[2], 1); - rp.fAlpha = color[3]; - - object->Render(rp, passInfo); - } } ///////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/Objects/EntityObject.cpp b/Code/Sandbox/Editor/Objects/EntityObject.cpp index 8beda36013..17e9fdda5c 100644 --- a/Code/Sandbox/Editor/Objects/EntityObject.cpp +++ b/Code/Sandbox/Editor/Objects/EntityObject.cpp @@ -25,21 +25,15 @@ #include "Settings.h" #include "Viewport.h" #include "LineGizmo.h" -#include "Material/MaterialManager.h" #include "Include/IObjectManager.h" #include "Objects/ObjectManager.h" #include "ViewManager.h" -#include "LensFlareEditor/LensFlareManager.h" -#include "LensFlareEditor/LensFlareUtil.h" -#include "LensFlareEditor/LensFlareLibrary.h" #include "AnimationContext.h" #include "HitContext.h" #include "Objects/SelectionGroup.h" - -const char* CEntityObject::s_LensFlarePropertyName("flare_Flare"); -const char* CEntityObject::s_LensFlareMaterialName("EngineAssets/Materials/lens_optics"); - +#include +#include ////////////////////////////////////////////////////////////////////////// //! Undo Entity Link @@ -1084,11 +1078,6 @@ XmlNodeRef CEntityObject::Export([[maybe_unused]] const QString& levelPath, XmlN objNode->setAttr("Name", GetName().toUtf8().data()); - if (GetMaterial()) - { - objNode->setAttr("Material", GetMaterial()->GetName().toUtf8().data()); - } - Vec3 pos = GetPos(), scale = GetScale(); Quat rotate = GetRotation(); @@ -1867,17 +1856,6 @@ void CEntityObject::OnLoadFailed() GetIEditor()->GetErrorReport()->ReportError(err); } -////////////////////////////////////////////////////////////////////////// -CMaterial* CEntityObject::GetRenderMaterial() const -{ - if (GetMaterial()) - { - return GetMaterial(); - } - - return NULL; -} - ////////////////////////////////////////////////////////////////////////// void CEntityObject::SetHelperScale(float scale) { @@ -1950,157 +1928,6 @@ void CEntityObject::OnContextMenu(QMenu* pMenu) CBaseObject::OnContextMenu(pMenu); } -////////////////////////////////////////////////////////////////////////// -void CEntityObject::OnMaterialChanged(MaterialChangeFlags change) -{ - if (change & MATERIALCHANGE_SURFACETYPE) - { - m_statObjValidator.Validate(0, GetRenderMaterial()); - } -} - -////////////////////////////////////////////////////////////////////////// -QString CEntityObject::GetTooltip() const -{ - return m_statObjValidator.GetDescription(); -} - -////////////////////////////////////////////////////////////////////////// -IOpticsElementBasePtr CEntityObject::GetOpticsElement() -{ - CDLight* pLight = GetLightProperty(); - if (pLight == NULL) - { - return NULL; - } - return pLight->GetLensOpticsElement(); -} - -////////////////////////////////////////////////////////////////////////// -void CEntityObject::SetOpticsElement(IOpticsElementBase* pOptics) -{ - CDLight* pLight = GetLightProperty(); - if (pLight == NULL) - { - return; - } - pLight->SetLensOpticsElement(pOptics); - if (GetEntityPropertyBool("bFlareEnable") && pOptics) - { - CBaseObject::SetMaterial(s_LensFlareMaterialName); - } - else - { - SetMaterial(NULL); - } -} - -////////////////////////////////////////////////////////////////////////// -void CEntityObject::ApplyOptics(const QString& opticsFullName, IOpticsElementBasePtr pOptics) -{ - if (pOptics == NULL) - { - CDLight* pLight = GetLightProperty(); - if (pLight) - { - pLight->SetLensOpticsElement(NULL); - } - SetFlareName(""); - SetMaterial(NULL); - } - else - { - int nOpticsIndex(0); - if (!gEnv->pOpticsManager->Load(opticsFullName.toUtf8().data(), nOpticsIndex)) - { - IOpticsElementBasePtr pNewOptics = gEnv->pOpticsManager->Create(eFT_Root); - if (!gEnv->pOpticsManager->AddOptics(pNewOptics, opticsFullName.toUtf8().data(), nOpticsIndex)) - { - CDLight* pLight = GetLightProperty(); - if (pLight) - { - pLight->SetLensOpticsElement(NULL); - SetMaterial(NULL); - } - return; - } - LensFlareUtil::CopyOptics(pOptics, pNewOptics); - } - SetFlareName(opticsFullName); - } -} - -////////////////////////////////////////////////////////////////////////// -void CEntityObject::SetOpticsName(const QString& opticsFullName) -{ - if (opticsFullName.isEmpty()) - { - CDLight* pLight = GetLightProperty(); - if (pLight) - { - pLight->SetLensOpticsElement(NULL); - } - SetFlareName(""); - SetMaterial(NULL); - } - else - { - if (GetOpticsElement()) - { - if (gEnv->pOpticsManager->Rename(GetOpticsElement()->GetName(), opticsFullName.toUtf8().data())) - { - SetFlareName(opticsFullName); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -CDLight* CEntityObject::GetLightProperty() const -{ - const PodArray* pLightEntities = GetIEditor()->Get3DEngine()->GetLightEntities(); - if (pLightEntities == NULL) - { - return NULL; - } - for (int i = 0, iLightSize(pLightEntities->Count()); i < iLightSize; ++i) - { - ILightSource* pLightSource = pLightEntities->GetAt(i); - if (pLightSource == NULL) - { - continue; - } - CDLight& lightProperty = pLightSource->GetLightProperties(); - if (GetName() != lightProperty.m_sName) - { - continue; - } - return &lightProperty; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -bool CEntityObject::GetValidFlareName(QString& outFlareName) const -{ - IVariable* pFlareVar(m_pProperties->FindVariable(s_LensFlarePropertyName)); - if (!pFlareVar) - { - return false; - } - - QString flareName; - pFlareVar->Get(flareName); - if (flareName.isEmpty() || flareName == "@root") - { - return false; - } - - outFlareName = flareName; - - return true; -} - ////////////////////////////////////////////////////////////////////////// void CEntityObject::PreInitLightProperty() { @@ -2108,42 +1935,6 @@ void CEntityObject::PreInitLightProperty() { return; } - - QString flareFullName; - if (GetValidFlareName(flareFullName)) - { - bool bEnableOptics = GetEntityPropertyBool("bFlareEnable"); - if (bEnableOptics) - { - CLensFlareManager* pLensManager = GetIEditor()->GetLensFlareManager(); - CLensFlareLibrary* pLevelLib = (CLensFlareLibrary*)pLensManager->GetLevelLibrary(); - IOpticsElementBasePtr pLevelOptics = pLevelLib->GetOpticsOfItem(flareFullName.toUtf8().data()); - if (pLevelLib && pLevelOptics) - { - int nOpticsIndex(0); - IOpticsElementBasePtr pNewOptics = GetOpticsElement(); - if (pNewOptics == NULL) - { - pNewOptics = gEnv->pOpticsManager->Create(eFT_Root); - } - - if (gEnv->pOpticsManager->AddOptics(pNewOptics, flareFullName.toUtf8().data(), nOpticsIndex)) - { - LensFlareUtil::CopyOptics(pLevelOptics, pNewOptics); - SetOpticsElement(pNewOptics); - } - else - { - CDLight* pLight = GetLightProperty(); - if (pLight) - { - pLight->SetLensOpticsElement(NULL); - SetMaterial(NULL); - } - } - } - } - } } ////////////////////////////////////////////////////////////////////////// @@ -2153,26 +1944,6 @@ void CEntityObject::UpdateLightProperty() { return; } - - QString flareName; - if (GetValidFlareName(flareName)) - { - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - pOptics = gEnv->pOpticsManager->Create(eFT_Root); - } - bool bEnableOptics = GetEntityPropertyBool("bFlareEnable"); - if (bEnableOptics && GetIEditor()->GetLensFlareManager()->LoadFlareItemByName(flareName, pOptics)) - { - pOptics->SetName(flareName.toUtf8().data()); - SetOpticsElement(pOptics); - } - else - { - SetOpticsElement(NULL); - } - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/Objects/EntityObject.h b/Code/Sandbox/Editor/Objects/EntityObject.h index 9964cbd72f..85368f7804 100644 --- a/Code/Sandbox/Editor/Objects/EntityObject.h +++ b/Code/Sandbox/Editor/Objects/EntityObject.h @@ -21,7 +21,6 @@ #include "IMovieSystem.h" #include "IEntityObjectListener.h" -#include "StatObjValidator.h" #include "Gizmo.h" #include "CryListenerSet.h" #include "StatObjBus.h" @@ -108,8 +107,6 @@ public: void SetEntityPropertyFloat(const char* name, float value); void SetEntityPropertyString(const char* name, const QString& value); - virtual QString GetTooltip() const; - virtual int MouseCreateCallback(CViewport* view, EMouseEvent event, QPoint& point, int flags); virtual void OnContextMenu(QMenu* menu); @@ -134,9 +131,6 @@ public: virtual void SetTransformDelegate(ITransformDelegate* pTransformDelegate) override; - virtual CMaterial* GetRenderMaterial() const; - virtual void OnMaterialChanged(MaterialChangeFlags change); - // Set attach flags and target enum EAttachmentType { @@ -220,11 +214,6 @@ public: QString GetLightAnimation() const; IVariable* GetLightVariable(const char* name) const; - IOpticsElementBasePtr GetOpticsElement(); - void SetOpticsElement(IOpticsElementBase* pOptics); - void ApplyOptics(const QString& opticsFullName, IOpticsElementBasePtr pOptics); - void SetOpticsName(const QString& opticsFullName); - bool GetValidFlareName(QString& outFlareName) const; void PreInitLightProperty(); void UpdateLightProperty(); @@ -236,14 +225,9 @@ public: static void StoreUndoEntityLink(CSelectionGroup* pGroup); - static const char* s_LensFlarePropertyName; - static const char* s_LensFlareMaterialName; - void RegisterListener(IEntityObjectListener* pListener); void UnregisterListener(IEntityObjectListener* pListener); - CDLight* GetLightProperty() const; - protected: template void SetEntityProperty(const char* name, T value); @@ -322,11 +306,6 @@ protected: void AdjustLightProperties(CVarBlockPtr& properties, const char* pSubBlock); IVariable* FindVariableInSubBlock(CVarBlockPtr& properties, IVariable* pSubBlockVar, const char* pVarName); - void SetFlareName(const QString& name) - { - SetEntityPropertyString(s_LensFlarePropertyName, name); - } - unsigned int m_bLoadFailed : 1; unsigned int m_bCalcPhysics : 1; unsigned int m_bDisplayBBox : 1; @@ -416,8 +395,6 @@ protected: static float m_helperScale; - CStatObjValidator m_statObjValidator; - EAttachmentType m_attachmentType; bool m_bEnableReload; diff --git a/Code/Sandbox/Editor/Objects/ObjectLoader.cpp b/Code/Sandbox/Editor/Objects/ObjectLoader.cpp index 746b9e8c73..41f543a5a3 100644 --- a/Code/Sandbox/Editor/Objects/ObjectLoader.cpp +++ b/Code/Sandbox/Editor/Objects/ObjectLoader.cpp @@ -17,7 +17,6 @@ // Editor #include "Util/PakFile.h" -#include "Material/MaterialManager.h" #include "WaitProgress.h" #include "Include/IObjectManager.h" @@ -239,14 +238,6 @@ void CObjectArchive::ResolveObjects() obj.pObject->CreateGameObject(); - CMaterial* pMaterial = obj.pObject->GetRenderMaterial(); - CMaterialManager* pManager = GetIEditor()->GetMaterialManager(); - - if (pMaterial && pMaterial->GetMatInfo() && pManager) - { - pManager->OnRequestMaterial(pMaterial->GetMatInfo()); - } - // unset the current validator object because the wait Step // might generate unrelated errors m_pCurrentErrorReport->SetCurrentValidatorObject(nullptr); diff --git a/Code/Sandbox/Editor/Objects/ObjectManager.cpp b/Code/Sandbox/Editor/Objects/ObjectManager.cpp index 39174774be..d383fb0e1b 100644 --- a/Code/Sandbox/Editor/Objects/ObjectManager.cpp +++ b/Code/Sandbox/Editor/Objects/ObjectManager.cpp @@ -400,8 +400,6 @@ void CObjectManager::DeleteObject(CBaseObject* obj) CUndo::Record(new CUndoBaseObjectDelete(obj)); } - OnObjectModified(obj, true, false); - AABB objAAB; obj->GetBoundBox(objAAB); GetIEditor()->GetGameEngine()->OnAreaModified(objAAB); @@ -2477,17 +2475,6 @@ IGizmoManager* CObjectManager::GetGizmoManager() return m_gizmoManager; } -////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////// -void CObjectManager::OnObjectModified(CBaseObject* pObject, [[maybe_unused]] bool bDelete, [[maybe_unused]] bool boModifiedTransformOnly) -{ - if (IRenderNode* pRenderNode = pObject->GetEngineNode()) - { - GetIEditor()->Get3DEngine()->OnObjectModified(pRenderNode, pRenderNode->GetRndFlags()); - } -} - ////////////////////////////////////////////////////////////////////////// bool CObjectManager::IsLightClass(CBaseObject* pObject) { diff --git a/Code/Sandbox/Editor/Objects/ObjectManager.h b/Code/Sandbox/Editor/Objects/ObjectManager.h index 26905c47cd..4939fdeefc 100644 --- a/Code/Sandbox/Editor/Objects/ObjectManager.h +++ b/Code/Sandbox/Editor/Objects/ObjectManager.h @@ -326,9 +326,6 @@ public: // Gathers all resources used by all objects. void GatherUsedResources(CUsedResources& resources); - // Called when object gets modified. - void OnObjectModified(CBaseObject* pObject, bool bDelete, bool boModifiedTransformOnly); - virtual bool IsLightClass(CBaseObject* pObject); virtual void FindAndRenameProperty2(const char* property2Name, const QString& oldValue, const QString& newValue); diff --git a/Code/Sandbox/Editor/Objects/SelectionGroup.cpp b/Code/Sandbox/Editor/Objects/SelectionGroup.cpp index b883b78e49..98e00645ee 100644 --- a/Code/Sandbox/Editor/Objects/SelectionGroup.cpp +++ b/Code/Sandbox/Editor/Objects/SelectionGroup.cpp @@ -20,8 +20,9 @@ // Editor #include "ViewManager.h" -#include "SurfaceInfoPicker.h" +#include "Include/IObjectManager.h" +#include ////////////////////////////////////////////////////////////////////////// CSelectionGroup::CSelectionGroup() @@ -238,16 +239,6 @@ void CSelectionGroup::Move(const Vec3& offset, EMoveSelectionFlag moveFlag, [[ma } SRayHitInfo pickedInfo; - if (moveFlag == eMS_FollowGeometryPosNorm && bValidFollowGeometryMode) - { - CSurfaceInfoPicker::CExcludedObjects excludeObjects; - for (int i = 0; i < GetFilteredCount(); ++i) - { - excludeObjects.Add(GetFilteredObject(i)); - } - CSurfaceInfoPicker surfacePicker; - bValidFollowGeometryMode = surfacePicker.Pick(point, pickedInfo, &excludeObjects); - } if (moveFlag == eMS_FollowGeometryPosNorm) { diff --git a/Code/Sandbox/Editor/Objects/StatObjValidator.cpp b/Code/Sandbox/Editor/Objects/StatObjValidator.cpp deleted file mode 100644 index 85226fb236..0000000000 --- a/Code/Sandbox/Editor/Objects/StatObjValidator.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "StatObjValidator.h" - -// Editor -#include "Material/Material.h" - - -CStatObjValidator::CStatObjValidator() - : m_isValid(true) -{ -} - -template -bool HasPrefix(const char* name, const char (&prefix)[size]) -{ - return _strnicmp(name, prefix, size - 1) == 0; -} - -struct SMeshMaterialIssue -{ - AZStd::string nodeName; - AZStd::string description; - int subMaterialIndex; - - SMeshMaterialIssue() - : subMaterialIndex(-1) - { - } - - SMeshMaterialIssue(const AZStd::string& name, const AZStd::string& description) - : nodeName(name) - , description(description) - , subMaterialIndex(-1) - { - } -}; - -static void ValidateMeshMaterials(std::vector* issues, IStatObj* pStatObj, CMaterial* pMaterial) -{ - _smart_ptr pIMaterial = 0; - if (pMaterial) - { - if (pMaterial->GetParent()) - { - pIMaterial = pMaterial->GetParent()->GetMatInfo(); - } - else - { - pIMaterial = pMaterial->GetMatInfo(); - } - } - - IIndexedMesh* pIndexedMesh = pStatObj->GetIndexedMesh(true); - if (pIndexedMesh) - { - int breakableSubmeshes = 0; - int nonbreakableSubmeshes = 0; - - int subsetCount = pIndexedMesh->GetSubSetCount(); - for (int i = 0; i < subsetCount; ++i) - { - const SMeshSubset& subset = pIndexedMesh->GetSubSet(i); - if (subset.nNumVerts == 0) - { - continue; - } - - // Check to see if the material uses multiple uv sets and if the vertex format has the same number of texCoord attributes - SShaderItem shaderItem = pIMaterial->GetShaderItem(i); - if (shaderItem.m_pShader) - { - size_t materialUVs = shaderItem.m_pShader->GetNumberOfUVSets(); - size_t meshUVs = subset.vertexFormat.GetAttributeUsageCount(AZ::Vertex::AttributeUsage::TexCoord); - if (materialUVs != meshUVs) - { - const char* meshName = pStatObj->GetRenderMesh() ? pStatObj->GetRenderMesh()->GetSourceName() : "unknown"; - AZStd::string errorMessage; - errorMessage = AZStd::string::format("Material '%s' sub-material %d with %zu uv set(s) was assigned to mesh '%s' with %zu uv set(s). ", pIMaterial->GetName(), i + 1, materialUVs, meshName, meshUVs); - - AZStd::string recommendedAction; - if (materialUVs < meshUVs) - { - recommendedAction = AZStd::string::format("If you do not intend to use %zu uv sets, remove the extra uv set(s) from the source mesh during the import process. Otherwise, consider checking the desired 'Use uv set 2 for...' shader gen params in the material editor.", meshUVs); - } - else - { - recommendedAction = AZStd::string::format("If you intend to use %zu uv sets, include the additional uv set(s) in the source mesh during the import process. Otherwise, consider unchecking the 'Use uv set 2 for...' shader gen params in the material editor.", materialUVs); - } - errorMessage += recommendedAction; - AZ_Warning("Material Editor", false, errorMessage.c_str()); - SMeshMaterialIssue issue(meshName, errorMessage); - issues->push_back(issue); - } - } - - _smart_ptr pSubMaterial = pIMaterial->GetSubMtl(subset.nMatID); - if (!pSubMaterial) - { - continue; - } - - if (size_t(subset.nMatID) > size_t(pMaterial->GetSubMaterialCount())) - { - continue; - } - - if (pSubMaterial->GetSurfaceType()->GetBreakable2DParams()) - { - ++breakableSubmeshes; - } - else - { - ++nonbreakableSubmeshes; - } - } - } - - - int subobjectCount = pStatObj->GetSubObjectCount(); - for (int i = 0; i < subobjectCount; ++i) - { - const IStatObj::SSubObject* subobject = pStatObj->GetSubObject(i); - if (subobject->pStatObj) - { - ValidateMeshMaterials(issues, subobject->pStatObj, pMaterial); - } - } -} - -void CStatObjValidator::Validate(IStatObj* statObj, CMaterial* editorMaterial) -{ - m_description = QString(); - m_isValid = true; - - _smart_ptr pIMaterial = 0; - if (editorMaterial) - { - if (editorMaterial->GetParent()) - { - pIMaterial = editorMaterial->GetParent()->GetMatInfo(); - } - else - { - pIMaterial = editorMaterial->GetMatInfo(); - } - } - - if (statObj && editorMaterial) - { - std::vector issues; - ValidateMeshMaterials(&issues, statObj, editorMaterial); - - if (!issues.empty()) - { - m_isValid = false; - } - - for (size_t i = 0; i < issues.size(); ++i) - { - const SMeshMaterialIssue& issue = issues[i]; - if (!m_description.isEmpty()) - { - m_description += "\n"; - } - if (!issue.nodeName.empty()) - { - m_description += "Node "; - m_description += issue.nodeName.c_str(); - m_description += ":"; - } - if (issue.subMaterialIndex >= 0) - { - m_description += QStringLiteral("SubMaterial %1:").arg(issue.subMaterialIndex + 1); - } - if (!issue.nodeName.empty() || issue.subMaterialIndex >= 0) - { - m_description += "\n "; - } - if (!issue.description.empty()) - { - m_description += issue.description.c_str(); - } - } - } -} - diff --git a/Code/Sandbox/Editor/Objects/StatObjValidator.h b/Code/Sandbox/Editor/Objects/StatObjValidator.h deleted file mode 100644 index 40145e90c5..0000000000 --- a/Code/Sandbox/Editor/Objects/StatObjValidator.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// This class is supposed to validate CGF with assigned material. -// Some of the asset issues may be diagnosed only when SurfaceType is known. - -#pragma once - -class CRYEDIT_API CStatObjValidator -{ -public: - CStatObjValidator(); - - void Validate(IStatObj* statObj, CMaterial* editorMaterial); - bool IsValid() const { return m_isValid; } - - QString GetDescription() const { return m_description; } -private: - bool m_isValid; - QString m_description; -}; - diff --git a/Code/Sandbox/Editor/PanelPreview.cpp b/Code/Sandbox/Editor/PanelPreview.cpp deleted file mode 100644 index fe5ea7be9b..0000000000 --- a/Code/Sandbox/Editor/PanelPreview.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "PanelPreview.h" - -// Qt -#include - -// CPanelPreview dialog - -CPanelPreview::CPanelPreview(QWidget* pParent /*=nullptr*/) - : QWidget(pParent) - , m_previewCtrl(new CPreviewModelCtrl(this)) -{ - QBoxLayout* layout = new QHBoxLayout; - layout->setMargin(0); - layout->addWidget(m_previewCtrl); - setLayout(layout); -} - -////////////////////////////////////////////////////////////////////////// -void CPanelPreview::LoadFile(const QString& filename) -{ - if (!filename.isEmpty()) - { - m_previewCtrl->EnableUpdate(false); - m_previewCtrl->LoadFile(filename, false); - } -} - diff --git a/Code/Sandbox/Editor/PanelPreview.h b/Code/Sandbox/Editor/PanelPreview.h deleted file mode 100644 index d2c951ba4e..0000000000 --- a/Code/Sandbox/Editor/PanelPreview.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_PANELPREVIEW_H -#define CRYINCLUDE_EDITOR_PANELPREVIEW_H -#pragma once - -// CPanelPreview dialog - -#include "Controls/PreviewModelCtrl.h" - - -class CPanelPreview - : public QWidget -{ -public: - CPanelPreview(QWidget* pParent = nullptr); // standard constructor - - void LoadFile(const QString& filename); - - QSize sizeHint() const override - { - return QSize(130, 240); - } - -protected: - CPreviewModelCtrl* m_previewCtrl; -}; - -#endif // CRYINCLUDE_EDITOR_PANELPREVIEW_H diff --git a/Code/Sandbox/Editor/Platform/Mac/editor_mac.cmake b/Code/Sandbox/Editor/Platform/Mac/editor_mac.cmake index 484974745d..62523369e7 100644 --- a/Code/Sandbox/Editor/Platform/Mac/editor_mac.cmake +++ b/Code/Sandbox/Editor/Platform/Mac/editor_mac.cmake @@ -9,13 +9,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -ly_add_bundle_resources( - TARGET Editor - FILES - ${CMAKE_SOURCE_DIR}/Code/Tools/RC/Config/rc/xmlfilter.txt - ${CMAKE_SOURCE_DIR}/Code/Tools/RC/Config/rc/rc.ini -) - # Set resources directory for app icons target_sources(Editor PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Images.xcassets) set_target_properties(Editor PROPERTIES diff --git a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.cpp b/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.cpp deleted file mode 100644 index cee7f0f716..0000000000 --- a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "AxisHelperExtended.h" - -#include "CryPhysicsDeprecation.h" - -// Editor -#include "Include/IDisplayViewport.h" -#include "SurfaceInfoPicker.h" -#include "Objects/DisplayContext.h" -#include "Objects/SelectionGroup.h" -#include "Util/fastlib.h" - - -////////////////////////////////////////////////////////////////////////// -// Helper Extended Axis object. -////////////////////////////////////////////////////////////////////////// -CAxisHelperExtended::CAxisHelperExtended() - : m_matrix(IDENTITY) - , m_vPos(ZERO) - , m_pCurObject(0) - , m_dwLastUpdateTime(0) - , m_fMaxDist(100.0f) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CAxisHelperExtended::DrawAxes(DisplayContext& dc, const Matrix34& matrix, bool bUsePhysicalProxy) -{ - const DWORD dwUpdateTime = 2000; // 2 sec - CSelectionGroup* pSel = GetIEditor()->GetSelection(); - int numSels = pSel->GetCount(); - - if (numSels == 0) - { - return; - } - - CBaseObject* pCurObject = pSel->GetObject(numSels - 1); // get just last object for simple check - - // Add current selection to the elements to be skipped - CRY_PHYSICS_REPLACEMENT_ASSERT(); - - Vec3 x = Vec3(1, 0, 0); - Vec3 y = Vec3(0, 1, 0); - Vec3 z = Vec3(0, 0, 1); - - Vec3 colR = Vec3(1, 0, 0); - Vec3 colG = Vec3(0, 1, 0); - Vec3 colB = Vec3(0, 0.8f, 1); - - m_vPos = matrix.GetTranslation(); - - Vec3 vDirX = (matrix * x - m_vPos); - Vec3 vDirY = (matrix * y - m_vPos); - Vec3 vDirZ = (matrix * z - m_vPos); - vDirX.Normalize(); - vDirY.Normalize(); - vDirZ.Normalize(); - - if ( - m_pCurObject != pCurObject || - GetTickCount() - m_dwLastUpdateTime > dwUpdateTime || - !Matrix34::IsEquivalent(m_matrix, matrix) - ) - { - Vec3 outTmp; - AABB aabb(m_vPos, m_fMaxDist); - m_objects.clear(); - CBaseObjectsArray allObjects; - GetIEditor()->GetObjectManager()->GetObjects(allObjects); - - for (size_t i = 0, n = allObjects.size(); i < n; ++i) - { - CBaseObject* pObject = allObjects[i]; - if (pObject->IsSelected() || !pObject->GetEngineNode()) - { - continue; - } - - AABB aabbObj; - pObject->GetBoundBox(aabbObj); - - if (!Intersect::Ray_AABB(m_vPos, vDirX, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, vDirY, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, vDirZ, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, -vDirX, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, -vDirY, aabbObj, outTmp) - && !Intersect::Ray_AABB(m_vPos, -vDirZ, aabbObj, outTmp)) - { - continue; - } - - if (aabb.IsIntersectBox(aabbObj)) - { - m_objects.push_back(pObject); - } - } - m_dwLastUpdateTime = GetTickCount(); - } - m_pCurObject = pCurObject; - m_matrix = matrix; - - DrawAxis(dc, vDirX, z, colR, bUsePhysicalProxy); - DrawAxis(dc, vDirY, z, colG, bUsePhysicalProxy); - DrawAxis(dc, vDirZ, x, colB, bUsePhysicalProxy); - DrawAxis(dc, -vDirX, z, colR, bUsePhysicalProxy); - DrawAxis(dc, -vDirY, z, colG, bUsePhysicalProxy); - DrawAxis(dc, -vDirZ, x, colB, bUsePhysicalProxy); -} - - -////////////////////////////////////////////////////////////////////////// -void CAxisHelperExtended::DrawAxis(DisplayContext& dc, const Vec3& vDir, const Vec3& vUpAxis, const Vec3& col, bool bUsePhysicalProxy) -{ - AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Editor); - - const float fBallSize = 0.005f; - const float fTextSize = 1.4f; - - float fDist = m_fMaxDist + 1.0f; - size_t objectsSize = m_objects.size(); - for (size_t i = 0; i < objectsSize; ++i) - { - CBaseObject* pObject = m_objects[i]; - if (pObject->CheckFlags(OBJFLAG_DELETED)) - { - continue; - } - - SRayHitInfo hitInfo; - if (pObject->IntersectRayMesh(m_vPos, vDir, hitInfo)) - { - Vec3 newP = pObject->GetWorldTM().TransformPoint(hitInfo.vHitPos); - float fNewDist = (newP - m_vPos).GetLength(); - if (fDist > fNewDist) - { - fDist = fNewDist; - } - } - } - - if (bUsePhysicalProxy) - { - CRY_PHYSICS_REPLACEMENT_ASSERT(); - } - else - { - CSurfaceInfoPicker picker; - m_objectsForPicker.assign(m_objects.begin(), m_objects.end()); - picker.SetObjects(&m_objectsForPicker); - SRayHitInfo hitInfo; - if (picker.Pick(m_vPos, fDist * vDir, hitInfo, NULL, CSurfaceInfoPicker::ePOG_All)) - { - fDist = hitInfo.fDistance; - } - picker.SetObjects(0); - } - - if (fDist < m_fMaxDist) - { - Vec3 p = m_vPos + vDir * fDist; - - dc.SetColor(col); - dc.DrawLine(m_vPos, p); - float fScreenScale = dc.view->GetScreenScaleFactor(p); - dc.DrawBall(p, fBallSize * fScreenScale); - QString label; - label = QString::number(fDist, 'f', 2); - dc.DrawTextOn2DBox((p + m_vPos) * 0.5f, label.toUtf8().data(), fTextSize, col, ColorF(0.0f, 0.0f, 0.0f, 0.7f)); - - Vec3 vUp = (m_matrix * vUpAxis - m_vPos); - vUp.Normalize(); - - Vec3 u = vUp; - Vec3 v = vDir ^ vUp; - float fPlaneSize = fDist / 4.0f; - float alphaMax = 1.0f, alphaMin = 0.0f; - ColorF colAlphaMin = ColorF(col.x, col.y, col.z, alphaMin); - - float fStepSize = dc.view->GetGridStep(); - const int MIN_STEP_COUNT = 5; - const int MAX_STEP_COUNT = 20; - int nSteps = std::min(std::max(FloatToIntRet(fPlaneSize / fStepSize), MIN_STEP_COUNT), MAX_STEP_COUNT); - float fGridSize = nSteps * fStepSize; - - for (int i = -nSteps; i <= nSteps; ++i) - { - Vec3 stepV = v * (fStepSize * i); - Vec3 stepU = u * (fStepSize * i); - ColorF colCurAlpha = ColorF(col.x, col.y, col.z, alphaMax - fabsf(float(i) / float(nSteps)) * (alphaMax - alphaMin)); - // Draw u lines. - dc.DrawLine(p + stepV, p + u * fGridSize + stepV, colCurAlpha, colAlphaMin); - dc.DrawLine(p + stepV, p - u * fGridSize + stepV, colCurAlpha, colAlphaMin); - // Draw v lines. - dc.DrawLine(p + stepU, p + v * fGridSize + stepU, colCurAlpha, colAlphaMin); - dc.DrawLine(p + stepU, p - v * fGridSize + stepU, colCurAlpha, colAlphaMin); - } - } -} diff --git a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.h b/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.h deleted file mode 100644 index 42a1c66b9c..0000000000 --- a/Code/Sandbox/Editor/RenderHelpers/AxisHelperExtended.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_RENDERHELPERS_AXISHELPEREXTENDED_H -#define CRYINCLUDE_EDITOR_RENDERHELPERS_AXISHELPEREXTENDED_H -#pragma once - -#include "Objects/BaseObject.h" -#include "Include/IObjectManager.h" - -struct DisplayContext; -struct HitContext; - -class CAxisHelperExtended -{ -public: - CAxisHelperExtended(); - void DrawAxes(DisplayContext& dc, const Matrix34& matrix, bool bUsePhysicalProxy); - -private: - void DrawAxis(DisplayContext& dc, const Vec3& vDirAxis, const Vec3& vUpAxis, const Vec3& col, bool bUsePhysicalProxy); - -private: - Matrix34 m_matrix; - Vec3 m_vPos; - std::vector m_objects; - CBaseObjectsArray m_objectsForPicker; - CBaseObject* m_pCurObject; - DWORD m_dwLastUpdateTime; - - float m_fMaxDist; -}; - -#endif // CRYINCLUDE_EDITOR_RENDERHELPERS_AXISHELPEREXTENDED_H diff --git a/Code/Sandbox/Editor/RenderViewport.cpp b/Code/Sandbox/Editor/RenderViewport.cpp index cac1840b75..49064b5bc5 100644 --- a/Code/Sandbox/Editor/RenderViewport.cpp +++ b/Code/Sandbox/Editor/RenderViewport.cpp @@ -42,7 +42,6 @@ # include #endif // defined(AZ_PLATFORM_WINDOWS) #include // for AzFramework::InputDeviceMouse -#include // AzQtComponents #include @@ -56,7 +55,6 @@ // CryCommon -#include #include // AzFramework @@ -90,6 +88,10 @@ #include +#include +#include +#include + AZ_CVAR( bool, ed_visibility_use, true, nullptr, AZ::ConsoleFunctorFlags::Null, "Enable/disable using the new IVisibilitySystem for Entity visibility determination"); @@ -250,10 +252,6 @@ CRenderViewport::~CRenderViewport() ////////////////////////////////////////////////////////////////////////// int CRenderViewport::OnCreate() { - m_renderer = GetIEditor()->GetRenderer(); - m_engine = GetIEditor()->Get3DEngine(); - assert(m_engine); - CreateRenderContext(); return 0; @@ -275,13 +273,10 @@ void CRenderViewport::resizeEvent(QResizeEvent* event) gEnv->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RESIZE, width(), height()); - if (AZ::Interface::Get()) - { - // We queue the window resize event because the render overlay may be hidden. - // If the render overlay is not visible, the native window that is backing it will - // also be hidden, and it will not resize until it becomes visible. - m_windowResizedEvent = true; - } + // We queue the window resize event because the render overlay may be hidden. + // If the render overlay is not visible, the native window that is backing it will + // also be hidden, and it will not resize until it becomes visible. + m_windowResizedEvent = true; } ////////////////////////////////////////////////////////////////////////// @@ -1037,7 +1032,7 @@ void CRenderViewport::Update() return; } - if (!m_renderer || !m_engine || m_rcClient.isEmpty() || GetIEditor()->IsInMatEditMode()) + if (!m_renderer || m_rcClient.isEmpty() || GetIEditor()->IsInMatEditMode()) { return; } @@ -1105,7 +1100,7 @@ void CRenderViewport::Update() AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus; AzFramework::DebugDisplayRequestBus::Bind( - debugDisplayBus, AzToolsFramework::ViewportInteraction::g_mainViewportEntityDebugDisplayId); + debugDisplayBus, AzFramework::g_defaultSceneEntityDebugDisplayId); AZ_Assert(debugDisplayBus, "Invalid DebugDisplayRequestBus."); AzFramework::DebugDisplayRequests* debugDisplay = @@ -1160,9 +1155,6 @@ void CRenderViewport::Update() m_renderer->SetClearColor(Vec3(0.4f, 0.4f, 0.4f)); - // 3D engine stats - GetIEditor()->GetSystem()->RenderBegin(); - InitDisplayContext(); OnRender(); @@ -1188,8 +1180,6 @@ void CRenderViewport::Update() } } - GetIEditor()->GetSystem()->RenderEnd(m_bRenderStats); - gEnv->pSystem->SetViewCamera(CurCamera); } @@ -1425,8 +1415,6 @@ void CRenderViewport::OnRender() // This is necessary so that automated editor tests using the null renderer to test systems like dynamic vegetation // are still able to manipulate the current logical camera position, even if nothing is rendered. GetIEditor()->GetSystem()->SetViewCamera(m_Camera); - GetIEditor()->GetRenderer()->SetCamera(gEnv->pSystem->GetViewCamera()); - m_engine->RenderWorld(0, SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_Camera), __FUNCTION__); return; } @@ -1499,7 +1487,7 @@ void CRenderViewport::OnRender() } } - m_Camera.SetFrustum(w, h, fov, fNearZ, gEnv->p3DEngine->GetMaxViewDistance()); + m_Camera.SetFrustum(w, h, fov, fNearZ); } GetIEditor()->GetSystem()->SetViewCamera(m_Camera); @@ -1535,7 +1523,7 @@ void CRenderViewport::OnRender() AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus; AzFramework::DebugDisplayRequestBus::Bind( - debugDisplayBus, AzToolsFramework::ViewportInteraction::g_mainViewportEntityDebugDisplayId); + debugDisplayBus, AzFramework::g_defaultSceneEntityDebugDisplayId); AZ_Assert(debugDisplayBus, "Invalid DebugDisplayRequestBus."); AzFramework::DebugDisplayRequests* debugDisplay = @@ -1553,14 +1541,6 @@ void CRenderViewport::OnRender() if (levelIsDisplayable) { m_renderer->SetViewport(0, 0, m_renderer->GetWidth(), m_renderer->GetHeight(), m_nCurViewportID); - - if (!AZ::Interface::Get()) - { - m_engine->Tick(); - m_engine->Update(); - - m_engine->RenderWorld(SHDF_ALLOW_AO | SHDF_ALLOWPOSTPROCESS | SHDF_ALLOW_WATER | SHDF_ALLOWHDR | SHDF_ZPASS, SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_Camera), __FUNCTION__); - } } else { @@ -1568,11 +1548,6 @@ void CRenderViewport::OnRender() m_renderer->ClearTargetsLater(FRT_CLEAR_COLOR, viewportBackgroundColor); DrawBackground(); } - - if (!m_renderer->IsStereoEnabled()) - { - GetIEditor()->GetSystem()->RenderStatistics(); - } } ////////////////////////////////////////////////////////////////////////// @@ -1602,7 +1577,6 @@ void CRenderViewport::InitDisplayContext() displayContext.settings = GetIEditor()->GetDisplaySettings(); displayContext.view = this; displayContext.renderer = m_renderer; - displayContext.engine = m_engine; displayContext.box.min = Vec3(-100000.0f, -100000.0f, -100000.0f); displayContext.box.max = Vec3(100000.0f, 100000.0f, 100000.0f); displayContext.camera = &m_Camera; @@ -1681,7 +1655,7 @@ void CRenderViewport::RenderAll() AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus; AzFramework::DebugDisplayRequestBus::Bind( - debugDisplayBus, AzToolsFramework::ViewportInteraction::g_mainViewportEntityDebugDisplayId); + debugDisplayBus, AzFramework::g_defaultSceneEntityDebugDisplayId); AZ_Assert(debugDisplayBus, "Invalid DebugDisplayRequestBus."); AzFramework::DebugDisplayRequests* debugDisplay = @@ -2043,14 +2017,14 @@ float CRenderViewport::AngleStep() return GetViewManager()->GetGrid()->GetAngleSnap(); } -AZ::Vector3 CRenderViewport::PickTerrain(const QPoint& point) +AZ::Vector3 CRenderViewport::PickTerrain(const AzFramework::ScreenPoint& point) { FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); - return LYVec3ToAZVec3(ViewToWorld(point, nullptr, true)); + return LYVec3ToAZVec3(ViewToWorld(AzToolsFramework::ViewportInteraction::QPointFromScreenPoint(point), nullptr, true)); } -AZ::EntityId CRenderViewport::PickEntity(const QPoint& point) +AZ::EntityId CRenderViewport::PickEntity(const AzFramework::ScreenPoint& point) { FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); @@ -2059,7 +2033,7 @@ AZ::EntityId CRenderViewport::PickEntity(const QPoint& point) AZ::EntityId entityId; HitContext hitInfo; hitInfo.view = this; - if (HitTest(point, hitInfo)) + if (HitTest(AzToolsFramework::ViewportInteraction::QPointFromScreenPoint(point), hitInfo)) { if (hitInfo.object && (hitInfo.object->GetType() == OBJTYPE_AZENTITY)) { @@ -2100,12 +2074,13 @@ void CRenderViewport::FindVisibleEntities(AZStd::vector& visibleEn } } -QPoint CRenderViewport::ViewportWorldToScreen(const AZ::Vector3& worldPosition) +AzFramework::ScreenPoint CRenderViewport::ViewportWorldToScreen(const AZ::Vector3& worldPosition) { FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); PreWidgetRendering(); - const QPoint screenPosition = WorldToView(AZVec3ToLYVec3(worldPosition)); + const AzFramework::ScreenPoint screenPosition = + AzToolsFramework::ViewportInteraction::ScreenPointFromQPoint(WorldToView(AZVec3ToLYVec3(worldPosition))); PostWidgetRendering(); return screenPosition; @@ -2478,7 +2453,6 @@ void CRenderViewport::ToggleCameraObject() { if (m_viewSourceType == ViewSourceType::SequenceCamera) { - gEnv->p3DEngine->GetPostEffectBaseGroup()->SetParam("Dof_Active", 0.0f); ResetToViewSourceType(ViewSourceType::LegacyCamera); } else @@ -2800,11 +2774,6 @@ void CRenderViewport::SetViewTM(const Matrix34& viewTM, bool bMoveOnly) ////////////////////////////////////////////////////////////////////////// void CRenderViewport::RenderSelectedRegion() { - if (!m_engine) - { - return; - } - AABB box; GetIEditor()->GetSelectedRegion(box); if (box.IsEmpty()) @@ -3396,19 +3365,9 @@ bool CRenderViewport::AdjustObjectPosition(const ray_hit& hit, Vec3& outNormal, } ////////////////////////////////////////////////////////////////////////// -bool CRenderViewport::RayRenderMeshIntersection(IRenderMesh* pRenderMesh, const Vec3& vInPos, const Vec3& vInDir, Vec3& vOutPos, Vec3& vOutNormal) const +bool CRenderViewport::RayRenderMeshIntersection(IRenderMesh*, const Vec3&, const Vec3&, Vec3&, Vec3&) const { - SRayHitInfo hitInfo; - hitInfo.bUseCache = false; - hitInfo.bInFirstHit = false; - hitInfo.inRay.origin = vInPos; - hitInfo.inRay.direction = vInDir.GetNormalized(); - hitInfo.inReferencePoint = vInPos; - hitInfo.fMaxHitDistance = 0; - bool bRes = GetIEditor()->Get3DEngine()->RenderMeshRayIntersection(pRenderMesh, hitInfo, nullptr); - vOutPos = hitInfo.vHitPos; - vOutNormal = hitInfo.vHitNormal; - return bRes; + return false; } ////////////////////////////////////////////////////////////////////////// @@ -3659,11 +3618,8 @@ bool CRenderViewport::CreateRenderContext() { m_bRenderContextCreated = true; - if (AZ::Interface::Get()) - { - AzFramework::WindowRequestBus::Handler::BusConnect(renderOverlayHWND()); - AzFramework::WindowSystemNotificationBus::Broadcast(&AzFramework::WindowSystemNotificationBus::Handler::OnWindowCreated, renderOverlayHWND()); - } + AzFramework::WindowRequestBus::Handler::BusConnect(renderOverlayHWND()); + AzFramework::WindowSystemNotificationBus::Broadcast(&AzFramework::WindowSystemNotificationBus::Handler::OnWindowCreated, renderOverlayHWND()); WIN_HWND oldContext = m_renderer->GetCurrentContextHWND(); m_renderer->CreateContext(renderOverlayHWND()); @@ -3696,7 +3652,6 @@ void CRenderViewport::SetDefaultCamera() return; } ResetToViewSourceType(ViewSourceType::None); - gEnv->p3DEngine->GetPostEffectBaseGroup()->SetParam("Dof_Active", 0.0f); GetViewManager()->SetCameraObjectId(m_cameraObjectId); SetName(m_defaultViewName); SetViewTM(m_defaultViewTM); @@ -3875,23 +3830,8 @@ void CRenderViewport::SetViewAndMovementLockFromEntityPerspective(const AZ::Enti bool CRenderViewport::GetActiveCameraPosition(AZ::Vector3& cameraPos) { - if (m_pPrimaryViewport == this) - { - if (GetIEditor()->IsInGameMode()) - { - const Vec3 camPos = m_engine->GetRenderingCamera().GetPosition(); - cameraPos = LYVec3ToAZVec3(camPos); - } - else - { - // Use viewTM, which is synced with the camera and guaranteed to be up-to-date - cameraPos = LYVec3ToAZVec3(m_viewTM.GetTranslation()); - } - - return true; - } - - return false; + cameraPos = LYVec3ToAZVec3(m_viewTM.GetTranslation()); + return true; } bool CRenderViewport::GetActiveCameraState(AzFramework::CameraState& cameraState) @@ -3900,9 +3840,7 @@ bool CRenderViewport::GetActiveCameraState(AzFramework::CameraState& cameraState { if (GetIEditor()->IsInGameMode()) { - const auto& renderingCamera = m_engine->GetRenderingCamera(); - cameraState = CameraStateFromCCamera( - renderingCamera, renderingCamera.GetFov(), m_rcClient.width(), m_rcClient.height()); + return false; } else { @@ -3974,18 +3912,6 @@ void CRenderViewport::RenderConstructionPlane() Ang3 angles = Ang3(pGrid->rotationAngles.x * gf_PI / 180.0, pGrid->rotationAngles.y * gf_PI / 180.0, pGrid->rotationAngles.z * gf_PI / 180.0); Matrix34 tm = Matrix33::CreateRotationXYZ(angles); - if (gSettings.snap.bGridGetFromSelected) - { - CSelectionGroup* sel = GetIEditor()->GetSelection(); - if (sel->GetCount() > 0) - { - CBaseObject* obj = sel->GetObject(0); - tm = obj->GetWorldTM(); - tm.OrthonormalizeFast(); - tm.SetTranslation(Vec3(0, 0, 0)); - } - } - u = tm * u; v = tm * v; } @@ -4040,11 +3966,6 @@ void CRenderViewport::RenderConstructionPlane() void CRenderViewport::RenderSnappingGrid() { // First, Check whether we should draw the grid or not. - CSelectionGroup* pSelGroup = GetIEditor()->GetSelection(); - if (pSelGroup == nullptr || pSelGroup->GetCount() != 1) - { - return; - } CGrid* pGrid = GetViewManager()->GetGrid(); if (pGrid->IsEnabled() == false && pGrid->IsAngleSnapEnabled() == false) { diff --git a/Code/Sandbox/Editor/RenderViewport.h b/Code/Sandbox/Editor/RenderViewport.h index 2edbd86770..d70dd59b98 100644 --- a/Code/Sandbox/Editor/RenderViewport.h +++ b/Code/Sandbox/Editor/RenderViewport.h @@ -190,17 +190,24 @@ public: bool ShowGrid() override; bool AngleSnappingEnabled() override; float AngleStep() override; - QPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override; - AZStd::optional ViewportScreenToWorld(const QPoint&, float) override { return {}; } - AZStd::optional ViewportScreenToWorldRay(const QPoint&) override { return {}; } + AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override; + AZStd::optional ViewportScreenToWorld(const AzFramework::ScreenPoint&, float) override + { + return {}; + } + AZStd::optional ViewportScreenToWorldRay( + const AzFramework::ScreenPoint&) override + { + return {}; + } // AzToolsFramework::ViewportFreezeRequestBus bool IsViewportInputFrozen() override; void FreezeViewportInput(bool freeze) override; // AzToolsFramework::MainEditorViewportInteractionRequestBus - AZ::EntityId PickEntity(const QPoint& point) override; - AZ::Vector3 PickTerrain(const QPoint& point) override; + AZ::EntityId PickEntity(const AzFramework::ScreenPoint& point) override; + AZ::Vector3 PickTerrain(const AzFramework::ScreenPoint& point) override; float TerrainHeight(const AZ::Vector2& position) override; void FindVisibleEntities(AZStd::vector& visibleEntitiesOut) override; bool ShowingWorldSpace() override; @@ -431,7 +438,6 @@ protected: //! Assigned renderer. IRenderer* m_renderer = nullptr; - I3DEngine* m_engine = nullptr; bool m_bRenderContextCreated = false; bool m_bInRotateMode = false; bool m_bInMoveMode = false; @@ -518,10 +524,6 @@ protected: OBB m_GroundOBB; Vec3 m_GroundOBBPos; - //------------------------------------------- - // Render options. - bool m_bRenderStats = true; - // Index of camera objects. mutable GUID m_cameraObjectId = GUID_NULL; mutable AZ::EntityId m_viewEntityId; diff --git a/Code/Sandbox/Editor/Resource.h b/Code/Sandbox/Editor/Resource.h index 78a9855d71..ea8ec828cf 100644 --- a/Code/Sandbox/Editor/Resource.h +++ b/Code/Sandbox/Editor/Resource.h @@ -75,7 +75,6 @@ #define IDC_PLATFORM_SALEM 2759 #define IDC_GROUPBOX_GLOBALTAGS 2916 #define IDC_GROUPBOX_FRAGMENTTAGS 2917 -#define ID_RESOURCES_GENERATECGFTHUMBNAILS 32894 #define ID_RESOURCES_REDUCEWORKINGSET 32896 #define ID_EDIT_HIDE 32898 #define ID_EDIT_UNHIDEALL 32899 @@ -91,13 +90,9 @@ #define ID_EXPORT_INDOORS 32915 #define ID_VIEW_CYCLE2DVIEWPORT 32916 #define ID_SNAPANGLE 32917 -#define ID_EDIT_RENAMEOBJECT 32925 #define ID_CHANGEMOVESPEED_INCREASE 32928 #define ID_CHANGEMOVESPEED_DECREASE 32929 #define ID_CHANGEMOVESPEED_CHANGESTEP 32930 -#define ID_MATERIAL_ASSIGNCURRENT 32933 -#define ID_MATERIAL_RESETTODEFAULT 32934 -#define ID_MATERIAL_GETMATERIAL 32935 #define ID_PHYSICS_GETPHYSICSSTATE 32937 #define ID_PHYSICS_RESETPHYSICSSTATE 32938 #define ID_GAME_SYNCPLAYER 32941 @@ -137,7 +132,6 @@ #define ID_FILE_EDITEDITORINI 33543 #define ID_FILE_EDITLOGFILE 33544 #define ID_PREFERENCES 33546 -#define ID_RELOAD_GEOMETRY 33549 #define ID_REDO 33550 #define ID_SWITCH_PHYSICS 33555 #define ID_REF_COORDS_SYS 33556 diff --git a/Code/Sandbox/Editor/Settings.cpp b/Code/Sandbox/Editor/Settings.cpp index 99a801eedc..15d3e793a5 100644 --- a/Code/Sandbox/Editor/Settings.cpp +++ b/Code/Sandbox/Editor/Settings.cpp @@ -252,8 +252,6 @@ SEditorSettings::SEditorSettings() gui.hSystemFontBold = QFont("Ms Shell Dlg 2", lfHeight, QFont::Bold); gui.hSystemFontItalic = QFont("Ms Shell Dlg 2", lfHeight, QFont::Normal, true); - bForceSkyUpdate = true; - backgroundUpdatePeriod = 0; g_TemporaryLevelName = nullptr; @@ -647,8 +645,6 @@ void SEditorSettings::Save() SaveValue("Settings\\ObjectColors", "GeometryAlpha", objectColorSettings.fGeomAlpha); SaveValue("Settings\\ObjectColors", "ChildGeometryAlpha", objectColorSettings.fChildGeomAlpha); - SaveValue("Settings", "ForceSkyUpdate", gSettings.bForceSkyUpdate); - ////////////////////////////////////////////////////////////////////////// // Smart file open settings ////////////////////////////////////////////////////////////////////////// @@ -873,8 +869,6 @@ void SEditorSettings::Load() LoadValue("Settings\\ObjectColors", "GeometryAlpha", objectColorSettings.fGeomAlpha); LoadValue("Settings\\ObjectColors", "ChildGeometryAlpha", objectColorSettings.fChildGeomAlpha); - LoadValue("Settings", "ForceSkyUpdate", gSettings.bForceSkyUpdate); - ////////////////////////////////////////////////////////////////////////// // Smart file open settings ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/Settings.h b/Code/Sandbox/Editor/Settings.h index 511bbb9bbe..93e61bc1ed 100644 --- a/Code/Sandbox/Editor/Settings.h +++ b/Code/Sandbox/Editor/Settings.h @@ -467,8 +467,6 @@ AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING bool bSettingsManagerMode; - bool bForceSkyUpdate; - bool bAutoSaveTagPoints; bool bNavigationContinuousUpdate; diff --git a/Code/Sandbox/Editor/Style/resources.qrc b/Code/Sandbox/Editor/Style/resources.qrc index aa32f29555..aec7e2cf68 100644 --- a/Code/Sandbox/Editor/Style/resources.qrc +++ b/Code/Sandbox/Editor/Style/resources.qrc @@ -4,6 +4,5 @@ EditorPreferencesDialog.qss LayoutConfigDialog.qss GraphicsSettingsDialog.qss - LensFlareEditor.qss diff --git a/Code/Sandbox/Editor/SurfaceInfoPicker.cpp b/Code/Sandbox/Editor/SurfaceInfoPicker.cpp deleted file mode 100644 index f3d06e0017..0000000000 --- a/Code/Sandbox/Editor/SurfaceInfoPicker.cpp +++ /dev/null @@ -1,561 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "SurfaceInfoPicker.h" - -// AzToolsFramework -#include - -// Editor -#include "Material/MaterialManager.h" -#include "Objects/EntityObject.h" -#include "Viewport.h" -#include "QtViewPane.h" - -// ComponentEntityEditorPlugin -#include "Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h" - -// LmbrCentral -#include -#include - - -static const float kEnoughFarDistance(5000.0f); - -CSurfaceInfoPicker::CSurfaceInfoPicker() - : m_pObjects(NULL) - , m_pSetObjects(NULL) - , m_PickOption(0) -{ - m_pActiveView = GetIEditor()->GetActiveView(); -} - -bool CSurfaceInfoPicker::PickByAABB(const QPoint& point, [[maybe_unused]] int nFlag, IDisplayViewport* pView, CExcludedObjects* pExcludedObjects, std::vector* pOutObjects) -{ - GetIEditor()->GetObjectManager()->GetObjects(m_objects); - - Vec3 vWorldRaySrc, vWorldRayDir; - m_pActiveView->ViewToWorldRay(point, vWorldRaySrc, vWorldRayDir); - vWorldRaySrc = vWorldRaySrc + vWorldRayDir * 0.1f; - vWorldRayDir = vWorldRayDir * kEnoughFarDistance; - - bool bPicked = false; - - for (int i = 0, iCount(m_objects.size()); i < iCount; ++i) - { - if (pExcludedObjects && pExcludedObjects->Contains(m_objects[i])) - { - continue; - } - - AABB worldObjAABB; - m_objects[i]->GetBoundBox(worldObjAABB); - - if (pView) - { - float fScreenFactor = pView->GetScreenScaleFactor(m_objects[i]->GetPos()); - worldObjAABB.Expand(0.01f * Vec3(fScreenFactor, fScreenFactor, fScreenFactor)); - } - - Vec3 vHitPos; - if (Intersect::Ray_AABB(vWorldRaySrc, vWorldRayDir, worldObjAABB, vHitPos)) - { - if ((vHitPos - vWorldRaySrc).GetNormalized().Dot(vWorldRayDir) > 0 || worldObjAABB.IsContainPoint(vHitPos)) - { - if (pOutObjects) - { - pOutObjects->push_back(m_objects[i]); - } - bPicked = true; - } - } - } - - return bPicked; -} - -bool CSurfaceInfoPicker::PickImpl(const QPoint& point, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects, - int nFlag) -{ - Vec3 vWorldRaySrc; - Vec3 vWorldRayDir; - if (!m_pActiveView) - { - m_pActiveView = GetIEditor()->GetActiveView(); - } - m_pActiveView->ViewToWorldRay(point, vWorldRaySrc, vWorldRayDir); - vWorldRaySrc = vWorldRaySrc + vWorldRayDir * 0.1f; - vWorldRayDir = vWorldRayDir * kEnoughFarDistance; - - return PickImpl(vWorldRaySrc, vWorldRayDir, ppOutLastMaterial, outHitInfo, pExcludedObjects, nFlag); -} - -bool CSurfaceInfoPicker::PickImpl(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects, - int nFlag) -{ - memset(&outHitInfo, 0, sizeof(outHitInfo)); - outHitInfo.fDistance = kEnoughFarDistance; - - if (m_pSetObjects) - { - m_pObjects = m_pSetObjects; - } - else - { - GetIEditor()->GetObjectManager()->GetObjects(m_objects); - m_pObjects = &m_objects; - } - - if (pExcludedObjects) - { - m_ExcludedObjects = *pExcludedObjects; - } - else - { - m_ExcludedObjects.Clear(); - } - - m_pPickedObject = NULL; - - if (nFlag & ePOG_Entity) - { - FindNearestInfoFromEntities(vWorldRaySrc, vWorldRayDir, ppOutLastMaterial, outHitInfo); - } - - if (!m_pSetObjects) - { - m_objects.clear(); - } - - m_ExcludedObjects.Clear(); - - return outHitInfo.fDistance < kEnoughFarDistance; -} - -void CSurfaceInfoPicker::FindNearestInfoFromEntities( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - _smart_ptr* pOutLastMaterial, - SRayHitInfo& outHitInfo) const -{ - for (size_t i = 0; i < m_pObjects->size(); ++i) - { - CBaseObject* object((*m_pObjects)[i]); - - if (object == nullptr - || !qobject_cast(object) - || object->IsHidden() - || IsFrozen(object) - || m_ExcludedObjects.Contains(object) - ) - { - continue; - } - - CEntityObject* entityObject = static_cast(object); - - // If a legacy entity doesn't have a material override, we'll get the default material for that statObj - _smart_ptr statObjDefaultMaterial = nullptr; - // And in some cases the material we want does comes from RayIntersection(), and we will skip AssignObjectMaterial(). - _smart_ptr pickedMaterial = nullptr; - - bool hit = false; - - // entityObject is a component entity... - if (entityObject->GetType() == OBJTYPE_AZENTITY) - { - AZ::EntityId id; - AzToolsFramework::ComponentEntityObjectRequestBus::EventResult(id, entityObject, &AzToolsFramework::ComponentEntityObjectRequestBus::Events::GetAssociatedEntityId); - - AZ::EBusAggregateResults statObjs; - LmbrCentral::LegacyMeshComponentRequestBus::EventResult(statObjs, id, &LmbrCentral::LegacyMeshComponentRequestBus::Events::GetStatObj); - - // If the entity has a MeshComponent, it will hit here - for (IStatObj* statObj : statObjs.values) - { - hit = RayIntersection(vWorldRaySrc, vWorldRayDir, nullptr, statObj, object->GetWorldTM(), outHitInfo, &statObjDefaultMaterial); - if (hit) - { - break; - } - } - - // If the entity has an ActorComponent or another component that overrides RenderNodeRequestBus, it will hit here - if (!hit) - { - // There might be multiple components with render nodes on the same entity - // This will get the highest priority one, as determined by RenderNodeRequests::GetRenderNodeRequestBusOrder - IRenderNode* renderNode = entityObject->GetEngineNode(); - - // If the renderNode exists and is physicalized, it will hit here - hit = RayIntersection_IRenderNode(vWorldRaySrc, vWorldRayDir, renderNode, &pickedMaterial, object->GetWorldTM(), outHitInfo); - if (!hit) - { - // If the renderNode is not physicalized, such as an actor component, but still exists and has a valid material we might want to pick - if (renderNode && renderNode->GetMaterial()) - { - // Do a hit test with anything in this entity that has overridden EditorComponentSelectionRequestsBus - CComponentEntityObject* componentEntityObject = static_cast(entityObject); - HitContext hc; - hc.raySrc = vWorldRaySrc; - hc.rayDir = vWorldRayDir; - bool intersects = componentEntityObject->HitTest(hc); - - if (intersects) - { - // If the distance is closer than the nearest distance so far - if (hc.dist < outHitInfo.fDistance) - { - hit = true; - outHitInfo.vHitPos = hc.raySrc + hc.rayDir * hc.dist; - outHitInfo.fDistance = hc.dist; - // We don't get material/sub-material information back from HitTest, so just use the material from the render node - pickedMaterial = renderNode->GetMaterial(); - outHitInfo.nHitMatID = 0; - // We don't get normal information back from HitTest, so just orient the selection disk towards the camera - outHitInfo.vHitNormal = vWorldRayDir.normalized(); - } - } - } - } - } - - // If the entity has a GeometryCacheComponent it will hit here - if (!hit) - { - IGeomCacheRenderNode* geomCacheRenderNode = nullptr; - LmbrCentral::GeometryCacheComponentRequestBus::EventResult(geomCacheRenderNode, id, &LmbrCentral::GeometryCacheComponentRequestBus::Events::GetGeomCacheRenderNode); - hit = RayIntersection_IGeomCacheRenderNode(vWorldRaySrc, vWorldRayDir, geomCacheRenderNode, &pickedMaterial, object->GetWorldTM(), outHitInfo); - } - } - - if (hit) - { - if(pickedMaterial) - { - AssignMaterial(pickedMaterial, outHitInfo, pOutLastMaterial); - } - else - { - if (object->GetMaterial()) - { - // If the entity has a material override, assign the object material - AssignObjectMaterial(object, outHitInfo, pOutLastMaterial); - } - else - { - // Otherwise assign the default material for that object - AssignMaterial(statObjDefaultMaterial, outHitInfo, pOutLastMaterial); - } - } - - m_pPickedObject = object; - } - } -} - -bool CSurfaceInfoPicker::RayIntersection_CBaseObject( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - CBaseObject* pBaseObject, - _smart_ptr* pOutLastMaterial, - SRayHitInfo& outHitInfo) -{ - if (pBaseObject == NULL) - { - return false; - } - IRenderNode* pRenderNode(pBaseObject->GetEngineNode()); - if (pRenderNode == NULL) - { - return false; - } - IStatObj* pStatObj(pRenderNode->GetEntityStatObj()); - if (pStatObj == NULL) - { - return false; - } - return RayIntersection(vWorldRaySrc, vWorldRayDir, pRenderNode, pStatObj, pBaseObject->GetWorldTM(), outHitInfo, pOutLastMaterial); -} - -bool CSurfaceInfoPicker::RayIntersection( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - IStatObj* pStatObj, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo, - _smart_ptr* ppOutLastMaterial) -{ - SRayHitInfo hitInfo; - bool bRayIntersection = false; - _smart_ptr pMaterial(NULL); - - bRayIntersection = RayIntersection_IStatObj(vWorldRaySrc, vWorldRayDir, pStatObj, &pMaterial, WorldTM, hitInfo); - if (!bRayIntersection) - { - bRayIntersection = RayIntersection_IRenderNode(vWorldRaySrc, vWorldRayDir, pRenderNode, &pMaterial, WorldTM, hitInfo); - } - - if (bRayIntersection) - { - hitInfo.fDistance = vWorldRaySrc.GetDistance(hitInfo.vHitPos); - if (hitInfo.fDistance < outHitInfo.fDistance) - { - if (ppOutLastMaterial) - { - *ppOutLastMaterial = pMaterial; - } - memcpy(&outHitInfo, &hitInfo, sizeof(SRayHitInfo)); - outHitInfo.vHitNormal.Normalize(); - return true; - } - } - return false; -} - -bool CSurfaceInfoPicker::RayIntersection_IStatObj( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IStatObj* pStatObj, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& worldTM, - SRayHitInfo& outHitInfo) -{ - if (pStatObj == NULL) - { - return false; - } - - Vec3 localRaySrc; - Vec3 localRayDir; - if (!RayWorldToLocal(worldTM, vWorldRaySrc, vWorldRayDir, localRaySrc, localRayDir)) - { - return false; - } - - // the outHitInfo contains information about the previous closest hit and should not be cleared / replaced unless you have a better hit! - // all of the intersection functions called (such as statobj's RayIntersection) only modify the hit info if it actually hits it closer than the current distance of the last hit. - - outHitInfo.inReferencePoint = localRaySrc; - outHitInfo.inRay = Ray(localRaySrc, localRayDir); - outHitInfo.bInFirstHit = false; - outHitInfo.bUseCache = false; - - _smart_ptr hitMaterial = nullptr; - - Vec3 hitPosOnAABB; - if (Intersect::Ray_AABB(outHitInfo.inRay, pStatObj->GetAABB(), hitPosOnAABB) == 0x00) - { - return false; - } - - if (pStatObj->RayIntersection(outHitInfo)) - { - if (outHitInfo.fDistance < 0) - { - return false; - } - outHitInfo.vHitPos = worldTM.TransformPoint(outHitInfo.vHitPos); - outHitInfo.vHitNormal = worldTM.GetTransposed().GetInverted().TransformVector(outHitInfo.vHitNormal); - - // we need to set nHitSurfaceID anyway - so we need to do this regardless of whether the caller - // has asked for detailed material info by passing in a non-null ppOutLastMaterial - hitMaterial = pStatObj->GetMaterial(); - - if (hitMaterial) - { - if (outHitInfo.nHitMatID >= 0) - { - if (hitMaterial->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < hitMaterial->GetSubMtlCount()) - { - _smart_ptr subMaterial = hitMaterial->GetSubMtl(outHitInfo.nHitMatID); - if (subMaterial) - { - hitMaterial = subMaterial; - } - } - } - outHitInfo.nHitSurfaceID = hitMaterial->GetSurfaceTypeId(); - } - - if ((ppOutLastMaterial) && (hitMaterial)) - { - *ppOutLastMaterial = hitMaterial; - } - - return true; - } - - return outHitInfo.fDistance < kEnoughFarDistance; -} - -#if defined(USE_GEOM_CACHES) -bool CSurfaceInfoPicker::RayIntersection_IGeomCacheRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IGeomCacheRenderNode* pGeomCacheRenderNode, - _smart_ptr* ppOutLastMaterial, - [[maybe_unused]] const Matrix34A& worldTM, - SRayHitInfo& outHitInfo) -{ - if (!pGeomCacheRenderNode) - { - return false; - } - - SRayHitInfo newHitInfo = outHitInfo; - newHitInfo.inReferencePoint = vWorldRaySrc; - newHitInfo.inRay = Ray(vWorldRaySrc, vWorldRayDir); - newHitInfo.bInFirstHit = false; - newHitInfo.bUseCache = false; - - if (pGeomCacheRenderNode->RayIntersection(newHitInfo)) - { - if (newHitInfo.fDistance < 0 || newHitInfo.fDistance > kEnoughFarDistance || (outHitInfo.fDistance != 0 && newHitInfo.fDistance > outHitInfo.fDistance)) - { - return false; - } - - // Only override outHitInfo if the new hit is closer than the original hit - outHitInfo = newHitInfo; - if (ppOutLastMaterial) - { - _smart_ptr pMaterial = pGeomCacheRenderNode->GetMaterial(); - if (pMaterial) - { - *ppOutLastMaterial = pMaterial; - if (outHitInfo.nHitMatID >= 0) - { - if (pMaterial->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < pMaterial->GetSubMtlCount()) - { - *ppOutLastMaterial = pMaterial->GetSubMtl(outHitInfo.nHitMatID); - } - } - } - } - return true; - } - - return false; -} -#endif - -bool CSurfaceInfoPicker::RayIntersection_IRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - _smart_ptr* pOutLastMaterial, - [[maybe_unused]] const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo) -{ - if (pRenderNode == NULL) - { - return false; - } - - AZ_UNUSED(vWorldRaySrc) - AZ_UNUSED(vWorldRayDir) - AZ_UNUSED(pRenderNode) - AZ_UNUSED(pOutLastMaterial) - AZ_UNUSED(WorldTM) - AZ_UNUSED(outHitInfo) - return false; -} - -bool CSurfaceInfoPicker::RayWorldToLocal( - const Matrix34A& WorldTM, - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - Vec3& outRaySrc, - Vec3& outRayDir) -{ - if (!WorldTM.IsValid()) - { - return false; - } - Matrix34A invertedM(WorldTM.GetInverted()); - if (!invertedM.IsValid()) - { - return false; - } - outRaySrc = invertedM.TransformPoint(vWorldRaySrc); - outRayDir = invertedM.TransformVector(vWorldRayDir).GetNormalized(); - return true; -} - -bool CSurfaceInfoPicker::IsMaterialValid(CMaterial* pMaterial) -{ - if (pMaterial == NULL) - { - return false; - } - return !(pMaterial->GetMatInfo()->GetFlags() & MTL_FLAG_NODRAW); -} - -void CSurfaceInfoPicker::AssignObjectMaterial(CBaseObject* pObject, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial) -{ - CMaterial* material = pObject->GetMaterial(); - if (material) - { - if (material->GetMatInfo()) - { - if (pOutMaterial) - { - *pOutMaterial = material->GetMatInfo(); - if (*pOutMaterial) - { - if (outHitInfo.nHitMatID >= 0 && (*pOutMaterial)->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < (*pOutMaterial)->GetSubMtlCount()) - { - *pOutMaterial = (*pOutMaterial)->GetSubMtl(outHitInfo.nHitMatID); - } - } - } - } - } -} - -void CSurfaceInfoPicker::AssignMaterial(_smart_ptr pMaterial, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial) -{ - if (pOutMaterial) - { - *pOutMaterial = pMaterial; - if (*pOutMaterial) - { - if (outHitInfo.nHitMatID >= 0 && (*pOutMaterial)->GetSubMtlCount() > 0 && outHitInfo.nHitMatID < (*pOutMaterial)->GetSubMtlCount()) - { - *pOutMaterial = (*pOutMaterial)->GetSubMtl(outHitInfo.nHitMatID); - } - } - } -} - -void CSurfaceInfoPicker::SetActiveView(IDisplayViewport* view) -{ - if (view) - { - m_pActiveView = view; - } - else - { - m_pActiveView = GetIEditor()->GetActiveView(); - } -} diff --git a/Code/Sandbox/Editor/SurfaceInfoPicker.h b/Code/Sandbox/Editor/SurfaceInfoPicker.h deleted file mode 100644 index 110408d558..0000000000 --- a/Code/Sandbox/Editor/SurfaceInfoPicker.h +++ /dev/null @@ -1,220 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_SURFACEINFOPICKER_H -#define CRYINCLUDE_EDITOR_SURFACEINFOPICKER_H - -#pragma once - -#include "Include/IObjectManager.h" -#include "Objects/BaseObject.h" - -class CKDTree; -struct IDisplayViewport; - -////////////////////////////////////////////////////////////////////////// -class SANDBOX_API CSurfaceInfoPicker -{ -public: - - CSurfaceInfoPicker(); - - class CExcludedObjects - { - public: - - CExcludedObjects(){} - ~CExcludedObjects(){} - CExcludedObjects(const CExcludedObjects& excluded) - { - objects = excluded.objects; - } - - void Add(CBaseObject* pObject) - { - objects.insert(pObject); - } - - void Clear() - { - objects.clear(); - } - - bool Contains(CBaseObject* pObject) const - { - return objects.find(pObject) != objects.end(); - } - - private: - std::set objects; - }; - - enum EPickedObjectGroup - { - ePOG_Entity = BIT(1), - ePOG_All = ePOG_Entity, - }; - - enum EPickOption - { - ePickOption_IncludeFrozenObject = BIT(0), - }; - - void SetPickOptionFlag(int nFlag) { m_PickOption = nFlag; } - -public: - - bool Pick(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - _smart_ptr& ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(vWorldRaySrc, vWorldRayDir, &ppOutLastMaterial, outHitInfo, pExcludedObjects, nFlag); - } - - bool Pick(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(vWorldRaySrc, vWorldRayDir, NULL, outHitInfo, pExcludedObjects, nFlag); - } - - bool Pick(const QPoint& point, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(point, NULL, outHitInfo, pExcludedObjects, nFlag); - } - - bool Pick(const QPoint& point, - _smart_ptr& ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All) - { - return PickImpl(point, &ppOutLastMaterial, outHitInfo, pExcludedObjects, nFlag); - } - - bool PickByAABB(const QPoint& point, int nFlag = ePOG_All, IDisplayViewport* pView = NULL, CExcludedObjects* pExcludedObjects = NULL, std::vector* pOutObjects = NULL); - - void SetObjects(CBaseObjectsArray* pSetObjects) { m_pSetObjects = pSetObjects; } - - CBaseObjectPtr GetPickedObject() - { - return m_pPickedObject; - } - - void SetActiveView(IDisplayViewport* view); - -public: - - static bool RayWorldToLocal( - const Matrix34A& WorldTM, - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - Vec3& outRaySrc, - Vec3& outRayDir); - -private: - - bool IsFrozen(CBaseObject* pBaseObject) const - { - return !(m_PickOption & ePickOption_IncludeFrozenObject) && pBaseObject->IsFrozen(); - } - - bool PickImpl(const QPoint& point, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All); - - bool PickImpl(const Vec3& vWorldRaySrc, const Vec3& vWorldRayDir, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo, - CExcludedObjects* pExcludedObjects = NULL, - int nFlag = ePOG_All); - - void FindNearestInfoFromEntities( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo) const; - - /// Detect ray intersection with a IRenderNode or IStatObj. - /// But only if the intersection is closer than the one already in outHitInfo. - static bool RayIntersection( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - IStatObj* pStatObj, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo, - _smart_ptr* ppOutLastMaterial); - - /// Detect ray intersection with a IStatObj - static bool RayIntersection_IStatObj( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IStatObj* pStatObj, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo); - - /// Detect ray intersection with a IGeomCacheRenderNode - static bool RayIntersection_IGeomCacheRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IGeomCacheRenderNode* pGeomCacheRenderNode, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& worldTM, - SRayHitInfo& outHitInfo); - - /// Detect ray intersection with a IRenderNode - static bool RayIntersection_IRenderNode( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - IRenderNode* pRenderNode, - _smart_ptr* ppOutLastMaterial, - const Matrix34A& WorldTM, - SRayHitInfo& outHitInfo); - - /// Detect ray intersection with a CBaseObject - static bool RayIntersection_CBaseObject( - const Vec3& vWorldRaySrc, - const Vec3& vWorldRayDir, - CBaseObject* pBaseObject, - _smart_ptr* ppOutLastMaterial, - SRayHitInfo& outHitInfo); - - static void AssignObjectMaterial(CBaseObject* pObject, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial); - static void AssignMaterial(_smart_ptr pObject, const SRayHitInfo& outHitInfo, _smart_ptr* pOutMaterial); - static bool IsMaterialValid(CMaterial* pMaterial); - -private: - - int m_PickOption; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - CBaseObjectsArray* m_pObjects; - CBaseObjectsArray* m_pSetObjects; - CBaseObjectsArray m_objects; - IDisplayViewport* m_pActiveView; - CExcludedObjects m_ExcludedObjects; - mutable CBaseObjectPtr m_pPickedObject; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -#endif // CRYINCLUDE_EDITOR_SURFACEINFOPICKER_H diff --git a/Code/Sandbox/Editor/SurfaceTypeValidator.cpp b/Code/Sandbox/Editor/SurfaceTypeValidator.cpp index 68bbdcf3bb..9aec070912 100644 --- a/Code/Sandbox/Editor/SurfaceTypeValidator.cpp +++ b/Code/Sandbox/Editor/SurfaceTypeValidator.cpp @@ -16,7 +16,6 @@ #include "SurfaceTypeValidator.h" // Editor -#include "Material/Material.h" #include "Include/IObjectManager.h" #include "Objects/BaseObject.h" #include "ErrorReport.h" diff --git a/Code/Sandbox/Editor/ThumbnailGenerator.cpp b/Code/Sandbox/Editor/ThumbnailGenerator.cpp deleted file mode 100644 index c2f03a1944..0000000000 --- a/Code/Sandbox/Editor/ThumbnailGenerator.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "ThumbnailGenerator.h" - -// Editor -#include "Util/Image.h" -#include "Util/ImageUtil.h" // for CUmageUtil -#include "WaitProgress.h" // for CWaitProgress - -#if defined(AZ_PLATFORM_MAC) || defined(AZ_PLATFORM_LINUX) -#include -#include -#endif - - - -CThumbnailGenerator::CThumbnailGenerator(void) -{ -} - -CThumbnailGenerator::~CThumbnailGenerator(void) -{ -} - -// Get directory contents. -static bool scan_directory(const QString& root, const QString& path, const QString& file, QStringList& files, bool recursive) -{ - QString fullPath = root + path + file; - QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags; - if (recursive) - { - flags = QDirIterator::Subdirectories; - } - QDirIterator dirIterator(fullPath, {file}, QDir::Files, flags); - if (!dirIterator.hasNext()) - { - return false; - } - else - { - // Find the rest of the .c files. - while (dirIterator.hasNext()) - { - files.push_back(dirIterator.next()); - //FileInfo fi; - //fi.attrib = c_file.attrib; - //fi.name = path + c_file.name; - /* - // Add . after file name without extension. - if (fi.name.find('.') == CString::npos) { - fi.name.append( "." ); - } - */ - //fi.size = c_file.size; - //fi.time = c_file.time_write; - //files.push_back( fi ); - } - } - return true; -} - -#if defined(AZ_PLATFORM_WINDOWS) -#define FileTimeType FILETIME - -inline void GetThumbFileTime(const char* fileName, FILETIME& time) -{ - HANDLE hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (INVALID_HANDLE_VALUE != hFile) - { - GetFileTime(hFile, NULL, NULL, &time); - CloseHandle(hFile); - } -} - -inline void SetThumbFileTime(const char* fileName, FILETIME& time) -{ - HANDLE hFile = CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (INVALID_HANDLE_VALUE != hFile) - { - SetFileTime(hFile, NULL, NULL, &time); - CloseHandle(hFile); - } -} - -inline bool ThumbFileTimeIsEqual(const FILETIME& ft1, const FILETIME& ft2) -{ - return ft1.dwHighDateTime == ft2.dwHighDateTime && ft1.dwLowDateTime == ft2.dwLowDateTime; -} -#elif defined(AZ_PLATFORM_MAC) || defined(AZ_PLATFORM_LINUX) -#define FileTimeType utimbuf - -inline void GetThumbFileTime(const char* fileName, utimbuf& times) -{ - struct stat sb; - if (stat(fileName, &sb) == 0) - { - times.actime = sb.st_atime; - times.modtime = sb.st_mtime; - } -} - -inline void SetThumbFileTime(const char* fileName, const utimbuf& times) -{ - utime(fileName, ×); -} - -inline bool ThumbFileTimeIsEqual(const utimbuf& ft1, const utimbuf& ft2) -{ - return ft1.modtime == ft2.modtime; -} -#endif - -void CThumbnailGenerator::GenerateForDirectory(const QString& path) -{ - return; - - ////////////////////////////////////////////////////////////////////////// - QStringList files; - //CString dir = GetIEditor()->GetPrimaryCDFolder(); - QString dir = path; - scan_directory(dir, "", "*.*", files, true); - - I3DEngine* engine = GetIEditor()->Get3DEngine(); - - int thumbSize = 128; - CImageEx image; - image.Allocate(thumbSize, thumbSize); - - char drive[_MAX_DRIVE]; - char fdir[_MAX_DIR]; - char fname[_MAX_FNAME]; - char fext[_MAX_EXT]; - char bmpFile[1024]; - - GetIEditor()->ShowConsole(true); - CWaitProgress wait("Generating CGF Thumbnails"); - for (int i = 0; i < files.size(); i++) - { - QString file = dir + files[i]; - _splitpath_s(file.toUtf8().data(), drive, fdir, fname, fext); - - //if (_stricmp(fext,".cgf") != 0 && _stricmp(fext,".bld") != 0) - if (_stricmp(fext, ".cgf") != 0) - { - continue; - } - - if (!wait.Step(100 * i / files.size())) - { - break; - } - - _makepath_s(bmpFile, drive, fdir, fname, ".tmb"); - - FileTimeType ft1, ft2; - GetThumbFileTime(file.toUtf8().data(), ft1); - GetThumbFileTime(bmpFile, ft2); - // Both cgf and bmp have same time stamp. - if (ThumbFileTimeIsEqual(ft1, ft2)) - { - continue; - } - - //CLogFile::FormatLine( "Generating thumbnail for %s...",file ); - - _smart_ptr obj = engine->LoadStatObjAutoRef(file.toUtf8().data(), NULL, NULL, false); - if (obj) - { - assert(!"IStatObj::MakeObjectPicture does not exist anymore"); - // obj->MakeObjectPicture( (unsigned char*)image.GetData(),thumbSize ); - - CImageUtil::SaveBitmap(bmpFile, image); - SetThumbFileTime(bmpFile, ft1); -#if defined(AZ_PLATFORM_WINDOWS) - SetFileAttributes(bmpFile, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); -#endif - obj->Release(); - } - } - //GetIEditor()->ShowConsole( false ); -} - -void CThumbnailGenerator::GenerateForFile([[maybe_unused]] const QString& fileName) -{ -} diff --git a/Code/Sandbox/Editor/ThumbnailGenerator.h b/Code/Sandbox/Editor/ThumbnailGenerator.h deleted file mode 100644 index ef5a833e60..0000000000 --- a/Code/Sandbox/Editor/ThumbnailGenerator.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_THUMBNAILGENERATOR_H -#define CRYINCLUDE_EDITOR_THUMBNAILGENERATOR_H - -#pragma once - - -class CThumbnailGenerator -{ -public: - CThumbnailGenerator(void); - ~CThumbnailGenerator(void); - - void GenerateForDirectory(const QString& path); - void GenerateForFile(const QString& fileName); -}; - -#endif // CRYINCLUDE_EDITOR_THUMBNAILGENERATOR_H diff --git a/Code/Sandbox/Editor/TimeOfDay.qrc b/Code/Sandbox/Editor/TimeOfDay.qrc deleted file mode 100644 index 7f45cf485f..0000000000 --- a/Code/Sandbox/Editor/TimeOfDay.qrc +++ /dev/null @@ -1,34 +0,0 @@ - - - TimeOfDay/main-00.png - TimeOfDay/main-01.png - TimeOfDay/main-02.png - TimeOfDay/main-03.png - TimeOfDay/main-04.png - TimeOfDay/main-05.png - TimeOfDay/main-06.png - TimeOfDay/main-07.png - TimeOfDay/main-08.png - TimeOfDay/main-09.png - TimeOfDay/main-10.png - TimeOfDay/main-11.png - TimeOfDay/main-12.png - Common/spline_edit-00.png - Common/spline_edit-01.png - Common/spline_edit-02.png - Common/spline_edit-03.png - Common/spline_edit-04.png - Common/spline_edit-05.png - Common/spline_edit-06.png - Common/spline_edit-07.png - Common/spline_edit-08.png - Common/spline_edit-09.png - Common/spline_edit-10.png - Common/spline_edit-11.png - Common/spline_edit-12.png - Common/spline_edit-13.png - Common/spline_edit-14.png - Common/spline_edit-15.png - Common/spline_edit-16.png - - diff --git a/Code/Sandbox/Editor/TimeOfDayDialog.cpp b/Code/Sandbox/Editor/TimeOfDayDialog.cpp deleted file mode 100644 index 80aa4d5172..0000000000 --- a/Code/Sandbox/Editor/TimeOfDayDialog.cpp +++ /dev/null @@ -1,1443 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "TimeOfDayDialog.h" - -// Qt -#include - -// AzToolsFramework -#include - -// CryCommon -#include - -// Editor -#include "Settings.h" -#include "Controls/CurveEditorCtrl.h" -#include "Mission.h" -#include "CryEditDoc.h" -#include "Clipboard.h" -#include "QtViewPaneManager.h" -#include "Undo/Undo.h" -#include "LyViewPaneNames.h" - -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -#include -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - -#define PANE_LAYOUT_SECTION _T("DockingPaneLayouts\\TimeOfDay") -#define PANE_LAYOUT_VERSION_ENTRY _T("PaneLayoutVersion") - -namespace TimeOfDayDetails -{ - const float kEpsilon = 0.00001f; - - const int kTimeOfDayDialogLayoutVersion = 0x0002; // bump this up on every substantial pane layout change - - static void SetKeyTangentType(ISplineInterpolator* pSpline, int key, ESplineKeyTangentType type) - { - int flags = (pSpline->GetKeyFlags(key) & ~SPLINE_KEY_TANGENT_IN_MASK) & ~SPLINE_KEY_TANGENT_OUT_MASK; - pSpline->SetKeyFlags(key, flags | (type << SPLINE_KEY_TANGENT_IN_SHIFT) | (type << SPLINE_KEY_TANGENT_OUT_SHIFT)); - } - - static QTime qTimeFromFloat(float time) - { - // The float time goes from 0.0 - 23.98 (since max time is 23:59), so - // convert this to seconds so we can construct a QTime object from that - int seconds = (time * 60.0f) * 60; - return QTime(0, 0).addSecs(seconds); - } - - static float floatFromQTime(const QTime& time) - { - return static_cast(time.msecsSinceStartOfDay() / 60000) / 60.0; - } - - AZ_INLINE static bool SkipUserInterface(int value) - { - // Check for obsolete parameters that we still want to keep around to migrate legacy data to new data - // but don't want to display in the UI - const ITimeOfDay::ETimeOfDayParamID enumValue = static_cast(value); - - // Split the check into two parts to try to keep the logic clear. - // The First set of parameters are always checked... - bool skipParameter = (enumValue == ITimeOfDay::PARAM_HDR_DYNAMIC_POWER_FACTOR) || - (enumValue == ITimeOfDay::PARAM_TERRAIN_OCCL_MULTIPLIER) || - (enumValue == ITimeOfDay::PARAM_SUN_COLOR_MULTIPLIER); - - return skipParameter; - } -} - -CHDRPane::CHDRPane(CTimeOfDayDialog* pTODDlg) - : QWidget(pTODDlg) - , m_pTODDlg(pTODDlg) - , m_pVars(new CVarBlock) -{ - assert(m_pTODDlg); -#if !defined(NDEBUG) - bool ok = -#endif - Init(); - assert(ok); -} - -bool CHDRPane::Init() -{ - m_filmCurveCtrl = new CCurveEditorCtrl(this); - m_filmCurveCtrl->SetControlPointCount(21); - m_filmCurveCtrl->SetMouseEnable(false); - m_filmCurveCtrl->SetPadding(16); - m_filmCurveCtrl->SetFlags( - CCurveEditorCtrl::eFlag_ShowVerticalRuler | - CCurveEditorCtrl::eFlag_ShowHorizontalRuler | - CCurveEditorCtrl::eFlag_ShowCursorAlways | - CCurveEditorCtrl::eFlag_ShowVerticalRulerText | - CCurveEditorCtrl::eFlag_ShowHorizontalRulerText | - CCurveEditorCtrl::eFlag_ShowPaddingBorder); - m_filmCurveCtrl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - m_propsCtrl = new ReflectedPropertyControl(this); - m_propsCtrl->Setup(); - - QVBoxLayout* l = new QVBoxLayout; - l->setMargin(0); - l->addWidget(m_filmCurveCtrl); - l->addWidget(m_propsCtrl); - setLayout(l); - - m_propsCtrl->SetSelChangeCallback(AZStd::bind(&CHDRPane::OnPropertySelected, this, AZStd::placeholders::_1)); - - return true; -} - -void CHDRPane::OnPropertySelected(IVariable *pVar) -{ - if (pVar && pVar->GetType() == IVariable::ARRAY) - { - pVar = nullptr; - } - - emit propertySelected(pVar); -} - -bool CHDRPane::GetFilmCurveParams(float& shoulderScale, float& midScale, float& toeScale, float& whitePoint) const -{ - int checked = 0; - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - - for (int i = 0; pTimeOfDay->GetVariableCount(); ++i) - { - ITimeOfDay::SVariableInfo varInfo; - bool ok = pTimeOfDay->GetVariableInfo(i, varInfo); - if (ok == false) - { - continue; - } - if (TimeOfDayDetails::SkipUserInterface(varInfo.nParamId)) - { - continue; - } - - switch (varInfo.nParamId) - { - case ITimeOfDay::PARAM_HDR_FILMCURVE_SHOULDER_SCALE: - shoulderScale = varInfo.fValue[0]; - ++checked; - break; - case ITimeOfDay::PARAM_HDR_FILMCURVE_LINEAR_SCALE: - midScale = varInfo.fValue[0]; - ++checked; - break; - case ITimeOfDay::PARAM_HDR_FILMCURVE_TOE_SCALE: - toeScale = varInfo.fValue[0]; - ++checked; - break; - case ITimeOfDay::PARAM_HDR_FILMCURVE_WHITEPOINT: - whitePoint = varInfo.fValue[0]; - ++checked; - break; - } - - if (checked == 4) - { - return true; - } - } - - return false; -} - -static float EvalFilmCurve(float x, float ss, float ms, float ts) -{ - return (x * (ss * 6.2f * x + 0.5f * ms)) / max((x * (ss * 6.2f * x + 1.7f) + ts * 0.06f), TimeOfDayDetails::kEpsilon); -} - -void CHDRPane::UpdateFilmCurve() -{ - float shoulderScale = 0, midScale = 0, toeScale = 0, whitePoint = 0; -#if !defined(NDEBUG) - bool ok = -#endif - GetFilmCurveParams(shoulderScale, midScale, toeScale, whitePoint); - assert(ok); - const float minX = -4.0f, minY = 0.0f, maxX = 4.0f; - float maxY = 1.0f, stepY = 0.1f; - - int numSamplePoints = m_filmCurveCtrl->GetControlPointCount(); - - for (int i = 0; i < numSamplePoints; ++i) - { - float t = static_cast(i) / (numSamplePoints - 1); - float logX = minX + ((maxX - minX) * t); - float x = powf(10.0f, logX); // Conventionally, the x domain is logarithmic. - - float v = EvalFilmCurve(x, shoulderScale, midScale, toeScale) / - max(EvalFilmCurve(whitePoint, shoulderScale, midScale, toeScale), TimeOfDayDetails::kEpsilon); - v = powf(v, 2.2f); // converting to a linear space - - // Update the maximum Y so that a proper domain can be set later. - if (v > maxY) - { - maxY = ceil(v / stepY) * stepY; - } - - m_filmCurveCtrl->SetControlPoint(i, Vec2(logX, v)); - } - - // maxY is not fixed, so adjust Y grid count properly according to it. - const UINT gridX = 4; // X grid is fixed. - UINT gridY = static_cast(maxY / stepY); - while (gridY > 20) // > 20 means too many, so reduce the count properly. - { - gridY = (gridY + 9) / 10; - stepY *= 10.0f; - } - maxY = stepY * gridY; - // Also prepare labels for the grid since the default labeling is improper - // especially for the X axis due to its log scale. - QStringList labelsX, labelsY; - for (int i = 0; i <= gridX; ++i) - { - QString label; - label.asprintf("%.4g", powf(10.0f, minX + (maxX - minX) * static_cast(i) / gridX)); - labelsX.push_back(label); - } - for (int i = 0; i <= gridY; ++i) - { - QString label; - label.asprintf("%.1f", i * stepY); - labelsY.push_back(label); - } - m_filmCurveCtrl->SetGrid(gridX, gridY, labelsX, labelsY); - m_filmCurveCtrl->MarkY(1.0f); // Mark the output of 1 so that users can quickly recognize where the clamping happens. - m_filmCurveCtrl->SetDomainBounds(minX, minY, maxX, maxY); - - m_filmCurveCtrl->update(); -} -////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////// -// Adapter for Multi element interpolators that allow to split it to several -// different interpolators for each element separately. -////////////////////////////////////////////////////////////////////////// -class CMultiElementSplineInterpolatorAdapter - : public ISplineInterpolator -{ -public: - CMultiElementSplineInterpolatorAdapter() - : m_pInterpolator(0) - , m_element(0) {} - CMultiElementSplineInterpolatorAdapter(ISplineInterpolator* pSpline, int element) - { - m_pInterpolator = pSpline; - m_element = element; - } - // Dimension of the spline from 0 to 3, number of parameters used in ValueType. - virtual int GetNumDimensions() { return m_pInterpolator->GetNumDimensions(); } - virtual int InsertKey(float time, ValueType value) - { - ValueType v = {0, 0, 0, 0}; - v[m_element] = value[0]; - return m_pInterpolator->InsertKey(time, v); - }; - virtual void RemoveKey(int key) { m_pInterpolator->RemoveKey(key); }; - - virtual void FindKeysInRange(float startTime, float endTime, int& firstFoundKey, int& numFoundKeys) - { m_pInterpolator->FindKeysInRange(startTime, endTime, firstFoundKey, numFoundKeys); } - virtual void RemoveKeysInRange(float startTime, float endTime) { m_pInterpolator->RemoveKeysInRange(startTime, endTime); } - - virtual int GetKeyCount() { return m_pInterpolator->GetKeyCount(); } - virtual void SetKeyTime(int key, float time) { return m_pInterpolator->SetKeyTime(key, time); }; - virtual float GetKeyTime(int key) { return m_pInterpolator->GetKeyTime(key); } - - virtual void SetKeyValue(int key, ValueType value) - { - ValueType v = {0, 0, 0, 0}; - m_pInterpolator->GetKeyValue(key, v); - v[m_element] = value[0]; - m_pInterpolator->SetKeyValue(key, v); - } - virtual bool GetKeyValue(int key, ValueType& value) - { - ValueType v = {0, 0, 0, 0}; - v[m_element] = value[0]; - return m_pInterpolator->GetKeyValue(key, value); - value[0] = v[m_element]; - } - - virtual void SetKeyInTangent([[maybe_unused]] int key, [[maybe_unused]] ValueType tin) {}; - virtual void SetKeyOutTangent([[maybe_unused]] int key, [[maybe_unused]] ValueType tout) {}; - virtual void SetKeyTangents([[maybe_unused]] int key, [[maybe_unused]] ValueType tin, [[maybe_unused]] ValueType tout) {}; - virtual bool GetKeyTangents([[maybe_unused]] int key, [[maybe_unused]] ValueType& tin, [[maybe_unused]] ValueType& tout) { return false; }; - - // Changes key flags, @see ESplineKeyFlags - virtual void SetKeyFlags(int key, int flags) { return m_pInterpolator->SetKeyFlags(key, flags); }; - // Retrieve key flags, @see ESplineKeyFlags - virtual int GetKeyFlags(int key) { return m_pInterpolator->GetKeyFlags(key); } - - virtual void Interpolate(float time, ValueType& value) - { - m_pInterpolator->Interpolate(time, value); - value[0] = value[m_element]; - }; - - virtual void SerializeSpline(XmlNodeRef& node, bool bLoading) { return m_pInterpolator->SerializeSpline(node, bLoading); }; - - virtual ISplineBackup* Backup() { return m_pInterpolator->Backup(); }; - virtual void Restore(ISplineBackup* pBackup) { return m_pInterpolator->Restore(pBackup); }; - -public: - ISplineInterpolator* m_pInterpolator; - int m_element; -}; - -////////////////////////////////////////////////////////////////////////// -class CTimeOfDaySplineSet - : public ISplineSet -{ -public: - void AddSpline(ISplineInterpolator* pSpline) { m_splines.push_back(pSpline); }; - void RemoveAllSplines() { m_splines.clear(); } - - virtual ISplineInterpolator* GetSplineFromID(const string& id) - { - int i = atoi(id.c_str()); - if (i >= 0 && i < (int)m_splines.size()) - { - return m_splines[i]; - } - return 0; - }; - virtual string GetIDFromSpline(ISplineInterpolator* pSpline) - { - for (int i = 0; i < (int)m_splines.size(); i++) - { - if (m_splines[i] == pSpline) - { - string s; - s.Format("%d", i); - return s; - } - } - return ""; - } - virtual int GetSplineCount() const { return (int)m_splines.size(); } - virtual int GetKeyCountAtTime(float time, float threshold) const - { - int count = 0; - for (int i = 0; i < (int)m_splines.size(); i++) - { - if (m_splines[i]->FindKey(time, threshold) > 0) - { - count++; - } - } - return count; - } - -public: - std::vector m_splines; -}; - -////////////////////////////////////////////////////////////////////////// -CTimeOfDayDialog::CTimeOfDayDialog(QWidget* parent /* = nullptr */) - : QMainWindow(parent) - , m_ui(new Ui::TimeOfDayDialog) - , m_timelineCtrl(new TimelineWidget(this)) - , m_pHDRPane(new CHDRPane(this)) -{ - gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener(this); - GetIEditor()->RegisterNotifyListener(this); - - m_ui->setupUi(this); - m_ui->parameters->Setup(); - splitDockWidget(m_ui->hdrPaneDock, m_ui->tasksDock, Qt::Horizontal); - - // Calculate our maximum time from the slider (23:59) - m_maxTime = m_ui->timelineSlider->maximum() / 60.0f; - - Init(); -} - -////////////////////////////////////////////////////////////////////////// -CTimeOfDayDialog::~CTimeOfDayDialog() -{ - m_alive = false; - GetIEditor()->UnregisterNotifyListener(this); - GetIEditor()->GetUndoManager()->RemoveListener(this); - - gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener(this); - - QSettings settings; - settings.beginGroup(QStringLiteral("EnvironmentEditor")); - settings.setValue(QStringLiteral("state"), saveState()); -} - -const GUID& CTimeOfDayDialog::GetClassID() -{ - // {85FB1272-D858-4ca5-ABB4-04D484ABF51E} - static const GUID guid = { - 0x85fb1272, 0xd858, 0x4ca5, { 0xab, 0xb4, 0x4, 0xd4, 0x84, 0xab, 0xf5, 0x1e } - }; - return guid; -} - -void CTimeOfDayDialog::RegisterViewClass() -{ - AzToolsFramework::ViewPaneOptions options; - options.paneRect = QRect(100, 100, 1500, 800); - options.canHaveMultipleInstances = true; - options.isDockable = true; - - AzToolsFramework::RegisterViewPane(LyViewPane::TimeOfDayEditor, LyViewPane::CategoryOther, options); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::UpdateValues() -{ - if (!m_alive) - { - return; - } - - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - ITimeOfDay::SAdvancedInfo advInfo; - pTimeOfDay->GetAdvancedInfo(advInfo); - - RefreshPropertiesValues(); - - SetTimeRange(advInfo.fStartTime, advInfo.fEndTime, advInfo.fAnimSpeed); - UpdateUI(false); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnSystemEvent(ESystemEvent event, [[maybe_unused]] UINT_PTR wparam, [[maybe_unused]] UINT_PTR lparam) -{ - - - switch (event) - { - case ESYSTEM_EVENT_TIME_OF_DAY_SET: - // We update the UI in response to a system event (instead of with direct callbacks in the dialog) because time could be set by any of the dialog, - // e_TimeOfDay cvar, a Flow Graph Node or Track View. - UpdateUI(); - break; - default: - // do nothing - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::Init() -{ - // Load toolbar images for the main toolbar - m_ui->actionUndo->setIcon(QIcon(":/TimeOfDay/main-00.png")); - m_ui->actionRedo->setIcon(QIcon(":/TimeOfDay/main-01.png")); - m_ui->actionImportFile->setIcon(QIcon(":/TimeOfDay/main-02.png")); - m_ui->actionExportFile->setIcon(QIcon(":/TimeOfDay/main-03.png")); - m_ui->actionPlayPause->setIcon(QIcon(":/TimeOfDay/main-04.png")); - m_ui->actionSetTimeTo0000->setIcon(QIcon(":/TimeOfDay/main-05.png")); - m_ui->actionSetTimeTo0600->setIcon(QIcon(":/TimeOfDay/main-06.png")); - m_ui->actionSetTimeTo1200->setIcon(QIcon(":/TimeOfDay/main-07.png")); - m_ui->actionSetTimeTo1800->setIcon(QIcon(":/TimeOfDay/main-08.png")); - m_ui->actionSetTimeTo2400->setIcon(QIcon(":/TimeOfDay/main-09.png")); - m_ui->actionStartStopRecording->setIcon(QIcon(":/TimeOfDay/main-10.png")); - m_ui->actionHold->setIcon(QIcon(":/TimeOfDay/main-11.png")); - m_ui->actionFetch->setIcon(QIcon(":/TimeOfDay/main-12.png")); - - // Load the images for the spline edit toolbar - m_ui->tangentsToAutoButton->setIcon(QIcon(":/Common/spline_edit-00.png")); - m_ui->inTangentToZeroButton->setIcon(QIcon(":/Common/spline_edit-01.png")); - m_ui->inTangentToStepButton->setIcon(QIcon(":/Common/spline_edit-02.png")); - m_ui->inTangentToLinearButton->setIcon(QIcon(":/Common/spline_edit-03.png")); - m_ui->outTangentToZerobutton->setIcon(QIcon(":/Common/spline_edit-04.png")); - m_ui->outTangentToStepButton->setIcon(QIcon(":/Common/spline_edit-05.png")); - m_ui->outTangentToLinearButton->setIcon(QIcon(":/Common/spline_edit-06.png")); - m_ui->fitSplinesHorizontalButton->setIcon(QIcon(":/Common/spline_edit-07.png")); - m_ui->fitSplinesVerticalButton->setIcon(QIcon(":/Common/spline_edit-08.png")); - m_ui->splineSnapGridX->setIcon(QIcon(":/Common/spline_edit-09.png")); - m_ui->splineSnapGridY->setIcon(QIcon(":/Common/spline_edit-10.png")); - m_ui->previousKeyButton->setIcon(QIcon(":/Common/spline_edit-14.png")); - m_ui->nextKeyButton->setIcon(QIcon(":/Common/spline_edit-15.png")); - m_ui->removeAllExceptSelectedButton->setIcon(QIcon(":/Common/spline_edit-16.png")); - - m_timelineCtrl->SetTicksTextScale(24.0f); - m_timelineCtrl->SetTimeRange(Range(0, 1)); - - m_ui->spline->SetDefaultKeyTangentType(SPLINE_KEY_TANGENT_LINEAR); - m_ui->spline->SetTimelineCtrl(m_timelineCtrl); - m_ui->spline->SetTimeRange(Range(0, 1.0f)); - m_ui->spline->SetValueRange(Range(-1.0f, 1.0f)); - m_ui->spline->SetMinTimeEpsilon(0.00001f); - m_ui->spline->SetTooltipValueScale(24, 1); - - m_ui->colorGradient->SetNoZoom(false); - m_ui->colorGradient->SetTimeRange(0, 1.0f); - m_ui->colorGradient->LockFirstAndLastKeys(true); - m_ui->colorGradient->SetTooltipValueScale(24, 1); - - CreateProperties(); - UpdateValues(); - UpdateUI(); - - QSettings settings; - settings.beginGroup(QStringLiteral("EnvironmentEditor")); - QByteArray state = settings.value(QStringLiteral("state")).toByteArray(); - if (!state.isEmpty()) - { - restoreState(state); - } - - ResetSpline(0); - - m_ui->hdrPaneDock->setWidget(m_pHDRPane); - m_pHDRPane->UpdateFilmCurve(); - - QString copyAllLabel(tr("Copy All Parameters")); - QString pasteAllLabel(tr("Paste All Parameters")); - m_ui->parameters->AddCustomPopupMenuItem(copyAllLabel, AZStd::bind(&CTimeOfDayDialog::CopyAllProperties, this)); - m_ui->parameters->AddCustomPopupMenuItem(pasteAllLabel, AZStd::bind(&CTimeOfDayDialog::PasteAllProperties, this)); - m_pHDRPane->properties().AddCustomPopupMenuItem(copyAllLabel, AZStd::bind(&CTimeOfDayDialog::CopyAllProperties, this)); - m_pHDRPane->properties().AddCustomPopupMenuItem(pasteAllLabel, AZStd::bind(&CTimeOfDayDialog::PasteAllProperties, this)); - - m_ui->parameters->SetSelChangeCallback(AZStd::bind(&CTimeOfDayDialog::OnPropertySelected, this, AZStd::placeholders::_1)); - connect(m_pHDRPane, &CHDRPane::propertySelected, this, &CTimeOfDayDialog::HdrPropertySelected); - m_pHDRPane->properties().SetUpdateCallback(AZStd::bind(&CTimeOfDayDialog::OnUpdateProperties, this, AZStd::placeholders::_1)); - m_ui->parameters->SetUpdateCallback(AZStd::bind(&CTimeOfDayDialog::OnUpdateProperties, this, AZStd::placeholders::_1)); - - connect(m_ui->importFromFileClickable, &QLabel::linkActivated, this, &CTimeOfDayDialog::OnImport); - connect(m_ui->exportToFileClickable, &QLabel::linkActivated, this, &CTimeOfDayDialog::OnExport); - connect(m_ui->resetValuesClickable, &QLabel::linkActivated, this, &CTimeOfDayDialog::OnResetToDefaultValues); - connect(m_ui->expandAllClickable, &QLabel::linkActivated, this, &CTimeOfDayDialog::OnExpandAll); - connect(m_ui->collapseAllClickable, &QLabel::linkActivated, this, &CTimeOfDayDialog::OnCollapseAll); - - connect(m_ui->currentTimeEdit, &QTimeEdit::timeChanged, this, [=](const QTime& time) { SetTime(TimeOfDayDetails::floatFromQTime(time)); }); - connect(m_ui->startTimeEdit, &QTimeEdit::timeChanged, this, &CTimeOfDayDialog::StartTimeChanged); - connect(m_ui->endTimeEdit, &QTimeEdit::timeChanged, this, &CTimeOfDayDialog::EndTimeChanged); - auto doubleValueChanged = static_cast(&QDoubleSpinBox::valueChanged); - connect(m_ui->playSpeedDoubleSpinBox, doubleValueChanged, this, &CTimeOfDayDialog::OnChangeTimeAnimSpeed); - - connect(m_ui->playClickable, &QLabel::linkActivated, this, [=]() { m_ui->actionPlayPause->setChecked(true); }); - connect(m_ui->stopClickable, &QLabel::linkActivated, this, [=]() { m_ui->actionPlayPause->setChecked(false); }); - - connect(m_ui->forceSkyUpdateCheckBox, &QCheckBox::stateChanged, this, [=](int state) { gSettings.bForceSkyUpdate = state == Qt::Checked; }); - - connect(m_ui->actionUndo, &QAction::triggered, this, &CTimeOfDayDialog::OnUndo); - connect(m_ui->actionRedo, &QAction::triggered, this, &CTimeOfDayDialog::OnRedo); - connect(m_ui->actionImportFile, &QAction::triggered, this, &CTimeOfDayDialog::OnImport); - connect(m_ui->actionExportFile, &QAction::triggered, this, &CTimeOfDayDialog::OnExport); - - connect(m_ui->actionSetTimeTo0000, &QAction::triggered, this, [=]() { SetTime(0); }); - connect(m_ui->actionSetTimeTo0600, &QAction::triggered, this, [=]() { SetTime(6); }); - connect(m_ui->actionSetTimeTo1200, &QAction::triggered, this, [=]() { SetTime(12); }); - connect(m_ui->actionSetTimeTo1800, &QAction::triggered, this, [=]() { SetTime(18); }); - connect(m_ui->actionSetTimeTo2400, &QAction::triggered, this, [=]() { SetTime(m_maxTime); }); - - connect(m_ui->actionHold, &QAction::triggered, this, &CTimeOfDayDialog::OnHold); - connect(m_ui->actionFetch, &QAction::triggered, this, &CTimeOfDayDialog::OnFetch); - - connect(m_ui->tangentsToAutoButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_TANGENT_AUTO); }); - connect(m_ui->inTangentToZeroButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_TANGENT_IN_ZERO); }); - connect(m_ui->inTangentToStepButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_TANGENT_IN_STEP); }); - connect(m_ui->inTangentToLinearButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_TANGENT_IN_LINEAR); }); - connect(m_ui->outTangentToZerobutton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_TANGENT_OUT_ZERO); }); - connect(m_ui->outTangentToStepButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_TANGENT_OUT_STEP); }); - connect(m_ui->outTangentToLinearButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_TANGENT_OUT_LINEAR); }); - connect(m_ui->fitSplinesHorizontalButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_SPLINE_FIT_X); }); - connect(m_ui->fitSplinesVerticalButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_SPLINE_FIT_Y); }); - connect(m_ui->splineSnapGridX, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_SPLINE_SNAP_GRID_X); }); - connect(m_ui->splineSnapGridY, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_SPLINE_SNAP_GRID_Y); }); - connect(m_ui->previousKeyButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_SPLINE_PREVIOUS_KEY); }); - connect(m_ui->nextKeyButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_SPLINE_NEXT_KEY); }); - connect(m_ui->removeAllExceptSelectedButton, &QAbstractButton::clicked, this, [=]() { m_ui->spline->OnUserCommand(ID_SPLINE_FLATTEN_ALL); }); - - connect(m_ui->timelineSlider, &AzQtComponents::SliderInt::valueChanged, this, [=](int value) { SetTime(value / 60.0f); }); - - connect(m_ui->spline, &SplineWidget::beforeChange, this, &CTimeOfDayDialog::OnBeforeSplineChange); - connect(m_ui->spline, &SplineWidget::change, this, [=]() { OnSplineChange(m_ui->spline); }); - connect(m_ui->spline, &SplineWidget::scrollZoomRequested, this, &CTimeOfDayDialog::OnSplineCtrlScrollZoom); - connect(m_ui->spline, &SplineWidget::timeChange, this, &CTimeOfDayDialog::OnTimelineCtrlChange); - connect(m_ui->spline, &SplineWidget::keySelectionChange, this, [=]() { SetTimeFromActiveKey(); }); - - connect(m_ui->colorGradient, &CColorGradientCtrl::beforeChange, this, &CTimeOfDayDialog::OnBeforeSplineChange); - connect(m_ui->colorGradient, &CColorGradientCtrl::change, this, [=]() { OnSplineChange(m_ui->colorGradient); }); - connect(m_ui->colorGradient, &CColorGradientCtrl::activeKeyChange, this, [=]() { SetTimeFromActiveKey(true); }); - //connect(m_timelineCtrl.data(), &TimelineWidget::startChange, this, &CTimeOfDayDialog::OnBeforeSplineChange); - connect(m_timelineCtrl, &TimelineWidget::change, this, &CTimeOfDayDialog::OnTimelineCtrlChange); - - //ITimeOfDay *pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - //m_ui->currentTimeEdit->setTime(qTimeFromFloat(pTimeOfDay->GetTime())); - - GetIEditor()->GetUndoManager()->AddListener(this); -} - -void CTimeOfDayDialog::HdrPropertySelected(IVariable* v) -{ - if (v) - { - m_ui->parameters->ClearSelection(); - } - ResetSpline(v); -} - -void CTimeOfDayDialog::StartTimeChanged([[maybe_unused]] const QTime& time) -{ - float converted = TimeOfDayDetails::floatFromQTime(m_ui->startTimeEdit->time()); - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - ITimeOfDay::SAdvancedInfo advInfo; - pTimeOfDay->GetAdvancedInfo(advInfo); - advInfo.fStartTime = converted; - pTimeOfDay->SetAdvancedInfo(advInfo); -} - -void CTimeOfDayDialog::EndTimeChanged([[maybe_unused]] const QTime& time) -{ - float converted = TimeOfDayDetails::floatFromQTime(m_ui->endTimeEdit->time()); - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - ITimeOfDay::SAdvancedInfo advInfo; - pTimeOfDay->GetAdvancedInfo(advInfo); - advInfo.fEndTime = converted; - pTimeOfDay->SetAdvancedInfo(advInfo); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::CreateProperties() -{ - m_pVars = new CVarBlock; - - std::map groups; - - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - for (int i = 0; i < pTimeOfDay->GetVariableCount(); i++) - { - ITimeOfDay::SVariableInfo varInfo; - if (!pTimeOfDay->GetVariableInfo(i, varInfo)) - { - continue; - } - - if (TimeOfDayDetails::SkipUserInterface(varInfo.nParamId)) - { - continue; - } - - if (!varInfo.pInterpolator) - { - continue; - } - - IVariable* pGroupVar = stl::find_in_map(groups, varInfo.group, 0); - if (!pGroupVar) - { - // Create new group - pGroupVar = new CVariableArray(); - pGroupVar->SetName(varInfo.group); - pGroupVar->SetUserData(-1); - if (strcmp(varInfo.group, "HDR") == 0) // HDR parameters should go into the separate HDR pane. - { - m_pHDRPane->variables()->AddVariable(pGroupVar); - } - else - { - m_pVars->AddVariable(pGroupVar); - } - groups[varInfo.group] = pGroupVar; - } - - IVariable* pVar = 0; - if (varInfo.type == ITimeOfDay::TYPE_COLOR) - { - ////////////////////////////////////////////////////////////////////////// - // Add Var. - pVar = new CVariable(); - pVar->SetDataType(IVariable::DT_COLOR); - pVar->Set(Vec3(varInfo.fValue[0], varInfo.fValue[1], varInfo.fValue[2])); - } - else if (varInfo.type == ITimeOfDay::TYPE_FLOAT) - { - // Add Var. - pVar = new CVariable(); - pVar->Set(varInfo.fValue[0]); - pVar->SetLimits(varInfo.fValue[1], varInfo.fValue[2]); - } - - if (pVar) - { - pVar->SetName(varInfo.name); - pVar->SetHumanName(varInfo.displayName); - pGroupVar->AddVariable(pVar); - pVar->SetUserData(i); - } - } - - m_ui->parameters->AddVarBlock(m_pVars); - m_ui->parameters->ExpandAll(); - m_ui->parameters->EnableNotifyWithoutValueChange(true); - - m_pHDRPane->properties().AddVarBlock(m_pHDRPane->variables()); - m_pHDRPane->properties().ExpandAll(); - m_pHDRPane->properties().EnableNotifyWithoutValueChange(true); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnBeforeSplineChange() -{ - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoTimeOfDayObject()); - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnSplineChange(const QWidget* source) -{ - RefreshPropertiesValues(); - - if (source == m_ui->spline) - { - // Update the time of day settings on spline changes (e.g. keys being moved) - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - bool bForceUpdate = m_ui->forceSkyUpdateCheckBox->isChecked(); - pTimeOfDay->Update(true, bForceUpdate); - - m_timelineCtrl->update(); - m_ui->colorGradient->update(); - } - else if (source == m_timelineCtrl) - { - m_ui->colorGradient->update(); - m_ui->spline->update(); - } - else - { - m_ui->spline->SplinesChanged(); - m_ui->spline->update(); - m_timelineCtrl->update(); - } - - - if (m_ui->spline->GetSplineCount() > 0) - { - ISplineInterpolator* pSpline = m_ui->spline->GetSpline(0); - if (NULL != pSpline) - { - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - const uint numVars = pTimeOfDay->GetVariableCount(); - for (uint i = 0; i < numVars; ++i) - { - ITimeOfDay::SVariableInfo varInfo; - pTimeOfDay->GetVariableInfo(i, varInfo); - } - } - } -} - -/** - * Update our time based on the currently active key - */ -void CTimeOfDayDialog::SetTimeFromActiveKey(bool useColorGradient) -{ - if (m_ui->spline->GetSplineCount() < 1) - { - return; - } - - ISplineInterpolator* pSpline = m_ui->spline->GetSpline(0); - if (!pSpline) - { - return; - } - - int activeKey = -1; - if (useColorGradient) - { - // If this method was triggered from our color gradient control, then - // retrieve its active key - activeKey = m_ui->colorGradient->GetActiveKey(); - } - else - { - // Otherwise this method was triggered from our main spline control, so - // we need to find the selected key by cycling through its keys - int numKeys = pSpline->GetKeyCount(); - for (int i = 0; i < numKeys; ++i) - { - if (pSpline->IsKeySelectedAtAnyDimension(i)) - { - activeKey = i; - break; - } - } - } - - if (activeKey == -1) - { - return; - } - - SetTime(pSpline->GetKeyTime(activeKey) * m_maxTime); -} - -////////////////////////////////////////////////////////////////////////// -float CTimeOfDayDialog::GetTime() const -{ - // This used to get the time from GetIEditor()->GetDocument()->GetCurrentMission()->GetTime(); but that seems like legacy CryEngine, so we're - // switching to grabbing it from the 3DEngine if possible - float time = .0f; - if (gEnv->p3DEngine->GetTimeOfDay()) - { - time = gEnv->p3DEngine->GetTimeOfDay()->GetTime(); - } - return time; -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::SetTimeRange(float fTimeStart, float fTimeEnd, float fSpeed) -{ - m_ui->startTimeEdit->setTime(TimeOfDayDetails::qTimeFromFloat(fTimeStart)); - m_ui->endTimeEdit->setTime(TimeOfDayDetails::qTimeFromFloat(fTimeEnd)); - - m_ui->playSpeedDoubleSpinBox->setValue(fSpeed); - - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - ITimeOfDay::SAdvancedInfo advInfo; - pTimeOfDay->GetAdvancedInfo(advInfo); - advInfo.fStartTime = fTimeStart; - advInfo.fEndTime = fTimeEnd; - advInfo.fAnimSpeed = fSpeed; - pTimeOfDay->SetAdvancedInfo(advInfo); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::RefreshPropertiesValues() -{ - m_ui->parameters->EnableUpdateCallback(false); - m_pHDRPane->properties().EnableUpdateCallback(false); - - // Interpolate internal values - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - for (int i = 0, numVars = pTimeOfDay->GetVariableCount(); i < numVars; i++) - { - ITimeOfDay::SVariableInfo varInfo; - if (!pTimeOfDay->GetVariableInfo(i, varInfo)) - { - continue; - } - if (TimeOfDayDetails::SkipUserInterface(varInfo.nParamId)) - { - continue; - } - - IVariable* pVar = FindVariable(varInfo.name); - - if (!pVar) - { - continue; - } - - switch (varInfo.type) - { - case ITimeOfDay::TYPE_FLOAT: - pVar->Set(varInfo.fValue[0]); - break; - case ITimeOfDay::TYPE_COLOR: - pVar->Set(Vec3(varInfo.fValue[0], varInfo.fValue[1], varInfo.fValue[2])); - break; - } - } - m_ui->parameters->EnableUpdateCallback(true); - m_pHDRPane->properties().EnableUpdateCallback(true); - - m_pHDRPane->UpdateFilmCurve(); - - // Notify that time of day values changed. - GetIEditor()->Notify(eNotify_OnTimeOfDayChange); -} - -void CTimeOfDayDialog::UpdateUI(bool updateProperties) -{ - float timeOfDayInHours = GetTime(); - - // update the Current Time edit field and Time Of Day Time Slider - QTime qTime = TimeOfDayDetails::qTimeFromFloat(timeOfDayInHours); - - QSignalBlocker sliderBlocker(m_ui->timelineSlider); - QSignalBlocker editBlocker(m_ui->currentTimeEdit); - - int v = qTime.msecsSinceStartOfDay(); - v /= 60000; - m_ui->timelineSlider->setValue(v); - m_ui->currentTimeEdit->setTime(qTime); - - m_ui->spline->SetTimeMarker(timeOfDayInHours / m_maxTime); - m_ui->colorGradient->SetTimeMarker(timeOfDayInHours / m_maxTime); - - if (updateProperties) - { - RefreshPropertiesValues(); - } - else - { - GetIEditor()->Notify(eNotify_OnTimeOfDayChange); - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::SetTime(float time) -{ - const bool bForceUpdate = m_ui->forceSkyUpdateCheckBox->isChecked(); - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - - // This is probably legacy and deprecated, but leaving it here just in case it's needed by some legacy game. - if (GetIEditor()->GetDocument()->GetCurrentMission()) - { - GetIEditor()->GetDocument()->GetCurrentMission()->SetTime(time); - } - - // pTimeOfDay->SetTime will trigger a ESYSTEM_EVENT_TIME_OF_DAY_SET, which in turn will result in UpdateUI() being called - pTimeOfDay->SetTime(time, bForceUpdate); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnCloseScene: - case eNotify_OnBeginNewScene: - case eNotify_OnBeginSceneOpen: - { - // prevent crash during redraw which can happen before eNotify_OnEndSceneOpen - m_ui->spline->RemoveAllSplines(); - m_ui->colorGradient->SetSpline(0); - } - break; - case eNotify_OnEndSceneOpen: - case eNotify_OnEndNewScene: - { - UpdateValues(); - - m_pHDRPane->properties().ClearSelection(); - if (ReflectedPropertyItem* pSelectedItem = m_ui->parameters->GetSelectedItem()) - { - if (IVariable* pVar = pSelectedItem->GetVariable()) - { - ResetSpline(pVar); - } - } - } - break; - - case eNotify_OnIdleUpdate: - if (m_ui->actionPlayPause->isChecked()) - { - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - float fHour = pTimeOfDay->GetTime(); - - ITimeOfDay::SAdvancedInfo advInfo; - pTimeOfDay->GetAdvancedInfo(advInfo); - // get the TOD cycle speed from UI - advInfo.fAnimSpeed = m_ui->playSpeedDoubleSpinBox->value(); - float dt = gEnv->pTimer->GetFrameTime(); - float fTime = fHour + dt * advInfo.fAnimSpeed; - if (fTime > advInfo.fEndTime) - { - fTime = advInfo.fStartTime; - } - if (fTime < advInfo.fStartTime) - { - fTime = advInfo.fEndTime; - } - SetTime(fTime); - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnTimelineCtrlChange() -{ - float fTime = m_timelineCtrl->GetTimeMarker(); - SetTime(fTime * m_maxTime); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnChangeTimeAnimSpeed(double value) -{ - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - ITimeOfDay::SAdvancedInfo advInfo; - pTimeOfDay->GetAdvancedInfo(advInfo); - // set current speed based on if we animating it currently or not - advInfo.fAnimSpeed = value; - pTimeOfDay->SetAdvancedInfo(advInfo); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnSplineCtrlScrollZoom() -{ - if (m_ui->spline && m_ui->colorGradient) - { - m_ui->colorGradient->SetZoom(m_ui->spline->GetZoom().x); - m_ui->colorGradient->SetOrigin(m_ui->spline->GetScrollOffset().x); - m_ui->colorGradient->update(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnImport() -{ - char szFilters[] = "Time Of Day Settings (*.xml);;Time Of Day Settings Old (*.tod)"; - QString fileName; - - if (CFileUtil::SelectFile(szFilters, GetIEditor()->GetLevelFolder(), fileName)) - { - XmlNodeRef root = GetISystem()->LoadXmlFromFile(fileName.toStdString().c_str()); - if (root) - { - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - float fTime = GetTime(); - pTimeOfDay->Serialize(root, true); - pTimeOfDay->SetTime(fTime, true); - - UpdateValues(); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnExport() -{ - char szFilters[] = "Time Of Day Settings (*.xml)"; - QString fileName; - if (CFileUtil::SelectSaveFile(szFilters, "xml", GetIEditor()->GetLevelFolder(), fileName)) - { - // Write the light settings into the archive - XmlNodeRef node = XmlHelpers::CreateXmlNode("TimeOfDay"); - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - pTimeOfDay->Serialize(node, false); - XmlHelpers::SaveXmlNode(GetIEditor()->GetFileUtil(), node, fileName.toStdString().c_str()); - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnExpandAll() -{ - m_ui->parameters->ExpandAll(); - m_pHDRPane->properties().ExpandAll(); -} -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnResetToDefaultValues() -{ - auto answer = QMessageBox::question(QApplication::activeWindow(), "Reset Values", "Are you sure you want to reset all values to their default values?"); - - if (answer == QMessageBox::Yes) - { - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - - // Load the default time of day settings and use those to reset the time of day. - XmlNodeRef root = GetISystem()->LoadXmlFromFile("default_time_of_day.xml"); - if (root) - { - pTimeOfDay->Serialize(root, true); - } - else - { - QMessageBox::warning(QApplication::activeWindow(), "Reset Values", "Unable to read default time of day file (Editor/default_time_of_day.xml), initializing variables to default values.", QMessageBox::Ok); - - // If for some reason the file is missing or corrupted, recreate the variables with their default states. - // Note that these variables may be out of sync with the default_time_of_day.xml file. - pTimeOfDay->ResetVariables(); - } - - ITimeOfDay::SAdvancedInfo advInfo; - pTimeOfDay->GetAdvancedInfo(advInfo); - SetTimeRange(advInfo.fStartTime, advInfo.fEndTime, advInfo.fAnimSpeed); - RefreshPropertiesValues(); - - m_pHDRPane->properties().ClearSelection(); - ReflectedPropertyItem* selectedItem = m_ui->parameters->GetSelectedItem(); - if (selectedItem) - { - IVariable* var = selectedItem->GetVariable(); - if (var) - { - ResetSpline(var); - } - } - } -} -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnCollapseAll() -{ - m_ui->parameters->CollapseAll(); - m_pHDRPane->properties().CollapseAll(); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnUpdateProperties(IVariable* pVar) -{ - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - - int nIndex = -1; - if (pVar) - { - nIndex = pVar->GetUserData().toInt(); - } - - if (nIndex != -1) - { - ITimeOfDay::SVariableInfo varInfo; - if (pTimeOfDay->GetVariableInfo(nIndex, varInfo)) - { - float fTime = GetTime(); - float fSplineTime = fTime / m_maxTime; - - const float cNearestKeySearchEpsilon = 0.00001f; - int nKey = varInfo.pInterpolator->FindKey(fSplineTime, cNearestKeySearchEpsilon); - int nLastKey = varInfo.pInterpolator->GetKeyCount() - 1; - - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoTimeOfDayObject()); - } - - switch (varInfo.type) - { - case ITimeOfDay::TYPE_FLOAT: - { - float fVal = 0; - pVar->Get(fVal); - if (m_ui->actionStartStopRecording->isChecked()) - { - if (nKey < 0) - { - nKey = varInfo.pInterpolator->InsertKeyFloat(fSplineTime, fVal); - } - else - { - varInfo.pInterpolator->SetKeyValueFloat(nKey, fVal); - if (nKey == 0) - { - varInfo.pInterpolator->SetKeyValueFloat(nLastKey, fVal); - } - else if (nKey == nLastKey) - { - varInfo.pInterpolator->SetKeyValueFloat(0, fVal); - } - } - if (m_ui->spline && m_ui->spline->GetDefaultKeyTangentType() != SPLINE_KEY_TANGENT_NONE) - { - TimeOfDayDetails::SetKeyTangentType(varInfo.pInterpolator, nKey, m_ui->spline->GetDefaultKeyTangentType()); - } - } - - float v3[3] = {fVal, varInfo.fValue[1], varInfo.fValue[2]}; - pTimeOfDay->SetVariableValue(nIndex, v3); - } - break; - case ITimeOfDay::TYPE_COLOR: - { - Vec3 vVal; - pVar->Get(vVal); - float v3[3] = {vVal.x, vVal.y, vVal.z}; - if (m_ui->actionStartStopRecording->isChecked()) - { - if (nKey < 0) - { - nKey = varInfo.pInterpolator->InsertKeyFloat3(fSplineTime, v3); - } - else - { - varInfo.pInterpolator->SetKeyValueFloat3(nKey, v3); - if (nKey == 0) - { - varInfo.pInterpolator->SetKeyValueFloat3(nLastKey, v3); - } - else if (nKey == nLastKey) - { - varInfo.pInterpolator->SetKeyValueFloat3(0, v3); - } - } - if (m_ui->spline && m_ui->spline->GetDefaultKeyTangentType() != SPLINE_KEY_TANGENT_NONE) - { - TimeOfDayDetails::SetKeyTangentType(varInfo.pInterpolator, nKey, m_ui->spline->GetDefaultKeyTangentType()); - } - } - pTimeOfDay->SetVariableValue(nIndex, v3); - - m_ui->colorGradient->update(); - } - break; - } - - if (m_ui->spline) - { - m_ui->spline->update(); - } - - if (varInfo.nParamId == ITimeOfDay::PARAM_HDR_FILMCURVE_SHOULDER_SCALE - || varInfo.nParamId == ITimeOfDay::PARAM_HDR_FILMCURVE_LINEAR_SCALE - || varInfo.nParamId == ITimeOfDay::PARAM_HDR_FILMCURVE_TOE_SCALE - || varInfo.nParamId == ITimeOfDay::PARAM_HDR_FILMCURVE_WHITEPOINT) - { - m_pHDRPane->UpdateFilmCurve(); - } - - bool bForceUpdate = m_ui->forceSkyUpdateCheckBox->isChecked(); - pTimeOfDay->Update(false, bForceUpdate); - - GetIEditor()->Notify(eNotify_OnTimeOfDayChange); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnPropertySelected(IVariable *pVar) -{ - if (pVar) - { - m_pHDRPane->properties().ClearSelection(); - } - - if (pVar && pVar->GetType() == IVariable::ARRAY) - { - pVar = nullptr; - } - - ResetSpline(pVar); -} - - -void CTimeOfDayDialog::ResetSpline(IVariable* pVar) -{ - if (pVar) - { - ITimeOfDay* pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay(); - ITimeOfDay::SVariableInfo varInfo; - int index = pVar->GetUserData().toInt(); - if (!pTimeOfDay->GetVariableInfo(index, varInfo)) - { - return; - } - - m_ui->spline->SetTimeRange(Range(0, 1.0f)); - m_ui->spline->RemoveAllSplines(); - - if (varInfo.type == ITimeOfDay::TYPE_COLOR) - { - QColor afColorArray[4]; - afColorArray[0] = QColor(255, 0, 0); - afColorArray[1] = QColor(0, 255, 0); - afColorArray[2] = QColor(0, 0, 255); - afColorArray[3] = QColor(255, 0, 255); //Pink... so you know it's wrong if you see it. - m_ui->spline->AddSpline(varInfo.pInterpolator, 0, afColorArray); - m_ui->spline->SetValueRange(Range(0, 1)); - - m_ui->colorGradient->SetSpline(varInfo.pInterpolator, TRUE); - m_ui->colorGradient->setEnabled(true); - m_ui->colorGradient->update(); - } - else - { - m_ui->colorGradient->setEnabled(false); - m_ui->colorGradient->SetSpline(0); - m_ui->colorGradient->update(); - - m_ui->spline->SetValueRange(Range(varInfo.fValue[1], varInfo.fValue[2])); - m_ui->spline->AddSpline(varInfo.pInterpolator, 0, QColor(0, 255, 0)); - } - m_ui->spline->SetSplineSet(0); - m_ui->spline->FitSplineToViewWidth(); - m_ui->spline->FitSplineHeightToValueRange(); - } - else - { - m_ui->spline->RemoveAllSplines(); - m_ui->colorGradient->setEnabled(false); - m_ui->colorGradient->SetSpline(0); - } - m_ui->spline->update(); -} - - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnHold() -{ - XmlNodeRef node = XmlHelpers::CreateXmlNode("TimeOfDay"); - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(node, false); - node->saveToFile((Path::GetUserSandboxFolder() + "TimeOfDayHold.xml").toUtf8().data()); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnFetch() -{ - XmlNodeRef node = XmlHelpers::LoadXmlFromFile((Path::GetUserSandboxFolder() + "TimeOfDayHold.xml").toUtf8().data()); - if (node) - { - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(node, true); - UpdateValues(); - UpdateUI(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnUndo() -{ - GetIEditor()->Undo(); - m_ui->spline->update(); - m_ui->colorGradient->update(); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::OnRedo() -{ - GetIEditor()->Redo(); - m_ui->spline->update(); - m_ui->colorGradient->update(); -} - -////////////////////////////////////////////////////////////////////////// -IVariable* CTimeOfDayDialog::FindVariable(const char* name) const -{ - IVariable* pVar = m_pVars->FindVariable(name); - if (!pVar) - { - pVar = m_pHDRPane->variables()->FindVariable(name); - } - - return pVar; -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::CopyAllProperties() -{ - CClipboard clipboard(this); - XmlNodeRef collectionNode = XmlHelpers::CreateXmlNode("PropertyCtrls"); - - ReflectedPropertyItem* pRoot = m_ui->parameters->GetRootItem(); - if (pRoot) // Main properties - { - XmlNodeRef rootNode = collectionNode->newChild("PropertyCtrl"); - for (int i = 0; i < pRoot->GetChildCount(); ++i) - { - m_ui->parameters->CopyItem(rootNode, pRoot->GetChild(i), true); - } - } - - pRoot = m_pHDRPane->properties().GetRootItem(); - if (pRoot) // HDR properties - { - XmlNodeRef rootNode = collectionNode->newChild("PropertyCtrl"); - for (int i = 0; i < pRoot->GetChildCount(); ++i) - { - m_pHDRPane->properties().CopyItem(rootNode, pRoot->GetChild(i), true); - } - } - - clipboard.Put(collectionNode); -} - -////////////////////////////////////////////////////////////////////////// -void CTimeOfDayDialog::PasteAllProperties() -{ - CClipboard clipboard(this); - CUndo undo("Paste Properties"); - - XmlNodeRef collectionNode = clipboard.Get(); - if (collectionNode != NULL && collectionNode->isTag("PropertyCtrls") - && collectionNode->getChildCount() == 2) - { - // Main properties - XmlNodeRef rootNode = collectionNode->getChild(0); - m_ui->parameters->SetValuesFromNode(rootNode); - - // HDR properties - rootNode = collectionNode->getChild(1); - m_pHDRPane->properties().SetValuesFromNode(rootNode); - } -} - -void CTimeOfDayDialog::SignalNumUndoRedo(const unsigned int& numUndo, const unsigned int& numRedo) -{ - m_ui->actionUndo->setEnabled(numUndo > 0); - m_ui->actionRedo->setEnabled(numRedo > 0); -} - -void CTimeOfDayDialog::resizeEvent([[maybe_unused]] QResizeEvent* event) -{ - if (m_ui->spline->GetSplineCount() == 0) - { - m_ui->spline->FitSplineToViewWidth(); - m_ui->spline->FitSplineToViewHeight(); - } -} - -CUndoTimeOfDayObject::CUndoTimeOfDayObject() -{ - m_undo = XmlHelpers::CreateXmlNode("Undo"); - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_undo, false); -} - -void CUndoTimeOfDayObject::Undo(bool bUndo) -{ - if (bUndo) - { - m_redo = XmlHelpers::CreateXmlNode("Redo"); - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_redo, false); - } - - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_undo, true); - UpdateTimeOfDayDialog(); -} - -void CUndoTimeOfDayObject::Redo() -{ - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_redo, true); - UpdateTimeOfDayDialog(); -} - -void CUndoTimeOfDayObject::UpdateTimeOfDayDialog() -{ - CTimeOfDayDialog* targetDialog = FindViewPane(CTimeOfDayDialog::ClassName()); - if (targetDialog != nullptr) - { - targetDialog->UpdateValues(); - } -} - -#include diff --git a/Code/Sandbox/Editor/TimeOfDayDialog.h b/Code/Sandbox/Editor/TimeOfDayDialog.h deleted file mode 100644 index 8e9a9e92a8..0000000000 --- a/Code/Sandbox/Editor/TimeOfDayDialog.h +++ /dev/null @@ -1,182 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_TIMEOFDAYDIALOG_H -#define CRYINCLUDE_EDITOR_TIMEOFDAYDIALOG_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "Controls/TimelineCtrl.h" -#include -#include "Undo/IUndoManagerListener.h" -#include "LyViewPaneNames.h" -#include -#endif - -////////////////////////////////////////////////////////////////////////// - -class QResizeEvent; -class CCurveEditorCtrl; -class CHDRPane; - -namespace Ui { - class TimeOfDayDialog; -} - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -////////////////////////////////////////////////////////////////////////// -// Window that holds effector info. -////////////////////////////////////////////////////////////////////////// -class SANDBOX_API CTimeOfDayDialog - : public QMainWindow - , public IEditorNotifyListener - , public ISystemEventListener - , public IUndoManagerListener -{ -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING - Q_OBJECT -public: - static const char* ClassName() { return LyViewPane::TimeOfDayEditor; } - static const GUID& GetClassID(); - - CTimeOfDayDialog(QWidget* parent = nullptr); - ~CTimeOfDayDialog(); - - static void RegisterViewClass(); - void UpdateValues(); - - // overrides from ISystemEventListener - void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam) override; - -protected: - void OnBeforeSplineChange(); - void OnSplineChange(const QWidget* source); - void OnPlayAnimFrom0(); - void OnChangeTimeAnimSpeed(double speed); - - void OnImport(); - void OnExport(); - void OnExpandAll(); - void OnResetToDefaultValues(); - void OnCollapseAll(); - - void OnHold(); - void OnFetch(); - void OnUndo(); - void OnRedo(); - - void OnPropertySelected(IVariable* node); - void OnSplineCtrlScrollZoom(); - void OnTimelineCtrlChange(); - - void Init(); - - void OnUpdateProperties(IVariable* var); - - void CreateProperties(); - - void SetTime(float time); - void SetTimeRange(float fTimeStart, float fTimeEnd, float fSpeed); - float GetTime() const; - - void RefreshPropertiesValues(); - void ResetSpline(IVariable* var); - - IVariable* FindVariable(const char* name) const; - - void CopyAllProperties(); - void PasteAllProperties(); - - void HdrPropertySelected(IVariable* v); - void StartTimeChanged(const QTime& time); - void EndTimeChanged(const QTime& time); - - ////////////////////////////////////////////////////////////////////////// - // IEditorNotifyListener - ////////////////////////////////////////////////////////////////////////// - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event); - ////////////////////////////////////////////////////////////////////////// - - // IUndoManagerListener - void SignalNumUndoRedo(const unsigned int& numUndo, const unsigned int& numRedo) override; - - void resizeEvent(QResizeEvent* event) override; - -private: - void UpdateUI(bool updateProperties=true); - void SetTimeFromActiveKey(bool useColorGradient = false); - - bool m_alive = true; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - QScopedPointer m_ui; - - CHDRPane* m_pHDRPane; - CVarBlockPtr m_pVars; - - TimelineWidget* m_timelineCtrl; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - float m_maxTime; -}; - -class CHDRPane - : public QWidget -{ - Q_OBJECT -public: - CHDRPane(CTimeOfDayDialog* pTODDlg); - - ReflectedPropertyControl& properties() { return *m_propsCtrl; } - CVarBlockPtr variables() { return m_pVars; } - - void UpdateFilmCurve(); - -signals: - void propertySelected(IVariable* variable); - -protected: - bool Init(); - void OnPropertySelected(IVariable*); - - bool GetFilmCurveParams(float& shoulderScale, float& midScale, float& toeScale, float& whitePoint) const; - - CTimeOfDayDialog* m_pTODDlg; - CCurveEditorCtrl* m_filmCurveCtrl; - ReflectedPropertyControl* m_propsCtrl; - CVarBlockPtr m_pVars; -}; - -/** Undo object stored when track is modified. -*/ -class CUndoTimeOfDayObject - : public IUndoObject -{ -public: - CUndoTimeOfDayObject(); - -protected: - virtual int GetSize() { return sizeof(*this); } - virtual QString GetDescription() { return "Time of Day"; }; - - virtual void Undo(bool bUndo); - virtual void Redo(); - -private: - void UpdateTimeOfDayDialog(); - - XmlNodeRef m_undo; - XmlNodeRef m_redo; -}; - -#endif // CRYINCLUDE_EDITOR_TIMEOFDAYDIALOG_H diff --git a/Code/Sandbox/Editor/TimeOfDayDialog.ui b/Code/Sandbox/Editor/TimeOfDayDialog.ui deleted file mode 100644 index 35e8e483a0..0000000000 --- a/Code/Sandbox/Editor/TimeOfDayDialog.ui +++ /dev/null @@ -1,980 +0,0 @@ - - - TimeOfDayDialog - - - - 0 - 0 - 1073 - 600 - - - - MainWindow - - - QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks - - - - - 2 - - - - - - 1 - 0 - - - - - - - - 2 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Set In/Out Tangents to Auto - - - - - - - 18 - 18 - - - - true - - - - - - - Qt::Vertical - - - - - - - Set In Tangent to Zero - - - - - - - 18 - 18 - - - - true - - - - - - - Set In Tangent to Step - - - - - - - 18 - 18 - - - - true - - - - - - - Set In Tangent to Linear - - - - - - - 18 - 18 - - - - true - - - - - - - Qt::Vertical - - - - - - - Set Out Tangent to Zero - - - - - - - 18 - 18 - - - - true - - - - - - - Set Out Tangent to Step - - - - - - - 18 - 18 - - - - true - - - - - - - Set Out Tangent to Linear - - - - - - - 18 - 18 - - - - true - - - - - - - Qt::Vertical - - - - - - - Fit Splines to the Visible Width - - - - - - - 18 - 18 - - - - true - - - - - - - Fit Splines to the Visible Height - - - - - - - 18 - 18 - - - - true - - - - - - - Qt::Vertical - - - - - - - Snap to time grid - - - - 18 - 18 - - - - true - - - true - - - - - - - Snap to value grid - - - - 18 - 18 - - - - true - - - true - - - - - - - Qt::Vertical - - - - - - - Previous Key - - - - - - - 18 - 18 - - - - true - - - - - - - Qt::Vertical - - - - - - - Next Key - - - - - - - 18 - 18 - - - - true - - - - - - - Remove all Keys BUT This - - - - - - - 18 - 18 - - - - true - - - - - - - Qt::Horizontal - - - - 69 - 20 - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 0 - 35 - - - - - - - - - - - - 1 - 1 - - - - - - - - - 0 - - - - - Timeline - - - - 6 - - - 0 - - - - - 23:59 - - - Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing - - - - - - - 00:00 - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - 12:00 - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - Qt::WheelFocus - - - 1439 - - - - - - - - - - - - - - - - - toolBar - - - - 32 - 32 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - - - - - - - - - - - - - 350 - 40 - - - - QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable - - - Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea - - - HDR Settings - - - 1 - - - - - 0 - 0 - - - - - 150 - 0 - - - - - - - - - 0 - 0 - - - - - 450 - 50 - - - - QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable - - - Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea - - - Parameters - - - 2 - - - - - - - - 0 - 0 - - - - - 200 - 0 - - - - - - - - - - QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable - - - Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea - - - Time of Day Tasks - - - 1 - - - - - - - - 0 - 0 - - - - - 0 - - - - - Tasks - - - - - - Import From File - - - - - - - Export To File - - - - - - - Reset Values - - - - - - - Expand All - - - - - - - Collapse All - - - - - - - - - - Time - - - - - - Current Time - - - currentTimeEdit - - - - - - - - - - Start Time - - - startTimeEdit - - - - - - - - - - End Time - - - endTimeEdit - - - - - - - - - - Play Speed - - - playSpeedDoubleSpinBox - - - - - - - 0.001000000000000 - - - - - - - - - - Update Tasks - - - - - - Play - - - - - - - Stop - - - - - - - Force sky update - - - true - - - - - - - - - - Qt::Vertical - - - - 20 - 139 - - - - - - - - - - - - - false - - - Undo - - - Undo - - - - - false - - - Redo - - - Redo - - - - - Import File - - - Import File - - - - - Export File - - - Export File - - - - - true - - - Play/Pause - - - Play/Pause - - - - - 00 - - - Set Time to 00:00 - - - - - 06 - - - Set Time to 06:00 - - - - - 12 - - - Set Time to 12:00 - - - - - 18 - - - Set Time to 18:00 - - - - - 24 - - - Set Time to 23:59 - - - - - true - - - true - - - Start/Stop Recording - - - Start/Stop Recording - - - - - Hold - - - Hold - - - - - Fetch - - - Fetch - - - - - - ReflectedPropertyControl - QWidget -
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.h
- 1 -
- - QCollapsibleGroupBox - QGroupBox -
QtUI/QCollapsibleGroupBox.h
- 1 -
- - ClickableLabel - QLabel -
QtUI/ClickableLabel.h
-
- - SplineWidget - QWidget -
Controls/SplineCtrlEx.h
- 1 -
- - CColorGradientCtrl - QWidget -
Controls/ColorGradientCtrl.h
- 1 -
- - AzQtComponents::DoubleSpinBox - QDoubleSpinBox -
AzQtComponents/Components/Widgets/SpinBox.h
-
- - TimeOfDaySlider - QWidget -
Controls/TimeOfDaySlider.h
- 1 -
-
- - timelineSlider - - - -
diff --git a/Code/Sandbox/Editor/ToolbarManager.cpp b/Code/Sandbox/Editor/ToolbarManager.cpp index 01bd7be82b..bbb3ef6790 100644 --- a/Code/Sandbox/Editor/ToolbarManager.cpp +++ b/Code/Sandbox/Editor/ToolbarManager.cpp @@ -16,7 +16,6 @@ // AzCore #include -#include #include // Qt diff --git a/Code/Sandbox/Editor/TrackView/TrackViewDialog.cpp b/Code/Sandbox/Editor/TrackView/TrackViewDialog.cpp index 06184c0fc3..0179b779e8 100644 --- a/Code/Sandbox/Editor/TrackView/TrackViewDialog.cpp +++ b/Code/Sandbox/Editor/TrackView/TrackViewDialog.cpp @@ -1505,12 +1505,6 @@ void CTrackViewDialog::OnEditorNotifyEvent(EEditorNotifyEvent event) m_bIgnoreUpdates = false; OnGameOrSimModeLock(false); break; - case eNotify_OnMissionChange: - if (!m_bIgnoreUpdates) - { - ReloadSequences(); - } - break; case eNotify_OnReloadTrackView: if (!m_bIgnoreUpdates) { diff --git a/Code/Sandbox/Editor/TrackView/TrackViewNodes.cpp b/Code/Sandbox/Editor/TrackView/TrackViewNodes.cpp index 3979bf3cca..0bde26edf1 100644 --- a/Code/Sandbox/Editor/TrackView/TrackViewNodes.cpp +++ b/Code/Sandbox/Editor/TrackView/TrackViewNodes.cpp @@ -832,32 +832,7 @@ void CTrackViewNodesCtrl::UpdateAnimNodeRecord(CRecord* record, CTrackViewAnimNo } else if (nodeType == AnimNodeType::Material) { - // Check if a valid material can be found by the node name. - _smart_ptr pMaterial = nullptr; - QString matName; - int subMtlIndex = GetMatNameAndSubMtlIndexFromName(matName, animNode->GetName()); - pMaterial = gEnv->p3DEngine->GetMaterialManager()->FindMaterial(matName.toUtf8().data()); - if (pMaterial) - { - bool bMultiMat = pMaterial->GetSubMtlCount() > 0; - bool bMultiMatWithoutValidIndex = bMultiMat && (subMtlIndex < 0 || subMtlIndex >= pMaterial->GetSubMtlCount()); - bool bLeafMatWithIndex = !bMultiMat && subMtlIndex != -1; - if (bMultiMatWithoutValidIndex || bLeafMatWithIndex) - { - pMaterial = nullptr; - } - } - - if (!pMaterial) - { - record->setForeground(0, TextColorForInvalidMaterial); - } - else - { - // set to default color from palette - // materials that originally pointed to material groups and are changed to sub-materials need this to reset their color - record->setForeground(0, palette().color(foregroundRole())); - } + record->setForeground(0, TextColorForInvalidMaterial); } // Mark the active director and other directors properly. @@ -2163,43 +2138,6 @@ int CTrackViewNodesCtrl::ShowPopupMenuSingleSelection(SContextMenu& contextMenu, bAppended = true; } - // Sub material menu - if (bOnNode && animNode->GetType() == AnimNodeType::Material) - { - QString matName; - int subMtlIndex = GetMatNameAndSubMtlIndexFromName(matName, animNode->GetName()); - _smart_ptr pMtl = gEnv->p3DEngine->GetMaterialManager()->FindMaterial(matName.toUtf8().data()); - bool bMultMatNode = pMtl ? pMtl->GetSubMtlCount() > 0 : false; - - bool bMatAppended = false; - - if (bMultMatNode) - { - for (int k = 0; k < pMtl->GetSubMtlCount(); ++k) - { - _smart_ptr pSubMaterial = pMtl->GetSubMtl(k); - - if (pSubMaterial) - { - QString subMaterialName = pSubMaterial->GetName(); - - if (!subMaterialName.isEmpty()) - { - AddMenuSeperatorConditional(contextMenu.main, bAppended); - QString subMatName = QString("[%1] %2").arg(k + 1).arg(subMaterialName); - QAction* a = contextMenu.main.addAction(subMatName); - a->setData(eMI_SelectSubmaterialBase + k); - a->setCheckable(true); - a->setChecked(k == subMtlIndex); - bMatAppended = true; - } - } - } - } - - bAppended = bAppended || bMatAppended; - } - // Delete track menu if (bOnTrackNotSub) { diff --git a/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp b/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp index 12f38c920a..0ba7c5b325 100644 --- a/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp +++ b/Code/Sandbox/Editor/TrackView/TrackViewSequenceManager.cpp @@ -27,7 +27,6 @@ #include "AnimationContext.h" #include "GameEngine.h" #include "Include/IObjectManager.h" -#include "Material/MaterialManager.h" #include "Objects/ObjectManager.h" @@ -35,7 +34,6 @@ CTrackViewSequenceManager::CTrackViewSequenceManager() { GetIEditor()->RegisterNotifyListener(this); - GetIEditor()->GetMaterialManager()->AddListener(this); AZ::EntitySystemBus::Handler::BusConnect(); } @@ -45,7 +43,6 @@ CTrackViewSequenceManager::~CTrackViewSequenceManager() { AZ::EntitySystemBus::Handler::BusDisconnect(); - GetIEditor()->GetMaterialManager()->RemoveListener(this); GetIEditor()->UnregisterNotifyListener(this); } diff --git a/Code/Sandbox/Editor/Util/CubemapUtils.cpp b/Code/Sandbox/Editor/Util/CubemapUtils.cpp index a143b7e5ce..bd650abaa8 100644 --- a/Code/Sandbox/Editor/Util/CubemapUtils.cpp +++ b/Code/Sandbox/Editor/Util/CubemapUtils.cpp @@ -30,6 +30,7 @@ #include "Util/ImageTIF.h" #include "Objects/BaseObject.h" +#include class CubemapSizeModel : public QAbstractListModel diff --git a/Code/Sandbox/Editor/Util/FileUtil.cpp b/Code/Sandbox/Editor/Util/FileUtil.cpp index fc5eca1952..8dd379f096 100644 --- a/Code/Sandbox/Editor/Util/FileUtil.cpp +++ b/Code/Sandbox/Editor/Util/FileUtil.cpp @@ -2088,7 +2088,6 @@ void CFileUtil::GatherAssetFilenamesFromLevel(std::set& rOutFilenames, rOutFilenames.clear(); CBaseObjectsArray objArr; CUsedResources usedRes; - IMaterialManager* pMtlMan = GetIEditor()->Get3DEngine()->GetMaterialManager(); GetIEditor()->GetObjectManager()->GetObjects(objArr); @@ -2116,66 +2115,6 @@ void CFileUtil::GatherAssetFilenamesFromLevel(std::set& rOutFilenames, rOutFilenames.insert(tmpStr); } } - - uint32 mtlCount = 0; - - pMtlMan->GetLoadedMaterials(NULL, mtlCount); - - if (mtlCount > 0) - { - AZStd::vector<_smart_ptr> arrMtls; - - arrMtls.resize(mtlCount); - pMtlMan->GetLoadedMaterials(&arrMtls, mtlCount); - - for (size_t i = 0; i < mtlCount; ++i) - { - _smart_ptr pMtl = arrMtls[i]; - - size_t subMtls = pMtl->GetSubMtlCount(); - - // for the main material - IRenderShaderResources* pShaderRes = pMtl->GetShaderItem().m_pShaderResources; - - // add the material filename - rOutFilenames.insert(pMtl->GetName()); - - if (pShaderRes) - { - for ( auto iter= pShaderRes->GetTexturesResourceMap()->begin() ; - iter!= pShaderRes->GetTexturesResourceMap()->end() ; ++iter ) - { - SEfResTexture* pTex = &(iter->second); - // add the texture filename - rOutFilenames.insert(pTex->m_Name.c_str()); - } - } - - // for the submaterials - for (size_t s = 0; s < subMtls; ++s) - { - _smart_ptr pSubMtl = pMtl->GetSubMtl(s); - - // fill up dependencies - if (pSubMtl) - { - IRenderShaderResources* pShaderRes2 = pSubMtl->GetShaderItem().m_pShaderResources; - - rOutFilenames.insert(pSubMtl->GetName()); - - if (pShaderRes2) - { - for (auto iter = pShaderRes2->GetTexturesResourceMap()->begin(); - iter != pShaderRes2->GetTexturesResourceMap()->end(); ++iter) - { - SEfResTexture* pTex = &(iter->second); - rOutFilenames.insert(pTex->m_Name.c_str()); - } - } - } - } - } - } } uint32 CFileUtil::GetAttributes(const char* filename, bool bUseSourceControl /*= true*/) diff --git a/Code/Sandbox/Editor/Util/KDTree.cpp b/Code/Sandbox/Editor/Util/KDTree.cpp index b407305a93..71ec798005 100644 --- a/Code/Sandbox/Editor/Util/KDTree.cpp +++ b/Code/Sandbox/Editor/Util/KDTree.cpp @@ -14,6 +14,8 @@ #include "KDTree.h" +#include + class KDTreeNode { public: diff --git a/Code/Sandbox/Editor/Util/Variable.h b/Code/Sandbox/Editor/Util/Variable.h index ab43d24e94..d00ef6103a 100644 --- a/Code/Sandbox/Editor/Util/Variable.h +++ b/Code/Sandbox/Editor/Util/Variable.h @@ -152,7 +152,7 @@ struct IVariable DT_LOCAL_STRING, DT_EQUIP, DT_REVERBPRESET, - DT_MATERIAL, + DT_DEPRECATED0, // formerly DT_MATERIAL DT_MATERIALLOOKUP, DT_EXTARRAY, // Extendable Array DT_SEQUENCE, // Movie Sequence (DEPRECATED, use DT_SEQUENCE_ID, instead.) @@ -163,7 +163,7 @@ struct IVariable DT_LIGHT_ANIMATION, // Light Animation Node in the global Light Animation Set DT_PARTICLE_EFFECT, DT_GEOM_CACHE, // Geometry cache - DT_FLARE, + DT_DEPRECATED, // formerly DT_FLARE DT_AUDIO_TRIGGER, DT_AUDIO_SWITCH, DT_AUDIO_SWITCH_STATE, diff --git a/Code/Sandbox/Editor/Util/VariablePropertyType.cpp b/Code/Sandbox/Editor/Util/VariablePropertyType.cpp index 5a3029807b..c7fd3d9de2 100644 --- a/Code/Sandbox/Editor/Util/VariablePropertyType.cpp +++ b/Code/Sandbox/Editor/Util/VariablePropertyType.cpp @@ -49,7 +49,7 @@ namespace Prop { IVariable::DT_SIMPLE, "Selection", ePropertySelection, -1 }, { IVariable::DT_SIMPLE, "List", ePropertyList, -1 }, { IVariable::DT_SHADER, "Shader", ePropertyShader, 9 }, - { IVariable::DT_MATERIAL, "Material", ePropertyMaterial, 14 }, + { IVariable::DT_DEPRECATED0, "DEPRECATED", ePropertyDeprecated2, -1 }, { IVariable::DT_EQUIP, "Equip", ePropertyEquip, 11 }, { IVariable::DT_REVERBPRESET, "ReverbPreset", ePropertyReverbPreset, 11 }, { IVariable::DT_LOCAL_STRING, "LocalString", ePropertyLocalString, 3 }, @@ -58,7 +58,6 @@ namespace Prop { IVariable::DT_USERITEMCB, "User", ePropertyUser, -1 }, { IVariable::DT_SEQUENCE_ID, "SequenceId", ePropertySequenceId, -1 }, { IVariable::DT_LIGHT_ANIMATION, "LightAnimation", ePropertyLightAnimation, -1 }, - { IVariable::DT_FLARE, "Flare", ePropertyFlare, 7 }, { IVariable::DT_PARTICLE_EFFECT, "ParticleEffect", ePropertyParticleName, 3 }, { IVariable::DT_GEOM_CACHE, "Geometry Cache", ePropertyGeomCache, 5 }, { IVariable::DT_AUDIO_TRIGGER, "Audio Trigger", ePropertyAudioTrigger, 6 }, diff --git a/Code/Sandbox/Editor/Util/VariablePropertyType.h b/Code/Sandbox/Editor/Util/VariablePropertyType.h index 86fc8e9c0f..130148c903 100644 --- a/Code/Sandbox/Editor/Util/VariablePropertyType.h +++ b/Code/Sandbox/Editor/Util/VariablePropertyType.h @@ -39,7 +39,7 @@ enum PropertyType ePropertySelection, ePropertyList, ePropertyShader, - ePropertyMaterial, + ePropertyDeprecated2, // formerly ePropertyMaterial ePropertyEquip, ePropertyReverbPreset, ePropertyLocalString, @@ -50,7 +50,7 @@ enum PropertyType ePropertyUser, ePropertySequenceId, ePropertyLightAnimation, - ePropertyFlare, + ePropertyDeprecated1, // formerly ePropertyFlare ePropertyParticleName, ePropertyGeomCache, ePropertyAudioTrigger, diff --git a/Code/Sandbox/Editor/Util/VariableTypeInfo.cpp b/Code/Sandbox/Editor/Util/VariableTypeInfo.cpp deleted file mode 100644 index 61cdac53c6..0000000000 --- a/Code/Sandbox/Editor/Util/VariableTypeInfo.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "EditorDefs.h" - -#include "VariableTypeInfo.h" -#include "TypeInfo_impl.h" -#include "IShader_info.h" - -#ifndef AZ_MONOLITHIC_BUILD -#include "I3DEngine_info.h" -#endif - -#include "Variable.h" -#include "UIEnumsDatabase.h" - -// CryCommon -#include - - -IVariable* CVariableTypeInfo::Create(CTypeInfo::CVarInfo const& VarInfo, void* pAddress, const void* pAddressDefault) -{ - pAddress = VarInfo.GetAddress(pAddress); - pAddressDefault = VarInfo.GetAddress(pAddressDefault); - - EType eType = GetType(VarInfo.Type); - if (eType == ARRAY) - { - return new CVariableTypeInfoStruct(VarInfo, pAddress, pAddressDefault); - } - - if (VarInfo.Type.EnumElem(0)) - { - return new CVariableTypeInfoEnum(VarInfo, pAddress, pAddressDefault); - } - - ISplineInterpolator* pSpline = 0; - if (VarInfo.Type.ToValue(pAddress, pSpline)) - { - return new CVariableTypeInfoSpline(VarInfo, pAddress, pAddressDefault, pSpline); - } - - return new CVariableTypeInfo(VarInfo, pAddress, pAddressDefault, eType); -} - -CVariableTypeInfo::EType CVariableTypeInfo::GetType(CTypeInfo const& typeInfo) -{ - // Translation to editor type values is currently done with some clunky type and name testing. - if (typeInfo.HasSubVars()) - { - if (typeInfo.IsType() && !typeInfo.NextSubVar(0)->Type.IsType()) - { - // This is a vector type (and not a sub-classed vector type) - return IVariable::VECTOR; - } - else - { - return IVariable::ARRAY; - } - } - else if (typeInfo.IsType()) - { - return IVariable::BOOL; - } - else if (typeInfo.IsType() || typeInfo.IsType()) - { - return IVariable::INT; - } - else if (typeInfo.IsType()) - { - return IVariable::FLOAT; - } - return IVariable::STRING; -} - -CVariableTypeInfo::CVariableTypeInfo(CTypeInfo::CVarInfo const& VarInfo, - void* pAddress, const void* pAddressDefault, EType eType) - : m_pVarInfo(&VarInfo) - , m_pData(pAddress) - , m_pDefaultData(pAddressDefault) -{ - SetName(SpacedName(VarInfo.GetName())); - SetTypes(VarInfo.Type, eType); - SetFlags(IVariable::UI_UNSORTED | IVariable::UI_HIGHLIGHT_EDITED); - SetDescription(VarInfo.GetComment()); -} - -void CVariableTypeInfo::SetTypes(CTypeInfo const& TypeInfo, EType eType) -{ - m_pTypeInfo = &TypeInfo; - m_eType = eType; - - SetDataType(DT_SIMPLE); - if (m_eType == VECTOR) - { - if (m_name == "Color") - { - SetDataType(DT_COLOR); - } - } - else if (m_eType == STRING) - { - if (m_name == "Texture" || m_name == "Glow Map" || m_name == "Normal Map" || m_name == "Trail Fading") - { - SetDataType(DT_TEXTURE); - } - else if (m_name == "Material") - { - SetDataType(DT_MATERIAL); - } - else if (m_name == "Geometry") - { - SetDataType(DT_OBJECT); - } - else if (m_name == "Start Trigger" || m_name == "Stop Trigger") - { - SetDataType(DT_AUDIO_TRIGGER); - } - else if (m_name == "GeomCache") - { - SetDataType(DT_GEOM_CACHE); - } - } -} - -// IVariable implementation. -CVariableTypeInfo::EType CVariableTypeInfo::GetType() const -{ - return m_eType; -} - -int CVariableTypeInfo::GetSize() const -{ - return m_pTypeInfo->Size; -} - -void CVariableTypeInfo::GetLimits(float& fMin, float& fMax, float& fStep, bool& bHardMin, bool& bHardMax) -{ - // Get hard limits from variable type, or vector element type. - const CTypeInfo* pLimitType = m_pTypeInfo; - if ((m_eType == VECTOR || m_eType == VECTOR2) && m_pTypeInfo->NextSubVar(0)) - { - pLimitType = &m_pTypeInfo->NextSubVar(0)->Type; - } - bHardMin = pLimitType->GetLimit(eLimit_Min, fMin); - bHardMax = pLimitType->GetLimit(eLimit_Max, fMax); - pLimitType->GetLimit(eLimit_Step, fStep); - - // Check var attrs for additional limits. - if (m_pVarInfo->GetAttr("SoftMin", fMin)) - { - bHardMin = false; - } - else if (m_pVarInfo->GetAttr("Min", fMin)) - { - bHardMin = true; - } - - if (m_pVarInfo->GetAttr("SoftMax", fMax)) - { - bHardMax = false; - } - else if (m_pVarInfo->GetAttr("Max", fMax)) - { - bHardMax = true; - } -} - -void CVariableTypeInfo::Set(const char* value) -{ - m_pTypeInfo->FromString(m_pData, value); - OnSetValue(false); -} - -void CVariableTypeInfo::Set(const QString& value) -{ - Set(value.toUtf8().data()); -} - -void CVariableTypeInfo::Set(float value) -{ - m_pTypeInfo->FromValue(m_pData, value); - OnSetValue(false); -} - -void CVariableTypeInfo::Set(int value) -{ - m_pTypeInfo->FromValue(m_pData, value); - OnSetValue(false); -} - -void CVariableTypeInfo::Set(bool value) -{ - m_pTypeInfo->FromValue(m_pData, value); - OnSetValue(false); -} - -void CVariableTypeInfo::Set(const Vec2& value) -{ - m_pTypeInfo->FromValue(m_pData, value); - OnSetValue(false); -} - -void CVariableTypeInfo::Set(const Vec3& value) -{ - m_pTypeInfo->FromValue(m_pData, value); - OnSetValue(false); -} - -void CVariableTypeInfo::Get(QString& value) const -{ - value = (const char*)m_pTypeInfo->ToString(m_pData); -} - -void CVariableTypeInfo::Get(float& value) const -{ - m_pTypeInfo->ToValue(m_pData, value); -} - -void CVariableTypeInfo::Get(int& value) const -{ - m_pTypeInfo->ToValue(m_pData, value); -} - -void CVariableTypeInfo::Get(bool& value) const -{ - m_pTypeInfo->ToValue(m_pData, value); -} - -void CVariableTypeInfo::Get(Vec2& value) const -{ - m_pTypeInfo->ToValue(m_pData, value); -} - -void CVariableTypeInfo::Get(Vec3& value) const -{ - m_pTypeInfo->ToValue(m_pData, value); -} - -bool CVariableTypeInfo::HasDefaultValue() const -{ - return m_pTypeInfo->ValueEqual(m_pData, m_pDefaultData); -} - -void CVariableTypeInfo::ResetToDefault() -{ - QString strVal = m_pTypeInfo->ToString(m_pDefaultData).c_str(); - Set(strVal); -} - -IVariable* CVariableTypeInfo::Clone([[maybe_unused]] bool bRecursive) const -{ - // Simply use a string var for universal conversion. - IVariable* pClone = new CVariable(); - QString str; - Get(str); - pClone->Set(str); - - //add extra information for the clone: Name, DataType - pClone->SetName(GetName()); - pClone->SetDataType(GetDataType()); - //use UserData to save eType since String Variable's GetType always return STRING - pClone->SetUserData(GetType()); - - return pClone; -} - -void CVariableTypeInfo::CopyValue(IVariable* fromVar) -{ - assert(fromVar); - QString str; - fromVar->Get(str); - Set(str); -} - -CVariableTypeInfoEnum::CTypeInfoEnumList::CTypeInfoEnumList(CTypeInfo const& info) - : TypeInfo(info) -{ -} - -QString CVariableTypeInfoEnum::CTypeInfoEnumList::GetItemName(uint index) -{ - return TypeInfo.EnumElem(index); -} - -CVariableTypeInfoEnum::CVariableTypeInfoEnum(CTypeInfo::CVarInfo const& VarInfo, - void* pAddress, const void* pAddressDefault, IVarEnumList* pEnumList) - : CVariableTypeInfo(VarInfo, pAddress, pAddressDefault, UNKNOWN) -{ - // Use custom enum, or enum defined in TypeInfo. - m_enumList = pEnumList ? pEnumList : new CTypeInfoEnumList(VarInfo.Type); -} - -IVarEnumList* CVariableTypeInfoEnum::GetEnumList() const -{ - return m_enumList; -} - -CVariableTypeInfoSpline::CVariableTypeInfoSpline(CTypeInfo::CVarInfo const& VarInfo, - void* pAddress, const void* pAddressDefault, ISplineInterpolator* pSpline) - : CVariableTypeInfo(VarInfo, pAddress, pAddressDefault, STRING) - , m_pSpline(pSpline) -{ - if (m_pSpline && m_pSpline->GetNumDimensions() == 3) - { - SetDataType(DT_CURVE | DT_COLOR); - } - else - { - SetDataType(DT_CURVE | DT_PERCENT); - } -} - -CVariableTypeInfoSpline::~CVariableTypeInfoSpline() -{ - delete m_pSpline; -} - -ISplineInterpolator* CVariableTypeInfoSpline::GetSpline() -{ - //if m_pSpline wasn't created or the data used to create spline was changed, we need create the m_pSpline - int flags = GetFlags(); - if (m_pSpline == nullptr || flags & UI_CREATE_SPLINE) - { - if (m_pSpline != nullptr) - { - delete m_pSpline; - m_pSpline = nullptr; - } - m_pTypeInfo->ToValue(m_pData, m_pSpline); - flags &= ~UI_CREATE_SPLINE; - SetFlags(flags); - } - return m_pSpline; -} - -void CVariableTypeInfoSpline::OnSetValue(bool bRecursive) -{ - m_pTypeInfo->ToValue(m_pData, m_pSpline); - CVariableTypeInfo::OnSetValue(bRecursive); -} - -CVariableTypeInfoStruct::CVariableTypeInfoStruct(CTypeInfo::CVarInfo const& VarInfo, - void* pAddress, const void* pAddressDefault) - : CVariableTypeInfo(VarInfo, pAddress, pAddressDefault, ARRAY) -{ - ProcessSubStruct(VarInfo, pAddress, pAddressDefault); -} - -void CVariableTypeInfoStruct::ProcessSubStruct(CTypeInfo::CVarInfo const& VarInfo, void* pAddress, const void* pAddressDefault) -{ - for AllSubVars(pSubVar, VarInfo.Type) - { - if (!*pSubVar->GetName()) - { - EType eType = GetType(pSubVar->Type); - if (eType == ARRAY) - { - // Recursively process nameless or base struct. - ProcessSubStruct(*pSubVar, pSubVar->GetAddress(pAddress), pSubVar->GetAddress(pAddressDefault)); - } - else if (pSubVar == VarInfo.Type.NextSubVar(0)) - { - // Inline edit first sub-var in main field. - SetTypes(pSubVar->Type, eType); - } - } - else - { - IVariable* pVar = CVariableTypeInfo::Create(*pSubVar, pAddress, pAddressDefault); - m_Vars.push_back(pVar); - } - } -} - -QString CVariableTypeInfoStruct::GetDisplayValue() const -{ - return (const char*)m_pTypeInfo->ToString(m_pData); -} - -void CVariableTypeInfoStruct::OnSetValue(bool bRecursive) -{ - CVariableBase::OnSetValue(bRecursive); - if (bRecursive) - { - for (Vars::iterator it = m_Vars.begin(); it != m_Vars.end(); ++it) - { - (*it)->OnSetValue(true); - } - } -} - -void CVariableTypeInfoStruct::SetFlagRecursive(EFlags flag) -{ - CVariableBase::SetFlagRecursive(flag); - for (Vars::iterator it = m_Vars.begin(); it != m_Vars.end(); ++it) - { - (*it)->SetFlagRecursive(flag); - } -} - -void CVariableTypeInfoStruct::CopyValue(IVariable* fromVar) -{ - assert(fromVar); - if (fromVar->GetType() != IVariable::ARRAY) - { - CVariableTypeInfo::CopyValue(fromVar); - } - - int numSrc = fromVar->GetNumVariables(); - int numTrg = m_Vars.size(); - for (int i = 0; i < numSrc && i < numTrg; i++) - { - // Copy Every child variable. - m_Vars[i]->CopyValue(fromVar->GetVariable(i)); - } -} - -int CVariableTypeInfoStruct::GetNumVariables() const -{ - return m_Vars.size(); -} - -IVariable* CVariableTypeInfoStruct::GetVariable(int index) const -{ - return m_Vars[index]; -} - -CUIEnumsDBList::CUIEnumsDBList(CUIEnumsDatabase_SEnum const* pEnumList) - : m_pEnumList(pEnumList) -{ -} - -QString CUIEnumsDBList::GetItemName(uint index) -{ - if (index >= m_pEnumList->strings.size()) - { - return NULL; - } - return m_pEnumList->strings[index]; -} diff --git a/Code/Sandbox/Editor/Util/VariableTypeInfo.h b/Code/Sandbox/Editor/Util/VariableTypeInfo.h deleted file mode 100644 index 1e36d1ca96..0000000000 --- a/Code/Sandbox/Editor/Util/VariableTypeInfo.h +++ /dev/null @@ -1,221 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_UTIL_VARIABLETYPEINFO_H -#define CRYINCLUDE_EDITOR_UTIL_VARIABLETYPEINFO_H -#pragma once - -#include "Variable.h" -#include "UIEnumsDatabase.h" -#include "VariableTypeInfo.h" - -#include - -////////////////////////////////////////////////////////////////////////// -// Adaptors for TypeInfo-defined variables to IVariable - -inline QString SpacedName(const char* sName) -{ - // Split name with spaces. - QString sSpacedName = sName; - for (int i = 1; i < sSpacedName.length(); i++) - { - if (sSpacedName[i].isUpper() && sSpacedName[i - 1].isLower()) - { - sSpacedName.insert(i, ' '); - i++; - } - } - return sSpacedName; -} - -////////////////////////////////////////////////////////////////////////// -// Scalar variable -////////////////////////////////////////////////////////////////////////// - -class EDITOR_CORE_API CVariableTypeInfo - : public CVariableBase -{ -public: - // Dynamic constructor function - static IVariable* Create(CTypeInfo::CVarInfo const& VarInfo, void* pBaseAddress, const void* pBaseAddressDefault); - - static EType GetType(CTypeInfo const& TypeInfo); - - CVariableTypeInfo(CTypeInfo::CVarInfo const& VarInfo, void* pAddress, const void* pAddressDefault, EType eType); - - void SetTypes(CTypeInfo const& TypeInfo, EType eType); - - // IVariable implementation. - virtual EType GetType() const; - virtual int GetSize() const; - - virtual void GetLimits(float& fMin, float& fMax, float& fStep, bool& bHardMin, bool& bHardMax); - - ////////////////////////////////////////////////////////////////////////// - // Access operators. - ////////////////////////////////////////////////////////////////////////// - - virtual void Set(const char* value); - - virtual void Set(const QString& value); - - virtual void Set(float value); - - virtual void Set(int value); - - virtual void Set(bool value); - - virtual void Set(const Vec2& value); - - virtual void Set(const Vec3& value); - - virtual void Get(QString& value) const; - - virtual void Get(float& value) const; - - virtual void Get(int& value) const; - - virtual void Get(bool& value) const; - - virtual void Get(Vec2& value) const; - - virtual void Get(Vec3& value) const; - - virtual bool HasDefaultValue() const; - - virtual void ResetToDefault(); - - virtual IVariable* Clone(bool bRecursive) const; - - // To do: This could be more efficient ? - virtual void CopyValue(IVariable* fromVar); - -protected: - CTypeInfo::CVarInfo const* m_pVarInfo; - CTypeInfo const* m_pTypeInfo; // TypeInfo system structure for this var. - void* m_pData; // Existing address in memory. Directly modified. - const void* m_pDefaultData; // Address of default data for this var. - EType m_eType; // Type info for editor. - IEditor* m_pEditor; -}; - -////////////////////////////////////////////////////////////////////////// -// Enum variable -////////////////////////////////////////////////////////////////////////// - -class EDITOR_CORE_API CVariableTypeInfoEnum - : public CVariableTypeInfo -{ - struct CTypeInfoEnumList - : IVarEnumList - { - CTypeInfo const& TypeInfo; - - CTypeInfoEnumList(CTypeInfo const& info); - - virtual QString GetItemName(uint index); - }; - -public: - - // Constructor. - CVariableTypeInfoEnum(CTypeInfo::CVarInfo const& VarInfo, void* pAddress, const void* pAddressDefault, IVarEnumList* pEnumList = 0); - - ////////////////////////////////////////////////////////////////////////// - // Additional IVariable implementation. - ////////////////////////////////////////////////////////////////////////// - - IVarEnumList* GetEnumList() const; - -protected: - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - TSmartPtr m_enumList; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -////////////////////////////////////////////////////////////////////////// -// Spline variable -////////////////////////////////////////////////////////////////////////// - -class EDITOR_CORE_API CVariableTypeInfoSpline - : public CVariableTypeInfo -{ - -public: - - // Constructor. - CVariableTypeInfoSpline(CTypeInfo::CVarInfo const& VarInfo, void* pAddress, const void* pAddressDefault, ISplineInterpolator* pSpline); - - ~CVariableTypeInfoSpline(); - - virtual ISplineInterpolator* GetSpline(); - - //! Overrides CVariableTypeInfo to keep m_pSpline in sync with CVariableTypeInfo::m_pData - //! when Set(value) functions are called - void OnSetValue(bool bRecursive) override; - -private: - ISplineInterpolator* m_pSpline; -}; - -////////////////////////////////////////////////////////////////////////// -// Struct variable -// Inherits implementation from CVariableArray -////////////////////////////////////////////////////////////////////////// - -class EDITOR_CORE_API CVariableTypeInfoStruct - : public CVariableTypeInfo -{ -public: - // Constructor. - CVariableTypeInfoStruct(CTypeInfo::CVarInfo const& VarInfo, void* pAddress, const void* pAddressDefault); - - void ProcessSubStruct(CTypeInfo::CVarInfo const& VarInfo, void* pAddress, const void* pAddressDefault); - - ////////////////////////////////////////////////////////////////////////// - // IVariable implementation. - ////////////////////////////////////////////////////////////////////////// - - virtual QString GetDisplayValue() const; - - virtual void OnSetValue(bool bRecursive); - - void SetFlagRecursive(EFlags flag) override; - - void CopyValue(IVariable* fromVar); - - int GetNumVariables() const; - - IVariable* GetVariable(int index) const; - -protected: - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - typedef std::vector Vars; - Vars m_Vars; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -struct EDITOR_CORE_API CUIEnumsDBList - : IVarEnumList -{ -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING - CUIEnumsDatabase_SEnum const* m_pEnumList; - - CUIEnumsDBList(CUIEnumsDatabase_SEnum const* pEnumList); - - virtual QString GetItemName(uint index); -}; - -#endif // CRYINCLUDE_EDITOR_UTIL_VARIABLETYPEINFO_H diff --git a/Code/Sandbox/Editor/ViewManager.cpp b/Code/Sandbox/Editor/ViewManager.cpp index 7dd0f3e033..334e78a826 100644 --- a/Code/Sandbox/Editor/ViewManager.cpp +++ b/Code/Sandbox/Editor/ViewManager.cpp @@ -34,7 +34,6 @@ #include "EditorViewportWidget.h" #include "CryEditDoc.h" -#include #include AZ_CVAR(bool, ed_useAtomNativeViewport, true, nullptr, AZ::ConsoleFunctorFlags::Null, "Use the new Atom-native Editor viewport (experimental, not yet stable"); @@ -42,7 +41,7 @@ AZ_CVAR(bool, ed_useAtomNativeViewport, true, nullptr, AZ::ConsoleFunctorFlags:: bool CViewManager::IsMultiViewportEnabled() { // Enable multi-viewport for legacy renderer, or if we're using the new fully Atom-native viewport - return !AZ::Interface::Get() || ed_useAtomNativeViewport; + return ed_useAtomNativeViewport; } ////////////////////////////////////////////////////////////////////// @@ -81,7 +80,7 @@ CViewManager::CViewManager() RegisterQtViewPane(GetIEditor(), "Left", LyViewPane::CategoryViewport, viewportOptions); viewportOptions.viewportType = ET_ViewportCamera; - if (ed_useAtomNativeViewport && AZ::Interface::Get()) + if (ed_useAtomNativeViewport) { RegisterQtViewPaneWithName(GetIEditor(), "Perspective", LyViewPane::CategoryViewport, viewportOptions); } diff --git a/Code/Sandbox/Editor/ViewPane.cpp b/Code/Sandbox/Editor/ViewPane.cpp index 43e4330113..480e39bedf 100644 --- a/Code/Sandbox/Editor/ViewPane.cpp +++ b/Code/Sandbox/Editor/ViewPane.cpp @@ -33,7 +33,6 @@ // AzFramework #include -#include #include // Editor diff --git a/Code/Sandbox/Editor/ViewportManipulatorController.cpp b/Code/Sandbox/Editor/ViewportManipulatorController.cpp index 0083d295c1..0bf2bbc412 100644 --- a/Code/Sandbox/Editor/ViewportManipulatorController.cpp +++ b/Code/Sandbox/Editor/ViewportManipulatorController.cpp @@ -112,8 +112,7 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram m_state.m_mousePick.m_screenCoordinates = screenPosition; AZStd::optional ray; ViewportInteractionRequestBus::EventResult( - ray, GetViewportId(), &ViewportInteractionRequestBus::Events::ViewportScreenToWorldRay, - QPoint(screenPosition.m_x, screenPosition.m_y)); + ray, GetViewportId(), &ViewportInteractionRequestBus::Events::ViewportScreenToWorldRay, screenPosition); if (ray.has_value()) { diff --git a/Code/Sandbox/Editor/editor_core_files.cmake b/Code/Sandbox/Editor/editor_core_files.cmake index 85db7ec86b..1aecbd03f6 100644 --- a/Code/Sandbox/Editor/editor_core_files.cmake +++ b/Code/Sandbox/Editor/editor_core_files.cmake @@ -54,13 +54,11 @@ set(FILES Util/MemoryBlock.cpp Util/Variable.cpp Util/UndoUtil.cpp - Util/VariableTypeInfo.cpp Util/VariablePropertyType.cpp Clipboard.h Util/MemoryBlock.h Util/Variable.h Util/UndoUtil.h - Util/VariableTypeInfo.h Util/VariablePropertyType.h Util/RefCountBase.h Util/PathUtil.h diff --git a/Code/Sandbox/Editor/editor_files.cmake b/Code/Sandbox/Editor/editor_files.cmake index 50521d23aa..9acfb2aaf8 100644 --- a/Code/Sandbox/Editor/editor_files.cmake +++ b/Code/Sandbox/Editor/editor_files.cmake @@ -13,6 +13,5 @@ set(FILES main.cpp Style/Editor.qss Style/resources.qrc - Style/LensFlareEditor.qss EditorCryEdit.rc ) diff --git a/Code/Sandbox/Editor/editor_lib_files.cmake b/Code/Sandbox/Editor/editor_lib_files.cmake index 80ec582d19..f6537909e9 100644 --- a/Code/Sandbox/Editor/editor_lib_files.cmake +++ b/Code/Sandbox/Editor/editor_lib_files.cmake @@ -309,15 +309,6 @@ set(FILES Util/AffineParts.cpp Objects/BaseObject.cpp Objects/BaseObject.h - Material/Material.cpp - Material/Material.h - Material/MaterialHelpers.cpp - Material/MaterialHelpers.h - Material/MaterialDialog.qrc - Material/MaterialPreviewModelView.cpp - Material/MaterialPreviewModelView.h - Material/PreviewModelView.cpp - Material/PreviewModelView.h Alembic/AlembicCompileDialog.cpp Alembic/AlembicCompileDialog.h Alembic/AlembicCompileDialog.ui @@ -332,11 +323,6 @@ set(FILES AzAssetBrowser/AzAssetBrowserWindow.cpp AzAssetBrowser/AzAssetBrowserWindow.h AzAssetBrowser/AzAssetBrowserWindow.ui - AzAssetBrowser/Preview/LegacyPreviewer.cpp - AzAssetBrowser/Preview/LegacyPreviewer.h - AzAssetBrowser/Preview/LegacyPreviewer.ui - AzAssetBrowser/Preview/LegacyPreviewerFactory.cpp - AzAssetBrowser/Preview/LegacyPreviewerFactory.h AssetDatabase/AssetDatabaseLocationListener.h AssetDatabase/AssetDatabaseLocationListener.cpp AssetImporter/AssetImporterManager/AssetImporterDragAndDropHandler.cpp @@ -385,8 +371,7 @@ set(FILES Controls/MultiMonHelper.h Controls/NumberCtrl.cpp Controls/NumberCtrl.h - Controls/PreviewModelCtrl.cpp - Controls/PreviewModelCtrl.h + Controls/NumberCtrl.h Controls/SplineCtrl.cpp Controls/SplineCtrl.h Controls/SplineCtrlEx.cpp @@ -395,8 +380,6 @@ set(FILES Controls/TextEditorCtrl.h Controls/TimelineCtrl.cpp Controls/TimelineCtrl.h - Controls/TimeOfDaySlider.cpp - Controls/TimeOfDaySlider.h Controls/WndGridHelper.h Controls/ReflectedPropertyControl/PropertyAnimationCtrl.cpp Controls/ReflectedPropertyControl/PropertyAnimationCtrl.h @@ -469,8 +452,6 @@ set(FILES LevelFileDialog.qrc LevelFileDialog.h LevelFileDialog.ui - PanelPreview.cpp - PanelPreview.h QuickAccessBar.cpp QuickAccessBar.h QuickAccessBar.ui @@ -504,10 +485,6 @@ set(FILES IconListDialog.ui UndoDropDown.cpp UndoDropDown.h - TimeOfDayDialog.cpp - TimeOfDayDialog.h - TimeOfDayDialog.ui - TimeOfDay.qrc DimensionsDialog.cpp DimensionsDialog.h DimensionsDialog.ui @@ -537,17 +514,10 @@ set(FILES GameResourcesExporter.cpp GameExporter.h GameResourcesExporter.h - Geometry/EdGeometry.cpp - Geometry/EdMesh.cpp Geometry/TriMesh.cpp - Geometry/EdGeometry.h - Geometry/EdMesh.h Geometry/TriMesh.h AboutDialog.h AboutDialog.ui - DatabaseFrameWnd.h - DatabaseFrameWnd.ui - DatabaseFrameWnd.qrc DocMultiArchive.h EditMode/DeepSelection.h FBXExporterDialog.h @@ -556,7 +526,6 @@ set(FILES IObservable.h IPostRenderer.h LightmapCompiler/SimpleTriangleRasterizer.h - SurfaceInfoPicker.h ToolBox.h TrackViewNewSequenceDialog.h UndoConfigSpec.h @@ -571,61 +540,13 @@ set(FILES WipFeaturesDlg.qrc LevelIndependentFileMan.cpp LevelIndependentFileMan.h - LensFlareEditor/ILensFlareListener.h - LensFlareEditor/LensFlareAtomicList.cpp - LensFlareEditor/LensFlareAtomicList.h - LensFlareEditor/LensFlareEditor.cpp - LensFlareEditor/LensFlareEditor.h - LensFlareEditor/LensFlareElement.cpp - LensFlareEditor/LensFlareElement.h - LensFlareEditor/LensFlareElementTree.cpp - LensFlareEditor/LensFlareElementTree.h - LensFlareEditor/LensFlareItem.cpp - LensFlareEditor/LensFlareItem.h - LensFlareEditor/LensFlareItemTree.cpp - LensFlareEditor/LensFlareItemTree.h - LensFlareEditor/LensFlareLibrary.cpp - LensFlareEditor/LensFlareLibrary.h - LensFlareEditor/LensFlareLightEntityTree.cpp - LensFlareEditor/LensFlareLightEntityTree.h - LensFlareEditor/LensFlareManager.cpp - LensFlareEditor/LensFlareManager.h - LensFlareEditor/LensFlareUndo.cpp - LensFlareEditor/LensFlareUndo.h - LensFlareEditor/LensFlareUtil.cpp - LensFlareEditor/LensFlareUtil.h - LensFlareEditor/LensFlareView.cpp - LensFlareEditor/LensFlareView.h LogFileImpl.cpp LogFileImpl.h - MatEditPreviewDlg.cpp - MatEditPreviewDlg.h - Material/MaterialBrowser.cpp - Material/MaterialBrowser.h - Material/MaterialBrowser.ui - Material/MaterialBrowserSearchFilters.cpp - Material/MaterialBrowserSearchFilters.h - Material/MaterialBrowserFilterModel.cpp - Material/MaterialBrowserFilterModel.h - Material/MaterialImageListCtrl.cpp - Material/MaterialImageListCtrl.h - Material/MaterialLibrary.cpp - Material/MaterialLibrary.h - Material/MaterialManager.cpp - Material/MaterialManager.h - MaterialSender.h - MaterialSender.cpp - Material/MaterialPythonFuncs.h - Material/MaterialPythonFuncs.cpp - Mission.cpp - Mission.h Objects/ClassDesc.cpp Objects/ClassDesc.h Objects/IEntityObjectListener.h Objects/SelectionGroup.cpp Objects/SelectionGroup.h - Objects/StatObjValidator.cpp - Objects/StatObjValidator.h Objects/SubObjSelection.cpp Objects/SubObjSelection.h Objects/ObjectLoader.cpp @@ -659,9 +580,7 @@ set(FILES QtUI/WaitCursor.h QtUI/WaitCursor.cpp RenderHelpers/AxisHelper.cpp - RenderHelpers/AxisHelperExtended.cpp RenderHelpers/AxisHelper.h - RenderHelpers/AxisHelperExtended.h Serialization.h Serialization/VariableOArchive.cpp Serialization/VariableOArchive.h @@ -706,7 +625,6 @@ set(FILES GraphicsSettingsDialog.cpp graphicssettingsdialog.ui AboutDialog.cpp - DatabaseFrameWnd.cpp ErrorReportTableModel.h ErrorReportTableModel.cpp EditMode/DeepSelection.cpp @@ -716,9 +634,6 @@ set(FILES LightmapCompiler/SimpleTriangleRasterizer.cpp ResourceSelectorHost.cpp ResourceSelectorHost.h - SurfaceInfoPicker.cpp - ThumbnailGenerator.cpp - ThumbnailGenerator.h ToolBox.cpp TrackViewNewSequenceDialog.cpp TrackViewNewSequenceDialog.ui @@ -750,9 +665,6 @@ set(FILES ShaderEnum.h SurfaceTypeValidator.cpp SurfaceTypeValidator.h - EnvironmentPanel.cpp - EnvironmentPanel.h - EnvironmentPanel.ui TrackView/AtomOutputFrameCapture.cpp TrackView/AtomOutputFrameCapture.h TrackView/TrackViewDialog.qrc @@ -944,9 +856,6 @@ set(FILES Grid.h LayoutWnd.cpp LayoutWnd.h - ModelViewport.cpp - ModelViewport.h - ModelViewportDC.cpp EditorViewportWidget.cpp EditorViewportWidget.h ViewportManipulatorController.cpp diff --git a/Code/Sandbox/Editor/editor_lib_test_files.cmake b/Code/Sandbox/Editor/editor_lib_test_files.cmake index f537169136..9eca3c56ae 100644 --- a/Code/Sandbox/Editor/editor_lib_test_files.cmake +++ b/Code/Sandbox/Editor/editor_lib_test_files.cmake @@ -18,7 +18,6 @@ set(FILES Lib/Tests/test_EditorUtils.cpp Lib/Tests/test_Main.cpp Lib/Tests/test_MainWindowPythonBindings.cpp - Lib/Tests/test_MaterialPythonFuncs.cpp Lib/Tests/test_ObjectManagerPythonBindings.cpp Lib/Tests/test_TrackViewPythonBindings.cpp Lib/Tests/test_ViewPanePythonBindings.cpp diff --git a/Code/Sandbox/Plugins/CMakeLists.txt b/Code/Sandbox/Plugins/CMakeLists.txt index 5b940921c1..0f83a98aa1 100644 --- a/Code/Sandbox/Plugins/CMakeLists.txt +++ b/Code/Sandbox/Plugins/CMakeLists.txt @@ -11,7 +11,6 @@ add_subdirectory(EditorCommon) add_subdirectory(ComponentEntityEditorPlugin) -add_subdirectory(FBXPlugin) add_subdirectory(FFMPEGPlugin) add_subdirectory(ProjectSettingsTool) add_subdirectory(PerforcePlugin) diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp index 60574ee48c..c85ed1248f 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp @@ -43,13 +43,10 @@ #include #include #include -#include #include #include -#include #include -#include #include #include #include @@ -112,7 +109,6 @@ void CComponentEntityObject::AssignEntity(AZ::Entity* entity, bool destroyOld) { AZ::TransformNotificationBus::Handler::BusDisconnect(); LmbrCentral::RenderBoundsNotificationBus::Handler::BusDisconnect(); - LmbrCentral::MeshComponentNotificationBus::Handler::BusDisconnect(); AzToolsFramework::ComponentEntityEditorRequestBus::Handler::BusDisconnect(); AZ::EntityBus::Handler::BusDisconnect(); AzToolsFramework::ComponentEntityObjectRequestBus::Handler::BusDisconnect(); @@ -158,7 +154,6 @@ void CComponentEntityObject::AssignEntity(AZ::Entity* entity, bool destroyOld) AZ::TransformNotificationBus::Handler::BusConnect(m_entityId); LmbrCentral::RenderBoundsNotificationBus::Handler::BusConnect(m_entityId); - LmbrCentral::MeshComponentNotificationBus::Handler::BusConnect(m_entityId); AzToolsFramework::ComponentEntityEditorRequestBus::Handler::BusConnect(m_entityId); AZ::EntityBus::Handler::BusConnect(m_entityId); AzToolsFramework::ComponentEntityObjectRequestBus::Handler::BusConnect(this); @@ -399,15 +394,6 @@ void CComponentEntityObject::OnParentChanged([[maybe_unused]] AZ::EntityId oldPa { } -void CComponentEntityObject::OnMeshCreated(const AZ::Data::Asset& asset) -{ - (void)asset; - - // Need to recalculate bounds when the mesh changes. - OnRenderBoundsReset(); - ValidateMeshStatObject(); -} - void CComponentEntityObject::OnRenderBoundsReset() { CEntityObject::InvalidateTM(0); @@ -919,7 +905,7 @@ void CComponentEntityObject::Display(DisplayContext& dc) AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus; AzFramework::DebugDisplayRequestBus::Bind( - debugDisplayBus, AzToolsFramework::ViewportInteraction::g_mainViewportEntityDebugDisplayId); + debugDisplayBus, AzFramework::g_defaultSceneEntityDebugDisplayId); AZ_Assert(debugDisplayBus, "Invalid DebugDisplayRequestBus."); AzFramework::DebugDisplayRequests* debugDisplay = @@ -950,9 +936,7 @@ void CComponentEntityObject::DrawDefault(DisplayContext& dc, const QColor& label IStatObj* CComponentEntityObject::GetIStatObj() { - IStatObj* statObj = nullptr; - LmbrCentral::LegacyMeshComponentRequestBus::EventResult(statObj, m_entityId, &LmbrCentral::LegacyMeshComponentRequests::GetStatObj); - return statObj; + return nullptr; } bool CComponentEntityObject::IsIsolated() const @@ -1110,56 +1094,3 @@ void CComponentEntityObject::DrawAccent(DisplayContext& dc) dc.DrawWireBox(box.min, box.max); } } - -void CComponentEntityObject::SetMaterial(CMaterial* material) -{ - AZ::Entity* entity = nullptr; - EBUS_EVENT_RESULT(entity, AZ::ComponentApplicationBus, FindEntity, m_entityId); - if (entity) - { - if (material) - { - EBUS_EVENT_ID(m_entityId, LmbrCentral::MaterialOwnerRequestBus, SetMaterial, material->GetMatInfo()); - } - else - { - EBUS_EVENT_ID(m_entityId, LmbrCentral::MaterialOwnerRequestBus, SetMaterial, nullptr); - } - } - - ValidateMeshStatObject(); -} - -CMaterial* CComponentEntityObject::GetMaterial() const -{ - _smart_ptr material = nullptr; - EBUS_EVENT_ID_RESULT(material, m_entityId, LmbrCentral::MaterialOwnerRequestBus, GetMaterial); - return GetIEditor()->GetMaterialManager()->FromIMaterial(material); -} - -CMaterial* CComponentEntityObject::GetRenderMaterial() const -{ - AZ::Entity* entity = nullptr; - EBUS_EVENT_RESULT(entity, AZ::ComponentApplicationBus, FindEntity, m_entityId); - if (entity) - { - _smart_ptr material = nullptr; - EBUS_EVENT_ID_RESULT(material, m_entityId, LmbrCentral::MaterialOwnerRequestBus, GetMaterial); - - if (material) - { - return GetIEditor()->GetMaterialManager()->LoadMaterial(material->GetName(), false); - } - } - - return nullptr; -} - -void CComponentEntityObject::ValidateMeshStatObject() -{ - IStatObj* statObj = GetIStatObj(); - CMaterial* editorMaterial = GetMaterial(); - CStatObjValidator statValidator; - statValidator.Validate(statObj, editorMaterial); -} - diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h index 208ade7cd7..b64bd6b3e1 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h @@ -27,7 +27,6 @@ #include #include "../Editor/Objects/EntityObject.h" -#include #include #endif @@ -43,7 +42,6 @@ class CComponentEntityObject , private AzToolsFramework::EditorEntityIconComponentNotificationBus::Handler , private AZ::TransformNotificationBus::Handler , private LmbrCentral::RenderBoundsNotificationBus::Handler - , private LmbrCentral::MeshComponentNotificationBus::Handler , private AzToolsFramework::ComponentEntityEditorRequestBus::Handler , private AzToolsFramework::ComponentEntityObjectRequestBus::Handler , private AZ::EntityBus::Handler @@ -81,9 +79,6 @@ public: CBaseObject* GetLinkParent() const override; XmlNodeRef Export(const QString& levelPath, XmlNodeRef& xmlNode) override; void DeleteEntity() override; - void SetMaterial(CMaterial* mtl) override; - CMaterial* GetMaterial() const override; - CMaterial* GetRenderMaterial() const override; void DrawDefault(DisplayContext& dc, const QColor& labelColor = QColor(255, 255, 255)) override; IStatObj* GetIStatObj() override; bool IsIsolated() const override; @@ -131,11 +126,6 @@ public: void OnParentChanged(AZ::EntityId oldParent, AZ::EntityId newParent) override; ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - //! MeshComponentNotificationBus - void OnMeshCreated(const AZ::Data::Asset& asset) override; - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// //! RenderBoundsNotificationBus void OnRenderBoundsReset() override; @@ -191,8 +181,6 @@ protected: void DrawAccent(DisplayContext& dc); - void ValidateMeshStatObject(); - class EditorActionGuard { public: diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp index ecfb155d79..c7c501c70a 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -162,13 +161,6 @@ void SandboxIntegrationManager::Setup() AzToolsFramework::EditorEvents::Bus::Handler::BusConnect(); AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect(); AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler::BusConnect(); - // turn on the this debug display request bus implementation if no other implementation is active - if( !(AZ::Interface::Get() && AzFramework::DebugDisplayRequestBus::HasHandlers())) - { - m_debugDisplayBusImplementationActive = true; - AzFramework::DebugDisplayRequestBus::Handler::BusConnect( - AzToolsFramework::ViewportInteraction::g_mainViewportEntityDebugDisplayId); - } AzFramework::DisplayContextRequestBus::Handler::BusConnect(); SetupFileExtensionMap(); @@ -302,12 +294,15 @@ void SandboxIntegrationManager::OnCatalogAssetAdded(const AZ::Data::AssetId& ass // operation writing to shared resource is queued on main thread. void SandboxIntegrationManager::OnCatalogAssetRemoved(const AZ::Data::AssetId& assetId, const AZ::Data::AssetInfo& assetInfo) { + bool isPrefabSystemEnabled = false; + AzFramework::ApplicationRequests::Bus::BroadcastResult(isPrefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); + // Check to see if the removed slice asset has any instance in the level, then check if // those dangling instances are directly under the root slice (not sub-slices). If yes, // detach them and save necessary information so they can be restored when their slice asset // comes back. - if (assetInfo.m_assetType == AZ::AzTypeInfo::Uuid()) + if (!isPrefabSystemEnabled && assetInfo.m_assetType == AZ::AzTypeInfo::Uuid()) { AZ::SliceComponent* rootSlice = nullptr; AzToolsFramework::SliceEditorEntityOwnershipServiceRequestBus::BroadcastResult(rootSlice, diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp index cd423535f2..49d56f67df 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerListModel.cpp @@ -1473,13 +1473,14 @@ void OutlinerListModel::OnEntityInfoUpdatedRemoveChildBegin(AZ::EntityId parentI emit EnableSelectionUpdates(false); auto parentIndex = GetIndexFromEntity(parentId); auto childIndex = GetIndexFromEntity(childId); - beginRemoveRows(parentIndex, childIndex.row(), childIndex.row()); + beginResetModel(); } void OutlinerListModel::OnEntityInfoUpdatedRemoveChildEnd(AZ::EntityId parentId, AZ::EntityId childId) { (void)childId; AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzToolsFramework); + endRemoveRows(); //must refresh partial lock/visibility of parents diff --git a/Code/Sandbox/Plugins/EditorCommon/ManipScene.cpp b/Code/Sandbox/Plugins/EditorCommon/ManipScene.cpp index 5aa5301693..5b76ca8804 100644 --- a/Code/Sandbox/Plugins/EditorCommon/ManipScene.cpp +++ b/Code/Sandbox/Plugins/EditorCommon/ManipScene.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include "../EditorCommon/QViewport.h" diff --git a/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp b/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp index 5ca6cf5ac6..2d9598ba83 100644 --- a/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp +++ b/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -37,8 +36,6 @@ #include #include -#include - #include // Class to implement the WindowRequestBus::Handler instead of the QViewport class. @@ -110,114 +107,6 @@ struct QViewport::SPreviousContext bool isMainViewport; }; -static void DrawGridLine(IRenderAuxGeom& aux, ColorB col, const float alpha, const float alphaFalloff, const float slide, const float halfSlide, [[maybe_unused]] const float maxSlide, const Vec3& stepDir, const Vec3& orthoDir, const SViewportState& state, const SViewportGridSettings& gridSettings) -{ - ColorB colEnd = col; - - float weight = 1.0f - (slide / halfSlide); - if (slide > halfSlide) - { - weight = (slide - halfSlide) / halfSlide; - } - - float orthoWeight = 1.0f; - - if (gridSettings.circular) - { - float invWeight = 1.0f - weight; - orthoWeight = sqrtf((invWeight * 2) - (invWeight * invWeight)); - } - else - { - orthoWeight = 1.0f; - } - - col.a = aznumeric_cast((1.0f - (weight * (1.0f - alphaFalloff))) * alpha); - colEnd.a = aznumeric_cast(alphaFalloff * alpha); - - Vec3 orthoStep = state.gridOrigin.q * (orthoDir * halfSlide * orthoWeight); - - Vec3 point = state.gridOrigin * (-(stepDir * halfSlide) + (stepDir * slide)); - Vec3 points[3] = { - point, - point - orthoStep, - point + orthoStep - }; - - aux.DrawLine(points[0], col, points[1], colEnd); - aux.DrawLine(points[0], col, points[2], colEnd); -} - -static void DrawGridLines(IRenderAuxGeom& aux, const uint count, const uint interStepCount, const Vec3& stepDir, const float stepSize, const Vec3& orthoDir, const float offset, const SViewportState& state, const SViewportGridSettings& gridSettings) -{ - const uint countHalf = count / 2; - Vec3 step = stepDir * stepSize; - Vec3 orthoStep = orthoDir * aznumeric_cast(countHalf); - Vec3 maxStep = step * aznumeric_cast(countHalf);// + stepDir*fabs(offset); - const float maxStepLen = count * stepSize; - const float halfStepLen = countHalf * stepSize; - - float interStepSize = interStepCount > 0 ? (stepSize / interStepCount) : stepSize; - const float alphaMulMain = (float)gridSettings.mainColor.a; - const float alphaMulInter = (float)gridSettings.middleColor.a; - const float alphaFalloff = 1.0f - (gridSettings.alphaFalloff / 100.0f); - - for (int i = 0; i < count + 2; i++) - { - float pointSlide = i * stepSize + offset; - if (pointSlide > 0.0f && pointSlide < maxStepLen) - { - DrawGridLine(aux, gridSettings.mainColor, alphaMulMain, alphaFalloff, pointSlide, halfStepLen, maxStepLen, stepDir, orthoDir, state, gridSettings); - } - - for (int d = 1; d < interStepCount; d++) - { - float interSlide = ((i - 1) * stepSize) + offset + (d * interStepSize); - if (interSlide > 0.0f && interSlide < maxStepLen) - { - DrawGridLine(aux, gridSettings.middleColor, alphaMulInter, alphaFalloff, interSlide, halfStepLen, maxStepLen, stepDir, orthoDir, state, gridSettings); - } - } - } -} - -static void DrawGrid(IRenderAuxGeom& aux, const SViewportState& state, const SViewportGridSettings& gridSettings) -{ - const uint count = gridSettings.count * 2; - const float gridSize = gridSettings.spacing * gridSettings.count * 2.0f; - const float halfGridSize = gridSettings.spacing * gridSettings.count; - - const float stepSize = gridSize / count; - DrawGridLines(aux, count, gridSettings.interCount, Vec3(1.0f, 0.0f, 0.0f), stepSize, Vec3(0.0f, 1.0f, 0.0f), state.gridCellOffset.x, state, gridSettings); - DrawGridLines(aux, count, gridSettings.interCount, Vec3(0.0f, 1.0f, 0.0f), stepSize, Vec3(1.0f, 0.0f, 0.0f), state.gridCellOffset.y, state, gridSettings); -} - -static void DrawOrigin(IRenderAuxGeom& aux, const ColorB& col) -{ - const float scale = 0.3f; - const float lineWidth = 4.0f; - aux.DrawLine(Vec3(-scale, 0, 0), col, Vec3(scale, 0, 0), col, lineWidth); - aux.DrawLine(Vec3(0, -scale, 0), col, Vec3(0, scale, 0), col, lineWidth); - aux.DrawLine(Vec3(0, 0, -scale), col, Vec3(0, 0, scale), col, lineWidth); -} - -static void DrawOrigin(IRenderAuxGeom& aux, const int left, const int top, const float scale, const Matrix34 cameraTM) -{ - Vec3 originPos = Vec3(aznumeric_cast(left), aznumeric_cast(top), 0); - Quat originRot = Quat(0.707107f, 0.707107f, 0, 0) * Quat(cameraTM).GetInverted(); - Vec3 x = originPos + originRot * Vec3(1, 0, 0) * scale; - Vec3 y = originPos + originRot * Vec3(0, 1, 0) * scale; - Vec3 z = originPos + originRot * Vec3(0, 0, 1) * scale; - ColorF xCol(1, 0, 0); - ColorF yCol(0, 1, 0); - ColorF zCol(0, 0, 1); - const float lineWidth = 2.0f; - - aux.DrawLine(originPos, xCol, x, xCol, lineWidth); - aux.DrawLine(originPos, yCol, y, yCol, lineWidth); - aux.DrawLine(originPos, zCol, z, zCol, lineWidth); -} - struct QViewport::SPrivate { CDLight m_VPLight0; @@ -365,7 +254,7 @@ bool QViewport::CreateRenderContext() HWND windowHandle = reinterpret_cast(QWidget::winId()); - if( AZ::Interface::Get() && m_renderContextCreated && windowHandle == m_lastHwnd) + if( m_renderContextCreated && windowHandle == m_lastHwnd) { // the hwnd has not changed, no need to destroy and recreate context (and swap chain etc) return false; @@ -377,13 +266,10 @@ bool QViewport::CreateRenderContext() { m_renderContextCreated = true; - if (AZ::Interface::Get()) - { - m_viewportRequests.get()->BusConnect(windowHandle); - AzFramework::WindowSystemNotificationBus::Broadcast(&AzFramework::WindowSystemNotificationBus::Handler::OnWindowCreated, windowHandle); + m_viewportRequests.get()->BusConnect(windowHandle); + AzFramework::WindowSystemNotificationBus::Broadcast(&AzFramework::WindowSystemNotificationBus::Handler::OnWindowCreated, windowHandle); - m_lastHwnd = windowHandle; - } + m_lastHwnd = windowHandle; StorePreviousContext(); GetIEditor()->GetEnv()->pRenderer->CreateContext(windowHandle); @@ -499,49 +385,6 @@ void QViewport::Update() { m_averageFrameTime = 0.01f * m_lastFrameTime + 0.99f * m_averageFrameTime; } - - if (GetIEditor()->GetEnv()->pRenderer == 0 || - GetIEditor()->GetEnv()->p3DEngine == 0) - { - return; - } - - if (!isVisible()) - { - return; - } - - if (!m_renderContextCreated) - { - return; - } - - if (m_updating) - { - return; - } - - AutoBool updating(&m_updating); - - if (m_resizeWindowEvent) - { - HWND windowHandle = reinterpret_cast(QWidget::winId()); - AzFramework::WindowNotificationBus::Event(windowHandle, &AzFramework::WindowNotificationBus::Handler::OnWindowResized, m_width, m_height); - m_resizeWindowEvent = false; - } - - if (hasFocus()) - { - ProcessMouse(); - ProcessKeys(); - } - - if ((m_width <= 0) || (m_height <= 0)) - { - return; - } - - RenderInternal(); } void QViewport::CaptureMouse() @@ -865,210 +708,16 @@ void QViewport::PreRender() m_state->lastCameraParentFrame = m_state->cameraParentFrame; m_state->lastCameraTarget = currentTM; - m_camera->SetFrustum(m_width, m_height, fov, m_settings->camera.nearClip, GetIEditor()->GetEnv()->p3DEngine->GetMaxViewDistance()); + m_camera->SetFrustum(m_width, m_height, fov, m_settings->camera.nearClip); m_camera->SetMatrix(Matrix34(m_state->cameraParentFrame * currentTM)); } void QViewport::Render() { - IRenderAuxGeom* aux = GetIEditor()->GetEnv()->pRenderer->GetIRenderAuxGeom(); - SAuxGeomRenderFlags oldFlags = aux->GetRenderFlags(); - - if (m_settings->grid.showGrid) - { - aux->SetRenderFlags(e_Mode3D | e_AlphaBlended | e_FillModeSolid | e_CullModeNone | e_DepthWriteOff | e_DepthTestOn); - DrawGrid(*aux, *m_state, m_settings->grid); - } - - if (m_settings->grid.origin) - { - aux->SetRenderFlags(e_Mode3D | e_AlphaBlended | e_FillModeSolid | e_CullModeNone | e_DepthWriteOff | e_DepthTestOn); - DrawOrigin(*aux, m_settings->grid.originColor); - } - - if (m_settings->camera.showViewportOrientation) - { - aux->SetRenderFlags(e_Mode3D | e_AlphaBlended | e_FillModeSolid | e_CullModeNone | e_DepthWriteOn | e_DepthTestOn); - TransformationMatrices backupSceneMatrices; - GetIEditor()->GetEnv()->pRenderer->Set2DMode(m_width, m_height, backupSceneMatrices); - DrawOrigin(*aux, 50, m_height - 50, 20.0f, m_camera->GetMatrix()); - GetIEditor()->GetEnv()->pRenderer->Unset2DMode(backupSceneMatrices); - } - - // Force grid, origin and viewport orientation to render by calling Flush(). This ensures that they are always drawn behind other geometry - aux->Flush(); - aux->SetRenderFlags(oldFlags); - - // wireframe mode - CScopedWireFrameMode scopedWireFrame(GetIEditor()->GetEnv()->pRenderer, m_settings->rendering.wireframe ? R_WIREFRAME_MODE : R_SOLID_MODE); - - SRenderingPassInfo passInfo = SRenderingPassInfo::CreateGeneralPassRenderingInfo(*m_camera, SRenderingPassInfo::DEFAULT_FLAGS, true); - GetIEditor()->GetEnv()->pRenderer->BeginSpawningGeneratingRendItemJobs(passInfo.ThreadID()); - GetIEditor()->GetEnv()->pRenderer->BeginSpawningShadowGeneratingRendItemJobs(passInfo.ThreadID()); - GetIEditor()->GetEnv()->pRenderer->EF_ClearSkinningDataPool(); - GetIEditor()->GetEnv()->pRenderer->EF_StartEf(passInfo); - - SRendParams rp; - - - //--------------------------------------------------------------------------------------- - //---- add light ------------------------------------------------------------- - //--------------------------------------------------------------------------------------- - ///////////////////////////////////////////////////////////////////////////////////// - // Confetti Start - ///////////////////////////////////////////////////////////////////////////////////// - // If time of day enabled, add sun light to preview - Confetti Vera. - if (m_settings->rendering.sunlight) - { - rp.AmbientColor.r = GetIEditor()->Get3DEngine()->GetSunColor().x / 255.0f * m_settings->lighting.m_brightness; - rp.AmbientColor.g = GetIEditor()->Get3DEngine()->GetSunColor().y / 255.0f * m_settings->lighting.m_brightness; - rp.AmbientColor.b = GetIEditor()->Get3DEngine()->GetSunColor().z / 255.0f * m_settings->lighting.m_brightness; - - m_private->m_sun.SetPosition(passInfo.GetCamera().GetPosition() + GetIEditor()->Get3DEngine()->GetSunDir()); - // The radius value respect the sun radius settings in Engine. - // Please refer to the function C3DEngine::UpdateSun(const SRenderingPassInfo &passInfo). -- Vera, Confetti - m_private->m_sun.m_fRadius = 100000000; //Radius of the sun from Engine. - m_private->m_sun.SetLightColor(GetIEditor()->Get3DEngine()->GetSunColor()); - m_private->m_sun.SetSpecularMult(GetIEditor()->Get3DEngine()->GetGlobalParameter(E3DPARAM_SUN_SPECULAR_MULTIPLIER)); - m_private->m_sun.m_Flags |= DLF_DIRECTIONAL | DLF_SUN | DLF_THIS_AREA_ONLY | DLF_LM | DLF_SPECULAROCCLUSION | - ((GetIEditor()->Get3DEngine()->IsSunShadows() && passInfo.RenderShadows()) ? DLF_CASTSHADOW_MAPS : 0); - m_private->m_sun.m_sName = "Sun"; - - GetIEditor()->GetEnv()->pRenderer->EF_ADDDlight(&m_private->m_sun, passInfo); - } - ///////////////////////////////////////////////////////////////////////////////////// - // Confetti End - ///////////////////////////////////////////////////////////////////////////////////// - else // Add directional light - { - rp.AmbientColor.r = m_settings->lighting.m_ambientColor.r / 255.0f * m_settings->lighting.m_brightness; - rp.AmbientColor.g = m_settings->lighting.m_ambientColor.g / 255.0f * m_settings->lighting.m_brightness; - rp.AmbientColor.b = m_settings->lighting.m_ambientColor.b / 255.0f * m_settings->lighting.m_brightness; - - // Directional light - if (m_settings->lighting.m_useLightRotation) - { - m_LightRotationRadian += m_averageFrameTime; - } - if (m_LightRotationRadian > gf_PI) - { - m_LightRotationRadian = -gf_PI; - } - - Matrix33 LightRot33 = Matrix33::CreateRotationZ(m_LightRotationRadian); - - f32 lightMultiplier = m_settings->lighting.m_lightMultiplier; - f32 lightSpecMultiplier = m_settings->lighting.m_lightSpecMultiplier; - - f32 lightOrbit = 15.0f; - Vec3 LPos0 = Vec3(-lightOrbit, lightOrbit, lightOrbit / 2); - m_private->m_VPLight0.SetPosition(LightRot33 * LPos0); - - Vec3 d0; - d0.x = f32(m_settings->lighting.m_directionalLightColor.r) / 255.0f; - d0.y = f32(m_settings->lighting.m_directionalLightColor.g) / 255.0f; - d0.z = f32(m_settings->lighting.m_directionalLightColor.b) / 255.0f; - m_private->m_VPLight0.SetLightColor(ColorF(d0.x * lightMultiplier, d0.y * lightMultiplier, d0.z * lightMultiplier, 0)); - m_private->m_VPLight0.SetSpecularMult(lightSpecMultiplier); - - m_private->m_VPLight0.m_Flags = DLF_SUN | DLF_DIRECTIONAL; - GetIEditor()->GetEnv()->pRenderer->EF_ADDDlight(&m_private->m_VPLight0, passInfo); - } - - //--------------------------------------------------------------------------------------- - - Matrix34 tm(IDENTITY); - rp.pMatrix = &tm; - rp.pPrevMatrix = &tm; - - rp.dwFObjFlags = 0; - - SRenderContext rc; - rc.camera = m_camera.get(); - rc.viewport = this; - rc.passInfo = &passInfo; - rc.renderParams = &rp; - - - for (size_t i = 0; i < m_consumers.size(); ++i) - { - m_consumers[i]->OnViewportRender(rc); - } - SignalRender(rc); - - if ((m_settings->rendering.fps == true) && (m_averageFrameTime != 0.0f)) - { - GetIEditor()->GetEnv()->pRenderer->Draw2dLabel(12.0f, 12.0f, 1.25f, ColorF(1, 1, 1, 1), false, "FPS: %.2f", 1.0f / m_averageFrameTime); - } - - GetIEditor()->GetEnv()->pRenderer->EF_EndEf3D(SHDF_STREAM_SYNC, -1, -1, passInfo); - - if (m_mouseMovementsSinceLastFrame > 0) - { - m_mouseMovementsSinceLastFrame = 0; - - // Make sure we deliver at least last mouse movement event - OnMouseEvent(m_pendingMouseMoveEvent); - } } void QViewport::RenderInternal() { - { - threadID mainThread = 0; - threadID renderThread = 0; - GetIEditor()->GetEnv()->pRenderer->GetThreadIDs(mainThread, renderThread); - const threadID currentThreadId = CryGetCurrentThreadId(); - - // I'm not sure if this criteria is right. It might not be restrictive enough, but it's at least strict enough to prevent - // the crash we encountered. - const uint32 workerThreadId = AZ::JobContext::GetGlobalContext()->GetJobManager().GetWorkerThreadId(); - const bool isValidThread = (workerThreadId != AZ::JobManager::InvalidWorkerThreadId) || mainThread == currentThreadId || renderThread == currentThreadId; - - if (!isValidThread) - { - AZ_Assert(false, "Attempting to render QViewport on unsupported thread %" PRI_THREADID, currentThreadId); - return; - } - } - - - SetCurrentContext(); - GetIEditor()->GetEnv()->pSystem->RenderBegin(); - - ColorF viewportBackgroundColor(m_settings->background.topColor.r / 255.0f, m_settings->background.topColor.g / 255.0f, m_settings->background.topColor.b / 255.0f); - GetIEditor()->GetEnv()->pRenderer->ClearTargetsImmediately(FRT_CLEAR, viewportBackgroundColor); - GetIEditor()->GetEnv()->pRenderer->ResetToDefault(); - - // Call PreRender to interpolate the new camera position - PreRender(); - GetIEditor()->GetEnv()->pRenderer->SetCamera(*m_camera); - - IRenderAuxGeom* aux = GetIEditor()->GetEnv()->pRenderer->GetIRenderAuxGeom(); - SAuxGeomRenderFlags oldFlags = aux->GetRenderFlags(); - - if (m_settings->background.useGradient) - { - Vec3 frustumVertices[8]; - m_camera->GetFrustumVertices(frustumVertices); - Vec3 lt = Vec3::CreateLerp(frustumVertices[0], frustumVertices[4], 0.10f); - Vec3 lb = Vec3::CreateLerp(frustumVertices[1], frustumVertices[5], 0.10f); - Vec3 rb = Vec3::CreateLerp(frustumVertices[2], frustumVertices[6], 0.10f); - Vec3 rt = Vec3::CreateLerp(frustumVertices[3], frustumVertices[7], 0.10f); - aux->SetRenderFlags(e_Mode3D | e_AlphaNone | e_FillModeSolid | e_CullModeNone | e_DepthWriteOff | e_DepthTestOn); - ColorB topColor = m_settings->background.topColor; - ColorB bottomColor = m_settings->background.bottomColor; - aux->DrawTriangle(lt, topColor, rt, topColor, rb, bottomColor); - aux->DrawTriangle(lb, bottomColor, rb, bottomColor, lt, topColor); - aux->Flush(); - } - aux->SetRenderFlags(oldFlags); - - Render(); - - bool renderStats = false; - GetIEditor()->GetEnv()->pSystem->RenderEnd(renderStats, false); - RestorePreviousContext(); } void QViewport::GetImageOffscreen(CImageEx& image, const QSize& customSize) diff --git a/Code/Sandbox/Plugins/EditorCommon/QViewport.h b/Code/Sandbox/Plugins/EditorCommon/QViewport.h index 2b18724d01..72b2024bc4 100644 --- a/Code/Sandbox/Plugins/EditorCommon/QViewport.h +++ b/Code/Sandbox/Plugins/EditorCommon/QViewport.h @@ -28,7 +28,6 @@ struct SRenderingPassInfo; struct SRendParams; struct Ray; struct IRenderer; -struct I3DEngine; struct SSystemGlobalEnvironment; namespace Serialization { class IArchive; diff --git a/Code/Sandbox/Plugins/FBXPlugin/CMakeLists.txt b/Code/Sandbox/Plugins/FBXPlugin/CMakeLists.txt deleted file mode 100644 index 4c433b9cd6..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -if(NOT PAL_TRAIT_BUILD_HOST_TOOLS) - return() -endif() - -include(Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake) -if(NOT PAL_TRAIT_BUILD_FBX_PLUGIN_SUPPORTED) - return() -endif() - -ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}) - -ly_add_target( - NAME FBXPlugin MODULE - NAMESPACE Legacy - OUTPUT_SUBDIRECTORY EditorPlugins - AUTOMOC - AUTOUIC - AUTORCC - FILES_CMAKE - fbxplugin_files.cmake - ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake - COMPILE_DEFINITIONS - PRIVATE - PLUGIN_EXPORTS - BUILD_DEPENDENCIES - PRIVATE - 3rdParty::Qt::Core - 3rdParty::Qt::Gui - 3rdParty::Qt::Widgets - 3rdParty::FbxSdk - Legacy::CryCommon - Legacy::Editor.Headers - Legacy::EditorCore -) - -ly_add_dependencies(Editor FBXPlugin) -set_property(GLOBAL APPEND PROPERTY LY_EDITOR_PLUGINS $) diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXExporter.cpp b/Code/Sandbox/Plugins/FBXPlugin/FBXExporter.cpp deleted file mode 100644 index 9aa46e78c4..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXExporter.cpp +++ /dev/null @@ -1,924 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "FBXPlugin_precompiled.h" - - -// FBX SDK Help: http://download.autodesk.com/global/docs/fbxsdk2012/en_us/index.html - -#include "FBXExporter.h" -#include "FBXSettingsDlg.h" - -#include "IEditor.h" - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// constants used to convert cameras to and from Maya - -static const float s_CONVERSION_BAKING_SAMPLE_RATE = 30.0f; - -// IMPORT_PRE/POST_ROTATIONS determined by experimentation with fbx2015 in Maya and Max. -// We are transforming a Z-axis forward (Max/Maya) to a negative Y-axis forward camera (Editor). -// Analytically this shold involve a preRotation of -90 degrees around the x-axis. -// For Y-Up scenes, our Open 3D Engine Tools inserts an additional 180 rotation around the Y-axis when orienting .cgf files. We need to -// 'undo' for FBX anim curves. This does not apply to cameras which do not use .cgf files -static const FbxVector4 s_PRE_ROTATION_FOR_YUP_SCENES (-90.0f, .0f, .0f); -static const FbxVector4 s_POST_ROTATION_FOR_YUP_OBJECTS(-90.0f, 180.0f, .0f); -static const FbxVector4 s_POST_ROTATION_FOR_ZFORWARD_CAMERAS(-90.0f, .0f, .0f); - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -namespace { - std::string GetFilePath(const std::string& filename) - { - int pos = filename.find_last_of("/\\"); - if (pos > 0) - { - return filename.substr(0, pos + 1); - } - - return filename; - } - - - std::string GetFileName(const std::string& fullFilename) - { - int pos = fullFilename.find_last_of("/\\"); - if (pos > 0) - { - return fullFilename.substr(pos + 1); - } - - return fullFilename; - } -} // namespace - - -#ifdef DEBUG -/////////////////////////////////////////////////////////////////////// -// debugging function to print all the keys in an Fbx Curve -void DebugPrintCurveKeys(FbxAnimCurve* pCurve, const QString& name) -{ - if (pCurve) - { - ILog* log = GetIEditor()->GetSystem()->GetILog(); - log->Log("\n%s", name); - for (int keyID = 0; keyID < pCurve->KeyGetCount(); ++keyID) - { - FbxAnimCurveKey key = pCurve->KeyGet(keyID); - - log->Log("%.2g:%g, ", key.GetTime().GetSecondDouble(), key.GetValue()); - } - } -} -#endif - -// CFBXExporter -CFBXExporter::CFBXExporter() - : m_pFBXManager(0) - , m_pFBXScene(0) -{ - m_settings.bCopyTextures = true; - m_settings.bEmbedded = false; - m_settings.bAsciiFormat = false; - m_settings.bConvertAxesForMaxMaya = false; -} - - -const char* CFBXExporter::GetExtension() const -{ - return "fbx"; -} - - -const char* CFBXExporter::GetShortDescription() const -{ - return "FBX format"; -} - - -bool CFBXExporter::ExportToFile(const char* filename, const Export::IData* pData) -{ - if (!m_pFBXManager) - { - m_pFBXManager = FbxManager::Create(); - } - - bool bAnimationExport = false; - - for (int objectID = 0; objectID < pData->GetObjectCount(); ++objectID) - { - Export::Object* pObject = pData->GetObject(objectID); - - if (pObject->GetEntityAnimationDataCount() > 0) - { - bAnimationExport = true; - break; - } - } - - // do nothing if the user cancels - if (!OpenFBXSettingsDlg(m_settings)) - { - return false; - } - - m_path = GetFilePath(filename); - std::string name = GetFileName(filename); - - // create an IOSettings object - FbxIOSettings* pSettings = FbxIOSettings::Create(m_pFBXManager, IOSROOT); - m_pFBXManager->SetIOSettings(pSettings); - - // Create a scene object - FbxScene* pFBXScene = FbxScene::Create(m_pFBXManager, "Test"); - pFBXScene->GetGlobalSettings().SetAxisSystem(FbxAxisSystem::Max); - pFBXScene->GetGlobalSettings().SetOriginalUpAxis(FbxAxisSystem::Max); - - // Create document info - FbxDocumentInfo* pDocInfo = FbxDocumentInfo::Create(m_pFBXManager, "DocInfo"); - pDocInfo->mTitle = name.c_str(); - pDocInfo->mSubject = "Exported geometry from editor application."; - pDocInfo->mAuthor = "Editor FBX exporter."; - pDocInfo->mRevision = "rev. 1.0"; - pDocInfo->mKeywords = "Editor FBX export"; - pDocInfo->mComment = ""; - pFBXScene->SetDocumentInfo(pDocInfo); - - // Create nodes from objects and add them to the scene - FbxNode* pRootNode = pFBXScene->GetRootNode(); - - FbxAnimStack* pAnimStack = FbxAnimStack::Create(pFBXScene, "AnimStack"); - FbxAnimLayer* pAnimBaseLayer = FbxAnimLayer::Create(pFBXScene, "AnimBaseLayer"); - pAnimStack->AddMember(pAnimBaseLayer); - - int numObjects = pData->GetObjectCount(); - - m_nodes.resize(0); - m_nodes.reserve(numObjects); - - for (int i = 0; i < numObjects; ++i) - { - Export::Object* pObj = pData->GetObject(i); - FbxNode* newNode = NULL; - - if (!bAnimationExport) - { - newNode = CreateFBXNode(pObj); - } - else - { - newNode = CreateFBXAnimNode(pFBXScene, pAnimBaseLayer, pObj); - } - - m_nodes.push_back(newNode); - } - - // solve hierarchy - for (int i = 0; i < m_nodes.size() && i < numObjects; ++i) - { - const Export::Object* pObj = pData->GetObject(i); - FbxNode* pNode = m_nodes[i]; - FbxNode* pParentNode = 0; - if (pObj->nParent >= 0 && pObj->nParent < m_nodes.size()) - { - pParentNode = m_nodes[pObj->nParent]; - } - if (pParentNode) - { - pParentNode->AddChild(pNode); - } - else - { - pRootNode->AddChild(pNode); - } - } - - int nFileFormat = -1; - - if (m_settings.bAsciiFormat) - { - if (nFileFormat < 0 || nFileFormat >= m_pFBXManager->GetIOPluginRegistry()->GetWriterFormatCount()) - { - nFileFormat = m_pFBXManager->GetIOPluginRegistry()->GetNativeWriterFormat(); - int lFormatIndex, lFormatCount = m_pFBXManager->GetIOPluginRegistry()->GetWriterFormatCount(); - for (lFormatIndex = 0; lFormatIndex < lFormatCount; lFormatIndex++) - { - if (m_pFBXManager->GetIOPluginRegistry()->WriterIsFBX(lFormatIndex)) - { - FbxString lDesc = m_pFBXManager->GetIOPluginRegistry()->GetWriterFormatDescription(lFormatIndex); - const char* lASCII = "ascii"; - if (lDesc.Find(lASCII) >= 0) - { - nFileFormat = lFormatIndex; - break; - } - } - } - } - } - - pSettings->SetBoolProp(EXP_FBX_EMBEDDED, m_settings.bEmbedded); - - if (m_settings.bConvertAxesForMaxMaya) - { - // convert the scene from our Z-Up world to Maya's Y-Up World. This is stored in the FBX scene and both Max & Maya will - // import accordingly - FbxAxisSystem::MayaYUp.ConvertScene(pFBXScene); - - // process all camera nodes in the scene to make them look down their negative Z-axis - convertCamerasForMaxMaya(pFBXScene->GetRootNode()); - } - - //Save a scene - bool bRet = false; - FbxExporter* pFBXExporter = FbxExporter::Create(m_pFBXManager, name.c_str()); - - // For backward compatilibity choose a widely compatible FBX version that's been out for a while: - if (pFBXExporter) - { - pFBXExporter->SetFileExportVersion(FBX_2014_00_COMPATIBLE); - - if (pFBXExporter->Initialize(filename, nFileFormat, pSettings)) - { - bRet = pFBXExporter->Export(pFBXScene); - } - pFBXExporter->Destroy(); - } - - pFBXScene->Destroy(); - - m_materials.clear(); - m_meshMaterialIndices.clear(); - - m_pFBXManager->Destroy(); - m_pFBXManager = 0; - - if (bRet) - { - GetIEditor()->GetSystem()->GetILog()->Log("\nFBX Exporter: Exported successfully to %s.", name.c_str()); - } - else - { - GetIEditor()->GetSystem()->GetILog()->LogError("\nFBX Exporter: Failed."); - } - - return bRet; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// This method finds all cameras (via recursion) in the node tree rooted at pNode and bakes the necessary -// transforms into any cameras it finds to take care of the conversion from Maya Z-forward to our negative-y forward cameras -void CFBXExporter::convertCamerasForMaxMaya(FbxNode* pNode) const -{ - if (pNode) - { - // recurse to children to convert all cameras in the level - for (int i = 0; i < pNode->GetChildCount(); i++) - { - convertCamerasForMaxMaya(pNode->GetChild(i)); - } - - // process this node if it's a camera - convertCameraForMaxMaya(pNode); - } -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Maya cameras look down the negative z-axis. Ours look down the positive-y. This method bakes the necessary transforms -// into the local transforms of the given pNode if it's a camera to take care of the conversion -void CFBXExporter::convertCameraForMaxMaya(FbxNode* pNode) const -{ - // Maya puts in an extra 90 x-rotation in the "Rotate Axis" channel. Adding an extra post-rotation fixes this, - // determined experimentally - static const FbxVector4 s_EXTRA_EXPORT_POST_ROTATION_FOR_MAX_MAYA(.0f, -90.0f, .0f); - - if (pNode && pNode->GetNodeAttribute() && pNode->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eCamera) - { - // bake in s_PRE/POST_ROTATION_FOR_MAYA into anim curves - pNode->SetPivotState(FbxNode::eSourcePivot, FbxNode::ePivotActive); - pNode->SetPivotState(FbxNode::eDestinationPivot, FbxNode::ePivotActive); - - pNode->SetPreRotation(FbxNode::eSourcePivot, s_PRE_ROTATION_FOR_YUP_SCENES); - pNode->SetPostRotation(FbxNode::eSourcePivot, s_POST_ROTATION_FOR_ZFORWARD_CAMERAS); - - pNode->ResetPivotSetAndConvertAnimation(s_CONVERSION_BAKING_SAMPLE_RATE, true); // bake postRotation in for all animStacks - - // Maya puts in an extra 90 x-rotation in the "Rotate Axis" channel. Adding an extra post-rotation after the baking of transforms - // fixes this - i.e. baked transformes change the camera's local rotation channels themselves, post-bake post-transforms get - // stuffed into Maya's 'Rotate Axis' channels - pNode->SetPostRotation(FbxNode::eSourcePivot, s_EXTRA_EXPORT_POST_ROTATION_FOR_MAX_MAYA); - } -} - -FbxMesh* CFBXExporter::CreateFBXMesh(const Export::Object* pObj) -{ - if (!m_pFBXManager) - { - return 0; - } - - int numVertices = pObj->GetVertexCount(); - const Export::Vector3D* pVerts = pObj->GetVertexBuffer(); - - int numMeshes = pObj->GetMeshCount(); - - int numAllFaces = 0; - for (int j = 0; j < numMeshes; ++j) - { - const Export::Mesh* pMesh = pObj->GetMesh(j); - int numFaces = pMesh->GetFaceCount(); - numAllFaces += numFaces; - } - - if (numVertices == 0 || numAllFaces == 0) - { - return 0; - } - - FbxMesh* pFBXMesh = FbxMesh::Create(m_pFBXManager, pObj->name); - - pFBXMesh->InitControlPoints(numVertices); - FbxVector4* pControlPoints = pFBXMesh->GetControlPoints(); - - for (int i = 0; i < numVertices; ++i) - { - const Export::Vector3D& vertex = pVerts[i]; - pControlPoints[i] = FbxVector4(vertex.x, vertex.y, vertex.z); - } - - /* - // We want to have one normal for each vertex (or control point), - // so we set the mapping mode to eBY_CONTROL_POINT. - FbxGeometryElementNormal* lElementNormal= pFBXMesh->CreateElementNormal(); - - //FbxVector4 lNormalZPos(0, 0, 1); - - lElementNormal->SetMappingMode(FbxGeometryElement::eBY_CONTROL_POINT); - - // Set the normal values for every control point. - lElementNormal->SetReferenceMode(FbxGeometryElement::eDIRECT); - - lElementNormal->GetDirectArray().Add(lNormalZPos); - */ - - - int numTexCoords = pObj->GetTexCoordCount(); - const Export::UV* pTextCoords = pObj->GetTexCoordBuffer(); - if (numTexCoords) - { - // Create UV for Diffuse channel. - FbxGeometryElementUV* pFBXDiffuseUV = pFBXMesh->CreateElementUV("DiffuseUV"); - FBX_ASSERT(pFBXDiffuseUV != NULL); - - pFBXDiffuseUV->SetMappingMode(FbxGeometryElement::eByPolygonVertex); - pFBXDiffuseUV->SetReferenceMode(FbxGeometryElement::eIndexToDirect); - - for (int i = 0; i < numTexCoords; ++i) - { - const Export::UV& textCoord = pTextCoords[i]; - pFBXDiffuseUV->GetDirectArray().Add(FbxVector2(textCoord.u, textCoord.v)); - } - - //Now we have set the UVs as eINDEX_TO_DIRECT reference and in eBY_POLYGON_VERTEX mapping mode - //we must update the size of the index array. - pFBXDiffuseUV->GetIndexArray().SetCount(numTexCoords); - } - - pFBXMesh->ReservePolygonCount(numAllFaces); - pFBXMesh->ReservePolygonVertexCount(numAllFaces * 3); - - // Set material mapping. - FbxGeometryElementMaterial* pMaterialElement = pFBXMesh->CreateElementMaterial(); - pMaterialElement->SetMappingMode(FbxGeometryElement::eByPolygon); - pMaterialElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect); - - for (int j = 0; j < numMeshes; ++j) - { - const Export::Mesh* pMesh = pObj->GetMesh(j); - - // Write all faces, convert the indices to one based indices - int numFaces = pMesh->GetFaceCount(); - - int polygonCount = pFBXMesh->GetPolygonCount(); - pMaterialElement->GetIndexArray().SetCount(polygonCount + numFaces); - int materialIndex = m_meshMaterialIndices[pMesh]; - - const Export::Face* pFaces = pMesh->GetFaceBuffer(); - for (int i = 0; i < numFaces; ++i) - { - const Export::Face& face = pFaces[i]; - pFBXMesh->BeginPolygon(-1, -1, -1, false); - - pFBXMesh->AddPolygon(face.idx[0], face.idx[0]); - pFBXMesh->AddPolygon(face.idx[1], face.idx[1]); - pFBXMesh->AddPolygon(face.idx[2], face.idx[2]); - - //pFBXDiffuseUV->GetIndexArray().SetAt(face.idx[0], face.idx[0]); - - pFBXMesh->EndPolygon(); - //pPolygonGroupElement->GetIndexArray().Add(j); - - pMaterialElement->GetIndexArray().SetAt(polygonCount + i, materialIndex); - } - } - - return pFBXMesh; -} - - -FbxFileTexture* CFBXExporter::CreateFBXTexture(const char* pTypeName, const char* pName) -{ - std::string filename = pName; - - if (m_settings.bCopyTextures) - { - // check if file exists - QFileInfo fi(pName); - if (!fi.exists() || fi.isDir()) - { - GetIEditor()->GetSystem()->GetILog()->LogError("\nFBX Exporter: Texture %s is not on the disk.", pName); - } - else - { - filename = m_path; - filename += GetFileName(pName); - if (QFile::copy(pName, filename.c_str())) - { - GetIEditor()->GetSystem()->GetILog()->Log("\nFBX Exporter: Texture %s was copied.", pName); - } - filename = GetFileName(pName); // It works for Maya, but not good for MAX - } - } - - FbxFileTexture* pFBXTexture = FbxFileTexture::Create(m_pFBXManager, pTypeName); - pFBXTexture->SetFileName(filename.c_str()); - pFBXTexture->SetTextureUse(FbxTexture::eStandard); - pFBXTexture->SetMappingType(FbxTexture::eUV); - pFBXTexture->SetMaterialUse(FbxFileTexture::eModelMaterial); - pFBXTexture->SetSwapUV(false); - pFBXTexture->SetTranslation(0.0, 0.0); - pFBXTexture->SetScale(1.0, 1.0); - pFBXTexture->SetRotation(0.0, 0.0); - - return pFBXTexture; -} - - -FbxSurfaceMaterial* CFBXExporter::CreateFBXMaterial(const std::string& name, const Export::Mesh* pMesh) -{ - auto it = m_materials.find(name); - if (it != m_materials.end()) - { - return it->second; - } - - FbxSurfacePhong* pMaterial = FbxSurfacePhong::Create(m_pFBXManager, name.c_str()); - - pMaterial->Diffuse.Set(FbxDouble3(pMesh->material.diffuse.r, pMesh->material.diffuse.g, pMesh->material.diffuse.b)); - pMaterial->DiffuseFactor.Set(1.0); - pMaterial->Specular.Set(FbxDouble3(pMesh->material.specular.r, pMesh->material.specular.g, pMesh->material.specular.b)); - pMaterial->SpecularFactor.Set(1.0); - - // Opacity - pMaterial->TransparentColor.Set(FbxDouble3(1.0f, 1.0f, 1.0f)); // need explicitly setup - pMaterial->TransparencyFactor.Set(1.0f - pMesh->material.opacity); - - // Glossiness - // CRC TODO: Why was this commented out? - //pMaterial->Shininess.Set(pow(2, pMesh->material.shininess * 10)); - - if (pMesh->material.mapDiffuse[0] != '\0') - { - FbxFileTexture* pFBXTexture = CreateFBXTexture("Diffuse", pMesh->material.mapDiffuse); - pMaterial->Diffuse.ConnectSrcObject(pFBXTexture); - } - - if (pMesh->material.mapSpecular[0] != '\0') - { - FbxFileTexture* pFBXTexture = CreateFBXTexture("Specular", pMesh->material.mapSpecular); - pMaterial->Specular.ConnectSrcObject(pFBXTexture); - } - - if (pMesh->material.mapOpacity[0] != '\0') - { - FbxFileTexture* pFBXTexture = CreateFBXTexture("Opacity", pMesh->material.mapOpacity); - pMaterial->TransparentColor.ConnectSrcObject(pFBXTexture); - } - // CRC TODO: Why was this commented out? - /* - if (pMesh->material.mapBump[0] != '\0') - { - FbxFileTexture* pFBXTexture = CreateFBXTexture("Bump", pMesh->material.mapBump); - pMaterial->Bump.ConnectSrcObject(pFBXTexture); - } - */ - - if (pMesh->material.mapDisplacement[0] != '\0') - { - FbxFileTexture* pFBXTexture = CreateFBXTexture("Displacement", pMesh->material.mapDisplacement); - pMaterial->DisplacementColor.ConnectSrcObject(pFBXTexture); - } - - m_materials[name] = pMaterial; - - return pMaterial; -} - - -FbxNode* CFBXExporter::CreateFBXAnimNode(FbxScene* pScene, FbxAnimLayer* pAnimBaseLayer, const Export::Object* pObj) -{ - FbxNode* pAnimNode = FbxNode::Create(pScene, pObj->name); - pAnimNode->LclTranslation.GetCurveNode(pAnimBaseLayer, true); - pAnimNode->LclRotation.GetCurveNode(pAnimBaseLayer, true); - pAnimNode->LclScaling.GetCurveNode(pAnimBaseLayer, true); - - FbxCamera* pCamera = FbxCamera::Create(pScene, pObj->name); - - if (pObj->entityType == Export::eCamera) - { - pCamera->SetApertureMode(FbxCamera::eHorizontal); - pCamera->SetFormat(FbxCamera::eCustomFormat); - pCamera->SetAspect(FbxCamera::eFixedRatio, 1.777778f, 1.0); - - pAnimNode->SetNodeAttribute(pCamera); - - if (pObj->cameraTargetNodeName[0]) - { - for (int i = 0; i < m_nodes.size(); ++i) - { - FbxNode* pCameraTargetNode = m_nodes[i]; - const char* nodeName = pCameraTargetNode->GetName(); - if (strcmp(nodeName, pObj->cameraTargetNodeName) == 0) - { - FbxMarker* pMarker = FbxMarker::Create(pScene, ""); - pCameraTargetNode->SetNodeAttribute(pMarker); - pAnimNode->SetTarget(pCameraTargetNode); - } - } - } - } - - if (pObj->GetEntityAnimationDataCount() > 0) - { - int animDataCount = pObj->GetEntityAnimationDataCount(); - - for (int animDataIndex = 0; animDataIndex < animDataCount; ++animDataIndex) - { - const Export::EntityAnimData* pAnimData = pObj->GetEntityAnimationData(animDataIndex); - - FbxTime time = 0; - time.SetSecondDouble(pAnimData->keyTime); - - FbxAnimCurve* pCurve = NULL; - - switch (pAnimData->dataType) - { - case Export::AnimParamType::PositionX: - pCurve = pAnimNode->LclTranslation.GetCurve(pAnimBaseLayer, "X", true); - break; - case Export::AnimParamType::PositionY: - pCurve = pAnimNode->LclTranslation.GetCurve(pAnimBaseLayer, "Y", true); - break; - case Export::AnimParamType::PositionZ: - pCurve = pAnimNode->LclTranslation.GetCurve(pAnimBaseLayer, "Z", true); - break; - case Export::AnimParamType::RotationX: - pCurve = pAnimNode->LclRotation.GetCurve(pAnimBaseLayer, "X", true); - break; - case Export::AnimParamType::RotationY: - pCurve = pAnimNode->LclRotation.GetCurve(pAnimBaseLayer, "Y", true); - break; - case Export::AnimParamType::RotationZ: - pCurve = pAnimNode->LclRotation.GetCurve(pAnimBaseLayer, "Z", true); - break; - case Export::AnimParamType::FOV: - { - pCurve = pCamera->FieldOfView.GetCurve(pAnimBaseLayer, "FieldOfView", true); - } - break; - - default: - break; - } - - if (pCurve) - { - int keyIndex = 0; - - pCurve->KeyModifyBegin(); - keyIndex = pCurve->KeyInsert(time); - pCurve->KeySet(keyIndex, time, pAnimData->keyValue, FbxAnimCurveDef::eInterpolationCubic, FbxAnimCurveDef::eTangentBreak, pAnimData->rightTangent, pAnimData->leftTangent, FbxAnimCurveDef::eWeightedAll, pAnimData->rightTangentWeight, pAnimData->leftTangentWeight); - - pCurve->KeySetLeftDerivative(keyIndex, pAnimData->leftTangent); - pCurve->KeySetRightDerivative(keyIndex, pAnimData->rightTangent); - - pCurve->KeySetLeftTangentWeight(keyIndex, pAnimData->leftTangentWeight); - pCurve->KeySetRightTangentWeight(keyIndex, pAnimData->rightTangentWeight); - - FbxAnimCurveTangentInfo keyLeftInfo; - keyLeftInfo.mAuto = 0; - keyLeftInfo.mDerivative = pAnimData->leftTangent; - keyLeftInfo.mWeight = pAnimData->leftTangentWeight; - keyLeftInfo.mWeighted = true; - keyLeftInfo.mVelocity = 0.0f; - keyLeftInfo.mHasVelocity = false; - - FbxAnimCurveTangentInfo keyRightInfo; - keyRightInfo.mAuto = 0; - keyRightInfo.mDerivative = pAnimData->rightTangent; - keyRightInfo.mWeight = pAnimData->rightTangentWeight; - keyRightInfo.mWeighted = true; - keyRightInfo.mVelocity = 0.0f; - keyRightInfo.mHasVelocity = false; - - pCurve->KeySetLeftDerivativeInfo(keyIndex, keyLeftInfo); - pCurve->KeySetRightDerivativeInfo(keyIndex, keyRightInfo); - - pCurve->KeyModifyEnd(); - } - } - } - - return pAnimNode; -} - -FbxNode* CFBXExporter::CreateFBXNode(const Export::Object* pObj) -{ - if (!m_pFBXManager) - { - return 0; - } - - // create a FbxNode - FbxNode* pNode = FbxNode::Create(m_pFBXManager, pObj->name); - pNode->LclTranslation.Set(FbxVector4(pObj->pos.x, pObj->pos.y, pObj->pos.z)); - - // Rotation: Create Euler angels from quaternion throughout a matrix - FbxAMatrix rotMat; - rotMat.SetQ(FbxQuaternion(pObj->rot.v.x, pObj->rot.v.y, pObj->rot.v.z, pObj->rot.w)); - pNode->LclRotation.Set(rotMat.GetR()); - - pNode->LclScaling.Set(FbxVector4(pObj->scale.x, pObj->scale.y, pObj->scale.z)); - - - // collect materials - int materialIndex = 0; - if (pObj->GetMeshCount() != 0 && pObj->materialName[0] != '\0') - { - for (int i = 0; i < pObj->GetMeshCount(); ++i) - { - const Export::Mesh* pMesh = pObj->GetMesh(i); - - if (pMesh->material.name[0] == '\0') - { - continue; - } - - // find if material was created for this object - int findIndex = -1; - for (int j = 0; j < i; ++j) - { - const Export::Mesh* pTestMesh = pObj->GetMesh(j); - if (!strcmp(pTestMesh->material.name, pMesh->material.name)) - { - findIndex = m_meshMaterialIndices[pTestMesh]; - break; - } - } - - if (findIndex != -1) - { - m_meshMaterialIndices[pMesh] = findIndex; - continue; - } - - std::string materialName = pObj->materialName; - if (strcmp(pObj->materialName, pMesh->material.name)) - { - materialName += ':'; - materialName += pMesh->material.name; - } - - FbxSurfaceMaterial* pFBXMaterial = CreateFBXMaterial(materialName, pMesh); - if (pFBXMaterial) - { - pNode->AddMaterial(pFBXMaterial); - m_meshMaterialIndices[pMesh] = materialIndex++; - } - } - } - - - FbxMesh* pFBXMesh = CreateFBXMesh(pObj); - if (pFBXMesh) - { - pNode->SetNodeAttribute(pFBXMesh); - pNode->SetShadingMode(FbxNode::eTextureShading); - } - - return pNode; -} - -void CFBXExporter::Release() -{ - delete this; -} - -inline f32 Maya2SandboxFOVDeg(const f32 fov, const f32 ratio) { return RAD2DEG(2.0f * atanf(tan(DEG2RAD(fov) / 2.0f) / ratio)); }; - -void CFBXExporter::FillAnimationData(Export::Object* pObject, FbxNode* pNode, [[maybe_unused]] FbxAnimLayer* pAnimLayer, FbxAnimCurve* pCurve, Export::AnimParamType paramType) -{ - if (pCurve) - { - for (int keyID = 0; keyID < pCurve->KeyGetCount(); ++keyID) - { - Export::EntityAnimData entityData; - - FbxAnimCurveKey key = pCurve->KeyGet(keyID); - entityData.keyValue = key.GetValue(); - FbxTime time = key.GetTime(); - entityData.keyTime = aznumeric_cast(time.GetSecondDouble()); - - entityData.leftTangent = pCurve->KeyGetLeftDerivative(keyID); - entityData.rightTangent = pCurve->KeyGetRightDerivative(keyID); - entityData.leftTangentWeight = pCurve->KeyGetLeftTangentWeight(keyID); - entityData.rightTangentWeight = pCurve->KeyGetRightTangentWeight(keyID); - - if (paramType == Export::AnimParamType::FocalLength && pNode && pNode->GetCamera()) - { - // special handling for Focal Length - we convert it to FoV for use in-engine (including switching the paramType) - // We handle this because Maya 2015 doesn't save Angle of View or Field of View animation in FBX - it only uses FocalLength. - entityData.dataType = Export::AnimParamType::FOV; - // Open 3D Engine field of view is the vertical angle - pNode->GetCamera()->SetApertureMode(FbxCamera::eVertical); - entityData.keyValue = aznumeric_cast(pNode->GetCamera()->ComputeFieldOfView(entityData.keyValue)); - } - else - { - entityData.dataType = paramType; - } - - // If the Exporter is Sandbox or Maya, convert fov, positions - QString exporterName = m_pFBXScene->GetDocumentInfo()->Original_ApplicationName.Get().Buffer(); - - if (!exporterName.toLower().contains("3ds")) - { - if (paramType == Export::AnimParamType::PositionX || paramType == Export::AnimParamType::PositionY || paramType == Export::AnimParamType::PositionZ) - { - entityData.rightTangent /= 100.0f; - entityData.leftTangent /= 100.0f; - entityData.keyValue /= 100.0f; - } - else if (paramType == Export::AnimParamType::FOV) // Maya 2015 uses FocalLength instead of FoV - assuming this is for legacy Sandbox or Maya? - { - const float kAspectRatio = 1.777778f; - entityData.keyValue = Maya2SandboxFOVDeg(entityData.keyValue, kAspectRatio); - } - } - - pObject->SetEntityAnimationData(entityData); - } - } -} - - -bool CFBXExporter::ImportFromFile(const char* filename, Export::IData* pData) -{ - FbxManager* pFBXManager = FbxManager::Create(); - - FbxScene* pFBXScene = FbxScene::Create(pFBXManager, "Test"); - m_pFBXScene = pFBXScene; - pFBXScene->GetGlobalSettings().SetAxisSystem(FbxAxisSystem::Max); - pFBXScene->GetGlobalSettings().SetOriginalUpAxis(FbxAxisSystem::Max); - - FbxImporter* pImporter = FbxImporter::Create(pFBXManager, ""); - - FbxIOSettings* pSettings = FbxIOSettings::Create(pFBXManager, IOSROOT); - - pFBXManager->SetIOSettings(pSettings); - pSettings->SetBoolProp(IMP_FBX_ANIMATION, true); - - const bool lImportStatus = pImporter->Initialize(filename, -1, pFBXManager->GetIOSettings()); - if (!lImportStatus) - { - return false; - } - - bool bLoadStatus = pImporter->Import(pFBXScene); - - if (!bLoadStatus) - { - return false; - } - - // record the original axis system used in the import file and then convert the file to Open 3D Engine's coord system, - // which matches Max's (Z-Up, negative Y-forward cameras) - int upSign = 1; - FbxAxisSystem importFileAxisSystem = pFBXScene->GetGlobalSettings().GetAxisSystem(); - FbxAxisSystem::EUpVector importSceneUpVector = importFileAxisSystem.GetUpVector(upSign); - FbxAxisSystem::Max.ConvertScene(pFBXScene); - - QString exporterName = pFBXScene->GetDocumentInfo()->Original_ApplicationName.Get().Buffer(); - // const bool fromMaya = (exporterName.contains("maya", Qt::CaseInsensitive)); - // const bool fromMax = (exporterName.contains("max", Qt::CaseInsensitive)); - - FbxNode* pRootNode = pFBXScene->GetRootNode(); - - if (pRootNode) - { - for (int animStackID = 0; animStackID < pFBXScene->GetSrcObjectCount(); ++animStackID) - { - FbxAnimStack* pAnimStack = pFBXScene->GetSrcObject(animStackID); - const int animLayersCount = pAnimStack->GetMemberCount(); - - for (int layerID = 0; layerID < animLayersCount; ++layerID) - { - FbxAnimLayer* pAnimLayer = pAnimStack->GetMember(layerID); - - const int nodeCount = pRootNode->GetChildCount(); - - for (int nodeID = 0; nodeID < nodeCount; ++nodeID) - { - FbxNode* pNode = pRootNode->GetChild(nodeID); - - if (pNode) - { - FbxAnimCurve* pCurve = 0; - Export::Object* pObject = pData->AddObject(pNode->GetName()); - - if (pObject) - { - azstrncpy(pObject->name, sizeof(pObject->name), pNode->GetName(), sizeof(pObject->name) - 1); - pObject->name[sizeof(pObject->name) - 1] = '\0'; - - FbxCamera* pCamera = pNode->GetCamera(); - - // convert animation for Y-Up scenes and for Z-forward Cameras - if (importSceneUpVector == FbxAxisSystem::eYAxis || pCamera) - { - pNode->SetPivotState(FbxNode::eSourcePivot, FbxNode::ePivotActive); - pNode->SetPivotState(FbxNode::eDestinationPivot, FbxNode::ePivotActive); - - if (importSceneUpVector == FbxAxisSystem::eYAxis) - { - // Maps RY to -RZ and RZ to RY - pNode->SetPreRotation(FbxNode::eSourcePivot, s_PRE_ROTATION_FOR_YUP_SCENES); - } - - if (pCamera) - { - // Converts Y-Up, -Z-forward cameras to Open 3D Engine Z-Up, Y-forward cameras - // It is needed regardless of the scene up vector - pNode->SetPostRotation(FbxNode::eSourcePivot, s_POST_ROTATION_FOR_ZFORWARD_CAMERAS); - } - else - { - // Objects from a Y-Up scene (i.e. not cameras). 'undo' the extra transform that the Open 3D Engine Tool - // bakes in to .cgf files from YUp scenes. - pNode->SetPostRotation(FbxNode::eSourcePivot, s_POST_ROTATION_FOR_YUP_OBJECTS); - } - - // bake the pre/post rotations into the anim curves - pNode->ConvertPivotAnimationRecursive(pAnimStack, FbxNode::eSourcePivot, s_CONVERSION_BAKING_SAMPLE_RATE); - } - - if (pCamera) - { - // extract specialized channels for cameras - pCurve = pCamera->FocalLength.GetCurve(pAnimLayer, "FocalLength"); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::FocalLength); - pCurve = pCamera->FieldOfView.GetCurve(pAnimLayer, "FieldOfView", true); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::FOV); - } - - pCurve = pNode->LclTranslation.GetCurve(pAnimLayer, "X"); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::PositionX); - pCurve = pNode->LclTranslation.GetCurve(pAnimLayer, "Y"); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::PositionY); - pCurve = pNode->LclTranslation.GetCurve(pAnimLayer, "Z"); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::PositionZ); - pCurve = pNode->LclRotation.GetCurve(pAnimLayer, "X"); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::RotationX); - pCurve = pNode->LclRotation.GetCurve(pAnimLayer, "Y"); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::RotationY); - pCurve = pNode->LclRotation.GetCurve(pAnimLayer, "Z"); - FillAnimationData(pObject, pNode, pAnimLayer, pCurve, Export::AnimParamType::RotationZ); - } - } - } - } - } - } - - return true; -} diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXExporter.h b/Code/Sandbox/Plugins/FBXPlugin/FBXExporter.h deleted file mode 100644 index 266de76a7d..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXExporter.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Export geometry to FBX file format - - -#ifndef CRYINCLUDE_FBXPLUGIN_FBXEXPORTER_H -#define CRYINCLUDE_FBXPLUGIN_FBXEXPORTER_H - -#pragma once -#include -#include "fbxsdk.h" - -struct SFBXSettings -{ - bool bCopyTextures; - bool bEmbedded; - bool bAsciiFormat; - bool bConvertAxesForMaxMaya; -}; - -class CFBXExporter - : public IExporter -{ -public: - CFBXExporter(); - - virtual const char* GetExtension() const; - virtual const char* GetShortDescription() const; - virtual bool ExportToFile(const char* filename, const Export::IData* pData); - virtual bool ImportFromFile(const char* filename, Export::IData* pData); - virtual void Release(); - -private: - // recursively traverse all nodes under pNode and reset prerotations for camera nodes by calling convertCameraForMaxMaya on them - void convertCamerasForMaxMaya(FbxNode* node) const; - // reset prerotations for a specified nodes if it's a camera - void convertCameraForMaxMaya(FbxNode* pNode) const; - - FbxMesh* CreateFBXMesh(const Export::Object* pObj); - FbxFileTexture* CreateFBXTexture(const char* pTypeName, const char* pName); - FbxSurfaceMaterial* CreateFBXMaterial(const std::string& name, const Export::Mesh* pMesh); - FbxNode* CreateFBXNode(const Export::Object* pObj); - FbxNode* CreateFBXAnimNode(FbxScene* pScene, FbxAnimLayer* pCameraAnimBaseLayer, const Export::Object* pObj); - void FillAnimationData(Export::Object* pObject, FbxNode* pNode, FbxAnimLayer* pAnimLayer, FbxAnimCurve* pCurve, Export::AnimParamType paramType); - - FbxManager* m_pFBXManager; - SFBXSettings m_settings; - FbxScene* m_pFBXScene; - std::string m_path; - std::vector m_nodes; - std::map m_materials; - std::map m_meshMaterialIndices; -}; -#endif // CRYINCLUDE_FBXPLUGIN_FBXEXPORTER_H diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.cpp b/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.cpp deleted file mode 100644 index 0d51889b9d..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "FBXPlugin_precompiled.h" -#include "FBXPlugin.h" - -namespace PluginInfo -{ - const char* kName = "FBX Exporter"; - const char* kGUID = "{6CD02F95-362C-4ADF-8BAE-87C6342A8027}"; - const int kVersion = 1; -} - -void CFBXPlugin::Release() -{ - delete this; -} - -void CFBXPlugin::ShowAbout() -{ -} - -const char* CFBXPlugin::GetPluginGUID() -{ - return PluginInfo::kGUID; -} - -DWORD CFBXPlugin::GetPluginVersion() -{ - return PluginInfo::kVersion; -} - -const char* CFBXPlugin::GetPluginName() -{ - return PluginInfo::kName; -} - -bool CFBXPlugin::CanExitNow() -{ - return true; -} - -void CFBXPlugin::Serialize([[maybe_unused]] FILE* hFile, [[maybe_unused]] bool bIsStoring) -{ -} - -void CFBXPlugin::ResetContent() -{ -} - -bool CFBXPlugin::CreateUIElements() -{ - return true; -} - -void CFBXPlugin::OnEditorNotify([[maybe_unused]] EEditorNotifyEvent aEventId) -{ -} diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.h b/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.h deleted file mode 100644 index 30579d6d1d..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -//////////////////////////////////////////////////////////////////////////// -// -// Crytek Engine Source File. -// Copyright (C), Crytek Studios, 2001-2012 -// ------------------------------------------------------------------------- -// Created: 24 June 2011 by Sergiy Shaykin. -// Description: Attachment to the Sandbox plug-in system -// -//////////////////////////////////////////////////////////////////////////// -#ifndef CRYINCLUDE_FBXPLUGIN_FBXPLUGIN_H -#define CRYINCLUDE_FBXPLUGIN_FBXPLUGIN_H -#include - -class CFBXPlugin - : public IPlugin -{ -public: - void Release(); - void ShowAbout(); - const char* GetPluginGUID(); - DWORD GetPluginVersion(); - const char* GetPluginName(); - bool CanExitNow(); - void Serialize(FILE* hFile, bool bIsStoring); - void ResetContent(); - bool CreateUIElements(); - void OnEditorNotify(EEditorNotifyEvent aEventId); -}; -#endif // CRYINCLUDE_FBXPLUGIN_FBXPLUGIN_H diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.rc b/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.rc deleted file mode 100644 index c681b1ea64..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin.rc +++ /dev/null @@ -1,104 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""winres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_FBX_EXPORT_SETTINGS DIALOGEX 0, 0, 202, 96 -STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOOLWINDOW -CAPTION "FBX Export Settings" -FONT 8, "MS Shell Dlg", 400, 0, 0x0 -BEGIN - CONTROL "Copy textures into folder with FBX file",IDC_COPY_TEXTURES, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,11,137,10 - CONTROL "Embedded data (Put textures inside FBX file)",IDC_EMBEDDED, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,25,157,10 - COMBOBOX IDC_FILE_FORMAT,71,53,100,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "OK",IDOK,88,75,50,14 - PUSHBUTTON "Cancel",IDCANCEL,140,75,50,14 - LTEXT "File Format:",IDC_STATIC,15,55,39,8 - CONTROL "Convert Cameras for Max/Maya",IDC_CONVERT_CAMERAS_FOR_MAX_MAYA, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,39,137,10 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_FBX_EXPORT_SETTINGS, DIALOG - BEGIN - LEFTMARGIN, 6 - RIGHTMARGIN, 190 - TOPMARGIN, 7 - BOTTOMMARGIN, 89 - END -END -#endif // APSTUDIO_INVOKED - -#endif // English (United States) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin_precompiled.cpp b/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin_precompiled.cpp deleted file mode 100644 index cedec4fe05..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin_precompiled.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "FBXPlugin_precompiled.h" - diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin_precompiled.h b/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin_precompiled.h deleted file mode 100644 index da268110a8..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXPlugin_precompiled.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once - -#include - -#include "resource.h" - -///////////////////////////////////////////////////////////////////////////// -// CRY Stuff //////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -#include - - -///////////////////////////////////////////////////////////////////////////// -// STL -///////////////////////////////////////////////////////////////////////////// -#include -#include -#include - -///////////////////////////////////////////////////////////////////////////// -// CRY Stuff //////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -#include -#include "Util/EditorUtils.h" - -#include "EditorCoreAPI.h" diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.cpp b/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.cpp deleted file mode 100644 index 9766288b5a..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "FBXPlugin_precompiled.h" -#include "FBXSettingsDlg.h" -#include "FBXExporter.h" -#include "resource.h" - -#include - -#include - -#include "ui_FBXSettingsDlg.h" - -bool OpenFBXSettingsDlg(struct SFBXSettings& settings) -{ - Ui::FBXSettingsDialog ui; - QDialog dialog(GetIEditor()->GetEditorMainWindow()); - ui.setupUi(&dialog); - - ui.hCopyTextures->setChecked(settings.bCopyTextures); - ui.hEmbedded->setChecked(settings.bEmbedded); - ui.hFileFormat->setCurrentIndex(settings.bAsciiFormat ? 1 : 0); - ui.hConvertAxesForMaxMaya->setChecked(settings.bConvertAxesForMaxMaya); - - if (dialog.exec() != QDialog::Accepted) - return false; - - settings.bCopyTextures = ui.hCopyTextures->isChecked(); - settings.bEmbedded = ui.hEmbedded->isChecked(); - settings.bAsciiFormat = ui.hFileFormat->currentIndex() == 1; - settings.bConvertAxesForMaxMaya = ui.hConvertAxesForMaxMaya->isChecked(); - - return true; -} diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.h b/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.h deleted file mode 100644 index e9b259234f..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.h +++ /dev/null @@ -1,20 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_FBXPLUGIN_FBXSETTINGSDLG_H -#define CRYINCLUDE_FBXPLUGIN_FBXSETTINGSDLG_H - -#pragma once - -bool OpenFBXSettingsDlg(struct SFBXSettings& settings); -#endif // CRYINCLUDE_FBXPLUGIN_FBXSETTINGSDLG_H diff --git a/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.ui b/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.ui deleted file mode 100644 index 8f2367255a..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/FBXSettingsDlg.ui +++ /dev/null @@ -1,109 +0,0 @@ - - - FBXSettingsDialog - - - - 0 - 0 - 313 - 149 - - - - FBX Export Settings - - - - - - Copy textures into folder with FBX file - - - - - - - Embedded data (Put textures inside FBX file) - - - - - - - Convert Cameras for Max/Maya - - - - - - - File Format: - - - hFileFormat - - - - - - - - Bin - - - - - Ascii - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - FBXSettingsDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - FBXSettingsDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/Code/Sandbox/Plugins/FBXPlugin/fbxplugin_files.cmake b/Code/Sandbox/Plugins/FBXPlugin/fbxplugin_files.cmake deleted file mode 100644 index b3cacea11c..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/fbxplugin_files.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - FBXExporter.cpp - FBXExporter.h - FBXPlugin.cpp - FBXPlugin.h - FBXPlugin.rc - FBXSettingsDlg.cpp - FBXSettingsDlg.h - FBXSettingsDlg.ui - main.cpp - resource.h - FBXPlugin_precompiled.cpp - FBXPlugin_precompiled.h -) diff --git a/Code/Sandbox/Plugins/FBXPlugin/main.cpp b/Code/Sandbox/Plugins/FBXPlugin/main.cpp deleted file mode 100644 index 1949350135..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Export geometry to FBX file format - -#include "FBXPlugin_precompiled.h" - -#include "FBXPlugin.h" -#include "FBXExporter.h" - - - -PLUGIN_API IPlugin* CreatePluginInstance(PLUGIN_INIT_PARAM* pInitParam) -{ - if (pInitParam->pluginVersion != SANDBOX_PLUGIN_SYSTEM_VERSION) - { - pInitParam->outErrorCode = IPlugin::eError_VersionMismatch; - return 0; - } - - ModuleInitISystem(GetIEditor()->GetSystem(), "FBX Exporter Plugin"); - - IExportManager* pExportManager = GetIEditor()->GetExportManager(); - if (pExportManager) - { - pExportManager->RegisterExporter(new CFBXExporter()); - } - - GetIEditor()->GetSystem()->GetILog()->Log("FBX plugin: CreatePluginInstance"); - return new CFBXPlugin; -} diff --git a/Code/Sandbox/Plugins/FBXPlugin/resource.h b/Code/Sandbox/Plugins/FBXPlugin/resource.h deleted file mode 100644 index 0784105d96..0000000000 --- a/Code/Sandbox/Plugins/FBXPlugin/resource.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#define IDD_FBX_EXPORT_SETTINGS 103 -#define IDC_COPY_TEXTURES 1003 -#define IDC_EMBEDDED 1004 -#define IDC_FILE_FORMAT 1005 -#define IDC_CONVERT_CAMERAS_FOR_MAX_MAYA 1006 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 104 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1007 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/Code/Sandbox/Plugins/PerforcePlugin/PerforceSourceControl.h b/Code/Sandbox/Plugins/PerforcePlugin/PerforceSourceControl.h index 16489d99fc..1efbbc912c 100644 --- a/Code/Sandbox/Plugins/PerforcePlugin/PerforceSourceControl.h +++ b/Code/Sandbox/Plugins/PerforcePlugin/PerforceSourceControl.h @@ -26,7 +26,7 @@ class CPerforceSourceControl public: // constructor CPerforceSourceControl() = default; - ~CPerforceSourceControl() = default; + virtual ~CPerforceSourceControl() = default; void Init(); diff --git a/Code/Tools/AssetBundler/CMakeLists.txt b/Code/Tools/AssetBundler/CMakeLists.txt index 41b95fd2ae..c99ffaef6b 100644 --- a/Code/Tools/AssetBundler/CMakeLists.txt +++ b/Code/Tools/AssetBundler/CMakeLists.txt @@ -13,9 +13,13 @@ if(NOT PAL_TRAIT_BUILD_HOST_TOOLS) return() endif() +include(${CMAKE_CURRENT_SOURCE_DIR}/Platform/${PAL_PLATFORM_NAME}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake) + +# AssetBundlerBatch - CLI Application ly_add_target( - NAME AssetBundler.Static STATIC + NAME AssetBundlerBatch.Static STATIC NAMESPACE AZ + AUTOMOC FILES_CMAKE assetbundlerbatch_files.cmake INCLUDE_DIRECTORIES @@ -23,6 +27,9 @@ ly_add_target( . BUILD_DEPENDENCIES PUBLIC + 3rdParty::Qt::Core + 3rdParty::Qt::Gui + 3rdParty::Qt::Widgets AZ::AzToolsFramework ${additional_dependencies} ) @@ -32,12 +39,41 @@ ly_add_target( NAMESPACE AZ FILES_CMAKE assetbundlerbatch_exe_files.cmake + COMPILE_DEFINITIONS + PRIVATE + AB_BATCH_MODE INCLUDE_DIRECTORIES PRIVATE . BUILD_DEPENDENCIES PRIVATE - AZ::AssetBundler.Static + AZ::AssetBundlerBatch.Static +) + +# AssetBundler - Qt GUI Application +ly_add_target( + NAME AssetBundler ${PAL_TRAIT_BUILD_ASSETBUNDLER_APPLICATION_TYPE} + NAMESPACE AZ + AUTOMOC + AUTOUIC + AUTORCC + FILES_CMAKE + assetbundlergui_files.cmake + assetbundler_exe_files.cmake + Platform/${PAL_PLATFORM_NAME}/assetbundlergui_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake + INCLUDE_DIRECTORIES + PUBLIC + Platform/${PAL_PLATFORM_NAME} + PRIVATE + . + BUILD_DEPENDENCIES + PUBLIC + 3rdParty::Qt::Core + 3rdParty::Qt::Gui + 3rdParty::Qt::Widgets + AZ::AzToolsFramework + AZ::AssetBundlerBatch.Static + ${additional_dependencies} ) if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) @@ -53,7 +89,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) BUILD_DEPENDENCIES PRIVATE AZ::AzTest - AZ::AssetBundler.Static + AZ::AssetBundlerBatch.Static AZ::AzFrameworkTestShared ) diff --git a/Code/Sandbox/Plugins/FBXPlugin/Platform/Mac/platform_mac.cmake b/Code/Tools/AssetBundler/Platform/Linux/PAL_linux.cmake similarity index 88% rename from Code/Sandbox/Plugins/FBXPlugin/Platform/Mac/platform_mac.cmake rename to Code/Tools/AssetBundler/Platform/Linux/PAL_linux.cmake index fc4f6ca1b3..d0d27a99ac 100644 --- a/Code/Sandbox/Plugins/FBXPlugin/Platform/Mac/platform_mac.cmake +++ b/Code/Tools/AssetBundler/Platform/Linux/PAL_linux.cmake @@ -9,4 +9,5 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -set(PAL_TRAIT_BUILD_FBX_PLUGIN_SUPPORTED TRUE) +set (PAL_TRAIT_BUILD_ASSETBUNDLER_APPLICATION_TYPE APPLICATION) + diff --git a/Gems/SVOGI/Code/Source/Platform/iOS/platform_ios_files.cmake b/Code/Tools/AssetBundler/Platform/Linux/assetbundlergui_linux_files.cmake similarity index 90% rename from Gems/SVOGI/Code/Source/Platform/iOS/platform_ios_files.cmake rename to Code/Tools/AssetBundler/Platform/Linux/assetbundlergui_linux_files.cmake index 0a7d42c2a4..23bbefccdc 100644 --- a/Gems/SVOGI/Code/Source/Platform/iOS/platform_ios_files.cmake +++ b/Code/Tools/AssetBundler/Platform/Linux/assetbundlergui_linux_files.cmake @@ -10,6 +10,5 @@ # set(FILES - SVOGI_Traits_Platform.h - SVOGI_Traits_iOS.h -) + source/utils/GUIApplicationManager_Linux.cpp +) \ No newline at end of file diff --git a/Code/Sandbox/Editor/Style/LensFlareEditor.qss b/Code/Tools/AssetBundler/Platform/Linux/source/utils/GUIApplicationManager_Linux.cpp similarity index 67% rename from Code/Sandbox/Editor/Style/LensFlareEditor.qss rename to Code/Tools/AssetBundler/Platform/Linux/source/utils/GUIApplicationManager_Linux.cpp index 58d99c9f92..7af09214cb 100644 --- a/Code/Sandbox/Editor/Style/LensFlareEditor.qss +++ b/Code/Tools/AssetBundler/Platform/Linux/source/utils/GUIApplicationManager_Linux.cpp @@ -10,8 +10,12 @@ * */ -#DatabaseFrameWnd QToolBar -{ - border-bottom: 2px solid #111111; -} +#include +namespace Platform +{ + AzQtComponents::WindowDecorationWrapper::Option GetWindowDecorationWrapperOption() + { + return AzQtComponents::WindowDecorationWrapper::OptionDisabled; + } +} \ No newline at end of file diff --git a/Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/platform_windows.cmake b/Code/Tools/AssetBundler/Platform/Mac/PAL_mac.cmake similarity index 88% rename from Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/platform_windows.cmake rename to Code/Tools/AssetBundler/Platform/Mac/PAL_mac.cmake index fc4f6ca1b3..d0d27a99ac 100644 --- a/Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/platform_windows.cmake +++ b/Code/Tools/AssetBundler/Platform/Mac/PAL_mac.cmake @@ -9,4 +9,5 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -set(PAL_TRAIT_BUILD_FBX_PLUGIN_SUPPORTED TRUE) +set (PAL_TRAIT_BUILD_ASSETBUNDLER_APPLICATION_TYPE APPLICATION) + diff --git a/Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/platform_windows_files.cmake b/Code/Tools/AssetBundler/Platform/Mac/assetbundlergui_mac_files.cmake similarity index 91% rename from Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/platform_windows_files.cmake rename to Code/Tools/AssetBundler/Platform/Mac/assetbundlergui_mac_files.cmake index 7e654edcbe..a8a116ac79 100644 --- a/Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/platform_windows_files.cmake +++ b/Code/Tools/AssetBundler/Platform/Mac/assetbundlergui_mac_files.cmake @@ -10,5 +10,5 @@ # set(FILES - DllMain_Windows.cpp -) + source/utils/GUIApplicationManager_OSX.cpp +) \ No newline at end of file diff --git a/Gems/Visibility/Code/Source/VisibilityGem.h b/Code/Tools/AssetBundler/Platform/Mac/source/utils/GUIApplicationManager_OSX.cpp similarity index 67% rename from Gems/Visibility/Code/Source/VisibilityGem.h rename to Code/Tools/AssetBundler/Platform/Mac/source/utils/GUIApplicationManager_OSX.cpp index 1abc1b8901..7af09214cb 100644 --- a/Gems/Visibility/Code/Source/VisibilityGem.h +++ b/Code/Tools/AssetBundler/Platform/Mac/source/utils/GUIApplicationManager_OSX.cpp @@ -10,18 +10,12 @@ * */ -#pragma once +#include -#include - -#include - - -class VisibilityGem - : public AZ::Module +namespace Platform { -public: - AZ_RTTI(VisibilityGem, "{5138F2B6-EDFB-490E-AB3E-B82E43263A20}"); - - VisibilityGem(); -}; + AzQtComponents::WindowDecorationWrapper::Option GetWindowDecorationWrapperOption() + { + return AzQtComponents::WindowDecorationWrapper::OptionDisabled; + } +} \ No newline at end of file diff --git a/Code/Sandbox/Plugins/FBXPlugin/Platform/Linux/platform_linux.cmake b/Code/Tools/AssetBundler/Platform/Windows/PAL_windows.cmake similarity index 88% rename from Code/Sandbox/Plugins/FBXPlugin/Platform/Linux/platform_linux.cmake rename to Code/Tools/AssetBundler/Platform/Windows/PAL_windows.cmake index ed7bdab4b2..d0d27a99ac 100644 --- a/Code/Sandbox/Plugins/FBXPlugin/Platform/Linux/platform_linux.cmake +++ b/Code/Tools/AssetBundler/Platform/Windows/PAL_windows.cmake @@ -9,4 +9,5 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -set(PAL_TRAIT_BUILD_FBX_PLUGIN_SUPPORTED FALSE) +set (PAL_TRAIT_BUILD_ASSETBUNDLER_APPLICATION_TYPE APPLICATION) + diff --git a/Gems/SVOGI/Code/Source/Platform/Mac/platform_mac_files.cmake b/Code/Tools/AssetBundler/Platform/Windows/assetbundlergui_windows_files.cmake similarity index 90% rename from Gems/SVOGI/Code/Source/Platform/Mac/platform_mac_files.cmake rename to Code/Tools/AssetBundler/Platform/Windows/assetbundlergui_windows_files.cmake index 81bdc1acba..f9e1ffda8d 100644 --- a/Gems/SVOGI/Code/Source/Platform/Mac/platform_mac_files.cmake +++ b/Code/Tools/AssetBundler/Platform/Windows/assetbundlergui_windows_files.cmake @@ -10,6 +10,5 @@ # set(FILES - SVOGI_Traits_Platform.h - SVOGI_Traits_Mac.h -) + source/utils/GUIApplicationManager_Win.cpp +) \ No newline at end of file diff --git a/Code/Sandbox/Editor/Geometry/EdGeometry.cpp b/Code/Tools/AssetBundler/Platform/Windows/source/utils/GUIApplicationManager_Win.cpp similarity index 67% rename from Code/Sandbox/Editor/Geometry/EdGeometry.cpp rename to Code/Tools/AssetBundler/Platform/Windows/source/utils/GUIApplicationManager_Win.cpp index 13e8dd96ba..99e254a774 100644 --- a/Code/Sandbox/Editor/Geometry/EdGeometry.cpp +++ b/Code/Tools/AssetBundler/Platform/Windows/source/utils/GUIApplicationManager_Win.cpp @@ -9,8 +9,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#include "EditorDefs.h" +#include -#include "EdGeometry.h" +namespace Platform +{ + AzQtComponents::WindowDecorationWrapper::Option GetWindowDecorationWrapperOption() + { + return AzQtComponents::WindowDecorationWrapper::OptionAutoAttach; + } +} \ No newline at end of file diff --git a/Gems/SVOGI/Code/svogi_shared_files.cmake b/Code/Tools/AssetBundler/assetbundler_exe_files.cmake similarity index 91% rename from Gems/SVOGI/Code/svogi_shared_files.cmake rename to Code/Tools/AssetBundler/assetbundler_exe_files.cmake index 11d334c13e..976405c4f7 100644 --- a/Gems/SVOGI/Code/svogi_shared_files.cmake +++ b/Code/Tools/AssetBundler/assetbundler_exe_files.cmake @@ -10,5 +10,6 @@ # set(FILES - Source/SVOGIModule.cpp + source/main.cpp + source/AssetBundler.rc ) diff --git a/Code/Tools/AssetBundler/assetbundlergui_files.cmake b/Code/Tools/AssetBundler/assetbundlergui_files.cmake new file mode 100644 index 0000000000..7ac5d34eb3 --- /dev/null +++ b/Code/Tools/AssetBundler/assetbundlergui_files.cmake @@ -0,0 +1,70 @@ +# +# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +# its licensors. +# +# For complete copyright and license terms please see the LICENSE at the root of this +# distribution (the "License"). All use of this software is governed by the License, +# or, if provided, by the license below or the license accompanying this file. Do not +# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# + +set(FILES + source/models/AssetBundlerAbstractFileTableModel.h + source/models/AssetBundlerAbstractFileTableModel.cpp + source/models/AssetBundlerFileTableFilterModel.h + source/models/AssetBundlerFileTableFilterModel.cpp + source/models/AssetListFileTableModel.h + source/models/AssetListFileTableModel.cpp + source/models/AssetListTableModel.cpp + source/models/AssetListTableModel.h + source/models/BundleFileListModel.h + source/models/BundleFileListModel.cpp + source/models/RulesFileTableModel.h + source/models/RulesFileTableModel.cpp + source/models/SeedListFileTableModel.h + source/models/SeedListFileTableModel.cpp + source/models/SeedListTableModel.h + source/models/SeedListTableModel.cpp + source/ui/style/AssetBundler.qrc + source/ui/style/AssetBundler.qss + source/ui/style/AssetBundlerConfig.ini + source/ui/style/AssetBundler-Icon-256x256@x2.ico + source/ui/AddSeedDialog.h + source/ui/AddSeedDialog.cpp + source/ui/AddSeedDialog.ui + source/ui/AssetBundlerTabWidget.h + source/ui/AssetBundlerTabWidget.cpp + source/ui/AssetListTabWidget.h + source/ui/AssetListTabWidget.cpp + source/ui/AssetListTabWidget.ui + source/ui/BundleListTabWidget.h + source/ui/BundleListTabWidget.cpp + source/ui/BundleListTabWidget.ui + source/ui/ComparisonDataWidget.h + source/ui/ComparisonDataWidget.cpp + source/ui/ComparisonDataWidget.ui + source/ui/EditSeedDialog.h + source/ui/EditSeedDialog.cpp + source/ui/EditSeedDialog.ui + source/ui/GenerateBundlesModal.h + source/ui/GenerateBundlesModal.cpp + source/ui/GenerateBundlesModal.ui + source/ui/MainWindow.h + source/ui/MainWindow.cpp + source/ui/MainWindow.ui + source/ui/NewFileDialog.h + source/ui/NewFileDialog.cpp + source/ui/NewFileDialog.ui + source/ui/PlatformSelectionWidget.h + source/ui/PlatformSelectionWidget.cpp + source/ui/PlatformSelectionWidget.ui + source/ui/RulesTabWidget.h + source/ui/RulesTabWidget.cpp + source/ui/RulesTabWidget.ui + source/ui/SeedTabWidget.h + source/ui/SeedTabWidget.cpp + source/ui/SeedTabWidget.ui + source/utils/GUIApplicationManager.h + source/utils/GUIApplicationManager.cpp +) diff --git a/Code/Tools/AssetBundler/source/AssetBundler.rc b/Code/Tools/AssetBundler/source/AssetBundler.rc new file mode 100644 index 0000000000..a3116a384f --- /dev/null +++ b/Code/Tools/AssetBundler/source/AssetBundler.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "ui\\style\\AssetBundler-Icon-256x256@x2.ico" diff --git a/Code/Tools/AssetBundler/source/main.cpp b/Code/Tools/AssetBundler/source/main.cpp index f1b782ff44..be152d6bf3 100644 --- a/Code/Tools/AssetBundler/source/main.cpp +++ b/Code/Tools/AssetBundler/source/main.cpp @@ -10,17 +10,48 @@ * */ +#if defined(AB_BATCH_MODE) #include +#else +#include +#include +#endif + +#if defined(AZ_TESTS_ENABLED) +#include +DECLARE_AZ_UNIT_TEST_MAIN(); +#endif int main(int argc, char* argv[]) { +#if defined(AZ_TESTS_ENABLED) + INVOKE_AZ_UNIT_TEST_MAIN(); +#endif + AZ::AllocatorInstance::Create(); int runSuccess = 0; + { - AssetBundler::ApplicationManager applicationManger(&argc, &argv); - applicationManger.Init(); - runSuccess = applicationManger.Run() ? 0 : 1; + //This nested scope is necessary as the applicationManager needs to have its destructor called BEFORE you destroy the allocators + +#if defined(AB_BATCH_MODE) + AssetBundler::ApplicationManager applicationManager(&argc, &argv); +#else + // Must be called before using any Qt, or the app won't be able to locate Qt libs + AzQtComponents::PrepareQtPaths(); + AssetBundler::GUIApplicationManager applicationManager(&argc, &argv); +#endif + if (!applicationManager.Init()) + { + AZ_Error("AssetBundler", false, "AssetBundler initialization failed"); + runSuccess = 1; + } + else + { + runSuccess = applicationManager.Run() ? 0 : 1; + } } + AZ::AllocatorInstance::Destroy(); return runSuccess; } diff --git a/Code/Tools/AssetBundler/source/models/AssetBundlerAbstractFileTableModel.cpp b/Code/Tools/AssetBundler/source/models/AssetBundlerAbstractFileTableModel.cpp new file mode 100644 index 0000000000..73bc075deb --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/AssetBundlerAbstractFileTableModel.cpp @@ -0,0 +1,244 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include + +#include + +namespace AssetBundler +{ + const char* DateTimeFormat = "hh:mm:ss MMM dd, yyyy"; + const char* ReadOnlyFileErrorMessage = "File (%s) is Read-Only. Please check your version control and try again."; + + AssetBundlerAbstractFileTableModel::AssetBundlerAbstractFileTableModel(QObject* parent) + : QAbstractTableModel(parent) + { + } + + void AssetBundlerAbstractFileTableModel::Reload( + const char* fileExtension, + const QSet& watchedFolders, + const QSet& watchedFiles, + const AZStd::unordered_map& pathToProjectNameMap) + { + AZStd::vector keysToRemove = m_fileListKeys; + + // Reload all the files in the watched folders + QString filter = QString("*.%1").arg(fileExtension); + + QSetIterator itr(watchedFolders); + while (itr.hasNext()) + { + QDir filesDir(itr.next()); + filesDir.setNameFilters({ filter }); + for (const QString& fileNameAndExtension : filesDir.entryList(QDir::Files)) + { + AZStd::string absolutePath = filesDir.absoluteFilePath(fileNameAndExtension).toUtf8().data(); + AZStd::string projectName; + if (pathToProjectNameMap.contains(absolutePath)) + { + projectName = pathToProjectNameMap.at(absolutePath); + } + + // If a project name is already specified, then the associated file is a default file + LoadFile(absolutePath, projectName, !projectName.empty()); + keysToRemove.erase( + AZStd::remove(keysToRemove.begin(), keysToRemove.end(), AssetBundler::GenerateKeyFromAbsolutePath(absolutePath)), + keysToRemove.end()); + } + } + + // Reload all the watched files + for (const QString& filePath : watchedFiles) + { + AZStd::string absolutePath = filePath.toUtf8().data(); + if (AZ::IO::FileIOBase::GetInstance()->Exists(absolutePath.c_str())) + { + AZStd::string projectName = pathToProjectNameMap.at(absolutePath); + + // If a project name is already specified, then the associated file is a default file + LoadFile(absolutePath, projectName, !projectName.empty()); + keysToRemove.erase( + AZStd::remove(keysToRemove.begin(), keysToRemove.end(), AssetBundler::GenerateKeyFromAbsolutePath(absolutePath)), + keysToRemove.end()); + } + } + + //Remove nonexistant files from the model + for (const AZStd::string& key : keysToRemove) + { + DeleteFileByKey(key); + } + } + + void AssetBundlerAbstractFileTableModel::ReloadFiles( + const AZStd::vector& absoluteFilePathList, + AZStd::unordered_map pathToProjectNameMap) + { + for (const AZStd::string& absoluteFilePath : absoluteFilePathList) + { + if (!AZ::IO::FileIOBase::GetInstance()->Exists(absoluteFilePath.c_str())) + { + // File is not present on-disk, make sure to remove it from the model + DeleteFileByKey(AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath)); + continue; + } + + // If a project name is already specified, then the associated file is a default file + AZStd::string projectName = pathToProjectNameMap[absoluteFilePath]; + LoadFile(absoluteFilePath, projectName, !projectName.empty()); + } + } + + bool AssetBundlerAbstractFileTableModel::Save(const QModelIndex& selectedIndex) + { + if (!selectedIndex.isValid() || m_keysWithUnsavedChanges.empty()) + { + // There is nothing to save + return true; + } + + AZStd::string key = GetFileKey(selectedIndex); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + // Save the file + if (!WriteToDisk(key)) + { + return false; + } + + // Update the display + m_keysWithUnsavedChanges.erase(key); + QModelIndex topLeftIndex = index(selectedIndex.row(), 0); + QModelIndex bottomRightIndex = index(selectedIndex.row(), columnCount() - 1); + emit dataChanged(topLeftIndex, bottomRightIndex, { Qt::DisplayRole, Qt::FontRole }); + + return true; + } + + bool AssetBundlerAbstractFileTableModel::SaveAll() + { + if (!HasUnsavedChanges()) + { + // No need to update all of the elements if we are not changing anything + return true; + } + + bool hasSaveErrors = false; + + // Save every file with unsaved changes + AZStd::unordered_set keysWithErrors; + for (const AZStd::string& key : m_keysWithUnsavedChanges) + { + if (!WriteToDisk(key)) + { + // Error has already been thrown + hasSaveErrors = true; + keysWithErrors.emplace(key); + } + } + + m_keysWithUnsavedChanges = keysWithErrors; + + // Update the display of all elements + QModelIndex firstIndex = index(0, 0); + QModelIndex lastIndex = index(rowCount() - 1, columnCount() - 1); + emit dataChanged(firstIndex, lastIndex, { Qt::DisplayRole, Qt::FontRole }); + + return !hasSaveErrors; + } + + bool AssetBundlerAbstractFileTableModel::HasUnsavedChanges() const + { + return !m_keysWithUnsavedChanges.empty(); + } + + int AssetBundlerAbstractFileTableModel::rowCount(const QModelIndex& /*parent*/) const + { + return static_cast(m_fileListKeys.size()); + } + + AZStd::string AssetBundlerAbstractFileTableModel::GetFileKey(const QModelIndex& index) const + { + int row = index.row(); + int col = index.column(); + if (row >= rowCount() || row < 0 || col >= columnCount() || col < 0) + { + AZ_Error("AssetBundler", false, "Selected index (%i, %i) is out of range.", row, col); + return {}; + } + + return m_fileListKeys.at(row); + } + + const AZStd::vector& AssetBundlerAbstractFileTableModel::GetAllFileKeys() const + { + return m_fileListKeys; + } + + int AssetBundlerAbstractFileTableModel::GetIndexRowByKey(const AZStd::string& key) const + { + auto it = AZStd::find(m_fileListKeys.begin(), m_fileListKeys.end(), key); + return it == m_fileListKeys.end() ? -1 : static_cast(AZStd::distance(m_fileListKeys.begin(), it)); + } + + void AssetBundlerAbstractFileTableModel::AddFileKey(const AZStd::string& key) + { + if (AZStd::find(m_fileListKeys.begin(), m_fileListKeys.end(), key) != m_fileListKeys.end()) + { + // Key already exists. This could happen when we update existing entires. + return; + } + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_fileListKeys.push_back(key); + endInsertRows(); + } + + bool AssetBundlerAbstractFileTableModel::RemoveFileKey(const QModelIndex& index) + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + int row = index.row(); + beginRemoveRows(QModelIndex(), row, row); + + m_fileListKeys.erase(m_fileListKeys.begin() + row); + m_keysWithUnsavedChanges.erase(key); + + endRemoveRows(); + + return true; + } + + bool AssetBundlerAbstractFileTableModel::DeleteFileByKey(const AZStd::string& key) + { + int indexRow = GetIndexRowByKey(key); + if (indexRow >= 0) + { + return DeleteFile(index(indexRow, 0)); + } + + return false; + } +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/AssetBundlerAbstractFileTableModel.h b/Code/Tools/AssetBundler/source/models/AssetBundlerAbstractFileTableModel.h new file mode 100644 index 0000000000..6c7ae81254 --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/AssetBundlerAbstractFileTableModel.h @@ -0,0 +1,124 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + + +namespace AssetBundler +{ + + extern const char* DateTimeFormat; + extern const char* ReadOnlyFileErrorMessage; + + //! Provides an abstract model that can be subclassed to create table models used to store information about files found on-disk. + class AssetBundlerAbstractFileTableModel + : public QAbstractTableModel + { + public: + + enum DataRoles + { + SortRole = Qt::UserRole + 1, + }; + + explicit AssetBundlerAbstractFileTableModel(QObject* parent = nullptr); + virtual ~AssetBundlerAbstractFileTableModel() {} + + ////////////////////////////////////////////////////////////////////////// + // Pure virtual functions + virtual AZStd::vector CreateNewFiles( + const AZStd::string& absoluteFilePath, + const AzFramework::PlatformFlags& platforms, + const QString& project = QString()) = 0; + virtual bool DeleteFile(const QModelIndex& index) = 0; + virtual void LoadFile( + const AZStd::string& absoluteFilePath, + const AZStd::string& projectName = "", + bool isDefaultFile = false) = 0; + virtual bool WriteToDisk(const AZStd::string& key) = 0; + + //! Returns the absolute path of the file at the given index on success, returns an empty string on failure. + virtual AZStd::string GetFileAbsolutePath(const QModelIndex& index) const = 0; + + virtual int GetFileNameColumnIndex() const = 0; + virtual int GetTimeStampColumnIndex() const = 0; + ////////////////////////////////////////////////////////////////////////// + + //! Reload all the data based on the watched folders and files + virtual void Reload( + const char* fileExtension, + const QSet& watchedFolders, + const QSet& watchedFiles = QSet(), + const AZStd::unordered_map& pathToProjectNameMap = AZStd::unordered_map()); + + virtual void ReloadFiles( + const AZStd::vector& absoluteFilePathList, + AZStd::unordered_map pathToProjectNameMap = AZStd::unordered_map()); + + bool Save(const QModelIndex& selectedIndex); + + bool SaveAll(); + + bool HasUnsavedChanges() const; + + ////////////////////////////////////////////////////////////////////////// + // QAbstractTableModel overrides + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + ////////////////////////////////////////////////////////////////////////// + + protected: + //! Verifies input index is in range and returns the associated key. + //! Throws an error and returns an empty string if the input index is out of range. + AZStd::string GetFileKey(const QModelIndex& index) const; + + //! Returns an ordered list of every file key in the model. + //! If a proxy model is not used, the order of this list will also be the display order. + const AZStd::vector& GetAllFileKeys() const; + + //! Get the index row if the file info is stored in the model + //! Returns -1 if the file key doesn't exist. + int GetIndexRowByKey(const AZStd::string& key) const; + + //! Adds input key to the end of the list of all keys and notifies the view that a row has been added. + //! When subclassing, instantiate all data associated with this key so the view can update properly. + void AddFileKey(const AZStd::string& key); + + //! Verifies input index, signals to the view that rows will be removed, and removes the key found at the input index. + //! When subclassing, be sure to remove all data associated with the key at this index before calling this function. + //! Returns true if the index is successfully removed, and false on failure + bool RemoveFileKey(const QModelIndex& index); + + //! Delete a file from the disk and remove it from the model by its key + bool DeleteFileByKey(const AZStd::string& key); + + AZStd::unordered_set m_keysWithUnsavedChanges; + + private: + //! When subclassing: store file information in a map, and add the keys to this vector. + //! Provides a 1:1 mapping between a QModelIndex::row value and a key. + AZStd::vector m_fileListKeys; + }; + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/AssetBundlerFileTableFilterModel.cpp b/Code/Tools/AssetBundler/source/models/AssetBundlerFileTableFilterModel.cpp new file mode 100644 index 0000000000..f9a24392a2 --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/AssetBundlerFileTableFilterModel.cpp @@ -0,0 +1,62 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include "AssetBundlerFileTableFilterModel.h" + +#include + +#include + +namespace AssetBundler +{ + AssetBundlerFileTableFilterModel::AssetBundlerFileTableFilterModel(QObject* parent, int displayNameCol, int dateTimeCol) + : QSortFilterProxyModel(parent) + , m_displayNameCol(displayNameCol) + , m_dateTimeCol(dateTimeCol) + { + } + + void AssetBundlerFileTableFilterModel::FilterChanged(const QString& newFilter) + { + setFilterRegExp(newFilter.toLower()); + invalidateFilter(); + } + + bool AssetBundlerFileTableFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const + { + // Override the default implemention since we want to define custom rules here + QModelIndex index = sourceModel()->index(sourceRow, m_displayNameCol, sourceParent); + QRegExp filter(filterRegExp()); + + return sourceModel()->data(index).toString().toLower().contains(filter); + } + + bool AssetBundlerFileTableFilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) const + { + // Any column displaying a DateTime string needs to be compared as a DateTime object to ensure + // proper sorting + if (left.column() != m_dateTimeCol || right.column() != m_dateTimeCol) + { + return QSortFilterProxyModel::lessThan(left, right); + } + + QVariant leftTime = sourceModel()->data(left, AssetBundlerAbstractFileTableModel::SortRole); + QVariant rightTime = sourceModel()->data(right, AssetBundlerAbstractFileTableModel::SortRole); + + if (leftTime.type() != QVariant::DateTime || rightTime.type() != QVariant::DateTime) + { + return QSortFilterProxyModel::lessThan(left, right); + } + + return leftTime.toDateTime() < rightTime.toDateTime(); + } +} diff --git a/Gems/LmbrCentral/Code/Source/Rendering/StereoRendererComponent.h b/Code/Tools/AssetBundler/source/models/AssetBundlerFileTableFilterModel.h similarity index 50% rename from Gems/LmbrCentral/Code/Source/Rendering/StereoRendererComponent.h rename to Code/Tools/AssetBundler/source/models/AssetBundlerFileTableFilterModel.h index 262c3cc5da..89f33c065a 100644 --- a/Gems/LmbrCentral/Code/Source/Rendering/StereoRendererComponent.h +++ b/Code/Tools/AssetBundler/source/models/AssetBundlerFileTableFilterModel.h @@ -12,26 +12,23 @@ #pragma once -#include +#include -/* -This class exposes functionality from the renderer to lua -*/ - -namespace LmbrCentral +namespace AssetBundler { - class StereoRendererComponent : - public AZ::Component + class AssetBundlerFileTableFilterModel + : public QSortFilterProxyModel { public: - AZ_COMPONENT(StereoRendererComponent, "{BBFE0965-5564-4739-8219-AFE8209A5E57}"); + AssetBundlerFileTableFilterModel(QObject* parent, int displayNameCol, int dateTimeCol = -1); - StereoRendererComponent() {}; - ~StereoRendererComponent() override {}; + void FilterChanged(const QString& newFilter); - void Activate() override {}; - void Deactivate() override {}; + protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; + bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; - static void Reflect(AZ::ReflectContext* context); + int m_displayNameCol = 0; + int m_dateTimeCol = -1; }; } diff --git a/Code/Tools/AssetBundler/source/models/AssetListFileTableModel.cpp b/Code/Tools/AssetBundler/source/models/AssetListFileTableModel.cpp new file mode 100644 index 0000000000..a2502c73a5 --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/AssetListFileTableModel.cpp @@ -0,0 +1,257 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace AssetBundler +{ + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // AssetListFileInfo + ////////////////////////////////////////////////////////////////////////////////////////////////// + AssetListFileInfo::AssetListFileInfo(const AZStd::string& absolutePath, const QString& fileName, const AZStd::string& platform) + : m_absolutePath(absolutePath) + , m_fileName(fileName) + , m_platform(QString(platform.c_str())) + { + AzFramework::StringFunc::Path::Normalize(m_absolutePath); + + // Modification time will either give us the time the file was last overwritten + // (or the time it was created if it has never been overwritten) + QFileInfo fileInfo(m_absolutePath.c_str()); + m_fileCreationTime = fileInfo.fileTime(QFileDevice::FileModificationTime); + + // Load the contents of the asset list file into memory + m_assetListModel.reset(new AssetListTableModel(nullptr, absolutePath, platform)); + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // AssetListFileTableModel + ////////////////////////////////////////////////////////////////////////////////////////////////// + AssetListFileTableModel::AssetListFileTableModel() + : AssetBundlerAbstractFileTableModel() + { + } + + QSharedPointer AssetListFileTableModel::GetAssetListFileContents(const QModelIndex& index) + { + auto assetListFileInfoOutcome = GetAssetFileInfo(index); + if (!assetListFileInfoOutcome.IsSuccess()) + { + return QSharedPointer(); + } + + return assetListFileInfoOutcome.GetValue()->m_assetListModel; + } + + bool AssetListFileTableModel::DeleteFile(const QModelIndex& index) + { + auto assetFileInfoOutcome = GetAssetFileInfo(index); + if (!assetFileInfoOutcome.IsSuccess()) + { + return false; + } + + AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(assetFileInfoOutcome.GetValue()->m_absolutePath); + if (m_assetListFileInfoMap.find(key) == m_assetListFileInfoMap.end()) + { + return false; + } + + AssetListFileInfoPtr assetFileInfo = m_assetListFileInfoMap[key]; + + // Remove file from disk + const char* absolutePath = assetFileInfo->m_absolutePath.c_str(); + if (AZ::IO::FileIOBase::GetInstance()->Exists(absolutePath)) + { + if (AZ::IO::FileIOBase::GetInstance()->IsReadOnly(absolutePath)) + { + AZ_Error(AssetBundler::AppWindowName, false, ReadOnlyFileErrorMessage, absolutePath); + return false; + } + + auto deleteResult = AZ::IO::FileIOBase::GetInstance()->Remove(absolutePath); + if (!deleteResult) + { + AZ_Error(AssetBundler::AppWindowName, false, + "Unable to delete (%s). Result code: %u", absolutePath, deleteResult.GetResultCode()); + return false; + } + } + + // Remove file from model + m_assetListFileInfoMap.erase(key); + RemoveFileKey(index); + + return true; + } + + void AssetListFileTableModel::LoadFile( + const AZStd::string& absoluteFilePath, + const AZStd::string& /*projectName*/, + bool /*isDefaultFile*/) + { + AZStd::string fullFileName; + AzFramework::StringFunc::Path::GetFullFileName(absoluteFilePath.c_str(), fullFileName); + + // Get the file name without the platform for display purposes + AZStd::string baseFileName; + AZStd::string platformIdentifier; + AzToolsFramework::SplitFilename(fullFileName, baseFileName, platformIdentifier); + + // Read the AssetListFile into memory and store it + AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath); + m_assetListFileInfoMap[key].reset(new AssetListFileInfo(absoluteFilePath, QString(baseFileName.c_str()), platformIdentifier)); + AddFileKey(key); + } + + bool AssetListFileTableModel::WriteToDisk(const AZStd::string& /*key*/) + { + return true; + } + + AZStd::string AssetListFileTableModel::GetFileAbsolutePath(const QModelIndex& index) const + { + auto assetFileInfoOutcome = GetAssetFileInfo(index); + if (!assetFileInfoOutcome.IsSuccess()) + { + // Error has already been thrown + return AZStd::string(); + } + return assetFileInfoOutcome.GetValue()->m_absolutePath; + } + + int AssetListFileTableModel::GetFileNameColumnIndex() const + { + return Column::ColumnFileName; + } + + int AssetListFileTableModel::GetTimeStampColumnIndex() const + { + return Column::ColumnFileCreationTime; + } + + int AssetListFileTableModel::columnCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : Column::Max; + } + + QVariant AssetListFileTableModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) + { + switch (section) + { + case Column::ColumnFileName: + return QString(tr("Asset List File")); + case Column::ColumnPlatform: + return QString(tr("Platform")); + case Column::ColumnFileCreationTime: + return QString(tr("Creation Time")); + default: + break; + } + } + + return QVariant(); + } + + QVariant AssetListFileTableModel::data(const QModelIndex& index, int role) const + { + auto assetListFileInfoOutcome = GetAssetFileInfo(index); + if (!assetListFileInfoOutcome.IsSuccess()) + { + return QVariant(); + } + + int col = index.column(); + + switch (role) + { + case Qt::DisplayRole: + [[fallthrough]]; + case SortRole: + { + if (col == Column::ColumnFileName) + { + return assetListFileInfoOutcome.GetValue()->m_fileName; + } + else if (col == Column::ColumnPlatform) + { + return assetListFileInfoOutcome.GetValue()->m_platform; + } + else if (col == Column::ColumnFileCreationTime) + { + if (role == SortRole) + { + return assetListFileInfoOutcome.GetValue()->m_fileCreationTime; + } + else + { + return assetListFileInfoOutcome.GetValue()->m_fileCreationTime.toString(DateTimeFormat); + } + } + else + { + // Returning an empty QString will ensure the checkboxes do not have any text displayed next to them + return QString(); + } + } + case Qt::FontRole: + { + if (col == Column::ColumnFileName) + { + QFont boldFont; + boldFont.setBold(true); + return boldFont; + } + } + default: + break; + } + + return QVariant(); + } + + AZ::Outcome AssetListFileTableModel::GetAssetFileInfo(const QModelIndex& index) const + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return AZ::Failure(); + } + + if (m_assetListFileInfoMap.find(key) != m_assetListFileInfoMap.end()) + { + return AZ::Success(m_assetListFileInfoMap.at(key)); + } + else + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot find Asset List File Info"); + return AZ::Failure(); + } + } + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/AssetListFileTableModel.h b/Code/Tools/AssetBundler/source/models/AssetListFileTableModel.h new file mode 100644 index 0000000000..699122a1ea --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/AssetListFileTableModel.h @@ -0,0 +1,91 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include + +#include +#include + +namespace AssetBundler +{ + class AssetListTableModel; + + struct AssetListFileInfo + { + /** + * Stores information about an Asset List File on disk. + * + * @param absolutePath The absolute path of the Asset List File + * @param fileName The name of the Asset List File. This does not include the platform ID + * @param platform The platform for the Asset List File + */ + AssetListFileInfo(const AZStd::string& absolutePath, const QString& fileName, const AZStd::string& platform); + + AZStd::string m_absolutePath; + QDateTime m_fileCreationTime; + /// Use QString for display purpose. This can help to avoid losts of string conversion + QString m_fileName; + QString m_platform; + + QSharedPointer m_assetListModel; + }; + + using AssetListFileInfoPtr = AZStd::shared_ptr; + /// Stores AssetListFileInfo, using the absolute path (without the drive letter) of the Asset List file as the key + using AssetListFileInfoMap = AZStd::unordered_map; + + class AssetListFileTableModel + : public AssetBundlerAbstractFileTableModel + { + public: + explicit AssetListFileTableModel(); + virtual ~AssetListFileTableModel() {} + + QSharedPointer GetAssetListFileContents(const QModelIndex& index); + + ////////////////////////////////////////////////////////////////////////// + // AssetBundlerAbstractFileTableModel overrides + AZStd::vector CreateNewFiles( + const AZStd::string& /*absoluteFilePath*/, + const AzFramework::PlatformFlags& /*platforms*/, + const QString& /*project*/) override { return {}; } + bool DeleteFile(const QModelIndex& index) override; + void LoadFile(const AZStd::string& absoluteFilePath, const AZStd::string& projectName = "", bool isDefaultFile = false) override; + bool WriteToDisk(const AZStd::string& key) override; + AZStd::string GetFileAbsolutePath(const QModelIndex& index) const override; + int GetFileNameColumnIndex() const override; + int GetTimeStampColumnIndex() const override; + + ////////////////////////////////////////////////////////////////////////// + // QAbstractListModel overrides + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex& index, int role) const override; + ////////////////////////////////////////////////////////////////////////// + + enum Column + { + ColumnFileName, + ColumnPlatform, + ColumnFileCreationTime, + Max + }; + + private: + AZ::Outcome GetAssetFileInfo(const QModelIndex& index) const; + + AssetListFileInfoMap m_assetListFileInfoMap; + }; + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/AssetListTableModel.cpp b/Code/Tools/AssetBundler/source/models/AssetListTableModel.cpp new file mode 100644 index 0000000000..cec057d38b --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/AssetListTableModel.cpp @@ -0,0 +1,129 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +#include + +#include + +namespace AssetBundler +{ + ////////////////////////////////////////////////////////////////////////////////////////////////// + // AssetListTableModel + ////////////////////////////////////////////////////////////////////////////////////////////////// + AssetListTableModel::AssetListTableModel(QObject* parent, const AZStd::string& absolutePath, const AZStd::string& platform) + : QAbstractTableModel(parent) + { + m_seedListManager.reset(new AzToolsFramework::AssetSeedManager()); + + if (absolutePath.empty() || platform.empty()) + { + return; + } + + AZ::Outcome outcome = m_seedListManager->LoadAssetFileInfo(absolutePath); + if (!outcome.IsSuccess()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Failed to load the asset file info for %s", absolutePath.c_str()); + return; + } + + m_assetFileInfoList = outcome.TakeValue(); + m_platformId = static_cast(AzFramework::PlatformHelper::GetPlatformIndexFromName(platform.c_str())); + } + + int AssetListTableModel::rowCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : static_cast(m_assetFileInfoList.m_fileInfoList.size()); + } + + int AssetListTableModel::columnCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : Column::Max; + } + + QVariant AssetListTableModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) + { + switch (section) + { + case Column::ColumnAssetName: + return QString("Asset Name"); + case Column::ColumnRelativePath: + return QString("Relative Path"); + case Column::ColumnAssetId: + return QString("Asset ID"); + default: + break; + } + } + + return QVariant(); + } + + QVariant AssetListTableModel::data(const QModelIndex& index, int role) const + { + auto assetFileInfoOutcome = GetAssetFileInfo(index); + if (!assetFileInfoOutcome.IsSuccess()) + { + return QVariant(); + } + + switch (role) + { + case Qt::DisplayRole: + { + switch (index.column()) + { + case Column::ColumnAssetName: + { + AZStd::string fileName = assetFileInfoOutcome.GetValue().m_assetRelativePath; + AzFramework::StringFunc::Path::GetFullFileName(fileName.c_str(), fileName); + + return fileName.c_str(); + } + case Column::ColumnRelativePath: + { + return assetFileInfoOutcome.GetValue().m_assetRelativePath.c_str(); + } + case Column::ColumnAssetId: + { + AZStd::string assetIdStr; + assetFileInfoOutcome.GetValue().m_assetId.ToString(assetIdStr); + + return assetIdStr.c_str(); + } + default: + break; + } + } + default: + break; + } + + return QVariant(); + } + + AZ::Outcome AssetListTableModel::GetAssetFileInfo(const QModelIndex& index) const + { + int row = index.row(); + int col = index.column(); + if (row >= rowCount() || row < 0 || col >= columnCount() || col < 0) + { + return AZ::Failure(AZStd::string::format("Selected index (%i, %i) is out of range", row, col)); + } + + return AZ::Success(m_assetFileInfoList.m_fileInfoList.at(row)); + } +} diff --git a/Code/Tools/AssetBundler/source/models/AssetListTableModel.h b/Code/Tools/AssetBundler/source/models/AssetListTableModel.h new file mode 100644 index 0000000000..f05fa0572b --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/AssetListTableModel.h @@ -0,0 +1,57 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include +#include + +#include + +namespace AssetBundler +{ + class AssetListTableModel + : public QAbstractTableModel + { + public: + explicit AssetListTableModel( + QObject* parent = nullptr, + const AZStd::string& absolutePath = AZStd::string(), + const AZStd::string& platform = ""); + virtual ~AssetListTableModel() {} + + AZStd::shared_ptr GetSeedListManager() { return m_seedListManager; } + + ////////////////////////////////////////////////////////////////////////// + // QAbstractListModel overrides + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex& index, int role) const override; + ////////////////////////////////////////////////////////////////////////// + + enum Column + { + ColumnAssetName, + ColumnRelativePath, + ColumnAssetId, + Max + }; + + private: + AZ::Outcome GetAssetFileInfo(const QModelIndex& index) const; + + AZStd::shared_ptr m_seedListManager; + AzToolsFramework::AssetFileInfoList m_assetFileInfoList; + AzFramework::PlatformId m_platformId; + }; +} diff --git a/Code/Tools/AssetBundler/source/models/BundleFileListModel.cpp b/Code/Tools/AssetBundler/source/models/BundleFileListModel.cpp new file mode 100644 index 0000000000..a2bb6ef91f --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/BundleFileListModel.cpp @@ -0,0 +1,240 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +#include +#include + +#include + +#include + + +namespace AssetBundler +{ + BundleFileInfo::BundleFileInfo(const AZStd::string& absolutePath) + : m_absolutePath(absolutePath) + , m_compressedSize(0u) + { + AzFramework::StringFunc::Path::Normalize(m_absolutePath); + + AZStd::string fileNameStr; + if (AzFramework::StringFunc::Path::GetFileName(m_absolutePath.c_str(), fileNameStr)) + { + m_fileName = QString(fileNameStr.c_str()); + } + else + { + AZ_Error("AssetBundler", false, "Failed to get file name from %s", m_absolutePath.c_str()); + } + + // Modification time will either give us the time the file was last overwritten + // (or the time it was created if it has never been overwritten) + QFileInfo fileInfo(m_absolutePath.c_str()); + m_fileCreationTime = fileInfo.fileTime(QFileDevice::FileModificationTime); + } + + BundleFileListModel::BundleFileListModel() + : AssetBundlerAbstractFileTableModel() + { + } + + bool BundleFileListModel::DeleteFile(const QModelIndex& index) + { + AZStd::string fileKey = GetFileKey(index); + if (fileKey.empty()) + { + // Error has already been thrown + return false; + } + + auto bundleFileInfoIt = m_bundleFileInfoMap.find(fileKey); + if (bundleFileInfoIt == m_bundleFileInfoMap.end()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Unable to find Bundle Info with key ( %s )", fileKey.c_str()); + return false; + } + + BundleFileInfoPtr bundleFileInfo = bundleFileInfoIt->second; + + // Remove file from disk + const char* absolutePath = bundleFileInfo->m_absolutePath.c_str(); + if (AZ::IO::FileIOBase::GetInstance()->Exists(absolutePath)) + { + if (AZ::IO::FileIOBase::GetInstance()->IsReadOnly(absolutePath)) + { + AZ_Error(AssetBundler::AppWindowName, false, ReadOnlyFileErrorMessage, absolutePath); + return false; + } + + auto deleteResult = AZ::IO::FileIOBase::GetInstance()->Remove(absolutePath); + if (!deleteResult) + { + AZ_Error(AssetBundler::AppWindowName, false, + "Unable to delete (%s). Result code: %u", absolutePath, deleteResult.GetResultCode()); + return false; + } + } + + // Remove file from Model + m_bundleFileInfoMap.erase(fileKey); + RemoveFileKey(index); + + return true; + } + + int BundleFileListModel::columnCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : Column::Max; + } + + QVariant BundleFileListModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) + { + switch (section) + { + case Column::ColumnFileName: + return QString(tr("Name")); + case Column::ColumnFileCreationTime: + return QString(tr("Creation Time")); + default: + break; + } + } + return QVariant(); + } + + QVariant BundleFileListModel::data(const QModelIndex& index, int role) const + { + auto bundleInfoOutcome = GetBundleInfo(index); + if (!bundleInfoOutcome.IsSuccess()) + { + return QVariant(); + } + + int col = index.column(); + + switch (role) + { + case Qt::DisplayRole: + [[fallthrough]]; + case SortRole: + { + if (col == Column::ColumnFileName) + { + return bundleInfoOutcome.GetValue()->m_fileName; + } + else if (col == Column::ColumnFileCreationTime) + { + if (role == SortRole) + { + return bundleInfoOutcome.GetValue()->m_fileCreationTime; + } + else + { + return bundleInfoOutcome.GetValue()->m_fileCreationTime.toString(DateTimeFormat); + } + } + } + default: + break; + } + + return QVariant(); + } + + AZStd::string BundleFileListModel::GetFileAbsolutePath(const QModelIndex& index) const + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return key; + } + + return m_bundleFileInfoMap.at(key)->m_absolutePath; + } + + int BundleFileListModel::GetFileNameColumnIndex() const + { + return Column::ColumnFileName; + } + + int BundleFileListModel::GetTimeStampColumnIndex() const + { + return Column::ColumnFileCreationTime; + } + + void BundleFileListModel::LoadFile( + const AZStd::string& absoluteFilePath, + const AZStd::string& /*projectName*/, + bool /*isDefaultFile*/) + { + AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath); + + BundleFileInfo* newInfo = new BundleFileInfo(absoluteFilePath); + + QFile bundleFile(absoluteFilePath.c_str()); + if (bundleFile.open(QIODevice::ReadOnly)) + { + newInfo->m_compressedSize = bundleFile.size(); + bundleFile.close(); + } + else + { + AZ_Error("AssetBundler", false, "Failed to open file at %s", absoluteFilePath.c_str()); + } + + auto manifest = AzToolsFramework::AssetBundleComponent::GetManifestFromBundle(absoluteFilePath); + if (manifest != nullptr) + { + for (auto& bundleName : manifest->GetDependentBundleNames()) + { + newInfo->m_relatedBundles.push_back(bundleName.c_str()); + } + } + else + { + AZ_Error("AssetBundler", false, "Failed to get manifest from bundle at %s", absoluteFilePath.c_str()); + } + + m_bundleFileInfoMap[key].reset(newInfo); + // Add it to the list that gets displayed by AssetBundlerAbstractFileTableModel. Make sure that + // AddFileKey is called after m_bundleFileInfoMap is reset since the filterAcceptsRow funtion + // of the filter model will be called when a new row is inserted and it could cause a crash + // without valid data being set + AddFileKey(key); + } + + AZ::Outcome BundleFileListModel::GetBundleInfo(const QModelIndex& index) const + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return AZ::Failure(); + } + + if (m_bundleFileInfoMap.find(key) != m_bundleFileInfoMap.end()) + { + return AZ::Success(m_bundleFileInfoMap.at(key)); + } + else + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot find Bundle File Info"); + return AZ::Failure(); + } + } + +} diff --git a/Code/Tools/AssetBundler/source/models/BundleFileListModel.h b/Code/Tools/AssetBundler/source/models/BundleFileListModel.h new file mode 100644 index 0000000000..320c2b2d59 --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/BundleFileListModel.h @@ -0,0 +1,77 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include +#include + +#include + +#include + +namespace AssetBundler +{ + + struct BundleFileInfo + { + AZStd::string m_absolutePath; + QString m_fileName; + QDateTime m_fileCreationTime; + AZ::u64 m_compressedSize; + QStringList m_relatedBundles; + + BundleFileInfo(const AZStd::string& absolutePath); + }; + + using BundleFileInfoPtr = AZStd::shared_ptr; + using BundleFileInfoMap = AZStd::unordered_map; + + class BundleFileListModel + : public AssetBundlerAbstractFileTableModel + { + public: + explicit BundleFileListModel(); + virtual ~BundleFileListModel() {} + + AZStd::vector CreateNewFiles( + const AZStd::string& /*absoluteFilePath*/, + const AzFramework::PlatformFlags& /*platforms*/, + const QString& /*project*/) override { return {}; } + bool DeleteFile(const QModelIndex& index) override; + void LoadFile(const AZStd::string& absoluteFilePath, const AZStd::string& projectName = "", bool isDefaultFile = false) override; + bool WriteToDisk(const AZStd::string& /*key*/) override { return true; } + + AZStd::string GetFileAbsolutePath(const QModelIndex& index) const override; + int GetFileNameColumnIndex() const override; + int GetTimeStampColumnIndex() const override; + + AZ::Outcome GetBundleInfo(const QModelIndex& index) const; + + ////////////////////////////////////////////////////////////////////////// + // QAbstractTableModel overrides + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex& index, int role) const override; + ////////////////////////////////////////////////////////////////////////// + + enum Column + { + ColumnFileName, + ColumnFileCreationTime, + Max + }; + + private: + BundleFileInfoMap m_bundleFileInfoMap; + }; +} diff --git a/Code/Tools/AssetBundler/source/models/RulesFileTableModel.cpp b/Code/Tools/AssetBundler/source/models/RulesFileTableModel.cpp new file mode 100644 index 0000000000..b452dee6bf --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/RulesFileTableModel.cpp @@ -0,0 +1,314 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +#include +#include +#include +#include + +#include +#include + +namespace AssetBundler +{ + RulesFileInfo::RulesFileInfo(const AZStd::string& absolutePath, const QString& fileName, bool loadFromFile) + : m_absolutePath(absolutePath) + , m_fileName(fileName) + { + AzFramework::StringFunc::Path::Normalize(m_absolutePath); + m_comparisonSteps = AZStd::make_shared(); + + if (loadFromFile) + { + auto outcome = AzToolsFramework::AssetFileInfoListComparison::Load(m_absolutePath); + if (!outcome.IsSuccess()) + { + AZ_Error("AssetBundler", false, outcome.GetError().c_str()); + return; + } + m_comparisonSteps = AZStd::make_unique(outcome.TakeValue()); + + QFileInfo fileInfo(m_absolutePath.c_str()); + m_fileModificationTime = fileInfo.fileTime(QFileDevice::FileModificationTime); + } + else + { + m_fileModificationTime = QDateTime::currentDateTime(); + } + } + + bool RulesFileInfo::SaveRulesFile() + { + if (!m_comparisonSteps->Save(m_absolutePath)) + { + return false; + } + + m_hasUnsavedChanges = false; + m_fileModificationTime = QDateTime::currentDateTime(); + return true; + } + + + + RulesFileTableModel::RulesFileTableModel() + : AssetBundlerAbstractFileTableModel() + { + } + + AZStd::vector RulesFileTableModel::CreateNewFiles( + const AZStd::string& absoluteFilePath, + const AzFramework::PlatformFlags& /*platforms*/, + const QString& /*project*/) + { + if (absoluteFilePath.empty()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Input file path is empty"); + return {}; + } + + // Create a platform-specific file path + if (AZ::IO::FileIOBase::GetInstance()->Exists(absoluteFilePath.c_str())) + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot Create New File: (%s) already exists", absoluteFilePath.c_str()); + return {}; + } + + // Get the file name without the extension for display purposes + AZStd::string fileName = absoluteFilePath; + AzToolsFramework::RemovePlatformIdentifier(fileName); + AzFramework::StringFunc::Path::GetFileName(fileName.c_str(), fileName); + + // Create a Rules File and save it to disk + AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath); + RulesFileInfoPtr newRulesFile = AZStd::make_shared(absoluteFilePath, QString(fileName.c_str()), false); + + if (!newRulesFile->SaveRulesFile()) + { + return {}; + } + + // Add the new file to the model + m_rulesFileInfoMap[key] = newRulesFile; + AddFileKey(key); + return { absoluteFilePath }; + } + + bool RulesFileTableModel::DeleteFile(const QModelIndex& index) + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + RulesFileInfoPtr rulesFileInfo = m_rulesFileInfoMap[key]; + + // Remove file from disk + if (AZ::IO::FileIOBase::GetInstance()->IsReadOnly(rulesFileInfo->m_absolutePath.c_str())) + { + AZ_Error(AssetBundler::AppWindowName, false, ReadOnlyFileErrorMessage, rulesFileInfo->m_absolutePath.c_str()); + return false; + } + + auto deleteResult = AZ::IO::FileIOBase::GetInstance()->Remove(rulesFileInfo->m_absolutePath.c_str()); + if (!deleteResult) + { + AZ_Error(AssetBundler::AppWindowName, false, + "Unable to delete (%s). Result code: %u", rulesFileInfo->m_absolutePath.c_str(), + deleteResult.GetResultCode()); + return false; + } + + // Remove file from model + m_rulesFileInfoMap.erase(key); + RemoveFileKey(index); + + return true; + } + + void RulesFileTableModel::LoadFile( + const AZStd::string& absoluteFilePath, + const AZStd::string& /*projectName*/, + bool /*isDefaultFile*/) + { + // Get the file name without the extension for display purposes + AZStd::string fileName(absoluteFilePath); + AzFramework::StringFunc::Path::GetFileName(fileName.c_str(), fileName); + + // Read the Rules file into memory and store it + AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath); + auto fileInfoIt = m_rulesFileInfoMap.find(key); + if (fileInfoIt != m_rulesFileInfoMap.end() && fileInfoIt->second->m_hasUnsavedChanges) + { + AZ_Warning(AssetBundler::AppWindowName, false, + "Rules File %s has unsaved changes and couldn't be reloaded", absoluteFilePath.c_str()); + return; + } + + m_rulesFileInfoMap[key] = AZStd::make_shared(absoluteFilePath, QString(fileName.c_str()), true); + AddFileKey(key); + } + + bool RulesFileTableModel::WriteToDisk(const AZStd::string& key) + { + auto rulesFileIt = m_rulesFileInfoMap.find(key); + return rulesFileIt != m_rulesFileInfoMap.end() && rulesFileIt->second->SaveRulesFile(); + } + + AZStd::string RulesFileTableModel::GetFileAbsolutePath(const QModelIndex& index) const + { + RulesFileInfoPtr rulesFileInfo = GetRulesFileInfoPtr(index); + if (!rulesFileInfo) + { + return AZStd::string(); + } + + return rulesFileInfo->m_absolutePath; + } + + int RulesFileTableModel::GetFileNameColumnIndex() const + { + return Column::ColumnFileName; + } + + int RulesFileTableModel::GetTimeStampColumnIndex() const + { + return Column::ColumnFileModificationTime; + } + + AZStd::shared_ptr RulesFileTableModel::GetComparisonSteps(const QModelIndex& index) const + { + RulesFileInfoPtr rulesFileInfo = GetRulesFileInfoPtr(index); + if (!rulesFileInfo) + { + return nullptr; + } + + return rulesFileInfo->m_comparisonSteps; + } + + bool RulesFileTableModel::MarkFileChanged(const QModelIndex& index) + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + m_rulesFileInfoMap[key]->m_hasUnsavedChanges = true; + + // Update display so the user knows there are unsaved changes + m_keysWithUnsavedChanges.emplace(key); + QModelIndex changedIndex = QAbstractTableModel::index(index.row(), Column::ColumnFileName); + emit dataChanged(changedIndex, changedIndex, { Qt::DisplayRole, Qt::FontRole }); + + return true; + } + + int RulesFileTableModel::columnCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : Column::Max; + } + + QVariant RulesFileTableModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) + { + switch (section) + { + case Column::ColumnFileName: + return QString(tr("Name")); + case Column::ColumnFileModificationTime: + return QString(tr("Modification Time")); + default: + break; + } + } + + return QVariant(); + } + + QVariant RulesFileTableModel::data(const QModelIndex& index, int role) const + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + return QVariant(); + } + + RulesFileInfoPtr rulesFileInfo = m_rulesFileInfoMap.at(key); + + int col = index.column(); + bool hasUnsavedChanges = rulesFileInfo->m_hasUnsavedChanges; + + switch (role) + { + case Qt::DisplayRole: + [[fallthrough]]; + case SortRole: + { + if (col == Column::ColumnFileName) + { + QString displayName = rulesFileInfo->m_fileName; + if (hasUnsavedChanges) + { + displayName.append("*"); + } + return displayName; + } + else if (col == Column::ColumnFileModificationTime) + { + if (role == SortRole) + { + return rulesFileInfo->m_fileModificationTime; + } + else + { + return rulesFileInfo->m_fileModificationTime.toString(DateTimeFormat); + } + } + break; + } + case Qt::FontRole: + { + if (col == Column::ColumnFileName && hasUnsavedChanges) + { + QFont boldFont; + boldFont.setBold(true); + return boldFont; + } + break; + } + default: + break; + } + + return QVariant(); + } + + RulesFileInfoPtr RulesFileTableModel::GetRulesFileInfoPtr(const QModelIndex& index) const + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + return nullptr; + } + + return m_rulesFileInfoMap.at(key); + } + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/RulesFileTableModel.h b/Code/Tools/AssetBundler/source/models/RulesFileTableModel.h new file mode 100644 index 0000000000..7808fc2479 --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/RulesFileTableModel.h @@ -0,0 +1,91 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include +#include + +#include + +#include + +namespace AssetBundler +{ + + //! Stores information about a Rules file on disk. + struct RulesFileInfo + { + RulesFileInfo(const AZStd::string& absolutePath, const QString& fileName, bool loadFromFile); + + bool SaveRulesFile(); + + AZStd::string m_absolutePath; + QString m_fileName; + QDateTime m_fileModificationTime; + bool m_hasUnsavedChanges = false; + + AZStd::shared_ptr m_comparisonSteps; + }; + + using RulesFileInfoPtr = AZStd::shared_ptr; + using RulesFileInfoMap = AZStd::unordered_map; + + + class RulesFileTableModel + : public AssetBundlerAbstractFileTableModel + { + public: + RulesFileTableModel(); + virtual ~RulesFileTableModel() {} + + AZStd::vector CreateNewFiles( + const AZStd::string& absoluteFilePath, + const AzFramework::PlatformFlags& platforms = AzFramework::PlatformFlags::Platform_NONE, + const QString& project = QString()) override; + + bool DeleteFile(const QModelIndex& index) override; + + void LoadFile(const AZStd::string& absoluteFilePath, const AZStd::string& projectName = "", bool isDefaultFile = false) override; + + bool WriteToDisk(const AZStd::string& key) override; + + AZStd::string GetFileAbsolutePath(const QModelIndex& index) const override; + + int GetFileNameColumnIndex() const override; + + int GetTimeStampColumnIndex() const override; + + AZStd::shared_ptr GetComparisonSteps(const QModelIndex& index) const; + + bool MarkFileChanged(const QModelIndex& index); + + ////////////////////////////////////////////////////////////////////////// + // QAbstractTableModel overrides + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex& index, int role) const override; + ////////////////////////////////////////////////////////////////////////// + + enum Column + { + ColumnFileName, + ColumnFileModificationTime, + Max + }; + + private: + RulesFileInfoMap m_rulesFileInfoMap; + + RulesFileInfoPtr GetRulesFileInfoPtr(const QModelIndex& index) const; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/SeedListFileTableModel.cpp b/Code/Tools/AssetBundler/source/models/SeedListFileTableModel.cpp new file mode 100644 index 0000000000..36622c809d --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/SeedListFileTableModel.cpp @@ -0,0 +1,625 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace AssetBundler +{ + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // SeedListFileInfo + ////////////////////////////////////////////////////////////////////////////////////////////////// + SeedListFileInfo::SeedListFileInfo( + const AZStd::string& absolutePath, + const QString& fileName, + const QString& project, + bool loadFromFile, + bool isDefaultSeedList, + const AZStd::vector& defaultSeeds, + const AzFramework::PlatformFlags& platforms) + : m_absolutePath(absolutePath) + , m_fileName(fileName) + , m_project(project) + , m_isDefaultSeedList(isDefaultSeedList) + { + AzFramework::StringFunc::Path::Normalize(m_absolutePath); + + // Load the contents of the seed file into memory + if (loadFromFile) + { + m_seedListModel.reset(new SeedListTableModel(nullptr, absolutePath)); + QFileInfo fileInfo(m_absolutePath.c_str()); + m_fileModificationTime = fileInfo.fileTime(QFileDevice::FileModificationTime); + } + else + { + m_seedListModel.reset(new SeedListTableModel(nullptr, "", defaultSeeds, platforms)); + m_fileModificationTime = QDateTime::currentDateTime(); + } + } + + bool SeedListFileInfo::SaveSeedFile() + { + if (m_seedListModel->Save(m_absolutePath)) + { + m_fileModificationTime = QDateTime::currentDateTime(); + return true; + } + return false; + } + + bool SeedListFileInfo::HasUnsavedChanges() + { + return m_seedListModel->HasUnsavedChanges(); + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // SeedListFileTableModel + ////////////////////////////////////////////////////////////////////////////////////////////////// + + SeedListFileTableModel::SeedListFileTableModel(SeedTabWidget* parentSeedTabWidget) + : AssetBundlerAbstractFileTableModel() + , m_seedTabWidget(parentSeedTabWidget) + { + m_inMemoryDefaultSeedList.reset(new SeedListFileInfo("", "", "", false)); + } + + SeedListFileTableModel::~SeedListFileTableModel() + { + m_seedTabWidget = nullptr; + } + + void SeedListFileTableModel::AddDefaultSeedsToInMemoryList( + const AZStd::vector& defaultSeeds, + const char* projectName, + const AzFramework::PlatformFlags& platforms) + { + m_inMemoryDefaultSeedList.reset( + new SeedListFileInfo(m_inMemoryDefaultSeedListKey, tr("DefaultSeeds"), QString(projectName), false, true, defaultSeeds, platforms)); + } + + AZStd::vector SeedListFileTableModel::CreateNewFiles( + const AZStd::string& absoluteFilePath, + const AzFramework::PlatformFlags& /*platforms*/, + const QString& project) + { + if (absoluteFilePath.empty()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Input file path is empty."); + return {}; + } + + // Get the file name without the extension for display purposes + AZStd::string fileName; + AzFramework::StringFunc::Path::GetFileName(absoluteFilePath.c_str(), fileName); + + // Create a Seed List File and save it to disk + AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath); + + AZStd::shared_ptr newSeedListFile = + AZStd::make_shared(absoluteFilePath, QString(fileName.c_str()), project, false); + newSeedListFile->m_seedListModel->SetHasUnsavedChanges(true); + bool saveResult = newSeedListFile->SaveSeedFile(); + if (!saveResult) + { + AZ_Error(AssetBundler::AppWindowName, false, "Unable to create Seed List File: %s", absoluteFilePath.c_str()); + return {}; + } + + // Add new file to the model + m_seedListFileInfoMap[key] = newSeedListFile; + AddFileKey(key); + + AZStd::vector createdFiles = { absoluteFilePath }; + return createdFiles; + } + + bool SeedListFileTableModel::DeleteFile(const QModelIndex& index) + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + if (m_seedListFileInfoMap.find(key) == m_seedListFileInfoMap.end()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Unable to find Seed File Info with key ( %s )", key.c_str()); + return false; + } + + SeedListFileInfoPtr seedFileInfo = m_seedListFileInfoMap[key]; + + // Remove file from disk + const char* absolutePath = seedFileInfo->m_absolutePath.c_str(); + if (AZ::IO::FileIOBase::GetInstance()->Exists(absolutePath)) + { + if (AZ::IO::FileIOBase::GetInstance()->IsReadOnly(absolutePath)) + { + AZ_Error(AssetBundler::AppWindowName, false, ReadOnlyFileErrorMessage, absolutePath); + return false; + } + + auto deleteResult = AZ::IO::FileIOBase::GetInstance()->Remove(absolutePath); + if (!deleteResult) + { + AZ_Error(AssetBundler::AppWindowName, false, + "Unable to delete (%s). Result code: %u", absolutePath, deleteResult.GetResultCode()); + return false; + } + } + + // Remove file from model + m_seedListFileInfoMap.erase(key); + RemoveFileKey(index); + + return true; + } + + void SeedListFileTableModel::Reload( + const char* fileExtension, + const QSet& watchedFolders, + const QSet& watchedFiles, + const AZStd::unordered_map& pathToProjectNameMap) + { + // Load in the Seed List files from disk + AssetBundlerAbstractFileTableModel::Reload(fileExtension, watchedFolders, watchedFiles, pathToProjectNameMap); + + // Add the in-memory Default Seed List to the model + m_seedListFileInfoMap[m_inMemoryDefaultSeedListKey] = m_inMemoryDefaultSeedList; + AddFileKey(m_inMemoryDefaultSeedListKey); + } + + void SeedListFileTableModel::LoadFile(const AZStd::string& absoluteFilePath, const AZStd::string& projectName, bool isDefaultFile) + { + // Get the file name without the extension for display purposes + AZStd::string fileName; + AzFramework::StringFunc::Path::GetFileName(absoluteFilePath.c_str(), fileName); + + // Read the SeedListFile into memory and store it + AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath); + auto fileInfoIt = m_seedListFileInfoMap.find(key); + if (fileInfoIt != m_seedListFileInfoMap.end() && fileInfoIt->second->HasUnsavedChanges()) + { + AZ_Warning(AssetBundler::AppWindowName, false, + "Seed List File %s has unsaved changes and couldn't be reloaded", absoluteFilePath.c_str()); + return; + } + + AZStd::string projectNameOnDisplay = projectName; + if (projectName.empty()) + { + auto outcome = AssetBundler::GetCurrentProjectName(); + if (!outcome.IsSuccess()) + { + AZ_Error(AssetBundler::AppWindowName, false, outcome.TakeError().c_str()); + return; + } + + projectNameOnDisplay = outcome.TakeValue(); + } + + m_seedListFileInfoMap[key].reset( + new SeedListFileInfo(absoluteFilePath, QString(fileName.c_str()), QString(projectNameOnDisplay.c_str()), true, isDefaultFile)); + AddFileKey(key); + } + + void SeedListFileTableModel::SelectDefaultSeedLists(bool setSelected) + { + for (const AZStd::string& key : GetAllFileKeys()) + { + auto seedFileInfo = m_seedListFileInfoMap[key]; + if (!seedFileInfo->m_isDefaultSeedList) + { + continue; + } + + seedFileInfo->m_isChecked = setSelected; + if(setSelected) + { + m_checkedSeedListFiles.insert(key); + } + else + { + m_checkedSeedListFiles.erase(key); + } + } + + m_seedTabWidget->SetGenerateAssetListsButtonEnabled(!m_checkedSeedListFiles.empty()); + + // Update the Check State display of all elements + QModelIndex firstIndex = index(0, 0); + QModelIndex lastIndex = index(rowCount() - 1, columnCount() - 1); + emit dataChanged(firstIndex, lastIndex, { Qt::CheckStateRole }); + } + + AZStd::vector SeedListFileTableModel::GenerateAssetLists( + const AZStd::string& absoluteFilePath, + const AzFramework::PlatformFlags& platforms) + { + if (!m_checkedSeedListFiles.size()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot Generate Asset List File(s): No Seed List Files are selected"); + return {}; + } + + if (absoluteFilePath.empty()) + { + AZ_Error(AssetBundler::AppWindowName, false, "File path cannot be empty"); + return {}; + } + + if(platforms == AzFramework::PlatformFlags::Platform_NONE) + { + AZ_Error(AssetBundler::AppWindowName, false, "Input platform cannot be empty"); + return {}; + } + + // Get all of the Seeds into one AssetSeedManager + AzToolsFramework::AssetSeedManager assetSeedManager; + + if (m_checkedSeedListFiles.find(m_inMemoryDefaultSeedListKey) != m_checkedSeedListFiles.end()) + { + // The In-Memory Default Seed List can't be loaded from a file on disk, it is a special case + assetSeedManager = *m_inMemoryDefaultSeedList->m_seedListModel->GetSeedListManager().get(); + m_checkedSeedListFiles.erase(m_inMemoryDefaultSeedListKey); + } + + for (const auto& checkedSeedFileKey : m_checkedSeedListFiles) + { + assetSeedManager.Load(m_seedListFileInfoMap[checkedSeedFileKey]->m_absolutePath); + } + + // Generate an AssetList for every input platform + AZStd::vector createdFiles; + for (const auto& platformIndex : AzFramework::PlatformHelper::GetPlatformIndicesInterpreted(platforms)) + { + AZStd::string platformSpecificCachePath = + AzToolsFramework::PlatformAddressedAssetCatalog::GetCatalogRegistryPathForPlatform(platformIndex); + AzFramework::StringFunc::Path::StripFullName(platformSpecificCachePath); + + FilePath platformSpecificPath(absoluteFilePath, AZStd::string(AzFramework::PlatformHelper::GetPlatformName(platformIndex))); + if (assetSeedManager.SaveAssetFileInfo(platformSpecificPath.AbsolutePath(), AzFramework::PlatformHelper::GetPlatformFlagFromPlatformIndex(platformIndex))) + { + createdFiles.emplace_back(platformSpecificPath.AbsolutePath()); + } + } + + return createdFiles; + } + + QSharedPointer SeedListFileTableModel::GetSeedListFileContents(const QModelIndex& index) + { + auto seedFileInfoOutcome = GetSeedFileInfo(index); + if (!seedFileInfoOutcome.IsSuccess()) + { + return QSharedPointer(); + } + + return seedFileInfoOutcome.GetValue()->m_seedListModel; + } + + bool SeedListFileTableModel::SetSeedPlatforms( + const QModelIndex& seedFileIndex, + const QModelIndex& seedIndex, + const AzFramework::PlatformFlags& platforms) + { + AZStd::string key = GetFileKey(seedFileIndex); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + if (m_seedListFileInfoMap.find(key) == m_seedListFileInfoMap.end()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Unable to find Seed File Info with key ( %s )", key.c_str()); + return false; + } + + SeedListFileInfoPtr seedFileInfo = m_seedListFileInfoMap[key]; + if (!seedFileInfo->m_seedListModel->SetSeedPlatforms(seedIndex, platforms)) + { + // Error has already been thrown + return false; + } + + // Update display so the user knows there are unsaved changes + m_keysWithUnsavedChanges.insert(key); + QModelIndex changedIndex = QAbstractTableModel::index(seedFileIndex.row(), Column::ColumnFileName); + emit dataChanged(changedIndex, changedIndex, { Qt::DisplayRole, Qt::FontRole }); + + return true; + } + + bool SeedListFileTableModel::AddSeed( + const QModelIndex& seedFileIndex, + const AZStd::string& seedRelativePath, + const AzFramework::PlatformFlags& platforms) + { + AZStd::string key = GetFileKey(seedFileIndex); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + if (m_seedListFileInfoMap.find(key) == m_seedListFileInfoMap.end()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Unable to find Seed File Info with key ( %s )", key.c_str()); + return false; + } + + SeedListFileInfoPtr seedFileInfo = m_seedListFileInfoMap[key]; + if (!seedFileInfo->m_seedListModel->AddSeed(seedRelativePath, platforms)) + { + // Error has already been thrown + return false; + } + + // Update display so the user knows there are unsaved changes + m_keysWithUnsavedChanges.insert(key); + QModelIndex changedIndex = QAbstractTableModel::index(seedFileIndex.row(), Column::ColumnFileName); + emit dataChanged(changedIndex, changedIndex, { Qt::DisplayRole, Qt::FontRole }); + + return true; + } + + bool SeedListFileTableModel::RemoveSeed(const QModelIndex& seedFileIndex, const QModelIndex& seedIndex) + { + AZStd::string key = GetFileKey(seedFileIndex); + if (key.empty()) + { + // Error has already been thrown + return false; + } + + if (m_seedListFileInfoMap.find(key) == m_seedListFileInfoMap.end()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Unable to find Seed File Info with key ( %s )", key.c_str()); + return false; + } + + SeedListFileInfoPtr seedFileInfo = m_seedListFileInfoMap[key]; + if (!seedFileInfo->m_seedListModel->RemoveSeed(seedIndex)) + { + // Error has already been thrown + return false; + } + + // Update display so the user knows there are unsaved changes + m_keysWithUnsavedChanges.insert(key); + QModelIndex changedIndex = QAbstractTableModel::index(seedFileIndex.row(), Column::ColumnFileName); + emit dataChanged(changedIndex, changedIndex, { Qt::DisplayRole, Qt::FontRole }); + + return true; + } + + bool SeedListFileTableModel::WriteToDisk(const AZStd::string& key) + { + if (key == m_inMemoryDefaultSeedListKey) + { + return true; + } + + auto seedListFileIt = m_seedListFileInfoMap.find(key); + return seedListFileIt != m_seedListFileInfoMap.end() && seedListFileIt->second->SaveSeedFile(); + } + + AZStd::string SeedListFileTableModel::GetFileAbsolutePath(const QModelIndex& index) const + { + auto seedFileInfoOutcome = GetSeedFileInfo(index); + if (!seedFileInfoOutcome.IsSuccess() || seedFileInfoOutcome.GetValue()->m_absolutePath == m_inMemoryDefaultSeedListKey) + { + // Error has already been thrown + return AZStd::string(); + } + return seedFileInfoOutcome.GetValue()->m_absolutePath; + } + + int SeedListFileTableModel::GetFileNameColumnIndex() const + { + return Column::ColumnFileName; + } + + int SeedListFileTableModel::GetTimeStampColumnIndex() const + { + return Column::ColumnFileModificationTime; + } + + int SeedListFileTableModel::columnCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : Column::Max; + } + + QVariant SeedListFileTableModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) + { + switch (section) + { + case Column::ColumnFileName: + return QString(tr("Seed List File")); + case Column::ColumnProject: + return QString(tr("Project Source")); + case Column::ColumnFileModificationTime: + return QString(tr("Modification Time")); + default: + break; + } + } + + return QVariant(); + } + + QVariant SeedListFileTableModel::data(const QModelIndex& index, int role) const + { + auto seedFileInfoOutcome = GetSeedFileInfo(index); + if (!seedFileInfoOutcome.IsSuccess()) + { + return QVariant(); + } + + int col = index.column(); + bool hasUnsavedChanges = seedFileInfoOutcome.GetValue()->m_seedListModel->HasUnsavedChanges(); + + switch (role) + { + case Qt::DisplayRole: + [[fallthrough]]; + case SortRole: + { + if (col == Column::ColumnFileName) + { + QString displayName = seedFileInfoOutcome.GetValue()->m_fileName; + if (hasUnsavedChanges) + { + displayName.append("*"); + } + return displayName; + } + else if (col == Column::ColumnProject) + { + return seedFileInfoOutcome.GetValue()->m_project; + } + else if (col == Column::ColumnFileModificationTime) + { + if (role == SortRole) + { + return seedFileInfoOutcome.GetValue()->m_fileModificationTime; + } + else + { + return seedFileInfoOutcome.GetValue()->m_fileModificationTime.toString(DateTimeFormat); + } + } + else + { + // Returning an empty QString will ensure the checkboxes do not have any text displayed next to them + return QString(); + } + } + case Qt::FontRole: + { + if (col == Column::ColumnFileName && hasUnsavedChanges) + { + QFont boldFont; + boldFont.setBold(true); + return boldFont; + } + } + case Qt::CheckStateRole: + { + if (col == Column::ColumnCheckBox) + { + if (seedFileInfoOutcome.GetValue()->m_isChecked) + { + return Qt::Checked; + } + else + { + return Qt::Unchecked; + } + } + } + default: + break; + } + + return QVariant(); + } + + bool SeedListFileTableModel::setData(const QModelIndex& index, const QVariant& value, int role) + { + if (role != Qt::CheckStateRole || index.column() != Column::ColumnCheckBox) + { + return false; + } + + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + return false; + } + + auto seedFileInfo = m_seedListFileInfoMap.find(key); + if (seedFileInfo == m_seedListFileInfoMap.end()) + { + return false; + } + + if (value == Qt::CheckState::Unchecked) + { + seedFileInfo->second->m_isChecked = false; + m_checkedSeedListFiles.erase(key); + + if (seedFileInfo->second->m_isDefaultSeedList) + { + m_seedTabWidget->UncheckSelectDefaultSeedListsCheckBox(); + } + } + else + { + seedFileInfo->second->m_isChecked = true; + m_checkedSeedListFiles.insert(key); + } + + m_seedTabWidget->SetGenerateAssetListsButtonEnabled(!m_checkedSeedListFiles.empty()); + + return true; + } + + Qt::ItemFlags SeedListFileTableModel::flags(const QModelIndex& index) const + { + if (index.column() == Column::ColumnCheckBox) + { + return Qt::ItemIsUserCheckable | QAbstractTableModel::flags(index); + } + + return QAbstractTableModel::flags(index); + } + + AZ::Outcome SeedListFileTableModel::GetSeedFileInfo(const QModelIndex& index) const + { + AZStd::string key = GetFileKey(index); + if (key.empty()) + { + // Error has already been thrown + return AZ::Failure(); + } + + if (m_seedListFileInfoMap.find(key) != m_seedListFileInfoMap.end()) + { + return AZ::Success(m_seedListFileInfoMap.at(key)); + } + else + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot find Seed File Info"); + return AZ::Failure(); + } + } + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/SeedListFileTableModel.h b/Code/Tools/AssetBundler/source/models/SeedListFileTableModel.h new file mode 100644 index 0000000000..9adac6a64b --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/SeedListFileTableModel.h @@ -0,0 +1,147 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include + +#include +#include + +#include +#include + +namespace AssetBundler +{ + class SeedListTableModel; + + class SeedTabWidget; + + struct SeedListFileInfo + { + /** + * Stores information about a Seed List File on disk. + * + * @param absolutePath The absolute path of the Seed List File + * @param fileName The name of the Seed List File. This does not include the ".seed" file extension + * @param project The area of the codebase the Seed List File is from (ex: ProjectName, Engine, Gem) + * @param loadFromFile Set to True if you wish to load an existing Seed List File into memory. Set to False if you are creating a new Seed List File. + */ + SeedListFileInfo( + const AZStd::string& absolutePath, + const QString& fileName, + const QString& project, + bool loadFromFile, + bool isDefaultSeedList = false, + const AZStd::vector& defaultSeeds = AZStd::vector(), + const AzFramework::PlatformFlags& platforms = AzFramework::PlatformFlags::Platform_NONE); + + bool SaveSeedFile(); + + bool HasUnsavedChanges(); + + AZStd::string m_absolutePath; + bool m_isChecked = false; + bool m_isDefaultSeedList = false; + QString m_fileName; + QString m_project; + QDateTime m_fileModificationTime; + + QSharedPointer m_seedListModel; + }; + + using SeedListFileInfoPtr = AZStd::shared_ptr; + /// Stores SeedListFileInfo, using the absolute path (without the drive letter) of the Seed List file as the key + using SeedListFileInfoMap = AZStd::unordered_map; + + class SeedListFileTableModel + : public AssetBundlerAbstractFileTableModel + { + + public: + explicit SeedListFileTableModel(SeedTabWidget* parentSeedTabWidget); + virtual ~SeedListFileTableModel(); + + void AddDefaultSeedsToInMemoryList( + const AZStd::vector& defaultSeeds, + const char* projectName, + const AzFramework::PlatformFlags& platforms); + + AZStd::vector CreateNewFiles( + const AZStd::string& absoluteFilePath, + const AzFramework::PlatformFlags& platforms, + const QString& project) override; + + bool DeleteFile(const QModelIndex& index) override; + + void Reload( + const char* fileExtension, + const QSet& watchedFolders, + const QSet& watchedFiles = QSet(), + const AZStd::unordered_map& pathToProjectNameMap = AZStd::unordered_map()) override; + + void LoadFile( + const AZStd::string& absoluteFilePath, + const AZStd::string& projectName = "", + bool isDefaultFile = false) override; + + void SelectDefaultSeedLists(bool setSelected); + + AZStd::vector GenerateAssetLists(const AZStd::string& absoluteFilePath, const AzFramework::PlatformFlags& platforms); + + QSharedPointer GetSeedListFileContents(const QModelIndex& index); + + bool SetSeedPlatforms(const QModelIndex& seedFileIndex, const QModelIndex& seedIndex, const AzFramework::PlatformFlags& platforms); + + bool AddSeed(const QModelIndex& seedFileIndex, const AZStd::string& seedRelativePath, const AzFramework::PlatformFlags& platforms); + + bool RemoveSeed(const QModelIndex& seedFileIndex, const QModelIndex& seedIndex); + + bool WriteToDisk(const AZStd::string& key) override; + + AZStd::string GetFileAbsolutePath(const QModelIndex& index) const override; + + int GetFileNameColumnIndex() const override; + + int GetTimeStampColumnIndex() const override; + + ////////////////////////////////////////////////////////////////////////// + // QAbstractListModel overrides + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex& index, int role) const override; + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::CheckStateRole) override; + Qt::ItemFlags flags(const QModelIndex& index) const override; + ////////////////////////////////////////////////////////////////////////// + + enum Column + { + ColumnCheckBox, + ColumnFileName, + ColumnProject, + ColumnFileModificationTime, + Max + }; + + private: + AZ::Outcome GetSeedFileInfo(const QModelIndex& index) const; + + SeedListFileInfoMap m_seedListFileInfoMap; + AZStd::unordered_set m_checkedSeedListFiles; + + AZStd::string m_inMemoryDefaultSeedListKey = "InMemoryDefaultKey"; + SeedListFileInfoPtr m_inMemoryDefaultSeedList; + + SeedTabWidget* m_seedTabWidget = nullptr; + }; + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/SeedListTableModel.cpp b/Code/Tools/AssetBundler/source/models/SeedListTableModel.cpp new file mode 100644 index 0000000000..8b721d961c --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/SeedListTableModel.cpp @@ -0,0 +1,279 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +namespace AssetBundler +{ + + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // AdditionalSeedInfo + ////////////////////////////////////////////////////////////////////////////////////////////////// + AdditionalSeedInfo::AdditionalSeedInfo(const QString& relativePath, const QString& platformList) + : m_relativePath(relativePath) + , m_platformList(platformList) + { + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // SeedListTableModel + ////////////////////////////////////////////////////////////////////////////////////////////////// + SeedListTableModel::SeedListTableModel( + QObject* parent, + const AZStd::string& absolutePath, + const AZStd::vector& defaultSeeds, + const AzFramework::PlatformFlags& platforms) + : QAbstractTableModel(parent) + { + m_seedListManager.reset(new AzToolsFramework::AssetSeedManager()); + + if (absolutePath.empty() && defaultSeeds.empty()) + { + return; + } + + if (!defaultSeeds.empty()) + { + for (const AZStd::string& seed : defaultSeeds) + { + m_seedListManager->AddSeedAssetForValidPlatforms(seed, platforms); + } + + m_isFileOnDisk = false; + } + else + { + m_seedListManager->Load(absolutePath); + } + + AZ::Data::AssetInfo assetInfo; + QString platformList; + for (const auto& seed : m_seedListManager->GetAssetSeedList()) + { + assetInfo = AzToolsFramework::AssetSeedManager::GetAssetInfoById( + seed.m_assetId, + AzFramework::PlatformHelper::GetPlatformIndicesInterpreted(seed.m_platformFlags)[0], + absolutePath); + platformList = QString(m_seedListManager->GetReadablePlatformList(seed).c_str()); + + m_additionalSeedInfoMap[seed.m_assetId].reset(new AdditionalSeedInfo(assetInfo.m_relativePath.c_str(), platformList)); + } + } + + AZ::Outcome SeedListTableModel::GetSeedPlatforms(const QModelIndex& index) const + { + auto seedOutcome = GetSeedInfo(index); + if (!seedOutcome.IsSuccess()) + { + // Error has already been thrown + return AZ::Failure(); + } + + return AZ::Success(seedOutcome.GetValue().m_platformFlags); + } + + bool SeedListTableModel::Save(const AZStd::string& absolutePath) + { + if (!HasUnsavedChanges()) + { + // There are no changes, so there is nothing to save + return true; + } + + SetHasUnsavedChanges(!m_seedListManager->Save(absolutePath)); + return !HasUnsavedChanges(); + } + + bool SeedListTableModel::SetSeedPlatforms(const QModelIndex& index, const AzFramework::PlatformFlags& platforms) + { + auto seedOutcome = GetSeedInfo(index); + if (!seedOutcome.IsSuccess()) + { + // Error has already been thrown + return false; + } + + if (platforms == AzFramework::PlatformFlags::Platform_NONE) + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot Edit Platforms: No platforms were selected"); + return false; + } + + auto setPlatformOutcome = m_seedListManager->SetSeedPlatformFlags(index.row(), platforms); + if (!setPlatformOutcome.IsSuccess()) + { + AZ_Error(AssetBundler::AppWindowName, false, setPlatformOutcome.GetError().c_str()); + return false; + } + + // Update the cached display info + auto additionalSeedInfo = m_additionalSeedInfoMap.find(seedOutcome.GetValue().m_assetId); + if (additionalSeedInfo == m_additionalSeedInfoMap.end()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Unable to find additional Seed info"); + return false; + } + additionalSeedInfo->second->m_platformList = + QString(AzFramework::PlatformHelper::GetCommaSeparatedPlatformList(platforms).c_str()); + + SetHasUnsavedChanges(true); + + // Update the display + QModelIndex firstChangedIndex = QAbstractTableModel::index(index.row(), Column::ColumnRelativePath); + QModelIndex lastChangedIndex = QAbstractTableModel::index(index.row(), Column::Max - 1); + emit dataChanged(firstChangedIndex, lastChangedIndex, { Qt::DisplayRole }); + + return true; + } + + bool SeedListTableModel::AddSeed(const AZStd::string& seedRelativePath, const AzFramework::PlatformFlags& platforms) + { + AZStd::pair addSeedsResult = + m_seedListManager->AddSeedAssetForValidPlatforms(seedRelativePath, platforms); + + if (!addSeedsResult.first.IsValid() || addSeedsResult.second == AzFramework::PlatformFlags::Platform_NONE) + { + // Error has already been thrown + return false; + } + + QString platformList = QString(AzFramework::PlatformHelper::GetCommaSeparatedPlatformList(addSeedsResult.second).c_str()); + + int lastRowIndex = AZStd::max(rowCount() - 1, 0); + beginInsertRows(QModelIndex(), lastRowIndex, lastRowIndex); + + m_additionalSeedInfoMap[addSeedsResult.first].reset(new AdditionalSeedInfo(QString(seedRelativePath.c_str()), platformList)); + + endInsertRows(); + + SetHasUnsavedChanges(true); + return true; + } + + bool SeedListTableModel::RemoveSeed(const QModelIndex& seedIndex) + { + auto seedOutcome = GetSeedInfo(seedIndex); + if (!seedOutcome.IsSuccess()) + { + // Error has already been thrown + return false; + } + + int row = seedIndex.row(); + beginRemoveRows(QModelIndex(), row, row); + m_seedListManager->RemoveSeedAsset(seedOutcome.GetValue().m_assetId, seedOutcome.GetValue().m_platformFlags); + m_additionalSeedInfoMap.erase(seedOutcome.GetValue().m_assetId); + endRemoveRows(); + + SetHasUnsavedChanges(true); + return true; + } + + int SeedListTableModel::rowCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : static_cast(m_additionalSeedInfoMap.size()); + } + + int SeedListTableModel::columnCount(const QModelIndex& parent) const + { + return parent.isValid() ? 0 : Column::Max; + } + + QVariant SeedListTableModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) + { + switch (section) + { + case Column::ColumnRelativePath: + return QString("Seed"); + case Column::ColumnPlatformList: + return QString("Platforms"); + default: + break; + } + } + + return QVariant(); + } + + QVariant SeedListTableModel::data(const QModelIndex& index, int role) const + { + auto additionalSeedInfoOutcome = GetAdditionalSeedInfo(index); + if (!additionalSeedInfoOutcome.IsSuccess()) + { + return QVariant(); + } + + switch (role) + { + case Qt::DisplayRole: + { + if (index.column() == Column::ColumnRelativePath) + { + return additionalSeedInfoOutcome.GetValue()->m_relativePath; + } + else if (index.column() == Column::ColumnPlatformList) + { + return additionalSeedInfoOutcome.GetValue()->m_platformList; + } + } + default: + break; + } + + return QVariant(); + } + + AZ::Outcome SeedListTableModel::GetSeedInfo(const QModelIndex& index) const + { + int row = index.row(); + int col = index.column(); + if (row >= rowCount() || row < 0 || col >= columnCount() || col < 0) + { + AZ_Error(AssetBundler::AppWindowName, false, "Selected index (%i, %i) is out of range", row, col); + return AZ::Failure(); + } + + return AZ::Success(m_seedListManager->GetAssetSeedList().at(row)); + } + + AZ::Outcome SeedListTableModel::GetAdditionalSeedInfo(const QModelIndex& index) const + { + auto seedInfoOutcome = GetSeedInfo(index); + if (!seedInfoOutcome.IsSuccess()) + { + // Error has already been thrown + return AZ::Failure(); + } + + auto additionalSeedInfoIt = m_additionalSeedInfoMap.find(seedInfoOutcome.GetValue().m_assetId); + if (additionalSeedInfoIt == m_additionalSeedInfoMap.end()) + { + return AZ::Failure(); + } + + return AZ::Success(additionalSeedInfoIt->second); + } + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/models/SeedListTableModel.h b/Code/Tools/AssetBundler/source/models/SeedListTableModel.h new file mode 100644 index 0000000000..37d52717a7 --- /dev/null +++ b/Code/Tools/AssetBundler/source/models/SeedListTableModel.h @@ -0,0 +1,88 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include + +#include +#include + +#include + +namespace AssetBundler +{ + struct AdditionalSeedInfo + { + AdditionalSeedInfo(const QString& relativePath, const QString& platformList); + + QString m_relativePath; + QString m_platformList; + }; + + using AdditionalSeedInfoPtr = AZStd::shared_ptr; + using AdditionalSeedInfoMap = AZStd::unordered_map; + + class SeedListTableModel + : public QAbstractTableModel + { + public: + explicit SeedListTableModel( + QObject* parent = nullptr, + const AZStd::string& absolutePath = AZStd::string(), + const AZStd::vector& defaultSeeds = AZStd::vector(), + const AzFramework::PlatformFlags& platforms = AzFramework::PlatformFlags::Platform_NONE); + virtual ~SeedListTableModel() {} + + AZStd::shared_ptr GetSeedListManager() { return m_seedListManager; } + + bool HasUnsavedChanges() { return m_hasUnsavedChanges && m_isFileOnDisk; } + + void SetHasUnsavedChanges(bool hasUnsavedChanges) { m_hasUnsavedChanges = hasUnsavedChanges; } + + bool Save(const AZStd::string& absolutePath); + + AZ::Outcome GetSeedPlatforms(const QModelIndex& index) const; + + bool SetSeedPlatforms(const QModelIndex& index, const AzFramework::PlatformFlags& platforms); + + bool AddSeed(const AZStd::string& seedRelativePath, const AzFramework::PlatformFlags& platforms); + + bool RemoveSeed(const QModelIndex& seedIndex); + + ////////////////////////////////////////////////////////////////////////// + // QAbstractListModel overrides + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex& index, int role) const override; + ////////////////////////////////////////////////////////////////////////// + + enum Column + { + ColumnRelativePath, + ColumnPlatformList, + Max + }; + + private: + AZ::Outcome GetSeedInfo(const QModelIndex& index) const; + + AZ::Outcome GetAdditionalSeedInfo(const QModelIndex& index) const; + + AZStd::shared_ptr m_seedListManager; + AdditionalSeedInfoMap m_additionalSeedInfoMap; + + bool m_hasUnsavedChanges = false; + bool m_isFileOnDisk = true; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/AddSeedDialog.cpp b/Code/Tools/AssetBundler/source/ui/AddSeedDialog.cpp new file mode 100644 index 0000000000..214fe7e850 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AddSeedDialog.cpp @@ -0,0 +1,102 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include + +#include +#include + +const char QtRelativePathPrefix[] = "../"; + +namespace AssetBundler +{ + AddSeedDialog::AddSeedDialog( + QWidget* parent, + const AzFramework::PlatformFlags& enabledPlatforms, + const AZStd::string& platformSpecificCachePath) + : QDialog(parent) + , m_platformSpecificCachePath(platformSpecificCachePath.c_str()) + { + m_ui.reset(new Ui::AddSeedDialog); + m_ui->setupUi(this); + + // Set up Browse File button + m_ui->fileNameLineEdit->setReadOnly(true); + connect(m_ui->browseFileButton, &QPushButton::clicked, this, &AddSeedDialog::OnBrowseFileButtonPressed); + + // Set up Platform selection + m_ui->platformSelectionWidget->Init(enabledPlatforms); + connect(m_ui->platformSelectionWidget, + &PlatformSelectionWidget::PlatformsSelected, + this, + &AddSeedDialog::OnPlatformSelectionChanged); + + // Set up Cancel and Create New File buttons + m_ui->addSeedButton->setEnabled(false); + connect(m_ui->cancelButton, &QPushButton::clicked, this, &QDialog::reject); + connect(m_ui->addSeedButton, &QPushButton::clicked, this, &QDialog::accept); + } + + AZStd::string AddSeedDialog::GetFileName() + { + return m_fileName; + } + + AzFramework::PlatformFlags AddSeedDialog::GetPlatformFlags() + { + return m_ui->platformSelectionWidget->GetSelectedPlatforms(); + } + + void AddSeedDialog::OnBrowseFileButtonPressed() + { + QString seedAbsolutePath = QFileDialog::getOpenFileName(this, tr("Add New Seed"), m_platformSpecificCachePath); + m_fileNameIsValid = !seedAbsolutePath.isEmpty(); + if (!m_fileNameIsValid) + { + // The user canceled out of the window, do not update anything + return; + } + + // Make sure the path is relative to the platform-specific cache + QDir platformSpecificCacheDir(m_platformSpecificCachePath); + QString seedRelativePath = platformSpecificCacheDir.relativeFilePath(seedAbsolutePath); + + // trim off the "../" from the relative path + FormatRelativePathString(seedRelativePath); + m_fileName = seedRelativePath.toUtf8().data(); + + // Update the ui + m_ui->fileNameLineEdit->setText(seedRelativePath); + m_ui->addSeedButton->setEnabled(m_platformIsValid && m_fileNameIsValid); + } + + void AddSeedDialog::OnPlatformSelectionChanged(const AzFramework::PlatformFlags& selectedPlatforms) + { + // Hide the "Create File" button if no platforms are selected + m_platformIsValid = selectedPlatforms != AzFramework::PlatformFlags::Platform_NONE; + m_ui->addSeedButton->setEnabled(m_platformIsValid && m_fileNameIsValid); + } + + void AddSeedDialog::FormatRelativePathString(QString& relativePath) + { + if (relativePath.startsWith(QtRelativePathPrefix)) + { + relativePath.remove(0, static_cast(strlen(QtRelativePathPrefix))); + } + } + +} //namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/AddSeedDialog.h b/Code/Tools/AssetBundler/source/ui/AddSeedDialog.h new file mode 100644 index 0000000000..7699f0a820 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AddSeedDialog.h @@ -0,0 +1,61 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include + +#include +#include +#endif + +namespace Ui +{ + class AddSeedDialog; +} + +namespace AssetBundler +{ + class GUIApplicationManager; + + class AddSeedDialog + : public QDialog + { + Q_OBJECT + + public: + explicit AddSeedDialog( + QWidget* parent, + const AzFramework::PlatformFlags& enabledPlatforms, + const AZStd::string& platformSpecificCachePath); + virtual ~AddSeedDialog() {} + + AZStd::string GetFileName(); + AzFramework::PlatformFlags GetPlatformFlags(); + + private: + void OnBrowseFileButtonPressed(); + void OnPlatformSelectionChanged(const AzFramework::PlatformFlags& selectedPlatforms); + + void FormatRelativePathString(QString& relativePath); + + QSharedPointer m_ui; + QString m_platformSpecificCachePath; + bool m_isAddSeedDialog = false; + + AZStd::string m_fileName; + + bool m_fileNameIsValid = false; + bool m_platformIsValid = false; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/AddSeedDialog.ui b/Code/Tools/AssetBundler/source/ui/AddSeedDialog.ui new file mode 100644 index 0000000000..e3c0f471aa --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AddSeedDialog.ui @@ -0,0 +1,185 @@ + + + AddSeedDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 450 + 108 + + + + + 0 + 0 + + + + + 450 + 0 + + + + Add Seed Asset + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Select Seed Asset: + + + + + + + + + true + + + + + + + Browse... + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + + + + + + + + + + + + + 10 + + + 10 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + false + + + + + + + Add Seed + + + true + + + + + + + + + + AssetBundler::PlatformSelectionWidget + QWidget +
source/ui/PlatformSelectionWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/AssetBundlerTabWidget.cpp b/Code/Tools/AssetBundler/source/ui/AssetBundlerTabWidget.cpp new file mode 100644 index 0000000000..2d2f40e038 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AssetBundlerTabWidget.cpp @@ -0,0 +1,377 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace AssetBundler +{ + const char AssetBundlerCommonSettingsFile[] = "AssetBundlerCommonSettings.json"; + const char AssetBundlerUserSettingsFile[] = "AssetBundlerUserSettings.json"; + + const char ScanPathsKey[] = "ScanPaths"; + + const QString AssetBundlingFileTypes[] = + { + "SeedLists", + "AssetLists", + "BundleSettings", + "Bundles", + "Rules" + }; + + const int MarginSize = 10; + + AssetBundlerTabWidget::AssetBundlerTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager) + : QWidget(parent) + , m_guiApplicationManager(guiApplicationManager) + { + connect(m_guiApplicationManager, &GUIApplicationManager::UpdateTab, this, &AssetBundlerTabWidget::OnUpdateTab); + connect(m_guiApplicationManager, &GUIApplicationManager::UpdateFiles, this, &AssetBundlerTabWidget::OnUpdateFiles); + + QAction* deleteFileAction = new QAction(tr("Delete"), this); + addAction(deleteFileAction); + deleteFileAction->setShortcut(QKeySequence::Delete); + connect(deleteFileAction, &QAction::triggered, this, &AssetBundlerTabWidget::OnDeleteSelectedFileRequested); + } + + AssetBundlerTabWidget::~AssetBundlerTabWidget() + { + m_guiApplicationManager = nullptr; + } + + void AssetBundlerTabWidget::Activate() + { + SetActiveProjectLabel(tr("Active Project: %1").arg(m_guiApplicationManager->GetCurrentProjectName().c_str())); + + SetupContextMenu(); + Reload(); + + connect(GetFileTableView()->header(), + &QHeaderView::sortIndicatorChanged, + m_fileTableFilterModel.get(), + &AssetBundlerFileTableFilterModel::sort); + GetFileTableView()->header()->setSortIndicatorShown(true); + // Setting this in descending order will ensure the most recent files are at the top + GetFileTableView()->header()->setSortIndicator(GetFileTableModel()->GetTimeStampColumnIndex(), Qt::DescendingOrder); + GetFileTableView()->setSortingEnabled(true); + } + + void AssetBundlerTabWidget::InitAssetBundlerSettings(const char* currentProjectFolderPath) + { + AZStd::string commonSettingsPath = GetAssetBundlerCommonSettingsFile(currentProjectFolderPath); + if (!AZ::IO::FileIOBase::GetInstance()->Exists(commonSettingsPath.c_str())) + { + CreateEmptyAssetBundlerSettings(commonSettingsPath); + } + + AZStd::string userSettingsPath = GetAssetBundlerUserSettingsFile(currentProjectFolderPath); + if (!AZ::IO::FileIOBase::GetInstance()->Exists(userSettingsPath.c_str())) + { + CreateEmptyAssetBundlerSettings(userSettingsPath); + } + } + + void AssetBundlerTabWidget::OnFileTableContextMenuRequested(const QPoint& pos) + { + AZStd::string selectedFileAbsolutePath(GetFileTableModel()->GetFileAbsolutePath(GetSelectedFileTableIndex())); + + QMenu* contextMenu = new QMenu(this); + contextMenu->setToolTipsVisible(true); + + bool arePathOperationsEnabled = !selectedFileAbsolutePath.empty(); + QString emptyPathToolTip(tr("This file is not present on-disk.")); + + QAction* action = contextMenu->addAction(AzQtComponents::fileBrowserActionName(), [=]() + { + AzQtComponents::ShowFileOnDesktop(selectedFileAbsolutePath.c_str()); + }); + if (arePathOperationsEnabled) + { + action->setToolTip(tr("Shows the location of this file on your computer")); + } + else + { + action->setToolTip(emptyPathToolTip); + action->setEnabled(false); + } + + action = contextMenu->addAction(tr("Copy Path to Clipboard"), [=]() + { + QApplication::clipboard()->setText(QString(selectedFileAbsolutePath.c_str())); + }); + if (arePathOperationsEnabled) + { + action->setToolTip(tr("Copies the absolute path of this file to your Clipboard")); + } + else + { + action->setToolTip(emptyPathToolTip); + action->setEnabled(false); + } + + contextMenu->addSeparator(); + + // We can't use the same Delete action as the constructor because we need to modify a lot of values + action = new QAction(tr("Delete"), this); + action->setShortcutContext(Qt::WidgetWithChildrenShortcut); + action->setShortcut(QKeySequence::Delete); + connect(action, &QAction::triggered, this, &AssetBundlerTabWidget::OnDeleteSelectedFileRequested); + if (arePathOperationsEnabled) + { + action->setToolTip(tr("Deletes the selected file from disk.")); + } + else + { + action->setToolTip(emptyPathToolTip); + action->setEnabled(false); + } + contextMenu->addAction(action); + + contextMenu->exec(GetFileTableView()->mapToGlobal(pos)); + delete contextMenu; + } + + void AssetBundlerTabWidget::OnDeleteSelectedFileRequested() + { + AZStd::string selectedFileAbsolutePath(GetFileTableModel()->GetFileAbsolutePath(GetSelectedFileTableIndex())); + if (selectedFileAbsolutePath.empty()) + { + return; + } + + QString messageBoxText = + QString(tr("Are you sure you would like to delete %1? \n\nThis will permanently delete the file.")).arg(QString(selectedFileAbsolutePath.c_str())); + + QMessageBox::StandardButton confirmDeleteFileResult = + QMessageBox::question(this, QString(tr("Delete %1")).arg(GetFileTypeDisplayName()), messageBoxText); + if (confirmDeleteFileResult != QMessageBox::StandardButton::Yes) + { + // User canceled out of the confirmation dialog + return; + } + + if (GetFileTableModel()->DeleteFile(GetSelectedFileTableIndex())) + { + RemoveScanPathFromAssetBundlerSettings(GetFileType(), selectedFileAbsolutePath.c_str()); + } + } + + void AssetBundlerTabWidget::ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType fileType) + { + AZStd::string currentProjectFolderPath = m_guiApplicationManager->GetCurrentProjectFolder(); + ReadAssetBundlerSettings(GetAssetBundlerUserSettingsFile(currentProjectFolderPath.c_str()), fileType); + ReadAssetBundlerSettings(GetAssetBundlerCommonSettingsFile(currentProjectFolderPath.c_str()), fileType); + } + + void AssetBundlerTabWidget::AddScanPathToAssetBundlerSettings(AssetBundlingFileType fileType, AZStd::string filePath) + { + AZStd::string defaultFolderPath; + switch (fileType) + { + case AssetBundlingFileType::SeedListFileType: + defaultFolderPath = m_guiApplicationManager->GetSeedListsFolder(); + break; + case AssetBundlingFileType::AssetListFileType: + defaultFolderPath = m_guiApplicationManager->GetAssetListsFolder(); + break; + case AssetBundlingFileType::RulesFileType: + defaultFolderPath = m_guiApplicationManager->GetRulesFolder(); + break; + case AssetBundlingFileType::BundleSettingsFileType: + defaultFolderPath = m_guiApplicationManager->GetBundleSettingsFolder(); + break; + case AssetBundlingFileType::BundleFileType: + defaultFolderPath = m_guiApplicationManager->GetBundlesFolder(); + break; + default: + AZ_Warning(AssetBundler::AppWindowName, false, + "No default folder is defined for AssetBundlingFileType ( %i ).", static_cast(fileType)); + break; + } + + AzFramework::StringFunc::Path::Normalize(filePath); + AzFramework::StringFunc::Path::Normalize(defaultFolderPath); + + if (AzFramework::StringFunc::StartsWith(filePath, defaultFolderPath)) + { + // file is already in a watched folder, no need to add it to the settings file + return; + } + + AddScanPathToAssetBundlerSettings(fileType, QString(filePath.c_str())); + } + + void AssetBundlerTabWidget::AddScanPathToAssetBundlerSettings(AssetBundlingFileType fileType, const QString& filePath) + { + AZStd::string assetBundlerSettingsFileAbsolutePath = + GetAssetBundlerUserSettingsFile(m_guiApplicationManager->GetCurrentProjectFolder().c_str()); + QJsonObject assetBundlerSettings = AssetBundler::ReadJson(assetBundlerSettingsFileAbsolutePath); + QJsonObject scanPathsSettings = assetBundlerSettings[ScanPathsKey].toObject(); + QJsonArray scanPaths = scanPathsSettings[AssetBundlingFileTypes[fileType]].toArray(); + + QFileInfo inputFileInfo(filePath); + + for (const QJsonValue scanPath : m_watchedFiles + m_watchedFolders) + { + auto scanFilePathStr = (AZ::IO::Path(AZStd::string_view{ AZ::Utils::GetEnginePath() }) + / scanPath.toString().toUtf8().data()).LexicallyNormal(); + + // Check whether the file has already been watched + // Get absolute file paths via QFileInfo to keep consistency in the letter case + if (inputFileInfo.absoluteFilePath().startsWith( + QFileInfo(scanFilePathStr.c_str()).absoluteFilePath())) + { + return; + } + } + + scanPaths.push_back(filePath); + scanPathsSettings[AssetBundlingFileTypes[fileType]] = scanPaths; + assetBundlerSettings[ScanPathsKey] = scanPathsSettings; + AssetBundler::SaveJson(assetBundlerSettingsFileAbsolutePath, assetBundlerSettings); + + m_watchedFiles.insert(filePath); + m_guiApplicationManager->AddWatchedPath(filePath); + } + + void AssetBundlerTabWidget::RemoveScanPathFromAssetBundlerSettings(AssetBundlingFileType fileType, const QString& filePath) + { + AZStd::string assetBundlerSettingsFileAbsolutePath = + GetAssetBundlerUserSettingsFile(m_guiApplicationManager->GetCurrentProjectFolder().c_str()); + QJsonObject assetBundlerSettings = AssetBundler::ReadJson(assetBundlerSettingsFileAbsolutePath); + QJsonObject scanPathsSettings = assetBundlerSettings[ScanPathsKey].toObject(); + QJsonArray scanPaths = scanPathsSettings[AssetBundlingFileTypes[fileType]].toArray(); + + for (auto itr = scanPaths.begin(); itr != scanPaths.end(); ++itr) + { + QJsonValueRef scanPathValueRef = *itr; + auto scanPath = (AZ::IO::Path(AZStd::string_view{ AZ::Utils::GetEnginePath() }) + / scanPathValueRef.toString().toUtf8().data()).LexicallyNormal(); + + // Check whether the file is being watched + // Get absolute file paths via QFileInfo to keep consistency in the letter case + if (QFileInfo(filePath).absoluteFilePath() == QFileInfo(scanPath.c_str()).absoluteFilePath()) + { + itr = scanPaths.erase(itr); + break; + } + } + + scanPathsSettings[AssetBundlingFileTypes[fileType]] = scanPaths; + assetBundlerSettings[ScanPathsKey] = scanPathsSettings; + AssetBundler::SaveJson(assetBundlerSettingsFileAbsolutePath, assetBundlerSettings); + + m_guiApplicationManager->RemoveWatchedPath(filePath); + } + + void AssetBundlerTabWidget::OnUpdateTab(const AZStd::string& path) + { + if (m_watchedFolders.contains(path.c_str()) || + m_watchedFiles.contains(path.c_str())) + { + Reload(); + } + } + + void AssetBundlerTabWidget::OnUpdateFiles(AssetBundlingFileType fileType, const AZStd::vector& absoluteFilePaths) + { + if (fileType == GetFileType()) + { + GetFileTableModel()->ReloadFiles(absoluteFilePaths, m_filePathToGemNameMap); + m_fileTableFilterModel->sort(m_fileTableFilterModel->sortColumn(), m_fileTableFilterModel->sortOrder()); + FileSelectionChanged(); + } + } + + void AssetBundlerTabWidget::SetupContextMenu() + { + GetFileTableView()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(GetFileTableView(), + &QTreeView::customContextMenuRequested, + this, + &AssetBundlerTabWidget::OnFileTableContextMenuRequested); + } + + void AssetBundlerTabWidget::ReadAssetBundlerSettings(const AZStd::string& filePath, AssetBundlingFileType fileType) + { + // Read the config file which contains the customized scan paths information + AZStd::vector assetBundlerSettingsFileList; + QJsonObject assetBundlerSettings = AssetBundler::ReadJson(filePath); + QJsonObject scanPaths = assetBundlerSettings.find(ScanPathsKey).value().toObject(); + + for (const QJsonValue scanPath : scanPaths[AssetBundlingFileTypes[fileType]].toArray()) + { + auto absoluteScanPath = (AZ::IO::Path(AZStd::string_view{ AZ::Utils::GetEnginePath() }) + / scanPath.toString().toUtf8().data()).LexicallyNormal(); + + if (AZ::IO::FileIOBase::GetInstance()->IsDirectory(absoluteScanPath.c_str())) + { + // The path specified in the config file is a directory + m_watchedFolders.insert(absoluteScanPath.c_str()); + } + else if (AZ::IO::FileIOBase::GetInstance()->Exists(absoluteScanPath.c_str())) + { + // The path specified in the config file is a file + m_watchedFiles.insert(absoluteScanPath.c_str()); + } + } + } + + AZStd::string AssetBundlerTabWidget::GetAssetBundlerUserSettingsFile(const char* currentProjectFolderPath) + { + AZStd::string absoluteFilePath; + AzFramework::StringFunc::Path::ConstructFull(currentProjectFolderPath, AssetBundlerUserSettingsFile, absoluteFilePath); + return absoluteFilePath; + } + + AZStd::string AssetBundlerTabWidget::GetAssetBundlerCommonSettingsFile(const char* currentProjectFolderPath) + { + AZStd::string absoluteFilePath; + AzFramework::StringFunc::Path::ConstructFull(currentProjectFolderPath, AssetBundlerCommonSettingsFile, absoluteFilePath); + return absoluteFilePath; + } + + void AssetBundlerTabWidget::CreateEmptyAssetBundlerSettings(const AZStd::string& filePath) + { + QJsonObject assetBundlerSettings; + QJsonObject scanPathSettings; + + for (const auto& fileType : AssetBundlingFileTypes) + { + scanPathSettings.insert(fileType, QJsonArray()); + } + + assetBundlerSettings.insert(ScanPathsKey, scanPathSettings); + + AssetBundler::SaveJson(filePath, assetBundlerSettings); + } + +} // namespace AssetBundler +#include diff --git a/Code/Tools/AssetBundler/source/ui/AssetBundlerTabWidget.h b/Code/Tools/AssetBundler/source/ui/AssetBundlerTabWidget.h new file mode 100644 index 0000000000..17eb171d6d --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AssetBundlerTabWidget.h @@ -0,0 +1,120 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#endif + +namespace AssetBundler +{ + // Keys for the corresponding scan path lists in the asset bundling settings file + extern const QString AssetBundlingFileTypes[]; + + extern const int MarginSize; + + class AssetBundlerTabWidget + : public QWidget + { + Q_OBJECT + + public: + explicit AssetBundlerTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager); + virtual ~AssetBundlerTabWidget(); + + void Activate(); + + virtual QString GetTabTitle() = 0; + + virtual QString GetFileTypeDisplayName() = 0; + + virtual AssetBundlingFileType GetFileType() = 0; + + virtual bool HasUnsavedChanges() = 0; + + //! Reload all the files on display. + virtual void Reload() = 0; + + //! Saves the selected file to disk. + //! @return true on successful save, or throws an error message and returns false on a failed save. + virtual bool SaveCurrentSelection() = 0; + + //! Saves all modified files to disk. + //! @return true on successful save, or throws an error message and returns false on a failed save. + virtual bool SaveAll() = 0; + + //! Set watched folders and files for the model + virtual void SetModelDataSource() = 0; + + virtual AzQtComponents::TableView* GetFileTableView() = 0; + + virtual QModelIndex GetSelectedFileTableIndex() = 0; + + virtual AssetBundlerAbstractFileTableModel* GetFileTableModel() = 0; + + virtual void SetActiveProjectLabel(const QString& labelText) = 0; + + virtual void ApplyConfig() = 0; + + virtual void FileSelectionChanged( + const QItemSelection& /*selected*/ = QItemSelection(), + const QItemSelection& /*deselected*/ = QItemSelection()) = 0; + + static void InitAssetBundlerSettings(const char* currentProjectFolderPath); + + void AddScanPathToAssetBundlerSettings(AssetBundlingFileType fileType, AZStd::string filePath); + + GUIApplicationManager* GetGUIApplicationManager() { return m_guiApplicationManager; } + + protected: + void OnFileTableContextMenuRequested(const QPoint& pos); + //! Asks the user to confirm they wish to permanently delete the selected file, then removes it from disk and memory. + void OnDeleteSelectedFileRequested(); + bool ConfirmFileDeleteDialog(const QString& absoluteFilePath); + void ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType fileType); + void RemoveScanPathFromAssetBundlerSettings(AssetBundlingFileType fileType, const QString& filePath); + + GUIApplicationManager* m_guiApplicationManager = nullptr; + QScopedPointer m_fileTableFilterModel; + + QSet m_watchedFolders; + QSet m_watchedFiles; + AZStd::unordered_map m_filePathToGemNameMap; + + private slots: + void OnUpdateTab(const AZStd::string& path); + void OnUpdateFiles(AssetBundlingFileType fileType, const AZStd::vector& absoluteFilePaths); + + private: + void SetupContextMenu(); + void AddScanPathToAssetBundlerSettings(AssetBundlingFileType fileType, const QString& filePath); + void ReadAssetBundlerSettings(const AZStd::string& filePath, AssetBundlingFileType fileType); + + static AZStd::string GetAssetBundlerUserSettingsFile(const char* currentProjectFolderPath); + static AZStd::string GetAssetBundlerCommonSettingsFile(const char* currentProjectFolderPath); + static void CreateEmptyAssetBundlerSettings(const AZStd::string& filePath); + }; + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.cpp b/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.cpp new file mode 100644 index 0000000000..2f0351e39e --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.cpp @@ -0,0 +1,200 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace AssetBundler +{ + AssetListTabWidget::AssetListTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager) + : AssetBundlerTabWidget(parent, guiApplicationManager) + , m_fileTableModel(new AssetListFileTableModel()) + , m_assetListContentsModel(new AssetListTableModel()) + { + m_ui.reset(new Ui::AssetListTabWidget); + m_ui->setupUi(this); + + m_ui->mainVerticalLayout->setContentsMargins(10, 10, 10, 10); + + // File view of all Asset List Files + m_fileTableFilterModel.reset(new AssetBundlerFileTableFilterModel( + this, + m_fileTableModel->GetFileNameColumnIndex(), + m_fileTableModel->GetTimeStampColumnIndex())); + + m_fileTableFilterModel->setSourceModel(m_fileTableModel.data()); + m_ui->assetListsTable->setModel(m_fileTableFilterModel.data()); + connect(m_ui->fileFilteredSearchWidget, + &AzQtComponents::FilteredSearchWidget::TextFilterChanged, + m_fileTableFilterModel.data(), + static_cast(&AssetBundlerFileTableFilterModel::FilterChanged)); + + connect(m_ui->assetListsTable->selectionModel(), + &QItemSelectionModel::selectionChanged, + this, + &AssetListTabWidget::FileSelectionChanged); + + m_ui->fileTableHeaderLayout->setContentsMargins(0, 0, 0, 0); + m_ui->fileTableVerticalLayout->setContentsMargins(0, 0, 0, 0); + m_ui->assetListsTable->setIndentation(0); + + // Generate Bundle Button + m_ui->generateBundleButton->setDefault(true); + m_ui->generateBundleButton->setEnabled(false); + connect(m_ui->generateBundleButton, &QPushButton::clicked, this, &AssetListTabWidget::OnGenerateBundleButtonPressed); + + // Absolute path of selected Asset List file + m_ui->assetListFileAbsolutePathLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + + // Table that displays the contents of an Asset List File + m_assetListContentsFilterModel.reset(new AssetBundlerFileTableFilterModel(this, AssetListTableModel::Column::ColumnAssetName)); + + m_assetListContentsFilterModel->setSourceModel(m_assetListContentsModel.data()); + m_ui->assetListContentsTable->setModel(m_assetListContentsFilterModel.data()); + connect(m_ui->assetListContentsFilteredSearchWidget, + &AzQtComponents::FilteredSearchWidget::TextFilterChanged, + m_assetListContentsFilterModel.data(), + static_cast(&AssetBundlerFileTableFilterModel::FilterChanged)); + + + m_ui->fileContentsHeaderLayout->setContentsMargins(0, 0, 0, 0); + m_ui->fileContentsVerticalLayout->setContentsMargins(0, 0, 0, 0); + m_ui->assetListContentsTable->setIndentation(0); + + SetModelDataSource(); + } + + void AssetListTabWidget::SetModelDataSource() + { + // Remove the current watched folders and files + m_guiApplicationManager->RemoveWatchedPaths(m_watchedFolders + m_watchedFiles); + + // Set the new watched folder for the model + m_watchedFolders.clear(); + m_watchedFiles.clear(); + m_watchedFolders.insert(m_guiApplicationManager->GetAssetListsFolder().c_str()); + ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType::AssetListFileType); + + m_guiApplicationManager->AddWatchedPaths(m_watchedFolders + m_watchedFiles); + } + + AzQtComponents::TableView* AssetListTabWidget::GetFileTableView() + { + return m_ui->assetListsTable; + } + + QModelIndex AssetListTabWidget::GetSelectedFileTableIndex() + { + return m_selectedFileTableIndex; + } + + AssetBundlerAbstractFileTableModel* AssetListTabWidget::GetFileTableModel() + { + return m_fileTableModel.get(); + } + + void AssetListTabWidget::SetActiveProjectLabel(const QString& labelText) + { + m_ui->activeProjectLabel->setText(labelText); + } + + void AssetListTabWidget::ApplyConfig() + { + const GUIApplicationManager::Config& config = m_guiApplicationManager->GetConfig(); + + m_ui->fileTableFrame->setFixedWidth(config.fileTableWidth); + + m_ui->assetListsTable->header()->resizeSection( + AssetListFileTableModel::Column::ColumnFileName, + config.assetListFileNameColumnWidth); + m_ui->assetListsTable->header()->resizeSection( + AssetListFileTableModel::Column::ColumnPlatform, + config.assetListPlatformColumnWidth); + + m_ui->assetListContentsFilteredSearchWidget->setFixedWidth(config.fileTableWidth); + + m_ui->assetListContentsTable->header()->resizeSection( + AssetListTableModel::Column::ColumnAssetName, + config.productAssetNameColumnWidth); + m_ui->assetListContentsTable->header()->resizeSection( + AssetListTableModel::Column::ColumnRelativePath, + config.productAssetRelativePathColumnWidth); + } + + + void AssetListTabWidget::Reload() + { + // Reload all the asset list files + m_fileTableModel->Reload(AzToolsFramework::AssetSeedManager::GetAssetListFileExtension(), m_watchedFolders, m_watchedFiles); + + // Update the selected row + FileSelectionChanged(); + } + + void AssetListTabWidget::FileSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) + { + AZ_UNUSED(selected); + AZ_UNUSED(deselected); + + if (m_ui->assetListsTable->selectionModel()->selectedRows().size() == 0) + { + // Set selected index to an invalid value + m_selectedFileTableIndex = QModelIndex(); + m_ui->assetListFileAbsolutePathLabel->setText(""); + m_assetListContentsModel.reset(new AssetListTableModel()); + m_assetListContentsFilterModel->setSourceModel(m_assetListContentsModel.data()); + m_ui->generateBundleButton->setEnabled(false); + + return; + } + + m_selectedFileTableIndex = m_fileTableFilterModel->mapToSource(m_ui->assetListsTable->selectionModel()->currentIndex()); + + m_ui->assetListFileAbsolutePathLabel->setText(QString(m_fileTableModel->GetFileAbsolutePath(m_selectedFileTableIndex).c_str())); + + m_assetListContentsModel = m_fileTableModel->GetAssetListFileContents(m_selectedFileTableIndex); + m_assetListContentsFilterModel->setSourceModel(m_assetListContentsModel.data()); + + m_ui->generateBundleButton->setEnabled(true); + } + + void AssetListTabWidget::OnGenerateBundleButtonPressed() + { + GenerateBundlesModal generateBundlesModal( + this, + m_fileTableModel->GetFileAbsolutePath(m_selectedFileTableIndex), + m_guiApplicationManager->GetBundlesFolder(), + m_guiApplicationManager->GetBundleSettingsFolder(), + this); + generateBundlesModal.exec(); + } +} //namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.h b/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.h new file mode 100644 index 0000000000..294c32ed38 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.h @@ -0,0 +1,84 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#endif + +namespace Ui +{ + class AssetListTabWidget; +} + +class QFileSystemModel; +class QStringListModel; + +namespace AssetBundler +{ + class GUIApplicationManager; + + class AssetListFileTableModel; + class AssetListTableModel; + + class AssetListTabWidget + : public AssetBundlerTabWidget + { + Q_OBJECT + + public: + explicit AssetListTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager); + virtual ~AssetListTabWidget() {} + + ////////////////////////////////////////////////////////////////////////// + // AssetBundlerTabWidget overrides + QString GetTabTitle() override { return tr("Asset Lists"); } + QString GetFileTypeDisplayName() override { return tr("Asset List file"); } + AssetBundlingFileType GetFileType() override { return AssetBundlingFileType::AssetListFileType; } + bool HasUnsavedChanges() override { return false; }; + void Reload() override; + bool SaveCurrentSelection() override { return true; }; + bool SaveAll() override { return true; }; + void SetModelDataSource() override; + AzQtComponents::TableView* GetFileTableView() override; + QModelIndex GetSelectedFileTableIndex() override; + AssetBundlerAbstractFileTableModel* GetFileTableModel() override; + void SetActiveProjectLabel(const QString& labelText) override; + void ApplyConfig() override; + void FileSelectionChanged( + const QItemSelection& /*selected*/ = QItemSelection(), + const QItemSelection& /*deselected*/ = QItemSelection()) override; + ////////////////////////////////////////////////////////////////////////// + + private: + void OnGenerateBundleButtonPressed(); + + QSharedPointer m_ui; + + QSharedPointer m_fileTableModel; + QModelIndex m_selectedFileTableIndex; + + QSharedPointer m_assetListContentsFilterModel; + QSharedPointer m_assetListContentsModel; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.ui b/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.ui new file mode 100644 index 0000000000..a5bdea227b --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/AssetListTabWidget.ui @@ -0,0 +1,168 @@ + + + AssetListTabWidget + + + + 0 + 0 + 813 + 673 + + + + Asset List Tab Widget + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Generate Bundle + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Asset List Files + + + + + + + + + + Filter by file name + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Asset List + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Filter by file name + + + + + + + + + + + + + + + + AzQtComponents::TableView + QTreeView +
AzQtComponents/Components/Widgets/TableView.h
+ 1 +
+ + AzQtComponents::FilteredSearchWidget + QTreeView +
AzQtComponents/Components/FilteredSearchWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.cpp b/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.cpp new file mode 100644 index 0000000000..53f0acc0fe --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.cpp @@ -0,0 +1,167 @@ +/* +* All or portions of this file Copyright(c) Amazon.com, Inc. or its affiliates or +*its licensors. +* +* For complete copyrightand license terms please see the LICENSE at the root of this +* distribution(the "License").All use of this software is governed by the License, +* or , if provided, by the license below or the license accompanying this file.Do not +*remove or modify any license notices.This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#include +#include + +#include +#include + +#include + +#include +#include + +const double BytesToMegabytes = 1024.0 * 1024.0; + +namespace AssetBundler +{ + + BundleListTabWidget::BundleListTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager) + : AssetBundlerTabWidget(parent, guiApplicationManager) + { + m_ui.reset(new Ui::BundleListTabWidget); + m_ui->setupUi(this); + + m_ui->mainVerticalLayout->setContentsMargins(MarginSize, MarginSize, MarginSize, MarginSize); + + m_fileTableModel.reset(new BundleFileListModel); + m_fileTableFilterModel.reset(new AssetBundlerFileTableFilterModel( + this, + m_fileTableModel->GetFileNameColumnIndex(), + m_fileTableModel->GetTimeStampColumnIndex())); + + m_fileTableFilterModel->setSourceModel(m_fileTableModel.data()); + m_ui->fileTableView->setModel(m_fileTableFilterModel.data()); + connect(m_ui->fileFilteredSearchWidget, + &AzQtComponents::FilteredSearchWidget::TextFilterChanged, + m_fileTableFilterModel.data(), + static_cast(&AssetBundlerFileTableFilterModel::FilterChanged)); + + connect(m_ui->fileTableView->selectionModel(), + &QItemSelectionModel::selectionChanged, + this, + &BundleListTabWidget::FileSelectionChanged); + + m_ui->fileTableView->setIndentation(0); + + m_relatedBundlesListModel.reset(new QStringListModel); + m_ui->relatedBundlesListView->setModel(m_relatedBundlesListModel.data()); + + m_ui->bundleFileContentsVerticalLayout->setContentsMargins(MarginSize, MarginSize, MarginSize, MarginSize); + + SetModelDataSource(); + } + + void BundleListTabWidget::Reload() + { + // The act of cracking open paks kicks off a DirectoryChanged event. We need to temporarily remove the Bundles + // directory from our watched paths to prevent an infinite loop of events. + m_guiApplicationManager->RemoveWatchedPaths(m_watchedFolders); + + // Reload all the bundle files + m_fileTableModel->Reload(AzToolsFramework::AssetBundleSettings::GetBundleFileExtension(), m_watchedFolders, m_watchedFiles); + + // Update the selected row + FileSelectionChanged(); + + // Start recieving DirectoryChanged events for these folders again + m_guiApplicationManager->AddWatchedPaths(m_watchedFolders); + } + + void BundleListTabWidget::SetModelDataSource() + { + // Remove the current watched folders and files + m_guiApplicationManager->RemoveWatchedPaths(m_watchedFolders + m_watchedFiles); + + // Set the new watched folder for the model + m_watchedFolders.clear(); + m_watchedFiles.clear(); + m_watchedFolders.insert(m_guiApplicationManager->GetBundlesFolder().c_str()); + ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType::BundleFileType); + + m_guiApplicationManager->AddWatchedPaths(m_watchedFolders + m_watchedFiles); + } + + AzQtComponents::TableView* BundleListTabWidget::GetFileTableView() + { + return m_ui->fileTableView; + } + + QModelIndex BundleListTabWidget::GetSelectedFileTableIndex() + { + return m_selectedFileTableIndex; + } + + AssetBundlerAbstractFileTableModel* BundleListTabWidget::GetFileTableModel() + { + return m_fileTableModel.get(); + } + + void BundleListTabWidget::SetActiveProjectLabel(const QString& labelText) + { + m_ui->activeProjectLabel->setText(labelText); + } + + void BundleListTabWidget::ApplyConfig() + { + const GUIApplicationManager::Config& config = m_guiApplicationManager->GetConfig(); + m_ui->fileTableFrame->setFixedWidth(config.fileTableWidth); + m_ui->fileTableView->header()->resizeSection(BundleFileListModel::Column::ColumnFileName, config.fileNameColumnWidth); + } + + + void BundleListTabWidget::FileSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/) + { + if (m_ui->fileTableView->selectionModel()->selectedRows().size() == 0) + { + m_selectedFileTableIndex = QModelIndex(); + ClearDisplayedBundleValues(); + return; + } + + m_selectedFileTableIndex = m_fileTableFilterModel->mapToSource(m_ui->fileTableView->selectionModel()->selectedRows()[0]); + AZ::Outcome< BundleFileInfoPtr, void> fileInfoOutcome = m_fileTableModel->GetBundleInfo(m_selectedFileTableIndex); + + if (!fileInfoOutcome.IsSuccess()) + { + ClearDisplayedBundleValues(); + return; + } + + BundleFileInfoPtr fileInfoPtr = fileInfoOutcome.GetValue(); + + m_ui->absolutePathLabel->setText(fileInfoPtr->m_absolutePath.c_str()); + + QString sizeFormat("%1 MB"); + double compressedSize = (double)fileInfoPtr->m_compressedSize / BytesToMegabytes; + m_ui->compressedSizeValueLabel->setText(sizeFormat.arg(compressedSize, 6, 'f', 3)); + + bool hasRelatedBundles = !fileInfoPtr->m_relatedBundles.isEmpty(); + if (hasRelatedBundles) + { + m_relatedBundlesListModel->setStringList(fileInfoPtr->m_relatedBundles); + } + m_ui->relatedBundlesLabel->setVisible(hasRelatedBundles); + m_ui->relatedBundlesListView->setVisible(hasRelatedBundles); + } + + void BundleListTabWidget::ClearDisplayedBundleValues() + { + m_ui->absolutePathLabel->clear(); + m_ui->compressedSizeValueLabel->clear(); + m_ui->relatedBundlesLabel->setVisible(false); + m_ui->relatedBundlesListView->setVisible(false); + m_relatedBundlesListModel->setStringList({}); + } +} + +#include diff --git a/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.h b/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.h new file mode 100644 index 0000000000..83439539c8 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.h @@ -0,0 +1,69 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include + +#include +#include +#include +#include +#include +#include +#endif + +namespace Ui +{ + class BundleListTabWidget; +} + +namespace AssetBundler +{ + class BundleFileListModel; + + class BundleListTabWidget + : public AssetBundlerTabWidget + { + Q_OBJECT + public: + explicit BundleListTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager); + virtual ~BundleListTabWidget() {} + + QString GetTabTitle() override { return tr("Completed Bundles"); } + QString GetFileTypeDisplayName() override { return tr("Bundle"); } + AssetBundlingFileType GetFileType() override { return AssetBundlingFileType::BundleFileType; } + bool HasUnsavedChanges() override { return false; } + void Reload() override; + bool SaveCurrentSelection() override { return true; } + bool SaveAll() override { return true; } + void SetModelDataSource() override; + AzQtComponents::TableView* GetFileTableView() override; + QModelIndex GetSelectedFileTableIndex() override; + AssetBundlerAbstractFileTableModel* GetFileTableModel() override; + void SetActiveProjectLabel(const QString& labelText) override; + void ApplyConfig() override; + void FileSelectionChanged( + const QItemSelection& /*selected*/ = QItemSelection(), + const QItemSelection& /*deselected*/ = QItemSelection()) override; + + private: + void ClearDisplayedBundleValues(); + + QSharedPointer m_ui; + QSharedPointer m_fileTableModel; + QModelIndex m_selectedFileTableIndex; + QSharedPointer m_relatedBundlesListModel; + }; + +} diff --git a/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.ui b/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.ui new file mode 100644 index 0000000000..9880640f09 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/BundleListTabWidget.ui @@ -0,0 +1,253 @@ + + + BundleListTabWidget + + + + 0 + 0 + 888 + 562 + + + + Bundle List Tab Widget + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Bundles + + + + + + + + + + Filter by file name + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Bundle Info + + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Compressed Size + + + + + + + TextLabel + + + + + + + Related Bundles + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + AzQtComponents::TableView + QTreeView +
AzQtComponents/Components/Widgets/TableView.h
+ 1 +
+ + AzQtComponents::FilteredSearchWidget + QTreeView +
AzQtComponents/Components/FilteredSearchWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.cpp b/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.cpp new file mode 100644 index 0000000000..81055676fb --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.cpp @@ -0,0 +1,466 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include + +#include +#include + +namespace AssetBundler +{ + ////////////////////////////////////////////////////////////////////////////////////////////////// + // ComparisonDataWidget + ////////////////////////////////////////////////////////////////////////////////////////////////// + + const QStringList ComparisonTypeStringList = { "Default", "Delta", "Union", "Intersection", "Complement", "Wildcard", "Regex" }; + + ComparisonDataWidget::ComparisonDataWidget( + AZStd::shared_ptr comparisonList, + size_t comparisonDataIndex, + const AZStd::string& defaultAssetListFileDirectory, + QWidget* parent) + : QWidget(parent) + , m_comparisonDataIndex(comparisonDataIndex) + , m_defaultAssetListFileDirectory(defaultAssetListFileDirectory) + { + m_ui.reset(new Ui::ComparisonDataWidget); + m_ui->setupUi(this); + + m_comparisonList = comparisonList; + + if (!IsComparisonDataIndexValid()) + { + AZ_Error("AssetBundler", false, + "ComparisonData index ( %u ) is out of bounds. ComparisonData cannot be displayed.", m_comparisonDataIndex); + return; + } + + // Due to initialization order, we need to hard-code this or else the value will be overwritten once this + // ComparisonDataWidget is added to the ComparisonDataCard, and the Card.qss file is applied + QString lineEditStyle("background-color: #CCCCCC;"); + m_ui->nameLineEdit->setStyleSheet(lineEditStyle); + m_ui->firstInputLineEdit->setStyleSheet(lineEditStyle); + m_ui->secondInputLineEdit->setStyleSheet(lineEditStyle); + m_ui->filePatternLineEdit->setStyleSheet(lineEditStyle); + + m_ui->firstInputLineEdit->setReadOnly(true); + m_ui->secondInputLineEdit->setReadOnly(true); + + SetAllDisplayValues(m_comparisonList->GetComparisonList()[m_comparisonDataIndex]); + + MouseWheelEventFilter* mouseWheelEventFilter = new MouseWheelEventFilter(this); + + connect(m_ui->nameLineEdit, &QLineEdit::textEdited, this, &ComparisonDataWidget::OnNameLineEditChanged); + + m_ui->comparisonTypeComboBox->installEventFilter(mouseWheelEventFilter); + connect(m_ui->comparisonTypeComboBox, + QOverload::of(&QComboBox::currentIndexChanged), + this, + &ComparisonDataWidget::OnComparisonTypeComboBoxChanged); + + m_ui->firstInputComboBox->installEventFilter(mouseWheelEventFilter); + connect(m_ui->firstInputComboBox, + QOverload::of(&QComboBox::currentIndexChanged), + this, + &ComparisonDataWidget::OnFirstInputComboBoxChanged); + connect(m_ui->firstInputBrowseButton, + &QPushButton::pressed, + this, + &ComparisonDataWidget::OnFirstInputBrowseButtonPressed); + + m_ui->secondInputComboBox->installEventFilter(mouseWheelEventFilter); + connect(m_ui->secondInputComboBox, + QOverload::of(&QComboBox::currentIndexChanged), + this, + &ComparisonDataWidget::OnSecondInputComboBoxChanged); + connect(m_ui->secondInputBrowseButton, &QPushButton::pressed, this, &ComparisonDataWidget::OnSecondInputBrowseButtonPressed); + + connect(m_ui->filePatternLineEdit, &QLineEdit::textEdited, this, &ComparisonDataWidget::OnFilePatternLineEditChanged); + } + + void ComparisonDataWidget::UpdateListOfTokenNames() + { + using namespace AzToolsFramework; + + if (!IsComparisonDataIndexValid()) + { + return; + } + + m_inputTokenNameList.clear(); + m_ui->firstInputComboBox->clear(); + m_ui->secondInputComboBox->clear(); + + // Store info about the current FirstInput and SecondInput values so we may auto-select them later + auto allComparisonDataSteps = m_comparisonList->GetComparisonList(); + AZStd::string selectedFirstInput = allComparisonDataSteps.at(m_comparisonDataIndex).m_firstInput; + int selectedFirstInputIndex = 0; + AZStd::string selectedSecondInput = allComparisonDataSteps.at(m_comparisonDataIndex).m_secondInput; + int selectedSecondInputIndex = 0; + + // Build list of all Token Names that have come before the current Comparison Step + m_inputTokenNameList.append(tr("Choose Asset List...")); + int currentComboBoxIndex = 1; + + AZStd::string tokenName; + for (size_t i = 0; i < m_comparisonDataIndex; ++i) + { + tokenName = allComparisonDataSteps.at(i).m_output; + if (!AssetFileInfoListComparison::IsTokenFile(tokenName)) + { + continue; + } + + if (tokenName == selectedFirstInput) + { + selectedFirstInputIndex = currentComboBoxIndex; + } + if (tokenName == selectedSecondInput) + { + selectedSecondInputIndex = currentComboBoxIndex; + } + + m_inputTokenNameList.append(RemoveTokenCharFromString(tokenName)); + ++currentComboBoxIndex; + } + + // Update display with list of Token Names, and select current Token Name in both input combo boxes + m_ui->firstInputComboBox->insertItems(0, m_inputTokenNameList); + m_ui->firstInputComboBox->setCurrentIndex(selectedFirstInputIndex); + m_isFirstInputFileNameVisible = selectedFirstInputIndex == 0; + SetFirstInputFileVisibility(m_isFirstInputFileNameVisible); + + m_ui->secondInputComboBox->insertItems(0, m_inputTokenNameList); + m_ui->secondInputComboBox->setCurrentIndex(selectedSecondInputIndex); + m_isSecondInputFileNameVisible = selectedSecondInputIndex == 0; + SetSecondInputFileVisibility(m_isSecondInputFileNameVisible); + } + + void ComparisonDataWidget::SetAllDisplayValues(const AzToolsFramework::AssetFileInfoListComparison::ComparisonData& comparisonData) + { + using namespace AzToolsFramework; + + // Name (Token value) + m_ui->nameLineEdit->setText(RemoveTokenCharFromString(comparisonData.m_output)); + + // Comparison Type + InitComparisonTypeComboBox(comparisonData); + + // Inputs + UpdateListOfTokenNames(); + m_ui->firstInputLineEdit->setText(QString(comparisonData.m_cachedFirstInputPath.c_str())); + m_ui->secondInputLineEdit->setText(QString(comparisonData.m_cachedSecondInputPath.c_str())); + + // Update fields that are not always visible + UpdateOnComparisonTypeChanged(comparisonData.m_filePatternType != AssetFileInfoListComparison::FilePatternType::Default); + } + + void ComparisonDataWidget::OnNameLineEditChanged() + { + if (!IsComparisonDataIndexValid()) + { + return; + } + + AZStd::string tokenName = m_ui->nameLineEdit->text().toUtf8().data(); + AzToolsFramework::AssetFileInfoListComparison::FormatOutputToken(tokenName); + m_comparisonList->SetOutput(m_comparisonDataIndex, tokenName); + emit comparisonDataChanged(); + emit comparisonDataTokenNameChanged(m_comparisonDataIndex); + } + + void ComparisonDataWidget::UpdateOnComparisonTypeChanged(bool isFilePatternOperation) + { + using namespace AzToolsFramework; + + if (!IsComparisonDataIndexValid()) + { + return; + } + + AssetFileInfoListComparison::ComparisonData comparisonData = m_comparisonList->GetComparisonList()[m_comparisonDataIndex]; + m_ui->inputBLabel->setVisible(!isFilePatternOperation); + m_ui->secondInputComboBox->setVisible(!isFilePatternOperation); + SetSecondInputFileVisibility(!isFilePatternOperation && m_isSecondInputFileNameVisible); + + m_ui->filePatternLabel->setVisible(isFilePatternOperation); + m_ui->filePatternLineEdit->setVisible(isFilePatternOperation); + m_ui->filePatternLineEdit->setText(comparisonData.m_filePattern.c_str()); + } + + void ComparisonDataWidget::InitComparisonTypeComboBox( + const AzToolsFramework::AssetFileInfoListComparison::ComparisonData& comparisonData) + { + using namespace AzToolsFramework; + + m_ui->comparisonTypeComboBox->insertItems(0, ComparisonTypeStringList); + int initialSelectionIndex = ComparisonTypeIndex::Default; + + if (comparisonData.m_filePatternType != AssetFileInfoListComparison::FilePatternType::Default + && comparisonData.m_comparisonType == AssetFileInfoListComparison::ComparisonType::FilePattern) + { + if (comparisonData.m_filePatternType == AssetFileInfoListComparison::FilePatternType::Wildcard) + { + initialSelectionIndex = ComparisonTypeIndex::Wildcard; + } + else + { + initialSelectionIndex = ComparisonTypeIndex::Regex; + } + } + else + { + switch (comparisonData.m_comparisonType) + { + case AssetFileInfoListComparison::ComparisonType::Default: + break; + case AssetFileInfoListComparison::ComparisonType::Delta: + initialSelectionIndex = ComparisonTypeIndex::Delta; + break; + case AssetFileInfoListComparison::ComparisonType::Union: + initialSelectionIndex = ComparisonTypeIndex::Union; + break; + case AssetFileInfoListComparison::ComparisonType::Intersection: + initialSelectionIndex = ComparisonTypeIndex::Intersection; + break; + case AssetFileInfoListComparison::ComparisonType::Complement: + initialSelectionIndex = ComparisonTypeIndex::Complement; + break; + default: + AZ_Warning("AssetBundler", false, + "ComparisonType ( %u ) is not supported in the Asset Bundler", comparisonData.m_comparisonType); + } + } + + m_ui->comparisonTypeComboBox->setCurrentIndex(initialSelectionIndex); + } + + void ComparisonDataWidget::OnComparisonTypeComboBoxChanged(int index) + { + using namespace AzToolsFramework; + + if (!IsComparisonDataIndexValid()) + { + return; + } + + bool isFilePattern = false; + + switch (index) + { + case ComparisonTypeIndex::Default: + m_comparisonList->SetComparisonType(m_comparisonDataIndex, AssetFileInfoListComparison::ComparisonType::Default); + break; + case ComparisonTypeIndex::Delta: + m_comparisonList->SetComparisonType(m_comparisonDataIndex, AssetFileInfoListComparison::ComparisonType::Delta); + break; + case ComparisonTypeIndex::Union: + m_comparisonList->SetComparisonType(m_comparisonDataIndex, AssetFileInfoListComparison::ComparisonType::Union); + break; + case ComparisonTypeIndex::Intersection: + m_comparisonList->SetComparisonType(m_comparisonDataIndex, AssetFileInfoListComparison::ComparisonType::Intersection); + break; + case ComparisonTypeIndex::Complement: + m_comparisonList->SetComparisonType(m_comparisonDataIndex, AssetFileInfoListComparison::ComparisonType::Complement); + break; + case ComparisonTypeIndex::Wildcard: + m_comparisonList->SetComparisonType(m_comparisonDataIndex, AssetFileInfoListComparison::ComparisonType::FilePattern); + m_comparisonList->SetFilePatternType(m_comparisonDataIndex, AssetFileInfoListComparison::FilePatternType::Wildcard); + isFilePattern = true; + break; + case ComparisonTypeIndex::Regex: + m_comparisonList->SetComparisonType(m_comparisonDataIndex, AssetFileInfoListComparison::ComparisonType::FilePattern); + m_comparisonList->SetFilePatternType(m_comparisonDataIndex, AssetFileInfoListComparison::FilePatternType::Regex); + isFilePattern = true; + break; + } + + UpdateOnComparisonTypeChanged(isFilePattern); + emit comparisonDataChanged(); + } + + void ComparisonDataWidget::OnFilePatternLineEditChanged() + { + if (!IsComparisonDataIndexValid()) + { + return; + } + + m_comparisonList->SetFilePattern(m_comparisonDataIndex, m_ui->filePatternLineEdit->text().toUtf8().data()); + emit comparisonDataChanged(); + } + + void ComparisonDataWidget::OnFirstInputComboBoxChanged(int index) + { + AZStd::string firstInputValue; + + if (!IsComparisonDataIndexValid()) + { + return; + } + + m_isFirstInputFileNameVisible = index == 0; + + if (!m_isFirstInputFileNameVisible) + { + // The 0th index is the default value, which translates to an empty token string. + firstInputValue = m_ui->firstInputComboBox->currentText().toUtf8().data(); + AzToolsFramework::AssetFileInfoListComparison::FormatOutputToken(firstInputValue); + } + + SetFirstInputFileVisibility(m_isFirstInputFileNameVisible); + + m_comparisonList->SetFirstInput(m_comparisonDataIndex, firstInputValue); + emit comparisonDataChanged(); + } + + void ComparisonDataWidget::SetFirstInputFileVisibility(bool isVisible) + { + m_ui->firstInputLineEdit->setVisible(isVisible); + m_ui->firstInputBrowseButton->setVisible(isVisible); + } + + void ComparisonDataWidget::OnFirstInputBrowseButtonPressed() + { + if (!IsComparisonDataIndexValid()) + { + return; + } + + QString absoluteFilePath = BrowseButtonPressed(); + if (absoluteFilePath.isEmpty()) + { + // User canceled out of the dialog + return; + } + + m_ui->firstInputLineEdit->setText(absoluteFilePath); + m_comparisonList->SetCachedFirstInputPath(m_comparisonDataIndex, absoluteFilePath.toUtf8().data()); + } + + void ComparisonDataWidget::OnSecondInputComboBoxChanged(int index) + { + if (!IsComparisonDataIndexValid()) + { + return; + } + + AZStd::string secondInputValue; + + m_isSecondInputFileNameVisible = index == 0; + + if (!m_isSecondInputFileNameVisible) + { + // The 0th index is the default value, which translates to an empty token string. + secondInputValue = m_ui->secondInputComboBox->currentText().toUtf8().data(); + AzToolsFramework::AssetFileInfoListComparison::FormatOutputToken(secondInputValue); + } + + SetSecondInputFileVisibility(m_isSecondInputFileNameVisible); + + m_comparisonList->SetSecondInput(m_comparisonDataIndex, secondInputValue); + emit comparisonDataChanged(); + } + + void ComparisonDataWidget::SetSecondInputFileVisibility(bool isVisible) + { + m_ui->secondInputLineEdit->setVisible(isVisible); + m_ui->secondInputBrowseButton->setVisible(isVisible); + } + + void ComparisonDataWidget::OnSecondInputBrowseButtonPressed() + { + if (!IsComparisonDataIndexValid()) + { + return; + } + + QString absoluteFilePath = BrowseButtonPressed(); + if (absoluteFilePath.isEmpty()) + { + // User canceled out of the dialog + return; + } + + m_ui->secondInputLineEdit->setText(absoluteFilePath); + m_comparisonList->SetCachedSecondInputPath(m_comparisonDataIndex, absoluteFilePath.toUtf8().data()); + } + + QString ComparisonDataWidget::BrowseButtonPressed() + { + AZStd::string selectedPath = NewFileDialog::OSNewFileDialog( + this, + AzToolsFramework::AssetSeedManager::GetAssetListFileExtension(), + "Asset List", + m_defaultAssetListFileDirectory); + AzToolsFramework::RemovePlatformIdentifier(selectedPath); + return selectedPath.c_str(); + } + + bool ComparisonDataWidget::IsComparisonDataIndexValid() + { + return m_comparisonList->GetComparisonList().size() > m_comparisonDataIndex; + } + + QString ComparisonDataWidget::RemoveTokenCharFromString(const AZStd::string& tokenName) + { + QString displayName = tokenName.c_str(); + if (displayName.startsWith(AzToolsFramework::AssetFileInfoListComparison::GetTokenIdentifier())) + { + displayName.remove(0, 1); + } + + return displayName; + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // MouseWheelEventFilter + ////////////////////////////////////////////////////////////////////////////////////////////////// + + bool MouseWheelEventFilter::eventFilter(QObject* obj, QEvent* ev) + { + if (ev->type() == QEvent::Wheel) + { + return true; + } + + return QObject::eventFilter(obj, ev); + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // ComparisonDataCard + ////////////////////////////////////////////////////////////////////////////////////////////////// + + ComparisonDataCard::ComparisonDataCard( + AZStd::shared_ptr comparisonList, + size_t comparisonDataIndex, + const AZStd::string& defaultAssetListFileDirectory, + QWidget* parent) + : AzQtComponents::Card(parent) + { + m_comparisonDataWidget = new ComparisonDataWidget(comparisonList, comparisonDataIndex, defaultAssetListFileDirectory, this); + setContentWidget(m_comparisonDataWidget); + + connect(this, &AzQtComponents::Card::contextMenuRequested, this, &ComparisonDataCard::OnContextMenuRequested); + } + + void ComparisonDataCard::OnContextMenuRequested(const QPoint& position) + { + emit comparisonDataCardContextMenuRequested(m_comparisonDataWidget->GetComparisonDataIndex(), position); + } + +} // namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.h b/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.h new file mode 100644 index 0000000000..9728d281a7 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.h @@ -0,0 +1,151 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include + +#include +#endif + +namespace Ui +{ + class ComparisonDataWidget; +} + +namespace AssetBundler +{ + //! Widget for displaying and editing a single Comparison Step inside a Comparison Rules file. + class ComparisonDataWidget + : public QWidget + { + Q_OBJECT + + public: + explicit ComparisonDataWidget( + AZStd::shared_ptr comparisonList, + size_t comparisonDataIndex, + const AZStd::string& defaultAssetListFileDirectory, + QWidget* parent = nullptr); + virtual ~ComparisonDataWidget() {} + + enum ComparisonTypeIndex : int + { + Default = 0, + Delta, + Union, + Intersection, + Complement, + Wildcard, + Regex, + MAX + }; + + size_t GetComparisonDataIndex() { return m_comparisonDataIndex; } + + void UpdateListOfTokenNames(); + + Q_SIGNALS: + void comparisonDataChanged(); + + void comparisonDataTokenNameChanged(size_t comparisonDataIndex); + + private: + void SetAllDisplayValues(const AzToolsFramework::AssetFileInfoListComparison::ComparisonData& comparisonData); + + void OnNameLineEditChanged(); + + void UpdateOnComparisonTypeChanged(bool isFilePatternOperation); + + void InitComparisonTypeComboBox(const AzToolsFramework::AssetFileInfoListComparison::ComparisonData& comparisonData); + + void OnComparisonTypeComboBoxChanged(int index); + + void OnFilePatternLineEditChanged(); + + void OnFirstInputComboBoxChanged(int index); + + void SetFirstInputFileVisibility(bool isVisible); + + void OnFirstInputBrowseButtonPressed(); + + void OnSecondInputComboBoxChanged(int index); + + void SetSecondInputFileVisibility(bool isVisible); + + void OnSecondInputBrowseButtonPressed(); + + QString BrowseButtonPressed(); + + bool IsComparisonDataIndexValid(); + + QString RemoveTokenCharFromString(const AZStd::string& tokenName); + + QSharedPointer m_ui; + + AZStd::shared_ptr m_comparisonList; + size_t m_comparisonDataIndex; + + AZStd::string m_defaultAssetListFileDirectory; + + QStringList m_inputTokenNameList; + QString m_outputAssetListFileAbsolutePath; + + bool m_isFirstInputFileNameVisible = false; + bool m_isSecondInputFileNameVisible = false; + }; + + class MouseWheelEventFilter + : public QObject + { + Q_OBJECT + + public: + explicit MouseWheelEventFilter(QObject* parent) : QObject(parent) {} + + protected: + bool eventFilter(QObject* obj, QEvent* ev) override; + }; + + + //! Wrapper widget that controls the expansion state and signals that trigger a context menu of a ComparisonDataWidget. + class ComparisonDataCard + : public AzQtComponents::Card + { + Q_OBJECT + + public: + explicit ComparisonDataCard( + AZStd::shared_ptr comparisonList, + size_t comparisonDataIndex, + const AZStd::string& defaultAssetListFileDirectory, + QWidget* parent = nullptr); + virtual ~ComparisonDataCard() {} + + ComparisonDataWidget* GetComparisonDataWidget() { return m_comparisonDataWidget; } + + Q_SIGNALS: + void comparisonDataCardContextMenuRequested(size_t comparisonDataIndex, const QPoint& position); + + private: + ComparisonDataWidget* m_comparisonDataWidget = nullptr; + + private slots: + void OnContextMenuRequested(const QPoint& position); + }; + + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.ui b/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.ui new file mode 100644 index 0000000000..4e148e21bb --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/ComparisonDataWidget.ui @@ -0,0 +1,150 @@ + + + ComparisonDataWidget + + + + 0 + 0 + 400 + 300 + + + + + 0 + 0 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + QLayout::SetDefaultConstraint + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Name + + + + + + + + + + Comparison Type + + + + + + + + + + Input A + + + + + + + + + + 10 + + + + + + + + Browse... + + + + + + + + + Input B + + + + + + + + + + 10 + + + + + + + + Browse... + + + + + + + + + File Pattern + + + + + + + + + + + + + + diff --git a/Code/Tools/AssetBundler/source/ui/EditSeedDialog.cpp b/Code/Tools/AssetBundler/source/ui/EditSeedDialog.cpp new file mode 100644 index 0000000000..db243f6bc2 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/EditSeedDialog.cpp @@ -0,0 +1,67 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include + +#include + +namespace AssetBundler +{ + + EditSeedDialog::EditSeedDialog( + QWidget* parent, + const AzFramework::PlatformFlags& enabledPlatforms, + const AzFramework::PlatformFlags& selectedPlatforms, + const AzFramework::PlatformFlags& partiallySelectedPlatforms) + : QDialog(parent) + { + m_ui.reset(new Ui::EditSeedDialog); + m_ui->setupUi(this); + + m_ui->platformSelectionWidget->Init(enabledPlatforms); + m_ui->platformSelectionWidget->SetSelectedPlatforms(selectedPlatforms, partiallySelectedPlatforms); + connect(m_ui->platformSelectionWidget, + &PlatformSelectionWidget::PlatformsSelected, + this, + &EditSeedDialog::OnPlatformSelectionChanged); + + // Set up confirm and cancel buttons + connect(m_ui->applyChangesButton, &QPushButton::clicked, this, &QDialog::accept); + connect(m_ui->cancelButton, &QPushButton::clicked, this, &QDialog::reject); + } + + AzFramework::PlatformFlags EditSeedDialog::GetPlatformFlags() + { + return m_ui->platformSelectionWidget->GetSelectedPlatforms(); + } + + AzFramework::PlatformFlags EditSeedDialog::GetPartiallySelectedPlatformFlags() + { + return m_ui->platformSelectionWidget->GetPartiallySelectedPlatforms(); + } + + void EditSeedDialog::OnPlatformSelectionChanged( + const AzFramework::PlatformFlags& selectedPlatforms, + const AzFramework::PlatformFlags& partiallySelectedPlatforms) + { + // Disable the "Apply Changes" button if no platforms are selected + bool areAnyPlatformsSelected = selectedPlatforms != AzFramework::PlatformFlags::Platform_NONE || + partiallySelectedPlatforms != AzFramework::PlatformFlags::Platform_NONE; + m_ui->applyChangesButton->setEnabled(areAnyPlatformsSelected); + } + +} // namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/EditSeedDialog.h b/Code/Tools/AssetBundler/source/ui/EditSeedDialog.h new file mode 100644 index 0000000000..189212ddbd --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/EditSeedDialog.h @@ -0,0 +1,54 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include + +#include +#include +#endif + +namespace Ui +{ + class EditSeedDialog; +} + +namespace AssetBundler +{ + class EditSeedDialog + : public QDialog + { + Q_OBJECT + + public: + explicit EditSeedDialog( + QWidget* parent, + const AzFramework::PlatformFlags& enabledPlatforms, + const AzFramework::PlatformFlags& selectedPlatforms, + const AzFramework::PlatformFlags& partiallySelectedPlatforms = AzFramework::PlatformFlags::Platform_NONE); + virtual ~EditSeedDialog() {} + + AzFramework::PlatformFlags GetPlatformFlags(); + AzFramework::PlatformFlags GetPartiallySelectedPlatformFlags(); + + private: + void OnPlatformSelectionChanged( + const AzFramework::PlatformFlags& selectedPlatforms, + const AzFramework::PlatformFlags& partiallySelectedPlatforms); + + QSharedPointer m_ui; + }; + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/EditSeedDialog.ui b/Code/Tools/AssetBundler/source/ui/EditSeedDialog.ui new file mode 100644 index 0000000000..7d42d2d252 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/EditSeedDialog.ui @@ -0,0 +1,117 @@ + + + EditSeedDialog + + + + 0 + 0 + 400 + 92 + + + + + 300 + 0 + + + + Edit Selected Platforms + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + 10 + + + 10 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + Apply Changes + + + true + + + + + + + + + + AssetBundler::PlatformSelectionWidget + QWidget +
source/ui/PlatformSelectionWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.cpp b/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.cpp new file mode 100644 index 0000000000..326251af88 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.cpp @@ -0,0 +1,299 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include + +const char CustomBundleSettingsText[] = "Custom"; + +namespace AssetBundler +{ + GenerateBundlesModal::GenerateBundlesModal( + QWidget* parent, + const AZStd::string& assetListFileAbsolutePath, + const AZStd::string& defaultBundleDirectory, + const AZStd::string& defaultBundleSettingsDirectory, + AssetListTabWidget* assetListTabWidget) + : QDialog(parent) + , m_assetListFileAbsolutePath(assetListFileAbsolutePath) + , m_defaultBundleDirectory(defaultBundleDirectory) + , m_defaultBundleSettingsDirectory(defaultBundleSettingsDirectory) + , m_assetListTabWidget(assetListTabWidget) + { + m_ui.reset(new Ui::GenerateBundlesModal); + m_ui->setupUi(this); + + m_platformName = AzToolsFramework::GetPlatformIdentifier(m_assetListFileAbsolutePath); + + // Selected Asset List + m_ui->selectedAssetListPathLabel->setText(QString(m_assetListFileAbsolutePath.c_str())); + + // Platform + m_ui->platformNameLabel->setText(QString(m_platformName.c_str())); + + // Bundle Output + m_ui->outputBundlePathLineEdit->setReadOnly(true); + connect(m_ui->outputBundlePathBrowseButton, + &QPushButton::clicked, + this, + &GenerateBundlesModal::OnOutputBundleLocationBrowseButtonPressed); + + // Bundle Settings files + m_ui->bundleSettingsFileLineEdit->setReadOnly(true); + m_ui->bundleSettingsFileLineEdit->setText(tr(CustomBundleSettingsText)); + connect(m_ui->bundleSettingsFileBrowseButton, + &QPushButton::clicked, + this, + &GenerateBundlesModal::OnBundleSettingsBrowseButtonPressed); + connect(m_ui->bundleSettingsFileSaveButton, + &QPushButton::clicked, + this, + &GenerateBundlesModal::OnBundleSettingsSaveButtonPressed); + + // Max Bundle Size + m_ui->maxBundleSizeSpinBox->setRange(1, AzToolsFramework::MaxBundleSizeInMB); + m_ui->maxBundleSizeSpinBox->setValue(AzToolsFramework::MaxBundleSizeInMB); + m_ui->maxBundleSizeSpinBox->setButtonSymbols(QAbstractSpinBox::ButtonSymbols::NoButtons); + m_ui->maxBundleSizeSpinBox->setSuffix(" MB"); + connect(m_ui->maxBundleSizeSpinBox, + QOverload::of(&QSpinBox::valueChanged), + this, + &GenerateBundlesModal::OnMaxBundleSizeChanged); + + // Bundle Version + m_ui->bundleVersionSpinBox->setRange(1, AzFramework::AssetBundleManifest::CurrentBundleVersion); + m_ui->bundleVersionSpinBox->setValue(AzFramework::AssetBundleManifest::CurrentBundleVersion); + m_ui->bundleVersionSpinBox->setButtonSymbols(QAbstractSpinBox::ButtonSymbols::NoButtons); + connect(m_ui->bundleVersionSpinBox, + QOverload::of(&QSpinBox::valueChanged), + this, + &GenerateBundlesModal::OnBundleVersionChanged); + + // Cancel and Generate Bundles buttons + m_ui->generateBundlesButton->setEnabled(false); + connect(m_ui->cancelButton, &QPushButton::clicked, this, &QDialog::reject); + connect(m_ui->generateBundlesButton, &QPushButton::clicked, this, &GenerateBundlesModal::OnGenerateBundlesButtonPressed); + + // In-memory Bundle Settings + m_bundleSettings.m_assetFileInfoListPath = m_assetListFileAbsolutePath; + m_bundleSettings.m_platform = m_platformName; + m_bundleSettings.m_maxBundleSizeInMB = static_cast(m_ui->maxBundleSizeSpinBox->value()); + m_bundleSettings.m_bundleVersion = m_ui->bundleVersionSpinBox->value(); + } + + GenerateBundlesModal::~GenerateBundlesModal() + { + m_assetListTabWidget = nullptr; + } + + void GenerateBundlesModal::OnOutputBundleLocationBrowseButtonPressed() + { + AZStd::string outputBundleAbsolutePath = NewFileDialog::OSNewFileDialog( + this, + AzToolsFramework::AssetBundleSettings::GetBundleFileExtension(), + "Bundle", + m_defaultBundleDirectory); + + if (outputBundleAbsolutePath.empty()) + { + // User canceled out of the dialog + return; + } + + AzToolsFramework::RemovePlatformIdentifier(outputBundleAbsolutePath); + AddPlatformIdentifier(outputBundleAbsolutePath, m_platformName); + + m_bundleSettings.m_bundleFilePath = outputBundleAbsolutePath; + + m_ui->outputBundlePathLineEdit->setText(outputBundleAbsolutePath.c_str()); + m_ui->generateBundlesButton->setEnabled(true); + } + + void GenerateBundlesModal::OnBundleSettingsBrowseButtonPressed() + { + AZStd::string bundleSettingsAbsolutePath = NewFileDialog::OSNewFileDialog( + this, + AzToolsFramework::AssetBundleSettings::GetBundleSettingsFileExtension(), + "Bundle Settings", + m_defaultBundleSettingsDirectory); + + if (bundleSettingsAbsolutePath.empty()) + { + // User canceled out of the dialog + return; + } + + // Read in the values from the Bundle Settings file + bool loadResult = LoadBundleSettingsValues(bundleSettingsAbsolutePath); + if (!loadResult) + { + return; + } + + // Update the display name for our settings + UpdateBundleSettingsDisplayName(bundleSettingsAbsolutePath); + } + + bool GenerateBundlesModal::LoadBundleSettingsValues(const AZStd::string& absoluteBundleSettingsFilePath) + { + using namespace AzToolsFramework; + + auto outcome = AssetBundleSettings::Load(absoluteBundleSettingsFilePath); + if (!outcome.IsSuccess()) + { + AZ_Error("AssetBundler", false, outcome.GetError().c_str()); + return false; + } + + // We don't want to overwrite all of the in-memory bundle settings, so we will just update a few + AssetBundleSettings loadedSettings = outcome.TakeValue(); + + m_bundleSettings.m_maxBundleSizeInMB = loadedSettings.m_maxBundleSizeInMB; + m_ui->maxBundleSizeSpinBox->setValue(static_cast(m_bundleSettings.m_maxBundleSizeInMB)); + + m_bundleSettings.m_bundleVersion = loadedSettings.m_bundleVersion; + m_ui->bundleVersionSpinBox->setValue(m_bundleSettings.m_bundleVersion); + + return true; + } + + void GenerateBundlesModal::UpdateBundleSettingsDisplayName(const AZStd::string& absoluteBundleSettingsFilePath) + { + if (absoluteBundleSettingsFilePath.empty()) + { + m_ui->bundleSettingsFileLineEdit->setText(tr(CustomBundleSettingsText)); + return; + } + + AZStd::string bundleSettingsFileName = absoluteBundleSettingsFilePath; + AzToolsFramework::RemovePlatformIdentifier(bundleSettingsFileName); + AzFramework::StringFunc::Path::GetFileName(bundleSettingsFileName.c_str(), bundleSettingsFileName); + m_ui->bundleSettingsFileLineEdit->setText(bundleSettingsFileName.c_str()); + } + + void GenerateBundlesModal::OnBundleSettingsSaveButtonPressed() + { + using namespace AzToolsFramework; + + // Ask the user where they want to save the Bundle Settings file + AZStd::string bundleSettingsAbsolutePath = NewFileDialog::OSNewFileDialog( + this, + AssetBundleSettings::GetBundleSettingsFileExtension(), + "Bundle Settings", + m_defaultBundleSettingsDirectory); + + if (bundleSettingsAbsolutePath.empty()) + { + // User canceled out of the operation + return; + } + + AzToolsFramework::RemovePlatformIdentifier(bundleSettingsAbsolutePath); + AddPlatformIdentifier(bundleSettingsAbsolutePath, m_platformName); + + if (AZ::IO::FileIOBase::GetInstance()->Exists(bundleSettingsAbsolutePath.c_str())) + { + QString messageBoxText = QString(tr( + "Bundle Settings ( %1 ) already exists on-disk. Saving the current settings will override the existing settings. \n\nDo you wish to continue?")).arg(bundleSettingsAbsolutePath.c_str()); + + QMessageBox::StandardButton confirmDeleteFileResult = + QMessageBox::question(this, QString(tr("Replace Existing Settings")), messageBoxText); + if (confirmDeleteFileResult != QMessageBox::StandardButton::Yes) + { + // User canceled out of the operation + return; + } + } + + bool saveResult = AssetBundleSettings::Save(m_bundleSettings, bundleSettingsAbsolutePath); + if (!saveResult) + { + // Error has already been thrown + return; + } + + m_assetListTabWidget->AddScanPathToAssetBundlerSettings(AssetBundlingFileType::BundleSettingsFileType, bundleSettingsAbsolutePath); + + UpdateBundleSettingsDisplayName(bundleSettingsAbsolutePath); + } + + void GenerateBundlesModal::OnMaxBundleSizeChanged() + { + m_bundleSettings.m_maxBundleSizeInMB = static_cast(m_ui->maxBundleSizeSpinBox->value()); + UpdateBundleSettingsDisplayName(""); + } + + void GenerateBundlesModal::OnBundleVersionChanged() + { + m_bundleSettings.m_bundleVersion = m_ui->bundleVersionSpinBox->value(); + UpdateBundleSettingsDisplayName(""); + } + + void GenerateBundlesModal::OnGenerateBundlesButtonPressed() + { + using namespace AzToolsFramework; + + if (AZ::IO::FileIOBase::GetInstance()->Exists(m_bundleSettings.m_bundleFilePath.c_str())) + { + QString messageBoxText = QString(tr( + "Asset Bundle ( %1 ) already exists on-disk. Generating a new Bundle will override the existing Bundle. \n\nDo you wish to permanently delete the existing Bundle?")).arg(m_bundleSettings.m_bundleFilePath.c_str()); + + QMessageBox::StandardButton confirmDeleteFileResult = + QMessageBox::question(this, QString(tr("Replace Existing Bundle")), messageBoxText); + if (confirmDeleteFileResult != QMessageBox::StandardButton::Yes) + { + // User canceled out of the operation + return; + } + } + + bool result = false; + AssetBundleCommandsBus::BroadcastResult(result, &AssetBundleCommandsBus::Events::CreateAssetBundle, m_bundleSettings); + + // This operation will take long enough that the OS will throw up its own wait cursor, + // but there is a slight delay where the UI is unresponsive but the cursor hasn't changed. + // We are changing the cursor manually to avoid that. + setCursor(Qt::WaitCursor); + + emit QDialog::accept(); + + if (result) + { + m_assetListTabWidget->AddScanPathToAssetBundlerSettings( + AssetBundlingFileType::BundleFileType, + m_bundleSettings.m_bundleFilePath); + + // The watched files list was updated after the files were created, so we need to force-reload them + m_assetListTabWidget->GetGUIApplicationManager()->UpdateFiles( + AssetBundlingFileType::BundleFileType, + { m_bundleSettings.m_bundleFilePath }); + } + + AZStd::vector generatedFilePaths = { m_bundleSettings.m_bundleFilePath }; + NewFileDialog::FileGenerationResultMessageBox(this, generatedFilePaths, !result); + + unsetCursor(); + } + +} // namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.h b/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.h new file mode 100644 index 0000000000..b4edaedb9b --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.h @@ -0,0 +1,75 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include + +#include +#include +#endif + +namespace Ui +{ + class GenerateBundlesModal; +} + +namespace AssetBundler +{ + class AssetListTabWidget; + + class GenerateBundlesModal + : public QDialog + { + Q_OBJECT + + public: + explicit GenerateBundlesModal( + QWidget* parent, + const AZStd::string& assetListFileAbsolutePath, + const AZStd::string& defaultBundleDirectory, + const AZStd::string& defaultBundleSettingsDirectory, + AssetListTabWidget* assetListTabWidget); + virtual ~GenerateBundlesModal(); + + private: + void OnOutputBundleLocationBrowseButtonPressed(); + + void OnBundleSettingsBrowseButtonPressed(); + + bool LoadBundleSettingsValues(const AZStd::string& absoluteBundleSettingsFilePath); + + void UpdateBundleSettingsDisplayName(const AZStd::string& absoluteBundleSettingsFilePath); + + void OnBundleSettingsSaveButtonPressed(); + + void OnMaxBundleSizeChanged(); + + void OnBundleVersionChanged(); + + void OnGenerateBundlesButtonPressed(); + + QSharedPointer m_ui; + + AssetListTabWidget* m_assetListTabWidget = nullptr; + + AZStd::string m_assetListFileAbsolutePath; + AZStd::string m_defaultBundleDirectory; + AZStd::string m_defaultBundleSettingsDirectory; + AZStd::string m_platformName; + + AzToolsFramework::AssetBundleSettings m_bundleSettings; + }; + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.ui b/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.ui new file mode 100644 index 0000000000..df7ac0f0be --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/GenerateBundlesModal.ui @@ -0,0 +1,292 @@ + + + GenerateBundlesModal + + + Qt::ApplicationModal + + + + 0 + 0 + 800 + 300 + + + + + 0 + 0 + + + + + 750 + 0 + + + + Generate Bundles + + + + 10 + + + 10 + + + 10 + + + 10 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 5 + + + 0 + + + 5 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Asset List + + + + + + + TextLabel + + + + + + + Platform + + + + + + + TextLabel + + + + + + + Output Bundle Name + + + + + + + + + + + + Browse... + + + + + + + + + + + + Qt::Horizontal + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Settings + + + + + + + + + + + + Browse... + + + + + + + Save + + + + + + + + + Max Bundle Size + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Bundle Version + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + Generate Bundles + + + true + + + + + + + + + + diff --git a/Code/Tools/AssetBundler/source/ui/MainWindow.cpp b/Code/Tools/AssetBundler/source/ui/MainWindow.cpp new file mode 100644 index 0000000000..53b1c07943 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/MainWindow.cpp @@ -0,0 +1,252 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace AssetBundler +{ + + MainWindow::MainWindow(AssetBundler::GUIApplicationManager* guiApplicationManager, QWidget* parent) + : QMainWindow(parent) + , m_guiApplicationManager(guiApplicationManager) + { + m_ui.reset(new Ui::MainWindow); + m_ui->setupUi(this); + + m_ui->verticalLayout->setContentsMargins(0, 0, 0, 0); + + // Set up Log + m_logModel.reset(new AzToolsFramework::Logging::LogTableModel(this)); + m_ui->logTableView->setModel(m_logModel.data()); + m_ui->logTableView->setIndentation(0); + + m_ui->logTableView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_ui->logTableView, &QWidget::customContextMenuRequested, this, &MainWindow::ShowLogContextMenu); + + AZ::Debug::TraceMessageBus::Handler::BusConnect(); + + // Create the Unsaved Changes Popup + m_unsavedChangesMsgBox.reset(new QMessageBox(this)); + m_unsavedChangesMsgBox->setText(tr("There are unsaved changes.")); + m_unsavedChangesMsgBox->setInformativeText(tr("Would you like to save all changes before quitting?")); + m_unsavedChangesMsgBox->setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + m_unsavedChangesMsgBox->setDefaultButton(QMessageBox::Save); + + // Set up Quit functionality + m_ui->actionClose->setShortcut(Qt::Key_Q | Qt::CTRL); + m_ui->actionClose->setMenuRole(QAction::QuitRole); + connect(m_ui->actionClose, SIGNAL(triggered()), this, SLOT(close())); + this->addAction(m_ui->actionClose); + + // Set up Tabs + AssetBundlerTabWidget::InitAssetBundlerSettings(m_guiApplicationManager->GetCurrentProjectFolder().c_str()); + + m_seedListTab.reset(new SeedTabWidget( + this, + m_guiApplicationManager, + QString(m_guiApplicationManager->GetAssetBundlingFolder().c_str()))); + m_ui->tabWidget->addTab(m_seedListTab.data(), m_seedListTab->GetTabTitle()); + + m_assetListTab.reset(new AssetListTabWidget(this, m_guiApplicationManager)); + m_ui->tabWidget->addTab(m_assetListTab.data(), m_assetListTab->GetTabTitle()); + + m_rulesTab.reset(new RulesTabWidget(this, m_guiApplicationManager)); + m_ui->tabWidget->addTab(m_rulesTab.data(), m_rulesTab->GetTabTitle()); + + m_bundleListTab.reset(new BundleListTabWidget(this, m_guiApplicationManager)); + m_ui->tabWidget->addTab(m_bundleListTab.data(), m_bundleListTab->GetTabTitle()); + + // Set up link to documentation + QAction* supportAction = new QAction(QIcon(":/stylesheet/img/help.svg"), "", this); + connect(supportAction, &QAction::triggered, this, &MainWindow::OnSupportClicked); + connect(m_ui->actionDocumentation, &QAction::triggered, this, &MainWindow::OnSupportClicked); + m_ui->tabWidget->setActionToolBarVisible(); + m_ui->tabWidget->addAction(supportAction); + + // Set up Save functionality + m_ui->actionSave->setShortcut(Qt::Key_S | Qt::CTRL); + connect(m_ui->actionSave, &QAction::triggered, this, &MainWindow::SaveCurrentSelection); + + m_ui->actionSaveAll->setShortcut(Qt::Key_S | Qt::CTRL | Qt::SHIFT); + connect(m_ui->actionSaveAll, &QAction::triggered, this, &MainWindow::SaveAll); + } + + MainWindow::~MainWindow() + { + AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); + m_guiApplicationManager = nullptr; + } + + void MainWindow::Activate() + { + m_seedListTab->Activate(); + m_rulesTab->Activate(); + m_assetListTab->Activate(); + m_bundleListTab->Activate(); + } + + void MainWindow::ApplyConfig() + { + const GUIApplicationManager::Config& config = m_guiApplicationManager->GetConfig(); + // Event Log Details + m_ui->logTableView->header()->resizeSection(AzToolsFramework::Logging::LogTableModel::ColumnType, config.logTypeColumnWidth); + m_ui->logTableView->header()->resizeSection(AzToolsFramework::Logging::LogTableModel::ColumnWindow, config.logSourceColumnWidth); + + m_seedListTab->ApplyConfig(); + m_assetListTab->ApplyConfig(); + m_rulesTab->ApplyConfig(); + m_bundleListTab->ApplyConfig(); + } + + void MainWindow::WriteToLog(const AZStd::string& message, AzToolsFramework::Logging::LogLine::LogType logType) + { + WriteToLog(message.c_str(), logType); + } + + void MainWindow::WriteToLog(const QString& message, AzToolsFramework::Logging::LogLine::LogType logType) + { + WriteToLog(message.toUtf8().data(), logType); + } + + void MainWindow::WriteToLog(const char* message, AzToolsFramework::Logging::LogLine::LogType logType) + { + WriteToLog(message, "AssetBundler", logType); + } + + void MainWindow::WriteToLog(const char* message, const char* window, AzToolsFramework::Logging::LogLine::LogType logType) + { + m_logModel->AppendLine( + AzToolsFramework::Logging::LogLine( + message, + window, + logType, + QDateTime::currentMSecsSinceEpoch())); + m_ui->logTableView->scrollToBottom(); + } + + bool MainWindow::OnPreError(const char* window, const char* /*fileName*/, int /*line*/, const char* /*func*/, const char* message) + { + WriteToLog(message, window, AzToolsFramework::Logging::LogLine::LogType::TYPE_ERROR); + return true; + } + + bool MainWindow::OnPreWarning(const char* window, const char* /*fileName*/, int /*line*/, const char* /*func*/, const char* message) + { + WriteToLog(message, window, AzToolsFramework::Logging::LogLine::LogType::TYPE_WARNING); + return true; + } + + bool MainWindow::OnPrintf(const char* /*window*/, const char* /*message*/) + { + return true; + } + + void MainWindow::ShowWindow() + { + AzQtComponents::bringWindowToTop(this); + } + + void MainWindow::closeEvent(QCloseEvent* event) + { + if (!HasUnsavedChanges()) + { + // No need to ask the user if they want to quit when there are no unsaved changes + event->accept(); + return; + } + + int unsavedChangesResult = m_unsavedChangesMsgBox->exec(); + + switch (unsavedChangesResult) + { + case QMessageBox::Save: + // Save All was clicked + SaveAll(); + event->accept(); + break; + case QMessageBox::Discard: + // Don't Save was clicked + event->accept(); + break; + case QMessageBox::Cancel: + // Cancel was clicked + event->ignore(); + break; + default: + // should never be reached + AZ_Assert(false, "No result was returned by the Unsaved Changes Message Box!"); + break; + } + } + + void MainWindow::OnSupportClicked() + { + QDesktopServices::openUrl( + QStringLiteral("https://docs.aws.amazon.com/lumberyard/latest/userguide/asset-bundler-overview.html")); + } + + void MainWindow::ShowLogContextMenu(const QPoint& pos) + { + QModelIndex index = m_ui->logTableView->indexAt(pos); + + QMenu menu; + + QAction* action = menu.addAction(tr("Copy line"), this, [&]() + { + QApplication::clipboard()->setText(index.data(AzToolsFramework::Logging::LogTableModel::LogLineTextRole).toString()); + }); + action->setEnabled(index.isValid()); + + menu.exec(m_ui->logTableView->mapToGlobal(pos)); + } + + bool MainWindow::HasUnsavedChanges() + { + return m_seedListTab->HasUnsavedChanges() || m_rulesTab->HasUnsavedChanges(); + } + + void MainWindow::SaveCurrentSelection() + { + switch (m_ui->tabWidget->currentIndex()) + { + case TabIndex::Seeds: + m_seedListTab->SaveCurrentSelection(); + break; + case TabIndex::Rules: + m_rulesTab->SaveCurrentSelection(); + break; + default: + break; + } + } + + void MainWindow::SaveAll() + { + m_seedListTab->SaveAll(); + m_rulesTab->SaveAll(); + } +} // namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/MainWindow.h b/Code/Tools/AssetBundler/source/ui/MainWindow.h new file mode 100644 index 0000000000..e8c5570649 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/MainWindow.h @@ -0,0 +1,105 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#endif + +namespace Ui +{ + class MainWindow; +} + +namespace AssetBundler +{ + class GUIApplicationManager; + + class MainWindow + : public QMainWindow + , public AZ::Debug::TraceMessageBus::Handler + { + Q_OBJECT + + public: + + explicit MainWindow(AssetBundler::GUIApplicationManager* guiApplicationManager, QWidget* parent = 0); + virtual ~MainWindow(); + + void Activate(); + + void ApplyConfig(); + + void WriteToLog(const AZStd::string& message, AzToolsFramework::Logging::LogLine::LogType logType); + void WriteToLog(const QString& message, AzToolsFramework::Logging::LogLine::LogType logType); + void WriteToLog(const char* message, AzToolsFramework::Logging::LogLine::LogType logType); + void WriteToLog(const char* message, const char* window, AzToolsFramework::Logging::LogLine::LogType logType); + + ///////////////////////////////////////////////////////// + // TraceMessageBus overrides + bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override; + bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override; + bool OnPrintf(const char* window, const char* message) override; + ///////////////////////////////////////////////////////// + + public Q_SLOTS: + void ShowWindow(); + + protected: + void closeEvent(QCloseEvent* event) override; + + private: + QSharedPointer m_ui; + + // Tabs + QSharedPointer m_assetListTab; + QSharedPointer m_seedListTab; + QSharedPointer m_rulesTab; + QSharedPointer m_bundleListTab; + + enum TabIndex + { + Seeds, + AssetLists, + Rules, + Bundles, + MAX + }; + + void OnSupportClicked(); + + // Log + QSharedPointer m_logModel; + + void ShowLogContextMenu(const QPoint& pos); + + // Detecting Unsaved Changes + QSharedPointer m_unsavedChangesMsgBox; + + bool HasUnsavedChanges(); + void SaveCurrentSelection(); + void SaveAll(); + + AssetBundler::GUIApplicationManager* m_guiApplicationManager = nullptr; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/MainWindow.ui b/Code/Tools/AssetBundler/source/ui/MainWindow.ui new file mode 100644 index 0000000000..902652459f --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/MainWindow.ui @@ -0,0 +1,112 @@ + + + MainWindow + + + + 0 + 0 + 1200 + 1000 + + + + + 200 + 200 + + + + Asset Bundler + + + + + + + -1 + + + + + + + + 0 + 0 + + + + + + + + + + 0 + 0 + 1200 + 21 + + + + + File + + + + + + + + + Help + + + + + + + + + Save + + + + + Close + + + + + Documentation + + + + + About Asset Bundler + + + + + Save All + + + + + + AzQtComponents::TableView + QTreeView +
AzQtComponents/Components/Widgets/TableView.h
+ 1 +
+ + AzQtComponents::TabWidget + QTabWidget +
AzQtComponents/Components/Widgets/TabWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/NewFileDialog.cpp b/Code/Tools/AssetBundler/source/ui/NewFileDialog.cpp new file mode 100644 index 0000000000..00a63d193b --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/NewFileDialog.cpp @@ -0,0 +1,239 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace AssetBundler +{ + NewFileDialog::NewFileDialog( + QWidget* parent, + const QString& dialogTitle, + const QString& startingPath, + const char* fileExtension, + const QString& fileNameFilter, + const AzFramework::PlatformFlags& enabledPlatforms, + bool isRunningRule) + : QDialog(parent) + , m_startingPath(startingPath) + , m_fileExtension(fileExtension) + { + m_ui.reset(new Ui::NewFileDialog); + m_ui->setupUi(this); + + setWindowTitle(dialogTitle); + + // Set up File Name section + m_ui->fileNameLineEdit->setEnabled(false); + connect(m_ui->browseButton, &QPushButton::clicked, this, &NewFileDialog::OnBrowseButtonPressed); + + m_newFileDialog.setFileMode(QFileDialog::AnyFile); + m_newFileDialog.setNameFilter(fileNameFilter); + m_newFileDialog.setViewMode(QFileDialog::Detail); + m_newFileDialog.setDirectory(m_startingPath); + // We are not creating a new file when Qt thinks we are, so we need to block signals or else the file watcher will be + // triggered too soon + m_newFileDialog.blockSignals(true); + + // Set up Platform selection + QString disabledPatformMessageOverride; + if (isRunningRule) + { + disabledPatformMessageOverride = tr("This platform is not valid for all input Asset Lists."); + } + m_ui->platformSelectionWidget->Init(enabledPlatforms, disabledPatformMessageOverride); + connect(m_ui->platformSelectionWidget, + &PlatformSelectionWidget::PlatformsSelected, + this, + &NewFileDialog::OnPlatformSelectionChanged); + + // Set up Cancel and Create New File buttons + m_ui->createFileButton->setEnabled(false); + connect(m_ui->cancelButton, &QPushButton::clicked, this, &QDialog::reject); + connect(m_ui->createFileButton, &QPushButton::clicked, this, &NewFileDialog::OnCreateFileButtonPressed); + } + + AZStd::string NewFileDialog::GetAbsoluteFilePath() + { + return m_absoluteFilePath; + } + + AzFramework::PlatformFlags NewFileDialog::GetPlatformFlags() + { + return m_ui->platformSelectionWidget->GetSelectedPlatforms(); + } + + void NewFileDialog::OnBrowseButtonPressed() + { + int result = m_newFileDialog.exec(); + if (result == QDialog::DialogCode::Accepted) + { + m_absoluteFilePath = m_newFileDialog.selectedFiles()[0].toUtf8().data(); + AzToolsFramework::RemovePlatformIdentifier(m_absoluteFilePath); + + if (m_fileExtension && !AzFramework::StringFunc::Path::HasExtension(m_absoluteFilePath.c_str())) + { + m_absoluteFilePath.append("."); + m_absoluteFilePath.append(m_fileExtension); + } + + m_ui->fileNameLineEdit->setEnabled(true); + m_ui->fileNameLineEdit->setText(m_absoluteFilePath.c_str()); + } + + m_fileNameIsValid = !m_absoluteFilePath.empty(); + m_ui->createFileButton->setEnabled(m_platformIsValid && m_fileNameIsValid); + } + + void NewFileDialog::OnPlatformSelectionChanged(const AzFramework::PlatformFlags& selectedPlatforms) + { + // Hide the "Create File" button if no platforms are selected + m_platformIsValid = selectedPlatforms != AzFramework::PlatformFlags::Platform_NONE; + m_ui->createFileButton->setEnabled(m_platformIsValid && m_fileNameIsValid); + } + + void NewFileDialog::OnCreateFileButtonPressed() + { + // Check to see if any of the selected platform-specific files already exist on-disk + QString overwriteExistingFilesList; + AZStd::fixed_vector selectedPlatformNames = + AzFramework::PlatformHelper::GetPlatforms(GetPlatformFlags()); + for (const AZStd::string& platformName : selectedPlatformNames) + { + FilePath platformSpecificFilePath(GetAbsoluteFilePath(), platformName); + const char* platformSpecificFileAbsolutePath = platformSpecificFilePath.AbsolutePath().c_str(); + if (AZ::IO::FileIOBase::GetInstance()->Exists(platformSpecificFileAbsolutePath)) + { + overwriteExistingFilesList.append(QString("%1\n").arg(platformSpecificFileAbsolutePath)); + } + } + + // Ask the user if they are sure they want to overwrite existing files + if (!overwriteExistingFilesList.isEmpty()) + { + QString messageBoxText = QString(tr( + "The following files already exist on-disk. Generating new files will overwrite the existing ones.\n\n%1\n\nDo you wish to permanently delete the existing files?")).arg(overwriteExistingFilesList); + + QMessageBox::StandardButton confirmDeleteFileResult = + QMessageBox::question(this, QString(tr("Replace Existing Files")), messageBoxText); + if (confirmDeleteFileResult != QMessageBox::StandardButton::Yes) + { + // User canceled out of the operation + return; + } + } + + emit QDialog::accept(); + } + + AZStd::string NewFileDialog::OSNewFileDialog( + QWidget* parent, + const char* fileExtension, + const char* fileTypeDisplayName, + const AZStd::string& startingDirectory) + { + QFileDialog filePathDialog(parent); + filePathDialog.setFileMode(QFileDialog::AnyFile); + filePathDialog.setNameFilter(QString(tr("%1 (*.%2)")).arg(fileTypeDisplayName).arg(fileExtension)); + filePathDialog.setViewMode(QFileDialog::Detail); + filePathDialog.setDirectory(startingDirectory.c_str()); + + // Since we handle file creation instead of the OS, we have to block signals or else the model will be reloaded, + // and our in-memory changes will be lost. + filePathDialog.blockSignals(true); + int result = filePathDialog.exec(); + if (result == QDialog::DialogCode::Rejected || filePathDialog.selectedFiles().empty()) + { + // User canceled out of the file dialog, cancel operation + return ""; + } + + AZStd::string absoluteFilePath(filePathDialog.selectedFiles()[0].toUtf8().data()); + if (!AzFramework::StringFunc::Path::HasExtension(absoluteFilePath.c_str())) + { + absoluteFilePath = + AZStd::string::format("%s%c%s", absoluteFilePath.c_str(), AZ_FILESYSTEM_EXTENSION_SEPARATOR, fileExtension); + } + + return absoluteFilePath; + } + + int NewFileDialog::FileGenerationResultMessageBox( + QWidget* parent, + const AZStd::vector& generatedFiles, + bool generatedWithErrors) + { + QMessageBox messageBox(parent); + messageBox.setStandardButtons(QMessageBox::Ok); + messageBox.setDefaultButton(QMessageBox::Ok); + + if (generatedFiles.empty()) + { + messageBox.setText(QString("No files were generated. Please refer to the console for more information.")); + messageBox.setIcon(QMessageBox::Critical); + return messageBox.exec(); + } + + QString messageText; + if (generatedWithErrors) + { + messageText = QString("The following files were generated with errors. Please refer to the console for more information.\n\n"); + messageBox.setIcon(QMessageBox::Warning); + } + else + { + messageText = QString("You have successfully generated:\n\n"); + messageBox.setIcon(QMessageBox::NoIcon); + } + + AZStd::string fileName; + for (const AZStd::string& filePath : generatedFiles) + { + AzFramework::StringFunc::Path::GetFullFileName(filePath.c_str(), fileName); + messageText.append(QString("%1\n").arg(fileName.c_str())); + } + + AZStd::string extension; + AzFramework::StringFunc::Path::GetExtension(fileName.c_str(), extension, false); + if (extension == AzToolsFramework::AssetSeedManager::GetAssetListFileExtension()) + { + messageText.append("\nVisit the Asset Lists tab to see the lists."); + } + else if (extension == AzToolsFramework::AssetBundleSettings::GetBundleFileExtension()) + { + messageText.append("\nVisit the Completed Bundles tab to see the bundles."); + } + + messageBox.setText(messageText); + + // QMessageBoxes try to shrink to the smallest size possible, so we need to make a spacer + QSpacerItem* horizontalSpacer = new QSpacerItem(550, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + QGridLayout* layout = static_cast(messageBox.layout()); + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + + return messageBox.exec(); + } + +} //namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/NewFileDialog.h b/Code/Tools/AssetBundler/source/ui/NewFileDialog.h new file mode 100644 index 0000000000..37cb81a3d3 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/NewFileDialog.h @@ -0,0 +1,80 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include + +#include +#include +#include +#endif + +namespace Ui +{ + class NewFileDialog; +} + +namespace AssetBundler +{ + class GUIApplicationManager; + + class NewFileDialog + : public QDialog + { + Q_OBJECT + + public: + explicit NewFileDialog( + QWidget* parent, + const QString& dialogTitle, + const QString& startingPath, + const char* fileExtension, + const QString& fileNameFilter, + const AzFramework::PlatformFlags& enabledPlatforms, + bool isRunningRule = false); + virtual ~NewFileDialog() {} + + AZStd::string GetAbsoluteFilePath(); + AzFramework::PlatformFlags GetPlatformFlags(); + + //! A standard OS-specific New File Dialog, but blocks all Qt signals from the dialog and does NOT create a new file. + //! Use in place of the static QFileDialog functions to avoid unexpected file watcher updates. + //! Returns the absolute path of the file the user either selected or attempted to create, or an empty string if the user canceled out of the dialog. + static AZStd::string OSNewFileDialog( + QWidget* parent, + const char* fileExtension, + const char* fileTypeDisplayName, + const AZStd::string& startingDirectory); + + static int FileGenerationResultMessageBox( + QWidget* parent, + const AZStd::vector& generatedFiles, + bool generatedWithErrors); + + private: + void OnBrowseButtonPressed(); + void OnPlatformSelectionChanged(const AzFramework::PlatformFlags& selectedPlatforms); + void OnCreateFileButtonPressed(); + + QSharedPointer m_ui; + QString m_startingPath; + const char* m_fileExtension; + QFileDialog m_newFileDialog; + + AZStd::string m_absoluteFilePath; + + bool m_fileNameIsValid = false; + bool m_platformIsValid = false; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/NewFileDialog.ui b/Code/Tools/AssetBundler/source/ui/NewFileDialog.ui new file mode 100644 index 0000000000..17d439549c --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/NewFileDialog.ui @@ -0,0 +1,154 @@ + + + NewFileDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 450 + 90 + + + + + 0 + 0 + + + + + 450 + 0 + + + + Dialog + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Save As: + + + + + + + true + + + + + + + Browse... + + + + + + + + + + + + + + + 10 + + + 10 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + false + + + + + + + Create New File + + + true + + + + + + + + + + AssetBundler::PlatformSelectionWidget + QWidget +
source/ui/PlatformSelectionWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.cpp b/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.cpp new file mode 100644 index 0000000000..ae203077fe --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.cpp @@ -0,0 +1,128 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include + +namespace AssetBundler +{ + + PlatformSelectionWidget::PlatformSelectionWidget(QWidget* parent) + : QWidget(parent) + { + m_ui.reset(new Ui::PlatformSelectionWidget); + m_ui->setupUi(this); + + m_platformHelper.reset(new AzFramework::PlatformHelper); + + m_selectedPlatforms = AzFramework::PlatformFlags::Platform_NONE; + m_partiallySelectedPlatforms = AzFramework::PlatformFlags::Platform_NONE; + } + + void PlatformSelectionWidget::Init(const AzFramework::PlatformFlags& enabledPlatforms, const QString& disabledPatformMessageOverride) + { + using namespace AzFramework; + + // Set up Platform Checkboxes + for (const AZStd::string_view& platformString : m_platformHelper->GetPlatforms(PlatformFlags::AllNamedPlatforms)) + { + // Create the CheckBox and store what platform it maps to + QSharedPointer platformCheckBox(new QCheckBox(QString::fromUtf8(platformString.data(), platformString.size()))); + m_platformCheckBoxes.push_back(platformCheckBox); + PlatformFlags currentPlatformFlag = m_platformHelper->GetPlatformFlag(platformString); + m_platformList.push_back(currentPlatformFlag); + + // Add the CheckBox to the view + m_ui->platformCheckBoxLayout->addWidget(platformCheckBox.data()); + + // If the platform is not enabled for the current project, disable it and tell the user + if ((enabledPlatforms & currentPlatformFlag) == PlatformFlags::Platform_NONE) + { + platformCheckBox->setEnabled(false); + if (disabledPatformMessageOverride.isEmpty()) + { + platformCheckBox->setToolTip(tr("This platform is not enabled for the current project.")); + } + else + { + platformCheckBox->setToolTip(disabledPatformMessageOverride); + } + } + else + { + connect(platformCheckBox.data(), &QCheckBox::stateChanged, this, &PlatformSelectionWidget::OnPlatformSelectionChanged); + } + } + } + + void PlatformSelectionWidget::SetSelectedPlatforms( + const AzFramework::PlatformFlags& selectedPlatforms, + const AzFramework::PlatformFlags& partiallySelectedPlatforms) + { + m_selectedPlatforms = AzFramework::PlatformFlags::Platform_NONE; + m_partiallySelectedPlatforms = AzFramework::PlatformFlags::Platform_NONE; + for (int checkBoxIndex = 0; checkBoxIndex < m_platformCheckBoxes.size(); ++checkBoxIndex) + { + AzFramework::PlatformFlags checkBoxPlatform = m_platformList[checkBoxIndex]; + bool isSelected = (checkBoxPlatform & selectedPlatforms) != AzFramework::PlatformFlags::Platform_NONE; + m_platformCheckBoxes[checkBoxIndex]->setChecked(isSelected); + if (isSelected) + { + m_selectedPlatforms |= checkBoxPlatform; + } + + // Set the check status to Qt::PartiallyChecked when some of the selected items support the current platform + bool isPartiallySelected = (checkBoxPlatform & partiallySelectedPlatforms) != AzFramework::PlatformFlags::Platform_NONE; + if (isPartiallySelected) + { + m_platformCheckBoxes[checkBoxIndex]->setCheckState(Qt::PartiallyChecked); + m_partiallySelectedPlatforms |= checkBoxPlatform; + } + } + + emit PlatformsSelected(m_selectedPlatforms, m_partiallySelectedPlatforms); + } + + AzFramework::PlatformFlags PlatformSelectionWidget::GetSelectedPlatforms() + { + return m_selectedPlatforms; + } + + AzFramework::PlatformFlags PlatformSelectionWidget::GetPartiallySelectedPlatforms() + { + return m_partiallySelectedPlatforms; + } + + void PlatformSelectionWidget::OnPlatformSelectionChanged() + { + m_selectedPlatforms = AzFramework::PlatformFlags::Platform_NONE; + m_partiallySelectedPlatforms = AzFramework::PlatformFlags::Platform_NONE; + for (int checkBoxIndex = 0; checkBoxIndex < m_platformCheckBoxes.size(); ++checkBoxIndex) + { + if (m_platformCheckBoxes[checkBoxIndex]->checkState() == Qt::Checked) + { + m_selectedPlatforms |= m_platformList[checkBoxIndex]; + } + else if (m_platformCheckBoxes[checkBoxIndex]->checkState() == Qt::PartiallyChecked) + { + m_partiallySelectedPlatforms |= m_platformList[checkBoxIndex]; + } + } + + emit PlatformsSelected(m_selectedPlatforms, m_partiallySelectedPlatforms); + } + +} // namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.h b/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.h new file mode 100644 index 0000000000..10e47d0385 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.h @@ -0,0 +1,64 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include + +#include +#include +#include +#endif + +namespace Ui +{ + class PlatformSelectionWidget; +} + +namespace AssetBundler +{ + class PlatformSelectionWidget + : public QWidget + { + Q_OBJECT + + public: + explicit PlatformSelectionWidget(QWidget* parent); + virtual ~PlatformSelectionWidget() {} + + void Init(const AzFramework::PlatformFlags& enabledPlatforms, const QString& disabledPatformMessageOverride = ""); + + void SetSelectedPlatforms( + const AzFramework::PlatformFlags& selectedPlatforms, + const AzFramework::PlatformFlags& partiallySelectedPlatforms); + + AzFramework::PlatformFlags GetSelectedPlatforms(); + AzFramework::PlatformFlags GetPartiallySelectedPlatforms(); + + Q_SIGNALS: + void PlatformsSelected(AzFramework::PlatformFlags selectedPlatforms, AzFramework::PlatformFlags partiallySelectedPlatforms); + + private: + void OnPlatformSelectionChanged(); + + QSharedPointer m_ui; + AZStd::unique_ptr m_platformHelper; + + QVector> m_platformCheckBoxes; + AZStd::vector m_platformList; + + AzFramework::PlatformFlags m_selectedPlatforms; + AzFramework::PlatformFlags m_partiallySelectedPlatforms; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.ui b/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.ui new file mode 100644 index 0000000000..d2ecb61e64 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/PlatformSelectionWidget.ui @@ -0,0 +1,49 @@ + + + PlatformSelectionWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Platforms: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + + diff --git a/Code/Tools/AssetBundler/source/ui/RulesTabWidget.cpp b/Code/Tools/AssetBundler/source/ui/RulesTabWidget.cpp new file mode 100644 index 0000000000..81eb5f3b61 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/RulesTabWidget.cpp @@ -0,0 +1,457 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +namespace AssetBundler +{ + RulesTabWidget::RulesTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager) + : AssetBundlerTabWidget(parent, guiApplicationManager) + { + m_ui.reset(new Ui::RulesTabWidget); + m_ui->setupUi(this); + + m_ui->mainVerticalLayout->setContentsMargins(MarginSize, MarginSize, MarginSize, MarginSize); + + m_fileTableModel.reset(new RulesFileTableModel); + m_ui->fileTableView->setModel(m_fileTableModel.data()); + + // Table View of all Rules files + m_fileTableFilterModel.reset(new AssetBundlerFileTableFilterModel( + this, + m_fileTableModel->GetFileNameColumnIndex(), + m_fileTableModel->GetTimeStampColumnIndex())); + + m_fileTableFilterModel->setSourceModel(m_fileTableModel.data()); + m_ui->fileTableView->setModel(m_fileTableFilterModel.data()); + connect(m_ui->fileFilteredSearchWidget, + &AzQtComponents::FilteredSearchWidget::TextFilterChanged, + m_fileTableFilterModel.data(), + static_cast(&AssetBundlerFileTableFilterModel::FilterChanged)); + + connect(m_ui->fileTableView->selectionModel(), + &QItemSelectionModel::selectionChanged, + this, + &RulesTabWidget::FileSelectionChanged); + + m_ui->fileTableView->setIndentation(0); + + // New File Button + connect(m_ui->createNewFileButton, &QPushButton::clicked, this, &RulesTabWidget::OnNewFileButtonPressed); + + // Run Rule Button + m_ui->runRuleButton->setEnabled(false); + connect(m_ui->runRuleButton, &QPushButton::clicked, this, &RulesTabWidget::OnRunRuleButtonPressed); + + // Add Comparison Step button + connect(m_ui->addComparisonStepButton, &QPushButton::clicked, this, &RulesTabWidget::AddNewComparisonStep); + + SetModelDataSource(); + } + + bool RulesTabWidget::HasUnsavedChanges() + { + return m_fileTableModel->HasUnsavedChanges(); + } + + void RulesTabWidget::Reload() + { + m_fileTableModel->Reload( + AzToolsFramework::AssetFileInfoListComparison::GetComparisonRulesFileExtension(), + m_watchedFolders, + m_watchedFiles); + FileSelectionChanged(); + } + + bool RulesTabWidget::SaveCurrentSelection() + { + return m_fileTableModel->Save(m_selectedFileTableIndex); + } + + bool RulesTabWidget::SaveAll() + { + return m_fileTableModel->SaveAll(); + } + + void RulesTabWidget::SetModelDataSource() + { + // Remove the current watched folders and files + m_guiApplicationManager->RemoveWatchedPaths(m_watchedFolders + m_watchedFiles); + + // Set the new watched folder for the model + m_watchedFolders.clear(); + m_watchedFiles.clear(); + m_watchedFolders.insert(m_guiApplicationManager->GetRulesFolder().c_str()); + ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType::RulesFileType); + + m_guiApplicationManager->AddWatchedPaths(m_watchedFolders + m_watchedFiles); + } + + AzQtComponents::TableView* RulesTabWidget::GetFileTableView() + { + return m_ui->fileTableView; + } + + QModelIndex RulesTabWidget::GetSelectedFileTableIndex() + { + return m_selectedFileTableIndex; + } + + AssetBundlerAbstractFileTableModel* RulesTabWidget::GetFileTableModel() + { + return m_fileTableModel.get(); + } + + void RulesTabWidget::SetActiveProjectLabel(const QString& labelText) + { + m_ui->activeProjectLabel->setText(labelText); + } + + void RulesTabWidget::ApplyConfig() + { + const GUIApplicationManager::Config& config = m_guiApplicationManager->GetConfig(); + m_ui->fileTableFrame->setFixedWidth(config.fileTableWidth); + m_ui->fileTableView->header()->resizeSection(RulesFileTableModel::Column::ColumnFileName, config.fileNameColumnWidth); + } + + + void RulesTabWidget::FileSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/) + { + if (m_ui->fileTableView->selectionModel()->selectedRows().size() == 0) + { + m_selectedFileTableIndex = QModelIndex(); + m_selectedComparisonRules = nullptr; + m_ui->runRuleButton->setEnabled(false); + m_ui->addComparisonStepButton->setEnabled(false); + m_ui->rulesFileAbsolutePathLabel->clear(); + RemoveAllComparisonDataCards(); + + return; + } + + m_ui->runRuleButton->setEnabled(true); + m_ui->addComparisonStepButton->setEnabled(true); + + m_selectedFileTableIndex = m_fileTableFilterModel->mapToSource(m_ui->fileTableView->selectionModel()->selectedRows()[0]); + m_selectedComparisonRules = m_fileTableModel->GetComparisonSteps(m_selectedFileTableIndex); + + m_ui->rulesFileAbsolutePathLabel->setText(m_fileTableModel->GetFileAbsolutePath(m_selectedFileTableIndex).c_str()); + + RebuildComparisonDataCardList(); + } + + void RulesTabWidget::OnNewFileButtonPressed() + { + AZStd::string absoluteFilePath = NewFileDialog::OSNewFileDialog( + this, + AzToolsFramework::AssetFileInfoListComparison::GetComparisonRulesFileExtension(), + "Comparison Rules", + m_guiApplicationManager->GetRulesFolder()); + + if (absoluteFilePath.empty()) + { + // User canceled out of the dialog + return; + } + + AZStd::vector createdFile = m_fileTableModel->CreateNewFiles(absoluteFilePath); + if (!createdFile.empty()) + { + AddScanPathToAssetBundlerSettings(AssetBundlingFileType::RulesFileType, createdFile.at(0)); + } + } + + void RulesTabWidget::OnRunRuleButtonPressed() + { + using namespace AzToolsFramework; + + // Determine which platforms all of the input Asset List files have in common + AzFramework::PlatformFlags commonPlatforms = AzFramework::PlatformFlags::AllNamedPlatforms; + for (const AssetFileInfoListComparison::ComparisonData& comparisonStep : m_selectedComparisonRules->GetComparisonList()) + { + if (!comparisonStep.m_cachedFirstInputPath.empty()) + { + commonPlatforms = commonPlatforms & GetPlatformsOnDiskForPlatformSpecificFile(comparisonStep.m_cachedFirstInputPath); + } + + if (!comparisonStep.m_cachedSecondInputPath.empty()) + { + commonPlatforms = commonPlatforms & GetPlatformsOnDiskForPlatformSpecificFile(comparisonStep.m_cachedSecondInputPath); + } + } + + if (commonPlatforms == AzFramework::PlatformFlags::Platform_NONE) + { + AZ_Error("AssetBundler", false, "Unable to run Rule: Input Asset List files have no platforms in common."); + return; + } + + // Prompt the user to select an output path and the platforms to run the rule on + NewFileDialog runRuleDialog = NewFileDialog( + this, + "Run Rule", + QString(m_guiApplicationManager->GetAssetListsFolder().c_str()), + AzToolsFramework::AssetSeedManager::GetAssetListFileExtension(), + QString(tr("Asset List (*.%1)")).arg(AzToolsFramework::AssetSeedManager::GetAssetListFileExtension()), + commonPlatforms, + true); + + auto dialogResponse = runRuleDialog.exec(); + if (dialogResponse == QDialog::DialogCode::Rejected) + { + // User canceled the operation + return; + } + + AZStd::vector outputFilePaths; + bool hasFileGenerationErrors = false; + + AZStd::fixed_vector selectedPlatformNames = + AzFramework::PlatformHelper::GetPlatforms(runRuleDialog.GetPlatformFlags()); + for (const AZStd::string& platformName : selectedPlatformNames) + { + // We do not want to modify the original Rules file, as we do not save Asset List file paths to disk + AssetFileInfoListComparison currentFileCopy = *m_selectedComparisonRules.get(); + + //Update the first and second input values with any non-token Asset List file paths that have been set, + size_t numComparisonSteps = currentFileCopy.GetNumComparisonSteps(); + for (size_t comparisonStepIndex = 0; comparisonStepIndex < numComparisonSteps; ++comparisonStepIndex) + { + AssetFileInfoListComparison::ComparisonData comparisonStep = currentFileCopy.GetComparisonList()[comparisonStepIndex]; + if (comparisonStep.m_firstInput.empty()) + { + if (comparisonStep.m_cachedFirstInputPath.empty()) + { + AZ_Error("AssetBundler", false, + "Unable to run Rule: Comparison Step #%u has no specified first input.", comparisonStepIndex); + return; + } + + FilePath firstInput = FilePath(comparisonStep.m_cachedFirstInputPath, platformName); + currentFileCopy.SetFirstInput(comparisonStepIndex, firstInput.AbsolutePath()); + } + + if (comparisonStep.m_comparisonType != AssetFileInfoListComparison::ComparisonType::FilePattern + && comparisonStep.m_secondInput.empty()) + { + if (comparisonStep.m_cachedSecondInputPath.empty()) + { + AZ_Error("AssetBundler", false, + "Unable to run Rule: Comparison Step #%u has no specified second input.", comparisonStepIndex); + return; + } + + FilePath secondInput = FilePath(comparisonStep.m_cachedSecondInputPath, platformName); + currentFileCopy.SetSecondInput(comparisonStepIndex, secondInput.AbsolutePath()); + } + } + + // Set the output location of the Asset List file that will be generated + FilePath finalOutputPath = FilePath(runRuleDialog.GetAbsoluteFilePath(), platformName); + currentFileCopy.SetOutput(numComparisonSteps - 1, finalOutputPath.AbsolutePath()); + + //Run the Rule + auto compareOutcome = currentFileCopy.CompareAndSaveResults(); + if (compareOutcome.IsSuccess()) + { + outputFilePaths.emplace_back(finalOutputPath.AbsolutePath()); + } + else + { + hasFileGenerationErrors = true; + AZ_Error("AssetBundler", false, compareOutcome.GetError().c_str()); + } + } + + // Add created files to the file watcher + for (const AZStd::string& absolutePath : outputFilePaths) + { + AddScanPathToAssetBundlerSettings(AssetBundlingFileType::AssetListFileType, absolutePath); + } + + // The watched files list was updated after the files were created, so we need to force-reload them + m_guiApplicationManager->UpdateFiles(AssetBundlingFileType::AssetListFileType, outputFilePaths); + + NewFileDialog::FileGenerationResultMessageBox(this, outputFilePaths, hasFileGenerationErrors); + } + + void RulesTabWidget::MarkFileChanged() + { + m_fileTableModel->MarkFileChanged(m_selectedFileTableIndex); + } + + void RulesTabWidget::RebuildComparisonDataCardList() + { + RemoveAllComparisonDataCards(); + PopulateComparisonDataCardList(); + } + + void RulesTabWidget::PopulateComparisonDataCardList() + { + if (!m_selectedComparisonRules) + { + return; + } + + for (int index = 0; index < m_selectedComparisonRules->GetComparisonList().size(); ++index) + { + CreateComparisonDataCard(m_selectedComparisonRules, static_cast(index)); + } + } + + void RulesTabWidget::CreateComparisonDataCard( + AZStd::shared_ptr comparisonList, + size_t comparisonDataIndex) + { + ComparisonDataCard* comparisonDataCard = new ComparisonDataCard( + comparisonList, + comparisonDataIndex, + m_guiApplicationManager->GetAssetListsFolder()); + comparisonDataCard->setTitle(tr("Step %1").arg(static_cast(comparisonDataIndex) + 1)); + m_ui->comparisonDataListLayout->addWidget(comparisonDataCard); + m_comparisonDataCardList.push_back(comparisonDataCard); + + ComparisonDataWidget* comparisonDataWidget = comparisonDataCard->GetComparisonDataWidget(); + connect(comparisonDataCard, + &ComparisonDataCard::comparisonDataCardContextMenuRequested, + this, + &RulesTabWidget::OnComparisonDataCardContextMenuRequested); + connect(comparisonDataWidget, &ComparisonDataWidget::comparisonDataChanged, this, &RulesTabWidget::MarkFileChanged); + connect(comparisonDataWidget, + &ComparisonDataWidget::comparisonDataTokenNameChanged, + this, + &RulesTabWidget::OnAnyTokenNameChanged); + + comparisonDataCard->show(); + } + + void RulesTabWidget::RemoveAllComparisonDataCards() + { + m_comparisonDataCardList.clear(); + + while (!m_ui->comparisonDataListLayout->isEmpty()) + { + QLayoutItem* item = m_ui->comparisonDataListLayout->takeAt(0); + item->widget()->hide(); + delete item; + } + } + + void RulesTabWidget::AddNewComparisonStep() + { + if (!m_selectedComparisonRules) + { + return; + } + + if (!m_selectedComparisonRules->AddComparisonStep(AzToolsFramework::AssetFileInfoListComparison::ComparisonData())) + { + return; + } + + CreateComparisonDataCard(m_selectedComparisonRules, m_selectedComparisonRules->GetComparisonList().size() - 1); + MarkFileChanged(); + } + + void RulesTabWidget::RemoveComparisonStep(size_t comparisonDataIndex) + { + if (!m_selectedComparisonRules) + { + return; + } + + if (m_selectedComparisonRules->RemoveComparisonStep(comparisonDataIndex)) + { + MarkFileChanged(); + RebuildComparisonDataCardList(); + } + } + + void RulesTabWidget::MoveComparisonStep(size_t startingIndex, size_t destinationIndex) + { + if (!m_selectedComparisonRules) + { + return; + } + + if (m_selectedComparisonRules->MoveComparisonStep(startingIndex, destinationIndex)) + { + MarkFileChanged(); + RebuildComparisonDataCardList(); + } + } + + void RulesTabWidget::OnAnyTokenNameChanged(size_t comparisonDataIndex) + { + if (comparisonDataIndex >= m_comparisonDataCardList.size() - 1) + { + return; + } + + for (size_t i = comparisonDataIndex + 1; i < m_comparisonDataCardList.size(); ++i) + { + m_comparisonDataCardList[i]->GetComparisonDataWidget()->UpdateListOfTokenNames(); + } + } + + void RulesTabWidget::OnComparisonDataCardContextMenuRequested(size_t comparisonDataIndex, const QPoint& position) + { + if (!m_selectedComparisonRules) + { + return; + } + + QMenu menu; + + QAction* moveUpAction = new QAction(tr("Move Up"), this); + moveUpAction->setEnabled(comparisonDataIndex > 0); + connect(moveUpAction, &QAction::triggered, this, [=]() { MoveComparisonStep(comparisonDataIndex, comparisonDataIndex - 1); }); + menu.addAction(moveUpAction); + + QAction* moveDownAction = new QAction(tr("Move Down"), this); + moveDownAction->setEnabled(comparisonDataIndex < m_selectedComparisonRules->GetNumComparisonSteps() - 1); + connect(moveDownAction, &QAction::triggered, this, [=]() { MoveComparisonStep(comparisonDataIndex, comparisonDataIndex + 2); }); + menu.addAction(moveDownAction); + + QAction* separator = new QAction(this); + separator->setSeparator(true); + menu.addAction(separator); + + QAction* deleteAction = new QAction(tr("Remove Comparison Step"), this); + connect(deleteAction, &QAction::triggered, this, [=]() { RemoveComparisonStep(comparisonDataIndex); }); + menu.addAction(deleteAction); + + menu.exec(position); + } + +} // namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/RulesTabWidget.h b/Code/Tools/AssetBundler/source/ui/RulesTabWidget.h new file mode 100644 index 0000000000..a48bd47617 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/RulesTabWidget.h @@ -0,0 +1,124 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include + +#include + +#include +#include +#include +#include +#include +#endif + +namespace Ui +{ + class RulesTabWidget; +} + +class QItemSelection; + +namespace AzToolsFramework +{ + class AssetFileInfoListComparison; +} + +namespace AssetBundler +{ + class GUIApplicationManager; + + class RulesFileTableModel; + + class ComparisonDataCard; + + class ComparisonDataWidget; + + class RulesTabWidget + : public AssetBundlerTabWidget + { + Q_OBJECT + + public: + explicit RulesTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager); + virtual ~RulesTabWidget() {} + + QString GetTabTitle() override { return tr("Rules"); } + + QString GetFileTypeDisplayName() override { return tr("Rules file"); } + + AssetBundlingFileType GetFileType() override { return AssetBundlingFileType::RulesFileType; } + + bool HasUnsavedChanges() override; + + void Reload() override; + + bool SaveCurrentSelection() override; + + bool SaveAll() override; + + void SetModelDataSource() override; + + AzQtComponents::TableView* GetFileTableView() override; + + QModelIndex GetSelectedFileTableIndex() override; + + AssetBundlerAbstractFileTableModel* GetFileTableModel() override; + + void SetActiveProjectLabel(const QString& labelText) override; + + void ApplyConfig() override; + + void FileSelectionChanged( + const QItemSelection& /*selected*/ = QItemSelection(), + const QItemSelection& /*deselected*/ = QItemSelection()) override; + + private: + void OnNewFileButtonPressed(); + + void OnRunRuleButtonPressed(); + + void MarkFileChanged(); + + void RebuildComparisonDataCardList(); + + void PopulateComparisonDataCardList(); + + void CreateComparisonDataCard( + AZStd::shared_ptr comparisonList, + size_t comparisonDataIndex); + + void RemoveAllComparisonDataCards(); + + void AddNewComparisonStep(); + + void RemoveComparisonStep(size_t comparisonDataIndex); + + void MoveComparisonStep(size_t startingIndex, size_t destinationIndex); + + void OnAnyTokenNameChanged(size_t comparisonDataIndex); + + QSharedPointer m_ui; + + QSharedPointer m_fileTableModel; + QModelIndex m_selectedFileTableIndex; + AZStd::shared_ptr m_selectedComparisonRules; + + AZStd::vector m_comparisonDataCardList; + + private slots: + void OnComparisonDataCardContextMenuRequested(size_t comparisonDataIndex, const QPoint& position); + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/RulesTabWidget.ui b/Code/Tools/AssetBundler/source/ui/RulesTabWidget.ui new file mode 100644 index 0000000000..f7eec0a796 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/RulesTabWidget.ui @@ -0,0 +1,312 @@ + + + RulesTabWidget + + + + 0 + 0 + 1180 + 728 + + + + Rules Tab Widget + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Run Selected Rule + + + true + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Rules + + + + + + + + + + Filter by file name + + + + + + + 5 + + + 5 + + + + + + Create new Rules file + + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Comparison Steps + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 5 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Add Step + + + + + + + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 0 + 0 + 573 + 614 + + + + + 0 + 0 + + + + + 12 + + + 10 + + + 10 + + + 10 + + + 0 + + + + + + + + Qt::Vertical + + + + 40 + 20 + + + + + + + + + + + + + + + + + + AzQtComponents::TableView + QTreeView +
AzQtComponents/Components/Widgets/TableView.h
+ 1 +
+ + AzQtComponents::FilteredSearchWidget + QTreeView +
AzQtComponents/Components/FilteredSearchWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/SeedTabWidget.cpp b/Code/Tools/AssetBundler/source/ui/SeedTabWidget.cpp new file mode 100644 index 0000000000..26e700a170 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/SeedTabWidget.cpp @@ -0,0 +1,495 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +const char GenerateAssetListFilesDialogName[] = "Generate Asset List Files"; + +const int CheckBoxTableIndentationSize = 2; // when the indentation is 0, the checkboxes are too close to the edge + +namespace AssetBundler +{ + SeedTabWidget::SeedTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager, const QString& assetBundlingDirectory) + : AssetBundlerTabWidget(parent, guiApplicationManager) + , m_fileTableModel(new SeedListFileTableModel(this)) + , m_seedListContentsModel(new SeedListTableModel()) + { + AZ_UNUSED(assetBundlingDirectory); + + m_ui.reset(new Ui::SeedTabWidget); + m_ui->setupUi(this); + + m_ui->mainVerticalLayout->setContentsMargins(MarginSize, MarginSize, MarginSize, MarginSize); + + AZ::Debug::TraceMessageBus::Handler::BusConnect(); + + // File view of all Seed List Files + m_fileTableFilterModel.reset(new AssetBundlerFileTableFilterModel( + this, + m_fileTableModel->GetFileNameColumnIndex(), + m_fileTableModel->GetTimeStampColumnIndex())); + + m_fileTableFilterModel->setSourceModel(m_fileTableModel.data()); + m_ui->fileTableView->setModel(m_fileTableFilterModel.data()); + connect(m_ui->fileFilteredSearchWidget, + &AzQtComponents::FilteredSearchWidget::TextFilterChanged, + m_fileTableFilterModel.data(), + static_cast(&AssetBundlerFileTableFilterModel::FilterChanged)); + + connect(m_ui->fileTableView->selectionModel(), + &QItemSelectionModel::selectionChanged, + this, + &SeedTabWidget::FileSelectionChanged); + + m_ui->fileTableView->setIndentation(CheckBoxTableIndentationSize); + + // New File Button + connect(m_ui->createNewSeedListButton, &QPushButton::clicked, this, &SeedTabWidget::OnNewFileButtonPressed); + + // Select Default Seed Lists + connect(m_ui->selectDefaultSeedListsCheckBox, &QCheckBox::clicked, this, &SeedTabWidget::OnSelectDefaultSeedListsCheckBoxChanged); + + // Generate Asset Lists Button + SetGenerateAssetListsButtonEnabled(false); + connect(m_ui->generateAssetListsButton, &QPushButton::clicked, this, &SeedTabWidget::OnGenerateAssetListsButtonPressed); + + // Table that displays the contents of a Seed List File + m_seedListContentsFilterModel.reset(new AssetBundlerFileTableFilterModel(this, SeedListTableModel::Column::ColumnRelativePath)); + + m_seedListContentsFilterModel->setSourceModel(m_seedListContentsModel.data()); + m_ui->seedFileContentsTable->setModel(m_seedListContentsFilterModel.data()); + connect(m_ui->seedListContentsFilteredSearchWidget, + &AzQtComponents::FilteredSearchWidget::TextFilterChanged, + m_seedListContentsFilterModel.data(), + static_cast(&AssetBundlerFileTableFilterModel::FilterChanged)); + + m_ui->seedFileContentsTable->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_ui->seedFileContentsTable, + &QTreeView::customContextMenuRequested, + this, + &SeedTabWidget::OnSeedListContentsTableContextMenuRequested); + + m_ui->seedFileContentsTable->setIndentation(0); + + // Edit All Platforms + connect(m_ui->editAllSeedsButton, &QPushButton::clicked, this, &SeedTabWidget::OnEditAllButtonPressed); + + // Add Seed + connect(m_ui->addSeedButton, &QPushButton::clicked, this, &SeedTabWidget::OnAddSeedButtonPressed); + + SetModelDataSource(); + } + + SeedTabWidget::~SeedTabWidget() + { + AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); + } + + bool SeedTabWidget::HasUnsavedChanges() + { + return m_fileTableModel->HasUnsavedChanges(); + } + + void SeedTabWidget::Reload() + { + // Reload all the seed list files + m_fileTableModel->Reload( + AzToolsFramework::AssetSeedManager::GetSeedFileExtension(), + m_watchedFolders, + m_watchedFiles, + m_filePathToGemNameMap); + + // Update the selected row + FileSelectionChanged(); + } + + bool SeedTabWidget::SaveCurrentSelection() + { + return m_fileTableModel->Save(m_selectedFileTableIndex); + } + + bool SeedTabWidget::SaveAll() + { + return m_fileTableModel->SaveAll(); + } + + void SeedTabWidget::SetModelDataSource() + { + // Remove the current watched folders and files + m_guiApplicationManager->RemoveWatchedPaths(m_watchedFolders + m_watchedFiles); + + // Set the new watched folders for the model + m_watchedFolders.clear(); + m_watchedFolders.insert(m_guiApplicationManager->GetSeedListsFolder().c_str()); + + // Get the list of default Seed List files + m_filePathToGemNameMap = AssetBundler::GetDefaultSeedListFiles( + AZStd::string_view{ AZ::Utils::GetEnginePath() }, + m_guiApplicationManager->GetCurrentProjectName(), + m_guiApplicationManager->GetGemInfoList(), m_guiApplicationManager->GetEnabledPlatforms()); + + // Get the list of default Seeds that are not stored in a Seed List file on-disk + AZStd::vector defaultSeeds = + GetDefaultSeeds(AZ::Utils::GetProjectPath(), m_guiApplicationManager->GetCurrentProjectName()); + m_fileTableModel->AddDefaultSeedsToInMemoryList( + defaultSeeds, + m_guiApplicationManager->GetCurrentProjectName().c_str(), + m_guiApplicationManager->GetEnabledPlatforms()); + + // Set the new watched filess for the model + m_watchedFiles.clear(); + for (const auto& it : m_filePathToGemNameMap) + { + m_watchedFiles.insert(it.first.c_str()); + } + + ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType::SeedListFileType); + m_guiApplicationManager->AddWatchedPaths(m_watchedFolders + m_watchedFiles); + } + + AzQtComponents::TableView* SeedTabWidget::GetFileTableView() + { + return m_ui->fileTableView; + } + + QModelIndex SeedTabWidget::GetSelectedFileTableIndex() + { + return m_selectedFileTableIndex; + } + + AssetBundlerAbstractFileTableModel* SeedTabWidget::GetFileTableModel() + { + return m_fileTableModel.get(); + } + + void SeedTabWidget::SetActiveProjectLabel(const QString& labelText) + { + m_ui->activeProjectLabel->setText(labelText); + } + + void SeedTabWidget::ApplyConfig() + { + const GUIApplicationManager::Config& config = m_guiApplicationManager->GetConfig(); + + m_ui->fileTableFrame->setFixedWidth(config.fileTableWidth); + m_ui->fileTableView->header()->resizeSection(SeedListFileTableModel::Column::ColumnFileName, config.seedListFileNameColumnWidth); + m_ui->fileTableView->header()->resizeSection(SeedListFileTableModel::Column::ColumnCheckBox, config.checkBoxColumnWidth); + m_ui->fileTableView->header()->resizeSection(SeedListFileTableModel::Column::ColumnProject, config.projectNameColumnWidth); + + m_ui->seedFileContentsTable->header()->resizeSection( + SeedListTableModel::Column::ColumnRelativePath, + config.seedListContentsNameColumnWidth); + } + + void SeedTabWidget::UncheckSelectDefaultSeedListsCheckBox() + { + m_ui->selectDefaultSeedListsCheckBox->setChecked(false); + } + + void SeedTabWidget::SetGenerateAssetListsButtonEnabled(bool isEnabled) + { + m_ui->generateAssetListsButton->setEnabled(isEnabled); + } + + bool SeedTabWidget::OnPreError( + const char* /*window*/, + const char* /*fileName*/, + int /*line*/, + const char* /*func*/, + const char* /*message*/) + { + m_hasWarningsOrErrors = true; + return false; + } + + bool SeedTabWidget::OnPreWarning( + const char* /*window*/, + const char* /*fileName*/, + int /*line*/, + const char* /*func*/, + const char* /*message*/) + { + m_hasWarningsOrErrors = true; + return false; + } + + void SeedTabWidget::FileSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/) + { + if (m_ui->fileTableView->selectionModel()->selectedRows().size() == 0) + { + // Set selected index to an invalid value + m_selectedFileTableIndex = QModelIndex(); + m_ui->seedListFileAbsolutePathLabel->clear(); + return; + } + + m_selectedFileTableIndex = m_fileTableFilterModel->mapToSource(m_ui->fileTableView->selectionModel()->currentIndex()); + + m_seedListContentsModel = m_fileTableModel->GetSeedListFileContents(m_selectedFileTableIndex); + m_seedListContentsFilterModel->setSourceModel(m_seedListContentsModel.data()); + + m_ui->seedListFileAbsolutePathLabel->setText(m_fileTableModel->GetFileAbsolutePath(m_selectedFileTableIndex).c_str()); + } + + void SeedTabWidget::OnNewFileButtonPressed() + { + AZStd::string absoluteFilePath = NewFileDialog::OSNewFileDialog( + this, + AzToolsFramework::AssetSeedManager::GetSeedFileExtension(), + "Seed List", + m_guiApplicationManager->GetSeedListsFolder()); + + if (absoluteFilePath.empty()) + { + // User canceled out of the file dialog + return; + } + + AZStd::vector createdFiles = m_fileTableModel->CreateNewFiles( + absoluteFilePath, + AzFramework::PlatformFlags::Platform_NONE, + QString(m_guiApplicationManager->GetCurrentProjectName().c_str())); + + if (!createdFiles.empty()) + { + AddScanPathToAssetBundlerSettings(AssetBundlingFileType::SeedListFileType, createdFiles.at(0)); + } + } + + void SeedTabWidget::OnSelectDefaultSeedListsCheckBoxChanged() + { + m_fileTableModel->SelectDefaultSeedLists(m_ui->selectDefaultSeedListsCheckBox->isChecked()); + } + + void SeedTabWidget::OnGenerateAssetListsButtonPressed() + { + m_generateAssetListsDialog.reset( + new NewFileDialog( + this, + GenerateAssetListFilesDialogName, + QString(m_guiApplicationManager->GetAssetListsFolder().c_str()), + AzToolsFramework::AssetSeedManager::GetAssetListFileExtension(), + QString(tr("Asset List (*.%1)")).arg(AzToolsFramework::AssetSeedManager::GetAssetListFileExtension()), + m_guiApplicationManager->GetEnabledPlatforms())); + auto dialogResponse = m_generateAssetListsDialog->exec(); + if (dialogResponse == QDialog::DialogCode::Rejected) + { + // User canceled the operation + return; + } + + m_hasWarningsOrErrors = false; + auto createdFiles = m_fileTableModel->GenerateAssetLists( + m_generateAssetListsDialog->GetAbsoluteFilePath(), + m_generateAssetListsDialog->GetPlatformFlags()); + + // Warnings will not prevent the generation of Asset List files, we must track them separately + NewFileDialog::FileGenerationResultMessageBox(this, createdFiles, m_hasWarningsOrErrors); + + if (createdFiles.empty()) + { + // Error has already been thrown + return; + } + + // Add created files to the file watcher + for (const AZStd::string& absolutePath : createdFiles) + { + AddScanPathToAssetBundlerSettings(AssetBundlingFileType::AssetListFileType, absolutePath); + } + + // The watched files list was updated after the files were created, so we need to force-reload them + m_guiApplicationManager->UpdateFiles(AssetBundlingFileType::AssetListFileType, createdFiles); + } + + void SeedTabWidget::OnEditSeedButtonPressed() + { + if (!m_selectedFileTableIndex.isValid()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot perform Edit Seed operation: No Seed List File is selected"); + return; + } + + // Get the current platforms of the selected Seed so we can display them as already checked + QModelIndex currentSeedIndex = + m_seedListContentsFilterModel->mapToSource(m_ui->seedFileContentsTable->selectionModel()->currentIndex()); + auto getPlatformOutcome = m_seedListContentsModel->GetSeedPlatforms(currentSeedIndex); + if (!getPlatformOutcome.IsSuccess()) + { + // Error has already been thrown + return; + } + + // Create and display the Edit Seed dialog + m_editSeedDialog.reset(new EditSeedDialog(this, m_guiApplicationManager->GetEnabledPlatforms(), getPlatformOutcome.GetValue())); + auto dialogResponse = m_editSeedDialog->exec(); + if (dialogResponse == QDialog::DialogCode::Rejected) + { + // User canceled the operation + return; + } + + // Set the data in the model + m_fileTableModel->SetSeedPlatforms(m_selectedFileTableIndex, currentSeedIndex, m_editSeedDialog->GetPlatformFlags()); + } + + void SeedTabWidget::OnEditAllButtonPressed() + { + if (!m_selectedFileTableIndex.isValid()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot perform Edit All operation: No Seed List File is selected"); + return; + } + + // Get the platforms of all the seeds so we can display them as already checked or partially checked + AzFramework::PlatformFlags selectedPlatformFlags = AzFramework::PlatformFlags::AllNamedPlatforms; + AzFramework::PlatformFlags partiallySelectedPlatformFlags = AzFramework::PlatformFlags::Platform_NONE; + QMap indexToPlatformFlagsMap; + for (int row = 0; row < m_seedListContentsModel->rowCount(); ++row) + { + QModelIndex currentSeedIndex = m_seedListContentsModel->index(row, 0); + auto getPlatformOutcome = m_seedListContentsModel->GetSeedPlatforms(currentSeedIndex); + if (!getPlatformOutcome.IsSuccess()) + { + // Error has already been thrown + return; + } + + indexToPlatformFlagsMap[currentSeedIndex] = getPlatformOutcome.TakeValue(); + selectedPlatformFlags &= indexToPlatformFlagsMap[currentSeedIndex]; + partiallySelectedPlatformFlags |= selectedPlatformFlags ^ indexToPlatformFlagsMap[currentSeedIndex]; + } + + // Create and display the Edit Seed dialog + m_editSeedDialog.reset(new EditSeedDialog( + this, + m_guiApplicationManager->GetEnabledPlatforms(), + selectedPlatformFlags, + partiallySelectedPlatformFlags)); + + auto dialogResponse = m_editSeedDialog->exec(); + if (dialogResponse == QDialog::DialogCode::Rejected) + { + // User canceled the operation + return; + } + + // Set the data in the model + for (int row = 0; row < m_seedListContentsModel->rowCount(); ++row) + { + QModelIndex currentSeedIndex = m_seedListContentsModel->index(row, 0); + AzFramework::PlatformFlags checkedPlatforms = m_editSeedDialog->GetPlatformFlags(); + AzFramework::PlatformFlags partiallyCheckedPlatforms = m_editSeedDialog->GetPartiallySelectedPlatformFlags(); + // If the platform is partially checked, we want to keep its original status when saving the changes + AzFramework::PlatformFlags platformFlags = + indexToPlatformFlagsMap[currentSeedIndex] & partiallyCheckedPlatforms | checkedPlatforms; + + m_fileTableModel->SetSeedPlatforms(m_selectedFileTableIndex, currentSeedIndex, platformFlags); + } + } + + void SeedTabWidget::OnAddSeedButtonPressed() + { + if (!m_selectedFileTableIndex.isValid()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot perform Add Seed operation: No Seed List File is selected"); + return; + } + + // Get path to the platform-specific cache folder of one of the enabled platforms + AzFramework::PlatformFlags enabledPlatforms = m_guiApplicationManager->GetEnabledPlatforms(); + AZStd::fixed_vector enabledPlatformIndices = + AzFramework::PlatformHelper::GetPlatformIndicesInterpreted(enabledPlatforms); + AZStd::string platformSpecificCachePath = + AzToolsFramework::PlatformAddressedAssetCatalog::GetCatalogRegistryPathForPlatform(enabledPlatformIndices[0]); + + // Create and display the Add Seed Dialog + m_addSeedDialog.reset(new AddSeedDialog(this, enabledPlatforms, platformSpecificCachePath)); + auto dialogResponse = m_addSeedDialog->exec(); + if (dialogResponse == QDialog::DialogCode::Rejected) + { + // User canceled the operation + return; + } + + // Set the data in the model + m_fileTableModel->AddSeed(m_selectedFileTableIndex, m_addSeedDialog->GetFileName(), m_addSeedDialog->GetPlatformFlags()); + } + + void SeedTabWidget::OnRemoveSeedButtonPressed() + { + if (!m_selectedFileTableIndex.isValid()) + { + AZ_Error(AssetBundler::AppWindowName, false, "Cannot perform Remove Seed operation: No Seed List File is selected"); + return; + } + + // Set the data in the model + QModelIndex currentSeedIndex = + m_seedListContentsFilterModel->mapToSource(m_ui->seedFileContentsTable->selectionModel()->currentIndex()); + m_fileTableModel->RemoveSeed(m_selectedFileTableIndex, currentSeedIndex); + } + + void SeedTabWidget::OnSeedListContentsTableContextMenuRequested(const QPoint& pos) + { + if (!m_selectedFileTableIndex.isValid()) + { + return; + } + + QMenu* contextMenu = new QMenu(this); + contextMenu->setToolTipsVisible(true); + + QAction* action = contextMenu->addAction(tr("Edit Platforms")); + connect(action, &QAction::triggered, this, &SeedTabWidget::OnEditSeedButtonPressed); + action->setToolTip(tr("Change what platforms are referenced when generating an Asset List file.")); + + contextMenu->addSeparator(); + + action = contextMenu->addAction(tr("Add Seed")); + connect(action, &QAction::triggered, this, &SeedTabWidget::OnAddSeedButtonPressed); + action->setToolTip(tr("Add a new Seed to the Seed List file.")); + + action = contextMenu->addAction(tr("Remove Seed")); + connect(action, &QAction::triggered, this, &SeedTabWidget::OnRemoveSeedButtonPressed); + action->setToolTip(tr("Removes the Seed from the Seed List file.")); + + contextMenu->exec(m_ui->seedFileContentsTable->mapToGlobal(pos)); + delete contextMenu; + } + +} //namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/ui/SeedTabWidget.h b/Code/Tools/AssetBundler/source/ui/SeedTabWidget.h new file mode 100644 index 0000000000..784b8edd80 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/SeedTabWidget.h @@ -0,0 +1,131 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#endif + +namespace Ui +{ + class SeedTabWidget; +} + +class QFileSystemModel; +class QStringListModel; + +namespace AssetBundler +{ + class GUIApplicationManager; + + class SeedListFileTableModel; + class SeedListTableModel; + + class NewFileDialog; + class EditSeedDialog; + class AddSeedDialog; + + class SeedTabWidget + : public AssetBundlerTabWidget + , public AZ::Debug::TraceMessageBus::Handler + { + Q_OBJECT + + public: + explicit SeedTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager, const QString& assetBundlingDirectory); + virtual ~SeedTabWidget(); + + QString GetTabTitle() override { return tr("Seeds"); } + + QString GetFileTypeDisplayName() override { return tr("Seed List file"); } + + AssetBundlingFileType GetFileType() override { return AssetBundlingFileType::SeedListFileType; } + + bool HasUnsavedChanges() override; + + void Reload() override; + + bool SaveCurrentSelection() override; + + bool SaveAll() override; + + void SetModelDataSource() override; + + AzQtComponents::TableView* GetFileTableView() override; + + QModelIndex GetSelectedFileTableIndex() override; + + AssetBundlerAbstractFileTableModel* GetFileTableModel() override; + + void SetActiveProjectLabel(const QString& labelText) override; + + void ApplyConfig() override; + + void FileSelectionChanged( + const QItemSelection& /*selected*/ = QItemSelection(), + const QItemSelection& /*deselected*/ = QItemSelection()) override; + + void UncheckSelectDefaultSeedListsCheckBox(); + + void SetGenerateAssetListsButtonEnabled(bool isEnabled); + + ///////////////////////////////////////////////////////// + // TraceMessageBus overrides + bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override; + bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override; + ///////////////////////////////////////////////////////// + + private: + + void OnNewFileButtonPressed(); + + void OnSelectDefaultSeedListsCheckBoxChanged(); + + void OnGenerateAssetListsButtonPressed(); + + void OnEditSeedButtonPressed(); + void OnEditAllButtonPressed(); + + void OnAddSeedButtonPressed(); + void OnRemoveSeedButtonPressed(); + + void OnSeedListContentsTableContextMenuRequested(const QPoint& pos); + + QSharedPointer m_ui; + QDir m_assetBundlingFolder; + + QSharedPointer m_fileTableModel; + QModelIndex m_selectedFileTableIndex; + + QSharedPointer m_generateAssetListsDialog; + + QSharedPointer m_seedListContentsFilterModel; + QSharedPointer m_seedListContentsModel; + + QSharedPointer m_editSeedDialog; + QSharedPointer m_addSeedDialog; + + bool m_hasWarningsOrErrors = false; + }; +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/ui/SeedTabWidget.ui b/Code/Tools/AssetBundler/source/ui/SeedTabWidget.ui new file mode 100644 index 0000000000..b32072696f --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/SeedTabWidget.ui @@ -0,0 +1,297 @@ + + + SeedTabWidget + + + + 0 + 0 + 813 + 673 + + + + Seed Tab Widget + + + + + + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Generate Asset Lists + + + true + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Seed List files + + + + + + + + + + Filter by file name + + + + + + + 5 + + + 5 + + + + + + Create new Seed List file + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Default Seed Lists + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Product Assets + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 5 + + + + + Filter by file name + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Edit All + + + + + + + + Add Asset + + + + + + + + + + + + + + + + + + AzQtComponents::TableView + QTreeView +
AzQtComponents/Components/Widgets/TableView.h
+ 1 +
+ + AzQtComponents::FilteredSearchWidget + QTreeView +
AzQtComponents/Components/FilteredSearchWidget.h
+ 1 +
+
+ + +
diff --git a/Code/Tools/AssetBundler/source/ui/style/AssetBundler-Icon-256x256@x2.ico b/Code/Tools/AssetBundler/source/ui/style/AssetBundler-Icon-256x256@x2.ico new file mode 100644 index 0000000000..ffbf974130 --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/style/AssetBundler-Icon-256x256@x2.ico @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:690a47a0e2ff4c41ce23ad0bc5dd5bd525e03676a26d3367726beaa96babf207 +size 138199 diff --git a/Code/Tools/AssetBundler/source/ui/style/AssetBundler.qrc b/Code/Tools/AssetBundler/source/ui/style/AssetBundler.qrc new file mode 100644 index 0000000000..65ad7f11cd --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/style/AssetBundler.qrc @@ -0,0 +1,7 @@ + + + AssetBundler.qss + AssetBundlerConfig.ini + AssetBundler-Icon-256x256@x2.ico + + \ No newline at end of file diff --git a/Code/Tools/AssetBundler/source/ui/style/AssetBundler.qss b/Code/Tools/AssetBundler/source/ui/style/AssetBundler.qss new file mode 100644 index 0000000000..8603bbbb1b --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/style/AssetBundler.qss @@ -0,0 +1,173 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +/************** General (MainWindow) **************/ + +QTabWidget:pane { + border: none; +} + +QLabel#activeProjectLabel { + font-size: 18px; + font-family: "Amazon Ember Light"; + margin-bottom: 5px; +} + +QTreeView#logTableView { + border: 1px solid #1B1B1B; + margin-left: 10px; + margin-right: 10px; + margin-bottom: 10px; +} + +QTreeView#logTableView QHeaderView::section { + background-color: #1B1B1B; +} + +/************** General (Tabs) **************/ + +QFrame#fileTableFrame, +QFrame#fileContentsFrame { + border: 1px solid #1B1B1B; +} + +QFrame#fileTableFrame { + margin-right: 10px; +} + +QFrame#fileTableHeaderFrame, +QFrame#fileContentsHeaderFrame, +QFrame#fileTableHeaderFrame QLabel, +QFrame#fileContentsHeaderFrame QLabel{ + background-color: #1B1B1B; +} + +QFrame#fileTableHeaderFrame QLabel, +QFrame#fileContentsHeaderFrame QLabel{ + background-color: #1B1B1B; + margin-left: 5px; +} + +QTabWidget QTreeView QHeaderView::section { + background-color: rgb(77, 77, 77); +} + +QWidget#PlatformSelectionWidget QLabel#platformSelectionLabel { + margin-right: 10px; +} + +QDialog#NewFileDialog QPushButton#browseFileButton, +QDialog#NewFileDialog QPushButton#createFileButton, +QDialog#NewFileDialog QPushButton#cancelButton { + margin-left: 10px; + margin-right: 10px; +} + +/************** Seeds Tab **************/ + +QWidget#SeedTabWidget QPushButton#generateAssetListsButton, +QWidget#SeedTabWidget QPushButton#browseFileButton, +QWidget#SeedTabWidget QPushButton#cancelButton, +QWidget#SeedTabWidget QPushButton#addSeedButton, +QWidget#SeedTabWidget QPushButton#applyChangesButton { + margin-left: 10px; + margin-right: 10px; +} + +QCheckBox#selectDefaultSeedListsCheckBox { + margin: 5px; +} + +QWidget#seedListContentsFilteredSearchWidget { + margin-left: 5px; +} + +QDialog QFrame#inputValuesFrame { + border: none; + margin: 10px; + padding: 10px; +} + +QDialog QFrame#lineFrame { + border: none; + margin-top: 10px; + margin-bottom: 10px; +} + +QDialog QFrame#inputValuesFrame, +QDialog QFrame#lineFrame, +QDialog#AddSeedDialog QLabel, +QDialog#AddSeedDialog QCheckBox, +QDialog#EditSeedDialog QLabel, +QDialog#EditSeedDialog QCheckBox, +QDialog#NewFileDialog QLabel, +QDialog#NewFileDialog QCheckBox { + background-color: #555555; +} + +/************** Asset List Tab **************/ + +QLabel#assetListContentsLabel { + margin-right: 10px; +} + +QWidget#fileFilteredSearchWidget, +QWidget#assetListContentsFilteredSearchWidget { + margin-left: 5px; + margin-right: 5px; +} + +QPushButton#generateBundleButton { + margin-left: 10px; + margin-right: 10px; +} + +/************** Generate Bundles Modal **************/ + +QFrame#bundleSettingsFrame { + border: none; + margin-bottom: 10px; +} + +QFrame#outputBundleLocationFrame, +QFrame#bundleSettingsFileFrame { + border: none; + margin: 10px; +} + +QFrame#bundleSettingsFrame, +QFrame#outputBundleLocationFrame, +QFrame#bundleSettingsFileFrame, +QFrame#bundleSettingsFrame QLabel { + background-color: #555555; +} + +QWidget#GenerateBundlesModal QPushButton { + margin-left: 10px; + margin-right: 10px; +} + +/************** Rules Tab **************/ + +QPushButton#runRuleButton, +QPushButton#addComparisonStepButton { + margin-left: 10px; + margin-right: 10px; +} + +QScrollArea#comparisonDataList { + border: none; +} + +QFrame#comparisonDataFrame { + padding: 10px; +} diff --git a/Code/Tools/AssetBundler/source/ui/style/AssetBundlerConfig.ini b/Code/Tools/AssetBundler/source/ui/style/AssetBundlerConfig.ini new file mode 100644 index 0000000000..876ceea40e --- /dev/null +++ b/Code/Tools/AssetBundler/source/ui/style/AssetBundlerConfig.ini @@ -0,0 +1,19 @@ +[ErrorLogDetails] +LogTypeColumnWidth=180 +LogSourceColumnWidth=130 + +[GeneralFileTableDetails] +FileTableWidth=450 +FileNameColumnWidth=250 + +[SeedsTabDetails] +CheckBoxColumnWidth=22 +SeedListFileNameColumnWidth=150 +ProjectNameColumnWidth=120 +SeedListContentsNameColumnWidth=400 + +[AssetListsTabDetails] +AssetListFileNameColumnWidth=210 +AssetListPlatformColumnWidth=70 +ProductAssetNameColumnWidth=220 +ProductAssetRelativePathColumnWidth=300 \ No newline at end of file diff --git a/Code/Tools/AssetBundler/source/utils/GUIApplicationManager.cpp b/Code/Tools/AssetBundler/source/utils/GUIApplicationManager.cpp new file mode 100644 index 0000000000..e4dd5edba7 --- /dev/null +++ b/Code/Tools/AssetBundler/source/utils/GUIApplicationManager.cpp @@ -0,0 +1,401 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +// Forward declare platform-specific functions +namespace Platform +{ + /// On Windows this will return the setting for our custom title bar + /// On other platforms this will return the setting for using platform default + /// This ensures that functions like Exit, Maximize, and Minimize appear in the right platform-specific style + AzQtComponents::WindowDecorationWrapper::Option GetWindowDecorationWrapperOption(); +} // namespace Platform + +const char AssetBundlingFolderName [] = "AssetBundling"; +const char SeedListsFolderName [] = "SeedLists"; +const char AssetListsFolderName [] = "AssetLists"; +const char RulesFolderName[] = "Rules"; +const char BundleSettingsFolderName [] = "BundleSettings"; +const char BundlesFolderName [] = "Bundles"; + +namespace AssetBundler +{ + + GUIApplicationManager::Config GUIApplicationManager::loadConfig(QSettings& settings) + { + using namespace AzQtComponents; + + Config config = defaultConfig(); + + // Error Log + { + ConfigHelpers::GroupGuard details(&settings, QStringLiteral("ErrorLogDetails")); + ConfigHelpers::read(settings, QStringLiteral("LogTypeColumnWidth"), config.logTypeColumnWidth); + ConfigHelpers::read(settings, QStringLiteral("LogSourceColumnWidth"), config.logSourceColumnWidth); + } + + // General File Tables + { + ConfigHelpers::GroupGuard details(&settings, QStringLiteral("GeneralFileTableDetails")); + ConfigHelpers::read(settings, QStringLiteral("FileTableWidth"), config.fileTableWidth); + ConfigHelpers::read(settings, QStringLiteral("FileNameColumnWidth"), config.fileNameColumnWidth); + } + + // Seeds Tab + { + ConfigHelpers::GroupGuard details(&settings, QStringLiteral("SeedsTabDetails")); + ConfigHelpers::read(settings, QStringLiteral("CheckBoxColumnWidth"), config.checkBoxColumnWidth); + ConfigHelpers::read(settings, QStringLiteral("SeedListFileNameColumnWidth"), config.seedListFileNameColumnWidth); + ConfigHelpers::read(settings, QStringLiteral("ProjectNameColumnWidth"), config.projectNameColumnWidth); + ConfigHelpers::read(settings, QStringLiteral("SeedListContentsNameColumnWidth"), config.seedListContentsNameColumnWidth); + } + + // Asset Lists Tab + { + ConfigHelpers::GroupGuard details(&settings, QStringLiteral("AssetListsTabDetails")); + ConfigHelpers::read(settings, QStringLiteral("AssetListFileNameColumnWidth"), config.assetListFileNameColumnWidth); + ConfigHelpers::read(settings, QStringLiteral("AssetListPlatformColumnWidth"), config.assetListPlatformColumnWidth); + ConfigHelpers::read(settings, QStringLiteral("ProductAssetNameColumnWidth"), config.productAssetNameColumnWidth); + ConfigHelpers::read( + settings, QStringLiteral("ProductAssetRelativePathColumnWidth"), config.productAssetRelativePathColumnWidth); + } + + return config; + } + + GUIApplicationManager::Config GUIApplicationManager::defaultConfig() + { + // These are used if the values can't be read from AssetBundlerConfig.ini. + Config config; + + config.logTypeColumnWidth = 150; + config.logSourceColumnWidth = 150; + + config.fileTableWidth = 250; + config.fileNameColumnWidth = 150; + + config.checkBoxColumnWidth = 150; + config.seedListFileNameColumnWidth = 150; + config.projectNameColumnWidth = 150; + config.seedListContentsNameColumnWidth = 150; + + config.assetListFileNameColumnWidth = 150; + config.assetListPlatformColumnWidth = 150; + config.productAssetNameColumnWidth = 150; + config.productAssetRelativePathColumnWidth = 150; + + return config; + } + + GUIApplicationManager::GUIApplicationManager(int* argc, char*** argv, QObject* parent) + : ApplicationManager(argc, argv, parent) + { + } + + GUIApplicationManager::~GUIApplicationManager() + { + // Reset this before DestroyApplication, BusDisconnect needs to happen before Application::Stop() destroys the allocators. + m_platformCatalogManager.reset(); + } + + bool GUIApplicationManager::Init() + { + m_isInitializing = true; + // Initialize Asset Bundler Batch + ApplicationManager::Init(); + + AZ::IO::FixedMaxPath engineRoot = GetEngineRoot(); + + if (engineRoot.empty()) + { + // Error has already been thrown + return false; + } + + // Determine the name of the current project + auto projectOutcome = AssetBundler::GetCurrentProjectName(); + if (!projectOutcome.IsSuccess()) + { + AZ_Error("AssetBundler", false, projectOutcome.GetError().c_str()); + return false; + } + m_currentProjectName = projectOutcome.GetValue(); + + // Set up paths to the Project folder, Project Cache folder, and determine enabled platforms + auto pathOutcome = InitializePaths(); + if (!pathOutcome.IsSuccess()) + { + AZ_Error("AssetBundler", false, pathOutcome.GetError().c_str()); + return false; + } + + // Set up platform-specific Asset Catalogs + m_platformCatalogManager = AZStd::make_unique(); + + // Define some application-level settings + QApplication::setOrganizationName("O3DE"); + QApplication::setApplicationName("Asset Bundler"); + + QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); + + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + + m_isInitializing = false; + + // Create the actual Qt Application + m_qApp.reset(new QApplication(*GetArgC(), *GetArgV())); + + // Create the Main Window + m_mainWindow.reset(new MainWindow(this)); + + return true; + } + + bool GUIApplicationManager::Run() + { + // Set up the Style Manager + AzQtComponents::StyleManager styleManager(qApp); + styleManager.initialize(qApp, GetEngineRoot()); + + AZ::IO::FixedMaxPath engineRoot(GetEngineRoot()); + QDir engineRootDir(engineRoot.c_str()); + AzQtComponents::StyleManager::addSearchPaths( + QStringLiteral("style"), + engineRootDir.filePath(QStringLiteral("Code/Tools/AssetBundler/source/ui/style")), + QStringLiteral(":/AssetBundler/style"), + engineRoot); + AzQtComponents::StyleManager::setStyleSheet(m_mainWindow.data(), QStringLiteral("style:AssetBundler.qss")); + + AzQtComponents::ConfigHelpers::loadConfig( + &m_fileWatcher, + &m_config, + QStringLiteral("style:AssetBundlerConfig.ini"), + this, + std::bind(&GUIApplicationManager::ApplyConfig, this)); + ApplyConfig(); + + qApp->setWindowIcon(QIcon("style:AssetBundler-Icon-256x256@x2.ico")); + + // Set up the Main Window + auto wrapper = new AzQtComponents::WindowDecorationWrapper(Platform::GetWindowDecorationWrapperOption()); + wrapper->setGuest(m_mainWindow.data()); + m_mainWindow->Activate(); + wrapper->show(); + m_mainWindow->show(); + + qApp->setQuitOnLastWindowClosed(true); + + // Run the application + return qApp->exec(); + } + + void GUIApplicationManager::AddWatchedPath(const QString& folderPath) + { + m_fileWatcher.addPath(folderPath); + } + + void GUIApplicationManager::AddWatchedPaths(const QSet& folderPaths) + { + m_fileWatcher.addPaths(folderPaths.values()); + } + + void GUIApplicationManager::RemoveWatchedPath(const QString& path) + { + m_fileWatcher.removePath(path); + } + + void GUIApplicationManager::RemoveWatchedPaths(const QSet& paths) + { + // Check whether the list is empty to get rid of the warning from Qt + if (paths.isEmpty()) + { + return; + } + + m_fileWatcher.removePaths(paths.values()); + } + + bool GUIApplicationManager::OnPreError( + const char* /*window*/, + const char* /*fileName*/, + int /*line*/, + const char* /*func*/, + const char* message) + { + // We want to display errors during initialization, then let the MainWindow handle errors during runtime + if (m_isInitializing) + { + // These are fatal initialization errors, and the application will shut down after the user closes the message box + m_qApp.reset(new QApplication(*GetArgC(), *GetArgV())); + QMessageBox errorMessageBox; + errorMessageBox.setWindowTitle("Asset Bundler"); + errorMessageBox.setText(message); + errorMessageBox.setStandardButtons(QMessageBox::Ok); + errorMessageBox.setDefaultButton(QMessageBox::Ok); + errorMessageBox.exec(); + + return true; + } + + return false; + } + + bool GUIApplicationManager::OnPreWarning( + const char* /*window*/, + const char* /*fileName*/, + int /*line*/, + const char* /*func*/, + const char* /*message*/) + { + // Don't handle warnings, let the MainWindow print them + return false; + } + + + bool GUIApplicationManager::OnPrintf(const char* /*window*/, const char* /*message*/) + { + // This is disabled during initialization to prevent a lot of message spam printed to the CLI that gets generated on setup + return m_isInitializing; + } + + AZ::Outcome GUIApplicationManager::InitializePaths() + { + // Calculate the path to the Cache for the current project + auto pathOutcome = AssetBundler::GetProjectCacheFolderPath(); + if (!pathOutcome.IsSuccess()) + { + return AZ::Failure(pathOutcome.GetError()); + } + + m_currentProjectCacheFolder = pathOutcome.GetValue().String(); + + // Calculate the path to the current project folder + pathOutcome = AssetBundler::GetProjectFolderPath(); + if (!pathOutcome.IsSuccess()) + { + return AZ::Failure(pathOutcome.GetError()); + } + + m_currentProjectFolder = pathOutcome.GetValue().String(); + + // Generate the AssetBundling folder inside the current project + AzFramework::StringFunc::Path::ConstructFull(m_currentProjectFolder.c_str(), AssetBundlingFolderName, m_assetBundlingFolder); + + // Seed Lists folder + AzFramework::StringFunc::Path::ConstructFull(m_assetBundlingFolder.c_str(), SeedListsFolderName, m_seedListsFolder); + AZ::Outcome createPathOutcome = AssetBundler::MakePath(m_seedListsFolder); + if (!createPathOutcome.IsSuccess()) + { + return createPathOutcome; + } + + // Asset Lists folder + AzFramework::StringFunc::Path::ConstructFull(m_assetBundlingFolder.c_str(), AssetListsFolderName, m_assetListsFolder); + createPathOutcome = AssetBundler::MakePath(m_assetListsFolder); + if (!createPathOutcome.IsSuccess()) + { + return createPathOutcome; + } + + // Rules folder + AzFramework::StringFunc::Path::ConstructFull(m_assetBundlingFolder.c_str(), RulesFolderName, m_rulesFolder); + createPathOutcome = AssetBundler::MakePath(m_rulesFolder); + if (!createPathOutcome.IsSuccess()) + { + return createPathOutcome; + } + + // Bundle Settings Folder + AzFramework::StringFunc::Path::ConstructFull(m_assetBundlingFolder.c_str(), BundleSettingsFolderName, m_bundleSettingsFolder); + createPathOutcome = AssetBundler::MakePath(m_bundleSettingsFolder); + if (!createPathOutcome.IsSuccess()) + { + return createPathOutcome; + } + + // Bundles Folder + AzFramework::StringFunc::Path::ConstructFull(m_assetBundlingFolder.c_str(), BundlesFolderName, m_bundlesFolder); + createPathOutcome = AssetBundler::MakePath(m_bundlesFolder); + if (!createPathOutcome.IsSuccess()) + { + return createPathOutcome; + } + + // Determine the enabled platforms + const char* appRoot = nullptr; + AzFramework::ApplicationRequests::Bus::BroadcastResult(appRoot, &AzFramework::ApplicationRequests::GetAppRoot); + m_enabledPlatforms = GetEnabledPlatformFlags(GetEngineRoot(), appRoot, AZ::Utils::GetProjectPath().c_str()); + + // Determine which Gems are enabled for the current project + if (!AzFramework::GetGemsInfo(m_gemInfoList, *m_settingsRegistry)) + { + return AZ::Failure(AZStd::string::format("Failed to read Gems for project: %s\n", m_currentProjectName.c_str())); + } + + QObject::connect(&m_fileWatcher, &QFileSystemWatcher::directoryChanged, this, &GUIApplicationManager::DirectoryChanged); + QObject::connect(&m_fileWatcher, &QFileSystemWatcher::fileChanged, this, &GUIApplicationManager::FileChanged); + + return AZ::Success(); + } + + void GUIApplicationManager::DirectoryChanged(const QString& directory) + { + UpdateTab(directory.toUtf8().data()); + } + + void GUIApplicationManager::FileChanged(const QString& path) + { + // FileChanged will only be called when engine or gem seed files are updated + // Otherwilse DirectoryChanged should be triggered + AZStd::string extension; + AzFramework::StringFunc::Path::GetExtension(path.toUtf8().data(), extension); + extension = extension.starts_with(".") ? extension.substr(1) : extension; + if (extension == AzToolsFramework::AssetSeedManager::GetSeedFileExtension()) + { + UpdateTab(GetSeedListsFolder()); + } + + // Many applications save an open file by writing a new file and then deleting the old one + // Add the file path back if it has been removed from the watcher file list + if (!m_fileWatcher.files().contains(path)) + { + m_fileWatcher.addPath(path); + } + } + + void GUIApplicationManager::ApplyConfig() + { + m_mainWindow->ApplyConfig(); + } + +} // namespace AssetBundler + +#include diff --git a/Code/Tools/AssetBundler/source/utils/GUIApplicationManager.h b/Code/Tools/AssetBundler/source/utils/GUIApplicationManager.h new file mode 100644 index 0000000000..e81607d4a8 --- /dev/null +++ b/Code/Tools/AssetBundler/source/utils/GUIApplicationManager.h @@ -0,0 +1,164 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#endif + +namespace AssetBundler +{ + enum AssetBundlingFileType : int + { + SeedListFileType = 0, + AssetListFileType, + BundleSettingsFileType, + BundleFileType, + RulesFileType, + NumBundlingFileTypes + }; + + class MainWindow; + + class GUIApplicationManager + : public ApplicationManager + { + Q_OBJECT + + public: + + struct Config + { + // These default values are used if the values can't be read from AssetBundlerConfig.ini, + // and the call to defaultConfig fails. + + // Error Log + int logTypeColumnWidth = -1; + int logSourceColumnWidth = -1; + + // General File Tables + int fileTableWidth = -1; + int fileNameColumnWidth = -1; + + // Seeds Tab + int checkBoxColumnWidth = -1; + int seedListFileNameColumnWidth = -1; + int projectNameColumnWidth = -1; + int seedListContentsNameColumnWidth = -1; + + // Asset Lists Tab + int assetListFileNameColumnWidth = -1; + int assetListPlatformColumnWidth = -1; + int productAssetNameColumnWidth = -1; + int productAssetRelativePathColumnWidth = -1; + }; + + /*! + * Loads the button config data from a settings object. + */ + static Config loadConfig(QSettings& settings); + + /*! + * Returns default button config data. + */ + static Config defaultConfig(); + + explicit GUIApplicationManager(int* argc, char*** argv, QObject* parent = 0); + virtual ~GUIApplicationManager(); + + bool Init() override; + + bool Run() override; + + AZStd::string GetCurrentProjectFolder() { return m_currentProjectFolder; } + AZStd::string GetAssetBundlingFolder() { return m_assetBundlingFolder; } + AZStd::string GetSeedListsFolder() { return m_seedListsFolder; } + AZStd::string GetAssetListsFolder() { return m_assetListsFolder; } + AZStd::string GetRulesFolder() { return m_rulesFolder; } + AZStd::string GetBundleSettingsFolder() { return m_bundleSettingsFolder; } + AZStd::string GetBundlesFolder() { return m_bundlesFolder; } + AZStd::string GetCurrentProjectCacheFolder() { return m_currentProjectCacheFolder; } + + AzFramework::PlatformFlags GetEnabledPlatforms() { return m_enabledPlatforms; } + + void AddWatchedPath(const QString& path); + void AddWatchedPaths(const QSet& paths); + void RemoveWatchedPath(const QString& path); + void RemoveWatchedPaths(const QSet& paths); + + //////////////////////////////////////////////////////////////////////////////////////////// + // Override the ApplicationManager TraceMessageBus methods so that messages go through MainWindow and not the CLI + + bool OnPreError(const char* window, const char* /*fileName*/, int /*line*/, const char* /*func*/, const char* message) override; + bool OnPreWarning(const char* /*window*/, const char* /*fileName*/, int /*line*/, const char* /*func*/, const char* /*message*/) override; + bool OnPrintf(const char* /*window*/, const char* /*message*/) override; + //////////////////////////////////////////////////////////////////////////////////////////// + + const Config& GetConfig() { return m_config; } + + Q_SIGNALS: + void ShowWindow(); + void UpdateTab(const AZStd::string& directory); + void UpdateFiles(AssetBundlingFileType fileType, const AZStd::vector& absoluteFilePaths); + + protected Q_SLOTS: + void DirectoryChanged(const QString& directory); + void FileChanged(const QString& path); + void ApplyConfig(); + + private: + /** + * Generates directory information for all paths used in this tool + * @return void on success, error message on failure + */ + AZ::Outcome InitializePaths(); + + QSharedPointer m_qApp; + + Config m_config; + + QSharedPointer m_mainWindow; + + AZStd::string m_currentProjectFolder; + AZStd::string m_assetBundlingFolder; + AZStd::string m_seedListsFolder; + AZStd::string m_assetListsFolder; + AZStd::string m_rulesFolder; + AZStd::string m_bundleSettingsFolder; + AZStd::string m_bundlesFolder; + AZStd::string m_currentProjectCacheFolder; + + AzFramework::PlatformFlags m_enabledPlatforms = AzFramework::PlatformFlags::Platform_NONE; + + AZStd::unique_ptr m_platformCatalogManager; + + bool m_isInitializing = false; + + QFileSystemWatcher m_fileWatcher; + }; + +} // namespace AssetBundler diff --git a/Code/Tools/AssetBundler/source/utils/applicationManager.cpp b/Code/Tools/AssetBundler/source/utils/applicationManager.cpp index bb4fee2ceb..ccf5427771 100644 --- a/Code/Tools/AssetBundler/source/utils/applicationManager.cpp +++ b/Code/Tools/AssetBundler/source/utils/applicationManager.cpp @@ -45,8 +45,9 @@ namespace AssetBundler { const char compareVariablePrefix = '$'; - ApplicationManager::ApplicationManager(int* argc, char*** argv) - : AzToolsFramework::ToolsApplication(argc, argv) + ApplicationManager::ApplicationManager(int* argc, char*** argv, QObject* parent) + : QObject(parent) + , AzToolsFramework::ToolsApplication(argc, argv) { } @@ -55,7 +56,7 @@ namespace AssetBundler DestroyApplication(); } - void ApplicationManager::Init() + bool ApplicationManager::Init() { AZ::Debug::TraceMessageBus::Handler::BusConnect(); Start(AzFramework::Application::Descriptor()); @@ -74,6 +75,7 @@ namespace AssetBundler // There is no need to update the UserSettings file, so we can avoid a race condition by disabling save on shutdown AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize); + return true; } void ApplicationManager::DestroyApplication() @@ -372,6 +374,13 @@ namespace AssetBundler { using namespace AzToolsFramework; + auto validateArgsOutcome = ValidateInputArgs(parser, m_allSeedsArgs); + if (!validateArgsOutcome.IsSuccess()) + { + OutputHelpSeeds(); + return AZ::Failure(validateArgsOutcome.TakeError()); + } + SeedsParams params; params.m_ignoreFileCase = parser->HasSwitch(IgnoreFileCaseFlag); @@ -462,6 +471,13 @@ namespace AssetBundler AZ::Outcome ApplicationManager::ParseAssetListsCommandData(const AZ::CommandLine* parser) { + auto validateArgsOutcome = ValidateInputArgs(parser, m_allAssetListsArgs); + if (!validateArgsOutcome.IsSuccess()) + { + OutputHelpAssetLists(); + return AZ::Failure(validateArgsOutcome.TakeError()); + } + AssetListsParams params; // Read in Platform arg @@ -525,6 +541,13 @@ namespace AssetBundler AZ::Outcome ApplicationManager::ParseComparisonRulesCommandData(const AZ::CommandLine* parser) { + auto validateArgsOutcome = ValidateInputArgs(parser, m_allComparisonRulesArgs); + if (!validateArgsOutcome.IsSuccess()) + { + OutputHelpComparisonRules(); + return AZ::Failure(validateArgsOutcome.TakeError()); + } + ScopedTraceHandler traceHandler; ComparisonRulesParams params; @@ -907,6 +930,13 @@ namespace AssetBundler AZ::Outcome ApplicationManager::ParseCompareCommandData(const AZ::CommandLine* parser) { + auto validateArgsOutcome = ValidateInputArgs(parser, m_allCompareArgs); + if (!validateArgsOutcome.IsSuccess()) + { + OutputHelpCompare(); + return AZ::Failure(validateArgsOutcome.TakeError()); + } + ComparisonParams params; // Read in Platform arg @@ -998,6 +1028,13 @@ namespace AssetBundler AZ::Outcome ApplicationManager::ParseBundleSettingsCommandData(const AZ::CommandLine* parser) { + auto validateArgsOutcome = ValidateInputArgs(parser, m_allBundleSettingsArgs); + if (!validateArgsOutcome.IsSuccess()) + { + OutputHelpBundleSettings(); + return AZ::Failure(validateArgsOutcome.TakeError()); + } + BundleSettingsParams params; // Read in Platform arg @@ -1202,6 +1239,13 @@ namespace AssetBundler AZ::Outcome ApplicationManager::ParseBundlesCommandData(const AZ::CommandLine* parser) { + auto validateArgsOutcome = ValidateInputArgs(parser, m_allBundlesArgs); + if (!validateArgsOutcome.IsSuccess()) + { + OutputHelpBundles(); + return AZ::Failure(validateArgsOutcome.TakeError()); + } + auto parseSettingsOutcome = ParseBundleSettingsAndOverrides(parser, BundlesCommand); if (!parseSettingsOutcome.IsSuccess()) { @@ -1213,6 +1257,14 @@ namespace AssetBundler AZ::Outcome ApplicationManager::ParseBundleSeedCommandData(const AZ::CommandLine* parser) { + + auto validateArgsOutcome = ValidateInputArgs(parser, m_allBundleSeedArgs); + if (!validateArgsOutcome.IsSuccess()) + { + OutputHelpBundleSeed(); + return AZ::Failure(validateArgsOutcome.TakeError()); + } + BundleSeedParams params; params.m_addSeedList = GetAddSeedArgList(parser); @@ -1230,6 +1282,12 @@ namespace AssetBundler AZ::Outcome ApplicationManager::ValidateInputArgs(const AZ::CommandLine* parser, const AZStd::vector& validArgList) { + constexpr AZStd::string_view ApplicationArgList = "/O3DE/AzCore/Application/ValidCommandOptions"; + AZStd::vector validApplicationArgs; + if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr) + { + settingsRegistry->GetObject(validApplicationArgs, ApplicationArgList); + } for (const auto& paramInfo : *parser) { // Skip positional arguments @@ -1247,10 +1305,18 @@ namespace AssetBundler break; } } + for (const auto& validArg : validApplicationArgs) + { + if (AZ::StringFunc::Equal(paramInfo.m_option, validArg)) + { + isValidArg = true; + break; + } + } if (!isValidArg) { - return AZ::Failure(AZStd::string::format("Unknown argument: \"--%s\" is not an unknown argument for this sub-command.", paramInfo.m_option.c_str())); + return AZ::Failure(AZStd::string::format(R"(Invalid argument: "--%s" is not a valid argument for this sub-command.)", paramInfo.m_option.c_str())); } } @@ -1335,10 +1401,10 @@ namespace AssetBundler } // If no platform was specified, defaulting to platforms specified in the asset processor config files - const char* appRoot = nullptr; - AzFramework::ApplicationRequests::Bus::BroadcastResult(appRoot, &AzFramework::ApplicationRequests::GetAppRoot); - - AzFramework::PlatformFlags platformFlags = GetEnabledPlatformFlags(GetEngineRoot(), appRoot, AZ::Utils::GetProjectPath().c_str()); + AzFramework::PlatformFlags platformFlags = GetEnabledPlatformFlags( + AZStd::string_view{ AZ::Utils::GetEnginePath() }, + AZStd::string_view{ AZ::Utils::GetEnginePath() }, + AZStd::string_view{ AZ::Utils::GetProjectPath() }); auto platformsString = AzFramework::PlatformHelper::GetCommaSeparatedPlatformList(platformFlags); AZ_TracePrintf(AppWindowName, "No platform specified, defaulting to platforms ( %s ).\n", platformsString.c_str()); @@ -1522,7 +1588,7 @@ namespace AssetBundler } } - AZStd::vector defaultSeeds = GetDefaultSeeds(GetEngineRoot(), AZ::Utils::GetProjectPath(), m_currentProjectName); + AZStd::vector defaultSeeds = GetDefaultSeeds(AZ::Utils::GetProjectPath(), m_currentProjectName); if (defaultSeeds.empty()) { // Error has already been thrown @@ -2847,3 +2913,4 @@ namespace AssetBundler return !m_showVerboseOutput; } } // namespace AssetBundler +#include diff --git a/Code/Tools/AssetBundler/source/utils/applicationManager.h b/Code/Tools/AssetBundler/source/utils/applicationManager.h index 01f180a77a..d49707f489 100644 --- a/Code/Tools/AssetBundler/source/utils/applicationManager.h +++ b/Code/Tools/AssetBundler/source/utils/applicationManager.h @@ -11,6 +11,7 @@ */ #pragma once +#if !defined(Q_MOC_RUN) #include #include #include @@ -22,7 +23,7 @@ #include #include #include - +#endif namespace AssetBundler { struct SeedsParams @@ -161,16 +162,18 @@ namespace AssetBundler }; class ApplicationManager - : public AZ::Debug::TraceMessageBus::Handler + : public QObject + , public AZ::Debug::TraceMessageBus::Handler , public AzToolsFramework::ToolsApplication { + Q_OBJECT public: - explicit ApplicationManager(int* argc, char*** argv); - ~ApplicationManager(); + explicit ApplicationManager(int* argc, char*** argv, QObject* parent = 0); + virtual ~ApplicationManager(); - void Init(); + virtual bool Init(); void DestroyApplication(); - bool Run(); + virtual bool Run(); //////////////////////////////////////////////////////////////////////////////////////////// // AzFramework::Application overrides diff --git a/Code/Tools/AssetBundler/source/utils/utils.cpp b/Code/Tools/AssetBundler/source/utils/utils.cpp index b1595f7dd8..b91dcde9e2 100644 --- a/Code/Tools/AssetBundler/source/utils/utils.cpp +++ b/Code/Tools/AssetBundler/source/utils/utils.cpp @@ -31,6 +31,7 @@ AZ_PUSH_DISABLE_WARNING(4244 4251, "-Wunknown-warning-option") #include #include #include +#include AZ_POP_DISABLE_WARNING namespace AssetBundler @@ -108,15 +109,15 @@ namespace AssetBundler const char* AssetCatalogFilename = "assetcatalog.xml"; - - const char EngineDirectoryName[] = "Engine"; + + constexpr auto EngineDirectoryName = AZ::IO::FixedMaxPath("Assets") / "Engine"; const char RestrictedDirectoryName[] = "restricted"; const char PlatformsDirectoryName[] = "Platforms"; const char GemsDirectoryName[] = "Gems"; const char GemsAssetsDirectoryName[] = "Assets"; const char GemsSeedFileName[] = "seedList"; const char EngineSeedFileName[] = "SeedAssetList"; - + namespace Internal { @@ -128,7 +129,7 @@ namespace AssetBundler AZStd::unordered_map& defaultSeedLists, AzFramework::PlatformFlags platformFlags) { - AZ::IO::FixedMaxPath engineRoot(GetEngineRoot()); + AZ::IO::FixedMaxPath engineRoot(AZ::Utils::GetEnginePath()); AZ::IO::FixedMaxPath engineRestrictedRoot = engineRoot / RestrictedDirectoryName; AZ::IO::FixedMaxPath engineLocalPath = AZ::IO::PathView(engineDirectory.LexicallyRelative(engineRoot)); @@ -154,8 +155,10 @@ namespace AssetBundler if (fileIO->Exists(platformDirectory.c_str())) { bool recurse = true; - AZ::Outcome, AZStd::string> result = AzFramework::FileFunc::FindFileList(platformDirectory.String(), - AZStd::string::format("*.%s", AzToolsFramework::AssetSeedManager::GetSeedFileExtension()).c_str(), recurse); + AZ::Outcome, AZStd::string> result = AzFramework::FileFunc::FindFileList( + platformDirectory.String(), + AZStd::string::format("*.%s", AzToolsFramework::AssetSeedManager::GetSeedFileExtension()).c_str(), + recurse); if (result.IsSuccess()) { @@ -201,17 +204,6 @@ namespace AssetBundler } } - AZ::IO::FixedMaxPath GetEngineRoot() - { - AZ::IO::FixedMaxPath engineRootPath; - if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr) - { - settingsRegistry->Get(engineRootPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder); - } - - return engineRootPath; - } - void AddPlatformIdentifier(AZStd::string& filePath, const AZStd::string& platformIdentifier) { AZStd::string fileName; @@ -243,8 +235,11 @@ namespace AssetBundler return platformFlags; } - AZStd::unordered_map GetDefaultSeedListFiles(AZStd::string_view enginePath, AZStd::string_view projectPath, - const AZStd::vector& gemInfoList, AzFramework::PlatformFlags platformFlag) + AZStd::unordered_map GetDefaultSeedListFiles( + AZStd::string_view enginePath, + AZStd::string_view projectPath, + const AZStd::vector& gemInfoList, + AzFramework::PlatformFlags platformFlag) { AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance(); AZ_Assert(fileIO, "AZ::IO::FileIOBase must be ready for use.\n"); @@ -259,11 +254,11 @@ namespace AssetBundler absoluteEngineSeedFilePath.ReplaceExtension(AzToolsFramework::AssetSeedManager::GetSeedFileExtension()); if (fileIO->Exists(absoluteEngineSeedFilePath.c_str())) { - defaultSeedLists[absoluteEngineSeedFilePath.Native()] = EngineDirectoryName; + defaultSeedLists[absoluteEngineSeedFilePath.Native()] = EngineDirectoryName.String(); } // Add Seed Lists from the Platforms directory - Internal::AddPlatformsDirectorySeeds(engineDirectory, EngineDirectoryName, defaultSeedLists, platformFlag); + Internal::AddPlatformsDirectorySeeds(engineDirectory, EngineDirectoryName.String(), defaultSeedLists, platformFlag); auto absoluteProjectDefaultSeedFilePath = AZ::IO::Path(projectPath) / EngineSeedFileName; absoluteProjectDefaultSeedFilePath.ReplaceExtension(AzToolsFramework::AssetSeedManager::GetSeedFileExtension()); @@ -276,11 +271,11 @@ namespace AssetBundler return defaultSeedLists; } - AZStd::vector GetDefaultSeeds(AZStd::string_view enginePath, AZStd::string_view projectPath, AZStd::string_view projectName) + AZStd::vector GetDefaultSeeds(AZStd::string_view projectPath, AZStd::string_view projectName) { AZStd::vector defaultSeeds; - defaultSeeds.emplace_back(GetProjectDependenciesAssetPath(enginePath, projectPath, projectName)); + defaultSeeds.emplace_back(GetProjectDependenciesAssetPath(projectPath, projectName)); return defaultSeeds; } @@ -294,34 +289,12 @@ namespace AssetBundler return projectDependenciesFilePath.LexicallyNormal(); } - AZ::IO::Path GetProjectDependenciesFileTemplate(AZStd::string_view engineRoot) - { - AZ::IO::Path projectDependenciesFileTemplate = engineRoot; - projectDependenciesFileTemplate /= DefaultProjectTemplatePath; - projectDependenciesFileTemplate /= AZStd::string::format("%s%s", ProjectName, DependenciesFileSuffix); - projectDependenciesFileTemplate.ReplaceExtension(DependenciesFileExtension); - return projectDependenciesFileTemplate.LexicallyNormal(); - } - - AZ::IO::Path GetProjectDependenciesAssetPath(AZStd::string_view enginePath, AZStd::string_view projectPath, AZStd::string_view projectName) + AZ::IO::Path GetProjectDependenciesAssetPath(AZStd::string_view projectPath, AZStd::string_view projectName) { AZ::IO::Path projectDependenciesFile = GetProjectDependenciesFile(projectPath, projectName); if (!AZ::IO::FileIOBase::GetInstance()->Exists(projectDependenciesFile.c_str())) { - AZ_TracePrintf(AssetBundler::AppWindowName, "Project dependencies file %s doesn't exist.\n", projectDependenciesFile.c_str()); - - AZ::IO::Path projectDependenciesFileTemplate = GetProjectDependenciesFileTemplate(enginePath); - if (AZ::IO::FileIOBase::GetInstance()->Copy(projectDependenciesFileTemplate.c_str(), projectDependenciesFile.c_str())) - { - AZ_TracePrintf(AssetBundler::AppWindowName, "Copied project dependencies file template %s to the current project.\n", - projectDependenciesFile.c_str()); - } - else - { - AZ_Error(AppWindowName, false, "Failed to copy project dependencies file template %s from default project" - " template to the current project.\n", projectDependenciesFileTemplate.c_str()); - return {}; - } + AZ_Error(AssetBundler::AppWindowName, false, "Project dependencies file %s doesn't exist.\n", projectDependenciesFile.c_str()); } // Turn the absolute path into a cache-relative path @@ -331,7 +304,9 @@ namespace AssetBundler return relativeProductPath; } - AZStd::unordered_map GetGemSeedListFilePathToGemNameMap(const AZStd::vector& gemInfoList, AzFramework::PlatformFlags platformFlags) + AZStd::unordered_map GetGemSeedListFilePathToGemNameMap( + const AZStd::vector& gemInfoList, + AzFramework::PlatformFlags platformFlags) { AZStd::unordered_map filePathToGemNameMap; for (const AzFramework::GemInfo& gemInfo : gemInfoList) @@ -357,7 +332,11 @@ namespace AssetBundler return filePathToGemNameMap; } - bool IsGemSeedFilePathValid(AZStd::string_view engineRoot, AZStd::string seedAbsoluteFilePath, const AZStd::vector& gemInfoList, AzFramework::PlatformFlags platformFlags) + bool IsGemSeedFilePathValid( + AZStd::string_view engineRoot, + AZStd::string seedAbsoluteFilePath, + const AZStd::vector& gemInfoList, + AzFramework::PlatformFlags platformFlags) { AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance(); AZ_Assert(fileIO, "AZ::IO::FileIOBase must be ready for use.\n"); @@ -401,7 +380,10 @@ namespace AssetBundler return false; } - AzFramework::PlatformFlags GetEnabledPlatformFlags(AZStd::string_view engineRoot, AZStd::string_view assetRoot, AZStd::string_view projectPath) + AzFramework::PlatformFlags GetEnabledPlatformFlags( + AZStd::string_view engineRoot, + AZStd::string_view assetRoot, + AZStd::string_view projectPath) { auto settingsRegistry = AZ::SettingsRegistry::Get(); if (settingsRegistry == nullptr) @@ -423,7 +405,8 @@ namespace AssetBundler } else { - AZ_Warning(AssetBundler::AppWindowName, false, "Platform Helper is not aware of the platform (%s).\n ", enabledPlatform.c_str()); + AZ_Warning(AssetBundler::AppWindowName, false, + "Platform Helper is not aware of the platform (%s).\n ", enabledPlatform.c_str()); } } @@ -489,31 +472,6 @@ namespace AssetBundler AZ::SettingsRegistryMergeUtils::FilePathKey_CacheProjectRootFolder)); } - AZ::Outcome GetPlatformNamesFromCacheFolder(AZStd::vector& platformNames) - { - AZ::Outcome projectCacheRootFolder = GetProjectCacheFolderPath(); - if (!projectCacheRootFolder) - { - return AZ::Failure(projectCacheRootFolder.TakeError()); - } - - const AZStd::string& projectCacheRootPath = projectCacheRootFolder.GetValue().Native(); - QDir projectCacheDir(QString::fromUtf8(projectCacheRootPath.c_str(), aznumeric_cast(projectCacheRootPath.size()))); - auto tempPlatformList = projectCacheDir.entryList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot); - - if (tempPlatformList.empty()) - { - return AZ::Failure(AZStd::string("Cache is empty. Please run the Open 3D Engine Asset Processor to generate a Cache and build assets.")); - } - - for (const QString& platform : tempPlatformList) - { - platformNames.push_back(AZStd::string(platform.toUtf8().data())); - } - - return AZ::Success(); - } - AZ::Outcome GetAssetCatalogFilePath() { AZ::IO::Path assetCatalogFilePath = GetPlatformSpecificCacheFolderPath(); @@ -533,11 +491,21 @@ namespace AssetBundler AZ::IO::Path platformSpecificCacheFolderPath; if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr) { - settingsRegistry->Get(platformSpecificCacheFolderPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_CacheProjectRootFolder); + settingsRegistry->Get( + platformSpecificCacheFolderPath.Native(), + AZ::SettingsRegistryMergeUtils::FilePathKey_CacheProjectRootFolder); } return platformSpecificCacheFolderPath; } + AZStd::string GenerateKeyFromAbsolutePath(const AZStd::string& absoluteFilePath) + { + AZStd::string key(absoluteFilePath); + AzFramework::StringFunc::Path::Normalize(key); + AzFramework::StringFunc::Path::StripDrive(key); + return key; + } + void ConvertToRelativePath(AZStd::string_view parentFolderPath, AZStd::string& absoluteFilePath) { absoluteFilePath = AZ::IO::PathView(absoluteFilePath).LexicallyRelative(parentFolderPath).String(); @@ -725,7 +693,8 @@ namespace AssetBundler m_errors.swap(AZStd::vector()); } - AZ::Outcome ParseComparisonType(const AZStd::string& comparisonType) + AZ::Outcome ParseComparisonType( + const AZStd::string& comparisonType) { using namespace AzToolsFramework; @@ -753,7 +722,8 @@ namespace AssetBundler } // Failure case - AZStd::string failureMessage = AZStd::string::format("Invalid Comparison Type ( %s ). Valid types are: ", comparisonType.c_str()); + AZStd::string failureMessage = AZStd::string::format( + "Invalid Comparison Type ( %s ). Valid types are: ", comparisonType.c_str()); for (size_t i = 0; i < numTypes - 1; ++i) { failureMessage.append(AZStd::string::format("%s, ", AssetFileInfoListComparison::ComparisonTypeNames[i])); @@ -762,7 +732,8 @@ namespace AssetBundler return AZ::Failure(failureMessage); } - AZ::Outcome ParseFilePatternType(const AZStd::string& filePatternType) + AZ::Outcome ParseFilePatternType( + const AZStd::string& filePatternType) { using namespace AzToolsFramework; @@ -790,7 +761,8 @@ namespace AssetBundler } // Failure case - AZStd::string failureMessage = AZStd::string::format("Invalid File Pattern Type ( %s ). Valid types are: ", filePatternType.c_str()); + AZStd::string failureMessage = AZStd::string::format( + "Invalid File Pattern Type ( %s ). Valid types are: ", filePatternType.c_str()); for (size_t i = 0; i < numTypes - 1; ++i) { failureMessage.append(AZStd::string::format("%s, ", AssetFileInfoListComparison::FilePatternTypeNames[i])); @@ -822,4 +794,26 @@ namespace AssetBundler } return false; } + + QJsonObject ReadJson(const AZStd::string& filePath) + { + QByteArray byteArray; + QFile jsonFile; + jsonFile.setFileName(filePath.c_str()); + jsonFile.open(QIODevice::ReadOnly | QIODevice::Text); + byteArray = jsonFile.readAll(); + jsonFile.close(); + + return QJsonDocument::fromJson(byteArray).object(); + } + + void SaveJson(const AZStd::string& filePath, const QJsonObject& jsonObject) + { + QFile jsonFile(filePath.c_str()); + QJsonDocument JsonDocument; + JsonDocument.setObject(jsonObject); + jsonFile.open(QFile::WriteOnly | QFile::Text | QFile::Truncate); + jsonFile.write(JsonDocument.toJson()); + jsonFile.close(); + } } diff --git a/Code/Tools/AssetBundler/source/utils/utils.h b/Code/Tools/AssetBundler/source/utils/utils.h index db6729098a..211096e07c 100644 --- a/Code/Tools/AssetBundler/source/utils/utils.h +++ b/Code/Tools/AssetBundler/source/utils/utils.h @@ -19,7 +19,9 @@ #include #include #include - +#include +#include +#include namespace AssetBundler { @@ -137,9 +139,6 @@ namespace AssetBundler bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override; }; - // Returns the engine root - AZ::IO::FixedMaxPath GetEngineRoot(); - /** * Determines the name of the currently enabled game project * @return Current Project name on success, error message on failure @@ -159,17 +158,6 @@ namespace AssetBundler */ AZ::Outcome GetProjectCacheFolderPath(); - /** - * Calculates the list of enabled platforms for the input project by reading the folder names inside the project-specific cache folder. - * If the Asset Processor has not been run yet, or has not been run since the enabled platform list inside AssetProcessorPlatformConfig.setreg - * was changed, the output of this function will be incorrect. - * - * @param projectCacheFolder The directory of a project-specific cache folder: /ProjectPath/Cache - * @param platformNames [out] The list of platforms enabled in the project - * @return void on success, error message on failure - */ - AZ::Outcome GetPlatformNamesFromCacheFolder(AZStd::vector& platformNames); - /** * Computes the absolute path to the Asset Catalog file for a specified project and platform. * With platform set as "pc" and project as "ProjectName", the path will resemble: C:/ProjectPath/Cache/pc/assetcatalog.xml @@ -192,6 +180,8 @@ namespace AssetBundler */ AZ::IO::Path GetPlatformSpecificCacheFolderPath(); + AZStd::string GenerateKeyFromAbsolutePath(const AZStd::string& absoluteFilePath); + void ConvertToRelativePath(AZStd::string_view parentFolderPath, AZStd::string& absoluteFilePath); AZ::Outcome MakePath(const AZStd::string& path); @@ -203,31 +193,43 @@ namespace AssetBundler AzFramework::PlatformFlags GetPlatformsOnDiskForPlatformSpecificFile(const AZStd::string& platformIndependentAbsolutePath); //! Returns a map of of all default Seed List files for the current game project. - AZStd::unordered_map GetDefaultSeedListFiles(AZStd::string_view enginePath, AZStd::string_view projectPath, - const AZStd::vector& gemInfoList, AzFramework::PlatformFlags platformFlags); + AZStd::unordered_map GetDefaultSeedListFiles( + AZStd::string_view enginePath, + AZStd::string_view projectPath, + const AZStd::vector& gemInfoList, + AzFramework::PlatformFlags platformFlags); //! Returns a vector of relative paths to Assets that should be included as default Seeds, but are not already in a Seed List file. - AZStd::vector GetDefaultSeeds(AZStd::string_view enginePath, AZStd::string_view projectPath, AZStd::string_view projectName); + AZStd::vector GetDefaultSeeds(AZStd::string_view projectPath, AZStd::string_view projectName); //! Returns the absolute path of {ProjectName}_Dependencies.xml AZ::IO::Path GetProjectDependenciesFile(AZStd::string_view productPath, AZStd::string_view projectName); - //! Returns the absolute path of the project dependencies file in the default project template - AZ::IO::Path GetProjectDependenciesFileTemplate(AZStd::string_view enginePath); - //! Creates the ProjectName_Dependencies.xml file if it does not exist, and adds returns the relative path to the asset in the Cache. - AZ::IO::Path GetProjectDependenciesAssetPath(AZStd::string_view enginePath, AZStd::string_view projectPath, AZStd::string_view projectName); + AZ::IO::Path GetProjectDependenciesAssetPath(AZStd::string_view projectPath, AZStd::string_view projectName); //! Returns the map from gem seed list file path to gem name - AZStd::unordered_map GetGemSeedListFilePathToGemNameMap(const AZStd::vector& gemInfoList, AzFramework::PlatformFlags platformFlags); + AZStd::unordered_map GetGemSeedListFilePathToGemNameMap( + const AZStd::vector& gemInfoList, + AzFramework::PlatformFlags platformFlags); //! Given an absolute gem seed file path determines whether the file is valid for the current game project. //! This method is for validating gem seed list files only. - bool IsGemSeedFilePathValid(AZStd::string_view enginePath, AZStd::string seedAbsoluteFilePath, const AZStd::vector& gemInfoList, AzFramework::PlatformFlags platformFlags); + bool IsGemSeedFilePathValid( + AZStd::string_view enginePath, + AZStd::string seedAbsoluteFilePath, + const AZStd::vector& gemInfoList, + AzFramework::PlatformFlags platformFlags); //! Returns platformFlags of all enabled platforms by parsing all the asset processor config files. //! Please note that the game project could be in a different location to the engine therefore we need the assetRoot param. - AzFramework::PlatformFlags GetEnabledPlatformFlags(AZStd::string_view enginePath, AZStd::string_view assetRoot, AZStd::string_view projectPath); + AzFramework::PlatformFlags GetEnabledPlatformFlags( + AZStd::string_view enginePath, + AZStd::string_view assetRoot, + AZStd::string_view projectPath); + + QJsonObject ReadJson(const AZStd::string& filePath); + void SaveJson(const AZStd::string& filePath, const QJsonObject& jsonObject); //! Filepath is a helper class that is used to find the absolute path of a file //! if the inputted file path is an absolute path than it does nothing @@ -238,7 +240,11 @@ namespace AssetBundler { public: AZ_CLASS_ALLOCATOR(FilePath, AZ::SystemAllocator, 0); - explicit FilePath(const AZStd::string& filePath, AZStd::string platformIdentifier = AZStd::string(), bool checkFileCase = false, bool ignoreFileCase = false); + explicit FilePath( + const AZStd::string& filePath, + AZStd::string platformIdentifier = AZStd::string(), + bool checkFileCase = false, + bool ignoreFileCase = false); explicit FilePath(const AZStd::string& filePath, bool checkFileCase, bool ignoreFileCase); FilePath() = default; const AZStd::string& AbsolutePath() const; @@ -278,8 +284,10 @@ namespace AssetBundler bool m_reportingError = false; }; - AZ::Outcome ParseComparisonType(const AZStd::string& comparisonType); - AZ::Outcome ParseFilePatternType(const AZStd::string& filePatternType); + AZ::Outcome ParseComparisonType( + const AZStd::string& comparisonType); + AZ::Outcome ParseFilePatternType( + const AZStd::string& filePatternType); bool LooksLikePath(const AZStd::string& inputString); bool LooksLikeWildcardPattern(const AZStd::string& inputPattern); } diff --git a/Code/Tools/AssetBundler/tests/Engine/SeedAssetList.seed b/Code/Tools/AssetBundler/tests/Assets/Engine/SeedAssetList.seed similarity index 100% rename from Code/Tools/AssetBundler/tests/Engine/SeedAssetList.seed rename to Code/Tools/AssetBundler/tests/Assets/Engine/SeedAssetList.seed diff --git a/Code/Tools/AssetBundler/tests/tests_main.cpp b/Code/Tools/AssetBundler/tests/tests_main.cpp index e1535bf0f5..9e12623b0d 100644 --- a/Code/Tools/AssetBundler/tests/tests_main.cpp +++ b/Code/Tools/AssetBundler/tests/tests_main.cpp @@ -88,7 +88,7 @@ namespace AssetBundler const char RelativeTestFolder[] = "Code/Tools/AssetBundler/tests"; const char GemsFolder[] = "Gems"; - const char EngineFolder[] = "Engine"; + constexpr auto EngineFolder = AZ::IO::FixedMaxPath("Assets") / "Engine"; const char PlatformsFolder[] = "Platforms"; const char DummyProjectFolder[] = "DummyProject"; @@ -113,14 +113,14 @@ namespace AssetBundler AZ::SettingsRegistry::Register(&m_registry); } - const char* engineRoot = nullptr; - AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot); - if (!engineRoot) + AZ::IO::FixedMaxPath engineRoot = AZ::Utils::GetEnginePath(); + if (engineRoot.empty()) { GTEST_FATAL_FAILURE_(AZStd::string::format("Unable to locate engine root.\n").c_str()); } - AzFramework::StringFunc::Path::Join(engineRoot, RelativeTestFolder, m_data->m_testEngineRoot); + + m_data->m_testEngineRoot = (engineRoot / RelativeTestFolder).LexicallyNormal().String(); m_data->m_localFileIO = aznew AZ::IO::LocalFileIO(); m_data->m_priorFileIO = AZ::IO::FileIOBase::GetInstance(); @@ -132,8 +132,8 @@ namespace AssetBundler AddGemData(m_data->m_testEngineRoot.c_str(), "GemA"); AddGemData(m_data->m_testEngineRoot.c_str(), "GemB"); - AZStd::string absoluteEngineSeedFilePath; - AzFramework::StringFunc::Path::ConstructFull(m_data->m_testEngineRoot.c_str(), EngineFolder, "SeedAssetList", AzToolsFramework::AssetSeedManager::GetSeedFileExtension(), absoluteEngineSeedFilePath, true); + auto absoluteEngineSeedFilePath = m_data->m_testEngineRoot / EngineFolder / "SeedAssetList"; + absoluteEngineSeedFilePath.ReplaceExtension(AzToolsFramework::AssetSeedManager::GetSeedFileExtension()); m_data->m_gemSeedFilePairList.emplace_back(AZStd::make_pair(absoluteEngineSeedFilePath, true)); AddGemData(m_data->m_testEngineRoot.c_str(), "GemC", false); @@ -213,7 +213,7 @@ namespace AssetBundler AZStd::unique_ptr m_application = {}; AZ::IO::FileIOBase* m_priorFileIO = nullptr; AZ::IO::FileIOBase* m_localFileIO = nullptr; - AZStd::string m_testEngineRoot; + AZ::IO::Path m_testEngineRoot; }; const int GemAIndex = 0; diff --git a/Code/Tools/AssetProcessor/Platform/Mac/assetprocessor_mac.cmake b/Code/Tools/AssetProcessor/Platform/Mac/assetprocessor_mac.cmake index e065f9a1a2..be1e85d370 100644 --- a/Code/Tools/AssetProcessor/Platform/Mac/assetprocessor_mac.cmake +++ b/Code/Tools/AssetProcessor/Platform/Mac/assetprocessor_mac.cmake @@ -9,13 +9,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -ly_add_bundle_resources( - TARGET AssetProcessor - FILES - ${CMAKE_SOURCE_DIR}/Code/Tools/RC/Config/rc/xmlfilter.txt - ${CMAKE_SOURCE_DIR}/Code/Tools/RC/Config/rc/rc.ini -) - # Set resources directory for app icons target_sources(AssetProcessor PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Platform/Mac/Images.xcassets) set_target_properties(AssetProcessor PROPERTIES diff --git a/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake b/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake index 79771a9d37..ab7a1e4a9f 100644 --- a/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake +++ b/Code/Tools/AssetProcessor/assetprocessor_gui_files.cmake @@ -31,7 +31,9 @@ set(FILES native/ui/GoToButton.h native/ui/GoToButton.cpp native/ui/GoToButton.ui - native/ui/MainWindow.h + native/ui/JobTreeViewItemDelegate.h + native/ui/JobTreeViewItemDelegate.cpp + native/ui/MainWindow.ui native/ui/MainWindow.cpp native/ui/MainWindow.ui native/ui/ProductAssetDetailsPanel.h diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.cpp b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.cpp similarity index 58% rename from Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.cpp rename to Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.cpp index 3c628d1b34..e0da06ad79 100644 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.cpp +++ b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.cpp @@ -9,18 +9,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#include "EditorDefs.h" -#include "LensFlareReferenceTree.h" +#include "JobTreeViewItemDelegate.h" -BEGIN_MESSAGE_MAP (CLensFlareReferenceTree, CXTTreeCtrl) -END_MESSAGE_MAP () - -CLensFlareReferenceTree::CLensFlareReferenceTree() +namespace AssetProcessor { -} + void JobTreeViewItemDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const + { + AzQtComponents::TableViewItemDelegate::initStyleOption(option, index); -CLensFlareReferenceTree::~CLensFlareReferenceTree() -{ + option->features &= ~(QStyleOptionViewItem::WrapText); + } } + +#include diff --git a/Code/Sandbox/Editor/Controls/TimeOfDaySlider.h b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h similarity index 55% rename from Code/Sandbox/Editor/Controls/TimeOfDaySlider.h rename to Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h index 72c4c08394..fbe45a3f75 100644 --- a/Code/Sandbox/Editor/Controls/TimeOfDaySlider.h +++ b/Code/Tools/AssetProcessor/native/ui/JobTreeViewItemDelegate.h @@ -9,26 +9,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#ifndef CRYINCLUDE_EDITOR_TIMEOFDAYSLIDER_H -#define CRYINCLUDE_EDITOR_TIMEOFDAYSLIDER_H #pragma once - #if !defined(Q_MOC_RUN) -#include +#include #endif -class TimeOfDaySlider - : public AzQtComponents::SliderInt +namespace AssetProcessor { - Q_OBJECT -public: - using AzQtComponents::SliderInt::SliderInt; + class JobTreeViewItemDelegate + : public AzQtComponents::TableViewItemDelegate + { + Q_OBJECT -protected: - QString hoverValueText(int sliderValue) const override; -}; + public: + using AzQtComponents::TableViewItemDelegate::TableViewItemDelegate; -#endif // CRYINCLUDE_EDITOR_TIMEOFDAYSLIDER_H + protected: + void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const override; + }; +} // namespace AssetProcessor diff --git a/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp b/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp index 3a874a464c..79019ab8fc 100644 --- a/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp +++ b/Code/Tools/AssetProcessor/native/ui/MainWindow.cpp @@ -32,6 +32,7 @@ #include #include "native/ui/ui_MainWindow.h" +#include "native/ui/JobTreeViewItemDelegate.h" #include "../utilities/GUIApplicationManager.h" @@ -221,6 +222,7 @@ void MainWindow::Activate() ui->jobTreeView->setModel(m_jobSortFilterProxy); ui->jobTreeView->setSortingEnabled(true); ui->jobTreeView->header()->setDefaultAlignment(Qt::AlignVCenter | Qt::AlignHCenter); + ui->jobTreeView->setItemDelegate(new AssetProcessor::JobTreeViewItemDelegate(ui->jobTreeView)); ui->jobTreeView->setToolTip(tr("Click to view Job Log")); diff --git a/Code/Tools/AssetProcessor/native/utilities/MissingDependencyScanner.cpp b/Code/Tools/AssetProcessor/native/utilities/MissingDependencyScanner.cpp index 73125fd58a..9daf97cf79 100644 --- a/Code/Tools/AssetProcessor/native/utilities/MissingDependencyScanner.cpp +++ b/Code/Tools/AssetProcessor/native/utilities/MissingDependencyScanner.cpp @@ -20,30 +20,32 @@ AZ_POP_DISABLE_WARNING #include "native/AssetDatabase/AssetDatabase.h" #include "native/assetprocessor.h" #include +#include #include #include #include #include +#include #include #include #include #include -#include namespace AssetProcessor { - const char* EngineFolder = "Engine"; + constexpr auto EngineFolder = AZ::IO::FixedMaxPath("Assets") / "Engine"; AZStd::string GetXMLDependenciesFile(const AZStd::string& fullPath, const AZStd::vector& gemInfoList, AZStd::string& tokenName) { AZ::IO::Path xmlDependenciesFileFullPath; - tokenName = EngineFolder; + tokenName = EngineFolder.String(); for (const AzFramework::GemInfo& gemElement : gemInfoList) { for (const AZ::IO::Path& absoluteSourcePath : gemElement.m_absoluteSourcePaths) { - if (AZ::StringFunc::StartsWith(fullPath, absoluteSourcePath.Native()) || AZ::StringFunc::Equal(absoluteSourcePath.Native(), fullPath)) + if (AZ::IO::PathView(fullPath).IsRelativeTo(absoluteSourcePath)) { + xmlDependenciesFileFullPath = absoluteSourcePath; xmlDependenciesFileFullPath /= AzFramework::GemInfo::GetGemAssetFolder(); xmlDependenciesFileFullPath /= AZStd::string::format("%s_Dependencies.xml", gemElement.m_gemName.c_str());; if (AZ::IO::FileIOBase::GetInstance()->Exists(xmlDependenciesFileFullPath.c_str())) @@ -57,7 +59,7 @@ namespace AssetProcessor // if we are here than either the %gemName%_Dependencies.xml file does not exists or the user inputted path is not inside a gems folder, // in both the cases we will return the engine dependencies file - xmlDependenciesFileFullPath = AZ::IO::FileIOBase::GetInstance()->GetAlias("@devroot@"); + xmlDependenciesFileFullPath = AZ::Utils::GetEnginePath(); xmlDependenciesFileFullPath /= EngineFolder; xmlDependenciesFileFullPath /= "Engine_Dependencies.xml"; diff --git a/Code/Tools/CMakeLists.txt b/Code/Tools/CMakeLists.txt index 65a1bf85ce..db5476756b 100644 --- a/Code/Tools/CMakeLists.txt +++ b/Code/Tools/CMakeLists.txt @@ -25,3 +25,4 @@ add_subdirectory(AssetBundler) add_subdirectory(GridHub) add_subdirectory(Standalone) add_subdirectory(TestImpactFramework) +add_subdirectory(ProjectManager) diff --git a/Code/CryEngine/CryFont/CMakeLists.txt b/Code/Tools/ProjectManager/CMakeLists.txt similarity index 54% rename from Code/CryEngine/CryFont/CMakeLists.txt rename to Code/Tools/ProjectManager/CMakeLists.txt index 9e2f29f7b6..e4354bac32 100644 --- a/Code/CryEngine/CryFont/CMakeLists.txt +++ b/Code/Tools/ProjectManager/CMakeLists.txt @@ -9,16 +9,33 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +if(NOT PAL_TRAIT_BUILD_HOST_TOOLS) + return() +endif() + ly_add_target( - NAME CryFont ${PAL_TRAIT_MONOLITHIC_DRIVEN_LIBRARY_TYPE} - NAMESPACE Legacy + NAME ProjectManager APPLICATION + OUTPUT_NAME o3de + NAMESPACE AZ + AUTOMOC + AUTOUIC + AUTORCC FILES_CMAKE - cryfont_files.cmake + project_manager_files.cmake + Platform/${PAL_PLATFORM_NAME}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake INCLUDE_DIRECTORIES - PRIVATE + PUBLIC . + PRIVATE + Source + BUILD_DEPENDENCIES PRIVATE - 3rdParty::freetype - Legacy::CryCommon -) + 3rdParty::Qt::Core + 3rdParty::Qt::Concurrent + 3rdParty::Qt::Widgets + AZ::AzCore + AZ::AzFramework + AZ::AzToolsFramework + AZ::AzQtComponents +) \ No newline at end of file diff --git a/Code/Sandbox/Plugins/FBXPlugin/Platform/Linux/platform_linux_files.cmake b/Code/Tools/ProjectManager/Platform/Android/PAL_android.cmake similarity index 100% rename from Code/Sandbox/Plugins/FBXPlugin/Platform/Linux/platform_linux_files.cmake rename to Code/Tools/ProjectManager/Platform/Android/PAL_android.cmake diff --git a/Code/Sandbox/Plugins/FBXPlugin/Platform/Mac/platform_mac_files.cmake b/Code/Tools/ProjectManager/Platform/Linux/PAL_linux.cmake similarity index 100% rename from Code/Sandbox/Plugins/FBXPlugin/Platform/Mac/platform_mac_files.cmake rename to Code/Tools/ProjectManager/Platform/Linux/PAL_linux.cmake diff --git a/Gems/SVOGI/CMakeLists.txt b/Code/Tools/ProjectManager/Platform/Mac/PAL_mac.cmake similarity index 95% rename from Gems/SVOGI/CMakeLists.txt rename to Code/Tools/ProjectManager/Platform/Mac/PAL_mac.cmake index 20a680bce9..4d5680a30d 100644 --- a/Gems/SVOGI/CMakeLists.txt +++ b/Code/Tools/ProjectManager/Platform/Mac/PAL_mac.cmake @@ -8,5 +8,3 @@ # remove or modify any license notices. This file is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # - -add_subdirectory(Code) diff --git a/Gems/GameEffectSystem/CMakeLists.txt b/Code/Tools/ProjectManager/Platform/Windows/PAL_windows.cmake similarity index 95% rename from Gems/GameEffectSystem/CMakeLists.txt rename to Code/Tools/ProjectManager/Platform/Windows/PAL_windows.cmake index 20a680bce9..4d5680a30d 100644 --- a/Gems/GameEffectSystem/CMakeLists.txt +++ b/Code/Tools/ProjectManager/Platform/Windows/PAL_windows.cmake @@ -8,5 +8,3 @@ # remove or modify any license notices. This file is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # - -add_subdirectory(Code) diff --git a/Code/Tools/ProjectManager/Platform/iOS/PAL_ios.cmake b/Code/Tools/ProjectManager/Platform/iOS/PAL_ios.cmake new file mode 100644 index 0000000000..4d5680a30d --- /dev/null +++ b/Code/Tools/ProjectManager/Platform/iOS/PAL_ios.cmake @@ -0,0 +1,10 @@ +# +# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +# its licensors. +# +# For complete copyright and license terms please see the LICENSE at the root of this +# distribution (the "License"). All use of this software is governed by the License, +# or, if provided, by the license below or the license accompanying this file. Do not +# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# diff --git a/Code/Tools/ProjectManager/Resources/Add.svg b/Code/Tools/ProjectManager/Resources/Add.svg new file mode 100644 index 0000000000..d2b9b2e0a6 --- /dev/null +++ b/Code/Tools/ProjectManager/Resources/Add.svg @@ -0,0 +1,4 @@ + + + + diff --git a/Code/Tools/ProjectManager/Resources/ProjectManager.qss b/Code/Tools/ProjectManager/Resources/ProjectManager.qss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Code/Tools/ProjectManager/Resources/Select_Folder.svg b/Code/Tools/ProjectManager/Resources/Select_Folder.svg new file mode 100644 index 0000000000..72dcd3385e --- /dev/null +++ b/Code/Tools/ProjectManager/Resources/Select_Folder.svg @@ -0,0 +1,4 @@ + + + + diff --git a/Code/Tools/ProjectManager/Resources/o3de_editor.ico b/Code/Tools/ProjectManager/Resources/o3de_editor.ico new file mode 100644 index 0000000000..0680ceea19 --- /dev/null +++ b/Code/Tools/ProjectManager/Resources/o3de_editor.ico @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c042fce57915fc749abc7b37de765fd697c3c4d7de045a3d44805aa0ce29901a +size 107016 diff --git a/Code/Tools/ProjectManager/Source/EngineSettings.cpp b/Code/Tools/ProjectManager/Source/EngineSettings.cpp new file mode 100644 index 0000000000..bc359637e4 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/EngineSettings.cpp @@ -0,0 +1,35 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +#include + +namespace O3DE::ProjectManager +{ + EngineSettings::EngineSettings(ProjectManagerWindow* window) + : ScreenWidget(window) + , m_ui(new Ui::EngineSettingsClass()) + { + m_ui->setupUi(this); + } + + EngineSettings::~EngineSettings() + { + } + + void EngineSettings::ConnectSlotsAndSignals() + { + // Do nothing for now + } + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/EngineSettings.h b/Code/Tools/ProjectManager/Source/EngineSettings.h new file mode 100644 index 0000000000..f90f760798 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/EngineSettings.h @@ -0,0 +1,39 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace Ui +{ + class EngineSettingsClass; +} + +namespace O3DE::ProjectManager +{ + class EngineSettings + : public ScreenWidget + { + public: + explicit EngineSettings(ProjectManagerWindow* window); + ~EngineSettings(); + + protected: + void ConnectSlotsAndSignals() override; + + private: + QScopedPointer m_ui; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/EngineSettings.ui b/Code/Tools/ProjectManager/Source/EngineSettings.ui new file mode 100644 index 0000000000..c8fda8bfd7 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/EngineSettings.ui @@ -0,0 +1,82 @@ + + + EngineSettingsClass + + + + 0 + 0 + 839 + 597 + + + + Form + + + + + + O3DE Settings + + + + + + + Engine Version + + + + + + + v1.01 + + + + + + + 3rd Party Software Folder + + + + + + + + + + Restricted Folder + + + + + + + + + + Default Gems Folder + + + + + + + + + + Default Project Templates Folder + + + + + + + + + + + diff --git a/Code/Tools/ProjectManager/Source/FirstTimeUse.cpp b/Code/Tools/ProjectManager/Source/FirstTimeUse.cpp new file mode 100644 index 0000000000..5f5dcd5087 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/FirstTimeUse.cpp @@ -0,0 +1,47 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +#include + +namespace O3DE::ProjectManager +{ + FirstTimeUse::FirstTimeUse(ProjectManagerWindow* window) + : ScreenWidget(window) + , m_ui(new Ui::FirstTimeUseClass()) + { + m_ui->setupUi(this); + + ConnectSlotsAndSignals(); + } + + FirstTimeUse::~FirstTimeUse() + { + } + + void FirstTimeUse::ConnectSlotsAndSignals() + { + QObject::connect(m_ui->createProjectButton, &QPushButton::pressed, this, &FirstTimeUse::HandleNewProjectButton); + QObject::connect(m_ui->openProjectButton, &QPushButton::pressed, this, &FirstTimeUse::HandleOpenProjectButton); + } + + void FirstTimeUse::HandleNewProjectButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::NewProjectSettings); + } + void FirstTimeUse::HandleOpenProjectButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::ProjectsHome); + } + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/FirstTimeUse.h b/Code/Tools/ProjectManager/Source/FirstTimeUse.h new file mode 100644 index 0000000000..708513d493 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/FirstTimeUse.h @@ -0,0 +1,43 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace Ui +{ + class FirstTimeUseClass; +} + +namespace O3DE::ProjectManager +{ + class FirstTimeUse + : public ScreenWidget + { + public: + explicit FirstTimeUse(ProjectManagerWindow* window); + ~FirstTimeUse(); + + protected: + void ConnectSlotsAndSignals() override; + + protected slots: + void HandleNewProjectButton(); + void HandleOpenProjectButton(); + + private: + QScopedPointer m_ui; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/FirstTimeUse.ui b/Code/Tools/ProjectManager/Source/FirstTimeUse.ui new file mode 100644 index 0000000000..fdc195731f --- /dev/null +++ b/Code/Tools/ProjectManager/Source/FirstTimeUse.ui @@ -0,0 +1,93 @@ + + + FirstTimeUseClass + + + + 0 + 0 + 881 + 555 + + + + Form + + + + + + + + + 30 + + + + READY. SET. CREATE! + + + + + + + <html><head/><body><p>Welcome to O3DE! Start something new by creating a project. Not sure what to create? </p><p>Explore what’s available by downloading our sample project.</p></body></html> + + + Qt::AutoText + + + + + + + + + + + + 0 + 0 + + + + Create Project + + + + :/Resources/Add.svg:/Resources/Add.svg + + + + 16 + 16 + + + + + + + + + 0 + 0 + + + + Open a Project + + + + :/Resources/Select_Folder.svg:/Resources/Select_Folder.svg + + + + + + + + + + + + diff --git a/Code/Tools/ProjectManager/Source/GemCatalog.cpp b/Code/Tools/ProjectManager/Source/GemCatalog.cpp new file mode 100644 index 0000000000..9d89740816 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/GemCatalog.cpp @@ -0,0 +1,47 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +#include + +namespace O3DE::ProjectManager +{ + GemCatalog::GemCatalog(ProjectManagerWindow* window) + : ScreenWidget(window) + , m_ui(new Ui::GemCatalogClass()) + { + m_ui->setupUi(this); + + ConnectSlotsAndSignals(); + } + + GemCatalog::~GemCatalog() + { + } + + void GemCatalog::ConnectSlotsAndSignals() + { + QObject::connect(m_ui->backButton, &QPushButton::pressed, this, &GemCatalog::HandleBackButton); + QObject::connect(m_ui->confirmButton, &QPushButton::pressed, this, &GemCatalog::HandleConfirmButton); + } + + void GemCatalog::HandleBackButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::NewProjectSettings); + } + void GemCatalog::HandleConfirmButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::ProjectsHome); + } + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/GemCatalog.h b/Code/Tools/ProjectManager/Source/GemCatalog.h new file mode 100644 index 0000000000..e45d865e58 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/GemCatalog.h @@ -0,0 +1,44 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace Ui +{ + class GemCatalogClass; +} + +namespace O3DE::ProjectManager +{ + class GemCatalog + : public ScreenWidget + { + + public: + explicit GemCatalog(ProjectManagerWindow* window); + ~GemCatalog(); + + protected: + void ConnectSlotsAndSignals() override; + + protected slots: + void HandleBackButton(); + void HandleConfirmButton(); + + private: + QScopedPointer m_ui; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/GemCatalog.ui b/Code/Tools/ProjectManager/Source/GemCatalog.ui new file mode 100644 index 0000000000..acc2ea80a1 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/GemCatalog.ui @@ -0,0 +1,231 @@ + + + GemCatalogClass + + + + 0 + 0 + 806 + 566 + + + + Form + + + + + + + + Gem Catalog + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cart + + + + + + + Hamburger Menu + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + RadioButton + + + + + + + RadioButton + + + + + + + RadioButton + + + + + + + Qt::Horizontal + + + + + + + TextLabel + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + + + + 0 + 0 + + + + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + Atom + + + + + Audio + + + + + Camera + + + + + PhysX + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Back + + + + + + + Create Project + + + + + + + + + + diff --git a/Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/DllMain_Windows.cpp b/Code/Tools/ProjectManager/Source/GemCatalog/GemInfo.cpp similarity index 60% rename from Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/DllMain_Windows.cpp rename to Code/Tools/ProjectManager/Source/GemCatalog/GemInfo.cpp index 7c180714d4..b11c7a7a2c 100644 --- a/Code/Sandbox/Plugins/FBXPlugin/Platform/Windows/DllMain_Windows.cpp +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemInfo.cpp @@ -10,17 +10,16 @@ * */ -#include +#include "GemInfo.h" -HINSTANCE g_hInstance = NULL; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL, ULONG fdwReason, [[maybe_unused]] LPVOID lpvReserved) +namespace O3DE::ProjectManager { - if (fdwReason == DLL_PROCESS_ATTACH) + GemInfo::GemInfo(const QString& name, const QString& creator, const QString& summary, Platforms platforms, bool isAdded) + : m_name(name) + , m_creator(creator) + , m_summary(summary) + , m_platforms(platforms) + , m_isAdded(isAdded) { - g_hInstance = hinstDLL; - //DisableThreadLibraryCalls(hInstance); } - - return(TRUE); -} +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/GemCatalog/GemInfo.h b/Code/Tools/ProjectManager/Source/GemCatalog/GemInfo.h new file mode 100644 index 0000000000..e5aa9c41f7 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemInfo.h @@ -0,0 +1,55 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include +#endif + +namespace O3DE::ProjectManager +{ + class GemInfo + { + public: + enum Platform + { + Android = 0x0, + iOS = 0x1, + Linux = 0x2, + macOS = 0x3, + Windows = 0x4 + }; + Q_DECLARE_FLAGS(Platforms, Platform) + + GemInfo(const QString& name, const QString& creator, const QString& summary, Platforms platforms, bool isAdded); + + QString m_name; + QString m_displayName; + AZ::Uuid m_uuid; + QString m_creator; + bool m_isAdded = false; //! Is the gem currently added and enabled in the project? + QString m_summary; + Platforms m_platforms; + QStringList m_features; + QString m_version; + QString m_lastUpdatedDate; + QString m_documentationUrl; + QVector m_dependingGemUuids; + QVector m_conflictingGemUuids; + }; +} // namespace O3DE::ProjectManager + +Q_DECLARE_OPERATORS_FOR_FLAGS(O3DE::ProjectManager::GemInfo::Platforms) diff --git a/Code/Tools/ProjectManager/Source/NewProjectSettings.cpp b/Code/Tools/ProjectManager/Source/NewProjectSettings.cpp new file mode 100644 index 0000000000..2ebe54e682 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/NewProjectSettings.cpp @@ -0,0 +1,47 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +#include + +namespace O3DE::ProjectManager +{ + NewProjectSettings::NewProjectSettings(ProjectManagerWindow* window) + : ScreenWidget(window) + , m_ui(new Ui::NewProjectSettingsClass()) + { + m_ui->setupUi(this); + + ConnectSlotsAndSignals(); + } + + NewProjectSettings::~NewProjectSettings() + { + } + + void NewProjectSettings::ConnectSlotsAndSignals() + { + QObject::connect(m_ui->backButton, &QPushButton::pressed, this, &NewProjectSettings::HandleBackButton); + QObject::connect(m_ui->nextButton, &QPushButton::pressed, this, &NewProjectSettings::HandleNextButton); + } + + void NewProjectSettings::HandleBackButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::FirstTimeUse); + } + void NewProjectSettings::HandleNextButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::GemCatalog); + } + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/NewProjectSettings.h b/Code/Tools/ProjectManager/Source/NewProjectSettings.h new file mode 100644 index 0000000000..f5fa91a9b9 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/NewProjectSettings.h @@ -0,0 +1,43 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace Ui +{ + class NewProjectSettingsClass; +} + +namespace O3DE::ProjectManager +{ + class NewProjectSettings + : public ScreenWidget + { + public: + explicit NewProjectSettings(ProjectManagerWindow* window); + ~NewProjectSettings(); + + protected: + void ConnectSlotsAndSignals() override; + + protected slots: + void HandleBackButton(); + void HandleNextButton(); + + private: + QScopedPointer m_ui; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/NewProjectSettings.ui b/Code/Tools/ProjectManager/Source/NewProjectSettings.ui new file mode 100644 index 0000000000..98db10338e --- /dev/null +++ b/Code/Tools/ProjectManager/Source/NewProjectSettings.ui @@ -0,0 +1,97 @@ + + + NewProjectSettingsClass + + + + 0 + 0 + 880 + 546 + + + + Form + + + + + + Project Name + + + + + + + + + + Project Path + + + + + + + + + + Project Template + + + + + + + + + Standard (Recommened) + + + + + + + Empty + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Back + + + + + + + Next + + + + + + + + + + diff --git a/Code/Tools/ProjectManager/Source/ProjectManagerWindow.cpp b/Code/Tools/ProjectManager/Source/ProjectManagerWindow.cpp new file mode 100644 index 0000000000..12980fc836 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectManagerWindow.cpp @@ -0,0 +1,106 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include +#include + +#include +#include + +#include + +#include + +namespace O3DE::ProjectManager +{ + ProjectManagerWindow::ProjectManagerWindow(QWidget* parent, const AZ::IO::PathView& engineRootPath) + : QMainWindow(parent) + , m_ui(new Ui::ProjectManagerWindowClass()) + { + m_ui->setupUi(this); + + ConnectSlotsAndSignals(); + + QDir rootDir = QString::fromUtf8(engineRootPath.Native().data(), aznumeric_cast(engineRootPath.Native().size())); + const auto pathOnDisk = rootDir.absoluteFilePath("Code/Tools/ProjectManager/Resources"); + const auto qrcPath = QStringLiteral(":/ProjectManagerWindow"); + AzQtComponents::StyleManager::addSearchPaths("projectmanagerwindow", pathOnDisk, qrcPath, engineRootPath); + + AzQtComponents::StyleManager::setStyleSheet(this, QStringLiteral("projectlauncherwindow:ProjectManagerWindow.qss")); + + BuildScreens(); + + ChangeToScreen(ProjectManagerScreen::FirstTimeUse); + } + + ProjectManagerWindow::~ProjectManagerWindow() + { + } + + void ProjectManagerWindow::BuildScreens() + { + // Basically just iterate over the ProjectManagerScreen enum creating each screen + // Could add some fancy to do this but there are few screens right now + + ResetScreen(ProjectManagerScreen::FirstTimeUse); + ResetScreen(ProjectManagerScreen::NewProjectSettings); + ResetScreen(ProjectManagerScreen::GemCatalog); + ResetScreen(ProjectManagerScreen::ProjectsHome); + ResetScreen(ProjectManagerScreen::ProjectSettings); + ResetScreen(ProjectManagerScreen::EngineSettings); + } + + QStackedWidget* ProjectManagerWindow::GetScreenStack() + { + return m_ui->stackedScreens; + } + + void ProjectManagerWindow::ChangeToScreen(ProjectManagerScreen screen) + { + int index = aznumeric_cast(screen); + m_ui->stackedScreens->setCurrentIndex(index); + } + + void ProjectManagerWindow::ResetScreen(ProjectManagerScreen screen) + { + int index = aznumeric_cast(screen); + + // Fine the old screen if it exists and get rid of it so we can start fresh + QWidget* oldScreen = m_ui->stackedScreens->widget(index); + + if (oldScreen) + { + m_ui->stackedScreens->removeWidget(oldScreen); + oldScreen->deleteLater(); + } + + // Add new screen + QWidget* newScreen = BuildScreen(this, screen); + m_ui->stackedScreens->insertWidget(index, newScreen); + } + + void ProjectManagerWindow::ConnectSlotsAndSignals() + { + QObject::connect(m_ui->projectsMenu, &QMenu::aboutToShow, this, &ProjectManagerWindow::HandleProjectsMenu); + QObject::connect(m_ui->engineMenu, &QMenu::aboutToShow, this, &ProjectManagerWindow::HandleEngineMenu); + } + + void ProjectManagerWindow::HandleProjectsMenu() + { + ChangeToScreen(ProjectManagerScreen::ProjectsHome); + } + void ProjectManagerWindow::HandleEngineMenu() + { + ChangeToScreen(ProjectManagerScreen::EngineSettings); + } + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ProjectManagerWindow.h b/Code/Tools/ProjectManager/Source/ProjectManagerWindow.h new file mode 100644 index 0000000000..9e5761fbd2 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectManagerWindow.h @@ -0,0 +1,57 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include + +#include +#include + +#include +#endif + +namespace Ui +{ + class ProjectManagerWindowClass; +} + +namespace O3DE::ProjectManager +{ + class ProjectManagerWindow + : public QMainWindow + { + Q_OBJECT + + public: + explicit ProjectManagerWindow(QWidget* parent, const AZ::IO::PathView& engineRootPath); + ~ProjectManagerWindow(); + + void BuildScreens(); + QStackedWidget* GetScreenStack(); + + public slots: + void ChangeToScreen(ProjectManagerScreen screen); + void ResetScreen(ProjectManagerScreen screen); + + protected: + void ConnectSlotsAndSignals(); + + protected slots: + void HandleProjectsMenu(); + void HandleEngineMenu(); + + private: + QScopedPointer m_ui; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ProjectManagerWindow.ui b/Code/Tools/ProjectManager/Source/ProjectManagerWindow.ui new file mode 100644 index 0000000000..704e74e38e --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectManagerWindow.ui @@ -0,0 +1,65 @@ + + + ProjectManagerWindowClass + + + + 0 + 0 + 800 + 600 + + + + O3DE Project Manager + + + + + + + + + + + + 0 + 0 + 800 + 36 + + + + + 16 + + + + + Icon + + + + :/Resources/o3de_editor.ico:/Resources/o3de_editor.ico + + + + + Projects + + + + + Engine + + + + + + + + + + + + diff --git a/Code/Tools/ProjectManager/Source/ProjectSettings.cpp b/Code/Tools/ProjectManager/Source/ProjectSettings.cpp new file mode 100644 index 0000000000..bc653f9c5b --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectSettings.cpp @@ -0,0 +1,42 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +#include + +namespace O3DE::ProjectManager +{ + ProjectSettings::ProjectSettings(ProjectManagerWindow* window) + : ScreenWidget(window) + , m_ui(new Ui::ProjectSettingsClass()) + { + m_ui->setupUi(this); + + ConnectSlotsAndSignals(); + } + + ProjectSettings::~ProjectSettings() + { + } + + void ProjectSettings::ConnectSlotsAndSignals() + { + QObject::connect(m_ui->gemsButton, &QPushButton::pressed, this, &ProjectSettings::HandleGemsButton); + } + + void ProjectSettings::HandleGemsButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::GemCatalog); + } + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ProjectSettings.h b/Code/Tools/ProjectManager/Source/ProjectSettings.h new file mode 100644 index 0000000000..e7781d3a2a --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectSettings.h @@ -0,0 +1,42 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace Ui +{ + class ProjectSettingsClass; +} + +namespace O3DE::ProjectManager +{ + class ProjectSettings + : public ScreenWidget + { + public: + explicit ProjectSettings(ProjectManagerWindow* window); + ~ProjectSettings(); + + protected: + void ConnectSlotsAndSignals() override; + + protected slots: + void HandleGemsButton(); + + private: + QScopedPointer m_ui; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ProjectSettings.ui b/Code/Tools/ProjectManager/Source/ProjectSettings.ui new file mode 100644 index 0000000000..934238a257 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectSettings.ui @@ -0,0 +1,113 @@ + + + ProjectSettingsClass + + + + 0 + 0 + 782 + 579 + + + + Form + + + + + + + + Project Settings + + + + + + + Gems + + + + + + + Qt::Horizontal + + + + 761 + 20 + + + + + + + + + + + + + + Project Name + + + + + + + + + + Project Location + + + + + + + + + + Project Image Location + + + + + + + + + + Project Background Image Location + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/Code/Tools/ProjectManager/Source/ProjectsHome.cpp b/Code/Tools/ProjectManager/Source/ProjectsHome.cpp new file mode 100644 index 0000000000..1a451f3d10 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectsHome.cpp @@ -0,0 +1,52 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +#include + +namespace O3DE::ProjectManager +{ + ProjectsHome::ProjectsHome(ProjectManagerWindow* window) + : ScreenWidget(window) + , m_ui(new Ui::ProjectsHomeClass()) + { + m_ui->setupUi(this); + + ConnectSlotsAndSignals(); + } + + ProjectsHome::~ProjectsHome() + { + } + + void ProjectsHome::ConnectSlotsAndSignals() + { + QObject::connect(m_ui->newProjectButton, &QPushButton::pressed, this, &ProjectsHome::HandleNewProjectButton); + QObject::connect(m_ui->addProjectButton, &QPushButton::pressed, this, &ProjectsHome::HandleAddProjectButton); + QObject::connect(m_ui->editProjectButton, &QPushButton::pressed, this, &ProjectsHome::HandleEditProjectButton); + } + + void ProjectsHome::HandleNewProjectButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::NewProjectSettings); + } + void ProjectsHome::HandleAddProjectButton() + { + //Do nothing for now + } + void ProjectsHome::HandleEditProjectButton() + { + m_projectManagerWindow->ChangeToScreen(ProjectManagerScreen::ProjectSettings); + } + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ProjectsHome.h b/Code/Tools/ProjectManager/Source/ProjectsHome.h new file mode 100644 index 0000000000..4cc2918a38 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectsHome.h @@ -0,0 +1,45 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace Ui +{ + class ProjectsHomeClass; +} + +namespace O3DE::ProjectManager +{ + class ProjectsHome + : public ScreenWidget + { + + public: + explicit ProjectsHome(ProjectManagerWindow* window); + ~ProjectsHome(); + + protected: + void ConnectSlotsAndSignals() override; + + protected slots: + void HandleNewProjectButton(); + void HandleAddProjectButton(); + void HandleEditProjectButton(); + + private: + QScopedPointer m_ui; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ProjectsHome.ui b/Code/Tools/ProjectManager/Source/ProjectsHome.ui new file mode 100644 index 0000000000..ea3e34d84b --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ProjectsHome.ui @@ -0,0 +1,137 @@ + + + ProjectsHomeClass + + + + 0 + 0 + 826 + 585 + + + + Form + + + + + + My Projects + + + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + 0 + + + + + + + + :/Resources/Add.svg:/Resources/Add.svg + + + + + + + + 0 + 0 + + + + + + + + :/Resources/Select_Folder.svg:/Resources/Select_Folder.svg + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + Edit Project + + + + + + + Open a Project + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/Code/Framework/AzFramework/AzFramework/API/AtomActiveInterface.h b/Code/Tools/ProjectManager/Source/ScreenDefs.h similarity index 65% rename from Code/Framework/AzFramework/AzFramework/API/AtomActiveInterface.h rename to Code/Tools/ProjectManager/Source/ScreenDefs.h index 80d4f6c867..f02b1de1b8 100644 --- a/Code/Framework/AzFramework/AzFramework/API/AtomActiveInterface.h +++ b/Code/Tools/ProjectManager/Source/ScreenDefs.h @@ -11,16 +11,15 @@ */ #pragma once -#include - -namespace AzFramework +namespace O3DE::ProjectManager { - class AtomActiveInterface + enum class ProjectManagerScreen { - public: - AZ_RTTI(AtomActiveInterface, "{4BB59C86-0848-485D-AB28-700540470B2B}"); - - AtomActiveInterface() = default; - virtual ~AtomActiveInterface() = default; + FirstTimeUse, + NewProjectSettings, + GemCatalog, + ProjectsHome, + ProjectSettings, + EngineSettings }; -} // namespace AzFramework +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ScreenFactory.cpp b/Code/Tools/ProjectManager/Source/ScreenFactory.cpp new file mode 100644 index 0000000000..b07816e69e --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ScreenFactory.cpp @@ -0,0 +1,43 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#include + +#include +#include +#include +#include +#include +#include + +namespace O3DE::ProjectManager +{ + QWidget* BuildScreen(ProjectManagerWindow* window, ProjectManagerScreen screen) + { + switch(screen) + { + case (ProjectManagerScreen::FirstTimeUse): + return new FirstTimeUse(window); + case (ProjectManagerScreen::NewProjectSettings): + return new NewProjectSettings(window); + case (ProjectManagerScreen::GemCatalog): + return new GemCatalog(window); + case (ProjectManagerScreen::ProjectsHome): + return new ProjectsHome(window); + case (ProjectManagerScreen::ProjectSettings): + return new ProjectSettings(window); + case (ProjectManagerScreen::EngineSettings): + return new EngineSettings(window); + default: + return new QWidget(window->GetScreenStack()); + } + } +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ScreenFactory.h b/Code/Tools/ProjectManager/Source/ScreenFactory.h new file mode 100644 index 0000000000..ea68534a08 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ScreenFactory.h @@ -0,0 +1,24 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#include + +#include + +#include + + +namespace O3DE::ProjectManager +{ + QWidget* BuildScreen(ProjectManagerWindow* window, ProjectManagerScreen screen); +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/ScreenWidget.h b/Code/Tools/ProjectManager/Source/ScreenWidget.h new file mode 100644 index 0000000000..b4c4fd190c --- /dev/null +++ b/Code/Tools/ProjectManager/Source/ScreenWidget.h @@ -0,0 +1,38 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ +#pragma once + +#if !defined(Q_MOC_RUN) +#include + +#include +#endif + +namespace O3DE::ProjectManager +{ + class ScreenWidget + : public QWidget + { + public: + explicit ScreenWidget(ProjectManagerWindow* window) + : QWidget(window->GetScreenStack()) + , m_projectManagerWindow(window) + { + } + + protected: + virtual void ConnectSlotsAndSignals() = 0; + + ProjectManagerWindow* m_projectManagerWindow; + }; + +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/main.cpp b/Code/Tools/ProjectManager/Source/main.cpp new file mode 100644 index 0000000000..149da79491 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/main.cpp @@ -0,0 +1,55 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +int main(int argc, char* argv[]) +{ + QApplication::setOrganizationName("O3DE"); + QApplication::setOrganizationDomain("o3de.org"); + QCoreApplication::setApplicationName("ProjectManager"); + QCoreApplication::setApplicationVersion("1.0"); + + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + AzQtComponents::Utilities::HandleDpiAwareness(AzQtComponents::Utilities::SystemDpiAware); + + QApplication app(argc, argv); + + // Need to use settings registry to get EngineRootFolder + AZ::IO::FixedMaxPath engineRootPath; + { + AZ::ComponentApplication componentApplication; + auto settingsRegistry = AZ::SettingsRegistry::Get(); + settingsRegistry->Get(engineRootPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder); + } + + AzQtComponents::StyleManager styleManager(&app); + styleManager.initialize(&app, engineRootPath); + + O3DE::ProjectManager::ProjectManagerWindow window(nullptr, engineRootPath); + window.show(); + + return app.exec(); +} diff --git a/Code/Tools/ProjectManager/project_manager.qrc b/Code/Tools/ProjectManager/project_manager.qrc new file mode 100644 index 0000000000..408398584b --- /dev/null +++ b/Code/Tools/ProjectManager/project_manager.qrc @@ -0,0 +1,8 @@ + + + Resources/ProjectManager.qss + Resources/Add.svg + Resources/Select_Folder.svg + Resources/o3de_editor.ico + + \ No newline at end of file diff --git a/Code/Tools/ProjectManager/project_manager_files.cmake b/Code/Tools/ProjectManager/project_manager_files.cmake new file mode 100644 index 0000000000..a97ff692b7 --- /dev/null +++ b/Code/Tools/ProjectManager/project_manager_files.cmake @@ -0,0 +1,42 @@ +# +# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +# its licensors. +# +# For complete copyright and license terms please see the LICENSE at the root of this +# distribution (the "License"). All use of this software is governed by the License, +# or, if provided, by the license below or the license accompanying this file. Do not +# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# + +set(FILES + project_manager.qrc + Source/main.cpp + Source/ScreenDefs.h + Source/ScreenFactory.h + Source/ScreenFactory.cpp + Source/ScreenWidget.h + Source/FirstTimeUse.h + Source/FirstTimeUse.cpp + Source/FirstTimeUse.ui + Source/ProjectManagerWindow.h + Source/ProjectManagerWindow.cpp + Source/ProjectManagerWindow.ui + Source/NewProjectSettings.h + Source/NewProjectSettings.cpp + Source/NewProjectSettings.ui + Source/GemCatalog.h + Source/GemCatalog.cpp + Source/GemCatalog.ui + Source/ProjectsHome.h + Source/ProjectsHome.cpp + Source/ProjectsHome.ui + Source/ProjectSettings.h + Source/ProjectSettings.cpp + Source/ProjectSettings.ui + Source/EngineSettings.h + Source/EngineSettings.cpp + Source/EngineSettings.ui + Source/GemCatalog/GemInfo.h + Source/GemCatalog/GemInfo.cpp +) diff --git a/Code/Tools/SceneAPI/CMakeLists.txt b/Code/Tools/SceneAPI/CMakeLists.txt index 0dfcbaf9cd..70bfe9e837 100644 --- a/Code/Tools/SceneAPI/CMakeLists.txt +++ b/Code/Tools/SceneAPI/CMakeLists.txt @@ -10,7 +10,7 @@ # add_subdirectory(FbxSceneBuilder) -add_subdirectory(FbxSDKWrapper) add_subdirectory(SceneCore) add_subdirectory(SceneData) add_subdirectory(SceneUI) +add_subdirectory(SDKWrapper) diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveNodeWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveNodeWrapper.cpp deleted file mode 100644 index 78d7c713e0..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveNodeWrapper.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include "FbxAnimCurveNodeWrapper.h" -#include "FbxAnimCurveWrapper.h" -#include "fbxsdk.h" - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxAnimCurveNodeWrapper::FbxAnimCurveNodeWrapper(FbxAnimCurveNode* fbxAnimCurveNode) - : m_fbxAnimCurveNode(fbxAnimCurveNode) - { - } - - const char* FbxAnimCurveNodeWrapper::GetName() const - { - return m_fbxAnimCurveNode->GetName(); - } - - int FbxAnimCurveNodeWrapper::GetChannelCount() const - { - return m_fbxAnimCurveNode->GetChannelsCount(); - } - - int FbxAnimCurveNodeWrapper::GetCurveCount(int channelID) const - { - return m_fbxAnimCurveNode->GetCurveCount(channelID); - } - - AZStd::shared_ptr FbxAnimCurveNodeWrapper::GetCurveWrapper(int channelID, int index) const - { - return AZStd::make_shared(static_cast(m_fbxAnimCurveNode->GetCurve(channelID, index))); - } - } -} diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveNodeWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveNodeWrapper.h deleted file mode 100644 index a1213de32b..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveNodeWrapper.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "fbxsdk.h" -#include "FbxTimeWrapper.h" -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxAnimCurveWrapper; - - class FbxAnimCurveNodeWrapper - { - public: - FbxAnimCurveNodeWrapper(FbxAnimCurveNode* fbxAnimCurveNode); - ~FbxAnimCurveNodeWrapper() = default; - const char* GetName() const; - int GetChannelCount() const; - int GetCurveCount(int channelID) const; - - AZStd::shared_ptr GetCurveWrapper(int channelID, int index) const; - - protected: - FbxAnimCurveNode* m_fbxAnimCurveNode; - }; - } -} diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveWrapper.cpp deleted file mode 100644 index e1e32278d9..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveWrapper.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxAnimCurveWrapper::FbxAnimCurveWrapper(FbxAnimCurve* fbxAnimCurve) - : m_fbxAnimCurve(fbxAnimCurve) - { - } - - const char* FbxAnimCurveWrapper::GetName() const - { - return m_fbxAnimCurve->GetName(); - } - - float FbxAnimCurveWrapper::Evaluate(FbxTimeWrapper& time) const - { - return m_fbxAnimCurve->Evaluate(time.m_fbxTime); - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveWrapper.h deleted file mode 100644 index f8793f53cd..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimCurveWrapper.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxAnimCurveWrapper - { - public: - FbxAnimCurveWrapper(FbxAnimCurve* fbxAnimCurve); - ~FbxAnimCurveWrapper() = default; - const char* GetName() const; - float Evaluate(FbxTimeWrapper& time) const; - - protected: - FbxAnimCurve* m_fbxAnimCurve; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimLayerWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimLayerWrapper.cpp deleted file mode 100644 index a99fe05303..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimLayerWrapper.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include - -#include "fbxsdk.h" - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxAnimLayerWrapper::FbxAnimLayerWrapper(FbxAnimLayer* fbxAnimLayer) - : m_fbxAnimLayer(fbxAnimLayer) - { - } - - const char* FbxAnimLayerWrapper::GetName() const - { - return m_fbxAnimLayer->GetName(); - } - - u32 FbxAnimLayerWrapper::GetCurveNodeCount() const - { - return static_cast(m_fbxAnimLayer->GetMemberCount()); - } - - FbxAnimLayer* FbxAnimLayerWrapper::GetFbxLayer() const - { - return m_fbxAnimLayer; - } - - AZStd::shared_ptr FbxAnimLayerWrapper::GetCurveNodeWrapper(u32 index) const - { - return AZStd::make_shared(static_cast(m_fbxAnimLayer->GetMember(aznumeric_cast(index)))); - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimLayerWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimLayerWrapper.h deleted file mode 100644 index ace0f7eee0..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimLayerWrapper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxAnimCurveNodeWrapper; - - class FbxAnimLayerWrapper - { - friend class FbxNodeWrapper; - public: - FbxAnimLayerWrapper(FbxAnimLayer* fbxAnimLayer); - ~FbxAnimLayerWrapper() = default; - const char* GetName() const; - u32 GetCurveNodeCount() const ; - FbxAnimLayer* GetFbxLayer() const; - AZStd::shared_ptr GetCurveNodeWrapper(u32 index) const; - - protected: - FbxAnimLayer* m_fbxAnimLayer; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimStackWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimStackWrapper.cpp deleted file mode 100644 index 943bff2bc0..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimStackWrapper.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxAnimStackWrapper::FbxAnimStackWrapper(FbxAnimStack* fbxAnimStack) - : m_fbxAnimStack(fbxAnimStack) - { - AZ_Assert(fbxAnimStack, "Invalid FbxAnimStack input to initialize FbxAnimStackWrapper"); - } - - FbxAnimStackWrapper::~FbxAnimStackWrapper() - { - m_fbxAnimStack = nullptr; - } - - const char* FbxAnimStackWrapper::GetName() const - { - return m_fbxAnimStack->GetName(); - } - - int FbxAnimStackWrapper::GetAnimationLayerCount() const - { - return m_fbxAnimStack->GetMemberCount(); - } - - const AZStd::shared_ptr FbxAnimStackWrapper::GetAnimationLayerAt(int index) const - { - AZ_Assert(index < GetAnimationLayerCount(), "Invalid animation layer index %d for layer count %d", index, GetAnimationLayerCount()); - return AZStd::make_shared(m_fbxAnimStack->GetMember(index)); - } - - FbxTimeSpanWrapper FbxAnimStackWrapper::GetLocalTimeSpan() const - { - return FbxTimeSpanWrapper(m_fbxAnimStack->GetLocalTimeSpan()); - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimStackWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimStackWrapper.h deleted file mode 100644 index 97e1f86324..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAnimStackWrapper.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - using FbxSDKLongLong = FbxLongLong; - class FbxAnimLayerWrapper; - class FbxTimeSpanWrapper; - - class FbxAnimStackWrapper - { - public: - FbxAnimStackWrapper(FbxAnimStack* fbxAnimStack); - virtual ~FbxAnimStackWrapper(); - - virtual const char* GetName() const; - virtual int GetAnimationLayerCount() const; - virtual const AZStd::shared_ptr GetAnimationLayerAt(int index) const; - virtual FbxTimeSpanWrapper GetLocalTimeSpan() const; - - protected: - FbxAnimStackWrapper() = default; - FbxAnimStack* m_fbxAnimStack; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAxisSystemWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAxisSystemWrapper.cpp deleted file mode 100644 index b957b1105c..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAxisSystemWrapper.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxAxisSystemWrapper::FbxAxisSystemWrapper(const FbxAxisSystem& fbxAxisSystem) - : m_fbxAxisSystem(fbxAxisSystem) - { - } - - FbxAxisSystemWrapper::UpVector FbxAxisSystemWrapper::GetUpVector(int& sign) const - { - switch (m_fbxAxisSystem.GetUpVector(sign)) - { - case FbxAxisSystem::eXAxis: - return X; - case FbxAxisSystem::eYAxis: - return Y; - case FbxAxisSystem::eZAxis: - return Z; - default: - AZ_TraceContext("Unknown value", m_fbxAxisSystem.GetUpVector(sign)); - AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unrecognized axis up vector type"); - return Unknown; - } - } - - SceneAPI::DataTypes::MatrixType FbxAxisSystemWrapper::CalculateConversionTransform(UpVector targetUpAxis) - { - FbxAxisSystem targetSystem; - switch (targetUpAxis) - { - case Y: - // Maya YUp coordinate system (UpVector = +Y, FrontVector = +Z, CoordSystem = +X (RightHanded)) - targetSystem = FbxAxisSystem::MayaYUp; - break; - case Z: - // CryTek ZUp coordinate system (UpVector = +Z, FrontVector = +Y, CoordSystem = -X (RightHanded)) - targetSystem = FbxAxisSystem(FbxAxisSystem::eZAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded); - break; - case X: - // Default XUp coordinate system (UpVector = +X, FrontVector = +Z, CoordSystem = -Y (RightHanded)) - targetSystem = FbxAxisSystem(FbxAxisSystem::eXAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded); - break; - default: - AZ_TraceContext("Unknown value", targetUpAxis); - AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unrecognized axis conversion target axis type"); - return SceneAPI::DataTypes::MatrixType::CreateIdentity(); - } - FbxAMatrix targetMatrix; - targetSystem.GetMatrix(targetMatrix); - FbxAMatrix currentMatrix; - m_fbxAxisSystem.GetMatrix(currentMatrix); - FbxAMatrix adjustMatrix = targetMatrix * currentMatrix.Inverse(); - return FbxTypeConverter::ToTransform(adjustMatrix); - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAxisSystemWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAxisSystemWrapper.h deleted file mode 100644 index d8dba5068a..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxAxisSystemWrapper.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxAxisSystemWrapper - { - public: - enum UpVector - { - X, - Y, - Z, - Unknown - }; - - FbxAxisSystemWrapper() = default; - FbxAxisSystemWrapper(const FbxAxisSystem& fbxAxisSystem); - virtual ~FbxAxisSystemWrapper() = default; - - virtual UpVector GetUpVector(int& sign) const; - virtual SceneAPI::DataTypes::MatrixType CalculateConversionTransform(UpVector targetUpAxis); - - protected: - FbxAxisSystem m_fbxAxisSystem; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeChannelWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeChannelWrapper.cpp deleted file mode 100644 index 92cf655dbd..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeChannelWrapper.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxBlendShapeChannelWrapper::FbxBlendShapeChannelWrapper(FbxBlendShapeChannel* fbxBlendShapeChannel) - : m_fbxBlendShapeChannel(fbxBlendShapeChannel) - { - AZ_Assert(fbxBlendShapeChannel, "Invalid FbxSkin input to initialize FbxBlendShapeChannelWrapper"); - } - - FbxBlendShapeChannelWrapper::~FbxBlendShapeChannelWrapper() - { - m_fbxBlendShapeChannel = nullptr; - } - - const char* FbxBlendShapeChannelWrapper::GetName() const - { - return m_fbxBlendShapeChannel->GetName(); - } - - //The engine currently only supports one target shape. If there are more than one, - //code will ultimately end up just using the max index returned by this function. - int FbxBlendShapeChannelWrapper::GetTargetShapeCount() const - { - return m_fbxBlendShapeChannel->GetTargetShapeCount(); - } - - //While not strictly true that the target shapes are meshes, for the purposes of the engine's - //current runtime they must be meshes. - AZStd::shared_ptr FbxBlendShapeChannelWrapper::GetTargetShape(int index) const - { - //we need to create a duplicate FbxMesh from the base mesh and the target data - //FbxMeshWrapper needs an FbxMesh to point to so we are generating one - //by cloning the mesh data and then replacing with the morph data. - FbxShape* fbxShape = m_fbxBlendShapeChannel->GetTargetShape(index); - if (!fbxShape) - { - return nullptr; - } - - FbxGeometry* fbxGeom = fbxShape->GetBaseGeometry(); - if (fbxGeom && fbxGeom->GetAttributeType() == FbxNodeAttribute::EType::eMesh) - { - FbxMesh* fbxMesh = static_cast(fbxGeom); - FbxMesh* fbxBlendMesh = FbxMesh::Create(m_fbxBlendShapeChannel->GetScene(),""); - fbxBlendMesh->Copy(*fbxMesh); - //TODO: test that mesh is managed by the sdk - const int count = fbxBlendMesh->GetControlPointsCount(); - //set control points from blend shape - for (int i = 0; i < count; i++) - { - fbxBlendMesh->SetControlPointAt(fbxShape->GetControlPointAt(i), i); - } - - //source data - FbxLayerElementArrayTemplate* normalsTemplate; - if (fbxShape->GetNormals(&normalsTemplate)) - { - int normalCount = normalsTemplate->GetCount(); - - //destination data - FbxLayer* normalLayer = fbxBlendMesh->GetLayer(0, FbxLayerElement::eNormal); - if (normalLayer) - { - FbxLayerElementNormal* normals = normalLayer->GetNormals(); - if (normals) - { - //set normal data from blend shape - for (int j = 0; j < normalCount; j++) - { - FbxVector4 normal = normalsTemplate->GetAt(j); - normals->GetDirectArray().SetAt(j, normal); - } - } - } - } - return AZStd::make_shared(fbxBlendMesh); - } - return nullptr; - } - } -} diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeChannelWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeChannelWrapper.h deleted file mode 100644 index a8f2fffdcc..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeChannelWrapper.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxNodeWrapper; - class FbxMeshWrapper; - - class FbxBlendShapeChannelWrapper - { - public: - FbxBlendShapeChannelWrapper(FbxBlendShapeChannel* fbxBlendShapeChannel); - virtual ~FbxBlendShapeChannelWrapper(); - - virtual const char* GetName() const; - virtual int GetTargetShapeCount() const; - - //While not strictly true that the target shapes are meshes, for the purposes of the engine's - //current runtime they must be meshes. - virtual AZStd::shared_ptr GetTargetShape(int index) const; - - protected: - FbxBlendShapeChannelWrapper() = default; - FbxBlendShapeChannel* m_fbxBlendShapeChannel; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeWrapper.cpp deleted file mode 100644 index ab75613ab5..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeWrapper.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxBlendShapeWrapper::FbxBlendShapeWrapper(FbxBlendShape* fbxBlendShape) - : m_fbxBlendShape(fbxBlendShape) - { - AZ_Assert(fbxBlendShape, "Invalid FbxBlendShape input to initialize FbxBlendShapeWrapper"); - } - - FbxBlendShapeWrapper::~FbxBlendShapeWrapper() - { - m_fbxBlendShape = nullptr; - } - - const char* FbxBlendShapeWrapper::GetName() const - { - return m_fbxBlendShape->GetName(); - } - - //Technically Fbx returns a FbxGeometry off this interface, but we only support meshes in the engine runtime. - AZStd::shared_ptr FbxBlendShapeWrapper::GetGeometry() const - { - FbxGeometry* fbxGeom = m_fbxBlendShape->GetGeometry(); - - if (fbxGeom && fbxGeom->GetAttributeType() == FbxNodeAttribute::EType::eMesh ) - { - return AZStd::make_shared(static_cast(fbxGeom)); - } - else - { - return nullptr; - } - } - - int FbxBlendShapeWrapper::GetBlendShapeChannelCount() const - { - return m_fbxBlendShape->GetBlendShapeChannelCount(); - } - - AZStd::shared_ptr FbxBlendShapeWrapper::GetBlendShapeChannel(int index) const - { - FbxBlendShapeChannel* fbxBlendShapeChannel = m_fbxBlendShape->GetBlendShapeChannel(index); - if (fbxBlendShapeChannel) - { - return AZStd::make_shared(fbxBlendShapeChannel); - } - else - { - return nullptr; - } - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeWrapper.h deleted file mode 100644 index d049f5cec8..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxBlendShapeWrapper.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxBlendShapeChannelWrapper; - class FbxNodeWrapper; - class FbxMeshWrapper; - - class FbxBlendShapeWrapper - { - public: - FbxBlendShapeWrapper(FbxBlendShape* fbxBlendShape); - virtual ~FbxBlendShapeWrapper(); - - virtual const char* GetName() const; - //Technically Fbx returns a FbxGeometry off this interface, but we only support meshes in the engine runtime. - virtual AZStd::shared_ptr GetGeometry() const; - virtual int GetBlendShapeChannelCount() const; - virtual AZStd::shared_ptr GetBlendShapeChannel(int index) const; - - protected: - FbxBlendShapeWrapper() = default; - FbxBlendShape* m_fbxBlendShape; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxLayerElementUtilities.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxLayerElementUtilities.h deleted file mode 100644 index a4eed3f947..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxLayerElementUtilities.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxLayerElementUtilities - { - public: - template - static void GetGeometryElement(ValueType& value, const ElementArrayType* elementArray, - int polygonIndex, int polygonVertexIndex, int controlPointIndex); - }; - } // namespace FbxSDKWrapper -} // namespace AZ - -#include "FbxLayerElementUtilities.inl" diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxLayerElementUtilities.inl b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxLayerElementUtilities.inl deleted file mode 100644 index eb1d9ef925..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxLayerElementUtilities.inl +++ /dev/null @@ -1,74 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - template - void FbxLayerElementUtilities::GetGeometryElement( ValueType& value, const ElementArrayType* elementArray, - int polygonIndex, int polygonVertexIndex, int controlPointIndex) - { - if (!elementArray) - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Invalid ElementArrayType input"); - return; - } - - int fbxElementIndex; - switch (elementArray->GetMappingMode()) - { - case FbxGeometryElement::eByControlPoint: - // One mapping coordinate for each surface control point/vertex. - fbxElementIndex = controlPointIndex; - break; - case FbxGeometryElement::eByPolygonVertex: - // One mapping coordinate for each vertex, for every polygon of which it is a part. - // This means that a vertex will have as many mapping coordinates as polygons of which it is a part. - fbxElementIndex = polygonVertexIndex; - break; - case FbxGeometryElement::eByPolygon: - // One mapping coordinate for the whole polygon. - fbxElementIndex = polygonIndex; - break; - default: - AZ_TraceContext("Unknown value", elementArray->GetMappingMode()); - AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Invalid ElementArrayType mapping mode"); - return; - } - - if (elementArray->GetReferenceMode() == FbxGeometryElement::eIndexToDirect) - { - // Convert index from "index of value's index" to "index of value". - const FbxLayerElementArrayTemplate& indices = elementArray->GetIndexArray(); - AZ_Assert(fbxElementIndex < indices.GetCount(), "Invalid element index %d", fbxElementIndex); - if (fbxElementIndex >= indices.GetCount()) - { - return; - } - fbxElementIndex = indices.GetAt(fbxElementIndex); - } - - const FbxLayerElementArrayTemplate& elements = elementArray->GetDirectArray(); - AZ_Assert(fbxElementIndex < elements.GetCount(), "Invalid element index %d", fbxElementIndex); - if (fbxElementIndex >= elements.GetCount()) - { - return; - } - value = elements.GetAt(fbxElementIndex); - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMaterialWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMaterialWrapper.cpp deleted file mode 100644 index 37c23bc2cb..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMaterialWrapper.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - const char* s_physicalisedAttributeName = "physicalize"; - const char* s_proxyNoDraw = "ProxyNoDraw"; -} - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxMaterialWrapper::FbxMaterialWrapper(FbxSurfaceMaterial* fbxMaterial) - : SDKMaterial::MaterialWrapper(fbxMaterial) - { - AZ_Assert(fbxMaterial, "Invalid FbxSurfaceMaterial input to initialize FbxMaterialWrapper"); - } - - AZStd::string FbxMaterialWrapper::GetName() const - { - return m_fbxMaterial->GetInitialName(); - } - - AZ::Vector3 FbxMaterialWrapper::GetDiffuseColor() const - { - if (m_fbxMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId)) - { - FbxSurfaceLambert* lambertMat = static_cast(m_fbxMaterial); - const FbxDouble3 fbxValue = lambertMat->Diffuse.Get(); - const float power = static_cast(lambertMat->DiffuseFactor.Get()); - return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); - } - else if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) - { - FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); - const FbxDouble3 fbxValue = phongMat->Diffuse.Get(); - const float power = static_cast(phongMat->DiffuseFactor.Get()); - return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); - } - - return AZ::Vector3::CreateOne(); - } - - AZ::Vector3 FbxMaterialWrapper::GetSpecularColor() const - { - if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) - { - FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); - const FbxDouble3 fbxValue = phongMat->Specular.Get(); - const float power = static_cast(phongMat->SpecularFactor.Get()); - return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); - } - - return AZ::Vector3::CreateZero(); - } - - AZ::Vector3 FbxMaterialWrapper::GetEmissiveColor() const - { - if (m_fbxMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId)) - { - FbxSurfaceLambert* lambertMat = static_cast(m_fbxMaterial); - const FbxDouble3 fbxValue = lambertMat->Emissive.Get(); - const float power = static_cast(lambertMat->EmissiveFactor.Get()); - return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); - } - else if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) - { - FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); - const FbxDouble3 fbxValue = phongMat->Emissive.Get(); - const float power = static_cast(phongMat->EmissiveFactor.Get()); - return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); - } - - return AZ::Vector3::CreateZero(); - } - - float FbxMaterialWrapper::GetShininess() const - { - if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) - { - FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); - return static_cast(phongMat->Shininess.Get()); - } - - return 10.f; - } - - AZ::u64 FbxMaterialWrapper::GetUniqueId() const - { - return m_fbxMaterial->GetUniqueID(); - } - - float FbxMaterialWrapper::GetOpacity() const - { - // FBX materials are erroneously reporting a TransparencyFactor of 1.0 (fully transparent) - // even for values that are 0.0 in Maya. It is instead storing it in the components - // for TransparentColor, so extract from there instead. - - if (m_fbxMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId)) - { - FbxSurfaceLambert* lambertMat = static_cast(m_fbxMaterial); - const FbxDouble3 fbxValue = lambertMat->TransparentColor.Get(); - return 1.f - AZ::GetMin(AZ::GetMin(static_cast(fbxValue[0]), static_cast(fbxValue[1])), static_cast(fbxValue[2])); - } - else if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) - { - FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); - const FbxDouble3 fbxValue = phongMat->TransparentColor.Get(); - return 1.f - AZ::GetMin(AZ::GetMin(static_cast(fbxValue[0]), static_cast(fbxValue[1])), static_cast(fbxValue[2])); - } - - return 1.f; - } - - AZStd::string FbxMaterialWrapper::GetTextureFileName(const char* textureType) const - { - FbxFileTexture* fileTexture = nullptr; - FbxProperty property = m_fbxMaterial->FindProperty(textureType); - FbxDataType propertyType = property.GetPropertyDataType(); - - /// Engine currently doesn't support multiple textures. Right now we only use first texture of first layer. - int layeredTextureCount = property.GetSrcObjectCount(); - if (layeredTextureCount > 0) - { - FbxLayeredTexture* layeredTexture = FbxCast(property.GetSrcObject(0)); - int textureCount = layeredTexture->GetSrcObjectCount(); - if (textureCount > 0) - { - fileTexture = FbxCast(layeredTexture->GetSrcObject(0)); - } - } - else - { - int textureCount = property.GetSrcObjectCount(); - if (textureCount > 0) - { - fileTexture = FbxCast(property.GetSrcObject(0)); - } - } - - return fileTexture ? fileTexture->GetFileName() : AZStd::string(); - } - - AZStd::string FbxMaterialWrapper::GetTextureFileName(const AZStd::string& textureType) const - { - return GetTextureFileName(textureType.c_str()); - } - - AZStd::string FbxMaterialWrapper::GetTextureFileName(MaterialMapType textureType) const - { - switch (textureType) - { - case MaterialMapType::Diffuse: - return GetTextureFileName(FbxSurfaceMaterial::sDiffuse); - case MaterialMapType::Specular: - return GetTextureFileName(FbxSurfaceMaterial::sSpecular); - case MaterialMapType::Bump: - return GetTextureFileName(FbxSurfaceMaterial::sBump); - case MaterialMapType::Normal: - return GetTextureFileName(FbxSurfaceMaterial::sNormalMap); - default: - AZ_TraceContext("Unknown value", aznumeric_cast(textureType)); - AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unrecognized MaterialMapType retrieved"); - return AZStd::string(); - } - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMaterialWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMaterialWrapper.h deleted file mode 100644 index 0f195b939d..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMaterialWrapper.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxMaterialWrapper : public SDKMaterial::MaterialWrapper - { - public: - AZ_RTTI(FbxMaterialWrapper, "{227582F6-93BC-4E44-823E-FB1D631443A7}", SDKMaterial::MaterialWrapper); - - FbxMaterialWrapper(FbxSurfaceMaterial* fbxMaterial); - ~FbxMaterialWrapper() override = default; - - AZStd::string GetName() const override; - virtual AZStd::string GetTextureFileName(const char* textureType) const; - virtual AZStd::string GetTextureFileName(const AZStd::string& textureType) const; - AZStd::string GetTextureFileName(MaterialMapType textureType) const override; - - AZ::Vector3 GetDiffuseColor() const override; - AZ::Vector3 GetSpecularColor() const override; - AZ::Vector3 GetEmissiveColor() const override; - float GetOpacity() const override; - float GetShininess() const override; - AZ::u64 GetUniqueId() const override; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMeshWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMeshWrapper.cpp deleted file mode 100644 index b6778153c2..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMeshWrapper.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxMeshWrapper::FbxMeshWrapper(FbxMesh* fbxMesh) - : m_fbxMesh(fbxMesh) - { - AZ_Assert(fbxMesh, "Invalid FbxMesh input to initialize FbxMeshWrapper"); - } - - FbxMeshWrapper::~FbxMeshWrapper() - { - m_fbxMesh = nullptr; - } - - const char* FbxMeshWrapper::GetName() const - { - return m_fbxMesh->GetName(); - } - - int FbxMeshWrapper::GetDeformerCount() const - { - return m_fbxMesh->GetDeformerCount(); - } - - int FbxMeshWrapper::GetDeformerCount(int type) const - { - return m_fbxMesh->GetDeformerCount(static_cast(type)); - } - - int FbxMeshWrapper::GetControlPointsCount() const - { - return m_fbxMesh->GetControlPointsCount(); - } - - AZStd::vector FbxMeshWrapper::GetControlPoints() const - { - FbxVector4* controlPoints = m_fbxMesh->GetControlPoints(); - AZStd::vector azControlPoints; - azControlPoints.reserve(aznumeric_caster(GetControlPointsCount())); - for (int i = 0; i < GetControlPointsCount(); ++i) - { - azControlPoints.push_back(FbxTypeConverter::ToVector3(controlPoints[i])); - } - return azControlPoints; - } - - AZStd::shared_ptr FbxMeshWrapper::GetSkin(int index) const - { - FbxSkin* skin = static_cast(m_fbxMesh->GetDeformer(index, FbxDeformer::eSkin)); - return skin ? AZStd::make_shared(skin) : nullptr; - } - - AZStd::shared_ptr FbxMeshWrapper::GetBlendShape(int index) const - { - FbxBlendShape* blendShape = static_cast(m_fbxMesh->GetDeformer(index, FbxDeformer::eBlendShape)); - return blendShape ? AZStd::make_shared(blendShape) : nullptr; - } - - int FbxMeshWrapper::GetPolygonCount() const - { - return m_fbxMesh->GetPolygonCount(); - } - - int FbxMeshWrapper::GetPolygonSize(int polygonIndex) const - { - return m_fbxMesh->GetPolygonSize(polygonIndex); - } - - int* FbxMeshWrapper::GetPolygonVertices() const - { - return m_fbxMesh->GetPolygonVertices(); - } - - int FbxMeshWrapper::GetPolygonVertexIndex(int polygonIndex) const - { - return m_fbxMesh->GetPolygonVertexIndex(polygonIndex); - } - - bool FbxMeshWrapper::GetMaterialIndices(FbxLayerElementArrayTemplate** lockableArray) const - { - return m_fbxMesh->GetMaterialIndices(lockableArray); - } - - FbxUVWrapper FbxMeshWrapper::GetElementUV(int index) - { - return FbxUVWrapper(m_fbxMesh->GetElementUV(index)); - } - - FbxVertexTangentWrapper FbxMeshWrapper::GetElementTangent(int index) - { - return FbxVertexTangentWrapper(m_fbxMesh->GetElementTangent(index)); - } - - FbxVertexBitangentWrapper FbxMeshWrapper::GetElementBitangent(int index) - { - return FbxVertexBitangentWrapper(m_fbxMesh->GetElementBinormal(index)); - } - - int FbxMeshWrapper::GetElementUVCount() const - { - return m_fbxMesh->GetElementUVCount(); - } - - int FbxMeshWrapper::GetElementTangentCount() const - { - return m_fbxMesh->GetElementTangentCount(); - } - - int FbxMeshWrapper::GetElementBitangentCount() const - { - return m_fbxMesh->GetElementBinormalCount(); - } - - FbxVertexColorWrapper FbxMeshWrapper::GetElementVertexColor(int index) - { - return FbxVertexColorWrapper(m_fbxMesh->GetElementVertexColor(index)); - } - - int FbxMeshWrapper::GetElementVertexColorCount() const - { - return m_fbxMesh->GetElementVertexColorCount(); - } - - bool FbxMeshWrapper::GetPolygonVertexNormal(int polyIndex, int vertexIndex, Vector3& normal) const - { - FbxVector4 fbxNormal; - bool hasVertexNormal = m_fbxMesh->GetPolygonVertexNormal(polyIndex, vertexIndex, fbxNormal); - normal = FbxTypeConverter::ToVector3(fbxNormal); - return hasVertexNormal; - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMeshWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMeshWrapper.h deleted file mode 100644 index 80912d1a1b..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxMeshWrapper.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxSkinWrapper; - class FbxBlendShapeWrapper; - class FbxVertexTangentWrapper; - class FbxVertexBitangentWrapper; - - class FbxMeshWrapper - { - public: - FbxMeshWrapper(FbxMesh* fbxMesh); - virtual ~FbxMeshWrapper(); - - virtual const char* GetName() const; - - virtual int GetDeformerCount() const; - virtual int GetDeformerCount(int type) const; - virtual AZStd::shared_ptr GetSkin(int index) const; - virtual AZStd::shared_ptr GetBlendShape(int index) const; - virtual bool GetMaterialIndices(FbxLayerElementArrayTemplate** lockableArray) const; - - // Vertex positions access - // Get the control points number - virtual int GetControlPointsCount() const; - - // Get the array of control points - virtual AZStd::vector GetControlPoints() const; - - // Polygon data accesses - // Get the polygon count of this mesh - virtual int GetPolygonCount() const; - - // Get the number of polygon vertices in a polygon - virtual int GetPolygonSize(int polygonIndex) const; - - // Get the array of polygon vertices (i.e: indices to the control points) - virtual int* GetPolygonVertices() const; - - // Gets the start index into the array returned by GetPolygonVertices() for the given polygon - virtual int GetPolygonVertexIndex(int polygonIndex) const; - - // Vertex colors and UV textures accesses - // Returns this geometry's UV element - virtual FbxUVWrapper GetElementUV(int index = 0); - - virtual int GetElementUVCount() const; - - virtual int GetElementTangentCount() const; - virtual int GetElementBitangentCount() const; - virtual FbxVertexTangentWrapper GetElementTangent(int index = 0); - virtual FbxVertexBitangentWrapper GetElementBitangent(int index = 0); - - // Returns this geometry's vertex color element - virtual FbxVertexColorWrapper GetElementVertexColor(int index = 0); - - virtual int GetElementVertexColorCount() const; - - // Get the normal associated with the specified polygon vertex - virtual bool GetPolygonVertexNormal(int polyIndex, int vertexIndex, Vector3& normal) const; - - protected: - FbxMeshWrapper() = default; - FbxMesh* m_fbxMesh; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxNodeWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxNodeWrapper.cpp deleted file mode 100644 index 92621c2ce4..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxNodeWrapper.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxNodeWrapper::FbxNodeWrapper(FbxNode* fbxNode) - : NodeWrapper(fbxNode) - { - AZ_Assert(fbxNode, "Invalid FbxNode to initialize FbxNodeWrapper"); - } - - FbxNodeWrapper::~FbxNodeWrapper() - { - } - - - int FbxNodeWrapper::GetMaterialCount() const - { - return m_fbxNode->GetMaterialCount(); - } - - const char* FbxNodeWrapper::GetMaterialName(int index) const - { - if (index < GetMaterialCount()) - { - return m_fbxNode->GetMaterial(index)->GetName(); - } - AZ_Assert(index < GetMaterialCount(), "Invalid material index %d", index); - return nullptr; - } - - const std::shared_ptr FbxNodeWrapper::GetMesh() const - { - FbxMesh* mesh = m_fbxNode->GetMesh(); - return mesh ? std::shared_ptr(new FbxMeshWrapper(mesh)) : nullptr; - } - - const std::shared_ptr FbxNodeWrapper::FindProperty(const char* name) const - { - FbxProperty propertyName = m_fbxNode->FindProperty(name); - return std::shared_ptr(new FbxPropertyWrapper(&propertyName)); - } - - bool FbxNodeWrapper::IsBone() const - { - return (m_fbxNode->GetSkeleton() != nullptr); - } - - bool FbxNodeWrapper::IsMesh() const - { - return (m_fbxNode->GetMesh() != nullptr); - } - - const char* FbxNodeWrapper::GetName() const - { - return m_fbxNode->GetName(); - } - - AZ::u64 FbxNodeWrapper::GetUniqueId() const - { - return m_fbxNode->GetUniqueID(); - } - - SceneAPI::DataTypes::MatrixType FbxNodeWrapper::EvaluateGlobalTransform() - { - return FbxTypeConverter::ToTransform(m_fbxNode->EvaluateGlobalTransform()); - } - - Vector3 FbxNodeWrapper::EvaluateLocalTranslation() - { - return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTranslation()); - } - - Vector3 FbxNodeWrapper::EvaluateLocalTranslation(FbxTimeWrapper& time) - { - return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTranslation(time.m_fbxTime)); - } - - SceneAPI::DataTypes::MatrixType FbxNodeWrapper::EvaluateLocalTransform() - { - return FbxTypeConverter::ToTransform(m_fbxNode->EvaluateLocalTransform()); - } - - SceneAPI::DataTypes::MatrixType FbxNodeWrapper::EvaluateLocalTransform(FbxTimeWrapper& time) - { - return FbxTypeConverter::ToTransform(m_fbxNode->EvaluateLocalTransform(time.m_fbxTime)); - } - - Vector3 FbxNodeWrapper::EvaluateLocalRotation() - { - return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTransform().GetR()); - } - - Vector3 FbxNodeWrapper::EvaluateLocalRotation(FbxTimeWrapper& time) - { - return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTransform(time.m_fbxTime).GetR()); - } - - Vector3 FbxNodeWrapper::GetGeometricTranslation() const - { - return FbxTypeConverter::ToVector3(m_fbxNode->GetGeometricTranslation(FbxNode::eSourcePivot)); - } - - Vector3 FbxNodeWrapper::GetGeometricScaling() const - { - return FbxTypeConverter::ToVector3(m_fbxNode->GetGeometricScaling(FbxNode::eSourcePivot)); - } - - Vector3 FbxNodeWrapper::GetGeometricRotation() const - { - return FbxTypeConverter::ToVector3(m_fbxNode->GetGeometricRotation(FbxNode::eSourcePivot)); - } - - SceneAPI::DataTypes::MatrixType FbxNodeWrapper::GetGeometricTransform() const - { - FbxAMatrix geoTransform(m_fbxNode->GetGeometricTranslation(FbxNode::eSourcePivot), - m_fbxNode->GetGeometricRotation(FbxNode::eSourcePivot), m_fbxNode->GetGeometricScaling(FbxNode::eSourcePivot)); - return FbxTypeConverter::ToTransform(geoTransform); - } - - const AZStd::shared_ptr FbxNodeWrapper::GetLocalTranslationCurve(const AZStd::shared_ptr& layer, - CurveNodeComponent component) const - { - if (!layer) - { - return nullptr; - } - const char* componentString = nullptr; - switch (component) - { - case Component_X: - componentString = FBXSDK_CURVENODE_COMPONENT_X; - break; - case Component_Y: - componentString = FBXSDK_CURVENODE_COMPONENT_Y; - break; - case Component_Z: - componentString = FBXSDK_CURVENODE_COMPONENT_Z; - break; - default: - break; - } - // If there is available animation curve data of specified component/channel for translation, create and return a wrapped version of it. - return m_fbxNode->LclTranslation.GetCurve(layer->m_fbxAnimLayer, componentString) ? - AZStd::make_shared(m_fbxNode->LclTranslation.GetCurve(layer->m_fbxAnimLayer, componentString)) : nullptr; - } - - const AZStd::shared_ptr FbxNodeWrapper::GetLocalRotationCurve(const AZStd::shared_ptr& layer, - CurveNodeComponent component) const - { - if (!layer) - { - return nullptr; - } - const char* componentString = nullptr; - switch (component) - { - case Component_X: - componentString = FBXSDK_CURVENODE_COMPONENT_X; - break; - case Component_Y: - componentString = FBXSDK_CURVENODE_COMPONENT_Y; - break; - case Component_Z: - componentString = FBXSDK_CURVENODE_COMPONENT_Z; - break; - default: - break; - } - // If there is available animation curve data of specified component/channel for rotation, create and return a wrapped version of it. - return m_fbxNode->LclRotation.GetCurve(layer->m_fbxAnimLayer, componentString) ? - AZStd::make_shared(m_fbxNode->LclRotation.GetCurve(layer->m_fbxAnimLayer, componentString)) : nullptr; - } - - bool FbxNodeWrapper::IsAnimated() const - { - return FbxAnimUtilities::IsAnimated(m_fbxNode); - } - - int FbxNodeWrapper::GetChildCount() const - { - return m_fbxNode->GetChildCount(); - } - - const std::shared_ptr FbxNodeWrapper::GetChild(int childIndex) const - { - FbxNode* child = m_fbxNode->GetChild(childIndex); - AZ_Assert(child, "Cannot get child FbxNode at index %d", childIndex); - return child ? std::shared_ptr(new FbxNodeWrapper(child)) : nullptr; - } - - const std::shared_ptr FbxNodeWrapper::GetMaterial(int index) const - { - if (index < GetMaterialCount()) - { - return std::shared_ptr(new FbxMaterialWrapper(m_fbxNode->GetMaterial(index))); - } - AZ_Assert(index < GetMaterialCount(), "Invalid material index %d", index); - return nullptr; - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxNodeWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxNodeWrapper.h deleted file mode 100644 index fceebc96d4..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxNodeWrapper.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxMaterialWrapper; - class FbxAnimLayerWrapper; - class FbxAnimCurveWrapper; - - class FbxNodeWrapper : public SDKNode::NodeWrapper - { - public: - AZ_RTTI(FbxNodeWrapper, "{5F1C09D1-791C-41CA-94DB-D7DD2810C859}", SDKNode::NodeWrapper); - FbxNodeWrapper(FbxNode* fbxNode); - ~FbxNodeWrapper() override; - - int GetMaterialCount() const override; - virtual const char* GetMaterialName(int index) const; - virtual const std::shared_ptr GetMaterial(int index) const; - virtual const std::shared_ptr GetMesh() const; - virtual const std::shared_ptr FindProperty(const char* name) const; - virtual bool IsBone() const; - virtual bool IsMesh() const; - const char* GetName() const override; - AZ::u64 GetUniqueId() const override; - - virtual SceneAPI::DataTypes::MatrixType EvaluateGlobalTransform(); - virtual Vector3 EvaluateLocalTranslation(); - virtual Vector3 EvaluateLocalTranslation(FbxTimeWrapper& time); - virtual SceneAPI::DataTypes::MatrixType EvaluateLocalTransform(); - virtual SceneAPI::DataTypes::MatrixType EvaluateLocalTransform(FbxTimeWrapper& time); - virtual Vector3 EvaluateLocalRotation(); - virtual Vector3 EvaluateLocalRotation(FbxTimeWrapper& time); - virtual Vector3 GetGeometricTranslation() const; - virtual Vector3 GetGeometricScaling() const; - virtual Vector3 GetGeometricRotation() const; - virtual SceneAPI::DataTypes::MatrixType GetGeometricTransform() const; - virtual const AZStd::shared_ptr GetLocalTranslationCurve(const AZStd::shared_ptr& layer, CurveNodeComponent component) const; - virtual const AZStd::shared_ptr GetLocalRotationCurve(const AZStd::shared_ptr& layer, CurveNodeComponent component) const; - - int GetChildCount() const override; - const std::shared_ptr GetChild(int childIndex) const override; - - virtual bool IsAnimated() const; - - protected: - FbxNodeWrapper() = default; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxPropertyWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxPropertyWrapper.cpp deleted file mode 100644 index 3e2e149a8c..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxPropertyWrapper.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxPropertyWrapper::FbxPropertyWrapper(FbxProperty* fbxProperty) - : m_fbxProperty(fbxProperty) - { - AZ_Assert(fbxProperty, "Invalid FbxProperty to initialize FbxPropertyWrapper"); - } - - FbxPropertyWrapper::~FbxPropertyWrapper() - { - m_fbxProperty = nullptr; - } - - bool FbxPropertyWrapper::IsValid() const - { - return m_fbxProperty->IsValid(); - } - - Vector3 FbxPropertyWrapper::GetFbxVector3() const - { - return FbxTypeConverter::ToVector3(m_fbxProperty->Get()); - } - - int FbxPropertyWrapper::GetFbxInt() const - { - return aznumeric_caster(m_fbxProperty->Get()); - } - - AZStd::string FbxPropertyWrapper::GetFbxString() const - { - return AZStd::string(m_fbxProperty->Get().Buffer()); - } - - const char* FbxPropertyWrapper::GetEnumValue(int index) const - { - return m_fbxProperty->GetEnumValue(index); - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxPropertyWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxPropertyWrapper.h deleted file mode 100644 index ffa174b0a9..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxPropertyWrapper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxPropertyWrapper - { - public: - FbxPropertyWrapper(FbxProperty* fbxProperty); - virtual ~FbxPropertyWrapper(); - - virtual bool IsValid() const; - virtual Vector3 GetFbxVector3() const; - virtual int GetFbxInt() const; - virtual AZStd::string GetFbxString() const; - virtual const char* GetEnumValue(int index) const; - - protected: - FbxProperty* m_fbxProperty; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSceneWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSceneWrapper.cpp deleted file mode 100644 index 0a1b8b50d8..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSceneWrapper.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxSceneWrapper::FbxSceneWrapper() - : SceneWrapperBase() - , m_fbxManager(nullptr) - , m_fbxImporter(nullptr) - , m_fbxIOSettings(nullptr) - { - } - - FbxSceneWrapper::FbxSceneWrapper(FbxScene* fbxScene) - : SceneWrapperBase(fbxScene) - , m_fbxManager(nullptr) - , m_fbxImporter(nullptr) - , m_fbxIOSettings(nullptr) - { - AZ_Assert(fbxScene, "FbxSceneWrapper should have a valid scene to initialize."); - } - - FbxSceneWrapper::~FbxSceneWrapper() - { - if (m_fbxScene) - { - m_fbxScene->Destroy(); - m_fbxScene = nullptr; - } - - if (m_fbxImporter) - { - m_fbxImporter->Destroy(); - m_fbxImporter = nullptr; - } - - if (m_fbxIOSettings) - { - m_fbxIOSettings->Destroy(); - m_fbxIOSettings = nullptr; - } - - if (m_fbxManager) - { - m_fbxManager->Destroy(); - m_fbxManager = nullptr; - } - } - - AZStd::shared_ptr FbxSceneWrapper::GetAxisSystem() const - { - return AZStd::make_shared(m_fbxScene->GetGlobalSettings().GetAxisSystem()); - } - - AZStd::shared_ptr FbxSceneWrapper::GetSystemUnit() const - { - return AZStd::make_shared(m_fbxScene->GetGlobalSettings().GetSystemUnit()); - } - - FbxTimeWrapper FbxSceneWrapper::GetTimeLineDefaultDuration() const - { - FbxTimeSpan timeSpan; - m_fbxScene->GetGlobalSettings().GetTimelineDefaultTimeSpan(timeSpan); - return FbxTimeWrapper(timeSpan.GetDuration()); - } - - const char* FbxSceneWrapper::GetLastSavedApplicationName() const - { - if (m_fbxScene->GetDocumentInfo()) - { - return m_fbxScene->GetDocumentInfo()->LastSaved_ApplicationName.Get().Buffer(); - } - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Cannot get valid document info from FbxScene"); - return nullptr; - } - - const char* FbxSceneWrapper::GetLastSavedApplicationVersion() const - { - if (m_fbxScene->GetDocumentInfo()) - { - return m_fbxScene->GetDocumentInfo()->LastSaved_ApplicationVersion.Get().Buffer(); - } - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Cannot get valid document info from FbxScene"); - return nullptr; - } - - const std::shared_ptr FbxSceneWrapper::GetRootNode() const - { - return std::shared_ptr(new FbxNodeWrapper(m_fbxScene->GetRootNode())); - } - - std::shared_ptr FbxSceneWrapper::GetRootNode() - { - return std::shared_ptr(new FbxNodeWrapper(m_fbxScene->GetRootNode())); - } - - int FbxSceneWrapper::GetAnimationStackCount() const - { - return m_fbxScene->GetSrcObjectCount(); - } - - const std::shared_ptr FbxSceneWrapper::GetAnimationStackAt(int index) const - { - return std::shared_ptr(new FbxAnimStackWrapper(FbxCast(m_fbxScene->GetSrcObject(index)))); - } - - bool FbxSceneWrapper::LoadSceneFromFile(const char* fileName) - { - AZ_TracePrintf(SceneAPI::Utilities::LogWindow, "FbxSceneWrapper::LoadSceneFromFile %s", fileName); - AZ_TraceContext("Filename", fileName); - - if (!m_fbxManager) - { - m_fbxManager = FbxManager::Create(); - if (!m_fbxManager) - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to create FbxManager"); - return false; - } - } - - if (!m_fbxIOSettings) - { - m_fbxIOSettings = FbxIOSettings::Create(m_fbxManager, IOSROOT); - if (!m_fbxIOSettings) - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to create FbxIOSettings"); - return false; - } - } - - m_fbxManager->SetIOSettings(m_fbxIOSettings); - - if (!m_fbxImporter) - { - m_fbxImporter = FbxImporter::Create(m_fbxManager, ""); - if (!m_fbxImporter) - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to create FbxImporter with FbxManager"); - return false; - } - } - - if (!m_fbxImporter->Initialize(fileName, -1, m_fbxManager->GetIOSettings())) - { - FbxString error = m_fbxImporter->GetStatus().GetErrorString(); - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to initialize FbxImporter with fbx file. Error returned: %s", error.Buffer()); - return false; - } - - // Create a new FBX scene so it can be populated by the imported file. - m_fbxScene = FbxScene::Create(m_fbxManager, s_defaultSceneName); - - if (!m_fbxScene) - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to create FbxScene"); - return false; - } - - if (!m_fbxImporter->Import(m_fbxScene)) - { - FbxString error = m_fbxImporter->GetStatus().GetErrorString(); - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to import FbxScene. Error returned: %s", error.Buffer()); - return false; - } - - return true; - } - - bool FbxSceneWrapper::LoadSceneFromFile(const AZStd::string& fileName) - { - return LoadSceneFromFile(fileName.c_str()); - } - - void FbxSceneWrapper::Clear() - { - if (m_fbxScene) - { - m_fbxScene->Clear(); - } - } - }//namespace FbxSDKWrapper - -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSceneWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSceneWrapper.h deleted file mode 100644 index f28ee6d7c3..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSceneWrapper.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// -// FBX SDK Wrapper -// provides isolation between AUTODESK FBX SDK and FBX Serializer -// provides necessary APIs for FBX Serializer -// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxSceneWrapper : public SDKScene::SceneWrapperBase - { - public: - AZ_RTTI(FbxSceneWrapper, "{63637E50-BB26-4BE9-AECD-D1168AE2355B}", SDKScene::SceneWrapperBase); - FbxSceneWrapper(); - FbxSceneWrapper(fbxsdk::FbxScene* fbxScene); - ~FbxSceneWrapper(); - - bool LoadSceneFromFile(const char* fileName) override; - bool LoadSceneFromFile(const AZStd::string& fileName) override; - - virtual AZStd::shared_ptr GetSystemUnit() const; - virtual AZStd::shared_ptr GetAxisSystem() const; - virtual FbxTimeWrapper GetTimeLineDefaultDuration() const; - virtual const char* GetLastSavedApplicationName() const; - virtual const char* GetLastSavedApplicationVersion() const; - const std::shared_ptr GetRootNode() const override; - std::shared_ptr GetRootNode() override; - virtual int GetAnimationStackCount() const; - virtual const std::shared_ptr GetAnimationStackAt(int index) const; - void Clear() override; - - protected: - FbxManager* m_fbxManager; - FbxImporter* m_fbxImporter; - FbxIOSettings* m_fbxIOSettings; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSkinWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSkinWrapper.cpp deleted file mode 100644 index 04b90ed6a3..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSkinWrapper.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxSkinWrapper::FbxSkinWrapper(FbxSkin* fbxSkin) - : m_fbxSkin(fbxSkin) - { - AZ_Assert(fbxSkin, "Invalid FbxSkin input to initialize FbxSkinWrapper"); - } - - FbxSkinWrapper::~FbxSkinWrapper() - { - m_fbxSkin = nullptr; - } - - const char* FbxSkinWrapper::GetName() const - { - return m_fbxSkin->GetName(); - } - - int FbxSkinWrapper::GetClusterCount() const - { - return m_fbxSkin->GetClusterCount(); - } - - int FbxSkinWrapper::GetClusterControlPointIndicesCount(int index) const - { - if (index < m_fbxSkin->GetClusterCount()) - { - return m_fbxSkin->GetCluster(index)->GetControlPointIndicesCount(); - } - AZ_Assert(index < m_fbxSkin->GetClusterCount(), "Invalid skin cluster index %d", index); - return 0; - } - - int FbxSkinWrapper::GetClusterControlPointIndex(int clusterIndex, int pointIndex) const - { - bool validIndex = clusterIndex < m_fbxSkin->GetClusterCount() && pointIndex < m_fbxSkin->GetCluster(clusterIndex)->GetControlPointIndicesCount(); - if (validIndex) - { - return m_fbxSkin->GetCluster(clusterIndex)->GetControlPointIndices()[pointIndex]; - } - AZ_Assert(validIndex, "Invalid skin cluster control point index at cluster index %d control point index %d", clusterIndex, pointIndex); - return -1; - } - - double FbxSkinWrapper::GetClusterControlPointWeight(int clusterIndex, int pointIndex) const - { - bool validIndex = clusterIndex < m_fbxSkin->GetClusterCount() && pointIndex < m_fbxSkin->GetCluster(clusterIndex)->GetControlPointIndicesCount(); - if (validIndex) - { - return m_fbxSkin->GetCluster(clusterIndex)->GetControlPointWeights()[pointIndex]; - } - AZ_Assert(validIndex, "Invalid skin cluster control point weight at cluster index %d control point index %d", clusterIndex, pointIndex); - return 0.0f; - } - - AZStd::shared_ptr FbxSkinWrapper::GetClusterLink(int index) const - { - if (index < m_fbxSkin->GetClusterCount()) - { - return AZStd::make_shared(m_fbxSkin->GetCluster(index)->GetLink()); - } - AZ_Assert(index < m_fbxSkin->GetClusterCount(), "Invalid skin cluster index %d", index); - return nullptr; - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSkinWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSkinWrapper.h deleted file mode 100644 index 1d31248f49..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSkinWrapper.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxNodeWrapper; - - class FbxSkinWrapper - { - public: - FbxSkinWrapper(FbxSkin* fbxSkin); - virtual ~FbxSkinWrapper(); - - virtual const char* GetName() const; - virtual int GetClusterCount() const; - virtual int GetClusterControlPointIndicesCount(int index) const; - virtual int GetClusterControlPointIndex(int clusterIndex, int pointIndex) const; - virtual double GetClusterControlPointWeight(int clusterIndex, int pointIndex) const; - virtual AZStd::shared_ptr GetClusterLink(int index) const; - - protected: - FbxSkinWrapper() = default; - FbxSkin* m_fbxSkin; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSystemUnitWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSystemUnitWrapper.cpp deleted file mode 100644 index 2171735c54..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSystemUnitWrapper.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxSystemUnitWrapper::FbxSystemUnitWrapper(const FbxSystemUnit& fbxSystemUnit) - : m_fbxSystemUnit(fbxSystemUnit) - { - } - - FbxSystemUnitWrapper::Unit FbxSystemUnitWrapper::GetUnit() const - { - if (m_fbxSystemUnit == FbxSystemUnit::mm) - { - return mm; - } - if (m_fbxSystemUnit == FbxSystemUnit::dm) - { - return dm; - } - if (m_fbxSystemUnit == FbxSystemUnit::cm) - { - return cm; - } - if (m_fbxSystemUnit == FbxSystemUnit::m) - { - return m; - } - if (m_fbxSystemUnit == FbxSystemUnit::km) - { - return km; - } - if (m_fbxSystemUnit == FbxSystemUnit::Inch) - { - return inch; - } - if (m_fbxSystemUnit == FbxSystemUnit::Foot) - { - return foot; - } - if (m_fbxSystemUnit == FbxSystemUnit::Mile) - { - return mile; - } - if (m_fbxSystemUnit == FbxSystemUnit::Yard) - { - return yard; - } - AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unrecognized current unit type"); - return unknown; - } - - float FbxSystemUnitWrapper::GetConversionFactorTo(Unit to) - { - FbxSystemUnit targetUnit; - switch (to) - { - case mm: - targetUnit = FbxSystemUnit::mm; - break; - case dm: - targetUnit = FbxSystemUnit::dm; - break; - case cm: - targetUnit = FbxSystemUnit::cm; - break; - case m: - targetUnit = FbxSystemUnit::m; - break; - case km: - targetUnit = FbxSystemUnit::km; - break; - case inch: - targetUnit = FbxSystemUnit::Inch; - break; - case foot: - targetUnit = FbxSystemUnit::Foot; - break; - case mile: - targetUnit = FbxSystemUnit::Mile; - break; - case yard: - targetUnit = FbxSystemUnit::Yard; - break; - default: - AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unrecognized unit conversion target type"); - targetUnit = FbxSystemUnit::m; - } - return aznumeric_caster(m_fbxSystemUnit.GetConversionFactorTo(targetUnit)); - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSystemUnitWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSystemUnitWrapper.h deleted file mode 100644 index 8973a68694..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxSystemUnitWrapper.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxSystemUnitWrapper - { - public: - enum Unit - { - mm, - dm, - cm, - m, - km, - inch, - foot, - mile, - yard, - unknown - }; - - FbxSystemUnitWrapper() = default; - FbxSystemUnitWrapper(const FbxSystemUnit& fbxSystemUnit); - virtual ~FbxSystemUnitWrapper() = default; - - virtual Unit GetUnit() const; - virtual float GetConversionFactorTo(Unit to); - - protected: - FbxSystemUnit m_fbxSystemUnit; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeSpanWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeSpanWrapper.cpp deleted file mode 100644 index 9e92a109e2..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeSpanWrapper.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxTimeSpanWrapper::FbxTimeSpanWrapper(const FbxTimeSpan& fbxTimeSpan) - : m_fbxTimeSpan(fbxTimeSpan) - { - } - - FbxTimeWrapper FbxTimeSpanWrapper::GetStartTime() const - { - return FbxTimeWrapper(m_fbxTimeSpan.GetStart()); - } - - FbxTimeWrapper FbxTimeSpanWrapper::GetStopTime() const - { - return FbxTimeWrapper(m_fbxTimeSpan.GetStop()); - } - - double FbxTimeSpanWrapper::GetFrameRate() const - { - return FbxTimeWrapper(m_fbxTimeSpan.GetStart()).GetFrameRate(); - } - - int64_t FbxTimeSpanWrapper::GetNumFrames() const - { - return GetStopTime().GetFrameCount() - GetStartTime().GetFrameCount() + 1; - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeSpanWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeSpanWrapper.h deleted file mode 100644 index 4dfdcc2da5..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeSpanWrapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxTimeSpanWrapper - { - public: - FbxTimeSpanWrapper(const FbxTimeSpan& fbxTimeSpan); - virtual ~FbxTimeSpanWrapper() = default; - - virtual FbxTimeWrapper GetStartTime() const; - virtual FbxTimeWrapper GetStopTime() const; - virtual double GetFrameRate() const; - int64_t GetNumFrames() const; - - protected: - FbxTimeSpan m_fbxTimeSpan; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeWrapper.cpp deleted file mode 100644 index 3b6c555fe1..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeWrapper.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxTimeWrapper::FbxTimeWrapper() : m_fbxTime(FBXSDK_TIME_INFINITE) - { - } - - FbxTimeWrapper::FbxTimeWrapper(const FbxTime& fbxTime) : m_fbxTime(fbxTime) - { - } - - FbxTimeWrapper::~FbxTimeWrapper() - { - } - - void FbxTimeWrapper::SetFrame(int64_t frames, TimeMode timeMode) - { - m_fbxTime.SetFrame(static_cast(frames), GetFbxTimeMode(timeMode)); - } - - void FbxTimeWrapper::SetTime(double time) - { - m_fbxTime.SetSecondDouble(time); - } - - double FbxTimeWrapper::GetFrameRate() const - { - return m_fbxTime.GetFrameRate(m_fbxTime.GetGlobalTimeMode()); - } - - int64_t FbxTimeWrapper::GetFrameCount() const - { - return static_cast(m_fbxTime.GetFrameCount()); - } - - double FbxTimeWrapper::GetTime() const - { - return m_fbxTime.GetSecondDouble(); - } - - FbxTime::EMode FbxTimeWrapper::GetFbxTimeMode(TimeMode timeMode) const - { - switch (timeMode) - { - case frames60: - return FbxTime::eFrames60; - case frames30: - return FbxTime::eFrames30; - case frames24: - return FbxTime::eFrames24; - case defaultMode: - return FbxTime::eDefaultMode; - default: - AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unsupported frame rate"); - return FbxTime::eDefaultMode; - } - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeWrapper.h deleted file mode 100644 index 6f00670025..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTimeWrapper.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxTimeWrapper - { - friend class FbxNodeWrapper; - friend class FbxAnimCurveWrapper; - public: - enum TimeMode - { - defaultMode, - frames60, - frames30, - frames24, - eModesCount - }; - - FbxTimeWrapper(); - FbxTimeWrapper(const FbxTime& fbxTime); - virtual ~FbxTimeWrapper(); - - virtual void SetFrame(int64_t frames, TimeMode timeMode = defaultMode); - virtual void SetTime(double time); - virtual double GetFrameRate() const; - virtual int64_t GetFrameCount() const; - virtual double GetTime() const; - - protected: - FbxTime::EMode GetFbxTimeMode(TimeMode timeMode) const; - - FbxTime m_fbxTime; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTypeConverter.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTypeConverter.cpp deleted file mode 100644 index 7bf1d719df..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTypeConverter.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - Vector2 FbxTypeConverter::ToVector2(const FbxVector2& vector) - { - return Vector2(static_cast(vector[0]), - static_cast(vector[1])); - } - - Vector3 FbxTypeConverter::ToVector3(const FbxVector4& vector) - { - // Note: FbxVector4[x] is of type FbxDouble and aznumeric_caster does not accept it as cast from type. - return Vector3(static_cast(vector[0]), - static_cast(vector[1]), - static_cast(vector[2])); - } - - SceneAPI::DataTypes::MatrixType FbxTypeConverter::ToTransform(const FbxAMatrix& matrix) - { - SceneAPI::DataTypes::MatrixType transform; - for (int row = 0; row < 3; ++row) - { - FbxVector4 line = matrix.GetColumn(row); - for (int column = 0; column < 4; ++column) - { - // Note: FbxVector4[x] is of type FbxDouble and aznumeric_caster does not accept it as cast from type. - transform.SetElement(row, column, static_cast(line[column])); - } - } - return transform; - } - - SceneAPI::DataTypes::MatrixType FbxTypeConverter::ToTransform(const FbxMatrix& matrix) - { - // This implementation ignores the last row, effectively assuming it to be (0,0,0,1) - SceneAPI::DataTypes::MatrixType transform; - for (int row = 0; row < 3; ++row) - { - FbxVector4 line = matrix.GetColumn(row); - for (int column = 0; column < 4; ++column) - { - // Note: FbxVector4[x] is of type FbxDouble and aznumeric_caster does not accept it as cast from type. - transform.SetElement(row, column, static_cast(line[column])); - } - } - return transform; - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTypeConverter.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTypeConverter.h deleted file mode 100644 index b670bc3770..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxTypeConverter.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxTypeConverter - { - public: - static Vector2 ToVector2(const FbxVector2& vector); - static Vector3 ToVector3(const FbxVector4& vector); - static SceneAPI::DataTypes::MatrixType ToTransform(const FbxAMatrix& matrix); - static SceneAPI::DataTypes::MatrixType ToTransform(const FbxMatrix& matrix); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxUVWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxUVWrapper.cpp deleted file mode 100644 index 8c7538b54e..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxUVWrapper.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxUVWrapper::FbxUVWrapper(FbxGeometryElementUV* fbxUV) - : m_fbxUV(fbxUV) - { - AZ_Assert(fbxUV, "Invalid FbxGeometryElementUV to initialize FbxUVWrapper") - } - - FbxUVWrapper::~FbxUVWrapper() - { - m_fbxUV = nullptr; - } - - const char* FbxUVWrapper::GetName() const - { - if (m_fbxUV) - { - return m_fbxUV->GetName(); - } - return nullptr; - } - - Vector2 FbxUVWrapper::GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const - { - FbxVector2 uv; - FbxLayerElementUtilities::GetGeometryElement(uv, m_fbxUV, polygonIndex, polygonVertexIndex, controlPointIndex); - return FbxTypeConverter::ToVector2(uv); - } - - bool FbxUVWrapper::IsValid() const - { - return m_fbxUV != nullptr; - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxUVWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxUVWrapper.h deleted file mode 100644 index 23bd77f4df..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxUVWrapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxUVWrapper - { - public: - FbxUVWrapper(FbxGeometryElementUV* fbxUV); - ~FbxUVWrapper(); - - Vector2 GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const; - const char* GetName() const; - bool IsValid() const; - - protected: - FbxGeometryElementUV* m_fbxUV; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexBitangentWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexBitangentWrapper.cpp deleted file mode 100644 index eeb3eb8f8e..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexBitangentWrapper.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxVertexBitangentWrapper::FbxVertexBitangentWrapper(FbxGeometryElementBinormal* fbxBitangent) - : m_fbxBitangent(fbxBitangent) - { - AZ_Assert(fbxBitangent, "Invalid FbxGeometryElementBinormal to initialize FbxVertexBitangentWrapper") - } - - - FbxVertexBitangentWrapper::~FbxVertexBitangentWrapper() - { - m_fbxBitangent = nullptr; - } - - - const char* FbxVertexBitangentWrapper::GetName() const - { - if (m_fbxBitangent) - { - return m_fbxBitangent->GetName(); - } - return ""; - } - - - Vector3 FbxVertexBitangentWrapper::GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const - { - FbxVector4 bitangent; - FbxLayerElementUtilities::GetGeometryElement(bitangent, m_fbxBitangent, polygonIndex, polygonVertexIndex, controlPointIndex); - return FbxTypeConverter::ToVector3(bitangent); - } - - - bool FbxVertexBitangentWrapper::IsValid() const - { - return m_fbxBitangent != nullptr; - } - - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexBitangentWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexBitangentWrapper.h deleted file mode 100644 index 51a9e3c1d4..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexBitangentWrapper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - - class FbxVertexBitangentWrapper - { - public: - FbxVertexBitangentWrapper(FbxGeometryElementBinormal* fbxBitangent); - ~FbxVertexBitangentWrapper(); - - Vector3 GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const; - const char* GetName() const; - bool IsValid() const; - - protected: - FbxGeometryElementBinormal* m_fbxBitangent; - }; - - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexColorWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexColorWrapper.cpp deleted file mode 100644 index 9a3aaf1328..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexColorWrapper.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - FbxColorWrapper::FbxColorWrapper(FbxColor& fbxColor) - : m_fbxColor(fbxColor) - { - } - - float FbxColorWrapper::GetR() const - { - return aznumeric_caster(m_fbxColor.mRed); - } - - float FbxColorWrapper::GetG() const - { - return aznumeric_caster(m_fbxColor.mGreen); - } - - float FbxColorWrapper::GetB() const - { - return aznumeric_caster(m_fbxColor.mBlue); - } - - float FbxColorWrapper::GetAlpha() const - { - return aznumeric_caster(m_fbxColor.mAlpha); - } - - FbxVertexColorWrapper::FbxVertexColorWrapper(FbxGeometryElementVertexColor* fbxVertexColor) - : m_fbxVertexColor(fbxVertexColor) - { - AZ_Assert(m_fbxVertexColor, "Invalid FbxGeometryElementVertexColor to initialie FbxVertexColorWrapper"); - } - - FbxVertexColorWrapper::~FbxVertexColorWrapper() - { - m_fbxVertexColor = nullptr; - } - - const char* FbxVertexColorWrapper::GetName() const - { - if (m_fbxVertexColor) - { - return m_fbxVertexColor->GetName(); - } - return nullptr; - } - - FbxColorWrapper FbxVertexColorWrapper::GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const - { - FbxColor color; - FbxLayerElementUtilities::GetGeometryElement(color, m_fbxVertexColor, polygonIndex, polygonVertexIndex, controlPointIndex); - return FbxColorWrapper(color); - } - - bool FbxVertexColorWrapper::IsValid() const - { - return m_fbxVertexColor != nullptr; - } - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexColorWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexColorWrapper.h deleted file mode 100644 index af1c414acb..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexColorWrapper.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxColorWrapper - { - public: - FbxColorWrapper(FbxColor& fbxColor); - float GetR() const; - float GetG() const; - float GetB() const; - float GetAlpha() const; - - protected: - FbxColor m_fbxColor; - }; - - class FbxVertexColorWrapper - { - public: - FbxVertexColorWrapper(FbxGeometryElementVertexColor* fbxVertexColor); - ~FbxVertexColorWrapper(); - - FbxColorWrapper GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const; - const char* GetName() const; - bool IsValid() const; - - protected: - FbxGeometryElementVertexColor* m_fbxVertexColor; - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexTangentWrapper.cpp b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexTangentWrapper.cpp deleted file mode 100644 index bdf2ebd44b..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexTangentWrapper.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - - FbxVertexTangentWrapper::FbxVertexTangentWrapper(FbxGeometryElementTangent* fbxTangent) - : m_fbxTangent(fbxTangent) - { - AZ_Assert(fbxTangent, "Invalid FbxGeometryElementTangent to initialize FbxVertexTangentWrapper") - } - - - FbxVertexTangentWrapper::~FbxVertexTangentWrapper() - { - m_fbxTangent = nullptr; - } - - - const char* FbxVertexTangentWrapper::GetName() const - { - if (m_fbxTangent) - { - return m_fbxTangent->GetName(); - } - return ""; - } - - - Vector3 FbxVertexTangentWrapper::GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const - { - FbxVector4 tangent; - FbxLayerElementUtilities::GetGeometryElement(tangent, m_fbxTangent, polygonIndex, polygonVertexIndex, controlPointIndex); - return FbxTypeConverter::ToVector3(tangent); - } - - - bool FbxVertexTangentWrapper::IsValid() const - { - return m_fbxTangent != nullptr; - } - - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexTangentWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexTangentWrapper.h deleted file mode 100644 index 24cfebd3d5..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/FbxVertexTangentWrapper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - - class FbxVertexTangentWrapper - { - public: - FbxVertexTangentWrapper(FbxGeometryElementTangent* fbxTangent); - ~FbxVertexTangentWrapper(); - - Vector3 GetElementAt(int polygonIndex, int polygonVertexIndex, int controlPointIndex) const; - const char* GetName() const; - bool IsValid() const; - - protected: - FbxGeometryElementTangent* m_fbxTangent; - }; - - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxAnimStackWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxAnimStackWrapper.h deleted file mode 100644 index 122ab05ecb..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxAnimStackWrapper.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxAnimStackWrapper - : public FbxAnimStackWrapper - { - public: - MOCK_CONST_METHOD0(GetMemberCount, - int()); - MOCK_CONST_METHOD1(GetAnimationLayerAt, - FbxAnimLayer * (int index)); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxAxisSystemWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxAxisSystemWrapper.h deleted file mode 100644 index 7cd022ce50..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxAxisSystemWrapper.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxAxisSystemWrapper - : public FbxAxisSystemWrapper - { - public: - MOCK_CONST_METHOD1(GetUpVector, - UpVector(int)); - MOCK_METHOD1(CalculateConversionTransform, - Transform(UpVector)); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxMaterialWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxMaterialWrapper.h deleted file mode 100644 index ac19831be7..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxMaterialWrapper.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxMaterialWrapper - : public FbxMaterialWrapper - { - public: - MOCK_CONST_METHOD0(GetName, - std::string()); - MOCK_CONST_METHOD1(GetTextureFileName, - std::string(const char* textureType)); - MOCK_CONST_METHOD1(GetTextureFileName, - std::string(const std::string& textureType)); - MOCK_CONST_METHOD1(GetTextureFileName, - std::string(MaterialMapType textureType)); - MOCK_CONST_METHOD0(IsNoDraw, - bool()); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxMeshWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxMeshWrapper.h deleted file mode 100644 index c498d56426..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxMeshWrapper.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxMeshWrapper - : public FbxMeshWrapper - { - public: - MOCK_CONST_METHOD0(GetDeformerCount, - int()); - MOCK_CONST_METHOD1(GetSkin, - AZStd::shared_ptr(int index)); - MOCK_CONST_METHOD1(GetMaterialIndices, - bool(FbxLayerElementArrayTemplate**)); - MOCK_CONST_METHOD0(GetControlPointsCount, - int()); - MOCK_CONST_METHOD0(GetControlPoints, - AZStd::vector()); - MOCK_CONST_METHOD0(GetPolygonCount, - int()); - MOCK_CONST_METHOD1(GetPolygonSize, - int(int)); - MOCK_CONST_METHOD1(GetPolygonVertics, - int(int index)); - MOCK_CONST_METHOD1(GetPolygonVertexIndex, - int(int)); - MOCK_CONST_METHOD1(GetElementUV, - FbxUVWrapper(int)); - MOCK_CONST_METHOD0(GetElementUVCount, - int()); - MOCK_CONST_METHOD1(GetElementVertexColor, - FbxVertexColorWrapper(int)); - MOCK_CONST_METHOD0(GetElementVertexColorCount, - int()); - MOCK_CONST_METHOD3(GetPolygonVertexNormal, - bool(int, int, Vector3&)); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxNodeWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxNodeWrapper.h deleted file mode 100644 index aa02d633b0..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxNodeWrapper.h +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxNodeWrapper - : public FbxNodeWrapper - { - public: - MOCK_CONST_METHOD0(GetMaterialCount, - int()); - MOCK_CONST_METHOD1(GetMaterialName, - const char*(int index)); - MOCK_CONST_METHOD1(GetMaterial, - const std::shared_ptr(int index)); - MOCK_CONST_METHOD0(GetMesh, - const std::shared_ptr()); - MOCK_CONST_METHOD1(FindProperty, - const std::shared_ptr(const char* name)); - MOCK_CONST_METHOD0(IsBone, - bool()); - MOCK_CONST_METHOD0(GetName, - const char*()); - MOCK_METHOD0(EvaluateGlobalTransform, - Transform()); - MOCK_METHOD0(EvaluateLocalTranslation, - Vector3()); - MOCK_METHOD1(EvaluateLocalTranslation, - Vector3(FbxTimeWrapper& time)); - MOCK_METHOD0(EvaluateLocalTransform, - Transform()); - MOCK_METHOD1(EvaluateLocalTransform, - Transform(FbxTimeWrapper& time)); - MOCK_CONST_METHOD0(GetGeometricTranslation, - Vector3()); - MOCK_CONST_METHOD0(GetGeometricScaling, - Vector3()); - MOCK_CONST_METHOD0(GetGeometricRotation, - Vector3()); - MOCK_CONST_METHOD0(GetGeometricTransform, - Transform()); - MOCK_CONST_METHOD0(GetChildCount, - int()); - MOCK_CONST_METHOD1(GetChild, - const std::shared_ptr(int childIndex)); - MOCK_CONST_METHOD0(IsAnimated, - bool()); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxPropertyWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxPropertyWrapper.h deleted file mode 100644 index f49521f136..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxPropertyWrapper.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxPropertyWrapper - : public FbxPropertyWrapper - { - public: - MockFbxPropertyWrapper() - : FbxPropertyWrapper(new FbxProperty()) - { - } - MOCK_CONST_METHOD0(IsValid, - bool()); - MOCK_CONST_METHOD0(GetFbxVector4, - Vector4()); - MOCK_CONST_METHOD0(GetFbxInt, - FbxInt()); - MOCK_CONST_METHOD0(GetFbxString, - AZStd::string()); - MOCK_CONST_METHOD1(GetEnumValue, - const char*(int index)); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSceneWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSceneWrapper.h deleted file mode 100644 index 8f3d1903ac..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSceneWrapper.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxSceneWrapper - : public FbxSceneWrapper - { - public: - virtual ~MockFbxSceneWrapper() = default; - - MOCK_METHOD1(LoadSceneFromFile, - bool(const char* fileName)); - MOCK_METHOD1(LoadSceneFromFile, - bool(const std::string& fileName)); - MOCK_CONST_METHOD0(GetSystemUnit, - AZStd::shared_ptr()); - MOCK_CONST_METHOD0(GetAxisSystem, - AZStd::shared_ptr()); - MOCK_CONST_METHOD0(GetTimeLineDefaultDuration, - FbxTimeWrapper()); - MOCK_CONST_METHOD0(GetLastSavedApplicationName, - const char*()); - MOCK_CONST_METHOD0(GetLastSavedApplicationVersion, - const char*()); - MOCK_CONST_METHOD0(GetRootNode, - const std::shared_ptr()); - MOCK_METHOD0(GetRootNode, - std::shared_ptr()); - MOCK_CONST_METHOD0(GetAnimationStackCount, - int()); - MOCK_CONST_METHOD1(GetAnimationStackAt, - const std::shared_ptr(int index)); - MOCK_METHOD0(Clear, - void()); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSkinWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSkinWrapper.h deleted file mode 100644 index dd17a12146..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSkinWrapper.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxSkinWrapper - : public FbxSkinWrapper - { - public: - MOCK_CONST_METHOD0(GetName, - const char*()); - MOCK_CONST_METHOD0(GetClusterCount, - int()); - MOCK_CONST_METHOD1(GetClusterControlPointIndicesCount, - int(int index)); - MOCK_CONST_METHOD2(GetClusterControlPointIndices, - int(int clusterIndex, int pointIndex)); - MOCK_CONST_METHOD2(GetClusterControlPointWeights, - double(int clusterIndex, int pointIndex)); - MOCK_CONST_METHOD1(GetClusterLink, - AZStd::shared_ptr(int index)); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSystemUnitWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSystemUnitWrapper.h deleted file mode 100644 index 822a700edd..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxSystemUnitWrapper.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxSystemUnitWrapper - : public FbxSystemUnitWrapper - { - public: - MOCK_CONST_METHOD0(GetUnit, - Unit()); - MOCK_METHOD1(GetConversionFactorTo, - float(Unit)); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxTimeWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxTimeWrapper.h deleted file mode 100644 index 6ab6194261..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxTimeWrapper.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxTimeWrapper - : public FbxTimeWrapper - { - public: - MOCK_METHOD2(SetFrame, - void(int64_t, TimeMode)); - MOCK_CONST_METHOD0(GetFrameRate, - double()); - MOCK_CONST_METHOD0(GetFrameCount, - int64_t()); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxUVWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxUVWrapper.h deleted file mode 100644 index 73fb2af587..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxUVWrapper.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxUVWrapper - : public FbxUVWrapper - { - public: - MOCK_CONST_METHOD3(GetElementAt, - Vector2(int, int, int)); - MOCK_CONST_METHOD0(GetName, - const char*()); - MOCK_CONST_METHOD0(IsValid, - bool()); - }; - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxVertexColorWrapper.h b/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxVertexColorWrapper.h deleted file mode 100644 index a2291807f6..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/Mocks/MockFbxVertexColorWrapper.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class MockFbxVertexColorWrapper - : public FbxVertexColorWrapper - { - public: - MOCK_CONST_METHOD3(GetElementAt, - FbxColorWrapper(int, int, int)); - MOCK_CONST_METHOD0(GetName, - const char*()); - MOCK_CONST_METHOD0(IsValid, - bool()); - }; - - } // namespace FbxSDKWrapper -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/fbxsdkwrapper_files.cmake b/Code/Tools/SceneAPI/FbxSDKWrapper/fbxsdkwrapper_files.cmake deleted file mode 100644 index a3bb994725..0000000000 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/fbxsdkwrapper_files.cmake +++ /dev/null @@ -1,69 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - FbxSceneWrapper.cpp - FbxAnimStackWrapper.cpp - FbxAnimLayerWrapper.cpp - FbxAnimCurveNodeWrapper.cpp - FbxAnimCurveWrapper.cpp - FbxNodeWrapper.cpp - FbxMeshWrapper.cpp - FbxSkinWrapper.cpp - FbxPropertyWrapper.cpp - FbxMaterialWrapper.cpp - FbxTimeWrapper.cpp - FbxTimeSpanWrapper.cpp - FbxTypeConverter.cpp - FbxAxisSystemWrapper.cpp - FbxSystemUnitWrapper.cpp - FbxVertexColorWrapper.cpp - FbxVertexTangentWrapper.cpp - FbxVertexBitangentWrapper.cpp - FbxUVWrapper.cpp - FbxBlendShapeWrapper.cpp - FbxBlendShapeChannelWrapper.cpp - FbxLayerElementUtilities.inl - FbxSceneWrapper.h - FbxAnimStackWrapper.h - FbxAnimLayerWrapper.h - FbxAnimCurveNodeWrapper.h - FbxAnimCurveWrapper.h - FbxNodeWrapper.h - FbxMeshWrapper.h - FbxSkinWrapper.h - FbxPropertyWrapper.h - FbxMaterialWrapper.h - FbxTimeWrapper.h - FbxTimeSpanWrapper.h - FbxTypeConverter.h - FbxAxisSystemWrapper.h - FbxSystemUnitWrapper.h - FbxVertexColorWrapper.h - FbxVertexTangentWrapper.h - FbxVertexBitangentWrapper.h - FbxUVWrapper.h - FbxBlendShapeWrapper.h - FbxBlendShapeChannelWrapper.h - FbxLayerElementUtilities.h - Mocks/MockFbxAnimStackWrapper.h - Mocks/MockFbxAxisSystemWrapper.h - Mocks/MockFbxMaterialWrapper.h - Mocks/MockFbxMeshWrapper.h - Mocks/MockFbxNodeWrapper.h - Mocks/MockFbxPropertyWrapper.h - Mocks/MockFbxSceneWrapper.h - Mocks/MockFbxSkinWrapper.h - Mocks/MockFbxSystemUnitWrapper.h - Mocks/MockFbxTimeWrapper.h - Mocks/MockFbxUVWrapper.h - Mocks/MockFbxVertexColorWrapper.h -) diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/CMakeLists.txt b/Code/Tools/SceneAPI/FbxSceneBuilder/CMakeLists.txt index fdd6f8b755..144191b286 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/CMakeLists.txt +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/CMakeLists.txt @@ -31,9 +31,9 @@ ly_add_target( AZ::AzFramework PUBLIC AZ::AzToolsFramework - AZ::FbxSDKWrapper AZ::SceneCore AZ::SceneData + AZ::SDKWrapper ) ly_add_target( diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/DllMain.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/DllMain.cpp index d567f1f9c5..3dc14814de 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/DllMain.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/DllMain.cpp @@ -31,18 +31,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include namespace AZ { @@ -78,18 +66,6 @@ namespace AZ g_componentDescriptors.push_back(FbxSceneBuilder::FbxImporter::CreateDescriptor()); // Node and attribute importers - g_componentDescriptors.push_back(FbxAnimationImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxBlendShapeImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxBoneImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxColorStreamImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxMaterialImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxMeshImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxSkinImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxSkinWeightsImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxTransformImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxUvMapImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxTangentStreamImporter::CreateDescriptor()); - g_componentDescriptors.push_back(FbxBitangentStreamImporter::CreateDescriptor()); g_componentDescriptors.push_back(AssImpBitangentStreamImporter::CreateDescriptor()); g_componentDescriptors.push_back(AssImpColorStreamImporter::CreateDescriptor()); g_componentDescriptors.push_back(AssImpMaterialImporter::CreateDescriptor()); diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.cpp index 650eb4c935..c7f7b4ad79 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.cpp @@ -20,13 +20,10 @@ #include #include #include -#include #include #include -#include +#include #include -#include -#include #include #include #include @@ -55,16 +52,7 @@ namespace AZ FbxImporter::FbxImporter() : m_sceneSystem(new FbxSceneSystem()) { - - if (m_useAssetImporterSDK) - { - m_sceneWrapper = AZStd::make_unique(); - } - else - { - m_sceneWrapper = AZStd::make_unique(); - } - + m_sceneWrapper = AZStd::make_unique(); BindToCall(&FbxImporter::ImportProcessing); } @@ -89,15 +77,13 @@ namespace AZ typedef AZStd::function ConvertFunc; ConvertFunc convertFunc; m_sceneSystem->Set(m_sceneWrapper.get()); - if (azrtti_istypeof(m_sceneWrapper.get())) - { - convertFunc = AZStd::bind(&FbxImporter::ConvertFbxSceneContext, this, AZStd::placeholders::_1); - } - else + if (!azrtti_istypeof(m_sceneWrapper.get())) { - convertFunc = AZStd::bind(&FbxImporter::ConvertFbxScene, this, AZStd::placeholders::_1); + return Events::ProcessingResult::Failure; } + convertFunc = AZStd::bind(&FbxImporter::ConvertFbxScene, this, AZStd::placeholders::_1); + if (convertFunc(context.GetScene())) { return Events::ProcessingResult::Success; @@ -108,175 +94,6 @@ namespace AZ } } - bool FbxImporter::ConvertFbxSceneContext(Containers::Scene& scene) const - { - std::shared_ptr fbxRoot = m_sceneWrapper->GetRootNode(); - if (!fbxRoot) - { - return false; - } - FbxSDKWrapper::FbxSceneWrapper* fbxSceneWrapper = azrtti_cast (m_sceneWrapper.get()); - int sign = 0; - FbxSDKWrapper::FbxAxisSystemWrapper::UpVector upVector = fbxSceneWrapper->GetAxisSystem()->GetUpVector(sign); - AZ_Assert(sign != 0, "sign failed to populate which is a failure in GetUpVector"); - - if (upVector == FbxSDKWrapper::FbxAxisSystemWrapper::UpVector::Z) - { - if (sign > 0) - { - scene.SetOriginalSceneOrientation(Containers::Scene::SceneOrientation::ZUp); - } - else - { - scene.SetOriginalSceneOrientation(Containers::Scene::SceneOrientation::NegZUp); - AZ_Assert(false, "Negative Z Up scene orientation is not a currently supported orientation."); - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Negative Z Up scene orientation is not a currently supported orientation."); - } - } - else if (upVector == FbxSDKWrapper::FbxAxisSystemWrapper::UpVector::Y) - { - if (sign > 0) - { - scene.SetOriginalSceneOrientation(Containers::Scene::SceneOrientation::YUp); - } - else - { - scene.SetOriginalSceneOrientation(Containers::Scene::SceneOrientation::NegYUp); - AZ_Assert(false, "Negative Y Up scene orientation is not a currently supported orientation."); - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Negative Y Up scene orientation is not a currently supported orientation."); - } - } - else if (upVector == FbxSDKWrapper::FbxAxisSystemWrapper::UpVector::X) - { - if (sign > 0) - { - scene.SetOriginalSceneOrientation(Containers::Scene::SceneOrientation::XUp); - AZ_Assert(false, "Positive X Up scene orientation is not a currently supported orientation."); - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Positive X Up scene orientation is not a currently supported orientation."); - } - else - { - scene.SetOriginalSceneOrientation(Containers::Scene::SceneOrientation::NegXUp); - AZ_Assert(false, "Negative X Up scene orientation is not a currently supported orientation."); - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Negative X Up scene orientation is not a currently supported orientation."); - } - } - - AZStd::queue nodes; - nodes.emplace(AZStd::move(fbxRoot), scene.GetGraph().GetRoot()); - - RenamedNodesMap nodeNameMap; - - while (!nodes.empty()) - { - FbxSceneBuilder::QueueNode& node = nodes.front(); - - AZ_Assert(node.m_node, "Empty fbx node queued"); - - if (!nodeNameMap.RegisterNode(node.m_node, scene.GetGraph(), node.m_parent)) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Failed to register fbx node in name table."); - continue; - } - AZStd::string nodeName = nodeNameMap.GetNodeName(node.m_node); - AZ_TraceContext("SceneAPI Node Name", nodeName); - - Containers::SceneGraph::NodeIndex newNode = scene.GetGraph().AddChild(node.m_parent, nodeName.c_str()); - AZ_Assert(newNode.IsValid(), "Failed to add node to scene graph"); - if (!newNode.IsValid()) - { - continue; - } - FbxNodeEncounteredContext sourceNodeEncountered(scene, newNode, *fbxSceneWrapper, *m_sceneSystem, nodeNameMap, *azrtti_cast(node.m_node.get())); - Events::ProcessingResultCombiner nodeResult; - nodeResult += Events::Process(sourceNodeEncountered); - - // If no importer created data, we still create an empty node that may eventually contain a transform - if (sourceNodeEncountered.m_createdData.empty()) - { - AZ_Assert(nodeResult.GetResult() != Events::ProcessingResult::Success, - "Importers returned success but no data was created"); - AZStd::shared_ptr nullData(nullptr); - sourceNodeEncountered.m_createdData.emplace_back(nullData); - nodeResult += Events::ProcessingResult::Success; - } - - // Create single node since only one piece of graph data was created - if (sourceNodeEncountered.m_createdData.size() == 1) - { - AZ_Assert(nodeResult.GetResult() != Events::ProcessingResult::Ignored, - "An importer created data, but did not return success"); - if (nodeResult.GetResult() == Events::ProcessingResult::Failure) - { - AZ_TracePrintf(Utilities::ErrorWindow, "One or more importers failed to create data."); - } - - SceneDataPopulatedContext dataProcessed(sourceNodeEncountered, - sourceNodeEncountered.m_createdData[0], nodeName.c_str()); - Events::ProcessingResult result = AddDataNodeWithContexts(dataProcessed); - if (result != Events::ProcessingResult::Failure) - { - newNode = dataProcessed.m_currentGraphPosition; - } - } - // Create an empty parent node and place all data under it. The remaining - // tree will be built off of this as the logical parent - else - { - AZ_Assert(nodeResult.GetResult() != Events::ProcessingResult::Ignored, - "%i importers created data, but did not return success", - sourceNodeEncountered.m_createdData.size()); - if (nodeResult.GetResult() == Events::ProcessingResult::Failure) - { - AZ_TracePrintf(Utilities::ErrorWindow, "One or more importers failed to create data."); - } - - size_t offset = nodeName.length(); - for (size_t i = 0; i < sourceNodeEncountered.m_createdData.size(); ++i) - { - nodeName += '_'; - nodeName += AZStd::to_string(aznumeric_cast(i + 1)); - - Containers::SceneGraph::NodeIndex subNode = - scene.GetGraph().AddChild(newNode, nodeName.c_str()); - AZ_Assert(subNode.IsValid(), "Failed to create new scene sub node"); - SceneDataPopulatedContext dataProcessed(sourceNodeEncountered, - sourceNodeEncountered.m_createdData[i], nodeName); - dataProcessed.m_currentGraphPosition = subNode; - AddDataNodeWithContexts(dataProcessed); - - // Remove the temporary extension again. - nodeName.erase(offset, nodeName.length() - offset); - } - } - - AZ_Assert(nodeResult.GetResult() == Events::ProcessingResult::Success, - "No importers successfully added processed scene data."); - AZ_Assert(newNode != node.m_parent, - "Failed to update current graph position during data processing."); - - int childCount = node.m_node->GetChildCount(); - for (int i = 0; i < childCount; ++i) - { - std::shared_ptr child = std::make_shared(node.m_node->GetChild(i)->GetFbxNode()); - if (child) - { - nodes.emplace(AZStd::move(child), newNode); - } - } - - nodes.pop(); - } - - Events::ProcessingResult result = Events::Process(scene, *fbxSceneWrapper, *m_sceneSystem, nodeNameMap); - if (result == Events::ProcessingResult::Failure) - { - return false; - } - - return true; - } - bool FbxImporter::ConvertFbxScene(Containers::Scene& scene) const { std::shared_ptr fbxRoot = m_sceneWrapper->GetRootNode(); diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.h index 5bf9ab84c9..5e35bcddc3 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.h +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/FbxImporter.h @@ -45,13 +45,11 @@ namespace AZ Events::ProcessingResult ImportProcessing(Events::ImportEventContext& context); protected: - bool ConvertFbxSceneContext(Containers::Scene& scene) const; bool ConvertFbxScene(Containers::Scene& scene) const; void SanitizeNodeName(AZStd::string& nodeName) const; AZStd::unique_ptr m_sceneWrapper; AZStd::shared_ptr m_sceneSystem; - bool m_useAssetImporterSDK = true; }; } // namespace FbxSceneBuilder } // namespace SceneAPI diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/FbxSceneSystem.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/FbxSceneSystem.cpp index af79ab86d3..31abaf0311 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/FbxSceneSystem.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/FbxSceneSystem.cpp @@ -11,8 +11,8 @@ */ #include -#include #include +#include #include #include #include @@ -33,103 +33,86 @@ namespace AZ void FbxSceneSystem::Set(const SDKScene::SceneWrapperBase* fbxScene) { // Get unit conversion factor to meter. - if (azrtti_istypeof(fbxScene)) + if (!azrtti_istypeof(fbxScene)) { - const FbxSDKWrapper::FbxSceneWrapper* fbxSDKScene = azrtti_cast (fbxScene); - m_unitSizeInMeters = fbxSDKScene->GetSystemUnit()->GetConversionFactorTo(FbxSDKWrapper::FbxSystemUnitWrapper::m); - const FbxGlobalSettings& globalSettings = fbxSDKScene->GetFbxScene()->GetGlobalSettings(); - m_originalUnitSizeInMeters = static_cast(globalSettings.GetOriginalSystemUnit().GetConversionFactorTo(FbxSystemUnit::m)); - - int sign = 0; - FbxSDKWrapper::FbxAxisSystemWrapper::UpVector upVector = fbxSDKScene->GetAxisSystem()->GetUpVector(sign); - - if (upVector != FbxSDKWrapper::FbxAxisSystemWrapper::Z && upVector != FbxSDKWrapper::FbxAxisSystemWrapper::Unknown) - { - m_adjustTransform.reset(new DataTypes::MatrixType(fbxSDKScene->GetAxisSystem()->CalculateConversionTransform(FbxSDKWrapper::FbxAxisSystemWrapper::Z))); - m_adjustTransformInverse.reset(new DataTypes::MatrixType(m_adjustTransform->GetInverseFull())); - } + return; } - else if (azrtti_istypeof(fbxScene)) - { - const AssImpSDKWrapper::AssImpSceneWrapper* assImpScene = azrtti_cast(fbxScene); - // If either meta data piece is not available, the default of 1 will be used. - assImpScene->GetAssImpScene()->mMetaData->Get("UnitScaleFactor", m_unitSizeInMeters); - assImpScene->GetAssImpScene()->mMetaData->Get("OriginalUnitScaleFactor", m_originalUnitSizeInMeters); + const AssImpSDKWrapper::AssImpSceneWrapper* assImpScene = azrtti_cast(fbxScene); - /* Conversion factor for converting from centimeters to meters */ - m_unitSizeInMeters = m_unitSizeInMeters *.01f; + // If either meta data piece is not available, the default of 1 will be used. + assImpScene->GetAssImpScene()->mMetaData->Get("UnitScaleFactor", m_unitSizeInMeters); + assImpScene->GetAssImpScene()->mMetaData->Get("OriginalUnitScaleFactor", m_originalUnitSizeInMeters); - AZStd::pair upAxisAndSign = assImpScene->GetUpVectorAndSign(); + /* Conversion factor for converting from centimeters to meters */ + m_unitSizeInMeters = m_unitSizeInMeters * .01f; - if (upAxisAndSign.second <= 0) - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Negative scene orientation is not a currently supported orientation."); - return; - } + AZStd::pair upAxisAndSign = assImpScene->GetUpVectorAndSign(); - AZStd::pair frontAxisAndSign = assImpScene->GetFrontVectorAndSign(); + if (upAxisAndSign.second <= 0) + { + AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Negative scene orientation is not a currently supported orientation."); + return; + } + AZStd::pair frontAxisAndSign = assImpScene->GetFrontVectorAndSign(); - if (upAxisAndSign.first != AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::Z && - upAxisAndSign.first != AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::Unknown) + if (upAxisAndSign.first != AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::Z && + upAxisAndSign.first != AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::Unknown) + { + AZ::Matrix4x4 currentCoordMatrix = AZ::Matrix4x4::CreateIdentity(); + //(UpVector = +Z, FrontVector = +Y, CoordSystem = -X(RightHanded)) + AZ::Matrix4x4 targetCoordMatrix = AZ::Matrix4x4::CreateFromColumns( + AZ::Vector4(-1, 0, 0, 0), + AZ::Vector4(0, 0, 1, 0), + AZ::Vector4(0, 1, 0, 0), + AZ::Vector4(0, 0, 0, 1)); + + switch (upAxisAndSign.first) { - AZ::Matrix4x4 currentCoordMatrix = AZ::Matrix4x4::CreateIdentity(); - //(UpVector = +Z, FrontVector = +Y, CoordSystem = -X(RightHanded)) - AZ::Matrix4x4 targetCoordMatrix = AZ::Matrix4x4::CreateFromColumns( - AZ::Vector4(-1, 0, 0, 0), - AZ::Vector4(0, 0, 1, 0), - AZ::Vector4(0, 1, 0, 0), - AZ::Vector4(0, 0, 0, 1)); - - switch (upAxisAndSign.first) + case AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::X: { + if (frontAxisAndSign.second == 1) + { + currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( + AZ::Vector4(0, -1, 0, 0), + AZ::Vector4(1, 0, 0, 0), + AZ::Vector4(0, 0, 1, 0), + AZ::Vector4(0, 0, 0, 1)); + } + else { - case AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::X: + currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( + AZ::Vector4(0, 1, 0, 0), + AZ::Vector4(1, 0, 0, 0), + AZ::Vector4(0, 0, -1, 0), + AZ::Vector4(0, 0, 0, 1)); + } + } + break; + case AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::Y: { + if (frontAxisAndSign.second == 1) { - if (frontAxisAndSign.second == 1) - { - currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( - AZ::Vector4(0, -1, 0, 0), - AZ::Vector4(1, 0, 0, 0), - AZ::Vector4(0, 0, 1, 0), - AZ::Vector4(0, 0, 0, 1)); - } - else - { - currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( - AZ::Vector4(0, 1, 0, 0), - AZ::Vector4(1, 0, 0, 0), - AZ::Vector4(0, 0, -1, 0), - AZ::Vector4(0, 0, 0, 1)); - } + currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( + AZ::Vector4(1, 0, 0, 0), + AZ::Vector4(0, 1, 0, 0), + AZ::Vector4(0, 0, 1, 0), + AZ::Vector4(0, 0, 0, 1)); } - break; - case AssImpSDKWrapper::AssImpSceneWrapper::AxisVector::Y: - { - if (frontAxisAndSign.second == 1) - { - currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( - AZ::Vector4(1, 0, 0, 0), - AZ::Vector4(0, 1, 0, 0), - AZ::Vector4(0, 0, 1, 0), - AZ::Vector4(0, 0, 0, 1)); - } - else - { - currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( - AZ::Vector4(-1, 0, 0, 0), - AZ::Vector4(0, 1, 0, 0), - AZ::Vector4(0, 0, -1, 0), - AZ::Vector4(0, 0, 0, 1)); - } - } - break; + else + { + currentCoordMatrix = AZ::Matrix4x4::CreateFromColumns( + AZ::Vector4(-1, 0, 0, 0), + AZ::Vector4(0, 1, 0, 0), + AZ::Vector4(0, 0, -1, 0), + AZ::Vector4(0, 0, 0, 1)); } - AZ::Matrix4x4 inverse = currentCoordMatrix.GetInverseTransform(); - AZ::Matrix4x4 adjustmatrix = targetCoordMatrix * currentCoordMatrix.GetInverseTransform(); - m_adjustTransform.reset(new DataTypes::MatrixType(AssImpSDKWrapper::AssImpTypeConverter::ToTransform(adjustmatrix))); - m_adjustTransformInverse.reset(new DataTypes::MatrixType(m_adjustTransform->GetInverseFull())); } + break; + } + AZ::Matrix4x4 inverse = currentCoordMatrix.GetInverseTransform(); + AZ::Matrix4x4 adjustmatrix = targetCoordMatrix * currentCoordMatrix.GetInverseTransform(); + m_adjustTransform.reset(new DataTypes::MatrixType(AssImpSDKWrapper::AssImpTypeConverter::ToTransform(adjustmatrix))); + m_adjustTransformInverse.reset(new DataTypes::MatrixType(m_adjustTransform->GetInverseFull())); } } diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/ImportContexts/FbxImportContexts.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/ImportContexts/FbxImportContexts.cpp deleted file mode 100644 index bbb1ac12ea..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/ImportContexts/FbxImportContexts.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxImportContext::FbxImportContext(const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, FbxSDKWrapper::FbxNodeWrapper& sourceNode) - : m_sourceScene(sourceScene) - , m_sourceSceneSystem(sourceSceneSystem) - , m_sourceNode(sourceNode) - { - } - - FbxNodeEncounteredContext::FbxNodeEncounteredContext(Containers::Scene& scene, - Containers::SceneGraph::NodeIndex currentGraphPosition, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode) - : FbxImportContext(sourceScene, sourceSceneSystem, sourceNode) - , NodeEncounteredContext(scene, currentGraphPosition, nodeNameMap) - { - } - - FbxNodeEncounteredContext::FbxNodeEncounteredContext( - Events::ImportEventContext& parent, Containers::SceneGraph::NodeIndex currentGraphPosition, - const FbxSDKWrapper::FbxSceneWrapper& sourceScene, const FbxSceneSystem& sourceSceneSystem, - RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode) - : FbxImportContext(sourceScene, sourceSceneSystem, sourceNode) - , NodeEncounteredContext(parent.GetScene(), currentGraphPosition, nodeNameMap) - { - } - - SceneDataPopulatedContext::SceneDataPopulatedContext(FbxNodeEncounteredContext& parent, - const AZStd::shared_ptr& graphData, const AZStd::string& dataName) - : FbxImportContext(parent.m_sourceScene, parent.m_sourceSceneSystem, parent.m_sourceNode) - , SceneDataPopulatedContextBase(parent, graphData, dataName) - { - } - - SceneDataPopulatedContext::SceneDataPopulatedContext(Containers::Scene& scene, - Containers::SceneGraph::NodeIndex currentGraphPosition, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode, - const AZStd::shared_ptr& nodeData, const AZStd::string& dataName) - : FbxImportContext(sourceScene, sourceSceneSystem, sourceNode) - , SceneDataPopulatedContextBase(scene, currentGraphPosition, nodeNameMap, nodeData, dataName) - { - } - - SceneNodeAppendedContext::SceneNodeAppendedContext(SceneDataPopulatedContext& parent, - Containers::SceneGraph::NodeIndex newIndex) - : FbxImportContext(parent.m_sourceScene, parent.m_sourceSceneSystem, parent.m_sourceNode) - , SceneNodeAppendedContextBase(parent.m_scene, newIndex, parent.m_nodeNameMap) - { - } - - SceneNodeAppendedContext::SceneNodeAppendedContext(Containers::Scene& scene, - Containers::SceneGraph::NodeIndex currentGraphPosition, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode) - : FbxImportContext(sourceScene, sourceSceneSystem, sourceNode) - , SceneNodeAppendedContextBase(scene, currentGraphPosition, nodeNameMap) - { - } - - SceneAttributeDataPopulatedContext::SceneAttributeDataPopulatedContext(SceneNodeAppendedContext& parent, - const AZStd::shared_ptr& nodeData, - const Containers::SceneGraph::NodeIndex attributeNodeIndex, const AZStd::string& dataName) - : FbxImportContext(parent.m_sourceScene, parent.m_sourceSceneSystem, parent.m_sourceNode) - , SceneAttributeDataPopulatedContextBase(parent, nodeData, attributeNodeIndex, dataName) - { - } - - SceneAttributeNodeAppendedContext::SceneAttributeNodeAppendedContext( - SceneAttributeDataPopulatedContext& parent, Containers::SceneGraph::NodeIndex newIndex) - : FbxImportContext(parent.m_sourceScene, parent.m_sourceSceneSystem, parent.m_sourceNode) - , SceneAttributeNodeAppendedContextBase(parent, newIndex) - { - } - - SceneNodeAddedAttributesContext::SceneNodeAddedAttributesContext(SceneNodeAppendedContext& parent) - : FbxImportContext(parent.m_sourceScene, parent.m_sourceSceneSystem, parent.m_sourceNode) - , SceneNodeAddedAttributesContextBase(parent) - { - } - - SceneNodeFinalizeContext::SceneNodeFinalizeContext(SceneNodeAddedAttributesContext& parent) - : FbxImportContext(parent.m_sourceScene, parent.m_sourceSceneSystem, parent.m_sourceNode) - , SceneNodeFinalizeContextBase(parent) - { - } - - FinalizeSceneContext::FinalizeSceneContext(Containers::Scene& scene, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap) - : FinalizeSceneContextBase(scene, nodeNameMap) - , m_sourceScene(sourceScene) - , m_sourceSceneSystem(sourceSceneSystem) - { - } - } // namespace SceneAPI - } // namespace FbxSceneBuilder -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/ImportContexts/FbxImportContexts.h b/Code/Tools/SceneAPI/FbxSceneBuilder/ImportContexts/FbxImportContexts.h deleted file mode 100644 index a3bc3e0b45..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/ImportContexts/FbxImportContexts.h +++ /dev/null @@ -1,184 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxSceneWrapper; - class FbxNodeWrapper; - } - - namespace SceneAPI - { - class FbxSceneSystem; - - namespace FbxSceneBuilder - { - class RenamedNodesMap; - - // FbxImportContext - // Base structure containing common data needed for all import contexts - // Member Variables: - // m_sourceScene - Basic scene data extracted from the FBX Scene. Used to - // transform data. - // m_sourceNode - FBX node being used for data processing. - struct FbxImportContext - { - AZ_RTTI(FbxImportContext, "{C8D665D5-E871-41AD-90E7-C84CF6842BCF}"); - - FbxImportContext(const FbxSDKWrapper::FbxSceneWrapper& sourceScene, const FbxSceneSystem& sourceSceneSystem, - FbxSDKWrapper::FbxNodeWrapper& sourceNode); - - const FbxSDKWrapper::FbxSceneWrapper& m_sourceScene; - const FbxSceneSystem& m_sourceSceneSystem; // Needed for unit and axis conversion - FbxSDKWrapper::FbxNodeWrapper& m_sourceNode; - }; - - // FbxNodeEncounteredContext - // Context pushed to indicate that a new FBX Node has been found and any - // importers that have means to process the contained data should do so - // Member Variables: - // m_createdData - out container that importers must add their created data - // to. - struct FbxNodeEncounteredContext - : public FbxImportContext - , public NodeEncounteredContext - { - AZ_RTTI(FbxNodeEncounteredContext, "{BE21E324-6745-41FD-A79C-A6CA7AB15A7A}", FbxImportContext, NodeEncounteredContext); - - FbxNodeEncounteredContext(Containers::Scene& scene, - Containers::SceneGraph::NodeIndex currentGraphPosition, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode); - - FbxNodeEncounteredContext(Events::ImportEventContext& parent, - Containers::SceneGraph::NodeIndex currentGraphPosition, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode); - }; - - // SceneDataPopulatedContext - // Context pushed to indicate that a piece of scene data has been fully - // processed and any importers that wish to place it within the scene graph - // may now do so. This may be triggered by processing a FbxNodeEncounteredContext - // (for base data, e.g. bones, meshes) or from a SceneNodeAppendedContext - // (for attribute data, e.g. UV Maps, materials) - // Member Variables: - // m_graphData - the piece of data that should be inserted in the graph - // m_dataName - the name that should be used as the basis for the scene node - // name - // m_isAttribute - Indicates whether the graph data is an attribute - struct SceneDataPopulatedContext - : public FbxImportContext - , public SceneDataPopulatedContextBase - { - AZ_RTTI(SceneDataPopulatedContext, "{DF17306C-FE28-4BEB-9CF0-88CF0472B8A8}", FbxImportContext, SceneDataPopulatedContextBase); - - SceneDataPopulatedContext(FbxNodeEncounteredContext& parent, - const AZStd::shared_ptr& nodeData, - const AZStd::string& dataName); - - SceneDataPopulatedContext(Containers::Scene& scene, - Containers::SceneGraph::NodeIndex currentGraphPosition, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode, - const AZStd::shared_ptr& nodeData, const AZStd::string& dataName); - }; - - // SceneNodeAppendedContext - // Context pushed to indicate that data has been added to the scene graph. - // Generally created due to the insertion of a node during SceneDataPopulatedContext - // processing. - struct SceneNodeAppendedContext - : public FbxImportContext - , public SceneNodeAppendedContextBase - { - AZ_RTTI(SceneNodeAppendedContext, "{72C1C37A-C6ED-4CB7-B929-DA03AA44131C}", FbxImportContext, SceneNodeAppendedContextBase); - - SceneNodeAppendedContext(SceneDataPopulatedContext& parent, Containers::SceneGraph::NodeIndex newIndex); - SceneNodeAppendedContext(Containers::Scene& scene, - Containers::SceneGraph::NodeIndex currentGraphPosition, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap, FbxSDKWrapper::FbxNodeWrapper& sourceNode); - }; - - // SceneAttributeDataPopulatedContext - // Context pushed to indicate that attribute data has been found and processed - struct SceneAttributeDataPopulatedContext - : public FbxImportContext - , public SceneAttributeDataPopulatedContextBase - { - AZ_RTTI(SceneAttributeDataPopulatedContext, "{93E67C26-5A40-4385-8189-947A626E3CDA}", FbxImportContext, SceneAttributeDataPopulatedContextBase); - - SceneAttributeDataPopulatedContext(SceneNodeAppendedContext& parent, - const AZStd::shared_ptr& nodeData, - const Containers::SceneGraph::NodeIndex attributeNodeIndex, const AZStd::string& dataName); - }; - - // SceneAttributeNodeAppendedContext - // Context pushed to indicate that an attribute node has been added to the scene graph - struct SceneAttributeNodeAppendedContext - : public FbxImportContext - , public SceneAttributeNodeAppendedContextBase - { - AZ_RTTI(SceneAttributeNodeAppendedContext, "{C0DD4F39-5C61-4CA0-96C5-9EA3AC40D98B}", FbxImportContext, SceneAttributeNodeAppendedContextBase); - - SceneAttributeNodeAppendedContext(SceneAttributeDataPopulatedContext& parent, - Containers::SceneGraph::NodeIndex newIndex); - }; - - // SceneNodeAddedAttributesContext - // Context pushed to indicate that all attribute processors have completed their - // work for a specific data node. - struct SceneNodeAddedAttributesContext - : public FbxImportContext - , public SceneNodeAddedAttributesContextBase - { - AZ_RTTI(SceneNodeAddedAttributesContext, "{1601900C-5109-4D37-83F1-22317A4D7C78}", FbxImportContext, SceneNodeAddedAttributesContextBase); - - SceneNodeAddedAttributesContext(SceneNodeAppendedContext& parent); - }; - - // SceneNodeFinalizeContext - // Context pushed last after all other contexts for a scene node to allow any - // post-processing needed for an importer. - struct SceneNodeFinalizeContext - : public FbxImportContext - , public SceneNodeFinalizeContextBase - { - AZ_RTTI(SceneNodeFinalizeContext, "{D1D9839A-EA48-425D-BB7A-A9AEA65B8B7A}", FbxImportContext, SceneNodeFinalizeContextBase); - - SceneNodeFinalizeContext(SceneNodeAddedAttributesContext& parent); - }; - - // FinalizeSceneContext - // Context pushed after the scene has been fully created. This can be used to finalize pending work - // such as resolving named links. - struct FinalizeSceneContext - : public FinalizeSceneContextBase - { - AZ_RTTI(FinalizeSceneContext, "{C8D665D5-E871-41AD-90E7-C84CF6842BCF}", FinalizeSceneContextBase); - - FinalizeSceneContext(Containers::Scene& scene, const FbxSDKWrapper::FbxSceneWrapper& sourceScene, - const FbxSceneSystem& sourceSceneSystem, RenamedNodesMap& nodeNameMap); - - const FbxSDKWrapper::FbxSceneWrapper& m_sourceScene; - const FbxSceneSystem& m_sourceSceneSystem; // Needed for unit and axis conversion - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ - diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.cpp index e456f2dbab..dd92e6bb8b 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.cpp @@ -22,11 +22,6 @@ #include #include #include -#include -#include -#include -#include -#include #include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.h index 3c06153d04..e27264c171 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.h +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpAnimationImporter.h @@ -12,8 +12,6 @@ #pragma once -#include -#include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBitangentStreamImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBitangentStreamImporter.cpp index b5bcab31e6..c2b1f20035 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBitangentStreamImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBitangentStreamImporter.cpp @@ -14,13 +14,14 @@ #include #include #include -#include +#include #include #include #include #include #include #include +#include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBlendShapeImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBlendShapeImporter.cpp index 404a5857c1..c0399329d3 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBlendShapeImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBlendShapeImporter.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBoneImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBoneImporter.cpp index 0dd525c058..4467d6933b 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBoneImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpBoneImporter.cpp @@ -17,8 +17,7 @@ #include #include #include -#include -#include +#include #include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpColorStreamImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpColorStreamImporter.cpp index 55c14fd5d7..7ebdb55363 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpColorStreamImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpColorStreamImporter.cpp @@ -14,13 +14,14 @@ #include #include #include -#include +#include #include #include #include #include #include #include +#include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpMaterialImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpMaterialImporter.cpp index a63c2406f4..e314804ea1 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpMaterialImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpMaterialImporter.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpSkinWeightsImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpSkinWeightsImporter.cpp index bcfbaa9624..abcbf10b4a 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpSkinWeightsImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpSkinWeightsImporter.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTangentStreamImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTangentStreamImporter.cpp index 88177a04a0..992a6a6ab1 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTangentStreamImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTangentStreamImporter.cpp @@ -14,13 +14,14 @@ #include #include #include -#include +#include #include #include #include #include #include #include +#include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTransformImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTransformImporter.cpp index 90030a3058..84c0e3e18c 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTransformImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpTransformImporter.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpUvMapImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpUvMapImporter.cpp index 65e7c00d74..f5f47b233d 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpUvMapImporter.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/AssImpUvMapImporter.cpp @@ -16,12 +16,13 @@ #include #include #include -#include +#include #include #include #include #include #include +#include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxAnimationImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxAnimationImporter.cpp deleted file mode 100644 index 8122b68e3d..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxAnimationImporter.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - const char* FbxAnimationImporter::s_animationNodeName = "animation"; - const FbxSDKWrapper::FbxTimeWrapper::TimeMode FbxAnimationImporter::s_defaultTimeMode = - FbxSDKWrapper::FbxTimeWrapper::frames30; - - FbxAnimationImporter::FbxAnimationImporter() - { - BindToCall(&FbxAnimationImporter::ImportAnimation); - } - - void FbxAnimationImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxAnimationImporter::ImportAnimation(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Animation"); - - // Add check for animation layers at the scene level. - - if (context.m_sourceScene.GetAnimationStackCount() <= 0) - { - return Events::ProcessingResult::Ignored; - } - - if (context.m_sourceNode.IsMesh()) - { - return ImportBlendShapeAnimation(context); - } - - if (!context.m_sourceNode.IsBone()) - { - return Events::ProcessingResult::Ignored; - } - - AZStd::string nodeName = s_animationNodeName; - RenamedNodesMap::SanitizeNodeName(nodeName, context.m_scene.GetGraph(), context.m_currentGraphPosition); - AZ_TraceContext("Animation node name", nodeName); - - auto animStackWrapper = context.m_sourceScene.GetAnimationStackAt(0); - const FbxSDKWrapper::FbxTimeWrapper startTime = animStackWrapper->GetLocalTimeSpan().GetStartTime(); - const double frameRate = startTime.GetFrameRate(); - - if (frameRate == 0.0) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Scene has a 0 framerate. Animation cannot be processed without timing information."); - return Events::ProcessingResult::Failure; - } - - const int64_t startFrame = startTime.GetFrameCount(); - const int64_t numFrames = animStackWrapper->GetLocalTimeSpan().GetNumFrames(); - - AZStd::shared_ptr createdAnimationData = - AZStd::make_shared(); - createdAnimationData->ReserveKeyFrames(numFrames); - createdAnimationData->SetTimeStepBetweenFrames(1.0 / frameRate); - - { - FbxSDKWrapper::FbxTimeWrapper currTime = startTime; - for (int64_t currFrame = startFrame; currFrame < startFrame + numFrames; currFrame++) - { - currTime.SetFrame(currFrame); - - SceneAPI::DataTypes::MatrixType animTransform = context.m_sourceNode.EvaluateLocalTransform(currTime); - context.m_sourceSceneSystem.SwapTransformForUpAxis(animTransform); - context.m_sourceSceneSystem.ConvertBoneUnit(animTransform); - - createdAnimationData->AddKeyFrame(animTransform); - } - - AZ_Assert(createdAnimationData->GetKeyFrameCount() == numFrames, "The imported animation data created does not have the same number of keyframes as the FBX data."); - } - - Containers::SceneGraph::NodeIndex addNode = context.m_scene.GetGraph().AddChild( - context.m_currentGraphPosition, nodeName.c_str(), AZStd::move(createdAnimationData)); - context.m_scene.GetGraph().MakeEndPoint(addNode); - - return Events::ProcessingResult::Success; - } - - Events::ProcessingResult FbxAnimationImporter::ImportBlendShapeAnimation(SceneNodeAppendedContext& context) - { - FbxNode * node = context.m_sourceNode.GetFbxNode(); - FbxMesh * pMesh = node->GetMesh(); - if (!pMesh) - { - return Events::ProcessingResult::Ignored; - } - - int deformerCount = pMesh->GetDeformerCount(FbxDeformer::eBlendShape); - int blendShapeIndex = -1; - AZStd::string nodeName; - AZStd::string animNodeName; - for (int deformerIndex = 0; deformerIndex < deformerCount; ++deformerIndex) - { - //we are assuming 1 anim stack (single animation clip export) - const FbxBlendShape* pDeformer = (FbxBlendShape*)pMesh->GetDeformer(deformerIndex, FbxDeformer::eBlendShape); - if (!pDeformer) - { - continue; - } - blendShapeIndex++; - int blendShapeChannelCount = pDeformer->GetBlendShapeChannelCount(); - auto animStackWrapper = context.m_sourceScene.GetAnimationStackAt(0); - - const FbxSDKWrapper::FbxTimeWrapper startTime = animStackWrapper->GetLocalTimeSpan().GetStartTime(); - const double frameRate = startTime.GetFrameRate(); - - if (frameRate == 0.0) - { - AZ_TracePrintf("Animation_Warning", "Scene has a 0 framerate. Animation cannot be processed without timing information."); - return Events::ProcessingResult::Failure; - } - - const int64_t startFrame = startTime.GetFrameCount(); - const int64_t numFrames = animStackWrapper->GetLocalTimeSpan().GetNumFrames(); - - const int layerCount = animStackWrapper->GetAnimationLayerCount(); - - for (int blendShapeChannelIdx = 0; blendShapeChannelIdx < blendShapeChannelCount; ++blendShapeChannelIdx) - { - const FbxBlendShapeChannel* pChannel = pDeformer->GetBlendShapeChannel(blendShapeChannelIdx); - if (!pChannel) - { - continue; - } - - for (int layerIndex = 0; layerIndex < layerCount; layerIndex++) - { - FbxAnimLayer* animationLayer = animStackWrapper->GetAnimationLayerAt(layerIndex)->GetFbxLayer(); - FbxAnimCurve* animCurve = pMesh->GetShapeChannel(blendShapeIndex, blendShapeChannelIdx, animationLayer); - if (!animCurve) - { - continue; - } - AZStd::shared_ptr animCurveWrapper = AZStd::make_shared(animCurve); - - AZStd::shared_ptr createdAnimationData = - AZStd::make_shared(); - - createdAnimationData->ReserveKeyFrames(numFrames); - createdAnimationData->SetTimeStepBetweenFrames(1.0 / frameRate); - - { - FbxSDKWrapper::FbxTimeWrapper currTime = startTime; - for (int64_t currFrame = startFrame; currFrame < startFrame + numFrames; currFrame++) - { - currTime.SetFrame(currFrame); - - //weight values from FBX are range 0 - 100 - float sampleValue = animCurveWrapper->Evaluate(currTime) / 100.0f; - createdAnimationData->AddKeyFrame(sampleValue); - } - AZ_Assert(createdAnimationData->GetKeyFrameCount() == numFrames, "Imported animation blend data does not contain the same number of keyframes as the source FBX data.") - } - - nodeName = pChannel->GetName(); - const size_t dotIndex = nodeName.find_last_of('.'); - nodeName = nodeName.substr(dotIndex + 1); - createdAnimationData->SetBlendShapeName(nodeName.c_str()); - animNodeName = AZStd::string::format("%s_%s", s_animationNodeName, nodeName.c_str()); - Containers::SceneGraph::NodeIndex addNode = context.m_scene.GetGraph().AddChild( - context.m_currentGraphPosition, animNodeName.c_str(), AZStd::move(createdAnimationData)); - context.m_scene.GetGraph().MakeEndPoint(addNode); - } - } - } - return Events::ProcessingResult::Success; - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxAnimationImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxAnimationImporter.h deleted file mode 100644 index 2abb7f1170..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxAnimationImporter.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxAnimationImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxAnimationImporter, "{26ABDA62-9DB7-4B4D-961D-44B5F5F56808}", SceneCore::LoadingComponent); - - FbxAnimationImporter(); - ~FbxAnimationImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportAnimation(SceneNodeAppendedContext& context); - Events::ProcessingResult ImportBlendShapeAnimation(SceneNodeAppendedContext& context); - - protected: - static const char* s_animationNodeName; - static const FbxSDKWrapper::FbxTimeWrapper::TimeMode s_defaultTimeMode; - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBitangentStreamImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBitangentStreamImporter.cpp deleted file mode 100644 index f94dc9cf2f..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBitangentStreamImporter.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxBitangentStreamImporter::FbxBitangentStreamImporter() - { - BindToCall(&FbxBitangentStreamImporter::ImportBitangents); - } - - - void FbxBitangentStreamImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - - Events::ProcessingResult FbxBitangentStreamImporter::ImportBitangents(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Bitangents"); - std::shared_ptr fbxMesh = context.m_sourceNode.GetMesh(); - if (!fbxMesh) - { - return Events::ProcessingResult::Ignored; - } - - Events::ProcessingResultCombiner combinedStreamResults; - const int numBitangentSets = context.m_sourceNode.GetMesh()->GetElementBitangentCount(); - for (int elementIndex = 0; elementIndex < numBitangentSets; ++elementIndex) - { - AZ_TraceContext("Bitangent set index", elementIndex); - - FbxSDKWrapper::FbxVertexBitangentWrapper fbxVertexBitangents = fbxMesh->GetElementBitangent(elementIndex); - if (!fbxVertexBitangents.IsValid()) - { - AZ_TracePrintf(Utilities::WarningWindow, "Invalid bitangent set found, ignoring"); - continue; - } - - const AZStd::string originalNodeName = AZStd::string::format("BitangentSet_Fbx_%d", elementIndex); - const AZStd::string nodeName = AZ::SceneAPI::DataTypes::Utilities::CreateUniqueName(originalNodeName, context.m_scene.GetManifest()); - AZ_TraceContext("Bitangent Set Name", nodeName); - if (originalNodeName != nodeName) - { - AZ_TracePrintf(Utilities::WarningWindow, "Bitangent set '%s' has been renamed to '%s' because the name was already in use.", originalNodeName.c_str(), nodeName.c_str()); - } - - AZStd::shared_ptr parentData = context.m_scene.GetGraph().GetNodeContent(context.m_currentGraphPosition); - AZ_Assert(parentData && parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid()), "Tried to construct bitangent set attribute for invalid or non-mesh parent data"); - if (!parentData || !parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid())) - { - combinedStreamResults += Events::ProcessingResult::Failure; - continue; - } - - const SceneData::GraphData::MeshData* const parentMeshData = azrtti_cast(parentData.get()); - const size_t vertexCount = parentMeshData->GetVertexCount(); - AZStd::shared_ptr bitangentStream = BuildVertexBitangentData(fbxVertexBitangents, vertexCount, fbxMesh); - - AZ_Assert(bitangentStream, "Failed to allocate bitangent data for scene graph."); - if (!bitangentStream) - { - combinedStreamResults += Events::ProcessingResult::Failure; - continue; - } - - bitangentStream->SetBitangentSetIndex(elementIndex); - bitangentStream->SetTangentSpace(AZ::SceneAPI::DataTypes::TangentSpace::FromFbx); - - Containers::SceneGraph::NodeIndex newIndex = context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, nodeName.c_str()); - AZ_Assert(newIndex.IsValid(), "Failed to create SceneGraph node for attribute."); - if (!newIndex.IsValid()) - { - combinedStreamResults += Events::ProcessingResult::Failure; - continue; - } - - Events::ProcessingResult streamResults; - SceneAttributeDataPopulatedContext dataPopulated(context, bitangentStream, newIndex, nodeName); - streamResults = Events::Process(dataPopulated); - if (streamResults != Events::ProcessingResult::Failure) - { - streamResults = AddAttributeDataNodeWithContexts(dataPopulated); - } - - combinedStreamResults += streamResults; - } - - return combinedStreamResults.GetResult(); - } - - - AZStd::shared_ptr FbxBitangentStreamImporter::BuildVertexBitangentData(const FbxSDKWrapper::FbxVertexBitangentWrapper& bitangents, size_t vertexCount, const std::shared_ptr& fbxMesh) - { - AZStd::shared_ptr bitangentData = AZStd::make_shared(); - bitangentData->ReserveContainerSpace(vertexCount); - - const int fbxPolygonCount = fbxMesh->GetPolygonCount(); - const int* const fbxPolygonVertices = fbxMesh->GetPolygonVertices(); - for (int fbxPolygonIndex = 0; fbxPolygonIndex < fbxPolygonCount; ++fbxPolygonIndex) - { - const int fbxPolygonVertexCount = fbxMesh->GetPolygonSize(fbxPolygonIndex); - if (fbxPolygonVertexCount <= 2) - { - continue; - } - - const int fbxVertexStartIndex = fbxMesh->GetPolygonVertexIndex(fbxPolygonIndex); - for (int index = 0; index < fbxPolygonVertexCount; ++index) - { - const int fbxPolygonVertexIndex = fbxVertexStartIndex + index; - const int fbxControlPointIndex = fbxPolygonVertices[fbxPolygonVertexIndex]; - - const Vector3 bitangent = bitangents.GetElementAt(fbxPolygonIndex, fbxPolygonVertexIndex, fbxControlPointIndex); - bitangentData->AppendBitangent(bitangent); - } - } - - if (bitangentData->GetCount() != vertexCount) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Vertex count (%i) doesn't match the number of entries for the bitangent stream %s (%i)", vertexCount, bitangents.GetName(), bitangentData->GetCount()); - return nullptr; - } - - return bitangentData; - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBitangentStreamImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBitangentStreamImporter.h deleted file mode 100644 index 4fd6820ebf..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBitangentStreamImporter.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace SceneData - { - namespace GraphData - { - class MeshVertexBitangentData; - } - } - - namespace FbxSDKWrapper - { - class FbxMeshWrapper; - class FbxVertexBitangentWrapper; - } - - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxBitangentStreamImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxBitangentStreamImporter, "{B68F90E6-9F9D-448F-A874-CABA9F67E5FD}", SceneCore::LoadingComponent); - - FbxBitangentStreamImporter(); - ~FbxBitangentStreamImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportBitangents(SceneNodeAppendedContext& context); - - protected: - AZStd::shared_ptr BuildVertexBitangentData(const FbxSDKWrapper::FbxVertexBitangentWrapper& bitangents, - size_t vertexCount, const std::shared_ptr& fbxMesh); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBlendShapeImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBlendShapeImporter.cpp deleted file mode 100644 index cc20d76d87..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBlendShapeImporter.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxBlendShapeImporter::FbxBlendShapeImporter() - { - BindToCall(&FbxBlendShapeImporter::ImportBlendShapes); - } - - void FbxBlendShapeImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxBlendShapeImporter::ImportBlendShapes(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Blend Shapes"); - - if (!IsSkinnedMesh(context.m_sourceNode)) - { - return Events::ProcessingResult::Ignored; - } - - Events::ProcessingResultCombiner combinedBlendShapeResult; - - const std::shared_ptr sourceMesh = context.m_sourceNode.GetMesh(); - int blendShapeDeformerCount = sourceMesh->GetDeformerCount(FbxDeformer::eBlendShape); - for (int deformerIndex = 0; deformerIndex < blendShapeDeformerCount; ++deformerIndex) - { - AZ_TraceContext("Deformer Index", deformerIndex); - AZStd::shared_ptr fbxBlendShape = sourceMesh->GetBlendShape(deformerIndex); - - if (!fbxBlendShape) - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Unable to extract BlendShape Deformer at index %d", deformerIndex); - return Events::ProcessingResult::Failure; - } - int blendShapeChannelCount = fbxBlendShape->GetBlendShapeChannelCount(); - for (int channelIndex = 0; channelIndex < blendShapeChannelCount; ++channelIndex) - { - //extract the mesh and build a blendshape data object. - AZStd::shared_ptr blendShapeChannel = fbxBlendShape->GetBlendShapeChannel(channelIndex); - - int shapeCount = blendShapeChannel->GetTargetShapeCount(); - - //We do not support percentage blends at this time. Take only the final shape. - AZStd::shared_ptr mesh = blendShapeChannel->GetTargetShape(shapeCount - 1); - - if (mesh) - { - //Maya is creating node names of the form cone_skin_blendShapeNode.cone_squash during export. - //We need the name after the period for our naming purposes. - AZStd::string nodeName(blendShapeChannel->GetName()); - size_t dotIndex = nodeName.rfind('.'); - if (dotIndex != AZStd::string::npos) - { - nodeName.erase(0, dotIndex + 1); - } - RenamedNodesMap::SanitizeNodeName(nodeName, context.m_scene.GetGraph(), context.m_currentGraphPosition, "BlendShape"); - AZ_TraceContext("Blend shape name", nodeName); - - AZStd::shared_ptr blendShapeData = - AZStd::make_shared(); - - BuildSceneBlendShapeFromFbxBlendShape(blendShapeData, mesh, context.m_sourceSceneSystem); - - Containers::SceneGraph::NodeIndex newIndex = - context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, nodeName.c_str()); - - Events::ProcessingResult blendShapeResult; - SceneAttributeDataPopulatedContext dataPopulated(context, blendShapeData, newIndex, nodeName); - blendShapeResult = Events::Process(dataPopulated); - - if (blendShapeResult != Events::ProcessingResult::Failure) - { - blendShapeResult = AddAttributeDataNodeWithContexts(dataPopulated); - } - combinedBlendShapeResult += blendShapeResult; - } - else - { - AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Unable to extract blendshape mesh for node '%s' from BlendShapeChannel %d", sourceMesh->GetName(), channelIndex); - combinedBlendShapeResult += Events::ProcessingResult::Failure; - } - } - } - - return combinedBlendShapeResult.GetResult(); - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBlendShapeImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBlendShapeImporter.h deleted file mode 100644 index b56a622383..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBlendShapeImporter.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxBlendShapeImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxBlendShapeImporter, "{3E733F1B-B4A1-4F6F-B2EE-A1C501830E91}", SceneCore::LoadingComponent); - - FbxBlendShapeImporter(); - ~FbxBlendShapeImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportBlendShapes(SceneNodeAppendedContext& context); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBoneImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBoneImporter.cpp deleted file mode 100644 index 728a4c7828..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBoneImporter.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxBoneImporter::FbxBoneImporter() - { - BindToCall(&FbxBoneImporter::ImportBone); - } - - void FbxBoneImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxBoneImporter::ImportBone(FbxNodeEncounteredContext& context) - { - AZ_TraceContext("Importer", "Bone"); - - if (!context.m_sourceNode.IsBone()) - { - return Events::ProcessingResult::Ignored; - } - - AZStd::shared_ptr boneGraphData; - - // If the current scene node (our eventual parent) contains bone data, we are not a root bone - AZStd::shared_ptr createdBoneData; - - if (NodeHasAncestorOfType(context.m_scene.GetGraph(), context.m_currentGraphPosition, - DataTypes::IBoneData::TYPEINFO_Uuid())) - { - createdBoneData = AZStd::make_shared(); - } - else - { - createdBoneData = AZStd::make_shared(); - } - - SceneAPI::DataTypes::MatrixType globalTransform = context.m_sourceNode.EvaluateGlobalTransform(); - - context.m_sourceSceneSystem.SwapTransformForUpAxis(globalTransform); - - context.m_sourceSceneSystem.ConvertBoneUnit(globalTransform); - - createdBoneData->SetWorldTransform(globalTransform); - - context.m_createdData.push_back(AZStd::move(createdBoneData)); - - return Events::ProcessingResult::Success; - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBoneImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBoneImporter.h deleted file mode 100644 index 29ac288149..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxBoneImporter.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxBoneImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxBoneImporter, "{3575F356-BC2F-45F6-B57C-9C590ED54995}", SceneCore::LoadingComponent); - - FbxBoneImporter(); - ~FbxBoneImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportBone(FbxNodeEncounteredContext& context); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxColorStreamImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxColorStreamImporter.cpp deleted file mode 100644 index 78c2933d0b..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxColorStreamImporter.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxColorStreamImporter::FbxColorStreamImporter() - { - BindToCall(&FbxColorStreamImporter::ImportColorStreams); - } - - void FbxColorStreamImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxColorStreamImporter::ImportColorStreams(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Color Stream"); - std::shared_ptr fbxMesh = - context.m_sourceNode.GetMesh(); - if (!fbxMesh) - { - return Events::ProcessingResult::Ignored; - } - - Events::ProcessingResultCombiner combinedVertexColorResults; - - for (int i = 0; i < context.m_sourceNode.GetMesh()->GetElementVertexColorCount(); ++i) - { - AZ_TraceContext("Vertex color index", i); - - FbxSDKWrapper::FbxVertexColorWrapper fbxVertexColors = - fbxMesh->GetElementVertexColor(i); - - if (!fbxVertexColors.IsValid()) - { - AZ_TracePrintf(Utilities::WarningWindow, "Invalid vertex color channel found, ignoring"); - continue; - } - - AZStd::string nodeName = fbxVertexColors.GetName(); - RenamedNodesMap::SanitizeNodeName(nodeName, context.m_scene.GetGraph(), context.m_currentGraphPosition, "ColorStream"); - AZ_TraceContext("Color Stream Name", nodeName); - - AZStd::shared_ptr parentData = - context.m_scene.GetGraph().GetNodeContent(context.m_currentGraphPosition); - AZ_Assert(parentData && parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid()), - "Tried to construct color stream attribute for invalid or non-mesh parent data"); - if (!parentData || !parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid())) - { - combinedVertexColorResults += Events::ProcessingResult::Failure; - continue; - } - - SceneData::GraphData::MeshData* parentMeshData = - azrtti_cast(parentData.get()); - size_t vertexCount = parentMeshData->GetVertexCount(); - AZStd::shared_ptr vertexColors = - BuildVertexColorData(fbxVertexColors, vertexCount, fbxMesh); - AZ_Assert(vertexColors, "Failed to allocate vertex color data for scene graph."); - if (!vertexColors) - { - combinedVertexColorResults += Events::ProcessingResult::Failure; - continue; - } - - Containers::SceneGraph::NodeIndex newIndex = - context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, nodeName.c_str()); - - AZ_Assert(newIndex.IsValid(), "Failed to create SceneGraph node for attribute."); - if (!newIndex.IsValid()) - { - combinedVertexColorResults += Events::ProcessingResult::Failure; - continue; - } - - Events::ProcessingResult vertexColorResult; - SceneAttributeDataPopulatedContext dataPopulated(context, vertexColors, newIndex, nodeName); - vertexColorResult = AddAttributeDataNodeWithContexts(dataPopulated); - - combinedVertexColorResults += vertexColorResult; - } - - return combinedVertexColorResults.GetResult(); - } - - AZStd::shared_ptr FbxColorStreamImporter::BuildVertexColorData(const FbxSDKWrapper::FbxVertexColorWrapper& fbxVertexColors, size_t vertexCount, const std::shared_ptr& fbxMesh) - { - AZ_Assert(fbxVertexColors.IsValid(), "BuildVertexColorData was called for invalid color stream data."); - if (!fbxVertexColors.IsValid()) - { - return nullptr; - } - - AZStd::shared_ptr colorData = AZStd::make_shared(); - colorData->ReserveContainerSpace(vertexCount); - colorData->SetCustomName(fbxVertexColors.GetName()); - - const int fbxPolygonCount = fbxMesh->GetPolygonCount(); - const int* const fbxPolygonVertices = fbxMesh->GetPolygonVertices(); - for (int fbxPolygonIndex = 0; fbxPolygonIndex < fbxPolygonCount; ++fbxPolygonIndex) - { - const int fbxPolygonVertexCount = fbxMesh->GetPolygonSize(fbxPolygonIndex); - if (fbxPolygonVertexCount < 3) - { - continue; - } - - const int fbxVertexStartIndex = fbxMesh->GetPolygonVertexIndex(fbxPolygonIndex); - - for (int polygonVertexIndex = 0; polygonVertexIndex < fbxPolygonVertexCount; ++polygonVertexIndex) - { - const int fbxPolygonVertexIndex = fbxVertexStartIndex + polygonVertexIndex; - const int fbxControlPointIndex = fbxPolygonVertices[fbxPolygonVertexIndex]; - - FbxSDKWrapper::FbxColorWrapper color = fbxVertexColors.GetElementAt(fbxPolygonIndex, fbxPolygonVertexIndex, fbxControlPointIndex); - - colorData->AppendColor({color.GetR(), color.GetG(), color.GetB(), color.GetAlpha()}); - } - } - - if (colorData->GetCount() != vertexCount) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Vertex count (%i) doesn't match the number of entries for the vertex color stream %s (%i)", - vertexCount, fbxVertexColors.GetName(), colorData->GetCount()); - return nullptr; - } - - return colorData; - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxColorStreamImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxColorStreamImporter.h deleted file mode 100644 index bf614cf0d3..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxColorStreamImporter.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace SceneData - { - namespace GraphData - { - class MeshVertexColorData; - } - } - - namespace FbxSDKWrapper - { - class FbxMeshWrapper; - class FbxVertexColorWrapper; - } - - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxColorStreamImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxColorStreamImporter, "{96A25361-04FC-43EC-A443-C81E2E28F3BB}", SceneCore::LoadingComponent); - - FbxColorStreamImporter(); - ~FbxColorStreamImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportColorStreams(SceneNodeAppendedContext& context); - - protected: - AZStd::shared_ptr BuildVertexColorData(const FbxSDKWrapper::FbxVertexColorWrapper& fbxVertexColors, size_t vertexCount, const std::shared_ptr& fbxMesh); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMaterialImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMaterialImporter.cpp deleted file mode 100644 index 199f476ec0..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMaterialImporter.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxMaterialImporter::FbxMaterialImporter() - { - BindToCall(&FbxMaterialImporter::ImportMaterials); - } - - void FbxMaterialImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxMaterialImporter::ImportMaterials(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Material"); - - if (!context.m_sourceNode.GetMesh()) - { - return Events::ProcessingResult::Ignored; - } - - Events::ProcessingResultCombiner combinedMaterialImportResults; - - for (int materialIndex = 0; materialIndex < context.m_sourceNode.GetMaterialCount(); ++materialIndex) - { - AZ_TraceContext("Material Index", materialIndex); - - const std::shared_ptr fbxMaterial = - context.m_sourceNode.GetMaterial(materialIndex); - - if (!fbxMaterial) - { - AZ_TracePrintf(Utilities::WarningWindow, "Invalid material data found, ignoring."); - continue; - } - - AZStd::string materialName = fbxMaterial->GetName().c_str(); - RenamedNodesMap::SanitizeNodeName(materialName, context.m_scene.GetGraph(), context.m_currentGraphPosition, "Material"); - AZ_TraceContext("Material Name", materialName); - - AZStd::shared_ptr materialData = - BuildMaterial(context.m_sourceNode, materialIndex); - - AZ_Assert(materialData, "Failed to allocate scene material data."); - if (!materialData) - { - combinedMaterialImportResults += Events::ProcessingResult::Failure; - continue; - } - - Events::ProcessingResult materialResult; - Containers::SceneGraph::NodeIndex newIndex = - context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, materialName.c_str()); - - AZ_Assert(newIndex.IsValid(), "Failed to create SceneGraph node for attribute."); - if(!newIndex.IsValid()) - { - combinedMaterialImportResults += Events::ProcessingResult::Failure; - continue; - } - - SceneAttributeDataPopulatedContext dataPopulated(context, materialData, newIndex, materialName); - materialResult = Events::Process(dataPopulated); - - if (materialResult != Events::ProcessingResult::Failure) - { - materialResult = AddAttributeDataNodeWithContexts(dataPopulated); - } - - combinedMaterialImportResults += materialResult; - } - - return combinedMaterialImportResults.GetResult(); - } - - AZStd::shared_ptr FbxMaterialImporter::BuildMaterial(FbxSDKWrapper::FbxNodeWrapper& node, int materialIndex) const - { - AZ_Assert(materialIndex < node.GetMaterialCount(), "Invalid material index (%i)", materialIndex); - const std::shared_ptr fbxMaterial = node.GetMaterial(materialIndex); - if (!fbxMaterial) - { - return nullptr; - } - - AZStd::shared_ptr material = AZStd::make_shared(); - - material->SetMaterialName(fbxMaterial->GetName()); - material->SetTexture(DataTypes::IMaterialData::TextureMapType::Diffuse, - fbxMaterial->GetTextureFileName(FbxSDKWrapper::FbxMaterialWrapper::MaterialMapType::Diffuse).c_str()); - material->SetTexture(DataTypes::IMaterialData::TextureMapType::Specular, - fbxMaterial->GetTextureFileName(FbxSDKWrapper::FbxMaterialWrapper::MaterialMapType::Specular).c_str()); - material->SetTexture(DataTypes::IMaterialData::TextureMapType::Bump, - fbxMaterial->GetTextureFileName(FbxSDKWrapper::FbxMaterialWrapper::MaterialMapType::Bump).c_str()); - material->SetTexture(DataTypes::IMaterialData::TextureMapType::Normal, - fbxMaterial->GetTextureFileName(FbxSDKWrapper::FbxMaterialWrapper::MaterialMapType::Normal).c_str()); - material->SetDiffuseColor(fbxMaterial->GetDiffuseColor()); - material->SetSpecularColor(fbxMaterial->GetSpecularColor()); - material->SetEmissiveColor(fbxMaterial->GetEmissiveColor()); - material->SetShininess(fbxMaterial->GetShininess()); - - float opacity = fbxMaterial->GetOpacity(); - if (opacity == 0.0f) - { - opacity = 1.0f; - AZ_TracePrintf(Utilities::WarningWindow, "Opacity has been changed from 0 to full. Some DCC tools ignore the opacity and " - "write 0 to indicate opacity is not used. This causes meshes to turn invisible, which is often not the intention so " - "the opacity has been set to full automatically. If the intention was for a fully transparent mesh, please update " - "the opacity in Open 3D Engine's material editor."); - } - material->SetOpacity(opacity); - - // Due to the fact that fbxMaterial->GetUniqueId() will return a different ID - // each time when the fbx is reprocessed, we need a more stable ID. - // The current best candidate is probably the name of the material. - // But this will also force the user to update the material component for overrides - // if the fbx material name is changed outside from apps like dcc tools. - // (Ideally, only changing the material properties in the dcc tool will force the user to update the material component) - // - // Using 32-bit CRC as it is mathematically stable and enough within the same fbx. - uint64_t id = uint32_t(AZ::Crc32(fbxMaterial->GetName())); - material->SetUniqueId(id); - return material; - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMaterialImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMaterialImporter.h deleted file mode 100644 index a6b7bbd5ee..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMaterialImporter.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace SceneData - { - namespace GraphData - { - class MaterialData; - } - } - - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxMaterialImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxMaterialImporter, "{E1DF4182-793D-4188-B833-1236D33CCEB4}", SceneCore::LoadingComponent); - - FbxMaterialImporter(); - ~FbxMaterialImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportMaterials(SceneNodeAppendedContext& context); - - protected: - AZStd::shared_ptr BuildMaterial(FbxSDKWrapper::FbxNodeWrapper& node, int materialIndex) const; - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMeshImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMeshImporter.cpp deleted file mode 100644 index 90d4dceb6c..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMeshImporter.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxMeshImporter::FbxMeshImporter() - { - BindToCall(&FbxMeshImporter::ImportMesh); - } - - void FbxMeshImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxMeshImporter::ImportMesh(FbxNodeEncounteredContext& context) - { - AZ_TraceContext("Importer", "Mesh"); - if (!context.m_sourceNode.GetMesh() || - IsSkinnedMesh(context.m_sourceNode)) - { - return Events::ProcessingResult::Ignored; - } - - AZStd::shared_ptr createdData = - AZStd::make_shared(); - - if (BuildSceneMeshFromFbxMesh(createdData, *context.m_sourceNode.GetMesh(), context.m_sourceSceneSystem)) - { - context.m_createdData.push_back(std::move(createdData)); - return Events::ProcessingResult::Success; - } - else - { - return Events::ProcessingResult::Failure; - } - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMeshImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMeshImporter.h deleted file mode 100644 index 6d205c7bfa..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxMeshImporter.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxMeshWrapper; - } - - namespace SceneData - { - namespace GraphData - { - class MeshData; - } - } - - namespace SceneAPI - { - class FbxSceneSystem; - - namespace FbxSceneBuilder - { - class FbxMeshImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxMeshImporter, "{8D131E77-4D53-486A-B3C6-80ACC27A6D50}", SceneCore::LoadingComponent); - - FbxMeshImporter(); - ~FbxMeshImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportMesh(FbxNodeEncounteredContext& context); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinImporter.cpp deleted file mode 100644 index 7c710fdda0..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinImporter.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxSkinImporter::FbxSkinImporter() - { - BindToCall(&FbxSkinImporter::ImportSkin); - } - - void FbxSkinImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxSkinImporter::ImportSkin(FbxNodeEncounteredContext& context) - { - if (!context.m_sourceNode.GetMesh() || - !IsSkinnedMesh(context.m_sourceNode)) - { - return Events::ProcessingResult::Ignored; - } - - AZStd::shared_ptr createdData = - AZStd::make_shared(); - - if (BuildSceneMeshFromFbxMesh(createdData, *context.m_sourceNode.GetMesh(), context.m_sourceSceneSystem)) - { - context.m_createdData.push_back(std::move(createdData)); - return Events::ProcessingResult::Success; - } - else - { - return Events::ProcessingResult::Failure; - } - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinImporter.h deleted file mode 100644 index 2ed63a2acd..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinImporter.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxSkinImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxSkinImporter, "{22108E92-7037-442D-94E0-A2E92554A79F}", SceneCore::LoadingComponent); - - FbxSkinImporter(); - ~FbxSkinImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportSkin(FbxNodeEncounteredContext& context); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinWeightsImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinWeightsImporter.cpp deleted file mode 100644 index 3e8b2324d8..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinWeightsImporter.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - const AZStd::string FbxSkinWeightsImporter::s_skinWeightName = "SkinWeight_"; - - FbxSkinWeightsImporter::FbxSkinWeightsImporter() - { - BindToCall(&FbxSkinWeightsImporter::ImportSkinWeights); - BindToCall(&FbxSkinWeightsImporter::SetupNamedBoneLinks); - } - - void FbxSkinWeightsImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxSkinWeightsImporter::ImportSkinWeights(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Skin Weights"); - - if (!IsSkinnedMesh(context.m_sourceNode)) - { - return Events::ProcessingResult::Ignored; - } - - Events::ProcessingResultCombiner combinedSkinWeightsResult; - - for (int deformerIndex = 0; deformerIndex < context.m_sourceNode.GetMesh()->GetDeformerCount(FbxDeformer::eSkin); ++deformerIndex) - { - AZ_TraceContext("Deformer Index", deformerIndex); - AZStd::shared_ptr fbxSkin = - context.m_sourceNode.GetMesh()->GetSkin(deformerIndex); - if (!fbxSkin) - { - return Events::ProcessingResult::Failure; - } - AZStd::string skinWeightName = s_skinWeightName; - skinWeightName += AZStd::to_string(deformerIndex); - RenamedNodesMap::SanitizeNodeName(skinWeightName, context.m_scene.GetGraph(), context.m_currentGraphPosition); - - AZStd::shared_ptr skinDeformer = - BuildSkinWeightData(context.m_sourceNode.GetMesh(), deformerIndex); - - AZ_Assert(skinDeformer, "Failed to allocate skin weighting data."); - if (!skinDeformer) - { - combinedSkinWeightsResult += Events::ProcessingResult::Failure; - continue; - } - - Containers::SceneGraph::NodeIndex newIndex = - context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, skinWeightName.c_str()); - - AZ_Assert(newIndex.IsValid(), "Failed to create SceneGraph node for attribute."); - if (!newIndex.IsValid()) - { - combinedSkinWeightsResult += Events::ProcessingResult::Failure; - continue; - } - - Events::ProcessingResult skinWeightsResult; - SceneAttributeDataPopulatedContext dataPopulated(context, skinDeformer, newIndex, skinWeightName); - skinWeightsResult = Events::Process(dataPopulated); - - if (skinWeightsResult != Events::ProcessingResult::Failure) - { - skinWeightsResult = AddAttributeDataNodeWithContexts(dataPopulated); - } - - combinedSkinWeightsResult += skinWeightsResult; - } - - return combinedSkinWeightsResult.GetResult(); - } - - AZStd::shared_ptr FbxSkinWeightsImporter::BuildSkinWeightData( - const std::shared_ptr& fbxMesh, int skinIndex) - { - AZStd::shared_ptr fbxSkin = fbxMesh->GetSkin(skinIndex); - AZ_Assert(fbxSkin, "BuildSkinWeightData was called for index %i which doesn't contain a skin deformer.", - skinIndex); - if (!fbxSkin) - { - return nullptr; - } - - AZStd::shared_ptr skinWeightData = - AZStd::make_shared(); - - // Cache the new object and the link info for now so it can be resolved at a later point when all - // names have been updated. - Pending pending; - pending.m_fbxMesh = fbxMesh; - pending.m_fbxSkin = fbxSkin; - pending.m_skinWeightData = skinWeightData; - m_pendingSkinWeights.push_back(pending); - - return skinWeightData; - } - - Events::ProcessingResult FbxSkinWeightsImporter::SetupNamedBoneLinks(FinalizeSceneContext& context) - { - AZ_TraceContext("Importer", "Skin Weights"); - - for (auto& it : m_pendingSkinWeights) - { - int controlPointCount = it.m_fbxMesh->GetControlPointsCount(); - it.m_skinWeightData->ResizeContainerSpace(controlPointCount); - - int clusterCount = it.m_fbxSkin->GetClusterCount(); - - for (int clusterIndex = 0; clusterIndex < clusterCount; ++clusterIndex) - { - int controlPointCount2 = it.m_fbxSkin->GetClusterControlPointIndicesCount(clusterIndex); - AZStd::shared_ptr fbxLink = it.m_fbxSkin->GetClusterLink(clusterIndex); - - if (!fbxLink) - { - AZ_TracePrintf(Utilities::WarningWindow, "FBX data contains null skin cluster link at index %i", clusterIndex); - continue; - } - - // The name of the bones may be updated as they get processed. Processing of bones may not necessarily happen before - // processing skin weights so to avoid storing names that will be updated later delay setting up the link until - // all processing has completed. - AZStd::string boneName = context.m_nodeNameMap.GetNodeName(fbxLink); - int boneId = it.m_skinWeightData->GetBoneId(boneName); - - for (int pointIndex = 0; pointIndex < controlPointCount2; ++pointIndex) - { - SceneAPI::DataTypes::ISkinWeightData::Link link; - link.boneId = boneId; - link.weight = aznumeric_caster(it.m_fbxSkin->GetClusterControlPointWeight(clusterIndex, pointIndex)); - it.m_skinWeightData->AppendLink(it.m_fbxSkin->GetClusterControlPointIndex(clusterIndex, pointIndex), link); - } - } - } - const auto result = m_pendingSkinWeights.empty() ? Events::ProcessingResult::Ignored : Events::ProcessingResult::Success; - m_pendingSkinWeights.clear(); - return result; - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinWeightsImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinWeightsImporter.h deleted file mode 100644 index dfe4ee4ecc..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxSkinWeightsImporter.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxMeshWrapper; - } - - namespace SceneData - { - namespace GraphData - { - class SkinWeightData; - } - } - - namespace SceneAPI - { - namespace Events - { - class PostImportEventContext; - } - - namespace FbxSceneBuilder - { - class FbxSkinWeightsImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxSkinWeightsImporter, "{95FCD291-5E1F-4591-90AD-AB5EA2599C3E}", SceneCore::LoadingComponent); - - FbxSkinWeightsImporter(); - ~FbxSkinWeightsImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportSkinWeights(SceneNodeAppendedContext& context); - Events::ProcessingResult SetupNamedBoneLinks(FinalizeSceneContext& context); - - protected: - struct Pending - { - std::shared_ptr m_fbxMesh; - AZStd::shared_ptr m_fbxSkin; - AZStd::shared_ptr m_skinWeightData; - }; - AZStd::shared_ptr BuildSkinWeightData( - const std::shared_ptr& fbxMesh, int skinIndex); - - //! List of skin weights that still need to be filled in. Setting the data for skin weights is - //! delayed until after the tree has been fully constructed as bones are linked by name, but until - //! the graph has been fully filled in, those names can change which would break the names recorded - //! for the skin. - AZStd::vector m_pendingSkinWeights; - - static const AZStd::string s_skinWeightName; - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTangentStreamImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTangentStreamImporter.cpp deleted file mode 100644 index 3a5257d851..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTangentStreamImporter.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxTangentStreamImporter::FbxTangentStreamImporter() - { - BindToCall(&FbxTangentStreamImporter::ImportTangents); - } - - - void FbxTangentStreamImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - - Events::ProcessingResult FbxTangentStreamImporter::ImportTangents(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Tangents"); - std::shared_ptr fbxMesh = context.m_sourceNode.GetMesh(); - if (!fbxMesh) - { - return Events::ProcessingResult::Ignored; - } - - Events::ProcessingResultCombiner combinedStreamResults; - const int numTangentSets = context.m_sourceNode.GetMesh()->GetElementTangentCount(); - for (int elementIndex = 0; elementIndex < numTangentSets; ++elementIndex) - { - AZ_TraceContext("Tangent set index", elementIndex); - - FbxSDKWrapper::FbxVertexTangentWrapper fbxVertexTangents = fbxMesh->GetElementTangent(elementIndex); - if (!fbxVertexTangents.IsValid()) - { - AZ_TracePrintf(Utilities::WarningWindow, "Invalid tangent set found, ignoring"); - continue; - } - - const AZStd::string originalNodeName = AZStd::string::format("TangentSet_Fbx_%d", elementIndex); - const AZStd::string nodeName = AZ::SceneAPI::DataTypes::Utilities::CreateUniqueName(originalNodeName, context.m_scene.GetManifest()); - AZ_TraceContext("Tangent Set Name", nodeName); - if (originalNodeName != nodeName) - { - AZ_TracePrintf(Utilities::WarningWindow, "Tangent set '%s' has been renamed to '%s' because the name was already in use.", originalNodeName.c_str(), nodeName.c_str()); - } - - AZStd::shared_ptr parentData = context.m_scene.GetGraph().GetNodeContent(context.m_currentGraphPosition); - AZ_Assert(parentData && parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid()), "Tried to construct tangent set attribute for invalid or non-mesh parent data"); - if (!parentData || !parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid())) - { - combinedStreamResults += Events::ProcessingResult::Failure; - continue; - } - - const SceneData::GraphData::MeshData* const parentMeshData = azrtti_cast(parentData.get()); - const size_t vertexCount = parentMeshData->GetVertexCount(); - AZStd::shared_ptr tangentStream = BuildVertexTangentData(fbxVertexTangents, vertexCount, fbxMesh); - - AZ_Assert(tangentStream, "Failed to allocate tangent data for scene graph."); - if (!tangentStream) - { - combinedStreamResults += Events::ProcessingResult::Failure; - continue; - } - - tangentStream->SetTangentSetIndex(elementIndex); - tangentStream->SetTangentSpace(AZ::SceneAPI::DataTypes::TangentSpace::FromFbx); - - const Containers::SceneGraph::NodeIndex newIndex = context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, nodeName.c_str()); - AZ_Assert(newIndex.IsValid(), "Failed to create SceneGraph node for attribute."); - if (!newIndex.IsValid()) - { - combinedStreamResults += Events::ProcessingResult::Failure; - continue; - } - - Events::ProcessingResult streamResults; - SceneAttributeDataPopulatedContext dataPopulated(context, tangentStream, newIndex, nodeName); - streamResults = Events::Process(dataPopulated); - - if (streamResults != Events::ProcessingResult::Failure) - { - streamResults = AddAttributeDataNodeWithContexts(dataPopulated); - } - - combinedStreamResults += streamResults; - } - - return combinedStreamResults.GetResult(); - } - - - AZStd::shared_ptr FbxTangentStreamImporter::BuildVertexTangentData(const FbxSDKWrapper::FbxVertexTangentWrapper& tangents, size_t vertexCount, const std::shared_ptr& fbxMesh) - { - AZStd::shared_ptr tangentData = AZStd::make_shared(); - tangentData->ReserveContainerSpace(vertexCount); - - const int fbxPolygonCount = fbxMesh->GetPolygonCount(); - const int* const fbxPolygonVertices = fbxMesh->GetPolygonVertices(); - for (int fbxPolygonIndex = 0; fbxPolygonIndex < fbxPolygonCount; ++fbxPolygonIndex) - { - const int fbxPolygonVertexCount = fbxMesh->GetPolygonSize(fbxPolygonIndex); - if (fbxPolygonVertexCount <= 2) - { - continue; - } - - const int fbxVertexStartIndex = fbxMesh->GetPolygonVertexIndex(fbxPolygonIndex); - for (int index = 0; index < fbxPolygonVertexCount; ++index) - { - const int fbxPolygonVertexIndex = fbxVertexStartIndex + index; - const int fbxControlPointIndex = fbxPolygonVertices[fbxPolygonVertexIndex]; - - const Vector3 tangent = tangents.GetElementAt(fbxPolygonIndex, fbxPolygonVertexIndex, fbxControlPointIndex); - tangentData->AppendTangent(AZ::Vector4(tangent.GetX(), tangent.GetY(), tangent.GetZ(), 1.0f)); - } - } - - if (tangentData->GetCount() != vertexCount) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Vertex count (%i) doesn't match the number of entries for the tangent stream %s (%i)", vertexCount, tangents.GetName(), tangentData->GetCount()); - return nullptr; - } - - return tangentData; - } - - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTangentStreamImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTangentStreamImporter.h deleted file mode 100644 index 38f561eb04..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTangentStreamImporter.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace SceneData - { - namespace GraphData - { - class MeshVertexTangentData; - } - } - - namespace FbxSDKWrapper - { - class FbxMeshWrapper; - class FbxVertexTangentWrapper; - } - - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxTangentStreamImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxTangentStreamImporter, "{70F3A9F5-5BB1-4FE2-BD63-A60C2DCA4589}", SceneCore::LoadingComponent); - - FbxTangentStreamImporter(); - ~FbxTangentStreamImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportTangents(SceneNodeAppendedContext& context); - - protected: - AZStd::shared_ptr BuildVertexTangentData(const FbxSDKWrapper::FbxVertexTangentWrapper& tangents, - size_t vertexCount, const std::shared_ptr& fbxMesh); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTransformImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTransformImporter.cpp deleted file mode 100644 index b1ccfe8acf..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTransformImporter.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - const char* FbxTransformImporter::s_transformNodeName = "transform"; - - FbxTransformImporter::FbxTransformImporter() - { - BindToCall(&FbxTransformImporter::ImportTransform); - } - - void FbxTransformImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxTransformImporter::ImportTransform(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "Transform"); - - DataTypes::MatrixType localTransform; - - if (!GetBindPoseLocalTransform(context.m_sourceScene, context.m_sourceNode, localTransform)) - { - localTransform = context.m_sourceNode.EvaluateLocalTransform(); - DataTypes::MatrixType geoTransform = context.m_sourceNode.GetGeometricTransform(); // transform of the pivot - localTransform *= geoTransform; - } - - if (localTransform == DataTypes::MatrixType::Identity()) - { - return Events::ProcessingResult::Ignored; - } - - - context.m_sourceSceneSystem.SwapTransformForUpAxis(localTransform); - - context.m_sourceSceneSystem.ConvertUnit(localTransform); - - AZStd::shared_ptr transformData = - AZStd::make_shared(localTransform); - AZ_Assert(transformData, "Failed to allocate transform data."); - if (!transformData) - { - return Events::ProcessingResult::Failure; - } - - - // If it is non-endpoint data populated node, add a transform attribute - if (context.m_scene.GetGraph().HasNodeContent(context.m_currentGraphPosition)) - { - if (!context.m_scene.GetGraph().IsNodeEndPoint(context.m_currentGraphPosition)) - { - AZStd::string nodeName = s_transformNodeName; - RenamedNodesMap::SanitizeNodeName(nodeName, context.m_scene.GetGraph(), context.m_currentGraphPosition); - AZ_TraceContext("Transform node name", nodeName); - - Containers::SceneGraph::NodeIndex newIndex = - context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, nodeName.c_str()); - - AZ_Assert(newIndex.IsValid(), "Failed to create SceneGraph node for attribute."); - if (!newIndex.IsValid()) - { - return Events::ProcessingResult::Failure; - } - - Events::ProcessingResult transformAttributeResult; - SceneAttributeDataPopulatedContext dataPopulated(context, transformData, newIndex, nodeName); - transformAttributeResult = Events::Process(dataPopulated); - - if (transformAttributeResult != Events::ProcessingResult::Failure) - { - transformAttributeResult = AddAttributeDataNodeWithContexts(dataPopulated); - } - - return transformAttributeResult; - } - } - else - { - bool addedData = context.m_scene.GetGraph().SetContent( - context.m_currentGraphPosition, - transformData); - - AZ_Assert(addedData, "Failed to add node data"); - return addedData ? Events::ProcessingResult::Success : Events::ProcessingResult::Failure; - } - - return Events::ProcessingResult::Ignored; - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTransformImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTransformImporter.h deleted file mode 100644 index d9e3b5371b..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxTransformImporter.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxTransformImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxTransformImporter, "{354EAAE2-DF31-4E11-BD8A-619419A3EA17}", SceneCore::LoadingComponent); - - FbxTransformImporter(); - ~FbxTransformImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportTransform(SceneNodeAppendedContext& context); - - protected: - static const char* s_transformNodeName; - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxUvMapImporter.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxUvMapImporter.cpp deleted file mode 100644 index b05c64fcad..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxUvMapImporter.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - FbxUvMapImporter::FbxUvMapImporter() - { - BindToCall(&FbxUvMapImporter::ImportUvMaps); - } - - void FbxUvMapImporter::Reflect(ReflectContext* context) - { - SerializeContext* serializeContext = azrtti_cast(context); - if (serializeContext) - { - serializeContext->Class()->Version(1); - } - } - - Events::ProcessingResult FbxUvMapImporter::ImportUvMaps(SceneNodeAppendedContext& context) - { - AZ_TraceContext("Importer", "UV Map"); - std::shared_ptr fbxMesh = - context.m_sourceNode.GetMesh(); - if (!fbxMesh) - { - return Events::ProcessingResult::Ignored; - } - - Events::ProcessingResultCombiner combinedUvMapResults; - - for (int uvElementIndex = 0; uvElementIndex < context.m_sourceNode.GetMesh()->GetElementUVCount(); ++uvElementIndex) - { - AZ_TraceContext("UV Map index", uvElementIndex); - - FbxSDKWrapper::FbxUVWrapper fbxVertexUVs = fbxMesh->GetElementUV(uvElementIndex); - - if (!fbxVertexUVs.IsValid()) - { - AZ_TracePrintf(Utilities::WarningWindow, "Invalid UV Map found, ignoring"); - continue; - } - - AZStd::string nodeName = fbxVertexUVs.GetName(); - RenamedNodesMap::SanitizeNodeName(nodeName, context.m_scene.GetGraph(), context.m_currentGraphPosition, "UV"); - AZ_TraceContext("UV Map Name", nodeName); - - AZStd::shared_ptr parentData = - context.m_scene.GetGraph().GetNodeContent(context.m_currentGraphPosition); - AZ_Assert(parentData && parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid()), - "Tried to construct uv stream attribute for invalid or non-mesh parent data"); - if (!parentData || !parentData->RTTI_IsTypeOf(SceneData::GraphData::MeshData::TYPEINFO_Uuid())) - { - combinedUvMapResults += Events::ProcessingResult::Failure; - continue; - } - - const SceneData::GraphData::MeshData* const parentMeshData = - azrtti_cast(parentData.get()); - size_t vertexCount = parentMeshData->GetVertexCount(); - - AZStd::shared_ptr uvMap = BuildVertexUVData(fbxVertexUVs, vertexCount, fbxMesh); - - AZ_Assert(uvMap, "Failed to allocate UV map data for scene graph."); - if (!uvMap) - { - combinedUvMapResults += Events::ProcessingResult::Failure; - continue; - } - - Containers::SceneGraph::NodeIndex newIndex = - context.m_scene.GetGraph().AddChild(context.m_currentGraphPosition, nodeName.c_str()); - - AZ_Assert(newIndex.IsValid(), "Failed to create SceneGraph node for attribute."); - if (!newIndex.IsValid()) - { - combinedUvMapResults += Events::ProcessingResult::Failure; - continue; - } - - Events::ProcessingResult uvMapResults; - SceneAttributeDataPopulatedContext dataPopulated(context, uvMap, newIndex, nodeName); - uvMapResults = Events::Process(dataPopulated); - - if (uvMapResults != Events::ProcessingResult::Failure) - { - uvMapResults = AddAttributeDataNodeWithContexts(dataPopulated); - } - - combinedUvMapResults += uvMapResults; - } - - return combinedUvMapResults.GetResult(); - } - - AZStd::shared_ptr FbxUvMapImporter::BuildVertexUVData(const FbxSDKWrapper::FbxUVWrapper& uvs, - size_t vertexCount, const std::shared_ptr& fbxMesh) - { - AZStd::shared_ptr uvData = AZStd::make_shared(); - uvData->ReserveContainerSpace(vertexCount); - uvData->SetCustomName(uvs.GetName()); - - const int fbxPolygonCount = fbxMesh->GetPolygonCount(); - const int* const fbxPolygonVertices = fbxMesh->GetPolygonVertices(); - for (int fbxPolygonIndex = 0; fbxPolygonIndex < fbxPolygonCount; ++fbxPolygonIndex) - { - const int fbxPolygonVertexCount = fbxMesh->GetPolygonSize(fbxPolygonIndex); - if (fbxPolygonVertexCount <= 2) - { - continue; - } - - const int fbxVertexStartIndex = fbxMesh->GetPolygonVertexIndex(fbxPolygonIndex); - - for (int uvIndex = 0; uvIndex < fbxPolygonVertexCount; ++uvIndex) - { - const int fbxPolygonVertexIndex = fbxVertexStartIndex + uvIndex; - const int fbxControlPointIndex = fbxPolygonVertices[fbxPolygonVertexIndex]; - - Vector2 uv = uvs.GetElementAt(fbxPolygonIndex, fbxPolygonVertexIndex, fbxControlPointIndex); - uv.SetY(1.0f - uv.GetY()); - uvData->AppendUV(uv); - } - } - - if (uvData->GetCount() != vertexCount) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Vertex count (%i) doesn't match the number of entries for the uv set %s (%i)", - vertexCount, uvs.GetName(), uvData->GetCount()); - return nullptr; - } - - return uvData; - - } - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxUvMapImporter.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxUvMapImporter.h deleted file mode 100644 index f64de0034f..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxUvMapImporter.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace AZ -{ - namespace SceneData - { - namespace GraphData - { - class MeshVertexUVData; - } - } - - namespace FbxSDKWrapper - { - class FbxMeshWrapper; - class FbxUVWrapper; - } - - namespace SceneAPI - { - namespace FbxSceneBuilder - { - class FbxUvMapImporter - : public SceneCore::LoadingComponent - { - public: - AZ_COMPONENT(FbxUvMapImporter, "{B16CD69D-3C0C-4FE2-B481-1084B1C36242}", SceneCore::LoadingComponent); - - FbxUvMapImporter(); - ~FbxUvMapImporter() override = default; - - static void Reflect(ReflectContext* context); - - Events::ProcessingResult ImportUvMaps(SceneNodeAppendedContext& context); - - protected: - AZStd::shared_ptr BuildVertexUVData(const FbxSDKWrapper::FbxUVWrapper& uvs, - size_t vertexCount, const std::shared_ptr& fbxMesh); - }; - } // namespace FbxSceneBuilder - } // namespace SceneAPI -} // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.cpp similarity index 85% rename from Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.cpp rename to Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.cpp index b50517381d..9b47e3e34a 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.cpp @@ -12,12 +12,8 @@ #include #include -#include #include -#include -#include -#include -#include +#include #include #include #include @@ -50,19 +46,7 @@ namespace AZ dataPopulated.m_scene.GetGraph().SetContent(dataPopulated.m_currentGraphPosition, AZStd::move(dataPopulated.m_graphData)); - if (azrtti_istypeof(dataPopulated)) - { - SceneDataPopulatedContext* dataPopulatedContext = azrtti_cast(&dataPopulated); - SceneNodeAppendedContext nodeAppended(*dataPopulatedContext, dataPopulated.m_currentGraphPosition); - nodeResults += Events::Process(nodeAppended); - - SceneNodeAddedAttributesContext addedAttributes(nodeAppended); - nodeResults += Events::Process(addedAttributes); - - SceneNodeFinalizeContext finalizeNode(addedAttributes); - nodeResults += Events::Process(finalizeNode); - } - else + if (azrtti_istypeof(dataPopulated)) { AssImpSceneDataPopulatedContext* dataPopulatedContext = azrtti_cast(&dataPopulated); AssImpSceneNodeAppendedContext nodeAppended(*dataPopulatedContext, dataPopulated.m_currentGraphPosition); @@ -91,13 +75,7 @@ namespace AZ dataPopulated.m_scene.GetGraph().SetContent(dataPopulated.m_currentGraphPosition, AZStd::move(dataPopulated.m_graphData)); - if (azrtti_istypeof(dataPopulated)) - { - SceneAttributeDataPopulatedContext* dataPopulatedContext = azrtti_cast(&dataPopulated); - SceneAttributeNodeAppendedContext nodeAppended(*dataPopulatedContext, dataPopulated.m_currentGraphPosition); - nodeResults += Events::Process(nodeAppended); - } - else + if (azrtti_istypeof(dataPopulated)) { AssImpSceneAttributeDataPopulatedContext* dataPopulatedContext = azrtti_cast(&dataPopulated); AssImpSceneAttributeNodeAppendedContext nodeAppended(*dataPopulatedContext, dataPopulated.m_currentGraphPosition); @@ -456,48 +434,6 @@ namespace AZ return true; } - - bool GetBindPoseLocalTransform(const FbxSDKWrapper::FbxSceneWrapper& sceneWrapper, - FbxSDKWrapper::FbxNodeWrapper& nodeWrapper, SceneAPI::DataTypes::MatrixType& xf) - { - PoseList poseList; - FbxArray nodeIndices; - - FbxNode* node = nodeWrapper.GetFbxNode(); - - FbxScene* scene = sceneWrapper.GetFbxScene(); - FbxMatrix nodeMatrix; - if (FbxPose::GetBindPoseContaining(scene, node, poseList, nodeIndices)) - { - nodeMatrix = poseList[0]->GetMatrix(nodeIndices[0]); - } - else - { - return false; - } - - // We are after the local transform of the node while fbx bind pose provides the global transform. - // To get the local transform, we multiply with the inverse of the parent's global transform. - FbxNode* parentNode = node->GetParent(); - FbxMatrix parentMatrix; - if (parentNode) - { - poseList.Clear(); - nodeIndices.Clear(); - if (FbxPose::GetBindPoseContaining(scene, parentNode, poseList, nodeIndices)) - { - parentMatrix = poseList[0]->GetMatrix(nodeIndices[0]); - } - else - { - parentMatrix = parentNode->EvaluateGlobalTransform(); - } - } - FbxMatrix nodeLocalMatrix = parentMatrix.Inverse() * nodeMatrix; - xf = FbxSDKWrapper::FbxTypeConverter::ToTransform(nodeLocalMatrix); - return true; - } - } // namespace FbxSceneBuilder } // namespace SceneAPI } // namespace AZ diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.h similarity index 74% rename from Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.h rename to Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.h index 7f16422fdb..d3577d54af 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.h +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.h @@ -12,7 +12,9 @@ #pragma once -#include +#include +#include +#include #include #include @@ -20,12 +22,6 @@ namespace AZ { struct Uuid; - namespace FbxSDKWrapper - { - class FbxNodeWrapper; - class FbxSceneWrapper; - } - namespace SceneAPI { namespace FbxSceneBuilder @@ -42,7 +38,6 @@ namespace AZ const AZ::Uuid& uuid); inline bool NodeHasAncestorOfType(const CoreSceneGraph& graph, CoreGraphNodeIndex nodeIndex, const AZ::Uuid& uuid); - inline bool IsSkinnedMesh(const FbxSDKWrapper::FbxNodeWrapper& sourceNode); CoreProcessingResult AddDataNodeWithContexts(SceneDataPopulatedContextBase& dataContext); CoreProcessingResult AddAttributeDataNodeWithContexts(SceneAttributeDataPopulatedContextBase& dataContext); bool AreSceneGraphsEqual(const CoreSceneGraph& lhsGraph, const CoreSceneGraph& rhsGraph); @@ -51,12 +46,8 @@ namespace AZ bool IsGraphDataEqual(const AZStd::shared_ptr& lhs, const AZStd::shared_ptr& rhs); - // If the scene contains bindpose information for the node, returns true and sets "xf" to the local transform - // of the node in bindpose. Returns false if bindpose info is not available for the node. - bool GetBindPoseLocalTransform(const FbxSDKWrapper::FbxSceneWrapper& sceneWrapper, - FbxSDKWrapper::FbxNodeWrapper& nodeWrapper, DataTypes::MatrixType& xf); } // namespace FbxSceneBuilder } // namespace SceneAPI } // namespace AZ -#include +#include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.inl b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.inl similarity index 81% rename from Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.inl rename to Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.inl index 3fd0e02f08..f56982a06c 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/FbxImporterUtilities.inl +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/ImporterUtilities.inl @@ -10,10 +10,7 @@ * */ -#include -#include -#include -#include +#include #include #include @@ -57,12 +54,6 @@ namespace AZ return false; } - bool IsSkinnedMesh(const FbxSDKWrapper::FbxNodeWrapper& sourceNode) - { - const std::shared_ptr fbxMesh = sourceNode.GetMesh(); - return (fbxMesh && (fbxMesh->GetDeformerCount(FbxDeformer::eSkin) > 0 || fbxMesh->GetDeformerCount(FbxDeformer::eBlendShape) > 0)); - } - bool AreScenesEqual(const CoreScene& lhs, const CoreScene& rhs) { if (lhs.GetGraph().GetNodeCount() != rhs.GetGraph().GetNodeCount()) diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/FbxMeshImporterUtilities.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/FbxMeshImporterUtilities.cpp deleted file mode 100644 index 5dddaff4d8..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/FbxMeshImporterUtilities.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - namespace SceneAPI - { - namespace FbxSceneBuilder - { - bool BuildSceneMeshFromFbxMesh(const AZStd::shared_ptr& mesh, - const FbxSDKWrapper::FbxMeshWrapper& sourceMesh, const FbxSceneSystem& sceneSystem) - { - // Save unit sizes of the mesh - mesh->SetUnitSizeInMeters(sceneSystem.GetUnitSizeInMeters()); - mesh->SetOriginalUnitSizeInMeters(sceneSystem.GetOriginalUnitSizeInMeters()); - - // Get mesh subset count by scanning material IDs in meshes. - // For negative material ids we will add an additional - // subset at the end, see "++maxMaterialIndex". - - // These defines material index range for all polygons in the mesh - // Each polygon has a material index - int minMeshMaterialIndex = INT_MAX; - int maxMeshMaterialIndex = INT_MIN; - - FbxLayerElementArrayTemplate* fbxMaterialIndices; - sourceMesh.GetMaterialIndices(&fbxMaterialIndices); // per polygon - - int fbxPolygonCount = sourceMesh.GetPolygonCount(); - - AZ_Error("FbxSceneBuilder", fbxPolygonCount, - "Source mesh %s polygon count is 0. Zero count meshes are not supported, either remove this mesh or add polygons to it.", - sourceMesh.GetName()); - for (int fbxPolygonIndex = 0; fbxPolygonIndex < fbxPolygonCount; ++fbxPolygonIndex) - { - // if the polygon has less than 3 vertices, it's not a valid polygon and is skipped - const int fbxPolygonVertexCount = sourceMesh.GetPolygonSize(fbxPolygonIndex); - if (fbxPolygonVertexCount <= 2) - { - continue; - } - - // Get the material index of each polygon - const int meshMaterialIndex = fbxMaterialIndices ? (*fbxMaterialIndices)[fbxPolygonIndex] : -1; - minMeshMaterialIndex = AZ::GetMin(minMeshMaterialIndex, meshMaterialIndex); - maxMeshMaterialIndex = AZ::GetMax(maxMeshMaterialIndex, meshMaterialIndex); - } - - if (minMeshMaterialIndex > maxMeshMaterialIndex) - { - return false; - } - - if (maxMeshMaterialIndex < 0) - { - minMeshMaterialIndex = maxMeshMaterialIndex = 0; - } - else if (minMeshMaterialIndex < 0) - { - minMeshMaterialIndex = 0; - ++maxMeshMaterialIndex; - } - - // Fill geometry - - // Control points contain positions of vertices - AZStd::vector fbxControlPoints = sourceMesh.GetControlPoints(); - const int* const fbxPolygonVertices = sourceMesh.GetPolygonVertices(); - - fbxMaterialIndices = nullptr; - sourceMesh.GetMaterialIndices(&fbxMaterialIndices); // per polygon - - // Iterate through each polygon in the mesh and convert data - fbxPolygonCount = sourceMesh.GetPolygonCount(); - for (int fbxPolygonIndex = 0; fbxPolygonIndex < fbxPolygonCount; ++fbxPolygonIndex) - { - const int fbxPolygonVertexCount = sourceMesh.GetPolygonSize(fbxPolygonIndex); - if (fbxPolygonVertexCount <= 2) - { - continue; - } - - AZ_TraceContext("Polygon Index", fbxPolygonIndex); - - // Ensure the validity of the material index for the polygon - int fbxMaterialIndex = fbxMaterialIndices ? (*fbxMaterialIndices)[fbxPolygonIndex] : -1; - if (fbxMaterialIndex < minMeshMaterialIndex || fbxMaterialIndex > maxMeshMaterialIndex) - { - fbxMaterialIndex = maxMeshMaterialIndex; - } - - const int fbxVertexStartIndex = sourceMesh.GetPolygonVertexIndex(fbxPolygonIndex); - - // Triangulate polygon as a fan and remember resulting vertices and faces - - int firstMeshVertexIndex = -1; - int previousMeshVertexIndex = -1; - - AZ::SceneAPI::DataTypes::IMeshData::Face meshFace; - int verticesInMeshFace = 0; - - // Iterate through each vertex in the polygon - for (int vertexIndex = 0; vertexIndex < fbxPolygonVertexCount; ++vertexIndex) - { - const int meshVertexIndex = aznumeric_caster(mesh->GetVertexCount()); - - const int fbxPolygonVertexIndex = fbxVertexStartIndex + vertexIndex; - const int fbxControlPointIndex = fbxPolygonVertices[fbxPolygonVertexIndex]; - - Vector3 meshPosition = fbxControlPoints[fbxControlPointIndex]; - - Vector3 meshVertexNormal; - sourceMesh.GetPolygonVertexNormal(fbxPolygonIndex, vertexIndex, meshVertexNormal); - - sceneSystem.SwapVec3ForUpAxis(meshPosition); - sceneSystem.ConvertUnit(meshPosition); - // Add position - mesh->AddPosition(meshPosition); - - // Add normal - sceneSystem.SwapVec3ForUpAxis(meshVertexNormal); - meshVertexNormal.NormalizeSafe(); - mesh->AddNormal(meshVertexNormal); - - mesh->SetVertexIndexToControlPointIndexMap(meshVertexIndex, fbxControlPointIndex); - - // Add face - { - if (vertexIndex == 0) - { - firstMeshVertexIndex = meshVertexIndex; - } - - int meshVertices[3]; - int meshVertexCount = 0; - - meshVertices[meshVertexCount++] = meshVertexIndex; - - // If we already have generated one triangle before, make a new triangle at a time as we encounter a new vertex. - // The new triangle is composed with the first vertex of the polygon, the last vertex, and the current vertex. - if (vertexIndex >= 3) - { - meshVertices[meshVertexCount++] = firstMeshVertexIndex; - meshVertices[meshVertexCount++] = previousMeshVertexIndex; - } - - for (int faceVertexIndex = 0; faceVertexIndex < meshVertexCount; ++faceVertexIndex) - { - meshFace.vertexIndex[verticesInMeshFace++] = meshVertices[faceVertexIndex]; - if (verticesInMeshFace == 3) - { - verticesInMeshFace = 0; - mesh->AddFace(meshFace, fbxMaterialIndex); - } - } - } - - previousMeshVertexIndex = meshVertexIndex; - } - - // Report problem if there are vertices that left for forming a polygon - if (verticesInMeshFace != 0) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Internal error in mesh filler"); - return false; - } - } - - // Report problem if no vertex or face converted to MeshData - if (mesh->GetVertexCount() <= 0 || mesh->GetFaceCount() <= 0) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Missing geometry data in mesh node"); - return false; - } - - return true; - } - - // Currently doesn't maintain a list of unique control points. - // Normals are associated with each triangle vertex from the face. - bool BuildSceneBlendShapeFromFbxBlendShape(const AZStd::shared_ptr& blendShape, - const AZStd::shared_ptr& sourceMesh, const FbxSceneSystem& sceneSystem) - { - // Control points contain positions of vertices - const AZStd::vector& fbxControlPoints = sourceMesh->GetControlPoints(); - const int* const fbxPolygonVertices = sourceMesh->GetPolygonVertices(); - - // Iterate through each polygon in the mesh and convert data - const int fbxPolygonCount = sourceMesh->GetPolygonCount(); - - for (int fbxPolygonIndex = 0; fbxPolygonIndex < fbxPolygonCount; ++fbxPolygonIndex) - { - const int fbxPolygonVertexCount = sourceMesh->GetPolygonSize(fbxPolygonIndex); - if (fbxPolygonVertexCount <= 2) - { - continue; - } - - AZ_TraceContext("Polygon Index", fbxPolygonIndex); - - const int fbxVertexStartIndex = sourceMesh->GetPolygonVertexIndex(fbxPolygonIndex); - - // Triangulate polygon as a fan and remember resulting vertices and faces - - int firstMeshVertexIndex = -1; - int previousMeshVertexIndex = -1; - - DataTypes::IBlendShapeData::Face face; - int verticesInMeshFace = 0; - - // Iterate through each vertex in the polygon - for (int vertexIndex = 0; vertexIndex < fbxPolygonVertexCount; ++vertexIndex) - { - const int meshVertexIndex = aznumeric_caster(blendShape->GetVertexCount()); - - const int fbxPolygonVertexIndex = fbxVertexStartIndex + vertexIndex; - const int fbxControlPointIndex = fbxPolygonVertices[fbxPolygonVertexIndex]; - - // This data allows for mapping vertex data to original Control Point index. - blendShape->SetVertexIndexToControlPointIndexMap(meshVertexIndex, fbxControlPointIndex); - - Vector3 meshVertexPosition = fbxControlPoints[fbxControlPointIndex]; - Vector3 meshVertexNormal; - sourceMesh->GetPolygonVertexNormal(fbxPolygonIndex, vertexIndex, meshVertexNormal); - - // position - sceneSystem.SwapVec3ForUpAxis(meshVertexPosition); - sceneSystem.ConvertUnit(meshVertexPosition); - - // normal - sceneSystem.SwapVec3ForUpAxis(meshVertexNormal); - meshVertexNormal.Normalize(); - - blendShape->AddPosition(meshVertexPosition); - blendShape->AddNormal(meshVertexNormal); - - // Add face - { - if (vertexIndex == 0) - { - firstMeshVertexIndex = meshVertexIndex; - } - - int meshVertices[3]; - int meshNormals[3]; - - int meshVertexCount = 0; - - meshVertices[meshVertexCount] = meshVertexIndex; - meshNormals[meshVertexCount++] = meshVertexIndex; - - // If we already have generated one triangle before, make a new triangle at a time as we encounter a new vertex. - // The new triangle is composed with the first vertex of the polygon, the last vertex, and the current vertex. - if (vertexIndex >= 3) - { - meshVertices[meshVertexCount++] = firstMeshVertexIndex; - meshVertices[meshVertexCount++] = previousMeshVertexIndex; - } - - for (int faceVertexIndex = 0; faceVertexIndex < meshVertexCount; ++faceVertexIndex) - { - face.vertexIndex[verticesInMeshFace++] = meshVertices[faceVertexIndex]; - - if (verticesInMeshFace == 3) - { - verticesInMeshFace = 0; - blendShape->AddFace(face); - break; - } - } - } - - previousMeshVertexIndex = meshVertexIndex; - } - - // Report problem if there are vertices that left for forming a polygon - if (verticesInMeshFace != 0) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Internal error in mesh filler. Vertices were left without forming polygon"); - return false; - } - } - - // Report problem if no vertex or face converted to MeshData - if (blendShape->GetVertexCount() <= 0 || blendShape->GetFaceCount() <= 0) - { - AZ_TracePrintf(Utilities::ErrorWindow, "Missing geometry data in blendshape node"); - return false; - } - - return true; - } - } - } -} diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/FbxMeshImporterUtilities.h b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/FbxMeshImporterUtilities.h deleted file mode 100644 index efb85e5275..0000000000 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/FbxMeshImporterUtilities.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -namespace AZ -{ - namespace FbxSDKWrapper - { - class FbxMeshWrapper; - } - - namespace SceneData - { - namespace GraphData - { - class MeshData; - class BlendShapeData; - } - } - - namespace SceneAPI - { - class FbxSceneSystem; - namespace FbxSceneBuilder - { - bool BuildSceneMeshFromFbxMesh(const AZStd::shared_ptr& mesh, - const FbxSDKWrapper::FbxMeshWrapper& sourceMesh, const FbxSceneSystem& sceneSystem); - bool BuildSceneBlendShapeFromFbxBlendShape(const AZStd::shared_ptr& blendShape, - const AZStd::shared_ptr& sourceMesh, const FbxSceneSystem& sceneSystem); - } - } -} diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/RenamedNodesMap.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/RenamedNodesMap.cpp index 3c0414734f..abc095d583 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/RenamedNodesMap.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Importers/Utilities/RenamedNodesMap.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/Tests/Importers/FbxImporterUtilitiesTests.cpp b/Code/Tools/SceneAPI/FbxSceneBuilder/Tests/Importers/FbxImporterUtilitiesTests.cpp index 7ac64b3eda..66db966cac 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/Tests/Importers/FbxImporterUtilitiesTests.cpp +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/Tests/Importers/FbxImporterUtilitiesTests.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Code/Tools/SceneAPI/FbxSceneBuilder/fbxscenebuilder_files.cmake b/Code/Tools/SceneAPI/FbxSceneBuilder/fbxscenebuilder_files.cmake index 93976a1709..92e02f3c6d 100644 --- a/Code/Tools/SceneAPI/FbxSceneBuilder/fbxscenebuilder_files.cmake +++ b/Code/Tools/SceneAPI/FbxSceneBuilder/fbxscenebuilder_files.cmake @@ -19,39 +19,8 @@ set(FILES FbxSceneSystem.cpp ImportContexts/ImportContexts.h ImportContexts/ImportContexts.cpp - ImportContexts/FbxImportContexts.h - ImportContexts/FbxImportContexts.cpp ImportContexts/AssImpImportContexts.h ImportContexts/AssImpImportContexts.cpp - Importers/FbxAnimationImporter.h - Importers/FbxAnimationImporter.cpp - Importers/FbxBoneImporter.h - Importers/FbxBoneImporter.cpp - Importers/FbxBlendShapeImporter.h - Importers/FbxBlendShapeImporter.cpp - Importers/FbxColorStreamImporter.h - Importers/FbxColorStreamImporter.cpp - Importers/FbxTangentStreamImporter.h - Importers/FbxTangentStreamImporter.cpp - Importers/FbxBitangentStreamImporter.h - Importers/FbxBitangentStreamImporter.cpp - Importers/FbxImporterUtilities.h - Importers/FbxImporterUtilities.inl - Importers/FbxImporterUtilities.cpp - Importers/FbxMaterialImporter.h - Importers/FbxMaterialImporter.cpp - Importers/FbxMeshImporter.h - Importers/FbxMeshImporter.cpp - Importers/FbxSkinImporter.h - Importers/FbxSkinImporter.cpp - Importers/FbxSkinWeightsImporter.h - Importers/FbxSkinWeightsImporter.cpp - Importers/FbxTransformImporter.h - Importers/FbxTransformImporter.cpp - Importers/FbxUvMapImporter.h - Importers/FbxUvMapImporter.cpp - Importers/Utilities/FbxMeshImporterUtilities.h - Importers/Utilities/FbxMeshImporterUtilities.cpp Importers/Utilities/AssImpMeshImporterUtilities.h Importers/Utilities/AssImpMeshImporterUtilities.cpp Importers/Utilities/RenamedNodesMap.h @@ -84,4 +53,7 @@ set(FILES Importers/AssImpUvMapImporter.cpp Importers/AssImpAnimationImporter.h Importers/AssImpAnimationImporter.cpp + Importers/ImporterUtilities.h + Importers/ImporterUtilities.cpp + Importers/ImporterUtilities.inl ) diff --git a/Code/Tools/SceneAPI/FbxSDKWrapper/CMakeLists.txt b/Code/Tools/SceneAPI/SDKWrapper/CMakeLists.txt similarity index 84% rename from Code/Tools/SceneAPI/FbxSDKWrapper/CMakeLists.txt rename to Code/Tools/SceneAPI/SDKWrapper/CMakeLists.txt index ddbabe604d..b1664ca7e5 100644 --- a/Code/Tools/SceneAPI/FbxSDKWrapper/CMakeLists.txt +++ b/Code/Tools/SceneAPI/SDKWrapper/CMakeLists.txt @@ -16,21 +16,18 @@ endif() set(sdkwrapper_dir ${CMAKE_CURRENT_LIST_DIR}/../SDKWrapper) ly_add_target( - NAME FbxSDKWrapper STATIC + NAME SDKWrapper STATIC NAMESPACE AZ FILES_CMAKE - fbxsdkwrapper_files.cmake - ${sdkwrapper_dir}/sdkwrapper_files.cmake + sdkwrapper_files.cmake INCLUDE_DIRECTORIES PUBLIC . ../.. - ${sdkwrapper_dir} BUILD_DEPENDENCIES PRIVATE AZ::AzCore AZ::AzToolsFramework PUBLIC - 3rdParty::FbxSdk 3rdParty::assimplib ) diff --git a/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp b/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp index 4de42eb944..989eccd526 100644 --- a/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp +++ b/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.cpp @@ -13,9 +13,135 @@ #include #include #include +#include +#include +#include namespace AZ { + namespace Python + { + static const char* const None = "None"; + + class PythonBehaviorInfo final + { + public: + AZ_RTTI(PythonBehaviorInfo, "{8055BD03-5B3B-490D-AEC5-1B1E2616D529}"); + AZ_CLASS_ALLOCATOR(PythonBehaviorInfo, AZ::SystemAllocator, 0); + + static void Reflect(AZ::ReflectContext* context); + + PythonBehaviorInfo(const AZ::BehaviorClass* behaviorClass); + PythonBehaviorInfo() = delete; + + protected: + bool IsMemberLike(const AZ::BehaviorMethod& method, const AZ::TypeId& typeId) const; + AZStd::string FetchPythonType(const AZ::BehaviorParameter& param) const; + void WriteMethod(AZStd::string_view methodName, const AZ::BehaviorMethod& behaviorMethod); + + private: + const AZ::BehaviorClass* m_behaviorClass = nullptr; + AZStd::vector m_methodList; + }; + + PythonBehaviorInfo::PythonBehaviorInfo(const AZ::BehaviorClass* behaviorClass) + : m_behaviorClass(behaviorClass) + { + AZ_Assert(m_behaviorClass, "PythonBehaviorInfo requires a valid behaviorClass pointer"); + for (const auto& entry : behaviorClass->m_methods) + { + WriteMethod(entry.first, *entry.second); + } + } + + void PythonBehaviorInfo::Reflect(AZ::ReflectContext* context) + { + AZ::BehaviorContext* behaviorContext = azrtti_cast(context); + if (behaviorContext) + { + behaviorContext->Class() + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene.graph") + ->Property("className", [](const PythonBehaviorInfo& self) + { return self.m_behaviorClass->m_name; }, nullptr) + ->Property("classUuid", [](const PythonBehaviorInfo& self) + { return self.m_behaviorClass->m_typeId.ToString(); }, nullptr) + ->Property("methodList", BehaviorValueGetter(&PythonBehaviorInfo::m_methodList), nullptr); + } + } + + bool PythonBehaviorInfo::IsMemberLike(const AZ::BehaviorMethod& method, const AZ::TypeId& typeId) const + { + return method.IsMember() || (method.GetNumArguments() > 0 && method.GetArgument(0)->m_typeId == typeId); + } + + AZStd::string PythonBehaviorInfo::FetchPythonType(const AZ::BehaviorParameter& param) const + { + using namespace AzToolsFramework; + EditorPythonConsoleInterface* editorPythonConsoleInterface = AZ::Interface::Get(); + if (editorPythonConsoleInterface) + { + return editorPythonConsoleInterface->FetchPythonTypeName(param); + } + return None; + } + + void PythonBehaviorInfo::WriteMethod(AZStd::string_view methodName, const AZ::BehaviorMethod& behaviorMethod) + { + // if the method is a static method then it is not a part of the abstract class + const bool isMemberLike = IsMemberLike(behaviorMethod, m_behaviorClass->m_typeId); + if (isMemberLike == false) + { + return; + } + + AZStd::string buffer; + AZStd::vector pythonArgs; + + AzFramework::StringFunc::Append(buffer, "def "); + AzFramework::StringFunc::Append(buffer, methodName.data()); + AzFramework::StringFunc::Append(buffer, "("); + + pythonArgs.emplace_back("self"); + + AZStd::string bufferArg; + for (size_t argIndex = 1; argIndex < behaviorMethod.GetNumArguments(); ++argIndex) + { + const AZStd::string* name = behaviorMethod.GetArgumentName(argIndex); + if (!name || name->empty()) + { + bufferArg = AZStd::string::format(" arg%zu", argIndex); + } + else + { + bufferArg = *name; + } + + AZStd::string_view type = FetchPythonType(*behaviorMethod.GetArgument(argIndex)); + if (!type.empty()) + { + AzFramework::StringFunc::Append(bufferArg, ": "); + AzFramework::StringFunc::Append(bufferArg, type.data()); + } + + pythonArgs.push_back(bufferArg); + bufferArg.clear(); + } + + AZStd::string resultValue{ None }; + if (behaviorMethod.HasResult() && behaviorMethod.GetResult()) + { + resultValue = FetchPythonType(*behaviorMethod.GetResult()); + } + + AZStd::string argsList; + AzFramework::StringFunc::Join(buffer, pythonArgs.begin(), pythonArgs.end(), ","); + AzFramework::StringFunc::Append(buffer, ") -> "); + AzFramework::StringFunc::Append(buffer, resultValue.c_str()); + m_methodList.emplace_back(buffer); + } + } + namespace SceneAPI { namespace Containers @@ -25,11 +151,29 @@ namespace AZ AZ::BehaviorContext* behaviorContext = azrtti_cast(context); if (behaviorContext) { + Python::PythonBehaviorInfo::Reflect(context); + + behaviorContext->Class(); + behaviorContext->Class() ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) ->Attribute(AZ::Script::Attributes::Module, "scene.graph") + ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All) ->Method("CastWithTypeName", &GraphObjectProxy::CastWithTypeName) ->Method("Invoke", &GraphObjectProxy::Invoke) + ->Method("GetClassInfo", [](GraphObjectProxy& self) -> Python::PythonBehaviorInfo* + { + if (self.m_pythonBehaviorInfo) + { + return self.m_pythonBehaviorInfo.get(); + } + if (self.m_behaviorClass) + { + self.m_pythonBehaviorInfo = AZStd::make_shared(self.m_behaviorClass); + return self.m_pythonBehaviorInfo.get(); + } + return nullptr; + }) ; } } diff --git a/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.h b/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.h index 094b896364..d83a147e5f 100644 --- a/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.h +++ b/Code/Tools/SceneAPI/SceneCore/Containers/GraphObjectProxy.h @@ -16,6 +16,11 @@ namespace AZ { + namespace Python + { + class PythonBehaviorInfo; + } + namespace SceneAPI { namespace Containers @@ -44,6 +49,7 @@ namespace AZ private: AZStd::shared_ptr m_graphObject; const AZ::BehaviorClass* m_behaviorClass = nullptr; + AZStd::shared_ptr m_pythonBehaviorInfo; }; } // Containers diff --git a/Code/Tools/SceneAPI/SceneCore/Tests/Containers/SceneBehaviorTests.cpp b/Code/Tools/SceneAPI/SceneCore/Tests/Containers/SceneBehaviorTests.cpp index cb23e73b0e..8d7fb63baf 100644 --- a/Code/Tools/SceneAPI/SceneCore/Tests/Containers/SceneBehaviorTests.cpp +++ b/Code/Tools/SceneAPI/SceneCore/Tests/Containers/SceneBehaviorTests.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -378,6 +379,25 @@ namespace AZ MOCK_CONST_METHOD1(QueryApplicationType, void(AZ::ApplicationTypeQuery&)); }; + class MockEditorPythonConsoleInterface final + : public AzToolsFramework::EditorPythonConsoleInterface + { + public: + MockEditorPythonConsoleInterface() + { + AZ::Interface::Register(this); + } + + ~MockEditorPythonConsoleInterface() + { + AZ::Interface::Unregister(this); + } + + MOCK_CONST_METHOD1(GetModuleList, void(AZStd::vector&)); + MOCK_CONST_METHOD1(GetGlobalFunctionList, void(GlobalFunctionCollection&)); + MOCK_METHOD1(FetchPythonTypeName, AZStd::string(const AZ::BehaviorParameter&)); + }; + // // SceneGraphBehaviorScriptTest // @@ -386,6 +406,7 @@ namespace AZ { public: AZStd::unique_ptr m_componentApplication; + AZStd::unique_ptr m_editorPythonConsoleInterface; AZStd::unique_ptr m_scriptContext; AZStd::unique_ptr m_behaviorContext; AZStd::unique_ptr m_serializeContext; @@ -454,6 +475,15 @@ namespace AZ { return this->m_serializeContext.get(); })); + + m_editorPythonConsoleInterface = AZStd::make_unique(); + } + + void SetupEditorPythonConsoleInterface() + { + EXPECT_CALL(*m_editorPythonConsoleInterface, FetchPythonTypeName(::testing::_)) + .Times(4) + .WillRepeatedly(::testing::Invoke([](const AZ::BehaviorParameter&) {return "int"; })); } void TearDown() override @@ -562,6 +592,38 @@ namespace AZ ExpectExecute("TestExpectEquals(value, 17)"); } + TEST_F(SceneGraphBehaviorScriptTest, GraphObjectProxy_GetClassInfo_Loads) + { + SetupEditorPythonConsoleInterface(); + + ExpectExecute("builder = MockBuilder()"); + ExpectExecute("builder:BuildSceneGraph()"); + ExpectExecute("scene = builder:GetScene()"); + ExpectExecute("nodeG = scene.graph:FindWithPath('A.C.E.G')"); + ExpectExecute("proxy = scene.graph:GetNodeContent(nodeG)"); + ExpectExecute("TestExpectTrue(proxy:CastWithTypeName('MockIGraphObject'))"); + ExpectExecute("info = proxy:GetClassInfo()"); + ExpectExecute("TestExpectTrue(info ~= nil)"); + } + + TEST_F(SceneGraphBehaviorScriptTest, GraphObjectProxy_GetClassInfo_CorrectFormats) + { + SetupEditorPythonConsoleInterface(); + + ExpectExecute("builder = MockBuilder()"); + ExpectExecute("builder:BuildSceneGraph()"); + ExpectExecute("scene = builder:GetScene()"); + ExpectExecute("nodeG = scene.graph:FindWithPath('A.C.E.G')"); + ExpectExecute("proxy = scene.graph:GetNodeContent(nodeG)"); + ExpectExecute("TestExpectTrue(proxy:CastWithTypeName('MockIGraphObject'))"); + ExpectExecute("info = proxy:GetClassInfo()"); + ExpectExecute("TestExpectTrue(info.className == 'MockIGraphObject')"); + ExpectExecute("TestExpectTrue(info.classUuid == '{66A082CC-851D-4E1F-ABBD-45B58A216CFA}')"); + ExpectExecute("TestExpectTrue(info.methodList[1] == 'def GetId(self) -> int')"); + ExpectExecute("TestExpectTrue(info.methodList[2] == 'def SetId(self, arg1: int) -> None')"); + ExpectExecute("TestExpectTrue(info.methodList[3] == 'def AddAndSet(self, arg1: int, arg2: int) -> None')"); + } + // // SceneManifestBehaviorScriptTest is meant to test the script abilities of the SceneManifest // diff --git a/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h b/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h index 9ae287da46..403ab867f2 100644 --- a/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h +++ b/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h @@ -31,7 +31,7 @@ namespace AZ public: AZ_RTTI(BlendShapeData, "{FF875C22-2E4F-4CE3-BA49-09BF78C70A09}", SceneAPI::DataTypes::IBlendShapeData) - SCENE_DATA_API static void Reflect(ReflectContext* context); + static void Reflect(ReflectContext* context); // Maximum number of color sets matches limitation set in assImp (AI_MAX_NUMBER_OF_COLOR_SETS) static constexpr AZ::u8 MaxNumColorSets = 8; diff --git a/Gems/AWSClientAuth/cdk/README.md b/Gems/AWSClientAuth/cdk/README.md index d604057a65..4fe668cb9d 100644 --- a/Gems/AWSClientAuth/cdk/README.md +++ b/Gems/AWSClientAuth/cdk/README.md @@ -26,9 +26,9 @@ Once the python and pip are set up, you can install the required dependencies. Set variables ``` -set O3D_AWS_DEPLOY_REGION="us-west-2" -set O3D_AWS_DEPLOY_ACCOUNT="" -set O3D_AWS_PROJECT_NAME="AWSIProject" +set O3DE_AWS_DEPLOY_REGION="us-west-2" +set O3DE_AWS_DEPLOY_ACCOUNT="" +set O3DE_AWS_PROJECT_NAME="AWSIProject" If you want to add 3rd party providers fill values in utils/constant.py ``` diff --git a/Gems/AWSClientAuth/cdk/app.py b/Gems/AWSClientAuth/cdk/app.py index d6bba06f39..3b57eea07f 100755 --- a/Gems/AWSClientAuth/cdk/app.py +++ b/Gems/AWSClientAuth/cdk/app.py @@ -16,11 +16,11 @@ from aws_client_auth.client_auth_stack import AWSClientAuthStack import os """Configuration""" -REGION = os.environ.get('O3D_AWS_DEPLOY_REGION', os.environ['CDK_DEFAULT_REGION']) -ACCOUNT = os.environ.get('O3D_AWS_DEPLOY_ACCOUNT', os.environ['CDK_DEFAULT_ACCOUNT']) +REGION = os.environ.get('O3DE_AWS_DEPLOY_REGION', os.environ['CDK_DEFAULT_REGION']) +ACCOUNT = os.environ.get('O3DE_AWS_DEPLOY_ACCOUNT', os.environ['CDK_DEFAULT_ACCOUNT']) # Set the common prefix to group stacks in a project together. -PROJECT_NAME = os.environ.get('O3D_AWS_PROJECT_NAME', f'O3D-AWS-PROJECT').upper() +PROJECT_NAME = os.environ.get('O3DE_AWS_PROJECT_NAME', f'O3DE-AWS-PROJECT').upper() env = core.Environment(account=ACCOUNT, region=REGION) app = core.App() diff --git a/Gems/AWSClientAuth/cdk/cognito/cognito_identity_pool.py b/Gems/AWSClientAuth/cdk/cognito/cognito_identity_pool.py index b09269bf3e..d030f8573c 100755 --- a/Gems/AWSClientAuth/cdk/cognito/cognito_identity_pool.py +++ b/Gems/AWSClientAuth/cdk/cognito/cognito_identity_pool.py @@ -58,7 +58,7 @@ class CognitoIdentityPool: self._identity_pool.add_depends_on(cognito_user_pool.get_user_pool()) self._identity_pool.add_depends_on(cognito_user_pool.get_user_pool_client()) - # Create roles to associate with Cognito Idenity pool + # Create roles to associate with Cognito Identity pool self._auth_role = CognitoIdentityPoolRole(scope, feature_name, project_name, env, self._identity_pool, authenticated=True) self._unauth_role = CognitoIdentityPoolRole(scope, feature_name, project_name, env, diff --git a/Gems/AWSClientAuth/cdk/utils/name_utils.py b/Gems/AWSClientAuth/cdk/utils/name_utils.py index 8c8f6a7e82..bab4cd0389 100755 --- a/Gems/AWSClientAuth/cdk/utils/name_utils.py +++ b/Gems/AWSClientAuth/cdk/utils/name_utils.py @@ -8,7 +8,7 @@ remove or modify any license notices. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ - +import re from aws_cdk import core @@ -21,7 +21,9 @@ def format_aws_resource_id(feature_name: str, project_name: str, env: core.Envir def format_aws_resource_sid(feature_name: str, project_name: str, resource_type: str): - return f'{project_name}{feature_name}{resource_type}SId' + sid = f'{project_name}{feature_name}{resource_type}SId' + # Strip out all chars not valid in a sid + return re.sub(r'[^a-zA-Z0-9]', '', sid) def format_aws_resource_authenticated_id(feature_name: str, project_name: str, env: core.Environment, diff --git a/Gems/AWSCore/Code/CMakeLists.txt b/Gems/AWSCore/Code/CMakeLists.txt index 468530be31..a58b02d1d4 100644 --- a/Gems/AWSCore/Code/CMakeLists.txt +++ b/Gems/AWSCore/Code/CMakeLists.txt @@ -86,7 +86,7 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS) ) ly_add_target( - NAME AWSCore.ResourceMappintTool MODULE + NAME AWSCore.ResourceMappingTool MODULE NAMESPACE Gem OUTPUT_SUBDIRECTORY AWSCoreEditorQtBin FILES_CMAKE @@ -94,15 +94,11 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS) INCLUDE_DIRECTORIES PRIVATE Include/Private - PUBLIC - Include/Public BUILD_DEPENDENCIES PRIVATE - 3rdParty::Qt::Core - 3rdParty::Qt::Widgets - AZ::AzToolsFramework + Gem::AWSCore.Editor.Static ) - ly_add_dependencies(AWSCore.Editor AWSCore.ResourceMappintTool) + ly_add_dependencies(AWSCore.Editor AWSCore.ResourceMappingTool) endif() ################################################################################ diff --git a/Gems/AWSCore/Code/Include/Private/Configuration/AWSCoreConfiguration.h b/Gems/AWSCore/Code/Include/Private/Configuration/AWSCoreConfiguration.h index f3d474f053..bd30af3ce7 100644 --- a/Gems/AWSCore/Code/Include/Private/Configuration/AWSCoreConfiguration.h +++ b/Gems/AWSCore/Code/Include/Private/Configuration/AWSCoreConfiguration.h @@ -25,13 +25,24 @@ namespace AWSCore : AWSCoreInternalRequestBus::Handler { public: - static constexpr const char AWSCORE_CONFIGURATION_FILENAME[] = "awscoreconfiguration.setreg"; + static constexpr const char AWSCoreConfigurationName[] = "AWSCoreConfiguration"; + static constexpr const char AWSCoreConfigurationFileName[] = "awscoreconfiguration.setreg"; - static constexpr const char AWSCORE_RESOURCE_MAPPING_CONFIG_FOLDERNAME[] = "Config"; - static constexpr const char AWSCORE_RESOURCE_MAPPING_CONFIG_FILENAME_KEY[] = "/AWSCore/ResourceMappingConfigFileName"; + static constexpr const char AWSCoreResourceMappingConfigFolderName[] = "Config"; + static constexpr const char AWSCoreResourceMappingConfigFileNameKey[] = "/AWSCore/ResourceMappingConfigFileName"; + + static constexpr const char AWSCoreDefaultProfileName[] = "default"; + static constexpr const char AWSCoreProfileNameKey[] = "/AWSCore/ProfileName"; + + static constexpr const char ProjectSourceFolderNotFoundErrorMessage[] = + "Failed to get project source folder path."; + static constexpr const char ProfileNameNotFoundErrorMessage[] = + "Failed to get profile name, return default value instead."; + static constexpr const char ResourceMappingFileNameNotFoundErrorMessage[] = + "Failed to get resource mapping config file name, return empty value instead."; + static constexpr const char SettingsRegistryLoadFailureErrorMessage[] = + "Failed to load AWSCore settings registry file."; - static constexpr const char AWSCORE_DEFAULT_PROFILE_NAME[] = "default"; - static constexpr const char AWSCORE_PROFILENAME_KEY[] = "/AWSCore/ProfileName"; AWSCoreConfiguration(); ~AWSCoreConfiguration() = default; @@ -55,6 +66,9 @@ namespace AWSCore // Parse values from project .setreg file void ParseSettingsRegistryValues(); + // Reset settings registry data + void ResetSettingsRegistryData(); + AZStd::string m_sourceProjectFolder; AZ::SettingsRegistryImpl m_settingsRegistry; AZStd::string m_profileName; diff --git a/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingConstants.h b/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingConstants.h index 2ca203bb96..55360f1c76 100644 --- a/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingConstants.h +++ b/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingConstants.h @@ -14,20 +14,20 @@ namespace AWSCore { - static constexpr const char AWS_CHINA_REGION_PREFIX[] = "cn-"; + static constexpr const char AWSChinaRegionPrefix[] = "cn-"; - static constexpr const char AWS_FEATURE_GEM_RESTAPI_ID_KEYNAME_SUFFIX[] = ".RESTApiId"; - static constexpr const char AWS_FEATURE_GEM_RESTAPI_STAGE_KEYNAME_SUFFIX[] = ".RESTApiStage"; + static constexpr const char AWSFeatureGemRESTApiIdKeyNameSuffix[] = ".RESTApiId"; + static constexpr const char AWSFeatureGemRESTApiStageKeyNameSuffix[] = ".RESTApiStage"; - static constexpr const char RESOURCE_MAPPING_ACCOUNTID_KEYNAME[] = "AccountId"; - static constexpr const char RESOURCE_MAPPING_RESOURCES_KEYNAME[] = "AWSResourceMappings"; - static constexpr const char RESOURCE_MAPPING_NAMEID_KEYNAME[] = "Name/ID"; - static constexpr const char RESOURCE_MAPPING_REGION_KEYNAME[] = "Region"; - static constexpr const char RESOURCE_MAPPING_TYPE_KEYNAME[] = "Type"; - static constexpr const char RESOURCE_MAPPING_VERSION_KEYNAME[] = "Version"; + static constexpr const char ResourceMappingAccountIdKeyName[] = "AccountId"; + static constexpr const char ResourceMappingResourcesKeyName[] = "AWSResourceMappings"; + static constexpr const char ResourceMappingNameIdKeyName[] = "Name/ID"; + static constexpr const char ResourceMappingRegionKeyName[] = "Region"; + static constexpr const char ResourceMappingTypeKeyName[] = "Type"; + static constexpr const char ResourceMappingVersionKeyName[] = "Version"; // TODO: move this into an independent file under AWSCore gem, if resource mapping tool can reuse it - static constexpr const char RESOURCE_MAPPING_JSON_SCHEMA[] = + static constexpr const char ResourceMappingJsonSchema[] = R"({ "$schema": "http://json-schema.org/draft-04/schema", "type": "object", diff --git a/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingManager.h b/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingManager.h index 9200a9c4ff..6d22c55d2c 100644 --- a/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingManager.h +++ b/Gems/AWSCore/Code/Include/Private/ResourceMapping/AWSResourceMappingManager.h @@ -45,6 +45,35 @@ namespace AWSCore }; public: + static constexpr const char AWSResourceMappingManagerName[] = "AWSResourceMappingManager"; + static constexpr const char ManagerUnexpectedStatusErrorMessage[] = + "AWSResourceMappingManager is in unexpected status."; + static constexpr const char ResourceMappingFileInvalidPathErrorMessage[] = + "Failed to get resource mapping config file path."; + static constexpr const char ResourceMappingKeyNotFoundErrorMessage[] = + "Failed to find resource mapping key: %s"; + static constexpr const char ResourceMappingFileNotLoadedErrorMessage[] = + "Resource mapping config file is not loaded, please confirm %s is setup correctly."; + static constexpr const char ResourceMappingFileLoadFailureErrorMessage[] = + "Resource mapping config file failed to load, please confirm file is present and in correct format."; + static constexpr const char ResourceMappingRESTApiIdAndStageInconsistentErrorMessage[] = + "Resource mapping %s and %s have inconsistent region value, return empty service url."; + static constexpr const char ResourceMappingRESTApiInvalidServiceUrlErrorMessage[] = + "Unable to format REST Api url with RESTApiId=%s, RESTApiRegion=%s, RESTApiStage=%s, return empty service url."; + static constexpr const char ResourceMappingFileInvalidJsonFormatErrorMessage[] = + "Failed to read resource mapping config file: %s"; + static constexpr const char ResourceMappingFileInvalidSchemaErrorMessage[] = + "Failed to load resource mapping config file json schema."; + static constexpr const char ResourceMappingFileInvalidContentErrorMessage[] = + "Failed to parse resource mapping config file: %s"; + + enum class Status : AZ::u8 + { + NotLoaded = 0, + Ready = 1, + Error = 2 + }; + AWSResourceMappingManager(); ~AWSResourceMappingManager() = default; @@ -63,7 +92,12 @@ namespace AWSCore const AZStd::string& restApiIdKeyName, const AZStd::string& restApiStageKeyName) const override; void ReloadConfigFile(bool reloadConfigFileName = false) override; + Status GetStatus() const; + private: + // Get resource attribute error message based on the status + AZStd::string GetResourceAttributeErrorMessageByStatus(const AZStd::string& resourceKeyName) const; + // Get resource attribute from resource mappings AZStd::string GetResourceAttribute( AZStd::function getAttributeFunction, @@ -83,6 +117,7 @@ namespace AWSCore // Validate JSON document against schema bool ValidateJsonDocumentAgainstSchema(const rapidjson::Document& jsonDocument); + Status m_status; // Resource mapping related data AZStd::string m_defaultAccountId; AZStd::string m_defaultRegion; diff --git a/Gems/AWSCore/Code/Include/Public/ScriptCanvas/AWSScriptBehaviorS3.h b/Gems/AWSCore/Code/Include/Public/ScriptCanvas/AWSScriptBehaviorS3.h index 5d7baf19a1..9d779e3629 100644 --- a/Gems/AWSCore/Code/Include/Public/ScriptCanvas/AWSScriptBehaviorS3.h +++ b/Gems/AWSCore/Code/Include/Public/ScriptCanvas/AWSScriptBehaviorS3.h @@ -75,6 +75,16 @@ namespace AWSCore class AWSScriptBehaviorS3 : public AWSScriptBehaviorBase { + static constexpr const char AWSScriptBehaviorS3Name[] = "AWSScriptBehaviorS3"; + static constexpr const char OutputFileIsEmptyErrorMessage[] = "Request validation failed, output file is empty."; + static constexpr const char OutputFileMissFullPathErrorMessage[] = "Request validation failed, output file miss full path."; + static constexpr const char OutputFileIsDirectoryErrorMessage[] = "Request validation failed, output file is a directory."; + static constexpr const char OutputFileDirectoryNotExistErrorMessage[] = "Request validation failed, output file directory doesn't exist."; + static constexpr const char OutputFileIsReadOnlyErrorMessage[] = "Request validation failed, output file is read-only."; + static constexpr const char BucketNameIsEmptyErrorMessage[] = "Request validation failed, bucket name is empty"; + static constexpr const char ObjectKeyNameIsEmptyErrorMessage[] = "Request validation failed, object key name is empty."; + static constexpr const char RegionNameIsEmptyErrorMessage[] = "Request validation failed, region name is empty."; + public: AWS_SCRIPT_BEHAVIOR_DEFINITION(AWSScriptBehaviorS3, "{7F4E956C-7463-4236-B320-C992D36A9C6E}"); @@ -87,7 +97,7 @@ namespace AWSCore private: using S3NotificationFunctionType = void(AWSScriptBehaviorS3Notifications::*)(const AZStd::string&); static bool ValidateGetObjectRequest(S3NotificationFunctionType notificationFunc, - const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, const AZStd::string& outFile); + const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, AZStd::string& outFile); static bool ValidateHeadObjectRequest(S3NotificationFunctionType notificationFunc, const AZStd::string& bucket, const AZStd::string& key, const AZStd::string& region); diff --git a/Gems/AWSCore/Code/Source/AWSCoreResourceMappingToolModule.cpp b/Gems/AWSCore/Code/Source/AWSCoreResourceMappingToolModule.cpp new file mode 100644 index 0000000000..794ee6c880 --- /dev/null +++ b/Gems/AWSCore/Code/Source/AWSCoreResourceMappingToolModule.cpp @@ -0,0 +1,44 @@ +/* +* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include + +namespace AWSCore +{ + class AWSCoreResourceMappingToolModule + : public AZ::Module + { + public: + AZ_RTTI(AWSCoreResourceMappingToolModule, "{9D16F400-009C-47FF-A186-E48BEB73D94D}", AZ::Module); + AZ_CLASS_ALLOCATOR(AWSCoreResourceMappingToolModule, AZ::SystemAllocator, 0); + + AWSCoreResourceMappingToolModule() + { + m_descriptors.insert(m_descriptors.end(), + { + AWSCoreEditorSystemComponent::CreateDescriptor(), + }); + } + + ~AWSCoreResourceMappingToolModule() override = default; + + AZ::ComponentTypeList GetRequiredSystemComponents() const override + { + return AZ::ComponentTypeList{azrtti_typeid()}; + } + }; +} + +// DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM +// The first parameter should be GemName_GemIdLower +// The second should be the fully qualified name of the class above +AZ_DECLARE_MODULE_CLASS(Gem_AWSCore_ResourceMappingTool, AWSCore::AWSCoreResourceMappingToolModule) diff --git a/Gems/AWSCore/Code/Source/Configuration/AWSCoreConfiguration.cpp b/Gems/AWSCore/Code/Source/Configuration/AWSCoreConfiguration.cpp index 0445ea830e..3c0f48c058 100644 --- a/Gems/AWSCore/Code/Source/Configuration/AWSCoreConfiguration.cpp +++ b/Gems/AWSCore/Code/Source/Configuration/AWSCoreConfiguration.cpp @@ -20,7 +20,7 @@ namespace AWSCore { AWSCoreConfiguration::AWSCoreConfiguration() : m_sourceProjectFolder("") - , m_profileName(AWSCORE_DEFAULT_PROFILE_NAME) + , m_profileName(AWSCoreDefaultProfileName) , m_resourceMappingConfigFileName("") { } @@ -44,16 +44,16 @@ namespace AWSCore { if (m_sourceProjectFolder.empty()) { - AZ_Warning("AWSCoreConfiguration", false, "Failed to get source project folder path."); + AZ_Warning(AWSCoreConfigurationName, false, ProjectSourceFolderNotFoundErrorMessage); return ""; } if (m_resourceMappingConfigFileName.empty()) { - AZ_Warning("AWSCoreConfiguration", false, "Failed to get resource mapping config file name."); + AZ_Warning(AWSCoreConfigurationName, false, ResourceMappingFileNameNotFoundErrorMessage); return ""; } AZStd::string configFilePath = AZStd::string::format("%s/%s/%s", - m_sourceProjectFolder.c_str(), AWSCORE_RESOURCE_MAPPING_CONFIG_FOLDERNAME, m_resourceMappingConfigFileName.c_str()); + m_sourceProjectFolder.c_str(), AWSCoreResourceMappingConfigFolderName, m_resourceMappingConfigFileName.c_str()); AzFramework::StringFunc::Path::Normalize(configFilePath); return configFilePath; } @@ -68,17 +68,17 @@ namespace AWSCore { if (m_sourceProjectFolder.empty()) { - AZ_Warning("AWSCoreConfiguration", false, "Failed to get source project folder path."); + AZ_Warning(AWSCoreConfigurationName, false, ProjectSourceFolderNotFoundErrorMessage); return; } AZStd::string settingsRegistryPath = AZStd::string::format("%s/%s/%s", - m_sourceProjectFolder.c_str(), AZ::SettingsRegistryInterface::RegistryFolder, AWSCoreConfiguration::AWSCORE_CONFIGURATION_FILENAME); + m_sourceProjectFolder.c_str(), AZ::SettingsRegistryInterface::RegistryFolder, AWSCoreConfiguration::AWSCoreConfigurationFileName); AzFramework::StringFunc::Path::Normalize(settingsRegistryPath); if (!m_settingsRegistry.MergeSettingsFile(settingsRegistryPath, AZ::SettingsRegistryInterface::Format::JsonMergePatch, "")) { - AZ_Warning("AWSCoreConfiguration", false, "Failed to merge AWS core settings registry."); + AZ_Warning(AWSCoreConfigurationName, false, SettingsRegistryLoadFailureErrorMessage); return; } @@ -90,7 +90,7 @@ namespace AWSCore auto sourceProjectFolder = AZ::IO::FileIOBase::GetInstance()->GetAlias("@devassets@"); if (!sourceProjectFolder) { - AZ_Error("AWSCoreConfiguration", false, "Failed to initialize source project folder path."); + AZ_Error(AWSCoreConfigurationName, false, ProjectSourceFolderNotFoundErrorMessage); } else { @@ -102,24 +102,38 @@ namespace AWSCore { m_resourceMappingConfigFileName.clear(); auto resourceMappingConfigFileNamePath = AZStd::string::format("%s%s", - AZ::SettingsRegistryMergeUtils::OrganizationRootKey, AWSCORE_RESOURCE_MAPPING_CONFIG_FILENAME_KEY); + AZ::SettingsRegistryMergeUtils::OrganizationRootKey, AWSCoreResourceMappingConfigFileNameKey); if (!m_settingsRegistry.Get(m_resourceMappingConfigFileName, resourceMappingConfigFileNamePath)) { - AZ_Warning("AWSCoreConfiguration", false, "Failed to get resource mapping config file name from settings registry."); + AZ_Warning(AWSCoreConfigurationName, false, ResourceMappingFileNameNotFoundErrorMessage); } m_profileName.clear(); auto profileNamePath = AZStd::string::format( - "%s%s", AZ::SettingsRegistryMergeUtils::OrganizationRootKey, AWSCORE_PROFILENAME_KEY); + "%s%s", AZ::SettingsRegistryMergeUtils::OrganizationRootKey, AWSCoreProfileNameKey); if (!m_settingsRegistry.Get(m_profileName, profileNamePath)) { - AZ_Warning("AWSCoreConfiguration", false, "Failed to get profile name from settings registry, using default value instead."); - m_profileName = AWSCORE_DEFAULT_PROFILE_NAME; + AZ_Warning(AWSCoreConfigurationName, false, ProfileNameNotFoundErrorMessage); + m_profileName = AWSCoreDefaultProfileName; } } + void AWSCoreConfiguration::ResetSettingsRegistryData() + { + auto profileNamePath = AZStd::string::format("%s%s", + AZ::SettingsRegistryMergeUtils::OrganizationRootKey, AWSCoreProfileNameKey); + m_settingsRegistry.Remove(profileNamePath); + m_profileName.clear(); + + auto resourceMappingConfigFileNamePath = AZStd::string::format("%s%s", + AZ::SettingsRegistryMergeUtils::OrganizationRootKey, AWSCoreResourceMappingConfigFileNameKey); + m_settingsRegistry.Remove(resourceMappingConfigFileNamePath); + m_resourceMappingConfigFileName.clear(); + } + void AWSCoreConfiguration::ReloadConfiguration() { + ResetSettingsRegistryData(); InitSettingsRegistry(); } } // namespace AWSCore diff --git a/Gems/AWSCore/Code/Source/Credential/AWSDefaultCredentialHandler.cpp b/Gems/AWSCore/Code/Source/Credential/AWSDefaultCredentialHandler.cpp index ba7a8c72dd..bb195e487a 100644 --- a/Gems/AWSCore/Code/Source/Credential/AWSDefaultCredentialHandler.cpp +++ b/Gems/AWSCore/Code/Source/Credential/AWSDefaultCredentialHandler.cpp @@ -84,7 +84,7 @@ namespace AWSCore { AZ_Warning("AWSDefaultCredentialHandler", false, "Failed to get profile name, use default profile name instead"); SetProfileCredentialsProvider(Aws::MakeShared( - AWSDEFAULTCREDENTIALHANDLER_ALLOC_TAG, AWSCoreConfiguration::AWSCORE_DEFAULT_PROFILE_NAME)); + AWSDEFAULTCREDENTIALHANDLER_ALLOC_TAG, AWSCoreConfiguration::AWSCoreDefaultProfileName)); } else { diff --git a/Gems/AWSCore/Code/Source/Framework/MultipartFormData.cpp b/Gems/AWSCore/Code/Source/Framework/MultipartFormData.cpp index fdd5fa3c92..bec352bf35 100644 --- a/Gems/AWSCore/Code/Source/Framework/MultipartFormData.cpp +++ b/Gems/AWSCore/Code/Source/Framework/MultipartFormData.cpp @@ -117,7 +117,7 @@ namespace AWSCore result.m_content.append(AZStd::string::format(Detail::FOOTER_FMT, m_boundary.c_str())); // Populate the metadata - result.m_contentLength = AZStd::string::format("%lu", result.m_content.length()); + result.m_contentLength = AZStd::string::format("%zu", result.m_content.length()); result.m_contentType = AZStd::string::format("multipart/form-data; boundary=%s", m_boundary.c_str()); return result; diff --git a/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingManager.cpp b/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingManager.cpp index c87a7f99ba..efdba0e9e0 100644 --- a/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingManager.cpp +++ b/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingManager.cpp @@ -12,12 +12,14 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -25,7 +27,8 @@ namespace AWSCore { AWSResourceMappingManager::AWSResourceMappingManager() - : m_defaultAccountId("") + : m_status(Status::NotLoaded) + , m_defaultAccountId("") , m_defaultRegion("") , m_resourceMappings() { @@ -43,11 +46,27 @@ namespace AWSCore ResetResourceMappingsData(); } + AZStd::string AWSResourceMappingManager::GetResourceAttributeErrorMessageByStatus(const AZStd::string& resourceKeyName) const + { + switch (m_status) + { + case Status::NotLoaded: + return AZStd::string::format(ResourceMappingFileNotLoadedErrorMessage, AWSCoreConfiguration::AWSCoreConfigurationFileName); + case Status::Ready: + return AZStd::string::format(ResourceMappingKeyNotFoundErrorMessage, resourceKeyName.c_str()); + case Status::Error: + return ResourceMappingFileLoadFailureErrorMessage; + default: + return ManagerUnexpectedStatusErrorMessage; + } + } + AZStd::string AWSResourceMappingManager::GetDefaultAccountId() const { if (m_defaultAccountId.empty()) { - AZ_Warning("AWSResourceMappingManager", false, "Account Id should not be empty, please make sure config file is valid."); + AZ_Warning(AWSResourceMappingManagerName, false, + GetResourceAttributeErrorMessageByStatus(ResourceMappingAccountIdKeyName).c_str()); } return m_defaultAccountId; } @@ -56,7 +75,8 @@ namespace AWSCore { if (m_defaultRegion.empty()) { - AZ_Warning("AWSResourceMappingManager", false, "Region should not be empty, please make sure config file is valid."); + AZ_Warning(AWSResourceMappingManagerName, false, + GetResourceAttributeErrorMessageByStatus(ResourceMappingRegionKeyName).c_str()); } return m_defaultRegion; } @@ -100,8 +120,8 @@ namespace AWSCore AZStd::string AWSResourceMappingManager::GetServiceUrlByServiceName(const AZStd::string& serviceName) const { return GetServiceUrlByRESTApiIdAndStage( - AZStd::string::format("%s%s", serviceName.c_str(), AWS_FEATURE_GEM_RESTAPI_ID_KEYNAME_SUFFIX), - AZStd::string::format("%s%s", serviceName.c_str(), AWS_FEATURE_GEM_RESTAPI_STAGE_KEYNAME_SUFFIX)); + AZStd::string::format("%s%s", serviceName.c_str(), AWSFeatureGemRESTApiIdKeyNameSuffix), + AZStd::string::format("%s%s", serviceName.c_str(), AWSFeatureGemRESTApiStageKeyNameSuffix)); } AZStd::string AWSResourceMappingManager::GetServiceUrlByRESTApiIdAndStage( @@ -113,16 +133,13 @@ namespace AWSCore AZStd::string serviceRegion = GetResourceRegion(restApiIdKeyName); if (serviceRegion != GetResourceRegion(restApiStageKeyName)) { - AZ_Warning( - "AWSResourceMappingManager", false, "%s and %s have inconsistent region value, return empty service url.", + AZ_Warning(AWSResourceMappingManagerName, false, ResourceMappingRESTApiIdAndStageInconsistentErrorMessage, restApiIdKeyName.c_str(), restApiStageKeyName.c_str()); return ""; } AZStd::string serviceRESTApiUrl = AWSResourceMappingUtils::FormatRESTApiUrl(serviceRESTApiId, serviceRegion, serviceRESTApiStage); - AZ_Warning( - "AWSResourceMappingManager", !serviceRESTApiUrl.empty(), - "Unable to format REST Api url with RESTApiId=%s, RESTApiRegion=%s, RESTApiStage=%s, return empty service url.", + AZ_Warning(AWSResourceMappingManagerName, !serviceRESTApiUrl.empty(), ResourceMappingRESTApiInvalidServiceUrlErrorMessage, serviceRESTApiId.c_str(), serviceRegion.c_str(), serviceRESTApiStage.c_str()); return serviceRESTApiUrl; } @@ -136,16 +153,21 @@ namespace AWSCore return getAttributeFunction(iter->second); } - AZ_Warning("AWSResourceMappingManager", false, "Failed to find resource mapping key: %s.", resourceKeyName.c_str()); + AZ_Warning(AWSResourceMappingManagerName, false, GetResourceAttributeErrorMessageByStatus(resourceKeyName).c_str()); return ""; } + AWSResourceMappingManager::Status AWSResourceMappingManager::GetStatus() const + { + return m_status; + } + void AWSResourceMappingManager::ParseJsonDocument(const rapidjson::Document& jsonDocument) { - m_defaultAccountId = jsonDocument.FindMember(RESOURCE_MAPPING_ACCOUNTID_KEYNAME)->value.GetString(); - m_defaultRegion = jsonDocument.FindMember(RESOURCE_MAPPING_REGION_KEYNAME)->value.GetString(); + m_defaultAccountId = jsonDocument.FindMember(ResourceMappingAccountIdKeyName)->value.GetString(); + m_defaultRegion = jsonDocument.FindMember(ResourceMappingRegionKeyName)->value.GetString(); - auto resourceMappings = jsonDocument.FindMember(RESOURCE_MAPPING_RESOURCES_KEYNAME)->value.GetObject(); + auto resourceMappings = jsonDocument.FindMember(ResourceMappingResourcesKeyName)->value.GetObject(); for (auto mappingIter = resourceMappings.MemberBegin(); mappingIter != resourceMappings.MemberEnd(); mappingIter++) { auto mappingValue = mappingIter->value.GetObject(); @@ -162,16 +184,16 @@ namespace AWSCore const JsonObject& jsonObject) { AWSResourceMappingAttributes attributes; - if (jsonObject.HasMember(RESOURCE_MAPPING_ACCOUNTID_KEYNAME)) + if (jsonObject.HasMember(ResourceMappingAccountIdKeyName)) { - attributes.resourceAccountId = jsonObject.FindMember(RESOURCE_MAPPING_ACCOUNTID_KEYNAME)->value.GetString(); + attributes.resourceAccountId = jsonObject.FindMember(ResourceMappingAccountIdKeyName)->value.GetString(); } - attributes.resourceNameId = jsonObject.FindMember(RESOURCE_MAPPING_NAMEID_KEYNAME)->value.GetString(); - if (jsonObject.HasMember(RESOURCE_MAPPING_REGION_KEYNAME)) + attributes.resourceNameId = jsonObject.FindMember(ResourceMappingNameIdKeyName)->value.GetString(); + if (jsonObject.HasMember(ResourceMappingRegionKeyName)) { - attributes.resourceRegion = jsonObject.FindMember(RESOURCE_MAPPING_REGION_KEYNAME)->value.GetString(); + attributes.resourceRegion = jsonObject.FindMember(ResourceMappingRegionKeyName)->value.GetString(); } - attributes.resourceType = jsonObject.FindMember(RESOURCE_MAPPING_TYPE_KEYNAME)->value.GetString(); + attributes.resourceType = jsonObject.FindMember(ResourceMappingTypeKeyName)->value.GetString(); return attributes; } @@ -188,7 +210,7 @@ namespace AWSCore AWSCoreInternalRequestBus::BroadcastResult(configJsonPath, &AWSCoreInternalRequests::GetResourceMappingConfigFilePath); if (configJsonPath.empty()) { - AZ_Warning("AWSResourceMappingManager", false, "Failed to get resource mapping config file path."); + AZ_Warning(AWSResourceMappingManagerName, false, ResourceMappingFileInvalidPathErrorMessage); return; } @@ -201,20 +223,26 @@ namespace AWSCore if (!ValidateJsonDocumentAgainstSchema(jsonDocument)) { // Failed to satisfy the validation against json schema + m_status = Status::Error; return; } ParseJsonDocument(jsonDocument); } else { - AZ_Warning( - "AWSResourceMappingManager", false, "Failed to get read resource mapping config file: %s\n Error: %s", - configJsonPath.c_str(), readJsonOutcome.GetError().c_str()); + m_status = Status::Error; + AZ_Warning(AWSResourceMappingManagerName, false, + ResourceMappingFileInvalidJsonFormatErrorMessage, readJsonOutcome.GetError().c_str()); + return; } + + // Resource mapping config file gets loaded successfully + m_status = Status::Ready; } void AWSResourceMappingManager::ResetResourceMappingsData() { + m_status = Status::NotLoaded; m_defaultAccountId = ""; m_defaultRegion = ""; m_resourceMappings.clear(); @@ -223,9 +251,9 @@ namespace AWSCore bool AWSResourceMappingManager::ValidateJsonDocumentAgainstSchema(const rapidjson::Document& jsonDocument) { rapidjson::Document jsonSchemaDocument; - if (jsonSchemaDocument.Parse(RESOURCE_MAPPING_JSON_SCHEMA).HasParseError()) + if (jsonSchemaDocument.Parse(ResourceMappingJsonSchema).HasParseError()) { - AZ_Error("AWSResourceMappingManager", false, "Invalid resource mapping json schema."); + AZ_Error(AWSResourceMappingManagerName, false, ResourceMappingFileInvalidSchemaErrorMessage); return false; } @@ -235,12 +263,10 @@ namespace AWSCore if (!jsonDocument.Accept(validator)) { rapidjson::StringBuffer error; - validator.GetInvalidSchemaPointer().StringifyUriFragment(error); - AZ_Warning("AWSResourceMappingManager", false, "Failed to load config file, invalid schema: %s.", error.GetString()); - AZ_Warning("AWSResourceMappingManager", false, "Failed to load config file, invalid keyword: %s.", validator.GetInvalidSchemaKeyword()); - error.Clear(); - validator.GetInvalidDocumentPointer().StringifyUriFragment(error); - AZ_Warning("AWSResourceMappingManager", false, "Failed to load config file, invalid document: %s.", error.GetString()); + rapidjson::PrettyWriter writer(error); + validator.GetError().Accept(writer); + AZ_Warning(AWSResourceMappingManagerName, false, ResourceMappingFileInvalidContentErrorMessage, error.GetString()); + return false; } return true; diff --git a/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingUtils.cpp b/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingUtils.cpp index 74be3bf914..7d17a86909 100644 --- a/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingUtils.cpp +++ b/Gems/AWSCore/Code/Source/ResourceMapping/AWSResourceMappingUtils.cpp @@ -18,8 +18,8 @@ namespace AWSCore namespace AWSResourceMappingUtils { // https://docs.aws.amazon.com/general/latest/gr/apigateway.html - static constexpr char RESTAPI_URL_FORMAT[] = "https://%s.execute-api.%s.amazonaws.com/%s"; - static constexpr char RESTAPI_CHINA_URL_FORMAT[] = "https://%s.execute-api.%s.amazonaws.com.cn/%s"; + static constexpr char RESTApiUrlFormat[] = "https://%s.execute-api.%s.amazonaws.com/%s"; + static constexpr char RESTApiChinaUrlFormat[] = "https://%s.execute-api.%s.amazonaws.com.cn/%s"; AZStd::string FormatRESTApiUrl( const AZStd::string& restApiId, const AZStd::string& restApiRegion, const AZStd::string& restApiStage) @@ -27,14 +27,14 @@ namespace AWSCore // https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html if (!restApiId.empty() && !restApiRegion.empty() && !restApiStage.empty()) { - if (restApiRegion.rfind(AWS_CHINA_REGION_PREFIX, 0) == 0) + if (restApiRegion.rfind(AWSChinaRegionPrefix, 0) == 0) { - return AZStd::string::format(RESTAPI_CHINA_URL_FORMAT, + return AZStd::string::format(RESTApiChinaUrlFormat, restApiId.c_str(), restApiRegion.c_str(), restApiStage.c_str()); } else { - return AZStd::string::format(RESTAPI_URL_FORMAT, + return AZStd::string::format(RESTApiUrlFormat, restApiId.c_str(), restApiRegion.c_str(), restApiStage.c_str()); } } diff --git a/Gems/AWSCore/Code/Source/ScriptCanvas/AWSScriptBehaviorS3.cpp b/Gems/AWSCore/Code/Source/ScriptCanvas/AWSScriptBehaviorS3.cpp index 742a6826af..1f529572f1 100644 --- a/Gems/AWSCore/Code/Source/ScriptCanvas/AWSScriptBehaviorS3.cpp +++ b/Gems/AWSCore/Code/Source/ScriptCanvas/AWSScriptBehaviorS3.cpp @@ -43,7 +43,7 @@ namespace AWSCore void AWSScriptBehaviorS3::ReflectBehaviors(AZ::BehaviorContext* behaviorContext) { - behaviorContext->Class("AWSScriptBehaviorS3") + behaviorContext->Class(AWSScriptBehaviorS3Name) ->Attribute(AZ::Script::Attributes::Category, "AWSCore") ->Method("GetObject", &AWSScriptBehaviorS3::GetObject, {{{"Bucket Resource KeyName", "The resource key name of the bucket in resource mapping config file."}, @@ -86,7 +86,9 @@ namespace AWSCore void AWSScriptBehaviorS3::GetObjectRaw( const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, const AZStd::string& outFile) { - if (!ValidateGetObjectRequest(&AWSScriptBehaviorS3NotificationBus::Events::OnGetObjectError, bucket, objectKey, region, outFile)) + AZStd::string normalizedOutFile = outFile; + if (!ValidateGetObjectRequest( + &AWSScriptBehaviorS3NotificationBus::Events::OnGetObjectError, bucket, objectKey, region, normalizedOutFile)) { return; } @@ -112,10 +114,10 @@ namespace AWSCore job->request.SetBucket(Aws::String(bucket.c_str())); job->request.SetKey(Aws::String(objectKey.c_str())); - Aws::String outFileName(outFile.c_str()); + Aws::String outFileName(normalizedOutFile.c_str()); job->request.SetResponseStreamFactory([outFileName]() { return Aws::New( - "AWSScriptBehaviorS3", outFileName.c_str(), + AWSScriptBehaviorS3Name, outFileName.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::binary | std::ios_base::trunc); }); job->Start(); @@ -163,20 +165,44 @@ namespace AWSCore } bool AWSScriptBehaviorS3::ValidateGetObjectRequest(S3NotificationFunctionType notificationFunc, - const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, const AZStd::string& outFile) + const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, AZStd::string& outFile) { if (ValidateHeadObjectRequest(notificationFunc, bucket, objectKey, region)) { - if (!AzFramework::StringFunc::Path::IsValid(outFile.c_str())) + AzFramework::StringFunc::Path::Normalize(outFile); + if (outFile.empty()) { - AZ_Warning("AWSScriptBehaviorS3", false, "Request validation failed, outfile is not valid."); - AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, "Request validation failed, outfile is not valid."); + AZ_Warning(AWSScriptBehaviorS3Name, false, OutputFileIsEmptyErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, OutputFileIsEmptyErrorMessage); return false; } + if (!AzFramework::StringFunc::Path::HasDrive(outFile.c_str())) + { + AZ_Warning(AWSScriptBehaviorS3Name, false, OutputFileMissFullPathErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, OutputFileMissFullPathErrorMessage); + return false; + } + if (AZ::IO::FileIOBase::GetInstance()->IsDirectory(outFile.c_str())) + { + AZ_Warning(AWSScriptBehaviorS3Name, false, OutputFileIsDirectoryErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, OutputFileIsDirectoryErrorMessage); + return false; + } + auto lastSeparator = outFile.find_last_of(AZ_CORRECT_FILESYSTEM_SEPARATOR); + if (lastSeparator != AZStd::string::npos) + { + auto parentPath = outFile.substr(0, lastSeparator); + if (!AZ::IO::FileIOBase::GetInstance()->Exists(parentPath.c_str())) + { + AZ_Warning(AWSScriptBehaviorS3Name, false, OutputFileDirectoryNotExistErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, OutputFileDirectoryNotExistErrorMessage); + return false; + } + } if (AZ::IO::FileIOBase::GetInstance()->IsReadOnly(outFile.c_str())) { - AZ_Warning("AWSScriptBehaviorS3", false, "Request validation failed, outfile is read-only."); - AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, "Request validation failed, outfile is read-only."); + AZ_Warning(AWSScriptBehaviorS3Name, false, OutputFileIsReadOnlyErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, OutputFileIsReadOnlyErrorMessage); return false; } return true; @@ -189,20 +215,20 @@ namespace AWSCore { if (bucket.empty()) { - AZ_Warning("AWSScriptBehaviorS3", false, "Request validation failed, bucket name is required."); - AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, "Request validation failed, bucket name is required."); + AZ_Warning(AWSScriptBehaviorS3Name, false, BucketNameIsEmptyErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, BucketNameIsEmptyErrorMessage); return false; } if (objectKey.empty()) { - AZ_Warning("AWSScriptBehaviorS3", false, "Request validation failed, object key name is required."); - AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, "Request validation failed, object key name is required."); + AZ_Warning(AWSScriptBehaviorS3Name, false, ObjectKeyNameIsEmptyErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, ObjectKeyNameIsEmptyErrorMessage); return false; } if (region.empty()) { - AZ_Warning("AWSScriptBehaviorS3", false, "Request validation failed, region name is required."); - AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, "Request validation failed, region name is required."); + AZ_Warning(AWSScriptBehaviorS3Name, false, RegionNameIsEmptyErrorMessage); + AWSScriptBehaviorS3NotificationBus::Broadcast(notificationFunc, RegionNameIsEmptyErrorMessage); return false; } return true; diff --git a/Gems/AWSCore/Code/Tests/Configuration/AWSCoreConfigurationTest.cpp b/Gems/AWSCore/Code/Tests/Configuration/AWSCoreConfigurationTest.cpp index dab405dee4..b3c2b8d2ca 100644 --- a/Gems/AWSCore/Code/Tests/Configuration/AWSCoreConfigurationTest.cpp +++ b/Gems/AWSCore/Code/Tests/Configuration/AWSCoreConfigurationTest.cpp @@ -46,7 +46,7 @@ public: void CreateTestSetRegFile(const AZStd::string& setregContent) { m_normalizedSetRegFilePath = AZStd::string::format("%s/%s", - m_normalizedSetRegFolderPath.c_str(), AWSCore::AWSCoreConfiguration::AWSCORE_CONFIGURATION_FILENAME); + m_normalizedSetRegFolderPath.c_str(), AWSCore::AWSCoreConfiguration::AWSCoreConfigurationFileName); AzFramework::StringFunc::Path::Normalize(m_normalizedSetRegFilePath); CreateTestFile(m_normalizedSetRegFilePath, setregContent); } @@ -177,7 +177,7 @@ TEST_F(AWSCoreConfigurationTest, ReloadConfiguration_LoadValidSettingsRegistryAf auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath(); auto actualProfileName = m_awsCoreConfiguration->GetProfileName(); EXPECT_TRUE(actualConfigFilePath.empty()); - EXPECT_TRUE(actualProfileName == AWSCoreConfiguration::AWSCORE_DEFAULT_PROFILE_NAME); + EXPECT_TRUE(actualProfileName == AWSCoreConfiguration::AWSCoreDefaultProfileName); CreateTestSetRegFile(TEST_VALID_RESOURCE_MAPPING_SETREG); m_awsCoreConfiguration->ReloadConfiguration(); @@ -185,5 +185,24 @@ TEST_F(AWSCoreConfigurationTest, ReloadConfiguration_LoadValidSettingsRegistryAf actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath(); actualProfileName = m_awsCoreConfiguration->GetProfileName(); EXPECT_FALSE(actualConfigFilePath.empty()); - EXPECT_TRUE(actualProfileName != AWSCoreConfiguration::AWSCORE_DEFAULT_PROFILE_NAME); + EXPECT_TRUE(actualProfileName != AWSCoreConfiguration::AWSCoreDefaultProfileName); +} + +TEST_F(AWSCoreConfigurationTest, ReloadConfiguration_LoadInvalidSettingsRegistryAfterValidOne_ReturnEmptyConfigFilePath) +{ + CreateTestSetRegFile(TEST_VALID_RESOURCE_MAPPING_SETREG); + m_awsCoreConfiguration->InitConfig(); + + auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath(); + auto actualProfileName = m_awsCoreConfiguration->GetProfileName(); + EXPECT_FALSE(actualConfigFilePath.empty()); + EXPECT_TRUE(actualProfileName != AWSCoreConfiguration::AWSCoreDefaultProfileName); + + CreateTestSetRegFile(TEST_INVALID_RESOURCE_MAPPING_SETREG); + m_awsCoreConfiguration->ReloadConfiguration(); + + actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath(); + actualProfileName = m_awsCoreConfiguration->GetProfileName(); + EXPECT_TRUE(actualConfigFilePath.empty()); + EXPECT_TRUE(actualProfileName == AWSCoreConfiguration::AWSCoreDefaultProfileName); } diff --git a/Gems/AWSCore/Code/Tests/ResourceMapping/AWSResourceMappingManagerTest.cpp b/Gems/AWSCore/Code/Tests/ResourceMapping/AWSResourceMappingManagerTest.cpp index 73a28f97cb..3adebc9a24 100644 --- a/Gems/AWSCore/Code/Tests/ResourceMapping/AWSResourceMappingManagerTest.cpp +++ b/Gems/AWSCore/Code/Tests/ResourceMapping/AWSResourceMappingManagerTest.cpp @@ -98,7 +98,7 @@ public: "AWSResourceMappingManager", AZ::Uuid::CreateRandom().ToString(false, false).c_str()); AzFramework::StringFunc::Path::Normalize(m_normalizedSourceProjectFolder); m_normalizedConfigFolderPath = AZStd::string::format("%s/%s/", - m_normalizedSourceProjectFolder.c_str(), AWSCore::AWSCoreConfiguration::AWSCORE_RESOURCE_MAPPING_CONFIG_FOLDERNAME); + m_normalizedSourceProjectFolder.c_str(), AWSCore::AWSCoreConfiguration::AWSCoreResourceMappingConfigFolderName); AzFramework::StringFunc::Path::Normalize(m_normalizedConfigFolderPath); AWSCoreInternalRequestBus::Handler::BusConnect(); } @@ -178,6 +178,7 @@ TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseInvalidConfigFile_Con EXPECT_EQ(m_reloadConfigurationCounter, 1); EXPECT_TRUE(actualAccountId.empty()); EXPECT_TRUE(actualRegion.empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Error); } TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_ConfigDataIsNotEmpty) @@ -192,6 +193,7 @@ TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_Confi EXPECT_EQ(m_reloadConfigurationCounter, 1); EXPECT_FALSE(actualAccountId.empty()); EXPECT_FALSE(actualRegion.empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready); } TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_ConfigDataIsNotEmptyWithMultithreadCalls) @@ -230,11 +232,13 @@ TEST_F(AWSResourceMappingManagerTest, DeactivateManager_AfterActivatingWithValid AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion); EXPECT_FALSE(actualAccountId.empty()); EXPECT_FALSE(actualRegion.empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready); m_resourceMappingManager->DeactivateManager(); EXPECT_TRUE(m_resourceMappingManager->GetDefaultAccountId().empty()); EXPECT_TRUE(m_resourceMappingManager->GetDefaultRegion().empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::NotLoaded); } TEST_F(AWSResourceMappingManagerTest, GetDefaultAccountId_AfterParsingValidConfigFile_GetExpectedDefaultAccountId) @@ -416,6 +420,7 @@ TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ParseValidConfigFileAfter EXPECT_EQ(m_reloadConfigurationCounter, 1); EXPECT_TRUE(actualAccountId.empty()); EXPECT_TRUE(actualRegion.empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Error); CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE); m_resourceMappingManager->ReloadConfigFile(); @@ -425,6 +430,7 @@ TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ParseValidConfigFileAfter EXPECT_EQ(m_reloadConfigurationCounter, 1); EXPECT_FALSE(actualAccountId.empty()); EXPECT_FALSE(actualRegion.empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready); } TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ReloadConfigFileNameAndParseValidConfigFile_ConfigDataGetParsed) @@ -435,6 +441,7 @@ TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ReloadConfigFileNameAndPa EXPECT_EQ(m_reloadConfigurationCounter, 1); EXPECT_FALSE(m_resourceMappingManager->GetDefaultAccountId().empty()); EXPECT_FALSE(m_resourceMappingManager->GetDefaultRegion().empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready); } TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_MissingSetRegFile_ConfigDataIsNotParsed) @@ -444,4 +451,5 @@ TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_MissingSetRegFile_ConfigD EXPECT_EQ(m_reloadConfigurationCounter, 1); EXPECT_TRUE(m_resourceMappingManager->GetDefaultAccountId().empty()); EXPECT_TRUE(m_resourceMappingManager->GetDefaultRegion().empty()); + EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::NotLoaded); } diff --git a/Gems/AWSCore/Code/Tests/ScriptCanvas/AWSScriptBehaviorS3Test.cpp b/Gems/AWSCore/Code/Tests/ScriptCanvas/AWSScriptBehaviorS3Test.cpp index fe258580e0..3489f09ac3 100644 --- a/Gems/AWSCore/Code/Tests/ScriptCanvas/AWSScriptBehaviorS3Test.cpp +++ b/Gems/AWSCore/Code/Tests/ScriptCanvas/AWSScriptBehaviorS3Test.cpp @@ -11,6 +11,7 @@ */ #include +#include #include #include @@ -38,7 +39,37 @@ public: MOCK_METHOD1(OnGetObjectError, void(const AZStd::string&)); }; -using AWSScriptBehaviorS3Test = UnitTest::ScopedAllocatorSetupFixture; +class AWSScriptBehaviorS3Test + : public AWSCoreFixture +{ +public: + void CreateReadOnlyTestFile(const AZStd::string& filePath) + { + AZ::IO::SystemFile file; + if (!file.Open( + filePath.c_str(), + AZ::IO::SystemFile::OpenMode::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY)) + { + AZ_Assert(false, "Failed to open test file at %s", filePath.c_str()); + } + AZStd::string testContent = "It is a test file"; + if (file.Write(testContent.c_str(), testContent.size()) != testContent.size()) + { + AZ_Assert(false, "Failed to write test file with content %s", testContent.c_str()); + } + file.Close(); + AZ_Assert(AZ::IO::SystemFile::SetWritable(filePath.c_str(), false), "Failed to mark test file as read-only"); + } + + void RemoveReadOnlyTestFile(const AZStd::string& filePath) + { + if (!filePath.empty()) + { + AZ_Assert(AZ::IO::SystemFile::SetWritable(filePath.c_str(), true), "Failed to mark test file as writeable"); + AZ_Assert(AZ::IO::SystemFile::Delete(filePath.c_str()), "Failed to delete test config file at %s", filePath.c_str()); + } + } +}; TEST_F(AWSScriptBehaviorS3Test, HeadObjectRaw_CallWithEmptyBucketName_InvokeOnError) { @@ -96,6 +127,40 @@ TEST_F(AWSScriptBehaviorS3Test, GetObjectRaw_CallWithEmptyOutfileName_InvokeOnEr AWSScriptBehaviorS3::GetObjectRaw("dummyBucket", "dummyObject", "dummyRegion", ""); } +TEST_F(AWSScriptBehaviorS3Test, GetObjectRaw_CallWithOutfileNameMissFullPath_InvokeOnError) +{ + AWSScriptBehaviorS3NotificationBusHandlerMock s3HandlerMock; + EXPECT_CALL(s3HandlerMock, OnGetObjectError(::testing::_)).Times(1); + AWSScriptBehaviorS3::GetObjectRaw("dummyBucket", "dummyObject", "dummyRegion", "dummyOut.txt"); +} + +TEST_F(AWSScriptBehaviorS3Test, GetObjectRaw_CallWithOutfileNameIsDirectory_InvokeOnError) +{ + AWSScriptBehaviorS3NotificationBusHandlerMock s3HandlerMock; + EXPECT_CALL(s3HandlerMock, OnGetObjectError(::testing::_)).Times(1); + AWSScriptBehaviorS3::GetObjectRaw("dummyBucket", "dummyObject", "dummyRegion", AZ::Test::GetCurrentExecutablePath()); +} + +TEST_F(AWSScriptBehaviorS3Test, GetObjectRaw_CallWithOutfileDirectoryNoExist_InvokeOnError) +{ + AWSScriptBehaviorS3NotificationBusHandlerMock s3HandlerMock; + EXPECT_CALL(s3HandlerMock, OnGetObjectError(::testing::_)).Times(1); + AZStd::string dummyDirectory = AZStd::string::format("%s/dummyDirectory/dummyOut.txt", AZ::Test::GetCurrentExecutablePath().c_str()); + AWSScriptBehaviorS3::GetObjectRaw("dummyBucket", "dummyObject", "dummyRegion", dummyDirectory); +} + +TEST_F(AWSScriptBehaviorS3Test, GetObjectRaw_CallWithOutfileIsReadOnly_InvokeOnError) +{ + AWSScriptBehaviorS3NotificationBusHandlerMock s3HandlerMock; + EXPECT_CALL(s3HandlerMock, OnGetObjectError(::testing::_)).Times(1); + AZStd::string randomTestFile = AZStd::string::format("%s/test%s.txt", + AZ::Test::GetCurrentExecutablePath().c_str(), AZ::Uuid::CreateRandom().ToString(false, false).c_str()); + AzFramework::StringFunc::Path::Normalize(randomTestFile); + CreateReadOnlyTestFile(randomTestFile); + AWSScriptBehaviorS3::GetObjectRaw("dummyBucket", "dummyObject", "dummyRegion", randomTestFile); + RemoveReadOnlyTestFile(randomTestFile); +} + TEST_F(AWSScriptBehaviorS3Test, GetObject_NoBucketNameInResourceMappingFound_InvokeOnError) { AWSScriptBehaviorS3NotificationBusHandlerMock s3HandlerMock; diff --git a/Gems/AWSCore/Code/awscore_resourcemappingtool_files.cmake b/Gems/AWSCore/Code/awscore_resourcemappingtool_files.cmake index b67c50e955..466a2c917f 100644 --- a/Gems/AWSCore/Code/awscore_resourcemappingtool_files.cmake +++ b/Gems/AWSCore/Code/awscore_resourcemappingtool_files.cmake @@ -10,6 +10,5 @@ # set(FILES - Include/Private/Editor/UI/AWSCoreResourceMappingToolAction.h - Source/Editor/UI/AWSCoreResourceMappingToolAction.cpp + Source/AWSCoreResourceMappingToolModule.cpp ) diff --git a/Gems/AWSCore/cdk/README.md b/Gems/AWSCore/cdk/README.md index c49155a422..e4c0335c9c 100644 --- a/Gems/AWSCore/cdk/README.md +++ b/Gems/AWSCore/cdk/README.md @@ -44,9 +44,9 @@ $ pip install -r requirements.txt ## Set environment variables or accept defaults -* O3D_AWS_DEPLOY_REGION*: The region to deploy the stacks into, will default to CDK_DEFAULT_REGION -* O3D_AWS_DEPLOY_ACCOUNT*: The account to deploy stacks into, will default to CDK_DEFAULT_ACCOUNT -* O3D_AWS_PROJECT_NAME*: The name of the O3DE project stacks should be deployed for will default to AWS-PROJECT +* O3DE_AWS_DEPLOY_REGION*: The region to deploy the stacks into, will default to CDK_DEFAULT_REGION +* O3DE_AWS_DEPLOY_ACCOUNT*: The account to deploy stacks into, will default to CDK_DEFAULT_ACCOUNT +* O3DE_AWS_PROJECT_NAME*: The name of the O3DE project stacks should be deployed for will default to AWS-PROJECT See https://docs.aws.amazon.com/cdk/latest/guide/environments.html for more information including how to pass parameters to use for environment variables. diff --git a/Gems/AWSCore/cdk/app.py b/Gems/AWSCore/cdk/app.py index 2e5b196e02..2d8bfa4181 100755 --- a/Gems/AWSCore/cdk/app.py +++ b/Gems/AWSCore/cdk/app.py @@ -22,11 +22,11 @@ from core.aws_core import AWSCore from example.example_resources_stack import ExampleResources """Configuration""" -REGION = os.environ.get('O3D_AWS_DEPLOY_REGION', os.environ.get('CDK_DEFAULT_REGION')) -ACCOUNT = os.environ.get('O3D_AWS_DEPLOY_ACCOUNT', os.environ.get('CDK_DEFAULT_ACCOUNT')) +REGION = os.environ.get('O3DE_AWS_DEPLOY_REGION', os.environ.get('CDK_DEFAULT_REGION')) +ACCOUNT = os.environ.get('O3DE_AWS_DEPLOY_ACCOUNT', os.environ.get('CDK_DEFAULT_ACCOUNT')) # Set the common prefix to group stacks in a project together. -PROJECT_NAME = os.environ.get('O3D_AWS_PROJECT_NAME', f'AWS-PROJECT').upper() +PROJECT_NAME = os.environ.get('O3DE_AWS_PROJECT_NAME', f'O3DE-AWS-PROJECT').upper() # The name of this feature FEATURE_NAME = 'Core' diff --git a/Gems/AWSCore/cdk/core/core_stack.py b/Gems/AWSCore/cdk/core/core_stack.py index 7bf8676987..997d15ef6b 100755 --- a/Gems/AWSCore/cdk/core/core_stack.py +++ b/Gems/AWSCore/cdk/core/core_stack.py @@ -27,7 +27,7 @@ class CoreStack(core.Stack): """ # Resource groups cannot start with 'AWS' or 'aws' so add this prefix - RESOURCE_GROUP_PREFIX = 'O3D' + RESOURCE_GROUP_PREFIX = 'O3DE' def __init__(self, scope: core.Construct, id_: str, project_name: str, feature_name: str, **kwargs) -> None: super().__init__(scope, id_, **kwargs) diff --git a/Gems/AWSMetrics/cdk/README.md b/Gems/AWSMetrics/cdk/README.md index 3f0544a9ce..6f2c774bc3 100644 --- a/Gems/AWSMetrics/cdk/README.md +++ b/Gems/AWSMetrics/cdk/README.md @@ -42,9 +42,9 @@ $ pip install -r requirements.txt ## Set environment variables or accept defaults -* O3D_AWS_DEPLOY_REGION*: The region to deploy the stacks into, will default to CDK_DEFAULT_REGION -* O3D_AWS_DEPLOY_ACCOUNT*: The account to deploy stacks into, will default to CDK_DEFAULT_ACCOUNT -* O3D_AWS_PROJECT_NAME*: The name of the O3DE project stacks should be deployed for will default to AWS-PROJECT +* O3DE_AWS_DEPLOY_REGION*: The region to deploy the stacks into, will default to CDK_DEFAULT_REGION +* O3DE_AWS_DEPLOY_ACCOUNT*: The account to deploy stacks into, will default to CDK_DEFAULT_ACCOUNT +* O3DE_AWS_PROJECT_NAME*: The name of the O3DE project stacks should be deployed for will default to AWS-PROJECT See https://docs.aws.amazon.com/cdk/latest/guide/environments.html for more information including how to pass parameters to use for environment variables. diff --git a/Gems/AWSMetrics/cdk/app.py b/Gems/AWSMetrics/cdk/app.py index 21f8c8f802..469925e533 100755 --- a/Gems/AWSMetrics/cdk/app.py +++ b/Gems/AWSMetrics/cdk/app.py @@ -17,11 +17,11 @@ from aws_metrics.aws_metrics_construct import AWSMetrics import os """Configuration""" -REGION = os.environ.get('O3D_AWS_DEPLOY_REGION', os.environ['CDK_DEFAULT_REGION']) -ACCOUNT = os.environ.get('O3D_AWS_DEPLOY_ACCOUNT', os.environ['CDK_DEFAULT_ACCOUNT']) +REGION = os.environ.get('O3DE_AWS_DEPLOY_REGION', os.environ['CDK_DEFAULT_REGION']) +ACCOUNT = os.environ.get('O3DE_AWS_DEPLOY_ACCOUNT', os.environ['CDK_DEFAULT_ACCOUNT']) # Set the common prefix to group stacks in a project together. Defaults to LY-AWS. -PROJECT_NAME = os.environ.get('O3D_AWS_PROJECT_NAME', f'AWS-PROJECT').upper() +PROJECT_NAME = os.environ.get('O3DE_AWS_PROJECT_NAME', f'O3DE-AWS-PROJECT').upper() # The name of this feature FEATURE_NAME = 'AWSMetrics' diff --git a/Gems/AWSMetrics/cdk/aws_metrics/batch_processing.py b/Gems/AWSMetrics/cdk/aws_metrics/batch_processing.py index f1a356addf..fe85615d8d 100755 --- a/Gems/AWSMetrics/cdk/aws_metrics/batch_processing.py +++ b/Gems/AWSMetrics/cdk/aws_metrics/batch_processing.py @@ -259,7 +259,7 @@ class BatchProcessing: ) policy_statements.append(input_stream_policy_statement) - log_policy_statetement = iam.PolicyStatement( + log_policy_statement = iam.PolicyStatement( actions=[ 'logs:PutLogEvents', ], @@ -268,7 +268,7 @@ class BatchProcessing: self._firehose_delivery_stream_log_group.log_group_arn ] ) - policy_statements.append(log_policy_statetement) + policy_statements.append(log_policy_statement) data_catalog_policy_statement = iam.PolicyStatement( actions=[ diff --git a/Gems/AssetValidation/Code/Source/AssetSeedUtil.h b/Gems/AssetValidation/Code/Source/AssetSeedUtil.h index 4a6ff1f1d8..60d94e8903 100644 --- a/Gems/AssetValidation/Code/Source/AssetSeedUtil.h +++ b/Gems/AssetValidation/Code/Source/AssetSeedUtil.h @@ -30,7 +30,7 @@ namespace AssetValidation::AssetSeed constexpr char GemsDirectoryName[] = "Gems"; constexpr char GemsSeedFileName[] = "seedList"; constexpr char EngineSeedFileName[] = "SeedAssetList"; - constexpr char EngineDirectoryName[] = "Engine"; + constexpr auto EngineDirectoryName = AZ::IO::FixedMaxPath("Assets") / "Engine"; void AddPlatformSeeds(const AZStd::string& rootFolder, AZStd::vector& defaultSeedLists, AzFramework::PlatformFlags platformFlags); diff --git a/Gems/AssetValidation/Code/Tests/AssetValidationTest.cpp b/Gems/AssetValidation/Code/Tests/AssetValidationTest.cpp index a5ff671fc3..5003c4484c 100644 --- a/Gems/AssetValidation/Code/Tests/AssetValidationTest.cpp +++ b/Gems/AssetValidation/Code/Tests/AssetValidationTest.cpp @@ -32,20 +32,21 @@ TEST_F(AssetValidationTest, DefaultSeedList_ReturnsExpectedSeedLists) { AZStd::vector gemInfo; - AZStd::string gemSeedList, engineSeedList, projectSeedList; + AZ::IO::Path gemSeedList, engineSeedList, projectSeedList; - ASSERT_TRUE(CreateDummyFile((AZ::IO::Path("mockGem") / AzFramework::GemInfo::GetGemAssetFolder()).c_str(), "seedList", "Mock Gem Seed List", gemSeedList)); - ASSERT_TRUE(CreateDummyFile("Engine", "SeedAssetList", "Engine Seed List", engineSeedList)); + ASSERT_TRUE(CreateDummyFile((AZ::IO::Path("mockGem") / AzFramework::GemInfo::GetGemAssetFolder()).c_str(), "seedList", "Mock Gem Seed List", gemSeedList.Native())); + ASSERT_TRUE(CreateDummyFile((AZ::IO::Path("Assets") / "Engine").c_str(), "SeedAssetList", "Engine Seed List", engineSeedList.Native())); AZ::SettingsRegistryInterface::FixedValueString projectName = AZ::Utils::GetProjectName(); ASSERT_FALSE(projectName.empty()); - ASSERT_TRUE(CreateDummyFile(projectName.c_str(), "SeedAssetList", "Project Seed List", projectSeedList)); + ASSERT_TRUE(CreateDummyFile(projectName.c_str(), "SeedAssetList", "Project Seed List", projectSeedList.Native())); AzFramework::GemInfo mockGem("MockGem"); mockGem.m_absoluteSourcePaths.push_back((m_tempDir / "mockGem").string().c_str()); gemInfo.push_back(mockGem); - AZStd::vector defaultSeedLists = AssetValidation::AssetSeed::GetDefaultSeedListFiles(gemInfo, AzFramework::PlatformFlags::Platform_PC); + AZStd::vector defaultSeedStringList = AssetValidation::AssetSeed::GetDefaultSeedListFiles(gemInfo, AzFramework::PlatformFlags::Platform_PC); + AZStd::vector defaultSeedLists{ AZStd::make_move_iterator(defaultSeedStringList.begin()), AZStd::make_move_iterator(defaultSeedStringList.end()) }; ASSERT_THAT(defaultSeedLists, ::testing::UnorderedElementsAre(gemSeedList, engineSeedList, projectSeedList)); } diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Previewer/ImagePreviewer.ui b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Previewer/ImagePreviewer.ui index bdb94bd489..a276adeb78 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Previewer/ImagePreviewer.ui +++ b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Previewer/ImagePreviewer.ui @@ -127,11 +127,6 @@ - - QWidget -
Controls/PreviewModelCtrl.h
- 1 -
AzToolsFramework::AspectRatioAwarePixmapWidget QWidget diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.cpp b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.cpp index 14f125c283..1af6563577 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.cpp +++ b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.cpp @@ -129,7 +129,7 @@ namespace ImageProcessingAtom { AZStd::string fullPath; AZ::StringFunc::Path::Join(watchFolder.c_str(), assetInfo.m_relativePath.c_str(), fullPath); - if (RenerThumbnailFromImage(thumbnailKey, thumbnailSize, IImageObjectPtr(LoadImageFromFile(fullPath)))) + if (RenderThumbnailFromImage(thumbnailKey, thumbnailSize, IImageObjectPtr(LoadImageFromFile(fullPath)))) { return; } @@ -139,7 +139,7 @@ namespace ImageProcessingAtom auto productKey = azrtti_cast(thumbnailKey.data()); if (productKey) { - if (RenerThumbnailFromImage(thumbnailKey, thumbnailSize, Utils::LoadImageFromImageAsset(productKey->GetAssetId()))) + if (RenderThumbnailFromImage(thumbnailKey, thumbnailSize, Utils::LoadImageFromImageAsset(productKey->GetAssetId()))) { return; } @@ -149,7 +149,7 @@ namespace ImageProcessingAtom thumbnailKey, &AzToolsFramework::Thumbnailer::ThumbnailerRendererNotifications::ThumbnailFailedToRender); } - bool ImageThumbnailSystemComponent::RenerThumbnailFromImage( + bool ImageThumbnailSystemComponent::RenderThumbnailFromImage( AzToolsFramework::Thumbnailer::SharedThumbnailKey thumbnailKey, int thumbnailSize, IImageObjectPtr previewImage) const { if (!previewImage) diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.h b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.h index 943857fd35..ca2453b532 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.h +++ b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Thumbnail/ImageThumbnailSystemComponent.h @@ -52,7 +52,7 @@ namespace ImageProcessingAtom bool Installed() const override; void RenderThumbnail(AzToolsFramework::Thumbnailer::SharedThumbnailKey thumbnailKey, int thumbnailSize) override; - bool RenerThumbnailFromImage( + bool RenderThumbnailFromImage( AzToolsFramework::Thumbnailer::SharedThumbnailKey thumbnailKey, int thumbnailSize, IImageObjectPtr previewImage) const; }; } // namespace Thumbnails diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Compressed.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Compressed.preset index dcbaea96aa..01595a3425 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Compressed.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Compressed.preset @@ -7,7 +7,10 @@ "UUID": "{2828FBFE-BDF9-45A7-9370-F93822719CCF}", "Name": "UserInterface_Compressed", "SuppressEngineReduce": true, - "PixelFormat": "R8G8B8X8" + "PixelFormat": "R8G8B8A8", + "SourceColor": "Linear", + "DestColor": "Linear", + "FileMasks": [ "_ui" ] }, "PlatformsPresets": { "es3": { diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Lossless.preset b/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Lossless.preset index 5ccaa3ac16..78c63790ab 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Lossless.preset +++ b/Gems/Atom/Asset/ImageProcessingAtom/Config/UserInterface_Lossless.preset @@ -7,32 +7,35 @@ "UUID": "{83003128-F63E-422B-AEC2-68F0A947225F}", "Name": "UserInterface_Lossless", "SuppressEngineReduce": true, - "PixelFormat": "R8G8B8X8" + "PixelFormat": "R8G8B8A8", + "SourceColor": "Linear", + "DestColor": "Linear", + "FileMasks": [ "_ui" ] }, "PlatformsPresets": { "es3": { "UUID": "{83003128-F63E-422B-AEC2-68F0A947225F}", "Name": "UserInterface_Lossless", "SuppressEngineReduce": true, - "PixelFormat": "R8G8B8X8" + "PixelFormat": "R8G8B8A8" }, "ios": { "UUID": "{83003128-F63E-422B-AEC2-68F0A947225F}", "Name": "UserInterface_Lossless", "SuppressEngineReduce": true, - "PixelFormat": "R8G8B8X8" + "PixelFormat": "R8G8B8A8" }, "osx_gl": { "UUID": "{83003128-F63E-422B-AEC2-68F0A947225F}", "Name": "UserInterface_Lossless", "SuppressEngineReduce": true, - "PixelFormat": "R8G8B8X8" + "PixelFormat": "R8G8B8A8" }, "provo": { "UUID": "{83003128-F63E-422B-AEC2-68F0A947225F}", "Name": "UserInterface_Lossless", "SuppressEngineReduce": true, - "PixelFormat": "R8G8B8X8" + "PixelFormat": "R8G8B8A8" } } } diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype index cb66a987ae..954e01c592 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype @@ -946,19 +946,6 @@ "type": "Bool", "defaultValue": false }, - { - "id": "factor", - "displayName": "Factor", - "description": "Strength factor for scaling the depth values", - "type": "Float", - "defaultValue": 0.0, - "min": 0.0, - "softMax": 0.1, - "connection": { - "type": "ShaderInput", - "id": "m_depthFactor" - } - }, { "id": "textureMap", "displayName": "Texture Map", @@ -981,6 +968,32 @@ "id": "m_parallaxUvIndex" } }, + { + "id": "factor", + "displayName": "Heightmap Scale", + "description": "The total height of the heightmap in local model units.", + "type": "Float", + "defaultValue": 0.0, + "min": 0.0, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "id": "m_depthFactor" + } + }, + { + "id": "offset", + "displayName": "Offset", + "description": "Adjusts the overall displacement amount in local model units.", + "type": "Float", + "defaultValue": 0.0, + "softMin": -0.1, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "id": "m_depthOffset" + } + }, { "id": "invert", "displayName": "Invert", @@ -1026,6 +1039,17 @@ "type": "ShaderOption", "id": "o_parallax_enablePixelDepthOffset" } + }, + { + "id": "showClipping", + "displayName": "Show Clipping", + "description": "Highlight areas where the heightmap is clipped by the mesh surface.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderOption", + "id": "o_parallax_highlightClipping" + } } ], "subsurfaceScattering": [ @@ -1714,22 +1738,6 @@ "shaderOption": "o_emissive_useTexture" } }, - { - // See the comment above for details. - "type": "UseTexture", - "args": { - "textureProperty": "parallax.textureMap", - "dependentProperties": ["parallax.textureMapUv"], - "useTextureProperty": "parallax.enable", - "shaderTags": [ - "ForwardPass", - "ForwardPass_EDS", - "Shadowmap_WithPS", - "DepthPass_WithPS" - ], - "shaderOption": "o_parallax_feature_enabled" - } - }, { // See the comment above for details. "type": "UseTexture", @@ -1813,34 +1821,6 @@ ] } }, - { - // Controls visibility for properties in the editor. - // @param actions - a list of actions that are executed in order. visibility will be set when triggerProperty hits the triggerValue. - // @param affectedProperties - the properties that are affected by actions. - "type": "UpdatePropertyVisibility", - "args": { - "actions": [ - { - "triggerProperty": "parallax.enable", - "triggerValue": true, - "visibility": "Enabled" - }, - { - "triggerProperty": "parallax.enable", - "triggerValue": false, - "visibility": "Hidden" - } - ], - "affectedProperties": [ - "parallax.factor", - "parallax.textureMap", - "parallax.invert", - "parallax.algorithm", - "parallax.quality", - "parallax.pdo" - ] - } - }, { "type": "UpdatePropertyVisibility", "args": { @@ -2076,6 +2056,12 @@ ] } }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_ParallaxState.lua" + } + }, { "type": "Lua", "args": { diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli index f9bfb75fea..34af9229c2 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "MaterialInputs/BaseColorInput.azsli" #include "MaterialInputs/RoughnessInput.azsli" @@ -104,7 +106,22 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial } // Callback function for ParallaxMapping.azsli -float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) +DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) { return SampleDepthOrHeightMap(MaterialSrg::m_depthInverted, MaterialSrg::m_depthMap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy); } + +COMMON_OPTIONS_PARALLAX() + +bool ShouldHandleParallax() +{ + // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled. + return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useDepthMap; +} + +bool ShouldHandleParallaxInDepthShaders() +{ + // The depth pass shaders need to calculate parallax when the result could affect the depth buffer, or when + // parallax could affect texel clipping. + return ShouldHandleParallax() && (o_parallax_enablePixelDepthOffset || o_opacity_mode == OpacityMode::Cutout); +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl index 28968b5941..db99ee7e24 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl @@ -10,7 +10,6 @@ * */ -#include #include "./EnhancedPBR_Common.azsli" #include #include @@ -55,7 +54,7 @@ VSDepthOutput MainVS(VSInput IN) OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { OUT.m_worldPosition = worldPosition.xyz; @@ -74,45 +73,28 @@ PSDepthOutput MainPS(VSDepthOutput IN, bool isFrontFace : SV_IsFrontFace) { PSDepthOutput OUT; - // Clip Alpha - float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; - float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); - CheckClipping(alpha, MaterialSrg::m_opacityFactor); - OUT.m_depth = IN.m_position.z; - - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + + if(ShouldHandleParallaxInDepthShaders()) { // We support two UV streams, but only a single stream of tangent/bitangent. So for UV[1+] we generated the tangent/bitangent in screen-space. float3 tangents[UvSetCount] = { IN.m_tangent.xyz, float3(0, 0, 0) }; float3 bitangents[UvSetCount] = { IN.m_bitangent.xyz, float3(0, 0, 0) }; PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents, 1); - float3 tangent = tangents[MaterialSrg::m_parallaxUvIndex]; - float3 bitangent = bitangents[MaterialSrg::m_parallaxUvIndex]; - float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - - float3 tangentOffset = GetParallaxOffset( MaterialSrg::m_depthFactor, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], - ViewSrg::m_worldPosition.xyz - IN.m_worldPosition, - tangent, - bitangent, - IN.m_normal, - uvMatrix); - - PixelDepthOffset pdo = CalcPixelDepthOffset(MaterialSrg::m_depthFactor, - tangentOffset, - IN.m_worldPosition, - tangent, - bitangent, - IN.m_normal, - uvMatrixInverse, - ObjectSrg::GetWorldMatrix(), - ViewSrg::m_viewProjectionMatrix); - OUT.m_depth = pdo.m_depth; + + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset, + ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth); } + + // Clip Alpha + float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; + float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; + float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); + CheckClipping(alpha, MaterialSrg::m_opacityFactor); + return OUT; } diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl index 36c8e81a94..23e28e8742 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl @@ -40,8 +40,8 @@ COMMON_OPTIONS_NORMAL() COMMON_OPTIONS_CLEAR_COAT() COMMON_OPTIONS_OCCLUSION() COMMON_OPTIONS_EMISSIVE() -COMMON_OPTIONS_PARALLAX() COMMON_OPTIONS_DETAIL_MAPS() +// Note COMMON_OPTIONS_PARALLAX is in StandardPBR_Common.azsli because it's needed by all StandardPBR shaders. // Alpha #include "MaterialInputs/AlphaInput.azsli" @@ -102,8 +102,11 @@ VSOutput EnhancedPbr_ForwardPassVS(VSInput IN) // but we would need to address how it works with the parallax code below that indexes into the m_detailUV array. OUT.m_detailUv[0] = mul(MaterialSrg::m_detailUvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_detailUv[1] = mul(MaterialSrg::m_detailUvMatrix, float3(IN.m_uv1, 1.0)).xy; + + // Shadow coords will be calculated in the pixel shader in this case + bool skipShadowCoords = ShouldHandleParallax() && o_parallax_enablePixelDepthOffset; - VertexHelper(IN, OUT, worldPosition, o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset); + VertexHelper(IN, OUT, worldPosition, skipShadowCoords); return OUT; } @@ -132,9 +135,11 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // ------- Depth & Parallax ------- depth = IN.m_position.z; + + bool displacementIsClipped = false; // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scatteirng is enabled - if(!o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useDepthMap) + if(ShouldHandleParallax()) { // GetParallaxInput applies an tangent offset to the UV. We want to apply the same offset to the detailUv (note: this needs to be tested with content) // The math is: offset = newUv - oldUv; detailUv += offset; @@ -143,9 +148,9 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset, ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth); + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth, displacementIsClipped); // Apply second part of the offset to the detail UV (see comment above) IN.m_detailUv[MaterialSrg::m_parallaxUvIndex] -= IN.m_uv[MaterialSrg::m_parallaxUvIndex]; @@ -206,6 +211,11 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float3 baseColor = GetDetailedBaseColorInput( MaterialSrg::m_baseColorMap, MaterialSrg::m_sampler, baseColorUv, o_baseColor_useTexture, MaterialSrg::m_baseColor, MaterialSrg::m_baseColorFactor, o_baseColorTextureBlendMode, MaterialSrg::m_detail_baseColor_texture, MaterialSrg::m_sampler, detailUv, o_detail_baseColor_useTexture, detailLayerBaseColorFactor); + + if(o_parallax_highlightClipping && displacementIsClipped) + { + ApplyParallaxClippingHighlight(baseColor); + } // ------- Metallic ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl index 15b58c4deb..80aedcd6f4 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl @@ -12,7 +12,6 @@ #include #include "EnhancedPBR_Common.azsli" -#include #include #include #include @@ -54,8 +53,8 @@ VertexOutput MainVS(VertexInput IN) // By design, only UV0 is allowed to apply transforms. OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + + if(ShouldHandleParallaxInDepthShaders()) { OUT.m_worldPosition = worldPosition.xyz; @@ -75,57 +74,32 @@ PSDepthOutput MainPS(VertexOutput IN, bool isFrontFace : SV_IsFrontFace) { PSDepthOutput OUT; - // Clip Alpha - float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; - float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); - CheckClipping(alpha, MaterialSrg::m_opacityFactor); - OUT.m_depth = IN.m_position.z; - - float3 dirToCamera; - if(ViewSrg::m_projectionMatrix[0].w) - { - // orthographic projection (directional light) - // No view position, use light direction - dirToCamera = ViewSrg::m_viewMatrix[2].xyz; - } - else + + if(ShouldHandleParallaxInDepthShaders()) { - dirToCamera = ViewSrg::m_worldPosition.xyz - IN.m_worldPosition; - } + static const float ShadowMapDepthBias = 0.000001; - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) - { // We support two UV streams, but only a single stream of tangent/bitangent. So for UV[1+] we generated the tangent/bitangent in screen-space. float3 tangents[UvSetCount] = { IN.m_tangent.xyz, float3(0, 0, 0) }; float3 bitangents[UvSetCount] = { IN.m_bitangent.xyz, float3(0, 0, 0) }; PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents, 1); - float3 tangent = tangents[MaterialSrg::m_parallaxUvIndex]; - float3 bitangent = bitangents[MaterialSrg::m_parallaxUvIndex]; - float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - float3 tangentOffset = GetParallaxOffset( MaterialSrg::m_depthFactor, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], - dirToCamera, - tangent, - bitangent, - IN.m_normal, - uvMatrix); - - PixelDepthOffset pdo = CalcPixelDepthOffset(MaterialSrg::m_depthFactor, - tangentOffset, - IN.m_worldPosition, - tangent, - bitangent, - IN.m_normal, - uvMatrixInverse, - ObjectSrg::GetWorldMatrix(), - ViewSrg::m_viewProjectionMatrix); - OUT.m_depth = pdo.m_depth; + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset, + ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth); + + OUT.m_depth += ShadowMapDepthBias; } + + // Clip Alpha + float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; + float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; + float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); + CheckClipping(alpha, MaterialSrg::m_opacityFactor); + return OUT; } diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/MaterialInputs/ParallaxInput.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/MaterialInputs/ParallaxInput.azsli index edee4c3c07..ab601429e8 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/MaterialInputs/ParallaxInput.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/MaterialInputs/ParallaxInput.azsli @@ -24,16 +24,15 @@ #define COMMON_SRG_INPUTS_PARALLAX(prefix) \ Texture2D prefix##m_depthMap; \ float prefix##m_depthFactor; \ +float prefix##m_depthOffset; \ bool prefix##m_depthInverted; #define COMMON_OPTIONS_PARALLAX(prefix) \ option bool prefix##o_useDepthMap; -option bool o_parallax_feature_enabled; - -void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float depthFactor, +void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float depthFactor, float depthOffset, float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse, - inout float2 uv, inout float3 worldPosition, inout float depth) + inout float2 uv, inout float3 worldPosition, inout float depth, out bool isClipped) { if(o_parallax_feature_enabled) { @@ -49,20 +48,22 @@ void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float dep dirToCamera = ViewSrg::m_worldPosition.xyz - worldPosition; } - float3 tangentOffset = GetParallaxOffset( depthFactor, - uv, - dirToCamera, - tangent, - bitangent, - normal, - uvMatrix); + ParallaxOffset tangentOffset = GetParallaxOffset( depthFactor, + depthOffset, + uv, + dirToCamera, + tangent, + bitangent, + normal, + uvMatrix); - uv += tangentOffset.xy; + uv += tangentOffset.m_offsetTS.xy; + isClipped = tangentOffset.m_isClipped; if(o_parallax_enablePixelDepthOffset) { PixelDepthOffset pdo = CalcPixelDepthOffset(depthFactor, - tangentOffset, + tangentOffset.m_offsetTS, worldPosition, tangent, bitangent, @@ -70,9 +71,20 @@ void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float dep uvMatrixInverse, objectWorldMatrix, ViewSrg::m_viewProjectionMatrix); + depth = pdo.m_depth; + worldPosition = pdo.m_worldPosition; } + } } +void GetParallaxInput(float3 normal, float3 tangent, float3 bitangent, float depthFactor, float depthOffset, + float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse, + inout float2 uv, inout float3 worldPosition, inout float depth) +{ + bool isClipped; + GetParallaxInput(normal, tangent, bitangent, depthFactor, depthOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depth, isClipped); +} + diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype index 7610a4c9db..e2119dcf12 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype @@ -18,11 +18,6 @@ "displayName": "Parallax Settings", "description": "Properties for configuring the parallax effect, applied to all layers." }, - { - "id": "opacity", - "displayName": "Opacity", - "description": "Properties for configuring the materials transparency." - }, { "id": "uv", "displayName": "UVs", @@ -361,19 +356,6 @@ "id": "m_parallaxUvIndex" } }, - { - "id": "factor", - "displayName": "Factor", - "description": "Strength factor for scaling the depth values for all layers.", - "type": "Float", - "defaultValue": 1.0, - "min": 0.0, - "softMax": 2.0, - "connection": { - "type": "ShaderInput", - "id": "m_parallaxMainDepthFactor" - } - }, { "id": "algorithm", "displayName": "Algorithm", @@ -408,73 +390,17 @@ "type": "ShaderOption", "id": "o_parallax_enablePixelDepthOffset" } - } - ], - "opacity": [ - { - "id": "mode", - "displayName": "Opacity Mode", - "description": "Opacity mode for this texture.", - "type": "Enum", - "enumValues": [ "Opaque", "Cutout", "Blended" ], - "defaultValue": "Opaque", - "connection": { - "type": "ShaderOption", - "id": "o_opacity_mode" - } }, { - "id": "alphaSource", - "displayName": "Alpha Source", - "description": "Source texture of alpha value.", - "type": "Enum", - "enumValues": [ "Packed", "Split", "None" ], - "defaultValue": "Packed", + "id": "showClipping", + "displayName": "Show Clipping", + "description": "Highlight areas where the heightmap is clipped by the mesh surface.", + "type": "Bool", + "defaultValue": false, "connection": { "type": "ShaderOption", - "id": "o_opacity_source" - } - }, - { - "id": "textureMap", - "displayName": "Texture Map", - "description": "Texture map for defining surface opacity.", - "type": "Image", - "connection": { - "type": "ShaderInput", - "id": "m_opacityMap" + "id": "o_parallax_highlightClipping" } - }, - { - "id": "textureMapUv", - "displayName": "UV", - "description": "Opacity texture map UV set", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "id": "m_opacityMapUvIndex" - } - }, - { - "id": "factor", - "displayName": "Factor", - "description": "Factor for cutout threshold and blending", - "type": "Float", - "min": 0.0, - "max": 1.0, - "defaultValue": 0.5, - "connection": { - "type": "ShaderInput", - "id": "m_opacityFactor" - } - }, - { - "id": "doubleSided", - "displayName": "Double-sided", - "description": "Whether to render back-faces or just front-faces.", - "type": "Bool" } ], "uv": [ @@ -1343,8 +1269,8 @@ }, { "id": "factor", - "displayName": "Factor", - "description": "Strength factor for scaling the depth values", + "displayName": "Heightmap Scale", + "description": "The total height of the heightmap in local model units.", "type": "Float", "defaultValue": 0.0, "min": 0.0, @@ -1354,6 +1280,19 @@ "id": "m_layer1_m_depthFactor" } }, + { + "id": "offset", + "displayName": "Offset", + "description": "Adjusts the overall displacement amount in local model units.", + "type": "Float", + "defaultValue": 0.0, + "softMin": -0.1, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "id": "m_layer1_m_depthOffset" + } + }, { "id": "invert", "displayName": "Invert", @@ -2036,8 +1975,8 @@ }, { "id": "factor", - "displayName": "Factor", - "description": "Strength factor for scaling the depth values", + "displayName": "Heightmap Scale", + "description": "The total height of the heightmap in local model units.", "type": "Float", "defaultValue": 0.0, "min": 0.0, @@ -2047,6 +1986,19 @@ "id": "m_layer2_m_depthFactor" } }, + { + "id": "offset", + "displayName": "Offset", + "description": "Adjusts the overall displacement amount in local model units.", + "type": "Float", + "defaultValue": 0.0, + "softMin": -0.1, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "id": "m_layer2_m_depthOffset" + } + }, { "id": "invert", "displayName": "Invert", @@ -2729,8 +2681,8 @@ }, { "id": "factor", - "displayName": "Factor", - "description": "Strength factor for scaling the depth values", + "displayName": "Heightmap Scale", + "description": "The total height of the heightmap in local model units.", "type": "Float", "defaultValue": 0.0, "min": 0.0, @@ -2740,6 +2692,19 @@ "id": "m_layer3_m_depthFactor" } }, + { + "id": "offset", + "displayName": "Offset", + "description": "Adjusts the overall displacement amount in local model units.", + "type": "Float", + "defaultValue": 0.0, + "softMin": -0.1, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "id": "m_layer3_m_depthOffset" + } + }, { "id": "invert", "displayName": "Invert", @@ -2851,16 +2816,7 @@ { "file": "Shaders/MotionVector/SkinnedMeshMotionVector.shader", "tag": "SkinnedMeshMotionVector" - }, - // Used by the light culling system to produce accurate depth bounds for this object when it uses blended transparency - { - "file": "Shaders/Depth/DepthPassTransparentMin.shader", - "tag": "DepthPassTransparentMin" - }, - { - "file": "Shaders/Depth/DepthPassTransparentMax.shader", - "tag": "DepthPassTransparentMax" - } + } ], "functors": [ //############################################################################################## @@ -2885,7 +2841,7 @@ { "type": "Lua", "args": { - "file": "StandardPBR_ShaderEnable.lua" + "file": "StandardMultilayerPBR_ShaderEnable.lua" } }, { @@ -2925,27 +2881,6 @@ "file": "StandardPBR_SubsurfaceState.lua" } }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_HandleOpacityDoubleSided.lua" - } - }, - { - "type": "OverrideDrawList", - "args": { - "triggerProperty": "opacity.mode", - "triggerValue": "Blended", - "shaderIndex": 1, - "drawList": "transparent" - } - }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_HandleOpacityMode.lua" - } - }, //############################################################################################## // Layer 1 Functors //############################################################################################## diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Common.azsli index db3ec45e0c..ba0eaf2ac1 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Common.azsli @@ -14,6 +14,7 @@ #include #include +#include #include "MaterialInputs/BaseColorInput.azsli" #include "MaterialInputs/RoughnessInput.azsli" @@ -26,6 +27,8 @@ #include "MaterialInputs/ParallaxInput.azsli" #include "MaterialInputs/UvSetCount.azsli" +// ------ ShaderResourceGroup ---------------------------------------- + #define DEFINE_LAYER_SRG_INPUTS(prefix) \ COMMON_SRG_INPUTS_BASE_COLOR(prefix) \ COMMON_SRG_INPUTS_ROUGHNESS(prefix) \ @@ -57,17 +60,16 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial float4 m_pad3; // [GFX TODO][ATOM-14595] This is a workaround for a data stomping bug. Remove once it's fixed. uint m_parallaxUvIndex; - float m_parallaxMainDepthFactor; + + // These are used to limit the heightmap intersection search range to the narrowest band possible, to give the best quality result. + float m_displacementMin; // The lowest displacement value possible from all layers combined + float m_displacementMax; // The highest displacement value possible from all layers combined float3x3 m_uvMatrix; float4 m_pad4; // [GFX TODO][ATOM-14595] This is a workaround for a data stomping bug. Remove once it's fixed. float3x3 m_uvMatrixInverse; float4 m_pad5; // [GFX TODO][ATOM-14595] This is a workaround for a data stomping bug. Remove once it's fixed. - float m_opacityFactor; - Texture2D m_opacityMap; - uint m_opacityMapUvIndex; - Sampler m_sampler { AddressU = Wrap; @@ -109,6 +111,8 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial uint m_transmissionThicknessMapUvIndex; } +// ------ Shader Options ---------------------------------------- + enum class DebugDrawMode { None, BlendMaskValues, DepthMaps }; option DebugDrawMode o_debugDrawMode; @@ -121,6 +125,8 @@ option BlendMaskSource o_blendSource; // [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream. option bool o_blendMask_isBound; +// ------ Blend Utilities ---------------------------------------- + //! Returns the BlendMaskSource that will actually be used when rendering (not necessarily the same BlendMaskSource specified by the user) BlendMaskSource GetFinalBlendMaskSource() { @@ -181,6 +187,22 @@ float3 BlendLayers(float3 layer1, float3 layer2, float3 layer3, float3 blendMask return layer1 * blendMaskValues.r + layer2 * blendMaskValues.g + layer3 * blendMaskValues.b; } +// ------ Parallax Utilities ---------------------------------------- + +bool ShouldHandleParallax() +{ + // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled. + // Also, all the debug draw modes avoid parallax (they early-return before parallax code actually) so you can see exactly where the various maps appear on the surface UV space. + return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_debugDrawMode == DebugDrawMode::None; +} + +bool ShouldHandleParallaxInDepthShaders() +{ + // The depth pass shaders need to calculate parallax when the result could affect the depth buffer (or when + // parallax could affect texel clipping but we don't have alpha/clipping support in multilayer PBR). + return ShouldHandleParallax() && o_parallax_enablePixelDepthOffset; +} + // These static values are used to pass extra data to the GetDepth callback function during the parallax depth search. static float3 s_blendMaskFromVertexStream; @@ -192,7 +214,7 @@ void GetDepth_Setup(float3 vertexBlendMask) } // Callback function for ParallaxMapping.azsli -float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) +DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) { float3 layerDepthValues = float3(0,0,0); @@ -204,8 +226,9 @@ float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) layerUv = mul(MaterialSrg::m_layer1_m_uvMatrix, float3(uv, 1.0)).xy; } - layerDepthValues.r = SampleDepthOrHeightMap(MaterialSrg::m_layer1_m_depthInverted, MaterialSrg::m_layer1_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy); + layerDepthValues.r = SampleDepthOrHeightMap(MaterialSrg::m_layer1_m_depthInverted, MaterialSrg::m_layer1_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth; layerDepthValues.r *= MaterialSrg::m_layer1_m_depthFactor; + layerDepthValues.r -= MaterialSrg::m_layer1_m_depthOffset; } if(o_layer2_o_useDepthMap) @@ -216,8 +239,9 @@ float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) layerUv = mul(MaterialSrg::m_layer2_m_uvMatrix, float3(uv, 1.0)).xy; } - layerDepthValues.g = SampleDepthOrHeightMap(MaterialSrg::m_layer2_m_depthInverted, MaterialSrg::m_layer2_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy); + layerDepthValues.g = SampleDepthOrHeightMap(MaterialSrg::m_layer2_m_depthInverted, MaterialSrg::m_layer2_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth; layerDepthValues.g *= MaterialSrg::m_layer2_m_depthFactor; + layerDepthValues.g -= MaterialSrg::m_layer2_m_depthOffset; } if(o_layer3_o_useDepthMap) @@ -228,8 +252,9 @@ float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) layerUv = mul(MaterialSrg::m_layer3_m_uvMatrix, float3(uv, 1.0)).xy; } - layerDepthValues.b = SampleDepthOrHeightMap(MaterialSrg::m_layer3_m_depthInverted, MaterialSrg::m_layer3_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy); + layerDepthValues.b = SampleDepthOrHeightMap(MaterialSrg::m_layer3_m_depthInverted, MaterialSrg::m_layer3_m_depthMap, MaterialSrg::m_sampler, layerUv, uv_ddx, uv_ddy).m_depth; layerDepthValues.b *= MaterialSrg::m_layer3_m_depthFactor; + layerDepthValues.b -= MaterialSrg::m_layer3_m_depthOffset; } // Note, when the blend source is BlendMaskSource::VertexColors, parallax will not be able to blend correctly between layers. It will end up using the same blend mask values @@ -237,7 +262,6 @@ float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) // you have a small depth factor relative to the size of the blend transition. float3 blendMaskValues = GetBlendMaskValues(uv, s_blendMaskFromVertexStream); - float3 depth = BlendLayers(layerDepthValues.r, layerDepthValues.g, layerDepthValues.b, blendMaskValues); - - return depth; + float depth = BlendLayers(layerDepthValues.r, layerDepthValues.g, layerDepthValues.b, blendMaskValues); + return DepthResultAbsolute(depth); } diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl index 074b9dce26..ae156d7313 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl @@ -11,12 +11,10 @@ */ #include -#include #include #include #include -#include "MaterialInputs/AlphaInput.azsli" #include "MaterialInputs/ParallaxInput.azsli" @@ -72,7 +70,7 @@ VSDepthOutput MainVS(VSInput IN) OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { OUT.m_worldPosition = worldPosition.xyz; @@ -101,18 +99,9 @@ PSDepthOutput MainPS(VSDepthOutput IN, bool isFrontFace : SV_IsFrontFace) { PSDepthOutput OUT; - // Alpha - float2 layer1_baseColorUV = IN.m_uv[MaterialSrg::m_layer1_m_baseColorMapUvIndex]; - float2 layer2_baseColorUV = IN.m_uv[MaterialSrg::m_layer2_m_baseColorMapUvIndex]; - float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - // [GFX TODO][ATOM-14589] Figure out how to deal with opacity, instead of just hard-coding to layer1 - float alpha = SampleAlpha(MaterialSrg::m_layer1_m_baseColorMap, MaterialSrg::m_opacityMap, layer1_baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); - - CheckClipping(alpha, MaterialSrg::m_opacityFactor); - OUT.m_depth = IN.m_position.z; - if(o_debugDrawMode == DebugDrawMode::None && o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { // We support two UV streams, but only a single stream of tangent/bitangent. So for UV[1+] we generated the tangent/bitangent in screen-space. float3 tangents[UvSetCount] = { IN.m_tangent.xyz, float3(0, 0, 0) }; @@ -126,7 +115,9 @@ PSDepthOutput MainPS(VSDepthOutput IN, bool isFrontFace : SV_IsFrontFace) float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_parallaxMainDepthFactor, + float parallaxOverallOffset = MaterialSrg::m_displacementMax; + float parallaxOverallFactor = MaterialSrg::m_displacementMax - MaterialSrg::m_displacementMin; + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], parallaxOverallFactor, parallaxOverallOffset, ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth); diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl index 560c7ab7eb..a83ea629e4 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl @@ -55,7 +55,6 @@ DEFINE_LAYER_OPTIONS(o_layer1_) DEFINE_LAYER_OPTIONS(o_layer2_) DEFINE_LAYER_OPTIONS(o_layer3_) -#include "MaterialInputs/AlphaInput.azsli" #include "MaterialInputs/SubsurfaceInput.azsli" #include "MaterialInputs/TransmissionInput.azsli" #include "StandardMultilayerPBR_Common.azsli" @@ -121,9 +120,8 @@ VSOutput ForwardPassVS(VSInput IN) OUT.m_blendMask = float3(1,1,1); } - // We can skip per-vertex shadow coords when parallax is enabled because we need to calculate per-pixel shadow coords anyway. - // We cannot skip shadow coords when o_debugDrawMode is on because some debug draw modes return before parallax. - bool skipShadowCoords = o_debugDrawMode == DebugDrawMode::None && o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset; + // Shadow coords will be calculated in the pixel shader in this case + bool skipShadowCoords = ShouldHandleParallax() && o_parallax_enablePixelDepthOffset; VertexHelper(IN, OUT, worldPosition, skipShadowCoords); return OUT; @@ -167,23 +165,27 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float if(o_debugDrawMode == DebugDrawMode::DepthMaps) { GetDepth_Setup(IN.m_blendMask); - float depth = GetDepth(IN.m_uv[MaterialSrg::m_parallaxUvIndex], float2(0,0), float2(0,0)); + float depth = GetNormalizedDepth(-MaterialSrg::m_displacementMax, -MaterialSrg::m_displacementMin, IN.m_uv[MaterialSrg::m_parallaxUvIndex], float2(0,0), float2(0,0)); return DebugOutput(float3(depth,depth,depth)); } // ------- Parallax ------- + bool displacementIsClipped = false; + // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scatteirng is enabled - if(!o_enableSubsurfaceScattering && o_parallax_feature_enabled) + if(ShouldHandleParallax()) { GetDepth_Setup(IN.m_blendMask); float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - - GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_parallaxMainDepthFactor, + + float parallaxOverallOffset = MaterialSrg::m_displacementMax; + float parallaxOverallFactor = MaterialSrg::m_displacementMax - MaterialSrg::m_displacementMin; + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], parallaxOverallFactor, parallaxOverallOffset, ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth); + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth, displacementIsClipped); // Adjust directional light shadow coorinates for parallax correction if(o_parallax_enablePixelDepthOffset) @@ -218,15 +220,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // Now that any parallax has been calculated, we calculate the blend factors for any layers that are impacted by the parallax. float3 blendMaskValues = GetBlendMaskValues(IN.m_uv[MaterialSrg::m_blendMaskUvIndex], IN.m_blendMask); - // ------- Alpha & Clip ------- - - float2 layer1_baseColorUv = uvLayer1[MaterialSrg::m_layer1_m_baseColorMapUvIndex]; - float2 layer2_baseColorUv = uvLayer2[MaterialSrg::m_layer2_m_baseColorMapUvIndex]; - float2 layer3_baseColorUv = uvLayer3[MaterialSrg::m_layer3_m_baseColorMapUvIndex]; - float2 opacityUv = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - // [GFX TODO][ATOM-14589] Figure out how to deal with opacity, instead of just hard-coding to layer1 - float alpha = GetAlphaInputAndClip(MaterialSrg::m_layer1_m_baseColorMap, MaterialSrg::m_opacityMap, layer1_baseColorUv, opacityUv, MaterialSrg::m_sampler, MaterialSrg::m_opacityFactor, o_opacity_source); - // ------- Normal ------- float3 layer1_normalFactor = MaterialSrg::m_layer1_m_normalFactor * blendMaskValues.r; @@ -245,6 +238,10 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float surface.normal = normalize(TangentSpaceToWorld(normalTS, IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex])); // ------- Base Color ------- + + float2 layer1_baseColorUv = uvLayer1[MaterialSrg::m_layer1_m_baseColorMapUvIndex]; + float2 layer2_baseColorUv = uvLayer2[MaterialSrg::m_layer2_m_baseColorMapUvIndex]; + float2 layer3_baseColorUv = uvLayer3[MaterialSrg::m_layer3_m_baseColorMapUvIndex]; float3 layer1_sampledColor = GetBaseColorInput(MaterialSrg::m_layer1_m_baseColorMap, MaterialSrg::m_sampler, layer1_baseColorUv, MaterialSrg::m_layer1_m_baseColor.rgb, o_layer1_o_baseColor_useTexture); float3 layer2_sampledColor = GetBaseColorInput(MaterialSrg::m_layer2_m_baseColorMap, MaterialSrg::m_sampler, layer2_baseColorUv, MaterialSrg::m_layer2_m_baseColor.rgb, o_layer2_o_baseColor_useTexture); @@ -253,6 +250,11 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float3 layer2_baseColor = BlendBaseColor(layer2_sampledColor, MaterialSrg::m_layer2_m_baseColor.rgb, MaterialSrg::m_layer2_m_baseColorFactor, o_layer2_o_baseColorTextureBlendMode, o_layer2_o_baseColor_useTexture); float3 layer3_baseColor = BlendBaseColor(layer3_sampledColor, MaterialSrg::m_layer3_m_baseColor.rgb, MaterialSrg::m_layer3_m_baseColorFactor, o_layer3_o_baseColorTextureBlendMode, o_layer3_o_baseColor_useTexture); float3 baseColor = BlendLayers(layer1_baseColor, layer2_baseColor, layer3_baseColor, blendMaskValues); + + if(o_parallax_highlightClipping && displacementIsClipped) + { + ApplyParallaxClippingHighlight(baseColor); + } // ------- Metallic ------- @@ -427,32 +429,13 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float lightingData.FinalizeLighting(surface.transmission.tint); - if (o_opacity_mode == OpacityMode::Blended || o_opacity_mode == OpacityMode::TintedTransparent) - { - alpha = FresnelSchlickWithRoughness(lightingData.NdotV, alpha, surface.roughnessLinear).x; // Increase opacity at grazing angles. - } + const float alpha = 1.0; PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); - // ------- Opacity ------- - - if (o_opacity_mode == OpacityMode::Blended) - { - // [GFX_TODO ATOM-13187] PbrLighting shouldn't be writing directly to render targets. It's confusing when - // specular is being added to diffuse just because we're calling render target 0 "diffuse". - - // For blended mode, we do (dest * alpha) + (source * 1.0). This allows the specular - // to be added on top of the diffuse, but then the diffuse must be pre-multiplied. - // It's done this way because surface transparency doesn't really change specular response (eg, glass). - lightingOutput.m_diffuseColor.rgb *= lightingOutput.m_diffuseColor.w; // pre-multiply diffuse - lightingOutput.m_diffuseColor.rgb += lightingOutput.m_specularColor.rgb; // add specular - } - else - { - // Pack factor and quality, drawback: because of precision limit of float16 cannot represent exact 1, maximum representable value is 0.9961 - uint factorAndQuality = dot(round(float2(saturate(surfaceScatteringFactor), MaterialSrg::m_subsurfaceScatteringQuality) * 255), float2(256, 1)); - lightingOutput.m_diffuseColor.w = factorAndQuality * (o_enableSubsurfaceScattering ? 1.0 : -1.0); - } + // Pack factor and quality, drawback: because of precision limit of float16 cannot represent exact 1, maximum representable value is 0.9961 + uint factorAndQuality = dot(round(float2(saturate(surfaceScatteringFactor), MaterialSrg::m_subsurfaceScatteringQuality) * 255), float2(256, 1)); + lightingOutput.m_diffuseColor.w = factorAndQuality * (o_enableSubsurfaceScattering ? 1.0 : -1.0); return lightingOutput; diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Parallax.lua b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Parallax.lua index 522121c96f..8880a4b842 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Parallax.lua +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Parallax.lua @@ -20,10 +20,12 @@ function GetMaterialPropertyDependencies() "layer1_parallax.enable", "layer2_parallax.enable", "layer3_parallax.enable", - "parallax.factor", "layer1_parallax.factor", "layer2_parallax.factor", - "layer3_parallax.factor" + "layer3_parallax.factor", + "layer1_parallax.offset", + "layer2_parallax.offset", + "layer3_parallax.offset" } end @@ -31,6 +33,23 @@ function GetShaderOptionDependencies() return {"o_parallax_feature_enabled"} end +function MergeRange(heightMinMax, offset, factor) + top = offset + bottom = offset - factor + + if(heightMinMax[1] == nil) then + heightMinMax[1] = top + else + heightMinMax[1] = math.max(heightMinMax[1], top) + end + + if(heightMinMax[0] == nil) then + heightMinMax[0] = bottom + else + heightMinMax[0] = math.min(heightMinMax[0], bottom) + end +end + function Process(context) local enableParallax = context:GetMaterialPropertyValue_bool("parallax.enable") local enable1 = context:GetMaterialPropertyValue_bool("layer1_parallax.enable") @@ -39,30 +58,25 @@ function Process(context) enableParallax = enableParallax and (enable1 or enable2 or enable3) context:SetShaderOptionValue_bool("o_parallax_feature_enabled", enableParallax) - -- Smaller values for the main parallax factor used in GetParallaxOffset() give better quality. - -- So increase the per-layer parallax factors by normalizing them, and reduce the main factor accordingly. if(enableParallax) then local factorLayer1 = context:GetMaterialPropertyValue_float("layer1_parallax.factor") local factorLayer2 = context:GetMaterialPropertyValue_float("layer2_parallax.factor") local factorLayer3 = context:GetMaterialPropertyValue_float("layer3_parallax.factor") - local mainFactor = context:GetMaterialPropertyValue_float("parallax.factor") - maxLayerFactor = 0.0 - if(enable1) then maxLayerFactor = math.max(maxLayerFactor, factorLayer1) end - if(enable2) then maxLayerFactor = math.max(maxLayerFactor, factorLayer2) end - if(enable3) then maxLayerFactor = math.max(maxLayerFactor, factorLayer3) end + local offsetLayer1 = context:GetMaterialPropertyValue_float("layer1_parallax.offset") + local offsetLayer2 = context:GetMaterialPropertyValue_float("layer2_parallax.offset") + local offsetLayer3 = context:GetMaterialPropertyValue_float("layer3_parallax.offset") + + local heightMinMax = {nil, nil} + if(enable1) then MergeRange(heightMinMax, offsetLayer1, factorLayer1) end + if(enable2) then MergeRange(heightMinMax, offsetLayer2, factorLayer2) end + if(enable3) then MergeRange(heightMinMax, offsetLayer3, factorLayer3) end - if(maxLayerFactor < 0.0001) then + if(heightMinMax[1] - heightMinMax[0] < 0.0001) then context:SetShaderOptionValue_bool("o_parallax_feature_enabled", false) else - factorLayer1 = factorLayer1 / maxLayerFactor - factorLayer2 = factorLayer2 / maxLayerFactor - factorLayer3 = factorLayer3 / maxLayerFactor - mainFactor = mainFactor * maxLayerFactor; - context:SetShaderConstant_float("m_layer1_m_depthFactor", factorLayer1) - context:SetShaderConstant_float("m_layer2_m_depthFactor", factorLayer2) - context:SetShaderConstant_float("m_layer3_m_depthFactor", factorLayer3) - context:SetShaderConstant_float("m_parallaxMainDepthFactor", mainFactor) + context:SetShaderConstant_float("m_displacementMin", heightMinMax[0]) + context:SetShaderConstant_float("m_displacementMax", heightMinMax[1]) end end end @@ -76,8 +90,8 @@ function ProcessEditor(context) end context:SetMaterialPropertyVisibility("parallax.parallaxUv", visibility) - context:SetMaterialPropertyVisibility("parallax.factor", visibility) context:SetMaterialPropertyVisibility("parallax.algorithm", visibility) context:SetMaterialPropertyVisibility("parallax.quality", visibility) context:SetMaterialPropertyVisibility("parallax.pdo", visibility) + context:SetMaterialPropertyVisibility("parallax.showClipping", visibility) end diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ParallaxPerLayer.lua b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ParallaxPerLayer.lua index a1695e827b..119dfed436 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ParallaxPerLayer.lua +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ParallaxPerLayer.lua @@ -42,7 +42,8 @@ function ProcessEditor(context) if(not enable or textureMap == nil) then visibility = MaterialPropertyVisibility_Hidden end - + context:SetMaterialPropertyVisibility("parallax.factor", visibility) + context:SetMaterialPropertyVisibility("parallax.offset", visibility) context:SetMaterialPropertyVisibility("parallax.invert", visibility) end diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ShaderEnable.lua b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ShaderEnable.lua new file mode 100644 index 0000000000..69df610ab2 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ShaderEnable.lua @@ -0,0 +1,39 @@ +-------------------------------------------------------------------------------------- +-- +-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +-- its licensors. +-- +-- For complete copyright and license terms please see the LICENSE at the root of this +-- distribution (the "License"). All use of this software is governed by the License, +-- or, if provided, by the license below or the license accompanying this file. Do not +-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- +-- +---------------------------------------------------------------------------------------------------- + +function GetMaterialPropertyDependencies() + return {"parallax.enable", "parallax.pdo"} +end + +function Process(context) + local parallaxEnabled = context:GetMaterialPropertyValue_bool("parallax.enable") + local parallaxPdoEnabled = context:GetMaterialPropertyValue_bool("parallax.pdo") + + local depthPass = context:GetShaderByTag("DepthPass") + local shadowMap = context:GetShaderByTag("Shadowmap") + local forwardPassEDS = context:GetShaderByTag("ForwardPass_EDS") + local depthPassWithPS = context:GetShaderByTag("DepthPass_WithPS") + local shadowMapWitPS = context:GetShaderByTag("Shadowmap_WithPS") + local forwardPass = context:GetShaderByTag("ForwardPass") + + local shadingAffectsDepth = parallaxEnabled and parallaxPdoEnabled; + + depthPass:SetEnabled(not shadingAffectsDepth) + shadowMap:SetEnabled(not shadingAffectsDepth) + forwardPassEDS:SetEnabled(not shadingAffectsDepth) + + depthPassWithPS:SetEnabled(shadingAffectsDepth) + shadowMapWitPS:SetEnabled(shadingAffectsDepth) + forwardPass:SetEnabled(shadingAffectsDepth) +end diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl index 1274e07f7d..325937b228 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl @@ -12,12 +12,10 @@ #include #include -#include #include #include #include -#include "MaterialInputs/AlphaInput.azsli" #include "MaterialInputs/ParallaxInput.azsli" #include "MaterialInputs/ParallaxInput.azsli" @@ -71,7 +69,7 @@ VertexOutput MainVS(VertexInput IN) OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { OUT.m_worldPosition = worldPosition.xyz; @@ -100,18 +98,9 @@ PSDepthOutput MainPS(VertexOutput IN, bool isFrontFace : SV_IsFrontFace) { PSDepthOutput OUT; - // Alpha - float2 layer1_baseColorUV = IN.m_uv[MaterialSrg::m_layer1_m_baseColorMapUvIndex]; - float2 layer2_baseColorUV = IN.m_uv[MaterialSrg::m_layer2_m_baseColorMapUvIndex]; - float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - // [GFX TODO][ATOM-14589] Figure out how to deal with opacity, instead of just hard-coding to layer1 - float alpha = SampleAlpha(MaterialSrg::m_layer1_m_baseColorMap, MaterialSrg::m_opacityMap, layer1_baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); - - CheckClipping(alpha, MaterialSrg::m_opacityFactor); - OUT.m_depth = IN.m_position.z; - if(o_debugDrawMode == DebugDrawMode::None && o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { // We support two UV streams, but only a single stream of tangent/bitangent. So for UV[1+] we generated the tangent/bitangent in screen-space. float3 tangents[UvSetCount] = { IN.m_tangent.xyz, float3(0, 0, 0) }; @@ -124,13 +113,15 @@ PSDepthOutput MainPS(VertexOutput IN, bool isFrontFace : SV_IsFrontFace) float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - - GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_parallaxMainDepthFactor, + + float parallaxOverallOffset = MaterialSrg::m_displacementMax; + float parallaxOverallFactor = MaterialSrg::m_displacementMax - MaterialSrg::m_displacementMin; + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], parallaxOverallFactor, parallaxOverallOffset, ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth); OUT.m_depth = depth; } - + return OUT; } diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype index e071a793a5..a74ceb1783 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype @@ -910,8 +910,8 @@ }, { "id": "factor", - "displayName": "Factor", - "description": "Strength factor for scaling the depth values", + "displayName": "Heightmap Scale", + "description": "The total height of the heightmap in local model units.", "type": "Float", "defaultValue": 0.0, "min": 0.0, @@ -921,6 +921,19 @@ "id": "m_depthFactor" } }, + { + "id": "offset", + "displayName": "Offset", + "description": "Adjusts the overall displacement amount in local model units.", + "type": "Float", + "defaultValue": 0.0, + "softMin": -0.1, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "id": "m_depthOffset" + } + }, { "id": "invert", "displayName": "Invert", @@ -966,6 +979,17 @@ "type": "ShaderOption", "id": "o_parallax_enablePixelDepthOffset" } + }, + { + "id": "showClipping", + "displayName": "Show Clipping", + "description": "Highlight areas where the heightmap is clipped by the mesh surface.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderOption", + "id": "o_parallax_highlightClipping" + } } ], "subsurfaceScattering": [ diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli index 1a7e039da3..5723a6cd1e 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "MaterialInputs/BaseColorInput.azsli" #include "MaterialInputs/RoughnessInput.azsli" @@ -93,8 +95,23 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial } // Callback function for ParallaxMapping.azsli -float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) +DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) { return SampleDepthOrHeightMap(MaterialSrg::m_depthInverted, MaterialSrg::m_depthMap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy); } + +COMMON_OPTIONS_PARALLAX() + +bool ShouldHandleParallax() +{ + // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled. + return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useDepthMap; +} + +bool ShouldHandleParallaxInDepthShaders() +{ + // The depth pass shaders need to calculate parallax when the result could affect the depth buffer, or when + // parallax could affect texel clipping. + return ShouldHandleParallax() && (o_parallax_enablePixelDepthOffset || o_opacity_mode == OpacityMode::Cutout); +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl index 4d4f7b195a..28708c12d5 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl @@ -10,7 +10,6 @@ * */ -#include #include "./StandardPBR_Common.azsli" #include #include @@ -56,7 +55,7 @@ VSDepthOutput MainVS(VSInput IN) OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { OUT.m_worldPosition = worldPosition.xyz; @@ -75,46 +74,29 @@ PSDepthOutput MainPS(VSDepthOutput IN, bool isFrontFace : SV_IsFrontFace) { PSDepthOutput OUT; - // Alpha - float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; - float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); - - CheckClipping(alpha, MaterialSrg::m_opacityFactor); - OUT.m_depth = IN.m_position.z; - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { // We support two UV streams, but only a single stream of tangent/bitangent. So for UV[1+] we generated the tangent/bitangent in screen-space. float3 tangents[UvSetCount] = { IN.m_tangent.xyz, float3(0, 0, 0) }; float3 bitangents[UvSetCount] = { IN.m_bitangent.xyz, float3(0, 0, 0) }; PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents, 1); - - float3 tangent = tangents[MaterialSrg::m_parallaxUvIndex]; - float3 bitangent = bitangents[MaterialSrg::m_parallaxUvIndex]; - + float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); + + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset, + ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth); + } + + // Alpha + float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; + float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; + float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); - float3 tangentOffset = GetParallaxOffset( MaterialSrg::m_depthFactor, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], - ViewSrg::m_worldPosition.xyz - IN.m_worldPosition, - tangent, - bitangent, - IN.m_normal, - uvMatrix); + CheckClipping(alpha, MaterialSrg::m_opacityFactor); - PixelDepthOffset pdo = CalcPixelDepthOffset(MaterialSrg::m_depthFactor, - tangentOffset, - IN.m_worldPosition, - tangent, - bitangent, - IN.m_normal, - uvMatrixInverse, - ObjectSrg::GetWorldMatrix(), - ViewSrg::m_viewProjectionMatrix); - OUT.m_depth = pdo.m_depth; - } return OUT; } diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl index d3bc72d162..22751b49bc 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl @@ -40,7 +40,7 @@ COMMON_OPTIONS_NORMAL() COMMON_OPTIONS_CLEAR_COAT() COMMON_OPTIONS_OCCLUSION() COMMON_OPTIONS_EMISSIVE() -COMMON_OPTIONS_PARALLAX() +// Note COMMON_OPTIONS_PARALLAX is in StandardPBR_Common.azsli because it's needed by all StandardPBR shaders. // Alpha #include "MaterialInputs/AlphaInput.azsli" @@ -94,7 +94,10 @@ VSOutput StandardPbr_ForwardPassVS(VSInput IN) OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - VertexHelper(IN, OUT, worldPosition, o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset); + // Shadow coords will be calculated in the pixel shader in this case + bool skipShadowCoords = ShouldHandleParallax() && o_parallax_enablePixelDepthOffset; + + VertexHelper(IN, OUT, worldPosition, skipShadowCoords); return OUT; } @@ -123,15 +126,18 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // ------- Depth & Parallax ------- depth = IN.m_position.z; + + bool displacementIsClipped = false; // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scatteirng is enabled - if(!o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useDepthMap) + if(ShouldHandleParallax()) { + float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset, ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth); + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth, displacementIsClipped); // Adjust directional light shadow coorinates for parallax correction if(o_parallax_enablePixelDepthOffset) @@ -166,6 +172,11 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float3 sampledColor = GetBaseColorInput(MaterialSrg::m_baseColorMap, MaterialSrg::m_sampler, baseColorUv, MaterialSrg::m_baseColor.rgb, o_baseColor_useTexture); float3 baseColor = BlendBaseColor(sampledColor, MaterialSrg::m_baseColor.rgb, MaterialSrg::m_baseColorFactor, o_baseColorTextureBlendMode, o_baseColor_useTexture); + if(o_parallax_highlightClipping && displacementIsClipped) + { + ApplyParallaxClippingHighlight(baseColor); + } + // ------- Metallic ------- float metallic = 0; diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ParallaxState.lua b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ParallaxState.lua index bf1b59616a..0287e1105e 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ParallaxState.lua +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ParallaxState.lua @@ -41,8 +41,10 @@ function ProcessEditor(context) if(not enable or textureMap == nil) then visibility = MaterialPropertyVisibility_Hidden end - + context:SetMaterialPropertyVisibility("parallax.factor", visibility) + context:SetMaterialPropertyVisibility("parallax.offset", visibility) + context:SetMaterialPropertyVisibility("parallax.showClipping", visibility) context:SetMaterialPropertyVisibility("parallax.invert", visibility) context:SetMaterialPropertyVisibility("parallax.algorithm", visibility) context:SetMaterialPropertyVisibility("parallax.quality", visibility) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl index e792c25778..7f24b29700 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl @@ -12,7 +12,6 @@ #include #include "StandardPBR_Common.azsli" -#include #include #include #include @@ -56,7 +55,7 @@ VertexOutput MainVS(VertexInput IN) OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { OUT.m_worldPosition = worldPosition.xyz; @@ -76,28 +75,9 @@ PSDepthOutput MainPS(VertexOutput IN, bool isFrontFace : SV_IsFrontFace) { PSDepthOutput OUT; - // Alpha - float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; - float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); - - CheckClipping(alpha, MaterialSrg::m_opacityFactor); - OUT.m_depth = IN.m_position.z; - float3 dirToCamera; - if(ViewSrg::m_projectionMatrix[0].w) - { - // orthographic projection (directional light) - // No view position, use light direction - dirToCamera = ViewSrg::m_viewMatrix[2].xyz; - } - else - { - dirToCamera = ViewSrg::m_worldPosition.xyz - IN.m_worldPosition; - } - - if(o_parallax_feature_enabled && o_parallax_enablePixelDepthOffset) + if(ShouldHandleParallaxInDepthShaders()) { static const float ShadowMapDepthBias = 0.000001; @@ -106,31 +86,22 @@ PSDepthOutput MainPS(VertexOutput IN, bool isFrontFace : SV_IsFrontFace) float3 bitangents[UvSetCount] = { IN.m_bitangent.xyz, float3(0, 0, 0) }; PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents, 1); - float3 tangent = tangents[MaterialSrg::m_parallaxUvIndex]; - float3 bitangent = bitangents[MaterialSrg::m_parallaxUvIndex]; - float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - float3 tangentOffset = GetParallaxOffset( MaterialSrg::m_depthFactor, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], - dirToCamera, - tangent, - bitangent, - IN.m_normal, - uvMatrix); - - PixelDepthOffset pdo = CalcPixelDepthOffset(MaterialSrg::m_depthFactor, - tangentOffset, - IN.m_worldPosition, - tangent, - bitangent, - IN.m_normal, - uvMatrixInverse, - ObjectSrg::GetWorldMatrix(), - ViewSrg::m_viewProjectionMatrix); - - OUT.m_depth = pdo.m_depth + ShadowMapDepthBias; + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, MaterialSrg::m_depthOffset, + ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, OUT.m_depth); + + OUT.m_depth += ShadowMapDepthBias; } + + // Alpha + float2 baseColorUV = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; + float2 opacityUV = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; + float alpha = SampleAlpha(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUV, opacityUV, MaterialSrg::m_sampler, o_opacity_source); + + CheckClipping(alpha, MaterialSrg::m_opacityFactor); + return OUT; } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ParallaxMapping.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ParallaxMapping.azsli index 8a6b5c479a..1d2beb0f10 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ParallaxMapping.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ParallaxMapping.azsli @@ -18,39 +18,147 @@ option bool o_parallax_enablePixelDepthOffset; option enum class ParallaxAlgorithm {Basic, Steep, POM, Relief, Contact} o_parallax_algorithm; option enum class ParallaxQuality {Low, Medium, High, Ultra} o_parallax_quality; + +option bool o_parallax_feature_enabled; +option bool o_parallax_highlightClipping; option bool o_parallax_shadow; +// I tried to make this an enum class, but ran into some DXC bug when compiling to SPIRV. +enum DepthResultCode +{ + DepthResultCode_Invalid, + DepthResultCode_Normalized, //!< The result is in range [0,1], where 0 is the top of the heightmap and 1 is the bottom of the heightmap. + DepthResultCode_Absolute //!< The result is tangent space units (the same as world units if there's no mesh scaling), where 0 is at the mesh surface and positive values are below the surface. +}; + +//! The return value for the GetDepth() callback function below. +struct DepthResult +{ + DepthResultCode m_resultCode; + float m_depth; +}; + +//! Convenience function for making a DepthResult with Code::Normalized +DepthResult DepthResultNormalized(float depth) +{ + DepthResult result; + result.m_resultCode = DepthResultCode_Normalized; + result.m_depth = depth; + return result; +} + +//! Convenience function for making a DepthResult with Code::Absolute +DepthResult DepthResultAbsolute(float depth) +{ + DepthResult result; + result.m_resultCode = DepthResultCode_Absolute; + result.m_depth = depth; + return result; +} + //! The client shader must define this function. //! This allows the client shader to implement special depth map sampling, for example procedurally generating or blending depth maps. +//! In simple cases though, the implementation of GetDepth() can simply call SampleDepthOrHeightMap(). //! @param uv the UV coordinates to use for sampling //! @param uv_ddx will be set to ddx_fine(uv) //! @param uv_ddy will be set to ddy_fine(uv) -float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy); +//! @return see struct DepthResult +DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy); //! Convenience function that can be used to implement GetDepth(). //! @param isHeightmap indicates whether to sample the map is a height map rather than a depth map. -float SampleDepthOrHeightMap(bool isHeightmap, Texture2D map, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy) +//! @return see struct DepthResult. In this case it will always contain a Code::Normalized result. +DepthResult SampleDepthOrHeightMap(bool isHeightmap, Texture2D map, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy) { - return abs((isHeightmap * 1.0) - map.SampleGrad(mapSampler, uv, uv_ddx, uv_ddy).r); + DepthResult result; + result.m_resultCode = DepthResultCode_Normalized; + result.m_depth = abs((isHeightmap * 1.0) - map.SampleGrad(mapSampler, uv, uv_ddx, uv_ddy).r); + return result; } +//! Calls GetDepth() and then normalizes the result if it isn't normalized already. +//! @param startDepth is the high point, which corresponds to a normalized depth value of 0. +//! @param stopDepth is the low point, which corresponds to a normalized depth value of 1. +//! @param inverseDepthRange is an optimization, and must be set to "1.0 / (stopDepth - startDepth)". +//! @param uv the UV coordinates to use for sampling +//! @param uv_ddx must be set to ddx_fine(uv) +//! @param uv_ddy must be set to ddy_fine(uv) +//! @param a depth value in the range [0,1] +float GetNormalizedDepth(float startDepth, float stopDepth, float inverseDepthRange, float2 uv, float2 uv_ddx, float2 uv_ddy) +{ + // startDepth can be less than 0, representing a displacement above the mesh surface. + // But since we don't currently support any vertex displacement, negative depth values would cause various + // problems especially when PDO is enabled, like parallax surfaces clipping through foreground geometry, and parallax + // surfaces disappearing at low angles. So we clamp all depth values to a minimum of 0. + + float normalizedDepth = 0.0; + + DepthResult depthResult = GetDepth(uv, uv_ddx, uv_ddy); + + if(stopDepth - startDepth > 0.0001) + { + if(DepthResultCode_Normalized == depthResult.m_resultCode) + { + float minNormalizedDepth = -startDepth * inverseDepthRange; + normalizedDepth = max(depthResult.m_depth, minNormalizedDepth); + } + else if(DepthResultCode_Absolute == depthResult.m_resultCode) + { + float clampedAbsoluteDepth = max(depthResult.m_depth, 0.0); + normalizedDepth = (clampedAbsoluteDepth - startDepth) * inverseDepthRange; + } + } + + return normalizedDepth; +} + +float GetNormalizedDepth(float startDepth, float stopDepth, float2 uv, float2 uv_ddx, float2 uv_ddy) +{ + float inverseDepthRange = 1.0 / (stopDepth - startDepth); + return GetNormalizedDepth(startDepth, stopDepth, inverseDepthRange, uv, uv_ddx, uv_ddy); +} + +void ApplyParallaxClippingHighlight(inout float3 baseColor) +{ + baseColor = lerp(baseColor, float3(1.0, 0.0, 1.0), 0.5); +} + +struct ParallaxOffset +{ + float3 m_offsetTS; //!< represents the intersection point relative to the geometry surface, in tangent space. + bool m_isClipped; //!< Indicates whether the result is being clipped by the geometry surface, mainly for debug rendering. Only set when o_parallax_highlightClipping is true. +}; + // dirToCameraTS should be in tangent space and normalized // From Reat-Time Rendering 3rd edition, p.192 -float3 BasicParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraTS) +ParallaxOffset BasicParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraTS) { // the amount to shift - float2 delta = dirToCameraTS.xy * GetDepth(uv, ddx_fine(uv), ddy_fine(uv)) * depthFactor; + float2 delta = dirToCameraTS.xy * GetNormalizedDepth(0, depthFactor, uv, ddx_fine(uv), ddy_fine(uv)) * depthFactor; - float3 offset = float3(0,0,0); - offset.xy -= delta; - return offset; + ParallaxOffset result; + + result.m_offsetTS = float3(0,0,0); + result.m_offsetTS.xy -= delta; + result.m_isClipped = false; + return result; } -// dirToCameraTS and dirToLightTS should be in tangent space and normalized -// Adapt from CryEngine shader shadelib.cfi and POM function in https://github.com/a-riccardi/shader-toy +// Performs ray intersection against a surface with a heightmap. +// Adapted from CryEngine shader shadelib.cfi and POM function in https://github.com/a-riccardi/shader-toy // check https://github.com/UPBGE/blender/issues/1009 for more details. -float3 AdvancedParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, int numSteps, inout float parallaxShadowAttenuation) +// @param depthFactor - scales the heightmap in tangent space units (which normally ends up being world units). +// @param depthOffset - offsets the heighmap up or down in tangent space units (which normally ends up being world units). +// @param uv - the UV coordinates on the surface, where the search will begin, used to sample the heightmap. +// @param dirToCameraTS - normalized direction to the camera, in tangent space. +// @param dirToLightTS - normalized direction to a light source, in tangent space, for self-shadowing (if enabled via o_parallax_shadow). +// @param numSteps - the number of steps to take when marching along the ray searching for intersection. +// @param parallaxShadowAttenuation - returns a factor for attenuating a light source, for self-shadowing (if enabled via o_parallax_shadow). +ParallaxOffset AdvancedParallaxMapping(float depthFactor, float depthOffset, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, int numSteps, inout float parallaxShadowAttenuation) { + ParallaxOffset result; + result.m_isClipped = false; + float dirToCameraZInverse = 1.0 / dirToCameraTS.z; float step = 1.0 / numSteps; float currentStep = 0.0; @@ -61,21 +169,38 @@ float3 AdvancedParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraT float2 ddx_uv = ddx_fine(uv); float2 ddy_uv = ddy_fine(uv); - float currentSample = GetDepth(uv, ddx_uv, ddy_uv); + float depthSearchStart = -depthOffset; + float depthSearchEnd = depthSearchStart + depthFactor; + + float inverseDepthFactor = 1.0 / depthFactor; + + // This is the relative position at which we begin searching for intersection. + // It is adjusted according to the depthOffset, raising or lowering the whole surface by depthOffset units. + float3 parallaxOffset = dirToCameraTS.xyz * dirToCameraZInverse * depthOffset; + + // Get an initial heightmap sample to start the intersection search, starting at our initial parallaxOffset position. + float currentSample = GetNormalizedDepth(depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv); float prevSample; - float3 parallaxOffset = float3(0,0,0); + + // Note that when depthOffset < 0, we could actually narrow the search so that instead of going through the entire [depthSearchStart,depthSearchEnd] range + // of the heightmap, we could go through the range [0,depthSearchEnd]. This would give more accurate results and fewer artifacts + // in case where the magnitude of depthOffset is significant. But for the sake of simplicity we currently search the whole range in all cases. - // find the intersect step + // Do a basic search for the intersect step while(currentSample > currentStep) { currentStep += step; parallaxOffset += delta; + prevSample = currentSample; - currentSample = GetDepth(uv + parallaxOffset.xy, ddx_uv, ddy_uv); + currentSample = GetNormalizedDepth(depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv); } + // Depending on the algorithm, we refine the result of the above search switch(o_parallax_algorithm) { + case ParallaxAlgorithm::Steep: + break; // This algorithm just relies on the course intersection test loop above case ParallaxAlgorithm::POM: { if(currentStep > 0.0) @@ -108,7 +233,7 @@ float3 AdvancedParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraT parallaxOffset += reliefDelta * depthSign; currentStep += reliefStep * depthSign; - currentSample = GetDepth(uv + parallaxOffset.xy, ddx_uv, ddy_uv); + currentSample = GetNormalizedDepth(depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv); } } break; @@ -136,7 +261,7 @@ float3 AdvancedParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraT parallaxOffset += adjustedDelta; prevSample = currentSample; - currentSample = GetDepth(uv + parallaxOffset.xy, ddx_uv, ddy_uv); + currentSample = GetNormalizedDepth(depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv); } } break; @@ -144,6 +269,30 @@ float3 AdvancedParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraT default: break; } + + // Even though we do a bunch of clamping above when calling GetClampedDepth(), there are still cases where the parallax offset + // can be noticeably above the surface and still needs to be clamped here. The main case is when depthFactor==0 and depthOffset>1. + if(parallaxOffset.z > 0.0) + { + parallaxOffset = float3(0,0,0); + } + + if (o_parallax_highlightClipping) + { + // The most accurate way to report clipping is to sample the heightmap one last time at the final adjusted UV. + // (trying to do it based on parallaxOffset.z values just leads to too many edge cases) + + DepthResult depthResult = GetDepth(uv + parallaxOffset.xy, ddx_uv, ddy_uv); + + if(DepthResultCode_Normalized == depthResult.m_resultCode) + { + result.m_isClipped = lerp(depthSearchStart, depthSearchEnd, depthResult.m_depth) < 0; + } + else if(DepthResultCode_Absolute == depthResult.m_resultCode) + { + result.m_isClipped = depthResult.m_depth < 0.0; + } + } if(o_parallax_shadow && any(dirToLightTS)) { @@ -168,7 +317,7 @@ float3 AdvancedParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraT } shadowUV += shadowDelta; - currentSample = GetDepth(shadowUV, ddx_uv, ddy_uv); + currentSample = GetNormalizedDepth(depthSearchStart, depthSearchEnd, inverseDepthFactor, shadowUV, ddx_uv, ddy_uv); currentStep -= step; } @@ -181,12 +330,13 @@ float3 AdvancedParallaxMapping(float depthFactor, float2 uv, float3 dirToCameraT parallaxShadowAttenuation = 1; } } - - return parallaxOffset; + + result.m_offsetTS = parallaxOffset; + return result; } // return offset in tangent space -float3 CalculateParallaxOffset(float depthFactor, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, inout float parallaxShadowAttenuation) +ParallaxOffset CalculateParallaxOffset(float depthFactor, float depthOffset, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, inout float parallaxShadowAttenuation) { if(o_parallax_algorithm == ParallaxAlgorithm::Basic) { @@ -194,27 +344,34 @@ float3 CalculateParallaxOffset(float depthFactor, float2 uv, float3 dirToCameraT } else { - float3 parallaxOffset; + ParallaxOffset parallaxOffset; switch(o_parallax_quality) { case ParallaxQuality::Low: - parallaxOffset = AdvancedParallaxMapping(depthFactor, uv, dirToCameraTS, dirToLightTS, 16, parallaxShadowAttenuation); + parallaxOffset = AdvancedParallaxMapping(depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 16, parallaxShadowAttenuation); break; case ParallaxQuality::Medium: - parallaxOffset = AdvancedParallaxMapping(depthFactor, uv, dirToCameraTS, dirToLightTS, 32, parallaxShadowAttenuation); + parallaxOffset = AdvancedParallaxMapping(depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 32, parallaxShadowAttenuation); break; case ParallaxQuality::High: - parallaxOffset = AdvancedParallaxMapping(depthFactor, uv, dirToCameraTS, dirToLightTS, 64, parallaxShadowAttenuation); + parallaxOffset = AdvancedParallaxMapping(depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 64, parallaxShadowAttenuation); break; case ParallaxQuality::Ultra: - parallaxOffset = AdvancedParallaxMapping(depthFactor, uv, dirToCameraTS, dirToLightTS, 128, parallaxShadowAttenuation); + parallaxOffset = AdvancedParallaxMapping(depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 128, parallaxShadowAttenuation); break; } return parallaxOffset; } } -float3 GetParallaxOffset( float depthFactor, +// Performs ray intersection against a surface with a heightmap, to determine an offset amount required for a parallax effect. +// @param depthFactor - scales the heightmap in tangent space units (which normally ends up being world units). +// @param depthOffset - offsets the heighmap up or down in tangent space units (which normally ends up being world units). +// @param uv - the UV coordinates on the surface, where the search will begin, used to sample the heightmap. +// @param dirToCameraTS - normalized direction to the camera, in tangent space. +// @param dirToLightTS - normalized direction to a light source, in tangent space, for self-shadowing (if enabled via o_parallax_shadow). +ParallaxOffset GetParallaxOffset( float depthFactor, + float depthOffset, float2 uv, float3 dirToCameraWS, float3 tangentWS, @@ -236,7 +393,7 @@ float3 GetParallaxOffset( float depthFactor, float4 dirToCameraTransformed = mul(uv3DTransform, float4(dirToCameraTS, 0.0)); float dummy = 1; - return CalculateParallaxOffset(depthFactor, uv, normalize(dirToCameraTransformed.xyz), float3(0,0,0), dummy); + return CalculateParallaxOffset(depthFactor, depthOffset, uv, normalize(dirToCameraTransformed.xyz), float3(0,0,0), dummy); } struct PixelDepthOffset diff --git a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrg.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/RayTracing/RayTracingSceneSrg.azsli similarity index 96% rename from Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrg.azsli rename to Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/RayTracing/RayTracingSceneSrg.azsli index 0aeb43bcf2..a7bb6cd3b1 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrg.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/RayTracing/RayTracingSceneSrg.azsli @@ -10,11 +10,9 @@ * */ -#ifndef AZ_COLLECTING_PARTIAL_SRGS -#error Do not include this file directly. Include the main .srgi file instead. -#endif +#include -partial ShaderResourceGroup RayTracingSceneSrg +ShaderResourceGroup RayTracingSceneSrg : SRG_RayTracingScene { RaytracingAccelerationStructure m_scene; @@ -150,6 +148,4 @@ partial ShaderResourceGroup RayTracingSceneSrg #define MESH_NORMAL_BUFFER_OFFSET 2 ByteAddressBuffer m_meshBuffers[]; -} - - +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrgAll.azsli b/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrgAll.azsli deleted file mode 100644 index b1b2bea750..0000000000 --- a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrgAll.azsli +++ /dev/null @@ -1,19 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -// Please review README.md to understand how this file is used in RayTracingSceneSrg.azsrg generation - -#ifdef AZ_COLLECTING_PARTIAL_SRGS -#include -#endif diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader index a781a598ba..804b534277 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant index e9f841047e..b3bee56bfd 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant index e399dbcef0..d9b2f17848 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant index 1580aa2477..cf39160d3f 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader index bfed840feb..c4a83a26dc 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant index ee2031bf1a..fb5b740f04 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant index 3b37084adf..b7bdabeb4e 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant index e2f5a8cb50..1eeeffa8be 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingcommon_raytracingglobalsrg.azsrg b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingcommon_raytracingglobalsrg.azsrg index 930d34171e..c9fa0f4e1c 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingcommon_raytracingglobalsrg.azsrg +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingcommon_raytracingglobalsrg.azsrg @@ -9904,4 +9904,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader index 84e773d9db..4f0cea1bfe 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant index b288bb7647..839efa7278 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant index 0f2473b606..5f08825487 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant index bfd979e588..a5b0e842ef 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SsaoCompute.azsl b/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SsaoCompute.azsl index c1fa41991e..8294911b44 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SsaoCompute.azsl +++ b/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SsaoCompute.azsl @@ -277,6 +277,8 @@ void MainCS(uint3 thread_id : SV_GroupThreadID, uint3 group_id : SV_GroupID, uin // Gather depth values float2 depthGatherUV = mad(float2(ldsPosition), GetPixelSize(), ldsOffsetUV); + // Gather on some GPUs will fall onto same pixels in adjacent coordinates due to rounding errors + depthGatherUV += GetHalfPixelSize(); float4 depthGather = PassSrg::m_linearDepth.Gather(PassSrg::PointSampler, depthGatherUV); WriteDepthGatherToLDS(ldsPosition, depthGather); diff --git a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake index f14fb4f4a0..84ef494216 100644 --- a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake +++ b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake @@ -280,8 +280,6 @@ set(FILES ShaderLib/Atom/Features/Shadow/Shadow.azsli ShaderLib/Atom/Features/Shadow/ShadowmapAtlasLib.azsli ShaderLib/Atom/Features/Vertex/VertexHelper.azsli - ShaderResourceGroups/RayTracingSceneSrg.azsli - ShaderResourceGroups/RayTracingSceneSrgAll.azsli ShaderResourceGroups/SceneSrg.azsli ShaderResourceGroups/SceneSrgAll.azsli ShaderResourceGroups/SceneTimeSrg.azsli diff --git a/Gems/Atom/Feature/Common/Code/CMakeLists.txt b/Gems/Atom/Feature/Common/Code/CMakeLists.txt index 93da352c6e..6f087edefe 100644 --- a/Gems/Atom/Feature/Common/Code/CMakeLists.txt +++ b/Gems/Atom/Feature/Common/Code/CMakeLists.txt @@ -30,7 +30,6 @@ ly_add_target( PUBLIC Include Source - 3rdParty/ACES COMPILE_DEFINITIONS PRIVATE IMGUI_DISABLE_OBSOLETE_FUNCTIONS @@ -58,6 +57,7 @@ ly_add_target( ${pal_source_dir} PUBLIC Include + 3rdParty/ACES COMPILE_DEFINITIONS PRIVATE IMGUI_DISABLE_OBSOLETE_FUNCTIONS diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Decals/DecalFeatureProcessorInterface.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Decals/DecalFeatureProcessorInterface.h index 214feb2040..a7aebf5aa4 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Decals/DecalFeatureProcessorInterface.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Decals/DecalFeatureProcessorInterface.h @@ -88,7 +88,10 @@ namespace AZ //! Sets the transform of the decal //! Equivalent to calling SetDecalPosition() + SetDecalOrientation() + SetDecalHalfSize() + //! @{ virtual void SetDecalTransform(DecalHandle handle, const AZ::Transform& world) = 0; + virtual void SetDecalTransform(DecalHandle handle, const AZ::Transform& world, const AZ::Vector3& nonUniformScale) = 0; + //! @} //! Sets the material information for this decal virtual void SetDecalMaterial(DecalHandle handle, const AZ::Data::AssetId) = 0; diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessor.h index a89875aaa6..ff84f77a3e 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessor.h @@ -36,10 +36,11 @@ namespace AZ void RemoveProbe(ReflectionProbeHandle& probe) override; void SetProbeOuterExtents(const ReflectionProbeHandle& probe, const AZ::Vector3& outerExtents) override; void SetProbeInnerExtents(const ReflectionProbeHandle& probe, const AZ::Vector3& innerExtents) override; - void SetProbeCubeMap(const ReflectionProbeHandle& probe, Data::Instance& cubeMapImage) override; + void SetProbeCubeMap(const ReflectionProbeHandle& probe, Data::Instance& cubeMapImage, const AZStd::string& relativePath) override; void SetProbeTransform(const ReflectionProbeHandle& probe, const AZ::Transform& transform) override; - void BakeProbe(const ReflectionProbeHandle& probe, BuildCubeMapCallback callback) override; - void NotifyCubeMapAssetReady(const AZStd::string relativePath, NotifyCubeMapAssetReadyCallback callback) override; + void BakeProbe(const ReflectionProbeHandle& probe, BuildCubeMapCallback callback, const AZStd::string& relativePath) override; + bool CheckCubeMapAssetNotification(const AZStd::string& relativePath, Data::Asset& outCubeMapAsset, CubeMapAssetNotificationType& outNotificationType) override; + bool IsCubeMapReferenced(const AZStd::string& relativePath) override; bool IsValidProbeHandle(const ReflectionProbeHandle& probe) const override { return (probe.get() != nullptr); } void ShowProbeVisualization(const ReflectionProbeHandle& probe, bool showVisualization) override; @@ -72,10 +73,9 @@ namespace AZ // AssetBus::MultiHandler overrides... void OnAssetReady(Data::Asset asset) override; void OnAssetError(Data::Asset asset) override; - void OnAssetReloaded(Data::Asset asset) override; // notifies and removes the notification entry - void HandleAssetNotification(Data::Asset asset, CubeMapAssetNotificationType notificationTyp); + void HandleAssetNotification(Data::Asset asset, CubeMapAssetNotificationType notificationType); // list of reflection probes const size_t InitialProbeAllocationSize = 64; @@ -86,9 +86,8 @@ namespace AZ { AZStd::string m_relativePath; AZ::Data::AssetId m_assetId; - bool m_existingAsset = false; - NotifyCubeMapAssetReadyCallback m_callback; Data::Asset m_asset; + CubeMapAssetNotificationType m_notificationType = CubeMapAssetNotificationType::None; }; typedef AZStd::vector NotifyCubeMapAssetVector; NotifyCubeMapAssetVector m_notifyCubeMapAssets; diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessorInterface.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessorInterface.h index 8b277e97c8..03c44d0442 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessorInterface.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessorInterface.h @@ -30,11 +30,11 @@ namespace AZ enum CubeMapAssetNotificationType { + None, Ready, Error, Reloaded }; - using NotifyCubeMapAssetReadyCallback = AZStd::function& cubeMapAsset, CubeMapAssetNotificationType notificationType)>; // ReflectionProbeFeatureProcessorInterface provides an interface to the feature processor for code outside of Atom class ReflectionProbeFeatureProcessorInterface @@ -47,10 +47,11 @@ namespace AZ virtual void RemoveProbe(ReflectionProbeHandle& handle) = 0; virtual void SetProbeOuterExtents(const ReflectionProbeHandle& handle, const AZ::Vector3& outerExtents) = 0; virtual void SetProbeInnerExtents(const ReflectionProbeHandle& handle, const AZ::Vector3& innerExtents) = 0; - virtual void SetProbeCubeMap(const ReflectionProbeHandle& handle, Data::Instance& cubeMapImage) = 0; + virtual void SetProbeCubeMap(const ReflectionProbeHandle& handle, Data::Instance& cubeMapImage, const AZStd::string& relativePath) = 0; virtual void SetProbeTransform(const ReflectionProbeHandle& handle, const AZ::Transform& transform) = 0; - virtual void BakeProbe(const ReflectionProbeHandle& handle, BuildCubeMapCallback callback) = 0; - virtual void NotifyCubeMapAssetReady(const AZStd::string relativePath, NotifyCubeMapAssetReadyCallback callback) = 0; + virtual void BakeProbe(const ReflectionProbeHandle& handle, BuildCubeMapCallback callback, const AZStd::string& relativePath) = 0; + virtual bool CheckCubeMapAssetNotification(const AZStd::string& relativePath, Data::Asset& outCubeMapAsset, CubeMapAssetNotificationType& outNotificationType) = 0; + virtual bool IsCubeMapReferenced(const AZStd::string& relativePath) = 0; virtual bool IsValidProbeHandle(const ReflectionProbeHandle& probe) const = 0; virtual void ShowProbeVisualization(const ReflectionProbeHandle& probe, bool showVisualization) = 0; }; diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/LightingPreset.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/LightingPreset.h index f1d8337a35..e79dc6d29e 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/LightingPreset.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/LightingPreset.h @@ -61,13 +61,14 @@ namespace AZ AZ_TYPE_INFO(AZ::Render::LightConfig, "{02644F52-9483-47A8-9028-37671695C34E}"); static void Reflect(AZ::ReflectContext* context); - AZ::Vector3 m_direction = AZ::Vector3::CreateAxisY(); + // Setting default direction to produce a visible shadow + AZ::Vector3 m_direction = AZ::Vector3(1.0f / 3.0f, 1.0f / 3.0f, -1.0f / 3.0f); AZ::Color m_color = AZ::Color::CreateOne(); float m_intensity = 1.0f; - uint16_t m_shadowCascadeCount = 1; - float m_shadowRatioLogarithmUniform = 0.5f; + uint16_t m_shadowCascadeCount = 4; + float m_shadowRatioLogarithmUniform = 1.0f; float m_shadowFarClipDistance = 20.0f; - ShadowmapSize m_shadowmapSize = ShadowmapSize::Size1024; + ShadowmapSize m_shadowmapSize = ShadowmapSize::Size2048; bool m_enableShadowDebugColoring = false; }; diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.cpp index 7abc6698fa..55fa633e5d 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.cpp @@ -264,7 +264,12 @@ namespace AZ void DecalFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world) { - // https://jira.agscollab.com/browse/ATOM-4330 + SetDecalTransform(handle, world, AZ::Vector3::CreateOne()); + } + + void DecalFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world, const AZ::Vector3& nonUniformScale) + { + // ATOM-4330 // Original Open 3D Engine uploads a 4x4 matrix rather than quaternion, rotation, scale. // That is more memory but less calculation because it is doing a matrix inverse rather than a polar decomposition // I've done some experiments and uploading a 3x4 transform matrix with 3x3 matrix inverse should be possible @@ -274,7 +279,7 @@ namespace AZ if (handle.IsValid()) { Quaternion orientation = world.GetRotation(); - Vector3 scale = world.GetScale(); + Vector3 scale = world.GetScale() * nonUniformScale; SetDecalHalfSize(handle, scale); SetDecalPosition(handle, world.GetTranslation()); diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.h index 9c4acf6322..3b99715d5a 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalFeatureProcessor.h @@ -73,7 +73,10 @@ namespace AZ //! Sets the transform of the decal //! Equivalent to calling SetDecalPosition() + SetDecalOrientation() + SetDecalHalfSize() + //! @{ void SetDecalTransform(DecalHandle handle, const AZ::Transform& world) override; + void SetDecalTransform(DecalHandle handle, const AZ::Transform& world, const AZ::Vector3& nonUniformScale) override; + //! @} //! Sets the material information for this decal void SetDecalMaterial(DecalHandle handle, const AZ::Data::AssetId) override; diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp index 9d1ea4e680..4000df646d 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp @@ -270,10 +270,16 @@ namespace AZ } void DecalTextureArrayFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world) + { + SetDecalTransform(handle, world, AZ::Vector3::CreateOne()); + } + + void DecalTextureArrayFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world, + const AZ::Vector3& nonUniformScale) { if (handle.IsValid()) { - SetDecalHalfSize(handle, world.GetScale()); + SetDecalHalfSize(handle, nonUniformScale * world.GetScale()); SetDecalPosition(handle, world.GetTranslation()); SetDecalOrientation(handle, world.GetRotation()); diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h index 7ab073c7f9..825e461fc2 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h @@ -82,7 +82,10 @@ namespace AZ //! Sets the transform of the decal //! Equivalent to calling SetDecalPosition() + SetDecalOrientation() + SetDecalHalfSize() + //! @{ void SetDecalTransform(const DecalHandle handle, const AZ::Transform& world) override; + void SetDecalTransform(const DecalHandle handle, const AZ::Transform& world, const AZ::Vector3& nonUniformScale) override; + //! @} //! Sets the material information for this decal void SetDecalMaterial(const DecalHandle handle, const AZ::Data::AssetId id) override; diff --git a/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp index 0c24c2953d..c4e9306dc9 100644 --- a/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/RayTracing/RayTracingFeatureProcessor.cpp @@ -67,7 +67,7 @@ namespace AZ // load the RayTracingSceneSrg asset Data::Asset rayTracingSceneSrgAsset = - RPI::AssetUtils::LoadAssetByProductPath("shaderlib/raytracingscenesrg_raytracingscenesrg.azsrg", RPI::AssetUtils::TraceLevel::Error); + RPI::AssetUtils::LoadAssetByProductPath("shaderlib/atom/features/raytracing/raytracingscenesrg_raytracingscenesrg.azsrg", RPI::AssetUtils::TraceLevel::Error); AZ_Assert(rayTracingSceneSrgAsset.IsReady(), "Failed to load RayTracingSceneSrg asset"); m_rayTracingSceneSrg = RPI::ShaderResourceGroup::Create(rayTracingSceneSrgAsset); diff --git a/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.cpp b/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.cpp index 0826739119..e0b79e23aa 100644 --- a/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.cpp @@ -120,13 +120,13 @@ namespace AZ { // stencil Srg // Note: the stencil pass uses a slightly reduced inner AABB to avoid seams - Vector3 innerExtentsReduced = m_innerExtents - Vector3(0.1f, 0.1f, 0.1f); - Matrix3x4 modelToWorldStencil = Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_position) * Matrix3x4::CreateScale(innerExtentsReduced); + Vector3 innerExtentsReduced = m_innerExtents * m_transform.GetScale() - Vector3(0.1f, 0.1f, 0.1f); + Matrix3x4 modelToWorldStencil = Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_transform.GetTranslation()) * Matrix3x4::CreateScale(innerExtentsReduced); m_stencilSrg->SetConstant(m_reflectionRenderData->m_modelToWorldStencilConstantIndex, modelToWorldStencil); m_stencilSrg->Compile(); // blend weight Srg - Matrix3x4 modelToWorldOuter = Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_position) * Matrix3x4::CreateScale(m_outerExtents); + Matrix3x4 modelToWorldOuter = Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_transform.GetTranslation()) * Matrix3x4::CreateScale(m_outerExtents * m_transform.GetScale()); m_blendWeightSrg->SetConstant(m_reflectionRenderData->m_modelToWorldRenderConstantIndex, modelToWorldOuter); m_blendWeightSrg->SetConstant(m_reflectionRenderData->m_aabbPosRenderConstantIndex, m_outerAabbWs.GetCenter()); m_blendWeightSrg->SetConstant(m_reflectionRenderData->m_outerAabbMinRenderConstantIndex, m_outerAabbWs.GetMin()); @@ -149,7 +149,7 @@ namespace AZ m_renderOuterSrg->Compile(); // render inner Srg - Matrix3x4 modelToWorldInner = Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_position) * Matrix3x4::CreateScale(m_innerExtents); + Matrix3x4 modelToWorldInner = Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_transform.GetTranslation()) * Matrix3x4::CreateScale(m_innerExtents * m_transform.GetScale()); m_renderInnerSrg->SetConstant(m_reflectionRenderData->m_modelToWorldRenderConstantIndex, modelToWorldInner); m_renderInnerSrg->SetConstant(m_reflectionRenderData->m_aabbPosRenderConstantIndex, m_outerAabbWs.GetCenter()); m_renderInnerSrg->SetConstant(m_reflectionRenderData->m_outerAabbMinRenderConstantIndex, m_outerAabbWs.GetMin()); @@ -208,30 +208,36 @@ namespace AZ void ReflectionProbe::SetTransform(const AZ::Transform& transform) { - m_position = transform.GetTranslation(); - m_meshFeatureProcessor->SetTransform(m_visualizationMeshHandle, transform); - m_outerAabbWs = Aabb::CreateCenterHalfExtents(m_position, m_outerExtents / 2.0f); - m_innerAabbWs = Aabb::CreateCenterHalfExtents(m_position, m_innerExtents / 2.0f); + m_transform = transform; + + // avoid scaling the visualization sphere + AZ::Transform visualizationTransform = m_transform; + visualizationTransform.ExtractScale(); + m_meshFeatureProcessor->SetTransform(m_visualizationMeshHandle, visualizationTransform); + + m_outerAabbWs = Aabb::CreateCenterHalfExtents(m_transform.GetTranslation(), m_outerExtents * m_transform.GetScale() / 2.0f); + m_innerAabbWs = Aabb::CreateCenterHalfExtents(m_transform.GetTranslation(), m_innerExtents * m_transform.GetScale() / 2.0f); m_updateSrg = true; } void ReflectionProbe::SetOuterExtents(const AZ::Vector3& outerExtents) { m_outerExtents = outerExtents; - m_outerAabbWs = Aabb::CreateCenterHalfExtents(m_position, m_outerExtents / 2.0f); + m_outerAabbWs = Aabb::CreateCenterHalfExtents(m_transform.GetTranslation(), m_outerExtents * m_transform.GetScale() / 2.0f); m_updateSrg = true; } void ReflectionProbe::SetInnerExtents(const AZ::Vector3& innerExtents) { m_innerExtents = innerExtents; - m_innerAabbWs = Aabb::CreateCenterHalfExtents(m_position, m_innerExtents / 2.0f); + m_innerAabbWs = Aabb::CreateCenterHalfExtents(m_transform.GetTranslation(), m_innerExtents * m_transform.GetScale() / 2.0f); m_updateSrg = true; } - void ReflectionProbe::SetCubeMapImage(const Data::Instance& cubeMapImage) + void ReflectionProbe::SetCubeMapImage(const Data::Instance& cubeMapImage, const AZStd::string& relativePath) { m_cubeMapImage = cubeMapImage; + m_cubeMapRelativePath = relativePath; m_updateSrg = true; } @@ -261,7 +267,7 @@ namespace AZ m_environmentCubeMapPipelineId = environmentCubeMapPipeline->GetId(); AZStd::shared_ptr passData = AZStd::make_shared(); - passData->m_position = m_position; + passData->m_position = m_transform.GetTranslation(); RPI::PassDescriptor environmentCubeMapPassDescriptor(Name("EnvironmentCubeMapPass")); environmentCubeMapPassDescriptor.m_passData = passData; diff --git a/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.h b/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.h index 22645a4ed3..ab0e7a81d3 100644 --- a/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.h +++ b/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbe.h @@ -75,20 +75,22 @@ namespace AZ void Init(RPI::Scene* scene, ReflectionRenderData* reflectionRenderData); void Simulate(uint32_t probeIndex); - const Vector3& GetPosition() const { return m_position; } + const Vector3& GetPosition() const { return m_transform.GetTranslation(); } void SetTransform(const AZ::Transform& transform); - const AZ::Vector3& GetOuterExtents() const { return m_outerExtents; } + AZ::Vector3 GetOuterExtents() const { return m_outerExtents * m_transform.GetScale(); } void SetOuterExtents(const AZ::Vector3& outerExtents); - const AZ::Vector3& GetInnerExtents() const { return m_innerExtents; } + AZ::Vector3 GetInnerExtents() const { return m_innerExtents * m_transform.GetScale(); } void SetInnerExtents(const AZ::Vector3& innerExtents); const Aabb& GetOuterAabbWs() const { return m_outerAabbWs; } const Aabb& GetInnerAabbWs() const { return m_innerAabbWs; } const Data::Instance& GetCubeMapImage() const { return m_cubeMapImage; } - void SetCubeMapImage(const Data::Instance& cubeMapImage); + void SetCubeMapImage(const Data::Instance& cubeMapImage, const AZStd::string& relativePath); + + const AZStd::string& GetCubeMapRelativePath() const { return m_cubeMapRelativePath; } bool GetUseParallaxCorrection() const { return m_useParallaxCorrection; } void SetUseParallaxCorrection(bool useParallaxCorrection) { m_useParallaxCorrection = useParallaxCorrection; } @@ -122,8 +124,8 @@ namespace AZ // scene RPI::Scene* m_scene = nullptr; - // probe capture position - AZ::Vector3 m_position = AZ::Vector3(0.0f, 0.0f, 0.0f); + // probe volume transform + AZ::Transform m_transform = AZ::Transform::CreateIdentity(); // extents of the probe volume AZ::Vector3 m_outerExtents = AZ::Vector3(0.0f, 0.0f, 0.0f); @@ -135,6 +137,7 @@ namespace AZ // cubemap Data::Instance m_cubeMapImage; + AZStd::string m_cubeMapRelativePath; bool m_useParallaxCorrection = false; // probe visualization diff --git a/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbeFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbeFeatureProcessor.cpp index a0d3e6ac51..740069fc6b 100644 --- a/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbeFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/ReflectionProbe/ReflectionProbeFeatureProcessor.cpp @@ -178,9 +178,9 @@ namespace AZ if (assetId.IsValid()) { - Data::AssetBus::MultiHandler::BusConnect(assetId); notificationEntry.m_assetId = assetId; notificationEntry.m_asset.Create(assetId, true); + Data::AssetBus::MultiHandler::BusConnect(assetId); } } @@ -257,10 +257,10 @@ namespace AZ m_probeSortRequired = true; } - void ReflectionProbeFeatureProcessor::SetProbeCubeMap(const ReflectionProbeHandle& probe, Data::Instance& cubeMapImage) + void ReflectionProbeFeatureProcessor::SetProbeCubeMap(const ReflectionProbeHandle& probe, Data::Instance& cubeMapImage, const AZStd::string& relativePath) { AZ_Assert(probe.get(), "SetProbeCubeMap called with an invalid handle"); - probe->SetCubeMapImage(cubeMapImage); + probe->SetCubeMapImage(cubeMapImage, relativePath); } void ReflectionProbeFeatureProcessor::SetProbeTransform(const ReflectionProbeHandle& probe, const AZ::Transform& transform) @@ -270,14 +270,11 @@ namespace AZ m_probeSortRequired = true; } - void ReflectionProbeFeatureProcessor::BakeProbe(const ReflectionProbeHandle& probe, BuildCubeMapCallback callback) + void ReflectionProbeFeatureProcessor::BakeProbe(const ReflectionProbeHandle& probe, BuildCubeMapCallback callback, const AZStd::string& relativePath) { AZ_Assert(probe.get(), "BakeProbe called with an invalid handle"); probe->BuildCubeMap(callback); - } - void ReflectionProbeFeatureProcessor::NotifyCubeMapAssetReady(const AZStd::string relativePath, NotifyCubeMapAssetReadyCallback callback) - { // check to see if this is an existing asset AZ::Data::AssetId assetId; AZ::Data::AssetCatalogRequestBus::BroadcastResult( @@ -287,13 +284,44 @@ namespace AZ azrtti_typeid(), false); - bool existingAsset = assetId.IsValid(); - m_notifyCubeMapAssets.push_back({ relativePath, assetId, existingAsset, callback }); + // we only track notifications for new cubemap assets, existing assets are automatically reloaded by the RPI + if (!assetId.IsValid()) + { + m_notifyCubeMapAssets.push_back({ relativePath, assetId }); + } + } + + bool ReflectionProbeFeatureProcessor::CheckCubeMapAssetNotification(const AZStd::string& relativePath, Data::Asset& outCubeMapAsset, CubeMapAssetNotificationType& outNotificationType) + { + for (NotifyCubeMapAssetVector::iterator itNotification = m_notifyCubeMapAssets.begin(); itNotification != m_notifyCubeMapAssets.end(); ++itNotification) + { + if (itNotification->m_relativePath == relativePath) + { + outNotificationType = itNotification->m_notificationType; + if (outNotificationType != CubeMapAssetNotificationType::None) + { + outCubeMapAsset = itNotification->m_asset; + m_notifyCubeMapAssets.erase(itNotification); + } + + return true; + } + } + + return false; + } - if (existingAsset) + bool ReflectionProbeFeatureProcessor::IsCubeMapReferenced(const AZStd::string& relativePath) + { + for (auto& reflectionProbe : m_reflectionProbes) { - Data::AssetBus::MultiHandler::BusConnect(assetId); + if (reflectionProbe->GetCubeMapRelativePath() == relativePath) + { + return true; + } } + + return false; } void ReflectionProbeFeatureProcessor::ShowProbeVisualization(const ReflectionProbeHandle& probe, bool showVisualization) @@ -509,17 +537,9 @@ namespace AZ { if (itNotification->m_assetId == asset.GetId()) { - if (itNotification->m_existingAsset && notificationType == CubeMapAssetNotificationType::Ready) - { - // existing cubemap assets only notify on reload or error - break; - } - - // notify - itNotification->m_callback(Data::static_pointer_cast(asset), notificationType); - - // remove the entry from the list - m_notifyCubeMapAssets.erase(itNotification); + // store the cubemap asset + itNotification->m_asset = Data::static_pointer_cast(asset); + itNotification->m_notificationType = notificationType; // stop notifications on this asset Data::AssetBus::MultiHandler::BusDisconnect(itNotification->m_assetId); @@ -540,11 +560,5 @@ namespace AZ HandleAssetNotification(asset, CubeMapAssetNotificationType::Error); } - - void ReflectionProbeFeatureProcessor::OnAssetReloaded(Data::Asset asset) - { - HandleAssetNotification(asset, CubeMapAssetNotificationType::Reloaded); - } - } // namespace Render } // namespace AZ diff --git a/Gems/Atom/Feature/Common/Code/Source/Utils/LightingPreset.cpp b/Gems/Atom/Feature/Common/Code/Source/Utils/LightingPreset.cpp index 77924b87a3..91ad31648b 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Utils/LightingPreset.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Utils/LightingPreset.cpp @@ -30,7 +30,7 @@ namespace AZ if (auto serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(3) + ->Version(4) ->Field("compensateValue", &ExposureControlConfig::m_manualCompensationValue) ->Field("exposureControlType", &ExposureControlConfig::m_exposureControlType) ->Field("autoExposureMin", &ExposureControlConfig::m_autoExposureMin) diff --git a/Gems/Atom/RHI/Code/Tests/Buffer.h b/Gems/Atom/RHI/Code/Tests/Buffer.h index cfa216293f..a5538b0071 100644 --- a/Gems/Atom/RHI/Code/Tests/Buffer.h +++ b/Gems/Atom/RHI/Code/Tests/Buffer.h @@ -30,6 +30,8 @@ namespace UnitTest void ShutdownInternal() override; }; + class BufferPool; + class Buffer : public AZ::RHI::Buffer { diff --git a/Gems/Atom/RHI/Code/Tests/Query.h b/Gems/Atom/RHI/Code/Tests/Query.h index 6220ae5f55..80b47f3e42 100644 --- a/Gems/Atom/RHI/Code/Tests/Query.h +++ b/Gems/Atom/RHI/Code/Tests/Query.h @@ -21,7 +21,6 @@ namespace UnitTest class Query : public AZ::RHI::Query { - friend class QueryPool; public: AZ_CLASS_ALLOCATOR(Query, AZ::SystemAllocator, 0); diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphExecuteGroupBase.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphExecuteGroupBase.cpp index 809790a7d5..6251eca7dc 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphExecuteGroupBase.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/FrameGraphExecuteGroupBase.cpp @@ -32,7 +32,7 @@ namespace AZ AZ_Assert(commandList && commandList->IsRecording() == false, "Command list not valid."); } } -#endif() +#endif return AZStd::move(m_workRequest); } diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/DynamicDraw/DynamicDrawContext.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/DynamicDraw/DynamicDrawContext.h index 789717cabe..e4b9b91e81 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/DynamicDraw/DynamicDrawContext.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/DynamicDraw/DynamicDrawContext.h @@ -156,6 +156,13 @@ namespace AZ //! Get the shader which is associated with this DynamicDrawContext const Data::Instance& GetShader() const; + //! Set the sort key for the next draw. + //! Note: The sort key will be increased by 1 whenever the a draw function is called. + void SetSortKey(RHI::DrawItemSortKey key); + + //! Get the current sort key. + RHI::DrawItemSortKey GetSortKey() const; + private: DynamicDrawContext() = default; @@ -228,6 +235,7 @@ namespace AZ struct DrawItemInfo { RHI::DrawItem m_drawItem; + RHI::DrawItemSortKey m_sortKey; uint32_t m_vertexBufferViewIndex = InvalidIndex; uint32_t m_indexBufferViewIndex = InvalidIndex; }; @@ -243,6 +251,8 @@ namespace AZ // This variable is used to see if the context is initialized. // You can only add draw calls when the context is initialized. bool m_initialized = false; + + RHI::DrawItemSortKey m_sortKey = 0; }; AZ_DEFINE_ENUM_BITWISE_OPERATORS(AZ::RPI::DynamicDrawContext::DrawStateOptions); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/DynamicDraw/DynamicDrawContext.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/DynamicDraw/DynamicDrawContext.cpp index 65b698f9ac..b7ba7d4a32 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/DynamicDraw/DynamicDrawContext.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/DynamicDraw/DynamicDrawContext.cpp @@ -447,6 +447,7 @@ namespace AZ drawItem.m_viewports = &m_viewport; } + drawItemInfo.m_sortKey = m_sortKey++; m_cachedDrawItems.emplace_back(drawItemInfo); } @@ -527,6 +528,7 @@ namespace AZ drawItem.m_viewports = &m_viewport; } + drawItemInfo.m_sortKey = m_sortKey++; m_cachedDrawItems.emplace_back(drawItemInfo); } @@ -577,6 +579,16 @@ namespace AZ return m_shader; } + void DynamicDrawContext::SetSortKey(RHI::DrawItemSortKey key) + { + m_sortKey = key; + } + + RHI::DrawItemSortKey DynamicDrawContext::GetSortKey() const + { + return m_sortKey; + } + void DynamicDrawContext::SubmitDrawData(ViewPtr view) { if (!m_initialized) @@ -588,8 +600,7 @@ namespace AZ { return; } - - uint64_t sortKey = 0; // use the draw order as sort key. + for (auto& drawItemInfo : m_cachedDrawItems) { if (drawItemInfo.m_indexBufferViewIndex != InvalidIndex) @@ -603,16 +614,16 @@ namespace AZ } RHI::DrawItemProperties drawItemProperties; - drawItemProperties.m_sortKey = sortKey; + drawItemProperties.m_sortKey = drawItemInfo.m_sortKey; drawItemProperties.m_item = &drawItemInfo.m_drawItem; drawItemProperties.m_drawFilterMask = m_drawFilter; view->AddDrawItem(m_drawListTag, drawItemProperties); - sortKey++; } } void DynamicDrawContext::FrameEnd() { + m_sortKey = 0; m_cachedDrawItems.clear(); m_cachedStreamBufferViews.clear(); m_cachedIndexBufferViews.clear(); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/ShaderCollection.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/ShaderCollection.cpp index 4cae8af48e..7fc75f67fe 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/ShaderCollection.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/ShaderCollection.cpp @@ -40,13 +40,22 @@ namespace AZ // Dependent asset references aren't guaranteed to finish loading by the time this asset is serialized, only by // the time this asset load is completed. But since the data is needed here, we will deliberately block until the // shader asset has finished loading. - shaderVariantReference->m_shaderAsset.QueueLoad(); - shaderVariantReference->m_shaderAsset.BlockUntilLoadComplete(); - - shaderVariantReference->m_shaderOptionGroup = ShaderOptionGroup{ - shaderVariantReference->m_shaderAsset->GetShaderOptionGroupLayout(), - shaderVariantReference->m_shaderVariantId - }; + if (shaderVariantReference->m_shaderAsset.QueueLoad()) + { + shaderVariantReference->m_shaderAsset.BlockUntilLoadComplete(); + } + + if (shaderVariantReference->m_shaderAsset.IsReady()) + { + shaderVariantReference->m_shaderOptionGroup = ShaderOptionGroup{ + shaderVariantReference->m_shaderAsset->GetShaderOptionGroupLayout(), + shaderVariantReference->m_shaderVariantId + }; + } + else + { + shaderVariantReference->m_shaderOptionGroup = {}; + } } }; @@ -82,7 +91,7 @@ namespace AZ if (BehaviorContext* behaviorContext = azrtti_cast(context)) { - behaviorContext->Class() + behaviorContext->Class("ShaderCollectionItem") ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation) ->Attribute(AZ::Script::Attributes::Category, "Shader") ->Attribute(AZ::Script::Attributes::Module, "shader") diff --git a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/012_Parallax_POM_Cutout.material b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/012_Parallax_POM_Cutout.material new file mode 100644 index 0000000000..fb862dc5d3 --- /dev/null +++ b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/012_Parallax_POM_Cutout.material @@ -0,0 +1,26 @@ +{ + "description": "", + "materialType": "Materials/Types/StandardPBR.materialtype", + "parentMaterial": "", + "propertyLayoutVersion": 3, + "properties": { + "baseColor": { + "textureMap": "TestData/Textures/TextureHaven/4k_castle_brick_02_red/4k_castle_brick_02_red_bc.png" + }, + "opacity": { + "alphaSource": "Split", + "mode": "Cutout", + "textureMap": "TestData/Textures/checker8x8_512.png" + }, + "parallax": { + "algorithm": "POM", + "enable": true, + "factor": 0.10000000149011612, + "quality": "High", + "textureMap": "TestData/Textures/TextureHaven/4k_castle_brick_02_red/4k_castle_brick_02_red_disp.png" + }, + "uv": { + "scale": 0.5 + } + } +} \ No newline at end of file diff --git a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl index 793b71b3af..424de7749d 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl @@ -121,12 +121,12 @@ void GetSurfaceShape(float2 uv, out float depth, out float3 normal) } // Callback function for ParallaxMapping.azsli -float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) +DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) { float depth; float3 normal; GetSurfaceShape(uv, depth, normal); - return depth; + return DepthResultNormalized(depth); } ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) @@ -136,15 +136,18 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) 0,1,0, 0,0,1 }; - float3 tangentOffset = GetParallaxOffset( AutoBrickSrg::m_lineDepth, - IN.m_uv, - ViewSrg::m_worldPosition.xyz - IN.m_worldPosition, - IN.m_tangent, - IN.m_bitangent, - IN.m_normal, - identityUvMatrix); + float depthOffset = 0.0; + + ParallaxOffset tangentOffset = GetParallaxOffset( AutoBrickSrg::m_lineDepth, + depthOffset, + IN.m_uv, + ViewSrg::m_worldPosition.xyz - IN.m_worldPosition, + IN.m_tangent, + IN.m_bitangent, + IN.m_normal, + identityUvMatrix); - IN.m_uv += tangentOffset.xy; + IN.m_uv += tangentOffset.m_offsetTS.xy; float3 baseColor = float3(1,1,1); const float noise = AutoBrickSrg::m_noise.Sample(AutoBrickSrg::m_sampler, IN.m_uv).r; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt b/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt index fb4750ce93..4cd6ad8182 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/CMakeLists.txt @@ -33,6 +33,7 @@ ly_add_target( AZ::AzQtComponents 3rdParty::Qt::Core 3rdParty::Qt::Gui + 3rdParty::Qt::Network 3rdParty::Qt::Widgets 3rdParty::Python Gem::Atom_RPI.Edit diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalServer.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalServer.h new file mode 100644 index 0000000000..4482566113 --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalServer.h @@ -0,0 +1,56 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include +#include +#endif + +namespace AtomToolsFramework +{ + //! A named local server that will manage connections and forward recieved data + class LocalServer : public QObject + { + Q_OBJECT + public: + LocalServer(); + ~LocalServer(); + + //! Start a named local server + bool Connect(const QString& serverName); + + //! Stop the server + void Disconnect(); + + //! Get server status + bool IsConnected() const; + + using ReadHandler = AZStd::function; + + //! Set a handler that recieved data will be forwarded to + void SetReadHandler(ReadHandler handler); + + private: + void AddConnection(QLocalSocket* connection); + void ReadFromConnection(QLocalSocket* connection); + void DeleteConnection(QLocalSocket* connection); + + QString m_serverName; + QLocalServer m_server; + ReadHandler m_readHandler; + }; +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalSocket.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalSocket.h new file mode 100644 index 0000000000..4eb4d533ed --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Communication/LocalSocket.h @@ -0,0 +1,45 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace AtomToolsFramework +{ + //! LocalSocket enables interprocess communication by establ;ishing a connection and sending data to a LocalServer + class LocalSocket : public QObject + { + Q_OBJECT + public: + LocalSocket(); + ~LocalSocket(); + + //! Attempt to connect to a named local server + bool Connect(const QString& serverName); + + //! Sever connection from server + void Disconnect(); + + //! Get the sockets connection status + bool IsConnected() const; + + //! Send a stream of data to the connected local server + bool Send(const QByteArray& buffer); + + private: + QString m_serverName; + QLocalSocket m_socket; + }; +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h index d1beed1a65..bba299187b 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h @@ -15,6 +15,7 @@ #if !defined(Q_MOC_RUN) #include #include +#include #include #endif @@ -31,7 +32,11 @@ namespace AtomToolsFramework void SetExpanded(bool expanded); bool IsExpanded() const; + Q_SIGNALS: + void clicked(QMouseEvent* event); + protected: + void mousePressEvent(QMouseEvent* event) override; void paintEvent(QPaintEvent* event) override; private: diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h index 5f16894a0c..81b512faf2 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h @@ -55,6 +55,12 @@ namespace AtomToolsFramework //! Calls Rebuild for all InspectorGroupWidget, allowing for destructive UI changes virtual void RebuildAll() = 0; + + //! Expands all groups and headers + virtual void ExpandAll() = 0; + + //! Collapses all groups and headers + virtual void CollapseAll() = 0; }; using InspectorRequestBus = AZ::EBus; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h index 9f8df2da71..b0932b3b04 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h @@ -29,11 +29,8 @@ namespace Ui namespace AtomToolsFramework { - class InspectorPropertyGroupWidget; -} + class InspectorGroupHeaderWidget; -namespace AtomToolsFramework -{ //! Provides controls for viewing and editing object settings. //! The settings can be divided into groups, with each one showing a subset of properties. class InspectorWidget @@ -66,8 +63,15 @@ namespace AtomToolsFramework void RefreshAll() override; void RebuildAll() override; + void ExpandAll() override; + void CollapseAll() override; + private: + void OnHeaderClicked(QMouseEvent* event, InspectorGroupHeaderWidget* groupHeader, QWidget* groupWidget); + QVBoxLayout* m_layout = nullptr; QScopedPointer m_ui; + AZStd::vector m_headers; + AZStd::vector m_groups; }; } // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Viewport/RenderViewportWidget.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Viewport/RenderViewportWidget.h index 5dbbf04f1b..8e64c1467e 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Viewport/RenderViewportWidget.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Viewport/RenderViewportWidget.h @@ -94,9 +94,10 @@ namespace AtomToolsFramework bool ShowGrid() override; bool AngleSnappingEnabled() override; float AngleStep() override; - QPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override; - AZStd::optional ViewportScreenToWorld(const QPoint& screenPosition, float depth) override; - AZStd::optional ViewportScreenToWorldRay(const QPoint& screenPosition) override; + AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override; + AZStd::optional ViewportScreenToWorld(const AzFramework::ScreenPoint& screenPosition, float depth) override; + AZStd::optional ViewportScreenToWorldRay( + const AzFramework::ScreenPoint& screenPosition) override; // AzToolsFramework::ViewportInteraction::ViewportMouseCursorRequestBus::Handler ... void BeginCursorCapture() override; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalServer.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalServer.cpp new file mode 100644 index 0000000000..6f26b00c4f --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalServer.cpp @@ -0,0 +1,108 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include +#include +#include + +namespace AtomToolsFramework +{ + LocalServer::LocalServer() + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Creating local server\n"); + m_server.setSocketOptions(QLocalServer::WorldAccessOption); + + QObject::connect(&m_server, &QLocalServer::newConnection, this, [this]() { AddConnection(m_server.nextPendingConnection()); }); + } + + LocalServer::~LocalServer() + { + Disconnect(); + } + + bool LocalServer::Connect(const QString& serverName) + { + Disconnect(); + + m_serverName = serverName; + + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Starting: %s\n", m_serverName.toUtf8().constData()); + if (m_server.listen(m_serverName)) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Started: %s\n", m_serverName.toUtf8().constData()); + return true; + } + + if (m_server.serverError() == QAbstractSocket::AddressInUseError) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Restarting: %s\n", m_serverName.toUtf8().constData()); + Disconnect(); + + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Starting: %s\n", m_serverName.toUtf8().constData()); + if (m_server.listen(m_serverName)) + { + return true; + } + } + + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Starting failed: %s\n", m_serverName.toUtf8().constData()); + Disconnect(); + return false; + } + + void LocalServer::Disconnect() + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Disconnecting: %s\n", m_serverName.toUtf8().constData()); + QLocalServer::removeServer(m_serverName); + } + + bool LocalServer::IsConnected() const + { + return m_server.isListening(); + } + + void LocalServer::SetReadHandler(LocalServer::ReadHandler handler) + { + m_readHandler = handler; + } + + void LocalServer::AddConnection(QLocalSocket* connection) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Connection added: %s\n", m_serverName.toUtf8().constData()); + QObject::connect(connection, &QLocalSocket::readyRead, this, [this, connection]() { ReadFromConnection(connection); }); + QObject::connect(connection, &QLocalSocket::disconnected, this, [this, connection]() { DeleteConnection(connection); }); + } + + void LocalServer::ReadFromConnection(QLocalSocket* connection) + { + if (connection) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Data received: %s\n", m_serverName.toUtf8().constData()); + QByteArray buffer = connection->readAll(); + if (m_readHandler) + { + m_readHandler(buffer); + } + } + } + + void LocalServer::DeleteConnection(QLocalSocket* connection) + { + if (connection) + { + AZ_TracePrintf("AtomToolsFramework::LocalServer", "Deleting connection: %s\n", m_serverName.toUtf8().constData()); + connection->deleteLater(); + } + } +} // namespace AtomToolsFramework + +#include diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalSocket.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalSocket.cpp new file mode 100644 index 0000000000..020998bf1a --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Communication/LocalSocket.cpp @@ -0,0 +1,86 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include +#include +#include +#include + +namespace AtomToolsFramework +{ + LocalSocket::LocalSocket() + { + } + + LocalSocket::~LocalSocket() + { + Disconnect(); + } + + bool LocalSocket::Connect(const QString& serverName) + { + Disconnect(); + + m_serverName = serverName; + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connecting to: %s\n", m_serverName.toUtf8().constData()); + m_socket.connectToServer(m_serverName); + + if (IsConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Waiting for connection to: %s\n", m_serverName.toUtf8().constData()); + if (m_socket.waitForConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connected to: %s\n", m_serverName.toUtf8().constData()); + return true; + } + } + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connecting failed: %s\n", m_serverName.toUtf8().constData()); + Disconnect(); + return false; + } + + void LocalSocket::Disconnect() + { + if (IsConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Disconnecting from: %s\n", m_serverName.toUtf8().constData()); + m_socket.disconnectFromServer(); + m_socket.waitForDisconnected(); + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Closing socket\n"); + m_socket.close(); + } + } + + bool LocalSocket::IsConnected() const + { + return m_socket.isOpen(); + } + + bool LocalSocket::Send(const QByteArray& buffer) + { + if (IsConnected()) + { + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Sending data to: %s\n", m_serverName.toUtf8().constData()); + m_socket.write(buffer); + + AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Waiting for write to: %s\n", m_serverName.toUtf8().constData()); + m_socket.waitForBytesWritten(); + return true; + } + return false; + } +} // namespace AtomToolsFramework + +#include diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp index 5784355498..8afd1dc8d5 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/DynamicProperty/DynamicProperty.cpp @@ -211,10 +211,7 @@ namespace AtomToolsFramework AZStd::string DynamicProperty::GetDescription() const { - return AZStd::string::format("%s%s(Script Name = '%s')", - m_config.m_description.c_str(), - m_config.m_description.empty() ? "" : "\n", - m_config.m_id.GetCStr()); + return m_config.m_description; } AZ::Crc32 DynamicProperty::GetVisibility() const diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp index 2928d745c1..41cc1e4a50 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp @@ -14,10 +14,10 @@ #include #include -#include -#include #include +#include #include +#include #include namespace AtomToolsFramework @@ -44,6 +44,11 @@ namespace AtomToolsFramework return m_expanded; } + void InspectorGroupHeaderWidget::mousePressEvent(QMouseEvent* event) + { + emit clicked(event); + } + void InspectorGroupHeaderWidget::paintEvent([[maybe_unused]] QPaintEvent* event) { QPainter painter(this); @@ -52,19 +57,10 @@ namespace AtomToolsFramework auto& icon = m_expanded ? m_iconExpanded : m_iconCollapsed; const QRect iconRect(5, (geometry().height() / 2) - (iconSize.height() / 2), iconSize.width(), iconSize.height()); - style->drawItemPixmap(&painter, - iconRect, - Qt::AlignLeft | Qt::AlignVCenter, - icon.scaledToWidth(iconSize.width())); + style->drawItemPixmap(&painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter, icon.scaledToWidth(iconSize.width())); const auto textRect = QRect(25, 0, geometry().width() - 21, geometry().height()); - style->drawItemText(&painter, - textRect, - Qt::AlignLeft | Qt::AlignVCenter, - QPalette(), - true, - text(), - QPalette::HighlightedText); + style->drawItemText(&painter, textRect, Qt::AlignLeft | Qt::AlignVCenter, QPalette(), true, text(), QPalette::HighlightedText); } } // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp index 31a291c845..ec5f9893bd 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp @@ -10,12 +10,13 @@ * */ +#include #include #include #include -#include #include +#include #include #include @@ -38,6 +39,8 @@ namespace AtomToolsFramework m_layout = new QVBoxLayout(m_ui->m_propertyContent); m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setSpacing(0); + m_headers.clear(); + m_groups.clear(); } void InspectorWidget::AddGroupsBegin() @@ -52,8 +55,7 @@ namespace AtomToolsFramework m_layout->addStretch(); // Scroll to top whenever there is new content - m_ui->m_propertyScrollArea->verticalScrollBar()->setValue( - m_ui->m_propertyScrollArea->verticalScrollBar()->minimum()); + m_ui->m_propertyScrollArea->verticalScrollBar()->setValue(m_ui->m_propertyScrollArea->verticalScrollBar()->minimum()); setUpdatesEnabled(true); } @@ -68,15 +70,15 @@ namespace AtomToolsFramework groupHeader->setText(groupDisplayName.c_str()); groupHeader->setToolTip(groupDescription.c_str()); m_layout->addWidget(groupHeader); + m_headers.push_back(groupHeader); groupWidget->setObjectName(groupNameId.c_str()); groupWidget->setParent(m_ui->m_propertyContent); m_layout->addWidget(groupWidget); + m_groups.push_back(groupWidget); - connect(groupHeader, &AzQtComponents::ExtendedLabel::clicked, this, [groupHeader, groupWidget]() - { - groupHeader->SetExpanded(!groupHeader->IsExpanded()); - groupWidget->setVisible(groupHeader->IsExpanded()); + connect(groupHeader, &InspectorGroupHeaderWidget::clicked, this, [this, groupHeader, groupWidget](QMouseEvent* event) { + OnHeaderClicked(event, groupHeader, groupWidget); }); } @@ -111,6 +113,57 @@ namespace AtomToolsFramework groupWidget->Rebuild(); } } + + void InspectorWidget::ExpandAll() + { + for (auto headerWidget : m_headers) + { + headerWidget->SetExpanded(true); + } + for (auto groupWidget : m_groups) + { + groupWidget->setVisible(true); + } + } + + void InspectorWidget::CollapseAll() + { + for (auto headerWidget : m_headers) + { + headerWidget->SetExpanded(false); + } + for (auto groupWidget : m_groups) + { + groupWidget->setVisible(false); + } + } + + void InspectorWidget::OnHeaderClicked(QMouseEvent* event, InspectorGroupHeaderWidget* groupHeader, QWidget* groupWidget) + { + if (event->button() == Qt::MouseButton::LeftButton) + { + groupHeader->SetExpanded(!groupHeader->IsExpanded()); + groupWidget->setVisible(groupHeader->IsExpanded()); + return; + } + + if (event->button() == Qt::MouseButton::RightButton) + { + QMenu menu; + menu.addAction("Expand", [groupHeader, groupWidget]() { + groupHeader->SetExpanded(true); + groupWidget->setVisible(true); + })->setEnabled(!groupHeader->IsExpanded()); + menu.addAction("Collapse", [groupHeader, groupWidget]() { + groupHeader->SetExpanded(false); + groupWidget->setVisible(false); + })->setEnabled(groupHeader->IsExpanded()); + menu.addAction("Expand All", [this]() { ExpandAll(); }); + menu.addAction("Collapse All", [this]() { CollapseAll(); }); + menu.exec(event->globalPos()); + return; + } + } } // namespace AtomToolsFramework #include diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp index 952e241143..41a627bef7 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/MaterialPropertyUtil.cpp @@ -91,6 +91,13 @@ namespace AtomToolsFramework propertyConfig.m_vectorLabels = propertyDefinition.m_vectorLabels; propertyConfig.m_visible = propertyDefinition.m_visibility != AZ::RPI::MaterialPropertyVisibility::Hidden; propertyConfig.m_readOnly = propertyDefinition.m_visibility == AZ::RPI::MaterialPropertyVisibility::Disabled; + + // Update the description for material properties to include script name assuming id is set beforehand + propertyConfig.m_description = AZStd::string::format( + "%s%s(Script Name = '%s')", + propertyConfig.m_description.c_str(), + propertyConfig.m_description.empty() ? "" : "\n", + propertyConfig.m_id.GetCStr()); } void ConvertToPropertyConfig(AtomToolsFramework::DynamicPropertyConfig& propertyConfig, const AZ::RPI::MaterialPropertyDynamicMetadata& propertyMetaData) diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp index 483b4bc55b..5f3c553601 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp @@ -407,44 +407,43 @@ namespace AtomToolsFramework return 0.0f; } - QPoint RenderViewportWidget::ViewportWorldToScreen(const AZ::Vector3& worldPosition) + AzFramework::ScreenPoint RenderViewportWidget::ViewportWorldToScreen(const AZ::Vector3& worldPosition) { - AZ::RPI::ViewPtr currentView = m_viewportContext->GetDefaultView(); - if (currentView == nullptr) + if (AZ::RPI::ViewPtr currentView = m_viewportContext->GetDefaultView(); + currentView == nullptr) { - return QPoint(); + return AzFramework::ScreenPoint(0, 0); } - AzFramework::ScreenPoint position = AzFramework::WorldToScreen( - worldPosition, - GetCameraState() - ); - return {position.m_x, position.m_y}; + + return AzFramework::WorldToScreen(worldPosition, GetCameraState()); } - AZStd::optional RenderViewportWidget::ViewportScreenToWorld(const QPoint& screenPosition, float depth) + AZStd::optional RenderViewportWidget::ViewportScreenToWorld(const AzFramework::ScreenPoint& screenPosition, float depth) { const auto& cameraProjection = m_viewportContext->GetCameraProjectionMatrix(); const auto& cameraView = m_viewportContext->GetCameraViewMatrix(); const AZ::Vector4 normalizedScreenPosition { - screenPosition.x() * 2.f / width() - 1.0f, - (height() - screenPosition.y()) * 2.f / height() - 1.0f, + screenPosition.m_x * 2.f / width() - 1.0f, + (height() - screenPosition.m_y) * 2.f / height() - 1.0f, 1.f - depth, // [GFX TODO] [ATOM-1501] Currently we always assume reverse depth 1.f }; + AZ::Matrix4x4 worldFromScreen = cameraProjection * cameraView; worldFromScreen.InvertFull(); - AZ::Vector4 projectedPosition = worldFromScreen * normalizedScreenPosition; - if (projectedPosition.GetW() == 0.f) + const AZ::Vector4 projectedPosition = worldFromScreen * normalizedScreenPosition; + if (projectedPosition.GetW() == 0.0f) { return {}; } + return projectedPosition.GetAsVector3() / projectedPosition.GetW(); } AZStd::optional RenderViewportWidget::ViewportScreenToWorldRay( - const QPoint& screenPosition) + const AzFramework::ScreenPoint& screenPosition) { auto pos0 = ViewportScreenToWorld(screenPosition, 0.f); auto pos1 = ViewportScreenToWorld(screenPosition, 1.f); @@ -457,6 +456,7 @@ namespace AtomToolsFramework AZ::Vector3 rayOrigin = pos0.value(); AZ::Vector3 rayDirection = pos1.value() - pos0.value(); rayDirection.Normalize(); + return AzToolsFramework::ViewportInteraction::ProjectedViewportRay{rayOrigin, rayDirection}; } diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake index e8539711f7..d8ceccc724 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake @@ -10,6 +10,8 @@ # set(FILES + Include/AtomToolsFramework/Communication/LocalServer.h + Include/AtomToolsFramework/Communication/LocalSocket.h Include/AtomToolsFramework/Debug/TraceRecorder.h Include/AtomToolsFramework/DynamicProperty/DynamicProperty.h Include/AtomToolsFramework/DynamicProperty/DynamicPropertyGroup.h @@ -22,6 +24,8 @@ set(FILES Include/AtomToolsFramework/Util/MaterialPropertyUtil.h Include/AtomToolsFramework/Util/Util.h Include/AtomToolsFramework/Viewport/RenderViewportWidget.h + Source/Communication/LocalServer.cpp + Source/Communication/LocalSocket.cpp Source/Debug/TraceRecorder.cpp Source/DynamicProperty/DynamicProperty.cpp Source/DynamicProperty/DynamicPropertyGroup.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt b/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt index 40d6a8f30a..134f605200 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt +++ b/Gems/Atom/Tools/MaterialEditor/Code/CMakeLists.txt @@ -93,6 +93,7 @@ ly_add_target( ly_add_target( NAME MaterialEditor EXECUTABLE NAMESPACE Gem + AUTOMOC FILES_CMAKE materialeditor_files.cmake Source/Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h index 84406d8402..0727547b13 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h @@ -11,6 +11,7 @@ */ #pragma once +#include #include #include #include @@ -66,6 +67,9 @@ namespace MaterialEditor //! Notify when field of view changes virtual void OnFieldOfViewChanged([[maybe_unused]] float fieldOfView) {} + + //! Notify when tone mapping changes + virtual void OnDisplayMapperOperationTypeChanged([[maybe_unused]] AZ::Render::DisplayMapperOperationType operationType) {} }; using MaterialViewportNotificationBus = AZ::EBus; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h index ea6be4f21a..0c9b6e945d 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h @@ -11,6 +11,7 @@ */ #pragma once +#include #include #include #include @@ -147,6 +148,12 @@ namespace MaterialEditor //! Get field of view virtual float GetFieldOfView() const = 0; + + //! Set tone mapping type + virtual void SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) = 0; + + //! Get tone mapping type + virtual AZ::Render::DisplayMapperOperationType GetDisplayMapperOperationType() const = 0; }; using MaterialViewportRequestBus = AZ::EBus; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h index 538777b762..55e6ddac20 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h @@ -28,6 +28,9 @@ namespace MaterialEditor static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; + //! Bring main window to foreground + virtual void ActivateWindow() = 0; + //! Add dockable widget in main window //! @param name title of the dockable window //! @param widget docked window content diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp index 3919684864..288530a4e4 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp @@ -762,6 +762,8 @@ namespace MaterialEditor // in the hierarchy are applied m_materialTypeSourceData.EnumerateProperties([this, &parentPropertyValues](const AZStd::string& groupNameId, const AZStd::string& propertyNameId, const auto& propertyDefinition) { AtomToolsFramework::DynamicPropertyConfig propertyConfig; + + // Assign id before conversion so it can be used in dynamic description propertyConfig.m_id = MaterialPropertyId(groupNameId, propertyNameId).GetCStr(); const auto& propertyIndex = m_materialAsset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyConfig.m_id); @@ -792,7 +794,8 @@ namespace MaterialEditor propertyConfig.m_nameId = "materialType"; propertyConfig.m_displayName = "Material Type"; propertyConfig.m_groupName = "Details"; - propertyConfig.m_description = propertyConfig.m_displayName; + propertyConfig.m_description = "The material type defines the layout, properties, default values, shader connections, and other " + "data needed to create and edit a derived material."; propertyConfig.m_defaultValue = AZStd::any(materialTypeAsset); propertyConfig.m_originalValue = propertyConfig.m_defaultValue; propertyConfig.m_parentValue = propertyConfig.m_defaultValue; @@ -806,7 +809,8 @@ namespace MaterialEditor propertyConfig.m_nameId = "parentMaterial"; propertyConfig.m_displayName = "Parent Material"; propertyConfig.m_groupName = "Details"; - propertyConfig.m_description = propertyConfig.m_displayName; + propertyConfig.m_description = + "The parent material provides an initial configuration whose properties are inherited and overriden by a derived material."; propertyConfig.m_defaultValue = AZStd::any(parentMaterialAsset); propertyConfig.m_originalValue = propertyConfig.m_defaultValue; propertyConfig.m_parentValue = propertyConfig.m_defaultValue; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp index a7aecf0b1f..b1a795b9f9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentModule.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ namespace MaterialEditor return AZ::ComponentTypeList{ azrtti_typeid(), azrtti_typeid(), - azrtti_typeid(), }; } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp index 2fd1aac211..dbb1d18e49 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp @@ -109,7 +109,6 @@ namespace MaterialEditor void MaterialDocumentSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { - required.push_back(AZ_CRC("TargetManagerService", 0x6d5708bc)); required.push_back(AZ_CRC("AssetProcessorToolsConnection", 0x734669bc)); required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601)); required.push_back(AZ_CRC("PropertyManagerService", 0x63a3d7ad)); @@ -135,31 +134,16 @@ namespace MaterialEditor m_documentMap.clear(); MaterialDocumentSystemRequestBus::Handler::BusConnect(); MaterialDocumentNotificationBus::Handler::BusConnect(); - AzFramework::TmMsgBus::Handler::BusConnect(AZ_CRC("OpenInMaterialEditor", 0x9f92aac8)); } void MaterialDocumentSystemComponent::Deactivate() { AZ::TickBus::Handler::BusDisconnect(); - AzFramework::TmMsgBus::Handler::BusDisconnect(); MaterialDocumentNotificationBus::Handler::BusDisconnect(); MaterialDocumentSystemRequestBus::Handler::BusDisconnect(); m_documentMap.clear(); } - void MaterialDocumentSystemComponent::OnReceivedMsg(AzFramework::TmMsgPtr msg) - { - if (msg->GetId() == AZ_CRC("OpenInMaterialEditor", 0x9f92aac8)) - { - const char* documentPath = reinterpret_cast(msg->GetCustomBlob()); - MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::OpenDocument, documentPath); - } - else - { - AZ_Assert(false, "We received a message of an unrecognized class type!"); - } - } - AZ::Uuid MaterialDocumentSystemComponent::CreateDocument() { auto document = AZStd::make_unique(); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h index b6c541421d..4b0ee424a7 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -35,7 +34,6 @@ namespace MaterialEditor class MaterialDocumentSystemComponent : public AZ::Component , private AZ::TickBus::Handler - , private AzFramework::TmMsgBus::Handler , private MaterialDocumentNotificationBus::Handler , private MaterialDocumentSystemRequestBus::Handler { @@ -72,11 +70,6 @@ namespace MaterialEditor void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; //////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // AzFramework::TmMsgBus::Handler overrides... - void OnReceivedMsg(AzFramework::TmMsgPtr msg) override; - ////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// // MaterialDocumentSystemRequestBus::Handler overrides... AZ::Uuid CreateDocument() override; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 66be1c23bb..1f32c2a66b 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -45,6 +45,7 @@ #include #include +#include #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT @@ -90,6 +91,14 @@ namespace MaterialEditor }); } + MaterialEditorApplication::~MaterialEditorApplication() + { + AzToolsFramework::EditorPythonConsoleNotificationBus::Handler::BusDisconnect(); + AzToolsFramework::AssetDatabase::AssetDatabaseRequestsBus::Handler::BusDisconnect(); + MaterialEditorWindowNotificationBus::Handler::BusDisconnect(); + AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); + } + void MaterialEditorApplication::CreateReflectionManager() { Application::CreateReflectionManager(); @@ -299,12 +308,19 @@ namespace MaterialEditor return false; } - void MaterialEditorApplication::ProcessCommandLine() + void MaterialEditorApplication::ProcessCommandLine(const AZ::CommandLine& commandLine) { + const AZStd::string activateWindowSwitchName = "activatewindow"; + if (commandLine.HasSwitch(activateWindowSwitchName)) + { + MaterialEditor::MaterialEditorWindowRequestBus::Broadcast( + &MaterialEditor::MaterialEditorWindowRequestBus::Handler::ActivateWindow); + } + const AZStd::string timeoputSwitchName = "timeout"; - if (m_commandLine.HasSwitch(timeoputSwitchName)) + if (commandLine.HasSwitch(timeoputSwitchName)) { - const AZStd::string& timeoutValue = m_commandLine.GetSwitchValue(timeoputSwitchName, 0); + const AZStd::string& timeoutValue = commandLine.GetSwitchValue(timeoputSwitchName, 0); const uint32_t timeoutInMs = atoi(timeoutValue.c_str()); AZ_Printf("MaterialEditor", "Timeout scheduled, shutting down in %u ms", timeoutInMs); QTimer::singleShot(timeoutInMs, [this] { @@ -315,10 +331,10 @@ namespace MaterialEditor // Process command line options for running one or more python scripts on startup const AZStd::string runPythonScriptSwitchName = "runpython"; - size_t runPythonScriptCount = m_commandLine.GetNumSwitchValues(runPythonScriptSwitchName); + size_t runPythonScriptCount = commandLine.GetNumSwitchValues(runPythonScriptSwitchName); for (size_t runPythonScriptIndex = 0; runPythonScriptIndex < runPythonScriptCount; ++runPythonScriptIndex) { - const AZStd::string runPythonScriptPath = m_commandLine.GetSwitchValue(runPythonScriptSwitchName, runPythonScriptIndex); + const AZStd::string runPythonScriptPath = commandLine.GetSwitchValue(runPythonScriptSwitchName, runPythonScriptIndex); AZStd::vector runPythonArgs; AZ_Printf("MaterialEditor", "Launching script: %s", runPythonScriptPath.c_str()); @@ -329,17 +345,17 @@ namespace MaterialEditor } // Process command line options for opening one or more material documents on startup - size_t openDocumentCount = m_commandLine.GetNumMiscValues(); + size_t openDocumentCount = commandLine.GetNumMiscValues(); for (size_t openDocumentIndex = 0; openDocumentIndex < openDocumentCount; ++openDocumentIndex) { - const AZStd::string openDocumentPath = m_commandLine.GetMiscValue(openDocumentIndex); + const AZStd::string openDocumentPath = commandLine.GetMiscValue(openDocumentIndex); AZ_Printf("MaterialEditor", "Opening document: %s", openDocumentPath.c_str()); MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::OpenDocument, openDocumentPath); } const AZStd::string exitAfterCommandsSwitchName = "exitaftercommands"; - if (m_commandLine.HasSwitch(exitAfterCommandsSwitchName)) + if (commandLine.HasSwitch(exitAfterCommandsSwitchName)) { ExitMainLoop(); } @@ -409,9 +425,56 @@ namespace MaterialEditor bool MaterialEditorApplication::LaunchDiscoveryService() { - const QStringList arguments = { "-fail_silently" }; + // Determine if this is the first launch of the tool by attempting to connect to a running server + if (m_socket.Connect(QApplication::applicationName())) + { + // If the server was located, the application is already running. + // Forward commandline options to other application instance. + QByteArray buffer; + buffer.append("ProcessCommandLine:"); + + // Add the command line options from this process to the message, skipping the executable path + for (int argi = 1; argi < m_argC; ++argi) + { + buffer.append(QString(m_argV[argi]).append("\n").toUtf8()); + } - return AtomToolsFramework::LaunchTool("GridHub", AZ_TRAIT_MATERIALEDITOR_EXT, arguments); + // Inject command line option to always bring the main window to the foreground + buffer.append("--activatewindow\n"); + + m_socket.Send(buffer); + m_socket.Disconnect(); + return false; + } + + // Setup server to handle basic commands + m_server.SetReadHandler([this](const QByteArray& buffer) { + // Handle commmand line params from connected socket + if (buffer.startsWith("ProcessCommandLine:")) + { + // Remove header and parse commands + AZStd::string params(buffer.data(), buffer.size()); + params = params.substr(strlen("ProcessCommandLine:")); + + AZStd::vector tokens; + AZ::StringFunc::Tokenize(params, tokens, "\n"); + + if (!tokens.empty()) + { + AZ::CommandLine commandLine; + commandLine.Parse(tokens); + ProcessCommandLine(commandLine); + } + } + }); + + // Launch local server + if (!m_server.Connect(QApplication::applicationName())) + { + return false; + } + + return true; } void MaterialEditorApplication::StartInternal() @@ -421,10 +484,14 @@ namespace MaterialEditor return; } - //[GFX TODO][ATOM-415] Try to factor out some of this stuff with AtomSampleViewerApplication - WriteStartupLog(); + if (!LaunchDiscoveryService()) + { + ExitMainLoop(); + return; + } + AzToolsFramework::AssetDatabase::AssetDatabaseRequestsBus::Handler::BusConnect(); AzToolsFramework::AssetBrowser::AssetDatabaseLocationNotificationBus::Broadcast(&AzToolsFramework::AssetBrowser::AssetDatabaseLocationNotifications::OnDatabaseInitialized); @@ -434,8 +501,6 @@ namespace MaterialEditor LoadSettings(); - LaunchDiscoveryService(); - MaterialEditorWindowNotificationBus::Handler::BusConnect(); MaterialEditor::MaterialEditorWindowFactoryRequestBus::Broadcast( @@ -450,7 +515,7 @@ namespace MaterialEditor } // Delay execution of commands and scripts post initialization - QTimer::singleShot(0, [this]() { ProcessCommandLine(); }); + QTimer::singleShot(0, [this]() { ProcessCommandLine(m_commandLine); }); } bool MaterialEditorApplication::GetAssetDatabaseLocation(AZStd::string& result) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h index 63ccbf3cec..2c66fd7c16 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h @@ -12,22 +12,20 @@ #pragma once - +#include +#include +#include +#include #include #include -#include #include - +#include #include #include #include - #include #include -#include -#include - #include #include @@ -51,7 +49,7 @@ namespace MaterialEditor using Base = AzFramework::Application; MaterialEditorApplication(int* argc, char*** argv); - virtual ~MaterialEditorApplication() = default; + virtual ~MaterialEditorApplication(); ////////////////////////////////////////////////////////////////////////// // AzFramework::Application @@ -110,7 +108,7 @@ namespace MaterialEditor void CompileCriticalAssets(); - void ProcessCommandLine(); + void ProcessCommandLine(const AZ::CommandLine& commandLine); void WriteStartupLog(); void LoadSettings(); @@ -138,5 +136,8 @@ namespace MaterialEditor bool m_activatedLocalUserSettings = false; QTimer m_timer; + + AtomToolsFramework::LocalSocket m_socket; + AtomToolsFramework::LocalServer m_server; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp index d6f2092d27..abaf50804f 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp @@ -508,6 +508,17 @@ namespace MaterialEditor return m_fieldOfView; } + void MaterialViewportComponent::SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) + { + m_displayMapperOperationType = operationType; + MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnDisplayMapperOperationTypeChanged, operationType); + } + + AZ::Render::DisplayMapperOperationType MaterialViewportComponent::GetDisplayMapperOperationType() const + { + return m_displayMapperOperationType; + } + void MaterialViewportComponent::OnCatalogLoaded([[maybe_unused]] const char* catalogFile) { AZ::TickBus::QueueFunction([this]() { diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h index 036974e123..8332cb862c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h @@ -12,6 +12,8 @@ #pragma once +#include + #include #include @@ -85,6 +87,8 @@ namespace MaterialEditor bool GetAlternateSkyboxEnabled() const override; void SetFieldOfView(float fieldOfView) override; float GetFieldOfView() const override; + void SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) override; + AZ::Render::DisplayMapperOperationType GetDisplayMapperOperationType() const override; //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// @@ -111,5 +115,6 @@ namespace MaterialEditor bool m_gridEnabled = true; bool m_alternateSkyboxEnabled = false; float m_fieldOfView = 90.0f; + AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; }; } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp index 53a2dc2ce6..5939a40db6 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -147,9 +148,11 @@ namespace MaterialEditor m_postProcessEntity->Activate(); // Init directional light processor - m_directionalLightFeatureProcessor = m_scene->GetFeatureProcessor(); + // Init display mapper processor + m_displayMapperFeatureProcessor = m_scene->GetFeatureProcessor(); + // Init Skybox m_skyboxFeatureProcessor = m_scene->GetFeatureProcessor(); @@ -423,6 +426,13 @@ namespace MaterialEditor MaterialEditorViewportInputControllerRequestBus::Broadcast(&MaterialEditorViewportInputControllerRequestBus::Handler::SetFieldOfView, fieldOfView); } + void MaterialViewportRenderer::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) + { + AZ::Render::DisplayMapperConfigurationDescriptor desc; + desc.m_operationType = operationType; + m_displayMapperFeatureProcessor->RegisterDisplayMapperConfiguration(desc); + } + void MaterialViewportRenderer::OnAssetReady(AZ::Data::Asset asset) { if (m_modelAssetId == asset.GetId()) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h index e014d9eada..744a887396 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h @@ -27,6 +27,11 @@ namespace AZ { + namespace Render + { + class DisplayMapperFeatureProcessorInterface; + } + class Entity; class Component; @@ -71,6 +76,7 @@ namespace MaterialEditor void OnGridEnabledChanged(bool enable) override; void OnAlternateSkyboxEnabledChanged(bool enable) override; void OnFieldOfViewChanged(float fieldOfView) override; + void OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) override; // AZ::Data::AssetBus::Handler interface overrides... void OnAssetReady(AZ::Data::Asset asset) override; @@ -92,6 +98,7 @@ namespace MaterialEditor AZ::RPI::RenderPipelinePtr m_renderPipeline; AZ::RPI::ScenePtr m_scene; AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr; + AZ::Render::DisplayMapperFeatureProcessorInterface* m_displayMapperFeatureProcessor = nullptr; AZ::Entity* m_cameraEntity = nullptr; AZ::Component* m_cameraComponent = nullptr; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 1e116b4a22..6e47de189c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -129,6 +129,12 @@ namespace MaterialEditor MaterialEditorWindowRequestBus::Handler::BusDisconnect(); } + void MaterialEditorWindow::ActivateWindow() + { + activateWindow(); + raise(); + } + bool MaterialEditorWindow::AddDockWidget(const AZStd::string& name, QWidget* widget, uint32_t area, uint32_t orientation) { auto dockWidgetItr = m_dockWidgets.find(name); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h index 6bd6e6b165..778e11275f 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h @@ -61,6 +61,7 @@ namespace MaterialEditor private: // MaterialEditorWindowRequestBus::Handler overrides... + void ActivateWindow() override; bool AddDockWidget(const AZStd::string& name, QWidget* widget, uint32_t area, uint32_t orientation) override; void RemoveDockWidget(const AZStd::string& name) override; void SetDockWidgetVisible(const AZStd::string& name, bool visible) override; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp index a1ff8da635..820cee30f9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp @@ -50,6 +50,7 @@ namespace MaterialEditor ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) ->Attribute(AZ::Script::Attributes::Category, "Editor") ->Attribute(AZ::Script::Attributes::Module, "materialeditor") + ->Event("ActivateWindow", &MaterialEditorWindowRequestBus::Events::ActivateWindow) ->Event("SetDockWidgetVisible", &MaterialEditorWindowRequestBus::Events::SetDockWidgetVisible) ->Event("IsDockWidgetVisible", &MaterialEditorWindowRequestBus::Events::IsDockWidgetVisible) ->Event("GetDockWidgetNames", &MaterialEditorWindowRequestBus::Events::GetDockWidgetNames) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp index dad4a34b1e..2af73bf436 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp @@ -38,7 +38,7 @@ namespace MaterialEditor m_toggleGrid->setCheckable(true); connect(m_toggleGrid, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_toggleGrid->isChecked()); - }); + }); bool enableGrid = false; MaterialViewportRequestBus::BroadcastResult(enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); m_toggleGrid->setChecked(enableGrid); @@ -49,31 +49,39 @@ namespace MaterialEditor connect(m_toggleShadowCatcher, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast( &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_toggleShadowCatcher->isChecked()); - }); + }); bool enableShadowCatcher = false; MaterialViewportRequestBus::BroadcastResult(enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); m_toggleShadowCatcher->setChecked(enableShadowCatcher); // Add mapping selection button - //[GFX TODO][ATOM-3992] + QToolButton* toneMappingButton = new QToolButton(this); QMenu* toneMappingMenu = new QMenu(toneMappingButton); - toneMappingMenu->addAction("None", [this]() { - MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "None"); - }); - toneMappingMenu->addAction("Gamma2.2", [this]() { - MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "Gamma2.2"); - }); - toneMappingMenu->addAction("ACES", [this]() { - MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "ACES"); - }); + + m_operationNames = + { + { AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard" }, + { AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB" }, + { AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough" }, + { AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut" }, + { AZ::Render::DisplayMapperOperationType::Aces, "Aces" } + }; + for (auto operationNamePair : m_operationNames) + { + m_operationActions[operationNamePair.first] = toneMappingMenu->addAction(operationNamePair.second, [operationNamePair]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, + operationNamePair.first); + }); + m_operationActions[operationNamePair.first]->setCheckable(true); + } + m_operationActions[AZ::Render::DisplayMapperOperationType::Aces]->setChecked(true); toneMappingButton->setMenu(toneMappingMenu); toneMappingButton->setText("Tone Mapping"); toneMappingButton->setIcon(QIcon(":/Icons/toneMapping.svg")); toneMappingButton->setPopupMode(QToolButton::InstantPopup); - - // hiding button until DisplayMapper supports changing settings at run time - toneMappingButton->setVisible(false); + toneMappingButton->setVisible(true); addWidget(toneMappingButton); // Add model combo box @@ -99,6 +107,14 @@ namespace MaterialEditor m_toggleGrid->setChecked(enable); } + void MaterialEditorToolBar::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) + { + for (auto operationActionPair : m_operationActions) + { + operationActionPair.second->setChecked(operationActionPair.first == operationType); + } + } + void MaterialEditorToolBar::OnShadowCatcherEnabledChanged(bool enable) { m_toggleShadowCatcher->setChecked(enable); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h index 147608bc23..25077c1868 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h @@ -33,8 +33,12 @@ namespace MaterialEditor // MaterialViewportNotificationBus::Handler overrides... void OnShadowCatcherEnabledChanged([[maybe_unused]] bool enable) override; void OnGridEnabledChanged([[maybe_unused]] bool enable) override; + void OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) override; QAction* m_toggleGrid = {}; QAction* m_toggleShadowCatcher = {}; + + AZStd::unordered_map m_operationNames; + AZStd::unordered_map m_operationActions; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp index 8efed36197..fd50ace918 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp @@ -36,6 +36,7 @@ namespace MaterialEditor ->Field("enableShadowCatcher", &GeneralViewportSettings::m_enableShadowCatcher) ->Field("enableAlternateSkybox", &GeneralViewportSettings::m_enableAlternateSkybox) ->Field("fieldOfView", &GeneralViewportSettings::m_fieldOfView) + ->Field("displayMapperOperationType", &GeneralViewportSettings::m_displayMapperOperationType) ; if (auto editContext = serializeContext->GetEditContext()) @@ -50,6 +51,12 @@ namespace MaterialEditor ->DataElement(AZ::Edit::UIHandlers::Slider, &GeneralViewportSettings::m_fieldOfView, "Field Of View", "") ->Attribute(AZ::Edit::Attributes::Min, 60.0f) ->Attribute(AZ::Edit::Attributes::Max, 120.0f) + ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralViewportSettings::m_displayMapperOperationType, "Display Mapper Type", "") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Aces, "Aces") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard") ; } } @@ -66,6 +73,7 @@ namespace MaterialEditor ->Property("enableShadowCatcher", BehaviorValueProperty(&GeneralViewportSettings::m_enableShadowCatcher)) ->Property("enableAlternateSkybox", BehaviorValueProperty(&GeneralViewportSettings::m_enableAlternateSkybox)) ->Property("fieldOfView", BehaviorValueProperty(&GeneralViewportSettings::m_fieldOfView)) + ->Property("displayMapperOperationType", BehaviorValueProperty(&GeneralViewportSettings::m_displayMapperOperationType)) ; } } @@ -298,6 +306,7 @@ namespace MaterialEditor MaterialViewportRequestBus::BroadcastResult( m_generalSettings.m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled); MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); + MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); AtomToolsFramework::InspectorWidget::Reset(); @@ -343,6 +352,12 @@ namespace MaterialEditor RefreshGroup("general"); } + void ViewportSettingsInspector::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) + { + m_generalSettings.m_displayMapperOperationType = operationType; + RefreshGroup("general"); + } + void ViewportSettingsInspector::BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) { AZ_UNUSED(pNode); @@ -370,6 +385,7 @@ namespace MaterialEditor MaterialViewportRequestBus::Broadcast( &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_generalSettings.m_enableAlternateSkybox); MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_generalSettings.m_fieldOfView); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_generalSettings.m_displayMapperOperationType); } AZStd::string ViewportSettingsInspector::GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h index 08e22a380c..c61acb2e4c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h @@ -13,6 +13,7 @@ #pragma once #if !defined(Q_MOC_RUN) +#include #include #include #include @@ -32,6 +33,7 @@ namespace MaterialEditor bool m_enableShadowCatcher = true; bool m_enableAlternateSkybox = false; float m_fieldOfView = 90.0f; + AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; }; //! Provides controls for viewing and editing a material document settings. @@ -74,6 +76,7 @@ namespace MaterialEditor void OnGridEnabledChanged(bool enable) override; void OnAlternateSkyboxEnabledChanged(bool enable) override; void OnFieldOfViewChanged(float fieldOfView) override; + void OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) override; // AzToolsFramework::IPropertyEditorNotify overrides... void BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) override; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp index 92d76c4373..8c55adba46 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp @@ -1,30 +1,31 @@ /* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#if !defined(Q_MOC_RUN) +#include #include #include -#include -#include #include -#include #include -#include -#include +#include +#include #include +#include +#include -#include #include - -#include +#include +#endif int main(int argc, char** argv) { @@ -45,15 +46,16 @@ int main(int argc, char** argv) AzQtComponents::Utilities::HandleDpiAwareness(AzQtComponents::Utilities::SystemDpiAware); MaterialEditor::MaterialEditorApplication app(&argc, &argv); + + auto globalEventFilter = new AzQtComponents::GlobalEventFilter(&app); + app.installEventFilter(globalEventFilter); + AZ::IO::FixedMaxPath engineRootPath; if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr) { settingsRegistry->Get(engineRootPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder); } - auto globalEventFilter = new AzQtComponents::GlobalEventFilter(&app); - app.installEventFilter(globalEventFilter); - AzQtComponents::StyleManager styleManager(&app); styleManager.initialize(&app, engineRootPath); diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp index f2fd70c0e6..50b2cbb53a 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentModule.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ namespace ShaderManagementConsole return AZ::ComponentTypeList{ azrtti_typeid(), azrtti_typeid(), - azrtti_typeid(), }; } } diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp index f0d72c61c3..31dabe2bac 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.cpp @@ -105,7 +105,6 @@ namespace ShaderManagementConsole void ShaderManagementConsoleDocumentSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { - required.push_back(AZ_CRC("TargetManagerService", 0x6d5708bc)); required.push_back(AZ_CRC("AssetProcessorToolsConnection", 0x734669bc)); required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601)); required.push_back(AZ_CRC("PropertyManagerService", 0x63a3d7ad)); @@ -130,13 +129,11 @@ namespace ShaderManagementConsole { m_documentMap.clear(); ShaderManagementConsoleDocumentSystemRequestBus::Handler::BusConnect(); - AzFramework::TmMsgBus::Handler::BusConnect(AZ_CRC("OpenInShaderManagementConsole", 0x9f92aac8)); } void ShaderManagementConsoleDocumentSystemComponent::Deactivate() { ShaderManagementConsoleDocumentSystemRequestBus::Handler::BusDisconnect(); - AzFramework::TmMsgBus::Handler::BusDisconnect(); m_documentMap.clear(); } @@ -159,19 +156,6 @@ namespace ShaderManagementConsole return m_documentMap.erase(documentId) != 0; } - void ShaderManagementConsoleDocumentSystemComponent::OnReceivedMsg(AzFramework::TmMsgPtr msg) - { - if (msg->GetId() == AZ_CRC("OpenInShaderManagementConsole", 0x9f92aac8)) - { - const char* documentPath = reinterpret_cast(msg->GetCustomBlob()); - ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::OpenDocument, documentPath); - } - else - { - AZ_Assert(false, "We received a message of an unrecognized class type!"); - } - } - AZ::Uuid ShaderManagementConsoleDocumentSystemComponent::OpenDocument(AZStd::string_view path) { return OpenDocumentImpl(path, true); diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h index 60c205aa72..2bd7306b8b 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Document/ShaderManagementConsoleDocumentSystemComponent.h @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -30,7 +29,6 @@ namespace ShaderManagementConsole //! ShaderManagementConsoleDocumentSystemComponent is the central component of the Shader Management Console Core gem class ShaderManagementConsoleDocumentSystemComponent : public AZ::Component - , private AzFramework::TmMsgBus::Handler , private ShaderManagementConsoleDocumentSystemRequestBus::Handler { public: @@ -55,11 +53,6 @@ namespace ShaderManagementConsole void Deactivate() override; //////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // TmMsgBus::Handler overrides... - void OnReceivedMsg(AzFramework::TmMsgPtr msg) override; - ////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// // ShaderManagementConsoleDocumentSystemRequestBus::Handler overrides... AZ::Uuid CreateDocument() override; diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeEditorModule.cpp b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeEditorModule.cpp index c955523d09..f2c2a6f5aa 100644 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeEditorModule.cpp +++ b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeEditorModule.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include "./Editor/AssetCollectionAsyncLoaderTestComponent.h" @@ -33,7 +32,6 @@ namespace AZ { // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. m_descriptors.insert(m_descriptors.end(), { - BuilderComponent::CreateDescriptor(), AssetCollectionAsyncLoaderTestComponent::CreateDescriptor(), }); } diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp index 1998642a02..90731488f4 100644 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp +++ b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp @@ -62,12 +62,10 @@ namespace AZ AtomBridgeSystemComponent::AtomBridgeSystemComponent() { - AZ::Interface::Register(this); } AtomBridgeSystemComponent::~AtomBridgeSystemComponent() { - AZ::Interface::Unregister(this); } void AtomBridgeSystemComponent::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided) @@ -146,15 +144,6 @@ namespace AZ { static const AZ::Uuid legacyRenderComponentUuids[] = { AZ::Uuid("{FC315B86-3280-4D03-B4F0-5553D7D08432}"), // EditorMeshComponent - AZ::Uuid("{4B85E77D-91F9-40C5-8FCB-B494000A9E69}"), // EditorLensFlareComponent - AZ::Uuid("{7C18B273-5BA3-4E0F-857D-1F30BD6B0733}"), // EditorLightComponent - AZ::Uuid("{00818135-138D-42AD-8657-FF3FD38D9E7A}"), // EditorPointLightComponent - AZ::Uuid("{1DE624B1-876F-4E0A-96A6-7B248FA2076F}"), // EditorAreaLightComponent - AZ::Uuid("{41928E34-B558-4559-82CF-8B5795A38CB4}"), // EditorProjectorLightComponent - AZ::Uuid("{BA3890BD-D2E7-4DB6-95CD-7E7D5525567A}"), // EditorDecalComponent - AZ::Uuid("{8DBD6035-583E-409F-AFD9-F36829A0655D}"), // EditorEnvProbeComponent - AZ::Uuid("{9C86E09D-0727-476E-A4A1-25989CDBF9C6}"), // EditorHighQualityShadowComponent - AZ::Uuid("{045C0C58-C13E-49B0-A471-D4AC5D3FC6BD}"), // EditorGeometryCacheComponent }; const AZStd::string deprecatedString = " (DEPRECATED By Atom)"; diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.h b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.h index 2ffd966216..da75d3c35c 100644 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.h +++ b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.h @@ -17,7 +17,6 @@ #include -#include #include #include @@ -37,7 +36,6 @@ namespace AZ class AtomBridgeSystemComponent : public Component - , public AzFramework::AtomActiveInterface , public AzFramework::Render::RenderSystemRequestBus::Handler , public AzFramework::Components::DeprecatedComponentsRequestBus::Handler , public Render::Bootstrap::NotificationBus::Handler diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.cpp b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.cpp index bee6d31275..8a063cd7a7 100644 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.cpp +++ b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.cpp @@ -244,9 +244,6 @@ namespace AZ::AtomBridge } //////////////////////////////////////////////////////////////////////// - // Partial implementation of the DebugDisplayRequestBus on Atom. - // Commented out function prototypes are waiting to be implemented. - // work tracked in [ATOM-3459] AtomDebugDisplayViewportInterface::AtomDebugDisplayViewportInterface(AZ::RPI::ViewportContextPtr viewportContextPtr) { ResetRenderState(); @@ -272,9 +269,8 @@ namespace AZ::AtomBridge InitInternal(scene, nullptr); } - void AtomDebugDisplayViewportInterface::InitInternal(RPI::Scene* scene, AZ::RPI::ViewportContextPtr viewportContextPtr) + void AtomDebugDisplayViewportInterface::UpdateAuxGeom(RPI::Scene* scene, AZ::RPI::View* view) { - AzFramework::DebugDisplayRequestBus::Handler::BusDisconnect(m_viewportId); if (!scene) { m_auxGeomPtr = nullptr; @@ -286,20 +282,46 @@ namespace AZ::AtomBridge m_auxGeomPtr = nullptr; return; } - if (m_defaultInstance) + // default instance draws to all viewports in the default scene + if (m_defaultInstance || !view) { m_auxGeomPtr = auxGeomFP->GetDrawQueue(); } else { - m_auxGeomPtr = auxGeomFP->GetOrCreateDrawQueueForView(viewportContextPtr->GetDefaultView().get()); + // cache the aux geom draw interface for the current view (aka camera) + m_auxGeomPtr = auxGeomFP->GetOrCreateDrawQueueForView(view); } + } + + void AtomDebugDisplayViewportInterface::InitInternal(RPI::Scene* scene, AZ::RPI::ViewportContextPtr viewportContextPtr) + { + AzFramework::DebugDisplayRequestBus::Handler::BusDisconnect(m_viewportId); + UpdateAuxGeom(scene, viewportContextPtr ? viewportContextPtr->GetDefaultView().get() : nullptr); AzFramework::DebugDisplayRequestBus::Handler::BusConnect(m_viewportId); + if (!m_defaultInstance) // only the per viewport instances need to listen for viewport changes + { + AZ::RPI::ViewportContextIdNotificationBus::Handler::BusConnect(viewportContextPtr->GetId()); + } + } + + + void AtomDebugDisplayViewportInterface::OnViewportDefaultViewChanged(AZ::RPI::ViewPtr view) + { + ResetRenderState(); + if (!m_defaultInstance) + { + // handle viewport update (view change, scene change, etc + auto viewportContextManager = AZ::Interface::Get(); + AZ::RPI::ViewportContextPtr viewportContextPtr = viewportContextManager->GetViewportContextById(m_viewportId); + UpdateAuxGeom(viewportContextPtr->GetRenderScene().get(), viewportContextPtr->GetDefaultView().get()); + } } AtomDebugDisplayViewportInterface::~AtomDebugDisplayViewportInterface() { AzFramework::DebugDisplayRequestBus::Handler::BusDisconnect(m_viewportId); + AZ::RPI::ViewportContextIdNotificationBus::Handler::BusDisconnect(); m_viewportId = AzFramework::InvalidViewportId; m_auxGeomPtr = nullptr; } @@ -1234,8 +1256,15 @@ namespace AZ::AtomBridge int srcOffsetX [[maybe_unused]], int srcOffsetY [[maybe_unused]]) { + // abort draw if draw is invalid or font query interface is missing. + if (!text || size == 0.0f || !AZ::Interface::Get()) + { + return; + } + AzFramework::FontDrawInterface* fontDrawInterface = AZ::Interface::Get()->GetDefaultFontDrawInterface(); - if (!fontDrawInterface || !text || size == 0.0f) + // abort draw if font draw interface is missing + if (!fontDrawInterface) { return; } @@ -1263,13 +1292,15 @@ namespace AZ::AtomBridge const char* text, bool center) { - auto fontQueryInterface = AZ::Interface::Get(); - if (!fontQueryInterface) + // abort draw if draw is invalid or font query interface is missing. + if (!text || size == 0.0f || !AZ::Interface::Get()) { return; } - AzFramework::FontDrawInterface* fontDrawInterface = fontQueryInterface->GetDefaultFontDrawInterface(); - if (!fontDrawInterface || !text || size == 0.0f) + + AzFramework::FontDrawInterface* fontDrawInterface = AZ::Interface::Get()->GetDefaultFontDrawInterface(); + // abort draw if font draw interface is missing + if (!fontDrawInterface) { return; } diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.h b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.h index 021d816ca4..c872e2b81e 100644 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.h +++ b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomDebugDisplayViewportInterface.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace AZ::AtomBridge { @@ -121,6 +122,7 @@ namespace AZ::AtomBridge class AtomDebugDisplayViewportInterface final : public AzFramework::DebugDisplayRequestBus::Handler + , public AZ::RPI::ViewportContextIdNotificationBus::Handler { public: AZ_RTTI(AtomDebugDisplayViewportInterface, "{09AF6A46-0100-4FBF-8F94-E6B221322D14}", AzFramework::DebugDisplayRequestBus::Handler); @@ -198,6 +200,12 @@ namespace AZ::AtomBridge void PopMatrix() override; private: + + // ViewportContextIdNotificationBus handlers + void OnViewportDefaultViewChanged(AZ::RPI::ViewPtr view) override; + + + // internal helper functions using LineSegmentFilterFunc = AZStd::function; enum CircleAxis { @@ -245,6 +253,7 @@ namespace AZ::AtomBridge const AZ::Matrix3x4& GetCurrentTransform() const; + void UpdateAuxGeom(RPI::Scene* scene, AZ::RPI::View* view); void InitInternal(RPI::Scene* scene, AZ::RPI::ViewportContextPtr viewportContextPtr); AZ::RPI::ViewportContextPtr GetViewportContext() const; @@ -254,10 +263,12 @@ namespace AZ::AtomBridge RenderState m_rendState; AZ::RPI::AuxGeomDrawPtr m_auxGeomPtr; - bool m_defaultInstance = false; // only true for drawing to a particular viewport. What would 2D drawing mean in a scene with several windows? + + // m_defaultInstance is true for the instance that multicasts the debug draws to all viewports + // (with an AuxGeom render pass) in the default scene. + bool m_defaultInstance = false; AzFramework::ViewportId m_viewportId = AzFramework::InvalidViewportId; // Address this instance answers on. - AZ::RPI::ViewportContext::SceneChangedEvent::Handler - m_sceneChangeHandler; + AZ::RPI::ViewportContext::SceneChangedEvent::Handler m_sceneChangeHandler; }; // this is duplicated from Cry_Math.h, GetBasisVectors. diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/BuilderComponent.cpp b/Gems/AtomLyIntegration/AtomBridge/Code/Source/BuilderComponent.cpp deleted file mode 100644 index b6ff2cb66d..0000000000 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/BuilderComponent.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include -#include -#include -#include - -#include - -#include - -namespace AZ -{ - namespace AtomBridge - { - void BuilderComponent::Reflect(AZ::ReflectContext* context) - { - if (auto* serialize = azrtti_cast(context)) - { - serialize->Class() - ->Version(0) - ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector({ AssetBuilderSDK::ComponentTags::AssetBuilder })) - ; - } - } - - BuilderComponent::BuilderComponent() - { - AZ::Interface::Register(this); - } - - BuilderComponent::~BuilderComponent() - { - AZ::Interface::Unregister(this); - } - - void BuilderComponent::Activate() - { - } - - void BuilderComponent::Deactivate() - { - } - } // namespace RPI -} // namespace AZ diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/BuilderComponent.h b/Gems/AtomLyIntegration/AtomBridge/Code/Source/BuilderComponent.h deleted file mode 100644 index 4e75fd2a88..0000000000 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/BuilderComponent.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace AZ -{ - namespace AtomBridge - { - class BuilderComponent final - : public AZ::Component - , public AzFramework::AtomActiveInterface - { - public: - AZ_COMPONENT(BuilderComponent, "{D1FE015B-8431-4155-8FD0-8197F246901A}"); - static void Reflect(AZ::ReflectContext* context); - - BuilderComponent(); - ~BuilderComponent() override; - - // AZ::Component overrides... - void Activate() override; - void Deactivate() override; - }; - } // namespace RPI -} // namespace AZ diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/atombridge_editor_files.cmake b/Gems/AtomLyIntegration/AtomBridge/Code/atombridge_editor_files.cmake index f2cf8c6c14..55ed9f28a0 100644 --- a/Gems/AtomLyIntegration/AtomBridge/Code/atombridge_editor_files.cmake +++ b/Gems/AtomLyIntegration/AtomBridge/Code/atombridge_editor_files.cmake @@ -13,8 +13,6 @@ set(FILES Source/AtomBridgeEditorModule.cpp Source/AtomBridgeModule.cpp Source/AtomBridgeModule.h - Source/BuilderComponent.cpp - Source/BuilderComponent.h Source/Editor/AssetCollectionAsyncLoaderTestComponent.cpp Source/Editor/AssetCollectionAsyncLoaderTestComponent.h ) diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h index 8e60cc2055..fd66534197 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h @@ -226,7 +226,7 @@ namespace AZ private: virtual ~FFont(); - bool InitFont(); + bool InitFont(AZ::RPI::Scene* renderScene); bool InitTexture(); bool InitCache(); diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.cpp index b1275b5b3b..dec52234bb 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.cpp @@ -65,27 +65,38 @@ namespace AZ void AtomFontSystemComponent::Activate() { - AZ::CryFontCreationRequestBus::Handler::BusConnect(); + CrySystemEventBus::Handler::BusConnect(); } void AtomFontSystemComponent::Deactivate() { - AZ::CryFontCreationRequestBus::Handler::BusDisconnect(); + CrySystemEventBus::Handler::BusDisconnect(); } - bool AtomFontSystemComponent::CreateCryFont(SSystemGlobalEnvironment& env, [[maybe_unused]] const SSystemInitParams& initParams) + void LoadFont(ICryFont& cryFont, const AZStd::string& fontName) + { + IFFont* font = cryFont.NewFont(fontName.c_str()); + AZ_Assert(font, "Could not instantiate font: %s", fontName.c_str()); + + const AZStd::string fontPath = "Fonts/" + fontName + ".font"; + if (!font->Load(fontPath.c_str())) + { + AZ_Error("AtomFont", false, "Could not load font: %s", fontPath.c_str()); + } + } + + void AtomFontSystemComponent::OnCrySystemInitialized(ISystem& system, const SSystemInitParams&) { - ISystem* system = env.pSystem; #if !defined(AZ_MONOLITHIC_BUILD) // When module is linked dynamically, we must set our gEnv pointer. // When module is linked statically, we'll share the application's gEnv pointer. - gEnv = system->GetGlobalEnvironment(); + gEnv = system.GetGlobalEnvironment(); #endif - if (env.IsDedicated()) + if (gEnv->IsDedicated()) { #if defined(USE_NULLFONT) - env.pCryFont = new AtomNullFont(); + gEnv->pCryFont = new AtomNullFont(); #else // The NULL font implementation must be present for all platforms // supporting running as a pure dedicated server. @@ -96,12 +107,17 @@ namespace AZ else { #if defined(USE_NULLFONT) && defined(USE_NULLFONT_ALWAYS) - env.pCryFont = new AtomNullFont(); + gEnv->pCryFont = new AtomNullFont(); #else - env.pCryFont = new AtomFont(system); + gEnv->pCryFont = new AtomFont(&system); #endif } - return env.pCryFont != 0; + + if (gEnv->pCryFont) + { + LoadFont(*gEnv->pCryFont, "default"); + LoadFont(*gEnv->pCryFont, "default-ui"); + } } void AtomFontSystemComponent::OnCrySystemShutdown([[maybe_unused]] ISystem& system) diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.h b/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.h index 23ce20c307..05e30661f2 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFontSystemComponent.h @@ -13,7 +13,6 @@ #include -#include #include namespace AZ @@ -22,7 +21,6 @@ namespace AZ { class AtomFontSystemComponent : public AZ::Component - , private AZ::CryFontCreationRequestBus::Handler , private CrySystemEventBus::Handler { public: @@ -43,12 +41,12 @@ namespace AZ //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// - // CryFontCreationBus - bool CreateCryFont(SSystemGlobalEnvironment& env, const SSystemInitParams& initParams) override; + // CrySystemEventBus + void OnCrySystemInitialized(ISystem& system, const SSystemInitParams& initParams); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// - // CryFontCreationBus + // CrySystemEventBus void OnCrySystemShutdown(ISystem& system) override; //////////////////////////////////////////////////////////////////////// }; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp index 20879876e7..40684640d6 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp @@ -99,8 +99,13 @@ AZ::RPI::WindowContextSharedPtr AZ::FFont::GetDefaultWindowContext() const return {}; } -bool AZ::FFont::InitFont() +bool AZ::FFont::InitFont(AZ::RPI::Scene* renderScene) { + if (!renderScene) + { + return false; + } + auto initializationState = InitializationState::Uninitialized; // Do an atomic transition to Initializing if we're in the Uninitialized state. // Otherwise, check the current state. @@ -112,7 +117,7 @@ bool AZ::FFont::InitFont() } // Create and initialize DynamicDrawContext for font draw - AZ::RPI::Ptr dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(GetDefaultViewportContext()->GetRenderScene().get()); + AZ::RPI::Ptr dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(renderScene); // Save draw srg input indices for later use Data::Instance drawSrg = dynamicDraw->NewDrawSrg(); @@ -299,7 +304,7 @@ void AZ::FFont::DrawStringUInternal( const TextDrawContext& ctx) { // Lazily ensure we're initialized before attempting to render. - if (!InitFont()) + if (!viewportContext || !InitFont(viewportContext->GetRenderScene().get())) { return; } @@ -1623,7 +1628,7 @@ void AZ::FFont::ScaleCoord(const RHI::Viewport& viewport, float& x, float& y) co void AZ::FFont::OnBootstrapSceneReady([[maybe_unused]] AZ::RPI::Scene* bootstrapScene) { - InitFont(); + InitFont(bootstrapScene); } static void SetCommonContextFlags(AZ::TextDrawContext& ctx, const AzFramework::TextDrawParameters& params) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/AttachmentComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/AttachmentComponent.cpp new file mode 100644 index 0000000000..138d619d97 --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/AttachmentComponent.cpp @@ -0,0 +1,355 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#include "AttachmentComponent.h" +#include +#include +#include +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + /// Behavior Context handler for AttachmentComponentNotificationBus + class BehaviorAttachmentComponentNotificationBusHandler : public LmbrCentral::AttachmentComponentNotificationBus::Handler, + public AZ::BehaviorEBusHandler + { + public: + AZ_EBUS_BEHAVIOR_BINDER( + BehaviorAttachmentComponentNotificationBusHandler, "{636B95A0-5C7D-4EE7-8645-955665315451}", AZ::SystemAllocator, + OnAttached, OnDetached); + + void OnAttached(AZ::EntityId id) override + { + Call(FN_OnAttached, id); + } + + void OnDetached(AZ::EntityId id) override + { + Call(FN_OnDetached, id); + } + }; + + void AttachmentConfiguration::Reflect(AZ::ReflectContext* context) + { + AZ::SerializeContext* serializeContext = azrtti_cast(context); + if (serializeContext) + { + serializeContext->Class() + ->Version(1) + ->Field("Target ID", &AttachmentConfiguration::m_targetId) + ->Field("Target Bone Name", &AttachmentConfiguration::m_targetBoneName) + ->Field("Target Offset", &AttachmentConfiguration::m_targetOffset) + ->Field("Attached Initially", &AttachmentConfiguration::m_attachedInitially) + ->Field("Scale Source", &AttachmentConfiguration::m_scaleSource); + } + AZ::BehaviorContext* behaviorContext = azrtti_cast(context); + if (behaviorContext) + { + behaviorContext->EBus("AttachmentComponentRequestBus") + ->Event("Attach", &LmbrCentral::AttachmentComponentRequestBus::Events::Attach) + ->Event("Detach", &LmbrCentral::AttachmentComponentRequestBus::Events::Detach) + ->Event("SetAttachmentOffset", &LmbrCentral::AttachmentComponentRequestBus::Events::SetAttachmentOffset); + + behaviorContext->EBus("AttachmentComponentNotificationBus") + ->Handler(); + } + } + + void AttachmentComponent::Reflect(AZ::ReflectContext* context) + { + AttachmentConfiguration::Reflect(context); + + AZ::SerializeContext* serializeContext = azrtti_cast(context); + if (serializeContext) + { + serializeContext->Class()->Version(1)->Field( + "Configuration", &AttachmentComponent::m_initialConfiguration); + } + } + + //========================================================================= + // BoneFollower + //========================================================================= + + void BoneFollower::Activate(AZ::Entity* owner, const AttachmentConfiguration& configuration, bool targetCanAnimate) + { + AZ_Assert(owner, "owner is required"); + AZ_Assert(!m_ownerId.IsValid(), "BoneFollower is already Activated"); + + m_ownerId = owner->GetId(); + m_targetCanAnimate = targetCanAnimate; + m_isUpdatingOwnerTransform = false; + m_scaleSource = configuration.m_scaleSource; + + m_cachedOwnerTransform = AZ::Transform::CreateIdentity(); + EBUS_EVENT_ID_RESULT(m_cachedOwnerTransform, m_ownerId, AZ::TransformBus, GetWorldTM); + + if (configuration.m_attachedInitially) + { + Attach(configuration.m_targetId, configuration.m_targetBoneName.c_str(), configuration.m_targetOffset); + } + + LmbrCentral::AttachmentComponentRequestBus::Handler::BusConnect(m_ownerId); + } + + void BoneFollower::Deactivate() + { + AZ_Assert(m_ownerId.IsValid(), "BoneFollower was never Activated"); + + LmbrCentral::AttachmentComponentRequestBus::Handler::BusDisconnect(); + Detach(); + m_ownerId.SetInvalid(); + } + + AZ::EntityId BoneFollower::GetTargetEntityId() + { + return m_targetId; + } + + AZ::Transform BoneFollower::GetOffset() + { + return m_targetOffset; + } + + void BoneFollower::Attach(AZ::EntityId targetId, const char* targetBoneName, const AZ::Transform& offset) + { + AZ_Assert(m_ownerId.IsValid(), "BoneFollower must be Activated to use.") + + // safe to try and detach, even if we weren't attached + Detach(); + + if (!targetId.IsValid()) + { + return; + } + + if (targetId == m_ownerId) + { + AZ_Error("Attachment Component", false, "AttachmentComponent cannot target itself"); + return; + } + + // Note: the target entity may not be activated yet. That's ok. + // When mesh is ready we are notified via MeshComponentEvents::OnModelReady + // When transform is ready we are notified via TransformNotificationBus::OnTransformChanged + + m_targetId = targetId; + m_targetBoneName = targetBoneName; + m_targetOffset = offset; + + BindTargetBone(); + + m_targetBoneTransform = AZ::Transform::Identity(); + + m_isTargetEntityTransformKnown = false; // target's transform may not be available yet + + AZ::TransformBus::EventResult( + m_cachedOwnerTransform, m_ownerId, &AZ::TransformBus::Events::GetWorldTM); // owner query will always succeed + + MeshComponentNotificationBus::Handler::BusConnect(m_targetId); // fires OnModelReady if asset is already ready + AZ::TransformNotificationBus::Handler::BusConnect(m_targetId); + if (m_targetCanAnimate) + { + // Only register for per-frame updates when target can animate + AZ::TickBus::Handler::BusConnect(); + } + + // update owner's transform + UpdateOwnerTransformIfNecessary(); + + // alert others that we've attached + LmbrCentral::AttachmentComponentNotificationBus::Event(m_targetId, &LmbrCentral::AttachmentComponentNotificationBus::Events::OnAttached, m_ownerId); + } + + void BoneFollower::Detach() + { + AZ_Assert(m_ownerId.IsValid(), "BoneFollower must be Activated to use."); + + if (m_targetId.IsValid()) + { + // alert others that we're detaching + EBUS_EVENT_ID(m_targetId, LmbrCentral::AttachmentComponentNotificationBus, OnDetached, m_ownerId); + + MeshComponentNotificationBus::Handler::BusDisconnect(); + AZ::TransformNotificationBus::Handler::BusDisconnect(m_targetId); + AZ::TickBus::Handler::BusDisconnect(); + + m_targetId.SetInvalid(); + } + } + + const char* BoneFollower::GetJointName() + { + return m_targetBoneName.c_str(); + } + + void BoneFollower::SetAttachmentOffset(const AZ::Transform& offset) + { + AZ_Assert(m_ownerId.IsValid(), "BoneFollower must be Activated to use."); + + if (m_targetId.IsValid()) + { + m_targetOffset = offset; + UpdateOwnerTransformIfNecessary(); + } + } + + void BoneFollower::OnModelReady([[maybe_unused]] const AZ::Data::Asset& modelAsset, [[maybe_unused]] const AZ::Data::Instance& model) + { + // reset character values + BindTargetBone(); + m_targetBoneTransform = QueryBoneTransform(); + + // move owner if necessary + UpdateOwnerTransformIfNecessary(); + } + + void BoneFollower::BindTargetBone() + { + m_targetBoneId = -1; + LmbrCentral::SkeletalHierarchyRequestBus::EventResult( + m_targetBoneId, m_targetId, &LmbrCentral::SkeletalHierarchyRequests::GetJointIndexByName, m_targetBoneName.c_str()); + } + + void BoneFollower::UpdateOwnerTransformIfNecessary() + { + // Can't update until target entity's transform is known + if (!m_isTargetEntityTransformKnown) + { + if (AZ::TransformBus::GetNumOfEventHandlers(m_targetId) == 0) + { + return; + } + + AZ::TransformBus::EventResult(m_targetEntityTransform, m_targetId, &AZ::TransformBus::Events::GetWorldTM); + m_isTargetEntityTransformKnown = true; + } + + AZ::Transform finalTransform; + if (m_scaleSource == AttachmentConfiguration::ScaleSource::WorldScale) + { + // apply offset in world-space + finalTransform = m_targetEntityTransform * m_targetBoneTransform; + finalTransform.SetScale(AZ::Vector3::CreateOne()); + finalTransform *= m_targetOffset; + } + else if (m_scaleSource == AttachmentConfiguration::ScaleSource::TargetEntityScale) + { + // apply offset in target-entity-space (ignoring bone scale) + AZ::Transform boneNoScale = m_targetBoneTransform; + boneNoScale.SetScale(AZ::Vector3::CreateOne()); + + finalTransform = m_targetEntityTransform * boneNoScale * m_targetOffset; + } + else // AttachmentConfiguration::ScaleSource::TargetEntityScale + { + // apply offset in target-bone-space + finalTransform = m_targetEntityTransform * m_targetBoneTransform * m_targetOffset; + } + + if (m_cachedOwnerTransform != finalTransform) + { + AZ_Warning( + "Attachment Component", !m_isUpdatingOwnerTransform, + "AttachmentComponent detected a cycle when updating transform, do not target child entities."); + if (!m_isUpdatingOwnerTransform) + { + m_cachedOwnerTransform = finalTransform; + m_isUpdatingOwnerTransform = true; + EBUS_EVENT_ID(m_ownerId, AZ::TransformBus, SetWorldTM, finalTransform); + m_isUpdatingOwnerTransform = false; + } + } + } + + AZ::Transform BoneFollower::QueryBoneTransform() const + { + AZ::Transform boneTransform = AZ::Transform::CreateIdentity(); + + if (m_targetBoneId >= 0) + { + LmbrCentral::SkeletalHierarchyRequestBus::EventResult( + boneTransform, m_targetId, &LmbrCentral::SkeletalHierarchyRequests::GetJointTransformCharacterRelative, m_targetBoneId); + } + + return boneTransform; + } + + // fires when target's transform changes + void BoneFollower::OnTransformChanged(const AZ::Transform& /*local*/, const AZ::Transform& world) + { + m_targetEntityTransform = world; + m_isTargetEntityTransformKnown = true; + UpdateOwnerTransformIfNecessary(); + } + + void BoneFollower::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/) + { + m_targetBoneTransform = QueryBoneTransform(); + UpdateOwnerTransformIfNecessary(); + } + + int BoneFollower::GetTickOrder() + { + return AZ::TICK_ATTACHMENT; + } + + void BoneFollower::Reattach(bool detachFirst) + { +#ifdef AZ_ENABLE_TRACING + AZ::Entity* ownerEntity = nullptr; + AZ::Entity* targetEntity = nullptr; + AZ::ComponentApplicationBus::BroadcastResult(ownerEntity, &AZ::ComponentApplicationBus::Events::FindEntity, m_ownerId); + AZ::ComponentApplicationBus::BroadcastResult(targetEntity, &AZ::ComponentApplicationBus::Events::FindEntity, m_targetId); + AZ_TracePrintf( + "BoneFollower", "Reattaching entity '%s' to entity '%s'", ownerEntity ? ownerEntity->GetName().c_str() : "", + targetEntity ? targetEntity->GetName().c_str() : ""); +#endif + + if (m_targetId.IsValid() && detachFirst) + { + LmbrCentral::AttachmentComponentNotificationBus::Event(m_targetId, &LmbrCentral::AttachmentComponentNotificationBus::Events::OnDetached, m_ownerId); + } + + if (m_targetId != m_ownerId) + { + LmbrCentral::AttachmentComponentNotificationBus::Event(m_targetId, &LmbrCentral::AttachmentComponentNotificationBus::Events::OnAttached, m_ownerId); + } + } + + //========================================================================= + // AttachmentComponent + //========================================================================= + + void AttachmentComponent::Activate() + { +#ifdef AZ_ENABLE_TRACING + bool isStaticTransform = false; + AZ::TransformBus::EventResult(isStaticTransform, GetEntityId(), &AZ::TransformBus::Events::IsStaticTransform); + AZ_Warning( + "Attachment Component", !isStaticTransform, "Attachment needs to move, but entity '%s' %s has a static transform.", + GetEntity()->GetName().c_str(), GetEntityId().ToString().c_str()); +#endif + + m_boneFollower.Activate(GetEntity(), m_initialConfiguration, true); + } + + void AttachmentComponent::Deactivate() + { + m_boneFollower.Deactivate(); + } + } // namespace Render +} // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/AttachmentComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/AttachmentComponent.h new file mode 100644 index 0000000000..ac03663f22 --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/AttachmentComponent.h @@ -0,0 +1,189 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#pragma once + +#include +#include +#include +#include +#include +#include + +struct ISkeletonPose; + +namespace AZ +{ + namespace Render + { + /*! + * Configuration data for AttachmentComponent. + */ + struct AttachmentConfiguration + { + AZ_TYPE_INFO(AttachmentConfiguration, "{74B5DC69-DE44-4640-836A-55339E116795}"); + + virtual ~AttachmentConfiguration() = default; + + static void Reflect(AZ::ReflectContext* context); + + //! Attach to this entity. + AZ::EntityId m_targetId; + + //! Attach to this bone on target entity. + AZStd::string m_targetBoneName; + + //! Offset from target. + AZ::Transform m_targetOffset = AZ::Transform::Identity(); + + //! Whether to attach to target upon activation. + //! If false, the entity remains detached until Attach() is called. + bool m_attachedInitially = true; + + //! Source from which to retrieve scale information. + enum class ScaleSource : AZ::u8 + { + WorldScale, // Scaled in world space. + TargetEntityScale, // Adopt scaling of attachment target entity. + TargetBoneScale, // Adopt scaling of attachment target entity/joint. + }; + ScaleSource m_scaleSource = ScaleSource::WorldScale; + }; + + /* + * Common functionality for game and editor attachment components. + * The BoneFollower tracks movement of the target's bone and + * updates the owning entity's TransformComponent to follow. + * This class should be a member within the attachment component + * and be activated/deactivated along with the component. + * \ref AttachmentComponent + */ + class BoneFollower + : public LmbrCentral::AttachmentComponentRequestBus::Handler + , public AZ::TransformNotificationBus::Handler + , public AZ::Render::MeshComponentNotificationBus::Handler + , public AZ::Data::AssetBus::Handler + , public AZ::TickBus::Handler + { + public: + void Activate(AZ::Entity* owner, const AttachmentConfiguration& initialConfiguration, bool targetCanAnimate); + void Deactivate(); + + //////////////////////////////////////////////////////////////////////// + // AttachmentComponentRequests + void Reattach(bool detachFirst); + void Attach(AZ::EntityId targetId, const char* targetBoneName, const AZ::Transform& offset) override; + void Detach() override; + void SetAttachmentOffset(const AZ::Transform& offset) override; + const char* GetJointName() override; + AZ::EntityId GetTargetEntityId() override; + AZ::Transform GetOffset() override; + //////////////////////////////////////////////////////////////////////// + + private: + + //////////////////////////////////////////////////////////////////////// + // AZ::TickBus + //! Check target bone transform every frame. + void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; + //! Make sure target bone transform updates after animation update. + int GetTickOrder() override; + //////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////// + // AZ::TransformNotificationBus + //! When target's transform changes + void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override; + //////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////// + // MeshComponentEvents + //! When target's mesh changes + void OnModelReady(const AZ::Data::Asset& modelAsset, const AZ::Data::Instance& model) override; + //////////////////////////////////////////////////////////////////////// + + void BindTargetBone(); + + AZ::Transform QueryBoneTransform() const; + + void UpdateOwnerTransformIfNecessary(); + + //! Entity which which is being attached. + AZ::EntityId m_ownerId; + + //! Whether to query bone position per-frame (false while in editor) + bool m_targetCanAnimate = false; + + AZ::EntityId m_targetId; + AZStd::string m_targetBoneName; + AZ::Transform m_targetOffset; //!< local transform + AZ::Transform m_targetBoneTransform; //!< local transform of bone + AZ::Transform m_targetEntityTransform; //!< world transform of target + bool m_isTargetEntityTransformKnown = false; + + //! Cached value, so we don't update owner's position unnecessarily. + AZ::Transform m_cachedOwnerTransform; + bool m_isUpdatingOwnerTransform = false; //!< detect infinite loops when updating owner's transform + + // Cached character values to avoid repeated lookup. + // These are set by calling ResetCharacter() + int m_targetBoneId; //!< negative when bone not found + + AttachmentConfiguration::ScaleSource m_scaleSource; + }; + + /*! + * The AttachmentComponent lets an entity stick to a particular bone on + * a target entity. This is achieved by tracking movement of the target's + * bone and updating the entity's TransformComponent accordingly. + */ + class AttachmentComponent + : public AZ::Component + { + public: + AZ_COMPONENT(AttachmentComponent, "{2D17A64A-7AC5-4C02-AC36-C5E8141FFDDF}"); + + friend class EditorAttachmentComponent; + + static void Reflect(AZ::ReflectContext* context); + + static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) + { + provided.push_back(AZ_CRC("AttachmentService", 0x5aaa7b63)); + } + + static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) + { + incompatible.push_back(AZ_CRC("AttachmentService", 0x5aaa7b63)); + } + + static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) + { + required.push_back(AZ_CRC("TransformService", 0x8ee22c50)); + } + + ~AttachmentComponent() override = default; + + private: + //////////////////////////////////////////////////////////////////////// + // AZ::Component + void Activate() override; + void Deactivate() override; + //////////////////////////////////////////////////////////////////////// + + //! Initial configuration for m_attachment + AttachmentConfiguration m_initialConfiguration; + + //! Implements actual attachment functionality + BoneFollower m_boneFollower; + }; + } // namespace Render +} // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/EditorAttachmentComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/EditorAttachmentComponent.cpp new file mode 100644 index 0000000000..3b50c0a48c --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/EditorAttachmentComponent.cpp @@ -0,0 +1,242 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include "EditorAttachmentComponent.h" +#include +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + void EditorAttachmentComponent::Reflect(AZ::ReflectContext* context) + { + AZ::SerializeContext* serializeContext = azrtti_cast(context); + if (serializeContext) + { + serializeContext->Class() + ->Version(1) + ->Field("Target ID", &EditorAttachmentComponent::m_targetId) + ->Field("Target Bone Name", &EditorAttachmentComponent::m_targetBoneName) + ->Field("Position Offset", &EditorAttachmentComponent::m_positionOffset) + ->Field("Rotation Offset", &EditorAttachmentComponent::m_rotationOffset) + ->Field("Scale Offset", &EditorAttachmentComponent::m_scaleOffset) + ->Field("Attached Initially", &EditorAttachmentComponent::m_attachedInitially) + ->Field("Scale Source", &EditorAttachmentComponent::m_scaleSource); + + AZ::EditContext* editContext = serializeContext->GetEditContext(); + if (editContext) + { + editContext + ->Class( + "Attachment", "The Attachment component lets an entity attach to a bone on the skeleton of another entity") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::Category, "Animation") + ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Attachment.svg") + ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Attachment.png") + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c)) + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->Attribute( + AZ::Edit::Attributes::HelpPageURL, + "https://docs.aws.amazon.com/lumberyard/latest/userguide/component-attachment.html") + ->DataElement(0, &EditorAttachmentComponent::m_targetId, "Target entity", "Attach to this entity.") + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetIdChanged) + ->DataElement( + AZ::Edit::UIHandlers::ComboBox, &EditorAttachmentComponent::m_targetBoneName, "Joint name", + "Attach to this joint on target entity.") + ->Attribute(AZ::Edit::Attributes::StringList, &EditorAttachmentComponent::GetTargetBoneOptions) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetBoneChanged) + ->DataElement( + 0, &EditorAttachmentComponent::m_positionOffset, "Position offset", "Local position offset from target bone") + ->Attribute(AZ::Edit::Attributes::Suffix, "m") + ->Attribute(AZ::Edit::Attributes::Step, 0.01f) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetOffsetChanged) + ->DataElement( + 0, &EditorAttachmentComponent::m_rotationOffset, "Rotation offset", "Local rotation offset from target bone") + ->Attribute(AZ::Edit::Attributes::Suffix, "deg") + ->Attribute(AZ::Edit::Attributes::Step, 0.01f) + ->Attribute(AZ::Edit::Attributes::Min, -AZ::RadToDeg(AZ::Constants::TwoPi)) + ->Attribute(AZ::Edit::Attributes::Max, AZ::RadToDeg(AZ::Constants::TwoPi)) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetOffsetChanged) + ->DataElement(0, &EditorAttachmentComponent::m_scaleOffset, "Scale offset", "Local scale offset from target entity") + ->Attribute(AZ::Edit::Attributes::Step, 0.1f) + ->Attribute(AZ::Edit::Attributes::Min, 0.001f) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetOffsetChanged) + ->DataElement( + 0, &EditorAttachmentComponent::m_attachedInitially, "Attached initially", + "Whether to attach to target upon activation.") + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnAttachedInitiallyChanged) + ->DataElement( + AZ::Edit::UIHandlers::ComboBox, &EditorAttachmentComponent::m_scaleSource, "Scaling", + "How object scale should be determined. " + "Use world scale = Attached object is scaled in world space, Use target entity scale = Attached object adopts " + "scale of target entity., Use target bone scale = Attached object adopts scale of target entity/joint.") + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnScaleSourceChanged) + ->EnumAttribute(AttachmentConfiguration::ScaleSource::WorldScale, "Use world scale") + ->EnumAttribute(AttachmentConfiguration::ScaleSource::TargetEntityScale, "Use target entity scale") + ->EnumAttribute(AttachmentConfiguration::ScaleSource::TargetBoneScale, "Use target bone scale"); + } + } + } + + void EditorAttachmentComponent::Activate() + { + Base::Activate(); + m_boneFollower.Activate(GetEntity(), CreateAttachmentConfiguration(), + false); // Entity's don't animate in Editor + } + + void EditorAttachmentComponent::Deactivate() + { + m_boneFollower.Deactivate(); + Base::Deactivate(); + } + + void EditorAttachmentComponent::BuildGameEntity(AZ::Entity* gameEntity) + { + AttachmentComponent* component = gameEntity->CreateComponent(); + if (component) + { + component->m_initialConfiguration = CreateAttachmentConfiguration(); + } + } + + AttachmentConfiguration EditorAttachmentComponent::CreateAttachmentConfiguration() const + { + AttachmentConfiguration configuration; + configuration.m_targetId = m_targetId; + configuration.m_targetBoneName = m_targetBoneName; + configuration.m_targetOffset = GetTargetOffset(); + configuration.m_attachedInitially = m_attachedInitially; + configuration.m_scaleSource = m_scaleSource; + return configuration; + } + + AZ::Transform EditorAttachmentComponent::GetTargetOffset() const + { + AZ::Transform offset = AZ::ConvertEulerDegreesToTransform(m_rotationOffset); + offset.SetTranslation(m_positionOffset); + offset.MultiplyByScale(m_scaleOffset); + return offset; + } + + AZStd::vector EditorAttachmentComponent::GetTargetBoneOptions() const + { + AZStd::vector names; + + // insert blank entry, so user may choose to bind to NO bone. + names.push_back(""); + + // track whether currently-set bone is found + bool currentTargetBoneFound = false; + + // Get character and iterate over bones + AZ::u32 jointCount = 0; + LmbrCentral::SkeletalHierarchyRequestBus::EventResult(jointCount, m_targetId, &LmbrCentral::SkeletalHierarchyRequests::GetJointCount); + for (AZ::u32 jointIndex = 0; jointIndex < jointCount; ++jointIndex) + { + const char* name = nullptr; + LmbrCentral::SkeletalHierarchyRequestBus::EventResult(name, m_targetId, &LmbrCentral::SkeletalHierarchyRequests::GetJointNameByIndex, jointIndex); + if (name) + { + names.push_back(name); + + if (!currentTargetBoneFound) + { + currentTargetBoneFound = (m_targetBoneName == names.back()); + } + } + } + + // If we never found currently-set bone name, + // stick it at top of list, just in case user wants to keep it anyway + if (!currentTargetBoneFound && !m_targetBoneName.empty()) + { + names.insert(names.begin(), m_targetBoneName); + } + + return names; + } + + AZ::u32 EditorAttachmentComponent::OnTargetIdChanged() + { + // Warn about bad setups (it won't crash, but it's nice to handle this early) + if (m_targetId == GetEntityId()) + { + AZ_Warning(GetEntity()->GetName().c_str(), false, "AttachmentComponent cannot target self.") m_targetId.SetInvalid(); + } + + // Warn about children attaching to a parent + AZ::EntityId parentOfTarget; + AZ::TransformBus::EventResult(parentOfTarget, m_targetId, &AZ::TransformBus::Events::GetParentId); + while (parentOfTarget.IsValid()) + { + if (parentOfTarget == GetEntityId()) + { + AZ_Warning( + GetEntity()->GetName().c_str(), parentOfTarget != GetEntityId(), "AttachmentComponent cannot target child entity"); + m_targetId.SetInvalid(); + break; + } + + AZ::EntityId currentParentId = parentOfTarget; + parentOfTarget.SetInvalid(); + AZ::TransformBus::EventResult(parentOfTarget, currentParentId, &AZ::TransformBus::Events::GetParentId); + } + + AttachOrDetachAsNecessary(); + + return AZ::Edit::PropertyRefreshLevels::AttributesAndValues; // refresh bone options + } + + AZ::u32 EditorAttachmentComponent::OnTargetBoneChanged() + { + AttachOrDetachAsNecessary(); + return AZ::Edit::PropertyRefreshLevels::None; + } + + AZ::u32 EditorAttachmentComponent::OnTargetOffsetChanged() + { + EBUS_EVENT_ID(GetEntityId(), LmbrCentral::AttachmentComponentRequestBus, SetAttachmentOffset, GetTargetOffset()); + return AZ::Edit::PropertyRefreshLevels::None; + } + + AZ::u32 EditorAttachmentComponent::OnAttachedInitiallyChanged() + { + AttachOrDetachAsNecessary(); + return AZ::Edit::PropertyRefreshLevels::None; + } + + AZ::u32 EditorAttachmentComponent::OnScaleSourceChanged() + { + m_boneFollower.Deactivate(); + m_boneFollower.Activate(GetEntity(), CreateAttachmentConfiguration(), false); + return AZ::Edit::PropertyRefreshLevels::None; + } + + void EditorAttachmentComponent::AttachOrDetachAsNecessary() + { + if (m_attachedInitially && m_targetId.IsValid()) + { + EBUS_EVENT_ID( + GetEntityId(), LmbrCentral::AttachmentComponentRequestBus, Attach, m_targetId, m_targetBoneName.c_str(), GetTargetOffset()); + } + else + { + EBUS_EVENT_ID(GetEntityId(), LmbrCentral::AttachmentComponentRequestBus, Detach); + } + } + } // namespace Render + } // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/EditorAttachmentComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/EditorAttachmentComponent.h new file mode 100644 index 0000000000..cac8a71a94 --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Animation/EditorAttachmentComponent.h @@ -0,0 +1,104 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ +#pragma once + +#include +#include "AttachmentComponent.h" + +namespace AZ +{ + namespace Render + { + /*! + * In-editor attachment component. + * \ref AttachmentComponent + */ + class EditorAttachmentComponent + : public AzToolsFramework::Components::EditorComponentBase + { + private: + using Base = AzToolsFramework::Components::EditorComponentBase; + public: + AZ_COMPONENT(EditorAttachmentComponent, "{DA6072FD-E696-47D8-81D9-1F77D3464200}", Base); + static void Reflect(AZ::ReflectContext* context); + + static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) + { + AttachmentComponent::GetProvidedServices(provided); + } + + static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) + { + AttachmentComponent::GetIncompatibleServices(incompatible); + } + + static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) + { + AttachmentComponent::GetRequiredServices(required); + } + + ~EditorAttachmentComponent() override = default; + void BuildGameEntity(AZ::Entity* gameEntity) override; + + protected: + + ////////////////////////////////////////////////////////////////////////// + // AZ::Component interface implementation + void Activate() override; + void Deactivate() override; + ////////////////////////////////////////////////////////////////////////// + + AZ::u32 OnTargetIdChanged(); + AZ::u32 OnTargetBoneChanged(); + AZ::u32 OnTargetOffsetChanged(); + AZ::u32 OnAttachedInitiallyChanged(); + AZ::u32 OnScaleSourceChanged(); + + //! Invoked when an attachment property changes + void AttachOrDetachAsNecessary(); + + //! For populating ComboBox + AZStd::vector GetTargetBoneOptions() const; + + //! Create runtime configuration from editor configuration + AttachmentConfiguration CreateAttachmentConfiguration() const; + + //! Create AZ::Transform from position and rotation + AZ::Transform GetTargetOffset() const; + + //! Attach to this entity. + AZ::EntityId m_targetId; + + //! Attach to this bone on target entity. + AZStd::string m_targetBoneName; + + //! Offset from target bone's position. + AZ::Vector3 m_positionOffset = AZ::Vector3::CreateZero(); + + //! Offset from target bone's rotation. + AZ::Vector3 m_rotationOffset = AZ::Vector3::CreateZero(); + + //! Offset from target entity's scale. + AZ::Vector3 m_scaleOffset = AZ::Vector3::CreateOne(); + + //! Observe scale information from the specified source. + AttachmentConfiguration::ScaleSource m_scaleSource = AttachmentConfiguration::ScaleSource::WorldScale; + + //! Whether to attach to target upon activation. + //! If false, the entity remains detached until Attach() is called. + bool m_attachedInitially = true; + + //! Implements actual attachment functionality + AZ::Render::BoneFollower m_boneFollower; + }; + } // namespace Render +} // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/EditorAreaLightComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/EditorAreaLightComponent.cpp index 8c5f6d6836..a77bcfdd12 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/EditorAreaLightComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/EditorAreaLightComponent.cpp @@ -336,6 +336,7 @@ namespace AZ bool needsFullRefresh = HandleLightTypeChange(); LmbrCentral::EditorShapeComponentRequestsBus::Event(GetEntityId(), &LmbrCentral::EditorShapeComponentRequests::SetShapeColor, m_controller.m_configuration.m_color); + LmbrCentral::EditorShapeComponentRequestsBus::Event(GetEntityId(), &LmbrCentral::EditorShapeComponentRequests::SetShapeWireframeColor, m_controller.m_configuration.m_color); // If photometric unit changes, convert the intensities so the actual intensity doesn't change. m_controller.ConvertToIntensityMode(m_controller.m_configuration.m_intensityMode); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.cpp index 22a7e1c6c0..3c748e352e 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.cpp @@ -75,6 +75,12 @@ namespace AZ incompatible.push_back(AZ_CRC_CE("DecalService")); } + void DecalComponentController::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) + { + dependent.push_back(AZ_CRC_CE("TransformService")); + dependent.push_back(AZ_CRC_CE("NonUniformScaleService")); + } + DecalComponentController::DecalComponentController(const DecalComponentConfig& config) : m_configuration(config) { @@ -90,6 +96,11 @@ namespace AZ m_handle = m_featureProcessor->AcquireDecal(); } + m_cachedNonUniformScale = AZ::Vector3::CreateOne(); + AZ::NonUniformScaleRequestBus::EventResult(m_cachedNonUniformScale, m_entityId, &AZ::NonUniformScaleRequests::GetScale); + AZ::NonUniformScaleRequestBus::Event(m_entityId, &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent, + m_nonUniformScaleChangedHandler); + AZ::Transform local, world; AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::GetLocalAndWorld, local, world); OnTransformChanged(local, world); @@ -103,6 +114,7 @@ namespace AZ { DecalRequestBus::Handler::BusDisconnect(m_entityId); TransformNotificationBus::Handler::BusDisconnect(m_entityId); + m_nonUniformScaleChangedHandler.Disconnect(); if (m_featureProcessor) { m_featureProcessor->ReleaseDecal(m_handle); @@ -125,7 +137,18 @@ namespace AZ { if (m_featureProcessor) { - m_featureProcessor->SetDecalTransform(m_handle, world); + m_featureProcessor->SetDecalTransform(m_handle, world, m_cachedNonUniformScale); + } + } + + void DecalComponentController::HandleNonUniformScaleChange(const AZ::Vector3& nonUniformScale) + { + m_cachedNonUniformScale = nonUniformScale; + if (m_featureProcessor) + { + AZ::Transform world = AZ::Transform::CreateIdentity(); + AZ::TransformBus::EventResult(world, m_entityId, &AZ::TransformBus::Events::GetWorldTM); + m_featureProcessor->SetDecalTransform(m_handle, world, nonUniformScale); } } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.h index dc6b6e70ea..14204c43dc 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/DecalComponentController.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -33,6 +34,7 @@ namespace AZ static void Reflect(AZ::ReflectContext* context); static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); + static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); DecalComponentController() = default; DecalComponentController(const DecalComponentConfig& config); @@ -64,11 +66,18 @@ namespace AZ void OpacityChanged(); void SortKeyChanged(); void MaterialChanged(); + void HandleNonUniformScaleChange(const AZ::Vector3& nonUniformScale); DecalComponentConfig m_configuration; DecalFeatureProcessorInterface* m_featureProcessor = nullptr; DecalFeatureProcessorInterface::DecalHandle m_handle; EntityId m_entityId; + AZ::Vector3 m_cachedNonUniformScale = AZ::Vector3::CreateOne(); + + AZ::NonUniformScaleChangedEvent::Handler m_nonUniformScaleChangedHandler + { + [&](const AZ::Vector3& nonUniformScale) { HandleNonUniformScaleChange(nonUniformScale); } + }; }; } // namespace Render } // AZ namespace diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp index f7915bbff4..03533e142f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp @@ -245,9 +245,12 @@ namespace AZ for (const auto& propertyDefinition : propertyListItr->second) { AtomToolsFramework::DynamicPropertyConfig propertyConfig; - AtomToolsFramework::ConvertToPropertyConfig(propertyConfig, propertyDefinition); + // Assign id before conversion so it can be used in dynamic description propertyConfig.m_id = AZ::RPI::MaterialPropertyId(groupNameId, propertyDefinition.m_nameId).GetFullName(); + + AtomToolsFramework::ConvertToPropertyConfig(propertyConfig, propertyDefinition); + propertyConfig.m_groupName = groupDisplayName; const auto& propertyIndex = m_editData.m_materialAsset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyConfig.m_id); propertyConfig.m_showThumbnail = true; diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp index 94dfb39419..e9a81f2e9f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -93,7 +95,6 @@ namespace AZ void EditorMaterialSystemComponent::Activate() { - AzFramework::TargetManagerClient::Bus::Handler::BusConnect(); EditorMaterialSystemComponentRequestBus::Handler::BusConnect(); AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusConnect(); AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect(); @@ -105,7 +106,6 @@ namespace AZ void EditorMaterialSystemComponent::Deactivate() { - AzFramework::TargetManagerClient::Bus::Handler::BusDisconnect(); EditorMaterialSystemComponentRequestBus::Handler::BusDisconnect(); AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusDisconnect(); AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); @@ -123,36 +123,19 @@ namespace AZ void EditorMaterialSystemComponent::OpenInMaterialEditor(const AZStd::string& sourcePath) { - if (m_materialEditorTarget.IsValid()) - { - AzFramework::TmMsg openDocumentMsg(AZ_CRC("OpenInMaterialEditor", 0x9f92aac8)); - openDocumentMsg.AddCustomBlob(sourcePath.c_str(), sourcePath.size() + 1); - AzFramework::TargetManager::Bus::Broadcast(&AzFramework::TargetManager::SendTmMessage, m_materialEditorTarget, openDocumentMsg); - } - else - { - AZ_TracePrintf("MaterialComponent", "Launching Material Editor"); + AZ_TracePrintf("MaterialComponent", "Launching Material Editor"); - QStringList arguments; - arguments.append(sourcePath.c_str()); - AtomToolsFramework::LaunchTool("MaterialEditor", ".exe", arguments); - } - } + QStringList arguments; + arguments.append(sourcePath.c_str()); - void EditorMaterialSystemComponent::TargetJoinedNetwork(AzFramework::TargetInfo info) - { - if (AZ::StringFunc::Equal(info.GetDisplayName(), "MaterialEditor")) + // Use the same RHI as the main editor + AZ::Name apiName = AZ::RHI::Factory::Get().GetName(); + if (!apiName.IsEmpty()) { - m_materialEditorTarget = info; + arguments.append(QString("--rhi=%1").arg(apiName.GetCStr())); } - } - void EditorMaterialSystemComponent::TargetLeftNetwork(AzFramework::TargetInfo info) - { - if (AZ::StringFunc::Equal(info.GetDisplayName(), "MaterialEditor")) - { - m_materialEditorTarget = {}; - } + AtomToolsFramework::LaunchTool("MaterialEditor", ".exe", arguments); } void EditorMaterialSystemComponent::OnApplicationAboutToStop() @@ -166,7 +149,10 @@ namespace AZ { m_openMaterialEditorAction = new QAction("Material Editor"); m_openMaterialEditorAction->setShortcut(QKeySequence(Qt::Key_M)); - QObject::connect(m_openMaterialEditorAction, &QAction::triggered, m_openMaterialEditorAction, [this]() + m_openMaterialEditorAction->setCheckable(false); + m_openMaterialEditorAction->setChecked(false); + QObject::connect( + m_openMaterialEditorAction, &QAction::triggered, m_openMaterialEditorAction, [this]() { OpenInMaterialEditor(""); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h index 09ad1c1b9c..cb1aac9163 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.h @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ namespace AZ class EditorMaterialSystemComponent : public AZ::Component , private EditorMaterialSystemComponentRequestBus::Handler - , private AzFramework::TargetManagerClient::Bus::Handler , private AzFramework::ApplicationLifecycleEvents::Bus::Handler , public AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler , public AzToolsFramework::EditorMenuNotificationBus::Handler @@ -57,10 +55,6 @@ namespace AZ //! EditorMaterialSystemComponentRequestBus::Handler overrides... void OpenInMaterialEditor(const AZStd::string& sourcePath) override; - //! AzFramework::TargetManagerClient::Bus::Handler overrides... - void TargetJoinedNetwork(AzFramework::TargetInfo info) override; - void TargetLeftNetwork(AzFramework::TargetInfo info) override; - // AzFramework::ApplicationLifecycleEvents overrides... void OnApplicationAboutToStop() override; @@ -74,9 +68,6 @@ namespace AZ void SetupThumbnails(); void TeardownThumbnails(); - // Material Editor target for interprocess communication with MaterialEditor - AzFramework::TargetInfo m_materialEditorTarget; - QAction* m_openMaterialEditorAction = nullptr; AZStd::unique_ptr m_materialBrowserInteractions; diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp index deab9d2715..70627fd2f1 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp @@ -131,6 +131,7 @@ namespace AZ void MeshComponentController::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { dependent.push_back(AZ_CRC("TransformService", 0x8ee22c50)); + dependent.push_back(AZ_CRC_CE("NonUniformScaleService")); } void MeshComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Module.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Module.cpp index b33dd7f165..2ef4e1e229 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Module.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Module.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef ATOMLYINTEGRATION_FEATURE_COMMON_EDITOR #include @@ -69,6 +70,7 @@ #include #include #include +#include #endif namespace AZ @@ -111,6 +113,7 @@ namespace AZ DiffuseProbeGridComponent::CreateDescriptor(), DeferredFogComponent::CreateDescriptor(), SurfaceData::SurfaceDataMeshComponent::CreateDescriptor(), + AttachmentComponent::CreateDescriptor(), #ifdef ATOMLYINTEGRATION_FEATURE_COMMON_EDITOR EditorAreaLightComponent::CreateDescriptor(), @@ -141,6 +144,7 @@ namespace AZ EditorDiffuseProbeGridComponent::CreateDescriptor(), EditorDeferredFogComponent::CreateDescriptor(), SurfaceData::EditorSurfaceDataMeshComponent::CreateDescriptor(), + EditorAttachmentComponent::CreateDescriptor(), #endif }); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp index efefcc3dc6..735eab5368 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp @@ -133,23 +133,14 @@ namespace AZ AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId()); AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(GetEntityId()); EditorReflectionProbeBus::Handler::BusConnect(GetEntityId()); + AZ::TickBus::Handler::BusConnect(); ReflectionProbeComponentConfig& configuration = m_controller.m_configuration; - // special handling is required if this component is being cloned in the editor: - // if the entityId in the configuration does not match this component's entityId it is being cloned - AZ::u64 entityId = (AZ::u64)GetEntityId(); - if (configuration.m_entityId != EntityId::InvalidEntityId - && configuration.m_entityId != entityId) - { - // clear the cubeMapRelativePath to prevent the newly cloned reflection probe - // from using the same cubemap path as the original reflection probe - configuration.m_bakedCubeMapRelativePath = ""; - } - // update UI cubemap path display m_bakedCubeMapRelativePath = configuration.m_bakedCubeMapRelativePath; + AZ::u64 entityId = (AZ::u64)GetEntityId(); configuration.m_entityId = entityId; } @@ -158,9 +149,55 @@ namespace AZ EditorReflectionProbeBus::Handler::BusDisconnect(GetEntityId()); AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect(); AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect(); + AZ::TickBus::Handler::BusDisconnect(); BaseClass::Deactivate(); } + void EditorReflectionProbeComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) + { + if (!m_controller.m_featureProcessor) + { + return; + } + + if (m_controller.m_configuration.m_useBakedCubemap) + { + AZStd::string cubeMapRelativePath = m_controller.m_configuration.m_bakedCubeMapRelativePath + ".streamingimage"; + Data::Asset cubeMapAsset; + CubeMapAssetNotificationType notificationType = CubeMapAssetNotificationType::None; + if (m_controller.m_featureProcessor->CheckCubeMapAssetNotification(cubeMapRelativePath, cubeMapAsset, notificationType)) + { + // a cubemap bake is in progress for this entity component + if (notificationType == CubeMapAssetNotificationType::Ready) + { + // bake is complete, update configuration with the new baked cubemap asset + m_controller.m_configuration.m_bakedCubeMapAsset = { cubeMapAsset.GetAs(), AZ::Data::AssetLoadBehavior::PreLoad }; + + // refresh the currently rendered cubemap + m_controller.UpdateCubeMap(); + + // update the UI + AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestRefresh, AzToolsFramework::PropertyModificationRefreshLevel::Refresh_AttributesAndValues); + } + else if (notificationType == CubeMapAssetNotificationType::Error) + { + // cubemap bake failed + QMessageBox::information( + QApplication::activeWindow(), + "Reflection Probe", + "Reflection Probe cubemap failed to bake, please check the Asset Processor for more information.", + QMessageBox::Ok); + + // clear relative path, this will allow the user to retry + m_controller.m_configuration.m_bakedCubeMapRelativePath.clear(); + + // update the UI + AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestRefresh, AzToolsFramework::PropertyModificationRefreshLevel::Refresh_AttributesAndValues); + } + } + } + } + void EditorReflectionProbeComponent::DisplayEntityViewport([[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) { // only draw the bounds if selected @@ -172,13 +209,19 @@ namespace AZ AZ::Vector3 position = AZ::Vector3::CreateZero(); AZ::TransformBus::EventResult(position, GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); + AZ::Vector3 scale = AZ::Vector3::CreateOne(); + AZ::TransformBus::EventResult(scale, GetEntityId(), &AZ::TransformBus::Events::GetLocalScale); + // draw AABB at probe position using the inner dimensions Color color(0.0f, 0.0f, 1.0f, 1.0f); debugDisplay.SetColor(color); ReflectionProbeComponentConfig& configuration = m_controller.m_configuration; - AZ::Vector3 innerMin(position.GetX() - configuration.m_innerWidth / 2, position.GetY() - configuration.m_innerLength / 2, position.GetZ() - configuration.m_innerHeight / 2); - AZ::Vector3 innerMax(position.GetX() + configuration.m_innerWidth / 2, position.GetY() + configuration.m_innerLength / 2, position.GetZ() + configuration.m_innerHeight / 2); + AZ::Vector3 innerExtents(configuration.m_innerWidth, configuration.m_innerLength, configuration.m_innerHeight); + innerExtents *= scale; + + AZ::Vector3 innerMin(position.GetX() - innerExtents.GetX() / 2, position.GetY() - innerExtents.GetY() / 2, position.GetZ() - innerExtents.GetZ() / 2); + AZ::Vector3 innerMax(position.GetX() + innerExtents.GetX() / 2, position.GetY() + innerExtents.GetY() / 2, position.GetZ() + innerExtents.GetZ() / 2); debugDisplay.DrawWireBox(innerMin, innerMax); } @@ -270,122 +313,94 @@ namespace AZ return AZ::Edit::PropertyRefreshLevels::None; } - // callback from the EnvironmentCubeMapPass when the cubemap render is complete - BuildCubeMapCallback buildCubeMapCallback = [this](uint8_t* const* cubeMapFaceTextureData, const RHI::Format cubeMapTextureFormat) - { - if (!m_bakeInProgress) - { - // user canceled the bake - return; - } + char projectPath[AZ_MAX_PATH_LEN]; + AZ::IO::FileIOBase::GetInstance()->ResolvePath("@devassets@", projectPath, AZ_MAX_PATH_LEN); - char projectPath[AZ_MAX_PATH_LEN]; - AZ::IO::FileIOBase::GetInstance()->ResolvePath("@devassets@", projectPath, AZ_MAX_PATH_LEN); + // retrieve the source cubemap path from the configuration + // we need to make sure to use the same source cubemap for each bake + AZStd::string cubeMapRelativePath = m_controller.m_configuration.m_bakedCubeMapRelativePath; + AZStd::string cubeMapFullPath; - // retrieve the source cubemap path from the configuration - // we need to make sure to use the same source cubemap for each bake - AZStd::string cubeMapRelativePath = m_controller.m_configuration.m_bakedCubeMapRelativePath; - AZStd::string cubeMapFullPath; + if (!cubeMapRelativePath.empty()) + { + // test to see if the cubemap file is actually there, if it was removed we need to + // generate a new filename, otherwise it will cause an error in the asset system + AzFramework::StringFunc::Path::Join(projectPath, cubeMapRelativePath.c_str(), cubeMapFullPath, true, true); - if (!cubeMapRelativePath.empty()) + if (!AZ::IO::FileIOBase::GetInstance()->Exists(cubeMapFullPath.c_str())) { - // test to see if the cubemap file is actually there, if it was removed we need to - // generate a new filename, otherwise it will cause an error in the asset system - AzFramework::StringFunc::Path::Join(projectPath, cubeMapRelativePath.c_str(), cubeMapFullPath, true, true); - - if (!AZ::IO::FileIOBase::GetInstance()->Exists(cubeMapFullPath.c_str())) - { - // clear it to force the generation of a new filename - cubeMapRelativePath.clear(); - } + // clear it to force the generation of a new filename + cubeMapRelativePath.clear(); } + } - // build a new cubemap path if necessary - if (cubeMapRelativePath.empty()) - { - // the file name is a combination of the entity name, a UUID, and the filemask - Entity* entity = GetEntity(); - AZ_Assert(entity, "ReflectionProbe entity is null"); + // build a new cubemap path if necessary + if (cubeMapRelativePath.empty()) + { + // the file name is a combination of the entity name, a UUID, and the filemask + Entity* entity = GetEntity(); + AZ_Assert(entity, "ReflectionProbe entity is null"); - AZ::Uuid uuid = AZ::Uuid::CreateRandom(); - AZStd::string uuidString; - uuid.ToString(uuidString); + AZ::Uuid uuid = AZ::Uuid::CreateRandom(); + AZStd::string uuidString; + uuid.ToString(uuidString); - cubeMapRelativePath = "ReflectionProbes/" + entity->GetName() + "_" + uuidString + "_iblspecularcm.dds"; + cubeMapRelativePath = "ReflectionProbes/" + entity->GetName() + "_" + uuidString + "_iblspecularcm.dds"; - // replace any invalid filename characters - auto invalidCharacters = [](char letter) - { - return - letter == ':' || letter == '"' || letter == '\'' || - letter == '{' || letter == '}' || - letter == '<' || letter == '>'; - }; - AZStd::replace_if(cubeMapRelativePath.begin(), cubeMapRelativePath.end(), invalidCharacters, '_'); - - // build the full source path - AzFramework::StringFunc::Path::Join(projectPath, cubeMapRelativePath.c_str(), cubeMapFullPath, true, true); - } - - // make sure the folder is created - AZStd::string reflectionProbeFolder; - AzFramework::StringFunc::Path::GetFolderPath(cubeMapFullPath.data(), reflectionProbeFolder); - AZ::IO::SystemFile::CreateDir(reflectionProbeFolder.c_str()); - - // check out the file in source control - bool checkedOutSuccessfully = false; - using ApplicationBus = AzToolsFramework::ToolsApplicationRequestBus; - ApplicationBus::BroadcastResult( - checkedOutSuccessfully, - &ApplicationBus::Events::RequestEditForFileBlocking, - cubeMapFullPath.c_str(), - "Checking out for edit...", - ApplicationBus::Events::RequestEditProgressCallback()); - - if (!checkedOutSuccessfully) + // replace any invalid filename characters + auto invalidCharacters = [](char letter) { - AZ_Error("ReflectionProbe", false, "Failed to write \"%s\", source control checkout failed", cubeMapFullPath.c_str()); - } - - // write the cubemap data to the .dds file - WriteOutputFile(cubeMapFullPath.c_str(), cubeMapFaceTextureData, cubeMapTextureFormat); - - // save the relative source path in the configuration - AzToolsFramework::ScopedUndoBatch undoBatch("Cubemap path changed."); - m_controller.m_configuration.m_bakedCubeMapRelativePath = cubeMapRelativePath; - SetDirty(); - - // update UI cubemap path display - m_bakedCubeMapRelativePath = cubeMapRelativePath; + return + letter == ':' || letter == '"' || letter == '\'' || + letter == '{' || letter == '}' || + letter == '<' || letter == '>'; + }; + AZStd::replace_if(cubeMapRelativePath.begin(), cubeMapRelativePath.end(), invalidCharacters, '_'); - // call the feature processor to notify when the asset is created and ready - NotifyCubeMapAssetReadyCallback notifyCubeMapAssetReadyCallback = [this](const Data::Asset& cubeMapAsset, CubeMapAssetNotificationType notificationType) - { - // we only need to store the cubemap asset and update the cubemap image on the first bake of the probe, - // otherwise it is a hot-reload of an existing cubemap asset which is handled by the RPI - if (notificationType == CubeMapAssetNotificationType::Ready) - { - // update configuration with the new baked cubemap asset - m_controller.m_configuration.m_bakedCubeMapAsset = { cubeMapAsset.GetAs(), AZ::Data::AssetLoadBehavior::PreLoad }; + // build the full source path + AzFramework::StringFunc::Path::Join(projectPath, cubeMapRelativePath.c_str(), cubeMapFullPath, true, true); + } - // refresh the currently rendered cubemap - m_controller.UpdateCubeMap(); + // make sure the folder is created + AZStd::string reflectionProbeFolder; + AzFramework::StringFunc::Path::GetFolderPath(cubeMapFullPath.data(), reflectionProbeFolder); + AZ::IO::SystemFile::CreateDir(reflectionProbeFolder.c_str()); + + // check out the file in source control + bool checkedOutSuccessfully = false; + using ApplicationBus = AzToolsFramework::ToolsApplicationRequestBus; + ApplicationBus::BroadcastResult( + checkedOutSuccessfully, + &ApplicationBus::Events::RequestEditForFileBlocking, + cubeMapFullPath.c_str(), + "Checking out for edit...", + ApplicationBus::Events::RequestEditProgressCallback()); + + if (!checkedOutSuccessfully) + { + AZ_Error("ReflectionProbe", false, "Failed to write \"%s\", source control checkout failed", cubeMapFullPath.c_str()); + } - // update the UI - AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestRefresh, AzToolsFramework::PropertyModificationRefreshLevel::Refresh_AttributesAndValues); - } + // save the relative source path in the configuration + AzToolsFramework::ScopedUndoBatch undoBatch("Cubemap path changed."); + m_controller.m_configuration.m_bakedCubeMapRelativePath = cubeMapRelativePath; + SetDirty(); - // signal completion - m_bakeInProgress = false; - }; + // update UI cubemap path display + m_bakedCubeMapRelativePath = cubeMapRelativePath; - AZStd::string cubeMapRelativeAssetPath = cubeMapRelativePath + ".streamingimage"; - m_controller.m_featureProcessor->NotifyCubeMapAssetReady(cubeMapRelativeAssetPath, notifyCubeMapAssetReadyCallback); + // callback from the EnvironmentCubeMapPass when the cubemap render is complete + BuildCubeMapCallback buildCubeMapCallback = [=](uint8_t* const* cubeMapFaceTextureData, const RHI::Format cubeMapTextureFormat) + { + // write the cubemap data to the .dds file + WriteOutputFile(cubeMapFullPath.c_str(), cubeMapFaceTextureData, cubeMapTextureFormat); + m_bakeInProgress = false; }; - // initiate the cubemap bake + // initiate the cubemap bake, this will invoke the buildCubeMapCallback when the cubemap data is ready m_bakeInProgress = true; - m_controller.BakeReflectionProbe(buildCubeMapCallback); + AZStd::string cubeMapRelativeAssetPath = cubeMapRelativePath + ".streamingimage"; + m_controller.BakeReflectionProbe(buildCubeMapCallback, cubeMapRelativeAssetPath); // show a dialog box letting the user know the probe is baking QProgressDialog bakeDialog; diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h index eba9575ec4..23fd391818 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h @@ -13,6 +13,7 @@ #pragma once #include +#include #include #include #include @@ -29,6 +30,7 @@ namespace AZ , public EditorReflectionProbeBus::Handler , private AzToolsFramework::EditorComponentSelectionRequestsBus::Handler , private AzFramework::EntityDebugDisplayEventBus::Handler + , private AZ::TickBus::Handler { public: using BaseClass = EditorRenderComponentAdapter; @@ -45,8 +47,12 @@ namespace AZ // AzFramework::EntityDebugDisplayEventBus::Handler overrides void DisplayEntityViewport(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override; + private: + // AZ::TickBus overrides + void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; + // validation AZ::Outcome OnUseBakedCubemapValidate(void* newValue, const AZ::Uuid& valueType); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp index c7349adefa..59d1f7afa7 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp @@ -111,6 +111,18 @@ namespace AZ m_boxShapeInterface = LmbrCentral::BoxShapeComponentRequestsBus::FindFirstHandler(m_entityId); AZ_Assert(m_boxShapeInterface, "ReflectionProbeComponentController was unable to find box shape component"); + // special handling is required if this component is being cloned in the editor: + // if this probe is using a baked cubemap, check to see if it is already referenced by another probe + if (m_configuration.m_useBakedCubemap) + { + if (m_featureProcessor->IsCubeMapReferenced(m_configuration.m_bakedCubeMapRelativePath)) + { + // clear the cubeMapRelativePath to prevent the newly cloned reflection probe + // from using the same cubemap path as the original reflection probe + m_configuration.m_bakedCubeMapRelativePath = ""; + } + } + // add this reflection probe to the feature processor const AZ::Transform& transform = m_transformInterface->GetWorldTM(); m_handle = m_featureProcessor->AddProbe(transform, m_configuration.m_useParallaxCorrection); @@ -130,12 +142,15 @@ namespace AZ m_configuration.m_useBakedCubemap ? m_configuration.m_bakedCubeMapAsset : m_configuration.m_authoredCubeMapAsset; Data::AssetBus::MultiHandler::BusConnect(cubeMapAsset.GetId()); + const AZStd::string& relativePath = + m_configuration.m_useBakedCubemap ? m_configuration.m_bakedCubeMapRelativePath : m_configuration.m_authoredCubeMapAsset.GetHint(); + if (cubeMapAsset.GetId().IsValid()) { if (cubeMapAsset.IsReady()) { Data::Instance image = RPI::StreamingImage::FindOrCreate(cubeMapAsset); - m_featureProcessor->SetProbeCubeMap(m_handle, image); + m_featureProcessor->SetProbeCubeMap(m_handle, image, relativePath); } else { @@ -169,8 +184,11 @@ namespace AZ return; } + const AZStd::string& relativePath = + m_configuration.m_useBakedCubemap ? m_configuration.m_bakedCubeMapRelativePath : m_configuration.m_authoredCubeMapAsset.GetHint(); + Data::Instance image = RPI::StreamingImage::FindOrCreate(asset); - m_featureProcessor->SetProbeCubeMap(m_handle, image); + m_featureProcessor->SetProbeCubeMap(m_handle, image, relativePath); } void ReflectionProbeComponentController::SetConfiguration(const ReflectionProbeComponentConfig& config) @@ -188,8 +206,11 @@ namespace AZ Data::Asset& cubeMapAsset = m_configuration.m_useBakedCubemap ? m_configuration.m_bakedCubeMapAsset : m_configuration.m_authoredCubeMapAsset; + const AZStd::string& relativePath = + m_configuration.m_useBakedCubemap ? m_configuration.m_bakedCubeMapRelativePath : m_configuration.m_authoredCubeMapAsset.GetHint(); + Data::Instance image = RPI::StreamingImage::FindOrCreate(cubeMapAsset); - m_featureProcessor->SetProbeCubeMap(m_handle, image); + m_featureProcessor->SetProbeCubeMap(m_handle, image, relativePath); } void ReflectionProbeComponentController::OnTransformChanged([[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world) @@ -240,14 +261,14 @@ namespace AZ m_configuration.m_innerHeight = AZStd::min(m_configuration.m_innerHeight, m_configuration.m_outerHeight); } - void ReflectionProbeComponentController::BakeReflectionProbe(BuildCubeMapCallback callback) + void ReflectionProbeComponentController::BakeReflectionProbe(BuildCubeMapCallback callback, const AZStd::string& relativePath) { if (!m_featureProcessor) { return; } - m_featureProcessor->BakeProbe(m_handle, callback); + m_featureProcessor->BakeProbe(m_handle, callback, relativePath); } AZ::Aabb ReflectionProbeComponentController::GetAabb() const diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.h index 20d692145c..0a57fde882 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.h @@ -79,7 +79,7 @@ namespace AZ AZ::Aabb GetAabb() const; // initiate the reflection probe bake, invokes callback when complete - void BakeReflectionProbe(BuildCubeMapCallback callback); + void BakeReflectionProbe(BuildCubeMapCallback callback, const AZStd::string& relativePath); // update the currently rendering cubemap asset for this probe void UpdateCubeMap(); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/CaptureStep.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/CaptureStep.cpp index f3c74629c2..16baf16886 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/CaptureStep.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/CaptureStep.cpp @@ -37,6 +37,15 @@ namespace AZ void CaptureStep::Start() { + if (!m_context->GetData()->m_materialAsset || + !m_context->GetData()->m_modelAsset) + { + AzToolsFramework::Thumbnailer::ThumbnailerRendererNotificationBus::Event( + m_context->GetData()->m_thumbnailKeyRendered, + &AzToolsFramework::Thumbnailer::ThumbnailerRendererNotifications::ThumbnailFailedToRender); + m_context->SetStep(Step::FindThumbnailToRender); + return; + } Render::MaterialComponentRequestBus::Event( m_context->GetData()->m_modelEntity->GetId(), &Render::MaterialComponentRequestBus::Events::SetDefaultMaterialOverride, diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/InitializeStep.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/InitializeStep.cpp index 100b0f61cd..322c765f1b 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/InitializeStep.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/InitializeStep.cpp @@ -189,6 +189,7 @@ namespace AZ m_context->GetData()->DefaultModelPath, RPI::ModelAsset::RTTI_Type(), false); + AZ_Error("ThumbnailRenderer", defaultModelAssetId.IsValid(), "Default model asset is invalid. Verify the asset %s exists.", m_context->GetData()->DefaultModelPath); if (m_context->GetData()->m_assetsToLoad.emplace(defaultModelAssetId).second) { data->m_defaultModelAsset.Create(defaultModelAssetId); @@ -203,6 +204,7 @@ namespace AZ m_context->GetData()->DefaultMaterialPath, RPI::MaterialAsset::RTTI_Type(), false); + AZ_Error("ThumbnailRenderer", defaultMaterialAssetId.IsValid(), "Default material asset is invalid. Verify the asset %s exists.", m_context->GetData()->DefaultMaterialPath); if (m_context->GetData()->m_assetsToLoad.emplace(defaultMaterialAssetId).second) { data->m_defaultMaterialAsset.Create(defaultMaterialAssetId); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake index ff8f33e06e..e58f72a121 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake @@ -11,6 +11,8 @@ set(FILES Source/Module.cpp + Source/Animation/EditorAttachmentComponent.h + Source/Animation/EditorAttachmentComponent.cpp Include/AtomLyIntegration/CommonFeatures/Material/EditorMaterialSystemComponentRequestBus.h Include/AtomLyIntegration/CommonFeatures/ReflectionProbe/EditorReflectionProbeBus.h Source/EditorCommonFeaturesSystemComponent.h diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_files.cmake b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_files.cmake index b26ebc60a6..e13d1d37d6 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_files.cmake +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_files.cmake @@ -10,6 +10,8 @@ # set(FILES + Source/Animation/AttachmentComponent.h + Source/Animation/AttachmentComponent.cpp Source/CoreLights/AreaLightComponent.h Source/CoreLights/AreaLightComponent.cpp Source/CoreLights/AreaLightComponentConfig.cpp diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h index b31091681e..1002fcbde1 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h @@ -18,7 +18,7 @@ #include -#include +#include #include #include diff --git a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp index 49ed813ed8..8ae7c30c6a 100644 --- a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp +++ b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/DebugConsole.cpp @@ -126,7 +126,12 @@ namespace AZ SetFilter(inputFilter); // Bind our custom log handler. - AZ::Interface::Get()->BindLogHandler(m_logHandler); + AZ::ILogger* loggerInstance = AZ::Interface::Get(); + AZ_Assert(loggerInstance, "Failed to get ILogger instance. Log handler not bound.") + if (loggerInstance) + { + loggerInstance->BindLogHandler(m_logHandler); + } // Connect to receive render tick events. auto atomViewportRequests = AZ::Interface::Get(); diff --git a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp index 34e7af688c..8493b78171 100644 --- a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp +++ b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp @@ -99,7 +99,7 @@ namespace AZ #endif } - void ImguiAtomSystemComponent::OnViewportSizeChanged(AzFramework::WindowSize size) + void ImguiAtomSystemComponent::OnViewportSizeChanged([[maybe_unused]] AzFramework::WindowSize size) { #if defined(IMGUI_ENABLED) ImGui::ImGuiManagerBus::Broadcast([this, size](ImGui::ImGuiManagerBus::Events* imgui) diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/main.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/main.py index 7fc7d49a40..8ffbee78d5 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/main.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/main.py @@ -29,7 +29,10 @@ import collections from collections import abc # import subprocess import logging as _logging -import pathlib +try: + import pathlib +except: + import pathlib2 as pathlib from pathlib import * import shelve # import socket diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/utilities.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/utilities.py index eb4974bd55..9fd031b106 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/utilities.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/Python/legacy_asset_converter/utilities.py @@ -17,8 +17,14 @@ import logging as _logging + +try: + import pathlib +except: + import pathlib2 as pathlib + from pathlib import Path -import pathlib + from box import Box import os diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/set_callbacks.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/set_callbacks.py index 5d495d2dcd..4a1a7164d8 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/set_callbacks.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/set_callbacks.py @@ -62,15 +62,15 @@ _LOGGER.debug('Invoking:: {0}.'.format({_MODULENAME})) # To Do: move the callback key like 'NewSceneOpened' here (instead of None) # ^ this would provide ability to loop through and replace key with CB object -_G_callbacks = Box(box_dots=True) # global scope container -_G_masterkey = 'DCCsi_callbacks' -_G_callbacks[_G_masterkey] = True # required master key +_G_CALLBACKS = Box(box_dots=True) # global scope container +_G_PRIMEKEY = 'DCCsi_callbacks' +_G_CALLBACKS[_G_PRIMEKEY] = True # required prime key # ------------------------------------------------------------------------- -def init_callbacks(_callbacks=_G_callbacks): +def init_callbacks(_callbacks=_G_CALLBACKS): # store as a dict (Box is a fancy dict) - _callbacks[_G_masterkey] = True # required master key + _callbacks[_G_PRIMEKEY] = True # required prime key # signature dict['callback key'] = ('CallBack'(type), func, callbackObj) _callbacks['on_new_file'] = ['NewSceneOpened', set_defaults, None] @@ -96,24 +96,24 @@ def uninstall_callbacks(): """Bulk uninstalls hte globally defined set of callbacks: _G_callbacks""" - global _G_callbacks + global _G_CALLBACKS _LOGGER.debug('uninstall_callbacks() fired') - for key, value in _G_callbacks: + for key, value in _G_CALLBACKS: if value[2] is not None: # have a cb value[2].uninstall() # so uninstall it else: _LOGGER.warning('No callback in: key {0}, value:{1}' ''.format(key, value)) - _G_callbacks = None + _G_CALLBACKS = None _LOGGER.info('DCCSI CALLBACKS UNINSTALLED ... EXITING') - return _G_callbacks + return _G_CALLBACKS # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- -def install_callbacks(_callbacks=_G_callbacks): +def install_callbacks(_callbacks=_G_CALLBACKS): """Bulk installs the globally defined set of callbacks: _G_callbacks""" @@ -126,15 +126,15 @@ def install_callbacks(_callbacks=_G_callbacks): _callbacks.pop('box_dots') # don't pass anything but carefully considered dict - if _G_masterkey in _callbacks: - _masterkey = _callbacks.pop(_G_masterkey) + if _G_PRIMEKEY in _callbacks: + _primekey = _callbacks.pop(_G_PRIMEKEY) else: - _LOGGER.error('No master key, use a correct dictionary') + _LOGGER.error('No prime key, use a correct dictionary') #To Do: implement error handling and return codes return _callbacks[None] - for key, value in _G_callbacks.items(): - # we popped the master key should the rest should be safe + for key, value in _G_CALLBACKS.items(): + # we popped the prime key should the rest should be safe if value[0] != 'nodeMessageType': # set callback up _cb = azEvCbH.EventCallbackHandler(value[0], @@ -195,10 +195,10 @@ def update_workspace(foo=None): # ------------------------------------------------------------------------- # install and init callbacks on an import obj -_G_callbacks = install_callbacks(_G_callbacks) +_G_CALLBACKS = install_callbacks(_G_CALLBACKS) # ========================================================================== # Module Tests #========================================================================== if __name__ == '__main__': - _G_callbacks = install_callbacks(_G_callbacks) + _G_CALLBACKS = install_callbacks(_G_CALLBACKS) diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/userSetup.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/userSetup.py index 809cb97494..c615311f3c 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/userSetup.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/Scripts/userSetup.py @@ -262,9 +262,9 @@ def post_startup(): # callbacks, To Do: these should also be moved to the bootstrapping config # Defered startup after the Ui is running. - _G_callbacks = Box(box_dots=True) # this just ensures a global scope container + _G_CALLBACKS = Box(box_dots=True) # this just ensures a global scope container if _G_LOAD_CALLBACKS: - from set_callbacks import _G_callbacks + from set_callbacks import _G_CALLBACKS # ^ need to hold on to this as the install repopulate set # this ensures the fixPaths callback is loaded diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/readme.txt b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/readme.txt index 5936b24632..cc090d922f 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/readme.txt +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/readme.txt @@ -74,7 +74,9 @@ Now your local maya install is all set up with pip so you can install additional Now you will want to run the following file to finish setup... We have a requirements.txt file with the extension packages we use in the DCCsi. -You'll need the repo/branch path of your Lumberyard(O3DE) install. -And you'll need to know where the DCCsi, we will install package dependancies there. +You'll need the repo/branch path of your O3DE (aka Lumberyard) install. +And you'll need to know where the DCCsi is located, we will install package dependancies there. -C:\Program Files\Autodesk\Maya2020\bin>mayapy -m pip install -r C:\Depot\Lumberyard\Gems\AtomLyIntegration\TechnicalArt\DccScriptingInterface\SDK\Maya\requirements.txt -t C:\Depot\Lumberyard\Gems\AtomLyIntegration\TechnicalArt\DccScriptingInterface\3rdParty\Python\Lib\2.x\2.7.x\site-packages +Note: you may need to update the paths below to match your local o3de engine install! + +C:\Program Files\Autodesk\Maya2020\bin>mayapy -m pip install -r C:\Depot\o3de\Gems\AtomLyIntegration\TechnicalArt\DccScriptingInterface\SDK\Maya\requirements.txt -t C:\Depot\o3de\Gems\AtomLyIntegration\TechnicalArt\DccScriptingInterface\3rdParty\Python\Lib\2.x\2.7.x\site-packages diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/requirements.txt b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/requirements.txt index 2d087be121..8fd084dac8 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/requirements.txt +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/SDK/Maya/requirements.txt @@ -4,12 +4,14 @@ # # pip-compile --generate-hashes requirements.txt # -typing==3.7.4.3 \ - --hash=sha256:1187fb9c82fd670d10aa07bbb6cfcfe4bdda42d6fab8d5134f04e8c4d0b71cc9 \ - --hash=sha256:283d868f5071ab9ad873e5e52268d611e851c870a2ba354193026f2dfb29d8b5 - # via - # -r requirements.txt - # dynaconf +cachetools==3.1.1 \ + --hash=sha256:428266a1c0d36dc5aca63a2d7c5942e88c2c898d72139fca0e97fdd2380517ae \ + --hash=sha256:8ea2d3ce97850f31e4a08b0e2b5e6c34997d7216a9d2c98e0f3978630d4da69a + # via -r requirements.txt +certifi==2020.6.20 \ + --hash=sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3 \ + --hash=sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41 + # via -r requirements.txt click==7.1.2 \ --hash=sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a \ --hash=sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc @@ -20,6 +22,14 @@ dynaconf==3.1.4 \ --hash=sha256:b2f472d83052f809c5925565b8a2ba76a103d5dc1dbb9748b693ed67212781b9 \ --hash=sha256:e6f383b84150b70fc439c8b2757581a38a58d07962aa14517292dcce1a77e160 # via -r requirements.txt +hashids==1.3.1 \ + --hash=sha256:6c3dc775e65efc2ce2c157a65acb776d634cb814598f406469abef00ae3f635c \ + --hash=sha256:8bddd1acba501bfc9306e7e5a99a1667f4f2cacdc20cbd70bcc5ddfa5147c94c + # via -r requirements.txt +pathlib2==2.3.5 \ + --hash=sha256:0ec8205a157c80d7acc301c0b18fbd5d44fe655968f5d947b6ecef5290fc35db \ + --hash=sha256:6cd9a47b597b37cc57de1c05e56fb1a1c9cc9fab04fe78c29acd090418529868 + # via -r requirements.txt pathlib==1.0.1 \ --hash=sha256:6940718dfc3eff4258203ad5021090933e5c04707d5ca8cc9e73c94a7894ea9f # via -r requirements.txt @@ -27,7 +37,38 @@ python-box==3.4.6 \ --hash=sha256:694a7555e3ff9fbbce734bbaef3aad92b8e4ed0659d3ed04d56b6a0a0eff26a9 \ --hash=sha256:a71d3dc9dbaa34c8597d3517c89a8041bd62fa875f23c0f3dad55e1958e3ce10 # via -r requirements.txt +scandir==1.10.0 \ + --hash=sha256:2586c94e907d99617887daed6c1d102b5ca28f1085f90446554abf1faf73123e \ + --hash=sha256:2ae41f43797ca0c11591c0c35f2f5875fa99f8797cb1a1fd440497ec0ae4b022 \ + --hash=sha256:2b8e3888b11abb2217a32af0766bc06b65cc4a928d8727828ee68af5a967fa6f \ + --hash=sha256:2c712840c2e2ee8dfaf36034080108d30060d759c7b73a01a52251cc8989f11f \ + --hash=sha256:4d4631f6062e658e9007ab3149a9b914f3548cb38bfb021c64f39a025ce578ae \ + --hash=sha256:67f15b6f83e6507fdc6fca22fedf6ef8b334b399ca27c6b568cbfaa82a364173 \ + --hash=sha256:7d2d7a06a252764061a020407b997dd036f7bd6a175a5ba2b345f0a357f0b3f4 \ + --hash=sha256:8c5922863e44ffc00c5c693190648daa6d15e7c1207ed02d6f46a8dcc2869d32 \ + --hash=sha256:92c85ac42f41ffdc35b6da57ed991575bdbe69db895507af88b9f499b701c188 \ + --hash=sha256:b24086f2375c4a094a6b51e78b4cf7ca16c721dcee2eddd7aa6494b42d6d519d \ + --hash=sha256:cb925555f43060a1745d0a321cca94bcea927c50114b623d73179189a4e100ac + # via + # -r requirements.txt + # pathlib2 +six==1.15.0 \ + --hash=sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259 \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced + # via + # -r requirements.txt + # pathlib2 +typing==3.7.4.3 \ + --hash=sha256:1187fb9c82fd670d10aa07bbb6cfcfe4bdda42d6fab8d5134f04e8c4d0b71cc9 \ + --hash=sha256:283d868f5071ab9ad873e5e52268d611e851c870a2ba354193026f2dfb29d8b5 + # via + # -r requirements.txt + # dynaconf unipath==1.1 \ --hash=sha256:09839adcc72e8a24d4f76d63656f30b5a1f721fc40c9bcd79d8c67bdd8b47dae \ --hash=sha256:e6257e508d8abbfb6ddd8ec357e33589f1f48b1599127f23b017124d90b0fff7 # via -r requirements.txt +wincertstore==0.2 \ + --hash=sha256:22d5eebb52df88a8d4014d5cf6d1b6c3a5d469e6c3b2e2854f3a003e48872356 \ + --hash=sha256:780bd1557c9185c15d9f4221ea7f905cb20b93f7151ca8ccaed9714dce4b327a + # via -r requirements.txt diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/__init__.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/__init__.py index 57b97ad1cb..69e4543a59 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/__init__.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/__init__.py @@ -36,11 +36,10 @@ _TYPE_TAG = 'module' _PACKAGENAME = _TOOL_TAG -__all__ = ['initialize_logger', - 'config_utils', 'render', +__all__ = ['config_utils', 'render', 'constants', 'return_stub', 'synthetic_env', 'env_base', 'env_bool', 'test', 'dev', - 'lumberyard', 'marmoset'] #'blender', 'maya', 'substance', 'houdini'] + 'lumberyard', 'marmoset'] # 'blender', 'maya', 'substance', 'houdini'] # ------------------------------------------------------------------------- @@ -68,7 +67,10 @@ _DCCSI_DEV_MODE = env_bool.env_bool(constants.ENVAR_DCCSI_DEV_MODE, False) # for py2.7 (Maya) we provide this, so we must assume some bootstrapping # has occured, see DccScriptingInterface\\config.py (_DCCSI_PYTHON_LIB_PATH) -import pathlib +try: + import pathlib +except: + import pathlib2 as pathlib from pathlib import Path if _G_DEBUG: print('DCCsi debug breadcrumb, pathlib is: {}'.format(pathlib)) diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/config_utils.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/config_utils.py index dbc75212d4..9c920a871d 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/config_utils.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/config_utils.py @@ -80,9 +80,9 @@ def return_stub_dir(stub_file='dccsi_stub'): # ------------------------------------------------------------------------- -def get_stub_check_path(in_path=os.getcwd(), check_stub='engineroot.txt'): +def get_stub_check_path(in_path=os.getcwd(), check_stub='engine.json'): ''' - Returns the branch root directory of the dev\\'engineroot.txt' + Returns the branch root directory of the dev\\'engine.json' (... or you can pass it another known stub) so we can safely build relative filepaths within that branch. @@ -158,7 +158,6 @@ def bootstrap_dccsi_py_libs(dccsi_dirpath=return_stub_dir()): """Builds and adds local site dir libs based on py version""" from azpy.constants import STR_DCCSI_PYTHON_LIB_PATH # a path string constructor - #_DCCSI_PYTHON_LIB_PATH = "E:\\P4\\jromnoa_spectra_atom_2\\dev\\Tools\\Python\\3.7.5\\windows\\Lib\\site-packages" _DCCSI_PYTHON_LIB_PATH = STR_DCCSI_PYTHON_LIB_PATH.format(dccsi_dirpath, sys.version_info[0], sys.version_info[1]) @@ -193,9 +192,9 @@ if __name__ == '__main__': _config = get_dccsi_config() _LOGGER.info('DCCSI_CONFIG_PATH: {}'.format(_config)) - _LOGGER.info('LY_DEV: {}'.format(get_stub_check_path('engineroot.txt'))) + _LOGGER.info('LY_DEV: {}'.format(get_stub_check_path('engine.json'))) - _LOGGER.info('LY_PROJECT: {}'.format(get_current_project(get_stub_check_path('engineroot.txt')))) + _LOGGER.info('LY_PROJECT: {}'.format(get_current_project(get_stub_check_path('bootstrap.cfg')))) _LOGGER.info('DCCSI_PYTHON_LIB_PATH: {}'.format(bootstrap_dccsi_py_libs(return_stub_dir('dccsi_stub')))) diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/constants.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/constants.py index 5ca0bc4a95..792f0faee6 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/constants.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/constants.py @@ -92,7 +92,7 @@ TAG_DIR_LY_BUILD = str('build') TAG_QT_PLUGIN_PATH = str('QT_PLUGIN_PATH') # filesystem markers, stub file names. -STUB_LY_DEV = str('engineroot.txt') +STUB_LY_DEV = str('engine.json') STUB_LY_ROOT_PROJECT = str('ly_project_stub') STUB_LY_ROOT_DCCSI = str('dccsi_stub') STUB_LY_DCCSI_AZPY = str('dccsi_azpy_stub') diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/maya/utils/wing_to_maya.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/maya/utils/wing_to_maya.py index 9798f3f268..3d34aceb40 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/maya/utils/wing_to_maya.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/maya/utils/wing_to_maya.py @@ -36,7 +36,7 @@ _LOGGER.info('local_host: {}'.format(_LOCAL_HOST)) # ------------------------------------------------------------------------- def start_wing_to_maya(local_host=_LOCAL_HOST, - comman_port=6000, + command_port=6000, logger=_LOGGER, *args, **kwargs): """ @@ -58,7 +58,7 @@ def start_wing_to_maya(local_host=_LOCAL_HOST, except NameError: port = None - port_name = str('{0}:{1}'.format(local_host, comman_port)) + port_name = str('{0}:{1}'.format(local_host, command_port)) # should only be getting the port passed in _LOGGER.info('Attempting to open port:: {0}'.format(port_name)) @@ -145,10 +145,10 @@ def start_wing_to_maya_menu(): port = object() # init a dummy object # default name ... name is first arg, or a kwarg - portName, kwargs = setSynthArgKwarg(port, argPosIndex=0, argTag='portName', - inArgs=args, inKwargs=kwargs, - defaultValue="127.0.0.1:6000") + portName, kwargs = set_synth_arg_kwarg(port, arg_pos_index=0, arg_tag='portName', + in_args=args, in_kwargs=kwargs, + default_value="127.0.0.1:6000") - port = start_wing_to_maya(local_host=_LOCAL_HOST, comman_port=6000) + port = start_wing_to_maya(local_host=_LOCAL_HOST, command_port=6000) return # ------------------------------------------------------------------------- diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/__init__.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/__init__.py index 7d165916c5..b30fef72c8 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/__init__.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/__init__.py @@ -15,30 +15,118 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """azpy.shared.ui.__init__""" import os -import logging -import logging.config +from pathlib import Path +import logging as _logging -# global space debug flag -_G_DEBUG = os.getenv('DCCSI_GDEBUG', False) +from azpy.env_bool import env_bool +from azpy.constants import ENVAR_DCCSI_GDEBUG +from azpy.constants import ENVAR_DCCSI_DEV_MODE -# global space debug flag -_DCCSI_DEV_MODE = os.getenv('DCCSI_DEV_MODE', False) +# global space +_G_DEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False) +_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False) -if _DCCSI_DEV_MODE: - _PACKAGENAME = __name__ - if _PACKAGENAME is '__main__': - _PACKAGENAME = 'noodely' - -_PKG_PARENT_PATH = str('azpy.shared') -_PKG_PATH = str('{0}.{1}'.format(_PKG_PARENT_PATH, _PACKAGENAME)) -_LOGGER = logging.getLogger(_PACKAGENAME) -_LOGGER.debug('Invoking __init__.py for {0}.'.format({_PKG_PATH})) +_PACKAGENAME = __name__ +if _PACKAGENAME is '__main__': + _PACKAGENAME = 'azpy.shared.noodely' +import azpy +_LOGGER = azpy.initialize_logger(_PACKAGENAME) +_LOGGER.debug('Invoking __init__.py for {0}.'.format({_PACKAGENAME})) # ------------------------------------------------------------------------- # -__all__ = ['config', 'find_arg', 'master', 'node', 'synth', - 'synth_arg_kwarg', 'test_foo'] +__all__ = ['find_arg', + 'helpers', + 'node', + 'synth', + 'synth_arg_kwarg', + 'test_foo'] # # ------------------------------------------------------------------------- -del _LOGGER + +# -- Project Globals ------------------------------------------------------ +while 1: + # But if we want to change the prject root, we can set a new one here. + def set_G_DEFAULT_PROJECT_DIR(value): + global _G_DEFAULT_PROJECT_DIR + """Sets and returns the _G_DEFAULT_PROJECT_DIR""" + _G_DEFAULT_PROJECT_DIR = Path(value).resolve() + return Path(_G_DEFAULT_PROJECT_DIR) + + def get_G_DEFAULT_PROJECT_DIR(): + global _G_DEFAULT_PROJECT_DIR + """Returns the _G_DEFAULT_PROJECT_DIR""" + return Path(_G_DEFAULT_PROJECT_DIR) + + # if we are initializing everythin properly, we can assume the project + # variables are properly set + global _G_DEFAULT_PROJECT_DIR + _G_DEFAULT_PROJECT_DIR = Path(os.getcwd()).resolve() + + break +# ------------------------------------------------------------------------- + +# ------------------------------------------------------------------------- +while 1: + global _G_PRIME_ROOT_NODE + _G_PRIME_ROOT_NODE = None # <-- needs to be set up! + # But if we want to change the prject root, we can set a new one here. + + def set_G_PRIME_ROOT_NODE(node): + """Sets and returns the _G_PRIME_ROOT_NODE""" + global _G_PRIME_ROOT_NODE + if not isinstance(node, ProjectRootNode): + message = '_G_PRIME_ROOT_NODE: {}\r'.format(type(node)) + message += 'A project root node needs to be properly set\r' + raise TypeError(message) + _G_PRIME_ROOT_NODE = node + return _G_PRIME_ROOT_NODE + + def get_G_PRIME_ROOT_NODE(): + """Returns the _G_PRIME_ROOT_NODE""" + global _G_PRIME_ROOT_NODE + return _G_PRIME_ROOT_NODE + + break +# ------------------------------------------------------------------------- + + +########################################################################### +# tests(), code block for testing module +# ------------------------------------------------------------------------- +def tests(): + _G_DEFAULT_PROJECT_DIR = set_G_DEFAULT_PROJECT_DIR(os.getcwd()) + _LOGGER.info(_G_DEFAULT_PROJECT_DIR) + _LOGGER.info(_G_DEFAULT_PROJECT_DIR.parent) + _LOGGER.info(_G_DEFAULT_PROJECT_DIR.parts) + + # NOT implemented yet + # _G_PRIME_ROOT_NODE + + return +# ------------------------------------------------------------------------- + + +# ------------------------------------------------------------------------- +if _DCCSI_DEV_MODE: + # If in dev mode this will test imports of __all__ + from azpy import test_imports + _LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME)) + test_imports(__all__, + _pkg=_PACKAGENAME, + _logger=_LOGGER) +# ------------------------------------------------------------------------- + + +########################################################################### +# --call block------------------------------------------------------------- +if __name__ == "__main__": + _LOGGER.info("# {0} #".format('-' * 72)) + _LOGGER.info('~ noodely.prime ... Running script as __main__') + _LOGGER.info("# {0} #".format('-' * 72)) + + # run simple tests + tests() + +del _LOGGER \ No newline at end of file diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/find_arg.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/find_arg.py index 517064e57a..1ed217bc73 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/find_arg.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/find_arg.py @@ -23,8 +23,8 @@ __author__ = 'HogJonny' # ------------------------------------------------------------------------- -def find_arg(argPosIndex=None, argTag=None, removeKwarg=None, - inArgs=None, inKwargs=None, defaultValue=None): +def find_arg(arg_pos_index=None, arg_tag=None, remove_kwarg=None, + in_args=None, in_kwargs=None, default_value=None): """ # finds and returns an arg... # if a positional index is given argPosIndex=0, it checks args first @@ -41,31 +41,33 @@ def find_arg(argPosIndex=None, argTag=None, removeKwarg=None, # # foundArg, args, kwargs = find_arg(0, 'name',) """ - if argPosIndex != None: - if not isinstance(argPosIndex, int): + + found_arg = None + + if arg_pos_index != None: + if not isinstance(arg_pos_index, int): raise TypeError('argPosIndex: accepts a index integer!\r' - 'got: {0}'.format(argPosIndex)) + 'got: {0}'.format(arg_pos_index)) # positional args ... check the position - if len(inArgs) > 0: + if len(in_args) > 0: try: - foundArg = inArgs[argPosIndex] + found_arg = in_args[arg_pos_index] except: pass # check kwargs ... a set kwarg will ALWAYS take precident over # positional arg!!! - try: - foundArg - except: - foundArg = inKwargs.get(argTag, defaultValue) # defaults to None + if in_kwargs: + found_arg = in_kwargs.get(arg_tag, default_value) # defaults to None - if removeKwarg: - if argTag in inKwargs: - del inKwargs[argTag] + if remove_kwarg: + if in_kwargs: + if arg_tag in in_kwargs: + del in_kwargs[arg_tag] # if we didn't find the arg/kwarg, the defualt return will be None - return foundArg, inKwargs + return found_arg, in_kwargs # ------------------------------------------------------------------------- @@ -86,14 +88,14 @@ if __name__ == "__main__": class TestNode(Foo): def __init__(self, *args, **kwargs): super().__init__() - self._name, kwargs = find_arg(argTag='foo', removeKwarg=True, - inArgs=args, inKwargs=kwargs) - self._name, kwargs = find_arg(argPosIndex=0, argTag='name', - removeKwarg=True, - inArgs=args, inKwargs=kwargs) # <-- first positional OR kwarg - self._parent, kwargs = find_arg(argPosIndex=1, argTag='parent', - removeKwarg=True, - inArgs=args, inKwargs=kwargs) # <-- second positional OR kwarg + self._name, kwargs = find_arg(arg_tag='foo', remove_kwarg=True, + in_args=args, in_kwargs=kwargs) + self._name, kwargs = find_arg(arg_pos_index=0, arg_tag='name', + remove_kwarg=True, + in_args=args, in_kwargs=kwargs) # <-- first positional OR kwarg + self._parent, kwargs = find_arg(arg_pos_index=1, arg_tag='parent', + remove_kwarg=True, + in_args=args, in_kwargs=kwargs) # <-- second positional OR kwarg self._kwargsDict = {} @@ -117,7 +119,7 @@ if __name__ == "__main__": testNode2 = TestNode(name='fooey', parent=testNode) - testNode3 = TestNode('kablooey', testNode2, goober='dufus') + testNode3 = TestNode('kablooey', testNode2, gomer='pile') print ('testNode2, name: {0}, parent: {1}'.format(testNode2._name, testNode2._parent)) print (testNode3) diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/master.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/master.py deleted file mode 100644 index d85ea48854..0000000000 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/master.py +++ /dev/null @@ -1,90 +0,0 @@ -""" -All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -its licensors. - -For complete copyright and license terms please see the LICENSE at the root of this -distribution (the "License"). All use of this software is governed by the License, -or, if provided, by the license below or the license accompanying this file. Do not -remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -""" -# ------------------------------------------------------------------------- - -# ------------------------------------------------------------------------- -# ------------------------------------------------------------------------- -# master.py -# Allows for project based setup to be used with noodly -# version: 0.1 -# author: Gallowj -# ------------------------------------------------------------------------- -# ------------------------------------------------------------------------- -import os - -from unipath import Path - -_G_DEFAULT_PROJECT_DIR = os.getcwd() -_G_MASTER_ROOT_NODE = None - - -@property -def _G_DEFAULT_PROJECT_DIR(value): - _G_DEFAULT_PROJECT_DIR = value - return _G_DEFAULT_PROJECT_DIR - - -def set_PROJECT_DIR(value): - """Sets and returns _G_DEFAULT_PROJECT_DIR""" - global _G_DEFAULT_PROJECT_DIR - _G_DEFAULT_PROJECT_DIR = Path(value).expand() - return Path(_G_DEFAULT_PROJECT_DIR) - - -@property -def _G_MASTER_ROOT_NODE(value): - _G_MASTER_ROOT_NODE = value - return _G_MASTER_ROOT_NODE - - -def set_MASTER_ROOT_NODE(value): - """Sets and returns _G_MASTER_ROOT_NODE""" - global _G_MASTER_ROOT_NODE - if not isinstance(inNode, ProjectRootNode): - raise TypeError('self._projectRootNode is: {0}\r' - 'A _projectRootNode, needs to be properly set\r' - 'So that we can acces:\r' - '\tself._projectRootNode._sourceRoot\r' - '\tself._projectRootNode._overrideRoot\r' - 'Use self.assignProjectRootNode()\r' - ''.format(type(inNode))) - - _G_MASTER_ROOT_NODE = inNode - return _G_MASTER_ROOT_NODE - - -########################################################################### -# tests(), code block for testing module -# ------------------------------------------------------------------------- -def tests(): - set_PROJECT_DIR(os.getcwd()) - print(_G_DEFAULT_PROJECT_DIR) - print(_G_DEFAULT_PROJECT_DIR.parent) - print(_G_DEFAULT_PROJECT_DIR.components()) - - # NOT implemented yet - # set_PROJECT_DIR - - return - - -########################################################################### -# --call block------------------------------------------------------------- -if __name__ == "__main__": - print ("# ----------------------------------------------------------------------- #") - print ('~ noodly.master ... Running script as __main__') - print ("# ----------------------------------------------------------------------- #\r") - - # run simple tests - tests() - - #_G_DEFAULT_PROJECT_DIR = Path(os.getcwd()) - print(_G_DEFAULT_PROJECT_DIR.components()) diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/node.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/node.py index 4eca3b315d..950b8fcbec 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/node.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/node.py @@ -16,7 +16,7 @@ from __future__ import division # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # node.py -# simple base Node Class, for tool creation. +# simple base Node Class, useful in tool creation. # version: 0.1 # author: Gallowj # ------------------------------------------------------------------------- @@ -25,16 +25,8 @@ from __future__ import division Module docstring: A Simple Node Base Class Module, for creating basic nodes within a hierarchy. """ - __author__ = 'HogJonny' -_G_DEBUG = True # global state for debugging -_G_SETTINGS = None # global Settings storage -_G_LOG = None # global LOGger storage - -_G_MASTER_NODE = None # We intend to init a master node, unless provided - -# ------------------------------------------------------------------------- # built-ins import os import copy @@ -48,11 +40,32 @@ import cachetools from sched import scheduler # local imports -from LyPy.si_shared.noodly.helpers import display_cached_value -from LyPy.si_shared.noodly.find_arg import find_arg -from LyPy.si_shared.noodly.synth import synthesize +from azpy.shared.noodely.helpers import display_cached_value +from azpy.shared.noodely.find_arg import find_arg +from azpy.shared.noodely.synth import synthesize + +import azpy +from azpy.env_bool import env_bool +from azpy.constants import ENVAR_DCCSI_GDEBUG +from azpy.constants import ENVAR_DCCSI_DEV_MODE + +# global space +# To Do: update to dynaconf dynamic env and settings? +_G_DEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False) +_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False) + +_MODULENAME = 'azpy.shared.noodely.node' + +_log_level = int(20) +if _G_DEBUG: + _log_level = int(10) +_LOGGER = azpy.initialize_logger(_MODULENAME, + log_to_file=False, + default_log_level=_log_level) +_LOGGER.debug('Starting:: {}.'.format({_MODULENAME})) # ------------------------------------------------------------------------- + # ------------------------------------------------------------------------- # quick test code (remove later) from hashids import Hashids @@ -79,8 +92,6 @@ if os.path.supports_unicode_filenames: ########################################################################### # HELPER method functions # ------------------------------------------------------------------------- - - def return_node_from_hashid(hashid): if not isinstance(hashid, str): raise TypeError("{0},{1}: Accepts hashids as str types!\r" @@ -95,6 +106,7 @@ def return_node_from_hashid(hashid): # ------------------------------------------------------------------------- +# ------------------------------------------------------------------------- class Node(object): """Class constructor: makes a node.""" @@ -131,9 +143,9 @@ class Node(object): # -- secret keyword ----------------------------------------------- self._temp_node = False - temp_node, kwargs = find_arg(argPosIndex=None, argTag='temp_node', - removeKwarg=True, inArgs=args, - inKwargs=kwargs) # <-- kwarg only + temp_node, kwargs = find_arg(arg_pos_index=None, arg_tag='temp_node', + remove_kwarg=True, in_args=args, + in_kwargs=kwargs) # <-- kwarg only self._temp_node = temp_node if self._temp_node: self._kwargs_dict['temp_node'] = self._temp_node @@ -141,9 +153,9 @@ class Node(object): # -- store message header ----------------------------------------- # setup the .message_header <-- kwarg only - message_header, kwargs = find_arg(argPosIndex=None, argTag='message_header', - removeKwarg=True, inArgs=args, inKwargs=kwargs, - defaultValue=('{0}(), Message' + message_header, kwargs = find_arg(arg_pos_index=None, arg_tag='message_header', + remove_kwarg=True, in_args=args, in_kwargs=kwargs, + default_value=('{0}(), Message' .format(self._node_type))) self._message_header = message_header # ----------------------------------------------------------------- @@ -165,7 +177,7 @@ class Node(object): # -- store the node name ------------------------------------------ self._node_name = node_name if (self._node_class_index == 0 and self._node_name == None): - self._node_name = 'MASTER' + self._node_name = 'PRIME' elif (self._node_class_index > 0 and self._node_name == None): # set a default node_name if none, based on the unihashid if not self._name_is_uni_hashid: @@ -325,7 +337,7 @@ class Node(object): @property def cls_node_dict(self): return Node._cls_node_dict - # ---------------------------------------------------------------------- + # --------------------------------------------------------------------- # --method-set--------------------------------------------------------- def cls_node_count_up(self): @@ -584,10 +596,10 @@ def tests(): print(default_node.hierarchy()) # retreive a node from it's known hashid - master_node = return_node_from_hashid('kxYLm0XQeXJ7jWaP') - print(master_node.uni_hashid) # verify hasid + prime_node = return_node_from_hashid('kxYLm0XQeXJ7jWaP') + print(prime_node.uni_hashid) # verify hasid # should return the same node as default_node - print(master_node.node_name) # should be 'MASTER' + print(prime_node.node_name) # should be 'PRIME' return # ------------------------------------------------------------------------- diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/pathnode.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/pathnode.py index f969e16fbe..5dee58b1c5 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/pathnode.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/pathnode.py @@ -27,12 +27,6 @@ A simple path objecy based Node Class, for creating path hierarchies. """ __author__ = 'HogJonny' -_G_DEBUG = True # global state for debugging -_G_SETTINGS = None # global Settings storage -_G_LOG = None # global LOGger storage - -_G_MASTER_NODE = None # We intend to init a master node - # ------------------------------------------------------------------------- # built-ins import os @@ -44,10 +38,31 @@ import logging from unipath import Path, AbstractPath # local ly imports -from LyPy.si_shared.noodly.helpers import istext -from LyPy.si_shared.noodly.find_arg import find_arg -from LyPy.si_shared.noodly.synth import synthesize -from LyPy.si_shared.noodly.node import Node +from azpy.shared.noodely.helpers import istext +from azpy.shared.noodely.find_arg import find_arg +from azpy.shared.noodely.synth import synthesize +from azpy.shared.noodely.node import Node + +import azpy +from azpy.env_bool import env_bool +from azpy.constants import ENVAR_DCCSI_GDEBUG +from azpy.constants import ENVAR_DCCSI_DEV_MODE + +# ------------------------------------------------------------------------- +# global space +# To Do: update to dynaconf dynamic env and settings? +_G_DEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False) +_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False) + +_MODULENAME = 'azpy.shared.noodely.pathnode' + +_log_level = int(20) +if _G_DEBUG: + _log_level = int(10) +_LOGGER = azpy.initialize_logger(_MODULENAME, + log_to_file=False, + default_log_level=_log_level) +_LOGGER.debug('Starting:: {}.'.format({_MODULENAME})) # ------------------------------------------------------------------------- @@ -63,20 +78,12 @@ if os.path.supports_unicode_filenames: # ------------------------------------------------------------------------- -# set up logger -_G_LOGGER = logging.getLogger(__name__) -# ------------------------------------------------------------------------- - - class PathNode(Node): """doc string""" # share the debug state _DEBUG = _G_DEBUG - # logger - _LOGGER = _G_LOGGER - # class header _message_header = 'noodly, PathNode(): Message' @@ -117,22 +124,22 @@ class PathNode(Node): # -- secret keyword ----------------------------------------------- self._temp_node = False - temp_node, kwargs = find_arg(argPosIndex=None, argTag='temp_node', - removeKwarg=True, inArgs=args, - inKwargs=kwargs) # <-- kwarg only + temp_node, kwargs = find_arg(arg_pos_index=None, arg_tag='temp_node', + remove_kwarg=True, in_args=args, + in_kwargs=kwargs) # <-- kwarg only self._temp_node = temp_node if self._temp_node: self.k_wargs_dict['temp_node'] = self._temp_node # -- Node class args/kwargs --------------------------------------- - node_name, kwargs = find_arg(argPosIndex=2, argTag='node_name', - removeKwarg=True, inArgs=args, - inKwargs=kwargs) # <-- third arg, kwarg + node_name, kwargs = find_arg(arg_pos_index=2, arg_tag='node_name', + remove_kwarg=True, in_args=args, + in_kwargs=kwargs) # <-- third arg, kwarg - parent_node, kwargs = find_arg(argPosIndex=3, argTag='parent_node', - removeKwarg=True, inArgs=args, - inKwargs=kwargs) # <-- fourth arg, kwarg + parent_node, kwargs = find_arg(arg_pos_index=3, arg_tag='parent_node', + remove_kwarg=True, in_args=args, + in_kwargs=kwargs) # <-- fourth arg, kwarg self._root_path = root_path @@ -344,12 +351,12 @@ class PathNode(Node): # ------------------------------------------------------------------------- def tests(): from node import Node - default_node = Node() # result: Node(node_name='MASTER') + default_node = Node() # result: Node(node_name='PRIME') print(default_node) first_child = PathNode(path=None, node_name='first_child', parent_node=default_node) print(first_child) - # result: PathNode(temp_node=True, parent_node=Node(node_name='MASTER')).siblingNodeFromHashid('WNPZoKBVpXV16QLz') + # result: PathNode(temp_node=True, parent_node=Node(node_name='PRIME')).siblingNodeFromHashid('WNPZoKBVpXV16QLz') # first_child.nodeType # first_child.parent_node # first_child.node_name diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/synth_arg_kwarg.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/synth_arg_kwarg.py index 3618ad67de..0f71439dae 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/synth_arg_kwarg.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/synth_arg_kwarg.py @@ -22,9 +22,9 @@ from synth import synthesize # ------------------------------------------------------------------------- -def setSynthArgKwarg(inst, argPosIndex=None, argTag=None, defaultValue=None, - inArgs=None, inKwargs=None, removeKwarg=True, - setAnyway=True): +def set_synth_arg_kwarg(inst, arg_pos_index=None, arg_tag=None, default_value=None, + in_args=None, in_kwargs=None, remove_kwarg=True, + set_anyway=True): """ Uses find_arg and sets a property on a object. @@ -34,44 +34,44 @@ def setSynthArgKwarg(inst, argPosIndex=None, argTag=None, defaultValue=None, If the arg/property doesn't exist we synthesize it """ - foundArg = None - argValueDict = {} + found_arg = None + arg_value_dict = {} # find the argument, or set to default value - foundArg, inKwargs = find_arg(argPosIndex, argTag, removeKwarg, - inArgs, inKwargs, - defaultValue) + found_arg, in_kwargs = find_arg(arg_pos_index, arg_tag, remove_kwarg, + in_args, in_kwargs, + default_value) - if foundArg: - argTag = foundArg + if found_arg: + arg_tag = found_arg # single arg first # make sure the object doesn't arealdy have this property try: - hasattr(inst, argTag) # check if property exists - if setAnyway: + hasattr(inst, arg_tag) # check if property exists + if set_anyway: try: - setattr(inst, argTag, defaultValue) # try to set + setattr(inst, arg_tag, default_value) # try to set except Exception as e: raise e except: pass # make it a synthetic property - if argTag: + if arg_tag: try: - argValue = synthesize(inst, argTag, defaultValue) - argValueDict[argTag] = argValue + arg_value = synthesize(inst, arg_tag, default_value) + arg_value_dict[arg_tag] = arg_value except Exception as e: raise e # multiple and/or remaining kwards next - if inKwargs: - if len(inKwargs) > 0: - for k, v in inKwargs.items(): + if in_kwargs: + if len(in_kwargs) > 0: + for k, v in in_kwargs.items(): try: hasattr(inst, k) # check if property exists - if setAnyway: + if set_anyway: try: setattr(inst, k, v) # try to set except Exception as e: @@ -81,12 +81,12 @@ def setSynthArgKwarg(inst, argPosIndex=None, argTag=None, defaultValue=None, if k: try: - argValue = synthesize(inst, k, v) - argValueDict[k] = argValue + arg_value = synthesize(inst, k, v) + arg_value_dict[k] = arg_value except Exception as e: raise e - return argValueDict + return arg_value_dict # -------------------------------------------------------------------------- @@ -98,28 +98,28 @@ if __name__ == '__main__': from test_foo import Foo # define a arg/property tag we know doesn't exist - synthArgTag = 'syntheticArg' + synth_arg_tag = 'synthetic_arg' # create a test object print('~ creating the test foo object...') - myFoo = Foo() + my_foo = Foo() print('~ Starting - single synthetic arg test...') # find and set existing, or create and set - argValueDict = setSynthArgKwarg(myFoo, - argTag=synthArgTag, - defaultValue='kablooey') + arg_value_dict = set_synth_arg_kwarg(my_foo, + arg_tag=synth_arg_tag, + default_value='kablooey') # what was returned print('~ single value returned...') - for k, v in argValueDict.items(): + for k, v in arg_value_dict.items(): print("Arg '{0}':'{1}'".format(k, v)) # attempt to access the new synthetic property directly print('~ direct property access test...') try: - myFoo.syntheticArg - print('myFoo.{0}: {1}'.format(synthArgTag, myFoo.syntheticArg)) + my_foo.synthetic_arg + print('myFoo.{0}: {1}'.format(synth_arg_tag, my_foo.synthetic_arg)) except Exception as e: raise e @@ -128,31 +128,31 @@ if __name__ == '__main__': newKwargs = {'fooey': 'chop suey', 'success': True} # find and set existing, or create and set - argValueDict = setSynthArgKwarg(myFoo, - inKwargs=newKwargs, - defaultValue='kablooey') + arg_value_dict = set_synth_arg_kwarg(my_foo, + in_kwargs=newKwargs, + default_value='kablooey') # what was returned print('~ multiple values returned...') - for k, v in argValueDict.items(): + for k, v in arg_value_dict.items(): print("Arg '{0}':'{1}'".format(k, v)) print('~ multiple direct property access test...') try: - myFoo.fooey - print('myFoo.{0}: {1}'.format('fooey', myFoo.fooey)) + my_foo.fooey + print('myFoo.{0}: {1}'.format('fooey', my_foo.fooey)) except Exception as e: raise e try: - myFoo.success - print('myFoo.{0}: {1}'.format('success', myFoo.success)) + my_foo.success + print('myFoo.{0}: {1}'.format('success', my_foo.success)) except Exception as e: raise e print('~ Starting - known failure test...') try: - myFoo.knownBad + my_foo.knownBad except Exception as e: print(e) print('Test failed as expected!!!') diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/test_foo.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/test_foo.py index ca652503d2..d1c535fe14 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/test_foo.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/noodely/test_foo.py @@ -25,13 +25,13 @@ class Foo(object): This is a Class, it creates a Foo object... which does nothing really """ - __propertyTag = 'fooProperty' + __property_tag = 'fooProperty' # ------------------------------------------------------------------ def __init__(self, name='Foo', value='defaultValue', *args, **kwargs): '''Class __init__''' synthesize(self, 'name', name) - synthesize(self, Foo.__propertyTag, value) + synthesize(self, Foo.__property_tag, value) synthesize(self, 'test', 'testValue') diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/custom_treemodel.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/custom_treemodel.py index cded8fec09..1ca3221508 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/custom_treemodel.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/custom_treemodel.py @@ -20,7 +20,10 @@ import os # from io import StringIO # for handling unicode strings # azpy -from azpy import initialize_logger +import azpy +from azpy.env_bool import env_bool +from azpy.constants import ENVAR_DCCSI_GDEBUG +from azpy.constants import ENVAR_DCCSI_DEV_MODE # 3rd Party from unipath import Path @@ -28,22 +31,22 @@ import PySide2.QtCore as QtCore import PySide2.QtWidgets as QtWidgets import PySide2.QtGui as QtGui # ------------------------------------------------------------------------- -# global space debug flag -_G_DEBUG = os.getenv('DCCSI_GDEBUG', False) - -# global space debug flag -_DCCSI_DEV_MODE = os.getenv('DCCSI_DEV_MODE', False) +# global space +# To Do: update to dynaconf dynamic env and settings? +_G_DEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False) +_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False) _MODULE_PATH = Path(__file__) -_ORG_TAG = 'Amazon_Lumberyard' -_APP_TAG = 'DCCsi' -_TOOL_TAG = 'azpy.shared.ui.custom_treemodel' -_TYPE_TAG = 'test' +_MODULENAME = 'azpy.shared.ui.custom_treemodel' -_MODULENAME = __name__ -if _MODULENAME is '__main__': - _MODULENAME = _TOOL_TAG +_log_level = int(20) +if _G_DEBUG: + _log_level = int(10) +_LOGGER = azpy.initialize_logger(_MODULENAME, + log_to_file=False, + default_log_level=_log_level) +_LOGGER.debug('Starting:: {}.'.format({_MODULENAME})) _UI_FILE = Path(_MODULE_PATH.parent, 'resources', 'example.ui') # ------------------------------------------------------------------------- @@ -75,15 +78,15 @@ class CustomFileTreeModel(QtCore.QAbstractItemModel): # TODO: need to make sure we are getting path objects # build the root node - self._root_node = self.buildRootNode('root', None, self._rootFilePath) + self._root_node = self.build_rootnode('root', None, self._root_filepath) - # master selection - self._masterSelection = masterSelection + # prime selection + self._prime_selection = prime_selection - # build the master selection node - self._masterNode = self.buildMasterNode('master', None, self._masterSelection, self._rootNode.path()) + # build the prime selection node + self._primenode = self.build_primenode('prime', None, self._prime_selection, self._rootnode.path()) # want to store off a couple lists in the model, for retreival later - self._nodeList = None - self._depNodesList = None + self._nodelist = None + self._dep_nodelist = None diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/help_menu.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/help_menu.py index 39f151cd2e..b261d4b0e1 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/help_menu.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/shared/ui/help_menu.py @@ -68,7 +68,7 @@ class HelpMenu(): INPUTS: main_window = the class instance of the QMainWindow tool_label = the menu label for the tool's help item - tool_help_page = the http:// path to the specific bpTool help page + tool_help_page = the http:// path to the tool specific help page Here's an example # self.help_menu = azpy.shared.ui.help_menu.setup(self, 'Help...', 'https://some.site.com/azpy') diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/synthetic_env.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/synthetic_env.py index 6186026852..86e4b68488 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/synthetic_env.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/synthetic_env.py @@ -667,7 +667,7 @@ if __name__ == '__main__': try: import azpy.test.entry_test print('SUCCESS: import azpy.test.entry_test') - azpy.test.entry_test.main(verbose=True, connectDebugger=True) + azpy.test.entry_test.main(verbose=True, connect_debugger=True) except ImportError as e: print('ERROR: {0}'.format(e)) raise e diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/test/entry_test.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/test/entry_test.py index 67dc3b60ad..46a852736e 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/test/entry_test.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/azpy/test/entry_test.py @@ -25,6 +25,7 @@ from pathlib import Path # ------------------------------------------------------------------------- _BOOT_CHECK = False # set true to test breakpoint in this module directly + import azpy from azpy.env_bool import env_bool from azpy.constants import ENVAR_DCCSI_GDEBUG @@ -48,13 +49,13 @@ _LOGGER.debug('Starting:: {}.'.format({_MODULENAME})) # ------------------------------------------------------------------------- -def main(verbose=_G_DEBUG, connectDebugger=True): +def main(verbose=_G_DEBUG, connect_debugger=True): _LOGGER.info('{}'.format('-' * 74)) _LOGGER.info('entry_test.main()') _LOGGER.info('Root test import successful:') _LOGGER.info('~ {}'.format(__file__)) - if connectDebugger: + if connect_debugger: status = connect_wing() _LOGGER.info(status) # ------------------------------------------------------------------------- @@ -137,4 +138,4 @@ def connect_wing(): # ------------------------------------------------------------------------- if __name__ == '__main__': _G_DEBUG = True - main(verbose=_G_DEBUG, connectDebugger=_G_DEBUG) + main(verbose=_G_DEBUG, connect_debugger=_G_DEBUG) diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py index 0068b4c766..c62571b2f5 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py @@ -26,7 +26,6 @@ import re # our framework for dcc tools need to run in apps like Maya that may still be # on py27 so we need to import and use after some boostrapping - # -------------------------------------------------------------------+------ #os.environ['PYTHONINSPECT'] = 'True' _MODULE_PATH = os.path.abspath(__file__) @@ -78,6 +77,10 @@ _DCCSI_PYTHON_LIB_PATH = azpy.config_utils.bootstrap_dccsi_py_libs(_DCCSIG_PATH) # Now we should be able to just carry on with pth lib and dynaconf from dynaconf import Dynaconf +try: + import pathlib +except: + import pathlib2 as pathlib from pathlib import Path _DCCSIG_PATH = Path(_DCCSIG_PATH).resolve() @@ -218,7 +221,7 @@ os.environ["DYNACONF_DCCSI_DEV_MODE"] = str(_DCCSI_DEV_MODE) # search up to get \dev _LY_DEV = azpy.config_utils.get_stub_check_path(in_path=_DCCSIG_PATH, - check_stub='engineroot.txt') + check_stub='engine.json') os.environ["DYNACONF_LY_DEV"] = str(_LY_DEV.resolve()) _LY_PROJECT = azpy.config_utils.get_current_project(_LY_DEV) os.environ["DYNACONF_LY_PROJECT"] = _LY_PROJECT diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/requirements.txt b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/requirements.txt index 05d47ea70c..2f7626addb 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/requirements.txt +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/requirements.txt @@ -4,34 +4,39 @@ # # pip-compile --generate-hashes requirements.txt # -typing==3.7.4.3 \ - --hash=sha256:1187fb9c82fd670d10aa07bbb6cfcfe4bdda42d6fab8d5134f04e8c4d0b71cc9 \ - --hash=sha256:283d868f5071ab9ad873e5e52268d611e851c870a2ba354193026f2dfb29d8b5 - # via - # -r requirements.txt - # dynaconf +cachetools==4.2.1 \ + --hash=sha256:1d9d5f567be80f7c07d765e21b814326d78c61eb0c3a637dffc0e5d1796cb2e2 \ + --hash=sha256:f469e29e7aa4cff64d8de4aad95ce76de8ea1125a16c68e0d93f65c3c3dc92e9 + # via -r requirements.txt +certifi==2020.12.5 \ + --hash=sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c \ + --hash=sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830 + # via -r requirements.txt click==7.1.2 \ --hash=sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a \ --hash=sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc # via # -r requirements.txt - # pip-tools dynaconf==3.1.4 \ --hash=sha256:b2f472d83052f809c5925565b8a2ba76a103d5dc1dbb9748b693ed67212781b9 \ --hash=sha256:e6f383b84150b70fc439c8b2757581a38a58d07962aa14517292dcce1a77e160 # via -r requirements.txt +hashids==1.3.1 \ + --hash=sha256:6c3dc775e65efc2ce2c157a65acb776d634cb814598f406469abef00ae3f635c \ + --hash=sha256:8bddd1acba501bfc9306e7e5a99a1667f4f2cacdc20cbd70bcc5ddfa5147c94c + # via -r requirements.txt pathlib==1.0.1 \ --hash=sha256:6940718dfc3eff4258203ad5021090933e5c04707d5ca8cc9e73c94a7894ea9f # via -r requirements.txt -python-box==3.4.6 \ - --hash=sha256:694a7555e3ff9fbbce734bbaef3aad92b8e4ed0659d3ed04d56b6a0a0eff26a9 \ - --hash=sha256:a71d3dc9dbaa34c8597d3517c89a8041bd62fa875f23c0f3dad55e1958e3ce10 +python-box==5.3.0 \ + --hash=sha256:4ed4ef5d34de505a65c01e3f1911de8cdb29484fcae0c035141dce535c6c194a \ + --hash=sha256:f2a531f9f5bbef078c175fad6abb31e9b59d40d121ea79993197e6bb221c6be6 # via -r requirements.txt unipath==1.1 \ --hash=sha256:09839adcc72e8a24d4f76d63656f30b5a1f721fc40c9bcd79d8c67bdd8b47dae \ --hash=sha256:e6257e508d8abbfb6ddd8ec357e33589f1f48b1599127f23b017124d90b0fff7 # via -r requirements.txt - -# WARNING: The following packages were not pinned, but pip requires them to be -# pinned when the requirements file includes hashes. Consider using the --allow-unsafe flag. -# pip +wincertstore==0.2 \ + --hash=sha256:22d5eebb52df88a8d4014d5cf6d1b6c3a5d469e6c3b2e2854f3a003e48872356 \ + --hash=sha256:780bd1557c9185c15d9f4221ea7f905cb20b93f7151ca8ccaed9714dce4b327a + # via -r requirements.txt \ No newline at end of file diff --git a/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp b/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp index 8011a87ed2..7f3735dacf 100644 --- a/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp +++ b/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp @@ -26,9 +26,9 @@ #include #include -#include #include #include +#include #include diff --git a/Gems/AudioSystem/Code/Source/Engine/ATLComponents.cpp b/Gems/AudioSystem/Code/Source/Engine/ATLComponents.cpp index e472ad57db..040d635bbd 100644 --- a/Gems/AudioSystem/Code/Source/Engine/ATLComponents.cpp +++ b/Gems/AudioSystem/Code/Source/Engine/ATLComponents.cpp @@ -33,8 +33,8 @@ #include #include -#include #include +#include namespace Audio { diff --git a/Gems/Blast/Code/Source/Family/ActorRenderManager.h b/Gems/Blast/Code/Source/Family/ActorRenderManager.h index 9512fba92d..3908ed5ecd 100644 --- a/Gems/Blast/Code/Source/Family/ActorRenderManager.h +++ b/Gems/Blast/Code/Source/Family/ActorRenderManager.h @@ -15,11 +15,6 @@ #include #include -namespace LmbrCentral -{ - class MeshComponentRequests; -} - namespace Blast { class BlastMeshData; diff --git a/Gems/CMakeLists.txt b/Gems/CMakeLists.txt index b6bda8c16e..8a9a140008 100644 --- a/Gems/CMakeLists.txt +++ b/Gems/CMakeLists.txt @@ -9,7 +9,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -add_subdirectory(ImageProcessing) add_subdirectory(TextureAtlas) add_subdirectory(LmbrCentral) add_subdirectory(LyShine) @@ -23,7 +22,6 @@ add_subdirectory(HttpRequestor) add_subdirectory(Gestures) add_subdirectory(FastNoise) add_subdirectory(GradientSignal) -add_subdirectory(GameEffectSystem) add_subdirectory(AudioSystem) add_subdirectory(AudioEngineWwise) add_subdirectory(GraphCanvas) @@ -37,7 +35,6 @@ add_subdirectory(MessagePopup) add_subdirectory(PhysX) add_subdirectory(PhysXDebug) add_subdirectory(ScriptEvents) -add_subdirectory(Visibility) add_subdirectory(AssetValidation) add_subdirectory(VirtualGamepad) add_subdirectory(SaveData) @@ -46,7 +43,6 @@ add_subdirectory(GameState) add_subdirectory(Vegetation) add_subdirectory(GameStateSamples) add_subdirectory(SliceFavorites) -add_subdirectory(SVOGI) add_subdirectory(Metastream) add_subdirectory(ScriptCanvas) add_subdirectory(ScriptedEntityTweener) diff --git a/Gems/EMotionFX/Code/EMotionFX/Pipeline/RCExt/Actor/ActorBuilder.cpp b/Gems/EMotionFX/Code/EMotionFX/Pipeline/RCExt/Actor/ActorBuilder.cpp index d57105a589..1327045806 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Pipeline/RCExt/Actor/ActorBuilder.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Pipeline/RCExt/Actor/ActorBuilder.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp index cfacdf9f09..ec1b00bda4 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/ActorInstance.cpp @@ -360,7 +360,7 @@ namespace EMotionFX ApplyMorphSetup(); UpdateSkinningMatrices(); UpdateAttachments(); - } + } // update the bounds when needed if (GetBoundsUpdateEnabled() && mBoundsUpdateType != BOUNDS_MESH_BASED) @@ -418,7 +418,8 @@ namespace EMotionFX } // Update the bounds when we are set to use mesh based bounds. - if (GetBoundsUpdateEnabled() == BOUNDS_MESH_BASED) + if (GetBoundsUpdateEnabled() && + GetBoundsUpdateType() == BOUNDS_MESH_BASED) { mBoundsUpdatePassedTime += timePassedInSeconds; if (mBoundsUpdatePassedTime >= mBoundsUpdateFrequency) @@ -449,7 +450,8 @@ namespace EMotionFX } // Update the bounds when we are set to use mesh based bounds. - if (GetBoundsUpdateEnabled() == BOUNDS_MESH_BASED) + if (GetBoundsUpdateEnabled() && + GetBoundsUpdateType() == BOUNDS_MESH_BASED) { mBoundsUpdatePassedTime += timePassedInSeconds; if (mBoundsUpdatePassedTime >= mBoundsUpdateFrequency) diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp index 73cbad195a..27cf34961f 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.cpp @@ -10,7 +10,8 @@ * */ -// include the required headers +#include +#include #include "EMotionFXConfig.h" #include "DualQuatSkinDeformer.h" #include "Mesh.h" @@ -23,138 +24,143 @@ #include #include - namespace EMotionFX { AZ_CLASS_ALLOCATOR_IMPL(DualQuatSkinDeformer, DeformerAllocator, 0) - // constructor DualQuatSkinDeformer::DualQuatSkinDeformer(Mesh* mesh) : MeshDeformer(mesh) { - mBones.SetMemoryCategory(EMFX_MEMCATEGORY_GEOMETRY_DEFORMERS); } - - // destructor DualQuatSkinDeformer::~DualQuatSkinDeformer() { - mBones.Clear(); } + AZ::Outcome DualQuatSkinDeformer::FindLocalBoneIndex(uint32 nodeIndex) const + { + const size_t numBones = m_bones.size(); + for (size_t i = 0; i < numBones; ++i) + { + if (m_bones[i].mNodeNr == nodeIndex) + { + return AZ::Success(i); + } + } + + return AZ::Failure(); + } - // creation DualQuatSkinDeformer* DualQuatSkinDeformer::Create(Mesh* mesh) { return aznew DualQuatSkinDeformer(mesh); } - - // get the type id uint32 DualQuatSkinDeformer::GetType() const { return TYPE_ID; } - - // get the subtype id uint32 DualQuatSkinDeformer::GetSubType() const { return SUBTYPE_ID; } - - // clone this class MeshDeformer* DualQuatSkinDeformer::Clone(Mesh* mesh) { // create the new cloned deformer DualQuatSkinDeformer* result = aznew DualQuatSkinDeformer(mesh); // copy the bone info (for precalc/optimization reasons) - result->mBones = mBones; + result->m_bones = m_bones; // return the result return result; } - // the main method where all calculations are done - void DualQuatSkinDeformer::Update(ActorInstance* actorInstance, Node* node, float timeDelta) + void DualQuatSkinDeformer::Update(ActorInstance* actorInstance, [[maybe_unused]] Node* node, [[maybe_unused]] float timeDelta) { - AZ_UNUSED(node); - MCORE_UNUSED(timeDelta); - const Actor* actor = actorInstance->GetActor(); const Pose* pose = actorInstance->GetTransformData()->GetCurrentPose(); + const uint32 numVertices = mMesh->GetNumVertices(); - AZ::Vector3 newPos, newNormal, newTangent, newBitangent; - AZ::Vector3 vtxPos, normal, tangent, bitangent; - AZ::Vector3* positions = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_POSITIONS)); - AZ::Vector3* normals = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_NORMALS)); - AZ::Vector4* tangents = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_TANGENTS)); - AZ::Vector3* bitangents = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_BITANGENTS)); - AZ::u32* orgVerts = static_cast(mMesh->FindVertexData(Mesh::ATTRIB_ORGVTXNUMBERS)); - - // precalc the skinning matrices - const uint32 numBones = mBones.GetLength(); - for (uint32 i = 0; i < numBones; i++) + // pre-calculate the skinning matrices + for (BoneInfo& boneInfo : m_bones) { - const uint32 nodeIndex = mBones[i].mNodeNr; - Transform skinTransform = actor->GetInverseBindPoseTransform(nodeIndex); - skinTransform.Multiply(pose->GetModelSpaceTransform(nodeIndex)); - mBones[i].mDualQuat.FromRotationTranslation(skinTransform.mRotation, skinTransform.mPosition); + const uint32 nodeIndex = boneInfo.mNodeNr; + const Transform skinTransform = actor->GetInverseBindPoseTransform(nodeIndex) * pose->GetModelSpaceTransform(nodeIndex); + boneInfo.mDualQuat.FromRotationTranslation(skinTransform.mRotation, skinTransform.mPosition); } - // find the skinning layer - SkinningInfoVertexAttributeLayer* layer = (SkinningInfoVertexAttributeLayer*)mMesh->FindSharedVertexAttributeLayer(SkinningInfoVertexAttributeLayer::TYPE_ID); - MCORE_ASSERT(layer); + AZ::JobCompletion jobCompletion; + + // Split up the skinned vertices into batches. + const AZ::u32 numBatches = aznumeric_caster(ceilf(aznumeric_cast(numVertices) / aznumeric_cast(s_numVerticesPerBatch))); + for (AZ::u32 batchIndex = 0; batchIndex < numBatches; ++batchIndex) + { + const AZ::u32 startVertex = batchIndex * s_numVerticesPerBatch; + const AZ::u32 endVertex = AZStd::min(startVertex + s_numVerticesPerBatch, numVertices); + + // Create a job for every batch and skin them simultaneously. + AZ::JobContext* jobContext = nullptr; + AZ::Job* job = AZ::CreateJobFunction([this, startVertex, endVertex]() + { + SkinRange(mMesh, startVertex, endVertex, m_bones); + }, /*isAutoDelete=*/true, jobContext); + + job->SetDependent(&jobCompletion); + job->Start(); + } + + jobCompletion.StartAndWaitForCompletion(); + } + + void DualQuatSkinDeformer::SkinRange(Mesh* mesh, AZ::u32 startVertex, AZ::u32 endVertex, const AZStd::vector& boneInfos) + { + SkinningInfoVertexAttributeLayer* layer = (SkinningInfoVertexAttributeLayer*)mesh->FindSharedVertexAttributeLayer(SkinningInfoVertexAttributeLayer::TYPE_ID); + AZ_Assert(layer, "Cannot find skinning layer."); + + AZ::Vector3 newTangent; + AZ::Vector3 vtxPos, normal, tangent, bitangent; + AZ::u32 orgVertex; + float weight; + + AZ::Vector3* positions = static_cast(mesh->FindVertexData(Mesh::ATTRIB_POSITIONS)); + AZ::Vector3* normals = static_cast(mesh->FindVertexData(Mesh::ATTRIB_NORMALS)); + AZ::Vector4* tangents = static_cast(mesh->FindVertexData(Mesh::ATTRIB_TANGENTS)); + AZ::Vector3* bitangents = static_cast(mesh->FindVertexData(Mesh::ATTRIB_BITANGENTS)); + AZ::u32* orgVerts = static_cast(mesh->FindVertexData(Mesh::ATTRIB_ORGVTXNUMBERS)); // if there are tangents and bitangents to skin if (tangents && bitangents) { - const uint32 numVertices = mMesh->GetNumVertices(); - uint32 v = 0; - uint32 orgVertex; - - SkinInfluence* influence; - BoneInfo* boneInfo; - float weight; - for (v = 0; v < numVertices; ++v) + for (AZ::u32 v = startVertex; v < endVertex; ++v) { - // get the original vertex number - orgVertex = *(orgVerts++); - - // reset the skinned position - newPos = AZ::Vector3::CreateZero(); - newNormal = AZ::Vector3::CreateZero(); - newTangent = AZ::Vector3::CreateZero(); - newBitangent = AZ::Vector3::CreateZero(); - - const float tangentW = tangents->GetW(); - vtxPos.Set (positions->GetX(), positions->GetY(), positions->GetZ()); - normal.Set (normals->GetX(), normals->GetY(), normals->GetZ()); - tangent.Set (tangents->GetX(), tangents->GetY(), tangents->GetZ()); - bitangent.Set(bitangents->GetX(), bitangents->GetY(), bitangents->GetZ()); + orgVertex = orgVerts[v]; + vtxPos = positions[v]; + normal = normals[v]; + const float tangentW = tangents[v].GetW(); + tangent.Set(tangents[v].GetX(), tangents[v].GetY(), tangents[v].GetZ()); + bitangent = bitangents[v]; // process the skin influences for this vertex const size_t numInfluences = layer->GetNumInfluences(orgVertex); if (numInfluences > 0) { // get the pivot quat, used for the dot product check - const MCore::DualQuaternion& pivotQuat = mBones[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; + const MCore::DualQuaternion& pivotQuat = boneInfos[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; // our skinning dual quaternion MCore::DualQuaternion skinQuat(AZ::Quaternion(0, 0, 0, 0), AZ::Quaternion(0, 0, 0, 0)); for (size_t i = 0; i < numInfluences; ++i) { - // get the influence - influence = layer->GetInfluence(orgVertex, i); - boneInfo = &mBones[ influence->GetBoneNr() ]; - weight = influence->GetWeight(); + SkinInfluence* influence = layer->GetInfluence(orgVertex, i); + weight = influence->GetWeight(); // check if we need to invert the dual quat - MCore::DualQuaternion& influenceQuat = mBones[ influence->GetBoneNr() ].mDualQuat; + MCore::DualQuaternion influenceQuat = boneInfos[ influence->GetBoneNr() ].mDualQuat; if (influenceQuat.mReal.Dot(pivotQuat.mReal) < 0.0f) { influenceQuat *= -1.0f; @@ -168,74 +174,50 @@ namespace EMotionFX skinQuat.Normalize(); // perform skinning - newPos = skinQuat.TransformPoint(vtxPos); - newNormal = skinQuat.TransformVector(normal); - newTangent = skinQuat.TransformVector(tangent); - newBitangent = skinQuat.TransformVector(bitangent); + positions[v] = skinQuat.TransformPoint(vtxPos); + normals[v] = skinQuat.TransformVector(normal); + newTangent = skinQuat.TransformVector(tangent); + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); + bitangents[v] = skinQuat.TransformVector(bitangent); } else { - // perform the skinning - newPos = vtxPos; - newNormal = normal; - newTangent = tangent; - newBitangent = bitangent; + // no skinning influences, just copy the values + positions[v] = vtxPos; + normals[v] = normal; + newTangent = tangent; + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); + bitangents[v] = bitangent; } - - // output the skinned values - positions->Set (newPos.GetX(), newPos.GetY(), newPos.GetZ()); - positions++; - normals->Set (newNormal.GetX(), newNormal.GetY(), newNormal.GetZ()); - normals++; - tangents->Set (newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); - tangents++; - bitangents->Set (newBitangent.GetX(), newBitangent.GetY(), newBitangent.GetZ()); - bitangents++; } } else if (tangents && !bitangents) // tangents but no bitangents { - const uint32 numVertices = mMesh->GetNumVertices(); - uint32 v = 0; - uint32 orgVertex; - - SkinInfluence* influence; - BoneInfo* boneInfo; - float weight; - for (v = 0; v < numVertices; ++v) + for (AZ::u32 v = startVertex; v < endVertex; ++v) { - // get the original vertex number - orgVertex = *(orgVerts++); - - // reset the skinned position - newPos = AZ::Vector3::CreateZero(); - newNormal = AZ::Vector3::CreateZero(); - newTangent = AZ::Vector3::CreateZero(); - - const float tangentW = tangents->GetW(); - vtxPos.Set (positions->GetX(), positions->GetY(), positions->GetZ()); - normal.Set (normals->GetX(), normals->GetY(), normals->GetZ()); - tangent.Set (tangents->GetX(), tangents->GetY(), tangents->GetZ()); + orgVertex = orgVerts[v]; + vtxPos = positions[v]; + normal = normals[v]; + const float tangentW = tangents[v].GetW(); + tangent.Set(tangents[v].GetX(), tangents[v].GetY(), tangents[v].GetZ()); // process the skin influences for this vertex const size_t numInfluences = layer->GetNumInfluences(orgVertex); if (numInfluences > 0) { // get the pivot quat, used for the dot product check - const MCore::DualQuaternion& pivotQuat = mBones[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; + const MCore::DualQuaternion& pivotQuat = boneInfos[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; // our skinning dual quaternion MCore::DualQuaternion skinQuat(AZ::Quaternion(0, 0, 0, 0), AZ::Quaternion(0, 0, 0, 0)); for (size_t i = 0; i < numInfluences; ++i) { - // get the influence - influence = layer->GetInfluence(orgVertex, i); - boneInfo = &mBones[ influence->GetBoneNr() ]; - weight = influence->GetWeight(); + SkinInfluence* influence = layer->GetInfluence(orgVertex, i); + weight = influence->GetWeight(); // check if we need to invert the dual quat - MCore::DualQuaternion& influenceQuat = mBones[ influence->GetBoneNr() ].mDualQuat; + MCore::DualQuaternion influenceQuat = boneInfos[ influence->GetBoneNr() ].mDualQuat; if (influenceQuat.mReal.Dot(pivotQuat.mReal) < 0.0f) { influenceQuat *= -1.0f; @@ -249,68 +231,46 @@ namespace EMotionFX skinQuat.Normalize(); // perform skinning - newPos = skinQuat.TransformPoint(vtxPos); - newNormal = skinQuat.TransformVector(normal); - newTangent = skinQuat.TransformVector(tangent); + positions[v] = skinQuat.TransformPoint(vtxPos); + normals[v] = skinQuat.TransformVector(normal); + newTangent = skinQuat.TransformVector(tangent); + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); } else { - // perform the skinning - newPos = vtxPos; - newNormal = normal; - newTangent = tangent; + // no skinning influences, just copy the values + positions[v] = vtxPos; + normals[v] = normal; + newTangent = tangent; + tangents[v].Set(newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); } - - // output the skinned values - positions->Set (newPos.GetX(), newPos.GetY(), newPos.GetZ()); - positions++; - normals->Set (newNormal.GetX(), newNormal.GetY(), newNormal.GetZ()); - normals++; - tangents->Set (newTangent.GetX(), newTangent.GetY(), newTangent.GetZ(), tangentW); - tangents++; } } else // there are no tangents and bitangents to skin { - const uint32 numVertices = mMesh->GetNumVertices(); - uint32 v = 0; - uint32 orgVertex; - - SkinInfluence* influence; - BoneInfo* boneInfo; - float weight; - - for (v = 0; v < numVertices; ++v) + for (AZ::u32 v = startVertex; v < endVertex; ++v) { - // get the original vertex number - orgVertex = *(orgVerts++); - - // reset the skinned position - newPos = AZ::Vector3::CreateZero(); - newNormal = AZ::Vector3::CreateZero(); - - vtxPos.Set(positions->GetX(), positions->GetY(), positions->GetZ()); - normal.Set(normals->GetX(), normals->GetY(), normals->GetZ()); + orgVertex = orgVerts[v]; + vtxPos = positions[v]; + normal = normals[v]; // process the skin influences for this vertex const size_t numInfluences = layer->GetNumInfluences(orgVertex); if (numInfluences > 0) { // get the pivot quat, used for the dot product check - const MCore::DualQuaternion& pivotQuat = mBones[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; + const MCore::DualQuaternion& pivotQuat = boneInfos[ layer->GetInfluence(orgVertex, 0)->GetBoneNr() ].mDualQuat; // our skinning dual quaternion MCore::DualQuaternion skinQuat(AZ::Quaternion(0, 0, 0, 0), AZ::Quaternion(0, 0, 0, 0)); for (size_t i = 0; i < numInfluences; ++i) { - // get the influence - influence = layer->GetInfluence(orgVertex, i); - boneInfo = &mBones[ influence->GetBoneNr() ]; - weight = influence->GetWeight(); + SkinInfluence* influence = layer->GetInfluence(orgVertex, i); + weight = influence->GetWeight(); // check if we need to invert the dual quat - MCore::DualQuaternion& influenceQuat = mBones[ influence->GetBoneNr() ].mDualQuat; + MCore::DualQuaternion influenceQuat = boneInfos[ influence->GetBoneNr() ].mDualQuat; if (influenceQuat.mReal.Dot(pivotQuat.mReal) < 0.0f) { influenceQuat *= -1.0f; @@ -324,26 +284,19 @@ namespace EMotionFX skinQuat.Normalize(); // perform skinning - newPos = skinQuat.TransformPoint(vtxPos); - newNormal = skinQuat.TransformVector(normal); + positions[v] = skinQuat.TransformPoint(vtxPos); + normals[v] = skinQuat.TransformVector(normal); } else { - // perform the skinning - newPos = vtxPos; - newNormal = normal; + // no skinning influences, just copy the values + positions[v] = vtxPos; + normals[v] = normal; } - - // output the skinned values - positions->Set(newPos.GetX(), newPos.GetY(), newPos.GetZ()); - positions++; - normals->Set(newNormal.GetX(), newNormal.GetY(), newNormal.GetZ()); - normals++; } } } - // initialize the mesh deformer void DualQuatSkinDeformer::Reinitialize(Actor* actor, Node* node, uint32 lodLevel) { @@ -352,7 +305,7 @@ namespace EMotionFX MCORE_UNUSED(lodLevel); // clear the bone information array, but don't free the currently allocated/reserved memory - mBones.Clear(false); + m_bones.clear(); // if there is no mesh if (mMesh == nullptr) @@ -360,13 +313,9 @@ namespace EMotionFX return; } - // get the attribute number SkinningInfoVertexAttributeLayer* skinningLayer = (SkinningInfoVertexAttributeLayer*)mMesh->FindSharedVertexAttributeLayer(SkinningInfoVertexAttributeLayer::TYPE_ID); MCORE_ASSERT(skinningLayer); - // reserve space for the bone array - //mBones.Reserve( actor->GetNumNodes() ); - // find out what bones this mesh uses const uint32 numOrgVerts = mMesh->GetNumOrgVertices(); for (uint32 i = 0; i < numOrgVerts; i++) @@ -379,26 +328,21 @@ namespace EMotionFX { SkinInfluence* influence = skinningLayer->GetInfluence(i, a); - // get the bone index in the array - uint32 boneIndex = FindLocalBoneIndex(influence->GetNodeNr()); - - // if the bone is not found in our array - if (boneIndex == MCORE_INVALIDINDEX32) + AZ::Outcome boneIndexOutcome = FindLocalBoneIndex(influence->GetNodeNr()); + if (boneIndexOutcome.IsSuccess()) + { + influence->SetBoneNr(boneIndexOutcome.GetValue()); + } + else { // add the bone to the array of bones in this deformer - mBones.AddEmptyExact(); - BoneInfo& lastBone = mBones.GetLast(); + BoneInfo lastBone; lastBone.mNodeNr = influence->GetNodeNr(); lastBone.mDualQuat.Identity(); - boneIndex = mBones.GetLength() - 1; + m_bones.emplace_back(lastBone); + influence->SetBoneNr(static_cast(m_bones.size() - 1)); } - - // set the bone number in the influence - influence->SetBoneNr(static_cast(boneIndex)); } } - - // get rid of all items in the used bones array - // mBones.Shrink(); } } // namespace EMotionFX diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h index fc80256524..ec00f1186f 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h +++ b/Gems/EMotionFX/Code/EMotionFX/Source/DualQuatSkinDeformer.h @@ -12,13 +12,13 @@ #pragma once -// include the required headers +#include +#include #include "EMotionFXConfig.h" #include #include "Mesh.h" #include "MeshDeformer.h" - namespace EMotionFX { // forward declarations @@ -101,37 +101,47 @@ namespace EMotionFX * This is the number of different bones that the skinning information of the mesh where this deformer works on uses. * @result The number of bones. */ - MCORE_INLINE uint32 GetNumLocalBones() const { return mBones.GetLength(); } + MCORE_INLINE uint32 GetNumLocalBones() const { return static_cast(m_bones.size()); } /** * Get the node number of a given local bone. * @param index The local bone number, which must be in range of [0..GetNumLocalBones()-1]. * @result The node number, which is in range of [0..Actor::GetNumNodes()-1], depending on the actor where this deformer works on. */ - MCORE_INLINE uint32 GetLocalBone(uint32 index) const { return mBones[index].mNodeNr; } + MCORE_INLINE uint32 GetLocalBone(uint32 index) const { return m_bones[index].mNodeNr; } /** * Pre-allocate space for a given number of local bones. * This does not alter the value returned by GetNumLocalBones(). * @param numBones The number of bones to pre-allocate space for. */ - MCORE_INLINE void ReserveLocalBones(uint32 numBones) { mBones.Reserve(numBones); } - + MCORE_INLINE void ReserveLocalBones(uint32 numBones) { m_bones.reserve(numBones); } protected: /** - * Structure used for precalculating the skinning matrices. + * Structure used for pre-calculating the skinning matrices. */ struct EMFX_API BoneInfo { uint32 mNodeNr; /**< The node number. */ - MCore::DualQuaternion mDualQuat; /**< The dual quat of the precalculated matrix that contains the "globalMatrix * inverse(bindPoseMatrix)". */ + MCore::DualQuaternion mDualQuat; /**< The dual quat of the pre-calculated matrix that contains the "globalMatrix * inverse(bindPoseMatrix)". */ MCORE_INLINE BoneInfo() : mNodeNr(MCORE_INVALIDINDEX32) {} }; + AZStd::vector m_bones; /**< The array of bone information used for pre-calculation. */ + + /** + * Skin a part of the mesh. + * @param mesh The mesh to be skinned. + * @param startVertex The start vertex index to start skinning. + * @param endVertex The end vertex index for the range to be skinned. + * @param boneInfos The pre-calculated skinning matrices shared across the skinning process. + */ + static void SkinRange(Mesh* mesh, AZ::u32 startVertex, AZ::u32 endVertex, const AZStd::vector& boneInfos); - MCore::Array mBones; /**< The array of bone information used for precalculation. */ + //! Number of vertices per batch/job used for multi-threaded software skinning. + static constexpr AZ::u32 s_numVerticesPerBatch = 10000; /** * Default constructor. @@ -149,18 +159,6 @@ namespace EMotionFX * @param nodeIndex The node number to search for. * @result The index inside the mBones member array, which uses the given node. */ - MCORE_INLINE uint32 FindLocalBoneIndex(uint32 nodeIndex) const - { - const uint32 numBones = mBones.GetLength(); - for (uint32 i = 0; i < numBones; ++i) - { - if (mBones[i].mNodeNr == nodeIndex) - { - return i; - } - } - - return MCORE_INVALIDINDEX32; - } + AZ::Outcome FindLocalBoneIndex(uint32 nodeIndex) const; }; } // namespace EMotionFX diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/MotionInstancePool.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/MotionInstancePool.cpp index cbe13308d9..d715fabd1c 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/MotionInstancePool.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/MotionInstancePool.cpp @@ -220,7 +220,7 @@ namespace EMotionFX //mPool->mFreeList.Reserve( numInstances * 2 ); if (mPool->mFreeList.GetMaxLength() < mPool->mNumInstances) { - mPool->mFreeList.Reserve(mPool->mNumInstances); + mPool->mFreeList.Reserve(mPool->mNumInstances + mPool->mFreeList.GetMaxLength() / 2); } mPool->mFreeList.ResizeFast(startIndex + numInstances); diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h index 85fc9c8d56..e33a5f3f51 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h @@ -78,8 +78,6 @@ namespace EMStudio virtual void OnBeforeRemovePlugin(uint32 classID) { MCORE_UNUSED(classID); } virtual void OnMainWindowClosed() {} - virtual void RegisterKeyboardShortcuts() {} - struct RenderInfo { MCORE_MEMORYOBJECTCATEGORY(EMStudioPlugin::RenderInfo, MCore::MCORE_DEFAULT_ALIGNMENT, MEMCATEGORY_EMSTUDIOSDK) diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.cpp index b8093d2115..d6fdb9128b 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.cpp @@ -116,14 +116,6 @@ namespace EMStudio } - void KeyboardShortcutsWindow::hideEvent(QHideEvent* event) - { - MCORE_UNUSED(event); - //if (mShortcutReceiverDialog) - // mShortcutReceiverDialog->reject(); - } - - // reconstruct the whole interface void KeyboardShortcutsWindow::ReInit() { @@ -138,11 +130,11 @@ namespace EMStudio // add the groups to the left list widget MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - const uint32 numGroups = shortcutManager->GetNumGroups(); + const size_t numGroups = shortcutManager->GetNumGroups(); for (uint32 i = 0; i < numGroups; ++i) { MysticQt::KeyboardShortcutManager::Group* group = shortcutManager->GetGroup(i); - mListWidget->addItem(group->GetName()); + mListWidget->addItem(FromStdString(group->GetName())); } mTableWidget->blockSignals(false); @@ -183,10 +175,10 @@ namespace EMStudio // get access to the shortcut group and some data MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); MysticQt::KeyboardShortcutManager::Group* group = shortcutManager->GetGroup(mSelectedGroup); - const uint32 numActions = group->GetNumActions(); + const size_t numActions = group->GetNumActions(); // set the row count - mTableWidget->setRowCount(numActions); + mTableWidget->setRowCount(aznumeric_caster(numActions)); // fill the table with the media root folders for (uint32 i = 0; i < numActions; ++i) @@ -195,11 +187,11 @@ namespace EMStudio MysticQt::KeyboardShortcutManager::Action* action = group->GetAction(i); // add the item to the table and set the row height - QTableWidgetItem* item = new QTableWidgetItem(action->mName.c_str()); + QTableWidgetItem* item = new QTableWidgetItem(action->m_qaction->text()); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); mTableWidget->setItem(i, 0, item); - const QString keyText = ConstructStringFromShortcut(action->mKey, action->mCtrl, action->mAlt); + const QString keyText = ConstructStringFromShortcut(action->m_qaction->shortcut()); item = new QTableWidgetItem(keyText); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); @@ -255,18 +247,14 @@ namespace EMStudio // handle conflicts if (shortcutWindow.mConflictDetected) { - shortcutWindow.mConflictAction->mKey = -1; - shortcutWindow.mConflictAction->mCtrl = false; - shortcutWindow.mConflictAction->mAlt = false; + shortcutWindow.mConflictAction->m_qaction->setShortcut({}); } // adjust the shortcut action - action->mKey = shortcutWindow.mKey; - action->mAlt = shortcutWindow.mAlt; - action->mCtrl = shortcutWindow.mCtrl; + action->m_qaction->setShortcut(shortcutWindow.mKey); // save the new shortcuts - QSettings settings(AZStd::string(GetManager()->GetAppDataFolder() + "EMStudioKeyboardShortcuts.cfg").c_str(), QSettings::IniFormat, this); + QSettings settings(FromStdString(AZStd::string(GetManager()->GetAppDataFolder() + "EMStudioKeyboardShortcuts.cfg")), QSettings::IniFormat, this); shortcutManager->Save(&settings); // reinit the window @@ -277,31 +265,14 @@ namespace EMStudio // construct a text version of a shortcut - QString KeyboardShortcutsWindow::ConstructStringFromShortcut(int key, bool ctrl, bool alt) + QString KeyboardShortcutsWindow::ConstructStringFromShortcut(QKeySequence key) { - if (key == -1) + if (key.isEmpty()) { return "not set"; } - QString keyText; - - if (ctrl) - { - #if AZ_TRAIT_OS_PLATFORM_APPLE - keyText += "COMMAND + "; - #else - keyText += "CTRL + "; - #endif - } - if (alt) - { - keyText += "ALT + "; - } - - keyText += QKeySequence(key).toString(QKeySequence::NativeText); - - return keyText; + return key.toString(QKeySequence::NativeText); } @@ -313,9 +284,7 @@ namespace EMStudio return; } - mContextMenuAction->mKey = mContextMenuAction->mDefaultKey; - mContextMenuAction->mCtrl = mContextMenuAction->mDefaultCtrl; - mContextMenuAction->mAlt = mContextMenuAction->mDefaultAlt; + mContextMenuAction->m_qaction->setShortcut(mContextMenuAction->m_defaultKeySequence); ReInit(); } @@ -378,19 +347,14 @@ namespace EMStudio setWindowTitle(" "); layout->addWidget(new QLabel("Press the new shortcut on the keyboard:")); - // find the initial shortcut - //MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - mOrgAction = action; mOrgGroup = group; mConflictAction = nullptr; mConflictDetected = false; - mKey = action->mKey; - mCtrl = action->mCtrl; - mAlt = action->mAlt; + mKey = action->m_qaction->shortcut(); - QString keyText = KeyboardShortcutsWindow::ConstructStringFromShortcut(mKey, mCtrl, mAlt); + QString keyText = KeyboardShortcutsWindow::ConstructStringFromShortcut(mKey); mLabel = new QLabel(keyText); mLabel->setAlignment(Qt::AlignHCenter); @@ -431,9 +395,7 @@ namespace EMStudio // reset the shortcut to its default value void ShortcutReceiverDialog::ResetToDefault() { - mKey = mOrgAction->mDefaultKey; - mCtrl = mOrgAction->mDefaultCtrl; - mAlt = mOrgAction->mDefaultAlt; + mKey = mOrgAction->m_defaultKeySequence; UpdateInterface(); } @@ -444,10 +406,8 @@ namespace EMStudio { MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - QString keyText = KeyboardShortcutsWindow::ConstructStringFromShortcut(mKey, mCtrl, mAlt); - // check if the currently assigned shortcut is already taken by another shortcut - mConflictAction = shortcutManager->FindShortcut(mKey, mCtrl, mAlt, mOrgGroup); + mConflictAction = shortcutManager->FindShortcut(mKey, mOrgGroup); if (mConflictAction == nullptr || mConflictAction == mOrgAction) { mOKButton->setToolTip(""); @@ -465,39 +425,25 @@ namespace EMStudio if (mConflictAction) { - AZStd::string tempString; - - tempString = AZStd::string::format("Assigning new shortcut will unassign '%s' automatically.", mConflictAction->mName.c_str()); - mOKButton->setToolTip(tempString.c_str()); + mOKButton->setToolTip(QString("Assigning new shortcut will unassign '%1' automatically.").arg(mConflictAction->m_qaction->text())); MysticQt::KeyboardShortcutManager::Group* conflictGroup = shortcutManager->FindGroupForShortcut(mConflictAction); if (conflictGroup) { - tempString = AZStd::string::format("Conflicts with: %s -> %s", conflictGroup->GetName(), mConflictAction->mName.c_str()); + mConflictKeyLabel->setText(QString("Conflicts with: %1 -> %2").arg(FromStdString(conflictGroup->GetName())).arg(mConflictAction->m_qaction->text())); } else { - tempString = AZStd::string::format("Conflicts with: %s", mConflictAction->mName.c_str()); + mConflictKeyLabel->setText(QString("Conflicts with: %1").arg(mConflictAction->m_qaction->text())); } - - mConflictKeyLabel->setText(tempString.c_str()); } } // adjust the label text to the new shortcut + const QString keyText = KeyboardShortcutsWindow::ConstructStringFromShortcut(mKey); mLabel->setText(keyText); } - - // close dialog as soon as it lost focus - void ShortcutReceiverDialog::focusOutEvent(QFocusEvent* event) - { - MCORE_UNUSED(event); - // if (event->reason() == Qt::ActiveWindowFocusReason) - // reject(); - } - - // called when the user pressed a new shortcut void ShortcutReceiverDialog::keyPressEvent(QKeyEvent* event) { @@ -513,18 +459,12 @@ namespace EMStudio if (event->key() == Qt::Key_Escape) { - //mKey = mOrgAction->mKey; - //mCtrl = mOrgAction->mCtrl; - //mAlt = mOrgAction->mAlt; - // close the dialog when pressing ESC reject(); } else { - mKey = event->key(); - mCtrl = event->modifiers() & Qt::ControlModifier; - mAlt = event->modifiers() & Qt::AltModifier; + mKey = event->key() | event->modifiers(); } UpdateInterface(); diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.h index 024479cc90..f6d4f43642 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/KeyboardShortcutsWindow.h @@ -41,12 +41,9 @@ namespace EMStudio virtual ~ShortcutReceiverDialog() {} void keyPressEvent(QKeyEvent* event) override; - void focusOutEvent(QFocusEvent* event) override; void UpdateInterface(); - int mKey; - bool mCtrl; - bool mAlt; + QKeySequence mKey; bool mConflictDetected; MysticQt::KeyboardShortcutManager::Action* mConflictAction; @@ -74,7 +71,7 @@ namespace EMStudio void Init(); void ReInit(); - static QString ConstructStringFromShortcut(int key, bool ctrl, bool alt); + static QString ConstructStringFromShortcut(QKeySequence key); MysticQt::KeyboardShortcutManager::Group* GetCurrentGroup() const; void setVisible(bool visible) override; @@ -95,6 +92,5 @@ namespace EMStudio ShortcutReceiverDialog* mShortcutReceiverDialog; void contextMenuEvent(QContextMenuEvent* event) override; - void hideEvent(QHideEvent* event) override; }; } // namespace EMStudio diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp index 496b6b8e94..950b63ff26 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp @@ -66,6 +66,7 @@ #include #include #include +#include AZ_PUSH_DISABLE_WARNING(4267, "-Wconversion") #include AZ_POP_DISABLE_WARNING @@ -508,14 +509,33 @@ namespace EMStudio mShortcutManager = new MysticQt::KeyboardShortcutManager(); // load the old shortcuts - QSettings shortcutSettings(AZStd::string(GetManager()->GetAppDataFolder() + "EMStudioKeyboardShortcuts.cfg").c_str(), QSettings::IniFormat, this); - mShortcutManager->Load(&shortcutSettings); + LoadKeyboardShortcuts(); // add the application mode group - const char* layoutGroupName = "Layouts"; - mShortcutManager->RegisterKeyboardShortcut("AnimGraph", layoutGroupName, Qt::Key_1, false, true, false); - mShortcutManager->RegisterKeyboardShortcut("Animation", layoutGroupName, Qt::Key_2, false, true, false); - mShortcutManager->RegisterKeyboardShortcut("Character", layoutGroupName, Qt::Key_3, false, true, false); + constexpr AZStd::string_view layoutGroupName = "Layouts"; + QAction* animGraphLayoutAction = new QAction( + "AnimGraph", + this); + animGraphLayoutAction->setShortcut(Qt::Key_1 | Qt::AltModifier); + mShortcutManager->RegisterKeyboardShortcut(animGraphLayoutAction, layoutGroupName, false); + connect(animGraphLayoutAction, &QAction::triggered, [this]{ mApplicationMode->setCurrentIndex(0); }); + addAction(animGraphLayoutAction); + + QAction* animationLayoutAction = new QAction( + "Animation", + this); + animationLayoutAction->setShortcut(Qt::Key_2 | Qt::AltModifier); + mShortcutManager->RegisterKeyboardShortcut(animationLayoutAction, layoutGroupName, false); + connect(animationLayoutAction, &QAction::triggered, [this]{ mApplicationMode->setCurrentIndex(1); }); + addAction(animationLayoutAction); + + QAction* characterLayoutAction = new QAction( + "Character", + this); + characterLayoutAction->setShortcut(Qt::Key_1 | Qt::AltModifier); + mShortcutManager->RegisterKeyboardShortcut(characterLayoutAction, layoutGroupName, false); + connect(characterLayoutAction, &QAction::triggered, [this]{ mApplicationMode->setCurrentIndex(2); }); + addAction(characterLayoutAction); EMotionFX::ActorEditorRequestBus::Handler::BusConnect(); @@ -1267,6 +1287,12 @@ namespace EMStudio mRecentActors.AddRecentFile(fileName.toUtf8().data()); } + void MainWindow::LoadKeyboardShortcuts() + { + QSettings shortcutSettings(AZStd::string(GetManager()->GetAppDataFolder() + "EMStudioKeyboardShortcuts.cfg").c_str(), QSettings::IniFormat, this); + mShortcutManager->Load(&shortcutSettings); + } + void MainWindow::LoadActor(const char* fileName, bool replaceCurrentScene) { // create the final command @@ -2577,41 +2603,6 @@ namespace EMStudio QTimer::singleShot(0, this, &MainWindow::RaiseFloatingWidgets); } - void MainWindow::keyPressEvent(QKeyEvent* event) - { - const char* layoutGroupName = "Layouts"; - const uint32 numLayouts = GetMainWindow()->GetNumLayouts(); - for (uint32 i = 0; i < numLayouts; ++i) - { - if (mShortcutManager->Check(event, GetLayoutName(i), layoutGroupName)) - { - mApplicationMode->setCurrentIndex(i); - event->accept(); - return; - } - } - - event->ignore(); - } - - - void MainWindow::keyReleaseEvent(QKeyEvent* event) - { - const char* layoutGroupName = "Layouts"; - const uint32 numLayouts = GetNumLayouts(); - for (uint32 i = 0; i < numLayouts; ++i) - { - if (mShortcutManager->Check(event, layoutGroupName, GetLayoutName(i))) - { - event->accept(); - return; - } - } - - event->ignore(); - } - - // get the name of the currently active layout const char* MainWindow::GetCurrentLayoutName() const { diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h index 15edaef144..850715b23f 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h @@ -152,9 +152,6 @@ namespace EMStudio FileManager* GetFileManager() const { return mFileManager; } PreferencesWindow* GetPreferencesWindow() const { return mPreferencesWindow; } - void keyPressEvent(QKeyEvent* event) override; - void keyReleaseEvent(QKeyEvent* event) override; - uint32 GetNumLayouts() const { return mLayoutNames.GetLength(); } const char* GetLayoutName(uint32 index) const { return mLayoutNames[index].c_str(); } const char* GetCurrentLayoutName() const; @@ -168,6 +165,8 @@ namespace EMStudio void AddRecentActorFile(const QString& fileName); + void LoadKeyboardShortcuts(); + public slots: void OnAutosaveTimeOut(); void LoadLayoutAfterShow(); diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/PluginManager.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/PluginManager.cpp index 214ed68367..ffe29ed691 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/PluginManager.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/PluginManager.cpp @@ -136,7 +136,6 @@ namespace EMStudio mActivePlugins.push_back(newPlugin); newPlugin->Init(); - newPlugin->RegisterKeyboardShortcuts(); return newPlugin; } diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.cpp index 47b88b1fa2..8e4c1bce37 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.cpp @@ -1020,17 +1020,6 @@ namespace EMStudio } - // register keyboard shortcuts used for the render plugin - void RenderPlugin::RegisterKeyboardShortcuts() - { - MysticQt::KeyboardShortcutManager* shortcutManger = GetMainWindow()->GetShortcutManager(); - - shortcutManger->RegisterKeyboardShortcut("Show Selected", "Render Window", Qt::Key_S, false, false, true); - shortcutManger->RegisterKeyboardShortcut("Show Entire Scene", "Render Window", Qt::Key_A, false, false, true); - shortcutManger->RegisterKeyboardShortcut("Toggle Selection Box Rendering", "Render Window", Qt::Key_J, false, false, true); - } - - // find the trajectory path for a given actor instance MCommon::RenderUtil::TrajectoryTracePath* RenderPlugin::FindTracePath(EMotionFX::ActorInstance* actorInstance) { diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.h index 43f237b89e..7dab0a5f95 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.h @@ -124,9 +124,6 @@ namespace EMStudio void ViewCloseup(bool selectedInstancesOnly = true, RenderWidget* renderWidget = nullptr, float flightTime = DEFAULT_FLIGHT_TIME); void SetSkipFollowCalcs(bool skipFollowCalcs); - // keyboard shortcuts - void RegisterKeyboardShortcuts() override; - // manipulators void ReInitTransformationManipulators(); MCommon::TransformationManipulator* GetActiveManipulator(MCommon::Camera* camera, int32 mousePosX, int32 mousePosY); @@ -177,6 +174,11 @@ namespace EMStudio void SaveRenderOptions(); void LoadRenderOptions(); + inline static constexpr AZStd::string_view s_renderWindowShortcutGroupName = "Render Window"; + inline static constexpr AZStd::string_view s_showSelectedShortcutName = "Show Selected"; + inline static constexpr AZStd::string_view s_showEntireSceneShortcutName = "Show Entire Scene"; + inline static constexpr AZStd::string_view s_toggleSelectionBoxRenderingShortcutName = "Toggle Selection Box Rendering"; + public slots: void SetManipulatorMode(RenderOptions::ManipulatorMode mode); void SetSelectionMode() { SetManipulatorMode(RenderOptions::ManipulatorMode::SELECT); } diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.cpp index f6c44980fe..9abb05ea2c 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.cpp @@ -16,7 +16,9 @@ #include "../PreferencesWindow.h" #include #include +#include #include +#include #include @@ -156,8 +158,17 @@ namespace EMStudio cameraMenu->addSeparator(); cameraMenu->addAction("Reset Camera", [this]() { this->OnResetCamera(); }); - cameraMenu->addAction("Show Selected", this, &RenderViewWidget::OnShowSelected); - cameraMenu->addAction("Show Entire Scene", this, &RenderViewWidget::OnShowEntireScene); + + QAction* showSelectedAction = cameraMenu->addAction("Show Selected", this, &RenderViewWidget::OnShowSelected); + showSelectedAction->setShortcut(Qt::Key_S); + GetMainWindow()->GetShortcutManager()->RegisterKeyboardShortcut(showSelectedAction, RenderPlugin::s_renderWindowShortcutGroupName, true); + addAction(showSelectedAction); + + QAction* showEntireSceneAction = cameraMenu->addAction("Show Entire Scene", this, &RenderViewWidget::OnShowEntireScene); + showEntireSceneAction->setShortcut(Qt::Key_A); + GetMainWindow()->GetShortcutManager()->RegisterKeyboardShortcut(showEntireSceneAction, RenderPlugin::s_renderWindowShortcutGroupName, true); + addAction(showEntireSceneAction); + cameraMenu->addSeparator(); mFollowCharacterAction = cameraMenu->addAction(tr("Follow Character")); @@ -181,8 +192,30 @@ namespace EMStudio connect(m_manipulatorModes[RenderOptions::ROTATE], &QAction::triggered, mPlugin, &RenderPlugin::SetRotationMode); connect(m_manipulatorModes[RenderOptions::SCALE], &QAction::triggered, mPlugin, &RenderPlugin::SetScaleMode); + QAction* toggleSelectionBoxRendering = new QAction( + "Toggle Selection Box Rendering", + this + ); + toggleSelectionBoxRendering->setShortcut(Qt::Key_J); + GetMainWindow()->GetShortcutManager()->RegisterKeyboardShortcut(toggleSelectionBoxRendering, RenderPlugin::s_renderWindowShortcutGroupName, true); + connect(toggleSelectionBoxRendering, &QAction::triggered, this, [this] + { + mPlugin->GetRenderOptions()->SetRenderSelectionBox(mPlugin->GetRenderOptions()->GetRenderSelectionBox() ^ true); + }); + addAction(toggleSelectionBoxRendering); + + QAction* deleteSelectedActorInstance = new QAction( + "Delete Selected Actor Instance", + this + ); + deleteSelectedActorInstance->setShortcut(Qt::Key_Delete); + connect(deleteSelectedActorInstance, &QAction::triggered, []{ CommandSystem::RemoveSelectedActorInstances(); }); + addAction(deleteSelectedActorInstance); + Reset(); UpdateInterface(); + + GetMainWindow()->LoadKeyboardShortcuts(); } void RenderViewWidget::SetManipulatorMode(RenderOptions::ManipulatorMode mode) diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.h index 33b648f9c9..3ef48d0749 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderViewWidget.h @@ -43,6 +43,8 @@ namespace EMStudio RenderViewWidget(RenderPlugin* parentPlugin, QWidget* parentWidget); virtual ~RenderViewWidget(); + void CreateActions(); + enum ERenderFlag { RENDER_SOLID = 0, diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.cpp index 6218194fc6..5ca912ef71 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.cpp @@ -25,7 +25,6 @@ #include "../EMStudioManager.h" #include "../MainWindow.h" #include -#include namespace EMStudio @@ -76,7 +75,6 @@ namespace EMStudio delete mAxisFakeCamera; } - // start view closeup flight void RenderWidget::ViewCloseup(const MCore::AABB& aabb, float flightTime, uint32 viewCloseupWaiting) { @@ -726,72 +724,6 @@ namespace EMStudio } - // called when a key got pressed - void RenderWidget::OnKeyPressEvent(QWidget* renderWidget, QKeyEvent* event) - { - MCORE_UNUSED(renderWidget); - MysticQt::KeyboardShortcutManager* shortcutManger = GetMainWindow()->GetShortcutManager(); - - if (shortcutManger->Check(event, "Show Selected", "Render Window")) - { - mPlugin->ViewCloseup(true, this); - event->accept(); - return; - } - - if (shortcutManger->Check(event, "Show Entire Scene", "Render Window")) - { - mPlugin->ViewCloseup(false, this); - event->accept(); - return; - } - - if (shortcutManger->Check(event, "Toggle Selection Box Rendering", "Render Window")) - { - mPlugin->GetRenderOptions()->SetRenderSelectionBox(mPlugin->GetRenderOptions()->GetRenderSelectionBox() ^ true); - event->accept(); - return; - } - - if (event->key() == Qt::Key_Delete) - { - CommandSystem::RemoveSelectedActorInstances(); - event->accept(); - return; - } - - event->ignore(); - } - - - // called when a key got released - void RenderWidget::OnKeyReleaseEvent(QWidget* renderWidget, QKeyEvent* event) - { - MCORE_UNUSED(renderWidget); - MysticQt::KeyboardShortcutManager* shortcutManger = GetMainWindow()->GetShortcutManager(); - - if (shortcutManger->Check(event, "Show Selected", "Render Window")) - { - event->accept(); - return; - } - - if (shortcutManger->Check(event, "Show Entire Scene", "Render Window")) - { - event->accept(); - return; - } - - if (event->key() == Qt::Key_Delete) - { - event->accept(); - return; - } - - event->ignore(); - } - - // handles context menu events void RenderWidget::OnContextMenuEvent(QWidget* renderWidget, bool shiftPressed, bool altPressed, int32 localMouseX, int32 localMouseY, QPoint globalMousePos) { diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.h index f376f10f84..99c1c38f70 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderWidget.h @@ -96,6 +96,8 @@ namespace EMStudio RenderWidget(RenderPlugin* renderPlugin, RenderViewWidget* viewWidget); virtual ~RenderWidget(); + void CreateActions(); + // main render callback virtual void Render() = 0; virtual void Update() = 0; @@ -132,8 +134,6 @@ namespace EMStudio void OnMousePressEvent(QWidget* renderWidget, QMouseEvent* event); void OnMouseReleaseEvent(QWidget* renderWidget, QMouseEvent* event); void OnWheelEvent(QWidget* renderWidget, QWheelEvent* event); - void OnKeyPressEvent(QWidget* renderWidget, QKeyEvent* event); - void OnKeyReleaseEvent(QWidget* renderWidget, QKeyEvent* event); void OnContextMenuEvent(QWidget* renderWidget, bool shiftPressed, bool altPressed, int32 localMouseX, int32 localMouseY, QPoint globalMousePos); protected: diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp index 4824821a61..28a4fb9c92 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/SaveChangedFilesManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -398,33 +399,49 @@ namespace EMStudio const size_t numDirtyFiles = dirtyFileNames.size(); mTableWidget->setRowCount(static_cast(numDirtyFiles)); - AZStd::string extension, typeString, filenameText, path, filenameOnly; for (size_t i = 0; i < numDirtyFiles; ++i) { SaveDirtyFilesCallback::ObjectPointer object = mObjects[i]; + QString labelText; if (dirtyFileNames[i].empty()) { - filenameText = ""; + labelText = ""; } else { - AzFramework::StringFunc::Path::GetFullPath(dirtyFileNames[i].c_str(), path); - AzFramework::StringFunc::Path::GetFullFileName(dirtyFileNames[i].c_str(), filenameOnly); - - filenameText = AZStd::string::format("%s%s", path.c_str(), filenameOnly.c_str()); + const AZStd::string& productFilename = dirtyFileNames[i]; + + // Get the asset source name from the product filename. + bool sourceAssetFound = false; + AZStd::string sourceAssetFilename; + AzToolsFramework::AssetSystemRequestBus::BroadcastResult(sourceAssetFound, + &AzToolsFramework::AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, + productFilename, + sourceAssetFilename); + + const AZStd::string usedFilename = sourceAssetFound ? sourceAssetFilename : dirtyFileNames[i]; + + // Separate the path from the filename, so that we can display the filename in bold. + AZStd::string fullPath; + AzFramework::StringFunc::Path::GetFullPath(usedFilename.c_str(), fullPath); + AzFramework::StringFunc::RelativePath::Normalize(fullPath); // Add trailing slash in case it is missing + AZStd::string fullFilename; + AzFramework::StringFunc::Path::GetFullFileName(usedFilename.c_str(), fullFilename); + labelText = QString("%1%2").arg(fullPath.c_str(), fullFilename.c_str()); } // create the checkbox QCheckBox* checkbox = new QCheckBox(""); - checkbox->setStyleSheet("background: transparent; padding-left: 3px; max-width: 13px;"); + checkbox->setStyleSheet("background: transparent;"); checkbox->setChecked(true); // create the filename table item QLabel* filenameLabel = new QLabel(); - filenameLabel->setToolTip(filenameText.c_str()); - filenameLabel->setText(filenameText.c_str()); + filenameLabel->setToolTip(labelText); + filenameLabel->setText(labelText); + QString typeString; if (object.mMotion) { typeString = "Motion"; @@ -445,12 +462,8 @@ namespace EMStudio { typeString = "Workspace"; } - else - { - typeString = ""; - } - QTableWidgetItem* itemType = new QTableWidgetItem(typeString.c_str()); + QTableWidgetItem* itemType = new QTableWidgetItem(typeString); const int row = static_cast(i); itemType->setData(Qt::UserRole, row); diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/RenderPlugins/Source/OpenGLRender/GLWidget.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/RenderPlugins/Source/OpenGLRender/GLWidget.h index 107869de33..c81d7c61ae 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/RenderPlugins/Source/OpenGLRender/GLWidget.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/RenderPlugins/Source/OpenGLRender/GLWidget.h @@ -72,8 +72,6 @@ namespace EMStudio void mousePressEvent(QMouseEvent* event) { RenderWidget::OnMousePressEvent(this, event); } void mouseReleaseEvent(QMouseEvent* event) { RenderWidget::OnMouseReleaseEvent(this, event); } void wheelEvent(QWheelEvent* event) { RenderWidget::OnWheelEvent(this, event); } - void keyPressEvent(QKeyEvent* event) { RenderWidget::OnKeyPressEvent(this, event); } - void keyReleaseEvent(QKeyEvent* event) { RenderWidget::OnKeyReleaseEvent(this, event); } void focusInEvent(QFocusEvent* event); void focusOutEvent(QFocusEvent* event); diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.cpp index 9cbd654393..f76f684ea5 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.cpp @@ -99,7 +99,7 @@ namespace EMStudio } if (!m_pasteItems.empty()) { - m_pasteOperation = PasteOperation::Copy; + SetPasteOperation(PasteOperation::Copy); } } @@ -126,7 +126,7 @@ namespace EMStudio } if (!m_pasteItems.empty()) { - m_pasteOperation = PasteOperation::Cut; + SetPasteOperation(PasteOperation::Cut); } } @@ -168,8 +168,8 @@ namespace EMStudio } } - m_pasteOperation = PasteOperation::None; m_pasteItems.clear(); + SetPasteOperation(PasteOperation::None); } void AnimGraphActionManager::SetEntryState() @@ -443,6 +443,18 @@ namespace EMStudio } } + void AnimGraphActionManager::NavigateToParent() + { + const QModelIndex parentFocus = m_plugin->GetAnimGraphModel().GetParentFocus(); + if (parentFocus.isValid()) + { + QModelIndex newParentFocus = parentFocus.model()->parent(parentFocus); + if (newParentFocus.isValid()) + { + m_plugin->GetAnimGraphModel().Focus(newParentFocus); + } + } + } void AnimGraphActionManager::OpenReferencedAnimGraph(EMotionFX::AnimGraphReferenceNode* referenceNode) { @@ -678,4 +690,10 @@ namespace EMStudio GetCommandManager()->ExecuteCommandGroup(commandGroup, outResult); } } + + void AnimGraphActionManager::SetPasteOperation(PasteOperation newOperation) + { + m_pasteOperation = newOperation; + emit PasteStateChanged(); + } } // namespace EMStudio diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.h index 30b520d2a5..9182272875 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.h @@ -72,6 +72,9 @@ namespace EMStudio Bottom }; + signals: + void PasteStateChanged(); + public slots: void Copy(); void Cut(); @@ -95,6 +98,7 @@ namespace EMStudio void DeleteSelectedNodes(); void NavigateToNode(); + void NavigateToParent(); void OpenReferencedAnimGraph(EMotionFX::AnimGraphReferenceNode* referenceNode); @@ -126,5 +130,7 @@ namespace EMStudio AnimGraphPlugin* m_plugin; AZStd::vector m_pasteItems; PasteOperation m_pasteOperation; + + void SetPasteOperation(PasteOperation newOperation); }; } // namespace EMStudio diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.cpp index 2669153dfd..d9b77ccf89 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.cpp @@ -461,10 +461,7 @@ namespace EMStudio { m_actionFilter = actionFilter; - if (mViewWidget) - { - mViewWidget->UpdateSelection(); - } + emit ActionFilterChanged(); } const AnimGraphActionFilter& AnimGraphPlugin::GetActionFilter() const @@ -1408,33 +1405,6 @@ namespace EMStudio } - // register keyboard shortcuts used for the render plugin - void AnimGraphPlugin::RegisterKeyboardShortcuts() - { - MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - - shortcutManager->RegisterKeyboardShortcut("Fit Entire Graph", "Anim Graph Window", Qt::Key_A, false, false, true); - shortcutManager->RegisterKeyboardShortcut("Zoom On Selected Nodes", "Anim Graph Window", Qt::Key_Z, false, false, true); - - shortcutManager->RegisterKeyboardShortcut("Open Parent Node", "Anim Graph Window", Qt::Key_Up, false, false, true); - shortcutManager->RegisterKeyboardShortcut("Open Selected Node", "Anim Graph Window", Qt::Key_Down, false, false, true); - shortcutManager->RegisterKeyboardShortcut("History Back", "Anim Graph Window", Qt::Key_Left, false, false, true); - shortcutManager->RegisterKeyboardShortcut("History Forward", "Anim Graph Window", Qt::Key_Right, false, false, true); - - shortcutManager->RegisterKeyboardShortcut("Align Left", "Anim Graph Window", Qt::Key_L, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Align Right", "Anim Graph Window", Qt::Key_R, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Align Top", "Anim Graph Window", Qt::Key_T, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Align Bottom", "Anim Graph Window", Qt::Key_B, true, false, true); - - shortcutManager->RegisterKeyboardShortcut("Cut", "Anim Graph Window", Qt::Key_X, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Copy", "Anim Graph Window", Qt::Key_C, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Paste", "Anim Graph Window", Qt::Key_V, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Select All", "Anim Graph Window", Qt::Key_A, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Unselect All", "Anim Graph Window", Qt::Key_D, true, false, true); - shortcutManager->RegisterKeyboardShortcut("Delete Selected Nodes", "Anim Graph Window", Qt::Key_Delete, false, false, true); - } - - // double clicked a node history item in the timeview plugin void AnimGraphPlugin::OnDoubleClickedRecorderNodeHistoryItem(EMotionFX::Recorder::ActorInstanceData* actorInstanceData, EMotionFX::Recorder::NodeHistoryItem* historyItem) { diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h index c1e2004aae..cb8e015429 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h @@ -49,7 +49,6 @@ namespace EMotionFX class AnimGraphObjectFactory; } - namespace EMStudio { // forward declarations @@ -151,8 +150,6 @@ namespace EMStudio void LoadOptions(); void SaveOptions(); - void RegisterKeyboardShortcuts() override; - bool CheckIfCanCreateObject(EMotionFX::AnimGraphObject* parentObject, const EMotionFX::AnimGraphObject* object, EMotionFX::AnimGraphObject::ECategory category) const; void ProcessFrame(float timePassedInSeconds) override; @@ -171,6 +168,27 @@ namespace EMStudio /// Is the given anim graph running on any selected actor instance? bool IsAnimGraphActive(EMotionFX::AnimGraph* animGraph) const; + inline static constexpr AZStd::string_view s_animGraphWindowShortcutGroupName = "Anim Graph Window"; + inline static constexpr AZStd::string_view s_fitEntireGraphShortcutName = "Fit Entire Graph"; + inline static constexpr AZStd::string_view s_zoomOnSelectedNodesShortcutName = "Zoom On Selected Nodes"; + inline static constexpr AZStd::string_view s_openParentNodeShortcutName = "Open Parent Node"; + inline static constexpr AZStd::string_view s_openSelectedNodeShortcutName = "Open Selected Node"; + inline static constexpr AZStd::string_view s_historyBackShortcutName = "History Back"; + inline static constexpr AZStd::string_view s_historyForwardShortcutName = "History Forward"; + inline static constexpr AZStd::string_view s_alignLeftShortcutName = "Align Left"; + inline static constexpr AZStd::string_view s_alignRightShortcutName = "Align Right"; + inline static constexpr AZStd::string_view s_alignTopShortcutName = "Align Top"; + inline static constexpr AZStd::string_view s_alignBottomShortcutName = "Align Bottom"; + inline static constexpr AZStd::string_view s_cutShortcutName = "Cut"; + inline static constexpr AZStd::string_view s_copyShortcutName = "Copy"; + inline static constexpr AZStd::string_view s_pasteShortcutName = "Paste"; + inline static constexpr AZStd::string_view s_selectAllShortcutName = "Select All"; + inline static constexpr AZStd::string_view s_unselectAllShortcutName = "Unselect All"; + inline static constexpr AZStd::string_view s_deleteSelectedNodesShortcutName = "Delete Selected Nodes"; + + signals: + void ActionFilterChanged(); + public slots: void OnFileOpen(); void OnFileSave(); diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.cpp index 4203271b58..eccabd37b5 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -40,74 +41,298 @@ namespace EMStudio : QWidget(parentWidget) , m_parentPlugin(plugin) { - for (uint32 i = 0; i < NUM_OPTIONS; ++i) + EMotionFX::ActorEditorRequestBus::Handler::BusConnect(); + } + + void BlendGraphViewWidget::CreateActions() + { + MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); + + m_actions[SELECTION_ALIGNLEFT] = new QAction( + QIcon(":/EMotionFX/AlignLeft.svg"), + FromStdString(AnimGraphPlugin::s_alignLeftShortcutName), + this); + m_actions[SELECTION_ALIGNLEFT]->setShortcut(Qt::Key_L | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[SELECTION_ALIGNLEFT], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[SELECTION_ALIGNLEFT], &QAction::triggered, &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignLeft); + + m_actions[SELECTION_ALIGNRIGHT] = new QAction( + QIcon(":/EMotionFX/AlignRight.svg"), + FromStdString(AnimGraphPlugin::s_alignRightShortcutName), + this); + m_actions[SELECTION_ALIGNRIGHT]->setShortcut(Qt::Key_R | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[SELECTION_ALIGNRIGHT], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[SELECTION_ALIGNRIGHT], &QAction::triggered, &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignRight); + + m_actions[SELECTION_ALIGNTOP] = new QAction( + QIcon(":/EMotionFX/AlignTop.svg"), + FromStdString(AnimGraphPlugin::s_alignTopShortcutName), + this); + m_actions[SELECTION_ALIGNTOP]->setShortcut(Qt::Key_T | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[SELECTION_ALIGNTOP], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[SELECTION_ALIGNTOP], &QAction::triggered, &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignTop); + + m_actions[SELECTION_ALIGNBOTTOM] = new QAction( + QIcon(":/EMotionFX/AlignBottom.svg"), + FromStdString(AnimGraphPlugin::s_alignBottomShortcutName), + this); + m_actions[SELECTION_ALIGNBOTTOM]->setShortcut(Qt::Key_B | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[SELECTION_ALIGNBOTTOM], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[SELECTION_ALIGNBOTTOM], &QAction::triggered, &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignBottom); + + m_actions[SELECTION_SELECTALL] = new QAction( + FromStdString(AnimGraphPlugin::s_selectAllShortcutName), + this + ); + m_actions[SELECTION_SELECTALL]->setShortcut(Qt::Key_A | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[SELECTION_SELECTALL], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[SELECTION_SELECTALL], &QAction::triggered, [this] + { + NodeGraph* activeGraph = m_parentPlugin->GetGraphWidget()->GetActiveGraph(); + if (activeGraph) + { + activeGraph->SelectAllNodes(); + } + }); + + m_actions[SELECTION_UNSELECTALL] = new QAction( + FromStdString(AnimGraphPlugin::s_unselectAllShortcutName), + this + ); + m_actions[SELECTION_UNSELECTALL]->setShortcut(Qt::Key_D | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[SELECTION_UNSELECTALL], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[SELECTION_UNSELECTALL], &QAction::triggered, [this] + { + NodeGraph* activeGraph = m_parentPlugin->GetGraphWidget()->GetActiveGraph(); + if (activeGraph) + { + activeGraph->UnselectAllNodes(); + } + }); + + m_actions[FILE_NEW] = new QAction( + QIcon(":/EMotionFX/Plus.svg"), + tr("Create a new anim graph"), + this); + m_actions[FILE_NEW]->setObjectName("EMFX.BlendGraphViewWidget.NewButton"); + connect(m_actions[FILE_NEW], &QAction::triggered, this, &BlendGraphViewWidget::OnCreateAnimGraph); + + m_actions[FILE_OPEN] = new QAction( + tr("Open..."), + this); + connect(m_actions[FILE_OPEN], &QAction::triggered, m_parentPlugin, &AnimGraphPlugin::OnFileOpen); + + m_actions[FILE_SAVE] = new QAction( + tr("Save"), + this); + connect(m_actions[FILE_SAVE], &QAction::triggered, m_parentPlugin, &AnimGraphPlugin::OnFileSave); + + m_actions[FILE_SAVEAS] = new QAction( + tr("Save as..."), + this); + connect(m_actions[FILE_SAVEAS], &QAction::triggered, m_parentPlugin, &AnimGraphPlugin::OnFileSaveAs); + + m_actions[NAVIGATION_FORWARD] = new QAction( + QIcon(":/EMotionFX/Forward.svg"), + FromStdString(AnimGraphPlugin::s_historyForwardShortcutName), + this); + m_actions[NAVIGATION_FORWARD]->setShortcut(Qt::Key_Right); + shortcutManager->RegisterKeyboardShortcut(m_actions[NAVIGATION_FORWARD], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[NAVIGATION_FORWARD], &QAction::triggered, [this] + { + m_parentPlugin->GetNavigationHistory()->StepForward(); + UpdateNavigation(); + }); + + m_actions[NAVIGATION_BACK] = new QAction( + QIcon(":/EMotionFX/Backward.svg"), + FromStdString(AnimGraphPlugin::s_historyBackShortcutName), + this); + m_actions[NAVIGATION_BACK]->setShortcut(Qt::Key_Left); + shortcutManager->RegisterKeyboardShortcut(m_actions[NAVIGATION_BACK], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[NAVIGATION_BACK], &QAction::triggered, [this] + { + m_parentPlugin->GetNavigationHistory()->StepBackward(); + UpdateNavigation(); + }); + + m_actions[NAVIGATION_NAVPANETOGGLE] = new QAction( + QIcon(":/EMotionFX/List.svg"), + tr("Show/hide navigation pane"), + this); + connect(m_actions[NAVIGATION_NAVPANETOGGLE], &QAction::triggered, this, &BlendGraphViewWidget::ToggleNavigationPane); + + m_actions[NAVIGATION_OPEN_SELECTED] = new QAction( + FromStdString(AnimGraphPlugin::s_openSelectedNodeShortcutName), + this); + m_actions[NAVIGATION_OPEN_SELECTED]->setShortcut(Qt::Key_Down); + shortcutManager->RegisterKeyboardShortcut(m_actions[NAVIGATION_OPEN_SELECTED], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[NAVIGATION_OPEN_SELECTED], &QAction::triggered, &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::NavigateToNode); + + m_actions[NAVIGATION_TO_PARENT] = new QAction( + FromStdString(AnimGraphPlugin::s_openParentNodeShortcutName), + this); + m_actions[NAVIGATION_TO_PARENT]->setShortcut(Qt::Key_Up); + shortcutManager->RegisterKeyboardShortcut(m_actions[NAVIGATION_TO_PARENT], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[NAVIGATION_TO_PARENT], &QAction::triggered, &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::NavigateToParent); + + m_actions[NAVIGATION_FRAME_ALL] = new QAction( + QIcon(":/EMotionFX/ZoomSelected.svg"), + FromStdString(AnimGraphPlugin::s_fitEntireGraphShortcutName), + this); + m_actions[NAVIGATION_FRAME_ALL]->setShortcut(Qt::Key_A); + shortcutManager->RegisterKeyboardShortcut(m_actions[NAVIGATION_FRAME_ALL], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[NAVIGATION_FRAME_ALL], &QAction::triggered, this, &BlendGraphViewWidget::ZoomToAll); + + m_actions[NAVIGATION_ZOOMSELECTION] = new QAction( + QIcon(":/EMotionFX/ZoomSelected.svg"), + FromStdString(AnimGraphPlugin::s_zoomOnSelectedNodesShortcutName), + this); + m_actions[NAVIGATION_ZOOMSELECTION]->setShortcut(Qt::Key_Z); + shortcutManager->RegisterKeyboardShortcut(m_actions[NAVIGATION_ZOOMSELECTION], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[NAVIGATION_ZOOMSELECTION], &QAction::triggered, this, &BlendGraphViewWidget::ZoomSelected); + + m_actions[ACTIVATE_ANIMGRAPH] = new QAction( + QIcon(":/EMotionFX/PlayForward.svg"), + tr("Activate Animgraph/State"), + this); + connect(m_actions[ACTIVATE_ANIMGRAPH], &QAction::triggered, &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::ActivateAnimGraph); + + m_actions[VISUALIZATION_PLAYSPEEDS] = new QAction( + tr("Display Play Speeds"), + this); + m_actions[VISUALIZATION_PLAYSPEEDS]->setCheckable(true); + connect(m_actions[VISUALIZATION_PLAYSPEEDS], &QAction::triggered, this, &BlendGraphViewWidget::OnDisplayPlaySpeeds); + + m_actions[VISUALIZATION_GLOBALWEIGHTS] = new QAction( + tr("Display Global Weights"), + this); + m_actions[VISUALIZATION_GLOBALWEIGHTS]->setCheckable(true); + connect(m_actions[VISUALIZATION_GLOBALWEIGHTS], &QAction::triggered, this, &BlendGraphViewWidget::OnDisplayGlobalWeights); + + m_actions[VISUALIZATION_SYNCSTATUS] = new QAction( + tr("Display Sync Status"), + this); + m_actions[VISUALIZATION_SYNCSTATUS]->setCheckable(true); + connect(m_actions[VISUALIZATION_SYNCSTATUS], &QAction::triggered, this, &BlendGraphViewWidget::OnDisplaySyncStatus); + + m_actions[VISUALIZATION_PLAYPOSITIONS] = new QAction( + tr("Display Play Positions"), + this); + m_actions[VISUALIZATION_PLAYPOSITIONS]->setCheckable(true); + connect(m_actions[VISUALIZATION_PLAYPOSITIONS], &QAction::triggered, this, &BlendGraphViewWidget::OnDisplayPlayPositions); + + m_actions[EDIT_CUT] = new QAction( + FromStdString(AnimGraphPlugin::s_cutShortcutName), + this + ); + m_actions[EDIT_CUT]->setShortcut(Qt::Key_X | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[EDIT_CUT], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[EDIT_CUT], &QAction::triggered, this, [this] + { + m_parentPlugin->GetActionManager().Cut(); + }); + + m_actions[EDIT_COPY] = new QAction( + FromStdString(AnimGraphPlugin::s_copyShortcutName), + this + ); + m_actions[EDIT_COPY]->setShortcut(Qt::Key_C | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[EDIT_COPY], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[EDIT_COPY], &QAction::triggered, this, [this] + { + m_parentPlugin->GetActionManager().Copy(); + }); + + m_actions[EDIT_PASTE] = new QAction( + FromStdString(AnimGraphPlugin::s_pasteShortcutName), + this + ); + m_actions[EDIT_PASTE]->setShortcut(Qt::Key_V | Qt::ControlModifier); + shortcutManager->RegisterKeyboardShortcut(m_actions[EDIT_PASTE], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[EDIT_PASTE], &QAction::triggered, this, [this] + { + const BlendGraphWidget* graphWidget = m_parentPlugin->GetGraphWidget(); + const NodeGraph* activeGraph = graphWidget->GetActiveGraph(); + if (!activeGraph) + { + return; + } + const QPoint pastePosition = graphWidget->underMouse() + ? graphWidget->SnapLocalToGrid(graphWidget->LocalToGlobal(graphWidget->mapFromGlobal(QCursor::pos()))) + : graphWidget->SnapLocalToGrid(graphWidget->LocalToGlobal(graphWidget->rect().center())); + m_parentPlugin->GetActionManager().Paste(activeGraph->GetModelIndex(), pastePosition); + }); + + m_actions[EDIT_DELETE] = new QAction( + FromStdString(AnimGraphPlugin::s_deleteSelectedNodesShortcutName), + this + ); + m_actions[EDIT_DELETE]->setShortcut(Qt::Key_Delete); + shortcutManager->RegisterKeyboardShortcut(m_actions[EDIT_DELETE], AnimGraphPlugin::s_animGraphWindowShortcutGroupName, true); + connect(m_actions[EDIT_DELETE], &QAction::triggered, this, [this] { - m_actions[i] = nullptr; + m_parentPlugin->GetGraphWidget()->DeleteSelectedItems(); + }); + + for (QAction* action : m_actions) + { + addAction(action); } - EMotionFX::ActorEditorRequestBus::Handler::BusConnect(); + GetMainWindow()->LoadKeyboardShortcuts(); } QToolBar* BlendGraphViewWidget::CreateTopToolBar() { QToolBar* toolBar = new QToolBar(this); toolBar->setObjectName("EMFX.BlendGraphViewWidget.TopToolBar"); - // Create new anim graph - { - QAction* action = toolBar->addAction(QIcon(":/EMotionFX/Plus.svg"), - tr("Create a new anim graph"), - this, &BlendGraphViewWidget::OnCreateAnimGraph); - action->setObjectName("EMFX.BlendGraphViewWidget.NewButton"); - - //action->setShortcut(QKeySequence::New); - m_actions[FILE_NEW] = action; - } + + toolBar->addAction(m_actions[FILE_NEW]); // Open anim graph { - QAction* action = toolBar->addAction( + m_openMenu = new QMenu(this); + connect(m_openMenu, &QMenu::aboutToShow, this, &BlendGraphViewWidget::BuildOpenMenu); + + QAction* action = new QAction( QIcon(":/EMotionFX/Open.svg"), - tr("Open anim graph asset")); - m_actions[FILE_OPEN] = action; + tr("Open")); + action->setMenu(m_openMenu); - QToolButton* toolButton = qobject_cast(toolBar->widgetForAction(action)); - AZ_Assert(toolButton, "The action widget must be a tool button."); - toolButton->setPopupMode(QToolButton::InstantPopup); + QToolButton* button = new QToolButton(); + button->setDefaultAction(action); + button->setPopupMode(QToolButton::InstantPopup); - m_openMenu = new QMenu(toolBar); - action->setMenu(m_openMenu); - BuildOpenMenu(); - connect(m_openMenu, &QMenu::aboutToShow, this, &BlendGraphViewWidget::BuildOpenMenu); + toolBar->addWidget(button); } + // Save anim graph { - QAction* saveMenuAction = toolBar->addAction( + QMenu* contextMenu = new QMenu(toolBar); + contextMenu->addAction(m_actions[FILE_SAVE]); + contextMenu->addAction(m_actions[FILE_SAVEAS]); + + QAction* saveMenuAction = new QAction( QIcon(":/EMotionFX/Save.svg"), tr("Save anim graph")); + saveMenuAction->setMenu(contextMenu); - QToolButton* toolButton = qobject_cast(toolBar->widgetForAction(saveMenuAction)); - AZ_Assert(toolButton, "The action widget must be a tool button."); - toolButton->setPopupMode(QToolButton::InstantPopup); - - QMenu* contextMenu = new QMenu(toolBar); - - m_actions[FILE_SAVE] = contextMenu->addAction(tr("Save"), m_parentPlugin, &AnimGraphPlugin::OnFileSave); - m_actions[FILE_SAVEAS] = contextMenu->addAction(tr("Save as..."), m_parentPlugin, &AnimGraphPlugin::OnFileSaveAs); + QToolButton* button = new QToolButton(); + button->setDefaultAction(saveMenuAction); + button->setPopupMode(QToolButton::InstantPopup); - saveMenuAction->setMenu(contextMenu); + toolBar->addWidget(button); } toolBar->addSeparator(); - m_actions[ACTIVATE_ANIMGRAPH] = toolBar->addAction(QIcon(":/EMotionFX/PlayForward.svg"), - tr("Activate Animgraph/State"), - &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::ActivateAnimGraph); + toolBar->addAction(m_actions[ACTIVATE_ANIMGRAPH]); + toolBar->addSeparator(); - m_actions[SELECTION_ZOOMSELECTION] = toolBar->addAction(QIcon(":/EMotionFX/ZoomSelected.svg"), - tr("Zoom Selection"), - this, &BlendGraphViewWidget::ZoomSelected); + toolBar->addAction(m_actions[NAVIGATION_ZOOMSELECTION]); // Visualization options { @@ -121,15 +346,10 @@ namespace EMStudio QMenu* contextMenu = new QMenu(toolBar); - m_actions[VISUALIZATION_PLAYSPEEDS] = contextMenu->addAction(tr("Display Play Speeds"), this, &BlendGraphViewWidget::OnDisplayPlaySpeeds); - m_actions[VISUALIZATION_GLOBALWEIGHTS] = contextMenu->addAction(tr("Display Global Weights"), this, &BlendGraphViewWidget::OnDisplayGlobalWeights); - m_actions[VISUALIZATION_SYNCSTATUS] = contextMenu->addAction(tr("Display Sync Status"), this, &BlendGraphViewWidget::OnDisplaySyncStatus); - m_actions[VISUALIZATION_PLAYPOSITIONS] = contextMenu->addAction(tr("Display Play Positions"), this, &BlendGraphViewWidget::OnDisplayPlayPositions); - - m_actions[VISUALIZATION_PLAYSPEEDS]->setCheckable(true); - m_actions[VISUALIZATION_GLOBALWEIGHTS]->setCheckable(true); - m_actions[VISUALIZATION_SYNCSTATUS]->setCheckable(true); - m_actions[VISUALIZATION_PLAYPOSITIONS]->setCheckable(true); + contextMenu->addAction(m_actions[VISUALIZATION_PLAYSPEEDS]); + contextMenu->addAction(m_actions[VISUALIZATION_GLOBALWEIGHTS]); + contextMenu->addAction(m_actions[VISUALIZATION_SYNCSTATUS]); + contextMenu->addAction(m_actions[VISUALIZATION_PLAYPOSITIONS]); menuAction->setMenu(contextMenu); } @@ -137,21 +357,10 @@ namespace EMStudio toolBar->addSeparator(); // Alignment Options - m_actions[SELECTION_ALIGNLEFT] = toolBar->addAction(QIcon(":/EMotionFX/AlignLeft.svg"), - tr("Align left"), - &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignLeft); - - m_actions[SELECTION_ALIGNRIGHT] = toolBar->addAction(QIcon(":/EMotionFX/AlignRight.svg"), - tr("Align right"), - &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignRight); - - m_actions[SELECTION_ALIGNTOP] = toolBar->addAction(QIcon(":/EMotionFX/AlignTop.svg"), - tr("Align top"), - &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignTop); - - m_actions[SELECTION_ALIGNBOTTOM] = toolBar->addAction(QIcon(":/EMotionFX/AlignBottom.svg"), - tr("Align bottom"), - &m_parentPlugin->GetActionManager(), &AnimGraphActionManager::AlignBottom); + toolBar->addAction(m_actions[SELECTION_ALIGNLEFT]); + toolBar->addAction(m_actions[SELECTION_ALIGNRIGHT]); + toolBar->addAction(m_actions[SELECTION_ALIGNTOP]); + toolBar->addAction(m_actions[SELECTION_ALIGNBOTTOM]); return toolBar; } @@ -160,27 +369,15 @@ namespace EMStudio { QToolBar* toolBar = new QToolBar(this); - m_actions[NAVIGATION_BACK] = toolBar->addAction(QIcon(":/EMotionFX/Backward.svg"), - tr("Back"), - this, [=] { - m_parentPlugin->GetNavigationHistory()->StepBackward(); - UpdateNavigation(); - }); + toolBar->addAction(m_actions[NAVIGATION_BACK]); - m_actions[NAVIGATION_FORWARD] = toolBar->addAction(QIcon(":/EMotionFX/Forward.svg"), - tr("Forward"), - this, [=] { - m_parentPlugin->GetNavigationHistory()->StepForward(); - UpdateNavigation(); - }); + toolBar->addAction(m_actions[NAVIGATION_FORWARD]); mNavigationLink = new NavigationLinkWidget(m_parentPlugin, this); mNavigationLink->setMinimumHeight(28); toolBar->addWidget(mNavigationLink); - m_actions[NAVIGATION_NAVPANETOGGLE] = toolBar->addAction(QIcon(":/EMotionFX/List.svg"), - tr("Show/hide navigation pane"), - this, &BlendGraphViewWidget::ToggleNavigationPane); + toolBar->addAction(m_actions[NAVIGATION_NAVPANETOGGLE]); return toolBar; } @@ -188,8 +385,11 @@ namespace EMStudio void BlendGraphViewWidget::Init(BlendGraphWidget* blendGraphWidget) { connect(&m_parentPlugin->GetAnimGraphModel(), &AnimGraphModel::FocusChanged, this, &BlendGraphViewWidget::OnFocusChanged); - connect(&m_parentPlugin->GetAnimGraphModel().GetSelectionModel(), &QItemSelectionModel::selectionChanged, this, &BlendGraphViewWidget::UpdateSelection); + connect(&m_parentPlugin->GetAnimGraphModel().GetSelectionModel(), &QItemSelectionModel::selectionChanged, this, &BlendGraphViewWidget::UpdateEnabledActions); connect(m_parentPlugin->GetNavigationHistory(), &NavigationHistory::ChangedSteppingLimits, this, &BlendGraphViewWidget::UpdateNavigation); + connect(m_parentPlugin->GetGraphWidget(), &NodeGraphWidget::ActiveGraphChanged, this, &BlendGraphViewWidget::UpdateEnabledActions); + connect(m_parentPlugin, &AnimGraphPlugin::ActionFilterChanged, this, &BlendGraphViewWidget::UpdateEnabledActions); + connect(&m_parentPlugin->GetActionManager(), &AnimGraphActionManager::PasteStateChanged, this, &BlendGraphViewWidget::UpdateEnabledActions); // create the vertical layout with the menu and the graph widget as entries QVBoxLayout* verticalLayout = new QVBoxLayout(this); @@ -198,6 +398,7 @@ namespace EMStudio verticalLayout->setMargin(2); // Create toolbars + CreateActions(); verticalLayout->addWidget(CreateTopToolBar()); verticalLayout->addWidget(CreateNavigationToolBar()); @@ -217,7 +418,7 @@ namespace EMStudio UpdateNavigation(); UpdateAnimGraphOptions(); - UpdateSelection(); + UpdateEnabledActions(); } BlendGraphViewWidget::~BlendGraphViewWidget() @@ -252,47 +453,35 @@ namespace EMStudio } } - void BlendGraphViewWidget::UpdateSelection() + void BlendGraphViewWidget::UpdateEnabledActions() { // do we have any selection? const bool anySelection = m_parentPlugin->GetAnimGraphModel().GetSelectionModel().hasSelection(); - SetOptionEnabled(SELECTION_ZOOMSELECTION, anySelection); - - QModelIndex firstSelectedNode; - bool atLeastTwoNodes = false; - const QModelIndexList selectedIndexes = m_parentPlugin->GetAnimGraphModel().GetSelectionModel().selectedRows(); - for (const QModelIndex& selected : selectedIndexes) - { - const AnimGraphModel::ModelItemType itemType = selected.data(AnimGraphModel::ROLE_MODEL_ITEM_TYPE).value(); - if (itemType == AnimGraphModel::ModelItemType::NODE) - { - if (firstSelectedNode.isValid()) - { - atLeastTwoNodes = true; - break; - } - else - { - firstSelectedNode = selected; - } - } - } + SetOptionEnabled(NAVIGATION_ZOOMSELECTION, anySelection); - if (m_parentPlugin->GetActionFilter().m_editNodes && - atLeastTwoNodes) - { - SetOptionEnabled(SELECTION_ALIGNLEFT, true); - SetOptionEnabled(SELECTION_ALIGNRIGHT, true); - SetOptionEnabled(SELECTION_ALIGNTOP, true); - SetOptionEnabled(SELECTION_ALIGNBOTTOM, true); - } - else + const auto isNodeSelected = [](const QModelIndex& index) { - SetOptionEnabled(SELECTION_ALIGNLEFT, false); - SetOptionEnabled(SELECTION_ALIGNRIGHT, false); - SetOptionEnabled(SELECTION_ALIGNTOP, false); - SetOptionEnabled(SELECTION_ALIGNBOTTOM, false); - } + return index.isValid() + && index.data(AnimGraphModel::ROLE_MODEL_ITEM_TYPE).value() == AnimGraphModel::ModelItemType::NODE; + }; + const QModelIndexList selectedIndexes = m_parentPlugin->GetAnimGraphModel().GetSelectionModel().selectedRows(); + const auto firstSelectedNode = AZStd::find_if(selectedIndexes.begin(), selectedIndexes.end(), isNodeSelected); + const auto secondSelectedNode = AZStd::find_if(firstSelectedNode, selectedIndexes.end(), isNodeSelected); + const bool atLeastTwoNodes = secondSelectedNode != selectedIndexes.end(); + + const bool enableAlignActions = m_parentPlugin->GetActionFilter().m_editNodes && atLeastTwoNodes; + SetOptionEnabled(SELECTION_ALIGNLEFT, enableAlignActions); + SetOptionEnabled(SELECTION_ALIGNRIGHT, enableAlignActions); + SetOptionEnabled(SELECTION_ALIGNTOP, enableAlignActions); + SetOptionEnabled(SELECTION_ALIGNBOTTOM, enableAlignActions); + + const bool isEditable = m_parentPlugin->GetGraphWidget()->GetActiveGraph() && !m_parentPlugin->GetGraphWidget()->GetActiveGraph()->IsInReferencedGraph(); + const AnimGraphActionFilter& actionFilter = m_parentPlugin->GetActionFilter(); + + SetOptionEnabled(EDIT_CUT, actionFilter.m_copyAndPaste && anySelection && isEditable); + SetOptionEnabled(EDIT_COPY, actionFilter.m_copyAndPaste && anySelection); + SetOptionEnabled(EDIT_PASTE, actionFilter.m_copyAndPaste && isEditable && m_parentPlugin->GetActionManager().GetIsReadyForPaste()); + SetOptionEnabled(EDIT_DELETE, actionFilter.m_copyAndPaste && anySelection && isEditable); } AnimGraphNodeWidget* BlendGraphViewWidget::GetWidgetForNode(const EMotionFX::AnimGraphNode* node) @@ -375,19 +564,17 @@ namespace EMStudio void BlendGraphViewWidget::SetOptionFlag(EOptionFlag option, bool isEnabled) { - const uint32 optionIndex = (uint32)option; - if (m_actions[optionIndex]) + if (m_actions[option]) { - m_actions[optionIndex]->setChecked(isEnabled); + m_actions[option]->setChecked(isEnabled); } } void BlendGraphViewWidget::SetOptionEnabled(EOptionFlag option, bool isEnabled) { - const uint32 optionIndex = (uint32)option; - if (m_actions[optionIndex]) + if (m_actions[option]) { - m_actions[optionIndex]->setEnabled(isEnabled); + m_actions[option]->setEnabled(isEnabled); } } @@ -395,8 +582,7 @@ namespace EMStudio { m_openMenu->clear(); - m_actions[FILE_OPEN] = m_openMenu->addAction(tr("Open...")); - connect(m_actions[FILE_OPEN], &QAction::triggered, m_parentPlugin, &AnimGraphPlugin::OnFileOpen); + m_openMenu->addAction(m_actions[FILE_OPEN]); const uint32 numAnimGraphs = EMotionFX::GetAnimGraphManager().GetNumAnimGraphs(); if (numAnimGraphs > 0) @@ -521,6 +707,19 @@ namespace EMStudio } } + void BlendGraphViewWidget::ZoomToAll() + { + BlendGraphWidget* blendGraphWidget = m_parentPlugin->GetGraphWidget(); + if (blendGraphWidget) + { + NodeGraph* nodeGraph = blendGraphWidget->GetActiveGraph(); + if (nodeGraph) + { + nodeGraph->FitGraphOnScreen(geometry().width(), geometry().height(), blendGraphWidget->GetMousePos()); + } + } + } + void BlendGraphViewWidget::OnActivateState() { // Transition to the selected state. @@ -546,7 +745,6 @@ namespace EMStudio } } - void BlendGraphViewWidget::NavigateToRoot() { const QModelIndex nodeModelIndex = m_parentPlugin->GetGraphWidget()->GetActiveGraph()->GetModelIndex(); @@ -556,20 +754,6 @@ namespace EMStudio } } - - void BlendGraphViewWidget::NavigateToParent() - { - const QModelIndex parentFocus = m_parentPlugin->GetAnimGraphModel().GetParentFocus(); - if (parentFocus.isValid()) - { - QModelIndex newParentFocus = parentFocus.model()->parent(parentFocus); - if (newParentFocus.isValid()) - { - m_parentPlugin->GetAnimGraphModel().Focus(newParentFocus); - } - } - } - void BlendGraphViewWidget::ToggleNavigationPane() { QList sizes = m_viewportSplitter->sizes(); @@ -588,16 +772,6 @@ namespace EMStudio m_viewportSplitter->setSizes(sizes); } - void BlendGraphViewWidget::NavigateToNode() - { - const QModelIndexList currentModelIndexes = m_parentPlugin->GetAnimGraphModel().GetSelectionModel().selectedRows(); - if (!currentModelIndexes.empty()) - { - const QModelIndex currentModelIndex = currentModelIndexes.front(); - m_parentPlugin->GetAnimGraphModel().Focus(currentModelIndex); - } - } - // toggle playspeed viz void BlendGraphViewWidget::OnDisplayPlaySpeeds() { @@ -638,36 +812,4 @@ namespace EMStudio EMotionFX::AnimGraphEditorNotificationBus::Broadcast(&EMotionFX::AnimGraphEditorNotificationBus::Events::OnShow); } - void BlendGraphViewWidget::keyPressEvent(QKeyEvent* event) - { - switch (event->key()) - { - case Qt::Key_Backspace: - { - m_parentPlugin->GetNavigationHistory()->StepBackward(); - event->accept(); - break; - } - - default: - event->ignore(); - } - } - - - // on key release - void BlendGraphViewWidget::keyReleaseEvent(QKeyEvent* event) - { - switch (event->key()) - { - case Qt::Key_Backspace: - { - event->accept(); - break; - } - - default: - event->ignore(); - } - } } // namespace EMStudio diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h index dbc200856a..196fadb115 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h @@ -53,25 +53,32 @@ namespace EMStudio public: enum EOptionFlag { - SELECTION_ALIGNLEFT = 0, - SELECTION_ALIGNRIGHT = 1, - SELECTION_ALIGNTOP = 2, - SELECTION_ALIGNBOTTOM = 3, - FILE_NEW = 4, - FILE_OPENFILE = 5, - FILE_OPEN = 6, - FILE_SAVE = 7, - FILE_SAVEAS = 8, - NAVIGATION_FORWARD = 9, - NAVIGATION_BACK = 10, - NAVIGATION_NAVPANETOGGLE = 11, - SELECTION_ZOOMSELECTION = 12, - ACTIVATE_ANIMGRAPH = 13, - WINDOWS_NODEGROUPWINDOW = 14, - VISUALIZATION_PLAYSPEEDS = 15, - VISUALIZATION_GLOBALWEIGHTS = 16, - VISUALIZATION_SYNCSTATUS = 17, - VISUALIZATION_PLAYPOSITIONS = 18, + SELECTION_ALIGNLEFT, + SELECTION_ALIGNRIGHT, + SELECTION_ALIGNTOP, + SELECTION_ALIGNBOTTOM, + SELECTION_SELECTALL, + SELECTION_UNSELECTALL, + FILE_NEW, + FILE_OPEN, + FILE_SAVE, + FILE_SAVEAS, + NAVIGATION_FORWARD, + NAVIGATION_BACK, + NAVIGATION_NAVPANETOGGLE, + NAVIGATION_OPEN_SELECTED, + NAVIGATION_TO_PARENT, + NAVIGATION_FRAME_ALL, + NAVIGATION_ZOOMSELECTION, + ACTIVATE_ANIMGRAPH, + VISUALIZATION_PLAYSPEEDS, + VISUALIZATION_GLOBALWEIGHTS, + VISUALIZATION_SYNCSTATUS, + VISUALIZATION_PLAYPOSITIONS, + EDIT_CUT, + EDIT_COPY, + EDIT_PASTE, + EDIT_DELETE, NUM_OPTIONS //automatically gets the next number assigned }; @@ -85,13 +92,12 @@ namespace EMStudio void Init(BlendGraphWidget* blendGraphWidget); void UpdateAnimGraphOptions(); - void UpdateSelection(); + void UpdateEnabledActions(); // If there is a specific widget to handle this node returns that. // Else, returns nullptr. AnimGraphNodeWidget* GetWidgetForNode(const EMotionFX::AnimGraphNode* node); - // Get Actions (used for testing purposes) QAction* GetAction(EOptionFlag option) const { return m_actions[option]; } public slots: @@ -100,11 +106,10 @@ namespace EMStudio void OnCreateAnimGraph(); void NavigateToRoot(); - void NavigateToNode(); - void NavigateToParent(); void ToggleNavigationPane(); void ZoomSelected(); + void ZoomToAll(); void OnActivateState(); @@ -122,17 +127,15 @@ namespace EMStudio void showEvent(QShowEvent* showEvent); - void keyReleaseEvent(QKeyEvent* event) override; - void keyPressEvent(QKeyEvent* event) override; - private: + void CreateActions(); QToolBar* CreateTopToolBar(); QToolBar* CreateNavigationToolBar(); QMenuBar* m_menu = nullptr; QMenu* m_openMenu = nullptr; QHBoxLayout* m_toolbarLayout = nullptr; - QAction* m_actions[NUM_OPTIONS]; + AZStd::array m_actions{}; AnimGraphPlugin* m_parentPlugin = nullptr; NavigationLinkWidget* mNavigationLink = nullptr; QStackedWidget m_viewportStack; diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.cpp index 7cd5a2d849..623f9f94a9 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.cpp @@ -71,12 +71,6 @@ namespace EMStudio } - // destructor - BlendGraphWidget::~BlendGraphWidget() - { - } - - // when dropping stuff in our window void BlendGraphWidget::dropEvent(QDropEvent* event) { @@ -1555,254 +1549,6 @@ namespace EMStudio } - // on keypress - void BlendGraphWidget::keyPressEvent(QKeyEvent* event) - { - MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - const AnimGraphActionFilter& actionFilter = mPlugin->GetActionFilter(); - - if (shortcutManager->Check(event, "Open Parent Node", "Anim Graph Window")) - { - const QModelIndex parentFocus = mPlugin->GetAnimGraphModel().GetParentFocus(); - if (parentFocus.isValid()) - { - QModelIndex newParentFocus = parentFocus.model()->parent(parentFocus); - if (newParentFocus.isValid()) - { - mPlugin->GetAnimGraphModel().Focus(newParentFocus); - } - } - event->accept(); - return; - } - - if (shortcutManager->Check(event, "Open Selected Node", "Anim Graph Window")) - { - mPlugin->GetActionManager().NavigateToNode(); - event->accept(); - return; - } - - if (shortcutManager->Check(event, "History Back", "Anim Graph Window")) - { - mPlugin->GetNavigationHistory()->StepBackward(); - event->accept(); - return; - } - - if (shortcutManager->Check(event, "History Forward", "Anim Graph Window")) - { - mPlugin->GetNavigationHistory()->StepForward(); - event->accept(); - return; - } - - if (mActiveGraph && - !mActiveGraph->IsInReferencedGraph()) - { - if (actionFilter.m_editNodes) - { - if (shortcutManager->Check(event, "Align Left", "Anim Graph Window")) - { - mPlugin->GetActionManager().AlignLeft(); - event->accept(); - return; - } - - if (shortcutManager->Check(event, "Align Right", "Anim Graph Window")) - { - mPlugin->GetActionManager().AlignRight(); - event->accept(); - return; - } - - if (shortcutManager->Check(event, "Align Top", "Anim Graph Window")) - { - mPlugin->GetActionManager().AlignTop(); - event->accept(); - return; - } - - if (shortcutManager->Check(event, "Align Bottom", "Anim Graph Window")) - { - mPlugin->GetActionManager().AlignBottom(); - event->accept(); - return; - } - } - - if (actionFilter.m_copyAndPaste && - shortcutManager->Check(event, "Cut", "Anim Graph Window")) - { - mPlugin->GetActionManager().Cut(); - event->accept(); - return; - } - } - - if (actionFilter.m_copyAndPaste) - { - if (shortcutManager->Check(event, "Copy", "Anim Graph Window")) - { - mPlugin->GetActionManager().Copy(); - event->accept(); - return; - } - - if (shortcutManager->Check(event, "Paste", "Anim Graph Window")) - { - if (mActiveGraph && !mActiveGraph->IsInReferencedGraph()) - { - if (mPlugin->GetActionManager().GetIsReadyForPaste()) - { - QModelIndex modelIndex = GetActiveGraph()->GetModelIndex(); - if (modelIndex.isValid()) - { - if (rect().contains(mapFromGlobal(QCursor::pos())) == false) - { - mPlugin->GetActionManager().Paste(modelIndex, GetMousePos()); - event->accept(); - } - } - } - } - return; - } - } - - if (shortcutManager->Check(event, "Select All", "Anim Graph Window")) - { - if (mActiveGraph) - { - mActiveGraph->SelectAllNodes(); - event->accept(); - } - return; - } - - if (shortcutManager->Check(event, "Unselect All", "Anim Graph Window")) - { - if (mActiveGraph) - { - mActiveGraph->UnselectAllNodes(); - event->accept(); - } - return; - } - - if (mActiveGraph && - actionFilter.m_delete && - !mActiveGraph->IsInReferencedGraph() && - shortcutManager->Check(event, "Delete Selected Nodes", "Anim Graph Window")) - { - DeleteSelectedItems(); - event->accept(); - return; - } - - return NodeGraphWidget::keyPressEvent(event); - } - - - // on key release - void BlendGraphWidget::keyReleaseEvent(QKeyEvent* event) - { - MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - const AnimGraphActionFilter& actionFilter = mPlugin->GetActionFilter(); - - if (shortcutManager->Check(event, "Open Parent Node", "Anim Graph Window")) - { - event->accept(); - return; - } - if (shortcutManager->Check(event, "Open Selected Node", "Anim Graph Window")) - { - event->accept(); - return; - } - if (shortcutManager->Check(event, "History Back", "Anim Graph Window")) - { - event->accept(); - return; - } - if (shortcutManager->Check(event, "History Forward", "Anim Graph Window")) - { - event->accept(); - return; - } - - if (mActiveGraph && !mActiveGraph->IsInReferencedGraph()) - { - if (actionFilter.m_editNodes) - { - if (shortcutManager->Check(event, "Align Left", "Anim Graph Window")) - { - event->accept(); - return; - } - if (shortcutManager->Check(event, "Align Right", "Anim Graph Window")) - { - event->accept(); - return; - } - if (shortcutManager->Check(event, "Align Top", "Anim Graph Window")) - { - event->accept(); - return; - } - if (shortcutManager->Check(event, "Align Bottom", "Anim Graph Window")) - { - event->accept(); - return; - } - } - - if (actionFilter.m_copyAndPaste && - shortcutManager->Check(event, "Cut", "Anim Graph Window")) - { - event->accept(); - return; - } - } - - if (actionFilter.m_copyAndPaste) - { - if (shortcutManager->Check(event, "Copy", "Anim Graph Window")) - { - event->accept(); - return; - } - if (mActiveGraph && !mActiveGraph->IsInReferencedGraph() && shortcutManager->Check(event, "Paste", "Anim Graph Window")) - { - event->accept(); - return; - } - } - - if (shortcutManager->Check(event, "Select All", "Anim Graph Window")) - { - event->accept(); - return; - } - if (shortcutManager->Check(event, "Unselect All", "Anim Graph Window")) - { - event->accept(); - return; - } - - if (mActiveGraph && - actionFilter.m_delete && - !mActiveGraph->IsInReferencedGraph() && - shortcutManager->Check(event, "Delete Selected Nodes", "Anim Graph Window")) - { - event->accept(); - return; - } - - return NodeGraphWidget::keyReleaseEvent(event); - } - - void BlendGraphWidget::OnRowsInserted(const QModelIndex& parent, int first, int last) { // Here we could be receiving connections, transitions or nodes being inserted into diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h index f5c5d4a5ea..7453e4cc53 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h @@ -45,7 +45,6 @@ namespace EMStudio public: BlendGraphWidget(AnimGraphPlugin* plugin, QWidget* parent); - ~BlendGraphWidget(); // overloaded bool CheckIfIsCreateConnectionValid(uint32 portNr, GraphNode* portNode, NodePort* port, bool isInputPort) override; @@ -120,8 +119,6 @@ namespace EMStudio void OnSelectionModelChanged(const QItemSelection& selected, const QItemSelection& deselected); private: - void keyReleaseEvent(QKeyEvent* event) override; - void keyPressEvent(QKeyEvent* event) override; EMotionFX::AnimGraphStateTransition* FindTransitionForConnection(NodeConnection* connection) const; EMotionFX::BlendTreeConnection* FindBlendTreeConnection(NodeConnection* connection) const; diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ContextMenu.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ContextMenu.cpp index 8866ec678e..80603c37bf 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ContextMenu.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ContextMenu.cpp @@ -183,17 +183,11 @@ namespace EMStudio if (graphNode == nullptr) { QMenu* menu = new QMenu(parentWidget); - if (actionFilter.m_copyAndPaste && actionManager.GetIsReadyForPaste()) - { - const QModelIndex modelIndex = nodeGraph->GetModelIndex(); - if (modelIndex.isValid()) - { - localMousePos = SnapLocalToGrid(LocalToGlobal(localMousePos)); - QAction* pasteAction = menu->addAction("Paste"); - connect(pasteAction, &QAction::triggered, [&actionManager, modelIndex, localMousePos]() { actionManager.Paste(modelIndex, localMousePos); }); - menu->addSeparator(); - } + if (actionFilter.m_copyAndPaste && actionManager.GetIsReadyForPaste() && nodeGraph->GetModelIndex().isValid()) + { + menu->addAction(viewWidget->GetAction(BlendGraphViewWidget::EDIT_PASTE)); + menu->addSeparator(); } if (actionFilter.m_createNodes) @@ -324,8 +318,7 @@ namespace EMStudio // we can only go to the selected node in case the selected node has a visual graph (state machine / blend tree) if (animGraphNode->GetHasVisualGraph()) { - QAction* goToNodeAction = menu->addAction("Open Selected Node"); - connect(goToNodeAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::NavigateToNode); + menu->addAction(viewWidget->GetAction(BlendGraphViewWidget::NAVIGATION_OPEN_SELECTED)); menu->addSeparator(); } @@ -360,20 +353,17 @@ namespace EMStudio if (!inReferenceGraph) { // cut and copy actions - QAction* cutAction = menu->addAction("Cut"); - connect(cutAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::Cut); + menu->addAction(viewWidget->GetAction(BlendGraphViewWidget::EDIT_CUT)); } - QAction* ccopyAction = menu->addAction("Copy"); - connect(ccopyAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::Copy); + menu->addAction(viewWidget->GetAction(BlendGraphViewWidget::EDIT_COPY)); menu->addSeparator(); } if (actionFilter.m_delete && !inReferenceGraph) { - QAction* removeNodeAction = menu->addAction("Delete Node"); - connect(removeNodeAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::DeleteSelectedNodes); + menu->addAction(viewWidget->GetAction(BlendGraphViewWidget::EDIT_DELETE)); menu->addSeparator(); } } @@ -403,22 +393,14 @@ namespace EMStudio if (actionFilter.m_editNodes && !inReferenceGraph) { - QAction* alignLeftAction = menu.addAction("Align Left"); - QAction* alignRightAction = menu.addAction("Align Right"); - QAction* alignTopAction = menu.addAction("Align Top"); - QAction* alignBottomAction = menu.addAction("Align Bottom"); - - - connect(alignLeftAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::AlignLeft); - connect(alignRightAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::AlignRight); - connect(alignTopAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::AlignTop); - connect(alignBottomAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::AlignBottom); - + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::SELECTION_ALIGNLEFT)); + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::SELECTION_ALIGNRIGHT)); + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::SELECTION_ALIGNTOP)); + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::SELECTION_ALIGNBOTTOM)); menu.addSeparator(); } - QAction* zoomSelectionAction = menu.addAction("Zoom Selection"); - connect(zoomSelectionAction, &QAction::triggered, viewWidget, &BlendGraphViewWidget::ZoomSelected); + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::NAVIGATION_ZOOMSELECTION)); menu.addSeparator(); @@ -494,12 +476,10 @@ namespace EMStudio if (!inReferenceGraph) { - QAction* cutAction = menu.addAction("Cut"); - connect(cutAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::Cut); + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::EDIT_CUT)); } - QAction* ccopyAction = menu.addAction("Copy"); - connect(ccopyAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::Copy); + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::EDIT_COPY)); } menu.addSeparator(); @@ -507,8 +487,7 @@ namespace EMStudio if (actionFilter.m_delete && !inReferenceGraph) { - QAction* removeNodesAction = menu.addAction("Delete Nodes"); - connect(removeNodesAction, &QAction::triggered, &actionManager, &AnimGraphActionManager::DeleteSelectedNodes); + menu.addAction(viewWidget->GetAction(BlendGraphViewWidget::EDIT_DELETE)); menu.addSeparator(); } @@ -526,4 +505,4 @@ namespace EMStudio } } } -} +} // namespace EMStudio diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.cpp index eae890c69d..f102cc5d96 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -155,6 +154,11 @@ namespace EMStudio // set the active graph void NodeGraphWidget::SetActiveGraph(NodeGraph* graph) { + if (mActiveGraph == graph) + { + return; + } + if (mActiveGraph) { mActiveGraph->StopCreateConnection(); @@ -165,6 +169,8 @@ namespace EMStudio mActiveGraph = graph; mMoveNode = nullptr; + + emit ActiveGraphChanged(); } @@ -322,7 +328,7 @@ namespace EMStudio // convert to a global position - QPoint NodeGraphWidget::LocalToGlobal(const QPoint& inPoint) + QPoint NodeGraphWidget::LocalToGlobal(const QPoint& inPoint) const { if (mActiveGraph) { @@ -334,7 +340,7 @@ namespace EMStudio // convert to a local position - QPoint NodeGraphWidget::GlobalToLocal(const QPoint& inPoint) + QPoint NodeGraphWidget::GlobalToLocal(const QPoint& inPoint) const { if (mActiveGraph) { @@ -345,7 +351,7 @@ namespace EMStudio } - QPoint NodeGraphWidget::SnapLocalToGrid(const QPoint& inPoint, uint32 cellSize) + QPoint NodeGraphWidget::SnapLocalToGrid(const QPoint& inPoint, uint32 cellSize) const { MCORE_UNUSED(cellSize); @@ -1491,45 +1497,9 @@ namespace EMStudio } } - MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - - if (shortcutManager->Check(event, "Fit Entire Graph", "Anim Graph Window")) - { - // zoom to fit the entire graph in view - if (mActiveGraph) - { - mActiveGraph->FitGraphOnScreen(geometry().width(), geometry().height(), GetMousePos()); - } - - event->accept(); - return; - } - - if (shortcutManager->Check(event, "Zoom On Selected Nodes", "Anim Graph Window")) - { - if (mActiveGraph) - { - // try zooming on the selection rect - QRect selectionRect = mActiveGraph->CalcRectFromSelection(true); - if (selectionRect.isEmpty() == false) - { - mActiveGraph->ZoomOnRect(selectionRect, geometry().width(), geometry().height()); - //update(); - } - else // zoom on the full scene - { - mActiveGraph->FitGraphOnScreen(geometry().width(), geometry().height(), GetMousePos()); - } - } - - event->accept(); - return; - } - event->ignore(); } - // on key release void NodeGraphWidget::keyReleaseEvent(QKeyEvent* event) { @@ -1552,20 +1522,6 @@ namespace EMStudio } } - MysticQt::KeyboardShortcutManager* shortcutManager = GetMainWindow()->GetShortcutManager(); - - if (shortcutManager->Check(event, "Fit Entire Graph", "Anim Graph Window")) - { - event->accept(); - return; - } - - if (shortcutManager->Check(event, "Zoom On Selected Nodes", "Anim Graph Window")) - { - event->accept(); - return; - } - event->ignore(); } diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.h index 68e9f72209..9b8d8c6ace 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraphWidget.h @@ -65,9 +65,9 @@ namespace EMStudio uint32 CalcNumSelectedNodes() const; - QPoint LocalToGlobal(const QPoint& inPoint); - QPoint GlobalToLocal(const QPoint& inPoint); - QPoint SnapLocalToGrid(const QPoint& inPoint, uint32 cellSize = 10); + QPoint LocalToGlobal(const QPoint& inPoint) const; + QPoint GlobalToLocal(const QPoint& inPoint) const; + QPoint SnapLocalToGrid(const QPoint& inPoint, uint32 cellSize = 10) const; void CalcSelectRect(QRect& outRect); @@ -106,6 +106,9 @@ namespace EMStudio const QString& GetTitleBarText() const { return m_titleBarText; } void SetTitleBarText(const QString& text) { m_titleBarText = text; } + signals: + void ActiveGraphChanged(); + protected: //virtual void paintEvent(QPaintEvent* event); void mouseMoveEvent(QMouseEvent* event) override; @@ -160,4 +163,4 @@ namespace EMStudio float m_borderOverwriteWidth; QString m_titleBarText; }; -} // namespace EMStudio +} // namespace EMStudio diff --git a/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.cpp b/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.cpp index 202feb3d18..0d44330b34 100644 --- a/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.cpp +++ b/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.cpp @@ -12,6 +12,8 @@ // include required headers #include "KeyboardShortcutManager.h" +#include +#include #include #include @@ -19,52 +21,27 @@ #include #include - namespace MysticQt { - // find action by name - KeyboardShortcutManager::Action* KeyboardShortcutManager::Group::FindActionByName(const char* actionName, bool local) const + void KeyboardShortcutManager::Group::RemoveAction(QAction* qaction, bool local) { - const uint32 numActions = mActions.GetLength(); - for (uint32 i = 0; i < numActions; ++i) + m_actions.erase(AZStd::find_if(begin(m_actions), end(m_actions), [&qaction, local](const AZStd::unique_ptr& action) { - if (mActions[i]->mLocal == local && mActions[i]->mName == actionName) - { - return mActions[i]; - } - } - - return nullptr; + return action->m_local == local && action->m_qaction == qaction; + })); } - // constructor - KeyboardShortcutManager::KeyboardShortcutManager() + KeyboardShortcutManager::Action* KeyboardShortcutManager::Group::FindActionByName(const QString& actionName, bool local) const { - } - - - // destructor - KeyboardShortcutManager::~KeyboardShortcutManager() - { - Clear(); - } - - - // get rid of all groups including their actions - void KeyboardShortcutManager::Clear() - { - // get rid of the groups - const uint32 numGroups = mGroups.GetLength(); - for (uint32 i = 0; i < numGroups; ++i) + const auto found = AZStd::find_if(begin(m_actions), end(m_actions), [&actionName, local](const AZStd::unique_ptr& action) { - delete mGroups[i]; - } + return action->m_local == local && action->m_qaction->text() == actionName; + }); - mGroups.Clear(); + return found != end(m_actions) ? found->get() : nullptr; } - - void KeyboardShortcutManager::RegisterKeyboardShortcut(const char* actionName, const char* groupName, int defaultKey, bool defaultCtrl, bool defaultAlt, bool local) + void KeyboardShortcutManager::RegisterKeyboardShortcut(QAction* qaction, AZStd::string_view groupName, bool local) { // find the group with the given name Group* group = FindGroupByName(groupName); @@ -72,188 +49,112 @@ namespace MysticQt // if there is no group with the given name, create it if (group == nullptr) { - group = new Group(groupName); - mGroups.Add(group); + m_groups.emplace_back(AZStd::make_unique(groupName)); + group = m_groups.back().get(); } // check if the action is already there to avoid adding it twice - Action* action = group->FindActionByName(actionName, local); + Action* action = group->FindActionByName(qaction->text(), local); if (action) { - action->mDefaultKey = defaultKey; - action->mDefaultCtrl = defaultCtrl; - action->mDefaultAlt = defaultAlt; + action->m_defaultKeySequence = qaction->shortcut(); return; } // create the new action and add it to the group - action = new Action(actionName, defaultKey, defaultCtrl, defaultAlt, local); - group->AddAction(action); - } - + group->AddAction(AZStd::make_unique(qaction, local)); - // find the action with the given name in the given group - KeyboardShortcutManager::Action* KeyboardShortcutManager::FindAction(const char* actionName, const char* groupName) - { - const uint32 numGroups = mGroups.GetLength(); - - // first search global shortcuts - for (uint32 i = 0; i < numGroups; ++i) + QAction::connect(qaction, &QAction::destroyed, this, [this, groupName = AZStd::string(groupName), local](QObject* qaction) { - if (mGroups[i]->GetNameString() == groupName) - { - Action* action = mGroups[i]->FindActionByName(actionName, false); - if (action) - { - return action; - } - } - } - - // then local shortcuts - for (uint32 i = 0; i < numGroups; ++i) - { - if (mGroups[i]->GetNameString() == groupName) - { - Action* action = mGroups[i]->FindActionByName(actionName, true); - if (action) - { - return action; - } - } - } - - // failure, not found - return nullptr; + UnregisterKeyboardShortcut(static_cast(qaction), groupName, local); + }); } - - // find a group by name - KeyboardShortcutManager::Group* KeyboardShortcutManager::FindGroupByName(const char* groupName) const + void KeyboardShortcutManager::UnregisterKeyboardShortcut(QAction* qaction, AZStd::string_view groupName, bool local) { - // iterate through the groups and find the one with the given name - const uint32 numGroups = mGroups.GetLength(); - for (uint32 i = 0; i < numGroups; ++i) + Group* group = FindGroupByName(groupName); + + if (!group) { - if (mGroups[i]->GetNameString() == groupName) - { - return mGroups[i]; - } + return; } - // failure, a group with the given name hasn't been found - return nullptr; + group->RemoveAction(qaction, local); } - bool KeyboardShortcutManager::Check(QKeyEvent* event, const char* actionName, const char* groupName) + // find the action with the given name in the given group + KeyboardShortcutManager::Action* KeyboardShortcutManager::FindAction(const QString& actionName, AZStd::string_view groupName) const { - // find the corresponding action for the given strings - Action* action = FindAction(actionName, groupName); - if (action == nullptr) + const Group* group = FindGroupByName(groupName); + if (!group) { - //MCore::LogError("Action named '%s' in group '%s' not registered. Please register the shortcut before using it.", actionName, groupName); - return false; + return nullptr; } - const bool ctrlPressed = event->modifiers() & Qt::ControlModifier; - //const bool shiftPressed = event->modifiers() & Qt::ShiftModifier; - const bool altPressed = event->modifiers() & Qt::AltModifier; - - Group* group = FindGroupByName(groupName); - Action* conflictAction = FindShortcut(event->key(), ctrlPressed, altPressed, group); - - // check if they are equal, if yes this means they match - if (action == conflictAction) + Action* action = group->FindActionByName(actionName, false); + if (action) { - return true; + return action; } + return group->FindActionByName(actionName, true); + } - // check if the action and the key event are the same shortcut - /*if (event->key() == action->mKey && - ctrlPressed == action->mCtrl && - altPressed == action->mAlt) - return true;*/ - return false; + // find a group by name + KeyboardShortcutManager::Group* KeyboardShortcutManager::FindGroupByName(AZStd::string_view groupName) const + { + const auto found = AZStd::find_if(begin(m_groups), end(m_groups), [&groupName](const AZStd::unique_ptr& group) + { + return group->GetName() == groupName; + }); + return found != end(m_groups) ? found->get() : nullptr; } // find the correspondng group for the given action - KeyboardShortcutManager::Group* KeyboardShortcutManager::FindGroupForShortcut(Action* action) + KeyboardShortcutManager::Group* KeyboardShortcutManager::FindGroupForShortcut(Action* action) const { - // get the number of available groups - const uint32 numGroups = mGroups.GetLength(); - - // first check the global shortcuts - for (uint32 i = 0; i < numGroups; ++i) + const auto foundGroup = AZStd::find_if(begin(m_groups), end(m_groups), [action](const AZStd::unique_ptr& group) { - Group* group = mGroups[i]; - - // iterate through the actions and save them - const uint32 numActions = group->GetNumActions(); - for (uint32 j = 0; j < numActions; ++j) + const auto foundAction = AZStd::find_if(begin(group->GetActions()), end(group->GetActions()), [action](const AZStd::unique_ptr& actionInGroup) { - if (group->GetAction(j) == action) - { - return group; - } - } - } - - // failure, not found - return nullptr; + return action == actionInGroup.get(); + }); + return foundAction != end(group->GetActions()) ? foundAction->get() : nullptr; + }); + return foundGroup != end(m_groups) ? foundGroup->get() : nullptr; } - KeyboardShortcutManager::Action* KeyboardShortcutManager::FindShortcut(int key, bool ctrl, bool alt, Group* group) + KeyboardShortcutManager::Action* KeyboardShortcutManager::FindShortcut(QKeySequence keySequence, Group* group) const { - // get the number of available groups - const uint32 numGroups = mGroups.GetLength(); - - // first check the global shortcuts - for (uint32 i = 0; i < numGroups; ++i) + const auto findMatchingAction = [keySequence] (const Group* group, const bool local) { - Group* currentGroup = mGroups[i]; - - // iterate through the actions and save them - const uint32 numActions = currentGroup->GetNumActions(); - for (uint32 j = 0; j < numActions; ++j) + return AZStd::find_if(begin(group->GetActions()), end(group->GetActions()), [keySequence, local] (const AZStd::unique_ptr& action) { - // get the shortcut action - KeyboardShortcutManager::Action* action = currentGroup->GetAction(j); - if (action->mLocal) + if (action->m_local != local) { - continue; + return false; } - // check if the action and shortcut are the same - if (key == action->mKey && - ctrl == action->mCtrl && - alt == action->mAlt) - { - return action; - } - } - } + return action->m_qaction->shortcut().matches(keySequence) == QKeySequence::ExactMatch; + }); + }; - // iterate through the actions and save them - const uint32 numActions = group->GetNumActions(); - for (uint32 j = 0; j < numActions; ++j) + // first check the global shortcuts + const auto globalAction = findMatchingAction(group, false); + if (globalAction != end(group->GetActions())) { - // get the shortcut action - KeyboardShortcutManager::Action* action = group->GetAction(j); + return globalAction->get(); + } - // check if the action and shortcut are the same - if (key == action->mKey && - ctrl == action->mCtrl && - alt == action->mAlt) - { - return action; - } + const auto localAction = findMatchingAction(group, true); + if (localAction != end(group->GetActions())) + { + return localAction->get(); } - // failure, shortcut not found return nullptr; } @@ -264,24 +165,16 @@ namespace MysticQt settings->clear(); // iterate through the groups and save all actions for them - const uint32 numGroups = mGroups.GetLength(); - for (uint32 i = 0; i < numGroups; ++i) + for (const AZStd::unique_ptr& group : m_groups) { - Group* group = mGroups[i]; - settings->beginGroup(group->GetName()); + settings->beginGroup(QString::fromUtf8(group->GetName().data(), group->GetName().size())); // iterate through the actions and save them - const uint32 numActions = group->GetNumActions(); - for (uint32 j = 0; j < numActions; ++j) + for (const AZStd::unique_ptr& action : group->GetActions()) { - // get the shortcut action - KeyboardShortcutManager::Action* action = group->GetAction(j); - - settings->beginGroup(action->mName.c_str()); - settings->setValue("Key", action->mKey); - settings->setValue("Ctrl", action->mCtrl); - settings->setValue("Alt", action->mAlt); - settings->setValue("Local", action->mLocal); + settings->beginGroup(action->m_qaction->text()); + settings->setValue("Key", action->m_qaction->shortcut()); + settings->setValue("Local", action->m_local); settings->endGroup(); } @@ -292,33 +185,49 @@ namespace MysticQt void KeyboardShortcutManager::Load(QSettings* settings) { - // clear the shortcut manager before loading - Clear(); - // iterate through the groups and load all actions - QStringList groupNames = settings->childGroups(); - const uint32 numGroups = groupNames.count(); - for (uint32 i = 0; i < numGroups; ++i) + const QStringList groupNames = settings->childGroups(); + for (const QString& groupName : groupNames) { - QString groupName = groupNames[i]; - settings->beginGroup(groupNames[i]); - QStringList actionNames = settings->childGroups(); + Group* group = FindGroupByName(FromQtString(groupName)); + if (!group) + { + continue; + } + + settings->beginGroup(groupName); + const QStringList actionNames = settings->childGroups(); // iterate through the actions and save them - const uint32 numActions = actionNames.count(); - for (uint32 j = 0; j < numActions; ++j) + for (const QString& actionName : actionNames) { - QString actionName = actionNames[j]; settings->beginGroup(actionName); - int key = settings->value("Key", "").toInt(); - bool ctrlPressed = settings->value("Ctrl", false).toBool(); - bool altPressed = settings->value("Alt", false).toBool(); - bool local = settings->value("Local", false).toBool(); - RegisterKeyboardShortcut(FromQtString(actionName).c_str(), FromQtString(groupName).c_str(), key, ctrlPressed, altPressed, local); + const bool local = settings->value("Local", false).toBool(); + + Action* action = group->FindActionByName(actionName, local); + if (!action) + { + continue; + } + + const QVariant keyValue = settings->value("Key", ""); + if (keyValue.canConvert()) + { + const QKeySequence key = keyValue.value(); + action->m_qaction->setShortcut(key); + } + else if (keyValue.canConvert()) + { + const int key = keyValue.value(); + const bool ctrlModifier = settings->value("Ctrl", false).value(); + const bool altModifier = settings->value("Alt", false).value(); + action->m_qaction->setShortcut(key | (ctrlModifier ? Qt::ControlModifier : 0) | (altModifier ? Qt::AltModifier : 0)); + } + settings->endGroup(); } settings->endGroup(); } } -} // namespace MysticQt +} // namespace MysticQt diff --git a/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.h b/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.h index 9bd1b58812..ce989767e0 100644 --- a/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.h +++ b/Gems/EMotionFX/Code/MysticQt/Source/KeyboardShortcutManager.h @@ -10,12 +10,14 @@ * */ -#ifndef __MYSTICQT_KEYBOARDSHORTCUTMANAGER_H -#define __MYSTICQT_KEYBOARDSHORTCUTMANAGER_H +#pragma once #if !defined(Q_MOC_RUN) +#include +#include +#include #include -#include +#include #include #include "MysticQtConfig.h" #endif @@ -26,86 +28,58 @@ class QSettings; namespace MysticQt { class MYSTICQT_API KeyboardShortcutManager + : public QObject { - MCORE_MEMORYOBJECTCATEGORY(KeyboardShortcutManager, MCore::MCORE_DEFAULT_ALIGNMENT, MEMCATEGORY_MYSTICQT); - public: - KeyboardShortcutManager(); - virtual ~KeyboardShortcutManager(); - struct Action { - MCORE_MEMORYOBJECTCATEGORY(KeyboardShortcutManager::Action, MCore::MCORE_DEFAULT_ALIGNMENT, MEMCATEGORY_MYSTICQT); - - AZStd::string mName; - int mKey; - bool mCtrl; - bool mAlt; - bool mLocal; - - int mDefaultKey; - bool mDefaultCtrl; - bool mDefaultAlt; - - Action(const char* name, int defaultKey, bool defaultCtrl, bool defaultAlt, bool local) + QAction* m_qaction; + QKeySequence m_defaultKeySequence; + bool m_local; + + Action(QAction* qaction, bool local) + : m_qaction(qaction) + , m_defaultKeySequence(qaction->shortcut()) + , m_local(local) { - mName = name; - mLocal = local; - - mKey = defaultKey; - mCtrl = defaultCtrl; - mAlt = defaultAlt; - - mDefaultKey = defaultKey; - mDefaultCtrl = defaultCtrl; - mDefaultAlt = defaultAlt; } }; class Group { - MCORE_MEMORYOBJECTCATEGORY(KeyboardShortcutManager::Group, MCore::MCORE_DEFAULT_ALIGNMENT, MEMCATEGORY_MYSTICQT); public: - Group(const char* groupName) { mName = groupName; } - virtual ~Group() + Group(AZStd::string_view groupName) + : m_name(groupName) { - const uint32 numActions = mActions.GetLength(); - for (uint32 i = 0; i < numActions; ++i) - { - delete mActions[i]; - } - mActions.Clear(); } - void AddAction(Action* action) { mActions.Add(action); } - uint32 GetNumActions() const { return mActions.GetLength(); } - Action* GetAction(uint32 index) { return mActions[index]; } - const char* GetName() const { return mName.c_str(); } - const AZStd::string& GetNameString() const { return mName; } - Action* FindActionByName(const char* actionName, bool local) const; + + void AddAction(AZStd::unique_ptr action) { m_actions.emplace_back(AZStd::move(action)); } + void RemoveAction(QAction* action, bool local); + size_t GetNumActions() const { return m_actions.size(); } + Action* GetAction(size_t index) { return m_actions[index].get(); } + const AZStd::vector>& GetActions() const { return m_actions; } + const AZStd::string& GetName() const { return m_name; } + Action* FindActionByName(const QString& actionName, bool local) const; private: - AZStd::string mName; - MCore::Array mActions; + AZStd::string m_name; + AZStd::vector> m_actions; }; - void RegisterKeyboardShortcut(const char* actionName, const char* groupName, int defaultKey, bool defaultCtrl, bool defaultAlt, bool local); - bool Check(QKeyEvent* event, const char* actionName, const char* groupName); - Action* FindShortcut(int key, bool ctrl, bool alt, Group* group); - Action* FindAction(const char* actionName, const char* groupName); - Group* FindGroupForShortcut(Action* action); - uint32 GetNumGroups() const { return mGroups.GetLength(); } - Group* GetGroup(uint32 index) const { return mGroups[index]; } - void Clear(); + void RegisterKeyboardShortcut(QAction* qaction, AZStd::string_view groupName, bool local); + void UnregisterKeyboardShortcut(QAction* qaction, AZStd::string_view groupName, bool local); + Action* FindShortcut(QKeySequence keySequence, Group* group) const; + Action* FindAction(const QString& actionName, AZStd::string_view groupName) const; + Group* FindGroupForShortcut(Action* action) const; + size_t GetNumGroups() const { return m_groups.size(); } + Group* GetGroup(size_t index) const { return m_groups[index].get(); } void Save(QSettings* settings); void Load(QSettings* settings); private: - MCore::Array mGroups; + AZStd::vector> m_groups; - Group* FindGroupByName(const char* groupName) const; + Group* FindGroupByName(AZStd::string_view groupName) const; }; } // namespace MysticQt - - -#endif diff --git a/Gems/EMotionFX/Code/MysticQt/Source/MysticQtConfig.h b/Gems/EMotionFX/Code/MysticQt/Source/MysticQtConfig.h index 54d2fddb54..90df0bf418 100644 --- a/Gems/EMotionFX/Code/MysticQt/Source/MysticQtConfig.h +++ b/Gems/EMotionFX/Code/MysticQt/Source/MysticQtConfig.h @@ -39,14 +39,19 @@ enum // convert from a QString into an AZStd::string MCORE_INLINE AZStd::string FromQtString(const QString& s) { - return s.toUtf8().data(); + return {s.toUtf8().data(), static_cast(s.size())}; } // convert from a QString into an AZStd::string MCORE_INLINE void FromQtString(const QString& s, AZStd::string* result) { - *result = s.toUtf8().data(); + *result = AZStd::string{s.toUtf8().data(), static_cast(s.size())}; +} + +inline QString FromStdString(AZStd::string_view s) +{ + return QString::fromUtf8(s.data(), static_cast(s.size())); } // forward declare a MysticQt class diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp index e3de713b3c..8ef87af9a7 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -414,9 +413,6 @@ namespace EMotionFX CheckAttachToEntity(); - // Send general mesh creation notification to interested parties. - LmbrCentral::MeshComponentNotificationBus::Event(entityId, &LmbrCentral::MeshComponentNotifications::OnMeshCreated, m_configuration.m_actorAsset); - Physics::RagdollConfiguration ragdollConfiguration; [[maybe_unused]] bool ragdollConfigValid = GetRagdollConfiguration(ragdollConfiguration); AZ_Assert(ragdollConfigValid, "Ragdoll Configuration is not valid"); @@ -460,11 +456,6 @@ namespace EMotionFX m_attachmentTargetActor = nullptr; - // Send general mesh destruction notification to interested parties. - LmbrCentral::MeshComponentNotificationBus::Event( - GetEntityId(), - &LmbrCentral::MeshComponentNotifications::OnMeshDestroyed); - ActorComponentNotificationBus::Event( GetEntityId(), &ActorComponentNotificationBus::Events::OnActorInstanceDestroyed, diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h index 1a185edccc..416705bff4 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h +++ b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -130,11 +129,7 @@ namespace EMotionFX provided.push_back(AZ_CRC("EMotionFXActorService", 0xd6e8f48d)); provided.push_back(AZ_CRC("MeshService", 0x71d8a455)); provided.push_back(AZ_CRC("CharacterPhysicsDataService", 0x34757927)); - - if (AZ::Interface::Get()) - { - provided.push_back(AZ_CRC("MaterialReceiverService", 0x0d1a6a74)); - } + provided.push_back(AZ_CRC("MaterialReceiverService", 0x0d1a6a74)); } static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/AnimAudioComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Components/AnimAudioComponent.cpp index 6958710b1a..eee9896dee 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/AnimAudioComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Components/AnimAudioComponent.cpp @@ -22,7 +22,7 @@ #include #include -#include // for SkeletalHierarchyRequestBus +#include #include diff --git a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp index 3aa281c4c2..d22bb0007f 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp @@ -26,8 +26,6 @@ #include #include -#include - #include #include #include @@ -255,11 +253,6 @@ namespace EMotionFX { if (m_actorInstance) { - // Send general mesh destruction notification to interested parties. - LmbrCentral::MeshComponentNotificationBus::Event( - GetEntityId(), - &LmbrCentral::MeshComponentNotifications::OnMeshDestroyed); - ActorComponentNotificationBus::Event( GetEntityId(), &ActorComponentNotificationBus::Events::OnActorInstanceDestroyed, @@ -650,7 +643,6 @@ namespace EMotionFX } distance = std::numeric_limits::max(); - bool isHit = false; // Get the MCore::Ray used by Mesh::Intersects // Convert the input source position and direction to a line segment by using the frustum depth as line length. @@ -659,12 +651,13 @@ namespace EMotionFX const AZ::Vector3 dest = src + dir * frustumDepth; const MCore::Ray ray(src, dest); - // Update the mesh deformers so the intersection test will hit the actor if it is being - // animated by a motion component that is previewing the animation in the editor + // Update the mesh deformers (apply software skinning and morphing) so the intersection test will hit the actor + // if it is being animated by a motion component that is previewing the animation in the editor. m_actorInstance->UpdateMeshDeformers(0.0f, true); const TransformData* transformData = m_actorInstance->GetTransformData(); const Pose* currentPose = transformData->GetCurrentPose(); + bool isHit = false; // Iterate through the meshes in the actor, looking for the closest hit const AZ::u32 lodLevel = m_actorInstance->GetLODLevel(); @@ -822,7 +815,7 @@ namespace EMotionFX bool EditorActorComponent::IsAtomDisabled() const { - return !AZ::Interface::Get(); + return false; } void EditorActorComponent::OnActorReady(Actor* actor) @@ -848,11 +841,6 @@ namespace EMotionFX if (m_actorInstance) { - // Send general mesh destruction notification to interested parties. - LmbrCentral::MeshComponentNotificationBus::Event( - GetEntityId(), - &LmbrCentral::MeshComponentNotifications::OnMeshDestroyed); - ActorComponentNotificationBus::Event( GetEntityId(), &ActorComponentNotificationBus::Events::OnActorInstanceDestroyed, @@ -941,9 +929,6 @@ namespace EMotionFX { LmbrCentral::AttachmentComponentRequestBus::Event(attachment, &LmbrCentral::AttachmentComponentRequestBus::Events::Reattach, true); } - - // Send general mesh creation notification to interested parties. - LmbrCentral::MeshComponentNotificationBus::Event(GetEntityId(), &LmbrCentral::MeshComponentNotifications::OnMeshCreated, m_actorAsset); } } //namespace Integration } // namespace EMotionFX diff --git a/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/CanDeleteAnimGraphNode.cpp b/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/CanDeleteAnimGraphNode.cpp index a7f9ae228f..c7b2363ad4 100644 --- a/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/CanDeleteAnimGraphNode.cpp +++ b/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/CanDeleteAnimGraphNode.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -64,8 +65,10 @@ namespace EMotionFX { m_blendGraphWidget->OnContextMenuEvent(m_blendGraphWidget, localPoint, m_blendGraphWidget->LocalToGlobal(localPoint), m_animGraphPlugin, m_blendGraphWidget->GetActiveGraph()->GetSelectedAnimGraphNodes(), true, false, m_animGraphPlugin->GetActionFilter()); // Find Action for deleting node - QAction* deleteAction = GetNamedAction(m_blendGraphWidget, "Delete Node"); - ASSERT_TRUE(deleteAction) << "Could not find the 'Delete Node' action in the context menu"; + QAction* deleteAction = GetNamedAction(m_animGraphPlugin->GetViewWidget(), FromStdString(EMStudio::AnimGraphPlugin::s_deleteSelectedNodesShortcutName)); + ASSERT_TRUE(deleteAction) << "Could not find the '" << + std::string(EMStudio::AnimGraphPlugin::s_deleteSelectedNodesShortcutName.data(), EMStudio::AnimGraphPlugin::s_deleteSelectedNodesShortcutName.size()) + << "' action in the context menu"; // Trigger delete const size_t nodeCount = activeAnimGraph->GetNumNodes(); diff --git a/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/Transitions/RemoveTransition.cpp b/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/Transitions/RemoveTransition.cpp index 819c24baa7..98fec0fe13 100644 --- a/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/Transitions/RemoveTransition.cpp +++ b/Gems/EMotionFX/Code/Tests/ProvidesUI/AnimGraph/Transitions/RemoveTransition.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include "qtestsystem.h" @@ -80,9 +81,8 @@ namespace EMotionFX ASSERT_TRUE(modelIndex.isValid()) << "Anim graph transition has an invalid model index."; animGraphModel.GetSelectionModel().select(QItemSelection(modelIndex, modelIndex), QItemSelectionModel::Current | QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); - // Delete key pressed. - EMStudio::BlendGraphWidget* blendGraphWidget = animGraphPlugin->GetGraphWidget(); - QTest::keyClick((QWidget*)blendGraphWidget, Qt::Key_Delete); + EMStudio::BlendGraphViewWidget* blendGraphViewWidget = animGraphPlugin->GetViewWidget(); + blendGraphViewWidget->GetAction(EMStudio::BlendGraphViewWidget::EDIT_DELETE)->trigger(); // Check if the transition get deleted. ASSERT_EQ(0, m_animGraph->GetRootStateMachine()->GetNumTransitions()) << " Anim Graph transition should be removed"; diff --git a/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp b/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp index 0759e1bbe9..b9b512da36 100644 --- a/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp +++ b/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp @@ -77,7 +77,6 @@ namespace EMotionFX m_app.RegisterComponentDescriptor(AzFramework::TransformComponent::CreateDescriptor()); m_envPrev = gEnv; - m_env.p3DEngine = nullptr; m_env.pRenderer = &m_data.m_renderer; m_env.pSystem = &m_data.m_system; gEnv = &m_env; diff --git a/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.cpp b/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.cpp index 2b7676e4db..a22064cfe2 100644 --- a/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.cpp +++ b/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.cpp @@ -161,7 +161,7 @@ namespace EditorPythonBindings bufferArg = *name; } - AZStd::string_view type = FetchPythonType(*behaviorMethod.GetArgument(argIndex)); + AZStd::string type = FetchPythonTypeName(*behaviorMethod.GetArgument(argIndex)); if (!type.empty()) { AzFramework::StringFunc::Append(bufferArg, ": "); @@ -289,7 +289,7 @@ namespace EditorPythonBindings bool isBroadcast = false; if (sender.m_event) { - AZStd::string_view addressType = FetchPythonType(behaviorEBus->m_idParam); + AZStd::string addressType = FetchPythonTypeName(behaviorEBus->m_idParam); if (addressType.empty()) { AzFramework::StringFunc::Append(buffer, "(busCallType: int, busEventName: str, address: Any, args: Tuple[Any])"); @@ -338,7 +338,7 @@ namespace EditorPythonBindings } const AZ::BehaviorParameter* resultParam = behaviorMethod->GetResult(); - AZStd::string_view returnType = FetchPythonType(*resultParam); + AZStd::string returnType = FetchPythonTypeName(*resultParam); AZStd::string returnTypeStr = AZStd::string::format(") -> " AZ_STRING_FORMAT" \n", AZ_STRING_ARG(returnType)); AzFramework::StringFunc::Append(inOutStrBuffer, returnTypeStr.c_str()); }; @@ -664,9 +664,9 @@ namespace EditorPythonBindings return m_typeCache[typeId]; } - AZStd::string_view PythonLogSymbolsComponent::FetchPythonType(const AZ::BehaviorParameter& param) + AZStd::string PythonLogSymbolsComponent::FetchPythonTypeName(const AZ::BehaviorParameter& param) { - AZStd::string_view pythonType = FetchPythonTypeAndTraits(param.m_typeId, param.m_traits); + AZStd::string pythonType = FetchPythonTypeAndTraits(param.m_typeId, param.m_traits); if (pythonType.empty()) { diff --git a/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.h b/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.h index 2972e3c9e0..e52cb00570 100644 --- a/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.h +++ b/Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.h @@ -62,6 +62,7 @@ namespace EditorPythonBindings void LogGlobalMethod(AZStd::string_view moduleName, AZStd::string_view methodName, AZ::BehaviorMethod* behaviorMethod) override; void LogGlobalProperty(AZStd::string_view moduleName, AZStd::string_view propertyName, AZ::BehaviorProperty* behaviorProperty) override; void Finalize() override; + AZStd::string FetchPythonTypeName(const AZ::BehaviorParameter& param) override; //////////////////////////////////////////////////////////////////////// // EditorPythonConsoleInterface @@ -71,7 +72,6 @@ namespace EditorPythonBindings //////////////////////////////////////////////////////////////////////// // Python type deduction AZStd::string_view FetchPythonTypeAndTraits(const AZ::TypeId& typeId, AZ::u32 traits); - AZStd::string_view FetchPythonType(const AZ::BehaviorParameter& param); private: using ModuleSet = AZStd::unordered_set; diff --git a/Gems/EditorPythonBindings/Code/Tests/PythonLogSymbolsComponentTests.cpp b/Gems/EditorPythonBindings/Code/Tests/PythonLogSymbolsComponentTests.cpp index 97f4dd02d0..8297bad094 100644 --- a/Gems/EditorPythonBindings/Code/Tests/PythonLogSymbolsComponentTests.cpp +++ b/Gems/EditorPythonBindings/Code/Tests/PythonLogSymbolsComponentTests.cpp @@ -41,9 +41,9 @@ namespace UnitTest return FetchPythonTypeAndTraits(typeId, traits); } - AZStd::string_view FetchPythonTypeWrapper(const AZ::BehaviorParameter& param) + AZStd::string FetchPythonTypeWrapper(const AZ::BehaviorParameter& param) { - return FetchPythonType(param); + return FetchPythonTypeName(param); } }; diff --git a/Gems/FastNoise/Code/Tests/FastNoiseTest.cpp b/Gems/FastNoise/Code/Tests/FastNoiseTest.cpp index 88b0df6e73..c825ab8834 100644 --- a/Gems/FastNoise/Code/Tests/FastNoiseTest.cpp +++ b/Gems/FastNoise/Code/Tests/FastNoiseTest.cpp @@ -115,7 +115,6 @@ struct MockGlobalEnvironment m_stubEnv.pCryPak = &m_stubPak; m_stubEnv.pConsole = &m_stubConsole; m_stubEnv.pSystem = &m_stubSystem; - m_stubEnv.p3DEngine = nullptr; gEnv = &m_stubEnv; } diff --git a/Gems/GameEffectSystem/Assets/GameEffectsSystem_Dependencies.xml b/Gems/GameEffectSystem/Assets/GameEffectsSystem_Dependencies.xml deleted file mode 100644 index 0e958e3c7d..0000000000 --- a/Gems/GameEffectSystem/Assets/GameEffectsSystem_Dependencies.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/Gems/GameEffectSystem/Assets/seedList.seed b/Gems/GameEffectSystem/Assets/seedList.seed deleted file mode 100644 index b011adc47b..0000000000 --- a/Gems/GameEffectSystem/Assets/seedList.seed +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/Gems/GameEffectSystem/Code/CMakeLists.txt b/Gems/GameEffectSystem/Code/CMakeLists.txt deleted file mode 100644 index f5735b5107..0000000000 --- a/Gems/GameEffectSystem/Code/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -ly_add_target( - NAME GameEffectSystem.Static STATIC - NAMESPACE Gem - FILES_CMAKE - gameeffectsystem_files.cmake - INCLUDE_DIRECTORIES - PUBLIC - include - source - BUILD_DEPENDENCIES - PUBLIC - Legacy::CryCommon -) - -ly_add_target( - NAME GameEffectSystem ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE} - NAMESPACE Gem - FILES_CMAKE - gameeffectsystem_shared_files.cmake - INCLUDE_DIRECTORIES - PUBLIC - include - BUILD_DEPENDENCIES - PRIVATE - Gem::GameEffectSystem.Static -) diff --git a/Gems/GameEffectSystem/Code/gameeffectsystem_files.cmake b/Gems/GameEffectSystem/Code/gameeffectsystem_files.cmake deleted file mode 100644 index a8f66da7e0..0000000000 --- a/Gems/GameEffectSystem/Code/gameeffectsystem_files.cmake +++ /dev/null @@ -1,27 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - source/GameEffectSystem_precompiled.cpp - source/GameEffectSystem_precompiled.h - include/GameEffectSystem/IGameEffectSystem.h - include/GameEffectSystem/IGameRenderNode.h - include/GameEffectSystem/GameEffectsSystemDefines.h - include/GameEffectSystem/GameEffects/IGameEffect.h - include/GameEffectSystem/GameEffects/GameEffectBase.h - source/GameEffectsSystem.h - source/GameEffectsSystem.cpp - source/GameEffects/GameEffectSoftCodeLibrary.cpp - source/RenderElements/GameRenderElement.h - source/RenderElements/GameRenderElement.cpp - source/RenderElements/GameRenderElementSoftCodeLibrary.cpp - source/RenderNodes/GameRenderNodeSoftCodeLibrary.cpp -) diff --git a/Gems/GameEffectSystem/Code/gameeffectsystem_shared_files.cmake b/Gems/GameEffectSystem/Code/gameeffectsystem_shared_files.cmake deleted file mode 100644 index 565deee4c2..0000000000 --- a/Gems/GameEffectSystem/Code/gameeffectsystem_shared_files.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - source/GameEffectSystemGem.h - source/GameEffectSystemGem.cpp -) - diff --git a/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffects/GameEffectBase.h b/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffects/GameEffectBase.h deleted file mode 100644 index 464c0bcdf0..0000000000 --- a/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffects/GameEffectBase.h +++ /dev/null @@ -1,213 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _GAMEEFFECTBASE_H_ -#define _GAMEEFFECTBASE_H_ - -#include -#include -#include "TypeLibrary.h" - -// Forward declares -struct SGameEffectParams; - -//================================================================================================== -// Name: Flag macros -// Desc: Flag macros to make code more readable -// Author: James Chilvers -//================================================================================================== -#define SET_FLAG(currentFlags, flag, state) ((state) ? (currentFlags |= flag) : (currentFlags &= ~flag)); -#define IS_FLAG_SET(currentFlags, flag) ((currentFlags & flag) ? true : false) -//-------------------------------------------------------------------------------------------------- - -//================================================================================================== -// Name: CGameEffect -// Desc: Game effect - Ideal for handling a specific visual game feature -// Author: James Chilvers -//================================================================================================== -class CGameEffect - : public IGameEffect -{ - DECLARE_TYPE(CGameEffect, IGameEffect); // Exposes this type for SoftCoding - -public: - CGameEffect(); - virtual ~CGameEffect(); - - void Initialize(const SGameEffectParams* gameEffectParams = NULL) override; - void Release() override; - void Update(float frameTime) override; - - void SetActive(bool isActive) override; - - void SetFlag(uint32 flag, bool state) override { SET_FLAG(m_flags, flag, state); } - bool IsFlagSet(uint32 flag) const override { return IS_FLAG_SET(m_flags, flag); } - uint32 GetFlags() const override { return m_flags; } - void SetFlags(uint32 flags) override { m_flags = flags; } - - void GetMemoryUsage(ICrySizer* pSizer) const override { pSizer->AddObject(this, sizeof(*this)); } - - void UnloadData() override { } - -protected: - // General data functions - static _smart_ptr LoadMaterial(const char* pMaterialName); - -private: - IGameEffect* Next() const override { return m_next; } - IGameEffect* Prev() const override { return m_prev; } - void SetNext(IGameEffect* newNext) override { m_next = newNext; } - void SetPrev(IGameEffect* newPrev) override { m_prev = newPrev; } - - IGameEffect* m_prev; - IGameEffect* m_next; - uint16 m_flags; - IGameEffectSystem* m_gameEffectSystem = nullptr; - -#if DEBUG_GAME_FX_SYSTEM - CryFixedStringT<32> m_debugName; -#endif -}; //----------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: CGameEffect -// Desc: Constructor -//-------------------------------------------------------------------------------------------------- -inline CGameEffect::CGameEffect() -{ - m_prev = NULL; - m_next = NULL; - m_flags = 0; - EBUS_EVENT_RESULT(m_gameEffectSystem, GameEffectSystemRequestBus, GetIGameEffectSystem); -} //------------------------------------------------------------------------------------------------ - -//-------------------------------------------------------------------------------------------------- -// Name: ~CGameEffect -// Desc: Destructor -//-------------------------------------------------------------------------------------------------- -inline CGameEffect::~CGameEffect() -{ -#if DEBUG_GAME_FX_SYSTEM - // Output message if effect hasn't been released before being deleted - const bool bEffectIsReleased = - (m_flags & GAME_EFFECT_RELEASED) || // -> Needs to be released before deleted - !(m_flags & GAME_EFFECT_INITIALISED) || // -> Except when not initialised - (gEnv->IsEditor()); // -> Or the editor (memory safely released by editor) - if (!bEffectIsReleased) - { - string dbgMessage = m_debugName + " being destroyed without being released first"; - FX_ASSERT_MESSAGE(bEffectIsReleased, dbgMessage.c_str()); - } -#endif - - if (m_gameEffectSystem) - { - // -> Effect should have been released and been unregistered, but to avoid - // crashes call unregister here too - m_gameEffectSystem->UnRegisterEffect(this); - } -} //------------------------------------------------------------------------------------------------ - -//-------------------------------------------------------------------------------------------------- -// Name: Initialise -// Desc: Initializes game effect -//-------------------------------------------------------------------------------------------------- -inline void CGameEffect::Initialize(const SGameEffectParams* gameEffectParams) -{ -#if DEBUG_GAME_FX_SYSTEM - m_debugName = GetName(); // Store name so it can be accessed in destructor and debugging -#endif - - if (!IsFlagSet(GAME_EFFECT_INITIALISED)) - { - SGameEffectParams params; - if (gameEffectParams) - { - params = *gameEffectParams; - } - - SetFlag(GAME_EFFECT_AUTO_UPDATES_WHEN_ACTIVE, params.autoUpdatesWhenActive); - SetFlag(GAME_EFFECT_AUTO_UPDATES_WHEN_NOT_ACTIVE, params.autoUpdatesWhenNotActive); - SetFlag(GAME_EFFECT_AUTO_RELEASE, params.autoRelease); - SetFlag(GAME_EFFECT_AUTO_DELETE, params.autoDelete); - - m_gameEffectSystem->RegisterEffect(this); - - SetFlag(GAME_EFFECT_INITIALISED, true); - SetFlag(GAME_EFFECT_RELEASED, false); - } -} //------------------------------------------------------------------------------------------------ - -//-------------------------------------------------------------------------------------------------- -// Name: Release -// Desc: Releases game effect -//-------------------------------------------------------------------------------------------------- -inline void CGameEffect::Release() -{ - SetFlag(GAME_EFFECT_RELEASING, true); - if (IsFlagSet(GAME_EFFECT_ACTIVE)) - { - SetActive(false); - } - m_gameEffectSystem->UnRegisterEffect(this); - SetFlag(GAME_EFFECT_INITIALISED, false); - SetFlag(GAME_EFFECT_RELEASING, false); - SetFlag(GAME_EFFECT_RELEASED, true); -} //------------------------------------------------------------------------------------------------ - -//-------------------------------------------------------------------------------------------------- -// Name: Update -// Desc: Updates game effect -//-------------------------------------------------------------------------------------------------- -inline void CGameEffect::Update(float frameTime) -{ - FX_ASSERT_MESSAGE(IsFlagSet(GAME_EFFECT_INITIALISED), - "Effect being updated without being initialised first"); - FX_ASSERT_MESSAGE((IsFlagSet(GAME_EFFECT_RELEASED) == false), - "Effect being updated after being released"); -} //------------------------------------------------------------------------------------------------ - -//-------------------------------------------------------------------------------------------------- -// Name: SetActive -// Desc: Sets active status -//-------------------------------------------------------------------------------------------------- -inline void CGameEffect::SetActive(bool isActive) -{ - FX_ASSERT_MESSAGE(IsFlagSet(GAME_EFFECT_INITIALISED), - "Effect changing active status without being initialised first"); - FX_ASSERT_MESSAGE((IsFlagSet(GAME_EFFECT_RELEASED) == false), - "Effect changing active status after being released"); - - SetFlag(GAME_EFFECT_ACTIVE, isActive); - m_gameEffectSystem->RegisterEffect(this); // Re-register effect with game effects system -} //------------------------------------------------------------------------------------------------ - -//-------------------------------------------------------------------------------------------------- -// Name: LoadMaterial -// Desc: Loads and calls AddRef on material -//-------------------------------------------------------------------------------------------------- -inline _smart_ptr CGameEffect::LoadMaterial(const char* pMaterialName) -{ - _smart_ptr pMaterial = NULL; - I3DEngine* p3DEngine = gEnv->p3DEngine; - if (pMaterialName && p3DEngine) - { - IMaterialManager* pMaterialManager = p3DEngine->GetMaterialManager(); - if (pMaterialManager) - { - pMaterial = pMaterialManager->LoadMaterial(pMaterialName); - } - } - return pMaterial; -} //------------------------------------------------------------------------------------------------ - - -#endif//_GAMEEFFECTBASE_H_ diff --git a/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffects/IGameEffect.h b/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffects/IGameEffect.h deleted file mode 100644 index b2f9aed17f..0000000000 --- a/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffects/IGameEffect.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _GAMEEFFECT_INTERFACE_H_ -#define _GAMEEFFECT_INTERFACE_H_ - -#include - -//================================================================================================== -// Name: EGameEffectFlags -// Desc: Game effect flags -// Author: James Chilvers -//================================================================================================== -enum EGameEffectFlags -{ - GAME_EFFECT_INITIALISED = (1 << 0), - GAME_EFFECT_RELEASED = (1 << 1), - GAME_EFFECT_AUTO_RELEASE = (1 << 2), // Release called when Game Effect System is destroyed - GAME_EFFECT_AUTO_DELETE = (1 << 3), // Delete is called when Game Effect System is destroyed - GAME_EFFECT_AUTO_UPDATES_WHEN_ACTIVE = (1 << 4), - GAME_EFFECT_AUTO_UPDATES_WHEN_NOT_ACTIVE = (1 << 5), - GAME_EFFECT_REGISTERED = (1 << 6), - GAME_EFFECT_ACTIVE = (1 << 7), - GAME_EFFECT_DEBUG_EFFECT = (1 << 8), // Set true for any debug effects to avoid confusion - GAME_EFFECT_UPDATE_WHEN_PAUSED = (1 << 9), - GAME_EFFECT_RELEASING = (1 << 10) -}; //----------------------------------------------------------------------------------------------- - -//================================================================================================== -// Name: SGameEffectParams -// Desc: Game effect parameters -// Author: James Chilvers -//================================================================================================== -struct SGameEffectParams -{ - friend class CGameEffect; - - // Make constructor private to stop SGameEffectParams ever being created, should always inherit - // this - // for each effect to avoid casting problems -protected: - SGameEffectParams() - { - autoUpdatesWhenActive = true; - autoUpdatesWhenNotActive = false; - autoRelease = false; - autoDelete = false; - } - -public: - bool autoUpdatesWhenActive; - bool autoUpdatesWhenNotActive; - bool autoRelease; // Release called when Game Effect System is destroyed - bool autoDelete; // Delete is called when Game Effect System is destroyed -}; //----------------------------------------------------------------------------------------------- - -//================================================================================================== -// Name: IGameEffect -// Desc: Interface for all game effects -// Author: James Chilvers -//================================================================================================== -struct IGameEffect -{ - DECLARE_TYPELIB(IGameEffect); // Allow soft coding on this interface - - friend class CGameEffectsSystem; - -public: - virtual ~IGameEffect() {} - - virtual void Initialize(const SGameEffectParams* gameEffectParams = NULL) = 0; - virtual void Release() = 0; - virtual void Update(float frameTime) = 0; - - virtual void SetActive(bool isActive) = 0; - - virtual void SetFlag(uint32 flag, bool state) = 0; - virtual bool IsFlagSet(uint32 flag) const = 0; - virtual uint32 GetFlags() const = 0; - virtual void SetFlags(uint32 flags) = 0; - - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - - virtual const char* GetName() const = 0; - - virtual void UnloadData() = 0; - -private: - virtual IGameEffect* Next() const = 0; - virtual IGameEffect* Prev() const = 0; - virtual void SetNext(IGameEffect* newNext) = 0; - virtual void SetPrev(IGameEffect* newPrev) = 0; -}; //----------------------------------------------------------------------------------------------- - -#endif//_GAMEEFFECT_INTERFACE_H_ diff --git a/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffectsSystemDefines.h b/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffectsSystemDefines.h deleted file mode 100644 index 296a9975e2..0000000000 --- a/Gems/GameEffectSystem/Code/include/GameEffectSystem/GameEffectsSystemDefines.h +++ /dev/null @@ -1,179 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _EFFECTS_GAMEEFFECTSSYSTEMDEFINES_H_ -#define _EFFECTS_GAMEEFFECTSSYSTEMDEFINES_H_ -#pragma once - -// Includes -#include "TypeLibrary.h" - -#include - -// Defines -#define GAME_FX_SYSTEM GetIGameEffectSystem() - -#ifndef _RELEASE -#define DEBUG_GAME_FX_SYSTEM 1 -#else -#define DEBUG_GAME_FX_SYSTEM 0 -#endif - -#if DEBUG_GAME_FX_SYSTEM -// Register effect's DebugOnInput and DebugDisplay callback functions -#define REGISTER_EFFECT_DEBUG_DATA(inputEventCallback, debugDisplayCallback, effectName) \ - static CGameEffectsSystem::SRegisterEffectDebugData effectName(inputEventCallback, \ - debugDisplayCallback, \ - #effectName) - -// Debug views -enum EGameEffectsSystemDebugView -{ - eGAME_FX_DEBUG_VIEW_None = 0, - eGAME_FX_DEBUG_VIEW_Profiling, - eGAME_FX_DEBUG_VIEW_EffectList, - eGAME_FX_DEBUG_VIEW_BoundingBox, - eGAME_FX_DEBUG_VIEW_BoundingSphere, - eGAME_FX_DEBUG_VIEW_Particles, - eMAX_GAME_FX_DEBUG_VIEWS - // ** If you add/remove a view then remember to update GAME_FX_DEBUG_VIEW_NAMES ** -}; - -#else -#define REGISTER_EFFECT_DEBUG_DATA(inputEventCallback, debugDisplayCallback, effectName) -#endif - -// FX Asserts -#if DEBUG_GAME_FX_SYSTEM -#define FX_ASSERT_MESSAGE(condition, message) \ - CRY_ASSERT_MESSAGE(condition, message); \ - if (!(condition)) \ - { \ - CryLogAlways("\n*************************************************************************" \ - "************"); \ - CryLogAlways("FX ASSERT"); \ - CryLogAlways("Condition: %s", #condition); \ - CryLogAlways("Message: %s", message); \ - CryLogAlways("File: %s", __FILE__); \ - CryLogAlways("Line: %d", __LINE__); \ - CryLogAlways("***************************************************************************" \ - "**********\n"); \ - } -#else -#define FX_ASSERT_MESSAGE(condition, message) -#endif - -// Profile tags -#define ENABLE_GAME_FX_PROFILE_TAGS 0 - -#if ENABLE_GAME_FX_PROFILE_TAGS -#define GAME_FX_PROFILE_BEGIN(_TAG_NAME_) \ - { \ - CryProfile::PushProfilingMarker(#_TAG_NAME_); \ - gEnv->pRenderer->PushProfileMarker(#_TAG_NAME_); \ - } -#define GAME_FX_PROFILE_END(_TAG_NAME_) \ - { \ - CryProfile::PopProfilingMarker(); \ - gEnv->pRenderer->PopProfileMarker(#_TAG_NAME_); \ - } -#define GAME_FX_PROFILE_MARKER(...) \ - { \ - PIXSetMarker(0, __VA_ARGS__); \ - } -#else -#define GAME_FX_PROFILE_BEGIN(_TAG_NAME_) \ - { \ - } -#define GAME_FX_PROFILE_END(_TAG_NAME_) \ - { \ - } -#define GAME_FX_PROFILE_MARKER(...) \ - { \ - } -#endif // ENABLE_GAME_FX_PROFILE_TAGS - -#define GAME_FX_LISTENER_NAME "GameEffectsSystem" -#define GAME_FX_LIBRARY_NAME "GameEffectsLibrary" -#define GAME_RENDER_NODE_LISTENER_NAME "GameRenderNodeListener" -#define GAME_RENDER_NODE_LIBRARY_NAME "GameRenderNodeLibrary" -#define GAME_RENDER_ELEMENT_LISTENER_NAME "GameRenderElementListener" -#define GAME_RENDER_ELEMENT_LIBRARY_NAME "GameRenderElementLibrary" - -// Macro to remove specific code when soft code is enabled -#ifdef SOFTCODE_ENABLED -#define REMOVE_IN_SOFT_CODE(_softCodeOnlyCode_) -#else -#define REMOVE_IN_SOFT_CODE(_softCodeOnlyCode_) _softCodeOnlyCode_ -#endif - -// Register effect's Game callbacks -#define REGISTER_GAME_CALLBACKS(enteredGameCallback, effectName) \ - static SRegisterGameCallbacks effectName(enteredGameCallback) - -// Create Game FX Soft Code instance -#ifdef SOFTCODE_ENABLED -#define CREATE_GAME_FX_SOFT_CODE_INSTANCE(T) \ - (static_cast(GAME_FX_SYSTEM.CreateSoftCodeInstance(#T))) -#else -#define CREATE_GAME_FX_SOFT_CODE_INSTANCE(T) (new T) -#endif - -// Safely release and delete effect through macro -#define SAFE_DELETE_GAME_EFFECT(pGameEffect) \ - if (pGameEffect) \ - { \ - pGameEffect->Release(); \ - SAFE_DELETE(pGameEffect); \ - } - -// Safely delete game render nodes -#define SAFE_DELETE_GAME_RENDER_NODE(pGameRenderNode) \ - if (pGameRenderNode) \ - { \ - pGameRenderNode->ReleaseGameRenderNode(); \ - gEnv->p3DEngine->FreeRenderNodeState(pGameRenderNode); \ - pGameRenderNode = NULL; \ - } - -// Safely delete game render elements -#define SAFE_DELETE_GAME_RENDER_ELEMENT(pGameRenderElement) \ - if (pGameRenderElement) \ - { \ - pGameRenderElement->ReleaseGameRenderElement(); \ - pGameRenderElement = NULL; \ - } - -// FX input -#define GAME_FX_INPUT_ReleaseDebugEffect AzFramework::InputDeviceKeyboard::Key::NavigationEnd.GetNameCrc32() -#define GAME_FX_INPUT_ResetParticleManager AzFramework::InputDeviceKeyboard::Key::NavigationDelete.GetNameCrc32() -#define GAME_FX_INPUT_PauseParticleManager AzFramework::InputDeviceKeyboard::Key::NavigationEnd.GetNameCrc32() -#define GAME_FX_INPUT_ReloadEffectData AzFramework::InputDeviceKeyboard::Key::NumPadDecimal.GetNameCrc32() -#define GAME_FX_INPUT_IncrementDebugEffectId AzFramework::InputDeviceKeyboard::Key::NumPadAdd.GetNameCrc32() -#define GAME_FX_INPUT_DecrementDebugEffectId AzFramework::InputDeviceKeyboard::Key::NumPadSubtract.GetNameCrc32() -#define GAME_FX_INPUT_IncrementDebugView AzFramework::InputDeviceKeyboard::Key::NavigationArrowRight.GetNameCrc32() -#define GAME_FX_INPUT_DecrementDebugView AzFramework::InputDeviceKeyboard::Key::NavigationArrowLeft.GetNameCrc32() - -// Forward declares -struct IGameEffect; -struct IGameRenderNode; -struct IGameRenderElement; -class CGameRenderNodeSoftCodeListener; -class CGameRenderElementSoftCodeListener; - -// Typedefs -typedef void (* EnteredGameCallback)(); -typedef void (* DebugOnInputEventCallback)(int); -typedef void (* DebugDisplayCallback)(const Vec2& textStartPos, float textSize, float textYStep); -typedef _smart_ptr IGameRenderNodePtr; -typedef _smart_ptr IGameRenderElementPtr; - -#endif//_EFFECTS_GAMEEFFECTSSYSTEMDEFINES_H_ diff --git a/Gems/GameEffectSystem/Code/include/GameEffectSystem/IGameEffectSystem.h b/Gems/GameEffectSystem/Code/include/GameEffectSystem/IGameEffectSystem.h deleted file mode 100644 index 22ca06b781..0000000000 --- a/Gems/GameEffectSystem/Code/include/GameEffectSystem/IGameEffectSystem.h +++ /dev/null @@ -1,163 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _GAMEEFFECTSYSTEM_INTERFACE_H_ -#define _GAMEEFFECTSYSTEM_INTERFACE_H_ - -#include -#include -#include -#include - -class IGameEffectSystem; -struct ITypeLibrary; - -/** - * For requesting the GameEffectSystem. - */ -class GameEffectSystemRequests - : public AZ::EBusTraits -{ -public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - ////////////////////////////////////////////////////////////////////////// - - virtual IGameEffectSystem* GetIGameEffectSystem() = 0; -}; -using GameEffectSystemRequestBus = AZ::EBus; - -/** - * Dispatches notifications from the GameEffectSystem. - */ -class GameEffectSystemNotifications - : public AZ::EBusTraits -{ -public: - /// Called when it's appropriate to release all registered GameEffects - virtual void OnReleaseGameEffects() { } -}; -using GameEffectSystemNotificationBus = AZ::EBus; - -/// Returns global instance of IGameEffectSystem. -/// This function exists to support the legacy GAME_FX_SYSYTEM macro, -/// this is not the suggested way to fetch a singleton. -inline IGameEffectSystem& GetIGameEffectSystem() -{ - IGameEffectSystem* instance = nullptr; - EBUS_EVENT_RESULT(instance, GameEffectSystemRequestBus, GetIGameEffectSystem); - return *instance; -} - -class IGameEffectSystem -{ -public: - virtual SC_API void RegisterEffect(IGameEffect* effect) = 0; - virtual SC_API void UnRegisterEffect(IGameEffect* effect) = 0; - - virtual SC_API void GameRenderNodeInstanceReplaced(void* pOldInstance, void* pNewInstance) = 0; - virtual SC_API void GameRenderElementInstanceReplaced(void* pOldInstance, void* pNewInstance) = 0; - -#ifdef SOFTCODE_ENABLED - // Create soft code instance using libs - virtual SC_API void* CreateSoftCodeInstance(const char* pTypeName); - // Register soft code lib for creation of instances - virtual SC_API void RegisterSoftCodeLib(ITypeLibrary* pLib); -#endif - - SC_API static void RegisterEnteredGameCallback(EnteredGameCallback enteredGameCallback); - -#ifdef DEBUG_GAME_FX_SYSTEM - SC_API static void RegisterEffectDebugData(DebugOnInputEventCallback inputEventCallback, - DebugDisplayCallback displayCallback, - const char* effectName); -#endif//DEBUG_GAME_FX_SYSTEM -}; - -#if DEBUG_GAME_FX_SYSTEM -// Creating a static version of SRegisterEffectDebugData inside an effect cpp registers the -// effect's debug data with the game effects system -struct SRegisterEffectDebugData -{ - SRegisterEffectDebugData(DebugOnInputEventCallback inputEventCallback, - DebugDisplayCallback debugDisplayCallback, const char* effectName) - { - IGameEffectSystem::RegisterEffectDebugData(inputEventCallback, debugDisplayCallback, - effectName); - } -}; - -struct SEffectDebugData -{ - SEffectDebugData(DebugOnInputEventCallback paramInputCallback, - DebugDisplayCallback paramDisplayCallback, const char* paramEffectName) - { - inputCallback = paramInputCallback; - displayCallback = paramDisplayCallback; - effectName = paramEffectName; - } - DebugOnInputEventCallback inputCallback; - DebugDisplayCallback displayCallback; - const char* effectName; -}; -#endif//DEBUG_GAME_FX_SYSTEM - -// Creating a static version of SRegisterGameCallbacks inside an effect cpp registers the -// effect's game callback functions with the game effects system -struct SRegisterGameCallbacks -{ - SRegisterGameCallbacks(EnteredGameCallback enteredGameCallback) - { - IGameEffectSystem::RegisterEnteredGameCallback(enteredGameCallback); - } -}; - -//-------------------------------------------------------------------------------------------------- -// Desc: Game Effect System Static data - contains access to any data where static initialisation -// order is critical, this will enforce initialisation on first use -//-------------------------------------------------------------------------------------------------- -struct SGameEffectSystemStaticData -{ - static PodArray& GetEnteredGameCallbackList() - { - static PodArray enteredGameCallbackList; - return enteredGameCallbackList; - } - -#if DEBUG_GAME_FX_SYSTEM - static PodArray& GetEffectDebugList() - { - static PodArray effectDebugList; - return effectDebugList; - } -#endif//DEBUG_GAME_FX_SYSTEM -}; -// Easy access macros -#define s_enteredGameCallbackList SGameEffectSystemStaticData::GetEnteredGameCallbackList() -#if DEBUG_GAME_FX_SYSTEM -#define s_effectDebugList SGameEffectSystemStaticData::GetEffectDebugList() -#endif//DEBUG_GAME_FX_SYSTEM - -//-------------------------------------------------------------------------------------------------- -// Name: RegisterEnteredGameCallback -// Desc: Registers entered game callback -//-------------------------------------------------------------------------------------------------- -inline void IGameEffectSystem::RegisterEnteredGameCallback(EnteredGameCallback enteredGameCallback) -{ - if (enteredGameCallback) - { - s_enteredGameCallbackList.push_back(enteredGameCallback); - } -} //------------------------------------------------------------------------------------------------- - -#endif//_GAMEEFFECTSYSTEM_INTERFACE_H_ diff --git a/Gems/GameEffectSystem/Code/include/GameEffectSystem/IGameRenderNode.h b/Gems/GameEffectSystem/Code/include/GameEffectSystem/IGameRenderNode.h deleted file mode 100644 index e236dbc8a6..0000000000 --- a/Gems/GameEffectSystem/Code/include/GameEffectSystem/IGameRenderNode.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _EFFECTS_RENDERNODES_IGAMERENDERNODE_H_ -#define _EFFECTS_RENDERNODES_IGAMERENDERNODE_H_ -#pragma once - -#include -#include - -// Forward declares -struct IGameRenderNodeParams; - -//================================================================================================== -// Name: IGameRenderNode -// Desc: Base interface for all game render nodes -// Author: James Chilvers -//================================================================================================== -struct IGameRenderNode - : public IRenderNode - , public _i_reference_target_t -{ - DECLARE_TYPELIB(IGameRenderNode); // Allow soft coding on this interface - - virtual ~IGameRenderNode() {} - - virtual bool InitialiseGameRenderNode() = 0; - virtual void ReleaseGameRenderNode() = 0; - - virtual void SetParams(const IGameRenderNodeParams* pParams = NULL) = 0; -}; //----------------------------------------------------------------------------------------------- - -//================================================================================================== -// Name: IGameRenderNodeParams -// Desc: Game render node params -// Author: James Chilvers -//================================================================================================== -struct IGameRenderNodeParams -{ - virtual ~IGameRenderNodeParams() {} -}; //------------------------------------------------------------------------------------------------ - -#endif//_EFFECTS_RENDERNODES_IGAMERENDERNODE_H_ diff --git a/Gems/GameEffectSystem/Code/source/GameEffectSystemGem.cpp b/Gems/GameEffectSystem/Code/source/GameEffectSystemGem.cpp deleted file mode 100644 index 589364a33a..0000000000 --- a/Gems/GameEffectSystem/Code/source/GameEffectSystemGem.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "GameEffectSystem_precompiled.h" -#include "GameEffectSystemGem.h" - -namespace -{ - /** - * Console command function for reloading the game effect system's data. - */ - void CmdReloadGameFx([[maybe_unused]] IConsoleCmdArgs* pArgs) - { - IGameEffectSystem* iGameEffectSystem = nullptr; - GameEffectSystemRequestBus::BroadcastResult(iGameEffectSystem, &GameEffectSystemRequestBus::Events::GetIGameEffectSystem); - if (iGameEffectSystem) - { - CGameEffectsSystem* cGameEffectsSystem = reinterpret_cast(iGameEffectSystem); - cGameEffectsSystem->ReloadData(); - } - } -} - -GameEffectSystemGem::GameEffectSystemGem() - : CryHooksModule() - , m_gameEffectSystem(nullptr) - , g_gameFXSystemDebug(0) -{ - GameEffectSystemRequestBus::Handler::BusConnect(); -} - -GameEffectSystemGem::~GameEffectSystemGem() -{ - GameEffectSystemRequestBus::Handler::BusDisconnect(); -} - -void GameEffectSystemGem::OnSystemEvent(ESystemEvent event, [[maybe_unused]] UINT_PTR wparam, [[maybe_unused]] UINT_PTR lparam) -{ - switch (event) - { - case ESYSTEM_EVENT_GAME_POST_INIT: - // Put your init code here - // All other Gems will exist at this point - REGISTER_CVAR(g_gameFXSystemDebug, 0, 0, "Toggles game effects system debug state"); - REGISTER_COMMAND("g_reloadGameFx", &CmdReloadGameFx, 0, "Reload all game fx"); - - m_gameEffectSystem = new CGameEffectsSystem(); - m_gameEffectSystem->Initialize(); - m_gameEffectSystem->LoadData(); - break; - - case ESYSTEM_EVENT_FULL_SHUTDOWN: - case ESYSTEM_EVENT_FAST_SHUTDOWN: - if (m_gameEffectSystem) - { - m_gameEffectSystem->ReleaseData(); - m_gameEffectSystem->Destroy(); - - delete m_gameEffectSystem; - m_gameEffectSystem = nullptr; - } - break; - } -} - -IGameEffectSystem* GameEffectSystemGem::GetIGameEffectSystem() -{ - return m_gameEffectSystem; -} - -AZ_DECLARE_MODULE_CLASS(Gem_GameEffectSystem, GameEffectSystemGem) diff --git a/Gems/GameEffectSystem/Code/source/GameEffectSystemGem.h b/Gems/GameEffectSystem/Code/source/GameEffectSystemGem.h deleted file mode 100644 index 930bbca726..0000000000 --- a/Gems/GameEffectSystem/Code/source/GameEffectSystemGem.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _GEM_GAMEEFFECTSYSTEM_H_ -#define _GEM_GAMEEFFECTSYSTEM_H_ - -#include "GameEffectsSystem.h" - -class GameEffectSystemGem - : public CryHooksModule - , public GameEffectSystemRequestBus::Handler -{ -public: - AZ_RTTI(GameEffectSystemGem, "{44350C39-A90B-46EB-AC1C-DB505113F4A6}", CryHooksModule); - -public: - GameEffectSystemGem(); - ~GameEffectSystemGem() override; - - void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam) override; - IGameEffectSystem* GetIGameEffectSystem() override; - -private: - CGameEffectsSystem* m_gameEffectSystem; - int g_gameFXSystemDebug; -}; - -#endif//_GEM_GAMEEFFECTSYSTEM_H_ diff --git a/Gems/GameEffectSystem/Code/source/GameEffectSystem_precompiled.cpp b/Gems/GameEffectSystem/Code/source/GameEffectSystem_precompiled.cpp deleted file mode 100644 index 9a1af37a08..0000000000 --- a/Gems/GameEffectSystem/Code/source/GameEffectSystem_precompiled.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "GameEffectSystem_precompiled.h" diff --git a/Gems/GameEffectSystem/Code/source/GameEffectSystem_precompiled.h b/Gems/GameEffectSystem/Code/source/GameEffectSystem_precompiled.h deleted file mode 100644 index a551219e7c..0000000000 --- a/Gems/GameEffectSystem/Code/source/GameEffectSystem_precompiled.h +++ /dev/null @@ -1,21 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef AFX_GAMEEFFECTSYSTEM_PRECOMPILED_H__140A8406_81F3_42C3_B6BB_0B14734012DE__INCLUDED_ -#define AFX_GAMEEFFECTSYSTEM_PRECOMPILED_H__140A8406_81F3_42C3_B6BB_0B14734012DE__INCLUDED_ - -#include -#include -#include -#include -#include - -#endif//AFX_GAMEEFFECTSYSTEM_PRECOMPILED_H__140A8406_81F3_42C3_B6BB_0B14734012DE__INCLUDED_ diff --git a/Gems/GameEffectSystem/Code/source/GameEffects/GameEffectSoftCodeLibrary.cpp b/Gems/GameEffectSystem/Code/source/GameEffects/GameEffectSoftCodeLibrary.cpp deleted file mode 100644 index 14f55b2af6..0000000000 --- a/Gems/GameEffectSystem/Code/source/GameEffects/GameEffectSoftCodeLibrary.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -//================================================================================================== -// Name: GameEffectSoftCodeLibrary -// Desc: Game Effect Soft Code Library -// Author: James Chilvers -//================================================================================================== - -// Includes -#include "GameEffectSystem_precompiled.h" -#include "GameEffectSystem/GameEffectsSystemDefines.h" -#include "GameEffectSystem/GameEffects/IGameEffect.h" - -IMPLEMENT_TYPELIB(IGameEffect, GAME_FX_LIBRARY_NAME); // Implementation of Soft Coding library diff --git a/Gems/GameEffectSystem/Code/source/GameEffectsSystem.cpp b/Gems/GameEffectSystem/Code/source/GameEffectsSystem.cpp deleted file mode 100644 index b9a2d4dfa7..0000000000 --- a/Gems/GameEffectSystem/Code/source/GameEffectsSystem.cpp +++ /dev/null @@ -1,1012 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -//================================================================================================== -// Name: CGameEffectsSystem -// Desc: System to handle game effects, render nodes and render elements -// Author: James Chilvers -//================================================================================================== - -// Includes -#include "GameEffectSystem_precompiled.h" -#include "GameEffectsSystem.h" -#include "BitFiddling.h" -#include "RenderElements/GameRenderElement.h" -#include -#include - -#include - -//-------------------------------------------------------------------------------------------------- -// Desc: Defines -//-------------------------------------------------------------------------------------------------- -#define GAME_FX_DATA_FILE "scripts/effects/gameeffects.xml" -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Desc: Debug data -//-------------------------------------------------------------------------------------------------- -#if DEBUG_GAME_FX_SYSTEM -int CGameEffectsSystem::s_currentDebugEffectId = 0; - -const char* GAME_FX_DEBUG_VIEW_NAMES[eMAX_GAME_FX_DEBUG_VIEWS] = { - "None", "Profiling", - "Effect List", "Bounding Box", - "Bounding Sphere", "Particles" -}; - -#endif -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Desc: Static data -//-------------------------------------------------------------------------------------------------- -int CGameEffectsSystem::s_postEffectCVarNameOffset = 0; -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -//================================================================================================== -// Name: CGameRenderNodeSoftCodeListener -// Desc: Game Render Node Soft Code Listener -// Author: James Chilvers -//================================================================================================== -class CGameRenderNodeSoftCodeListener - : public ISoftCodeListener -{ -public: - CGameRenderNodeSoftCodeListener() - { - if (gEnv->pSoftCodeMgr) - { - gEnv->pSoftCodeMgr->AddListener(GAME_RENDER_NODE_LIBRARY_NAME, this, - GAME_RENDER_NODE_LISTENER_NAME); - } - } - virtual ~CGameRenderNodeSoftCodeListener() - { - if (gEnv->pSoftCodeMgr) - { - gEnv->pSoftCodeMgr->RemoveListener(GAME_RENDER_NODE_LIBRARY_NAME, this); - } - } - - virtual void InstanceReplaced(void* pOldInstance, void* pNewInstance) - { - GAME_FX_SYSTEM.GameRenderNodeInstanceReplaced(pOldInstance, pNewInstance); - } -}; //------------------------------------------------------------------------------------------------ - -//================================================================================================== -// Name: CGameRenderElementSoftCodeListener -// Desc: Game Render Element Soft Code Listener -// Author: James Chilvers -//================================================================================================== -class CGameRenderElementSoftCodeListener - : public ISoftCodeListener -{ -public: - CGameRenderElementSoftCodeListener() - { - if (gEnv->pSoftCodeMgr) - { - gEnv->pSoftCodeMgr->AddListener(GAME_RENDER_ELEMENT_LIBRARY_NAME, this, - GAME_RENDER_ELEMENT_LISTENER_NAME); - } - } - virtual ~CGameRenderElementSoftCodeListener() - { - if (gEnv->pSoftCodeMgr) - { - gEnv->pSoftCodeMgr->RemoveListener(GAME_RENDER_ELEMENT_LIBRARY_NAME, this); - } - } - - virtual void InstanceReplaced(void* pOldInstance, void* pNewInstance) - { - GAME_FX_SYSTEM.GameRenderElementInstanceReplaced(pOldInstance, pNewInstance); - } -}; //------------------------------------------------------------------------------------------------ - -//-------------------------------------------------------------------------------------------------- -// Name: CGameEffectsSystem -// Desc: Constructor -//-------------------------------------------------------------------------------------------------- -CGameEffectsSystem::CGameEffectsSystem() - : AzFramework::InputChannelEventListener(AzFramework::InputChannelEventListener::GetPriorityDebug()) -{ -#if DEBUG_GAME_FX_SYSTEM - AzFramework::InputChannelEventListener::Connect(); -#endif - -#ifdef SOFTCODE_ENABLED - if (gEnv->pSoftCodeMgr) - { - gEnv->pSoftCodeMgr->AddListener(GAME_FX_LIBRARY_NAME, this, GAME_FX_LISTENER_NAME); - } - - m_gameRenderNodes.clear(); - m_gameRenderNodeSoftCodeListener = new CGameRenderNodeSoftCodeListener; - - m_gameRenderElements.clear(); - m_gameRenderElementSoftCodeListener = new CGameRenderElementSoftCodeListener; - - RegisterSoftCodeLib(IGameEffect::TLibrary::Instance()); - RegisterSoftCodeLib(IGameRenderNode::TLibrary::Instance()); - RegisterSoftCodeLib(IGameRenderElement::TLibrary::Instance()); -#endif - - Reset(); -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: ~CGameEffectsSystem -// Desc: Destructor -//-------------------------------------------------------------------------------------------------- -CGameEffectsSystem::~CGameEffectsSystem() -{ -#if DEBUG_GAME_FX_SYSTEM - AzFramework::InputChannelEventListener::Disconnect(); -#endif - -#ifdef SOFTCODE_ENABLED - if (gEnv->pSoftCodeMgr) - { - gEnv->pSoftCodeMgr->RemoveListener(GAME_FX_LIBRARY_NAME, this); - } - - SAFE_DELETE(m_gameRenderNodeSoftCodeListener); - SAFE_DELETE(m_gameRenderElementSoftCodeListener); - m_softCodeTypeLibs.clear(); - m_gameRenderNodes.clear(); - m_gameRenderElements.clear(); -#endif - - AZ::TickBus::Handler::BusDisconnect(); -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: Destroy -// Desc: Destroys effects system -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::Destroy() -{ - EBUS_EVENT(GameEffectSystemNotificationBus, OnReleaseGameEffects); - AutoReleaseAndDeleteFlaggedEffects(m_effectsToUpdate); - AutoReleaseAndDeleteFlaggedEffects(m_effectsNotToUpdate); - FX_ASSERT_MESSAGE(m_effectsToUpdate == nullptr && m_effectsNotToUpdate == nullptr, - "Game Effects System being destroyed even though game effects still exist!"); -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: Reset -// Desc: Resets effects systems data -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::Reset() -{ - m_isInitialised = false; - m_effectsToUpdate = NULL; - m_effectsNotToUpdate = NULL; - m_nextEffectToUpdate = NULL; - s_postEffectCVarNameOffset = 0; - -#if DEBUG_GAME_FX_SYSTEM - m_debugView = eGAME_FX_DEBUG_VIEW_None; -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: Initialize -// Desc: Initializes effects system -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::Initialize() -{ - if (m_isInitialised == false) - { - Reset(); - SetPostEffectCVarCallbacks(); - - AZ::TickBus::Handler::BusConnect(); - - m_isInitialised = true; - } -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: GameRulesInitialise -// Desc: Game Rules initialise -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::GameRulesInitialise() -{ -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: LoadData -// Desc: Loads data for game effects system and effects -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::LoadData() -{ -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: ReleaseData -// Desc: Releases any loaded data for game effects system and any effects with registered callbacks -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::ReleaseData() -{ - if (s_hasLoadedData) - { -#if DEBUG_GAME_FX_SYSTEM - // Unload all debug effects which rely on effect data - for (size_t i = 0; i < s_effectDebugList.Size(); i++) - { - if (s_effectDebugList[i].inputCallback) - { - s_effectDebugList[i].inputCallback(GAME_FX_INPUT_ReleaseDebugEffect); - } - } -#endif - - for (IGameEffect* ge = m_effectsToUpdate; ge; ge = ge->Next()) - { - ge->UnloadData(); - } - for (IGameEffect* ge = m_effectsNotToUpdate; ge; ge = ge->Next()) - { - ge->UnloadData(); - } - s_hasLoadedData = false; - } -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: ReloadData -// Desc: Reloads any loaded data for game effects registered callbacks -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::ReloadData() -{ -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: EnteredGame -// Desc: Called when entering a game -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::EnteredGame() -{ - const int callbackCount = s_enteredGameCallbackList.size(); - EnteredGameCallback enteredGameCallbackFunc = NULL; - for (int i = 0; i < callbackCount; i++) - { - enteredGameCallbackFunc = s_enteredGameCallbackList[i]; - if (enteredGameCallbackFunc) - { - enteredGameCallbackFunc(); - } - } -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: AutoReleaseAndDeleteFlaggedEffects -// Desc: Calls release and delete on any effects with the these flags set -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::AutoReleaseAndDeleteFlaggedEffects(IGameEffect* effectList) -{ - if (effectList) - { - IGameEffect* effect = effectList; - while (effect) - { - m_nextEffectToUpdate = effect->Next(); - - bool autoRelease = effect->IsFlagSet(GAME_EFFECT_AUTO_RELEASE); - bool autoDelete = effect->IsFlagSet(GAME_EFFECT_AUTO_DELETE); - - if (autoRelease || autoDelete) - { - SOFTCODE_RETRY(effect, effect->Release()); - if (autoDelete) - { - SAFE_DELETE(effect); - } - } - - effect = m_nextEffectToUpdate; - } - m_nextEffectToUpdate = NULL; - } -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: InstanceReplaced -// Desc: Replaces instance for soft coding -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::InstanceReplaced([[maybe_unused]] void* pOldInstance, [[maybe_unused]] void* pNewInstance) -{ -#ifdef SOFTCODE_ENABLED - if (pNewInstance && pOldInstance) - { - IGameEffect* pNewGameEffectInstance = static_cast(pNewInstance); - IGameEffect* pOldGameEffectInstance = static_cast(pOldInstance); - - // Copy over flags and remove registered flag so new effect instance can be registered - // We haven't used the SOFT macro on the m_flags member because the oldInstance's flags - // would then be Nulled out, and they are needed for the effect to be deregistered - uint32 oldGameEffectFlags = pOldGameEffectInstance->GetFlags(); - SET_FLAG(oldGameEffectFlags, GAME_EFFECT_REGISTERED, false); - pNewGameEffectInstance->SetFlags(oldGameEffectFlags); - - // Register new effect instance, old instance will get unregistered by destructor - GAME_FX_SYSTEM.RegisterEffect(pNewGameEffectInstance); - - // Reload all data used by effects, then data can be added/removed for soft coding - ReloadData(); - - // Data used by effect will be copied to new effect, so mustn't release it but - // must set flag so destructor doesn't assert - pOldGameEffectInstance->SetFlag(GAME_EFFECT_RELEASED, true); - } -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: GameRenderNodeInstanceReplaced -// Desc: Replaces Game Render Node instance for soft coding -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::GameRenderNodeInstanceReplaced([[maybe_unused]] void* pOldInstance, [[maybe_unused]] void* pNewInstance) -{ -#ifdef SOFTCODE_ENABLED - if (pOldInstance && pNewInstance) - { - IGameRenderNode* pOldGameRenderNodeInstance = (IGameRenderNode*)pOldInstance; - IGameRenderNode* pNewGameRenderNodeInstance = (IGameRenderNode*)pNewInstance; - - // Unregister old node from engine - gEnv->p3DEngine->FreeRenderNodeState(pOldGameRenderNodeInstance); - - // Register new node with engine - gEnv->p3DEngine->RegisterEntity(pNewGameRenderNodeInstance); - - for (TGameRenderNodeVec::iterator iter(m_gameRenderNodes.begin()); - iter != m_gameRenderNodes.end(); ++iter) - { - IGameRenderNodePtr* ppRenderNode = *iter; - if (ppRenderNode) - { - IGameRenderNodePtr& pRenderNode = *ppRenderNode; - - if (pRenderNode == pOldGameRenderNodeInstance) - { - pRenderNode = pNewGameRenderNodeInstance; - } - } - } - } -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: GameRenderElementInstanceReplaced -// Desc: Replaces Game Render Element instance for soft coding -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::GameRenderElementInstanceReplaced([[maybe_unused]] void* pOldInstance, [[maybe_unused]] void* pNewInstance) -{ -#ifdef SOFTCODE_ENABLED - if (pOldInstance && pNewInstance) - { - IGameRenderElement* pOldGameRenderElementInstance = (IGameRenderElement*)pOldInstance; - IGameRenderElement* pNewGameRenderElementInstance = (IGameRenderElement*)pNewInstance; - - pNewGameRenderElementInstance->UpdatePrivateImplementation(); - - for (TGameRenderElementVec::iterator iter(m_gameRenderElements.begin()); - iter != m_gameRenderElements.end(); ++iter) - { - IGameRenderElementPtr* ppRenderElement = *iter; - if (ppRenderElement) - { - IGameRenderElementPtr& pRenderElement = *ppRenderElement; - - if (pRenderElement == pOldGameRenderElementInstance) - { - pRenderElement = pNewGameRenderElementInstance; - } - } - } - } -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: SetPostEffectCVarCallbacks -// Desc: Sets Post effect CVar callbacks for testing and tweaking post effect values -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::SetPostEffectCVarCallbacks() -{ -#if DEBUG_GAME_FX_SYSTEM - ICVar* postEffectCvar = NULL; - const char postEffectNames[][64] = - { - "g_postEffect.FilterGrain_Amount", "g_postEffect.FilterRadialBlurring_Amount", - "g_postEffect.FilterRadialBlurring_ScreenPosX", - "g_postEffect.FilterRadialBlurring_ScreenPosY", "g_postEffect.FilterRadialBlurring_Radius", - "g_postEffect.Global_User_ColorC", "g_postEffect.Global_User_ColorM", - "g_postEffect.Global_User_ColorY", "g_postEffect.Global_User_ColorK", - "g_postEffect.Global_User_Brightness", "g_postEffect.Global_User_Contrast", - "g_postEffect.Global_User_Saturation", "g_postEffect.Global_User_ColorHue" - }; - - int postEffectNameCount = sizeof(postEffectNames) / sizeof(*postEffectNames); - - if (postEffectNameCount > 0) - { - // Calc name offset - const char* postEffectName = postEffectNames[0]; - s_postEffectCVarNameOffset = 0; - while ((*postEffectName) != 0) - { - s_postEffectCVarNameOffset++; - if ((*postEffectName) == '.') - { - break; - } - postEffectName++; - } - - // Set callback functions - for (int i = 0; i < postEffectNameCount; i++) - { - postEffectCvar = gEnv->pConsole->GetCVar(postEffectNames[i]); - if (postEffectCvar) - { - postEffectCvar->SetOnChangeCallback(PostEffectCVarCallback); - } - } - } -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: PostEffectCVarCallback -// Desc: Callback function of post effect cvars to set their values -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::PostEffectCVarCallback(ICVar* cvar) -{ - const char* effectName = cvar->GetName() + s_postEffectCVarNameOffset; - gEnv->p3DEngine->SetPostEffectParam(effectName, cvar->GetFVal()); -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: RegisterEffect -// Desc: Registers effect with effect system -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::RegisterEffect(IGameEffect* effect) -{ - FX_ASSERT_MESSAGE(m_isInitialised, - "Game Effects System trying to register an effect without being initialised"); - FX_ASSERT_MESSAGE(effect, "Trying to Register a NULL effect"); - - if (effect) - { - // If effect is registered, then unregister first - if (effect->IsFlagSet(GAME_EFFECT_REGISTERED)) - { - UnRegisterEffect(effect); - } - - // Add effect to effect list - IGameEffect** effectList = NULL; - bool isActive = effect->IsFlagSet(GAME_EFFECT_ACTIVE); - bool autoUpdatesWhenActive = effect->IsFlagSet(GAME_EFFECT_AUTO_UPDATES_WHEN_ACTIVE); - bool autoUpdatesWhenNotActive = effect->IsFlagSet(GAME_EFFECT_AUTO_UPDATES_WHEN_NOT_ACTIVE); - if ((isActive && autoUpdatesWhenActive) || ((!isActive) && autoUpdatesWhenNotActive)) - { - effectList = &m_effectsToUpdate; - } - else - { - effectList = &m_effectsNotToUpdate; - } - - if (*effectList) - { - (*effectList)->SetPrev(effect); - effect->SetNext(*effectList); - } - (*effectList) = effect; - - effect->SetFlag(GAME_EFFECT_REGISTERED, true); - } -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: UnRegisterEffect -// Desc: UnRegisters effect from effect system -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::UnRegisterEffect(IGameEffect* effect) -{ - FX_ASSERT_MESSAGE( - m_isInitialised, - "Game Effects System trying to unregister an effect without being initialised"); - FX_ASSERT_MESSAGE(effect, "Trying to UnRegister a NULL effect"); - - if (effect && effect->IsFlagSet(GAME_EFFECT_REGISTERED)) - { - // If the effect is the next one to be updated, then point m_nextEffectToUpdate to the next - // effect after it - if (effect == m_nextEffectToUpdate) - { - m_nextEffectToUpdate = m_nextEffectToUpdate->Next(); - } - - if (effect->Prev()) - { - effect->Prev()->SetNext(effect->Next()); - } - else - { - if (m_effectsToUpdate == effect) - { - m_effectsToUpdate = effect->Next(); - } - else - { - FX_ASSERT_MESSAGE((m_effectsNotToUpdate == effect), - "Effect isn't either updating list"); - m_effectsNotToUpdate = effect->Next(); - } - } - - if (effect->Next()) - { - effect->Next()->SetPrev(effect->Prev()); - } - - effect->SetNext(NULL); - effect->SetPrev(NULL); - - effect->SetFlag(GAME_EFFECT_REGISTERED, false); - } -} //------------------------------------------------------------------------------------------------- - -void CGameEffectsSystem::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) -{ - Update(deltaTime); -} - -//-------------------------------------------------------------------------------------------------- -// Name: Update -// Desc: Updates effects system and any effects registered in it's update list -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::Update(float frameTime) -{ - FX_ASSERT_MESSAGE(m_isInitialised, - "Game Effects System trying to update without being initialised"); - - // Update effects - if (m_effectsToUpdate) - { - IGameEffect* effect = m_effectsToUpdate; - while (effect) - { - m_nextEffectToUpdate = effect->Next(); - if (effect->IsFlagSet(GAME_EFFECT_UPDATE_WHEN_PAUSED)) - { - SOFTCODE_RETRY(effect, effect->Update(frameTime)); - } - effect = m_nextEffectToUpdate; - } - } - - m_nextEffectToUpdate = NULL; - -#if DEBUG_GAME_FX_SYSTEM - DrawDebugDisplay(); -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: CreateSoftCodeInstance -// Desc: Creates soft code instance -//-------------------------------------------------------------------------------------------------- -#ifdef SOFTCODE_ENABLED -void* CGameEffectsSystem::CreateSoftCodeInstance(const char* pTypeName) -{ - void* pNewInstance = NULL; - - if (pTypeName) - { - for (std::vector::iterator iter(m_softCodeTypeLibs.begin()); - iter != m_softCodeTypeLibs.end(); ++iter) - { - ITypeLibrary* pLib = *iter; - if (pLib) - { - if (pNewInstance = pLib->CreateInstanceVoid(pTypeName)) - { - break; - } - } - } - } - - return pNewInstance; -} -#endif -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: RegisterSoftCodeLib -// Desc: Register soft code lib for creation of instances -//-------------------------------------------------------------------------------------------------- -#ifdef SOFTCODE_ENABLED -void CGameEffectsSystem::RegisterSoftCodeLib(ITypeLibrary* pLib) -{ - m_softCodeTypeLibs.push_back(pLib); -}; -#endif -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: RegisterGameRenderNode -// Desc: Registers game render node -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::RegisterGameRenderNode([[maybe_unused]] IGameRenderNodePtr& pGameRenderNode) -{ -#ifdef SOFTCODE_ENABLED - for (TGameRenderNodeVec::iterator iter(m_gameRenderNodes.begin()); - iter != m_gameRenderNodes.end(); ++iter) - { - IGameRenderNodePtr* ppIterRenderNode = *iter; - if (ppIterRenderNode == NULL) - { - *iter = &pGameRenderNode; - return; - } - } - m_gameRenderNodes.push_back(&pGameRenderNode); -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: UnregisterGameRenderNode -// Desc: Unregisters game render node -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::UnregisterGameRenderNode([[maybe_unused]] IGameRenderNodePtr& pGameRenderNode) -{ -#ifdef SOFTCODE_ENABLED - TGameRenderNodeVec::iterator iter( - std::find(m_gameRenderNodes.begin(), m_gameRenderNodes.end(), &pGameRenderNode)); - if (iter != m_gameRenderNodes.end()) - { - *iter = NULL; - } -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: RegisterGameRenderElement -// Desc: Registers game render element -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::RegisterGameRenderElement([[maybe_unused]] IGameRenderElementPtr& pGameRenderElement) -{ -#ifdef SOFTCODE_ENABLED - for (TGameRenderElementVec::iterator iter(m_gameRenderElements.begin()); - iter != m_gameRenderElements.end(); ++iter) - { - IGameRenderElementPtr* ppIterRenderElement = *iter; - if (ppIterRenderElement == NULL) - { - *iter = &pGameRenderElement; - return; - } - } - m_gameRenderElements.push_back(&pGameRenderElement); -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: UnregisterGameRenderElement -// Desc: Unregisters game render element -//-------------------------------------------------------------------------------------------------- -void CGameEffectsSystem::UnregisterGameRenderElement([[maybe_unused]] IGameRenderElementPtr& pGameRenderElement) -{ -#ifdef SOFTCODE_ENABLED - TGameRenderElementVec::iterator iter( - std::find(m_gameRenderElements.begin(), m_gameRenderElements.end(), &pGameRenderElement)); - if (iter != m_gameRenderElements.end()) - { - *iter = NULL; - } -#endif -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: DrawDebugDisplay -// Desc: Draws debug display -//-------------------------------------------------------------------------------------------------- -#if DEBUG_GAME_FX_SYSTEM -void CGameEffectsSystem::DrawDebugDisplay() -{ - static ColorF textCol(1.0f, 1.0f, 1.0f, 1.0f); - static ColorF controlCol(0.6f, 0.6f, 0.6f, 1.0f); - - static Vec2 textPos(10.0f, 10.0f); - static float textSize = 1.4f; - static float textYSpacing = 18.0f; - - static float effectNameXOffset = 100.0f; - static ColorF effectNameCol(0.0f, 1.0f, 0.0f, 1.0f); - - Vec2 currentTextPos = textPos; - - int debugEffectCount = s_effectDebugList.Size(); - if (GetISystem()->GetIConsole()->GetCVar("g_gameFXSystemDebug")->GetIVal() && debugEffectCount > 0) - { - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, &textCol.r, - false, "Debug view:"); - gEnv->pRenderer->Draw2dLabel(currentTextPos.x + effectNameXOffset, currentTextPos.y, - textSize, &effectNameCol.r, false, - GAME_FX_DEBUG_VIEW_NAMES[m_debugView]); - currentTextPos.y += textYSpacing; - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, &controlCol.r, - false, "(Change debug view: Left/Right arrows)"); - currentTextPos.y += textYSpacing; - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, &textCol.r, - false, "Debug effect:"); - gEnv->pRenderer->Draw2dLabel(currentTextPos.x + effectNameXOffset, currentTextPos.y, - textSize, &effectNameCol.r, false, - s_effectDebugList[s_currentDebugEffectId].effectName); - currentTextPos.y += textYSpacing; - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, &controlCol.r, - false, "(Change effect: NumPad +/-)"); - currentTextPos.y += textYSpacing; - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, &controlCol.r, - false, "(Reload effect data: NumPad .)"); - currentTextPos.y += textYSpacing; - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, &controlCol.r, - false, "(Reset Particle System: Delete)"); - currentTextPos.y += textYSpacing; - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, &controlCol.r, - false, "(Pause Particle System: End)"); - currentTextPos.y += textYSpacing; - - if (s_effectDebugList[s_currentDebugEffectId].displayCallback) - { - s_effectDebugList[s_currentDebugEffectId].displayCallback(currentTextPos, textSize, - textYSpacing); - } - - if (m_debugView == eGAME_FX_DEBUG_VIEW_EffectList) - { - static Vec2 listPos(350.0f, 50.0f); - static float nameSize = 150.0f; - static float tabSize = 60.0f; - currentTextPos = listPos; - - const int EFFECT_LIST_COUNT = 2; - IGameEffect* pEffectListArray[EFFECT_LIST_COUNT] = { - m_effectsToUpdate, - m_effectsNotToUpdate - }; - - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, - &effectNameCol.r, false, "Name"); - currentTextPos.x += nameSize; - - const int FLAG_COUNT = 9; - - const char* flagName[FLAG_COUNT] = { - "Init", "Rel", "ARels", "ADels", "AUWA", - "AUWnA", "Reg", "Actv", "DBG" - }; - const int flag[FLAG_COUNT] = { - GAME_EFFECT_INITIALISED, GAME_EFFECT_RELEASED, - GAME_EFFECT_AUTO_RELEASE, GAME_EFFECT_AUTO_DELETE, - GAME_EFFECT_AUTO_UPDATES_WHEN_ACTIVE, - GAME_EFFECT_AUTO_UPDATES_WHEN_NOT_ACTIVE, - GAME_EFFECT_REGISTERED, GAME_EFFECT_ACTIVE, - GAME_EFFECT_DEBUG_EFFECT - }; - - for (int i = 0; i < FLAG_COUNT; i++) - { - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, - &effectNameCol.r, false, flagName[i]); - currentTextPos.x += tabSize; - } - - currentTextPos.y += textYSpacing; - - for (int l = 0; l < EFFECT_LIST_COUNT; l++) - { - IGameEffect* pCurrentEffect = pEffectListArray[l]; - while (pCurrentEffect) - { - currentTextPos.x = listPos.x; - - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, - &textCol.r, false, pCurrentEffect->GetName()); - currentTextPos.x += nameSize; - - for (int i = 0; i < FLAG_COUNT; i++) - { - gEnv->pRenderer->Draw2dLabel(currentTextPos.x, currentTextPos.y, textSize, - &textCol.r, false, - pCurrentEffect->IsFlagSet(flag[i]) ? "1" - : "0"); - currentTextPos.x += tabSize; - } - - currentTextPos.y += textYSpacing; - pCurrentEffect = pCurrentEffect->Next(); - } - } - } - } -} -#endif -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: OnInputChannelEventFiltered -// Desc: Handles any debug input for the game effects system to test effects -//-------------------------------------------------------------------------------------------------- -bool CGameEffectsSystem::OnInputChannelEventFiltered([[maybe_unused]] const AzFramework::InputChannel& inputChannel) -{ -#if DEBUG_GAME_FX_SYSTEM - - int debugEffectCount = s_effectDebugList.Size(); - - if ((GetISystem()->GetIConsole()->GetCVar("g_gameFXSystemDebug")->GetIVal()) && (debugEffectCount > 0)) - { - if (AzFramework::InputDeviceKeyboard::IsKeyboardDevice(inputChannel.GetInputDevice().GetInputDeviceId()) && - inputChannel.IsStateBegan()) - { - const AZ::Crc32& inputChannelNameCrc32 = inputChannel.GetInputChannelId().GetNameCrc32(); - if (inputChannelNameCrc32 == GAME_FX_INPUT_IncrementDebugEffectId) - { - if (s_currentDebugEffectId < (debugEffectCount - 1)) - { - s_currentDebugEffectId++; - } - } - else if (inputChannelNameCrc32 == GAME_FX_INPUT_DecrementDebugEffectId) - { - if (s_currentDebugEffectId > 0) - { - s_currentDebugEffectId--; - } - } - else if (inputChannelNameCrc32 == GAME_FX_INPUT_DecrementDebugView) - { - if (m_debugView > 0) - { - OnDeActivateDebugView(m_debugView); - m_debugView--; - OnActivateDebugView(m_debugView); - } - } - else if (inputChannelNameCrc32 == GAME_FX_INPUT_IncrementDebugView) - { - if (m_debugView < (eMAX_GAME_FX_DEBUG_VIEWS - 1)) - { - OnDeActivateDebugView(m_debugView); - m_debugView++; - OnActivateDebugView(m_debugView); - } - } - else if (inputChannelNameCrc32 == GAME_FX_INPUT_ReloadEffectData) - { - ReloadData(); - } - - // Send input to current debug effect - if (s_effectDebugList[s_currentDebugEffectId].inputCallback) - { - s_effectDebugList[s_currentDebugEffectId].inputCallback(inputChannelNameCrc32); - } - } - } -#endif - - return false; // Return false so that other listeners will get this event -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: GetDebugEffect -// Desc: Gets debug instance of effect -//-------------------------------------------------------------------------------------------------- -#if DEBUG_GAME_FX_SYSTEM -IGameEffect* CGameEffectsSystem::GetDebugEffect(const char* pEffectName) const -{ - const int EFFECT_LIST_COUNT = 2; - IGameEffect* pEffectListArray[EFFECT_LIST_COUNT] = {m_effectsToUpdate, m_effectsNotToUpdate}; - - for (int l = 0; l < EFFECT_LIST_COUNT; l++) - { - IGameEffect* pCurrentEffect = pEffectListArray[l]; - while (pCurrentEffect) - { - if (pCurrentEffect->IsFlagSet(GAME_EFFECT_DEBUG_EFFECT) && - (strcmp(pCurrentEffect->GetName(), pEffectName) == 0)) - { - return pCurrentEffect; - } - pCurrentEffect = pCurrentEffect->Next(); - } - } - - return NULL; -} -#endif -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: OnActivateDebugView -// Desc: Called on debug view activation -//-------------------------------------------------------------------------------------------------- -#if DEBUG_GAME_FX_SYSTEM -void CGameEffectsSystem::OnActivateDebugView(int debugView) -{ - switch (debugView) - { - case eGAME_FX_DEBUG_VIEW_Profiling: - { - ICVar* r_displayInfoCVar = gEnv->pConsole->GetCVar("r_DisplayInfo"); - if (r_displayInfoCVar) - { - r_displayInfoCVar->Set(1); - } - break; - } - } -} -#endif -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: OnDeActivateDebugView -// Desc: Called on debug view de-activation -//-------------------------------------------------------------------------------------------------- -#if DEBUG_GAME_FX_SYSTEM -void CGameEffectsSystem::OnDeActivateDebugView(int debugView) -{ - switch (debugView) - { - case eGAME_FX_DEBUG_VIEW_Profiling: - { - ICVar* r_displayInfoCVar = gEnv->pConsole->GetCVar("r_DisplayInfo"); - if (r_displayInfoCVar) - { - r_displayInfoCVar->Set(0); - } - break; - } - } -} -#endif -//-------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: RegisterEffectDebugData -// Desc: Registers effect's debug data with the game effects system, which will then call the -// relevant debug callback functions for the for the effect when its selected -//using the -// s_currentDebugEffectId -//-------------------------------------------------------------------------------------------------- -#if DEBUG_GAME_FX_SYSTEM -void IGameEffectSystem::RegisterEffectDebugData(DebugOnInputEventCallback inputEventCallback, - DebugDisplayCallback displayCallback, - const char* effectName) -{ - s_effectDebugList.push_back(SEffectDebugData(inputEventCallback, displayCallback, effectName)); -} -#endif -//-------------------------------------------------------------------------------------------------- diff --git a/Gems/GameEffectSystem/Code/source/GameEffectsSystem.h b/Gems/GameEffectSystem/Code/source/GameEffectsSystem.h deleted file mode 100644 index 4dd6fe0435..0000000000 --- a/Gems/GameEffectSystem/Code/source/GameEffectsSystem.h +++ /dev/null @@ -1,137 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _EFFECTS_GAMEEFFECTSSYSTEM_H_ -#define _EFFECTS_GAMEEFFECTSSYSTEM_H_ -#pragma once - -// Includes -#include "GameEffectSystem/IGameEffectSystem.h" -#include "GameEffectSystem/GameEffectsSystemDefines.h" -#include -#include - -//================================================================================================== -// Name: CGameEffectsSystem -// Desc: System to handle game effects, game render nodes and game render elements -// Game effect: separates out effect logic from game logic -// Game render node: handles the render object in 3d space -// Game render element: handles the rendering of the object -// CVar activation system: system used to have data driven cvars activated in game -//effects -// Post effect activation system: system used to have data driven post effects -//activated in game effects -// Author: James Chilvers -//================================================================================================== -class CGameEffectsSystem - : public IGameEffectSystem - , public AzFramework::InputChannelEventListener - , public ISoftCodeListener - , public AZ::TickBus::Handler -{ - friend struct SGameEffectSystemStaticData; - -public: - void Destroy(); - void Initialize(); - void LoadData(); - void ReleaseData(); - - template - T* CreateEffect() // Use if dynamic memory allocation is required for the game effect - { // Using this function then allows easy changing of memory allocator for all dynamically - // created effects - T* newEffect = new T; - return newEffect; - } - - // Each effect automatically registers and unregisters itself - SC_API void RegisterEffect(IGameEffect* effect) override; - SC_API void UnRegisterEffect(IGameEffect* effect) override; - - void Update(float frameTime); - - SC_API void RegisterGameRenderNode(IGameRenderNodePtr& pGameRenderNode); - SC_API void UnregisterGameRenderNode(IGameRenderNodePtr& pGameRenderNode); - - SC_API void RegisterGameRenderElement(IGameRenderElementPtr& pGameRenderElement); - SC_API void UnregisterGameRenderElement(IGameRenderElementPtr& pGameRenderElement); - -#ifdef SOFTCODE_ENABLED - SC_API void* - CreateSoftCodeInstance(const char* pTypeName) override; // Create soft code instance using libs - SC_API void - RegisterSoftCodeLib(ITypeLibrary* pLib) override; // Register soft code lib for creation of instances -#endif - - bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override; - - // ISoftCodeListener implementation - void InstanceReplaced(void* pOldInstance, void* pNewInstance) override; - void GameRenderNodeInstanceReplaced(void* pOldInstance, void* pNewInstance) override; - void GameRenderElementInstanceReplaced(void* pOldInstance, void* pNewInstance) override; - - // SGameRulesListener implementation - void GameRulesInitialise(); - // #TODO: Have this receive events from GameRules - void EnteredGame();// override; - - void ReloadData(); - - CGameEffectsSystem(); - virtual ~CGameEffectsSystem(); - - // AZ::TickBus::Handler implementation - void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; - -private: - void Reset(); - void AutoReleaseAndDeleteFlaggedEffects(IGameEffect* effectList); - void AutoDeleteEffects(IGameEffect* effectList); - void SetPostEffectCVarCallbacks(); - static void PostEffectCVarCallback(ICVar* cvar); - -#if DEBUG_GAME_FX_SYSTEM - void DrawDebugDisplay(); - void OnActivateDebugView(int debugView); - void OnDeActivateDebugView(int debugView); - - int GetDebugView() const { return m_debugView; } - SC_API IGameEffect* GetDebugEffect(const char* pEffectName) const; - - static int s_currentDebugEffectId; - - int m_debugView; -#endif - - static int s_postEffectCVarNameOffset; - -#ifdef SOFTCODE_ENABLED - std::vector m_softCodeTypeLibs; - - typedef std::vector TGameRenderNodeVec; - TGameRenderNodeVec m_gameRenderNodes; - CGameRenderNodeSoftCodeListener* m_gameRenderNodeSoftCodeListener; - - typedef std::vector TGameRenderElementVec; - TGameRenderElementVec m_gameRenderElements; - CGameRenderElementSoftCodeListener* m_gameRenderElementSoftCodeListener; -#endif - - IGameEffect* m_effectsToUpdate; - IGameEffect* m_effectsNotToUpdate; - // If in update loop, this is the next effect to be updated this will get changed if the effect is unregistered - IGameEffect* m_nextEffectToUpdate; - bool m_isInitialised; - bool s_hasLoadedData; -}; //------------------------------------------------------------------------------------------------ - -#endif//_EFFECTS_GAMEEFFECTSSYSTEM_H_ diff --git a/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElement.cpp b/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElement.cpp deleted file mode 100644 index c68b8526b0..0000000000 --- a/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElement.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -//================================================================================================== -// Name: CGameRenderElement -// Desc: Base class for all game render elements -// Author: James Chilvers -//================================================================================================== - -// Includes -#include "GameEffectSystem_precompiled.h" -#include "GameRenderElement.h" - -//-------------------------------------------------------------------------------------------------- -// Name: CGameRenderElement -// Desc: Constructor -//-------------------------------------------------------------------------------------------------- -CGameRenderElement::CGameRenderElement() -{ - m_pREGameEffect = NULL; -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: InitialiseGameRenderElement -// Desc: Initialises game render element -//-------------------------------------------------------------------------------------------------- -bool CGameRenderElement::InitialiseGameRenderElement() -{ - m_pREGameEffect = (CREGameEffect*)gEnv->pRenderer->EF_CreateRE(eDATA_GameEffect); - if (m_pREGameEffect) - { - m_pREGameEffect->SetPrivateImplementation(this); - m_pREGameEffect->mfUpdateFlags(FCEF_TRANSFORM); - } - - return true; -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: ReleaseGameRenderElement -// Desc: Releases game render element -//-------------------------------------------------------------------------------------------------- -void CGameRenderElement::ReleaseGameRenderElement() -{ - if (m_pREGameEffect) - { - m_pREGameEffect->SetPrivateImplementation(NULL); - m_pREGameEffect->Release(false); - } -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: UpdatePrivateImplementation -// Desc: Updates private implementation -//-------------------------------------------------------------------------------------------------- -void CGameRenderElement::UpdatePrivateImplementation() -{ - if (m_pREGameEffect) - { - m_pREGameEffect->SetPrivateImplementation(this); - } -} //------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: GetCREGameEffect -// Desc: returns the game effect render element -//-------------------------------------------------------------------------------------------------- -CREGameEffect* CGameRenderElement::GetCREGameEffect() -{ - return m_pREGameEffect; -} //------------------------------------------------------------------------------------------------- diff --git a/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElement.h b/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElement.h deleted file mode 100644 index 37d149cdde..0000000000 --- a/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElement.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef _EFFECTS_RENDERELEMENTS_GAMERENDERELEMENT_H_ -#define _EFFECTS_RENDERELEMENTS_GAMERENDERELEMENT_H_ -#pragma once - -// Includes -#include "GameEffectsSystem.h" -#include - -// Forward declares -struct IGameRenderElementParams; - -//================================================================================================== -// Name: IGameRenderElement -// Desc: Base interface for all game render elements -// Author: James Chilvers -//================================================================================================== -struct IGameRenderElement - : public IREGameEffect - , public _i_reference_target_t -{ - DECLARE_TYPELIB(IGameRenderElement); // Allow soft coding on this interface - - virtual ~IGameRenderElement() {} - - virtual bool InitialiseGameRenderElement() = 0; - virtual void ReleaseGameRenderElement() = 0; - virtual void UpdatePrivateImplementation() = 0; - - virtual CREGameEffect* GetCREGameEffect() = 0; - - virtual IGameRenderElementParams* GetParams() = 0; -}; //------------------------------------------------------------------------------------------------ - -//================================================================================================== -// Name: CGameRenderElement -// Desc: Base class for all game render elements -// Author: James Chilvers -//================================================================================================== -class CGameRenderElement - : public IGameRenderElement -{ - DECLARE_TYPE(CGameRenderElement, IGameRenderElement); // Exposes this type for SoftCoding -public: - CGameRenderElement(); - virtual ~CGameRenderElement() {} - - virtual bool InitialiseGameRenderElement(); - virtual void ReleaseGameRenderElement(); - virtual void UpdatePrivateImplementation(); - - virtual CREGameEffect* GetCREGameEffect(); - -protected: - CREGameEffect* SOFT(m_pREGameEffect); -}; //------------------------------------------------------------------------------------------------ - -//================================================================================================== -// Name: IGameRenderElementParams -// Desc: Game Render Element params -// Author: James Chilvers -//================================================================================================== -struct IGameRenderElementParams -{ - virtual ~IGameRenderElementParams() {} -}; //------------------------------------------------------------------------------------------------ - -#endif//_EFFECTS_RENDERELEMENTS_GAMERENDERELEMENT_H_ diff --git a/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElementSoftCodeLibrary.cpp b/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElementSoftCodeLibrary.cpp deleted file mode 100644 index 76bb0eb325..0000000000 --- a/Gems/GameEffectSystem/Code/source/RenderElements/GameRenderElementSoftCodeLibrary.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -//================================================================================================== -// Name: GameRenderElementSoftCodeLibrary -// Desc: Render Node Soft Code Library -// Author: James Chilvers -//================================================================================================== - -// Includes -#include "GameEffectSystem_precompiled.h" -#include -#include "RenderElements/GameRenderElement.h" - -IMPLEMENT_TYPELIB(IGameRenderElement, - GAME_RENDER_ELEMENT_LIBRARY_NAME); // Implementation of Soft Coding library diff --git a/Gems/GameEffectSystem/Code/source/RenderNodes/GameRenderNodeSoftCodeLibrary.cpp b/Gems/GameEffectSystem/Code/source/RenderNodes/GameRenderNodeSoftCodeLibrary.cpp deleted file mode 100644 index a46e964016..0000000000 --- a/Gems/GameEffectSystem/Code/source/RenderNodes/GameRenderNodeSoftCodeLibrary.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -//================================================================================================== -// Name: GameRenderNodeSoftCodeLibrary -// Desc: Render Node Soft Code Library -// Author: James Chilvers -//================================================================================================== - -// Includes -#include "GameEffectSystem_precompiled.h" -#include -#include -#include - -IMPLEMENT_TYPELIB(IGameRenderNode, GAME_RENDER_NODE_LIBRARY_NAME); // Implementation of Soft Coding library diff --git a/Gems/GameEffectSystem/Code/source/RenderNodes/IGameRenderNode.h b/Gems/GameEffectSystem/Code/source/RenderNodes/IGameRenderNode.h deleted file mode 100644 index 7a88db116d..0000000000 --- a/Gems/GameEffectSystem/Code/source/RenderNodes/IGameRenderNode.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef CRYINCLUDE_GAMEDLL_EFFECTS_RENDERNODES_IGAMERENDERNODE_H -#define CRYINCLUDE_GAMEDLL_EFFECTS_RENDERNODES_IGAMERENDERNODE_H -#pragma once - -#include "Effects/RenderElements/GameRenderElement.h" -#include "Effects/GameEffectsSystem.h" - -// Forward declares -struct IGameRenderNodeParams; - -//================================================================================================== -// Name: IGameRenderNode -// Desc: Base interface for all game render nodes -// Author: James Chilvers -//================================================================================================== -struct IGameRenderNode - : public IRenderNode - , public _i_reference_target_t -{ - DECLARE_TYPELIB(IGameRenderNode); // Allow soft coding on this interface - - virtual ~IGameRenderNode() {} - - virtual bool InitialiseGameRenderNode() = 0; - virtual void ReleaseGameRenderNode() = 0; - - virtual void SetParams(const IGameRenderNodeParams* pParams = NULL) = 0; -}; //------------------------------------------------------------------------------------------------ - -//================================================================================================== -// Name: IGameRenderNodeParams -// Desc: Game render node params -// Author: James Chilvers -//================================================================================================== -struct IGameRenderNodeParams -{ - virtual ~IGameRenderNodeParams() {} -}; //------------------------------------------------------------------------------------------------ - -#endif // CRYINCLUDE_GAMEDLL_EFFECTS_RENDERNODES_IGAMERENDERNODE_H diff --git a/Gems/GameEffectSystem/gem.json b/Gems/GameEffectSystem/gem.json deleted file mode 100644 index ad97bc61ea..0000000000 --- a/Gems/GameEffectSystem/gem.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "gem_name": "GameEffectSystem", - "GemFormatVersion": 3, - "LinkType": "DynamicStatic", - "Name": "GameEffectSystem", - "DisplayName": "Game Effect System", - "Summary": "Provides fundamentals for creating and managing visual effects.", - "Tags": ["Effects System"], - "Uuid": "d378b5a7b47747d0a7aa741945df58f3", - "Version": "1.0.0", - "IconPath": "preview.png" -} diff --git a/Gems/GameStateSamples/Code/Include/GameStateSamples/GameStateLevelRunning.inl b/Gems/GameStateSamples/Code/Include/GameStateSamples/GameStateLevelRunning.inl index 174a5b43c4..335291d57e 100644 --- a/Gems/GameStateSamples/Code/Include/GameStateSamples/GameStateLevelRunning.inl +++ b/Gems/GameStateSamples/Code/Include/GameStateSamples/GameStateLevelRunning.inl @@ -27,7 +27,6 @@ #include #include -#include #include #include @@ -59,10 +58,6 @@ namespace GameStateSamples { // Unload the currently loaded level levelSystem->UnloadLevel(); - if (iSystem->GetI3DEngine()) - { - iSystem->GetI3DEngine()->LoadEmptyLevel(); - } } } diff --git a/Gems/Gestures/Code/Source/Gestures_precompiled.h b/Gems/Gestures/Code/Source/Gestures_precompiled.h index c51e121abc..926c68d091 100644 --- a/Gems/Gestures/Code/Source/Gestures_precompiled.h +++ b/Gems/Gestures/Code/Source/Gestures_precompiled.h @@ -13,5 +13,4 @@ #pragma once #include -#include #include diff --git a/Gems/GradientSignal/Code/CMakeLists.txt b/Gems/GradientSignal/Code/CMakeLists.txt index 362ef61185..7b8c9813e6 100644 --- a/Gems/GradientSignal/Code/CMakeLists.txt +++ b/Gems/GradientSignal/Code/CMakeLists.txt @@ -24,7 +24,6 @@ ly_add_target( Legacy::CryCommon Gem::LmbrCentral Gem::SurfaceData - Gem::ImageProcessing.Headers Gem::ImageProcessingAtom.Headers ) @@ -42,7 +41,6 @@ ly_add_target( PRIVATE Gem::GradientSignal.Static PUBLIC - Gem::ImageProcessing.Headers # ImageProcessing/PixelFormats.h is part of a header in Includes Gem::ImageProcessingAtom.Headers # Atom/ImageProcessing/PixelFormats.h is part of a header in Includes RUNTIME_DEPENDENCIES Gem::LmbrCentral diff --git a/Gems/GradientSignal/Code/Include/GradientSignal/ImageAsset.h b/Gems/GradientSignal/Code/Include/GradientSignal/ImageAsset.h index 20db212da1..3114b4e811 100644 --- a/Gems/GradientSignal/Code/Include/GradientSignal/ImageAsset.h +++ b/Gems/GradientSignal/Code/Include/GradientSignal/ImageAsset.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace AZ { @@ -42,7 +42,7 @@ namespace GradientSignal AZ::u32 m_imageWidth = 0; AZ::u32 m_imageHeight = 0; AZ::u8 m_bytesPerPixel = 0; - ImageProcessing::EPixelFormat m_imageFormat = ImageProcessing::EPixelFormat::ePixelFormat_Unknown; + ImageProcessingAtom::EPixelFormat m_imageFormat = ImageProcessingAtom::EPixelFormat::ePixelFormat_Unknown; AZStd::vector m_imageData; }; diff --git a/Gems/GradientSignal/Code/Source/Editor/EditorImageBuilderComponent.cpp b/Gems/GradientSignal/Code/Source/Editor/EditorImageBuilderComponent.cpp index bd1fbfb464..ceaf2268e1 100644 --- a/Gems/GradientSignal/Code/Source/Editor/EditorImageBuilderComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Editor/EditorImageBuilderComponent.cpp @@ -24,13 +24,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include @@ -258,47 +255,6 @@ namespace GradientSignal return AZ::Uuid::CreateString("{7520DF20-16CA-4CF6-A6DB-D96759A09EE4}"); } - static AZStd::unique_ptr LegacyLoadImageFromPath(const AZStd::string& fullPath) - { - ImageProcessing::IImageObjectPtr imageObject; - ImageProcessing::ImageProcessingRequestBus::BroadcastResult(imageObject, &ImageProcessing::ImageProcessingRequests::LoadImage, - fullPath); - - if (!imageObject) - { - return {}; - } - - //create a new image asset - auto imageAsset = AZStd::make_unique(); - - if (!imageAsset) - { - return {}; - } - - imageAsset->m_imageWidth = imageObject->GetWidth(0); - imageAsset->m_imageHeight = imageObject->GetHeight(0); - imageAsset->m_imageFormat = imageObject->GetPixelFormat(); - - AZ::u8* mem = nullptr; - AZ::u32 pitch = 0; - AZ::u32 mipBufferSize = imageObject->GetMipBufSize(0); - imageObject->GetImagePointer(0, mem, pitch); - - imageAsset->m_imageData = { mem, mem + mipBufferSize }; - - return imageAsset; - } - - static ImageProcessing::EPixelFormat AtomPixelFormatToLegacyPixelFormat(ImageProcessingAtom::EPixelFormat atomPixFormat) - { - // This could be dangerous to do if these enums have differences in the middle. - // So far the enumerations correspond 1-to-1. Worst case this could be changed into a massive switch block. - int pixelFormatInt = static_cast(atomPixFormat); - return static_cast(pixelFormatInt); - } - static AZStd::unique_ptr AtomLoadImageFromPath(const AZStd::string& fullPath) { ImageProcessingAtom::IImageObjectPtr imageObject; @@ -320,7 +276,7 @@ namespace GradientSignal imageAsset->m_imageWidth = imageObject->GetWidth(0); imageAsset->m_imageHeight = imageObject->GetHeight(0); - imageAsset->m_imageFormat = AtomPixelFormatToLegacyPixelFormat(imageObject->GetPixelFormat()); + imageAsset->m_imageFormat = imageObject->GetPixelFormat(); AZ::u8* mem = nullptr; AZ::u32 pitch = 0; @@ -334,14 +290,7 @@ namespace GradientSignal AZStd::unique_ptr EditorImageBuilderWorker::LoadImageFromPath(const AZStd::string& fullPath) { - if (AZ::Interface::Get()) - { - return AtomLoadImageFromPath(fullPath); - } - else - { - return LegacyLoadImageFromPath(fullPath); - } + return AtomLoadImageFromPath(fullPath); } AZStd::unique_ptr EditorImageBuilderWorker::LoadImageSettingsFromPath(const AZStd::string& fullPath) diff --git a/Gems/GradientSignal/Code/Source/GradientImageConversion.cpp b/Gems/GradientSignal/Code/Source/GradientImageConversion.cpp index cfbb71936b..4ed9107c47 100644 --- a/Gems/GradientSignal/Code/Source/GradientImageConversion.cpp +++ b/Gems/GradientSignal/Code/Source/GradientImageConversion.cpp @@ -13,7 +13,7 @@ #include "GradientSignal_precompiled.h" #include -#include +#include namespace { @@ -25,10 +25,10 @@ namespace constexpr auto A = 3; } - ImageProcessing::EPixelFormat ExportFormatToPixelFormat(GradientSignal::ExportFormat format) + ImageProcessingAtom::EPixelFormat ExportFormatToPixelFormat(GradientSignal::ExportFormat format) { using namespace GradientSignal; - using namespace ImageProcessing; + using namespace ImageProcessingAtom; switch (format) { @@ -49,29 +49,29 @@ namespace } } - template + template struct Underlying {}; template <> - struct Underlying + struct Underlying { using type = AZ::u8; }; template <> - struct Underlying + struct Underlying { using type = AZ::u16; }; template <> - struct Underlying + struct Underlying { using type = AZ::u32; }; template <> - struct Underlying + struct Underlying { using type = float; }; @@ -167,10 +167,10 @@ namespace buffer = AZStd::move(newBuffer); } - template - void ConvertBufferType(AZStd::vector& buffer, ImageProcessing::EPixelFormat newFormat, bool autoScale, AZStd::pair userRange) + template + void ConvertBufferType(AZStd::vector& buffer, ImageProcessingAtom::EPixelFormat newFormat, bool autoScale, AZStd::pair userRange) { - using namespace ImageProcessing; + using namespace ImageProcessingAtom; switch (newFormat) { @@ -195,9 +195,9 @@ namespace } } - ImageProcessing::EPixelFormat ConvertBufferType(AZStd::vector& buffer, ImageProcessing::EPixelFormat old, ImageProcessing::EPixelFormat newFormat, bool autoScale, AZStd::pair userRange) + ImageProcessingAtom::EPixelFormat ConvertBufferType(AZStd::vector& buffer, ImageProcessingAtom::EPixelFormat old, ImageProcessingAtom::EPixelFormat newFormat, bool autoScale, AZStd::pair userRange) { - using namespace ImageProcessing; + using namespace ImageProcessingAtom; switch (old) { @@ -356,9 +356,9 @@ namespace mem.resize(mem.size() / channels); } - AZStd::size_t GetChannels(ImageProcessing::EPixelFormat format) + AZStd::size_t GetChannels(ImageProcessingAtom::EPixelFormat format) { - using namespace ImageProcessing; + using namespace ImageProcessingAtom; switch (format) { @@ -379,10 +379,10 @@ namespace } template