Merge remote-tracking branch 'GarageGames/development' into physx3_basic

This commit is contained in:
rextimmy 2014-06-06 22:40:14 +10:00
commit d58a69e76c
527 changed files with 9928 additions and 5548 deletions

View file

@ -24,7 +24,7 @@
#define _BULLET_H_
// NOTE: We set these defines which bullet needs here.
#ifdef TORQUE_OS_WIN32
#ifdef TORQUE_OS_WIN
#define WIN32
#endif

View file

@ -46,7 +46,7 @@
#define __APPLE__
#elif defined(TORQUE_OS_LINUX) && !defined(LINUX)
#define LINUX
#elif defined(TORQUE_OS_WIN32) && !defined(WIN32)
#elif defined(TORQUE_OS_WIN) && !defined(WIN32)
#define WIN32
#endif

View file

@ -527,7 +527,7 @@ bool PxMultiActorData::preload( bool server, String &errorBuffer )
return false;
}
if (!shapeName || shapeName == '\0')
if (!shapeName || shapeName[0] == '\0')
{
errorBuffer = "PxMultiActorDatas::preload: no shape name!";
return false;

View file

@ -39,7 +39,7 @@ AFTER_MODULE_INIT( Sim )
{
NamedFactory<PhysicsPlugin>::add( "PhysX", &PxPlugin::create );
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
NamedFactory<PhysicsPlugin>::add( "default", &PxPlugin::create );
#endif

View file

@ -29,25 +29,25 @@
#define __APPLE__
#elif defined(TORQUE_OS_LINUX) && !defined(LINUX)
#define LINUX
#elif defined(TORQUE_OS_WIN32) && !defined(WIN32)
#elif defined(TORQUE_OS_WIN) && !defined(WIN32)
#define WIN32
#endif
//-------------------------------------------------------------------------
#include <PxPhysicsAPI.h>
#include <extensions/PxExtensionsAPI.h>
#include <extensions/PxDefaultErrorCallback.h>
#include <extensions/PxDefaultAllocator.h>
#include <extensions/PxDefaultSimulationFilterShader.h>
#include <extensions/PxDefaultCpuDispatcher.h>
#include <extensions/PxShapeExt.h>
#include <extensions/PxSimpleFactory.h>
#include <foundation/PxFoundation.h>
#include <characterkinematic/PxController.h>
#include <common/PxIO.h>
#include <PxExtensionsAPI.h>
#include <PxDefaultErrorCallback.h>
#include <PxDefaultAllocator.h>
#include <PxDefaultSimulationFilterShader.h>
#include <PxDefaultCpuDispatcher.h>
#include <PxShapeExt.h>
#include <PxSimpleFactory.h>
#include <PxFoundation.h>
#include <PxController.h>
#include <PxIO.h>
extern physx::PxPhysics* gPhysics3SDK;
#endif
#endif // _PHYSX3_

View file

@ -24,7 +24,7 @@
#include "T3D/physics/physx3/px3Body.h"
#include "T3D/physics/physx3/px3.h"
#include "T3D/physics/physx3/px3Cast.h"
#include "T3D/physics/physx3/px3Casts.h"
#include "T3D/physics/physx3/px3World.h"
#include "T3D/physics/physx3/px3Collision.h"
@ -123,24 +123,23 @@ bool Px3Body::init( PhysicsCollision *shape,
Con::errorf("PhysX3 Dynamic Triangle Mesh is not supported.");
}
}
physx::PxShape * pShape = mActor->createShape(*desc->pGeometry,*mMaterial,desc->pose);
physx::PxShape * pShape = mActor->createShape(*desc->pGeometry,*mMaterial);
physx::PxFilterData colData;
if(isDebris)
colData.word0 = PX3_DEBRIS;
else if(isTrigger)
{
//We don't want trigger shapes taking part in shape pair intersection tests
pShape->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE, false);
colData.word0 = PX3_TRIGGER;
}
colData.word0 = PX3_TRIGGER;
else
colData.word0 = PX3_DEFAULT;
//set local pose - actor->createShape with a local pose is deprecated in physx 3.3
pShape->setLocalPose(desc->pose);
//set the skin width
pShape->setContactOffset(0.01f);
pShape->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE, !isTrigger);
pShape->setFlag(physx::PxShapeFlag::eSCENE_QUERY_SHAPE,true);
pShape->setSimulationFilterData(colData);
pShape->setQueryFilterData(colData);
pShape->setSimulationFilterData(colData);
pShape->setQueryFilterData(colData);
}
//mass & intertia has to be set after creating the shape
@ -148,6 +147,10 @@ bool Px3Body::init( PhysicsCollision *shape,
{
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
physx::PxRigidBodyExt::setMassAndUpdateInertia(*actor,mass);
if(mBodyFlags & BF_CCD)
actor->setRigidBodyFlag(physx::PxRigidBodyFlag::eENABLE_CCD, true);
else
actor->setRigidBodyFlag(physx::PxRigidBodyFlag::eENABLE_CCD, false);
}
// This sucks, but it has to happen if we want
@ -366,6 +369,23 @@ void Px3Body::setSimulationEnabled( bool enabled )
delete [] shapes;
}
void Px3Body::moveKinematicTo( const MatrixF &transform )
{
AssertFatal( mActor, "Px3Body::moveKinematicTo - The actor is null!" );
const bool isKinematic = mBodyFlags & BF_KINEMATIC;
if (!isKinematic )
{
Con::errorf("Px3Body::moveKinematicTo is only for kinematic bodies.");
return;
}
mWorld->releaseWriteLock();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
actor->setKinematicTarget(px3Cast<physx::PxTransform>(transform));
}
void Px3Body::setTransform( const MatrixF &transform )
{
AssertFatal( mActor, "Px3Body::setTransform - The actor is null!" );

View file

@ -20,8 +20,8 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _T3D_PHYSICS_PX3BODY_H_
#define _T3D_PHYSICS_PX3BODY_H_
#ifndef _PX3BODY_H_
#define _PX3BODY_H_
#ifndef _T3D_PHYSICS_PHYSICSBODY_H_
#include "T3D/physics/physicsBody.h"
@ -88,6 +88,7 @@ public:
// PhysicsObject
virtual PhysicsWorld* getWorld();
virtual void setTransform( const MatrixF &xfm );
virtual void moveKinematicTo( const MatrixF &xfm );
virtual MatrixF& getTransform( MatrixF *outMatrix );
virtual Box3F getWorldBounds();
virtual void setSimulationEnabled( bool enabled );
@ -118,4 +119,4 @@ public:
virtual void applyImpulse( const Point3F &origin, const Point3F &force );
};
#endif
#endif // _PX3BODY_H_

View file

@ -0,0 +1,137 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _PX3CASTS_H_
#define _PX3CASTS_H_
#ifndef _MPOINT3_H_
#include "math/mPoint3.h"
#endif
#ifndef _MMATRIX_H_
#include "math/mMatrix.h"
#endif
#ifndef _MBOX_H_
#include "math/mBox.h"
#endif
#ifndef _MQUAT_H_
#include "math/mQuat.h"
#endif
#ifndef _MTRANSFORM_H_
#include "math/mTransform.h"
#endif
template <class T, class F> inline T px3Cast( const F &from );
//-------------------------------------------------------------------------
template<>
inline Point3F px3Cast( const physx::PxVec3 &vec )
{
return Point3F( vec.x, vec.y, vec.z );
}
template<>
inline physx::PxVec3 px3Cast( const Point3F &point )
{
return physx::PxVec3( point.x, point.y, point.z );
}
//-------------------------------------------------------------------------
template<>
inline QuatF px3Cast( const physx::PxQuat &quat )
{
/// The Torque quat has the opposite winding order.
return QuatF( -quat.x, -quat.y, -quat.z, quat.w );
}
template<>
inline physx::PxQuat px3Cast( const QuatF &quat )
{
/// The Torque quat has the opposite winding order.
physx::PxQuat result( -quat.x, -quat.y, -quat.z, quat.w );
return result;
}
//-------------------------------------------------------------------------
template<>
inline physx::PxExtendedVec3 px3Cast( const Point3F &point )
{
return physx::PxExtendedVec3( point.x, point.y, point.z );
}
template<>
inline Point3F px3Cast( const physx::PxExtendedVec3 &xvec )
{
return Point3F( xvec.x, xvec.y, xvec.z );
}
//-------------------------------------------------------------------------
template<>
inline physx::PxBounds3 px3Cast( const Box3F &box )
{
physx::PxBounds3 bounds(px3Cast<physx::PxVec3>(box.minExtents),
px3Cast<physx::PxVec3>(box.maxExtents));
return bounds;
}
template<>
inline Box3F px3Cast( const physx::PxBounds3 &bounds )
{
return Box3F( bounds.minimum.x,
bounds.minimum.y,
bounds.minimum.z,
bounds.maximum.x,
bounds.maximum.y,
bounds.maximum.z );
}
//-------------------------------------------------------------------------
template<>
inline physx::PxTransform px3Cast( const MatrixF &xfm )
{
physx::PxTransform out;
QuatF q;
q.set(xfm);
out.q = px3Cast<physx::PxQuat>(q);
out.p = px3Cast<physx::PxVec3>(xfm.getPosition());
return out;
}
template<>
inline TransformF px3Cast(const physx::PxTransform &xfm)
{
TransformF out(px3Cast<Point3F>(xfm.p),AngAxisF(px3Cast<QuatF>(xfm.q)));
return out;
}
template<>
inline MatrixF px3Cast( const physx::PxTransform &xfm )
{
MatrixF out;
TransformF t = px3Cast<TransformF>(xfm);
out = t.getMatrix();
return out;
}
#endif //_PX3CASTS_H_

View file

@ -26,7 +26,7 @@
#include "math/mPoint3.h"
#include "math/mMatrix.h"
#include "T3D/physics/physx3/px3.h"
#include "T3D/physics/physx3/px3Cast.h"
#include "T3D/physics/physx3/px3Casts.h"
#include "T3D/physics/physx3/px3World.h"
#include "T3D/physics/physx3/px3Stream.h"
@ -105,7 +105,10 @@ bool Px3Collision::addConvex( const Point3F *points,
convexMesh = gPhysics3SDK->createConvexMesh(in);
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxConvexMeshGeometry(convexMesh);
physx::PxVec3 scale = px3Cast<physx::PxVec3>(localXfm.getScale());
physx::PxQuat rotation = px3Cast<physx::PxQuat>(QuatF(localXfm));
physx::PxMeshScale meshScale(scale,rotation);
desc->pGeometry = new physx::PxConvexMeshGeometry(convexMesh,meshScale);
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
return true;
@ -177,13 +180,13 @@ bool Px3Collision::addHeightfield( const U16 *heights,
if ( holes && holes[ getMax( (S32)index - 1, 0 ) ] ) // row index for holes adjusted so PhysX collision shape better matches rendered terrain
{
currentSample->materialIndex0 = 0;
currentSample->materialIndex1 = 0;
currentSample->materialIndex0 = physx::PxHeightFieldMaterial::eHOLE;
currentSample->materialIndex1 = physx::PxHeightFieldMaterial::eHOLE;
}
else
{
currentSample->materialIndex0 = 1;
currentSample->materialIndex1 = 1;
currentSample->materialIndex0 = 0;
currentSample->materialIndex1 = 0;
}
int flag = ( column + tess ) % 2;

View file

@ -20,8 +20,8 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _T3D_PHYSICS_PX3COLLISION_H_
#define _T3D_PHYSICS_PX3COLLISION_H_
#ifndef _PX3COLLISION_H_
#define _PX3COLLISION_H_
#ifndef _T3D_PHYSICS_PHYSICSCOLLISION_H_
#include "T3D/physics/physicsCollision.h"
@ -32,7 +32,7 @@
#ifndef _MMATRIX_H_
#include "math/mMatrix.h"
#endif
//nasty hate doing this!
#include <foundation/PxTransform.h>
//forward declare
@ -84,4 +84,4 @@ public:
const MatrixF &localXfm );
};
#endif
#endif // _PX3COLLISION_H_

View file

@ -24,7 +24,7 @@
#include "T3D/physics/physx3/px3Player.h"
#include "T3D/physics/physicsPlugin.h"
#include "T3D/physics/physx3/px3World.h"
#include "T3D/physics/physx3/px3Cast.h"
#include "T3D/physics/physx3/px3Casts.h"
#include "T3D/physics/physx3/px3Utils.h"
#include "collision/collision.h"
@ -322,7 +322,10 @@ void Px3Player::setScale( const Point3F &scale )
Box3F Px3Player::getWorldBounds()
{
Con::warnf( "Px3Player::getWorldBounds - not implemented" );
return Box3F::Invalid;
physx::PxBounds3 bounds;
physx::PxRigidDynamic *actor = mController->getActor();
physx::PxShape *shape = px3GetFirstShape(actor);
bounds = physx::PxShapeExt::getWorldBounds(*shape,*actor);
return px3Cast<Box3F>( bounds );
}

View file

@ -101,4 +101,4 @@ public:
};
#endif // _PXPLAYER_H
#endif // _PX3PLAYER_H_

View file

@ -37,7 +37,7 @@ AFTER_MODULE_INIT( Sim )
{
NamedFactory<PhysicsPlugin>::add( "PhysX3", &Px3Plugin::create );
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
NamedFactory<PhysicsPlugin>::add( "default", &Px3Plugin::create );
#endif
}
@ -224,4 +224,3 @@ U32 Px3Plugin::getWorldCount() const
{
return mPhysicsWorldLookup.size();
}

View file

@ -20,13 +20,15 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _T3D_PHYSICS_PX3PLUGIN_H_
#define _T3D_PHYSICS_PX3PLUGIN_H_
#ifndef _PX3PLUGIN_H_
#define _PX3PLUGIN_H_
#ifndef _T3D_PHYSICS_PHYSICSPLUGIN_H_
#include "T3D/physics/physicsPlugin.h"
#endif
class Px3ClothShape;
class Px3Plugin : public PhysicsPlugin
{
public:
@ -52,7 +54,6 @@ public:
virtual PhysicsWorld* getWorld( const String &worldName ) const;
virtual PhysicsWorld* getWorld() const;
virtual U32 getWorldCount() const;
};
#endif
#endif // _PX3PLUGIN_H_

View file

@ -20,8 +20,8 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _T3D_PHYSICS_PX3STREAM_H_
#define _T3D_PHYSICS_PX3STREAM_H_
#ifndef _PX3STREAM_H_
#define _PX3STREAM_H_
#ifndef _PHYSX3_H_
#include "T3D/physics/physx3/px3.h"
@ -74,4 +74,4 @@ public:
virtual ~Px3ConsoleStream();
};
#endif
#endif // _PX3STREAM_H_

View file

@ -20,8 +20,8 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _PHYSX3_UTILS_H_
#define _PHYSX3_UTILS_H_
#ifndef _PX3UTILS_H_
#define _PX3UTILS_H_
namespace physx
{
@ -31,5 +31,4 @@ namespace physx
extern physx::PxShape* px3GetFirstShape(physx::PxRigidActor *actor);
#endif
#endif // _PX3UTILS_H_

View file

@ -25,7 +25,7 @@
#include "T3D/physics/physx3/px3.h"
#include "T3D/physics/physx3/px3Plugin.h"
#include "T3D/physics/physx3/px3Cast.h"
#include "T3D/physics/physx3/px3Casts.h"
#include "T3D/physics/physx3/px3Stream.h"
#include "T3D/physics/physicsUserData.h"
@ -54,6 +54,23 @@ physx::PxDefaultAllocator Px3World::smMemoryAlloc;
F32 Px3World::smPhysicsStepTime = 1.0f/(F32)TickMs;
U32 Px3World::smPhysicsMaxIterations = 4;
//filter shader with support for CCD pairs
static physx::PxFilterFlags sCcdFilterShader(
physx::PxFilterObjectAttributes attributes0,
physx::PxFilterData filterData0,
physx::PxFilterObjectAttributes attributes1,
physx::PxFilterData filterData1,
physx::PxPairFlags& pairFlags,
const void* constantBlock,
physx::PxU32 constantBlockSize)
{
pairFlags = physx::PxPairFlag::eRESOLVE_CONTACTS;
pairFlags |= physx::PxPairFlag::eCCD_LINEAR;
return physx::PxFilterFlags();
}
Px3World::Px3World(): mScene( NULL ),
mProcessList( NULL ),
mIsSimulating( false ),
@ -198,7 +215,6 @@ void Px3World::destroyWorld()
mScene->release();
mScene = NULL;
}
}
bool Px3World::initWorld( bool isServer, ProcessList *processList )
@ -221,10 +237,12 @@ bool Px3World::initWorld( bool isServer, ProcessList *processList )
sceneDesc.cpuDispatcher = smCpuDispatcher;
Con::printf("PhysX3 using Cpu: %d workers", smCpuDispatcher->getWorkerCount());
}
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_CCD;
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
sceneDesc.filterShader = physx::PxDefaultSimulationFilterShader;
sceneDesc.filterShader = sCcdFilterShader;
mScene = gPhysics3SDK->createScene(sceneDesc);
@ -559,7 +577,6 @@ void Px3World::onDebugDraw( const SceneRenderState *state )
}
}
//set simulation timing via script
DefineEngineFunction( physx3SetSimulationTiming, void, ( F32 stepTime, U32 maxSteps ),, "Set simulation timing of the PhysX 3 plugin" )
{

View file

@ -20,8 +20,8 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _PHYSX3_WORLD_H_
#define _PHYSX3_WORLD_H_
#ifndef _PX3WORLD_H_
#define _PX3WORLD_H_
#ifndef _T3D_PHYSICS_PHYSICSWORLD_H_
#include "T3D/physics/physicsWorld.h"
@ -53,7 +53,6 @@ class Px3World : public PhysicsWorld
protected:
physx::PxScene* mScene;
bool mIsEnabled;
bool mIsSimulating;
bool mIsServer;
@ -71,7 +70,6 @@ protected:
static physx::PxVisualDebuggerConnection* smPvdConnection;
static F32 smPhysicsStepTime;
static U32 smPhysicsMaxIterations;
F32 mAccumulator;
bool _simulate(const F32 dt);
@ -105,6 +103,4 @@ public:
static void setTiming(F32 stepTime,U32 maxIterations);
};
#endif
#endif // _PX3WORLD_H_