Class: BatchManager

pc.BatchManager

Glues many mesh instances into a single one for better performance.

Constructor

new BatchManager(device, root, scene)

Parameters:
Name Type Description
device pc.GraphicsDevice The graphics device used by the batch manager.
root pc.Entity The entity under which batched models are added.
scene pc.Scene The scene that the batch manager affects.
Source:

Methods

(private, static) markGroupDirty(id)

Mark a specific batch group as dirty. Dirty groups are re-batched before the next frame is rendered. Note, re-batching a group is a potentially expensive operation
Parameters:
Name Type Description
id Number Batch Group ID to mark as dirty
Source:

addGroup(name, dynamic, maxAabbSize, idopt, layersopt) → {pc.BatchGroup}

Adds new global batch group.
Parameters:
Name Type Attributes Description
name String Custom name
dynamic Boolean Is this batch group dynamic? Will these objects move/rotate/scale after being batched?
maxAabbSize Number Maximum size of any dimension of a bounding box around batched objects. pc.BatchManager#prepare will split objects into local groups based on this size.
id Number <optional>
Optional custom unique id for the group (will be generated automatically otherwise).
layers Array.<Number> <optional>
Optional layer ID array. Default is [pc.LAYERID_WORLD]. The whole batch group will belong to these layers. Layers of source models will be ignored.
Source:
Returns:
Group object.
Type
pc.BatchGroup

clone(batch, clonedMeshInstances) → {pc.Batch}

Clones a batch. This method doesn't rebuild batch geometry, but only creates a new model and batch objects, linked to different source mesh instances.
Parameters:
Name Type Description
batch pc.Batch A batch object
clonedMeshInstances Array New mesh instances
Source:
Returns:
New batch object
Type
pc.Batch

create(meshInstances, dynamic, batchGroupIdopt) → {pc.Batch}

Takes a mesh instance list that has been prepared by pc.BatchManager#prepare, and returns a pc.Batch object. This method assumes that all mesh instances provided can be rendered in a single draw call.
Parameters:
Name Type Attributes Description
meshInstances Array Input list of mesh instances
dynamic Boolean Is it a static or dynamic batch? Will objects be transformed after batching?
batchGroupId Number <optional>
Link this batch to a specific batch group. This is done automatically with default batches.
Source:
Returns:
The resulting batch object.
Type
pc.Batch

(private) decrement(batch)

Decrements reference counter on a batch. If it's zero, the batch is removed from scene, and its geometry is deleted from memory.
Parameters:
Name Type Description
batch pc.Batch A batch object
Source:

(private) destroy(batch)

Mark the batches ref counter to 0, remove the batch model out of all layers and destroy it
Parameters:
Name Type Description
batch pc.Batch A batch object
Source:

generate(groupIdsopt)

Destroys all batches and creates new based on scene models. Hides original models. Called by engine automatically on app start, and if batchGroupIds on models are changed.
Parameters:
Name Type Attributes Description
groupIds Array <optional>
Optional array of batch group IDs to update. Otherwise all groups are updated.
Source:

(private) getBatches(batchGroupId) → {Array.<pc.Batch>}

Return a list of all pc.Batch objects that belong to the Batch Group supplied
Parameters:
Name Type Description
batchGroupId Number The id of the batch group
Source:
Returns:
A list of batches that are used to render the batch group
Type
Array.<pc.Batch>

getGroupByName(name) → {pc.BatchGroup}

Retrieves a pc.BatchGroup object with a corresponding name, if it exists, or null otherwise.
Parameters:
Name Type Description
name String Name
Source:
Returns:
Group object.
Type
pc.BatchGroup

prepare(meshInstances, dynamic, maxAabbSize, translucent) → {Array}

Takes a list of mesh instances to be batched and sorts them into lists one for each draw call. The input list will be split, if:
  • Mesh instances use different materials
  • Mesh instances have different parameters (e.g. lightmaps or static lights)
  • Mesh instances have different shader defines (shadow receiving, being aligned to screen space, etc)
  • Too many vertices for a single batch (65535 is maximum)
  • Too many instances for a single batch (hardware-dependent, expect 128 on low-end and 1024 on high-end)
  • Bounding box of a batch is larger than maxAabbSize in any dimension
Parameters:
Name Type Description
meshInstances Array Input list of mesh instances
dynamic Boolean Are we preparing for a dynamic batch? Instance count will matter then (otherwise not).
maxAabbSize Number Maximum size of any dimension of a bounding box around batched objects.
translucent Boolean Are we batching UI elements or sprites This is useful to keep a balance between the number of draw calls and the number of drawn triangles, because smaller batches can be hidden when not visible in camera.
Source:
Returns:
An array of arrays of mesh instances, each valid to pass to pc.BatchManager#create.
Type
Array

removeGroup(id)

Remove global batch group by id. Note, this traverses the entire scene graph and clears the batch group id from all components
Parameters:
Name Type Description
id String Group id
Source:

(private) update(batch)

Updates bounding box for a batch. Called automatically.
Parameters:
Name Type Description
batch pc.Batch A batch object
Source:

(private) updateAll()

Updates bounding boxes for all dynamic batches. Called automatically.
Source: