Jump to content
  • Advertisement
Sign in to follow this  

triangle vertices from mesh.intersect

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

using c# //Is it possible to extract the triangle vertices from mesh.intersect? if (yes) { how?; }

Share this post

Link to post
Share on other sites

you need a structure to represent a vertex. something like:

public struct PositionNormalTexVertex
public Vector3 Position;
public Vector3 Normal;
public float Tu0, Tv0;
public static readonly VertexFormats FVF = VertexFormats.Position |

but you'll need to change it if your vertex declaration is different.

then lock the buffers and extract your info. i'll assume you've already created your ray and stuff:

//shoot ray
IntersectInformation intInf;
bool yup = m_mesh.Intersect(vPickRayOrig, vPickRayDir, out intInf);

PositionNormalTexVertex[] arr;
arr = new PositionNormalTexVertex[3];
if (yup)
//get streams to the buffers
VertexBuffer pVB;
IndexBuffer pIB;
pVB = m_mesh.VertexBuffer;
pIB = m_mesh.IndexBuffer;
GraphicsStream gsIB = pIB.Lock(0, 0, LockFlags.ReadOnly);
GraphicsStream gsVB = pVB.Lock(0, 0, LockFlags.ReadOnly);

//get pointers to the data
PositionNormalTexVertex* vbArray = (PositionNormalTexVertex*)gsVB.InternalDataPointer;
ushort* ibArray = (ushort*)gsIB.InternalDataPointer;

//get triangle indices
ushort i1, i2, i3;
i1 = ibArray[intInf.FaceIndex * 3 + 1];
i2 = ibArray[intInf.FaceIndex * 3 + 2];
i3 = ibArray[intInf.FaceIndex * 3 + 0];

//get triangle vertices
arr[0] = vbArray[i1];
arr[1] = vbArray[i2];
arr[2] = vbArray[i3];

//finished with the buffers

hope that helps,

Share this post

Link to post
Share on other sites

I had thought I'd need to reference the vertexBuffer and indexBuffer but had no idea about a structure to represent the vertices.

I'm new to C# so I'll have to study this a bit, but I do think my answer is in there.


yes, the answer is in there, but it's "unsafe". Is there anyway to do it with safe code?

[Edited by - DwD on March 2, 2006 7:48:39 AM]

Share this post

Link to post
Share on other sites
yes it's unsafe. i don't really know what that means tho :)
i just declare the function unsafe:

public unsafe Vector3 PickMesh(Matrix view, Vector3 ray)

maybe thats bad, i don't know, but it works fine.

Share this post

Link to post
Share on other sites

I'm not sure what it means either. Guess I'll have to look it up. I had already declared the method unsafe, just see that it worked.

I'm concerned it may cause trouble with publishing and one click security.

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!