+ 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:
@@ -60,8 +60,8 @@ public:
|
||||
int m_minimumPointsPerturbationThreshold;
|
||||
|
||||
CreateFunc()
|
||||
: m_numPerturbationIterations(3),
|
||||
m_minimumPointsPerturbationThreshold(3)
|
||||
: m_numPerturbationIterations(1),
|
||||
m_minimumPointsPerturbationThreshold(1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,13 @@ btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int
|
||||
m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
|
||||
m_unscaledPoints.resize(numPoints);
|
||||
|
||||
unsigned char* pointsBaseAddress = (unsigned char*)points;
|
||||
unsigned char* pointsAddress = (unsigned char*)points;
|
||||
|
||||
for (int i=0;i<numPoints;i++)
|
||||
{
|
||||
btVector3* point = (btVector3*)(pointsBaseAddress + i*stride);
|
||||
m_unscaledPoints[i] = point[0];
|
||||
btScalar* point = (btScalar*)pointsAddress;
|
||||
m_unscaledPoints[i] = btVector3(point[0], point[1], point[2]);
|
||||
pointsAddress += stride;
|
||||
}
|
||||
|
||||
recalcLocalAabb();
|
||||
|
||||
@@ -23,66 +23,127 @@ btStridingMeshInterface::~btStridingMeshInterface()
|
||||
|
||||
void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
{
|
||||
(void)aabbMin;
|
||||
(void)aabbMax;
|
||||
int numtotalphysicsverts = 0;
|
||||
int part,graphicssubparts = getNumSubParts();
|
||||
const unsigned char * vertexbase;
|
||||
const unsigned char * indexbase;
|
||||
int indexstride;
|
||||
PHY_ScalarType type;
|
||||
PHY_ScalarType gfxindextype;
|
||||
int stride,numverts,numtriangles;
|
||||
int gfxindex;
|
||||
btVector3 triangle[3];
|
||||
btScalar* graphicsbase;
|
||||
(void)aabbMin;
|
||||
(void)aabbMax;
|
||||
int numtotalphysicsverts = 0;
|
||||
int part,graphicssubparts = getNumSubParts();
|
||||
const unsigned char * vertexbase;
|
||||
const unsigned char * indexbase;
|
||||
int indexstride;
|
||||
PHY_ScalarType type;
|
||||
PHY_ScalarType gfxindextype;
|
||||
int stride,numverts,numtriangles;
|
||||
int gfxindex;
|
||||
btVector3 triangle[3];
|
||||
|
||||
btVector3 meshScaling = getScaling();
|
||||
btVector3 meshScaling = getScaling();
|
||||
|
||||
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
|
||||
for (part=0;part<graphicssubparts ;part++)
|
||||
{
|
||||
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
|
||||
numtotalphysicsverts+=numtriangles*3; //upper bound
|
||||
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
|
||||
for (part=0;part<graphicssubparts ;part++)
|
||||
{
|
||||
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
|
||||
numtotalphysicsverts+=numtriangles*3; //upper bound
|
||||
|
||||
switch (gfxindextype)
|
||||
{
|
||||
case PHY_INTEGER:
|
||||
{
|
||||
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));
|
||||
}
|
||||
///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
|
||||
|
||||
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)
|
||||
|
||||
@@ -44,11 +44,9 @@ void btTriangleIndexVertexArray::getLockedVertexIndexBase(unsigned char **vertex
|
||||
|
||||
numverts = mesh.m_numVertices;
|
||||
(*vertexbase) = (unsigned char *) mesh.m_vertexBase;
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
type = PHY_DOUBLE;
|
||||
#else
|
||||
type = PHY_FLOAT;
|
||||
#endif
|
||||
|
||||
type = mesh.m_vertexType;
|
||||
|
||||
vertexStride = mesh.m_vertexStride;
|
||||
|
||||
numfaces = mesh.m_numTriangles;
|
||||
@@ -64,11 +62,9 @@ void btTriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned
|
||||
|
||||
numverts = mesh.m_numVertices;
|
||||
(*vertexbase) = (const unsigned char *)mesh.m_vertexBase;
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
type = PHY_DOUBLE;
|
||||
#else
|
||||
type = PHY_FLOAT;
|
||||
#endif
|
||||
|
||||
type = mesh.m_vertexType;
|
||||
|
||||
vertexStride = mesh.m_vertexStride;
|
||||
|
||||
numfaces = mesh.m_numTriangles;
|
||||
|
||||
@@ -25,18 +25,33 @@ subject to the following restrictions:
|
||||
///Instead of the number of indices, we pass the number of triangles.
|
||||
ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
|
||||
{
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
int m_numTriangles;
|
||||
const unsigned char * m_triangleIndexBase;
|
||||
int m_triangleIndexStride;
|
||||
int m_numVertices;
|
||||
const unsigned char * m_vertexBase;
|
||||
int m_vertexStride;
|
||||
// The index type is set when adding an indexed mesh to the
|
||||
// btTriangleIndexVertexArray, do not set it manually
|
||||
PHY_ScalarType m_indexType;
|
||||
int pad;
|
||||
int m_numTriangles;
|
||||
const unsigned char * m_triangleIndexBase;
|
||||
int m_triangleIndexStride;
|
||||
int m_numVertices;
|
||||
const unsigned char * m_vertexBase;
|
||||
int m_vertexStride;
|
||||
|
||||
// The index type is set when adding an indexed mesh to the
|
||||
// btTriangleIndexVertexArray, do not set it manually
|
||||
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
|
||||
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[m_indexedMeshes.size()-1].m_indexType = indexType;
|
||||
m_indexedMeshes.push_back(mesh);
|
||||
m_indexedMeshes[m_indexedMeshes.size()-1].m_indexType = indexType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ struct btContactSolverInfo : public btContactSolverInfoData
|
||||
m_splitImpulsePenetrationThreshold = -0.02f;
|
||||
m_linearSlop = btScalar(0.0);
|
||||
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
|
||||
}
|
||||
};
|
||||
|
||||
@@ -490,7 +490,7 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
||||
|
||||
|
||||
///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;
|
||||
if (rb0)
|
||||
|
||||
Reference in New Issue
Block a user