# [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.

## Recommended Posts

Hello.
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++ ) { ODEVerticesBuffer[2]=VerBuffer.z; ODEVerticesBuffer[1]=VerBuffer.y; ODEVerticesBuffer[0]=VerBuffer.x; ODEVerticesBuffer[3]=0; } m_BodyMesh->UnlockVertexBuffer(); m_BodyMesh->LockIndexBuffer (0, (void**)&IndxBuffer); for( int i = 0; i < TrimCount; i++ ) { ODEIndicesBuffer[i*3]=IndxBuffer[i*3]; ODEIndicesBuffer[i*3+1]=IndxBuffer[i*3+1]; ODEIndicesBuffer[i*3+2]=IndxBuffer[i*3+2]; } m_BodyMesh->UnlockIndexBuffer(); dGeomTriMeshDataBuildSingle( m_TrimeshData, &ODEVerticesBuffer[0], 3 * sizeof(float), VertCount, &ODEIndicesBuffer[0], TrimCount*3, 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 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:
(0,1,2)
(0,2,3)

(0,1,2,3)
(4,5,6,7)

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:
(0,1,2,3,4)

polygon converted to triangles:
(0,1,2)
(0,2,3)
(0,3,4)

Hope that helps

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 10
• 9
• 11
• 15
• 21