+ disable perturbation for btConvexPlaneCollisionAlgorithm, it introduces artifacts (additional points cause spheres/cylinders and other curved objects to move)

+ applied patch to mix double/single precision meshes independent from double/single precision Bullet build
Thanks to Ole for the patch, http://code.google.com/p/bullet/issues/detail?id=213
+ re-enable warming starting in constraint solver, it was disabled by accident
+ fix btConvexHullShape constructor, so accept vertices with non-16-byte striding
Thanks Shawn Baird for report and fix: http://code.google.com/p/bullet/issues/detail?id=204
This commit is contained in:
erwin.coumans
2009-05-06 19:13:11 +00:00
parent 77fac5e2ae
commit f3c3d2f156
7 changed files with 160 additions and 87 deletions

View File

@@ -60,8 +60,8 @@ public:
int m_minimumPointsPerturbationThreshold; int m_minimumPointsPerturbationThreshold;
CreateFunc() CreateFunc()
: m_numPerturbationIterations(3), : m_numPerturbationIterations(1),
m_minimumPointsPerturbationThreshold(3) m_minimumPointsPerturbationThreshold(1)
{ {
} }

View File

@@ -24,12 +24,13 @@ btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int
m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE; m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
m_unscaledPoints.resize(numPoints); m_unscaledPoints.resize(numPoints);
unsigned char* pointsBaseAddress = (unsigned char*)points; unsigned char* pointsAddress = (unsigned char*)points;
for (int i=0;i<numPoints;i++) for (int i=0;i<numPoints;i++)
{ {
btVector3* point = (btVector3*)(pointsBaseAddress + i*stride); btScalar* point = (btScalar*)pointsAddress;
m_unscaledPoints[i] = point[0]; m_unscaledPoints[i] = btVector3(point[0], point[1], point[2]);
pointsAddress += stride;
} }
recalcLocalAabb(); recalcLocalAabb();

View File

@@ -23,66 +23,127 @@ btStridingMeshInterface::~btStridingMeshInterface()
void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
{ {
(void)aabbMin; (void)aabbMin;
(void)aabbMax; (void)aabbMax;
int numtotalphysicsverts = 0; int numtotalphysicsverts = 0;
int part,graphicssubparts = getNumSubParts(); int part,graphicssubparts = getNumSubParts();
const unsigned char * vertexbase; const unsigned char * vertexbase;
const unsigned char * indexbase; const unsigned char * indexbase;
int indexstride; int indexstride;
PHY_ScalarType type; PHY_ScalarType type;
PHY_ScalarType gfxindextype; PHY_ScalarType gfxindextype;
int stride,numverts,numtriangles; int stride,numverts,numtriangles;
int gfxindex; int gfxindex;
btVector3 triangle[3]; btVector3 triangle[3];
btScalar* graphicsbase;
btVector3 meshScaling = getScaling(); btVector3 meshScaling = getScaling();
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype ///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
for (part=0;part<graphicssubparts ;part++) for (part=0;part<graphicssubparts ;part++)
{ {
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part); getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
numtotalphysicsverts+=numtriangles*3; //upper bound numtotalphysicsverts+=numtriangles*3; //upper bound
switch (gfxindextype) ///unlike that developers want to pass in double-precision meshes in single-precision Bullet build
{ ///so disable this feature by default
case PHY_INTEGER: ///see patch http://code.google.com/p/bullet/issues/detail?id=213
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
case PHY_SHORT:
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
default:
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
}
unLockReadOnlyVertexBase(part); #ifdef BT_USE_DOUBLE_PRECISION
} switch (type)
{
case PHY_FLOAT:
#endif
{
float* graphicsbase;
switch (gfxindextype)
{
case PHY_INTEGER:
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
case PHY_SHORT:
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
default:
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
}
break;
}
#ifdef BT_USE_DOUBLE_PRECISION
case PHY_DOUBLE:
{
double* graphicsbase;
switch (gfxindextype)
{
case PHY_INTEGER:
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
case PHY_SHORT:
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
default:
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
}
break;
}
default:
btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE));
}
#endif //BT_USE_DOUBLE_PRECISION
unLockReadOnlyVertexBase(part);
}
} }
void btStridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax) void btStridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax)

View File

@@ -44,11 +44,9 @@ void btTriangleIndexVertexArray::getLockedVertexIndexBase(unsigned char **vertex
numverts = mesh.m_numVertices; numverts = mesh.m_numVertices;
(*vertexbase) = (unsigned char *) mesh.m_vertexBase; (*vertexbase) = (unsigned char *) mesh.m_vertexBase;
#ifdef BT_USE_DOUBLE_PRECISION
type = PHY_DOUBLE; type = mesh.m_vertexType;
#else
type = PHY_FLOAT;
#endif
vertexStride = mesh.m_vertexStride; vertexStride = mesh.m_vertexStride;
numfaces = mesh.m_numTriangles; numfaces = mesh.m_numTriangles;
@@ -64,11 +62,9 @@ void btTriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned
numverts = mesh.m_numVertices; numverts = mesh.m_numVertices;
(*vertexbase) = (const unsigned char *)mesh.m_vertexBase; (*vertexbase) = (const unsigned char *)mesh.m_vertexBase;
#ifdef BT_USE_DOUBLE_PRECISION
type = PHY_DOUBLE; type = mesh.m_vertexType;
#else
type = PHY_FLOAT;
#endif
vertexStride = mesh.m_vertexStride; vertexStride = mesh.m_vertexStride;
numfaces = mesh.m_numTriangles; numfaces = mesh.m_numTriangles;

View File

@@ -25,18 +25,33 @@ subject to the following restrictions:
///Instead of the number of indices, we pass the number of triangles. ///Instead of the number of indices, we pass the number of triangles.
ATTRIBUTE_ALIGNED16( struct) btIndexedMesh ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
{ {
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
int m_numTriangles; int m_numTriangles;
const unsigned char * m_triangleIndexBase; const unsigned char * m_triangleIndexBase;
int m_triangleIndexStride; int m_triangleIndexStride;
int m_numVertices; int m_numVertices;
const unsigned char * m_vertexBase; const unsigned char * m_vertexBase;
int m_vertexStride; int m_vertexStride;
// The index type is set when adding an indexed mesh to the
// btTriangleIndexVertexArray, do not set it manually // The index type is set when adding an indexed mesh to the
PHY_ScalarType m_indexType; // btTriangleIndexVertexArray, do not set it manually
int pad; PHY_ScalarType m_indexType;
// The vertex type has a default type similar to Bullet's precision mode (float or double)
// but can be set manually if you for example run Bullet with double precision but have
// mesh data in single precision..
PHY_ScalarType m_vertexType;
btIndexedMesh()
{
#ifdef BT_USE_DOUBLE_PRECISION
m_vertexType = PHY_DOUBLE;
#else // BT_USE_DOUBLE_PRECISION
m_vertexType = PHY_FLOAT;
#endif // BT_USE_DOUBLE_PRECISION
}
} }
; ;
@@ -69,10 +84,10 @@ public:
//just to be backwards compatible //just to be backwards compatible
btTriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride); btTriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride);
void addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER) void addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER)
{ {
m_indexedMeshes.push_back(mesh); m_indexedMeshes.push_back(mesh);
m_indexedMeshes[m_indexedMeshes.size()-1].m_indexType = indexType; m_indexedMeshes[m_indexedMeshes.size()-1].m_indexType = indexType;
} }

View File

@@ -77,7 +77,7 @@ struct btContactSolverInfo : public btContactSolverInfoData
m_splitImpulsePenetrationThreshold = -0.02f; m_splitImpulsePenetrationThreshold = -0.02f;
m_linearSlop = btScalar(0.0); m_linearSlop = btScalar(0.0);
m_warmstartingFactor=btScalar(0.85); m_warmstartingFactor=btScalar(0.85);
m_solverMode = SOLVER_USE_WARMSTARTING | SOLVER_SIMD ;//SOLVER_RANDMIZE_ORDER m_solverMode = SOLVER_USE_WARMSTARTING | SOLVER_SIMD;// | SOLVER_RANDMIZE_ORDER;
m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution
} }
}; };

View File

@@ -490,7 +490,7 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
///warm starting (or zero if disabled) ///warm starting (or zero if disabled)
if (0)//infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING) if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
{ {
solverConstraint.m_appliedImpulse = cp.m_appliedImpulse * infoGlobal.m_warmstartingFactor; solverConstraint.m_appliedImpulse = cp.m_appliedImpulse * infoGlobal.m_warmstartingFactor;
if (rb0) if (rb0)