+ 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

@@ -35,7 +35,6 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
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();
@@ -45,6 +44,19 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
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
///unlike that developers want to pass in double-precision meshes in single-precision Bullet build
///so disable this feature by default
///see patch http://code.google.com/p/bullet/issues/detail?id=213
#ifdef BT_USE_DOUBLE_PRECISION
switch (type)
{
case PHY_FLOAT:
#endif
{
float* graphicsbase;
switch (gfxindextype) switch (gfxindextype)
{ {
case PHY_INTEGER: case PHY_INTEGER:
@@ -52,11 +64,11 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
for (gfxindex=0;gfxindex<numtriangles;gfxindex++) for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{ {
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride); graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex); callback->internalProcessTriangleIndex(triangle,part,gfxindex);
} }
@@ -67,11 +79,11 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
for (gfxindex=0;gfxindex<numtriangles;gfxindex++) for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{ {
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride); graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex); callback->internalProcessTriangleIndex(triangle,part,gfxindex);
} }
@@ -80,6 +92,55 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
default: default:
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT)); 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); unLockReadOnlyVertexBase(part);
} }

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

@@ -33,10 +33,25 @@ ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
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 // The index type is set when adding an indexed mesh to the
// btTriangleIndexVertexArray, do not set it manually // btTriangleIndexVertexArray, do not set it manually
PHY_ScalarType m_indexType; PHY_ScalarType m_indexType;
int pad;
// 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
}
} }
; ;

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)