Skip to content

VoxelInspector ​

Debug views and statistics of a VoxelView, exposed as view.inspector: a wireframe of the meshed chunks, chunk outlines, mesh counters and block usage.

ts
view.inspector.mode = "overlay";
view.inspector.chunkBounds = true;

const { faces, culledFaces, triangles } = view.inspector.mesh.stats;
const { voxels, unusedBlocks } = view.inspector.blocks.stats;

Options ​

Passed as VoxelViewOptions.inspector.

OptionDefaultDescription
mode"off"Initial mode.
color0x66FF99Wireframe colour.
opacity0.5Wireframe opacity; 1 disables blending.
chunkBoundsfalseOutline every chunk.
chunkBoundsColor0xFF3B30

Properties ​

ts
mode: "off" | "overlay" | "wireframe";
enabled: boolean;
chunkBounds: boolean;
readonly mesh: { readonly stats: VoxelMeshStats };
readonly blocks: VoxelBlockInspector;
readonly metrics: readonly VoxelMetric[];

nextMode(): VoxelInspectorMode;

Modes ​

ModeEffect
"off"Chunks render normally.
"overlay"A wireframe is drawn over the textured chunks.
"wireframe"Only the wireframe is drawn.

Switching modes never remeshes. nextMode() cycles through the three and returns the new mode. enabled = true selects "overlay", false selects "off".

chunkBounds outlines each meshed chunk, independently of mode. The outlines are drawn on top of the scene and follow chunks hidden or unloaded by the view distance.

Mesh statistics ​

mesh.stats sums the last build of every meshed chunk. Chunks not built yet, or unloaded by the view distance, are not counted.

FieldDescription
chunksChunks meshed, including those with no face.
culledChunksOf those, chunks hidden by the view distance.
meshesChunk meshes in the scene, one draw call each.
voxelsVoxels visited.
hiddenVoxelsVoxels covered by a higher layer.
facesFaces drawn.
culledFacesFaces hidden by an opaque neighbour.
vertices, triangles
facesPerSolidVoxelfaces / (voxels - hiddenVoxels); 0 when nothing was drawn.
bytesPerVertexVertex attribute bytes per vertex, indices excluded.
bytesGPU memory of the chunk geometries.
buildTimeMsSum of each chunk's last build time, not a frame cost.

Metrics ​

metrics lists the same counters as metric definitions for a performance recorder. VoxelMetric is compatible with MetricDefinition from @jolly-pixel/ui/stats.

ts
runtime.metrics.addSource(view.inspector);
MetricUnitValue
chunkscountmesh.stats.chunks
meshescountmesh.stats.meshes
voxelscountmesh.stats.voxels
facescountmesh.stats.faces
meshTrianglescountmesh.stats.triangles
culledFacespercentculledFaces / (faces + culledFaces), 0 before any build
facesPerVoxeldecimalmesh.stats.facesPerSolidVoxel
meshMemorybytesmesh.stats.bytes
buildTimeMsmsmesh.stats.buildTimeMs

All metrics are in the voxel group with tile: false.

Block statistics ​

blocks counts the voxels stored in document.world per block, including hidden layers and covered voxels. Results are computed on each call.

ts
readonly stats: VoxelBlockStats;
inspectUsage(blockId: number): VoxelBlockUsage;
inspectBlocksetUsage(blocksetId: string): VoxelBlocksetUsage;
stats fieldDescription
voxelsVoxels stored in every layer.
layers{ layerName, voxels, chunks } per layer, in world.getLayers() order.
blocksMap of voxel count per stored block id, orphans included.
unusedBlocksRegistered ids no voxel uses, in registry order.
orphanBlocksStored ids missing from the registry, ascending.
orphanVoxelsVoxels whose block is in orphanBlocks.

inspectUsage() returns { blockId, voxels, layers }, listing only the layers that hold the block. Check it before removing a block: block-removed leaves the voxels in place as orphans.

ts
const { voxels, layers } = view.inspector.blocks.inspectUsage(blockId);
if (voxels > 0) {
  console.warn(`Block used by ${voxels} voxels in ${layers.length} layers`);
}

inspectBlocksetUsage() returns { blocksetId, blocks, voxels }: the registered blocks with at least one tile in the blockset, and their voxel count. A block using two blocksets counts toward both.