diff --git a/Code/Framework/AzFramework/AzFramework/Physics/ShapeConfiguration.cpp b/Code/Framework/AzFramework/AzFramework/Physics/ShapeConfiguration.cpp index f01e42a443..617fd026b6 100644 --- a/Code/Framework/AzFramework/AzFramework/Physics/ShapeConfiguration.cpp +++ b/Code/Framework/AzFramework/AzFramework/Physics/ShapeConfiguration.cpp @@ -32,6 +32,9 @@ namespace Physics { if (auto serializeContext = azrtti_cast(context)) { + serializeContext + ->RegisterGenericType>(); + serializeContext->Class() ->Version(1) ->Field("Radius", &SphereShapeConfiguration::m_radius) @@ -60,6 +63,9 @@ namespace Physics { if (auto serializeContext = azrtti_cast(context)) { + serializeContext + ->RegisterGenericType>(); + serializeContext->Class() ->Version(1) ->Field("Configuration", &BoxShapeConfiguration::m_dimensions) @@ -88,6 +94,9 @@ namespace Physics { if (auto serializeContext = azrtti_cast(context)) { + serializeContext + ->RegisterGenericType>(); + serializeContext->Class() ->Version(1) ->Field("Height", &CapsuleShapeConfiguration::m_height) @@ -137,6 +146,9 @@ namespace Physics { if (auto serializeContext = azrtti_cast(context)) { + serializeContext + ->RegisterGenericType>(); + serializeContext->Class() ->Version(1) ->Field("PhysicsAsset", &PhysicsAssetShapeConfiguration::m_asset) @@ -169,6 +181,9 @@ namespace Physics { if (auto serializeContext = azrtti_cast(context)) { + serializeContext + ->RegisterGenericType>(); + serializeContext->Class() ->Version(1) ->Field("Scale", &NativeShapeConfiguration::m_nativeShapeScale) @@ -192,6 +207,9 @@ namespace Physics { if (auto serializeContext = azrtti_cast(context)) { + serializeContext + ->RegisterGenericType>(); + serializeContext->Class() ->Version(1) ->Field("CookedData", &CookedMeshShapeConfiguration::m_cookedData) diff --git a/Gems/PhysX/Code/CMakeLists.txt b/Gems/PhysX/Code/CMakeLists.txt index ac5fd902c2..65fafcf88b 100644 --- a/Gems/PhysX/Code/CMakeLists.txt +++ b/Gems/PhysX/Code/CMakeLists.txt @@ -45,6 +45,7 @@ ly_add_target( ${physx_dependency} AZ::AzCore AZ::AzFramework + AZ::AzToolsFramework Legacy::CryCommon Gem::LmbrCentral ) diff --git a/Gems/PhysX/Code/Tests/PhysXColliderPrefabTests.cpp b/Gems/PhysX/Code/Tests/PhysXColliderPrefabTests.cpp new file mode 100644 index 0000000000..d489ac2990 --- /dev/null +++ b/Gems/PhysX/Code/Tests/PhysXColliderPrefabTests.cpp @@ -0,0 +1,126 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +namespace PhysX +{ + class PhysXColliderPrefabTest + : public ::testing::Test + { + protected: + void SetUp() override + { + + } + + void TearDown() override + { + + } + + + }; + + TEST_F(PhysXColliderPrefabTest, JsonStoreAndLoadPhysicsObjectsWithPrefabTest) + { + AzToolsFramework::Prefab::PrefabDom prefabDom; + + //material selection + Physics::MaterialSelection materialSelection; + AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), materialSelection); + + AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Material Selection", prefabDom); + + Physics::MaterialSelection newSelection; + AZ::JsonSerialization::Load(newSelection, prefabDom); + + EXPECT_EQ(materialSelection.GetMaterialId(), newSelection.GetMaterialId()); + + //collider configuration + Physics::ColliderConfiguration colliderConfig; + AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), colliderConfig); + + AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Collider Configuration", prefabDom); + + Physics::ColliderConfiguration newConfig; + AZ::JsonSerialization::Load(newConfig, prefabDom); + + EXPECT_EQ(colliderConfig.m_collisionLayer, newConfig.m_collisionLayer); + + //shared pointer - collider configuration - defaults only + auto colliderConfigPtr = AZStd::make_shared(); + AZ::JsonSerializationResult::ResultCode result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), colliderConfigPtr); + + AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Collider Configuration", prefabDom); + + colliderConfigPtr = nullptr; + AZ::JsonSerialization::Load(colliderConfigPtr, prefabDom); + + EXPECT_NE(nullptr, colliderConfigPtr); + + //shared pointer - collider configuration - non default + auto updatedColliderConfigPtr = AZStd::make_shared(); + updatedColliderConfigPtr->m_isTrigger = true; + AZ::JsonSerializationResult::ResultCode result2 = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), updatedColliderConfigPtr); + + AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Collider Configuration", prefabDom); + + updatedColliderConfigPtr = nullptr; + AZ::JsonSerialization::Load(updatedColliderConfigPtr, prefabDom); + + EXPECT_NE(nullptr, updatedColliderConfigPtr); + + //shared pointer - shape configuration - defaults only + auto shapeConfigPtr = AZStd::make_shared(); + AZ::JsonSerializationResult::ResultCode result3 = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), shapeConfigPtr); + + AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Shape Configuration", prefabDom); + + shapeConfigPtr = nullptr; + AZ::JsonSerialization::Load(shapeConfigPtr, prefabDom); + + EXPECT_NE(nullptr, shapeConfigPtr); + + //shared pointer - shape configuration - non default + auto updatedShapeConfigPtr = AZStd::make_shared(); + updatedShapeConfigPtr->m_radius = 2.0f; + AZ::JsonSerializationResult::ResultCode result4 = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), updatedShapeConfigPtr); + + AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Shape Configuration", prefabDom); + + updatedShapeConfigPtr = nullptr; + AZ::JsonSerialization::Load(updatedShapeConfigPtr, prefabDom); + + EXPECT_NE(nullptr, updatedColliderConfigPtr); + } +} diff --git a/Gems/PhysX/Code/physx_tests_files.cmake b/Gems/PhysX/Code/physx_tests_files.cmake index 406aed64a7..182ff6a625 100644 --- a/Gems/PhysX/Code/physx_tests_files.cmake +++ b/Gems/PhysX/Code/physx_tests_files.cmake @@ -25,6 +25,7 @@ set(FILES Tests/PhysXForceRegionTest.cpp Tests/PhysXMaterialLibraryTest.cpp Tests/PhysXCollisionFilteringTest.cpp + Tests/PhysXColliderPrefabTests.cpp Tests/PhysXJointsTest.cpp Tests/PhysXSceneTests.cpp Tests/PhysXSceneQueryTests.cpp