00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00041 #include "../include/IPSA/SoCollisionShapeTriMesh.h"
00042
00043 #include "../include/IPSA/TriangleExtractor.h"
00044 #include "../include/IPSA/VertexStorage.h"
00045
00046 SO_KIT_SOURCE(SoCollisionShapeTriMesh);
00047
00050 void SoCollisionShapeTriMesh::initClass()
00051 {
00052 SO_KIT_INIT_CLASS(SoCollisionShapeTriMesh, SoCollisionShape, "CollisionShape");
00053 }
00054
00055
00062 SoCollisionShapeTriMesh::SoCollisionShapeTriMesh(const SbString& nodeName )
00063 : SoCollisionShape(nodeName)
00064 {
00065 SO_KIT_CONSTRUCTOR(SoCollisionShapeTriMesh);
00066 isBuiltIn = TRUE;
00067
00068 SO_KIT_ADD_FIELD(ivModel, (NULL));
00069
00070 SO_KIT_CHANGE_ENTRY_TYPE(visualisation,SoNode,SoNode);
00071 SO_KIT_CHANGE_NULL_BY_DEFAULT(visualisation, TRUE);
00072
00073 SO_KIT_INIT_INSTANCE();
00074
00075 updateOdePropertiesTrigger.appendConnection(&ivModel);
00076 }
00077
00078
00082 SoCollisionShape* SoCollisionShapeTriMesh::copy(SbBool copyConnections) const
00083 {
00084
00085
00086 SoCollisionShapeTriMesh* newSoCollisionShape = dynamic_cast<SoCollisionShapeTriMesh*> (SoCollisionShape::copy(copyConnections));
00087 newSoCollisionShape->setUpConnections(TRUE, TRUE);
00088 return newSoCollisionShape;
00089 }
00090
00091
00097 void SoCollisionShapeTriMesh::updateVisualisationAndOdeProperties()
00098 {
00099
00101 }
00102
00103
00111 dGeomID SoCollisionShapeTriMesh::cGeom(const SbMatrix& mm)
00112 {
00113 assert(space != NULL);
00114
00115 printf("creating TriMesh Geom from ivModel, pass 1\n");
00116 SoNode* model = this->ivModel.getValue();
00117 assert(NULL != model && "SoCollisionShapeTriMesh::cGeom() -> no ivModel set\n");
00118
00119 TriangleExtractor* te = new TriangleExtractor( model );
00120 te->execute();
00121 VertexStorage<odeVertexType> *vertices = te->getResult();
00122
00123 dTriMeshDataID triMeshData = dGeomTriMeshDataCreate();
00124
00125 #ifdef dSINGLE
00126
00127
00128
00129
00130
00131 dGeomTriMeshDataBuildSingle( triMeshData,
00132 (dReal*)vertices->vertices, sizeof(odeVertexType), vertices->MAX_VERTEX_COUNT,
00133 (int*)vertices->indices, vertices->MAX_INDEX_COUNT, 3 * sizeof(int) );
00134 #else
00135 dGeomTriMeshDataBuildDouble( triMeshData,
00136 (dReal*)vertices->vertices, sizeof(odeVertexType), vertices->MAX_VERTEX_COUNT,
00137 (int*)vertices->indices, vertices->MAX_INDEX_COUNT, 3 * sizeof(int) );
00138 #endif
00139
00140 dGeomTriMeshDataPreprocess( triMeshData );
00141
00142 dGeomID geom = dCreateTriMesh( space, triMeshData, 0, 0, 0);
00143
00144
00145
00146
00147
00148
00149 dMass triMeshMass;
00150 dMassSetTrimesh( &triMeshMass, 1.0, geom );
00151 printf("cGeom(Tri): COG before shift is [%f,%f,%f], Mass: %f\n",(double) triMeshMass.c[0],
00152 (double) triMeshMass.c[1],
00153 (double) triMeshMass.c[2],
00154 (double) triMeshMass.mass);
00155 SbVec3f lcog = SbVec3f((float)triMeshMass.c[0], (float)triMeshMass.c[1], (float)triMeshMass.c[2]);
00156 COG = lcog;
00157
00158 dGeomDestroy(geom);
00159
00160 printf("creating TriMesh Geom from ivModel, pass 2\n");
00161
00162 te = new TriangleExtractor( model );
00163 te->execute(-lcog);
00164 vertices = te->getResult();
00165
00166 #ifdef dSINGLE
00167 dGeomTriMeshDataBuildSingle( triMeshData,
00168 (dReal*)vertices->vertices, sizeof(odeVertexType), vertices->MAX_VERTEX_COUNT,
00169 (int*)vertices->indices, vertices->MAX_INDEX_COUNT, 3 * sizeof(int) );
00170 #else
00171 dGeomTriMeshDataBuildDouble( triMeshData,
00172 (dReal*)vertices->vertices, sizeof(odeVertexType), vertices->MAX_VERTEX_COUNT,
00173 (int*)vertices->indices, vertices->MAX_INDEX_COUNT, 3 * sizeof(int) );
00174 #endif
00175 dGeomTriMeshDataPreprocess( triMeshData );
00176 geom = dCreateTriMesh( space, triMeshData, 0, 0, 0);
00177
00178 return geom;
00179 }