Merge remote-tracking branch 'origin/master' into 1.7

# Conflicts:
#	Source/Engine/Physics/PhysX/SimulationEventCallbackPhysX.cpp
This commit is contained in:
Wojtek Figat
2023-09-13 10:29:28 +02:00
22 changed files with 1328 additions and 136 deletions

View File

@@ -223,9 +223,10 @@ void WheeledVehicle::Setup()
return;
// Release previous
void* scene = GetPhysicsScene()->GetPhysicsScene();
if (_vehicle)
{
PhysicsBackend::RemoveVehicle(GetPhysicsScene()->GetPhysicsScene(), this);
PhysicsBackend::RemoveVehicle(scene, this);
PhysicsBackend::DestroyVehicle(_vehicle, (int32)_driveTypeCurrent);
_vehicle = nullptr;
}
@@ -236,7 +237,7 @@ void WheeledVehicle::Setup()
if (!_vehicle)
return;
_driveTypeCurrent = _driveType;
PhysicsBackend::AddVehicle(GetPhysicsScene()->GetPhysicsScene(), this);
PhysicsBackend::AddVehicle(scene, this);
PhysicsBackend::SetRigidDynamicActorSolverIterationCounts(_actor, 12, 4);
#else
LOG(Fatal, "Vehicles are not supported.");
@@ -358,8 +359,23 @@ void WheeledVehicle::OnColliderChanged(Collider* c)
{
RigidBody::OnColliderChanged(c);
// Rebuild vehicle when someone adds/removed wheels
Setup();
if (_useWheelsUpdates)
{
// Rebuild vehicle when someone adds/removed wheels
Setup();
}
}
void WheeledVehicle::OnActiveInTreeChanged()
{
// Skip rebuilds from per-wheel OnColliderChanged when whole vehicle is toggled
_useWheelsUpdates = false;
RigidBody::OnActiveInTreeChanged();
_useWheelsUpdates = true;
// Perform whole rebuild when it gets activated
if (IsActiveInHierarchy())
Setup();
}
void WheeledVehicle::OnPhysicsSceneChanged(PhysicsScene* previous)

View File

@@ -329,6 +329,7 @@ private:
DifferentialSettings _differential;
GearboxSettings _gearbox;
bool _fixInvalidForwardDir = false; // [Deprecated on 13.06.2023, expires on 13.06.2025]
bool _useWheelsUpdates = true;
public:
/// <summary>
@@ -484,6 +485,7 @@ public:
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
void OnColliderChanged(Collider* c) override;
void OnActiveInTreeChanged() override;
protected:
void OnPhysicsSceneChanged(PhysicsScene* previous) override;

View File

@@ -1231,18 +1231,42 @@ void* PhysicsBackend::CreateScene(const PhysicsSettings& settings)
PxSceneDesc sceneDesc(ToleranceScale);
sceneDesc.gravity = C2P(settings.DefaultGravity);
sceneDesc.flags |= PxSceneFlag::eENABLE_ACTIVE_ACTORS;
sceneDesc.flags |= PxSceneFlag::eENABLE_PCM;
if (!settings.DisableCCD)
sceneDesc.flags |= PxSceneFlag::eENABLE_CCD;
sceneDesc.simulationEventCallback = &scenePhysX->EventsCallback;
sceneDesc.filterShader = FilterShader;
sceneDesc.bounceThresholdVelocity = settings.BounceThresholdVelocity;
sceneDesc.solverType = PxSolverType::ePGS;
switch (settings.SolverType)
{
case PhysicsSolverType::ProjectedGaussSeidelIterativeSolver:
sceneDesc.solverType = PxSolverType::ePGS;
break;
case PhysicsSolverType::TemporalGaussSeidelSolver:
sceneDesc.solverType = PxSolverType::eTGS;
break;
}
if (sceneDesc.cpuDispatcher == nullptr)
{
scenePhysX->CpuDispatcher = PxDefaultCpuDispatcherCreate(Math::Clamp<uint32>(Platform::GetCPUInfo().ProcessorCoreCount - 1, 1, 4));
CHECK_INIT(scenePhysX->CpuDispatcher, "PxDefaultCpuDispatcherCreate failed!");
sceneDesc.cpuDispatcher = scenePhysX->CpuDispatcher;
}
switch (settings.BroadPhaseType)
{
case PhysicsBroadPhaseType::SweepAndPrune:
sceneDesc.broadPhaseType = PxBroadPhaseType::eSAP;
break;
case PhysicsBroadPhaseType::MultiBoxPruning:
sceneDesc.broadPhaseType = PxBroadPhaseType::eMBP;
break;
case PhysicsBroadPhaseType::AutomaticBoxPruning:
sceneDesc.broadPhaseType = PxBroadPhaseType::eABP;
break;
case PhysicsBroadPhaseType::ParallelAutomaticBoxPruning:
sceneDesc.broadPhaseType = PxBroadPhaseType::ePABP;
break;
}
// Create scene
scenePhysX->Scene = PhysX->createScene(sceneDesc);

View File

@@ -11,8 +11,10 @@
namespace
{
void ClearColliderFromCollection(PhysicsColliderActor* collider, Array<SimulationEventCallback::CollidersPair>& collection)
void ClearColliderFromCollection(const PhysicsColliderActor* collider, Array<SimulationEventCallback::CollidersPair>& collection)
{
if (collection.IsEmpty())
return;
for (int32 i = 0; i < collection.Count(); i++)
{
if (collection[i].First == collider || collection[i].Second == collider)

View File

@@ -57,6 +57,8 @@ void PhysicsSettings::Deserialize(DeserializeStream& stream, ISerializeModifier*
DESERIALIZE(FrictionCombineMode);
DESERIALIZE(RestitutionCombineMode);
DESERIALIZE(DisableCCD);
DESERIALIZE(BroadPhaseType);
DESERIALIZE(SolverType);
DESERIALIZE(MaxDeltaTime);
DESERIALIZE(EnableSubstepping);
DESERIALIZE(SubstepDeltaTime);

View File

@@ -6,6 +6,50 @@
#include "Engine/Core/Math/Vector3.h"
#include "Types.h"
/// <summary>
/// Broad phase algorithm used in the simulation.
/// <see href="https://nvidia-omniverse.github.io/PhysX/physx/5.1.0/_build/physx/latest/struct_px_broad_phase_type.html"/>
/// </summary>
API_ENUM() enum class PhysicsBroadPhaseType
{
/// <summary>
/// 3-axes sweep-and-prune. Good generic choice with great performance when many objects are sleeping.
/// </summary>
SweepAndPrune = 0,
/// <summary>
/// Alternative broad phase algorithm that does not suffer from the same performance issues as SAP when all objects are moving or when inserting large numbers of objects.
/// </summary>
MultiBoxPruning = 1,
/// <summary>
/// Revisited implementation of MBP, which automatically manages broad-phase regions.
/// </summary>
AutomaticBoxPruning = 2,
/// <summary>
/// Parallel implementation of ABP. It can often be the fastest (CPU) broadphase, but it can use more memory than ABP.
/// </summary>
ParallelAutomaticBoxPruning = 3,
};
/// <summary>
/// The type of solver used in the simulation.
/// <see href="https://nvidia-omniverse.github.io/PhysX/physx/5.1.0/_build/physx/latest/struct_px_solver_type.html"/>
/// </summary>
API_ENUM() enum class PhysicsSolverType
{
/// <summary>
/// The iterative sequential impulse solver.
/// </summary>
ProjectedGaussSeidelIterativeSolver = 0,
/// <summary>
/// Non linear iterative solver. This kind of solver can lead to improved convergence and handle large mass ratios, long chains and jointed systems better. It is slightly more expensive than the default solver and can introduce more energy to correct joint and contact errors.
/// </summary>
TemporalGaussSeidelSolver = 1,
};
/// <summary>
/// Physics simulation settings container.
/// </summary>
@@ -43,6 +87,18 @@ public:
API_FIELD(Attributes="EditorOrder(70), EditorDisplay(\"Simulation\")")
bool DisableCCD = false;
/// <summary>
/// Broad phase algorithm to use in the simulation.
/// </summary>
API_FIELD(Attributes="EditorOrder(71), EditorDisplay(\"Simulation\")")
PhysicsBroadPhaseType BroadPhaseType = PhysicsBroadPhaseType::ParallelAutomaticBoxPruning;
/// <summary>
/// The solver type to use in the simulation.
/// </summary>
API_FIELD(Attributes="EditorOrder(72), EditorDisplay(\"Simulation\")")
PhysicsSolverType SolverType = PhysicsSolverType::ProjectedGaussSeidelIterativeSolver;
/// <summary>
/// The maximum allowed delta time (in seconds) for the physics simulation step.
/// </summary>