Jump to content
  • Advertisement
Sign in to follow this  
CsharpNewbie

[MDX] Easy way to find vertex information in a Mesh File

This topic is 4339 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 Everyone, I have a mesh that I am using for ground in a game, I also have a ball that I am using as the "hero". What would be the easiest way to fill an array of x,y,z values of the ground mesh to compare to that of the x,y,z value of the ball. Once I find the x,y,z values I'll be fine with computing collision detection etc, I just can't find a way to extract that vertex information. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Unfortunately, the Mesh or .X docs don't really say much about the vertex format. I believe that since .X is a templated format, it can be arbitrary. However, one thing that we can be sure of is that the position element will be first in the vertex. We can also get the total size of the vertex using Mesh.NumberBytesPerVertex().

Using this info, you can lock the mesh's vertex buffer (Mesh.LockVertexBuffer()) and retrieve the data from the graphics stream. You know that the first 12 bytes of each vertex (a float3) are the x,y,z vectors. Kind of like this (I don't know any MDX, so this is psuedo-code-ish):


GraphicsStream stream = Mesh.LockVertexBuffer( LockFlags.ReadOnly );
int vertexSize = Mesh.NumberBytesPerVertex;

for( int i = 0; i < Mesh.NumVertices; i++ )
{
stream.Seek( i * vertexSize, SeekOrigin.Begin );
Vector3 position = stream.Read();
}

Share this post


Link to post
Share on other sites
Thanks for the reply, I think im just going to use heightmaps for the levels and then meshes for bldgs etc, that way i already have all the vertext information at my fingertips. Know any good resources for reading heightmaps? :)

Share this post


Link to post
Share on other sites
Quote:
Original post by CsharpNewbie at my fingertips. Know any good resources for reading heightmaps? :)


These look to be decent:

1

2

3

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!