Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Creating a Mesh using Vertex Data

This topic is 5416 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

Hey, I''ve been working on a terrain renderer based on height maps, I can get it to render the terrain if I create a vertex buffer and put all the triangles in it, but is there a way to put the triangles into a Mesh? I''m working in C# here with Managed DirectX, but normal DX advice also helps. I''ve looked at the mesh class and there are methods like "SetVertexBufferData" and "LockVertexBuffer" but i''ve tried setting the vertex buffer of the mesh to my vertex data, and when I tell the mesh to draw there is nothing on screen. Thanks, Chris

Share this post

Link to post
Share on other sites
Ah HA! figured it out, for anyone that wants to know:

// C# Managed DirectX Code:

// Create a new new mesh:

Mesh mesh = new Mesh(number_of_triangles,number_of_verticies,MeshFlags.Dynamic, VertexFormats.Position,device);

// Set the vertex data:


// set the indicies data!! VERY IMPORTANT


// Generate Normals:

Mesh tempMesh = mesh.Clone(mesh.Options.Value,mesh.VertexFormat | VertexFormats.Normal,device);


mesh = tempMesh;

Where I was going wrong was the indicies and not generating normal data. "verts" can be any object that contains an array of data, like an array of Vector3[]''s, indicies MUST be of type "short" or it won''t work.

Indicies connect verticies together, so if you make 10 triangles each made of 3 verticies you can just do:

short[] indices = new short[number_of_verticies];
for (short j=0; j < number_of_verticies; j++)
indices[j] = j;

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!