Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions physics/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ Engine* Engine::instance()
Engine::Engine()
: _cooking(NULL), _cudaManager(NULL), _pvdTransport(NULL), _pvd(NULL)
{
#if (PX_PHYSICS_VERSION_MAJOR > 3)
PxFoundation* foundation = PxCreateFoundation(PX_PHYSICS_VERSION, defaultAllocator, errorHandler);
#else
PxFoundation* foundation = PxCreateFoundation(PX_FOUNDATION_VERSION, defaultAllocator, errorHandler);
#endif

if (!foundation)
{
OSG_WARN << "Unable to initialize PhysX foundation." << std::endl;
Expand Down Expand Up @@ -127,6 +132,7 @@ bool Engine::addActor(const std::string& s, PxRigidActor* actor, const PxFilterD
return false;
}

#if !(PX_PHYSICS_VERSION_MAJOR > 3)
bool Engine::addActor(const std::string& s, physx::PxParticleBase* ps, const physx::PxFilterData& filter)
{
if (addActor(s, ps))
Expand All @@ -137,6 +143,7 @@ bool Engine::addActor(const std::string& s, physx::PxParticleBase* ps, const phy
else
return false;
}
#endif

bool Engine::removeActor(const std::string& s, PxActor* actor)
{
Expand Down
5 changes: 4 additions & 1 deletion physics/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include <PxPhysicsAPI.h>
#include <extensions/PxExtensionsAPI.h>
#include <vector>
#include <string>
#include <map>

#if PX_PHYSICS_VERSION_MAJOR==3 && PX_PHYSICS_VERSION_MINOR==4
#if PX_PHYSICS_VERSION_MAJOR==3 && PX_PHYSICS_VERSION_MINOR==4 || PX_PHYSICS_VERSION_MAJOR > 3
//
#else
# error "Unsupport PhysX version"
Expand Down Expand Up @@ -43,7 +44,9 @@ namespace osgPhysics
/** Add actor object to specified scene */
bool addActor(const std::string& scene, physx::PxActor* actor);
bool addActor(const std::string& scene, physx::PxRigidActor* actor, const physx::PxFilterData& filter);
#if !(PX_PHYSICS_VERSION_MAJOR > 3)
bool addActor(const std::string& scene, physx::PxParticleBase* ps, const physx::PxFilterData& filter);
#endif
bool removeActor(const std::string& scene, physx::PxActor* actor);

typedef std::vector<physx::PxActor*> ActorList;
Expand Down
3 changes: 2 additions & 1 deletion physics/ParticleUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <iostream>

#if !(PX_PHYSICS_VERSION_MAJOR > 3)
#include <intrin.h>
#pragma intrinsic(_BitScanForward)
#pragma intrinsic(_BitScanReverse)
Expand Down Expand Up @@ -420,5 +421,5 @@ void NativeParticleOperator::operateParticles(osgParticle::ParticleSystem* ps, d
// FIXME: are unhandled particles all dead?
}
}

#endif
#endif
3 changes: 2 additions & 1 deletion physics/ParticleUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <osg/Referenced>
#include "Engine.h"

#if !(PX_PHYSICS_VERSION_MAJOR > 3)
namespace osgPhysics
{

Expand Down Expand Up @@ -187,5 +188,5 @@ namespace osgPhysics
#endif

}

#endif
#endif
14 changes: 13 additions & 1 deletion physics/PhysicsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ namespace osgPhysics
heightFieldDesc.nbColumns = numColumns;
heightFieldDesc.nbRows = numRows;
heightFieldDesc.format = PxHeightFieldFormat::eS16_TM;
#if !(PX_PHYSICS_VERSION_MAJOR > 3)
heightFieldDesc.thickness = thickness;
#endif

PxHeightFieldSample* samplesData = (PxHeightFieldSample*)malloc(
sizeof(PxHeightFieldSample) * numColumns * numRows);
Expand Down Expand Up @@ -322,6 +324,7 @@ namespace osgPhysics
return createTriangleMesh(verts, indices);
}

#if !(PX_PHYSICS_VERSION_MAJOR > 3)
PxClothFabric* createClothFabric(const std::vector<PxVec3>& verts, const std::vector<PxU32>& indices,
const osg::Vec3& gravity)
{
Expand All @@ -336,7 +339,7 @@ namespace osgPhysics
PxVec3 g(gravity[0], gravity[1], gravity[2]);
return PxClothFabricCreate(*SDK_OBJ, meshDesc, g);
}

#endif
PxScene* createScene(const osg::Vec3& gravity, const PxSimulationFilterShader& filter,
physx::PxSceneFlags flags, unsigned int numThreads, bool useGPU)
{
Expand All @@ -348,10 +351,19 @@ namespace osgPhysics
if (useGPU)
{
PxCudaContextManager* cudaManager = Engine::instance()->getOrCreateCudaContextManager();
#if (PX_PHYSICS_VERSION_MAJOR > 3)
if (cudaManager) sceneDesc.cudaContextManager = cudaManager;
#else
if (cudaManager) sceneDesc.gpuDispatcher = cudaManager->getGpuDispatcher();
#endif

}

#if (PX_PHYSICS_VERSION_MAJOR > 3)
if (!sceneDesc.cudaContextManager && !sceneDesc.cpuDispatcher)
#else
if (!sceneDesc.gpuDispatcher && !sceneDesc.cpuDispatcher)
#endif
{
PxDefaultCpuDispatcher* defCpuDispatcher = PxDefaultCpuDispatcherCreate(numThreads);
if (!defCpuDispatcher)
Expand Down
14 changes: 12 additions & 2 deletions physics/PhysicsUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ namespace osgPhysics
/** Cook and create new convex mesh */
extern physx::PxConvexMesh* createConvexMesh(
const std::vector<physx::PxVec3>& verts,
physx::PxConvexFlags flags = physx::PxConvexFlag::eCOMPUTE_CONVEX | physx::PxConvexFlag::eINFLATE_CONVEX);
physx::PxConvexFlags flags = physx::PxConvexFlag::eCOMPUTE_CONVEX
#if !(PX_PHYSICS_VERSION_MAJOR > 3)
| physx::PxConvexFlag::eINFLATE_CONVEX
#endif
);

/** Cook and create new convex mesh from node */
extern physx::PxConvexMesh* createConvexMesh(
osg::Node& node,
physx::PxConvexFlags flags = physx::PxConvexFlag::eCOMPUTE_CONVEX | physx::PxConvexFlag::eINFLATE_CONVEX);
physx::PxConvexFlags flags = physx::PxConvexFlag::eCOMPUTE_CONVEX
#if !(PX_PHYSICS_VERSION_MAJOR > 3)
| physx::PxConvexFlag::eINFLATE_CONVEX
#endif
);

/** Cook and create new height field, where lowerTriangleData & upperTriangleData contain material index data
and hole flag of the lower/upper triangle of each height field cell
Expand All @@ -53,9 +61,11 @@ namespace osgPhysics
extern physx::PxTriangleMesh* createTriangleMesh(osg::Node& node);

/** Cook and create new physics cloth fabric */
#if !(PX_PHYSICS_VERSION_MAJOR > 3)
extern physx::PxClothFabric* createClothFabric(const std::vector<physx::PxVec3>& verts,
const std::vector<physx::PxU32>& indices,
const osg::Vec3& gravity);
#endif

/** Create a physics scene */
extern physx::PxScene* createScene(const osg::Vec3& gravity,
Expand Down
12 changes: 12 additions & 0 deletions physics/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@ physx::PxRigidDynamic* WheeledVehicle::createActorAndFilters(
PxMaterial* defMaterial = VehicleManager::instance()->getSurfaceMaterial(VehicleManager::SURFACE_TARMAC);
for (int i = 0; i < numWheels; ++i)
{

#if (PX_PHYSICS_VERSION_MAJOR > 3)
_wheelShapes[i] = PxRigidActorExt::createExclusiveShape(*actor, *(wheelGeometries[i]), wheelMtl ? *wheelMtl : *defMaterial);
actor->attachShape(*_wheelShapes[i]);
#else
_wheelShapes[i] = actor->createShape(*(wheelGeometries[i]), wheelMtl ? *wheelMtl : *defMaterial);
#endif

_wheelShapes[i]->setLocalPose(PxTransform(PxIdentity));

// Create a query filter data for the car to ensure that cars do not attempt to drive on themselves
Expand All @@ -271,7 +278,12 @@ physx::PxRigidDynamic* WheeledVehicle::createActorAndFilters(
}

// Must first create wheels and then chassis because PhysX will treat the first shape as the wheel
#if (PX_PHYSICS_VERSION_MAJOR > 3)
_chassisShape = PxRigidActorExt::createExclusiveShape(*actor, PxConvexMeshGeometry(chassis.mesh), chassisMtl ? *chassisMtl : *defMaterial);
actor->attachShape(*_chassisShape);
#else
_chassisShape = actor->createShape(PxConvexMeshGeometry(chassis.mesh), chassisMtl ? *chassisMtl : *defMaterial);
#endif
_chassisShape->setLocalPose(PxTransform(PxIdentity));
VehicleManager::createFilter(VehicleManager::FILTER_UNDRIVABLE_SURFACE, _chassisShape);
VehicleManager::createFilter(VehicleManager::FILTER_CHASSIS, _chassisShape);
Expand Down
2 changes: 2 additions & 0 deletions physics/VehicleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ bool VehicleManager::addActor(const std::string& scene, PxActor* actor,
}
else if (actor)
{
#if !(PX_PHYSICS_VERSION_MAJOR > 3)
PxParticleBase* particleBase = actor->is<PxParticleBase>();
if (particleBase)
{
Expand All @@ -179,6 +180,7 @@ bool VehicleManager::addActor(const std::string& scene, PxActor* actor,
filter.word1 = COLLISION_FLAG_OBSTACLE_AGAINST;
particleBase->setSimulationFilterData(filter);
}
#endif
}
return osgPhysics::Engine::instance()->addActor(scene, actor);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/physics_vehicle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ osg::Group* createCar(osgPhysicsUtils::InputManager* manager, osgPhysics::Update
return car.release();
}

#if !(PX_PHYSICS_VERSION_MAJOR > 3)
osgParticle::ParticleSystem* createParticleSystem(osg::Group* parent)
{
// Set up the particle appearance
Expand Down Expand Up @@ -241,6 +242,7 @@ osgParticle::ParticleSystem* createParticleSystem(osg::Group* parent)
parent->addChild(geode.get());
return ps.get();
}
#endif

int main(int argc, char** argv)
{
Expand Down Expand Up @@ -289,17 +291,21 @@ int main(int argc, char** argv)
osg::ref_ptr<osg::MatrixTransform> particleGroup = new osg::MatrixTransform;
particleGroup->setMatrix(osg::Matrix::translate(initialPosition + osg::Z_AXIS * 5.0f));

#if !(PX_PHYSICS_VERSION_MAJOR > 3)
osgParticle::ParticleSystem* ps = createParticleSystem(particleGroup.get());
osg::ref_ptr<osgParticle::ParticleSystemUpdater> particleUpdater = new osgParticle::ParticleSystemUpdater;
particleUpdater->addParticleSystem(ps);
#endif

// Build the scene graph
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addUpdateCallback(physicsUpdater.get());
root->addChild(terrain.get());
root->addChild(vehicle.get());
root->addChild(ball.get());
#if !(PX_PHYSICS_VERSION_MAJOR > 3)
root->addChild(particleUpdater.get());
#endif
root->addChild(particleGroup.get());

// Start the viewer
Expand Down