free memory for btShapeHulls, keep track of it in GL_ShapeDrawer.
move btShapeHull and btConvexHull into its own library in Extras/ConvexHull (it allocates memory using mem/delete and refactoring into using btAlignedAlloc/Free takes too much time) fix heightfield / btOptimizedBvh for quantization, so that raycast can use quantized aabb (clamp up for maxima and down for minima) work-in-progress (update projectfiles etc)
This commit is contained in:
@@ -182,20 +182,16 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
|
||||
}
|
||||
|
||||
|
||||
void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point) const
|
||||
void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point,int isMax) const
|
||||
{
|
||||
|
||||
|
||||
btVector3 clampedPoint(point);
|
||||
clampedPoint.setMax(m_localAabbMin);
|
||||
clampedPoint.setMin(m_localAabbMax);
|
||||
|
||||
btVector3 v = (clampedPoint );// * m_quantization;
|
||||
|
||||
// SMJ - Add 0.5 in the correct direction before doing the int conversion.
|
||||
out[0] = (int)(v.getX() + v.getX() / btFabs(v.getX())* btScalar(0.5) );
|
||||
out[1] = (int)(v.getY() + v.getY() / btFabs(v.getY())* btScalar(0.5) );
|
||||
out[2] = (int)(v.getZ() + v.getZ() / btFabs(v.getZ())* btScalar(0.5) );
|
||||
btVector3 v = (clampedPoint);// - m_bvhAabbMin) * m_bvhQuantization;
|
||||
out[0] = (unsigned short)(((unsigned short)v.getX() & 0xffffffe) | isMax);
|
||||
out[1] = (unsigned short)(((unsigned short)v.getY() & 0xffffffe) | isMax);
|
||||
out[2] = (unsigned short)(((unsigned short)v.getZ() & 0xffffffe) | isMax);
|
||||
|
||||
}
|
||||
|
||||
@@ -214,8 +210,8 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
|
||||
btVector3 localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
|
||||
btVector3 localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
|
||||
|
||||
quantizeWithClamp(quantizedAabbMin, localAabbMin);
|
||||
quantizeWithClamp(quantizedAabbMax, localAabbMax);
|
||||
quantizeWithClamp(quantizedAabbMin, localAabbMin,0);
|
||||
quantizeWithClamp(quantizedAabbMax, localAabbMax,1);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ protected:
|
||||
btVector3 m_localScaling;
|
||||
|
||||
virtual btScalar getHeightFieldValue(int x,int y) const;
|
||||
void quantizeWithClamp(int* out, const btVector3& point) const;
|
||||
void quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
|
||||
void getVertex(int x,int y,btVector3& vertex) const;
|
||||
|
||||
inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const int* aabbMin2,const int* aabbMax2) const
|
||||
|
||||
@@ -132,8 +132,8 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized
|
||||
aabbMin.setZ(aabbMin.z() - MIN_AABB_HALF_DIMENSION);
|
||||
}
|
||||
|
||||
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMin[0],aabbMin);
|
||||
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMax[0],aabbMax);
|
||||
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMin[0],aabbMin,0);
|
||||
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMax[0],aabbMax,1);
|
||||
|
||||
node.m_escapeIndexOrTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
|
||||
|
||||
@@ -221,8 +221,8 @@ void btOptimizedBvh::refitPartial(btStridingMeshInterface* meshInterface,const b
|
||||
unsigned short quantizedQueryAabbMin[3];
|
||||
unsigned short quantizedQueryAabbMax[3];
|
||||
|
||||
quantizeWithClamp(&quantizedQueryAabbMin[0],aabbMin);
|
||||
quantizeWithClamp(&quantizedQueryAabbMax[0],aabbMax);
|
||||
quantizeWithClamp(&quantizedQueryAabbMin[0],aabbMin,0);
|
||||
quantizeWithClamp(&quantizedQueryAabbMax[0],aabbMax,1);
|
||||
|
||||
int i;
|
||||
for (i=0;i<this->m_SubtreeHeaders.size();i++)
|
||||
@@ -328,8 +328,8 @@ void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int f
|
||||
aabbMin.setMin(triangleVerts[2]);
|
||||
aabbMax.setMax(triangleVerts[2]);
|
||||
|
||||
quantizeWithClamp(&curNode.m_quantizedAabbMin[0],aabbMin);
|
||||
quantizeWithClamp(&curNode.m_quantizedAabbMax[0],aabbMax);
|
||||
quantizeWithClamp(&curNode.m_quantizedAabbMin[0],aabbMin,0);
|
||||
quantizeWithClamp(&curNode.m_quantizedAabbMax[0],aabbMax,1);
|
||||
|
||||
} else
|
||||
{
|
||||
@@ -613,8 +613,8 @@ void btOptimizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallb
|
||||
///quantize query AABB
|
||||
unsigned short int quantizedQueryAabbMin[3];
|
||||
unsigned short int quantizedQueryAabbMax[3];
|
||||
quantizeWithClamp(quantizedQueryAabbMin,aabbMin);
|
||||
quantizeWithClamp(quantizedQueryAabbMax,aabbMax);
|
||||
quantizeWithClamp(quantizedQueryAabbMin,aabbMin,0);
|
||||
quantizeWithClamp(quantizedQueryAabbMax,aabbMax,1);
|
||||
|
||||
switch (m_traversalMode)
|
||||
{
|
||||
@@ -783,8 +783,8 @@ void btOptimizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
|
||||
|
||||
unsigned short int quantizedQueryAabbMin[3];
|
||||
unsigned short int quantizedQueryAabbMax[3];
|
||||
quantizeWithClamp(quantizedQueryAabbMin,rayAabbMin);
|
||||
quantizeWithClamp(quantizedQueryAabbMax,rayAabbMax);
|
||||
quantizeWithClamp(quantizedQueryAabbMin,rayAabbMin,0);
|
||||
quantizeWithClamp(quantizedQueryAabbMax,rayAabbMax,1);
|
||||
|
||||
while (curIndex < endNodeIndex)
|
||||
{
|
||||
@@ -833,11 +833,11 @@ void btOptimizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
|
||||
}
|
||||
#endif
|
||||
#ifdef RAYAABB2
|
||||
///disable this check: need to check division by zero (above) and fix the unQuantize method
|
||||
///careful with this check: need to check division by zero (above) and fix the unQuantize method
|
||||
///thanks Joerg/hiker for the reproduction case!
|
||||
///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
|
||||
|
||||
rayBoxOverlap = true;//btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
|
||||
rayBoxOverlap = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max);
|
||||
#else
|
||||
rayBoxOverlap = true;//btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal);
|
||||
#endif
|
||||
|
||||
@@ -191,7 +191,7 @@ protected:
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[0] ,aabbMin);
|
||||
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[0] ,aabbMin,0);
|
||||
} else
|
||||
{
|
||||
m_contiguousNodes[nodeIndex].m_aabbMinOrg = aabbMin;
|
||||
@@ -202,7 +202,7 @@ protected:
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[0],aabbMax);
|
||||
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[0],aabbMax,1);
|
||||
} else
|
||||
{
|
||||
m_contiguousNodes[nodeIndex].m_aabbMaxOrg = aabbMax;
|
||||
@@ -251,8 +251,8 @@ protected:
|
||||
{
|
||||
unsigned short int quantizedAabbMin[3];
|
||||
unsigned short int quantizedAabbMax[3];
|
||||
quantizeWithClamp(quantizedAabbMin,newAabbMin);
|
||||
quantizeWithClamp(quantizedAabbMax,newAabbMax);
|
||||
quantizeWithClamp(quantizedAabbMin,newAabbMin,0);
|
||||
quantizeWithClamp(quantizedAabbMax,newAabbMax,1);
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] > quantizedAabbMin[i])
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
void reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const;
|
||||
void reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||
|
||||
SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point) const
|
||||
SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point,int isMax) const
|
||||
{
|
||||
|
||||
btAssert(m_useQuantization);
|
||||
@@ -341,13 +341,11 @@ public:
|
||||
btVector3 clampedPoint(point);
|
||||
clampedPoint.setMax(m_bvhAabbMin);
|
||||
clampedPoint.setMin(m_bvhAabbMax);
|
||||
|
||||
btVector3 v = (clampedPoint - m_bvhAabbMin) * m_bvhQuantization;
|
||||
out[0] = (unsigned short)(v.getX()+0.5f);
|
||||
out[1] = (unsigned short)(v.getY()+0.5f);
|
||||
out[2] = (unsigned short)(v.getZ()+0.5f);
|
||||
out[0] = (unsigned short)(((unsigned short)v.getX() & 0xfffe) | isMax);
|
||||
out[1] = (unsigned short)(((unsigned short)v.getY() & 0xfffe) | isMax);
|
||||
out[2] = (unsigned short)(((unsigned short)v.getZ() & 0xfffe) | isMax);
|
||||
}
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 unQuantize(const unsigned short* vecIn) const
|
||||
{
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
btbtShapeHull implemented by John McCutchan.
|
||||
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2008 Erwin Coumans http://bulletphysics.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "btShapeHull.h"
|
||||
#include "LinearMath/btConvexHull.h"
|
||||
|
||||
#define NUM_UNITSPHERE_POINTS 42
|
||||
|
||||
static btVector3 btUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
|
||||
{
|
||||
btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
|
||||
btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
|
||||
btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
|
||||
btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
|
||||
btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
|
||||
btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
|
||||
btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
|
||||
btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
|
||||
btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
|
||||
btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
|
||||
btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
|
||||
btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
|
||||
btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
|
||||
btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
|
||||
btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
|
||||
btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
|
||||
btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
|
||||
btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
|
||||
btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
|
||||
btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
|
||||
btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
|
||||
btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
|
||||
btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
|
||||
btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
|
||||
btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
|
||||
btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
|
||||
btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
|
||||
btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
|
||||
btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
|
||||
btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
|
||||
btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
|
||||
btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
|
||||
btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
|
||||
btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
|
||||
btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
|
||||
btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
|
||||
btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
|
||||
btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
|
||||
btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
|
||||
btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
|
||||
btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
|
||||
btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
|
||||
};
|
||||
|
||||
btShapeHull::btShapeHull (const btConvexShape* shape)
|
||||
{
|
||||
m_shape = shape;
|
||||
m_vertices.clear ();
|
||||
m_indices = NULL;
|
||||
m_numIndices = 0;
|
||||
}
|
||||
|
||||
btShapeHull::~btShapeHull ()
|
||||
{
|
||||
if (m_indices)
|
||||
delete [] m_indices;
|
||||
m_vertices.clear ();
|
||||
}
|
||||
|
||||
bool
|
||||
btShapeHull::buildHull (btScalar margin)
|
||||
{
|
||||
int numSampleDirections = NUM_UNITSPHERE_POINTS;
|
||||
{
|
||||
int numPDA = m_shape->getNumPreferredPenetrationDirections();
|
||||
if (numPDA)
|
||||
{
|
||||
for (int i=0;i<numPDA;i++)
|
||||
{
|
||||
btVector3 norm;
|
||||
m_shape->getPreferredPenetrationDirection(i,norm);
|
||||
btUnitSpherePoints[numSampleDirections] = norm;
|
||||
numSampleDirections++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btVector3 supportPoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
|
||||
int i;
|
||||
for (i = 0; i < numSampleDirections; i++)
|
||||
{
|
||||
supportPoints[i] = m_shape->localGetSupportingVertex(btUnitSpherePoints[i]);
|
||||
}
|
||||
|
||||
HullDesc hd;
|
||||
hd.mFlags = QF_TRIANGLES;
|
||||
hd.mVcount = numSampleDirections;
|
||||
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
hd.mVertices = &supportPoints[0];
|
||||
hd.mVertexStride = sizeof(btVector3);
|
||||
#else
|
||||
hd.mVertices = &supportPoints[0];
|
||||
hd.mVertexStride = sizeof (btVector3);
|
||||
#endif
|
||||
|
||||
HullLibrary hl;
|
||||
HullResult hr;
|
||||
if (hl.CreateConvexHull (hd, hr) == QE_FAIL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_vertices.resize (hr.mNumOutputVertices);
|
||||
|
||||
|
||||
for (i = 0; i < hr.mNumOutputVertices; i++)
|
||||
{
|
||||
m_vertices[i] = hr.mOutputVertices[i];
|
||||
}
|
||||
m_numIndices = hr.mNumIndices;
|
||||
m_indices = new unsigned int [m_numIndices];
|
||||
for (i = 0; i < m_numIndices; i++)
|
||||
{
|
||||
m_indices[i] = hr.mIndices[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
btShapeHull::numTriangles () const
|
||||
{
|
||||
return m_numIndices / 3;
|
||||
}
|
||||
|
||||
int
|
||||
btShapeHull::numVertices () const
|
||||
{
|
||||
return m_vertices.size ();
|
||||
}
|
||||
|
||||
int
|
||||
btShapeHull::numIndices () const
|
||||
{
|
||||
return m_numIndices;
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
btShapeHull implemented by John McCutchan.
|
||||
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef _SHAPE_HULL_H
|
||||
#define _SHAPE_HULL_H
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "btConvexShape.h"
|
||||
|
||||
|
||||
///btShapeHull takes a btConvexShape, builds the convex hull using btConvexHull and provides triangle indices and vertices.
|
||||
class btShapeHull
|
||||
{
|
||||
public:
|
||||
btShapeHull (const btConvexShape* shape);
|
||||
~btShapeHull ();
|
||||
|
||||
bool buildHull (btScalar margin);
|
||||
|
||||
int numTriangles () const;
|
||||
int numVertices () const;
|
||||
int numIndices () const;
|
||||
|
||||
const btVector3* getVertexPointer() const
|
||||
{
|
||||
return &m_vertices[0];
|
||||
}
|
||||
const unsigned int* getIndexPointer() const
|
||||
{
|
||||
return m_indices;
|
||||
}
|
||||
|
||||
protected:
|
||||
btAlignedObjectArray<btVector3> m_vertices;
|
||||
unsigned int* m_indices;
|
||||
unsigned int m_numIndices;
|
||||
const btConvexShape* m_shape;
|
||||
};
|
||||
|
||||
#endif //_SHAPE_HULL_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,138 +0,0 @@
|
||||
|
||||
/*
|
||||
Stan Melax Convex Hull Computation
|
||||
Copyright (c) 2008 Stan Melax http://www.melax.com/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
///includes modifications/improvements by John Ratcliff, see BringOutYourDead below.
|
||||
|
||||
#ifndef CD_HULL_H
|
||||
#define CD_HULL_H
|
||||
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
class HullResult
|
||||
{
|
||||
public:
|
||||
HullResult(void)
|
||||
{
|
||||
mPolygons = true;
|
||||
mNumOutputVertices = 0;
|
||||
mOutputVertices = 0;
|
||||
mNumFaces = 0;
|
||||
mNumIndices = 0;
|
||||
mIndices = 0;
|
||||
}
|
||||
bool mPolygons; // true if indices represents polygons, false indices are triangles
|
||||
unsigned int mNumOutputVertices; // number of vertices in the output hull
|
||||
btVector3 *mOutputVertices; // array of vertices
|
||||
unsigned int mNumFaces; // the number of faces produced
|
||||
unsigned int mNumIndices; // the total number of indices
|
||||
unsigned int *mIndices; // pointer to indices.
|
||||
|
||||
// If triangles, then indices are array indexes into the vertex list.
|
||||
// If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc..
|
||||
};
|
||||
|
||||
enum HullFlag
|
||||
{
|
||||
QF_TRIANGLES = (1<<0), // report results as triangles, not polygons.
|
||||
QF_REVERSE_ORDER = (1<<1), // reverse order of the triangle indices.
|
||||
QF_DEFAULT = QF_TRIANGLES
|
||||
};
|
||||
|
||||
|
||||
class HullDesc
|
||||
{
|
||||
public:
|
||||
HullDesc(void)
|
||||
{
|
||||
mFlags = QF_DEFAULT;
|
||||
mVcount = 0;
|
||||
mVertices = 0;
|
||||
mVertexStride = sizeof(btVector3);
|
||||
mNormalEpsilon = 0.001f;
|
||||
mMaxVertices = 4096; // maximum number of points to be considered for a convex hull.
|
||||
mMaxFaces = 4096;
|
||||
};
|
||||
|
||||
HullDesc(HullFlag flag,
|
||||
unsigned int vcount,
|
||||
const btVector3 *vertices,
|
||||
unsigned int stride = sizeof(btVector3))
|
||||
{
|
||||
mFlags = flag;
|
||||
mVcount = vcount;
|
||||
mVertices = vertices;
|
||||
mVertexStride = stride;
|
||||
mNormalEpsilon = btScalar(0.001);
|
||||
mMaxVertices = 4096;
|
||||
}
|
||||
|
||||
bool HasHullFlag(HullFlag flag) const
|
||||
{
|
||||
if ( mFlags & flag ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetHullFlag(HullFlag flag)
|
||||
{
|
||||
mFlags|=flag;
|
||||
}
|
||||
|
||||
void ClearHullFlag(HullFlag flag)
|
||||
{
|
||||
mFlags&=~flag;
|
||||
}
|
||||
|
||||
unsigned int mFlags; // flags to use when generating the convex hull.
|
||||
unsigned int mVcount; // number of vertices in the input point cloud
|
||||
const btVector3 *mVertices; // the array of vertices.
|
||||
unsigned int mVertexStride; // the stride of each vertex, in bytes.
|
||||
btScalar mNormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on.
|
||||
unsigned int mMaxVertices; // maximum number of vertices to be considered for the hull!
|
||||
unsigned int mMaxFaces;
|
||||
};
|
||||
|
||||
enum HullError
|
||||
{
|
||||
QE_OK, // success!
|
||||
QE_FAIL // failed.
|
||||
};
|
||||
|
||||
class HullLibrary
|
||||
{
|
||||
public:
|
||||
|
||||
HullError CreateConvexHull(const HullDesc& desc, // describes the input request
|
||||
HullResult& result); // contains the resulst
|
||||
HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
|
||||
private:
|
||||
//BringOutYourDead (John Ratcliff): When you create a convex hull you hand it a large input set of vertices forming a 'point cloud'.
|
||||
//After the hull is generated it give you back a set of polygon faces which index the *original* point cloud.
|
||||
//The thing is, often times, there are many 'dead vertices' in the point cloud that are on longer referenced by the hull.
|
||||
//The routine 'BringOutYourDead' find only the referenced vertices, copies them to an new buffer, and re-indexes the hull so that it is a minimal representation.
|
||||
void BringOutYourDead(const btVector3* verts,unsigned int vcount, btVector3* overts,unsigned int &ocount,unsigned int* indices,unsigned indexcount);
|
||||
|
||||
bool CleanupVertices(unsigned int svcount,
|
||||
const btVector3* svertices,
|
||||
unsigned int stride,
|
||||
unsigned int &vcount, // output number of vertices
|
||||
btVector3* vertices, // location to store the results.
|
||||
btScalar normalepsilon,
|
||||
btVector3& scale);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user