# BatchedTilesPlugin

class in `3d-tiles-renderer/three/plugins`

```js
import { BatchedTilesPlugin } from '3d-tiles-renderer/three/plugins';
```

Plugin that uses three.js `BatchedMesh` to limit the number of draw calls required and
improve performance. The `BatchedMesh` geometry and instance size are automatically resized
and optimized as new geometry is added and removed. Note that the `renderer` field is
required. Requires Three.js r170 or later.

> **Warning:** All tile geometry rendered with `BatchedMesh` will use the same material and only a single
material map is supported. Only tile geometry containing a single mesh is supported. Not
compatible with plugins that modify mesh materials or rely on bespoke mesh data (e.g.
`TilesFadePlugin`, `DebugTilesPlugin`, GLTF Metadata extensions).

Example: Drawing all tiles in one batched mesh

```js
import { TilesRenderer } from '3d-tiles-renderer/three';
import { BatchedTilesPlugin } from '3d-tiles-renderer/three/plugins';

// scene, camera and renderer are initialized here

const URL = 'https://raw.githubusercontent.com/NASA-AMMOS/3DTilesSampleData/master/msl-dingo-gap/0528_0260184_to_s64o256_colorize/0528_0260184_to_s64o256_colorize/0528_0260184_to_s64o256_colorize_tileset.json';
const tiles = new TilesRenderer( URL );
tiles.registerPlugin( new BatchedTilesPlugin( { renderer } ) );
tiles.setCamera( camera );
tiles.setResolutionFromRenderer( camera, renderer );
tiles.group.rotation.x = Math.PI / 2;
scene.add( tiles.group );
camera.position.set( 20, 10, 20 );

renderer.setAnimationLoop( () => {

	camera.updateMatrixWorld();
	tiles.update();
	renderer.render( scene, camera );

} );
```

## Constructor

```js
new BatchedTilesPlugin( options: Object )
```

- `options`, `Object`
  - `renderer`, `WebGLRenderer`: The renderer used to generate a `WebGLArrayRenderTarget`.
  - `instanceCount`, `number`, optional, default `500`: Initial number of instances in the batched mesh.
  - `vertexCount`, `number`, optional, default `1000`: Minimum vertex space to reserve per tile geometry added.
  - `indexCount`, `number`, optional, default `1000`: Minimum index space to reserve per tile geometry added.
  - `expandPercent`, `number`, optional, default `0.25`: Fraction by which to grow the mesh when capacity is exceeded.
  - `maxInstanceCount`, `number`, optional, default `Infinity`: Hard cap on instance count (clamped to GPU limits).
  - `discardOriginalContent`, `boolean`, optional, default `true`: Free the original tile scene after batching. Set to `false` when used with `UnloadTilesPlugin`.
  - `textureSize`, `number | null`, optional, default `null`: Override width/height for the texture array; defaults to the first tile's texture size.
  - `material`, `Material | null`, optional, default `null`: Custom material for the batched mesh; defaults to the first tile's material type.
