Created
September 4, 2018 11:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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