Skip to main content
Instead of adding each individual object as an Object3D derived entity to the three.js scene, we split and organize them into batches, which are then added to the three.js scene. The Batch is defined as an interface, and is implemented by several batch types based on the geometry type.

Properties

batchMaterial

The batch’s default material. Batch objects have been grouped by this material. Returns: Material

geometryType

The batch’s GeometryType. Returns: GeometryType

id

The UUID of the batch. Follows three.js uuid format. Returns: string

renderObject

The batch’s renderable object. Depending on the batch type, this can be either a Mesh, LineSegment2, Points, Text. Returns: Object3D

renderViews

The collection of render views that make up the batch. Returns: NodeRenderView[]

subtreeId

The id of the subtree the batch is part of. Returns: number

Accessors

bounds

Gets the bounds of the batch. Returns: Box3

drawCalls

Gets the current of draw calls for the batch. Returns: number

groups

Gets the current list of draw groups. A draw group is equivalent to a draw call. Returns: DrawGroup[]

materials

Gets the current list of materials used for rendering the batch. Returns: Material[]

minDrawCalls

Gets the implementation’s desired minimum draw calls. Ideally 1, but implementation dependant. Returns: number

triCount

Gets the batch’s triangle count. Returns: number

vertCount

Gets the batch’s vertex count. Returns: number

Methods

buildBatch

Build this batch. The implementation needs to make the batch renderable by:
  • Building the geometry
  • Creating appropriate BatchObjects (if any) and their acceleration structures (if any)
  • Setting appropriate batch data to the render views
  • Initialising the batch’s renderObject
Returns: void

getCount

Gets the batch’s primitive count Returns: void

getDepth

Gets the batch’s BatchUpdateRange required for the depth pass. Returns: BatchUpdateRange

getMaterial

Gets the current material of the provided render view. Parameters: Returns: Material

getMaterialAtIndex

Gets the current material of the provided primitive index. Batches that build acceleration structures do not need to implement this. Parameters:
  • index: The primitive index to lookup
Returns: Material

getOpaque

Gets the batch’s opaque BatchUpdateRange. Returns: BatchUpdateRange

getRenderView

Gets the render view at the specified index. Batches that build acceleration structures do not need to implement this. Parameters:
  • index: The primitive index to lookup
Returns: NodeRenderView

getStencil

Gets the batch’s stencil BatchUpdateRange. Returns: BatchUpdateRange

getTransparent

Gets the batch’s transparent BatchUpdateRange. Returns: BatchUpdateRange

getVisibleRange

Gets the batch’s visible BatchUpdateRange. Returns: [BatchUpdateRange](/developers/viewer/batch-api#batchupd

onRender

Callback for the viewer’s render loop. Parameters: Returns: void

onUpdate

Callback for the viewer’s update loop. Parameters:
  • deltaTime: number
Returns: void

purge

Purges the batch by disposing of the associated geometry data and materials. Returns: void

resetDrawRanges

Resets the batch to its default state where there is a single draw group rendered with the batchMaterial. Returns: void

setBatchBuffers

Updates relevant batch buffers based on the MaterialOptions from the provided BatchUpdateRange. Implementation specific. Parameters: Returns: void

setBatchMaterial

Sets the default batch material. Parameters: Returns: void

setDrawRanges

Sets materials to specific objects inside the batch by specifying their draw ranges.
Materials are assigned to objects inside batches by using this method. Normally, the viewer offers a higher level of assigning materials through SpeckleRenderer’s setMaterial which calls this method internally.
Parameters: Returns: void

setVisibleRange

Sets visibility of objects inside the batch. Implementation specific.
Mesh batches currently only allow for contiguous visibility between draw ranges. i.e no different visibility gaps. Line batches however are not restricted by this.
Parameters: Returns: void

Typedefs

BatchUpdateRange

Represents a region of the batch. Multi purpose. It can represent either a specific object from the batch, or a specific index range in the batch spanning across multiple objects.

DrawGroup

Formalisation of three.js’s notion of draw group.
The viewer’s MeshBatch implementation of Batch uses three.js’s geometry groups as a means to render parts of the batch with different materials.

LineBatch

Batch implementation for lines.

MeshBatch

Batch implementation for triangle meshes.

InstancedMeshBatch

Batch implementation for instances of triangle meshes with hardware instancing support.

PointBatch

Batch implementation for points and point clouds.

TextBatch

Batch implementation for text. Using troika-three-text internally.
Last modified on July 18, 2026