So I'm using ID3DXMESH to store a .X file, I'm loading it into the application with D3DXLoadMeshHierarchyFromX. I'm trying to get the vertex and index buffer from the mesh but getting incorrect results. The vertex buffer is correct but the index buffer is not, at least I don't think so. To simplify things; I created a basic cube mesh .X file. I've been changing around the index values of the file and the model changes shape but the returned index buffer does not reflect what is stated in the file.
Retriving Indices from mesh buffer
This is how i lock the mesh and get the vertices , you might be able to work something out with the indices
Thanks for the response! I made some changes based on your code example. Unfortunately same results :(.
Ok so if anyone is interested in how this all worked out. I took the time to remove the duplicate vertices in the .X cube file so that there are now only 8 vertices, which is correct for an indexed cube. Vertex and index values are now listed below. The index buffer now returns different values, still not the ones listed in the file though. I took a look at the vertex buffer in the application and the vertices have been reordered, also for some reason GetNumVertices() returns 16 instead of eight. It's obvious that each of the 8 vertices has been duplicated in the buffer, I have no idea why. Anyway I matched the vertices in the vertex buffer to the vertices in the file. Then I matched the returned indices to those values, and the 12 faces in the index buffer are indeed correct and identical to the 12 faces in the .X file. So bottom line is that D3DXLoadHierarchyFromX() is doing some things to both the vertex and index buffers behind the scenes, but adding an additional 8 vertices certainly does not seem like an optimization. Oh well at least I know the indices are right now, I'm going to try to do a vertex cache mesh->OptimizeInPlace and see if that removes the duplicate vertices. If that doesn't work I guess I'll just add some code to remove the duplicate vertices.
Ok last bit of info. I thought the vertex buffer contained duplicate vertices. My .X file lists only 8 vertices but the application says 16 vertices. I wasn't bothering to look at the indexed normal list contained in the .X file. D3DXLoadHierarchyFromX is creating vertices with the same position, but with different normals, so they are not duplicates and everything seems to be working as intended. :)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.