Jump to content
  • Advertisement
Sign in to follow this  
hotpixel

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.

If you intended to correct an error in the post then please contact us.

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; } }
...load mesh method....
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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 hotpixel
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.


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]

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.

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!