mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-14 13:50:04 +00:00
Allow multiple meshes to be used in the TriangleIndexVertexArray (this name is bad, is should be 'MeshArray'.
Renamed some 'box' into 'convex' in ConvexConcaveCollisionAlgorithm (it is generic for all convex objects, not for boxes).
This commit is contained in:
parent
206c56f2ca
commit
09aeefe029
@ -17,7 +17,6 @@ subject to the following restrictions:
|
||||
#include "ConvexConcaveCollisionAlgorithm.h"
|
||||
#include "CollisionDispatch/CollisionObject.h"
|
||||
#include "CollisionShapes/MultiSphereShape.h"
|
||||
#include "CollisionShapes/BoxShape.h"
|
||||
#include "ConvexConvexAlgorithm.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||
#include "CollisionShapes/TriangleShape.h"
|
||||
@ -28,7 +27,7 @@ subject to the following restrictions:
|
||||
|
||||
ConvexConcaveCollisionAlgorithm::ConvexConcaveCollisionAlgorithm( const CollisionAlgorithmConstructionInfo& ci,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||
: CollisionAlgorithm(ci),m_convex(*proxy0),m_concave(*proxy1),
|
||||
m_boxTriangleCallback(ci.m_dispatcher,proxy0,proxy1)
|
||||
m_ConvexTriangleCallback(ci.m_dispatcher,proxy0,proxy1)
|
||||
|
||||
{
|
||||
}
|
||||
@ -39,8 +38,8 @@ ConvexConcaveCollisionAlgorithm::~ConvexConcaveCollisionAlgorithm()
|
||||
|
||||
|
||||
|
||||
BoxTriangleCallback::BoxTriangleCallback(Dispatcher* dispatcher,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1):
|
||||
m_boxProxy(proxy0),m_triangleProxy(*proxy1),m_dispatcher(dispatcher),
|
||||
ConvexTriangleCallback::ConvexTriangleCallback(Dispatcher* dispatcher,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1):
|
||||
m_convexProxy(proxy0),m_triangleProxy(*proxy1),m_dispatcher(dispatcher),
|
||||
m_dispatchInfoPtr(0)
|
||||
{
|
||||
|
||||
@ -52,7 +51,7 @@ BoxTriangleCallback::BoxTriangleCallback(Dispatcher* dispatcher,BroadphaseProxy
|
||||
ClearCache();
|
||||
}
|
||||
|
||||
BoxTriangleCallback::~BoxTriangleCallback()
|
||||
ConvexTriangleCallback::~ConvexTriangleCallback()
|
||||
{
|
||||
ClearCache();
|
||||
m_dispatcher->ReleaseManifold( m_manifoldPtr );
|
||||
@ -60,14 +59,14 @@ BoxTriangleCallback::~BoxTriangleCallback()
|
||||
}
|
||||
|
||||
|
||||
void BoxTriangleCallback::ClearCache()
|
||||
void ConvexTriangleCallback::ClearCache()
|
||||
{
|
||||
m_dispatcher->ClearManifold(m_manifoldPtr);
|
||||
};
|
||||
|
||||
|
||||
|
||||
void BoxTriangleCallback::ProcessTriangle(SimdVector3* triangle,int partId, int triangleIndex)
|
||||
void ConvexTriangleCallback::ProcessTriangle(SimdVector3* triangle,int partId, int triangleIndex)
|
||||
{
|
||||
|
||||
//just for debugging purposes
|
||||
@ -81,7 +80,7 @@ void BoxTriangleCallback::ProcessTriangle(SimdVector3* triangle,int partId, int
|
||||
|
||||
|
||||
|
||||
CollisionObject* colObj = static_cast<CollisionObject*>(m_boxProxy->m_clientObject);
|
||||
CollisionObject* colObj = static_cast<CollisionObject*>(m_convexProxy->m_clientObject);
|
||||
|
||||
if (colObj->m_collisionShape->IsConvex())
|
||||
{
|
||||
@ -93,8 +92,8 @@ void BoxTriangleCallback::ProcessTriangle(SimdVector3* triangle,int partId, int
|
||||
CollisionShape* tmpShape = ob->m_collisionShape;
|
||||
ob->m_collisionShape = &tm;
|
||||
|
||||
ConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_boxProxy,&m_triangleProxy);
|
||||
cvxcvxalgo.ProcessCollision(m_boxProxy,&m_triangleProxy,*m_dispatchInfoPtr);
|
||||
ConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexProxy,&m_triangleProxy);
|
||||
cvxcvxalgo.ProcessCollision(m_convexProxy,&m_triangleProxy,*m_dispatchInfoPtr);
|
||||
ob->m_collisionShape = tmpShape;
|
||||
|
||||
}
|
||||
@ -105,22 +104,22 @@ void BoxTriangleCallback::ProcessTriangle(SimdVector3* triangle,int partId, int
|
||||
|
||||
|
||||
|
||||
void BoxTriangleCallback::SetTimeStepAndCounters(float collisionMarginTriangle,const DispatcherInfo& dispatchInfo)
|
||||
void ConvexTriangleCallback::SetTimeStepAndCounters(float collisionMarginTriangle,const DispatcherInfo& dispatchInfo)
|
||||
{
|
||||
m_dispatchInfoPtr = &dispatchInfo;
|
||||
m_collisionMarginTriangle = collisionMarginTriangle;
|
||||
|
||||
//recalc aabbs
|
||||
CollisionObject* boxBody = (CollisionObject* )m_boxProxy->m_clientObject;
|
||||
CollisionObject* convexBody = (CollisionObject* )m_convexProxy->m_clientObject;
|
||||
CollisionObject* triBody = (CollisionObject* )m_triangleProxy.m_clientObject;
|
||||
|
||||
SimdTransform boxInTriangleSpace;
|
||||
boxInTriangleSpace = triBody->m_worldTransform.inverse() * boxBody->m_worldTransform;
|
||||
SimdTransform convexInTriangleSpace;
|
||||
convexInTriangleSpace = triBody->m_worldTransform.inverse() * convexBody->m_worldTransform;
|
||||
|
||||
CollisionShape* boxshape = static_cast<CollisionShape*>(boxBody->m_collisionShape);
|
||||
CollisionShape* convexShape = static_cast<CollisionShape*>(convexBody->m_collisionShape);
|
||||
//CollisionShape* triangleShape = static_cast<CollisionShape*>(triBody->m_collisionShape);
|
||||
|
||||
boxshape->GetAabb(boxInTriangleSpace,m_aabbMin,m_aabbMax);
|
||||
convexShape->GetAabb(convexInTriangleSpace,m_aabbMin,m_aabbMax);
|
||||
|
||||
float extraMargin = collisionMarginTriangle;//CONVEX_DISTANCE_MARGIN;//+0.1f;
|
||||
|
||||
@ -133,14 +132,14 @@ void BoxTriangleCallback::SetTimeStepAndCounters(float collisionMarginTriangle,c
|
||||
|
||||
void ConvexConcaveCollisionAlgorithm::ClearCache()
|
||||
{
|
||||
m_boxTriangleCallback.ClearCache();
|
||||
m_ConvexTriangleCallback.ClearCache();
|
||||
|
||||
}
|
||||
|
||||
void ConvexConcaveCollisionAlgorithm::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy* ,const DispatcherInfo& dispatchInfo)
|
||||
{
|
||||
|
||||
CollisionObject* boxBody = static_cast<CollisionObject* >(m_convex.m_clientObject);
|
||||
CollisionObject* convexBody = static_cast<CollisionObject* >(m_convex.m_clientObject);
|
||||
CollisionObject* triBody = static_cast<CollisionObject* >(m_concave.m_clientObject);
|
||||
|
||||
if (triBody->m_collisionShape->GetShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
|
||||
@ -154,17 +153,19 @@ void ConvexConcaveCollisionAlgorithm::ProcessCollision (BroadphaseProxy* ,Broadp
|
||||
CollisionObject* triOb = static_cast<CollisionObject*>(m_concave.m_clientObject);
|
||||
TriangleMeshShape* triangleMesh = static_cast<TriangleMeshShape*>( triOb->m_collisionShape);
|
||||
|
||||
if (boxBody->m_collisionShape->IsConvex())
|
||||
if (convexBody->m_collisionShape->IsConvex())
|
||||
{
|
||||
float collisionMarginTriangle = triangleMesh->GetMargin();
|
||||
|
||||
m_boxTriangleCallback.SetTimeStepAndCounters(collisionMarginTriangle,dispatchInfo);
|
||||
#ifdef USE_BOX_TRIANGLE
|
||||
m_dispatcher->ClearManifold(m_boxTriangleCallback.m_manifoldPtr);
|
||||
#endif
|
||||
m_boxTriangleCallback.m_manifoldPtr->SetBodies(m_convex.m_clientObject,m_concave.m_clientObject);
|
||||
m_ConvexTriangleCallback.SetTimeStepAndCounters(collisionMarginTriangle,dispatchInfo);
|
||||
|
||||
triangleMesh->ProcessAllTriangles( &m_boxTriangleCallback,m_boxTriangleCallback.GetAabbMin(),m_boxTriangleCallback.GetAabbMax());
|
||||
//Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
|
||||
//m_dispatcher->ClearManifold(m_ConvexTriangleCallback.m_manifoldPtr);
|
||||
|
||||
|
||||
m_ConvexTriangleCallback.m_manifoldPtr->SetBodies(m_convex.m_clientObject,m_concave.m_clientObject);
|
||||
|
||||
triangleMesh->ProcessAllTriangles( &m_ConvexTriangleCallback,m_ConvexTriangleCallback.GetAabbMin(),m_ConvexTriangleCallback.GetAabbMax());
|
||||
|
||||
|
||||
}
|
||||
|
@ -25,10 +25,10 @@ class Dispatcher;
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||
|
||||
|
||||
|
||||
class BoxTriangleCallback : public TriangleCallback
|
||||
///For each triangle in the concave mesh that overlaps with the AABB of a convex (m_convexProxy), ProcessTriangle is called.
|
||||
class ConvexTriangleCallback : public TriangleCallback
|
||||
{
|
||||
BroadphaseProxy* m_boxProxy;
|
||||
BroadphaseProxy* m_convexProxy;
|
||||
BroadphaseProxy m_triangleProxy;
|
||||
|
||||
SimdVector3 m_aabbMin;
|
||||
@ -43,11 +43,11 @@ int m_triangleCount;
|
||||
|
||||
PersistentManifold* m_manifoldPtr;
|
||||
|
||||
BoxTriangleCallback(Dispatcher* dispatcher,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1);
|
||||
ConvexTriangleCallback(Dispatcher* dispatcher,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1);
|
||||
|
||||
void SetTimeStepAndCounters(float collisionMarginTriangle,const DispatcherInfo& dispatchInfo);
|
||||
|
||||
virtual ~BoxTriangleCallback();
|
||||
virtual ~ConvexTriangleCallback();
|
||||
|
||||
virtual void ProcessTriangle(SimdVector3* triangle, int partId, int triangleIndex);
|
||||
|
||||
@ -75,7 +75,7 @@ class ConvexConcaveCollisionAlgorithm : public CollisionAlgorithm
|
||||
|
||||
BroadphaseProxy m_concave;
|
||||
|
||||
BoxTriangleCallback m_boxTriangleCallback;
|
||||
ConvexTriangleCallback m_ConvexTriangleCallback;
|
||||
|
||||
|
||||
public:
|
||||
|
@ -15,39 +15,51 @@ subject to the following restrictions:
|
||||
|
||||
#include "TriangleIndexVertexArray.h"
|
||||
|
||||
TriangleIndexVertexArray::TriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride)
|
||||
:m_numTriangleIndices(numTriangleIndices),
|
||||
m_triangleIndexBase(triangleIndexBase),
|
||||
m_triangleIndexStride(triangleIndexStride),
|
||||
m_numVertices(numVertices),
|
||||
m_vertexBase(vertexBase),
|
||||
m_vertexStride(vertexStride)
|
||||
TriangleIndexVertexArray::TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride)
|
||||
{
|
||||
IndexedMesh mesh;
|
||||
|
||||
mesh.m_numTriangles = numTriangles;
|
||||
mesh.m_triangleIndexBase = triangleIndexBase;
|
||||
mesh.m_triangleIndexStride = triangleIndexStride;
|
||||
mesh.m_numVertices = numVertices;
|
||||
mesh.m_vertexBase = vertexBase;
|
||||
mesh.m_vertexStride = vertexStride;
|
||||
|
||||
AddIndexedMesh(mesh);
|
||||
|
||||
}
|
||||
|
||||
void TriangleIndexVertexArray::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart)
|
||||
{
|
||||
numverts = m_numVertices;
|
||||
(*vertexbase) = (unsigned char *)m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = m_vertexStride;
|
||||
ASSERT(subpart< getNumSubParts() );
|
||||
|
||||
IndexedMesh& mesh = m_indexedMeshes[subpart];
|
||||
|
||||
numfaces = m_numTriangleIndices;
|
||||
(*indexbase) = (unsigned char *)m_triangleIndexBase;
|
||||
indexstride = m_triangleIndexStride;
|
||||
numverts = mesh.m_numVertices;
|
||||
(*vertexbase) = (unsigned char *) mesh.m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = mesh.m_vertexStride;
|
||||
|
||||
numfaces = mesh.m_numTriangles;
|
||||
|
||||
(*indexbase) = (unsigned char *)mesh.m_triangleIndexBase;
|
||||
indexstride = mesh.m_triangleIndexStride;
|
||||
indicestype = PHY_INTEGER;
|
||||
}
|
||||
|
||||
void TriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const
|
||||
{
|
||||
numverts = m_numVertices;
|
||||
(*vertexbase) = (unsigned char *)m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = m_vertexStride;
|
||||
const IndexedMesh& mesh = m_indexedMeshes[subpart];
|
||||
|
||||
numfaces = m_numTriangleIndices;
|
||||
(*indexbase) = (unsigned char *)m_triangleIndexBase;
|
||||
indexstride = m_triangleIndexStride;
|
||||
numverts = mesh.m_numVertices;
|
||||
(*vertexbase) = (const unsigned char *)mesh.m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = mesh.m_vertexStride;
|
||||
|
||||
numfaces = mesh.m_numTriangles;
|
||||
(*indexbase) = (const unsigned char *)mesh.m_triangleIndexBase;
|
||||
indexstride = mesh.m_triangleIndexStride;
|
||||
indicestype = PHY_INTEGER;
|
||||
}
|
||||
|
||||
|
@ -14,22 +14,47 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
#include "StridingMeshInterface.h"
|
||||
#include <vector>
|
||||
|
||||
///IndexedMesh indexes into existing vertex and index arrays, in a similar way OpenGL glDrawElements
|
||||
///instead of the number of indices, we pass the number of triangles
|
||||
///todo: explain with pictures
|
||||
struct IndexedMesh
|
||||
{
|
||||
int m_numTriangles;
|
||||
int* m_triangleIndexBase;
|
||||
int m_triangleIndexStride;
|
||||
int m_numVertices;
|
||||
float* m_vertexBase;
|
||||
int m_vertexStride;
|
||||
};
|
||||
|
||||
///TriangleIndexVertexArray allows to use multiple meshes, by indexing into existing triangle/index arrays.
|
||||
///Additional meshes can be added using AddIndexedMesh
|
||||
///No duplcate is made of the vertex/index data, it only indexes into external vertex/index arrays.
|
||||
///So keep those arrays around during the lifetime of this TriangleIndexVertexArray.
|
||||
class TriangleIndexVertexArray : public StridingMeshInterface
|
||||
{
|
||||
std::vector<IndexedMesh> m_indexedMeshes;
|
||||
|
||||
int m_numTriangleIndices;
|
||||
int* m_triangleIndexBase;
|
||||
int m_triangleIndexStride;
|
||||
int m_numVertices;
|
||||
float* m_vertexBase;
|
||||
int m_vertexStride;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
TriangleIndexVertexArray()
|
||||
{
|
||||
}
|
||||
|
||||
//just to be backwards compatible
|
||||
TriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride);
|
||||
|
||||
void AddIndexedMesh(const IndexedMesh& mesh)
|
||||
{
|
||||
m_indexedMeshes.push_back(mesh);
|
||||
}
|
||||
|
||||
|
||||
virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
|
||||
|
||||
virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;
|
||||
@ -42,7 +67,9 @@ public:
|
||||
|
||||
/// getNumSubParts returns the number of seperate subparts
|
||||
/// each subpart has a continuous array of vertices and indices
|
||||
virtual int getNumSubParts() const { return 1;}
|
||||
virtual int getNumSubParts() const {
|
||||
return (int)m_indexedMeshes.size();
|
||||
}
|
||||
|
||||
virtual void preallocateVertices(int numverts){}
|
||||
virtual void preallocateIndices(int numindices){}
|
||||
|
Loading…
Reference in New Issue
Block a user