Merge branch 'physics-settings' of https://github.com/Tryibion/FlaxEngine into Tryibion-physics-settings
This commit is contained in:
@@ -890,17 +890,46 @@ void* PhysicsBackend::CreateScene(const PhysicsSettings& settings)
|
|||||||
sceneDesc.gravity = C2P(settings.DefaultGravity);
|
sceneDesc.gravity = C2P(settings.DefaultGravity);
|
||||||
sceneDesc.flags |= PxSceneFlag::eENABLE_ACTIVE_ACTORS;
|
sceneDesc.flags |= PxSceneFlag::eENABLE_ACTIVE_ACTORS;
|
||||||
if (!settings.DisableCCD)
|
if (!settings.DisableCCD)
|
||||||
sceneDesc.flags |= PxSceneFlag::eENABLE_CCD;
|
sceneDesc.flags |= PxSceneFlag::eENABLE_CCD | PxSceneFlag::eENABLE_PCM;
|
||||||
sceneDesc.simulationEventCallback = &scenePhysX->EventsCallback;
|
sceneDesc.simulationEventCallback = &scenePhysX->EventsCallback;
|
||||||
sceneDesc.filterShader = FilterShader;
|
sceneDesc.filterShader = FilterShader;
|
||||||
sceneDesc.bounceThresholdVelocity = settings.BounceThresholdVelocity;
|
sceneDesc.bounceThresholdVelocity = settings.BounceThresholdVelocity;
|
||||||
sceneDesc.solverType = PxSolverType::ePGS;
|
|
||||||
|
switch (settings.SolverType)
|
||||||
|
{
|
||||||
|
case PhysicsSolverType::ProjectedGaussSeidelIterativeSolver:
|
||||||
|
sceneDesc.solverType = PxSolverType::ePGS;
|
||||||
|
break;
|
||||||
|
case PhysicsSolverType::DefaultTemporalGaussSeidelSolver:
|
||||||
|
sceneDesc.solverType = PxSolverType::eTGS;
|
||||||
|
break;
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
|
||||||
|
sceneDesc.solverType = PxSolverType::eTGS;
|
||||||
if (sceneDesc.cpuDispatcher == nullptr)
|
if (sceneDesc.cpuDispatcher == nullptr)
|
||||||
{
|
{
|
||||||
scenePhysX->CpuDispatcher = PxDefaultCpuDispatcherCreate(Math::Clamp<uint32>(Platform::GetCPUInfo().ProcessorCoreCount - 1, 1, 4));
|
scenePhysX->CpuDispatcher = PxDefaultCpuDispatcherCreate(Math::Clamp<uint32>(Platform::GetCPUInfo().ProcessorCoreCount - 1, 1, 4));
|
||||||
CHECK_INIT(scenePhysX->CpuDispatcher, "PxDefaultCpuDispatcherCreate failed!");
|
CHECK_INIT(scenePhysX->CpuDispatcher, "PxDefaultCpuDispatcherCreate failed!");
|
||||||
sceneDesc.cpuDispatcher = scenePhysX->CpuDispatcher;
|
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;
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
|
||||||
// Create scene
|
// Create scene
|
||||||
scenePhysX->Scene = PhysX->createScene(sceneDesc);
|
scenePhysX->Scene = PhysX->createScene(sceneDesc);
|
||||||
|
|||||||
@@ -6,6 +6,50 @@
|
|||||||
#include "Engine/Core/Math/Vector3.h"
|
#include "Engine/Core/Math/Vector3.h"
|
||||||
#include "Types.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>
|
||||||
|
/// Sweep and prune.
|
||||||
|
/// </summary>
|
||||||
|
SweepAndPrune = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multi box pruning.
|
||||||
|
/// </summary>
|
||||||
|
MultiboxPruning = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Automatic box pruning.
|
||||||
|
/// </summary>
|
||||||
|
AutomaticBoxPruning = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parallel automatic box pruning.
|
||||||
|
/// </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>
|
||||||
|
/// Projected Gauss-Seidel iterative solver.
|
||||||
|
/// </summary>
|
||||||
|
ProjectedGaussSeidelIterativeSolver = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default Temporal Gauss-Seidel solver.
|
||||||
|
/// </summary>
|
||||||
|
DefaultTemporalGaussSeidelSolver = 1,
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Physics simulation settings container.
|
/// Physics simulation settings container.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -43,6 +87,18 @@ public:
|
|||||||
API_FIELD(Attributes="EditorOrder(70), EditorDisplay(\"Simulation\")")
|
API_FIELD(Attributes="EditorOrder(70), EditorDisplay(\"Simulation\")")
|
||||||
bool DisableCCD = false;
|
bool DisableCCD = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Broad phase algorithm to use in the simulation.
|
||||||
|
/// </summary>
|
||||||
|
API_FIELD(Attributes="EditorOrder(71), EditorDisplay(\"Simulation\")")
|
||||||
|
PhysicsBroadPhaseType BroadPhaseType = PhysicsBroadPhaseType::SweepAndPrune;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The solver type to use in the simulation.
|
||||||
|
/// </summary>
|
||||||
|
API_FIELD(Attributes="EditorOrder(72), EditorDisplay(\"Simulation\")")
|
||||||
|
PhysicsSolverType SolverType = PhysicsSolverType::ProjectedGaussSeidelIterativeSolver;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum allowed delta time (in seconds) for the physics simulation step.
|
/// The maximum allowed delta time (in seconds) for the physics simulation step.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user