BGE soft body: change welding option to disable welding check by default: speeds up shape conversion. This is fine if the object has no duplicate vertices. Otherwise, bullet will be extremely slow and you can either set some welding or remove duplicates in the mesh. Welding is now displayed in linear scale: 0.0 -> 0.01, no need to use logarithmic scale ;-). Fix a bug with Bullet by which vertex array for soft body must have 3xfloat stride.

This commit is contained in:
Benoit Bolsee
2009-04-27 22:21:42 +00:00
parent fa826774a3
commit d4f8b416e9
6 changed files with 43 additions and 47 deletions

View File

@@ -1368,9 +1368,9 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
}
}
m_vertexArray.resize(tot_bt_verts);
m_vertexArray.resize(tot_bt_verts*3);
btVector3 *bt= &m_vertexArray[0];
btScalar *bt= &m_vertexArray[0];
for (int p2=0; p2<numpolys; p2++)
{
@@ -1388,8 +1388,9 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
const float* vtx = v->getXYZ();
vert_tag_array[orig_index]= false;
bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]);
bt++;
*bt++ = vtx[0];
*bt++ = vtx[1];
*bt++ = vtx[2];
}
}
}
@@ -1421,11 +1422,11 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
}
}
m_vertexArray.resize(tot_bt_verts);
m_vertexArray.resize(tot_bt_verts*3);
m_polygonIndexArray.resize(tot_bt_tris);
m_triFaceArray.resize(tot_bt_tris*3);
btVector3 *bt= &m_vertexArray[0];
btScalar *bt= &m_vertexArray[0];
int *poly_index_pt= &m_polygonIndexArray[0];
int *tri_pt= &m_triFaceArray[0];
@@ -1459,20 +1460,23 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
if (vert_tag_array[i1]==true) { /* *** v1 *** */
vert_tag_array[i1]= false;
vtx = v1->getXYZ();
bt->setX(vtx[0]); bt->setY( vtx[1]); bt->setZ(vtx[2]);
bt++;
*bt++ = vtx[0];
*bt++ = vtx[1];
*bt++ = vtx[2];
}
if (vert_tag_array[i2]==true) { /* *** v2 *** */
vert_tag_array[i2]= false;
vtx = v2->getXYZ();
bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]);
bt++;
*bt++ = vtx[0];
*bt++ = vtx[1];
*bt++ = vtx[2];
}
if (vert_tag_array[i3]==true) { /* *** v3 *** */
vert_tag_array[i3]= false;
vtx = v3->getXYZ();
bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]);
bt++;
*bt++ = vtx[0];
*bt++ = vtx[1];
*bt++ = vtx[2];
}
if (poly->VertexCount()==4)
@@ -1493,8 +1497,9 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
if (vert_tag_array[i4]==true) { /* *** v4 *** */
vert_tag_array[i4]= false;
vtx = v4->getXYZ();
bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]);
bt++;
*bt++ = vtx[0];
*bt++ = vtx[1];
*bt++ = vtx[2];
}
}
}
@@ -1577,7 +1582,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
break;
case PHY_SHAPE_POLYTOPE:
collisionShape = new btConvexHullShape(&m_vertexArray[0].getX(), m_vertexArray.size());
collisionShape = new btConvexHullShape(&m_vertexArray[0], m_vertexArray.size()/3, 3*sizeof(btScalar));
break;
case PHY_SHAPE_MESH:
@@ -1594,9 +1599,9 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
m_polygonIndexArray.size(),
&m_triFaceArray[0],
3*sizeof(int),
m_vertexArray.size(),
(btScalar*) &m_vertexArray[0].x(),
sizeof(btVector3)
m_vertexArray.size()/3,
&m_vertexArray[0],
3*sizeof(btScalar)
);
btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(indexVertexArrays);
@@ -1619,12 +1624,13 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
bool removeDuplicateVertices=true;
// m_vertexArray not in multiple of 3 anymore, use m_triFaceArray
for(int i=0; i<m_triFaceArray.size(); i+=3) {
collisionMeshData->addTriangle(
m_vertexArray[m_triFaceArray[i]],
m_vertexArray[m_triFaceArray[i+1]],
m_vertexArray[m_triFaceArray[i+2]],
removeDuplicateVertices
);
btScalar *bt = &m_vertexArray[3*m_triFaceArray[i]];
btVector3 v1(bt[0], bt[1], bt[2]);
bt = &m_vertexArray[3*m_triFaceArray[i+1]];
btVector3 v2(bt[0], bt[1], bt[2]);
bt = &m_vertexArray[3*m_triFaceArray[i+2]];
btVector3 v3(bt[0], bt[1], bt[2]);
collisionMeshData->addTriangle(v1, v2, v3, removeDuplicateVertices);
}
indexVertexArrays = collisionMeshData;
@@ -1634,9 +1640,9 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
m_polygonIndexArray.size(),
&m_triFaceArray[0],
3*sizeof(int),
m_vertexArray.size(),
(btScalar*) &m_vertexArray[0].x(),
sizeof(btVector3));
m_vertexArray.size()/3,
&m_vertexArray[0],
3*sizeof(btScalar));
}
// this shape will be shared and not deleted until shapeInfo is deleted