Sign in to follow this  
eschan01

direct x mesh format question

Recommended Posts

eschan01    122
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[i] << " " << 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.

Share this post


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

Share this post


Link to post
Share on other sites
jollyjeffers    1570
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

Share this post


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

Share this post


Link to post
Share on other sites
eschan01    122
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this