javascriptbabylonjs

get mesh/face/vertices count in BabylonJS outside of the inspector


I would like to be able to show some basic stats for my scene in BabylonJS, without needing to display the inspector. Is there a way to get those statistics from the scene?


Solution

  • Yes you can thanks to the scene instrumentation class:

    var instrumentation = new BABYLON.SceneInstrumentation(scene);

    Documentation: https://doc.babylonjs.com/divingDeeper/scene/optimize_your_scene#sceneinstrumentation

    For mesh / faces / vertices count:

    scene.getTotalVertices(); // total vertices
    scene.getActiveIndices() / 3; // faces
    scene.getActiveMeshes().length; // Total meshes