# XrMeshDetection

Class · extends [`EventHandler`](https://api.playcanvas.com/engine/classes/EventHandler.md) · category: XR

Source: https://github.com/playcanvas/engine/blob/b5b983982a9860d21e0c1dafb2f85f72e2c01afb/src/framework/xr/xr-mesh-detection.js#L28

Mesh Detection provides the ability to detect real world meshes based on the
scanning and reconstruction by the underlying AR system.

```javascript
// start session with plane detection enabled
app.xr.start(camera, XRTYPE_AR, XRSPACE_LOCALFLOOR, {
    meshDetection: true
});
```

```javascript
app.xr.meshDetection.on('add', (mesh) => {
    // new mesh been added
});
```

## Accessors

### available

```ts
get available(): boolean
```

True if Mesh Detection is available. This information is available only when session has started.

### meshes

```ts
get meshes(): XrMesh[]
```

Array of [XrMesh](https://api.playcanvas.com/engine/classes/XrMesh.md) instances that contain transform, vertices and label information.

### supported

```ts
get supported(): boolean
```

True if Mesh Detection is supported.

## Events

### EVENT_ADD

```ts
static EVENT_ADD: string = 'add'
```

Fired when new [XrMesh](https://api.playcanvas.com/engine/classes/XrMesh.md) is added to the list. The handler is passed the [XrMesh](https://api.playcanvas.com/engine/classes/XrMesh.md)
instance that has been added.

**Example**

```ts
app.xr.meshDetection.on('add', (mesh) => {
    // a new XrMesh has been added
});
```

### EVENT_AVAILABLE

```ts
static EVENT_AVAILABLE: string = 'available'
```

Fired when mesh detection becomes available.

**Example**

```ts
app.xr.meshDetection.on('available', () => {
    console.log('Mesh detection is available');
});
```

### EVENT_REMOVE

```ts
static EVENT_REMOVE: string = 'remove'
```

Fired when a [XrMesh](https://api.playcanvas.com/engine/classes/XrMesh.md) is removed from the list. The handler is passed the
[XrMesh](https://api.playcanvas.com/engine/classes/XrMesh.md) instance that has been removed.

**Example**

```ts
app.xr.meshDetection.on('remove', (mesh) => {
    // XrMesh has been removed
});
```

### EVENT_UNAVAILABLE

```ts
static EVENT_UNAVAILABLE: string = 'unavailable'
```

Fired when mesh detection becomes unavailable.

**Example**

```ts
app.xr.meshDetection.on('unavailable', () => {
    console.log('Mesh detection is unavailable');
});
```

## Inherited from [EventHandler](https://api.playcanvas.com/engine/classes/EventHandler.md)

- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
