added initial support for per-triangle material properties in a non-convex mesh. needs testing.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
//Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
|
||||
|
||||
//
|
||||
// AxisSweep3
|
||||
//
|
||||
|
||||
@@ -14,8 +14,8 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
#include "SimpleBroadphase.h"
|
||||
#include "BroadphaseCollision/Dispatcher.h"
|
||||
#include "BroadphaseCollision/CollisionAlgorithm.h"
|
||||
#include <BroadphaseCollision/Dispatcher.h>
|
||||
#include <BroadphaseCollision/CollisionAlgorithm.h>
|
||||
|
||||
#include "SimdVector3.h"
|
||||
#include "SimdTransform.h"
|
||||
|
||||
@@ -45,7 +45,7 @@ struct CollisionObject
|
||||
{
|
||||
isStatic = 1,
|
||||
noContactResponse = 2,
|
||||
|
||||
customMaterialCallback = 4,//this allows per-triangle material (friction/restitution)
|
||||
};
|
||||
|
||||
int m_collisionFlags;
|
||||
@@ -54,6 +54,9 @@ struct CollisionObject
|
||||
int m_activationState1;
|
||||
float m_deactivationTime;
|
||||
|
||||
SimdScalar m_friction;
|
||||
SimdScalar m_restitution;
|
||||
|
||||
BroadphaseProxy* m_broadphaseHandle;
|
||||
CollisionShape* m_collisionShape;
|
||||
|
||||
@@ -102,6 +105,23 @@ struct CollisionObject
|
||||
return ((GetActivationState() != ISLAND_SLEEPING) && (GetActivationState() != DISABLE_SIMULATION));
|
||||
}
|
||||
|
||||
void setRestitution(float rest)
|
||||
{
|
||||
m_restitution = rest;
|
||||
}
|
||||
float getRestitution() const
|
||||
{
|
||||
return m_restitution;
|
||||
}
|
||||
void setFriction(float frict)
|
||||
{
|
||||
m_friction = frict;
|
||||
}
|
||||
float getFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ void ConvexTriangleCallback::ProcessTriangle(SimdVector3* triangle,int partId, i
|
||||
ob->m_collisionShape = &tm;
|
||||
|
||||
ConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexProxy,&m_triangleProxy);
|
||||
cvxcvxalgo.SetShapeIdentifiers(-1,-1,partId,triangleIndex);
|
||||
cvxcvxalgo.ProcessCollision(m_convexProxy,&m_triangleProxy,*m_dispatchInfoPtr);
|
||||
ob->m_collisionShape = tmpShape;
|
||||
|
||||
|
||||
@@ -55,7 +55,13 @@ public:
|
||||
|
||||
void SetLowLevelOfDetail(bool useLowLevel);
|
||||
|
||||
|
||||
virtual void SetShapeIdentifiers(int partId0,int index0, int partId1,int index1)
|
||||
{
|
||||
m_gjkPairDetector.m_partId0=partId0;
|
||||
m_gjkPairDetector.m_partId1=partId1;
|
||||
m_gjkPairDetector.m_index0=index0;
|
||||
m_gjkPairDetector.m_index1=index1;
|
||||
}
|
||||
|
||||
const PersistentManifold* GetManifold()
|
||||
{
|
||||
|
||||
@@ -18,6 +18,31 @@ subject to the following restrictions:
|
||||
#include "NarrowPhaseCollision/PersistentManifold.h"
|
||||
#include "CollisionDispatch/CollisionObject.h"
|
||||
|
||||
|
||||
///This is to allow MaterialCombiner/Custom Friction/Restitution values
|
||||
ContactAddedCallback gContactAddedCallback=0;
|
||||
|
||||
///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= CollisionObject::customMaterialCallback;
|
||||
inline SimdScalar calculateCombinedFriction(const CollisionObject* body0,const CollisionObject* body1)
|
||||
{
|
||||
SimdScalar friction = body0->getFriction() * body1->getFriction();
|
||||
|
||||
const SimdScalar MAX_FRICTION = 10.f;
|
||||
if (friction < -MAX_FRICTION)
|
||||
friction = -MAX_FRICTION;
|
||||
if (friction > MAX_FRICTION)
|
||||
friction = MAX_FRICTION;
|
||||
return friction;
|
||||
|
||||
}
|
||||
|
||||
inline SimdScalar calculateCombinedRestitution(const CollisionObject* body0,const CollisionObject* body1)
|
||||
{
|
||||
return body0->getRestitution() * body1->getRestitution();
|
||||
}
|
||||
|
||||
|
||||
|
||||
ManifoldResult::ManifoldResult(CollisionObject* body0,CollisionObject* body1,PersistentManifold* manifoldPtr)
|
||||
:m_manifoldPtr(manifoldPtr),
|
||||
m_body0(body0),
|
||||
@@ -56,6 +81,20 @@ void ManifoldResult::AddContactPoint(const SimdVector3& normalOnBInWorld,const S
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
|
||||
newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
|
||||
|
||||
//User can override friction and/or restitution
|
||||
if (gContactAddedCallback &&
|
||||
//and if either of the two bodies requires custom material
|
||||
((m_body0->m_collisionFlags & CollisionObject::customMaterialCallback) ||
|
||||
(m_body1->m_collisionFlags & CollisionObject::customMaterialCallback)))
|
||||
{
|
||||
//experimental feature info, for per-triangle material etc.
|
||||
(*gContactAddedCallback)(newPt,m_body0,m_partId0,m_index0,m_body1,m_partId1,m_index1);
|
||||
}
|
||||
|
||||
m_manifoldPtr->AddManifoldPoint(newPt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ subject to the following restrictions:
|
||||
#include "NarrowPhaseCollision/DiscreteCollisionDetectorInterface.h"
|
||||
struct CollisionObject;
|
||||
class PersistentManifold;
|
||||
class ManifoldPoint;
|
||||
|
||||
|
||||
typedef bool (*ContactAddedCallback)(ManifoldPoint& cp, const CollisionObject* colObj0,int partId0,int index0,const CollisionObject* colObj1,int partId1,int index1);
|
||||
extern ContactAddedCallback gContactAddedCallback;
|
||||
|
||||
|
||||
|
||||
@@ -31,15 +33,28 @@ class ManifoldResult : public DiscreteCollisionDetectorInterface::Result
|
||||
PersistentManifold* m_manifoldPtr;
|
||||
CollisionObject* m_body0;
|
||||
CollisionObject* m_body1;
|
||||
|
||||
int m_partId0;
|
||||
int m_partId1;
|
||||
int m_index0;
|
||||
int m_index1;
|
||||
public:
|
||||
|
||||
ManifoldResult(CollisionObject* body0,CollisionObject* body1,PersistentManifold* manifoldPtr);
|
||||
|
||||
virtual ~ManifoldResult() {};
|
||||
|
||||
virtual void SetShapeIdentifiers(int partId0,int index0, int partId1,int index1)
|
||||
{
|
||||
m_partId0=partId0;
|
||||
m_partId1=partId1;
|
||||
m_index0=index0;
|
||||
m_index1=index1;
|
||||
}
|
||||
|
||||
virtual void AddContactPoint(const SimdVector3& normalOnBInWorld,const SimdVector3& pointInWorld,float depth);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //MANIFOLD_RESULT_H
|
||||
|
||||
@@ -34,6 +34,9 @@ struct DiscreteCollisionDetectorInterface
|
||||
void operator delete(void* ptr) {};
|
||||
|
||||
virtual ~Result(){}
|
||||
|
||||
///SetShapeIdentifiers provides experimental support for per-triangle material / custom material combiner
|
||||
virtual void SetShapeIdentifiers(int partId0,int index0, int partId1,int index1)=0;
|
||||
virtual void AddContactPoint(const SimdVector3& normalOnBInWorld,const SimdVector3& pointInWorld,float depth)=0;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,11 @@ m_penetrationDepthSolver(penetrationDepthSolver),
|
||||
m_simplexSolver(simplexSolver),
|
||||
m_minkowskiA(objectA),
|
||||
m_minkowskiB(objectB),
|
||||
m_ignoreMargin(false)
|
||||
m_ignoreMargin(false),
|
||||
m_partId0(-1),
|
||||
m_index0(-1),
|
||||
m_partId1(-1),
|
||||
m_index1(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -207,6 +211,8 @@ int curIter = 0;
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
output.SetShapeIdentifiers(m_partId0,m_index0,m_partId1,m_index1);
|
||||
|
||||
output.AddContactPoint(
|
||||
normalInB,
|
||||
pointOnB,
|
||||
|
||||
@@ -39,9 +39,17 @@ class GjkPairDetector : public DiscreteCollisionDetectorInterface
|
||||
ConvexShape* m_minkowskiA;
|
||||
ConvexShape* m_minkowskiB;
|
||||
bool m_ignoreMargin;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//experimental feature information, per triangle, per convex etc.
|
||||
//'material combiner' / contact added callback
|
||||
int m_partId0;
|
||||
int m_index0;
|
||||
int m_partId1;
|
||||
int m_index1;
|
||||
|
||||
GjkPairDetector(ConvexShape* objectA,ConvexShape* objectB,SimplexSolverInterface* simplexSolver,ConvexPenetrationDepthSolver* penetrationDepthSolver);
|
||||
virtual ~GjkPairDetector() {};
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ class ManifoldPoint
|
||||
m_localPointB( pointB ),
|
||||
m_normalWorldOnB( normal ),
|
||||
m_distance1( distance ),
|
||||
m_combinedFriction(0.f),
|
||||
m_combinedRestitution(0.f),
|
||||
m_userPersistentData(0),
|
||||
m_lifeTime(0)
|
||||
{
|
||||
@@ -57,6 +59,8 @@ class ManifoldPoint
|
||||
SimdVector3 m_normalWorldOnB;
|
||||
|
||||
float m_distance1;
|
||||
float m_combinedFriction;
|
||||
float m_combinedRestitution;
|
||||
|
||||
|
||||
void* m_userPersistentData;
|
||||
|
||||
@@ -32,6 +32,9 @@ struct MyResult : public DiscreteCollisionDetectorInterface::Result
|
||||
float m_depth;
|
||||
bool m_hasResult;
|
||||
|
||||
virtual void SetShapeIdentifiers(int partId0,int index0, int partId1,int index1)
|
||||
{
|
||||
}
|
||||
void AddContactPoint(const SimdVector3& normalOnBInWorld,const SimdVector3& pointInWorld,float depth)
|
||||
{
|
||||
m_normalOnBInWorld = normalOnBInWorld;
|
||||
|
||||
@@ -19,7 +19,8 @@ subject to the following restrictions:
|
||||
#include <assert.h>
|
||||
|
||||
float gContactBreakingTreshold = 0.02f;
|
||||
ContactDestroyedCallback gContactCallback = 0;
|
||||
ContactDestroyedCallback gContactDestroyedCallback = 0;
|
||||
|
||||
|
||||
|
||||
PersistentManifold::PersistentManifold()
|
||||
@@ -75,9 +76,9 @@ void PersistentManifold::ClearUserCache(ManifoldPoint& pt)
|
||||
assert(occurance<=0);
|
||||
#endif //DEBUG_PERSISTENCY
|
||||
|
||||
if (pt.m_userPersistentData && gContactCallback)
|
||||
if (pt.m_userPersistentData && gContactDestroyedCallback)
|
||||
{
|
||||
(*gContactCallback)(pt.m_userPersistentData);
|
||||
(*gContactDestroyedCallback)(pt.m_userPersistentData);
|
||||
pt.m_userPersistentData = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ struct CollisionResult;
|
||||
extern float gContactBreakingTreshold;
|
||||
|
||||
typedef bool (*ContactDestroyedCallback)(void* userPersistentData);
|
||||
extern ContactDestroyedCallback gContactDestroyedCallback;
|
||||
|
||||
extern ContactDestroyedCallback gContactCallback;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,11 @@ struct PointCollector : public DiscreteCollisionDetectorInterface::Result
|
||||
{
|
||||
}
|
||||
|
||||
virtual void SetShapeIdentifiers(int partId0,int index0, int partId1,int index1)
|
||||
{
|
||||
//??
|
||||
}
|
||||
|
||||
virtual void AddContactPoint(const SimdVector3& normalOnBInWorld,const SimdVector3& pointInWorld,float depth)
|
||||
{
|
||||
if (depth< m_distance)
|
||||
|
||||
Reference in New Issue
Block a user