Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've a set of voxel data and I want to create a mesh out of it at run-time.

I've looked into MeshBuilder and MeshHelper but I haven't found anything useful or a good tutorial how to use them. Can anyone tell me how to create a mesh at run-time?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

I think this should answer your question: http://forums.create.msdn.com/forums/p/4751/24616.aspx

Basically you should just create a vertex and index buffer yourself (you can wrap them up in a nice class that implements IDrawable ofc).

Once you have a vertex and index buffer you can draw your model like in this MSDN article:

VertexBuffer  vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.None);

vertexBuffer.SetData<VertexPositionColor>(primitiveList);

IndexBuffer  lineListIndexBuffer = new IndexBuffer(
    GraphicsDevice,
    IndexElementSize.SixteenBits,
    sizeof(short) * lineListIndices.Length,
    BufferUsage.None);

lineListIndexBuffer.SetData<short>(lineListIndices);

GraphicsDevice.Indices = lineListIndexBuffer;
GraphicsDevice.SetVertexBuffer(vertexBuffer);
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, 8, 0, 7);
share|improve this answer
    
thanks! (at least 15 characters) –  Valdiralita Jul 24 '12 at 6:57

I have been working on 2D game 2y ago and had to draw shapes like thet. You could look what I have done Project - Squared

Take a look at GraphicsDrawer class under SquaredEngine.Graphics, it will allow you to draw some basic meshes, triangles, lines, quads, ellipses, etc.

You could easily make this to work in 3D env.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.