@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
76 lines (75 loc) • 3.87 kB
TypeScript
/**
* Picker object used to select mesh instances from screen coordinates.
*
* @property {number} width Width of the pick buffer in pixels (read-only).
* @property {number} height Height of the pick buffer in pixels (read-only).
* @property {RenderTarget} renderTarget The render target used by the picker internally
* (read-only).
*
* @category Graphics
*/
export class Picker {
/**
* Create a new Picker instance.
*
* @param {import('../app-base.js').AppBase} app - The application managing this picker
* instance.
* @param {number} width - The width of the pick buffer in pixels.
* @param {number} height - The height of the pick buffer in pixels.
*/
constructor(app: import("../app-base.js").AppBase, width: number, height: number);
renderTarget: any;
mapping: Map<any, any>;
renderer: import("../../index.js").ForwardRenderer;
device: GraphicsDevice;
renderPass: RenderPassPicker;
width: number;
height: number;
/**
* Return the list of mesh instances selected by the specified rectangle in the previously
* prepared pick buffer.The rectangle using top-left coordinate system.
*
* @param {number} x - The left edge of the rectangle.
* @param {number} y - The top edge of the rectangle.
* @param {number} [width] - The width of the rectangle. Defaults to 1.
* @param {number} [height] - The height of the rectangle. Defaults to 1.
* @returns {import('../../scene/mesh-instance.js').MeshInstance[]} An array of mesh instances
* that are in the selection.
* @example
* // Get the selection at the point (10,20)
* const selection = picker.getSelection(10, 20);
* @example
* // Get all models in rectangle with corners at (10,20) and (20,40)
* const selection = picker.getSelection(10, 20, 10, 20);
*/
getSelection(x: number, y: number, width?: number, height?: number): import("../../scene/mesh-instance.js").MeshInstance[];
allocateRenderTarget(): void;
releaseRenderTarget(): void;
/**
* 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, {@link Picker#getSelection} can
* be called multiple times on the same picker object. Therefore, if the models or camera do
* not change in any way, {@link Picker#prepare} does not need to be called again.
*
* @param {import('../components/camera/component.js').CameraComponent} camera - The camera
* component used to render the scene.
* @param {import('../../scene/scene.js').Scene} scene - The scene containing the pickable mesh
* instances.
* @param {Layer[]} [layers] - Layers from which objects will be picked. If not supplied, all layers of the specified camera will be used.
*/
prepare(camera: import("../components/camera/component.js").CameraComponent, scene: import("../../scene/scene.js").Scene, layers?: Layer[]): void;
/**
* 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 {@link Picker#getSelection}. On the other hand, smaller pick buffers
* will yield greater performance, so there is a trade off.
*
* @param {number} width - The width of the pick buffer in pixels.
* @param {number} height - The height of the pick buffer in pixels.
*/
resize(width: number, height: number): void;
}
import { GraphicsDevice } from '../../platform/graphics/graphics-device.js';
import { RenderPassPicker } from './render-pass-picker.js';
import { Layer } from '../../scene/layer.js';