Archived

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

JohanL

Working with a mesh Vertex and Index Buffer...

Recommended Posts

I''m trying to work with a mesh file as the terrain for my engine but need to use the vertices from the mesh vertex buffer in some way... What I''m trying to do (as have many other according to the threads) is to point and click on my terrain and hightlight (actually move my character to) that tile/face/position on the map. So the questions is, is there an easy way to withdraw the specific verticies that makes up a face (which I can get from Mesh.Intersect(...)). Regards Johan

Share this post


Link to post
Share on other sites
Don't bother, I've done it...


  
public void RenderFace(int face, Device dev) {
int[] vi = new int[3];
byte[] buffer = new byte[6];
VertexBuffer vb = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 3, dev, Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0,0); // Lock the buffer (which will return our structs)


CustomVertex.PositionNormalTextured[] meshVB = (CustomVertex.PositionNormalTextured[])mesh.LockVertexBuffer(typeof(CustomVertex.PositionNormalTextured),LockFlags.ReadOnly,mesh.NumberVertices);
Direct3D.GraphicsStream meshIB = mesh.LockIndexBuffer(LockFlags.ReadOnly);

meshIB.Position = face*6;
meshIB.Read(buffer,0,6);

vi[0] = buffer[1]*256+buffer[0];
vi[1] = buffer[3]*256+buffer[2];
vi[2] = buffer[5]*256+buffer[4];

verts[0] = meshVB[vi[0]];
verts[1] = meshVB[vi[1]];
verts[2] = meshVB[vi[2]];

mesh.UnlockIndexBuffer();
mesh.UnlockVertexBuffer();

dev.RenderState.CullMode = Cull.None;
dev.RenderState.FillMode = FillMode.Solid;
dev.DrawUserPrimitives(PrimitiveType.TriangleList,1,verts);
}


Johan

[edited by - JohanL on January 21, 2003 7:43:29 AM]

Share this post


Link to post
Share on other sites