merge from main
This commit is contained in:
@@ -104,7 +104,7 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
void BaseColliderComponent::SetShapeConfigurationList(const Physics::ShapeConfigurationList& shapeConfigList)
|
||||
void BaseColliderComponent::SetShapeConfigurationList(const AzPhysics::ShapeColliderPairList& shapeConfigList)
|
||||
{
|
||||
if (GetEntity()->GetState() == AZ::Entity::State::Active)
|
||||
{
|
||||
@@ -115,7 +115,7 @@ namespace PhysX
|
||||
m_shapeConfigList = shapeConfigList;
|
||||
}
|
||||
|
||||
Physics::ShapeConfigurationList BaseColliderComponent::GetShapeConfigurations()
|
||||
AzPhysics::ShapeColliderPairList BaseColliderComponent::GetShapeConfigurations()
|
||||
{
|
||||
return m_shapeConfigList;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ namespace PhysX
|
||||
{
|
||||
AZ_Assert(IsMeshCollider(), "InitMeshCollider called for a non-mesh collider.");
|
||||
|
||||
const Physics::ShapeConfigurationPair& shapeConfigurationPair = *(m_shapeConfigList.begin());
|
||||
const AzPhysics::ShapeColliderPair& shapeConfigurationPair = *(m_shapeConfigList.begin());
|
||||
const Physics::ColliderConfiguration& componentColliderConfiguration = *(shapeConfigurationPair.first.get());
|
||||
const Physics::PhysicsAssetShapeConfiguration& physicsAssetConfiguration =
|
||||
*(static_cast<const Physics::PhysicsAssetShapeConfiguration*>(shapeConfigurationPair.second.get()));
|
||||
|
||||
@@ -40,10 +40,10 @@ namespace PhysX
|
||||
|
||||
BaseColliderComponent() = default;
|
||||
|
||||
void SetShapeConfigurationList(const Physics::ShapeConfigurationList& shapeConfigList);
|
||||
void SetShapeConfigurationList(const AzPhysics::ShapeColliderPairList& shapeConfigList);
|
||||
|
||||
// ColliderComponentRequestBus
|
||||
Physics::ShapeConfigurationList GetShapeConfigurations() override;
|
||||
AzPhysics::ShapeColliderPairList GetShapeConfigurations() override;
|
||||
AZStd::vector<AZStd::shared_ptr<Physics::Shape>> GetShapes() override;
|
||||
|
||||
// TransformNotificationsBus
|
||||
@@ -100,10 +100,9 @@ namespace PhysX
|
||||
required.push_back(AZ_CRC("TransformService", 0x8ee22c50));
|
||||
}
|
||||
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
static void GetIncompatibleServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
// Not compatible with cry engine colliders
|
||||
incompatible.push_back(AZ_CRC("ColliderService", 0x902d4e93));
|
||||
|
||||
}
|
||||
|
||||
// AZ::Component
|
||||
@@ -115,7 +114,7 @@ namespace PhysX
|
||||
virtual void UpdateScaleForShapeConfigs();
|
||||
|
||||
ShapeInfoCache m_shapeInfoCache;
|
||||
Physics::ShapeConfigurationList m_shapeConfigList;
|
||||
AzPhysics::ShapeColliderPairList m_shapeConfigList;
|
||||
private:
|
||||
bool InitShapes();
|
||||
bool IsMeshCollider() const;
|
||||
|
||||
@@ -258,9 +258,9 @@ namespace PhysX
|
||||
{
|
||||
ActorData* userData = Utils::GetUserData(actor);
|
||||
Physics::Shape* shape = Utils::GetUserData(pxShape);
|
||||
if (userData != nullptr && userData->GetWorldBody())
|
||||
if (userData != nullptr && userData->GetSimulatedBody())
|
||||
{
|
||||
return GetPxHitType(m_filterCallback(userData->GetWorldBody(), shape));
|
||||
return GetPxHitType(m_filterCallback(userData->GetSimulatedBody(), shape));
|
||||
}
|
||||
}
|
||||
return m_hitType;
|
||||
|
||||
@@ -63,6 +63,11 @@ namespace PhysX
|
||||
required.push_back(AZ_CRC("PhysXRigidBodyService", 0x1d4c64a8));
|
||||
}
|
||||
|
||||
void EditorBallJointComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void EditorBallJointComponent::Activate()
|
||||
{
|
||||
EditorJointComponent::Activate();
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace PhysX
|
||||
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
|
||||
// AZ::Component
|
||||
void Activate() override;
|
||||
|
||||
@@ -88,33 +88,33 @@ namespace PhysX
|
||||
editContext->Class<EditorProxyShapeConfig>(
|
||||
"EditorProxyShapeConfig", "PhysX Base shape collider")
|
||||
->DataElement(AZ::Edit::UIHandlers::ComboBox, &EditorProxyShapeConfig::m_shapeType, "Shape", "The shape of the collider")
|
||||
->EnumAttribute(Physics::ShapeType::Sphere, "Sphere")
|
||||
->EnumAttribute(Physics::ShapeType::Box, "Box")
|
||||
->EnumAttribute(Physics::ShapeType::Capsule, "Capsule")
|
||||
->EnumAttribute(Physics::ShapeType::PhysicsAsset, "PhysicsAsset")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree)
|
||||
// note: we do not want the user to be able to change shape types while in ComponentMode (there will
|
||||
// potentially be different ComponentModes for different shape types)
|
||||
->Attribute(AZ::Edit::Attributes::ReadOnly, &AzToolsFramework::ComponentModeFramework::InComponentMode)
|
||||
->EnumAttribute(Physics::ShapeType::Sphere, "Sphere")
|
||||
->EnumAttribute(Physics::ShapeType::Box, "Box")
|
||||
->EnumAttribute(Physics::ShapeType::Capsule, "Capsule")
|
||||
->EnumAttribute(Physics::ShapeType::PhysicsAsset, "PhysicsAsset")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree)
|
||||
// note: we do not want the user to be able to change shape types while in ComponentMode (there will
|
||||
// potentially be different ComponentModes for different shape types)
|
||||
->Attribute(AZ::Edit::Attributes::ReadOnly, &AzToolsFramework::ComponentModeFramework::InComponentMode)
|
||||
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorProxyShapeConfig::m_sphere, "Sphere", "Configuration of sphere shape")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsSphereConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsSphereConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorProxyShapeConfig::m_box, "Box", "Configuration of box shape")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsBoxConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsBoxConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorProxyShapeConfig::m_capsule, "Capsule", "Configuration of capsule shape")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsCapsuleConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsCapsuleConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorProxyShapeConfig::m_physicsAsset, "Asset", "Configuration of asset shape")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsAssetConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::IsAssetConfig)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorProxyShapeConfig::m_subdivisionLevel, "Subdivision level",
|
||||
"The level of subdivision if a primitive shape is replaced with a convex mesh due to scaling")
|
||||
->Attribute(AZ::Edit::Attributes::Min, Utils::MinCapsuleSubdivisionLevel)
|
||||
->Attribute(AZ::Edit::Attributes::Max, Utils::MaxCapsuleSubdivisionLevel)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::ShowingSubdivisionLevel)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
->Attribute(AZ::Edit::Attributes::Min, Utils::MinCapsuleSubdivisionLevel)
|
||||
->Attribute(AZ::Edit::Attributes::Max, Utils::MaxCapsuleSubdivisionLevel)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorProxyShapeConfig::ShowingSubdivisionLevel)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnConfigurationChanged)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -189,8 +189,8 @@ namespace PhysX
|
||||
"PhysX Collider", "PhysX shape collider")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
|
||||
->Attribute(AZ::Edit::Attributes::HelpPageURL, "http://docs.aws.amazon.com/console/lumberyard/component/physx/collider")
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
@@ -312,6 +312,26 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
AZStd::shared_ptr<Physics::ShapeConfiguration> EditorProxyShapeConfig::CloneCurrent() const
|
||||
{
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case Physics::ShapeType::Sphere:
|
||||
return AZStd::make_shared<Physics::SphereShapeConfiguration>(m_sphere);
|
||||
case Physics::ShapeType::Capsule:
|
||||
return AZStd::make_shared<Physics::CapsuleShapeConfiguration>(m_capsule);
|
||||
case Physics::ShapeType::PhysicsAsset:
|
||||
return AZStd::make_shared<Physics::PhysicsAssetShapeConfiguration>(m_physicsAsset.m_configuration);
|
||||
case Physics::ShapeType::CookedMesh:
|
||||
return AZStd::make_shared<Physics::CookedMeshShapeConfiguration>(m_cookedMesh);
|
||||
default:
|
||||
AZ_Warning("EditorProxyShapeConfig", false, "Unsupported shape type, defaulting to Box.");
|
||||
[[fallthrough]];
|
||||
case Physics::ShapeType::Box:
|
||||
return AZStd::make_shared<Physics::BoxShapeConfiguration>(m_box);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorProxyShapeConfig::ShowingSubdivisionLevel() const
|
||||
{
|
||||
return (m_hasNonUniformScale && (IsCapsuleConfig() || IsSphereConfig() || IsAssetConfig()));
|
||||
@@ -345,7 +365,6 @@ namespace PhysX
|
||||
AzToolsFramework::BoxManipulatorRequestBus::Handler::BusConnect(
|
||||
AZ::EntityComponentIdPair(GetEntityId(), GetId()));
|
||||
ColliderShapeRequestBus::Handler::BusConnect(GetEntityId());
|
||||
LmbrCentral::MeshComponentNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
AZ::Render::MeshComponentNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
EditorColliderComponentRequestBus::Handler::BusConnect(AZ::EntityComponentIdPair(GetEntityId(), GetId()));
|
||||
m_nonUniformScaleChangedHandler = AZ::NonUniformScaleChangedEvent::Handler(
|
||||
@@ -388,13 +407,12 @@ namespace PhysX
|
||||
|
||||
void EditorColliderComponent::Deactivate()
|
||||
{
|
||||
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusDisconnect();
|
||||
m_colliderDebugDraw.Disconnect();
|
||||
AZ::Data::AssetBus::MultiHandler::BusDisconnect();
|
||||
m_nonUniformScaleChangedHandler.Disconnect();
|
||||
EditorColliderComponentRequestBus::Handler::BusDisconnect();
|
||||
AZ::Render::MeshComponentNotificationBus::Handler::BusDisconnect();
|
||||
LmbrCentral::MeshComponentNotificationBus::Handler::BusDisconnect();
|
||||
ColliderShapeRequestBus::Handler::BusDisconnect();
|
||||
AzToolsFramework::BoxManipulatorRequestBus::Handler::BusDisconnect();
|
||||
AZ::TransformNotificationBus::Handler::BusDisconnect();
|
||||
@@ -407,7 +425,6 @@ namespace PhysX
|
||||
if (m_sceneInterface)
|
||||
{
|
||||
m_sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
m_editorBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +598,6 @@ namespace PhysX
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
m_sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
m_editorBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -594,10 +610,6 @@ namespace PhysX
|
||||
configuration.m_entityId = GetEntityId();
|
||||
configuration.m_debugName = GetEntity()->GetName();
|
||||
|
||||
// This configuration needs to be at the scope of the function to be added
|
||||
// to m_colliderAndShapeData as a pointer.
|
||||
Physics::ColliderConfiguration colliderConfig;
|
||||
|
||||
if (m_shapeConfiguration.IsAssetConfig())
|
||||
{
|
||||
AZStd::vector<AZStd::shared_ptr<Physics::Shape>> shapes;
|
||||
@@ -607,13 +619,15 @@ namespace PhysX
|
||||
}
|
||||
else
|
||||
{
|
||||
colliderConfig = GetColliderConfigurationScaled();
|
||||
Physics::ShapeConfiguration& shapeConfig = m_shapeConfiguration.GetCurrent();
|
||||
AZStd::shared_ptr<Physics::ColliderConfiguration> colliderConfig = AZStd::make_shared<Physics::ColliderConfiguration>(
|
||||
GetColliderConfigurationScaled());
|
||||
AZStd::shared_ptr<Physics::ShapeConfiguration> shapeConfig = m_shapeConfiguration.CloneCurrent();
|
||||
|
||||
if (IsNonUniformlyScaledPrimitive(m_shapeConfiguration))
|
||||
{
|
||||
auto convexConfig = Utils::CreateConvexFromPrimitive(GetColliderConfiguration(), shapeConfig,
|
||||
m_shapeConfiguration.m_subdivisionLevel, shapeConfig.m_scale);
|
||||
auto colliderConfigurationNoOffset = colliderConfig;
|
||||
auto convexConfig = Utils::CreateConvexFromPrimitive(GetColliderConfiguration(), *(shapeConfig.get()),
|
||||
m_shapeConfiguration.m_subdivisionLevel, shapeConfig->m_scale);
|
||||
Physics::ColliderConfiguration colliderConfigurationNoOffset = *colliderConfig;
|
||||
colliderConfigurationNoOffset.m_rotation = AZ::Quaternion::CreateIdentity();
|
||||
colliderConfigurationNoOffset.m_position = AZ::Vector3::CreateZero();
|
||||
|
||||
@@ -626,7 +640,7 @@ namespace PhysX
|
||||
}
|
||||
else
|
||||
{
|
||||
configuration.m_colliderAndShapeData = AzPhysics::ShapeColliderPair(&colliderConfig, &shapeConfig);
|
||||
configuration.m_colliderAndShapeData = AzPhysics::ShapeColliderPair(colliderConfig, shapeConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -636,7 +650,6 @@ namespace PhysX
|
||||
if (m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
m_sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
m_editorBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
|
||||
m_editorBodyHandle = m_sceneInterface->AddSimulatedBody(m_editorSceneHandle, &configuration);
|
||||
@@ -644,7 +657,7 @@ namespace PhysX
|
||||
|
||||
m_colliderDebugDraw.ClearCachedGeometry();
|
||||
|
||||
Physics::WorldBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusConnect(GetEntityId());
|
||||
}
|
||||
|
||||
AZ::Data::Asset<Pipeline::MeshAsset> EditorColliderComponent::GetMeshAsset() const
|
||||
@@ -810,7 +823,7 @@ namespace PhysX
|
||||
return;
|
||||
}
|
||||
|
||||
Physics::ShapeConfigurationList shapeConfigList;
|
||||
AzPhysics::ShapeColliderPairList shapeConfigList;
|
||||
Utils::GetColliderShapeConfigsFromAsset(physicsAssetConfiguration, m_configuration, m_hasNonUniformScale,
|
||||
m_shapeConfiguration.m_subdivisionLevel, shapeConfigList);
|
||||
|
||||
@@ -884,7 +897,7 @@ namespace PhysX
|
||||
|
||||
const Physics::PhysicsAssetShapeConfiguration& physicsAssetConfiguration = m_shapeConfiguration.m_physicsAsset.m_configuration;
|
||||
|
||||
Physics::ShapeConfigurationList shapeConfigList;
|
||||
AzPhysics::ShapeColliderPairList shapeConfigList;
|
||||
Utils::GetColliderShapeConfigsFromAsset(physicsAssetConfiguration, m_configuration, m_hasNonUniformScale,
|
||||
m_shapeConfiguration.m_subdivisionLevel, shapeConfigList);
|
||||
|
||||
@@ -1053,13 +1066,19 @@ namespace PhysX
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
m_sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
m_editorBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorColliderComponent::IsPhysicsEnabled() const
|
||||
{
|
||||
return m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle;
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
if (auto* body = m_sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorBodyHandle))
|
||||
{
|
||||
return body->m_simulating;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::Aabb EditorColliderComponent::GetAabb() const
|
||||
@@ -1074,7 +1093,7 @@ namespace PhysX
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* EditorColliderComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBody* EditorColliderComponent::GetSimulatedBody()
|
||||
{
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
@@ -1086,6 +1105,11 @@ namespace PhysX
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBodyHandle EditorColliderComponent::GetSimulatedBodyHandle() const
|
||||
{
|
||||
return m_editorBodyHandle;
|
||||
}
|
||||
|
||||
AzPhysics::SceneQueryHit EditorColliderComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
{
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
@@ -1179,17 +1203,7 @@ namespace PhysX
|
||||
AZ::Render::MeshComponentRequestBus::EventResult(atomMeshAsset, GetEntityId(),
|
||||
&AZ::Render::MeshComponentRequestBus::Events::GetModelAsset);
|
||||
|
||||
if (atomMeshAsset.GetId().IsValid())
|
||||
{
|
||||
return atomMeshAsset;
|
||||
}
|
||||
|
||||
// Try legacy render MeshComponent
|
||||
AZ::Data::Asset<AZ::Data::AssetData> legacyMeshAsset;
|
||||
LmbrCentral::MeshComponentRequestBus::EventResult(legacyMeshAsset,
|
||||
GetEntityId(), &LmbrCentral::MeshComponentRequests::GetMeshAsset);
|
||||
|
||||
return legacyMeshAsset;
|
||||
return atomMeshAsset;
|
||||
}
|
||||
|
||||
void EditorColliderComponent::SetCollisionMeshFromRender()
|
||||
@@ -1264,14 +1278,6 @@ namespace PhysX
|
||||
renderMeshAsset.GetHint().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void EditorColliderComponent::OnMeshCreated([[maybe_unused]] const AZ::Data::Asset<AZ::Data::AssetData>& asset)
|
||||
{
|
||||
if (ShouldUpdateCollisionMeshFromRender())
|
||||
{
|
||||
SetCollisionMeshFromRender();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorColliderComponent::OnModelReady([[maybe_unused]] const AZ::Data::Asset<AZ::RPI::ModelAsset>& modelAsset,
|
||||
[[maybe_unused]] const AZ::Data::Instance<AZ::RPI::Model>& model)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
#include <AzFramework/Physics/Shape.h>
|
||||
#include <AzFramework/Physics/ShapeConfiguration.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Components/SimulatedBodyComponentBus.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsEvents.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsTypes.h>
|
||||
|
||||
@@ -32,8 +32,6 @@
|
||||
#include <AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h>
|
||||
#include <AzToolsFramework/UI/PropertyEditor/ComponentEditor.hxx>
|
||||
|
||||
#include <LmbrCentral/Rendering/MeshComponentBus.h>
|
||||
|
||||
#include <PhysX/ColliderShapeBus.h>
|
||||
#include <PhysX/EditorColliderComponentRequestBus.h>
|
||||
#include <PhysX/MeshAsset.h>
|
||||
@@ -88,6 +86,8 @@ namespace PhysX
|
||||
Physics::ShapeConfiguration& GetCurrent();
|
||||
const Physics::ShapeConfiguration& GetCurrent() const;
|
||||
|
||||
AZStd::shared_ptr<Physics::ShapeConfiguration> CloneCurrent() const;
|
||||
|
||||
bool ShowingSubdivisionLevel() const;
|
||||
|
||||
AZ::u32 OnConfigurationChanged();
|
||||
@@ -105,10 +105,9 @@ namespace PhysX
|
||||
, private PhysX::MeshColliderComponentRequestsBus::Handler
|
||||
, private AZ::TransformNotificationBus::Handler
|
||||
, private PhysX::ColliderShapeRequestBus::Handler
|
||||
, private LmbrCentral::MeshComponentNotificationBus::Handler
|
||||
, private AZ::Render::MeshComponentNotificationBus::Handler
|
||||
, private PhysX::EditorColliderComponentRequestBus::Handler
|
||||
, private Physics::WorldBodyRequestBus::Handler
|
||||
, private AzPhysics::SimulatedBodyComponentRequestsBus::Handler
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(EditorColliderComponent, "{FD429282-A075-4966-857F-D0BBF186CFE6}", AzToolsFramework::Components::EditorComponentBase);
|
||||
@@ -175,9 +174,6 @@ namespace PhysX
|
||||
AZ::Transform GetCurrentTransform() override;
|
||||
AZ::Vector3 GetBoxScale() override;
|
||||
|
||||
// LmbrCentral::MeshComponentNotificationBus
|
||||
void OnMeshCreated(const AZ::Data::Asset<AZ::Data::AssetData>& asset) override;
|
||||
|
||||
// AZ::Render::MeshComponentNotificationBus
|
||||
void OnModelReady(const AZ::Data::Asset<AZ::RPI::ModelAsset>& modelAsset,
|
||||
const AZ::Data::Instance<AZ::RPI::Model>& model) override;
|
||||
@@ -211,12 +207,13 @@ namespace PhysX
|
||||
AZ::u32 OnConfigurationChanged();
|
||||
void UpdateShapeConfigurationScale();
|
||||
|
||||
// WorldBodyRequestBus
|
||||
// AzPhysics::SimulatedBodyComponentRequestsBus::Handler overrides ...
|
||||
void EnablePhysics() override;
|
||||
void DisablePhysics() override;
|
||||
bool IsPhysicsEnabled() const override;
|
||||
AZ::Aabb GetAabb() const override;
|
||||
AzPhysics::SimulatedBody* GetWorldBody() override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBody() override;
|
||||
AzPhysics::SimulatedBodyHandle GetSimulatedBodyHandle() const override;
|
||||
AzPhysics::SceneQueryHit RayCast(const AzPhysics::RayCastRequest& request) override;
|
||||
|
||||
// Mesh collider
|
||||
|
||||
@@ -60,6 +60,11 @@ namespace PhysX
|
||||
required.push_back(AZ_CRC("PhysXRigidBodyService", 0x1d4c64a8));
|
||||
}
|
||||
|
||||
void EditorFixedJointComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void EditorFixedJointComponent::Activate()
|
||||
{
|
||||
EditorJointComponent::Activate();
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace PhysX
|
||||
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
|
||||
// AZ::Component
|
||||
void Activate() override;
|
||||
|
||||
@@ -173,8 +173,8 @@ namespace PhysX
|
||||
"PhysX Force Region", "The force region component is used to apply a physical force on objects within the region")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/ForceRegion.png")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/ForceRegion.png")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/ForceRegion.png")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/ForceRegion.png")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
|
||||
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://docs.aws.amazon.com/console/lumberyard/physx/force-region")
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
|
||||
@@ -63,6 +63,11 @@ namespace PhysX
|
||||
required.push_back(AZ_CRC("PhysXRigidBodyService", 0x1d4c64a8));
|
||||
}
|
||||
|
||||
void EditorHingeJointComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void EditorHingeJointComponent::Activate()
|
||||
{
|
||||
EditorJointComponent::Activate();
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace PhysX
|
||||
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
|
||||
// AZ::Component
|
||||
void Activate() override;
|
||||
|
||||
@@ -265,14 +265,14 @@ namespace PhysX
|
||||
}
|
||||
CreateEditorWorldRigidBody();
|
||||
|
||||
Physics::WorldBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusConnect(GetEntityId());
|
||||
}
|
||||
|
||||
void EditorRigidBodyComponent::Deactivate()
|
||||
{
|
||||
m_debugDisplayDataChangeHandler.Disconnect();
|
||||
|
||||
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusDisconnect();
|
||||
m_nonUniformScaleChangedHandler.Disconnect();
|
||||
m_sceneStartSimHandler.Disconnect();
|
||||
Physics::ColliderComponentEventBus::Handler::BusDisconnect();
|
||||
@@ -282,9 +282,7 @@ namespace PhysX
|
||||
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_rigidBodyHandle);
|
||||
m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
m_editorBody = nullptr;
|
||||
sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorRigidBodyHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,8 +305,8 @@ namespace PhysX
|
||||
"PhysX Rigid Body", "The entity behaves as a movable rigid object in PhysX.")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/PhysXRigidBody.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/PhysXRigidBody.svg")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/PhysXRigidBody.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/PhysXRigidBody.svg")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://docs.aws.amazon.com/console/lumberyard/components/physx/rigid-body")
|
||||
@@ -342,12 +340,15 @@ namespace PhysX
|
||||
[[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo,
|
||||
AzFramework::DebugDisplayRequests& debugDisplay)
|
||||
{
|
||||
if (m_editorBody && m_config.m_centerOfMassDebugDraw)
|
||||
if (m_config.m_centerOfMassDebugDraw)
|
||||
{
|
||||
debugDisplay.DepthTestOff();
|
||||
debugDisplay.SetColor(m_centerOfMassDebugColor);
|
||||
debugDisplay.DrawBall(m_editorBody->GetCenterOfMassWorld(), m_centerOfMassDebugSize);
|
||||
debugDisplay.DepthTestOn();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
debugDisplay.DepthTestOff();
|
||||
debugDisplay.SetColor(m_centerOfMassDebugColor);
|
||||
debugDisplay.DrawBall(body->GetCenterOfMassWorld(), m_centerOfMassDebugSize);
|
||||
debugDisplay.DepthTestOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,29 +367,30 @@ namespace PhysX
|
||||
AZ::Transform colliderTransform = GetWorldTM();
|
||||
colliderTransform.ExtractScale();
|
||||
|
||||
AzPhysics::RigidBodyConfiguration configuration;
|
||||
AzPhysics::RigidBodyConfiguration configuration = m_config;
|
||||
configuration.m_orientation = colliderTransform.GetRotation();
|
||||
configuration.m_position = colliderTransform.GetTranslation();
|
||||
configuration.m_entityId = GetEntityId();
|
||||
configuration.m_debugName = GetEntity()->GetName();
|
||||
configuration.m_centerOfMassOffset = m_config.m_centerOfMassOffset;
|
||||
configuration.m_computeCenterOfMass = m_config.m_computeCenterOfMass;
|
||||
configuration.m_computeInertiaTensor = m_config.m_computeInertiaTensor;
|
||||
configuration.m_inertiaTensor = m_config.m_inertiaTensor;
|
||||
configuration.m_simulated = false;
|
||||
configuration.m_kinematic = m_config.m_kinematic;
|
||||
configuration.m_startSimulationEnabled = false;
|
||||
configuration.m_colliderAndShapeData = Internal::GetCollisionShapes(GetEntity());
|
||||
|
||||
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
m_rigidBodyHandle = sceneInterface->AddSimulatedBody(m_editorSceneHandle, &configuration);
|
||||
m_editorBody = azdynamic_cast<AzPhysics::RigidBody*>(sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_rigidBodyHandle));
|
||||
m_editorRigidBodyHandle = sceneInterface->AddSimulatedBody(m_editorSceneHandle, &configuration);
|
||||
if (auto* body = azdynamic_cast<AzPhysics::RigidBody*>(
|
||||
sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorRigidBodyHandle)
|
||||
))
|
||||
{
|
||||
// AddSimulatedBody may update mass / CoM / Inertia tensor based on the config, so grab the updated values.
|
||||
m_config.m_mass = body->GetMass();
|
||||
m_config.m_centerOfMassOffset = body->GetCenterOfMassLocal();
|
||||
m_config.m_inertiaTensor = body->GetInverseInertiaLocal();
|
||||
}
|
||||
}
|
||||
|
||||
m_editorBody->UpdateMassProperties(m_config.GetMassComputeFlags(), &m_config.m_centerOfMassOffset, &m_config.m_inertiaTensor, &m_config.m_mass);
|
||||
m_config.m_mass = m_editorBody->GetMass();
|
||||
m_config.m_centerOfMassOffset = m_editorBody->GetCenterOfMassLocal();
|
||||
m_config.m_inertiaTensor = m_editorBody->GetInverseInertiaLocal();
|
||||
AZ_Error("EditorRigidBodyComponent",
|
||||
m_editorRigidBodyHandle != AzPhysics::InvalidSimulatedBodyHandle, "Failed to create editor rigid body");
|
||||
}
|
||||
|
||||
void EditorRigidBodyComponent::OnColliderChanged()
|
||||
@@ -424,9 +426,7 @@ namespace PhysX
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_rigidBodyHandle);
|
||||
m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
m_editorBody = nullptr;
|
||||
sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorRigidBodyHandle);
|
||||
|
||||
CreateEditorWorldRigidBody();
|
||||
}
|
||||
@@ -436,41 +436,65 @@ namespace PhysX
|
||||
|
||||
void EditorRigidBodyComponent::EnablePhysics()
|
||||
{
|
||||
if (!IsPhysicsEnabled())
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
m_editorBody->SetSimulationEnabled(true);
|
||||
sceneInterface->EnableSimulationOfBody(m_editorSceneHandle, m_editorRigidBodyHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorRigidBodyComponent::DisablePhysics()
|
||||
{
|
||||
m_editorBody->SetSimulationEnabled(false);
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->DisableSimulationOfBody(m_editorSceneHandle, m_editorRigidBodyHandle);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorRigidBodyComponent::IsPhysicsEnabled() const
|
||||
{
|
||||
return m_editorBody && m_editorBody->m_simulating;
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
if (AzPhysics::SimulatedBody* body =
|
||||
sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorRigidBodyHandle))
|
||||
{
|
||||
return body->m_simulating;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::Aabb EditorRigidBodyComponent::GetAabb() const
|
||||
{
|
||||
if (m_editorBody)
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
return m_editorBody->GetAabb();
|
||||
if (AzPhysics::SimulatedBody* body =
|
||||
sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorRigidBodyHandle))
|
||||
{
|
||||
return body->GetAabb();
|
||||
}
|
||||
}
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* EditorRigidBodyComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBody* EditorRigidBodyComponent::GetSimulatedBody()
|
||||
{
|
||||
return m_editorBody;
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
return sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorRigidBodyHandle);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBodyHandle EditorRigidBodyComponent::GetSimulatedBodyHandle() const
|
||||
{
|
||||
return m_editorRigidBodyHandle;
|
||||
}
|
||||
|
||||
AzPhysics::SceneQueryHit EditorRigidBodyComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
{
|
||||
if (m_editorBody)
|
||||
if (AzPhysics::SimulatedBody* body = GetSimulatedBody())
|
||||
{
|
||||
return m_editorBody->RayCast(request);
|
||||
return body->RayCast(request);
|
||||
}
|
||||
return AzPhysics::SceneQueryHit();
|
||||
}
|
||||
@@ -483,7 +507,12 @@ namespace PhysX
|
||||
|
||||
const AzPhysics::RigidBody* EditorRigidBodyComponent::GetRigidBody() const
|
||||
{
|
||||
return m_editorBody;
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
return azdynamic_cast<AzPhysics::RigidBody*>(
|
||||
sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorRigidBodyHandle));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void EditorRigidBodyComponent::SetShouldBeRecreated()
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
#include <AzFramework/Physics/SimulatedBodies/RigidBody.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Components/SimulatedBodyComponentBus.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsEvents.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsTypes.h>
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace PhysX
|
||||
struct EditorRigidBodyConfiguration
|
||||
: public AzPhysics::RigidBodyConfiguration
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR(EditorRigidBodyConfiguration, AZ::SystemAllocator, 0);
|
||||
AZ_RTTI(EditorRigidBodyConfiguration, "{27297024-5A99-4C58-8614-4EF18137CE69}", AzPhysics::RigidBodyConfiguration);
|
||||
AZ_CLASS_ALLOCATOR(PhysX::EditorRigidBodyConfiguration, AZ::SystemAllocator, 0);
|
||||
AZ_RTTI(PhysX::EditorRigidBodyConfiguration, "{27297024-5A99-4C58-8614-4EF18137CE69}", AzPhysics::RigidBodyConfiguration);
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace PhysX
|
||||
, protected AzFramework::EntityDebugDisplayEventBus::Handler
|
||||
, private AZ::TransformNotificationBus::Handler
|
||||
, private Physics::ColliderComponentEventBus::Handler
|
||||
, private Physics::WorldBodyRequestBus::Handler
|
||||
, private AzPhysics::SimulatedBodyComponentRequestsBus::Handler
|
||||
{
|
||||
public:
|
||||
AZ_EDITOR_COMPONENT(EditorRigidBodyComponent, "{F2478E6B-001A-4006-9D7E-DCB5A6B041DD}", AzToolsFramework::Components::EditorComponentBase);
|
||||
@@ -107,12 +107,13 @@ namespace PhysX
|
||||
// Physics::ColliderComponentEventBus
|
||||
void OnColliderChanged() override;
|
||||
|
||||
// WorldBodyRequestBus
|
||||
// AzPhysics::SimulatedBodyComponentRequestsBus::Handler overrides ...
|
||||
void EnablePhysics() override;
|
||||
void DisablePhysics() override;
|
||||
bool IsPhysicsEnabled() const override;
|
||||
AZ::Aabb GetAabb() const override;
|
||||
AzPhysics::SimulatedBody* GetWorldBody() override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBody() override;
|
||||
AzPhysics::SimulatedBodyHandle GetSimulatedBodyHandle() const override;
|
||||
AzPhysics::SceneQueryHit RayCast(const AzPhysics::RayCastRequest& request) override;
|
||||
|
||||
void CreateEditorWorldRigidBody();
|
||||
@@ -126,8 +127,7 @@ namespace PhysX
|
||||
Debug::DebugDisplayDataChangedEvent::Handler m_debugDisplayDataChangeHandler;
|
||||
|
||||
EditorRigidBodyConfiguration m_config;
|
||||
AzPhysics::SimulatedBodyHandle m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
AzPhysics::RigidBody* m_editorBody = nullptr;
|
||||
AzPhysics::SimulatedBodyHandle m_editorRigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
AzPhysics::SceneHandle m_editorSceneHandle = AzPhysics::InvalidSceneHandle;
|
||||
|
||||
AZ::Color m_centerOfMassDebugColor = AZ::Colors::White;
|
||||
|
||||
@@ -83,8 +83,8 @@ namespace PhysX
|
||||
"PhysX Shape Collider", "Creates geometry in the PhysX simulation based on an attached shape component")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/PhysXCollider.svg")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorShapeColliderComponent::m_colliderConfig,
|
||||
@@ -120,8 +120,6 @@ namespace PhysX
|
||||
|
||||
void EditorShapeColliderComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
// Not compatible with Legacy Cry Physics services
|
||||
incompatible.push_back(AZ_CRC("ColliderService", 0x902d4e93));
|
||||
incompatible.push_back(AZ_CRC("LegacyCryPhysicsService", 0xbb370351));
|
||||
incompatible.push_back(AZ_CRC("PhysXShapeColliderService", 0x98a7e779));
|
||||
}
|
||||
@@ -228,7 +226,7 @@ namespace PhysX
|
||||
void EditorShapeColliderComponent::BuildGameEntity(AZ::Entity* gameEntity)
|
||||
{
|
||||
auto* shapeColliderComponent = gameEntity->CreateComponent<ShapeColliderComponent>();
|
||||
Physics::ShapeConfigurationList shapeConfigurationList;
|
||||
AzPhysics::ShapeColliderPairList shapeConfigurationList;
|
||||
shapeConfigurationList.reserve(m_shapeConfigs.size());
|
||||
for (const auto& shapeConfig : m_shapeConfigs)
|
||||
{
|
||||
@@ -259,21 +257,27 @@ namespace PhysX
|
||||
configuration.m_entityId = GetEntityId();
|
||||
configuration.m_debugName = GetEntity()->GetName();
|
||||
|
||||
AZStd::vector<AzPhysics::ShapeColliderPair> colliderShapePairs;
|
||||
AzPhysics::ShapeColliderPairList colliderShapePairs;
|
||||
colliderShapePairs.reserve(m_shapeConfigs.size());
|
||||
for (const auto& shapeConfig : m_shapeConfigs)
|
||||
{
|
||||
colliderShapePairs.emplace_back(&m_colliderConfig, shapeConfig.get());
|
||||
colliderShapePairs.emplace_back(
|
||||
AZStd::make_shared<Physics::ColliderConfiguration>(m_colliderConfig), shapeConfig);
|
||||
}
|
||||
configuration.m_colliderAndShapeData = colliderShapePairs;
|
||||
|
||||
if (m_sceneInterface)
|
||||
{
|
||||
//remove the previous body if any
|
||||
if (m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
m_sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
}
|
||||
|
||||
m_editorBodyHandle = m_sceneInterface->AddSimulatedBody(m_editorSceneHandle, &configuration);
|
||||
m_editorBody = azdynamic_cast<StaticRigidBody*>(m_sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorBodyHandle));
|
||||
}
|
||||
|
||||
Physics::WorldBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusConnect(GetEntityId());
|
||||
}
|
||||
|
||||
AZ::u32 EditorShapeColliderComponent::OnConfigurationChanged()
|
||||
@@ -323,6 +327,7 @@ namespace PhysX
|
||||
else
|
||||
{
|
||||
m_shapeType = !shapeCrc ? ShapeType::None : ShapeType::Unsupported;
|
||||
m_shapeConfigs.clear();
|
||||
AZ_Warning("PhysX Shape Collider Component", m_shapeTypeWarningIssued, "Unsupported shape type for "
|
||||
"entity \"%s\". The following shapes are currently supported - box, capsule, sphere, polygon prism.",
|
||||
GetEntity()->GetName().c_str());
|
||||
@@ -663,7 +668,7 @@ namespace PhysX
|
||||
|
||||
void EditorShapeColliderComponent::Deactivate()
|
||||
{
|
||||
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusDisconnect();
|
||||
m_colliderDebugDraw.Disconnect();
|
||||
|
||||
m_nonUniformScaleChangedHandler.Disconnect();
|
||||
@@ -677,8 +682,6 @@ namespace PhysX
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
m_sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
m_editorBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
m_editorBody = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,28 +752,53 @@ namespace PhysX
|
||||
|
||||
bool EditorShapeColliderComponent::IsPhysicsEnabled() const
|
||||
{
|
||||
return m_editorBody != nullptr && m_editorBody->m_simulating;
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
if (auto* body = m_sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorBodyHandle))
|
||||
{
|
||||
return body->m_simulating;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::Aabb EditorShapeColliderComponent::GetAabb() const
|
||||
{
|
||||
if (m_editorBody)
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
return m_editorBody->GetAabb();
|
||||
if (auto* body = m_sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorBodyHandle))
|
||||
{
|
||||
return body->GetAabb();
|
||||
}
|
||||
}
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* EditorShapeColliderComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBody* EditorShapeColliderComponent::GetSimulatedBody()
|
||||
{
|
||||
return m_editorBody;
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
if (auto* body = m_sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorBodyHandle))
|
||||
{
|
||||
return body;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBodyHandle EditorShapeColliderComponent::GetSimulatedBodyHandle() const
|
||||
{
|
||||
return m_editorBodyHandle;
|
||||
}
|
||||
|
||||
AzPhysics::SceneQueryHit EditorShapeColliderComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
{
|
||||
if (m_editorBody)
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
return m_editorBody->RayCast(request);
|
||||
if (auto* body = m_sceneInterface->GetSimulatedBodyFromHandle(m_editorSceneHandle, m_editorBodyHandle))
|
||||
{
|
||||
return body->RayCast(request);
|
||||
}
|
||||
}
|
||||
return AzPhysics::SceneQueryHit();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <AzCore/Component/NonUniformScaleBus.h>
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
#include <AzFramework/Physics/Shape.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Components/SimulatedBodyComponentBus.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsEvents.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsTypes.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
@@ -68,7 +68,7 @@ namespace PhysX
|
||||
, protected DebugDraw::DisplayCallback
|
||||
, protected LmbrCentral::ShapeComponentNotificationsBus::Handler
|
||||
, private PhysX::ColliderShapeRequestBus::Handler
|
||||
, protected Physics::WorldBodyRequestBus::Handler
|
||||
, protected AzPhysics::SimulatedBodyComponentRequestsBus::Handler
|
||||
{
|
||||
public:
|
||||
AZ_EDITOR_COMPONENT(EditorShapeColliderComponent, "{2389DDC7-871B-42C6-9C95-2A679DDA0158}",
|
||||
@@ -120,12 +120,13 @@ namespace PhysX
|
||||
// handling for non-uniform scale
|
||||
void OnNonUniformScaleChanged(const AZ::Vector3& scale);
|
||||
|
||||
// WorldBodyRequestBus
|
||||
// AzPhysics::SimulatedBodyComponentRequestsBus::Handler overrides ...
|
||||
void EnablePhysics() override;
|
||||
void DisablePhysics() override;
|
||||
bool IsPhysicsEnabled() const override;
|
||||
AZ::Aabb GetAabb() const override;
|
||||
AzPhysics::SimulatedBody* GetWorldBody() override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBody() override;
|
||||
AzPhysics::SimulatedBodyHandle GetSimulatedBodyHandle() const override;
|
||||
AzPhysics::SceneQueryHit RayCast(const AzPhysics::RayCastRequest& request) override;
|
||||
|
||||
// LmbrCentral::ShapeComponentNotificationBus
|
||||
@@ -142,7 +143,6 @@ namespace PhysX
|
||||
DebugDraw::Collider m_colliderDebugDraw; //!< Handles drawing the collider based on global and local
|
||||
AzPhysics::SceneInterface* m_sceneInterface = nullptr;
|
||||
AzPhysics::SceneHandle m_editorSceneHandle = AzPhysics::InvalidSceneHandle;
|
||||
StaticRigidBody* m_editorBody = nullptr; //!< Body in the editor physics scene if there is no rigid body component.
|
||||
AzPhysics::SimulatedBodyHandle m_editorBodyHandle = AzPhysics::InvalidSimulatedBodyHandle; //!< Handle to the body in the editor physics scene if there is no rigid body component.
|
||||
bool m_shapeTypeWarningIssued = false; //!< Records whether a warning about unsupported shapes has been previously issued.
|
||||
PolygonPrismMeshUtils::Mesh2D m_mesh; //!< Used for storing decompositions of the polygon prism.
|
||||
|
||||
@@ -343,7 +343,6 @@ namespace PhysX
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_sceneOwner, m_shadowBodyHandle);
|
||||
m_shadowBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
m_shadowBody = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,19 +167,18 @@ namespace PhysX
|
||||
return aznew CharacterController(pxController, AZStd::move(callbackManager), scene->GetSceneHandle());
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<Ragdoll> CreateRagdoll(Physics::RagdollConfiguration& configuration,
|
||||
const Physics::RagdollState& initialState, const ParentIndices& parentIndices, AzPhysics::SceneHandle sceneHandle)
|
||||
Ragdoll* CreateRagdoll(Physics::RagdollConfiguration& configuration, AzPhysics::SceneHandle sceneHandle)
|
||||
{
|
||||
const size_t numNodes = configuration.m_nodes.size();
|
||||
if (numNodes != initialState.size())
|
||||
if (numNodes != configuration.m_initialState.size())
|
||||
{
|
||||
AZ_Error("PhysX Ragdoll", false, "Mismatch between number of nodes in ragdoll configuration (%i) "
|
||||
"and number of nodes in the initial ragdoll state (%i)", numNodes, initialState.size());
|
||||
"and number of nodes in the initial ragdoll state (%i)", numNodes, configuration.m_initialState.size());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<Ragdoll> ragdoll = AZStd::make_unique<Ragdoll>(sceneHandle);
|
||||
ragdoll->SetParentIndices(parentIndices);
|
||||
ragdoll->SetParentIndices(configuration.m_parentIndices);
|
||||
|
||||
auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
|
||||
if (sceneInterface == nullptr)
|
||||
@@ -192,15 +191,21 @@ namespace PhysX
|
||||
for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++)
|
||||
{
|
||||
Physics::RagdollNodeConfiguration& nodeConfig = configuration.m_nodes[nodeIndex];
|
||||
const Physics::RagdollNodeState& nodeState = initialState[nodeIndex];
|
||||
const Physics::RagdollNodeState& nodeState = configuration.m_initialState[nodeIndex];
|
||||
|
||||
Physics::CharacterColliderNodeConfiguration* colliderNodeConfig = configuration.m_colliders.FindNodeConfigByName(nodeConfig.m_debugName);
|
||||
if (colliderNodeConfig)
|
||||
{
|
||||
AZStd::vector<AZStd::shared_ptr<Physics::Shape>> shapes;
|
||||
for (const auto& shapeConfig : colliderNodeConfig->m_shapes)
|
||||
for (const auto& [colliderConfig, shapeConfig] : colliderNodeConfig->m_shapes)
|
||||
{
|
||||
if (auto shape = AZStd::make_shared<Shape>(*shapeConfig.first, *shapeConfig.second))
|
||||
if (colliderConfig == nullptr || shapeConfig == nullptr)
|
||||
{
|
||||
AZ_Error("PhysX Ragdoll", false, "Failed to create collider shape for ragdoll node %s", nodeConfig.m_debugName.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (auto shape = AZStd::make_shared<Shape>(*colliderConfig, *shapeConfig))
|
||||
{
|
||||
shapes.emplace_back(shape);
|
||||
}
|
||||
@@ -212,22 +217,20 @@ namespace PhysX
|
||||
}
|
||||
nodeConfig.m_colliderAndShapeData = shapes;
|
||||
}
|
||||
nodeConfig.m_startSimulationEnabled = false;
|
||||
nodeConfig.m_position = nodeState.m_position;
|
||||
nodeConfig.m_orientation = nodeState.m_orientation;
|
||||
|
||||
AzPhysics::SimulatedBodyHandle newBodyHandle = sceneInterface->AddSimulatedBody(sceneHandle, &nodeConfig);
|
||||
if (newBodyHandle == AzPhysics::InvalidSimulatedBodyHandle)
|
||||
AZStd::unique_ptr<RagdollNode> node = AZStd::make_unique<RagdollNode>(sceneHandle, nodeConfig);
|
||||
if (node->GetRigidBodyHandle() != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
ragdoll->AddNode(AZStd::move(node));
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error("PhysX Ragdoll", false, "Failed to create rigid body for ragdoll node %s", nodeConfig.m_debugName.c_str());
|
||||
return nullptr;
|
||||
node.reset();
|
||||
}
|
||||
sceneInterface->DisableSimulationOfBody(sceneHandle, newBodyHandle);
|
||||
auto* rigidBody = azdynamic_cast<AzPhysics::RigidBody*>(sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, newBodyHandle));
|
||||
|
||||
physx::PxRigidDynamic* pxRigidDynamic = static_cast<physx::PxRigidDynamic*>(rigidBody->GetNativePointer());
|
||||
physx::PxTransform transform(PxMathConvert(nodeState.m_position), PxMathConvert(nodeState.m_orientation));
|
||||
pxRigidDynamic->setGlobalPose(transform);
|
||||
|
||||
AZStd::unique_ptr<RagdollNode> node = AZStd::make_unique<RagdollNode>(rigidBody, newBodyHandle);
|
||||
ragdoll->AddNode(AZStd::move(node));
|
||||
}
|
||||
|
||||
// Set up joints. Needs a second pass because child nodes in the ragdoll config aren't guaranteed to have
|
||||
@@ -235,7 +238,7 @@ namespace PhysX
|
||||
size_t rootIndex = SIZE_MAX;
|
||||
for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++)
|
||||
{
|
||||
size_t parentIndex = parentIndices[nodeIndex];
|
||||
size_t parentIndex = configuration.m_parentIndices[nodeIndex];
|
||||
if (parentIndex < numNodes)
|
||||
{
|
||||
physx::PxRigidDynamic* parentActor = ragdoll->GetPxRigidDynamic(parentIndex);
|
||||
@@ -301,8 +304,8 @@ namespace PhysX
|
||||
}
|
||||
|
||||
ragdoll->SetRootIndex(rootIndex);
|
||||
|
||||
return ragdoll;
|
||||
|
||||
return ragdoll.release();
|
||||
}
|
||||
|
||||
physx::PxD6JointDrive CreateD6JointDrive(float stiffness, float dampingRatio, float forceLimit)
|
||||
|
||||
@@ -40,11 +40,8 @@ namespace PhysX
|
||||
|
||||
//! Creates a ragdoll based on the specified setup and initial pose.
|
||||
//! @param configuration Information about collider geometry and joint setup required to initialize the ragdoll.
|
||||
//! @param initialState Initial settings for the positions, orientations and velocities of the ragdoll nodes.
|
||||
//! @param parentIndices Identifies the parent ragdoll node for each node in the ragdoll.
|
||||
//! @param sceneHandle A handle to the physics scene in which the ragdoll should be created.
|
||||
AZStd::unique_ptr<Ragdoll> CreateRagdoll(Physics::RagdollConfiguration& configuration,
|
||||
const Physics::RagdollState& initialState, const ParentIndices& parentIndices, AzPhysics::SceneHandle sceneHandle);
|
||||
Ragdoll* CreateRagdoll(Physics::RagdollConfiguration& configuration, AzPhysics::SceneHandle sceneHandle);
|
||||
|
||||
//! Creates a joint drive with properties based on the input values.
|
||||
//! The input values are validated and the damping ratio is used to calculate the damping value used internally.
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace PhysX
|
||||
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<Ragdoll>()
|
||||
serializeContext->Class<PhysX::Ragdoll, Physics::Ragdoll>()
|
||||
->Version(1)
|
||||
;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace PhysX
|
||||
m_nodes.push_back(AZStd::move(node));
|
||||
}
|
||||
|
||||
void Ragdoll::SetParentIndices(const ParentIndices& parentIndices)
|
||||
void Ragdoll::SetParentIndices(const Physics::ParentIndices& parentIndices)
|
||||
{
|
||||
m_parentIndices = parentIndices;
|
||||
}
|
||||
@@ -109,7 +109,6 @@ namespace PhysX
|
||||
this->ApplyQueuedDisableSimulation();
|
||||
})
|
||||
{
|
||||
m_simulating = false;
|
||||
m_sceneOwner = sceneHandle;
|
||||
}
|
||||
|
||||
@@ -117,14 +116,7 @@ namespace PhysX
|
||||
{
|
||||
m_sceneStartSimHandler.Disconnect();
|
||||
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
const size_t numNodes = m_nodes.size();
|
||||
for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++)
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_sceneOwner, m_nodes[nodeIndex]->GetRigidBodyHandle());
|
||||
}
|
||||
}
|
||||
m_nodes.clear(); //the nodes destructor will remove the simulated body from the scene.
|
||||
}
|
||||
|
||||
void Ragdoll::ApplyQueuedEnableSimulation()
|
||||
@@ -204,7 +196,6 @@ namespace PhysX
|
||||
|
||||
sceneInterface->EnableSimulationOfBody(m_sceneOwner, m_nodes[nodeIndex]->GetRigidBodyHandle());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
AZ_Error("PhysX Ragdoll", false, "Invalid PhysX actor for node index %i", nodeIndex);
|
||||
@@ -222,8 +213,7 @@ namespace PhysX
|
||||
}
|
||||
|
||||
sceneInterface->RegisterSceneSimulationStartHandler(m_sceneOwner, m_sceneStartSimHandler);
|
||||
|
||||
m_simulating = true;
|
||||
sceneInterface->EnableSimulationOfBody(m_sceneOwner, m_bodyHandle);
|
||||
}
|
||||
|
||||
void Ragdoll::EnableSimulationQueued(const Physics::RagdollState& initialState)
|
||||
@@ -276,7 +266,7 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
m_simulating = false;
|
||||
sceneInterface->DisableSimulationOfBody(m_sceneOwner, m_bodyHandle);
|
||||
}
|
||||
|
||||
void Ragdoll::DisableSimulationQueued()
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
namespace PhysX
|
||||
{
|
||||
using ParentIndices = AZStd::vector<size_t>;
|
||||
|
||||
/// PhysX specific implementation of generic physics API Ragdoll class.
|
||||
class Ragdoll
|
||||
: public Physics::Ragdoll
|
||||
@@ -29,7 +27,7 @@ namespace PhysX
|
||||
friend class RagdollComponent;
|
||||
|
||||
AZ_CLASS_ALLOCATOR(Ragdoll, AZ::SystemAllocator, 0);
|
||||
AZ_TYPE_INFO_LEGACY(PhysX::Ragdoll, "{55D477B5-B922-4D3E-89FE-7FB7B9FDD635}", Physics::Ragdoll);
|
||||
AZ_RTTI(PhysX::Ragdoll, "{55D477B5-B922-4D3E-89FE-7FB7B9FDD635}", Physics::Ragdoll);
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
Ragdoll() = default;
|
||||
@@ -38,7 +36,7 @@ namespace PhysX
|
||||
~Ragdoll();
|
||||
|
||||
void AddNode(AZStd::unique_ptr<RagdollNode> node);
|
||||
void SetParentIndices(const ParentIndices& parentIndices);
|
||||
void SetParentIndices(const Physics::ParentIndices& parentIndices);
|
||||
void SetRootIndex(size_t nodeIndex);
|
||||
physx::PxRigidDynamic* GetPxRigidDynamic(size_t nodeIndex) const;
|
||||
physx::PxTransform GetRootPxTransform() const;
|
||||
@@ -75,7 +73,7 @@ namespace PhysX
|
||||
void ApplyQueuedDisableSimulation();
|
||||
|
||||
AZStd::vector<AZStd::unique_ptr<RagdollNode>> m_nodes;
|
||||
ParentIndices m_parentIndices;
|
||||
Physics::ParentIndices m_parentIndices;
|
||||
AZ::Outcome<size_t> m_rootIndex = AZ::Failure();
|
||||
|
||||
/// Queued initial state for the ragdoll, for EnableSimulationQueued, to be applied prior to the world update.
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <PhysX_precompiled.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzFramework/Physics/PhysicsScene.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsSceneQueries.h>
|
||||
#include <PhysXCharacters/API/RagdollNode.h>
|
||||
#include <PhysX/NativeTypeIdentifiers.h>
|
||||
@@ -30,14 +31,14 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
RagdollNode::RagdollNode(AzPhysics::RigidBody* rigidBody, AzPhysics::SimulatedBodyHandle rigidBodyHandle)
|
||||
: m_rigidBody(rigidBody)
|
||||
, m_rigidBodyHandle(rigidBodyHandle)
|
||||
RagdollNode::RagdollNode(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig)
|
||||
{
|
||||
physx::PxRigidDynamic* pxRigidDynamic = static_cast<physx::PxRigidDynamic*>(m_rigidBody->GetNativePointer());
|
||||
m_actorUserData = PhysX::ActorData(pxRigidDynamic);
|
||||
m_actorUserData.SetRagdollNode(this);
|
||||
m_actorUserData.SetEntityId(m_rigidBody->GetEntityId());
|
||||
CreatePhysicsBody(sceneHandle, nodeConfig);
|
||||
}
|
||||
|
||||
RagdollNode::~RagdollNode()
|
||||
{
|
||||
DestroyPhysicsBody();
|
||||
}
|
||||
|
||||
void RagdollNode::SetJoint(const AZStd::shared_ptr<Physics::Joint>& joint)
|
||||
@@ -124,4 +125,46 @@ namespace PhysX
|
||||
{
|
||||
return m_rigidBodyHandle;
|
||||
}
|
||||
|
||||
void RagdollNode::CreatePhysicsBody(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig)
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
m_rigidBodyHandle = sceneInterface->AddSimulatedBody(sceneHandle, &nodeConfig);
|
||||
if (m_rigidBodyHandle == AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
AZ_Error("PhysX RagdollNode", false, "Failed to create rigid body for ragdoll node %s", nodeConfig.m_debugName.c_str());
|
||||
return;
|
||||
}
|
||||
m_rigidBody = azdynamic_cast<AzPhysics::RigidBody*>(sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, m_rigidBodyHandle));
|
||||
}
|
||||
if (m_rigidBody == nullptr)
|
||||
{
|
||||
AZ_Error("PhysX RagdollNode", false, "Failed to create rigid body for ragdoll node %s", nodeConfig.m_debugName.c_str());
|
||||
return;
|
||||
}
|
||||
m_sceneOwner = sceneHandle;
|
||||
|
||||
physx::PxRigidDynamic* pxRigidDynamic = static_cast<physx::PxRigidDynamic*>(m_rigidBody->GetNativePointer());
|
||||
physx::PxTransform transform(PxMathConvert(nodeConfig.m_position), PxMathConvert(nodeConfig.m_orientation));
|
||||
pxRigidDynamic->setGlobalPose(transform);
|
||||
|
||||
m_actorUserData = PhysX::ActorData(pxRigidDynamic);
|
||||
m_actorUserData.SetRagdollNode(this);
|
||||
m_actorUserData.SetEntityId(m_rigidBody->GetEntityId());
|
||||
}
|
||||
|
||||
void RagdollNode::DestroyPhysicsBody()
|
||||
{
|
||||
if (m_rigidBody != nullptr)
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_sceneOwner, m_rigidBodyHandle);
|
||||
}
|
||||
m_rigidBody = nullptr;
|
||||
m_sceneOwner = AzPhysics::InvalidSceneHandle;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace PhysX
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace PhysX
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
RagdollNode() = default;
|
||||
explicit RagdollNode(AzPhysics::RigidBody* rigidBody, AzPhysics::SimulatedBodyHandle rigidBodyHandle);
|
||||
~RagdollNode() = default;
|
||||
explicit RagdollNode(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig);
|
||||
~RagdollNode();
|
||||
|
||||
void SetJoint(const AZStd::shared_ptr<Physics::Joint>& joint);
|
||||
|
||||
@@ -58,9 +58,13 @@ namespace PhysX
|
||||
AzPhysics::SimulatedBodyHandle GetRigidBodyHandle() const;
|
||||
|
||||
private:
|
||||
void CreatePhysicsBody(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig);
|
||||
void DestroyPhysicsBody();
|
||||
|
||||
AZStd::shared_ptr<Physics::Joint> m_joint;
|
||||
AzPhysics::RigidBody* m_rigidBody;
|
||||
AzPhysics::SimulatedBodyHandle m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
AzPhysics::SceneHandle m_sceneOwner = AzPhysics::InvalidSceneHandle;
|
||||
PhysX::ActorData m_actorUserData;
|
||||
};
|
||||
} // namespace PhysX
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace PhysX
|
||||
AZ::TransformNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
Physics::CharacterRequestBus::Handler::BusConnect(GetEntityId());
|
||||
Physics::CollisionFilteringRequestBus::Handler::BusConnect(GetEntityId());
|
||||
Physics::WorldBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusConnect(GetEntityId());
|
||||
}
|
||||
|
||||
void CharacterControllerComponent::Deactivate()
|
||||
@@ -95,7 +95,7 @@ namespace PhysX
|
||||
DestroyController();
|
||||
|
||||
Physics::CollisionFilteringRequestBus::Handler::BusDisconnect();
|
||||
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusDisconnect();
|
||||
AZ::TransformNotificationBus::Handler::BusDisconnect();
|
||||
Physics::CharacterRequestBus::Handler::BusDisconnect();
|
||||
}
|
||||
@@ -215,11 +215,20 @@ namespace PhysX
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* CharacterControllerComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBody* CharacterControllerComponent::GetSimulatedBody()
|
||||
{
|
||||
return GetCharacter();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBodyHandle CharacterControllerComponent::GetSimulatedBodyHandle() const
|
||||
{
|
||||
if (m_controller)
|
||||
{
|
||||
return m_controller->m_bodyHandle;
|
||||
}
|
||||
return AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
|
||||
AzPhysics::SceneQueryHit CharacterControllerComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
{
|
||||
if (m_controller)
|
||||
@@ -412,7 +421,6 @@ namespace PhysX
|
||||
AZ::TransformBus::EventResult(entityTranslation, GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation);
|
||||
m_characterConfig->m_position = entityTranslation;
|
||||
|
||||
AZ_Assert(m_controller == nullptr, "Calling create CharacterControllerComponent::CreateController() with an already created controller.");
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
AzPhysics::SimulatedBodyHandle bodyHandle = sceneInterface->AddSimulatedBody(defaultSceneHandle, m_characterConfig.get());
|
||||
@@ -451,13 +459,11 @@ namespace PhysX
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_controller->m_sceneOwner, m_controller->m_bodyHandle);
|
||||
m_controller = nullptr;
|
||||
}
|
||||
m_controller = nullptr;
|
||||
|
||||
m_preSimulateHandler.Disconnect();
|
||||
|
||||
CharacterControllerRequestBus::Handler::BusDisconnect();
|
||||
|
||||
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsDisabled);
|
||||
}
|
||||
} // namespace PhysX
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <AzFramework/Physics/CharacterBus.h>
|
||||
#include <AzFramework/Physics/SystemBus.h>
|
||||
#include <AzFramework/Physics/CollisionBus.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Components/SimulatedBodyComponentBus.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsEvents.h>
|
||||
#include <PhysXCharacters/API/CharacterController.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
@@ -35,7 +35,7 @@ namespace PhysX
|
||||
class CharacterControllerComponent
|
||||
: public AZ::Component
|
||||
, public Physics::CharacterRequestBus::Handler
|
||||
, public Physics::WorldBodyRequestBus::Handler
|
||||
, public AzPhysics::SimulatedBodyComponentRequestsBus::Handler
|
||||
, public AZ::TransformNotificationBus::Handler
|
||||
, public CharacterControllerRequestBus::Handler
|
||||
, public Physics::CollisionFilteringRequestBus::Handler
|
||||
@@ -59,6 +59,7 @@ namespace PhysX
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC("PhysXCharacterControllerService", 0x428de4fa));
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
@@ -99,12 +100,13 @@ namespace PhysX
|
||||
bool IsPresent() const override { return IsPhysicsEnabled(); }
|
||||
Physics::Character* GetCharacter() override;
|
||||
|
||||
// WorldBodyRequestBus
|
||||
// AzPhysics::SimulatedBodyComponentRequestsBus::Handler overrides ...
|
||||
void EnablePhysics() override;
|
||||
void DisablePhysics() override;
|
||||
bool IsPhysicsEnabled() const override;
|
||||
AZ::Aabb GetAabb() const override;
|
||||
AzPhysics::SimulatedBody* GetWorldBody() override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBody() override;
|
||||
AzPhysics::SimulatedBodyHandle GetSimulatedBodyHandle() const override;
|
||||
AzPhysics::SceneQueryHit RayCast(const AzPhysics::RayCastRequest& request) override;
|
||||
|
||||
// CharacterControllerRequestBus
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <PhysX_precompiled.h>
|
||||
#include <PhysXCharacters/Components/CharacterGameplayComponent.h>
|
||||
#include <AzFramework/Physics/CharacterBus.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <PhysX/PhysXLocks.h>
|
||||
@@ -52,6 +51,7 @@ namespace PhysX
|
||||
void CharacterGameplayComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC("PhysXCharacterGameplayService", 0xfacd7876));
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void CharacterGameplayComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
@@ -158,7 +158,7 @@ namespace PhysX
|
||||
void CharacterGameplayComponent::Activate()
|
||||
{
|
||||
AzPhysics::SimulatedBody* worldBody = nullptr;
|
||||
Physics::WorldBodyRequestBus::EventResult(worldBody, GetEntityId(), &Physics::WorldBodyRequests::GetWorldBody);
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::EventResult(worldBody, GetEntityId(), &AzPhysics::SimulatedBodyComponentRequests::GetSimulatedBody);
|
||||
if (worldBody)
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
|
||||
+2
-2
@@ -101,8 +101,8 @@ namespace PhysX
|
||||
"PhysX Character Controller", "PhysX Character Controller")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorCharacterControllerComponent::m_configuration,
|
||||
"Configuration", "Configuration for the character controller")
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace PhysX
|
||||
incompatible.push_back(AZ_CRC("PhysXCharacterControllerService", 0x428de4fa));
|
||||
incompatible.push_back(AZ_CRC("LegacyCryPhysicsService", 0xbb370351));
|
||||
incompatible.push_back(AZ_CRC("PhysXRigidBodyService", 0x1d4c64a8));
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
|
||||
+3
-2
@@ -23,6 +23,7 @@ namespace PhysX
|
||||
void EditorCharacterGameplayComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC("PhysXCharacterGameplayService", 0xfacd7876));
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void EditorCharacterGameplayComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
@@ -49,8 +50,8 @@ namespace PhysX
|
||||
"PhysX Character Gameplay", "PhysX Character Gameplay")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/PhysXCharacter.svg")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorCharacterGameplayComponent::m_gameplayConfig,
|
||||
"Gameplay Configuration", "Gameplay Configuration")
|
||||
|
||||
@@ -55,6 +55,16 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
if (classElement.GetVersion() < 3)
|
||||
{
|
||||
int ragdollElementIndex = classElement.FindElement(AZ_CRC_CE("PhysXRagdoll"));
|
||||
|
||||
if (ragdollElementIndex >= 0)
|
||||
{
|
||||
classElement.RemoveElement(ragdollElementIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,8 +76,7 @@ namespace PhysX
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<RagdollComponent, AZ::Component>()
|
||||
->Version(2, &VersionConverter)
|
||||
->Field("PhysXRagdoll", &RagdollComponent::m_ragdoll)
|
||||
->Version(3, &VersionConverter)
|
||||
->Field("PositionIterations", &RagdollComponent::m_positionIterations)
|
||||
->Field("VelocityIterations", &RagdollComponent::m_velocityIterations)
|
||||
->Field("EnableJointProjection", &RagdollComponent::m_enableJointProjection)
|
||||
@@ -82,8 +91,8 @@ namespace PhysX
|
||||
"PhysX Ragdoll", "Provides simulation of characters in PhysX.")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/PhysXRagdoll.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/PhysXRagdoll.svg")
|
||||
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/PhysXRagdoll.svg")
|
||||
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/PhysXRagdoll.svg")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &RagdollComponent::m_positionIterations, "Position Iteration Count",
|
||||
@@ -187,7 +196,7 @@ namespace PhysX
|
||||
|
||||
Physics::Ragdoll* RagdollComponent::GetRagdoll()
|
||||
{
|
||||
return m_ragdoll.get();
|
||||
return m_ragdoll;
|
||||
}
|
||||
|
||||
void RagdollComponent::GetState(Physics::RagdollState& ragdollState) const
|
||||
@@ -248,9 +257,18 @@ namespace PhysX
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* RagdollComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBody* RagdollComponent::GetSimulatedBody()
|
||||
{
|
||||
return m_ragdoll.get();
|
||||
return GetRagdoll();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBodyHandle RagdollComponent::GetSimulatedBodyHandle() const
|
||||
{
|
||||
if (m_ragdoll)
|
||||
{
|
||||
return m_ragdoll->m_bodyHandle;
|
||||
}
|
||||
return AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
|
||||
AzPhysics::SceneQueryHit RagdollComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
@@ -283,8 +301,8 @@ namespace PhysX
|
||||
return;
|
||||
}
|
||||
|
||||
ParentIndices parentIndices;
|
||||
parentIndices.resize(numNodes);
|
||||
|
||||
ragdollConfiguration.m_parentIndices.resize(numNodes);
|
||||
for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++)
|
||||
{
|
||||
AZStd::string parentName;
|
||||
@@ -292,7 +310,7 @@ namespace PhysX
|
||||
AzFramework::CharacterPhysicsDataRequestBus::EventResult(parentName, GetEntityId(),
|
||||
&AzFramework::CharacterPhysicsDataRequests::GetParentNodeName, nodeName);
|
||||
AZ::Outcome<size_t> parentIndex = Utils::Characters::GetNodeIndex(ragdollConfiguration, parentName);
|
||||
parentIndices[nodeIndex] = parentIndex ? parentIndex.GetValue() : SIZE_MAX;
|
||||
ragdollConfiguration.m_parentIndices[nodeIndex] = parentIndex ? parentIndex.GetValue() : SIZE_MAX;
|
||||
|
||||
ragdollConfiguration.m_nodes[nodeIndex].m_entityId = GetEntityId();
|
||||
}
|
||||
@@ -303,12 +321,17 @@ namespace PhysX
|
||||
|
||||
AZ::Transform entityTransform = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(entityTransform, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
|
||||
Physics::RagdollState bindPoseWorld = GetBindPoseWorld(bindPose, entityTransform);
|
||||
ragdollConfiguration.m_initialState = GetBindPoseWorld(bindPose, entityTransform);
|
||||
|
||||
AzPhysics::SceneHandle defaultSceneHandle = AzPhysics::InvalidSceneHandle;
|
||||
Physics::DefaultWorldBus::BroadcastResult(defaultSceneHandle, &Physics::DefaultWorldRequests::GetDefaultSceneHandle);
|
||||
m_ragdoll = Utils::Characters::CreateRagdoll(ragdollConfiguration, bindPoseWorld, parentIndices, defaultSceneHandle);
|
||||
if (!m_ragdoll)
|
||||
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
AzPhysics::SimulatedBodyHandle bodyHandle = sceneInterface->AddSimulatedBody(defaultSceneHandle, &ragdollConfiguration);
|
||||
m_ragdoll = azdynamic_cast<PhysX::Ragdoll*>(sceneInterface->GetSimulatedBodyFromHandle(defaultSceneHandle, bodyHandle));
|
||||
}
|
||||
if (m_ragdoll == nullptr)
|
||||
{
|
||||
AZ_Error("PhysX Ragdoll Component", false, "Failed to create ragdoll.");
|
||||
return;
|
||||
@@ -343,7 +366,7 @@ namespace PhysX
|
||||
}
|
||||
|
||||
AzFramework::RagdollPhysicsRequestBus::Handler::BusConnect(GetEntityId());
|
||||
Physics::WorldBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusConnect(GetEntityId());
|
||||
|
||||
AzFramework::RagdollPhysicsNotificationBus::Event(GetEntityId(),
|
||||
&AzFramework::RagdollPhysicsNotifications::OnRagdollActivated);
|
||||
@@ -353,12 +376,15 @@ namespace PhysX
|
||||
{
|
||||
if (m_ragdoll)
|
||||
{
|
||||
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
|
||||
AzFramework::RagdollPhysicsRequestBus::Handler::BusDisconnect();
|
||||
AzFramework::RagdollPhysicsNotificationBus::Event(GetEntityId(),
|
||||
&AzFramework::RagdollPhysicsNotifications::OnRagdollDeactivated);
|
||||
|
||||
m_ragdoll.reset();
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_ragdoll->m_sceneOwner, m_ragdoll->m_bodyHandle);
|
||||
}
|
||||
m_ragdoll = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <PhysXCharacters/API/Ragdoll.h>
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzFramework/Physics/CharacterPhysicsDataBus.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Components/SimulatedBodyComponentBus.h>
|
||||
|
||||
namespace AzPhysics
|
||||
{
|
||||
@@ -28,11 +28,11 @@ namespace PhysX
|
||||
class RagdollComponent
|
||||
: public AZ::Component
|
||||
, public AzFramework::RagdollPhysicsRequestBus::Handler
|
||||
, public Physics::WorldBodyRequestBus::Handler
|
||||
, public AzPhysics::SimulatedBodyComponentRequestsBus::Handler
|
||||
, public AzFramework::CharacterPhysicsDataNotificationBus::Handler
|
||||
{
|
||||
public:
|
||||
AZ_COMPONENT(RagdollComponent, "{B89498F8-4718-42FE-A457-A377DD0D61A0}");
|
||||
AZ_COMPONENT(PhysX::RagdollComponent, "{B89498F8-4718-42FE-A457-A377DD0D61A0}");
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace PhysX
|
||||
{
|
||||
incompatible.push_back(AZ_CRC("PhysXRagdollService", 0x6d889c70));
|
||||
incompatible.push_back(AZ_CRC("LegacyCryPhysicsService", 0xbb370351));
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
@@ -81,12 +82,13 @@ namespace PhysX
|
||||
void SetNodeState(size_t nodeIndex, const Physics::RagdollNodeState& nodeState) override;
|
||||
Physics::RagdollNode* GetNode(size_t nodeIndex) const override;
|
||||
|
||||
// WorldBodyRequestBus
|
||||
// AzPhysics::SimulatedBodyComponentRequestsBus::Handler overrides ...
|
||||
void EnablePhysics() override;
|
||||
void DisablePhysics() override;
|
||||
bool IsPhysicsEnabled() const override;
|
||||
AZ::Aabb GetAabb() const override;
|
||||
AzPhysics::SimulatedBody* GetWorldBody() override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBody() override;
|
||||
AzPhysics::SimulatedBodyHandle GetSimulatedBodyHandle() const override;
|
||||
AzPhysics::SceneQueryHit RayCast(const AzPhysics::RayCastRequest& request) override;
|
||||
|
||||
// CharacterPhysicsDataNotificationBus
|
||||
@@ -105,7 +107,7 @@ namespace PhysX
|
||||
|
||||
bool IsJointProjectionVisible();
|
||||
|
||||
AZStd::unique_ptr<Ragdoll> m_ragdoll;
|
||||
Ragdoll* m_ragdoll;
|
||||
/// Minimum number of position iterations to perform in the PhysX solver.
|
||||
/// Lower iteration counts are less expensive but may behave less realistically.
|
||||
AZ::u32 m_positionIterations = 16;
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace PhysX
|
||||
|
||||
const char* HeightFieldAssetHandler::GetBrowserIcon() const
|
||||
{
|
||||
return "Editor/Icons/Components/ColliderMesh.svg";
|
||||
return "Icons/Components/ColliderMesh.svg";
|
||||
}
|
||||
|
||||
const char* HeightFieldAssetHandler::GetGroup() const
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace PhysX
|
||||
|
||||
const char* MeshAssetHandler::GetBrowserIcon() const
|
||||
{
|
||||
return "Editor/Icons/Components/ColliderMesh.svg";
|
||||
return "Icons/Components/ColliderMesh.svg";
|
||||
}
|
||||
|
||||
const char* MeshAssetHandler::GetGroup() const
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
set(PAL_TRAIT_PHYSX_SUPPORTED TRUE)
|
||||
|
||||
@@ -82,12 +82,8 @@ namespace PhysX
|
||||
|
||||
SetName(configuration.m_debugName);
|
||||
SetGravityEnabled(configuration.m_gravityEnabled);
|
||||
SetSimulationEnabled(configuration.m_simulated);
|
||||
SetCCDEnabled(configuration.m_ccdEnabled);
|
||||
|
||||
AzPhysics::MassComputeFlags flags = configuration.GetMassComputeFlags();
|
||||
UpdateMassProperties(flags, &configuration.m_centerOfMassOffset, &configuration.m_inertiaTensor,
|
||||
&configuration.m_mass);
|
||||
SetKinematic(configuration.m_kinematic);
|
||||
|
||||
if (configuration.m_customUserData)
|
||||
{
|
||||
@@ -459,7 +455,7 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Vector3 RigidBody::GetLinearVelocityAtWorldPoint(const AZ::Vector3& worldPoint)
|
||||
AZ::Vector3 RigidBody::GetLinearVelocityAtWorldPoint(const AZ::Vector3& worldPoint) const
|
||||
{
|
||||
return m_pxRigidActor ?
|
||||
GetLinearVelocity() + GetAngularVelocity().Cross(worldPoint - GetCenterOfMassWorld()) :
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace PhysX
|
||||
void SetLinearVelocity(const AZ::Vector3& velocity) override;
|
||||
AZ::Vector3 GetAngularVelocity() const override;
|
||||
void SetAngularVelocity(const AZ::Vector3& angularVelocity) override;
|
||||
AZ::Vector3 GetLinearVelocityAtWorldPoint(const AZ::Vector3& worldPoint) override;
|
||||
AZ::Vector3 GetLinearVelocityAtWorldPoint(const AZ::Vector3& worldPoint) const override;
|
||||
void ApplyLinearImpulse(const AZ::Vector3& impulse) override;
|
||||
void ApplyLinearImpulseAtWorldPoint(const AZ::Vector3& impulse, const AZ::Vector3& worldPoint) override;
|
||||
void ApplyAngularImpulse(const AZ::Vector3& angularImpulse) override;
|
||||
|
||||
@@ -184,12 +184,10 @@ namespace PhysX
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
m_rigidBody = nullptr;
|
||||
}
|
||||
|
||||
Physics::RigidBodyRequestBus::Handler::BusDisconnect();
|
||||
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusDisconnect();
|
||||
AZ::TransformNotificationBus::MultiHandler::BusDisconnect();
|
||||
m_sceneFinishSimHandler.Disconnect();
|
||||
AZ::TickBus::Handler::BusDisconnect();
|
||||
@@ -231,15 +229,30 @@ namespace PhysX
|
||||
// User sets kinematic Target ---> Update transform
|
||||
// User sets transform ---> Update kinematic target
|
||||
|
||||
if (!IsPhysicsEnabled() || (m_rigidBody->IsKinematic() && !m_isLastMovementFromKinematicSource))
|
||||
if (!IsPhysicsEnabled() || (IsKinematic() && !m_isLastMovementFromKinematicSource))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
|
||||
if (sceneInterface == nullptr)
|
||||
{
|
||||
AZ_Error("RigidBodyComponent", false, "PostPhysicsTick, SceneInterface is null");
|
||||
return;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* rigidBody =
|
||||
sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
if (rigidBody == nullptr)
|
||||
{
|
||||
AZ_Error("RigidBodyComponent", false, "Unable to retrieve simulated rigid body");
|
||||
return;
|
||||
}
|
||||
|
||||
AZ::Transform transform = rigidBody->GetTransform();
|
||||
if (m_configuration.m_interpolateMotion)
|
||||
{
|
||||
AZ::Transform transform = m_rigidBody->GetTransform();
|
||||
m_interpolator->SetTarget(transform.GetTranslation(), m_rigidBody->GetOrientation(), fixedDeltaTime);
|
||||
m_interpolator->SetTarget(transform.GetTranslation(), rigidBody->GetOrientation(), fixedDeltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -254,13 +267,17 @@ namespace PhysX
|
||||
// Note: OnTransformChanged is not safe at the moment due to TransformComponent design flaw.
|
||||
// It is called when the parent entity is activated after the children causing rigid body
|
||||
// to move through the level instantly.
|
||||
if (IsPhysicsEnabled() && (m_rigidBody->IsKinematic() && !m_isLastMovementFromKinematicSource))
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
m_rigidBody->SetKinematicTarget(world);
|
||||
}
|
||||
else if (!IsPhysicsEnabled())
|
||||
{
|
||||
m_rigidBodyTransformNeedsUpdateOnPhysReEnable = true;
|
||||
if (body->m_simulating &&
|
||||
(body->IsKinematic() && !m_isLastMovementFromKinematicSource))
|
||||
{
|
||||
body->SetKinematicTarget(world);
|
||||
}
|
||||
else if (!body->m_simulating)
|
||||
{
|
||||
m_rigidBodyTransformNeedsUpdateOnPhysReEnable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,16 +300,9 @@ namespace PhysX
|
||||
auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
|
||||
if (sceneInterface != nullptr)
|
||||
{
|
||||
m_configuration.m_startSimulationEnabled = false; //enable physics will enable this when called.
|
||||
m_rigidBodyHandle = sceneInterface->AddSimulatedBody(m_attachedSceneHandle, &m_configuration);
|
||||
m_rigidBody = azdynamic_cast<AzPhysics::RigidBody*>(sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_rigidBodyHandle));
|
||||
//disable simulating the body until EnablePhysics is called.
|
||||
sceneInterface->DisableSimulationOfBody(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
}
|
||||
m_rigidBody->SetKinematic(m_configuration.m_kinematic);
|
||||
|
||||
AzPhysics::MassComputeFlags flags = m_configuration.GetMassComputeFlags();
|
||||
m_rigidBody->UpdateMassProperties(flags, &m_configuration.m_centerOfMassOffset, &m_configuration.m_inertiaTensor,
|
||||
&m_configuration.m_mass);
|
||||
|
||||
// Listen to the PhysX system for events concerning this entity.
|
||||
if (sceneInterface != nullptr)
|
||||
@@ -302,7 +312,7 @@ namespace PhysX
|
||||
AZ::TickBus::Handler::BusConnect();
|
||||
AZ::TransformNotificationBus::MultiHandler::BusConnect(GetEntityId());
|
||||
Physics::RigidBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
Physics::WorldBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusConnect(GetEntityId());
|
||||
}
|
||||
|
||||
void RigidBodyComponent::EnablePhysics()
|
||||
@@ -312,16 +322,23 @@ namespace PhysX
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
|
||||
if (sceneInterface == nullptr)
|
||||
{
|
||||
sceneInterface->EnableSimulationOfBody(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
AZ_Error("RigidBodyComponent", false, "Unable to enable physics, SceneInterface is null");
|
||||
return;
|
||||
}
|
||||
SetSimulationEnabled(true);
|
||||
|
||||
AZ::Transform transform = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(transform, GetEntityId(), &AZ::TransformInterface::GetWorldTM);
|
||||
if (m_rigidBodyTransformNeedsUpdateOnPhysReEnable)
|
||||
{
|
||||
m_rigidBody->SetTransform(transform);
|
||||
if (AzPhysics::SimulatedBody* body =
|
||||
sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_rigidBodyHandle))
|
||||
{
|
||||
body->SetTransform(transform);
|
||||
}
|
||||
m_rigidBodyTransformNeedsUpdateOnPhysReEnable = false;
|
||||
}
|
||||
|
||||
@@ -332,201 +349,338 @@ namespace PhysX
|
||||
m_interpolator->Reset(transform.GetTranslation(), rotation);
|
||||
|
||||
Physics::RigidBodyNotificationBus::Event(GetEntityId(), &Physics::RigidBodyNotificationBus::Events::OnPhysicsEnabled);
|
||||
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsEnabled);
|
||||
}
|
||||
|
||||
void RigidBodyComponent::DisablePhysics()
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->DisableSimulationOfBody(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
}
|
||||
SetSimulationEnabled(false);
|
||||
|
||||
Physics::RigidBodyNotificationBus::Event(GetEntityId(), &Physics::RigidBodyNotificationBus::Events::OnPhysicsDisabled);
|
||||
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsDisabled);
|
||||
}
|
||||
|
||||
bool RigidBodyComponent::IsPhysicsEnabled() const
|
||||
{
|
||||
return m_rigidBody != nullptr && m_rigidBody->m_simulating;
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->m_simulating;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::ApplyLinearImpulse(const AZ::Vector3& impulse)
|
||||
{
|
||||
m_rigidBody->ApplyLinearImpulse(impulse);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->ApplyLinearImpulse(impulse);
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyComponent::ApplyLinearImpulseAtWorldPoint(const AZ::Vector3& impulse, const AZ::Vector3& worldSpacePoint)
|
||||
{
|
||||
m_rigidBody->ApplyLinearImpulseAtWorldPoint(impulse, worldSpacePoint);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->ApplyLinearImpulseAtWorldPoint(impulse, worldSpacePoint);
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyComponent::ApplyAngularImpulse(const AZ::Vector3& impulse)
|
||||
{
|
||||
m_rigidBody->ApplyAngularImpulse(impulse);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->ApplyAngularImpulse(impulse);
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Vector3 RigidBodyComponent::GetLinearVelocity() const
|
||||
{
|
||||
return m_rigidBody->GetLinearVelocity();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetLinearVelocity();
|
||||
}
|
||||
return AZ::Vector3::CreateZero();
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetLinearVelocity(const AZ::Vector3& velocity)
|
||||
{
|
||||
m_rigidBody->SetLinearVelocity(velocity);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetLinearVelocity(velocity);
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Vector3 RigidBodyComponent::GetAngularVelocity() const
|
||||
{
|
||||
return m_rigidBody->GetAngularVelocity();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetAngularVelocity();
|
||||
}
|
||||
return AZ::Vector3::CreateZero();
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetAngularVelocity(const AZ::Vector3& angularVelocity)
|
||||
{
|
||||
m_rigidBody->SetAngularVelocity(angularVelocity);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetAngularVelocity(angularVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Vector3 RigidBodyComponent::GetLinearVelocityAtWorldPoint(const AZ::Vector3& worldPoint) const
|
||||
{
|
||||
return m_rigidBody->GetLinearVelocityAtWorldPoint(worldPoint);
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetLinearVelocityAtWorldPoint(worldPoint);
|
||||
}
|
||||
return AZ::Vector3::CreateZero();
|
||||
}
|
||||
|
||||
AZ::Vector3 RigidBodyComponent::GetCenterOfMassWorld() const
|
||||
{
|
||||
return m_rigidBody->GetCenterOfMassWorld();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetCenterOfMassWorld();
|
||||
}
|
||||
return AZ::Vector3::CreateZero();
|
||||
}
|
||||
|
||||
AZ::Vector3 RigidBodyComponent::GetCenterOfMassLocal() const
|
||||
{
|
||||
return m_rigidBody->GetCenterOfMassLocal();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetCenterOfMassLocal();
|
||||
}
|
||||
return AZ::Vector3::CreateZero();
|
||||
}
|
||||
|
||||
AZ::Matrix3x3 RigidBodyComponent::GetInverseInertiaWorld() const
|
||||
{
|
||||
return m_rigidBody->GetInverseInertiaWorld();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetInverseInertiaWorld();
|
||||
}
|
||||
return AZ::Matrix3x3::CreateZero();
|
||||
}
|
||||
|
||||
AZ::Matrix3x3 RigidBodyComponent::GetInverseInertiaLocal() const
|
||||
{
|
||||
return m_rigidBody->GetInverseInertiaLocal();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetInverseInertiaLocal();
|
||||
}
|
||||
return AZ::Matrix3x3::CreateZero();
|
||||
}
|
||||
|
||||
float RigidBodyComponent::GetMass() const
|
||||
{
|
||||
return m_rigidBody->GetMass();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetMass();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float RigidBodyComponent::GetInverseMass() const
|
||||
{
|
||||
return m_rigidBody->GetInverseMass();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetInverseMass();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetMass(float mass)
|
||||
{
|
||||
m_rigidBody->SetMass(mass);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetMass(mass);
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetCenterOfMassOffset(const AZ::Vector3& comOffset)
|
||||
{
|
||||
m_rigidBody->SetCenterOfMassOffset(comOffset);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetCenterOfMassOffset(comOffset);
|
||||
}
|
||||
}
|
||||
|
||||
float RigidBodyComponent::GetLinearDamping() const
|
||||
{
|
||||
return m_rigidBody->GetLinearDamping();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetLinearDamping();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetLinearDamping(float damping)
|
||||
{
|
||||
m_rigidBody->SetLinearDamping(damping);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetLinearDamping(damping);
|
||||
}
|
||||
}
|
||||
|
||||
float RigidBodyComponent::GetAngularDamping() const
|
||||
{
|
||||
return m_rigidBody->GetAngularDamping();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetAngularDamping();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetAngularDamping(float damping)
|
||||
{
|
||||
m_rigidBody->SetAngularDamping(damping);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetAngularDamping(damping);
|
||||
}
|
||||
}
|
||||
|
||||
bool RigidBodyComponent::IsAwake() const
|
||||
{
|
||||
return m_rigidBody->IsAwake();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->IsAwake();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::ForceAsleep()
|
||||
{
|
||||
m_rigidBody->ForceAsleep();
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->ForceAsleep();
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyComponent::ForceAwake()
|
||||
{
|
||||
m_rigidBody->ForceAwake();
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->ForceAwake();
|
||||
}
|
||||
}
|
||||
|
||||
bool RigidBodyComponent::IsKinematic() const
|
||||
{
|
||||
return m_rigidBody->IsKinematic();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->IsKinematic();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetKinematic(bool kinematic)
|
||||
{
|
||||
m_rigidBody->SetKinematic(kinematic);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetKinematic(kinematic);
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetKinematicTarget(const AZ::Transform& targetPosition)
|
||||
{
|
||||
m_isLastMovementFromKinematicSource = true;
|
||||
m_rigidBody->SetKinematicTarget(targetPosition);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetKinematicTarget(targetPosition);
|
||||
}
|
||||
}
|
||||
|
||||
bool RigidBodyComponent::IsGravityEnabled() const
|
||||
{
|
||||
return m_rigidBody->IsGravityEnabled();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->IsGravityEnabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetGravityEnabled(bool enabled)
|
||||
{
|
||||
m_rigidBody->SetGravityEnabled(enabled);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetGravityEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetSimulationEnabled(bool enabled)
|
||||
{
|
||||
m_rigidBody->SetSimulationEnabled(enabled);
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
sceneInterface->EnableSimulationOfBody(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
sceneInterface->DisableSimulationOfBody(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float RigidBodyComponent::GetSleepThreshold() const
|
||||
{
|
||||
return m_rigidBody->GetSleepThreshold();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetSleepThreshold();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetSleepThreshold(float threshold)
|
||||
{
|
||||
m_rigidBody->SetSleepThreshold(threshold);
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
body->SetSleepThreshold(threshold);
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Aabb RigidBodyComponent::GetAabb() const
|
||||
{
|
||||
return m_rigidBody->GetAabb();
|
||||
if (const AzPhysics::RigidBody* body = GetRigidBodyConst())
|
||||
{
|
||||
return body->GetAabb();
|
||||
}
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
AzPhysics::RigidBody* RigidBodyComponent::GetRigidBody()
|
||||
{
|
||||
return m_rigidBody;
|
||||
return azdynamic_cast<AzPhysics::RigidBody*>(GetSimulatedBody());
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* RigidBodyComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBody* RigidBodyComponent::GetSimulatedBody()
|
||||
{
|
||||
return m_rigidBody;
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
return sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_rigidBodyHandle);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const AzPhysics::RigidBody* RigidBodyComponent::GetRigidBodyConst() const
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
return azdynamic_cast<AzPhysics::RigidBody*>(
|
||||
sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_rigidBodyHandle));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBodyHandle RigidBodyComponent::GetSimulatedBodyHandle() const
|
||||
{
|
||||
return m_rigidBodyHandle;
|
||||
}
|
||||
|
||||
AzPhysics::SceneQueryHit RigidBodyComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
{
|
||||
if (m_rigidBody)
|
||||
if (AzPhysics::RigidBody* body = GetRigidBody())
|
||||
{
|
||||
return m_rigidBody->RayCast(request);
|
||||
return body->RayCast(request);
|
||||
}
|
||||
return AzPhysics::SceneQueryHit();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzFramework/Physics/RigidBodyBus.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Components/SimulatedBodyComponentBus.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsEvents.h>
|
||||
#include <AzFramework/Physics/Configuration/RigidBodyConfiguration.h>
|
||||
#include <AzFramework/Physics/SimulatedBodies/RigidBody.h>
|
||||
@@ -35,7 +35,7 @@ namespace PhysX
|
||||
class RigidBodyComponent
|
||||
: public AZ::Component
|
||||
, public Physics::RigidBodyRequestBus::Handler
|
||||
, public Physics::WorldBodyRequestBus::Handler
|
||||
, public AzPhysics::SimulatedBodyComponentRequestsBus::Handler
|
||||
, public AZ::TickBus::Handler
|
||||
, public AzFramework::SliceGameEntityOwnershipServiceNotificationBus::Handler
|
||||
, protected AZ::TransformNotificationBus::MultiHandler
|
||||
@@ -120,8 +120,9 @@ namespace PhysX
|
||||
void SetSleepThreshold(float threshold) override;
|
||||
AzPhysics::RigidBody* GetRigidBody() override;
|
||||
|
||||
// WorldBodyRequestBus
|
||||
AzPhysics::SimulatedBody* GetWorldBody() override;
|
||||
// AzPhysics::SimulatedBodyComponentRequestsBus::Handler overrides ...
|
||||
AzPhysics::SimulatedBody* GetSimulatedBody() override;
|
||||
AzPhysics::SimulatedBodyHandle GetSimulatedBodyHandle() const override;
|
||||
|
||||
// SliceGameEntityOwnershipServiceNotificationBus
|
||||
void OnSliceInstantiated(const AZ::Data::AssetId&, const AZ::SliceComponent::SliceInstanceAddress&,
|
||||
@@ -152,11 +153,12 @@ namespace PhysX
|
||||
void InitPhysicsTickHandler();
|
||||
void PostPhysicsTick(float fixedDeltaTime);
|
||||
|
||||
const AzPhysics::RigidBody* GetRigidBodyConst() const;
|
||||
|
||||
std::unique_ptr<TransformForwardTimeInterpolator> m_interpolator;
|
||||
|
||||
AzPhysics::RigidBodyConfiguration m_configuration;
|
||||
AzPhysics::SimulatedBodyHandle m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
AzPhysics::RigidBody* m_rigidBody = nullptr;
|
||||
AzPhysics::SceneHandle m_attachedSceneHandle = AzPhysics::InvalidSceneHandle;
|
||||
|
||||
bool m_staticTransformAtActivation = false; ///< Whether the transform was static when the component last activated.
|
||||
|
||||
@@ -189,6 +189,22 @@ namespace PhysX
|
||||
return newBody;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* CreateRigidBody(const AzPhysics::RigidBodyConfiguration* configuration, AZ::Crc32& crc)
|
||||
{
|
||||
RigidBody* newBody = aznew RigidBody(*configuration);
|
||||
if (!AZStd::holds_alternative<AZStd::monostate>(configuration->m_colliderAndShapeData))
|
||||
{
|
||||
const bool shapeAdded = AddShape(newBody, configuration->m_colliderAndShapeData);
|
||||
AZ_Warning("PhysXScene", shapeAdded, "No Collider or Shape information found when creating Rigid body [%s]", configuration->m_debugName.c_str());
|
||||
}
|
||||
const AzPhysics::MassComputeFlags& flags = configuration->GetMassComputeFlags();
|
||||
newBody->UpdateMassProperties(flags, &configuration->m_centerOfMassOffset,
|
||||
&configuration->m_inertiaTensor, &configuration->m_mass);
|
||||
|
||||
crc = AZ::Crc32(newBody, sizeof(*newBody));
|
||||
return newBody;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* CreateCharacterBody(PhysXScene* scene,
|
||||
const Physics::CharacterConfiguration* characterConfig)
|
||||
{
|
||||
@@ -209,6 +225,13 @@ namespace PhysX
|
||||
return controller;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* CreateRagdollBody(PhysXScene* scene,
|
||||
const Physics::RagdollConfiguration* ragdollConfig)
|
||||
{
|
||||
return Utils::Characters::CreateRagdoll(const_cast<Physics::RagdollConfiguration&>(*ragdollConfig),
|
||||
scene->GetSceneHandle());
|
||||
}
|
||||
|
||||
//helper to perform a ray cast
|
||||
AzPhysics::SceneQueryHits RayCast(const AzPhysics::RayCastRequest* raycastRequest,
|
||||
AZStd::vector<physx::PxRaycastHit>& raycastBuffer,
|
||||
@@ -610,7 +633,7 @@ namespace PhysX
|
||||
AZ::Crc32 newBodyCrc;
|
||||
if (azrtti_istypeof<AzPhysics::RigidBodyConfiguration>(simulatedBodyConfig))
|
||||
{
|
||||
newBody = Internal::CreateSimulatedBody<RigidBody, AzPhysics::RigidBodyConfiguration>(
|
||||
newBody = Internal::CreateRigidBody(
|
||||
azdynamic_cast<const AzPhysics::RigidBodyConfiguration*>(simulatedBodyConfig), newBodyCrc);
|
||||
}
|
||||
else if (azrtti_istypeof<AzPhysics::StaticRigidBodyConfiguration>(simulatedBodyConfig))
|
||||
@@ -622,6 +645,15 @@ namespace PhysX
|
||||
{
|
||||
newBody = Internal::CreateCharacterBody(this, azdynamic_cast<const Physics::CharacterConfiguration*>(simulatedBodyConfig));
|
||||
}
|
||||
else if (azrtti_istypeof<Physics::RagdollConfiguration>(simulatedBodyConfig))
|
||||
{
|
||||
newBody = Internal::CreateRagdollBody(this, azdynamic_cast<const Physics::RagdollConfiguration*>(simulatedBodyConfig));
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Warning("PhysXScene", false, "Unknown SimulatedBodyConfiguration.");
|
||||
return AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
|
||||
if (newBody != nullptr)
|
||||
{
|
||||
@@ -648,8 +680,11 @@ namespace PhysX
|
||||
newBody->m_bodyHandle = newBodyHandle;
|
||||
m_simulatedBodyAddedEvent.Signal(m_sceneHandle, newBodyHandle);
|
||||
|
||||
// Enable simulation by default (not signaling OnSimulationBodySimulationEnabled event)
|
||||
EnableSimulationOfBodyInternal(*newBody);
|
||||
// Enable simulation by default (not signaling OnSimulationBodySimulationEnabled event)
|
||||
if (simulatedBodyConfig->m_startSimulationEnabled)
|
||||
{
|
||||
EnableSimulationOfBodyInternal(*newBody);
|
||||
}
|
||||
|
||||
return newBodyHandle;
|
||||
}
|
||||
@@ -694,7 +729,7 @@ namespace PhysX
|
||||
return results;
|
||||
}
|
||||
|
||||
void PhysXScene::RemoveSimulatedBody(AzPhysics::SimulatedBodyHandle bodyHandle)
|
||||
void PhysXScene::RemoveSimulatedBody(AzPhysics::SimulatedBodyHandle& bodyHandle)
|
||||
{
|
||||
if (bodyHandle == AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
@@ -716,10 +751,12 @@ namespace PhysX
|
||||
m_deferredDeletions.push_back(m_simulatedBodies[index].second);
|
||||
m_simulatedBodies[index] = AZStd::make_pair(AZ::Crc32(), nullptr);
|
||||
m_freeSceneSlots.push(index);
|
||||
|
||||
bodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXScene::RemoveSimulatedBodies(const AzPhysics::SimulatedBodyHandleList& bodyHandles)
|
||||
void PhysXScene::RemoveSimulatedBodies(AzPhysics::SimulatedBodyHandleList& bodyHandles)
|
||||
{
|
||||
for (auto& handle: bodyHandles)
|
||||
{
|
||||
@@ -878,7 +915,8 @@ namespace PhysX
|
||||
void PhysXScene::EnableSimulationOfBodyInternal(AzPhysics::SimulatedBody& body)
|
||||
{
|
||||
//character controller is a special actor and only needs the m_simulating flag set,
|
||||
if (!azrtti_istypeof<PhysX::CharacterController>(body))
|
||||
if (!azrtti_istypeof<PhysX::CharacterController>(body) &&
|
||||
!azrtti_istypeof<PhysX::Ragdoll>(body))
|
||||
{
|
||||
auto pxActor = static_cast<physx::PxActor*>(body.GetNativePointer());
|
||||
AZ_Assert(pxActor, "Simulated Body doesn't have a valid physx actor");
|
||||
@@ -904,7 +942,8 @@ namespace PhysX
|
||||
void PhysXScene::DisableSimulationOfBodyInternal(AzPhysics::SimulatedBody& body)
|
||||
{
|
||||
//character controller is a special actor and only needs the m_simulating flag set,
|
||||
if (!azrtti_istypeof<PhysX::CharacterController>(body))
|
||||
if (!azrtti_istypeof<PhysX::CharacterController>(body) &&
|
||||
!azrtti_istypeof<PhysX::Ragdoll>(body))
|
||||
{
|
||||
auto pxActor = static_cast<physx::PxActor*>(body.GetNativePointer());
|
||||
AZ_Assert(pxActor, "Simulated Body doesn't have a valid physx actor");
|
||||
@@ -948,11 +987,14 @@ namespace PhysX
|
||||
|
||||
void PhysXScene::ClearDeferedDeletions()
|
||||
{
|
||||
for (auto& simulatedBody : m_deferredDeletions)
|
||||
// swap the deletions in case the simulated body
|
||||
// manages more bodies and removes them on destruction (ie. Ragdoll).
|
||||
AZStd::vector<AzPhysics::SimulatedBody*> deletions;
|
||||
deletions.swap(m_deferredDeletions);
|
||||
for (auto* simulatedBody : deletions)
|
||||
{
|
||||
delete simulatedBody;
|
||||
}
|
||||
m_deferredDeletions.clear();
|
||||
}
|
||||
|
||||
void PhysXScene::ProcessTriggerEvents()
|
||||
|
||||
@@ -48,8 +48,8 @@ namespace PhysX
|
||||
AzPhysics::SimulatedBodyHandleList AddSimulatedBodies(const AzPhysics::SimulatedBodyConfigurationList& simulatedBodyConfigs) override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBodyFromHandle(AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
AzPhysics::SimulatedBodyList GetSimulatedBodiesFromHandle(const AzPhysics::SimulatedBodyHandleList& bodyHandles) override;
|
||||
void RemoveSimulatedBody(AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
void RemoveSimulatedBodies(const AzPhysics::SimulatedBodyHandleList& bodyHandles) override;
|
||||
void RemoveSimulatedBody(AzPhysics::SimulatedBodyHandle& bodyHandle) override;
|
||||
void RemoveSimulatedBodies(AzPhysics::SimulatedBodyHandleList& bodyHandles) override;
|
||||
void EnableSimulationOfBody(AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
void DisableSimulationOfBody(AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
AzPhysics::SceneQueryHits QueryScene(const AzPhysics::SceneQueryRequest* request) override;
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace PhysX
|
||||
return {}; //return an empty list
|
||||
}
|
||||
|
||||
void PhysXSceneInterface::RemoveSimulatedBody(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandle bodyHandle)
|
||||
void PhysXSceneInterface::RemoveSimulatedBody(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandle& bodyHandle)
|
||||
{
|
||||
if (AzPhysics::Scene* scene = m_physxSystem->GetScene(sceneHandle))
|
||||
{
|
||||
@@ -120,7 +120,7 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSceneInterface::RemoveSimulatedBodies(AzPhysics::SceneHandle sceneHandle, const AzPhysics::SimulatedBodyHandleList& bodyHandles)
|
||||
void PhysXSceneInterface::RemoveSimulatedBodies(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandleList& bodyHandles)
|
||||
{
|
||||
if (AzPhysics::Scene* scene = m_physxSystem->GetScene(sceneHandle))
|
||||
{
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace PhysX
|
||||
AzPhysics::SimulatedBodyHandleList AddSimulatedBodies(AzPhysics::SceneHandle sceneHandle, const AzPhysics::SimulatedBodyConfigurationList& simulatedBodyConfigs) override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBodyFromHandle(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
AzPhysics::SimulatedBodyList GetSimulatedBodiesFromHandle(AzPhysics::SceneHandle sceneHandle, const AzPhysics::SimulatedBodyHandleList& bodyHandles) override;
|
||||
void RemoveSimulatedBody(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
void RemoveSimulatedBodies(AzPhysics::SceneHandle sceneHandle, const AzPhysics::SimulatedBodyHandleList& bodyHandles) override;
|
||||
void RemoveSimulatedBody(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandle& bodyHandle) override;
|
||||
void RemoveSimulatedBodies(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandleList& bodyHandles) override;
|
||||
void EnableSimulationOfBody(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
void DisableSimulationOfBody(AzPhysics::SceneHandle sceneHandle, AzPhysics::SimulatedBodyHandle bodyHandle) override;
|
||||
AzPhysics::SceneQueryHits QueryScene(AzPhysics::SceneHandle sceneHandle, const AzPhysics::SceneQueryRequest* request) override;
|
||||
|
||||
@@ -83,8 +83,8 @@ namespace PhysX
|
||||
continue;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* body1 = actorData1->GetWorldBody();
|
||||
AzPhysics::SimulatedBody* body2 = actorData2->GetWorldBody();
|
||||
AzPhysics::SimulatedBody* body1 = actorData1->GetSimulatedBody();
|
||||
AzPhysics::SimulatedBody* body2 = actorData2->GetSimulatedBody();
|
||||
|
||||
if (!body1 || !body2)
|
||||
{
|
||||
@@ -161,7 +161,7 @@ namespace PhysX
|
||||
}
|
||||
|
||||
ActorData* triggerBodyActorData = Utils::GetUserData(triggerPair.triggerActor);
|
||||
AzPhysics::SimulatedBody* triggerBody = triggerBodyActorData->GetWorldBody();
|
||||
AzPhysics::SimulatedBody* triggerBody = triggerBodyActorData->GetSimulatedBody();
|
||||
if (!triggerBody)
|
||||
{
|
||||
AZ_Error("PhysX", false, "onTrigger:: trigger body was invalid");
|
||||
@@ -174,7 +174,7 @@ namespace PhysX
|
||||
}
|
||||
|
||||
ActorData* otherActorData = Utils::GetUserData(triggerPair.otherActor);
|
||||
AzPhysics::SimulatedBody* otherBody = otherActorData->GetWorldBody();
|
||||
AzPhysics::SimulatedBody* otherBody = otherActorData->GetSimulatedBody();
|
||||
if (!otherBody)
|
||||
{
|
||||
AZ_Error("PhysX", false, "onTrigger:: otherBody was invalid");
|
||||
|
||||
@@ -62,8 +62,6 @@ namespace PhysX
|
||||
|
||||
void StaticRigidBodyComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
// Not compatible with cry engine colliders
|
||||
incompatible.push_back(AZ_CRC("ColliderService", 0x902d4e93));
|
||||
// There can be only one StaticRigidBodyComponent per entity
|
||||
incompatible.push_back(AZ_CRC("PhysXStaticRigidBodyService", 0xaae8973b));
|
||||
// Cannot have both StaticRigidBodyComponent and RigidBodyComponent
|
||||
@@ -75,11 +73,6 @@ namespace PhysX
|
||||
dependent.push_back(AZ_CRC("PhysXColliderService", 0x4ff43f7c));
|
||||
}
|
||||
|
||||
PhysX::StaticRigidBody* StaticRigidBodyComponent::GetStaticRigidBody()
|
||||
{
|
||||
return m_staticRigidBody;
|
||||
}
|
||||
|
||||
void StaticRigidBodyComponent::InitStaticRigidBody()
|
||||
{
|
||||
AZ::Transform transform = AZ::Transform::CreateIdentity();
|
||||
@@ -107,7 +100,6 @@ namespace PhysX
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
m_staticRigidBodyHandle = sceneInterface->AddSimulatedBody(m_attachedSceneHandle, &configuration);
|
||||
m_staticRigidBody = azdynamic_cast<PhysX::StaticRigidBody*>(sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_staticRigidBodyHandle));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +109,7 @@ namespace PhysX
|
||||
|
||||
InitStaticRigidBody();
|
||||
|
||||
Physics::WorldBodyRequestBus::Handler::BusConnect(GetEntityId());
|
||||
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsEnabled);
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusConnect(GetEntityId());
|
||||
}
|
||||
|
||||
void StaticRigidBodyComponent::Deactivate()
|
||||
@@ -126,17 +117,18 @@ namespace PhysX
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
sceneInterface->RemoveSimulatedBody(m_attachedSceneHandle, m_staticRigidBodyHandle);
|
||||
m_staticRigidBodyHandle = AzPhysics::InvalidSceneHandle;
|
||||
m_staticRigidBody = nullptr;
|
||||
}
|
||||
|
||||
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
|
||||
AzPhysics::SimulatedBodyComponentRequestsBus::Handler::BusDisconnect();
|
||||
AZ::TransformNotificationBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
void StaticRigidBodyComponent::OnTransformChanged(const AZ::Transform& /*local*/, const AZ::Transform& world)
|
||||
void StaticRigidBodyComponent::OnTransformChanged([[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world)
|
||||
{
|
||||
m_staticRigidBody->SetTransform(world);
|
||||
if (AzPhysics::SimulatedBody* body = GetSimulatedBody())
|
||||
{
|
||||
body->SetTransform(world);
|
||||
}
|
||||
}
|
||||
|
||||
void StaticRigidBodyComponent::EnablePhysics()
|
||||
@@ -149,8 +141,6 @@ namespace PhysX
|
||||
{
|
||||
sceneInterface->EnableSimulationOfBody(m_attachedSceneHandle, m_staticRigidBodyHandle);
|
||||
}
|
||||
|
||||
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsEnabled);
|
||||
}
|
||||
|
||||
void StaticRigidBodyComponent::DisablePhysics()
|
||||
@@ -159,30 +149,56 @@ namespace PhysX
|
||||
{
|
||||
sceneInterface->DisableSimulationOfBody(m_attachedSceneHandle, m_staticRigidBodyHandle);
|
||||
}
|
||||
|
||||
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsDisabled);
|
||||
}
|
||||
|
||||
bool StaticRigidBodyComponent::IsPhysicsEnabled() const
|
||||
{
|
||||
return m_staticRigidBody != nullptr && m_staticRigidBody->m_simulating;
|
||||
if (m_staticRigidBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
|
||||
sceneInterface != nullptr &&
|
||||
sceneInterface->IsEnabled(m_attachedSceneHandle))//check if the scene is enabled
|
||||
{
|
||||
if (AzPhysics::SimulatedBody* body = sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_staticRigidBodyHandle))
|
||||
{
|
||||
return body->m_simulating;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::Aabb StaticRigidBodyComponent::GetAabb() const
|
||||
{
|
||||
return m_staticRigidBody->GetAabb();
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
if (AzPhysics::SimulatedBody* body = sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_staticRigidBodyHandle))
|
||||
{
|
||||
return body->GetAabb();
|
||||
}
|
||||
}
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* StaticRigidBodyComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBodyHandle StaticRigidBodyComponent::GetSimulatedBodyHandle() const
|
||||
{
|
||||
return m_staticRigidBody;
|
||||
return m_staticRigidBodyHandle;
|
||||
}
|
||||
|
||||
AzPhysics::SimulatedBody* StaticRigidBodyComponent::GetSimulatedBody()
|
||||
{
|
||||
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
return sceneInterface->GetSimulatedBodyFromHandle(m_attachedSceneHandle, m_staticRigidBodyHandle);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AzPhysics::SceneQueryHit StaticRigidBodyComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
{
|
||||
if (m_staticRigidBody)
|
||||
if (auto* body = azdynamic_cast<PhysX::StaticRigidBody*>(GetSimulatedBody()))
|
||||
{
|
||||
return m_staticRigidBody->RayCast(request);
|
||||
return body->RayCast(request);
|
||||
}
|
||||
return AzPhysics::SceneQueryHit();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzFramework/Physics/WorldBodyBus.h>
|
||||
#include <AzFramework/Physics/Components/SimulatedBodyComponentBus.h>
|
||||
#include <PhysX/ComponentTypeIds.h>
|
||||
|
||||
namespace AzPhysics
|
||||
@@ -27,7 +27,7 @@ namespace PhysX
|
||||
|
||||
class StaticRigidBodyComponent final
|
||||
: public AZ::Component
|
||||
, public Physics::WorldBodyRequestBus::Handler
|
||||
, public AzPhysics::SimulatedBodyComponentRequestsBus::Handler
|
||||
, private AZ::TransformNotificationBus::Handler
|
||||
{
|
||||
public:
|
||||
@@ -44,14 +44,14 @@ namespace PhysX
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
|
||||
|
||||
PhysX::StaticRigidBody* GetStaticRigidBody();
|
||||
|
||||
// WorldBodyRequestBus
|
||||
// AzPhysics::SimulatedBodyComponentRequestsBus::Handler overrides ...
|
||||
void EnablePhysics() override;
|
||||
void DisablePhysics() override;
|
||||
bool IsPhysicsEnabled() const override;
|
||||
AZ::Aabb GetAabb() const override;
|
||||
AzPhysics::SimulatedBody* GetWorldBody() override;
|
||||
AzPhysics::SimulatedBodyHandle GetSimulatedBodyHandle() const override;
|
||||
AzPhysics::SimulatedBody* GetSimulatedBody() override;
|
||||
|
||||
AzPhysics::SceneQueryHit RayCast(const AzPhysics::RayCastRequest& request) override;
|
||||
|
||||
private:
|
||||
@@ -65,7 +65,6 @@ namespace PhysX
|
||||
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
|
||||
|
||||
AzPhysics::SimulatedBodyHandle m_staticRigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
PhysX::StaticRigidBody* m_staticRigidBody = nullptr;
|
||||
AzPhysics::SceneHandle m_attachedSceneHandle = AzPhysics::InvalidSceneHandle;
|
||||
};
|
||||
} // namespace PhysX
|
||||
|
||||
@@ -140,6 +140,9 @@ namespace PhysX
|
||||
}
|
||||
};
|
||||
|
||||
AZ_Warning("PhysXSystem", deltaTime <= m_systemConfig.m_maxTimestep,
|
||||
"Frame delta time of [%.6f seconds] exceeds Physics max frame timestep, physics timestep will be clamped to [%.6f seconds].",
|
||||
deltaTime, m_systemConfig.m_maxTimestep);
|
||||
deltaTime = AZ::GetClamp(deltaTime, 0.0f, m_systemConfig.m_maxTimestep);
|
||||
|
||||
AZ_Assert(m_systemConfig.m_fixedTimestep >= 0.0f, "PhysXSystem - fixed timestep is negitive.");
|
||||
|
||||
@@ -770,7 +770,7 @@ namespace PhysX
|
||||
return worldPosAabb;
|
||||
}
|
||||
|
||||
Physics::ShapeConfigurationList colliderShapes;
|
||||
AzPhysics::ShapeColliderPairList colliderShapes;
|
||||
GetColliderShapeConfigsFromAsset(physicsAssetConfig,
|
||||
colliderConfiguration,
|
||||
hasNonUniformScale,
|
||||
@@ -812,7 +812,7 @@ namespace PhysX
|
||||
|
||||
void GetColliderShapeConfigsFromAsset(const Physics::PhysicsAssetShapeConfiguration& assetConfiguration,
|
||||
const Physics::ColliderConfiguration& originalColliderConfiguration, bool hasNonUniformScale,
|
||||
AZ::u8 subdivisionLevel, Physics::ShapeConfigurationList& resultingColliderShapes)
|
||||
AZ::u8 subdivisionLevel, AzPhysics::ShapeColliderPairList& resultingColliderShapes)
|
||||
{
|
||||
if (!assetConfiguration.m_asset.IsReady())
|
||||
{
|
||||
@@ -896,13 +896,13 @@ namespace PhysX
|
||||
const Physics::ColliderConfiguration& originalColliderConfiguration, bool hasNonUniformScale,
|
||||
AZ::u8 subdivisionLevel, AZStd::vector<AZStd::shared_ptr<Physics::Shape>>& resultingShapes)
|
||||
{
|
||||
Physics::ShapeConfigurationList resultingColliderShapeConfigs;
|
||||
AzPhysics::ShapeColliderPairList resultingColliderShapeConfigs;
|
||||
GetColliderShapeConfigsFromAsset(assetConfiguration, originalColliderConfiguration,
|
||||
hasNonUniformScale, subdivisionLevel, resultingColliderShapeConfigs);
|
||||
|
||||
resultingShapes.reserve(resultingShapes.size() + resultingColliderShapeConfigs.size());
|
||||
|
||||
for (const Physics::ShapeConfigurationPair& shapeConfigPair : resultingColliderShapeConfigs)
|
||||
for (const AzPhysics::ShapeColliderPair& shapeConfigPair : resultingColliderShapeConfigs)
|
||||
{
|
||||
// Scale the collider offset
|
||||
shapeConfigPair.first->m_position *= shapeConfigPair.second->m_scale;
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace PhysX
|
||||
|
||||
void GetColliderShapeConfigsFromAsset(const Physics::PhysicsAssetShapeConfiguration& assetConfiguration,
|
||||
const Physics::ColliderConfiguration& originalColliderConfiguration,
|
||||
bool hasNonUniformScale, AZ::u8 subdivisionLevel, Physics::ShapeConfigurationList& resultingColliderShapes);
|
||||
bool hasNonUniformScale, AZ::u8 subdivisionLevel, AzPhysics::ShapeColliderPairList& resultingColliderShapes);
|
||||
|
||||
//! Gets the scale from the entity's Transform component.
|
||||
AZ::Vector3 GetTransformScale(AZ::EntityId entityId);
|
||||
|
||||
Reference in New Issue
Block a user