Public Group

# C#/DX Vertexbuffers, getting vertex information

This topic is 3684 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi ya, I'm trying to do collision detection for meshes against a terrain. I have a working example in C++ and it involves passing a pointer to a custom vertexformat into a vb->Lock() method and you get a list of vertex information, fine! I have searched everywhere and I can't find an example of how to do it in C#??? I have this, I'm guessing I'm close...
Quote:
 struct vertexformat { public Vector3 Pos; public Vector3 Normal; public Vector2 TexCoord; public vertexformat(Vector3 _Pos, Vector3 _Normal, float texx, float texy) { Pos = _Pos; Normal = _Normal; TexCoord.X = texx; TexCoord.Y = texy; } }
Quote:
 mesh = Mesh.FromFile(path, MeshFlags.Managed, device, out gStream, out materialarray); mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device); vb = mesh.VertexBuffer; ib = mesh.IndexBuffer; numVerts = mesh.NumberVertices; numInds = mesh.NumberFaces; vertexformat[] vf = new vertexformat[numVerts];
..and now I'm stuck? ? = vb.Lock(?,?,?); ?? Thanks, Andy

##### Share on other sites

Ugh, that's really been a while. I dug up an old sample (this one), which has this code:

CustomVertex.PositionNormalTextured[] meshVertices =     (CustomVertex.PositionNormalTextured[])scannerMesh.LockVertexBuffer(        typeof(CustomVertex.PositionNormalTextured),         LockFlags.ReadOnly,         scannerMesh.NumberVertices    );

As I recall, the Lock overload with the arrays somehow worked better for me than those messing with the GraphicsStream. Anyway, the parameters should be pretty straightforward, supplying the type of your vertex struct, a lockflags flag (the enum values should be selfdescribing) and the number of vertices you want to lock. This will subsequently return the data as an array of structs of the type and count you specified.

Hope this helps & don't forget to VertexBuffer.Unlock() [smile]

##### Share on other sites
Awesome, thanks!

I remember seeing this sample and did think it probably did it but I've downloaded installed/uninstalled sooo many versions of the DX SDK I just couldn't remember where it was or if in fact it was a managed example or not.

It would be good if M$stuck all the DX samples together in one big download instead of me having to download TBs worth of SDKs just to get the sample I was looking for. #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by hotpixelI remember seeing this sample and did think it probably did it but I've downloaded installed/uninstalled sooo many versions of the DX SDK I just couldn't remember where it was or if in fact it was a managed example or not.It would be good if M$ stuck all the DX samples together in one big download instead of me having to download TBs worth of SDKs just to get the sample I was looking for.

Actually the sample in all DX SDKs is in C++ only, so I ported this one over to C#/MDX and stuck it up on MDXInfo. I'm all for some good MS bashing when they really did something wrong, but this is one of the things that can't be really blamed on them... Well, perhaps they should have included my port in the sample browser [wink]

1. 1
2. 2
3. 3
4. 4
frob
13
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632170
• Total Posts
3004549

×