API Reference

Class List

Picker

Picker object used to select mesh instances from screen coordinates.

Summary

Properties

height

Height of the pick buffer in pixels (read-only).

renderTarget

The render target used by the picker internally (read-only).

width

Width of the pick buffer in pixels (read-only).

Methods

getSelection

Return the list of mesh instances selected by the specified rectangle in the previously prepared pick buffer.

prepare

Primes the pick buffer with a rendering of the specified models from the point of view of the supplied camera.

resize

Sets the resolution of the pick buffer.

Details

Constructor

Picker(app, width, height)

Create a new Picker instance.

Parameters

appAppBase

The application managing this picker instance.

widthnumber

The width of the pick buffer in pixels.

heightnumber

The height of the pick buffer in pixels.

Properties

numberheight

Height of the pick buffer in pixels (read-only).

RenderTargetrenderTarget

The render target used by the picker internally (read-only).

numberwidth

Width of the pick buffer in pixels (read-only).

Methods

getSelection(x, y, [width], [height])

Return the list of mesh instances selected by the specified rectangle in the previously prepared pick buffer.The rectangle using top-left coordinate system.

// Get the selection at the point (10,20)
const selection = picker.getSelection(10, 20);
// Get all models in rectangle with corners at (10,20) and (20,40)
const selection = picker.getSelection(10, 20, 10, 20);

Parameters

xnumber

The left edge of the rectangle.

ynumber

The top edge of the rectangle.

widthnumber

The width of the rectangle.

heightnumber

The height of the rectangle.

Returns

MeshInstance[]

An array of mesh instances that are in the selection.

prepare(camera, scene, [layers])

Primes the pick buffer with a rendering of the specified models from the point of view of the supplied camera. Once the pick buffer has been prepared, Picker#getSelection can be called multiple times on the same picker object. Therefore, if the models or camera do not change in any way, Picker#prepare does not need to be called again.

Parameters

cameraCameraComponent

The camera component used to render the scene.

sceneScene

The scene containing the pickable mesh instances.

layersLayer[]

Layers from which objects will be picked. If not supplied, all layers of the specified camera will be used.

resize(width, height)

Sets the resolution of the pick buffer. The pick buffer resolution does not need to match the resolution of the corresponding frame buffer use for general rendering of the 3D scene. However, the lower the resolution of the pick buffer, the less accurate the selection results returned by Picker#getSelection. On the other hand, smaller pick buffers will yield greater performance, so there is a trade off.

Parameters

widthnumber

The width of the pick buffer in pixels.

heightnumber

The height of the pick buffer in pixels.