Sign in to follow this  

triangle vertices from mesh.intersect

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

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


hope that helps,
n.

Share this post


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

Share this post


Link to post
Share on other sites

This topic is 4307 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this