Plugin that flattens tile geometry vertices onto the surface of one or more mesh
"shapes", useful for placing flat terrain overlays or cutting roads into terrain.
Shapes are added via addShape() and removed via deleteShape() or clearShapes().
import { Mesh, PlaneGeometry, Vector3 } from 'three';
import { TilesRenderer } from '3d-tiles-renderer/three';
import { TileFlatteningPlugin } 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 );
const flattening = new TileFlatteningPlugin();
tiles.registerPlugin( flattening );
tiles.setCamera( camera );
tiles.setResolutionFromRenderer( camera, renderer );
tiles.group.rotation.x = Math.PI / 2;
scene.add( tiles.group );
camera.position.set( 20, 10, 20 );
const shape = new Mesh( new PlaneGeometry( 10, 10 ) );
shape.position.z = 1.5;
flattening.addShape( shape, new Vector3( 0, 0, 1 ) );
renderer.setAnimationLoop( () => {
camera.updateMatrixWorld();
tiles.update();
renderer.render( scene, camera );
} );Methods
hasShape( mesh: Object3D ): booleanReturns whether the given object has already been added as a shape.
addShape(
// The shape mesh to flatten tile vertices onto.
mesh: Object3D,
// Direction to cast rays when flattening (default downward along -Z).
direction?: Vector3,
options?: {
// Maximum distance from the shape surface within which vertices are flattened. `Infinity` always flattens; `0` never flattens.
threshold: number = Infinity
}
): voidAdds the given mesh as a flattening shape. All coordinates must be in the tileset's local frame. Throws if the shape has already been added.
updateShape( mesh: Object3D ): voidNotifies the plugin that a shape's geometry or transform has changed and tile flattening needs to be regenerated.
deleteShape( mesh: Object3D ): booleanRemoves the given shape and triggers tile regeneration.
clearShapes(): voidRemoves all shapes and resets flattened tiles to their original positions.