# 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
# Typedefs
BatchUpdateRange | DrawGroup | LineBatch | MeshBatch |
---|---|---|---|
InstancedMeshBatch | PointBatch | TextBatch | InstancedMeshBatch |
# Properties
# batchMaterial
batchMaterial: Material;
The batch's default material. Batch objects have been grouped by this material.
Returns: Material (opens new window)
# 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 (opens new window), LineSegment2 (opens new window), Points (opens new window), Text (opens new window).
Returns: Object3D (opens new window)
# 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 (opens new window)
# 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[] (opens new window)
# 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
- renderView: NodeRenderView
Returns: Material (opens new window)
# 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 (opens new window)
# 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
# onRender
onRender(renderer: WebGLRenderer): void
Callback for the viewer's render loop.
Parameters
- renderer: WebGLRenderer (opens new window)
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
- range: BatchUpdateRange
Returns: void
# setBatchMaterial
setBatchMaterial(material: Material): void
Sets the default batch material.
Parameters
- material: Material (opens new window)
Returns: void
# setDrawRanges
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 which calls this method internally.
Parameters
- ranges: BatchUpdateRange
Returns: void
# setVisibleRange
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.
Parameters
- ranges: BatchUpdateRange
Returns: void
# Typedefs
# BatchUpdateRange
interface BatchUpdateRange {
offset: number;
count: number;
material?: Material;
materialOptions?: FilterMaterialOptions;
}
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;
}
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 {}
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 (opens new window) internally.