PhysX 3.4 implementation

This commit is contained in:
rextimmy 2018-01-19 22:34:26 +10:00
parent 463cd50d0a
commit 3bbdd9b155
15 changed files with 527 additions and 418 deletions

View file

@ -35,12 +35,11 @@
#include "T3D/physics/physicsWorld.h" #include "T3D/physics/physicsWorld.h"
#include "core/util/tNamedFactory.h" #include "core/util/tNamedFactory.h"
PhysicsPlugin* PhysicsPlugin::smSingleton = NULL; PhysicsPlugin* PhysicsPlugin::smSingleton = NULL;
PhysicsResetSignal PhysicsPlugin::smPhysicsResetSignal; PhysicsResetSignal PhysicsPlugin::smPhysicsResetSignal;
bool PhysicsPlugin::smSinglePlayer = false; bool PhysicsPlugin::smSinglePlayer = false;
U32 PhysicsPlugin::smThreadCount = 2; U32 PhysicsPlugin::smThreadCount = 2;
bool PhysicsPlugin::smGpuAccelerationAllowed = false;
String PhysicsPlugin::smServerWorldName( "server" ); String PhysicsPlugin::smServerWorldName( "server" );
String PhysicsPlugin::smClientWorldName( "client" ); String PhysicsPlugin::smClientWorldName( "client" );
@ -51,6 +50,10 @@ AFTER_MODULE_INIT( Sim )
"@brief Informs the physics simulation if only a single player exists.\n\n" "@brief Informs the physics simulation if only a single player exists.\n\n"
"If true, optimizations will be implemented to better cater to a single player environmnent.\n\n" "If true, optimizations will be implemented to better cater to a single player environmnent.\n\n"
"@ingroup Physics\n"); "@ingroup Physics\n");
Con::addVariable("$Physics::gpuAccelerationAllowed", TypeBool, &PhysicsPlugin::smGpuAccelerationAllowed,
"@brief Informs the physics plugin if it is allowed to use gpu acceleration.\n\n"
"Not all physics implemenations or gpus can support gpu acceleration, this simply informs the plugin if it is allowed to try and use it or not.\n\n"
"@ingroup Physics\n");
Con::addVariable( "$pref::Physics::threadCount", TypeS32, &PhysicsPlugin::smThreadCount, Con::addVariable( "$pref::Physics::threadCount", TypeS32, &PhysicsPlugin::smThreadCount,
"@brief Number of threads to use in a single pass of the physics engine.\n\n" "@brief Number of threads to use in a single pass of the physics engine.\n\n"
"Defaults to 2 if not set.\n\n" "Defaults to 2 if not set.\n\n"

View file

@ -96,6 +96,10 @@ public:
/// @see PHYSICSPLUGIN /// @see PHYSICSPLUGIN
static PhysicsPlugin* getSingleton() { return smSingleton; } static PhysicsPlugin* getSingleton() { return smSingleton; }
/// Allow gpu acceleration if supported
static bool smGpuAccelerationAllowed;
static bool gpuAccelerationAllowed() { return smGpuAccelerationAllowed; }
/// ///
static bool activate( const char *library ); static bool activate( const char *library );

View file

@ -26,6 +26,8 @@
//Physics timing //Physics timing
F32 PhysicsWorld::smPhysicsStepTime = 1.0f / 60.f; //default 60fps F32 PhysicsWorld::smPhysicsStepTime = 1.0f / 60.f; //default 60fps
U32 PhysicsWorld::smPhysicsMaxSubSteps = 4; U32 PhysicsWorld::smPhysicsMaxSubSteps = 4;
//Gpu acceleration
bool PhysicsWorld::smGpuEnabled = false;
PhysicsWorld::PhysicsWorld() PhysicsWorld::PhysicsWorld()
: mGravity( 0, 0, -20.0f ) // NOTE: This matches the gravity used for player objects. : mGravity( 0, 0, -20.0f ) // NOTE: This matches the gravity used for player objects.

View file

@ -49,6 +49,9 @@ protected:
/// The current gravity force. /// The current gravity force.
Point3F mGravity; Point3F mGravity;
/// Gpu acceleration
static bool smGpuEnabled;
public: public:
/// The constructor. /// The constructor.
@ -115,6 +118,9 @@ public:
/// Physics timing /// Physics timing
static F32 smPhysicsStepTime; static F32 smPhysicsStepTime;
static U32 smPhysicsMaxSubSteps; static U32 smPhysicsMaxSubSteps;
/// Gpu acceleration
static bool isGpuEnabled() { return smGpuEnabled; }
}; };

View file

@ -33,19 +33,43 @@
#define WIN32 #define WIN32
#endif #endif
// macOS _DEBUG & NDEBUG
#if defined(TORQUE_OS_MAC) && defined(TORQUE_DEBUG) && !defined(_DEBUG)
#define _DEBUG
#elif defined(TORQUE_OS_MAC) && defined(TORQUE_RELEASE) && !defined(NDEBUG)
#define NDEBUG
#endif
// Linux _DEBUG & NDEBUG
#if defined(TORQUE_OS_LINUX) && defined(TORQUE_DEBUG) && !defined(_DEBUG)
#define _DEBUG
#elif defined(TORQUE_OS_LINUX) && defined(TORQUE_RELEASE) && !defined(NDEBUG)
#define NDEBUG
#endif
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
//safe release template
template <class T> void SafeReleasePhysx(T* a)
{
if (a)
{
a->release();
a = NULL;
}
}
#include <PxPhysicsAPI.h> #include <PxPhysicsAPI.h>
#include <PxExtensionsAPI.h> #include <extensions/PxExtensionsAPI.h>
#include <PxDefaultErrorCallback.h> #include <extensions/PxDefaultErrorCallback.h>
#include <PxDefaultAllocator.h> #include <extensions/PxDefaultAllocator.h>
#include <PxDefaultSimulationFilterShader.h> #include <extensions/PxDefaultSimulationFilterShader.h>
#include <PxDefaultCpuDispatcher.h> #include <extensions/PxDefaultCpuDispatcher.h>
#include <PxShapeExt.h> #include <extensions/PxShapeExt.h>
#include <PxSimpleFactory.h> #include <extensions/PxSimpleFactory.h>
#include <PxFoundation.h> #include <foundation/PxFoundation.h>
#include <PxController.h> #include <characterkinematic/PxController.h>
#include <PxIO.h> #include <pvd/PxPvd.h>
extern physx::PxPhysics* gPhysics3SDK; extern physx::PxPhysics* gPhysics3SDK;

View file

@ -52,12 +52,9 @@ void Px3Body::_releaseActor()
if ( !mActor ) if ( !mActor )
return; return;
mWorld->releaseWriteLock();
mActor->userData = NULL; mActor->userData = NULL;
mActor->release(); SafeReleasePhysx(mActor);
mActor = NULL;
mBodyFlags = 0; mBodyFlags = 0;
if ( mMaterial ) if ( mMaterial )
@ -96,18 +93,20 @@ bool Px3Body::init( PhysicsCollision *shape,
{ {
mActor = gPhysics3SDK->createRigidDynamic(physx::PxTransform(physx::PxIDENTITY())); mActor = gPhysics3SDK->createRigidDynamic(physx::PxTransform(physx::PxIDENTITY()));
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>(); physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
actor->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, true); actor->setRigidBodyFlag(physx::PxRigidBodyFlag::eKINEMATIC, true);
actor->setMass(getMax( mass, 1.0f )); actor->setMass(getMax( mass, 1.0f ));
} }
else if ( mass > 0.0f ) else if ( mass > 0.0f )
{ {
mActor = gPhysics3SDK->createRigidDynamic(physx::PxTransform(physx::PxIDENTITY())); mActor = gPhysics3SDK->createRigidDynamic(physx::PxTransform(physx::PxIDENTITY()));
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
actor->setMaxAngularVelocity(80.f);
} }
else else
{ {
mActor = gPhysics3SDK->createRigidStatic(physx::PxTransform(physx::PxIDENTITY())); mActor = gPhysics3SDK->createRigidStatic(physx::PxTransform(physx::PxIDENTITY()));
mIsStatic = true; mIsStatic = true;
} }
mMaterial = gPhysics3SDK->createMaterial(0.6f,0.4f,0.1f); mMaterial = gPhysics3SDK->createMaterial(0.6f,0.4f,0.1f);
@ -123,12 +122,13 @@ bool Px3Body::init( PhysicsCollision *shape,
Con::errorf("PhysX3 Dynamic Triangle Mesh is not supported."); Con::errorf("PhysX3 Dynamic Triangle Mesh is not supported.");
} }
} }
physx::PxShape * pShape = mActor->createShape(*desc->pGeometry,*mMaterial);
physx::PxShape * pShape = physx::PxRigidActorExt::createExclusiveShape(*mActor, *desc->pGeometry, *mMaterial);
physx::PxFilterData colData; physx::PxFilterData colData;
if(isDebris) if(isDebris)
colData.word0 = PX3_DEBRIS; colData.word0 = PX3_DEBRIS;
else if(isTrigger) else if(isTrigger)
colData.word0 = PX3_TRIGGER; colData.word0 = PX3_TRIGGER;
else else
colData.word0 = PX3_DEFAULT; colData.word0 = PX3_DEFAULT;
@ -149,10 +149,6 @@ bool Px3Body::init( PhysicsCollision *shape,
physx::PxRigidBodyExt::setMassAndUpdateInertia(*actor,mass); physx::PxRigidBodyExt::setMassAndUpdateInertia(*actor,mass);
} }
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
mWorld->getScene()->addActor(*mActor); mWorld->getScene()->addActor(*mActor);
mIsEnabled = true; mIsEnabled = true;
@ -178,9 +174,9 @@ void Px3Body::setMaterial( F32 restitution,
actor->wakeUp(); actor->wakeUp();
} }
mMaterial->setRestitution(restitution); mMaterial->setRestitution(restitution);
mMaterial->setStaticFriction(staticFriction); mMaterial->setStaticFriction(staticFriction);
mMaterial->setDynamicFriction(friction); mMaterial->setDynamicFriction(friction);
} }
@ -324,7 +320,6 @@ Box3F Px3Body::getWorldBounds()
bounds.setEmpty(); bounds.setEmpty();
physx::PxBounds3 shapeBounds; physx::PxBounds3 shapeBounds;
U32 shapeCount = mActor->getNbShapes(); U32 shapeCount = mActor->getNbShapes();
physx::PxShape **shapes = new physx::PxShape*[shapeCount]; physx::PxShape **shapes = new physx::PxShape*[shapeCount];
mActor->getShapes(shapes, shapeCount); mActor->getShapes(shapes, shapeCount);
@ -350,10 +345,6 @@ void Px3Body::setSimulationEnabled( bool enabled )
if(mBodyFlags & BF_TRIGGER) if(mBodyFlags & BF_TRIGGER)
return; return;
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
U32 shapeCount = mActor->getNbShapes(); U32 shapeCount = mActor->getNbShapes();
physx::PxShape **shapes = new physx::PxShape*[shapeCount]; physx::PxShape **shapes = new physx::PxShape*[shapeCount];
mActor->getShapes(shapes, shapeCount); mActor->getShapes(shapes, shapeCount);
@ -368,19 +359,13 @@ void Px3Body::setTransform( const MatrixF &transform )
{ {
AssertFatal( mActor, "Px3Body::setTransform - The actor is null!" ); AssertFatal( mActor, "Px3Body::setTransform - The actor is null!" );
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
mActor->setGlobalPose(px3Cast<physx::PxTransform>(transform),false); mActor->setGlobalPose(px3Cast<physx::PxTransform>(transform),false);
if(mIsStatic) if(mIsStatic)
return; return;
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>(); physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
bool kinematic = actor->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC; bool kinematic = actor->getRigidBodyFlags() & physx::PxRigidBodyFlag::eKINEMATIC;
// If its dynamic we have more to do. // If its dynamic we have more to do.
if ( isDynamic() && !kinematic ) if ( isDynamic() && !kinematic )
{ {
@ -395,10 +380,6 @@ void Px3Body::applyCorrection( const MatrixF &transform )
AssertFatal( mActor, "Px3Body::applyCorrection - The actor is null!" ); AssertFatal( mActor, "Px3Body::applyCorrection - The actor is null!" );
AssertFatal( isDynamic(), "Px3Body::applyCorrection - This call is only for dynamics!" ); AssertFatal( isDynamic(), "Px3Body::applyCorrection - This call is only for dynamics!" );
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
mActor->setGlobalPose( px3Cast<physx::PxTransform>(transform) ); mActor->setGlobalPose( px3Cast<physx::PxTransform>(transform) );
} }
@ -406,35 +387,27 @@ void Px3Body::applyImpulse( const Point3F &origin, const Point3F &force )
{ {
AssertFatal( mActor, "Px3Body::applyImpulse - The actor is null!" ); AssertFatal( mActor, "Px3Body::applyImpulse - The actor is null!" );
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>(); physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
if ( mIsEnabled && isDynamic() ) if ( mIsEnabled && isDynamic() )
physx::PxRigidBodyExt::addForceAtPos(*actor,px3Cast<physx::PxVec3>(force), physx::PxRigidBodyExt::addForceAtPos( *actor,px3Cast<physx::PxVec3>(force), px3Cast<physx::PxVec3>(origin), physx::PxForceMode::eIMPULSE );
px3Cast<physx::PxVec3>(origin),
physx::PxForceMode::eIMPULSE);
} }
void Px3Body::applyTorque( const Point3F &torque ) void Px3Body::applyTorque(const Point3F &torque)
{ {
AssertFatal(mActor, "Px3Body::applyImpulse - The actor is null!"); AssertFatal(mActor, "Px3Body::applyImpulse - The actor is null!");
mWorld->releaseWriteLock();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>(); physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
if (mIsEnabled && isDynamic()) if (mIsEnabled && isDynamic())
actor->addTorque( px3Cast<physx::PxVec3>(torque), physx::PxForceMode::eFORCE, true); actor->addTorque(px3Cast<physx::PxVec3>(torque), physx::PxForceMode::eFORCE, true);
} }
void Px3Body::applyForce( const Point3F &force ) void Px3Body::applyForce(const Point3F &force)
{ {
AssertFatal(mActor, "Px3Body::applyTorque - The actor is null!"); AssertFatal(mActor, "Px3Body::applyTorque - The actor is null!");
mWorld->releaseWriteLock();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>(); physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
if (mIsEnabled && isDynamic()) if (mIsEnabled && isDynamic())
actor->addForce( px3Cast<physx::PxVec3>(force), physx::PxForceMode::eFORCE, true); actor->addForce(px3Cast<physx::PxVec3>(force), physx::PxForceMode::eFORCE, true);
} }
void Px3Body::findContact(SceneObject **contactObject, void Px3Body::findContact(SceneObject **contactObject,

View file

@ -40,7 +40,8 @@ class Px3World;
class Px3Collision; class Px3Collision;
struct Px3CollisionDesc; struct Px3CollisionDesc;
namespace physx{ namespace physx
{
class PxRigidActor; class PxRigidActor;
class PxMaterial; class PxMaterial;
class PxShape; class PxShape;

View file

@ -37,135 +37,123 @@ Px3Collision::Px3Collision()
Px3Collision::~Px3Collision() Px3Collision::~Px3Collision()
{ {
for ( U32 i=0; i < mColShapes.size(); i++ )
{
Px3CollisionDesc *desc = mColShapes[i];
delete desc->pGeometry;
// Delete the descriptor.
delete desc;
}
for ( U32 i=0; i < mColShapes.size(); i++ ) mColShapes.clear();
{
Px3CollisionDesc *desc = mColShapes[i];
delete desc->pGeometry;
// Delete the descriptor.
delete desc;
}
mColShapes.clear();
} }
void Px3Collision::addPlane( const PlaneF &plane ) void Px3Collision::addPlane( const PlaneF &plane )
{ {
physx::PxVec3 pos = px3Cast<physx::PxVec3>(plane.getPosition()); physx::PxVec3 pos = px3Cast<physx::PxVec3>(plane.getPosition());
Px3CollisionDesc *desc = new Px3CollisionDesc; Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxPlaneGeometry(); desc->pGeometry = new physx::PxPlaneGeometry();
desc->pose = physx::PxTransform(pos, physx::PxQuat(physx::PxHalfPi, physx::PxVec3(0.0f, -1.0f, 0.0f))); desc->pose = physx::PxTransform(pos, physx::PxQuat(physx::PxHalfPi, physx::PxVec3(0.0f, -1.0f, 0.0f)));
mColShapes.push_back(desc); mColShapes.push_back(desc);
} }
void Px3Collision::addBox( const Point3F &halfWidth,const MatrixF &localXfm ) void Px3Collision::addBox( const Point3F &halfWidth,const MatrixF &localXfm )
{ {
Px3CollisionDesc *desc = new Px3CollisionDesc; Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxBoxGeometry(px3Cast<physx::PxVec3>(halfWidth)); desc->pGeometry = new physx::PxBoxGeometry(px3Cast<physx::PxVec3>(halfWidth));
desc->pose = px3Cast<physx::PxTransform>(localXfm); desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc); mColShapes.push_back(desc);
} }
void Px3Collision::addSphere( F32 radius, void Px3Collision::addSphere( F32 radius, const MatrixF &localXfm )
const MatrixF &localXfm )
{ {
Px3CollisionDesc *desc = new Px3CollisionDesc; Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxSphereGeometry(radius); desc->pGeometry = new physx::PxSphereGeometry(radius);
desc->pose = px3Cast<physx::PxTransform>(localXfm); desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc); mColShapes.push_back(desc);
} }
void Px3Collision::addCapsule( F32 radius, void Px3Collision::addCapsule( F32 radius, F32 height, const MatrixF &localXfm )
F32 height,
const MatrixF &localXfm )
{ {
Px3CollisionDesc *desc = new Px3CollisionDesc; Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxCapsuleGeometry(radius,height*0.5);//uses half height desc->pGeometry = new physx::PxCapsuleGeometry(radius,height*0.5);//uses half height
desc->pose = px3Cast<physx::PxTransform>(localXfm); desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc); mColShapes.push_back(desc);
} }
bool Px3Collision::addConvex( const Point3F *points, bool Px3Collision::addConvex( const Point3F *points, U32 count, const MatrixF &localXfm )
U32 count,
const MatrixF &localXfm )
{ {
physx::PxCooking *cooking = Px3World::getCooking(); physx::PxCooking *cooking = Px3World::getCooking();
physx::PxConvexMeshDesc convexDesc; physx::PxConvexMeshDesc convexDesc;
convexDesc.points.data = points; convexDesc.points.data = points;
convexDesc.points.stride = sizeof(Point3F); convexDesc.points.stride = sizeof(Point3F);
convexDesc.points.count = count; convexDesc.points.count = count;
convexDesc.flags = physx::PxConvexFlag::eFLIPNORMALS|physx::PxConvexFlag::eCOMPUTE_CONVEX | physx::PxConvexFlag::eINFLATE_CONVEX; convexDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX | physx::PxConvexFlag::eCHECK_ZERO_AREA_TRIANGLES;
if(PhysicsWorld::isGpuEnabled())
convexDesc.flags |= physx::PxConvexFlag::eGPU_COMPATIBLE;
Px3MemOutStream stream; Px3MemOutStream stream;
if(!cooking->cookConvexMesh(convexDesc,stream)) if(!cooking->cookConvexMesh(convexDesc,stream))
return false; return false;
physx::PxConvexMesh* convexMesh; physx::PxConvexMesh* convexMesh;
Px3MemInStream in(stream.getData(), stream.getSize()); Px3MemInStream in(stream.getData(), stream.getSize());
convexMesh = gPhysics3SDK->createConvexMesh(in); convexMesh = gPhysics3SDK->createConvexMesh(in);
Px3CollisionDesc *desc = new Px3CollisionDesc; Px3CollisionDesc *desc = new Px3CollisionDesc;
physx::PxVec3 scale = px3Cast<physx::PxVec3>(localXfm.getScale()); physx::PxVec3 scale = px3Cast<physx::PxVec3>(localXfm.getScale());
physx::PxQuat rotation = px3Cast<physx::PxQuat>(QuatF(localXfm)); physx::PxQuat rotation = px3Cast<physx::PxQuat>(QuatF(localXfm));
physx::PxMeshScale meshScale(scale,rotation); physx::PxMeshScale meshScale(scale,rotation);
desc->pGeometry = new physx::PxConvexMeshGeometry(convexMesh,meshScale); desc->pGeometry = new physx::PxConvexMeshGeometry(convexMesh,meshScale);
desc->pose = px3Cast<physx::PxTransform>(localXfm); desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc); mColShapes.push_back(desc);
return true; return true;
} }
bool Px3Collision::addTriangleMesh( const Point3F *vert, bool Px3Collision::addTriangleMesh( const Point3F *vert, U32 vertCount, const U32 *index, U32 triCount, const MatrixF &localXfm )
U32 vertCount,
const U32 *index,
U32 triCount,
const MatrixF &localXfm )
{ {
physx::PxCooking *cooking = Px3World::getCooking(); physx::PxCooking *cooking = Px3World::getCooking();
physx::PxTriangleMeshDesc meshDesc; physx::PxTriangleMeshDesc meshDesc;
meshDesc.points.count = vertCount; meshDesc.points.count = vertCount;
meshDesc.points.data = vert; meshDesc.points.data = vert;
meshDesc.points.stride = sizeof(Point3F); meshDesc.points.stride = sizeof(Point3F);
meshDesc.triangles.count = triCount; meshDesc.triangles.count = triCount;
meshDesc.triangles.data = index; meshDesc.triangles.data = index;
meshDesc.triangles.stride = 3*sizeof(U32); meshDesc.triangles.stride = 3*sizeof(U32);
meshDesc.flags = physx::PxMeshFlag::eFLIPNORMALS; meshDesc.flags = physx::PxMeshFlag::eFLIPNORMALS;
Px3MemOutStream stream; Px3MemOutStream stream;
if(!cooking->cookTriangleMesh(meshDesc,stream)) if(!cooking->cookTriangleMesh(meshDesc,stream))
return false; return false;
physx::PxTriangleMesh *mesh; physx::PxTriangleMesh *mesh;
Px3MemInStream in(stream.getData(), stream.getSize()); Px3MemInStream in(stream.getData(), stream.getSize());
mesh = gPhysics3SDK->createTriangleMesh(in); mesh = gPhysics3SDK->createTriangleMesh(in);
Px3CollisionDesc *desc = new Px3CollisionDesc; Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxTriangleMeshGeometry(mesh); desc->pGeometry = new physx::PxTriangleMeshGeometry(mesh);
desc->pose = px3Cast<physx::PxTransform>(localXfm); desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc); mColShapes.push_back(desc);
return true; return true;
} }
bool Px3Collision::addHeightfield( const U16 *heights, bool Px3Collision::addHeightfield( const U16 *heights, const bool *holes, U32 blockSize, F32 metersPerSample, const MatrixF &localXfm )
const bool *holes,
U32 blockSize,
F32 metersPerSample,
const MatrixF &localXfm )
{ {
const F32 heightScale = 0.03125f; const F32 heightScale = 0.03125f;
physx::PxHeightFieldSample* samples = (physx::PxHeightFieldSample*) new physx::PxHeightFieldSample[blockSize*blockSize]; physx::PxHeightFieldSample* samples = (physx::PxHeightFieldSample*) new physx::PxHeightFieldSample[blockSize*blockSize];
memset(samples,0,blockSize*blockSize*sizeof(physx::PxHeightFieldSample)); memset(samples,0,blockSize*blockSize*sizeof(physx::PxHeightFieldSample));
physx::PxHeightFieldDesc heightFieldDesc; physx::PxHeightFieldDesc heightFieldDesc;
heightFieldDesc.nbColumns = blockSize; heightFieldDesc.nbColumns = blockSize;
heightFieldDesc.nbRows = blockSize; heightFieldDesc.nbRows = blockSize;
heightFieldDesc.thickness = -10.f; heightFieldDesc.thickness = -10.f;
heightFieldDesc.convexEdgeThreshold = 0; heightFieldDesc.convexEdgeThreshold = 0;
heightFieldDesc.format = physx::PxHeightFieldFormat::eS16_TM; heightFieldDesc.format = physx::PxHeightFieldFormat::eS16_TM;
heightFieldDesc.samples.data = samples; heightFieldDesc.samples.data = samples;
heightFieldDesc.samples.stride = sizeof(physx::PxHeightFieldSample); heightFieldDesc.samples.stride = sizeof(physx::PxHeightFieldSample);
physx::PxU8 *currentByte = (physx::PxU8*)heightFieldDesc.samples.data; physx::PxU8 *currentByte = (physx::PxU8*)heightFieldDesc.samples.data;
for ( U32 row = 0; row < blockSize; row++ ) for ( U32 row = 0; row < blockSize; row++ )
{ {
const U32 tess = ( row + 1 ) % 2; const U32 tess = ( row + 1 ) % 2;
@ -177,7 +165,6 @@ bool Px3Collision::addHeightfield( const U16 *heights,
U32 index = ( blockSize - row - 1 ) + ( column * blockSize ); U32 index = ( blockSize - row - 1 ) + ( column * blockSize );
currentSample->height = (physx::PxI16)heights[ index ]; currentSample->height = (physx::PxI16)heights[ index ];
if ( holes && holes[ getMax( (S32)index - 1, 0 ) ] ) // row index for holes adjusted so PhysX collision shape better matches rendered terrain if ( holes && holes[ getMax( (S32)index - 1, 0 ) ] ) // row index for holes adjusted so PhysX collision shape better matches rendered terrain
{ {
currentSample->materialIndex0 = physx::PxHeightFieldMaterial::eHOLE; currentSample->materialIndex0 = physx::PxHeightFieldMaterial::eHOLE;
@ -189,29 +176,30 @@ bool Px3Collision::addHeightfield( const U16 *heights,
currentSample->materialIndex1 = 0; currentSample->materialIndex1 = 0;
} }
int flag = ( column + tess ) % 2; S32 flag = ( column + tess ) % 2;
if(flag) if(flag)
currentSample->clearTessFlag(); currentSample->clearTessFlag();
else else
currentSample->setTessFlag(); currentSample->setTessFlag();
currentByte += heightFieldDesc.samples.stride; currentByte += heightFieldDesc.samples.stride;
} }
} }
physx::PxHeightField * hf = gPhysics3SDK->createHeightField(heightFieldDesc); physx::PxCooking *cooking = Px3World::getCooking();
physx::PxHeightFieldGeometry *geom = new physx::PxHeightFieldGeometry(hf,physx::PxMeshGeometryFlags(),heightScale,metersPerSample,metersPerSample); physx::PxHeightField * hf = cooking->createHeightField(heightFieldDesc,gPhysics3SDK->getPhysicsInsertionCallback());
physx::PxHeightFieldGeometry *geom = new physx::PxHeightFieldGeometry(hf,physx::PxMeshGeometryFlags(),heightScale,metersPerSample,metersPerSample);
physx::PxTransform pose= physx::PxTransform(physx::PxQuat(Float_HalfPi, physx::PxVec3(1, 0, 0 ))); physx::PxTransform pose= physx::PxTransform(physx::PxQuat(Float_HalfPi, physx::PxVec3(1, 0, 0 )));
physx::PxTransform pose1= physx::PxTransform(physx::PxQuat(Float_Pi, physx::PxVec3(0, 0, 1 ))); physx::PxTransform pose1= physx::PxTransform(physx::PxQuat(Float_Pi, physx::PxVec3(0, 0, 1 )));
physx::PxTransform pose2 = pose1 * pose; physx::PxTransform pose2 = pose1 * pose;
pose2.p = physx::PxVec3(( blockSize - 1 ) * metersPerSample, 0, 0 ); pose2.p = physx::PxVec3(( blockSize - 1 ) * metersPerSample, 0, 0 );
Px3CollisionDesc *desc = new Px3CollisionDesc; Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = geom; desc->pGeometry = geom;
desc->pose = pose2; desc->pose = pose2;
mColShapes.push_back(desc); mColShapes.push_back(desc);
SAFE_DELETE(samples); SAFE_DELETE(samples);
return true; return true;
} }

View file

@ -23,6 +23,9 @@
#ifndef _PX3COLLISION_H_ #ifndef _PX3COLLISION_H_
#define _PX3COLLISION_H_ #define _PX3COLLISION_H_
#ifndef _PHYSX3_H_
#include "T3D/physics/physx3/px3.h"
#endif
#ifndef _T3D_PHYSICS_PHYSICSCOLLISION_H_ #ifndef _T3D_PHYSICS_PHYSICSCOLLISION_H_
#include "T3D/physics/physicsCollision.h" #include "T3D/physics/physicsCollision.h"
#endif #endif

View file

@ -53,7 +53,7 @@ void Px3Player::_releaseController()
{ {
mController->getActor()->userData = NULL; mController->getActor()->userData = NULL;
mWorld->getStaticChangedSignal().remove( this, &Px3Player::_onStaticChanged ); mWorld->getStaticChangedSignal().remove( this, &Px3Player::_onStaticChanged );
mController->release(); SafeReleasePhysx(mController);
} }
} }
@ -136,8 +136,6 @@ Point3F Px3Player::move( const VectorF &disp, CollisionList &outCol )
return newPos; return newPos;
} }
mWorld->releaseWriteLock();
mCollisionList = &outCol; mCollisionList = &outCol;
physx::PxVec3 dispNx( disp.x, disp.y, disp.z ); physx::PxVec3 dispNx( disp.x, disp.y, disp.z );
@ -151,7 +149,7 @@ Point3F Px3Player::move( const VectorF &disp, CollisionList &outCol )
physx::PxFilterData data; physx::PxFilterData data;
data.word0=groups; data.word0=groups;
filter.mFilterData = &data; filter.mFilterData = &data;
filter.mFilterFlags = physx::PxSceneQueryFilterFlags(physx::PxControllerFlag::eCOLLISION_DOWN|physx::PxControllerFlag::eCOLLISION_SIDES|physx::PxControllerFlag::eCOLLISION_UP); filter.mFilterFlags = physx::PxQueryFlags(physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::eSTATIC);
mController->move( dispNx,0.0001f,0, filter ); mController->move( dispNx,0.0001f,0, filter );
@ -272,7 +270,6 @@ void Px3Player::enableCollision()
{ {
AssertFatal( mController, "Px3Player::enableCollision - The controller is null!" ); AssertFatal( mController, "Px3Player::enableCollision - The controller is null!" );
mWorld->releaseWriteLock();
px3GetFirstShape(mController->getActor())->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE,true); px3GetFirstShape(mController->getActor())->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE,true);
} }
@ -280,7 +277,6 @@ void Px3Player::disableCollision()
{ {
AssertFatal( mController, "Px3Player::disableCollision - The controller is null!" ); AssertFatal( mController, "Px3Player::disableCollision - The controller is null!" );
mWorld->releaseWriteLock();
px3GetFirstShape(mController->getActor())->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE,false); px3GetFirstShape(mController->getActor())->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE,false);
} }
@ -293,8 +289,6 @@ void Px3Player::setTransform( const MatrixF &transform )
{ {
AssertFatal( mController, "Px3Player::setTransform - The controller is null!" ); AssertFatal( mController, "Px3Player::setTransform - The controller is null!" );
mWorld->releaseWriteLock();
Point3F newPos = transform.getPosition(); Point3F newPos = transform.getPosition();
newPos.z += mOriginOffset; newPos.z += mOriginOffset;
@ -355,7 +349,6 @@ void Px3Player::setSpacials(const Point3F &nPos, const Point3F &nSize)
F32 height = nSize.z - (radius * 2.0f); F32 height = nSize.z - (radius * 2.0f);
height -= mSkinWidth * 2.0f; height -= mSkinWidth * 2.0f;
mWorld->releaseWriteLock();
mController->resize(height); mController->resize(height);
px3GetFirstShape(mController->getActor())->getCapsuleGeometry(mGeometry); px3GetFirstShape(mController->getActor())->getCapsuleGeometry(mGeometry);
} }

View file

@ -83,10 +83,7 @@ Px3ConsoleStream::~Px3ConsoleStream()
{ {
} }
void Px3ConsoleStream::reportError( physx::PxErrorCode code, const char *message, const char* file, int line ) void Px3ConsoleStream::reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line)
{ {
UTF8 info[1024]; Con::warnf( "PhysX Warning: %s(%d) : %s", file, line, message );
dSprintf( info, 1024, "File: %s\nLine: %d\n%s", file, line, message );
Platform::AlertOK( "PhysX Error", info );
// Con::printf( "PhysX Error:\n %s(%d) : %s\n", file, line, message );
} }

View file

@ -62,11 +62,11 @@ protected:
}; };
class Px3ConsoleStream : public physx::PxDefaultErrorCallback class Px3ConsoleStream : public physx::PxErrorCallback
{ {
protected: protected:
virtual void reportError( physx::PxErrorCode code, const char *message, const char* file, int line ); virtual void reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line);
public: public:

View file

@ -41,27 +41,31 @@
#include "gfx/sim/debugDraw.h" #include "gfx/sim/debugDraw.h"
#include "gfx/primBuilder.h" #include "gfx/primBuilder.h"
physx::PxPhysics* gPhysics3SDK = NULL; physx::PxPhysics* gPhysics3SDK = NULL;
physx::PxCooking* Px3World::smCooking = NULL; physx::PxCooking* Px3World::smCooking = NULL;
physx::PxFoundation* Px3World::smFoundation = NULL; physx::PxFoundation* Px3World::smFoundation = NULL;
physx::PxProfileZoneManager* Px3World::smProfileZoneManager = NULL; physx::PxDefaultCpuDispatcher* Px3World::smCpuDispatcher = NULL;
physx::PxDefaultCpuDispatcher* Px3World::smCpuDispatcher=NULL; #ifndef TORQUE_OS_MAC
physx::PxCudaContextManager* Px3World::smCudaContextManager = NULL;
#endif
Px3ConsoleStream* Px3World::smErrorCallback = NULL; Px3ConsoleStream* Px3World::smErrorCallback = NULL;
physx::PxVisualDebuggerConnection* Px3World::smPvdConnection=NULL; physx::PxPvd* Px3World::smPvdConnection = NULL;
physx::PxPvdTransport* Px3World::smPvdTransport = NULL;
physx::PxDefaultAllocator Px3World::smMemoryAlloc; physx::PxDefaultAllocator Px3World::smMemoryAlloc;
Px3World::Px3World(): mScene( NULL ), Px3World::Px3World() :
mProcessList( NULL ), mScene( NULL ),
mIsSimulating( false ),
mErrorReport( false ),
mTickCount( 0 ),
mIsEnabled( false ), mIsEnabled( false ),
mIsSimulating( false ),
mIsServer( false ),
mIsSceneLocked( false ),
mTickCount( 0 ),
mProcessList( NULL ),
mEditorTimeScale( 1.0f ), mEditorTimeScale( 1.0f ),
mAccumulator( 0 ), mErrorReport( false ),
mControllerManager(NULL), mControllerManager(NULL),
mIsSceneLocked(false), mRenderBuffer(NULL),
mRenderBuffer(NULL) mAccumulator( 0 )
{ {
} }
@ -80,33 +84,25 @@ bool Px3World::restartSDK( bool destroyOnly, Px3World *clientWorld, Px3World *se
// then we cannot reset the SDK. // then we cannot reset the SDK.
if ( clientWorld || serverWorld ) if ( clientWorld || serverWorld )
return false; return false;
#ifndef TORQUE_OS_MAC
if(smPvdConnection) SafeReleasePhysx(smCudaContextManager);
smPvdConnection->release(); #endif
SafeReleasePhysx(smCpuDispatcher);
if(smCooking) SafeReleasePhysx(smCooking);
smCooking->release(); smGpuEnabled = false;
if(smCpuDispatcher)
smCpuDispatcher->release();
// Destroy the existing SDK. // Destroy the existing SDK.
if ( gPhysics3SDK ) if ( gPhysics3SDK )
{ {
PxCloseExtensions(); PxCloseExtensions();
gPhysics3SDK->release(); SafeReleasePhysx(gPhysics3SDK);
} }
if(smErrorCallback) SafeReleasePhysx(smPvdConnection);
{ SafeReleasePhysx(smPvdTransport);
SAFE_DELETE(smErrorCallback);
}
if(smFoundation) SAFE_DELETE(smErrorCallback);
{ SafeReleasePhysx(smFoundation);
smFoundation->release();
SAFE_DELETE(smErrorCallback);
}
// If we're not supposed to restart... return. // If we're not supposed to restart... return.
if ( destroyOnly ) if ( destroyOnly )
@ -114,20 +110,18 @@ bool Px3World::restartSDK( bool destroyOnly, Px3World *clientWorld, Px3World *se
bool memTrack = false; bool memTrack = false;
#ifdef TORQUE_DEBUG #ifdef TORQUE_DEBUG
memTrack = true; memTrack = false;
#endif #endif
smErrorCallback = new Px3ConsoleStream; smErrorCallback = new Px3ConsoleStream;
smFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, smMemoryAlloc, *smErrorCallback); smFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, smMemoryAlloc, *smErrorCallback);
smProfileZoneManager = &physx::PxProfileZoneManager::createProfileZoneManager(smFoundation); smPvdConnection = PxCreatePvd(*smFoundation);
gPhysics3SDK = PxCreatePhysics(PX_PHYSICS_VERSION, *smFoundation, physx::PxTolerancesScale(),memTrack,smProfileZoneManager); gPhysics3SDK = PxCreatePhysics(PX_PHYSICS_VERSION, *smFoundation, physx::PxTolerancesScale(),memTrack, smPvdConnection);
if ( !gPhysics3SDK ) if ( !gPhysics3SDK )
{ {
Con::errorf( "PhysX3 failed to initialize!" ); Con::errorf( "PhysX3 failed to initialize!" );
Platform::messageBox( Con::getVariable( "$appName" ), Platform::messageBox( Con::getVariable( "$appName" ), avar("PhysX3 could not be started!\r\n"), MBOk, MIStop );
avar("PhysX3 could not be started!\r\n"),
MBOk, MIStop );
Platform::forceShutdown( -1 ); Platform::forceShutdown( -1 );
// We shouldn't get here, but this shuts up // We shouldn't get here, but this shuts up
@ -135,33 +129,67 @@ bool Px3World::restartSDK( bool destroyOnly, Px3World *clientWorld, Px3World *se
return false; return false;
} }
if(!PxInitExtensions(*gPhysics3SDK)) if(!PxInitExtensions(*gPhysics3SDK, smPvdConnection))
{ {
Con::errorf( "PhysX3 failed to initialize extensions!" ); Con::errorf( "PhysX3 failed to initialize extensions!" );
Platform::messageBox( Con::getVariable( "$appName" ), Platform::messageBox( Con::getVariable( "$appName" ), avar("PhysX3 could not be started!\r\n"), MBOk, MIStop );
avar("PhysX3 could not be started!\r\n"),
MBOk, MIStop );
Platform::forceShutdown( -1 ); Platform::forceShutdown( -1 );
return false; return false;
} }
//no gpu support on macOS
#ifndef TORQUE_OS_MAC
//check if we are allowed to use gpu acceleration
if (PhysicsPlugin::gpuAccelerationAllowed())
{
// attempt to create a cuda context manager - only works on nvidia gpu (SM 3.0+ i.e kepler or better)
if (!smCpuDispatcher)
{
//check we have capable gpu, -1 means none found
S32 suggestedGpu = PxGetSuggestedCudaDeviceOrdinal(*smErrorCallback);
if (suggestedGpu != -1)
{
physx::PxCudaContextManagerDesc cudaContextManagerDesc;
smCudaContextManager = PxCreateCudaContextManager(*smFoundation, cudaContextManagerDesc);
if (smCudaContextManager)
smGpuEnabled = true;
}
}
}
#endif
smCooking = PxCreateCooking(PX_PHYSICS_VERSION, *smFoundation, physx::PxCookingParams(physx::PxTolerancesScale())); //cpu dispatcher
if (!smCpuDispatcher)
smCpuDispatcher = physx::PxDefaultCpuDispatcherCreate(PHYSICSMGR->getThreadCount());
physx::PxCookingParams params = physx::PxCookingParams(physx::PxTolerancesScale());
params.meshWeldTolerance = 0.001f;
params.meshPreprocessParams = physx::PxMeshPreprocessingFlags(physx::PxMeshPreprocessingFlag::eWELD_VERTICES);
#ifndef TORQUE_OS_MAC
if(smGpuEnabled)
params.buildGPUData = true;
#endif
smCooking = PxCreateCooking(PX_PHYSICS_VERSION, *smFoundation, params);
if(!smCooking) if(!smCooking)
{ {
Con::errorf( "PhysX3 failed to initialize cooking!" ); Con::errorf( "PhysX3 failed to initialize cooking!" );
Platform::messageBox( Con::getVariable( "$appName" ), Platform::messageBox( Con::getVariable( "$appName" ), avar("PhysX3 could not be started!\r\n"), MBOk, MIStop );
avar("PhysX3 could not be started!\r\n"),
MBOk, MIStop );
Platform::forceShutdown( -1 ); Platform::forceShutdown( -1 );
return false; return false;
} }
//TODO: enable/disable this from script
#ifdef TORQUE_DEBUG #ifdef TORQUE_DEBUG
physx::PxVisualDebuggerConnectionFlags connectionFlags(physx::PxVisualDebuggerExt::getAllConnectionFlags()); if(!smPvdTransport)
smPvdConnection = physx::PxVisualDebuggerExt::createConnection(gPhysics3SDK->getPvdConnectionManager(), smPvdTransport = physx::PxDefaultPvdSocketTransportCreate("localhost", 5425, 100);
"localhost", 5425, 100, connectionFlags);
smPvdConnection->connect(*smPvdTransport, physx::PxPvdInstrumentationFlag::eALL);
#endif #endif
//use legacy heightfield
//TODO: new method causing crashes on collision in debug build (unified HeightFields)
PxRegisterLegacyHeightFields(*gPhysics3SDK);
return true; return true;
} }
@ -169,8 +197,6 @@ void Px3World::destroyWorld()
{ {
getPhysicsResults(); getPhysicsResults();
mRenderBuffer = NULL;
// Release the tick processing signals. // Release the tick processing signals.
if ( mProcessList ) if ( mProcessList )
{ {
@ -179,19 +205,9 @@ void Px3World::destroyWorld()
mProcessList = NULL; mProcessList = NULL;
} }
if(mControllerManager) SafeReleasePhysx(mControllerManager);
{
mControllerManager->release();
mControllerManager = NULL;
}
// Destroy the scene. // Destroy the scene.
if ( mScene ) SafeReleasePhysx(mScene);
{
// Release the scene.
mScene->release();
mScene = NULL;
}
} }
bool Px3World::initWorld( bool isServer, ProcessList *processList ) bool Px3World::initWorld( bool isServer, ProcessList *processList )
@ -208,22 +224,27 @@ bool Px3World::initWorld( bool isServer, ProcessList *processList )
sceneDesc.gravity = px3Cast<physx::PxVec3>(mGravity); sceneDesc.gravity = px3Cast<physx::PxVec3>(mGravity);
sceneDesc.userData = this; sceneDesc.userData = this;
if(!sceneDesc.cpuDispatcher)
{
//Create shared cpu dispatcher
if(!smCpuDispatcher)
smCpuDispatcher = physx::PxDefaultCpuDispatcherCreate(PHYSICSMGR->getThreadCount());
sceneDesc.cpuDispatcher = smCpuDispatcher; sceneDesc.cpuDispatcher = smCpuDispatcher;
Con::printf("PhysX3 using Cpu: %d workers", smCpuDispatcher->getWorkerCount()); Con::printf("PhysX3 using Cpu: %d workers", smCpuDispatcher->getWorkerCount());
#ifndef TORQUE_OS_MAC
if (smGpuEnabled)
{
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_GPU_DYNAMICS;
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_PCM;
sceneDesc.broadPhaseType = physx::PxBroadPhaseType::eGPU;
sceneDesc.gpuDispatcher = smCudaContextManager->getGpuDispatcher();
Con::printf("PhysX3 using Gpu: %s", smCudaContextManager->getDeviceName());
} }
#endif
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_CCD; sceneDesc.flags |= physx::PxSceneFlag::eENABLE_CCD;
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_ACTIVETRANSFORMS; sceneDesc.flags |= physx::PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
sceneDesc.filterShader = physx::PxDefaultSimulationFilterShader; sceneDesc.filterShader = physx::PxDefaultSimulationFilterShader;
mScene = gPhysics3SDK->createScene(sceneDesc); mScene = gPhysics3SDK->createScene(sceneDesc);
//cache renderbuffer for use with debug drawing
mRenderBuffer = const_cast<physx::PxRenderBuffer*>(&mScene->getRenderBuffer()); mRenderBuffer = const_cast<physx::PxRenderBuffer*>(&mScene->getRenderBuffer());
physx::PxDominanceGroupPair debrisDominance( 0.0f, 1.0f ); physx::PxDominanceGroupPair debrisDominance( 0.0f, 1.0f );
@ -252,11 +273,12 @@ bool Px3World::_simulate(const F32 dt)
if (numSimulationSubSteps) if (numSimulationSubSteps)
{ {
//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt //clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
S32 clampedSimulationSteps = (numSimulationSubSteps > smPhysicsMaxSubSteps)? smPhysicsMaxSubSteps : numSimulationSubSteps; S32 clampedSimulationSteps = (numSimulationSubSteps > smPhysicsMaxSubSteps) ? smPhysicsMaxSubSteps : numSimulationSubSteps;
for (S32 i=0;i<clampedSimulationSteps;i++) for (S32 i=0;i<clampedSimulationSteps;i++)
{ {
mScene->fetchResults(true); if(i > 0)
mScene->fetchResults(true);
mScene->simulate(smPhysicsStepTime); mScene->simulate(smPhysicsStepTime);
} }
} }
@ -299,36 +321,6 @@ void Px3World::getPhysicsResults()
mScene->fetchResults(true); mScene->fetchResults(true);
mIsSimulating = false; mIsSimulating = false;
mTickCount++; mTickCount++;
// Con::printf( "%s PhysXWorld::getPhysicsResults!", this == smClientWorld ? "Client" : "Server" );
}
void Px3World::releaseWriteLocks()
{
Px3World *world = dynamic_cast<Px3World*>( PHYSICSMGR->getWorld( "server" ) );
if ( world )
world->releaseWriteLock();
world = dynamic_cast<Px3World*>( PHYSICSMGR->getWorld( "client" ) );
if ( world )
world->releaseWriteLock();
}
void Px3World::releaseWriteLock()
{
if ( !mScene || !mIsSimulating )
return;
PROFILE_SCOPE(PxWorld_ReleaseWriteLock);
// We use checkResults here to release the write lock
// but we do not change the simulation flag or increment
// the tick count... we may have gotten results, but the
// simulation hasn't really ticked!
mScene->checkResults( true );
//AssertFatal( mScene->isWritable(), "PhysX3World::releaseWriteLock() - We should have been writable now!" );
} }
void Px3World::lockScenes() void Px3World::lockScenes()
@ -389,7 +381,6 @@ void Px3World::unlockScene()
bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse ) bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse )
{ {
physx::PxVec3 orig = px3Cast<physx::PxVec3>( startPnt ); physx::PxVec3 orig = px3Cast<physx::PxVec3>( startPnt );
physx::PxVec3 dir = px3Cast<physx::PxVec3>( endPnt - startPnt ); physx::PxVec3 dir = px3Cast<physx::PxVec3>( endPnt - startPnt );
physx::PxF32 maxDist = dir.magnitude(); physx::PxF32 maxDist = dir.magnitude();
@ -398,15 +389,15 @@ bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo
U32 groups = 0xffffffff; U32 groups = 0xffffffff;
groups &= ~( PX3_TRIGGER ); // No trigger shapes! groups &= ~( PX3_TRIGGER ); // No trigger shapes!
physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::eIMPACT | physx::PxHitFlag::eNORMAL); physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::ePOSITION | physx::PxHitFlag::eNORMAL);
physx::PxQueryFilterData filterData(physx::PxQueryFlag::eSTATIC|physx::PxQueryFlag::eDYNAMIC); physx::PxQueryFilterData filterData(physx::PxQueryFlag::eSTATIC|physx::PxQueryFlag::eDYNAMIC);
filterData.data.word0 = groups; filterData.data.word0 = groups;
physx::PxRaycastBuffer buf; physx::PxRaycastBuffer buf;
if(!mScene->raycast(orig,dir,maxDist,buf,outFlags,filterData)) if(!mScene->raycast(orig,dir,maxDist,buf,outFlags,filterData))
return false; return false;
if(!buf.hasBlock) if(!buf.hasBlock)
return false; return false;
const physx::PxRaycastHit hit = buf.block; const physx::PxRaycastHit hit = buf.block;
physx::PxRigidActor *actor = hit.actor; physx::PxRigidActor *actor = hit.actor;
@ -425,8 +416,8 @@ bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo
} }
if ( impulse.isZero() || if ( impulse.isZero() ||
!actor->isRigidDynamic() || !actor->is<physx::PxRigidDynamic>() ||
actor->is<physx::PxRigidDynamic>()->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC ) actor->is<physx::PxRigidDynamic>()->getRigidBodyFlags() & physx::PxRigidBodyFlag::eKINEMATIC )
return true; return true;
physx::PxRigidBody *body = actor->is<physx::PxRigidBody>(); physx::PxRigidBody *body = actor->is<physx::PxRigidBody>();
@ -453,7 +444,7 @@ PhysicsBody* Px3World::castRay( const Point3F &start, const Point3F &end, U32 bo
groups &= ~( PX3_TRIGGER ); // triggers groups &= ~( PX3_TRIGGER ); // triggers
groups &= ~( PX3_DEBRIS ); // debris groups &= ~( PX3_DEBRIS ); // debris
physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::eIMPACT | physx::PxHitFlag::eNORMAL); physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::ePOSITION | physx::PxHitFlag::eNORMAL);
physx::PxQueryFilterData filterData; physx::PxQueryFilterData filterData;
if(bodyTypes & BT_Static) if(bodyTypes & BT_Static)
filterData.flags |= physx::PxQueryFlag::eSTATIC; filterData.flags |= physx::PxQueryFlag::eSTATIC;
@ -491,12 +482,12 @@ void Px3World::explosion( const Point3F &pos, F32 radius, F32 forceMagnitude )
{ {
physx::PxRigidActor *actor = buffer.touches[i].actor; physx::PxRigidActor *actor = buffer.touches[i].actor;
bool dynamic = actor->isRigidDynamic(); bool dynamic = actor->is<physx::PxRigidDynamic>();
if ( !dynamic ) if ( !dynamic )
continue; continue;
bool kinematic = actor->is<physx::PxRigidDynamic>()->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC; bool kinematic = actor->is<physx::PxRigidDynamic>()->getRigidBodyFlags() & physx::PxRigidBodyFlag::eKINEMATIC;
if ( kinematic ) if ( kinematic )
continue; continue;
@ -523,8 +514,6 @@ physx::PxController* Px3World::createController( physx::PxControllerDesc &desc )
if ( !mScene ) if ( !mScene )
return NULL; return NULL;
// We need the writelock!
releaseWriteLock();
physx::PxController* pController = mControllerManager->createController(desc); physx::PxController* pController = mControllerManager->createController(desc);
AssertFatal( pController, "Px3World::createController - Got a null!" ); AssertFatal( pController, "Px3World::createController - Got a null!" );
return pController; return pController;
@ -543,7 +532,7 @@ static ColorI getDebugColor( physx::PxU32 packed )
void Px3World::onDebugDraw( const SceneRenderState *state ) void Px3World::onDebugDraw( const SceneRenderState *state )
{ {
if ( !mScene || !mRenderBuffer ) if ( !mScene || !mRenderBuffer)
return; return;
mScene->setVisualizationParameter(physx::PxVisualizationParameter::eSCALE,1.0f); mScene->setVisualizationParameter(physx::PxVisualizationParameter::eSCALE,1.0f);

View file

@ -23,15 +23,15 @@
#ifndef _PX3WORLD_H_ #ifndef _PX3WORLD_H_
#define _PX3WORLD_H_ #define _PX3WORLD_H_
#ifndef _PHYSX3_H_
#include "T3D/physics/physx3/px3.h"
#endif
#ifndef _T3D_PHYSICS_PHYSICSWORLD_H_ #ifndef _T3D_PHYSICS_PHYSICSWORLD_H_
#include "T3D/physics/physicsWorld.h" #include "T3D/physics/physicsWorld.h"
#endif #endif
#ifndef _MMATH_H_ #ifndef _MMATH_H_
#include "math/mMath.h" #include "math/mMath.h"
#endif #endif
#ifndef _PHYSX3_H_
#include "T3D/physics/physx3/px3.h"
#endif
#ifndef _TVECTOR_H_ #ifndef _TVECTOR_H_
#include "core/util/tVector.h" #include "core/util/tVector.h"
#endif #endif
@ -51,7 +51,6 @@ enum Px3CollisionGroup
class Px3World : public PhysicsWorld class Px3World : public PhysicsWorld
{ {
protected: protected:
physx::PxScene* mScene; physx::PxScene* mScene;
bool mIsEnabled; bool mIsEnabled;
bool mIsSimulating; bool mIsSimulating;
@ -61,16 +60,20 @@ protected:
ProcessList *mProcessList; ProcessList *mProcessList;
F32 mEditorTimeScale; F32 mEditorTimeScale;
bool mErrorReport; bool mErrorReport;
physx::PxRenderBuffer *mRenderBuffer;
physx::PxControllerManager* mControllerManager; physx::PxControllerManager* mControllerManager;
physx::PxRenderBuffer *mRenderBuffer;
F32 mAccumulator;
static Px3ConsoleStream *smErrorCallback; static Px3ConsoleStream *smErrorCallback;
static physx::PxDefaultAllocator smMemoryAlloc; static physx::PxDefaultAllocator smMemoryAlloc;
static physx::PxFoundation* smFoundation; static physx::PxFoundation* smFoundation;
static physx::PxCooking *smCooking; static physx::PxCooking *smCooking;
static physx::PxProfileZoneManager* smProfileZoneManager;
static physx::PxDefaultCpuDispatcher* smCpuDispatcher; static physx::PxDefaultCpuDispatcher* smCpuDispatcher;
static physx::PxVisualDebuggerConnection* smPvdConnection; #ifndef TORQUE_OS_MAC
F32 mAccumulator; static physx::PxCudaContextManager* smCudaContextManager;
#endif
static physx::PxPvd* smPvdConnection;
static physx::PxPvdTransport* smPvdTransport;
bool _simulate(const F32 dt); bool _simulate(const F32 dt);
public: public:
@ -86,21 +89,20 @@ public:
virtual PhysicsBody* castRay( const Point3F &start, const Point3F &end, U32 bodyTypes = BT_All ); virtual PhysicsBody* castRay( const Point3F &start, const Point3F &end, U32 bodyTypes = BT_All );
virtual void explosion( const Point3F &pos, F32 radius, F32 forceMagnitude ); virtual void explosion( const Point3F &pos, F32 radius, F32 forceMagnitude );
virtual bool isEnabled() const { return mIsEnabled; } virtual bool isEnabled() const { return mIsEnabled; }
physx::PxScene* getScene(){ return mScene;} physx::PxScene* getScene(){ return mScene; }
void setEnabled( bool enabled ); void setEnabled( bool enabled );
U32 getTick() { return mTickCount; } U32 getTick() { return mTickCount; }
void tickPhysics( U32 elapsedMs ); void tickPhysics( U32 elapsedMs );
void getPhysicsResults(); void getPhysicsResults();
void setEditorTimeScale( F32 timeScale ) { mEditorTimeScale = timeScale; } void setEditorTimeScale( F32 timeScale ) { mEditorTimeScale = timeScale; }
const F32 getEditorTimeScale() const { return mEditorTimeScale; } const F32 getEditorTimeScale() const { return mEditorTimeScale; }
void releaseWriteLock(); bool isServer() { return mIsServer; }
bool isServer(){return mIsServer;}
physx::PxController* createController( physx::PxControllerDesc &desc ); physx::PxController* createController( physx::PxControllerDesc &desc );
void lockScene(); void lockScene();
void unlockScene(); void unlockScene();
//static //static
static bool restartSDK( bool destroyOnly = false, Px3World *clientWorld = NULL, Px3World *serverWorld = NULL ); static bool restartSDK( bool destroyOnly = false, Px3World *clientWorld = NULL, Px3World *serverWorld = NULL );
static void releaseWriteLocks();
static physx::PxCooking *getCooking(); static physx::PxCooking *getCooking();
static void lockScenes(); static void lockScenes();
static void unlockScenes(); static void unlockScenes();

View file

@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Copyright (c) 2015 GarageGames, LLC # Copyright (c) 2017 GarageGames, LLC
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to # of this software and associated documentation files (the "Software"), to
@ -20,16 +20,18 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# module Physx 3.3 # module Physx 3.4
option(TORQUE_PHYSICS_PHYSX3 "Use PhysX 3.3 physics" OFF) #do note the inconsistent upper/lower case nvidia use for directory names in physx
option(TORQUE_PHYSICS_PHYSX3 "Use PhysX 3.4 physics" OFF)
if( NOT TORQUE_PHYSICS_PHYSX3 ) if( NOT TORQUE_PHYSICS_PHYSX3 )
return() return()
endif() endif()
if("${PHYSX3_BASE_PATH}" STREQUAL "") if("${PHYSX3_BASE_PATH}" STREQUAL "")
set(PHYSX3_BASE_PATH "" CACHE PATH "PhysX 3.3 path" FORCE) set(PHYSX3_BASE_PATH "" CACHE PATH "PhysX 3.4 path" FORCE)
endif() endif()
#still no path we can't go any further #still no path we can't go any further
@ -39,63 +41,177 @@ if("${PHYSX3_BASE_PATH}" STREQUAL "")
endif() endif()
#set physx path #set physx path
set(PHYSX3_PATH "${PHYSX3_BASE_PATH}/PhysXSDK") set(PHYSX3_PATH "${PHYSX3_BASE_PATH}/PhysX_3.4")
# TODO linux support # Windows/ Visual Studio
if(MSVC) if(MSVC)
if(TORQUE_CPU_X32) if(TORQUE_CPU_X32)
if(MSVC11) if(MSVC11)
set(PHYSX3_LIBPATH_PREFIX vc11win32) set(PHYSX3_LIBPATH_PREFIX vc11win32)
elseif(MSVC12) elseif(MSVC12)
set(PHYSX3_LIBPATH_PREFIX vc12win32) set(PHYSX3_LIBPATH_PREFIX vc12win32)
elseif(MSVC14) elseif(MSVC14)
set(PHYSX3_LIBPATH_PREFIX vc14win32) set(PHYSX3_LIBPATH_PREFIX vc14win32)
else() else()
return() message(FATAL_ERROR "This version of VS is not supported")
endif() return()
endif()
set(PHYSX3_LIBNAME_POSTFIX _x86) set(PHYSX3_LIBNAME_POSTFIX _x86)
elseif(TORQUE_CPU_X64) elseif(TORQUE_CPU_X64)
if(MSVC11) if(MSVC11)
set(PHYSX3_LIBPATH_PREFIX vc11win64) set(PHYSX3_LIBPATH_PREFIX vc11win64)
elseif(MSVC12) elseif(MSVC12)
set(PHYSX3_LIBPATH_PREFIX vc12win64) set(PHYSX3_LIBPATH_PREFIX vc12win64)
elseif(MSVC14) elseif(MSVC14)
set(PHYSX3_LIBPATH_PREFIX vc14win64) set(PHYSX3_LIBPATH_PREFIX vc14win64)
else() else()
return() message(FATAL_ERROR "This version of VS is not supported")
endif() return()
set(PHYSX3_LIBNAME_POSTFIX _x64) endif()
set(PHYSX3_LIBNAME_POSTFIX _x64)
endif()
endif() endif()
endif(MSVC) # Only suport 64bit on macOS and linux
if(APPLE)
set(PHYSX3_LIBPATH_PREFIX osx64)
set(PHYSX3_LIBNAME_POSTFIX _x64)
elseif(UNIX)
set(PHYSX3_LIBPATH_PREFIX linux64)
set(PHYSX3_LIBNAME_POSTFIX _x64)
endif()
MACRO(FIND_PHYSX3_LIBRARY VARNAME LIBNAME WITHPOSTFIX) MACRO(FIND_PHYSX3_LIBRARY VARNAME LIBNAME WITHPOSTFIX SEARCHDIR)
set(LIBPOSTFIX "") set(LIBPOSTFIX "")
if(${WITHPOSTFIX}) if(${WITHPOSTFIX})
set(LIBPOSTFIX ${PHYSX3_LIBNAME_POSTFIX}) set(LIBPOSTFIX ${PHYSX3_LIBNAME_POSTFIX})
endif(${WITHPOSTFIX}) endif(${WITHPOSTFIX})
find_library(PHYSX3_${VARNAME}_LIBRARY NAMES ${LIBNAME}${LIBPOSTFIX} #release
PATHS ${PHYSX3_PATH}/Lib/${PHYSX3_LIBPATH_PREFIX}) find_library(PHYSX3_${VARNAME}_LIBRARY NAMES ${LIBNAME}${LIBPOSTFIX} PATHS ${SEARCHDIR}${PHYSX3_LIBPATH_PREFIX})
find_library(PHYSX3_${VARNAME}_LIBRARY_DEBUG NAMES ${LIBNAME}DEBUG${LIBPOSTFIX} #debug
PATHS ${PHYSX3_PATH}/Lib/${PHYSX3_LIBPATH_PREFIX}) find_library(PHYSX3_${VARNAME}_LIBRARY_DEBUG NAMES ${LIBNAME}DEBUG${LIBPOSTFIX} PATHS ${SEARCHDIR}${PHYSX3_LIBPATH_PREFIX})
ENDMACRO(FIND_PHYSX3_LIBRARY VARNAME LIBNAME) ENDMACRO()
# Find the Libs, we just use the full path to save playing around with link_directories # Find the Libs
FIND_PHYSX3_LIBRARY(CORE PhysX3 1) if( WIN32 )
FIND_PHYSX3_LIBRARY(COMMON PhysX3Common 1) FIND_PHYSX3_LIBRARY(CORE PhysX3 1 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(COOKING PhysX3Cooking 1) FIND_PHYSX3_LIBRARY(COMMON PhysX3Common 1 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(CHARACTER PhysX3CharacterKinematic 1) FIND_PHYSX3_LIBRARY(COOKING PhysX3Cooking 1 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(EXTENSIONS PhysX3Extensions 0) FIND_PHYSX3_LIBRARY(CHARACTER PhysX3CharacterKinematic 1 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(TASK PxTask 0) FIND_PHYSX3_LIBRARY(EXTENSIONS PhysX3Extensions 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(DEBUGGER PhysXVisualDebuggerSDK 0) FIND_PHYSX3_LIBRARY(TASK PxTask 1 ${PHYSX3_BASE_PATH}/PxShared/Lib/)
FIND_PHYSX3_LIBRARY(PROFILE PhysXProfileSDK 0) FIND_PHYSX3_LIBRARY(FOUNDATION PxFoundation 1 ${PHYSX3_BASE_PATH}/PxShared/Lib/)
FIND_PHYSX3_LIBRARY(PVD PxPvdSDK 1 ${PHYSX3_BASE_PATH}/PxShared/Lib/)
if(NOT PHYSX3_CORE_LIBRARY)
return()
endif()
#Add the libs
set(PHYSX_LIBRARIES
${PHYSX3_CORE_LIBRARY}
${PHYSX3_COMMON_LIBRARY}
${PHYSX3_EXTENSIONS_LIBRARY}
${PHYSX3_COOKING_LIBRARY}
${PHYSX3_CHARACTER_LIBRARY}
${PHYSX3_TASK_LIBRARY}
${PHYSX3_PVD_LIBRARY}
${PHYSX3_FOUNDATION_LIBRARY}
)
set(PHYSX_LIBRARIES_DEBUG
${PHYSX3_CORE_LIBRARY_DEBUG}
${PHYSX3_COMMON_LIBRARY_DEBUG}
${PHYSX3_EXTENSIONS_LIBRARY_DEBUG}
${PHYSX3_COOKING_LIBRARY_DEBUG}
${PHYSX3_CHARACTER_LIBRARY_DEBUG}
${PHYSX3_TASK_LIBRARY_DEBUG}
${PHYSX3_PVD_LIBRARY_DEBUG}
${PHYSX3_FOUNDATION_LIBRARY_DEBUG}
)
#macOS & linux
elseif(UNIX)
#common
FIND_PHYSX3_LIBRARY(EXTENSIONS PhysX3Extensions 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(CONTROLLER SimulationController 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(SCENEQUERY SceneQuery 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(LOWLEVEL LowLevel 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(LOWLEVEL_DYNAMICS LowLevelDynamics 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(LOWLEVEL_AABB LowLevelAABB 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(LOWLEVEL_CLOTH LowLevelCloth 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(LOWLEVEL_PARTICLES LowLevelParticles 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(TASK PxTask 0 ${PHYSX3_BASE_PATH}/PxShared/lib/)
#platform dependent
if(APPLE)
FIND_PHYSX3_LIBRARY(CORE PhysX3 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(COMMON PhysX3Common 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(COOKING PhysX3Cooking 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(CHARACTER PhysX3CharacterKinematic 0 ${PHYSX3_PATH}/Lib/)
FIND_PHYSX3_LIBRARY(FOUNDATION PxFoundation 0 ${PHYSX3_BASE_PATH}/PxShared/lib/)
FIND_PHYSX3_LIBRARY(PVD PxPvdSDK 0 ${PHYSX3_BASE_PATH}/PxShared/lib/)
elseif() #linux
FIND_PHYSX3_LIBRARY(CORE PhysX3 1 ${PHYSX3_PATH}/Bin/)
FIND_PHYSX3_LIBRARY(COMMON PhysX3Common 1 ${PHYSX3_PATH}/Bin/)
FIND_PHYSX3_LIBRARY(CHARACTER PhysX3CharacterKinematic 1 ${PHYSX3_PATH}/Bin/)
FIND_PHYSX3_LIBRARY(COOKING PhysX3Cooking 1 ${PHYSX3_PATH}/Bin/)
FIND_PHYSX3_LIBRARY(FOUNDATION PxFoundation 1 ${PHYSX3_BASE_PATH}/PxShared/bin/)
FIND_PHYSX3_LIBRARY(PVD PxPvdSDK 1 ${PHYSX3_BASE_PATH}/PxShared/bin/)
FIND_PHYSX3_LIBRARY(CUDA PxCudaContextManager 0 ${PHYSX3_BASE_PATH}/PxShared/lib/)
FIND_PHYSX3_LIBRARY(GPU PhysX3Gpu 1 ${PHYSX3_PATH}/Bin/)
FIND_PHYSX3_LIBRARY(XML PsFastXml 0 ${PHYSX3_BASE_PATH}/PxShared/lib/)
endif()
if(NOT PHYSX3_CORE_LIBRARY)
return()
endif()
#Add the libs
set(PHYSX_LIBRARIES
${PHYSX3_CORE_LIBRARY}
${PHYSX3_GPU_LIBRARY}
${PHYSX3_CHARACTER_LIBRARY}
${PHYSX3_COOKING_LIBRARY}
${PHYSX3_COMMON_LIBRARY}
${PHYSX3_EXTENSIONS_LIBRARY}
${PHYSX3_CONTROLLER_LIBRARY}
${PHYSX3_SCENEQUERY_LIBRARY}
${PHYSX3_LOWLEVEL_LIBRARY}
${PHYSX3_LOWLEVEL_AABB_LIBRARY}
${PHYSX3_LOWLEVEL_DYNAMICS_LIBRARY}
${PHYSX3_LOWLEVEL_CLOTH_LIBRARY}
${PHYSX3_LOWLEVEL_PARTICLES_LIBRARY}
${PHYSX3_CUDA_LIBRARY}
${PHYSX3_TASK_LIBRARY}
${PHYSX3_XML_LIBRARY}
${PHYSX3_FOUNDATION_LIBRARY}
${PHYSX3_PVD_LIBRARY}
)
set(PHYSX_LIBRARIES_DEBUG
${PHYSX3_CORE_LIBRARY_DEBUG}
${PHYSX3_GPU_LIBRARY_DEBUG}
${PHYSX3_CHARACTER_LIBRARY_DEBUG}
${PHYSX3_COOKING_LIBRARY_DEBUG}
${PHYSX3_COMMON_LIBRARY_DEBUG}
${PHYSX3_EXTENSIONS_LIBRARY_DEBUG}
${PHYSX3_CONTROLLER_LIBRARY_DEBUG}
${PHYSX3_SCENEQUERY_LIBRARY_DEBUG}
${PHYSX3_LOWLEVEL_LIBRARY_DEBUG}
${PHYSX3_LOWLEVEL_AABB_LIBRARY_DEBUG}
${PHYSX3_LOWLEVEL_DYNAMICS_LIBRARY_DEBUG}
${PHYSX3_LOWLEVEL_CLOTH_LIBRARY_DEBUG}
${PHYSX3_LOWLEVEL_PARTICLES_LIBRARY_DEBUG}
${PHYSX3_CUDA_LIBRARY_DEBUG}
${PHYSX3_TASK_LIBRARY_DEBUG}
${PHYSX3_XML_LIBRARY_DEBUG}
${PHYSX3_FOUNDATION_LIBRARY_DEBUG}
${PHYSX3_PVD_LIBRARY_DEBUG}
)
if(NOT PHYSX3_CORE_LIBRARY)
return()
endif() endif()
# Defines # Defines
@ -106,56 +222,64 @@ addDef( "TORQUE_PHYSICS_ENABLED" )
addPath( "${srcDir}/T3D/physics/physx3" ) addPath( "${srcDir}/T3D/physics/physx3" )
# Includes # Includes
addInclude( "${PHYSX3_BASE_PATH}/PxShared/include" )
addInclude( "${PHYSX3_BASE_PATH}/PxShared/src/foundation/include" )
addInclude( "${PHYSX3_BASE_PATH}/PxShared/src/pvd/include" )
addInclude( "${PHYSX3_PATH}/Include" ) addInclude( "${PHYSX3_PATH}/Include" )
addInclude( "${PHYSX3_PATH}/Include/extensions" )
addInclude( "${PHYSX3_PATH}/Include/foundation" )
addInclude( "${PHYSX3_PATH}/Include/characterkinematic" )
addInclude( "${PHYSX3_PATH}/Include/common" )
#Add the libs # Libs
set(PHYSX_LIBRARIES_DEBUG addLibRelease( "${PHYSX_LIBRARIES}" )
${PHYSX3_CORE_LIBRARY_DEBUG} addLibDebug( "${PHYSX_LIBRARIES_DEBUG}" )
${PHYSX3_COMMON_LIBRARY_DEBUG}
${PHYSX3_COOKING_LIBRARY_DEBUG}
${PHYSX3_CHARACTER_LIBRARY_DEBUG}
${PHYSX3_EXTENSIONS_LIBRARY_DEBUG}
${PHYSX3_TASK_LIBRARY_DEBUG}
${PHYSX3_DEBUGGER_LIBRARY_DEBUG}
${PHYSX3_PROFILE_LIBRARY_DEBUG}
)
set(PHYSX_LIBRARIES #Install files
${PHYSX3_CORE_LIBRARY}
${PHYSX3_COMMON_LIBRARY}
${PHYSX3_COOKING_LIBRARY}
${PHYSX3_CHARACTER_LIBRARY}
${PHYSX3_EXTENSIONS_LIBRARY}
${PHYSX3_TASK_LIBRARY}
${PHYSX3_DEBUGGER_LIBRARY}
${PHYSX3_PROFILE_LIBRARY}
)
addLibRelease("${PHYSX_LIBRARIES}")
addLibDebug("${PHYSX_LIBRARIES_DEBUG}")
#Install dll files
if( WIN32 ) if( WIN32 )
# File Copy for Release # File Copy for Release
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Release") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CharacterKinematic${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Release") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3Gpu${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3Common${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Release") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CharacterKinematic${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3Cooking${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Release") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3Common${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3Cooking${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/PxFoundation${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/PxPvdSDK${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
# File Copy for Debug # File Copy
if(TORQUE_CPU_X32) if(TORQUE_CPU_X32)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/nvToolsExt32_1.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Debug") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysXDevice.dll" DESTINATION "${projectOutDir}")
elseif(TORQUE_CPU_X64) INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/nvToolsExt32_1.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/nvToolsExt64_1.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Debug") elseif(TORQUE_CPU_X64)
endif() INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysXDevice64.dll" DESTINATION "${projectOutDir}")
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/nvToolsExt64_1.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
endif()
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3DEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Debug") #File copy for Debug
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CharacterKinematicDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Debug") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3DEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CommonDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Debug") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3GpuDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CookingDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS "Debug") INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CharacterKinematicDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CommonDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/PhysX3CookingDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/PxFoundationDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/PxPvdSDKDEBUG${PHYSX3_LIBNAME_POSTFIX}.dll" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
endif(WIN32) endif()
#linux - apple xcode physx build generates static libs
if(UNIX AND NOT APPLE)
# File Copy for Release
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3CharacterKinematic${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3Common${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3Cooking${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/libPxFoundation${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/libPxPvdSDK${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3Gpu${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Release)
# File Copy for Debug
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3DEBUG${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3CharacterKinematicDEBUG${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3CommonDEBUG${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3CookingDEBUG${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/libPxFoundationDEBUG${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_BASE_PATH}/PxShared/bin/${PHYSX3_LIBPATH_PREFIX}/libPxPvdSDKDEBUG${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
INSTALL(FILES "${PHYSX3_PATH}/Bin/${PHYSX3_LIBPATH_PREFIX}/libPhysX3GpuDEBUG${PHYSX3_LIBNAME_POSTFIX}.so" DESTINATION "${projectOutDir}" CONFIGURATIONS Debug)
endif()