Jump to content
  • Advertisement
Sign in to follow this  
mrWodoo

[mesh] Get indices

This topic is 2588 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

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 this post


Link to post
Share on other sites
Advertisement
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)

a quad list:
(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

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!