Skip to main content
gamedev.net
🔒 Locked

Faces from Mesh.FromFile objects

Started by sune 0 replies 300+ views
Original Post
sune
sune
Hi, I´m using the Mesh class in my application, since it affords me some nice features at no cost :) However i need to do some calculations on the vertices and therefore I need to pull them out of the Mesh object. I use simple Lock functions on the objects Index- and Vertexbuffer and using a for-loop I run through the indexbuffer using the values to take out vertices of vertexbuffer (3 indices per triangle). This straightforward method works splendidly on the standard Mesh.Box, Mesh.Sphere etc. but when I try to use it on a Mesh.FromFile object it fails. The vertices seem fine, but the indices are wrong. Anyone know why this is ? When I do my reading I assume that the only primitive in the buffer is Triangles, could that be my problem ?
remigius
remigius
Well, it should work, since DirectX only uses triangles for polygon rendering. My guess is that the vertex format in the file mesh is different from the one in the Mesh.Box and Mesh.Sphere ones, since it is most likely also textured, whereas the latter are not. This will make the lock method read in wrong values for all but the first vertex, causing strange results (I would know ;).

You can easily verify the vertex format on the Mesh by looking at its VertexFormat (or VertexDeclatation) property. If this is indeed the problem, you can use the VertexDeclaraton to create your own struct for reading in the data from the file mesh into an array, or you could use it as a guideline to read the vertex features from a GraphicsStream. I haven't found a way to do this for all arbitrary vertex formats, but it's easy to do for one single format.

If the vertex formats are the same though, you may want to check the bit size of the indices you're reading, since these can come in both 16 and 32 bit. Picking the wrong format might be another potential cause of the problem.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.