# TilesRenderer

class in `3d-tiles-renderer/three`, extends `TilesRendererBase`

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

Three.js implementation of a 3D Tiles renderer. Extends `TilesRendererBase` with
camera management, three.js scene integration, and GPU-accelerated tile loading.
Add `tiles.group` to your scene and call `tiles.update()` each frame.

Every object in a loaded tile's scene is stamped with a `userData.tile` back-reference to
its owning tile, so a raycast hit, click target, or debug inspector can resolve the tile
directly from any intersected object without walking the hierarchy or consulting the renderer.

Example: Loading and rendering a tileset

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

// 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.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 );

} );
```

## Properties

### .autoDisableRendererCulling: boolean

default `true`

If `true`, all tile meshes automatically have `frustumCulled` set to `false` since the
tiles renderer performs its own frustum culling. If `displayActiveTiles` is `true` or
multiple cameras are being used, consider setting this to `false`.

### .accelerateRaycast: boolean

default `true`

Whether to use the bounding-volume hierarchy to accelerate raycasting. When disabled,
all active tile geometry is tested directly. Useful for tilesets with inaccurate
bounding volumes (e.g. Google Photorealistic Tiles) where traversal may miss
geometry between bounding volumes.

### .group: Group

The container `Group` for the 3D tiles. Add this to the three.js scene. The group
also exposes a `matrixWorldInverse` field for transforming objects into the local
tileset frame.

### .ellipsoid: Ellipsoid

default `WGS84_ELLIPSOID`

The ellipsoid definition used for the tileset. May be overridden by the
`3DTILES_ellipsoid` extension. Specified in the local frame of `TilesRenderer.group`.

### .surface: Object

default `this.ellipsoid`

The surface definition used to map between cartographic values and the tile geometry
in the local frame of `TilesRenderer.group`. Defaults to the ellipsoid and may be
reassigned by plugins that flatten or reproject the tile geometry.

### .cameras: Array<Camera>

Array of cameras registered with this renderer.

### .manager: LoadingManager

default `new LoadingManager()`

The `LoadingManager` used when loading tile geometry.

## Methods

### .getBoundingBox

```js
.getBoundingBox( target: Box3 ): boolean
```

Returns the axis-aligned bounding box of the root tile in the group's local space.

- `target`, `Box3`: Target box to write into.

Returns `boolean`: Whether the tileset is loaded and a bounding box is available.

### .getOrientedBoundingBox

```js
.getOrientedBoundingBox( targetBox: Box3, targetMatrix: Matrix4 ): boolean
```

Returns the oriented bounding box and transform of the root tile.

- `targetBox`, `Box3`: Target box to write into (in local OBB space).
- `targetMatrix`, `Matrix4`: Transform from OBB local space to group local space.

Returns `boolean`: Whether the tileset is loaded and an OBB is available.

### .getBoundingSphere

```js
.getBoundingSphere( target: Sphere ): boolean
```

Returns the bounding sphere of the root tile in the group's local space.

- `target`, `Sphere`: Target sphere to write into.

Returns `boolean`: Whether the tileset is loaded and a bounding sphere is available.

### .forEachLoadedModel

```js
.forEachLoadedModel( callback: function )
```

Iterates over all currently loaded tile scenes.

- `callback`, `function`: Called with `( scene: Object3D, tile: object )` for each loaded tile.

### .raycast

```js
.raycast( raycaster: Raycaster, intersects: Array )
```

Performs a raycast against all loaded tile scenes. Compatible with Three.js raycasting.
Supports `raycaster.firstHitOnly` for early termination.

- `raycaster`, `Raycaster`
- `intersects`, `Array`: Array to push intersection results into.

### .hasCamera

```js
.hasCamera( camera: Camera ): boolean
```

Returns whether the given camera is registered with this renderer.

- `camera`, `Camera`

### .setCamera

```js
.setCamera( camera: Camera ): boolean
```

Registers a camera with the renderer so it is used for tile selection and screen-space error
calculation. Use `setResolution` or `setResolutionFromRenderer` to provide the camera's resolution.

- `camera`, `Camera`

Returns `boolean`: Whether the camera was newly added.

### .setResolution

```js
.setResolution( camera: Camera, xOrVec: number | Vector2, y?: number ): boolean
```

Sets the render resolution for a registered camera, used for screen-space error calculation.

- `camera`, `Camera`: A previously registered camera.
- `xOrVec`, `number | Vector2`: Render width in pixels, or a Vector2 containing width and height.
- `y`, `number`, optional: Render height in pixels when `xOrVec` is a number.

Returns `boolean`: Whether the camera is registered and the resolution was updated.

### .getResolution

```js
.getResolution( camera: Camera, target: Vector2 ): Vector2 | null
```

Returns the render resolution previously set for a registered camera.

- `camera`, `Camera`: A previously registered camera.
- `target`, `Vector2`: Vector2 to write the result into.

Returns `Vector2 | null`: The target with width/height filled in, or null if the camera is not registered.

### .setResolutionFromRenderer

```js
.setResolutionFromRenderer( camera: Camera, renderer: WebGLRenderer ): boolean
```

Sets the render resolution for a camera by reading the current size from a WebGLRenderer.

- `camera`, `Camera`: A previously registered camera.
- `renderer`, `WebGLRenderer`

Returns `boolean`: Whether the camera is registered and the resolution was updated.

### .deleteCamera

```js
.deleteCamera( camera: Camera ): boolean
```

Unregisters a camera from the renderer.

- `camera`, `Camera`

Returns `boolean`: Whether the camera was found and removed.
