Integrating up through commit 90f050496
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzFramework/Physics/ColliderComponentBus.h>
|
||||
#include <AzFramework/Physics/SystemBus.h>
|
||||
#include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
|
||||
#include <AzFramework/Physics/Configuration/StaticRigidBodyConfiguration.h>
|
||||
#include <LyViewPaneNames.h>
|
||||
#include <ShapeColliderComponent.h>
|
||||
#include <EditorRigidBodyComponent.h>
|
||||
@@ -30,6 +32,7 @@
|
||||
#include <AzCore/Math/Geometry2DUtils.h>
|
||||
#include <cmath>
|
||||
|
||||
#include <RigidBodyStatic.h>
|
||||
#include <System/PhysXSystem.h>
|
||||
|
||||
namespace PhysX
|
||||
@@ -47,6 +50,7 @@ namespace PhysX
|
||||
m_colliderConfig.m_materialSelection.OnDefaultMaterialLibraryChanged(defaultMaterialLibrary);
|
||||
Physics::ColliderComponentEventBus::Event(GetEntityId(), &Physics::ColliderComponentEvents::OnColliderChanged);
|
||||
})
|
||||
, m_nonUniformScaleChangedHandler([this](const AZ::Vector3& scale) {OnNonUniformScaleChanged(scale);})
|
||||
{
|
||||
m_colliderConfig.SetPropertyVisibility(Physics::ColliderConfiguration::Offset, false);
|
||||
}
|
||||
@@ -182,13 +186,13 @@ namespace PhysX
|
||||
if (polygonPrismPtr)
|
||||
{
|
||||
const AZ::Vector3 uniformScale = Utils::GetUniformScale(GetEntityId());
|
||||
const AZ::Vector3 overallScale = uniformScale * m_currentNonUniformScale;
|
||||
|
||||
const AZStd::vector<AZ::Vector2>& vertices = polygonPrismPtr->m_vertexContainer.GetVertices();
|
||||
for (const auto& vertex : vertices)
|
||||
{
|
||||
const float scalarScale = uniformScale.GetX();
|
||||
const float scaledX = scalarScale * vertex.GetX();
|
||||
const float scaledY = scalarScale * vertex.GetY();
|
||||
const float scaledX = overallScale.GetX() * vertex.GetX();
|
||||
const float scaledY = overallScale.GetY() * vertex.GetY();
|
||||
m_geometryCache.m_cachedSamplePoints.emplace_back(AZ::Vector3(scaledX, scaledY, 0.0f));
|
||||
m_geometryCache.m_cachedSamplePoints.emplace_back(AZ::Vector3(scaledX, scaledY, m_geometryCache.m_height));
|
||||
}
|
||||
@@ -247,30 +251,26 @@ namespace PhysX
|
||||
return;
|
||||
}
|
||||
|
||||
AZStd::shared_ptr<Physics::World> editorWorld;
|
||||
Physics::EditorWorldBus::BroadcastResult(editorWorld, &Physics::EditorWorldRequests::GetEditorWorld);
|
||||
if (editorWorld)
|
||||
const AZ::Transform colliderTransform = GetWorldTM();
|
||||
|
||||
AzPhysics::StaticRigidBodyConfiguration configuration;
|
||||
configuration.m_orientation = colliderTransform.GetRotation();
|
||||
configuration.m_position = colliderTransform.GetTranslation();
|
||||
configuration.m_entityId = GetEntityId();
|
||||
configuration.m_debugName = GetEntity()->GetName();
|
||||
|
||||
AZStd::vector<AzPhysics::ShapeColliderPair> colliderShapePairs;
|
||||
colliderShapePairs.reserve(m_shapeConfigs.size());
|
||||
for (const auto& shapeConfig : m_shapeConfigs)
|
||||
{
|
||||
AZ::Transform colliderTransform = GetWorldTM();
|
||||
colliderShapePairs.emplace_back(&m_colliderConfig, shapeConfig.get());
|
||||
}
|
||||
configuration.m_colliderAndShapeData = colliderShapePairs;
|
||||
|
||||
Physics::WorldBodyConfiguration configuration;
|
||||
configuration.m_orientation = colliderTransform.GetRotation();
|
||||
configuration.m_position = colliderTransform.GetTranslation();
|
||||
configuration.m_entityId = GetEntityId();
|
||||
configuration.m_debugName = GetEntity()->GetName();
|
||||
|
||||
m_editorBody = AZ::Interface<Physics::System>::Get()->CreateStaticRigidBody(configuration);
|
||||
|
||||
for (const auto& shapeConfig : m_shapeConfigs)
|
||||
{
|
||||
AZStd::shared_ptr<Physics::Shape> shape = AZ::Interface<Physics::System>::Get()->CreateShape(m_colliderConfig, *shapeConfig);
|
||||
m_editorBody->AddShape(shape);
|
||||
}
|
||||
|
||||
if (!m_shapeConfigs.empty())
|
||||
{
|
||||
editorWorld->AddBody(*m_editorBody);
|
||||
}
|
||||
if (m_sceneInterface)
|
||||
{
|
||||
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());
|
||||
@@ -292,11 +292,12 @@ namespace PhysX
|
||||
&LmbrCentral::ShapeComponentRequests::GetShapeType);
|
||||
|
||||
const AZ::Vector3 uniformScale = Utils::GetUniformScale(GetEntityId());
|
||||
const AZ::Vector3 overallScale = uniformScale * m_currentNonUniformScale;
|
||||
|
||||
// using if blocks because switch statements aren't supported for values generated by the crc macro
|
||||
if (shapeCrc == ShapeConstants::Box)
|
||||
{
|
||||
UpdateBoxConfig(uniformScale);
|
||||
UpdateBoxConfig(overallScale);
|
||||
}
|
||||
|
||||
else if (shapeCrc == ShapeConstants::Capsule)
|
||||
@@ -561,7 +562,8 @@ namespace PhysX
|
||||
const float unscaledPrismHeight = polygonPrismPtr->GetHeight();
|
||||
|
||||
const AZ::Vector3 uniformScale = Utils::GetUniformScale(GetEntityId());
|
||||
m_geometryCache.m_height = uniformScale.GetX() * unscaledPrismHeight;
|
||||
const AZ::Vector3 overallScale = uniformScale * m_currentNonUniformScale;
|
||||
m_geometryCache.m_height = overallScale.GetZ() * unscaledPrismHeight;
|
||||
|
||||
int shapeConfigsCount = 0;
|
||||
bool refreshPropertyTree = false;
|
||||
@@ -584,7 +586,7 @@ namespace PhysX
|
||||
currentEdge = currentEdge->m_next;
|
||||
}
|
||||
|
||||
AZStd::optional<Physics::CookedMeshShapeConfiguration> shapeConfig = Utils::CreatePxCookedMeshConfiguration(points, uniformScale);
|
||||
AZStd::optional<Physics::CookedMeshShapeConfiguration> shapeConfig = Utils::CreatePxCookedMeshConfiguration(points, overallScale);
|
||||
|
||||
if (shapeConfig.has_value())
|
||||
{
|
||||
@@ -635,9 +637,19 @@ namespace PhysX
|
||||
AZ::TransformNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
LmbrCentral::ShapeComponentNotificationsBus::Handler::BusConnect(GetEntityId());
|
||||
PhysX::ColliderShapeRequestBus::Handler::BusConnect(GetEntityId());
|
||||
AZ::NonUniformScaleRequestBus::Event(GetEntityId(), &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent,
|
||||
m_nonUniformScaleChangedHandler);
|
||||
|
||||
AZ::TransformBus::EventResult(m_cachedWorldTransform, GetEntityId(), &AZ::TransformInterface::GetWorldTM);
|
||||
|
||||
m_currentNonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(m_currentNonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
||||
|
||||
if (m_sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
|
||||
{
|
||||
m_editorSceneHandle = m_sceneInterface->GetSceneHandle(AzPhysics::EditorPhysicsSceneName);
|
||||
}
|
||||
|
||||
UpdateShapeConfigs();
|
||||
|
||||
// Debug drawing
|
||||
@@ -660,7 +672,12 @@ namespace PhysX
|
||||
AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect();
|
||||
AzToolsFramework::Components::EditorComponentBase::Deactivate();
|
||||
|
||||
m_editorBody = nullptr;
|
||||
if (m_sceneInterface && m_editorBodyHandle != AzPhysics::InvalidSimulatedBodyHandle)
|
||||
{
|
||||
m_sceneInterface->RemoveSimulatedBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
m_editorBodyHandle = AzPhysics::InvalidSimulatedBodyHandle;
|
||||
m_editorBody = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// AzToolsFramework::EntitySelectionEvents
|
||||
@@ -695,22 +712,36 @@ namespace PhysX
|
||||
Physics::ColliderComponentEventBus::Event(GetEntityId(), &Physics::ColliderComponentEvents::OnColliderChanged);
|
||||
}
|
||||
|
||||
void EditorShapeColliderComponent::OnNonUniformScaleChanged(const AZ::Vector3& scale)
|
||||
{
|
||||
m_currentNonUniformScale = scale;
|
||||
|
||||
UpdateShapeConfigs();
|
||||
|
||||
CreateStaticEditorCollider();
|
||||
m_geometryCache.m_cachedSamplePointsDirty = true;
|
||||
Physics::ColliderComponentEventBus::Event(GetEntityId(), &Physics::ColliderComponentEvents::OnColliderChanged);
|
||||
}
|
||||
|
||||
void EditorShapeColliderComponent::EnablePhysics()
|
||||
{
|
||||
if (!IsPhysicsEnabled())
|
||||
if (!IsPhysicsEnabled() && m_sceneInterface)
|
||||
{
|
||||
CreateStaticEditorCollider();
|
||||
m_sceneInterface->EnableSimulationOfBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorShapeColliderComponent::DisablePhysics()
|
||||
{
|
||||
m_editorBody.reset();
|
||||
if (m_sceneInterface)
|
||||
{
|
||||
m_sceneInterface->DisableSimulationOfBody(m_editorSceneHandle, m_editorBodyHandle);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorShapeColliderComponent::IsPhysicsEnabled() const
|
||||
{
|
||||
return m_editorBody && m_editorBody->GetWorld();
|
||||
return m_editorBody != nullptr && m_editorBody->m_simulating;
|
||||
}
|
||||
|
||||
AZ::Aabb EditorShapeColliderComponent::GetAabb() const
|
||||
@@ -722,18 +753,18 @@ namespace PhysX
|
||||
return AZ::Aabb::CreateNull();
|
||||
}
|
||||
|
||||
Physics::WorldBody* EditorShapeColliderComponent::GetWorldBody()
|
||||
AzPhysics::SimulatedBody* EditorShapeColliderComponent::GetWorldBody()
|
||||
{
|
||||
return m_editorBody.get();
|
||||
return m_editorBody;
|
||||
}
|
||||
|
||||
Physics::RayCastHit EditorShapeColliderComponent::RayCast(const Physics::RayCastRequest& request)
|
||||
AzPhysics::SceneQueryHit EditorShapeColliderComponent::RayCast(const AzPhysics::RayCastRequest& request)
|
||||
{
|
||||
if (m_editorBody)
|
||||
{
|
||||
return m_editorBody->RayCast(request);
|
||||
}
|
||||
return Physics::RayCastHit();
|
||||
return AzPhysics::SceneQueryHit();
|
||||
}
|
||||
|
||||
// LmbrCentral::ShapeComponentNotificationBus
|
||||
@@ -760,9 +791,10 @@ namespace PhysX
|
||||
if (polygonPrismPtr)
|
||||
{
|
||||
const AZ::Vector3 uniformScale = Utils::GetUniformScale(GetEntityId());
|
||||
const AZ::Vector3 overallScale = uniformScale * m_currentNonUniformScale;
|
||||
const float height = polygonPrismPtr->GetHeight();
|
||||
m_colliderDebugDraw.DrawPolygonPrism(debugDisplay, m_colliderConfig, m_mesh.GetDebugDrawPoints(height,
|
||||
uniformScale.GetX()));
|
||||
overallScale));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,7 +820,7 @@ namespace PhysX
|
||||
case Physics::ShapeType::Box:
|
||||
{
|
||||
const auto& boxConfig = static_cast<const Physics::BoxShapeConfiguration&>(*shapeConfig);
|
||||
m_colliderDebugDraw.DrawBox(debugDisplay, m_colliderConfig, boxConfig, AZ::Vector3::CreateOne(), true);
|
||||
m_colliderDebugDraw.DrawBox(debugDisplay, m_colliderConfig, boxConfig, m_currentNonUniformScale, false);
|
||||
break;
|
||||
}
|
||||
case Physics::ShapeType::Capsule:
|
||||
|
||||
Reference in New Issue
Block a user