Hi,
MichelPaulissenIf you want to get data directly from mesh, you can use this code:
Code:
//Add Model Resource
H3DRes meshRes = h3dAddResource( H3DResTypes::SceneGraph, "models/SomeModel.scene.xml", 0 );
// Load Model
h3dutLoadResourcesFromDisk( _contentdir.c_str() );
//Add Model Node
H3DNode model = h3dAddNodes( H3DRootNode, meshRes );
//Sample function for getting mesh parameters
getModelParams(model);
...
void getModelParams(H3DNode model)
{
//This function will get parameters from the model. It assumes that there is only one mesh in a model
//Now you should get mesh handle from the model
H3DNode meshNode = h3dGetNodeChild(model, 0)//I haven't tested this - maybe the index should be 1
H3DRes geoResource = h3dGetNodeParamI(model, H3DModel::GeoResI)//get geometry resource, used by the model
unsigned int numVertices = h3dGetNodeParamI(meshNode, H3DMesh::VertREndI) - h3dGetNodeParamI(meshNode, H3DMesh::VertRStartI) + 1;//get mesh vertices count
unsigned int numTriangleIndices = h3dGetNodeParamI(meshNode, H3DMesh::BatchCountI);//get mesh triangle indices count
unsigned int vertRStart = h3dGetNodeParamI(meshNode, H3DMesh::VertRStartI);//get the first vertex of the mesh
int vertexOffset = vertRStart * 3;
int indexOffset = h3dGetNodeParamI(meshNode, H3DMesh::BatchStartI);
//In order to get vertex data:
float* vertexBase = (float*) h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertPosStream, true, false);//gets pointer to the vertex data
h3dUnmapResStream(geoResource);//closes vertex stream
if( vertexBase ) vertexBase += vertexOffset;
//Triangle indices may be stored in 16 bit and 32 bit format, so you have to check both variants:
unsigned int* TriangleBase32 = NULL;
unsigned short* TriangleBase16 = NULL;
if (h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndices16I))
{
unsigned short* tb = (unsigned short*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
TriangleBase16 = new unsigned short[ numTriangleIndices ];
memcpy(TriangleBase16, tb+indexOffset, sizeof(unsigned short)*numTriangleIndices);
h3dUnmapResStream(geoResource);
delete TriangleBase32;
}
else
{
unsigned int* tb = (unsigned int*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
TriangleBase32 = new unsigned int[numTriangleIndices];
memcpy(TriangleBase32, tb+indexOffset, sizeof(unsigned int)*numTriangleIndices);
h3dUnmapResStream(geoResource);
delete TriangleBase16;
}
//Now you have everything you need in order to build collision hulls.
}
You may want to check
Horde3D Bullet Physics Integration.