How Can I Return Number of Faces in a Mesh?

Another newbie question,

Is there a built-in way to spit out the number of faces that a mesh has within a scene? If so, how do I use it?

I attempted to return a number from getTotalVertices() from the human figure in this playground, but it returned zero instead. I must need to access a nested child mesh somehow:
https://www.babylonjs-playground.com/#0K8EYN#0

What I suspect is that this mesh is a combo of low poly model and smooth shading to make it appear like a more complex geometry, but I want to be able to study polycount of a given mesh regardless.

1 Like

You are right, the Dude is composed a several child meshes:

On a specific mesh, you can use mesh.getTotalVertices() and mesh.getTotalIndices()

Thank you as always for your swift reply @Deltakosh :slight_smile:

I logged a rather high number when I ran this. It reflects a single sub mesh or the entire body of “dude”?

console.log(dude.getChildMeshes()[0].getTotalIndices()) // Returns 21690

This playground runs smoothly even though I expected to see some slow down on mobile, so I’m attempting to use it as a test case for poly count in a scene.

It is the number of indices per mesh. Number of faces or triangles = indices / 3

2 Likes

https://doc.babylonjs.com/how_to/how_to_use_facetdata#what-is-a-mesh-facet

https://doc.babylonjs.com/how_to/how_to_use_facetdata

2 Likes