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;
|
btRigidBodyOutput output;
|
||||||
output.m_colShape = colShape;
|
output.m_colShape = colShape;
|
||||||
output.m_compoundShape = compoundShape;
|
output.m_compoundShape = compoundShape;
|
||||||
|
output.m_mass = 1.f;
|
||||||
|
output.m_isDynamics = true;
|
||||||
|
|
||||||
btRigidBodyInput rbInput;
|
btRigidBodyInput rbInput;
|
||||||
rbInput.m_rigidBodyRef2 = rigidBodyRef;
|
rbInput.m_rigidBodyRef2 = rigidBodyRef;
|
||||||
@@ -436,6 +438,8 @@ bool ColladaConverter::convert()
|
|||||||
btRigidBodyOutput output;
|
btRigidBodyOutput output;
|
||||||
output.m_colShape = colShape;
|
output.m_colShape = colShape;
|
||||||
output.m_compoundShape = compoundShape;
|
output.m_compoundShape = compoundShape;
|
||||||
|
output.m_mass = 1.f;
|
||||||
|
output.m_isDynamics = true;
|
||||||
|
|
||||||
btRigidBodyInput rbInput;
|
btRigidBodyInput rbInput;
|
||||||
rbInput.m_rigidBodyRef2 = rigidBodyRef;
|
rbInput.m_rigidBodyRef2 = rigidBodyRef;
|
||||||
@@ -1035,113 +1039,165 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
|||||||
{
|
{
|
||||||
const domMeshRef meshRef = geom->getMesh();
|
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())
|
||||||
for (unsigned int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
btTriangleMesh* trimesh = new btTriangleMesh();
|
||||||
domTrianglesRef triRef = meshRef->getTriangles_array()[tg];
|
|
||||||
const domPRef pRef = triRef->getP();
|
|
||||||
btIndexedMesh meshPart;
|
|
||||||
meshPart.m_triangleIndexStride=0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int vertexoffset = -1;
|
for (unsigned int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
|
||||||
domInputLocalOffsetRef indexOffsetRef;
|
|
||||||
|
|
||||||
|
|
||||||
for (unsigned int w=0;w<triRef->getInput_array().getCount();w++)
|
|
||||||
{
|
{
|
||||||
int offset = triRef->getInput_array()[w]->getOffset();
|
|
||||||
daeString str = triRef->getInput_array()[w]->getSemantic();
|
|
||||||
if (!strcmp(str,"VERTEX"))
|
domTrianglesRef triRef = meshRef->getTriangles_array()[tg];
|
||||||
|
const domPRef pRef = triRef->getP();
|
||||||
|
btIndexedMesh meshPart;
|
||||||
|
meshPart.m_triangleIndexStride=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int vertexoffset = -1;
|
||||||
|
domInputLocalOffsetRef indexOffsetRef;
|
||||||
|
|
||||||
|
|
||||||
|
for (unsigned int w=0;w<triRef->getInput_array().getCount();w++)
|
||||||
{
|
{
|
||||||
indexOffsetRef = triRef->getInput_array()[w];
|
int offset = triRef->getInput_array()[w]->getOffset();
|
||||||
vertexoffset = offset;
|
daeString str = triRef->getInput_array()[w]->getSemantic();
|
||||||
}
|
if (!strcmp(str,"VERTEX"))
|
||||||
if (offset > meshPart.m_triangleIndexStride)
|
|
||||||
{
|
|
||||||
meshPart.m_triangleIndexStride = offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
meshPart.m_triangleIndexStride++;
|
|
||||||
domListOfUInts indexArray =triRef->getP()->getValue();
|
|
||||||
|
|
||||||
//int* m_triangleIndexBase;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
meshPart.m_numTriangles = triRef->getCount();
|
|
||||||
|
|
||||||
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();
|
indexOffsetRef = triRef->getInput_array()[w];
|
||||||
|
vertexoffset = offset;
|
||||||
|
}
|
||||||
|
if (offset > meshPart.m_triangleIndexStride)
|
||||||
|
{
|
||||||
|
meshPart.m_triangleIndexStride = offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
meshPart.m_triangleIndexStride++;
|
||||||
|
domListOfUInts indexArray =triRef->getP()->getValue();
|
||||||
|
|
||||||
int k=vertexoffset;
|
//int* m_triangleIndexBase;
|
||||||
int t=0;
|
|
||||||
int vertexStride = 3;//instead of hardcoded stride, should use the 'accessor'
|
|
||||||
for (;t<meshPart.m_numTriangles;t++)
|
|
||||||
|
meshPart.m_numTriangles = triRef->getCount();
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
btVector3 verts[3];
|
const domListOfFloats& listFloats = flArray->getValue();
|
||||||
int index0;
|
|
||||||
for (int i=0;i<3;i++)
|
int k=vertexoffset;
|
||||||
|
int t=0;
|
||||||
|
int vertexStride = 3;//instead of hardcoded stride, should use the 'accessor'
|
||||||
|
for (;t<meshPart.m_numTriangles;t++)
|
||||||
{
|
{
|
||||||
index0 = indexArray.get(k)*vertexStride;
|
btVector3 verts[3];
|
||||||
domFloat fl0 = listFloats.get(index0);
|
int index0;
|
||||||
domFloat fl1 = listFloats.get(index0+1);
|
for (int i=0;i<3;i++)
|
||||||
domFloat fl2 = listFloats.get(index0+2);
|
{
|
||||||
k+=meshPart.m_triangleIndexStride;
|
index0 = indexArray.get(k)*vertexStride;
|
||||||
verts[i].setValue(fl0,fl1,fl2);
|
domFloat fl0 = listFloats.get(index0);
|
||||||
|
domFloat fl1 = listFloats.get(index0+1);
|
||||||
|
domFloat fl2 = listFloats.get(index0+2);
|
||||||
|
k+=meshPart.m_triangleIndexStride;
|
||||||
|
verts[i].setValue(fl0,fl1,fl2);
|
||||||
|
}
|
||||||
|
trimesh->addTriangle(verts[0],verts[1],verts[2]);
|
||||||
}
|
}
|
||||||
trimesh->addTriangle(verts[0],verts[1],verts[2]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//int m_triangleIndexStride;//calculate max offset
|
//int m_triangleIndexStride;//calculate max offset
|
||||||
//int m_numVertices;
|
//int m_numVertices;
|
||||||
//float* m_vertexBase;//getRawData on floatArray
|
//float* m_vertexBase;//getRawData on floatArray
|
||||||
//int m_vertexStride;//use the accessor for this
|
//int m_vertexStride;//use the accessor for this
|
||||||
|
|
||||||
//};
|
//};
|
||||||
//tindexArray->addIndexedMesh(meshPart);
|
//tindexArray->addIndexedMesh(meshPart);
|
||||||
if (rbOutput.m_isDynamics)
|
if (rbOutput.m_isDynamics)
|
||||||
|
{
|
||||||
|
printf("moving concave <mesh> not supported, transformed into convex\n");
|
||||||
|
rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("static concave triangle <mesh> added\n");
|
||||||
|
rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
|
||||||
|
//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
|
||||||
|
//rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
|
||||||
|
|
||||||
|
//btTriangleMeshShape
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
printf("moving concave <mesh> not supported, transformed into convex\n");
|
|
||||||
rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
|
btConvexHullShape* convexHull = new btConvexHullShape();
|
||||||
} else
|
int numAddedVerts = 0;
|
||||||
{
|
|
||||||
printf("static concave triangle <mesh> added\n");
|
const domVerticesRef vertsRef = meshRef->getVertices();
|
||||||
rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
|
int numInputs = vertsRef->getInput_array().getCount();
|
||||||
//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
|
for (int i=0;i<numInputs;i++)
|
||||||
//rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
|
{
|
||||||
|
domInputLocalRef localRef = vertsRef->getInput_array()[i];
|
||||||
//btTriangleMeshShape
|
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( );
|
//ReadGeometry( );
|
||||||
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
||||||
if (!strcmp(lib->getName(),urlref2))
|
if (!strcmp(lib->getId(),urlref2))
|
||||||
{
|
{
|
||||||
//found convex_hull geometry
|
//found convex_hull geometry
|
||||||
domMesh *meshElement = lib->getMesh();//linkedGeom->getMesh();
|
domMesh *meshElement = lib->getMesh();//linkedGeom->getMesh();
|
||||||
|
|||||||
Reference in New Issue
Block a user