Skip to content

Instantly share code, notes, and snippets.

@PixelsCommander
Created September 4, 2018 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PixelsCommander/0727c833c9bdf4bbbd18552f2063d0c1 to your computer and use it in GitHub Desktop.
Save PixelsCommander/0727c833c9bdf4bbbd18552f2063d0c1 to your computer and use it in GitHub Desktop.
There is no built in way in BabylonJS to measure total number of vertices so here we go
// TODO check for instanced, should we exclude them from count?
// TODO check for invisible
let verticesCounted = 0;
let indicesCounted = 0;
export function totalVertices(scene: Scene): { vertices: number; indices: number; } {
verticesCounted = 0;
scene.meshes.forEach((mesh) => {
if (mesh) {
countVertices(mesh as Mesh);
}
});
return {
vertices: verticesCounted,
indices: indicesCounted,
};
}
function countVertices(mesh: Mesh) {
if (mesh.getChildMeshes) {
const children = mesh.getChildMeshes(true);
children.forEach(countVertices);
}
if (mesh.getTotalVertices && mesh.getTotalIndices) {
verticesCounted += mesh.getTotalVertices();
indicesCounted += mesh.getTotalIndices();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment