Horde3D http://horde3d.org/forums/ |
|
Getting vertex data from a SceneGraph, no clue http://horde3d.org/forums/viewtopic.php?f=2&t=1262 |
Page 1 of 1 |
Author: | MichelPaulissen [ 29.09.2010, 18:43 ] |
Post subject: | Getting vertex data from a SceneGraph, no clue |
Howdy folks, At school we're working on a project and we're using Horde3D as a graphics engine. I need vertex data from some of the props in the game to use as collision hulls. However, I can't figure out how to. Code: meshRes = h3dAddResource(H3DResTypes::SceneGraph, meshFilename.c_str(), 0); This is (obviously) how the SceneGraph is loaded. You guessed it, I have not the faintest clue where to go from here. Suggestions, code? Thanks in advance. |
Author: | Irdis [ 29.09.2010, 21:03 ] |
Post subject: | Re: Getting vertex data from a SceneGraph, no clue |
Hi, MichelPaulissen If 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. |
Author: | MichelPaulissen [ 29.09.2010, 21:23 ] |
Post subject: | Re: Getting vertex data from a SceneGraph, no clue |
Thanks alot, now I can do the actual important stuff. About your tip, yes, I know about the physics integration. However, the idea of the framework we developed is that graphics and physics are entirely seperate modules, so that either can be switched if needed (this also goes for audio, window/systems abstraction, etc.) I'll be sure to also post the project here once it's finished, which will probably be around next summer. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |