From 08464b19642551567cc2018b5302ed5e327b86be Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Tue, 18 Jul 2006 04:42:27 +0000 Subject: [PATCH] Added COLLADA-DOM import for concave triangle --- Demos/ColladaDemo/ColladaDemo.cpp | 104 ++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 18 deletions(-) diff --git a/Demos/ColladaDemo/ColladaDemo.cpp b/Demos/ColladaDemo/ColladaDemo.cpp index ce17d7a74..c2caabd1f 100644 --- a/Demos/ColladaDemo/ColladaDemo.cpp +++ b/Demos/ColladaDemo/ColladaDemo.cpp @@ -1043,6 +1043,21 @@ int main(int argc,char** argv) xsNCName bodyName = rigidbodyRef->getBody(); + domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common(); + if (techniqueRef) + { + if (techniqueRef->getMass()) + { + mass = techniqueRef->getMass()->getValue(); + } + if (techniqueRef->getDynamic()) + { + isDynamics = techniqueRef->getDynamic()->getValue(); + } + } + + printf("mass = %f, isDynamics %i\n",mass,isDynamics); + if (bodyName) { //try to find the rigid body @@ -1111,9 +1126,14 @@ int main(int argc,char** argv) { const domMeshRef meshRef = geom->getMesh(); TriangleIndexVertexArray* tindexArray = new TriangleIndexVertexArray(); + + TriangleMesh* trimesh = new TriangleMesh(); + for (int tg = 0;tggetTriangles_array().getCount();tg++) { + + domTrianglesRef triRef = meshRef->getTriangles_array()[tg]; const domPRef pRef = triRef->getP(); daeMemoryRef memRef = pRef->getValue().getRawData(); @@ -1122,17 +1142,27 @@ int main(int argc,char** argv) + int vertexoffset = -1; + domInputLocalOffsetRef indexOffsetRef; + for (int w=0;wgetInput_array().getCount();w++) { int offset = triRef->getInput_array()[w]->getOffset(); + daeString str = triRef->getInput_array()[w]->getSemantic(); + if (!strcmp(str,"VERTEX")) + { + 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 count = indexArray.getCount(); //int* m_triangleIndexBase; @@ -1140,6 +1170,49 @@ int main(int argc,char** argv) meshPart.m_numTriangles = triRef->getCount(); + const domVerticesRef vertsRef = meshRef->getVertices(); + int numInputs = vertsRef->getInput_array().getCount(); + for (int i=0;igetInput_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(); + + int numVerts = listFloats.getCount()/3; + int k=vertexoffset; + int t=0; + int vertexStride = 3;//instead of hardcoded stride, should use the 'accessor' + for (;tAddTriangle(verts[0],verts[1],verts[2]); + } + } + } + } + + @@ -1149,11 +1222,19 @@ int main(int argc,char** argv) //int m_vertexStride;//use the accessor for this //}; - tindexArray->AddIndexedMesh(meshPart); + //tindexArray->AddIndexedMesh(meshPart); + if (isDynamics) + { + printf("moving concave not supported, transformed into convex\n"); + colShape = new ConvexTriangleMeshShape(trimesh); + } else + { + printf("static concave triangle added\n"); + colShape = new TriangleMeshShape(trimesh); + } + } - - printf("(concave) mesh not supported yet\n"); } if (geom->getConvex_mesh()) @@ -1322,20 +1403,7 @@ int main(int argc,char** argv) } - domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common(); - if (techniqueRef) - { - if (techniqueRef->getMass()) - { - mass = techniqueRef->getMass()->getValue(); - } - if (techniqueRef->getDynamic()) - { - isDynamics = techniqueRef->getDynamic()->getValue(); - } - } - - printf("mass = %f, isDynamics %i\n",mass,isDynamics); + if (colShape) { CreatePhysicsObject(isDynamics,mass,startTransform,colShape);