add support for premade aabb in btStridingMeshInterface/btBvhTriangleMeshShape,
Thanks Roy Eltham, http://code.google.com/p/bullet/issues/detail?id=70
This commit is contained in:
@@ -30,7 +30,14 @@ m_ownsBvh(false)
|
|||||||
#ifndef DISABLE_BVH
|
#ifndef DISABLE_BVH
|
||||||
|
|
||||||
btVector3 bvhAabbMin,bvhAabbMax;
|
btVector3 bvhAabbMin,bvhAabbMax;
|
||||||
|
if(meshInterface->hasPremadeAabb())
|
||||||
|
{
|
||||||
|
meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);
|
meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);
|
||||||
|
}
|
||||||
|
|
||||||
if (buildBvh)
|
if (buildBvh)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ class btStridingMeshInterface
|
|||||||
virtual void preallocateVertices(int numverts)=0;
|
virtual void preallocateVertices(int numverts)=0;
|
||||||
virtual void preallocateIndices(int numindices)=0;
|
virtual void preallocateIndices(int numindices)=0;
|
||||||
|
|
||||||
|
virtual bool hasPremadeAabb() const { return false; }
|
||||||
|
virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const {}
|
||||||
|
virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const {}
|
||||||
|
|
||||||
const btVector3& getScaling() const {
|
const btVector3& getScaling() const {
|
||||||
return m_scaling;
|
return m_scaling;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,3 +76,21 @@ void btTriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned
|
|||||||
indicestype = mesh.m_indexType;
|
indicestype = mesh.m_indexType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool btTriangleIndexVertexArray::hasPremadeAabb() const
|
||||||
|
{
|
||||||
|
return (m_hasAabb == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax )
|
||||||
|
{
|
||||||
|
m_aabbMin = aabbMin;
|
||||||
|
m_aabbMax = aabbMax;
|
||||||
|
m_hasAabb = 1; // this is intentionally an int see notes in header
|
||||||
|
}
|
||||||
|
|
||||||
|
void btTriangleIndexVertexArray::getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
|
||||||
|
{
|
||||||
|
*aabbMin = m_aabbMin;
|
||||||
|
*aabbMax = m_aabbMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,14 +51,16 @@ ATTRIBUTE_ALIGNED16( class) btTriangleIndexVertexArray : public btStridingMeshIn
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
IndexedMeshArray m_indexedMeshes;
|
IndexedMeshArray m_indexedMeshes;
|
||||||
int m_pad[3];
|
int m_pad[2];
|
||||||
|
int m_hasAabb; // using int instead of bool to maintain alignment
|
||||||
|
btVector3 m_aabbMin;
|
||||||
|
btVector3 m_aabbMax;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
btTriangleIndexVertexArray()
|
btTriangleIndexVertexArray() : m_hasAabb(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +105,10 @@ public:
|
|||||||
virtual void preallocateVertices(int numverts){(void) numverts;}
|
virtual void preallocateVertices(int numverts){(void) numverts;}
|
||||||
virtual void preallocateIndices(int numindices){(void) numindices;}
|
virtual void preallocateIndices(int numindices){(void) numindices;}
|
||||||
|
|
||||||
|
virtual bool hasPremadeAabb() const;
|
||||||
|
virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax );
|
||||||
|
virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const;
|
||||||
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,14 @@ subject to the following restrictions:
|
|||||||
btTriangleMeshShape::btTriangleMeshShape(btStridingMeshInterface* meshInterface)
|
btTriangleMeshShape::btTriangleMeshShape(btStridingMeshInterface* meshInterface)
|
||||||
: m_meshInterface(meshInterface)
|
: m_meshInterface(meshInterface)
|
||||||
{
|
{
|
||||||
|
if(meshInterface->hasPremadeAabb())
|
||||||
|
{
|
||||||
|
meshInterface->getPremadeAabb(&m_localAabbMin, &m_localAabbMax);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
recalcLocalAabb();
|
recalcLocalAabb();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user