Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 07:44

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 29.09.2010, 18:43 
Offline

Joined: 11.09.2010, 17:03
Posts: 4
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.


Top
 Profile  
Reply with quote  
PostPosted: 29.09.2010, 21:03 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
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.


Top
 Profile  
Reply with quote  
PostPosted: 29.09.2010, 21:23 
Offline

Joined: 11.09.2010, 17:03
Posts: 4
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group