# Batch

A batch is the structural component of the viewer's scenegraph. All loaded objects are split and organized into batches. 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 geometryType id renderObject
renderViews subtreeId

#

Accessors

bounds drawCalls groups materials
minDrawCalls triCount vertCount

#

Methods

buildBatch getCount getDepth getMaterial
getMaterialAtIndex getOpaque getRenderView getStencil
getTransparent getVisibleRange onRender onUpdate
purge resetDrawRanges setBatchBuffers setBatchMaterial
setDrawRanges setVisibleRange

#

Typedefs

BatchUpdateRange DrawGroup LineBatch MeshBatch
InstancedMeshBatch PointBatch TextBatch InstancedMeshBatch

#

Properties

# batchMaterial

batchMaterial: Material;
1

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

Returns: Material (opens new window)

# geometryType

geometryType: GeometryType;
1

The batch's GeometryType.

Returns: GeometryType

# id

id: string;
1

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

Returns: string

# renderObject

renderObject: Object3D;
1

The batch's renderable object. Depending on the batch type, this can be either a Mesh (opens new window), LineSegment2 (opens new window), Points (opens new window), Text (opens new window).

Returns: Object3D (opens new window)

# renderViews

renderViews: NodeRenderView[]
1

The collection of render views that make up the batch.

Returns: NodeRenderView[]

# subtreeId

subtreeId: number;
1

The id of the subtree the batch is part of.

Returns: number

#

Properties

# bounds

get bounds(): Box3
1

Gets the bounds of the batch.

Returns: Box3 (opens new window)

# drawCalls

get drawCalls(): number
1

Gets the current of draw calls for the batch.

Returns: number

# groups

get groups(): DrawGroup[]
1

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

Returns: DrawGroup[]

# materials

get materials(): Material[]
1

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

Returns: Material[] (opens new window)

# minDrawCalls

get minDrawCalls(): number
1

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

Returns: number

# triCount

get triCount(): number
1

Gets the batch's triangle count.

Returns: number

# vertCount

get vertCount(): number
1

Gets the batch's vertex count.

Returns: number

#

Methods

# buildBatch

buildBatch();
1

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
1

Gets the batch's primitive count

Returns: void

# getCount()

getCount(): number
1

Gets the batch's primitive count.

Returns: void

# getDepth()

getDepth(): BatchUpdateRange
1

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

Returns: BatchUpdateRange

# getMaterial()

getMaterial(renderView: NodeRenderView): Material
1

Gets the current material of the provided render view.

Parameters

Returns: Material (opens new window)

# getMaterialAtIndex()

getMaterialAtIndex(index: number): Material
1

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 (opens new window)

# getOpaque()

getOpaque(): BatchUpdateRange
1

Gets the batch's opaque BatchUpdateRange.

Returns: BatchUpdateRange

# getRenderView()

getRenderView(index: number): NodeRenderView
1

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
1

Gets the batch's stencil BatchUpdateRange.

Returns: BatchUpdateRange

# getTransparent()

getTransparent(): BatchUpdateRange
1

Gets the batch's transparent BatchUpdateRange.

Returns: BatchUpdateRange

# getVisibleRange()

getVisibleRange(): BatchUpdateRange
1

Gets the batch's visible BatchUpdateRange.

Returns: BatchUpdateRange

# onRender()

onRender(renderer: WebGLRenderer): void
1

Callback for the viewer's render loop.

Parameters

Returns: void

# onUpdate()

onUpdate(deltaTime: number): void
1

Callback for the viewer's update loop.

Parameters

  • deltaTime: number

Returns: void

# purge()

purge(): void
1

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

Returns: void

# resetDrawRanges()

resetDrawRanges: void
1

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
1

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

Parameters

Returns: void

# setBatchMaterial()

setBatchMaterial(material: Material): void
1

Sets the default batch material.

Parameters

Returns: void

# setDrawRanges()

setDrawRanges(ranges: BatchUpdateRange[]): void
1

Sets materials to specific objects inside the batch by specifying their draw ranges.

TIP

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
1

Sets visibility of objects inside the batch. Implementation specific.

WARNING

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;
}
1
2
3
4
5
6

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;
}
1
2
3
4
5

Formalisation of three.js's notion of draw group.

TIP

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 {}
1

Batch implementation for lines.

# MeshBatch

class MeshBatch implements Batch {}
1

Batch implementation for triangle meshes.

# InstancedMeshBatch

class InstancedMeshBatch implements Batch {}
1

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

# PointBatch

class PointBatch implements Batch {}
1

Batch implementation for points and point clouds.

# TextBatch

class TextBatch implements Batch {}
1

Batch implementation for text. Using troika-three-text (opens new window) internally.