How do I query accelerate the triangles from a StaticMesh?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

How do I query accelerate the triangles from a StaticMesh?

Post by Spankenstein »

I usually use:

Code: Select all

Space.BroadPhase.QueryAccelerator.GetEntries
to obtain all the entities that intersect a bounding sphere.

How can I do the same thing but with the triangles of a StaticMesh without have to test against all the triangles in the mesh (i.e. using a built in "accelerator")?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How do I query accelerate the triangles from a StaticMes

Post by Norbo »

This would work:

Code: Select all

if(staticMesh.Mesh.Tree.GetOverlaps(boundingShape, overlapsList))
{
      //Do stuff
}
StaticMeshes are special amongst meshes in that they have a world space hierarchy which can be queried directly. Other meshes, like the Terrain and InstancedMesh, have local space hierarchies. Querying them is a little trickier, but still possible.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: How do I query accelerate the triangles from a StaticMes

Post by Spankenstein »

Thanks Norbo. Here's what I've done:

Code: Select all

                    List<int> triangleIndices = new List<int>();
                    
                    // Test for overlapping triangles in the static mesh
                    StaticMesh mesh = c as StaticMesh;
                    mesh.Mesh.Tree.GetOverlaps(boundingSphere, triangleIndices);

                    Vector3 vertexA;
                    Vector3 vertexB;
                    Vector3 vertexC;

                    int numIntersected = triangleIndices.Count;

                    for (int t = 0; t < numIntersected; ++t)
                    {
                        mesh.Mesh.Tree.TriangleMeshData.GetTriangle(triangleIndices[t], out vertexA, out vertexB, out vertexC);
                        triangles[numTriangles++] = new Triangle(vertexA, vertexC, vertexB);
                    }
Post Reply