Page 1 of 1
How do I query accelerate the triangles from a StaticMesh?
Posted: Sun May 15, 2011 10:26 am
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")?
Re: How do I query accelerate the triangles from a StaticMes
Posted: Sun May 15, 2011 7:23 pm
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.
Re: How do I query accelerate the triangles from a StaticMes
Posted: Sun May 15, 2011 11:21 pm
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);
}