more fixes in Collada Physics conversion, related to convex meshes and uninitialized mass data.
This commit is contained in:
@@ -361,6 +361,8 @@ bool ColladaConverter::convert()
|
||||
btRigidBodyOutput output;
|
||||
output.m_colShape = colShape;
|
||||
output.m_compoundShape = compoundShape;
|
||||
output.m_mass = 1.f;
|
||||
output.m_isDynamics = true;
|
||||
|
||||
btRigidBodyInput rbInput;
|
||||
rbInput.m_rigidBodyRef2 = rigidBodyRef;
|
||||
@@ -436,6 +438,8 @@ bool ColladaConverter::convert()
|
||||
btRigidBodyOutput output;
|
||||
output.m_colShape = colShape;
|
||||
output.m_compoundShape = compoundShape;
|
||||
output.m_mass = 1.f;
|
||||
output.m_isDynamics = true;
|
||||
|
||||
btRigidBodyInput rbInput;
|
||||
rbInput.m_rigidBodyRef2 = rigidBodyRef;
|
||||
@@ -1035,8 +1039,12 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
||||
{
|
||||
const domMeshRef meshRef = geom->getMesh();
|
||||
|
||||
btTriangleMesh* trimesh = new btTriangleMesh();
|
||||
//it can be either triangle mesh, or we just pick the vertices/positions
|
||||
|
||||
if (meshRef->getTriangles_array().getCount())
|
||||
{
|
||||
|
||||
btTriangleMesh* trimesh = new btTriangleMesh();
|
||||
|
||||
for (unsigned int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
|
||||
{
|
||||
@@ -1142,6 +1150,54 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
||||
}
|
||||
|
||||
}
|
||||
} else
|
||||
{
|
||||
|
||||
btConvexHullShape* convexHull = new btConvexHullShape();
|
||||
int numAddedVerts = 0;
|
||||
|
||||
const domVerticesRef vertsRef = meshRef->getVertices();
|
||||
int numInputs = vertsRef->getInput_array().getCount();
|
||||
for (int i=0;i<numInputs;i++)
|
||||
{
|
||||
domInputLocalRef localRef = vertsRef->getInput_array()[i];
|
||||
daeString str = localRef->getSemantic();
|
||||
if ( !strcmp(str,"POSITION"))
|
||||
{
|
||||
const domURIFragmentType& frag = localRef->getSource();
|
||||
|
||||
daeElementConstRef constElem = frag.getElement();
|
||||
|
||||
const domSourceRef node = *(const domSourceRef*)&constElem;
|
||||
const domFloat_arrayRef flArray = node->getFloat_array();
|
||||
if (flArray)
|
||||
{
|
||||
const domListOfFloats& listFloats = flArray->getValue();
|
||||
int vertexStride = 3;//instead of hardcoded stride, should use the 'accessor'
|
||||
int vertIndex = 0;
|
||||
for (vertIndex = 0;vertIndex < listFloats.getCount();vertIndex+=vertexStride)
|
||||
{
|
||||
btVector3 verts[3];
|
||||
domFloat fl0 = listFloats.get(vertIndex);
|
||||
domFloat fl1 = listFloats.get(vertIndex+1);
|
||||
domFloat fl2 = listFloats.get(vertIndex+2);
|
||||
convexHull->addPoint(btPoint3(fl0,fl1,fl2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//convexHull->addPoint();
|
||||
if (numAddedVerts > 0)
|
||||
{
|
||||
rbOutput.m_colShape = convexHull;
|
||||
} else
|
||||
{
|
||||
delete convexHull;
|
||||
printf("no vertices found for convex hull\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1191,7 +1247,7 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
||||
{
|
||||
//ReadGeometry( );
|
||||
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
||||
if (!strcmp(lib->getName(),urlref2))
|
||||
if (!strcmp(lib->getId(),urlref2))
|
||||
{
|
||||
//found convex_hull geometry
|
||||
domMesh *meshElement = lib->getMesh();//linkedGeom->getMesh();
|
||||
|
||||
Reference in New Issue
Block a user