made shape construction virtual, to allow destruction of memory of btCollisionShape
This commit is contained in:
@@ -93,6 +93,11 @@ int btRigidBodyColladaInfo::getUid()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int btRigidConstraintColladaInfo::getUid()
|
int btRigidConstraintColladaInfo::getUid()
|
||||||
{
|
{
|
||||||
if (m_typedConstraint->getUid()==-1)
|
if (m_typedConstraint->getUid()==-1)
|
||||||
@@ -2624,6 +2629,110 @@ char* ColladaConverter::fixFileName(const char* lpCmdLine)
|
|||||||
return m_cleaned_filename;
|
return m_cleaned_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btCollisionShape* ColladaConverter::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
|
||||||
|
{
|
||||||
|
btCollisionShape* planeShape = new btStaticPlaneShape(planeNormal,planeConstant);
|
||||||
|
m_allocatedCollisionShapes.push_back(planeShape);
|
||||||
|
|
||||||
|
return planeShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
btCollisionShape* ColladaConverter::createBoxShape(const btVector3& halfExtents)
|
||||||
|
{
|
||||||
|
btCollisionShape* shape = new btBoxShape(halfExtents);
|
||||||
|
m_allocatedCollisionShapes.push_back(shape);
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
btCollisionShape* ColladaConverter::createSphereShape(btScalar radius)
|
||||||
|
{
|
||||||
|
btCollisionShape* shape = new btSphereShape(radius);
|
||||||
|
m_allocatedCollisionShapes.push_back(shape);
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
btCompoundShape* ColladaConverter::createCompoundShape()
|
||||||
|
{
|
||||||
|
btCompoundShape* shape = new btCompoundShape();
|
||||||
|
m_allocatedCollisionShapes.push_back(shape);
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
btCollisionShape* ColladaConverter::createCylinderShapeY(btScalar radius,btScalar height)
|
||||||
|
{
|
||||||
|
btCollisionShape* shape = new btCylinderShape(btVector3(radius,height,radius));
|
||||||
|
m_allocatedCollisionShapes.push_back(shape);
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
btTriangleMesh* ColladaConverter::createTriangleMeshContainer()
|
||||||
|
{
|
||||||
|
btTriangleMesh* meshContainer = new btTriangleMesh(m_use32bitIndices,m_use4componentVertices);
|
||||||
|
return meshContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
btConvexHullShape* ColladaConverter::createConvexHullShape()
|
||||||
|
{
|
||||||
|
btConvexHullShape* shape = new btConvexHullShape();
|
||||||
|
m_allocatedCollisionShapes.push_back(shape);
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
btCollisionShape* ColladaConverter::createBvhTriangleMeshShape(btTriangleMesh* trimesh)
|
||||||
|
{
|
||||||
|
bool useQuantizedAabbCompression = true;
|
||||||
|
btCollisionShape* shape = new btBvhTriangleMeshShape(trimesh,useQuantizedAabbCompression);
|
||||||
|
m_allocatedCollisionShapes.push_back(shape);
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
btCollisionShape* ColladaConverter::createConvexTriangleMeshShape(btTriangleMesh* trimesh)
|
||||||
|
{
|
||||||
|
btCollisionShape* shape = new btConvexTriangleMeshShape(trimesh);
|
||||||
|
m_allocatedCollisionShapes.push_back(shape);
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ColladaConverter::getNumCollisionShapes() const
|
||||||
|
{
|
||||||
|
return m_allocatedCollisionShapes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
btCollisionShape* ColladaConverter::getCollisionShape(int shapeIndex)
|
||||||
|
{
|
||||||
|
return m_allocatedCollisionShapes[shapeIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ColladaConverter::deleteAllocatedCollisionShapes()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (int i=0;i<m_allocatedCollisionShapes.size();i++)
|
||||||
|
{
|
||||||
|
delete m_allocatedCollisionShapes[i];
|
||||||
|
}
|
||||||
|
m_allocatedCollisionShapes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColladaConverter::deleteShape(btCollisionShape* shape)
|
||||||
|
{
|
||||||
|
for (int i=0;i<m_allocatedCollisionShapes.size();i++)
|
||||||
|
{
|
||||||
|
if (m_allocatedCollisionShapes[i]==shape)
|
||||||
|
{
|
||||||
|
delete m_allocatedCollisionShapes[i];
|
||||||
|
m_allocatedCollisionShapes.swap( i,m_allocatedCollisionShapes.size()-1);
|
||||||
|
m_allocatedCollisionShapes.pop_back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBodyOutput& rbOutput)
|
void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBodyOutput& rbOutput)
|
||||||
{
|
{
|
||||||
@@ -2695,402 +2804,422 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
|||||||
{
|
{
|
||||||
domRigid_body::domTechnique_common::domShapeRef shapeRef = techniqueRef->getShape_array()[s];
|
domRigid_body::domTechnique_common::domShapeRef shapeRef = techniqueRef->getShape_array()[s];
|
||||||
|
|
||||||
if (shapeRef->getPlane())
|
rbOutput.m_colShape = 0;
|
||||||
|
//future shape instancing
|
||||||
|
//rbOutput.m_colShape = findShapeForShapeRef(&shapeRef)
|
||||||
|
|
||||||
|
|
||||||
|
if (rbOutput.m_colShape)
|
||||||
{
|
{
|
||||||
domPlaneRef planeRef = shapeRef->getPlane();
|
|
||||||
if (planeRef->getEquation())
|
} else
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (shapeRef->getPlane())
|
||||||
{
|
{
|
||||||
const domFloat4 planeEq = planeRef->getEquation()->getValue();
|
domPlaneRef planeRef = shapeRef->getPlane();
|
||||||
btVector3 planeNormal(planeEq.get(0),planeEq.get(1),planeEq.get(2));
|
if (planeRef->getEquation())
|
||||||
btScalar planeConstant = planeEq.get(3)*m_unitMeterScaling;
|
{
|
||||||
rbOutput.m_colShape = new btStaticPlaneShape(planeNormal,planeConstant);
|
const domFloat4 planeEq = planeRef->getEquation()->getValue();
|
||||||
|
btVector3 planeNormal(planeEq.get(0),planeEq.get(1),planeEq.get(2));
|
||||||
|
btScalar planeConstant = planeEq.get(3)*m_unitMeterScaling;
|
||||||
|
rbOutput.m_colShape = createPlaneShape(planeNormal,planeConstant);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
if (shapeRef->getBox())
|
||||||
|
|
||||||
if (shapeRef->getBox())
|
|
||||||
{
|
|
||||||
domBoxRef boxRef = shapeRef->getBox();
|
|
||||||
domBox::domHalf_extentsRef domHalfExtentsRef = boxRef->getHalf_extents();
|
|
||||||
domFloat3& halfExtents = domHalfExtentsRef->getValue();
|
|
||||||
float x = halfExtents.get(0)*m_unitMeterScaling;
|
|
||||||
float y = halfExtents.get(1)*m_unitMeterScaling;
|
|
||||||
float z = halfExtents.get(2)*m_unitMeterScaling;
|
|
||||||
rbOutput.m_colShape = new btBoxShape(btVector3(x,y,z));
|
|
||||||
}
|
|
||||||
if (shapeRef->getSphere())
|
|
||||||
{
|
|
||||||
domSphereRef sphereRef = shapeRef->getSphere();
|
|
||||||
domSphere::domRadiusRef radiusRef = sphereRef->getRadius();
|
|
||||||
domFloat radius = radiusRef->getValue()*m_unitMeterScaling;
|
|
||||||
rbOutput.m_colShape = new btSphereShape(radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shapeRef->getCylinder())
|
|
||||||
{
|
|
||||||
domCylinderRef cylinderRef = shapeRef->getCylinder();
|
|
||||||
domFloat height = cylinderRef->getHeight()->getValue()*m_unitMeterScaling;
|
|
||||||
domFloat2 radius2 = cylinderRef->getRadius()->getValue();
|
|
||||||
domFloat radius0 = radius2.get(0)*m_unitMeterScaling;
|
|
||||||
|
|
||||||
//Cylinder around the local Y axis
|
|
||||||
rbOutput.m_colShape = new btCylinderShape(btVector3(radius0,height,radius0));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shapeRef->getInstance_geometry())
|
|
||||||
{
|
|
||||||
const domInstance_geometryRef geomInstRef = shapeRef->getInstance_geometry();
|
|
||||||
daeElement* geomElem = geomInstRef->getUrl().getElement();
|
|
||||||
//elemRef->getTypeName();
|
|
||||||
domGeometry* geom = (domGeometry*) geomElem;
|
|
||||||
if (geom && geom->getMesh())
|
|
||||||
{
|
{
|
||||||
const domMeshRef meshRef = geom->getMesh();
|
domBoxRef boxRef = shapeRef->getBox();
|
||||||
|
domBox::domHalf_extentsRef domHalfExtentsRef = boxRef->getHalf_extents();
|
||||||
|
domFloat3& halfExtents = domHalfExtentsRef->getValue();
|
||||||
|
float x = halfExtents.get(0)*m_unitMeterScaling;
|
||||||
|
float y = halfExtents.get(1)*m_unitMeterScaling;
|
||||||
|
float z = halfExtents.get(2)*m_unitMeterScaling;
|
||||||
|
rbOutput.m_colShape = createBoxShape(btVector3(x,y,z));
|
||||||
|
}
|
||||||
|
if (shapeRef->getSphere())
|
||||||
|
{
|
||||||
|
domSphereRef sphereRef = shapeRef->getSphere();
|
||||||
|
domSphere::domRadiusRef radiusRef = sphereRef->getRadius();
|
||||||
|
domFloat radius = radiusRef->getValue()*m_unitMeterScaling;
|
||||||
|
rbOutput.m_colShape = createSphereShape(radius);
|
||||||
|
}
|
||||||
|
|
||||||
//it can be either triangle mesh, or we just pick the vertices/positions
|
if (shapeRef->getCylinder())
|
||||||
|
{
|
||||||
|
domCylinderRef cylinderRef = shapeRef->getCylinder();
|
||||||
|
domFloat height = cylinderRef->getHeight()->getValue()*m_unitMeterScaling;
|
||||||
|
domFloat2 radius2 = cylinderRef->getRadius()->getValue();
|
||||||
|
domFloat radius0 = radius2.get(0)*m_unitMeterScaling;
|
||||||
|
|
||||||
if (meshRef->getTriangles_array().getCount())
|
//Cylinder around the local Y axis
|
||||||
|
rbOutput.m_colShape = createCylinderShapeY(radius0,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shapeRef->getInstance_geometry())
|
||||||
|
{
|
||||||
|
const domInstance_geometryRef geomInstRef = shapeRef->getInstance_geometry();
|
||||||
|
daeElement* geomElem = geomInstRef->getUrl().getElement();
|
||||||
|
//elemRef->getTypeName();
|
||||||
|
domGeometry* geom = (domGeometry*) geomElem;
|
||||||
|
if (geom && geom->getMesh())
|
||||||
{
|
{
|
||||||
|
const domMeshRef meshRef = geom->getMesh();
|
||||||
|
|
||||||
btTriangleMesh* trimesh = new btTriangleMesh(m_use32bitIndices,m_use4componentVertices);
|
//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 = createTriangleMeshContainer();
|
||||||
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*m_unitMeterScaling,fl1*m_unitMeterScaling,fl2*m_unitMeterScaling);
|
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*m_unitMeterScaling,fl1*m_unitMeterScaling,fl2*m_unitMeterScaling);
|
||||||
|
}
|
||||||
|
trimesh->addTriangle(verts[0],verts[1],verts[2]);
|
||||||
}
|
}
|
||||||
trimesh->addTriangle(verts[0],verts[1],verts[2]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
|
||||||
bool useQuantizedAabbCompression = true;
|
|
||||||
rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh,useQuantizedAabbCompression);
|
|
||||||
//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
|
|
||||||
//rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
|
|
||||||
|
|
||||||
//btTriangleMeshShape
|
|
||||||
}
|
|
||||||
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
|
||||||
|
|
||||||
} 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];
|
printf("moving concave <mesh> not supported, transformed into convex\n");
|
||||||
daeString str = localRef->getSemantic();
|
rbOutput.m_colShape = createConvexTriangleMeshShape(trimesh);
|
||||||
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'
|
|
||||||
unsigned 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) * m_unitMeterScaling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//convexHull->addPoint();
|
|
||||||
if (numAddedVerts > 0)
|
|
||||||
{
|
|
||||||
rbOutput.m_colShape = convexHull;
|
|
||||||
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
delete convexHull;
|
printf("static concave triangle <mesh> added\n");
|
||||||
printf("no vertices found for convex hull\n");
|
|
||||||
|
rbOutput.m_colShape = createBvhTriangleMeshShape(trimesh);
|
||||||
|
|
||||||
|
//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
|
||||||
|
//rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
|
||||||
|
|
||||||
|
//btTriangleMeshShape
|
||||||
}
|
}
|
||||||
|
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (geom && geom->getConvex_mesh())
|
|
||||||
{
|
|
||||||
|
|
||||||
{
|
|
||||||
const domConvex_meshRef convexRef = geom->getConvex_mesh();
|
|
||||||
daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement();
|
|
||||||
if ( otherElemRef != NULL )
|
|
||||||
{
|
|
||||||
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
|
||||||
printf( "otherLinked\n");
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount());
|
|
||||||
printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount());
|
btConvexHullShape* convexHull = createConvexHullShape();
|
||||||
|
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'
|
||||||
|
unsigned 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) * m_unitMeterScaling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//convexHull->addPoint();
|
||||||
|
if (numAddedVerts > 0)
|
||||||
|
{
|
||||||
|
rbOutput.m_colShape = convexHull;
|
||||||
|
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
deleteShape( convexHull);
|
||||||
|
printf("no vertices found for convex hull\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (geom && geom->getConvex_mesh())
|
||||||
|
|
||||||
btConvexHullShape* convexHullShape = new btConvexHullShape(0,0);
|
|
||||||
|
|
||||||
//it is quite a trick to get to the vertices, using Collada.
|
|
||||||
//we are not there yet...
|
|
||||||
|
|
||||||
const domConvex_meshRef convexRef = geom->getConvex_mesh();
|
|
||||||
//daeString urlref = convexRef->getConvex_hull_of().getURI();
|
|
||||||
daeString urlref2 = convexRef->getConvex_hull_of().getOriginalURI();
|
|
||||||
if (urlref2)
|
|
||||||
{
|
{
|
||||||
daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement();
|
|
||||||
// if ( otherElemRef != NULL )
|
|
||||||
// domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
|
||||||
|
|
||||||
// Load all the geometry libraries
|
|
||||||
for ( unsigned int i = 0; i < m_dom->getLibrary_geometries_array().getCount(); i++)
|
|
||||||
{
|
{
|
||||||
domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i];
|
const domConvex_meshRef convexRef = geom->getConvex_mesh();
|
||||||
//int index = libgeom->findLastIndexOf(urlref2);
|
daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement();
|
||||||
//can't find it
|
if ( otherElemRef != NULL )
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++)
|
|
||||||
{
|
{
|
||||||
//ReadGeometry( );
|
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
||||||
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
printf( "otherLinked\n");
|
||||||
if (!strcmp(lib->getId(),urlref2+1)) // skip the # at the front of urlref2
|
} else
|
||||||
|
{
|
||||||
|
printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount());
|
||||||
|
printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
btConvexHullShape* convexHullShape = createConvexHullShape();
|
||||||
|
|
||||||
|
//it is quite a trick to get to the vertices, using Collada.
|
||||||
|
//we are not there yet...
|
||||||
|
|
||||||
|
const domConvex_meshRef convexRef = geom->getConvex_mesh();
|
||||||
|
//daeString urlref = convexRef->getConvex_hull_of().getURI();
|
||||||
|
daeString urlref2 = convexRef->getConvex_hull_of().getOriginalURI();
|
||||||
|
if (urlref2)
|
||||||
|
{
|
||||||
|
daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement();
|
||||||
|
// if ( otherElemRef != NULL )
|
||||||
|
// domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
||||||
|
|
||||||
|
// Load all the geometry libraries
|
||||||
|
for ( unsigned int i = 0; i < m_dom->getLibrary_geometries_array().getCount(); i++)
|
||||||
|
{
|
||||||
|
domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i];
|
||||||
|
//int index = libgeom->findLastIndexOf(urlref2);
|
||||||
|
//can't find it
|
||||||
|
|
||||||
|
for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++)
|
||||||
{
|
{
|
||||||
//found convex_hull geometry
|
//ReadGeometry( );
|
||||||
domMesh *meshElement = lib->getMesh();//linkedGeom->getMesh();
|
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
||||||
if (meshElement)
|
if (!strcmp(lib->getId(),urlref2+1)) // skip the # at the front of urlref2
|
||||||
{
|
{
|
||||||
const domVerticesRef vertsRef = meshElement->getVertices();
|
//found convex_hull geometry
|
||||||
int numInputs = vertsRef->getInput_array().getCount();
|
domMesh *meshElement = lib->getMesh();//linkedGeom->getMesh();
|
||||||
for (int i=0;i<numInputs;i++)
|
if (meshElement)
|
||||||
{
|
{
|
||||||
domInputLocalRef localRef = vertsRef->getInput_array()[i];
|
const domVerticesRef vertsRef = meshElement->getVertices();
|
||||||
daeString str = localRef->getSemantic();
|
int numInputs = vertsRef->getInput_array().getCount();
|
||||||
if ( !strcmp(str,"POSITION"))
|
for (int i=0;i<numInputs;i++)
|
||||||
{
|
{
|
||||||
const domURIFragmentType& frag = localRef->getSource();
|
domInputLocalRef localRef = vertsRef->getInput_array()[i];
|
||||||
|
daeString str = localRef->getSemantic();
|
||||||
daeElementConstRef constElem = frag.getElement();
|
if ( !strcmp(str,"POSITION"))
|
||||||
|
|
||||||
const domSourceRef node = *(const domSourceRef*)&constElem;
|
|
||||||
const domFloat_arrayRef flArray = node->getFloat_array();
|
|
||||||
if (flArray)
|
|
||||||
{
|
{
|
||||||
int numElem = flArray->getCount();
|
const domURIFragmentType& frag = localRef->getSource();
|
||||||
const domListOfFloats& listFloats = flArray->getValue();
|
|
||||||
|
|
||||||
for (int k=0;k+2<numElem;k+=3)
|
daeElementConstRef constElem = frag.getElement();
|
||||||
|
|
||||||
|
const domSourceRef node = *(const domSourceRef*)&constElem;
|
||||||
|
const domFloat_arrayRef flArray = node->getFloat_array();
|
||||||
|
if (flArray)
|
||||||
{
|
{
|
||||||
domFloat fl0 = listFloats.get(k);
|
int numElem = flArray->getCount();
|
||||||
domFloat fl1 = listFloats.get(k+1);
|
const domListOfFloats& listFloats = flArray->getValue();
|
||||||
domFloat fl2 = listFloats.get(k+2);
|
|
||||||
//printf("float %f %f %f\n",fl0,fl1,fl2);
|
for (int k=0;k+2<numElem;k+=3)
|
||||||
|
{
|
||||||
|
domFloat fl0 = listFloats.get(k);
|
||||||
|
domFloat fl1 = listFloats.get(k+1);
|
||||||
|
domFloat fl2 = listFloats.get(k+2);
|
||||||
|
//printf("float %f %f %f\n",fl0,fl1,fl2);
|
||||||
|
|
||||||
|
convexHullShape->addPoint(btPoint3(fl0,fl1,fl2) * m_unitMeterScaling);
|
||||||
|
}
|
||||||
|
|
||||||
convexHullShape->addPoint(btPoint3(fl0,fl1,fl2) * m_unitMeterScaling);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//no getConvex_hull_of but direct vertices
|
||||||
|
const domVerticesRef vertsRef = convexRef->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)
|
||||||
|
{
|
||||||
|
int numElem = flArray->getCount();
|
||||||
|
const domListOfFloats& listFloats = flArray->getValue();
|
||||||
|
|
||||||
|
for (int k=0;k+2<numElem;k+=3)
|
||||||
|
{
|
||||||
|
domFloat fl0 = listFloats.get(k);
|
||||||
|
domFloat fl1 = listFloats.get(k+1);
|
||||||
|
domFloat fl2 = listFloats.get(k+2);
|
||||||
|
//printf("float %f %f %f\n",fl0,fl1,fl2);
|
||||||
|
|
||||||
|
convexHullShape->addPoint(btPoint3(fl0,fl1,fl2)*m_unitMeterScaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//no getConvex_hull_of but direct vertices
|
if (convexHullShape->getNumVertices())
|
||||||
const domVerticesRef vertsRef = convexRef->getVertices();
|
|
||||||
int numInputs = vertsRef->getInput_array().getCount();
|
|
||||||
for (int i=0;i<numInputs;i++)
|
|
||||||
{
|
{
|
||||||
domInputLocalRef localRef = vertsRef->getInput_array()[i];
|
rbOutput.m_colShape = convexHullShape;
|
||||||
daeString str = localRef->getSemantic();
|
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||||
if ( !strcmp(str,"POSITION"))
|
printf("created convexHullShape with %i points\n",convexHullShape->getNumVertices());
|
||||||
{
|
} else
|
||||||
const domURIFragmentType& frag = localRef->getSource();
|
{
|
||||||
|
deleteShape( convexHullShape);
|
||||||
daeElementConstRef constElem = frag.getElement();
|
printf("failed to create convexHullShape\n");
|
||||||
|
|
||||||
const domSourceRef node = *(const domSourceRef*)&constElem;
|
|
||||||
const domFloat_arrayRef flArray = node->getFloat_array();
|
|
||||||
if (flArray)
|
|
||||||
{
|
|
||||||
int numElem = flArray->getCount();
|
|
||||||
const domListOfFloats& listFloats = flArray->getValue();
|
|
||||||
|
|
||||||
for (int k=0;k+2<numElem;k+=3)
|
|
||||||
{
|
|
||||||
domFloat fl0 = listFloats.get(k);
|
|
||||||
domFloat fl1 = listFloats.get(k+1);
|
|
||||||
domFloat fl2 = listFloats.get(k+2);
|
|
||||||
//printf("float %f %f %f\n",fl0,fl1,fl2);
|
|
||||||
|
|
||||||
convexHullShape->addPoint(btPoint3(fl0,fl1,fl2)*m_unitMeterScaling);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
||||||
|
|
||||||
|
printf("convexmesh\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convexHullShape->getNumVertices())
|
|
||||||
{
|
|
||||||
rbOutput.m_colShape = convexHullShape;
|
|
||||||
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
|
||||||
printf("created convexHullShape with %i points\n",convexHullShape->getNumVertices());
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
delete convexHullShape;
|
|
||||||
printf("failed to create convexHullShape\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
|
||||||
|
|
||||||
printf("convexmesh\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//if more then 1 shape, or a non-identity local shapetransform
|
//if more then 1 shape, or a non-identity local shapetransform
|
||||||
//use a compound
|
//use a compound
|
||||||
|
|
||||||
bool hasShapeLocalTransform = ((shapeRef->getRotate_array().getCount() > 0) ||
|
bool hasShapeLocalTransform = ((shapeRef->getRotate_array().getCount() > 0) ||
|
||||||
(shapeRef->getTranslate_array().getCount() > 0));
|
(shapeRef->getTranslate_array().getCount() > 0));
|
||||||
|
|
||||||
if (rbOutput.m_colShape)
|
if (rbOutput.m_colShape)
|
||||||
{
|
|
||||||
if ((techniqueRef->getShape_array().getCount()>1) ||
|
|
||||||
(hasShapeLocalTransform))
|
|
||||||
{
|
{
|
||||||
|
if ((techniqueRef->getShape_array().getCount()>1) ||
|
||||||
if (!rbOutput.m_compoundShape)
|
(hasShapeLocalTransform))
|
||||||
{
|
{
|
||||||
rbOutput.m_compoundShape = new btCompoundShape();
|
|
||||||
}
|
if (!rbOutput.m_compoundShape)
|
||||||
|
{
|
||||||
|
rbOutput.m_compoundShape = createCompoundShape();
|
||||||
|
}
|
||||||
|
|
||||||
btTransform localTransform;
|
btTransform localTransform;
|
||||||
localTransform.setIdentity();
|
localTransform.setIdentity();
|
||||||
if (hasShapeLocalTransform)
|
if (hasShapeLocalTransform)
|
||||||
{
|
{
|
||||||
localTransform = GetbtTransformFromCOLLADA_DOM(
|
localTransform = GetbtTransformFromCOLLADA_DOM(
|
||||||
emptyMatrixArray,
|
emptyMatrixArray,
|
||||||
shapeRef->getRotate_array(),
|
shapeRef->getRotate_array(),
|
||||||
shapeRef->getTranslate_array(),
|
shapeRef->getTranslate_array(),
|
||||||
m_unitMeterScaling
|
m_unitMeterScaling
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
rbOutput.m_compoundShape->addChildShape(localTransform,rbOutput.m_colShape);
|
rbOutput.m_compoundShape->addChildShape(localTransform,rbOutput.m_colShape);
|
||||||
rbOutput.m_colShape = 0;
|
rbOutput.m_colShape = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//for future shape instancing
|
||||||
|
//storeShapeRef(shapeRef,rbOutput.m_colShape);
|
||||||
|
|
||||||
|
|
||||||
}//for each shape
|
}//for each shape
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class btRigidConstraintColladaInfo
|
class btRigidConstraintColladaInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -77,11 +79,15 @@ public:
|
|||||||
class ColladaConverter
|
class ColladaConverter
|
||||||
{
|
{
|
||||||
char m_cleaned_filename[513];
|
char m_cleaned_filename[513];
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
btDynamicsWorld* m_dynamicsWorld;
|
btDynamicsWorld* m_dynamicsWorld;
|
||||||
|
|
||||||
|
btAlignedObjectArray<class btCollisionShape*> m_allocatedCollisionShapes;
|
||||||
|
|
||||||
|
|
||||||
btHashMap<btHashKeyPtr<btRigidBodyColladaInfo*>,btRigidBodyColladaInfo*> m_rbUserInfoHashMap;
|
btHashMap<btHashKeyPtr<btRigidBodyColladaInfo*>,btRigidBodyColladaInfo*> m_rbUserInfoHashMap;
|
||||||
btHashMap<btHashKeyPtr<btRigidConstraintColladaInfo*>,btRigidConstraintColladaInfo*> m_constraintUserInfoHashMap;
|
btHashMap<btHashKeyPtr<btRigidConstraintColladaInfo*>,btRigidConstraintColladaInfo*> m_constraintUserInfoHashMap;
|
||||||
|
|
||||||
@@ -213,6 +219,22 @@ public:
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant);
|
||||||
|
virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
|
||||||
|
virtual btCollisionShape* createSphereShape(btScalar radius);
|
||||||
|
virtual btCollisionShape* createCylinderShapeY(btScalar radius,btScalar height);
|
||||||
|
virtual class btTriangleMesh* createTriangleMeshContainer();
|
||||||
|
virtual btCollisionShape* createBvhTriangleMeshShape(btTriangleMesh* trimesh);
|
||||||
|
virtual btCollisionShape* createConvexTriangleMeshShape(btTriangleMesh* trimesh);
|
||||||
|
virtual class btConvexHullShape* createConvexHullShape();
|
||||||
|
virtual class btCompoundShape* createCompoundShape();
|
||||||
|
|
||||||
|
int getNumCollisionShapes() const;
|
||||||
|
btCollisionShape* getCollisionShape(int shapeIndex);
|
||||||
|
void deleteAllocatedCollisionShapes();
|
||||||
|
void deleteShape(btCollisionShape* shape);
|
||||||
|
|
||||||
|
|
||||||
char* getLastFileName();
|
char* getLastFileName();
|
||||||
|
|
||||||
char* fixFileName(const char* lpCmdLine);
|
char* fixFileName(const char* lpCmdLine);
|
||||||
|
|||||||
Reference in New Issue
Block a user