How to get inspector information programatically

When I view a scene in Babylon, the debug Inspector has an option to view Statistics Pane > Count . This information contains items such as Total meshes, Active meshes, Active indices, ... , Total materials, Total textures.

I would like to get this information using the Babylonjs library but unable to figure out using the documentation how to do so. Could you please advise which part of the Babylonjs API supports the functionality to get the above data programatically?

Welcome to the forum!! :slight_smile:

All of this data can be found in core elements of the project.
Total meshes can be found in the scene, active meshes is a part of the render loop and so on.
There are also two classes you will find interesting - the SceneInstrumentaion and the EngineInstrumentation.

Check this - Babylon.js/statisticsTabComponent.tsx at master · BabylonJS/Babylon.js (github.com), this is where the information is being gathered.

3 Likes

Thanks @RaananW ! I was able to get the scene level statistics using the github sample you shared. I am now looking at the the statistics you see in the inspector on the right when you click Scene. They include a count of “Total Meshes”, “Active Meshes”, “Active indices”, “Active faces”, “Active bones”, “Active particles”, “Draw calls”, “Total lights”, “Total vertices”, “Total materials”, “Total textures”.

I can see that some of the counts I programatically got from the scene object are different from the counts I see in the inspector.

Specifically, the following are different as shown in the debug inspector and as received from the scene object programatically – Active Meshes, Active Indices, Active faces, Draw calls. The scene object returns them all as 0 however they show a value in the debug inspector. Am I missing something?

For instance Active Meshes.

The debug inspector shows the value as 2.

However, this is the scene.getActiveMeshes().length result in the code.

SmartArray {length: 0, data: Array(256), _id: 2}
_id:2
data:(256) […]
length:0
[[Prototype]]:Object
proto (get):Ć’ proto()
proto (set):Ć’ proto()

The resulting array seems to have data, but its length property is 0. Moreover, I don’t see a value of 2.

Funny enough, this is something @SahilTara has experienced last week :slight_smile:

Are you checking the number of before render, or on after render? Because those numbers are only available after render is done, and are being reset on each frame

3 Likes

Thanks @RaananW , that resolves the issue i.e. getting the counts after render :slight_smile:

1 Like