Jump to content
  • Advertisement
Sign in to follow this  

[mesh] Get indices

This topic is 2895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My problem is: I think that I'm creating bad indices for dGeomTriMeshDataBuildSingle... this is how I do it
m_TrimeshData = dGeomTriMeshDataCreate();

int VertCount = m_BodyMesh->GetNumVertices();
int TrimCount = m_BodyMesh->GetNumFaces ();

D3DXVECTOR3 *VerBuffer;
WORD *IndxBuffer;

dVector3 *ODEVerticesBuffer;
int *ODEIndicesBuffer;

ODEVerticesBuffer = new dVector3[ VertCount ];
ODEIndicesBuffer = new int[ TrimCount * 3 ];

m_BodyMesh->LockVertexBuffer( 0, (void**) &VerBuffer );

for( int i = 0; i < VertCount; i++ )


m_BodyMesh->LockIndexBuffer (0, (void**)&IndxBuffer);
for( int i = 0; i < TrimCount; i++ )


dGeomTriMeshDataBuildSingle( m_TrimeshData,
3 * sizeof(float),
3*sizeof( dTriIndex ) );

//add ode body
m_ODEBody = dBodyCreate( cWorld.GetWorld() );
m_ODEGeom = dCreateTriMesh( cWorld.GetSpace(), m_TrimeshData, 0, 0, 0 );
dGeomTriMeshSetData( m_ODEGeom, m_TrimeshData );
dGeomSetData( m_ODEGeom, m_TrimeshData );
dBodySetData( m_ODEBody, m_TrimeshData );
dGeomSetBody( m_ODEGeom, m_ODEBody );
dMassSetTrimesh( &m_ODEMass, 2, m_ODEGeom );
dBodySetPosition( m_ODEBody, 0, 5, MaxSpeed );

Share this post

Link to post
Share on other sites
So what's your problem exactly? You have to at least say what the problem is, haha

Anyway, just a suggestion, I'm guessing your loading in a model from a file? what type of model is it? Some models such as the obj format assume arrays start at "1" while c++ starts arrays at "0". You can usually check the very first index loaded in from the model, and if its a "1", that means that the format assumes arrays start at "1", and you will have to subtract one from all the indicies.

Another idea is maybe the model you are loading in is not using strictly triangles, but polygons with more than 3 sides, such as quads or more. You will have to change the index buffer so that it is only doing triangles instead of polygons with more sides than 3.

a triangle list:

a quad list:

To change a polygon list to a triangle list is not difficult. all you have to do is create an initial triangle for the quad or polygon, and create an additional triangle for each extra vertex using the very first index of that quad or polygon, the last index of the previous triangle, and the next new index. So here is an example of how it would look:

a polygon:

polygon converted to triangles:

Hope that helps

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!