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