direct x mesh format question

Started by
3 comments, last by eschan01 16 years, 2 months ago
Hope someone can help with this. I'm trying to find all triangles in a mesh. I wanted to look at the index buffer content so I printed it out. The mesh is just loaded with the D3DXLoadMeshFromX function. HR(D3DXLoadMeshFromX(XFile.c_str(), D3DXMESH_SYSTEMMEM, d3dDevice, &adjBuffer, &mtrlBuffer, 0, &numMtrls, &meshSys)); WORD* k; unsigned nIndices = mesh->GetNumFaces() * 3; mesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&k); std::ofstream fout("triangles.txt", std::ios::out); for (unsigned i=0; i<nIndices; ) { //... print out indices fout << k << " " << k[i+1] << " " << k[i+2] << std::endl; i+=3; } fout.close(); mesh->UnlockIndexBuffer(); The indices are throwing me off. I get something that looks like this 2188 0 2187 0 2186 0 2188 0 2186 0 2185 0 2192 0 2191 0 2190 0 2192 0 2190 0 2189 0 2196 0 2195 0 2194 0 2196 0 2194 0 2193 0 ... ... and the pattern continues How can any triangle be indexed with v[0],v[2193], and v[0] having two vertices be the same? And, it's also very strange that all the triangles involves v[0]. I thought that each group of 3 indices in the index buffer would form a triangle, but this index buffer doesn't look right. Does anyone know why this is so? Any help is appreciated.
Advertisement
What does the mesh look like when you render it?

Also, try using a simpler mesh. For example, you can create a simple box with D3DXCreateBox() and see if the output makes sense (just to verify that your code is correct).
I'd definitely go with Gage64's suggestion of trying a simpler mesh to validate your own code.

Also, a triangle with two identical indices or vertices is a 'degenerate triangle' - they can be used for triangle strips where you actually want a gap between triangles...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Looks like the indices are 32-bit each, and not 16-bit each. Try a DWORD* for k, instead of WORD* (You can change how many bits the index buffer is by examining the mesh flags).
Sirob Yes.» - status: Work-O-Rama.
Quote:Original post by sirob
Looks like the indices are 32-bit each, and not 16-bit each. Try a DWORD* for k, instead of WORD* (You can change how many bits the index buffer is by examining the mesh flags).


Ah that might have something to do with it. D3DXComputeTangentFrameEx was complaining about the mesh not having enough index range so I cloned it to 32 bit. Didn't think about how it'd impact other things.

Thank you, everyone, for the help. I'll double check my code.

Edit: yep that was the problem. After matching up the size of the indices, they're being read correctly now. Thank you!

[Edited by - eschan01 on February 19, 2008 4:06:41 PM]

This topic is closed to new replies.

Advertisement