# TilesRenderer

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

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

PlayCanvas implementation of the 3D Tiles renderer. Manages tile loading, caching, traversal and
the PlayCanvas entity hierarchy. Tile content is loaded through the engine's glTF parser.

> **Warning:** Only `glTF`, `GLB` and `B3DM` content, and `box` and `sphere` bounding volumes are
supported.

Example: Loading and rendering a tileset

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

// app and camera 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, app );
tiles.setCamera( camera.camera );
tiles.group.setLocalEulerAngles( 90, 0, 0 );
app.root.addChild( tiles.group );
app.on( 'update', () => tiles.update() );
```

## Constructor

```js
new TilesRenderer( url: string, app: AppBase )
```

- `url`, `string`: URL of the root tileset JSON.
- `app`, `AppBase`: The PlayCanvas application to create the tiles for.

## Properties

### .app: AppBase

The PlayCanvas application the tiles are created for.

### .group: Entity

Root entity that all visible tiles are parented to. Add it to the scene hierarchy, and
transform it to place the tileset.

### .cameras: Array<CameraComponent>

Cameras used to calculate the screen space error and visibility of tiles. Use
`TilesRenderer#setCamera` and `TilesRenderer#deleteCamera` to change it.

### .assetOptions: Object | null

Options passed to the `container` asset of every tile, such as glTF parser callbacks.

### .renderOptions: Object | null

Options passed to the render components created for every tile, such as `castShadows`
or `layers`.

## Methods

### .addEventListener

```js
.addEventListener( type: string, listener: function )
```

Registers a listener for the given event type. The listener receives the event object.

- `type`, `string`
- `listener`, `function`

### .hasEventListener

```js
.hasEventListener( type: string, listener: function ): boolean
```

- `type`, `string`
- `listener`, `function`

### .removeEventListener

```js
.removeEventListener( type: string, listener: function )
```

Removes a previously registered listener.

- `type`, `string`
- `listener`, `function`

### .dispatchEvent

```js
.dispatchEvent( event: Object )
```

- `event`, `Object`

### .on

```js
.on( type: string, listener: function ): this
```

Alias of `TilesRenderer#addEventListener`, matching the PlayCanvas event API.

- `type`, `string`
- `listener`, `function`

### .off

```js
.off( type: string, listener: function ): this
```

Alias of `TilesRenderer#removeEventListener`, matching the PlayCanvas event API.

- `type`, `string`
- `listener`, `function`

### .hasCamera

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

- `camera`, `CameraComponent`

### .setCamera

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

Adds a camera used to calculate tile visibility and screen space error. The render
resolution is read every frame: the size of the camera's render target in pixels, or the size
of the canvas in CSS pixels.

- `camera`, `CameraComponent`

Returns `boolean`: False if the camera was already added.

### .deleteCamera

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

- `camera`, `CameraComponent`

Returns `boolean`: False if the camera was not added.

### .forEachLoadedModel

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

Calls the callback for every tile with loaded content.

- `callback`, `function`: Called with the tile's entity and the tile.

### .dispose

```js
.dispose(  )
```

Disposes the renderer, releasing all loaded tile content and the root entity.
