Calc tris and verts pr. frame in webplayer

Hi there, I have some people who says parts of a level is slowing the FPS down. As the users can build the levels themselfs, I would like to examine the FPS and verts/tris in certain areas/levels.

I have a FPS running now, but how do I calculate the verts/tris run-time in a scene?

I cant find anything in script reference, so I guess its gotta be manually somehow. Is it “for each child gameobject in scene, calc verts/tris and check every child within too recursively” ?

if so, where do I find the verts and tris?

The Mesh-class has all you need. Every mesh is made up of vertices and triangles. With Mesh.vertexCount you can get the vertex count of this Mesh. The triangle count can only be queried by reading the length of the Mesh.triangles array and divide it by 3.

To get the overall vertex / triangle count in the scene just use this:

// C#:

int vertices = 0;
int tris = 0;

MeshFilter[] allMeshFilters = (MeshFilter[])FindObjectsOfType(typeof(MeshFilter));
SkinnedMeshRenderer[] allSkinnedMeshes = (SkinnedMeshRenderer[])FindObjectsOfType(typeof(SkinnedMeshRenderer));

foreach(MeshFilter MF in allMeshFilters)
{
    vertices += MF.sharedMesh.vertexCount;
    tris += MF.sharedMesh.triangles.Length / 3;
}
foreach(SkinnedMeshRenderer SMR in allSkinnedMeshes)
{
    vertices += SMR.sharedMesh.vertexCount;
    tris += SMR.sharedMesh.triangles.Length / 3;
}

Debug.Log("Vertex count: " + vertices + "   triangle count:" + tris);