Adding additional PhysX tests for work with Prefabs

main
jonbeer 5 years ago
parent 9ca29b5f33
commit 6eddf39eff

@ -32,6 +32,9 @@ namespace Physics
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext
->RegisterGenericType<AZStd::shared_ptr<SphereShapeConfiguration>>();
serializeContext->Class<SphereShapeConfiguration, ShapeConfiguration>()
->Version(1)
->Field("Radius", &SphereShapeConfiguration::m_radius)
@ -60,6 +63,9 @@ namespace Physics
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext
->RegisterGenericType<AZStd::shared_ptr<BoxShapeConfiguration>>();
serializeContext->Class<BoxShapeConfiguration, ShapeConfiguration>()
->Version(1)
->Field("Configuration", &BoxShapeConfiguration::m_dimensions)
@ -88,6 +94,9 @@ namespace Physics
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext
->RegisterGenericType<AZStd::shared_ptr<CapsuleShapeConfiguration>>();
serializeContext->Class<CapsuleShapeConfiguration, ShapeConfiguration>()
->Version(1)
->Field("Height", &CapsuleShapeConfiguration::m_height)
@ -137,6 +146,9 @@ namespace Physics
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext
->RegisterGenericType<AZStd::shared_ptr<PhysicsAssetShapeConfiguration>>();
serializeContext->Class<PhysicsAssetShapeConfiguration, ShapeConfiguration>()
->Version(1)
->Field("PhysicsAsset", &PhysicsAssetShapeConfiguration::m_asset)
@ -169,6 +181,9 @@ namespace Physics
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext
->RegisterGenericType<AZStd::shared_ptr<NativeShapeConfiguration>>();
serializeContext->Class<NativeShapeConfiguration, ShapeConfiguration>()
->Version(1)
->Field("Scale", &NativeShapeConfiguration::m_nativeShapeScale)
@ -192,6 +207,9 @@ namespace Physics
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext
->RegisterGenericType<AZStd::shared_ptr<CookedMeshShapeConfiguration>>();
serializeContext->Class<CookedMeshShapeConfiguration, ShapeConfiguration>()
->Version(1)
->Field("CookedData", &CookedMeshShapeConfiguration::m_cookedData)

@ -45,6 +45,7 @@ ly_add_target(
${physx_dependency}
AZ::AzCore
AZ::AzFramework
AZ::AzToolsFramework
Legacy::CryCommon
Gem::LmbrCentral
)

@ -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 <PhysX_precompiled.h>
#include <AzTest/AzTest.h>
#include <PhysX/SystemComponentBus.h>
#include <AzCore/Asset/AssetManager.h>
#include <AzCore/IO/SystemFile.h>
#include <AzCore/Interface/Interface.h>
#include <AzFramework/Physics/SystemBus.h>
#include <AzFramework/Physics/PhysicsSystem.h>
#include <AzCore/Serialization/Json/JsonSerialization.h>
#include <AzCore/Serialization/Json/JsonSerializationSettings.h>
#include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
#include <AzToolsFramework/Prefab/PrefabDomTypes.h>
#include <AzToolsFramework/Prefab/PrefabSystemComponent.h>
#include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
#include <AzToolsFramework/Prefab/Instance/InstanceToTemplateInterface.h>
#include <AzToolsFramework/Prefab/Instance/InstanceEntityMapperInterface.h>
#include <AzToolsFramework/Prefab/PrefabDomUtils.h>
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<Physics::ColliderConfiguration>();
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<Physics::ColliderConfiguration>();
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<Physics::SphereShapeConfiguration>();
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<Physics::SphereShapeConfiguration>();
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);
}
}

@ -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

Loading…
Cancel
Save