module:extras/raypick

Back to documentation index.

### module:extras/raypick()

The extras/raypick.js module. To import all symbols in this module, either of the following can be used:

import * from "extras/raypick.js";
// -- or --
import * as CustomModuleName from "extras/raypick.js";

Methods

### (static) module:extras/raypick.raypick(x, y, projView, viewport, objects)

Finds the three-dimensional shape object and world-space coordinates corresponding to the given two-dimensional (X and Y) coordinates.

Parameters

Return Value

An object with the following properties:<ul>

  • index - Index, starting from 0, into the objects array of the shape object that was picked. Is -1 if no object was picked (and the "local" and "world" properties will be absent).
  • local - 3-element array giving the X, Y, and Z coordinates of the picked point in object (model) space.
  • world - 3-element array giving the X, Y, and Z coordinates of the picked point in world space.</ul> #### Examples The following example shows how a hypothetical scene graph could implement picking objects based on the position of the mouse cursor. var mousePos = scene.getMousePosInPixels(); var viewport = [0, 0, scene.getWidth(), scene.getHeight()]; var projview = scene.getProjectionViewMatrix(); var o = raypick(mousePos.cx, mousePos.cy, projview, viewport, objects); if(o.index >= 0) { pickedShape = objects[o.index]; } else { pickedShape = null; } [Back to documentation index.](index.html)