Class: MeshBatch

MeshBatch

MeshBatch allows bundling a Mesh with a Material similar to MeshInstance, but allows rendering multiple instances in a single draw call. To save on memory usage, individual instances are referred to by individual IDs instead of Transform objects. Despite being a subclass, MeshBatch is still considered a MeshInstance component.


new MeshBatch(mesh, material, dynamic)

Parameters:
Name Type Description
mesh Mesh

The Mesh providing the geometry for this instance.

material Material

The Material to use to render the given Mesh.

dynamic Boolean

Whether or not the generated geometry is dynamic. If so, updating the instance transforms often can be faster, but it removes frustum culling for this batch unless bounds are explicitly assigned. Defaults to false.

Properties:
Name Type Description
numInstances number

The amount of instances that will be drawn.

Author:
  • derschmale <http://www.derschmale.com>

Extends

Methods


createInstance(transform)

Adds an instance with a given transform. This method returns the ID for the instance, which is used when the instance needs to be deleted or its transform updated.

Parameters:
Name Type Description
transform

A Matrix4x4 or a Transform containing the transformation for the instance.

Returns:

An ID representing the instance. Use this to set the transform in MeshBatch#setTransform and MeshBatch#destroyInstance.

Type
number

destroyInstance(instanceID)

Destroys an instance.

Parameters:
Name Type Description
instanceID

The instance ID as returned by MeshBatch#createInstance


setTransform(instanceID, transform)

Changes the transform for an instance.

Parameters:
Name Type Description
instanceID

The instance ID as returned by MeshBatch#createInstance

transform

A Matrix4x4 or Transform object.