SystemComponent is now only build in PhysX.Static, instead of most of the Physx projects.

This commit is contained in:
amzn-sean
2021-04-13 15:03:21 +01:00
parent 3d3f43b0b9
commit 23cf2d5d68
15 changed files with 82 additions and 131 deletions
@@ -142,13 +142,6 @@ namespace Physics
virtual AZStd::shared_ptr<Shape> CreateShape(const ColliderConfiguration& colliderConfiguration, const ShapeConfiguration& configuration) = 0;
/// Adds an appropriate collider component to the entity based on the provided shape configuration.
/// @param entity Entity where the component should be added to.
/// @param colliderConfiguration Configuration of the collider.
/// @param shapeConfiguration Configuration of the shape of the collider.
/// @param addEditorComponents Tells whether to add the Editor version of the collider component or the Game one.
virtual void AddColliderComponentToEntity(AZ::Entity* entity, const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& shapeConfiguration, bool addEditorComponents = false) = 0;
/// Releases the mesh object created by the physics backend.
/// @param nativeMeshObject Pointer to the mesh object.
virtual void ReleaseNativeMeshObject(void* nativeMeshObject) = 0;
-3
View File
@@ -213,9 +213,6 @@ namespace Blast
CreateShape,
AZStd::shared_ptr<Physics::Shape>(
const Physics::ColliderConfiguration&, const Physics::ShapeConfiguration&));
MOCK_METHOD4(
AddColliderComponentToEntity,
void(AZ::Entity*, const Physics::ColliderConfiguration&, const Physics::ShapeConfiguration&, bool));
MOCK_METHOD1(ReleaseNativeMeshObject, void(void*));
MOCK_METHOD1(CreateMaterial, AZStd::shared_ptr<Physics::Material>(const Physics::MaterialConfiguration&));
MOCK_METHOD0(GetDefaultMaterial, AZStd::shared_ptr<Physics::Material>());
@@ -33,7 +33,6 @@ namespace Physics
BusDisconnect();
}
MOCK_METHOD2(CreateShape, AZStd::shared_ptr<Physics::Shape>(const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& configuration));
MOCK_METHOD4(AddColliderComponentToEntity, void(AZ::Entity* entity, const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& shapeConfiguration, bool addEditorComponents));
MOCK_METHOD1(ReleaseNativeMeshObject, void(void* nativeMeshObject));
MOCK_METHOD1(CreateMaterial, AZStd::shared_ptr<Physics::Material>(const Physics::MaterialConfiguration& materialConfiguration));
MOCK_METHOD0(GetDefaultMaterial, AZStd::shared_ptr<Physics::Material>());
+3
View File
@@ -15,6 +15,7 @@
#include <AzFramework/Physics/CollisionBus.h>
#include <AzFramework/Physics/SystemBus.h>
#include <AzFramework/Physics/Configuration/CollisionConfiguration.h>
#include <AzFramework/Physics/Configuration/SceneConfiguration.h>
#include <AzToolsFramework/API/ViewPaneOptions.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <LyViewPaneNames.h>
@@ -23,6 +24,8 @@
#include <Editor/EditorWindow.h>
#include <Editor/ConfigurationWidget.h>
#include <System/PhysXSystem.h>
#include <PhysX/Configuration/PhysXConfiguration.h>
#include <PhysX/Debug/PhysXDebugConfiguration.h>
namespace PhysX
{
+7
View File
@@ -19,6 +19,7 @@
namespace AzPhysics
{
class CollisionConfiguration;
struct SceneConfiguration;
}
namespace Ui
@@ -28,6 +29,12 @@ namespace Ui
namespace PhysX
{
struct PhysXSystemConfiguration;
namespace Debug
{
struct DebugConfiguration;
}
namespace Editor
{
/// Window pane wrapper for the PhysX Configuration Widget.
@@ -18,13 +18,15 @@
#include <AzFramework/Physics/SystemBus.h>
#include <AzFramework/Physics/Collision/CollisionEvents.h>
#include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
#include <Editor/ConfigStringLineEditCtrl.h>
#include <Editor/EditorJointConfiguration.h>
#include <I3DEngine.h>
#include <IEditor.h>
#include <ISurfaceType.h>
#include <Editor/ConfigStringLineEditCtrl.h>
#include <Editor/EditorJointConfiguration.h>
#include <Editor/EditorWindow.h>
#include <Editor/PropertyTypes.h>
#include <System/PhysXSystem.h>
namespace PhysX
@@ -116,18 +118,20 @@ namespace PhysX
{
AzPhysics::SceneConfiguration editorWorldConfiguration = physicsSystem->GetDefaultSceneConfiguration();
editorWorldConfiguration.m_sceneName = AzPhysics::EditorPhysicsSceneName;
editorWorldConfiguration.m_sceneName = "EditorScene";
m_editorWorldSceneHandle = physicsSystem->AddScene(editorWorldConfiguration);
}
PhysX::RegisterConfigStringLineEditHandler(); // Register custom unique string line edit control
PhysX::Editor::RegisterPropertyTypes();
AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect();
}
void EditorSystemComponent::Deactivate()
{
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect();
AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
Physics::EditorWorldBus::Handler::BusDisconnect();
if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
@@ -164,6 +168,16 @@ namespace PhysX
}
}
void EditorSystemComponent::PopulateEditorGlobalContextMenu([[maybe_unused]] QMenu* menu, [[maybe_unused]] const AZ::Vector2& point, [[maybe_unused]] int flags)
{
}
void EditorSystemComponent::NotifyRegisterViews()
{
PhysX::Editor::EditorWindow::RegisterViewClass();
}
AZ::Data::AssetId EditorSystemComponent::GenerateSurfaceTypesLibrary()
{
AZ::Data::AssetId resultAssetId;
@@ -30,6 +30,7 @@ namespace PhysX
: public AZ::Component
, public Physics::EditorWorldBus::Handler
, private AzToolsFramework::EditorEntityContextNotificationBus::Handler
, private AzToolsFramework::EditorEvents::Bus::Handler
{
public:
AZ_COMPONENT(EditorSystemComponent, "{560F08DC-94F5-4D29-9AD4-CDFB3B57C654}");
@@ -60,6 +61,10 @@ namespace PhysX
void OnStartPlayInEditorBegin() override;
void OnStopPlayInEditor() override;
// AztoolsFramework::EditorEvents::Bus::Handler
void PopulateEditorGlobalContextMenu(QMenu* menu, const AZ::Vector2& point, int flags) override;
void NotifyRegisterViews() override;
AZ::Data::AssetId GenerateSurfaceTypesLibrary();
AzPhysics::SceneHandle m_editorWorldSceneHandle = AzPhysics::InvalidSceneHandle;
@@ -15,38 +15,18 @@
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzFramework/Physics/Utils.h>
#include <AzFramework/Physics/Material.h>
#include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
#include <AzFramework/Physics/Configuration/RigidBodyConfiguration.h>
#include <AzFramework/Physics/Configuration/StaticRigidBodyConfiguration.h>
#include <AzFramework/Asset/AssetSystemBus.h>
#include <AzFramework/API/ApplicationAPI.h>
#include <PhysX/MeshAsset.h>
#include <PhysX/HeightFieldAsset.h>
#include <Source/RigidBody.h>
#include <Source/RigidBodyStatic.h>
#include <Source/Utils.h>
#include <Source/Collision.h>
#include <Source/Shape.h>
#include <Source/Joint.h>
#include <Source/SphereColliderComponent.h>
#include <Source/BoxColliderComponent.h>
#include <Source/CapsuleColliderComponent.h>
#include <Source/Pipeline/MeshAssetHandler.h>
#include <Source/Pipeline/HeightFieldAssetHandler.h>
#include <Source/PhysXCharacters/API/CharacterUtils.h>
#include <Source/PhysXCharacters/API/CharacterController.h>
#include <Source/WindProvider.h>
#ifdef PHYSX_EDITOR
#include <Source/EditorColliderComponent.h>
#include <Editor/EditorWindow.h>
#include <Editor/PropertyTypes.h>
#include <AzToolsFramework/SourceControl/SourceControlAPI.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
#endif
#include <PhysX/Debug/PhysXDebugInterface.h>
#include <System/PhysXSystem.h>
@@ -233,21 +213,11 @@ namespace PhysX
Physics::CollisionRequestBus::Handler::BusConnect();
Physics::CharacterSystemRequestBus::Handler::BusConnect();
#ifdef PHYSX_EDITOR
PhysX::Editor::RegisterPropertyTypes();
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect();
AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
#endif
ActivatePhysXSystem();
}
void SystemComponent::Deactivate()
{
#ifdef PHYSX_EDITOR
AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect();
#endif
AZ::TickBus::Handler::BusDisconnect();
Physics::CharacterSystemRequestBus::Handler::BusDisconnect();
Physics::CollisionRequestBus::Handler::BusDisconnect();
@@ -272,19 +242,6 @@ namespace PhysX
m_assetHandlers.clear(); //this need to be after m_physXSystem->Shutdown(); For it will drop the default material library reference.
}
#ifdef PHYSX_EDITOR
// AztoolsFramework::EditorEvents::Bus::Handler overrides
void SystemComponent::PopulateEditorGlobalContextMenu([[maybe_unused]] QMenu* menu, [[maybe_unused]] const AZ::Vector2& point, [[maybe_unused]] int flags)
{
}
void SystemComponent::NotifyRegisterViews()
{
PhysX::Editor::EditorWindow::RegisterViewClass();
}
#endif
physx::PxConvexMesh* SystemComponent::CreateConvexMesh(const void* vertices, AZ::u32 vertexNum, AZ::u32 vertexStride)
{
physx::PxConvexMeshDesc desc;
@@ -464,54 +421,6 @@ namespace PhysX
}
}
void SystemComponent::AddColliderComponentToEntity(AZ::Entity* entity, const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& shapeConfiguration, [[maybe_unused]] bool addEditorComponents)
{
[[maybe_unused]] Physics::ShapeType shapeType = shapeConfiguration.GetShapeType();
#ifdef PHYSX_EDITOR
if (addEditorComponents)
{
entity->CreateComponent<EditorColliderComponent>(colliderConfiguration, shapeConfiguration);
}
else
#else
{
if (shapeType == Physics::ShapeType::Sphere)
{
const Physics::SphereShapeConfiguration& sphereConfiguration = static_cast<const Physics::SphereShapeConfiguration&>(shapeConfiguration);
auto sphereColliderComponent = entity->CreateComponent<SphereColliderComponent>();
sphereColliderComponent->SetShapeConfigurationList({ AZStd::make_pair(
AZStd::make_shared<Physics::ColliderConfiguration>(colliderConfiguration),
AZStd::make_shared<Physics::SphereShapeConfiguration>(sphereConfiguration)) });
}
else if (shapeType == Physics::ShapeType::Box)
{
const Physics::BoxShapeConfiguration& boxConfiguration = static_cast<const Physics::BoxShapeConfiguration&>(shapeConfiguration);
auto boxColliderComponent = entity->CreateComponent<BoxColliderComponent>();
boxColliderComponent->SetShapeConfigurationList({ AZStd::make_pair(
AZStd::make_shared<Physics::ColliderConfiguration>(colliderConfiguration),
AZStd::make_shared<Physics::BoxShapeConfiguration>(boxConfiguration)) });
}
else if (shapeType == Physics::ShapeType::Capsule)
{
const Physics::CapsuleShapeConfiguration& capsuleConfiguration = static_cast<const Physics::CapsuleShapeConfiguration&>(shapeConfiguration);
auto capsuleColliderComponent = entity->CreateComponent<CapsuleColliderComponent>();
capsuleColliderComponent->SetShapeConfigurationList({ AZStd::make_pair(
AZStd::make_shared<Physics::ColliderConfiguration>(colliderConfiguration),
AZStd::make_shared<Physics::CapsuleShapeConfiguration>(capsuleConfiguration)) });
}
}
AZ_Error("PhysX System", !addEditorComponents, "AddColliderComponentToEntity(): Trying to add an Editor collider component in a stand alone build.",
static_cast<AZ::u8>(shapeType));
#endif
{
AZ_Error("PhysX System", shapeType == Physics::ShapeType::Sphere || shapeType == Physics::ShapeType::Box || shapeType == Physics::ShapeType::Capsule,
"AddColliderComponentToEntity(): Using Shape of type %d is not implemented.", static_cast<AZ::u8>(shapeType));
}
}
// Physics::CharacterSystemRequestBus
AZStd::unique_ptr<Physics::Character> SystemComponent::CreateCharacter(const Physics::CharacterConfiguration&
characterConfig, const Physics::ShapeConfiguration& shapeConfig, AzPhysics::SceneHandle& sceneHandle)
-16
View File
@@ -36,9 +36,6 @@
#include <DefaultWorldComponent.h>
#include <Material.h>
#ifdef PHYSX_EDITOR
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#endif
namespace AzPhysics
{
struct StaticRigidBodyConfiguration;
@@ -61,10 +58,6 @@ namespace PhysX
, public Physics::SystemRequestBus::Handler
, public PhysX::SystemRequestsBus::Handler
, public Physics::CharacterSystemRequestBus::Handler
#ifdef PHYSX_EDITOR
, public AzToolsFramework::EditorEntityContextNotificationBus::Handler
, private AzToolsFramework::EditorEvents::Bus::Handler
#endif
, private Physics::CollisionRequestBus::Handler
, private AZ::TickBus::Handler
{
@@ -100,8 +93,6 @@ namespace PhysX
bool CookTriangleMeshToMemory(const AZ::Vector3* vertices, AZ::u32 vertexCount,
const AZ::u32* indices, AZ::u32 indexCount, AZStd::vector<AZ::u8>& result) override;
void AddColliderComponentToEntity(AZ::Entity* entity, const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& shapeConfiguration, bool addEditorComponents = false) override;
physx::PxFilterData CreateFilterData(const AzPhysics::CollisionLayer& layer, const AzPhysics::CollisionGroup& group) override;
physx::PxCooking* GetCooking() override;
@@ -125,13 +116,6 @@ namespace PhysX
void Activate() override;
void Deactivate() override;
#ifdef PHYSX_EDITOR
// AztoolsFramework::EditorEvents::Bus::Handler overrides
void PopulateEditorGlobalContextMenu(QMenu* menu, const AZ::Vector2& point, int flags) override;
void NotifyRegisterViews() override;
#endif
// Physics::SystemRequestBus::Handler
AZStd::shared_ptr<Physics::Shape> CreateShape(const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& configuration) override;
AZStd::shared_ptr<Physics::Material> CreateMaterial(const Physics::MaterialConfiguration& materialConfiguration) override;
@@ -24,6 +24,8 @@
#include <AzFramework/Components/TransformComponent.h>
#include <PhysX/ComponentTypeIds.h>
#include <PhysX/SystemComponentBus.h>
#include <Source/SphereColliderComponent.h>
#include <Source/CapsuleColliderComponent.h>
#include <System/PhysXSystem.h>
#include <Tests/PhysXTestFixtures.h>
#include <Tests/PhysXTestUtil.h>
@@ -31,6 +33,51 @@
namespace PhysX
{
namespace Internal
{
void AddColliderComponentToEntity(AZ::Entity* entity, const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& shapeConfiguration)
{
Physics::ShapeType shapeType = shapeConfiguration.GetShapeType();
switch (shapeType)
{
case Physics::ShapeType::Sphere:
{
const Physics::SphereShapeConfiguration& sphereConfiguration = static_cast<const Physics::SphereShapeConfiguration&>(shapeConfiguration);
auto sphereColliderComponent = entity->CreateComponent<SphereColliderComponent>();
sphereColliderComponent->SetShapeConfigurationList({ AZStd::make_pair(
AZStd::make_shared<Physics::ColliderConfiguration>(colliderConfiguration),
AZStd::make_shared<Physics::SphereShapeConfiguration>(sphereConfiguration)) });
}
break;
case Physics::ShapeType::Box:
{
const Physics::BoxShapeConfiguration& boxConfiguration = static_cast<const Physics::BoxShapeConfiguration&>(shapeConfiguration);
auto boxColliderComponent = entity->CreateComponent<BoxColliderComponent>();
boxColliderComponent->SetShapeConfigurationList({ AZStd::make_pair(
AZStd::make_shared<Physics::ColliderConfiguration>(colliderConfiguration),
AZStd::make_shared<Physics::BoxShapeConfiguration>(boxConfiguration)) });
}
break;
case Physics::ShapeType::Capsule:
{
const Physics::CapsuleShapeConfiguration& capsuleConfiguration = static_cast<const Physics::CapsuleShapeConfiguration&>(shapeConfiguration);
auto capsuleColliderComponent = entity->CreateComponent<CapsuleColliderComponent>();
capsuleColliderComponent->SetShapeConfigurationList({ AZStd::make_pair(
AZStd::make_shared<Physics::ColliderConfiguration>(colliderConfiguration),
AZStd::make_shared<Physics::CapsuleShapeConfiguration>(capsuleConfiguration)) });
}
break;
default:
{
AZ_Error("PhysX", false,
"AddColliderComponentToEntity(): Using Shape of type %d is not implemented.", static_cast<AZ::u8>(shapeType));
}
break;
}
}
}
// transform for a floor centred at x = 0, y = 0, with top at level z = 0
static const AZ::Transform DefaultFloorTransform = AZ::Transform::CreateTranslation(AZ::Vector3::CreateAxisZ(-0.5f));
@@ -367,8 +414,7 @@ namespace PhysX
auto triggerEntity = AZStd::make_unique<AZ::Entity>("TriggerEntity");
triggerEntity->CreateComponent<AzFramework::TransformComponent>()->SetWorldTM(AZ::Transform::Identity());
triggerEntity->CreateComponent(PhysX::StaticRigidBodyComponentTypeId);
Physics::SystemRequestBus::Broadcast(&Physics::SystemRequests::AddColliderComponentToEntity,
triggerEntity.get(), triggerConfig, boxConfig, false);
Internal::AddColliderComponentToEntity(triggerEntity.get(), triggerConfig, boxConfig);
triggerEntity->Init();
triggerEntity->Activate();
@@ -11,6 +11,4 @@
set(FILES
Source/Module.cpp
Source/SystemComponent.cpp
Source/SystemComponent.h
)
@@ -11,8 +11,6 @@
set(FILES
Source/Module.cpp
Source/SystemComponent.cpp
Source/SystemComponent.h
Tests/PhysXTestCommon.cpp
Tests/PhysXTestCommon.h
Tests/ColliderScalingTests.cpp
+2
View File
@@ -12,6 +12,8 @@
set(FILES
Source/PhysX_precompiled.cpp
Source/PhysX_precompiled.h
Source/SystemComponent.cpp
Source/SystemComponent.h
Include/PhysX/SystemComponentBus.h
Include/PhysX/ColliderComponentBus.h
Include/PhysX/NativeTypeIdentifiers.h
-2
View File
@@ -11,8 +11,6 @@
set(FILES
Source/Module.cpp
Source/SystemComponent.cpp
Source/SystemComponent.h
Source/ComponentDescriptors.cpp
Source/ComponentDescriptors.h
)
-2
View File
@@ -10,8 +10,6 @@
#
set(FILES
Source/SystemComponent.cpp
Source/SystemComponent.h
Source/ComponentDescriptors.cpp
Source/ComponentDescriptors.h
Tests/PhysXComponentBusTests.cpp