[page:Mesh] →

[name]

A special version of [page:Mesh] with multi draw batch rendering support. Use [name] if you have to render a large number of objects with the same material but with different world transformations and geometry. The usage of [name] will help you to reduce the number of draw calls and thus improve the overall rendering performance in your application.

If the [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension] is not supported then a less performant callback is used.

Code Example

const box = new THREE.BoxGeometry( 1, 1, 1 ); const sphere = new THREE.BoxGeometry( 1, 1, 1 ); const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } ); // initialize and add geometries into the batched mesh const batchedMesh = new BatchedMesh( 10, 5000, 10000, material ); const boxId = batchedMesh.addGeometry( box ); const sphereId = batchedMesh.addGeometry( sphere ); // position the geometries batchedMesh.setMatrixAt( boxId, boxMatrix ); batchedMesh.setMatrixAt( sphereId, sphereMatrix ); scene.add( batchedMesh );

Examples

[example:webgl_mesh_batch WebGL / mesh / batch]

Constructor

[name]( [param:Integer maxGeometryCount], [param:Integer maxVertexCount], [param:Integer maxIndexCount], [param:Material material], )

[page:Integer maxGeometryCount] - the max number of individual geometries planned to be added.
[page:Integer maxVertexCount] - the max number of vertices to be used by all geometries.
[page:Integer maxIndexCount] - the max number of indices to be used by all geometries.
[page:Material material] - an instance of [page:Material]. Default is a new [page:MeshBasicMaterial].

Properties

See the base [page:Mesh] class for common properties.

[property:Box3 boundingBox]

This bounding box encloses all instances of the [name]. Can be calculated with [page:.computeBoundingBox](). Default is `null`.

[property:Sphere boundingSphere]

This bounding sphere encloses all instances of the [name]. Can be calculated with [page:.computeBoundingSphere](). Default is `null`.

[property:Boolean perObjectFrustumCulled]

If true then the individual objects within the [name] are frustum culled. Default is `true`.

[property:Boolean sortObjects]

If true then the individual objects within the [name] are sorted to improve overdraw-related artifacts. If the material is marked as "transparent" objects are rendered back to front and if not then they are rendered front to back. Default is `true`.

[property:Integer maxGeometryCount]

The maximum number of individual geometries that can be stored in the [name]. Read only.

[property:Boolean isBatchedMesh]

Read-only flag to check if a given object is of type [name].

Methods

See the base [page:Mesh] class for common methods.

[method:undefined computeBoundingBox]()

Computes the bounding box, updating [page:.boundingBox] attribute.
Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are `null`.

[method:undefined computeBoundingSphere]()

Computes the bounding sphere, updating [page:.boundingSphere] attribute.
Bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are `null`.

[method:undefined dispose]()

Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.

[method:this setCustomSort]( [param:Function sortFunction] )

Takes a sort a function that is run before render. The function takes a list of items to sort and a camera. The objects in the list include a "z" field to perform a depth-ordered sort with.

[method:Matrix4 getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

[page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance.

Get the local transformation matrix of the defined instance.

[method:Boolean getVisibleAt]( [param:Integer index] )

[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

Get whether the given instance is marked as "visible" or not.

[method:this setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

[page:Matrix4 matrix]: A 4x4 matrix representing the local transformation of a single instance.

Sets the given local transformation matrix to the defined instance.

[method:this setVisibleAt]( [param:Integer index], [param:Boolean visible] )

[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

[page:Boolean visible]: A boolean value indicating the visibility state.

Sets the visibility of the object at the given index.

[method:Integer addGeometry]( [param:BufferGeometry geometry], [param:Integer reservedVertexRange], [param:Integer reservedIndexRange] )

[page:BufferGeometry geometry]: The geometry to add into the [name].

[page:Integer reservedVertexRange]: Optional parameter specifying the amount of vertex buffer space to reserve for the added geometry. This is necessary if it is planned to set a new geometry at this index at a later time that is larger than the original geometry. Defaults to the length of the given geometry vertex buffer.

[page:Integer reservedIndexRange]: Optional parameter specifying the amount of index buffer space to reserve for the added geometry. This is necessary if it is planned to set a new geometry at this index at a later time that is larger than the original geometry. Defaults to the length of the given geometry index buffer.

Adds the given geometry to the [name] and returns the associated index referring to it.

[method:Integer setGeometryAt]( [param:Integer index], [param:BufferGeometry geometry] )

[page:Integer index]: Which geometry index to replace with this geometry.

[page:BufferGeometry geometry]: The geometry to substitute at the given geometry index.

Replaces the geometry at `index` with the provided geometry. Throws an error if there is not enough space reserved for geometry at the index.

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]