triangle vertices from mesh.intersect

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

Recommended Posts

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

Share on other sites
yes.

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 |               VertexFormats.Texture1;}

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 rayIntersectInformation 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      pIB.Unlock();      pVB.Unlock();}

hope that helps,
n.

Share on other sites
Thanks,

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.

[EDIT]

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 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 on other sites
heh,

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.

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• Forum Statistics

• Total Topics
631749
• Total Posts
3002054
×