> ## Documentation Index
> Fetch the complete documentation index at: https://docs.speckle.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# Batch

> 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

```typescript theme={null}
batchMaterial: Material;
```

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

**Returns**: [*Material*](https://threejs.org/docs/index.html?q=mater#api/en/materials/Material)

### geometryType

```typescript theme={null}
geometryType: GeometryType;
```

The batch's [*GeometryType*](/developers/viewer/render-view-api#geometrytypeenum).

**Returns**: [*GeometryType*](/developers/viewer/render-view-api#geometrytypeenum)

### id

```typescript theme={null}
id: string;
```

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

**Returns**: string

### renderObject

```typescript theme={null}
renderObject: Object3D;
```

The batch's renderable object. Depending on the batch type, this can be either
a [*Mesh*](https://threejs.org/docs/index.html?q=mesh#api/en/objects/Mesh),
[*LineSegment2*](https://threejs.org/docs/index.html?q=linese#api/en/objects/LineSegments),
[*Points*](https://threejs.org/docs/index.html?q=point#api/en/objects/Points),
[*Text*](https://www.npmjs.com/package/troika-three-text).

**Returns**: [*Object3D*](https://threejs.org/docs/index.html?q=point#api/en/core/Object3D)

### renderViews

```typescript theme={null}
renderViews: NodeRenderView[]
```

The collection of render views that make up the batch.

**Returns**: [*NodeRenderView\[\]*](/developers/viewer/render-view-api)

### subtreeId

```typescript theme={null}
subtreeId: number;
```

The id of the subtree the batch is part of.

**Returns**: number

## Accessors

### bounds

```typescript theme={null}
get bounds(): Box3
```

Gets the bounds of the batch.

**Returns**: [*Box3*](https://threejs.org/docs/index.html?q=box3#api/en/math/Box3)

### drawCalls

```typescript theme={null}
get drawCalls(): number
```

Gets the current of draw calls for the batch.

**Returns**: number

### groups

```typescript theme={null}
get groups(): DrawGroup[]
```

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

**Returns**: [*DrawGroup\[\]*](/developers/viewer/batch-api#drawgroup)

### materials

```typescript theme={null}
get materials(): Material[]
```

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

**Returns**: [*Material\[\]*](https://threejs.org/docs/index.html?q=materi#api/en/materials/Material)

### minDrawCalls

```typescript theme={null}
get minDrawCalls(): number
```

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

**Returns**: number

### triCount

```typescript theme={null}
get triCount(): number
```

Gets the batch's triangle count.

**Returns**: number

### vertCount

```typescript theme={null}
get vertCount(): number
```

Gets the batch's vertex count.

**Returns**: number

## Methods

### buildBatch

```typescript theme={null}
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*](/developers/viewer/batch-api#renderobject)

**Returns**: void

### getCount

```typescript theme={null}
getCount(): number
```

Gets the batch's primitive count

**Returns**: void

### getDepth

```typescript theme={null}
getDepth(): BatchUpdateRange
```

Gets the batch's [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange) required for the depth pass.

**Returns**: [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange)

### getMaterial

```typescript theme={null}
getMaterial(renderView: NodeRenderView): Material
```

Gets the current material of the provided render view.

**Parameters**

* **renderView**: [*NodeRenderView*](/developers/viewer/render-view-api)

**Returns**: [*Material*](https://threejs.org/docs/index.html?q=materi#api/en/materials/Material)

### getMaterialAtIndex

```typescript theme={null}
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*](https://threejs.org/docs/index.html?q=materi#api/en/materials/Material)

### getOpaque

```typescript theme={null}
getOpaque(): BatchUpdateRange
```

Gets the batch's opaque [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange).

**Returns**: [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange)

### getRenderView

```typescript theme={null}
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*](/developers/viewer/render-view-api)

### getStencil

```typescript theme={null}
getStencil(): BatchUpdateRange
```

Gets the batch's stencil [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange).

**Returns**: [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange)

### getTransparent

```typescript theme={null}
getTransparent(): BatchUpdateRange
```

Gets the batch's transparent [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange).

**Returns**: [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange)

### getVisibleRange

```typescript theme={null}
getVisibleRange(): BatchUpdateRange
```

Gets the batch's visible [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange).

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

### onRender

```typescript theme={null}
onRender(renderer: WebGLRenderer): void
```

Callback for the viewer's render loop.

**Parameters**

* **renderer**: [*WebGLRenderer*](https://threejs.org/docs/index.html?q=webglre#api/en/renderers/WebGLRenderer)

**Returns**: void

### onUpdate

```typescript theme={null}
onUpdate(deltaTime: number): void
```

Callback for the viewer's update loop.

**Parameters**

* **deltaTime**: number

**Returns**: void

### purge

```typescript theme={null}
purge(): void
```

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

**Returns**: void

### resetDrawRanges

```typescript theme={null}
resetDrawRanges: void
```

Resets the batch to its default state where there is a single draw group rendered with the [*batchMaterial*](/developers/viewer/batch-api#batchmaterial).

**Returns**: void

### setBatchBuffers

```typescript theme={null}
setBatchBuffers(range: BatchUpdateRange[]): void
```

Updates relevant batch buffers based on the [*MaterialOptions*](/developers/viewer/speckle-material-api#materialoptions) from the provided [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange). Implementation specific.

**Parameters**

* **range**: [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange)

**Returns**: void

### setBatchMaterial

```typescript theme={null}
setBatchMaterial(material: Material): void
```

Sets the default batch material.

**Parameters**

* **material**: [*Material*](https://threejs.org/docs/index.html?q=mater#api/en/materials/Material)

**Returns**: void

### setDrawRanges

```typescript theme={null}
setDrawRanges(ranges: BatchUpdateRange[]): void
```

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*](/developers/viewer/speckle-renderer-api#setmaterial) which calls this
  method internally.
</Tip>

**Parameters**

* **ranges**: [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange)

**Returns**: void

### setVisibleRange

```typescript theme={null}
setVisibleRange(range: BatchUpdateRange[]): void
```

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.
</Warning>

**Parameters**

* **ranges**: [*BatchUpdateRange*](/developers/viewer/batch-api#batchupdaterange)

**Returns**: void

## Typedefs

### BatchUpdateRange

```typescript theme={null}
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

```typescript theme={null}
interface DrawGroup {
  start: number;
  count: number;
  materialIndex?: number;
}
```

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

<Tip>
  The viewer's [*MeshBatch*](/developers/viewer/batch-api#meshbatch) implementation of
  Batch uses three.js's geometry groups as a means to render parts of the batch
  with different materials.
</Tip>

### LineBatch

```typescript theme={null}
class LineBatch implements Batch {}
```

Batch implementation for lines.

### MeshBatch

```typescript theme={null}
class MeshBatch implements Batch {}
```

Batch implementation for triangle meshes.

### InstancedMeshBatch

```typescript theme={null}
class InstancedMeshBatch implements Batch {}
```

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

### PointBatch

```typescript theme={null}
class PointBatch implements Batch {}
```

Batch implementation for points and point clouds.

### TextBatch

```typescript theme={null}
class TextBatch implements Batch {}
```

Batch implementation for text. Using [*troika-three-text*](https://www.npmjs.com/package/troika-three-text) internally.
