Merge branch 'main' into non-uniform-scale-visibility

This commit is contained in:
greerdv
2021-04-15 14:17:11 +01:00
2683 changed files with 45449 additions and 543490 deletions
@@ -319,7 +319,8 @@ namespace PhysX
void EditorColliderComponent::Activate()
{
if (m_sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
m_sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
if (m_sceneInterface)
{
m_editorSceneHandle = m_sceneInterface->GetSceneHandle(AzPhysics::EditorPhysicsSceneName);
}
@@ -696,7 +697,7 @@ namespace PhysX
// Here we check the material indices assigned to every shape and validate that every index is used at least once.
// It's not an error if the validation fails here but something we want to let the designers know about.
size_t surfacesNum = physicsAsset->m_assetData.m_surfaceNames.size();
[[maybe_unused]] size_t surfacesNum = physicsAsset->m_assetData.m_surfaceNames.size();
const AZStd::vector<AZ::u16>& indexPerShape = physicsAsset->m_assetData.m_materialIndexPerShape;
AZStd::unordered_set<AZ::u16> usedIndices;
@@ -879,7 +880,6 @@ namespace PhysX
return;
}
const AZ::Data::Asset<Pipeline::MeshAsset>& physicsAsset = m_shapeConfiguration.m_physicsAsset.m_pxAsset;
const Physics::PhysicsAssetShapeConfiguration& physicsAssetConfiguration = m_shapeConfiguration.m_physicsAsset.m_configuration;
Physics::ShapeConfigurationList shapeConfigList;
@@ -422,12 +422,11 @@ namespace PhysX
AZ::ConstSplinePtr splinePtr = nullptr;
LmbrCentral::SplineComponentRequestBus::EventResult(splinePtr, GetEntityId()
, &LmbrCentral::SplineComponentRequestBus::Events::GetSpline);
AZ::Entity* entity = GetEntity();
AZ_Warning("PhysX EditorForceRegionComponent"
, splinePtr!=nullptr
, "Please add spline shape for force region in entity <%s: %s>."
, entity->GetName().c_str()
, entity->GetId().ToString().c_str());
, GetEntity()->GetName().c_str()
, GetEntity()->GetId().ToString().c_str());
}
ForceRegionNotificationBus::Broadcast(
@@ -645,7 +645,8 @@ namespace PhysX
m_currentNonUniformScale = AZ::Vector3::CreateOne();
AZ::NonUniformScaleRequestBus::EventResult(m_currentNonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
if (m_sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
m_sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
if (m_sceneInterface)
{
m_editorSceneHandle = m_sceneInterface->GetSceneHandle(AzPhysics::EditorPhysicsSceneName);
}
@@ -60,7 +60,6 @@ namespace PhysX
behaviorContext->EBus<ForceWorldSpaceRequestBus>("ForceWorldSpaceRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "physics")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::Preview)
->Attribute(AZ::Script::Attributes::Category, "PhysX")
->Event("SetDirection", &ForceWorldSpaceRequestBus::Events::SetDirection)
->Event("GetDirection", &ForceWorldSpaceRequestBus::Events::GetDirection)
@@ -133,7 +132,6 @@ namespace PhysX
behaviorContext->EBus<ForceLocalSpaceRequestBus>("ForceLocalSpaceRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "physics")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::Preview)
->Attribute(AZ::Script::Attributes::Category, "PhysX")
->Event("SetDirection", &ForceLocalSpaceRequestBus::Events::SetDirection)
->Event("GetDirection", &ForceLocalSpaceRequestBus::Events::GetDirection)
@@ -201,7 +199,6 @@ namespace PhysX
behaviorContext->EBus<ForcePointRequestBus>("ForcePointRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "physics")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::Preview)
->Attribute(AZ::Script::Attributes::Category, "PhysX")
->Event("SetMagnitude", &ForcePointRequestBus::Events::SetMagnitude)
->Event("GetMagnitude", &ForcePointRequestBus::Events::GetMagnitude)
@@ -274,7 +271,6 @@ namespace PhysX
behaviorContext->EBus<ForceSplineFollowRequestBus>("ForceSplineFollowRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "physics")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::Preview)
->Attribute(AZ::Script::Attributes::Category, "PhysX")
->Event("SetDampingRatio", &ForceSplineFollowRequestBus::Events::SetDampingRatio)
->Event("GetDampingRatio", &ForceSplineFollowRequestBus::Events::GetDampingRatio)
@@ -418,7 +414,6 @@ namespace PhysX
behaviorContext->EBus<ForceSimpleDragRequestBus>("ForceSimpleDragRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "physics")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::Preview)
->Attribute(AZ::Script::Attributes::Category, "PhysX")
->Event("SetDensity", &ForceSimpleDragRequestBus::Events::SetDensity)
->Event("GetDensity", &ForceSimpleDragRequestBus::Events::GetDensity)
@@ -489,7 +484,6 @@ namespace PhysX
behaviorContext->EBus<ForceLinearDampingRequestBus>("ForceLinearDampingRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "physics")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::Preview)
->Attribute(AZ::Script::Attributes::Category, "PhysX")
->Event("SetDamping", &ForceLinearDampingRequestBus::Events::SetDamping)
->Event("GetDamping", &ForceLinearDampingRequestBus::Events::GetDamping)
+1 -1
View File
@@ -80,7 +80,7 @@ namespace PhysX
#if defined(PHYSX_EDITOR)
{
AZStd::unique_ptr<AZ::DynamicModuleHandle> sceneCoreModule = AZ::DynamicModuleHandle::Create("SceneCore");
bool ok = sceneCoreModule->Load(true/*isInitializeFunctionRequired*/);
[[maybe_unused]] bool ok = sceneCoreModule->Load(true/*isInitializeFunctionRequired*/);
AZ_Error("PhysX::Module", ok, "Error loading SceneCore module");
m_modules.push_back(AZStd::move(sceneCoreModule));
@@ -104,9 +104,11 @@ namespace PhysX
PhysX::PhysXScene* physxScene = nullptr;
if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
{
if (scene = physicsSystem->GetScene(sceneHandle))
scene = physicsSystem->GetScene(sceneHandle);
if (scene)
{
if (physxScene = azrtti_cast<PhysX::PhysXScene*>(scene))
physxScene = azrtti_cast<PhysX::PhysXScene*>(scene);
if (physxScene)
{
manager = physxScene->GetOrCreateControllerManager();
}
@@ -82,7 +82,7 @@ namespace PhysX
void CharacterControllerComponent::Activate()
{
EnablePhysics();
CreateController();
AZ::TransformNotificationBus::Handler::BusConnect(GetEntityId());
Physics::CharacterRequestBus::Handler::BusConnect(GetEntityId());
@@ -92,7 +92,7 @@ namespace PhysX
void CharacterControllerComponent::Deactivate()
{
DisablePhysics();
DestroyController();
Physics::CollisionFilteringRequestBus::Handler::BusDisconnect();
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
@@ -193,47 +193,17 @@ namespace PhysX
void CharacterControllerComponent::EnablePhysics()
{
if (IsPhysicsEnabled())
{
return;
}
bool success = CreateController();
if (success)
{
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsEnabled);
}
CreateController();
}
void CharacterControllerComponent::DisablePhysics()
{
if(IsPhysicsEnabled())
{
m_controller->DisablePhysics();
// The character is first removed from the scene, and then its deletion is deferred.
// This ensures trigger exit events are raised correctly on deleted objects.
{
auto* scene = azdynamic_cast<PhysX::PhysXScene*>(m_controller->GetScene());
AZ_Assert(scene, "Invalid PhysX scene");
scene->DeferDelete(AZStd::move(m_controller));
m_controller.reset();
}
m_preSimulateHandler.Disconnect();
if (CharacterControllerRequestBus::Handler::BusIsConnected())
{
CharacterControllerRequestBus::Handler::BusDisconnect();
}
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsDisabled);
}
DestroyController();
}
bool CharacterControllerComponent::IsPhysicsEnabled() const
{
return m_controller && m_controller->m_simulating;
return m_controller != nullptr;
}
AZ::Aabb CharacterControllerComponent::GetAabb() const
@@ -410,14 +380,19 @@ namespace PhysX
}
}
bool CharacterControllerComponent::CreateController()
void CharacterControllerComponent::CreateController()
{
if (m_controller)
{
return;
}
AzPhysics::SceneHandle defaultSceneHandle = AzPhysics::InvalidSceneHandle;
Physics::DefaultWorldBus::BroadcastResult(defaultSceneHandle, &Physics::DefaultWorldRequests::GetDefaultSceneHandle);
if (defaultSceneHandle == AzPhysics::InvalidSceneHandle)
{
AZ_Error("PhysX Character Controller Component", false, "Failed to retrieve default scene.");
return false;
return;
}
m_characterConfig->m_debugName = GetEntity()->GetName();
@@ -427,7 +402,7 @@ namespace PhysX
if (!m_controller)
{
AZ_Error("PhysX Character Controller Component", false, "Failed to create character controller.");
return false;
return;
}
m_controller->EnablePhysics(*m_characterConfig);
@@ -437,6 +412,7 @@ namespace PhysX
// make the foot position coincide with the entity position.
m_controller->SetBasePosition(entityTranslation);
AttachColliders(*m_controller);
CharacterControllerRequestBus::Handler::BusConnect(GetEntityId());
m_preSimulateHandler = AzPhysics::SystemEvents::OnPresimulateEvent::Handler(
@@ -451,7 +427,32 @@ namespace PhysX
physXSystem->RegisterPreSimulateEvent(m_preSimulateHandler);
}
return true;
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsEnabled);
}
void CharacterControllerComponent::DestroyController()
{
if (!m_controller)
{
return;
}
m_controller->DisablePhysics();
// The character is first removed from the scene, and then its deletion is deferred.
// This ensures trigger exit events are raised correctly on deleted objects.
{
auto* scene = azdynamic_cast<PhysX::PhysXScene*>(m_controller->GetScene());
AZ_Assert(scene, "Invalid PhysX scene");
scene->DeferDelete(AZStd::move(m_controller));
m_controller.reset();
}
m_preSimulateHandler.Disconnect();
CharacterControllerRequestBus::Handler::BusDisconnect();
Physics::WorldBodyNotificationBus::Event(GetEntityId(), &Physics::WorldBodyNotifications::OnPhysicsDisabled);
}
void CharacterControllerComponent::AttachColliders(Physics::Character& character)
@@ -129,7 +129,8 @@ namespace PhysX
void ToggleCollisionLayer(const AZStd::string& layerName, AZ::Crc32 colliderTag, bool enabled) override;
private:
bool CreateController();
void CreateController();
void DestroyController();
void AttachColliders(Physics::Character& character);
void OnPreSimulate(float deltaTime);
@@ -154,11 +154,7 @@ namespace PhysX
void RagdollComponent::Deactivate()
{
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
AzFramework::RagdollPhysicsRequestBus::Handler::BusDisconnect();
AzFramework::RagdollPhysicsNotificationBus::Event(GetEntityId(),
&AzFramework::RagdollPhysicsNotifications::OnRagdollDeactivated);
m_ragdoll.reset();
DestroyRagdoll();
AzFramework::CharacterPhysicsDataNotificationBus::Handler::BusDisconnect();
}
@@ -266,9 +262,16 @@ namespace PhysX
return AzPhysics::SceneQueryHit();
}
void RagdollComponent::OnRagdollConfigurationReady(const Physics::RagdollConfiguration& ragdollConfigurationRef)
void RagdollComponent::OnRagdollConfigurationReady(const Physics::RagdollConfiguration& ragdollConfiguration)
{
Physics::RagdollConfiguration ragdollConfiguration( ragdollConfigurationRef );
CreateRagdoll(ragdollConfiguration);
}
void RagdollComponent::CreateRagdoll(const Physics::RagdollConfiguration& ragdollConfigurationRef)
{
DestroyRagdoll();
Physics::RagdollConfiguration ragdollConfiguration(ragdollConfigurationRef);
const size_t numNodes = ragdollConfiguration.m_nodes.size();
@@ -346,6 +349,19 @@ namespace PhysX
&AzFramework::RagdollPhysicsNotifications::OnRagdollActivated);
}
void RagdollComponent::DestroyRagdoll()
{
if (m_ragdoll)
{
Physics::WorldBodyRequestBus::Handler::BusDisconnect();
AzFramework::RagdollPhysicsRequestBus::Handler::BusDisconnect();
AzFramework::RagdollPhysicsNotificationBus::Event(GetEntityId(),
&AzFramework::RagdollPhysicsNotifications::OnRagdollDeactivated);
m_ragdoll.reset();
}
}
// deprecated Cry functions
void RagdollComponent::EnterRagdoll()
{
@@ -100,6 +100,9 @@ namespace PhysX
static bool VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
private:
void CreateRagdoll(const Physics::RagdollConfiguration& ragdollConfiguration);
void DestroyRagdoll();
bool IsJointProjectionVisible();
AZStd::unique_ptr<Ragdoll> m_ragdoll;
+6 -6
View File
@@ -1011,9 +1011,9 @@ namespace PhysX
m_pxScene->getSimulationStatistics(stats);
}
const char* RootCategory = "PhysX/%s/%s";
[[maybe_unused]] const char* RootCategory = "PhysX/%s/%s";
const char* ShapesSubCategory = "Shapes";
[[maybe_unused]] const char* ShapesSubCategory = "Shapes";
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbShapes[PxGeometryType::eSPHERE], RootCategory, ShapesSubCategory, "Sphere");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbShapes[PxGeometryType::ePLANE], RootCategory, ShapesSubCategory, "Plane");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbShapes[PxGeometryType::eCAPSULE], RootCategory, ShapesSubCategory, "Capsule");
@@ -1022,7 +1022,7 @@ namespace PhysX
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbShapes[PxGeometryType::eTRIANGLEMESH], RootCategory, ShapesSubCategory, "TriangleMesh");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbShapes[PxGeometryType::eHEIGHTFIELD], RootCategory, ShapesSubCategory, "Heightfield");
const char* ObjectsSubCategory = "Objects";
[[maybe_unused]] const char* ObjectsSubCategory = "Objects";
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbActiveConstraints, RootCategory, ObjectsSubCategory, "ActiveConstraints");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbActiveDynamicBodies, RootCategory, ObjectsSubCategory, "ActiveDynamicBodies");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbActiveKinematicBodies, RootCategory, ObjectsSubCategory, "ActiveKinematicBodies");
@@ -1032,13 +1032,13 @@ namespace PhysX
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbAggregates, RootCategory, ObjectsSubCategory, "Aggregates");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbArticulations, RootCategory, ObjectsSubCategory, "Articulations");
const char* SolverSubCategory = "Solver";
[[maybe_unused]] const char* SolverSubCategory = "Solver";
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.nbAxisSolverConstraints, RootCategory, SolverSubCategory, "AxisSolverConstraints");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.compressedContactSize, RootCategory, SolverSubCategory, "CompressedContactSize");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.requiredContactConstraintMemory, RootCategory, SolverSubCategory, "RequiredContactConstraintMemory");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.peakConstraintMemory, RootCategory, SolverSubCategory, "PeakConstraintMemory");
const char* BroadphaseSubCategory = "Broadphase";
[[maybe_unused]] const char* BroadphaseSubCategory = "Broadphase";
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.getNbBroadPhaseAdds(), RootCategory, BroadphaseSubCategory, "BroadPhaseAdds");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, stats.getNbBroadPhaseRemoves(), RootCategory, BroadphaseSubCategory, "BroadPhaseRemoves");
@@ -1060,7 +1060,7 @@ namespace PhysX
}
}
const char* CollisionsSubCategory = "Collisions";
[[maybe_unused]] const char* CollisionsSubCategory = "Collisions";
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, ccdPairs, RootCategory, CollisionsSubCategory, "CCDPairs");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, modifiedPairs, RootCategory, CollisionsSubCategory, "ModifiedPairs");
AZ_PROFILE_DATAPOINT(AZ::Debug::ProfileCategory::Physics, triggerPairs, RootCategory, CollisionsSubCategory, "TriggerPairs");
@@ -31,7 +31,7 @@ namespace PhysX
const char* GetDescription() const override { return "PhysX general memory allocator"; }
};
//! Implementation of the PhysX memory allocation callback interface using Lumberyard allocator.
//! Implementation of the PhysX memory allocation callback interface using Open 3D Engine allocator.
class PxAzAllocatorCallback
: public physx::PxAllocatorCallback
{
@@ -16,7 +16,7 @@
namespace PhysX
{
//! CPU dispatcher which directs tasks submitted by PhysX to the Lumberyard scheduling system.
//! CPU dispatcher which directs tasks submitted by PhysX to the Open 3D Engine scheduling system.
class PhysXCpuDispatcher
: public physx::PxCpuDispatcher
{
@@ -32,6 +32,6 @@ namespace PhysX
physx::PxU32 getWorkerCount() const override;
};
//! Creates a CPU dispatcher which directs tasks submitted by PhysX to the Lumberyard scheduling system.
//! Creates a CPU dispatcher which directs tasks submitted by PhysX to the Open 3D Engine scheduling system.
PhysXCpuDispatcher* PhysXCpuDispatcherCreate();
} // namespace PhysX
+1 -1
View File
@@ -17,7 +17,7 @@
namespace PhysX
{
//! Handles PhysX tasks in the Lumberyard job scheduler.
//! Handles PhysX tasks in the Open 3D Engine job scheduler.
class PhysXJob
: public AZ::Job
{
@@ -15,7 +15,7 @@
namespace PhysX
{
//! Implementation of the PhysX error callback interface directing errors to Lumberyard error output.
//! Implementation of the PhysX error callback interface directing errors to Open 3D Engine error output.
class PxAzErrorCallback
: public physx::PxErrorCallback
{
+3 -2
View File
@@ -466,7 +466,7 @@ namespace PhysX
void SystemComponent::AddColliderComponentToEntity(AZ::Entity* entity, const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& shapeConfiguration, [[maybe_unused]] bool addEditorComponents)
{
Physics::ShapeType shapeType = shapeConfiguration.GetShapeType();
[[maybe_unused]] Physics::ShapeType shapeType = shapeConfiguration.GetShapeType();
#ifdef PHYSX_EDITOR
if (addEditorComponents)
@@ -664,7 +664,8 @@ namespace PhysX
void SystemComponent::ActivatePhysXSystem()
{
if (m_physXSystem = GetPhysXSystem())
m_physXSystem = GetPhysXSystem();
if (m_physXSystem)
{
m_physXSystem->RegisterSystemInitializedEvent(m_onSystemInitializedHandler);
m_physXSystem->RegisterSystemConfigurationChangedEvent(m_onSystemConfigChangedHandler);
+1 -1
View File
@@ -53,7 +53,7 @@ namespace PhysX
/// System component for PhysX.
/// The system component handles underlying tasks such as initialization and shutdown of PhysX, managing a
/// Lumberyard memory allocator for PhysX allocations, scheduling for PhysX jobs, and connections to the PhysX
/// Open 3D Engine memory allocator for PhysX allocations, scheduling for PhysX jobs, and connections to the PhysX
/// Visual Debugger. It also owns fundamental PhysX objects which manage worlds, rigid bodies, shapes, materials,
/// constraints etc., and perform cooking (processing assets such as meshes and heightfields ready for use in PhysX).
class SystemComponent