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

batchMaterial: Material;

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

Returns: Material

geometryType

geometryType: GeometryType;

The batch’s GeometryType.

Returns: GeometryType

id

id: string;

The UUID of the batch. Follows three.js uuid format.

Returns: string

renderObject

renderObject: Object3D;

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

Returns: Object3D

renderViews

renderViews: NodeRenderView[]

The collection of render views that make up the batch.

Returns: NodeRenderView[]

subtreeId

subtreeId: number;

The id of the subtree the batch is part of.

Returns: number

Accessors

bounds

get bounds(): Box3

Gets the bounds of the batch.

Returns: Box3

drawCalls

get drawCalls(): number

Gets the current of draw calls for the batch.

Returns: number

groups

get groups(): DrawGroup[]

Gets the current list of draw groups. A draw group is equivalent to a draw call.

Returns: DrawGroup[]

materials

get materials(): Material[]

Gets the current list of materials used for rendering the batch.

Returns: Material[]

minDrawCalls

get minDrawCalls(): number

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

Returns: number

triCount

get triCount(): number

Gets the batch’s triangle count.

Returns: number

vertCount

get vertCount(): number

Gets the batch’s vertex count.

Returns: number

Methods

buildBatch

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

getCount(): number

Gets the batch’s primitive count

Returns: void

getDepth

getDepth(): BatchUpdateRange

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

Returns: BatchUpdateRange

getMaterial

getMaterial(renderView: NodeRenderView): Material

Gets the current material of the provided render view.

Parameters

Returns: Material

getMaterialAtIndex

getMaterialAtIndex(index: number): Material

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

getOpaque(): BatchUpdateRange

Gets the batch’s opaque BatchUpdateRange.

Returns: BatchUpdateRange

getRenderView

getRenderView(index: number): NodeRenderView

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

getStencil(): BatchUpdateRange

Gets the batch’s stencil BatchUpdateRange.

Returns: BatchUpdateRange

getTransparent

getTransparent(): BatchUpdateRange

Gets the batch’s transparent BatchUpdateRange.

Returns: BatchUpdateRange

getVisibleRange

getVisibleRange(): BatchUpdateRange

Gets the batch’s visible BatchUpdateRange.

Returns: [BatchUpdateRange](/developers/viewer/batch-api#batchupd

onRender

onRender(renderer: WebGLRenderer): void

Callback for the viewer’s render loop.

Parameters

Returns: void

onUpdate

onUpdate(deltaTime: number): void

Callback for the viewer’s update loop.

Parameters

  • deltaTime: number

Returns: void

purge

purge(): void

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

Returns: void

resetDrawRanges

resetDrawRanges: void

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

Returns: void

setBatchBuffers

setBatchBuffers(range: BatchUpdateRange[]): void

Updates relevant batch buffers based on the MaterialOptions from the provided BatchUpdateRange. Implementation specific.

Parameters

Returns: void

setBatchMaterial

setBatchMaterial(material: Material): void

Sets the default batch material.

Parameters

Returns: void

setDrawRanges

setDrawRanges(ranges: BatchUpdateRange[]): void

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

setVisibleRange(range: BatchUpdateRange[]): void

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

interface BatchUpdateRange {
  offset: number;
  count: number;
  material?: Material;
  materialOptions?: FilterMaterialOptions;
}

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

interface DrawGroup {
  start: number;
  count: number;
  materialIndex?: number;
}

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

class LineBatch implements Batch {}

Batch implementation for lines.

MeshBatch

class MeshBatch implements Batch {}

Batch implementation for triangle meshes.

InstancedMeshBatch

class InstancedMeshBatch implements Batch {}

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

PointBatch

class PointBatch implements Batch {}

Batch implementation for points and point clouds.

TextBatch

class TextBatch implements Batch {}

Batch implementation for text. Using troika-three-text internally.