Merge branch 'main' into physx_fix_tests

This commit is contained in:
amzn-sean
2021-05-05 12:40:09 +01:00
134 changed files with 1854 additions and 1248 deletions
-1
View File
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Game" UpAxis="Y" MeshPrediction="1" UseBFrames="1" IndexFrameDistance="10" BlockCompressionFormat="deflate" PlaybackFromMemory="0" PositionPrecision="1" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Game (fast decode)" UpAxis="Y" MeshPrediction="1" UseBFrames="1" IndexFrameDistance="10" BlockCompressionFormat="lz4hc" PlaybackFromMemory="0" PositionPrecision="1" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Game (Z-up)" UpAxis="Z" MeshPrediction="1" UseBFrames="1" IndexFrameDistance="10" BlockCompressionFormat="deflate" PlaybackFromMemory="0" PositionPrecision="1" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Game (fast decode, Z-up)" UpAxis="Z" MeshPrediction="1" UseBFrames="1" IndexFrameDistance="10" BlockCompressionFormat="lz4hc" PlaybackFromMemory="0" PositionPrecision="1" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Prerendered" UpAxis="Y" MeshPrediction="1" UseBFrames="1" IndexFrameDistance="10" BlockCompressionFormat="deflate" PlaybackFromMemory="0" PositionPrecision="0" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Prerendered (Z-up)" UpAxis="Z" MeshPrediction="1" UseBFrames="1" IndexFrameDistance="10" BlockCompressionFormat="deflate" PlaybackFromMemory="0" PositionPrecision="0" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Rigids Only" UpAxis="Y" MeshPrediction="0" UseBFrames="0" IndexFrameDistance="10" BlockCompressionFormat="deflate" PlaybackFromMemory="1" PositionPrecision="0" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Rigids Only (Z-up)" UpAxis="Z" MeshPrediction="0" UseBFrames="0" IndexFrameDistance="10" BlockCompressionFormat="deflate" PlaybackFromMemory="1" PositionPrecision="0" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Uncompressed (fastest compile)" UpAxis="Y" MeshPrediction="0" UseBFrames="0" IndexFrameDistance="10" BlockCompressionFormat="store" PlaybackFromMemory="0" PositionPrecision="0" UVmax="0"/>
@@ -1 +0,0 @@
<CacheBuildConfiguration Name="Uncompressed (fastest compile, Z-up)" UpAxis="Z" MeshPrediction="0" UseBFrames="0" IndexFrameDistance="10" BlockCompressionFormat="store" PlaybackFromMemory="0" PositionPrecision="0" UVmax="0"/>
@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9c36d7bc993ddf616f478115a123efabda5b4b833a4e6524312f43c228ae0902
size 487003
@@ -1 +0,0 @@
<CacheBuildConfiguration UpAxis="Y" MeshPrediction="1" UseBFrames="1" IndexFrameDistance="15" BlockCompressionFormat="deflate" PlaybackFromMemory="1"/>
@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:96a21446422b834ea90a5d38eaaca309fdee31dc3cc03c0e9c094b39ec3a459d
size 4715164
@@ -1,17 +0,0 @@
<Material MtlFlags="524544" vertModifType="0">
<SubMaterials>
<Material Name="mat01_white" MtlFlags="524416" Shader="Illum" GenMask="12000020040003" StringGenMask="%ALLOW_SILHOUETTE_POM%ALLOW_SPECULAR_ANTIALIASING%EMITTANCE_MAP%NORMAL_MAP%SPECULAR_MAP%SUBSURFACE_SCATTERING" SurfaceType="mat_default" Diffuse="1,1,1,1" Specular="0.5,0.5,0.5,1" Opacity="1" Shininess="174.72" vertModifType="0" LayerAct="1">
<Textures>
<Texture Map="Diffuse" File="engineassets/textures/white.dds"/>
</Textures>
<PublicParams EmittanceMapGamma="1" SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
<Material Name="mat02_grey" MtlFlags="524416" Shader="Illum" GenMask="10000000000003" StringGenMask="%ALLOW_SILHOUETTE_POM%ALLOW_SPECULAR_ANTIALIASING%SUBSURFACE_SCATTERING" SurfaceType="mat_default" Diffuse="0.5,0.5,0.5,1" Specular="0.5,0.5,0.5,1" Opacity="1" Shininess="10" vertModifType="0" LayerAct="1">
<Textures>
<Texture Map="Diffuse" File="engineassets/textures/white.dds"/>
</Textures>
<PublicParams EmittanceMapGamma="1" SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
</SubMaterials>
<PublicParams EmittanceMapGamma="1" SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
@@ -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)
@@ -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', '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)
@@ -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
@@ -305,11 +269,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 +279,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
@@ -374,18 +328,6 @@ class TestAutomation(TestAutomationBase):
from . import C4044461_Material_Restitution as test_module
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')
def test_C14902097_ScriptCanvas_PreUpdateEvent(self, request, workspace, editor, launcher_platform):
@@ -415,11 +357,6 @@ 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
@@ -441,21 +378,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 +398,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 +445,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)
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
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)
@@ -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)
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or 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)
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:231d5ac32c95334eeb1cbf77ea0bceae1d8010de3290dfdbd991abb46d18bae6
size 6844
oid sha256:83af66a6db4ff2b4df7212099b661a96668cfb326d8984e41b16506ec0062141
size 5844
@@ -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 <Atom/Features/SrgSemantics.azsli>
partial ShaderResourceGroup RayTracingSceneSrg : SRG_RayTracingScene
{
/* Intentionally Empty. Helps define the SrgSemantic for RayTracingSceneSrg once.*/
};
#define AZ_COLLECTING_PARTIAL_SRGS
#include <Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrgAll.azsli>
#undef AZ_COLLECTING_PARTIAL_SRGS
-26
View File
@@ -31,7 +31,6 @@
#include <AzCore/Interface/Interface.h>
#include <AzFramework/Logging/MissingAssetLogger.h>
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Interface/Interface.h>
@@ -1162,31 +1161,6 @@ void CSystem::SleepIfInactive()
{
return;
}
#if defined(WIN32)
if (!AZ::Interface<AzFramework::AtomActiveInterface>::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
}
//////////////////////////////////////////////////////////////////////////
-16
View File
@@ -68,7 +68,6 @@
#include <LyShine/Bus/UiSystemBus.h>
#include <AzFramework/Logging/MissingAssetLogger.h>
#include <AzFramework/Platform/PlatformDefaults.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/Utils/Utils.h>
@@ -2462,21 +2461,6 @@ AZ_POP_DISABLE_WARNING
m_env.pRenderer->SetViewport(0, 0, screenWidth, screenHeight);
// Skip splash screen rendering
if (!AZ::Interface<AzFramework::AtomActiveInterface>::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);
+38 -13
View File
@@ -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;
Matrix3x3 operator-() const;
Matrix3x3& operator*=(const Matrix3x3& rhs);
//! Operator for matrix-matrix addition.
//! @{
[[nodiscard]] Matrix3x3 operator+(const Matrix3x3& rhs) const;
Matrix3x3& operator+=(const Matrix3x3& rhs);
//! @}
//! 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);
//! @}
//! 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 <AzCore/Math/Matrix3x3.inl>
+84 -57
View File
@@ -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,51 +408,12 @@ 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()));
}
AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator-(const Matrix3x3& rhs) const
{
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 multiplier) 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));
}
AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator/(float divisor) const
{
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));
}
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 Matrix3x3& Matrix3x3::operator*=(const Matrix3x3& rhs)
{
*this = *this * rhs;
return *this;
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())
);
}
@@ -471,6 +424,17 @@ namespace AZ
}
AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator-(const Matrix3x3& rhs) const
{
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-=(const Matrix3x3& rhs)
{
*this = *this - rhs;
@@ -478,6 +442,33 @@ 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::operator*=(const Matrix3x3& rhs)
{
*this = *this * rhs;
return *this;
}
AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator*(float multiplier) 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)
);
}
AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator*=(float multiplier)
{
*this = *this * multiplier;
@@ -485,6 +476,18 @@ namespace AZ
}
AZ_MATH_INLINE Matrix3x3 Matrix3x3::operator/(float divisor) const
{
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)
);
}
AZ_MATH_INLINE Matrix3x3& Matrix3x3::operator/=(float divisor)
{
*this = *this / divisor;
@@ -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
+30 -11
View File
@@ -225,23 +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 multiplication.
[[nodiscard]] Matrix3x4 operator*(const Matrix3x4& rhs) const;
//! Compound assignment operator for matrix-matrix multiplication.
Matrix3x4& operator*=(const Matrix3x4& rhs);
//! Operator for matrix-matrix addition.
//! @{
[[nodiscard]] Matrix3x4 operator+(const Matrix3x4& rhs) const;
//! Compound assignment operator for matrix-matrix addition.
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;
Matrix3x4& operator*=(const Matrix3x4& rhs);
//! @}
//! Operator for multiplying all matrix's elements with a scalar
[[nodiscard]] Matrix3x4 operator*(float scalar) const;
//! @{
[[nodiscard]] Matrix3x4 operator*(float multiplier) const;
Matrix3x4& operator*=(float multiplier);
//! @}
//! Compound assignment operator for multiplying all matrix's elements with a scalar
Matrix3x4& operator*=(float scalar);
//! 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;
@@ -353,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 <AzCore/Math/Matrix3x4.inl>
+77 -22
View File
@@ -472,21 +472,6 @@ namespace AZ
}
AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator*(const Matrix3x4& rhs) const
{
Matrix3x4 result;
Simd::Vec4::Mat3x4Multiply(GetSimdValues(), rhs.GetSimdValues(), result.GetSimdValues());
return result;
}
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
@@ -505,25 +490,89 @@ namespace AZ
}
AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator*(float scalar) const
AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator-(const Matrix3x4& rhs) const
{
const Vector4 vector4Scalar(scalar);
return Matrix3x4
(
Simd::Vec4::Mul(m_rows[0].GetSimdValue(), vector4Scalar.GetSimdValue()),
Simd::Vec4::Mul(m_rows[1].GetSimdValue(), vector4Scalar.GetSimdValue()),
Simd::Vec4::Mul(m_rows[2].GetSimdValue(), vector4Scalar.GetSimdValue())
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*=(float scalar)
AZ_MATH_INLINE Matrix3x4& Matrix3x4::operator-=(const Matrix3x4& rhs)
{
*this = *this * scalar;
*this = *this - rhs;
return *this;
}
AZ_MATH_INLINE Matrix3x4 Matrix3x4::operator*(const Matrix3x4& rhs) const
{
Matrix3x4 result;
Simd::Vec4::Mat3x4Multiply(GetSimdValues(), rhs.GetSimdValues(), result.GetSimdValues());
return result;
}
AZ_MATH_INLINE Matrix3x4& Matrix3x4::operator*=(const Matrix3x4& rhs)
{
*this = *this * rhs;
return *this;
}
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
@@ -711,4 +760,10 @@ namespace AZ
{
return reinterpret_cast<Simd::Vec4::FloatType*>(m_rows);
}
AZ_MATH_INLINE Matrix3x4 operator*(float lhs, const Matrix3x4& rhs)
{
return rhs * lhs;
}
} // namespace AZ
+39 -5
View File
@@ -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 <AzCore/Math/Matrix4x4.inl>
+92 -15
View File
@@ -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
@@ -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<AZStd::string>().c_str(), typeId.ToString<AZStd::string>().c_str());
void** objectPtr = reinterpret_cast<void**>(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<AZStd::string>().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<AZStd::string>().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);
@@ -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:
@@ -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.");
}
@@ -14,6 +14,7 @@
#include <AzCore/Math/Transform.h>
#include <AzCore/Math/Quaternion.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AZTestShared/Math/MathTestHelpers.h>
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)
@@ -467,53 +467,136 @@ namespace UnitTest
EXPECT_THAT(matrix.Multiply3x3(axisDirection), IsClose(forwardDirection));
}
TEST(MATH_Matrix3x4, MultiplyByMatrix3x4)
TEST(MATH_Matrix3x4, TestMatrixMultiplication)
{
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));
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, AddMatrix3x4)
TEST(MATH_Matrix3x4, TestSum)
{
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;
EXPECT_THAT(matrix1 + (matrix2 + matrix3), IsClose((matrix1 + matrix2) + matrix3));
EXPECT_THAT(matrix2 + AZ::Matrix3x4::CreateZero(), IsClose(matrix2));
EXPECT_THAT(matrix3 + AZ::Matrix3x4::CreateZero(), IsClose(AZ::Matrix3x4::CreateZero() + matrix3));
EXPECT_THAT(matrix3 + matrix3, IsClose(matrix3 * 2.0f));
EXPECT_THAT(matrix5, IsClose(matrix1 + matrix4));
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, MultiplyByScalar)
TEST(MATH_Matrix3x4, TestDifference)
{
const AZ::Vector4 row0(1.488f, 2.56f, 0.096f, 2.3f);
const AZ::Vector4 row1(0.384f, -1.92f, 0.428f, -1.6f);
const AZ::Vector4 row2(1.28f, -2.4f, -0.24f, 3.7f);
const float scalar = 3.2f;
const AZ::Vector4 row0Result = row0 * scalar;
const AZ::Vector4 row1Result = row1 * scalar;
const AZ::Vector4 row2Result = row2 * scalar;
AZ::Matrix3x4 matrix = AZ::Matrix3x4::CreateFromRows(row0, row1, row2);
EXPECT_THAT(matrix * 0.0f, IsClose(AZ::Matrix3x4::CreateZero()));
EXPECT_THAT(matrix * 1.0f, IsClose(matrix));
EXPECT_THAT(matrix * scalar, IsClose(AZ::Matrix3x4::CreateFromRows(row0Result, row1Result, row2Result)));
EXPECT_THAT(matrix * 2.0f, IsClose(matrix + matrix));
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)
@@ -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));
}
}
@@ -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<int>(), 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<int>(), 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<int*>(azmalloc(sizeof(int), alignof(int), AZ::SystemAllocator));
ResultCode result = ContinueLoading(&ptrValue, azrtti_typeid<int>(), 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<int>(), *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<int>(), *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<int>(), *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<int>(), *m_jsonSerializationContext, Flags::ResolvePointer);
EXPECT_EQ(Processing::Completed, result.GetProcessing());
Expect_DocStrEq("null");
}
TEST_F(BaseJsonSerializerTests, ContinueStoring_ReplaceDefault_ValueStoredCorrectly)
{
using namespace AZ::JsonSerializationResult;
@@ -32,11 +32,6 @@ namespace JsonSerializationTests
return AZStd::make_shared<AZ::JsonSmartPointerSerializer>();
}
AZStd::shared_ptr<SmartPointer> CreateDefaultInstance() override
{
return AZStd::make_shared<SmartPointer>();
}
void Reflect(AZStd::unique_ptr<AZ::SerializeContext>& context) override
{
context->RegisterGenericType<SmartPointer>();
@@ -51,6 +46,13 @@ namespace JsonSerializationTests
using SmartPointer = T<SimpleClass>;
using Base = SmartPointerBaseTestDescription<SmartPointer>;
AZStd::shared_ptr<SmartPointer> CreateDefaultInstance() override
{
auto result = AZStd::make_shared<SmartPointer>();
*result = SmartPointer(aznew SimpleClass());
return result;
}
AZStd::shared_ptr<SmartPointer> CreateFullySetInstance() override
{
auto result = AZStd::make_shared<SmartPointer>();
@@ -106,21 +108,6 @@ namespace JsonSerializationTests
}
};
template<template<typename...> class T>
class SmartPointerSimpleClassWithInstanceTestDescription :
public SmartPointerSimpleClassTestDescription<T>
{
public:
using SmartPointer = typename SmartPointerSimpleClassTestDescription<T>::SmartPointer;
AZStd::shared_ptr<SmartPointer> CreateDefaultInstance() override
{
auto result = AZStd::make_shared<SmartPointer>();
*result = SmartPointer(aznew SimpleClass());
return result;
}
};
template<template<typename...> class T>
class SmartPointerSimpleDerivedClassTestDescription :
public SmartPointerBaseTestDescription<T<BaseClass>>
@@ -129,6 +116,13 @@ namespace JsonSerializationTests
using SmartPointer = T<BaseClass>;
using Base = SmartPointerBaseTestDescription<SmartPointer>;
AZStd::shared_ptr<SmartPointer> CreateDefaultInstance() override
{
auto result = AZStd::make_shared<SmartPointer>();
*result = SmartPointer(aznew BaseClass());
return result;
}
AZStd::shared_ptr<SmartPointer> CreateFullySetInstance() override
{
auto* instance = aznew SimpleInheritence();
@@ -272,6 +266,13 @@ namespace JsonSerializationTests
using SmartPointer = T<BaseClass2>;
using Base = SmartPointerBaseTestDescription<SmartPointer>;
AZStd::shared_ptr<SmartPointer> CreateDefaultInstance() override
{
auto result = AZStd::make_shared<SmartPointer>();
*result = SmartPointer(aznew BaseClass2());
return result;
}
AZStd::shared_ptr<SmartPointer> CreateFullySetInstance() override
{
auto* instance = aznew MultipleInheritence();
@@ -424,9 +425,6 @@ namespace JsonSerializationTests
SmartPointerSimpleClassTestDescription<AZStd::unique_ptr>,
SmartPointerSimpleClassTestDescription<AZStd::shared_ptr>,
SmartPointerSimpleClassTestDescription<AZStd::intrusive_ptr>,
SmartPointerSimpleClassWithInstanceTestDescription<AZStd::unique_ptr>,
SmartPointerSimpleClassWithInstanceTestDescription<AZStd::shared_ptr>,
SmartPointerSimpleClassWithInstanceTestDescription<AZStd::intrusive_ptr>,
// Simple derived class, include single inheritance.
SmartPointerSimpleDerivedClassTestDescription<AZStd::unique_ptr>,
SmartPointerSimpleDerivedClassTestDescription<AZStd::shared_ptr>,
@@ -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<SmartPointer> compare = m_description.CreateDefaultInstance();
m_jsonDocument->SetObject();
JSR::ResultCode result =
m_serializer.Load(&instance, azrtti_typeid<SmartPointer>(), *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<SmartPointer> instance = m_description.CreateFullySetInstance();
AZStd::shared_ptr<SmartPointer> compare = m_description.CreateFullySetInstance();
m_jsonDocument->SetObject();
JSR::ResultCode result =
m_serializer.Load(instance.get(), azrtti_typeid<SmartPointer>(), *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<SmartPointer> 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<SmartPointer>(), *m_jsonSerializationContext);
EXPECT_EQ(JSR::Outcomes::Success, result.GetOutcome());
}
TEST_F(JsonSmartPointerSerializerTests, Store_ValuePointerIsNullPtr_ReturnsSuccessAndStoresNull)
{
namespace JSR = AZ::JsonSerializationResult;
SmartPointer instance;
AZStd::shared_ptr<SmartPointer> defaultInstance = m_description.CreateFullySetInstance();
JSR::ResultCode result = m_serializer.Store(
*m_jsonDocument, &instance, defaultInstance.get(), azrtti_typeid<SmartPointer>(), *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<SmartPointer>(), *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<SmartPointer> instance = m_description.CreateDefaultInstance();
AZStd::shared_ptr<SmartPointer> defaultInstance = m_description.CreateDefaultInstance();
JSR::ResultCode result =
m_serializer.Store(*m_jsonDocument, instance.get(), defaultInstance.get(), azrtti_typeid<SmartPointer>(), *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<SmartPointer> instance = m_description.CreateDefaultInstance();
SmartPointer defaultInstance;
JSR::ResultCode result = m_serializer.Store(
*m_jsonDocument, instance.get(), &defaultInstance, azrtti_typeid<SmartPointer>(), *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;
@@ -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.
*
*/
#pragma once
#include <AzCore/RTTI/RTTI.h>
namespace AzFramework
{
class AtomActiveInterface
{
public:
AZ_RTTI(AtomActiveInterface, "{4BB59C86-0848-485D-AB28-700540470B2B}");
AtomActiveInterface() = default;
virtual ~AtomActiveInterface() = default;
};
} // namespace AzFramework
@@ -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
@@ -38,8 +38,9 @@ namespace AzManipulatorTestFramework
void SetGridSize(float size) override;
void SetAngularStep(float step) override;
int GetViewportId() const override;
AZStd::optional<AZ::Vector3> ViewportScreenToWorld(const QPoint& screenPosition, float depth) override;
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportScreenToWorldRay(const QPoint& screenPosition) override;
AZStd::optional<AZ::Vector3> ViewportScreenToWorld(const AzFramework::ScreenPoint& screenPosition, float depth) override;
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> 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<NullDebugDisplayRequests> m_nullDebugDisplayRequests;
const int m_viewportId = 1234; // Arbitrary viewport id for manipulator tests
@@ -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<AZ::Vector3> ViewportInteraction::ViewportScreenToWorld([[maybe_unused]]const QPoint& screenPosition, [[maybe_unused]]float depth)
AZStd::optional<AZ::Vector3> ViewportInteraction::ViewportScreenToWorld(
[[maybe_unused]] const AzFramework::ScreenPoint& screenPosition, [[maybe_unused]] float depth)
{
return {};
}
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportInteraction::ViewportScreenToWorldRay([[maybe_unused]]const QPoint& screenPosition)
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportInteraction::ViewportScreenToWorldRay(
[[maybe_unused]] const AzFramework::ScreenPoint& screenPosition)
{
return {};
}
@@ -16,7 +16,6 @@
#include <AzCore/std/string/string.h>
#include <AzCore/std/containers/fixed_vector.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Interface/Interface.h>
namespace AzQtComponents
@@ -13,6 +13,12 @@
#include <AzCore/EBus/EBus.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/std/string/string.h>
namespace AZ
{
struct BehaviorParameter;
}
namespace AzToolsFramework
{
@@ -40,6 +46,8 @@ namespace AzToolsFramework
};
using GlobalFunctionCollection = AZStd::vector<GlobalFunction>;
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
@@ -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<Vertex>(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(
@@ -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);
@@ -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<Instance>& 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());
@@ -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<Instance>& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch);
/**
* Given a list of entityIds, finds the prefab instance that owns the common root entity of the entityIds.
*
@@ -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()))
{
@@ -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<PrefabSystemComponentInterface>::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()
@@ -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;
@@ -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();
}
@@ -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
@@ -21,8 +21,6 @@
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/Viewport/ViewportTypes.h>
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<AZ::Vector3> ViewportScreenToWorld(const QPoint& screenPosition, float depth) = 0;
virtual AZStd::optional<AZ::Vector3> 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<ProjectedViewportRay> ViewportScreenToWorldRay(const QPoint& screenPosition) = 0;
virtual AZStd::optional<ProjectedViewportRay> 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.
@@ -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<float>(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;
@@ -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,
@@ -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.
@@ -316,14 +316,14 @@ namespace AzToolsFramework
template<typename EntitySelectFuncType, typename EntityIdContainer, typename Compare>
static void BoxSelectAddRemoveToEntitySelection(
const AZStd::optional<QRect>& boxSelect, const QPoint& screenPosition, const AZ::EntityId visibleEntityId,
const AZStd::optional<QRect>& 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);
@@ -23,7 +23,6 @@
#include "Objects/SelectionGroup.h"
#include "ViewManager.h"
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Interface/Interface.h>
// Qt
+5 -43
View File
@@ -27,12 +27,6 @@
// AzFramework
#include <AzFramework/Archive/IArchive.h>
#include <AzFramework/API/ApplicationAPI.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzFramework/Viewport/CameraInput.h>
// Atom
#include <Atom/RPI.Public/ViewportContext.h>
#include <Atom/RPI.Public/ViewportContextBus.h>
// AzToolsFramework
#include <AzToolsFramework/Slice/SliceUtilities.h>
@@ -68,6 +62,9 @@
#include "StatObjBus.h"
// LmbrCentral
#include <ModernViewportCameraController.h>
#include <Atom/RPI.Public/ViewportContext.h>
#include <Atom/RPI.Public/ViewportContextBus.h>
#include <LmbrCentral/Rendering/EditorLightComponentBus.h> // for LmbrCentral::EditorLightComponentRequestBus
@@ -2410,44 +2407,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<AzFramework::AtomActiveInterface>::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<AZ::SliceAsset>(), false);
if (m_envProbeSliceAssetId.IsValid())
{
AZ::Data::Asset<AZ::Data::AssetData> asset = AZ::Data::AssetManager::Instance().FindOrCreateAsset<AZ::SliceAsset>(
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)
+15 -15
View File
@@ -40,7 +40,6 @@
# include <AzFramework/Input/Buses/Notifications/RawInputNotificationBus_Platform.h>
#endif // defined(AZ_PLATFORM_WINDOWS)
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h> // for AzFramework::InputDeviceMouse
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzFramework/Viewport/ViewportControllerList.h>
// AzQtComponents
@@ -321,8 +320,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;
@@ -1132,14 +1131,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 +1147,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 +1173,7 @@ void EditorViewportWidget::FindVisibleEntities(AZStd::vector<AZ::EntityId>& 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);
}
@@ -2002,7 +2001,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
@@ -2024,7 +2023,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);
@@ -2035,7 +2035,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);
@@ -2152,7 +2152,7 @@ bool EditorViewportWidget::RayRenderMeshIntersection(IRenderMesh* pRenderMesh, c
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();
@@ -2160,9 +2160,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;
}
+4 -5
View File
@@ -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<AZ::EntityId>& visibleEntitiesOut) override;
bool ShowingWorldSpace() override;
@@ -557,8 +557,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();
-66
View File
@@ -15,7 +15,6 @@
#include "IconManager.h"
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Interface/Interface.h>
// AzToolsFramework
@@ -115,71 +114,6 @@ int CIconManager::GetIconTexture(const char* iconName)
return 0;
}
if (AZ::Interface<AzFramework::AtomActiveInterface>::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;
}
-1
View File
@@ -24,7 +24,6 @@
#include <QTextDocumentFragment>
#include <AzCore/Interface/Interface.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzQtComponents/Components/Style.h> // for AzQtComponents::Style
// Editor
+1 -13
View File
@@ -42,7 +42,6 @@ AZ_POP_DISABLE_WARNING
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
#include <AzFramework/Network/SocketConnection.h>
#include <AzFramework/Asset/AssetSystemComponent.h>
#include <AzFramework/API/AtomActiveInterface.h>
// AzToolsFramework
#include <AzToolsFramework/Application/Ticker.h>
@@ -1093,7 +1092,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<AzFramework::AtomActiveInterface>::Get())
if( saveLevelStatsAction )
{
saveLevelStatsAction->setEnabled(false);
}
@@ -1189,13 +1188,6 @@ void MainWindow::InitActions()
.SetIcon(Style::icon("Audio"))
.SetApplyHoverEffect();
if (!AZ::Interface<AzFramework::AtomActiveInterface>::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();
@@ -1652,10 +1644,6 @@ void MainWindow::RegisterStdViewClasses()
AzAssetBrowserWindow::RegisterViewClass();
AssetEditorWindow::RegisterViewClass();
if (!AZ::Interface<AzFramework::AtomActiveInterface>::Get())
{
CTimeOfDayDialog::RegisterViewClass();
}
#ifdef ThumbnailDemo
ThumbnailsSampleWidget::RegisterViewClass();
#endif
+13 -27
View File
@@ -42,7 +42,6 @@
# include <AzFramework/Input/Buses/Notifications/RawInputNotificationBus_Platform.h>
#endif // defined(AZ_PLATFORM_WINDOWS)
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h> // for AzFramework::InputDeviceMouse
#include <AzFramework/API/AtomActiveInterface.h>
// AzQtComponents
#include <AzQtComponents/Utilities/QtWindowUtilities.h>
@@ -275,13 +274,10 @@ void CRenderViewport::resizeEvent(QResizeEvent* event)
gEnv->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RESIZE, width(), height());
if (AZ::Interface<AzFramework::AtomActiveInterface>::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;
}
//////////////////////////////////////////////////////////////////////////
@@ -1553,14 +1549,6 @@ void CRenderViewport::OnRender()
if (levelIsDisplayable)
{
m_renderer->SetViewport(0, 0, m_renderer->GetWidth(), m_renderer->GetHeight(), m_nCurViewportID);
if (!AZ::Interface<AzFramework::AtomActiveInterface>::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
{
@@ -2043,14 +2031,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 +2047,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 +2088,13 @@ void CRenderViewport::FindVisibleEntities(AZStd::vector<AZ::EntityId>& 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;
@@ -3659,11 +3648,8 @@ bool CRenderViewport::CreateRenderContext()
{
m_bRenderContextCreated = true;
if (AZ::Interface<AzFramework::AtomActiveInterface>::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());
+12 -5
View File
@@ -190,17 +190,24 @@ public:
bool ShowGrid() override;
bool AngleSnappingEnabled() override;
float AngleStep() override;
QPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override;
AZStd::optional<AZ::Vector3> ViewportScreenToWorld(const QPoint&, float) override { return {}; }
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportScreenToWorldRay(const QPoint&) override { return {}; }
AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override;
AZStd::optional<AZ::Vector3> ViewportScreenToWorld(const AzFramework::ScreenPoint&, float) override
{
return {};
}
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> 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<AZ::EntityId>& visibleEntitiesOut) override;
bool ShowingWorldSpace() override;
-1
View File
@@ -16,7 +16,6 @@
// AzCore
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Interface/Interface.h>
// Qt
+2 -3
View File
@@ -34,7 +34,6 @@
#include "EditorViewportWidget.h"
#include "CryEditDoc.h"
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Console/IConsole.h>
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<AzFramework::AtomActiveInterface>::Get() || ed_useAtomNativeViewport;
return ed_useAtomNativeViewport;
}
//////////////////////////////////////////////////////////////////////
@@ -81,7 +80,7 @@ CViewManager::CViewManager()
RegisterQtViewPane<C2DViewport_YZ>(GetIEditor(), "Left", LyViewPane::CategoryViewport, viewportOptions);
viewportOptions.viewportType = ET_ViewportCamera;
if (ed_useAtomNativeViewport && AZ::Interface<AzFramework::AtomActiveInterface>::Get())
if (ed_useAtomNativeViewport)
{
RegisterQtViewPaneWithName<EditorViewportWidget>(GetIEditor(), "Perspective", LyViewPane::CategoryViewport, viewportOptions);
}
-1
View File
@@ -33,7 +33,6 @@
// AzFramework
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzCore/Interface/Interface.h>
// Editor
@@ -112,8 +112,7 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram
m_state.m_mousePick.m_screenCoordinates = screenPosition;
AZStd::optional<ProjectedViewportRay> 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())
{
@@ -30,7 +30,6 @@
#include <AzFramework/Entity/EntityContextBus.h>
#include <AzFramework/Physics/Material.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzToolsFramework/API/EntityCompositionRequestBus.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
@@ -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<AzFramework::AtomActiveInterface>::Get() && AzFramework::DebugDisplayRequestBus::HasHandlers()))
{
m_debugDisplayBusImplementationActive = true;
AzFramework::DebugDisplayRequestBus::Handler::BusConnect(
AzToolsFramework::ViewportInteraction::g_mainViewportEntityDebugDisplayId);
}
AzFramework::DisplayContextRequestBus::Handler::BusConnect();
SetupFileExtensionMap();
@@ -37,8 +37,6 @@
#include <AzCore/Jobs/JobManager.h>
#include <AzCore/Interface/Interface.h>
#include <AzFramework/API/AtomActiveInterface.h>
#include <AzQtComponents/Utilities/QtWindowUtilities.h>
// Class to implement the WindowRequestBus::Handler instead of the QViewport class.
@@ -365,7 +363,7 @@ bool QViewport::CreateRenderContext()
HWND windowHandle = reinterpret_cast<HWND>(QWidget::winId());
if( AZ::Interface<AzFramework::AtomActiveInterface>::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 +375,10 @@ bool QViewport::CreateRenderContext()
{
m_renderContextCreated = true;
if (AZ::Interface<AzFramework::AtomActiveInterface>::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);
@@ -13,9 +13,135 @@
#include <SceneAPI/SceneCore/Containers/GraphObjectProxy.h>
#include <AzCore/Casting/numeric_cast.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
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<AZStd::string> 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<AZ::BehaviorContext*>(context);
if (behaviorContext)
{
behaviorContext->Class<PythonBehaviorInfo>()
->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<AZStd::string>(); }, 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<EditorPythonConsoleInterface>::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<AZStd::string> 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,6 +151,8 @@ namespace AZ
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
if (behaviorContext)
{
Python::PythonBehaviorInfo::Reflect(context);
behaviorContext->Class<DataTypes::IGraphObject>();
behaviorContext->Class<GraphObjectProxy>()
@@ -33,6 +161,19 @@ namespace AZ
->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<Python::PythonBehaviorInfo>(self.m_behaviorClass);
return self.m_pythonBehaviorInfo.get();
}
return nullptr;
})
;
}
}
@@ -16,6 +16,11 @@
namespace AZ
{
namespace Python
{
class PythonBehaviorInfo;
}
namespace SceneAPI
{
namespace Containers
@@ -44,6 +49,7 @@ namespace AZ
private:
AZStd::shared_ptr<const DataTypes::IGraphObject> m_graphObject;
const AZ::BehaviorClass* m_behaviorClass = nullptr;
AZStd::shared_ptr<Python::PythonBehaviorInfo> m_pythonBehaviorInfo;
};
} // Containers
@@ -20,6 +20,7 @@
#include <AzCore/Component/ComponentApplication.h>
#include <AzCore/Serialization/Json/RegistrationContext.h>
#include <AzCore/Serialization/Json/JsonSystemComponent.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
@@ -378,6 +379,25 @@ namespace AZ
MOCK_CONST_METHOD1(QueryApplicationType, void(AZ::ApplicationTypeQuery&));
};
class MockEditorPythonConsoleInterface final
: public AzToolsFramework::EditorPythonConsoleInterface
{
public:
MockEditorPythonConsoleInterface()
{
AZ::Interface<AzToolsFramework::EditorPythonConsoleInterface>::Register(this);
}
~MockEditorPythonConsoleInterface()
{
AZ::Interface<AzToolsFramework::EditorPythonConsoleInterface>::Unregister(this);
}
MOCK_CONST_METHOD1(GetModuleList, void(AZStd::vector<AZStd::string_view>&));
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<MockSceneComponentApplication> m_componentApplication;
AZStd::unique_ptr<MockEditorPythonConsoleInterface> m_editorPythonConsoleInterface;
AZStd::unique_ptr<AZ::ScriptContext> m_scriptContext;
AZStd::unique_ptr<AZ::BehaviorContext> m_behaviorContext;
AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
@@ -454,6 +475,15 @@ namespace AZ
{
return this->m_serializeContext.get();
}));
m_editorPythonConsoleInterface = AZStd::make_unique<MockEditorPythonConsoleInterface>();
}
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
//
@@ -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;
@@ -10,11 +10,9 @@
*
*/
#ifndef AZ_COLLECTING_PARTIAL_SRGS
#error Do not include this file directly. Include the main .srgi file instead.
#endif
#include <Atom/Features/SrgSemantics.azsli>
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[];
}
}
@@ -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 <Atom/Feature/Common/Assets/ShaderResourceGroups/RayTracingSceneSrg.azsli>
#endif
@@ -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);
@@ -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
@@ -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<RPI::Image>& cubeMapImage) override;
void SetProbeCubeMap(const ReflectionProbeHandle& probe, Data::Instance<RPI::Image>& 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<RPI::StreamingImageAsset>& 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<Data::AssetData> asset) override;
void OnAssetError(Data::Asset<Data::AssetData> asset) override;
void OnAssetReloaded(Data::Asset<Data::AssetData> asset) override;
// notifies and removes the notification entry
void HandleAssetNotification(Data::Asset<Data::AssetData> asset, CubeMapAssetNotificationType notificationTyp);
void HandleAssetNotification(Data::Asset<Data::AssetData> 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<RPI::StreamingImageAsset> m_asset;
CubeMapAssetNotificationType m_notificationType = CubeMapAssetNotificationType::None;
};
typedef AZStd::vector<NotifyCubeMapAssetEntry> NotifyCubeMapAssetVector;
NotifyCubeMapAssetVector m_notifyCubeMapAssets;
@@ -30,11 +30,11 @@ namespace AZ
enum CubeMapAssetNotificationType
{
None,
Ready,
Error,
Reloaded
};
using NotifyCubeMapAssetReadyCallback = AZStd::function<void(const Data::Asset<RPI::StreamingImageAsset>& 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<RPI::Image>& cubeMapImage) = 0;
virtual void SetProbeCubeMap(const ReflectionProbeHandle& handle, Data::Instance<RPI::Image>& 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<RPI::StreamingImageAsset>& 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;
};
@@ -67,7 +67,7 @@ namespace AZ
// load the RayTracingSceneSrg asset
Data::Asset<RPI::ShaderResourceGroupAsset> rayTracingSceneSrgAsset =
RPI::AssetUtils::LoadAssetByProductPath<RPI::ShaderResourceGroupAsset>("shaderlib/raytracingscenesrg_raytracingscenesrg.azsrg", RPI::AssetUtils::TraceLevel::Error);
RPI::AssetUtils::LoadAssetByProductPath<RPI::ShaderResourceGroupAsset>("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);
@@ -234,9 +234,10 @@ namespace AZ
m_updateSrg = true;
}
void ReflectionProbe::SetCubeMapImage(const Data::Instance<RPI::Image>& cubeMapImage)
void ReflectionProbe::SetCubeMapImage(const Data::Instance<RPI::Image>& cubeMapImage, const AZStd::string& relativePath)
{
m_cubeMapImage = cubeMapImage;
m_cubeMapRelativePath = relativePath;
m_updateSrg = true;
}
@@ -88,7 +88,9 @@ namespace AZ
const Aabb& GetInnerAabbWs() const { return m_innerAabbWs; }
const Data::Instance<RPI::Image>& GetCubeMapImage() const { return m_cubeMapImage; }
void SetCubeMapImage(const Data::Instance<RPI::Image>& cubeMapImage);
void SetCubeMapImage(const Data::Instance<RPI::Image>& 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; }
@@ -135,6 +137,7 @@ namespace AZ
// cubemap
Data::Instance<RPI::Image> m_cubeMapImage;
AZStd::string m_cubeMapRelativePath;
bool m_useParallaxCorrection = false;
// probe visualization
@@ -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<RPI::Image>& cubeMapImage)
void ReflectionProbeFeatureProcessor::SetProbeCubeMap(const ReflectionProbeHandle& probe, Data::Instance<RPI::Image>& 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,15 +284,46 @@ namespace AZ
azrtti_typeid<AZ::RPI::StreamingImageAsset>(),
false);
bool existingAsset = assetId.IsValid();
m_notifyCubeMapAssets.push_back({ relativePath, assetId, existingAsset, callback });
if (existingAsset)
// we only track notifications for new cubemap assets, existing assets are automatically reloaded by the RPI
if (!assetId.IsValid())
{
Data::AssetBus::MultiHandler::BusConnect(assetId);
m_notifyCubeMapAssets.push_back({ relativePath, assetId });
}
}
bool ReflectionProbeFeatureProcessor::CheckCubeMapAssetNotification(const AZStd::string& relativePath, Data::Asset<RPI::StreamingImageAsset>& 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;
}
bool ReflectionProbeFeatureProcessor::IsCubeMapReferenced(const AZStd::string& relativePath)
{
for (auto& reflectionProbe : m_reflectionProbes)
{
if (reflectionProbe->GetCubeMapRelativePath() == relativePath)
{
return true;
}
}
return false;
}
void ReflectionProbeFeatureProcessor::ShowProbeVisualization(const ReflectionProbeHandle& probe, bool showVisualization)
{
AZ_Assert(probe.get(), "ShowProbeVisualization called with an invalid handle");
@@ -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<RPI::StreamingImageAsset>(asset), notificationType);
// remove the entry from the list
m_notifyCubeMapAssets.erase(itNotification);
// store the cubemap asset
itNotification->m_asset = Data::static_pointer_cast<RPI::StreamingImageAsset>(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<Data::AssetData> asset)
{
HandleAssetNotification(asset, CubeMapAssetNotificationType::Reloaded);
}
} // namespace Render
} // namespace AZ
@@ -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();
if (shaderVariantReference->m_shaderAsset.QueueLoad())
{
shaderVariantReference->m_shaderAsset.BlockUntilLoadComplete();
}
shaderVariantReference->m_shaderOptionGroup = ShaderOptionGroup{
shaderVariantReference->m_shaderAsset->GetShaderOptionGroupLayout(),
shaderVariantReference->m_shaderVariantId
};
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<BehaviorContext*>(context))
{
behaviorContext->Class<Item>()
behaviorContext->Class<Item>("ShaderCollectionItem")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Shader")
->Attribute(AZ::Script::Attributes::Module, "shader")
@@ -94,9 +94,10 @@ namespace AtomToolsFramework
bool ShowGrid() override;
bool AngleSnappingEnabled() override;
float AngleStep() override;
QPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override;
AZStd::optional<AZ::Vector3> ViewportScreenToWorld(const QPoint& screenPosition, float depth) override;
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportScreenToWorldRay(const QPoint& screenPosition) override;
AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override;
AZStd::optional<AZ::Vector3> ViewportScreenToWorld(const AzFramework::ScreenPoint& screenPosition, float depth) override;
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportScreenToWorldRay(
const AzFramework::ScreenPoint& screenPosition) override;
// AzToolsFramework::ViewportInteraction::ViewportMouseCursorRequestBus::Handler ...
void BeginCursorCapture() override;

Some files were not shown because too many files have changed in this diff Show More