playcanvas
Version:
PlayCanvas WebGL game engine
103 lines (102 loc) • 5.22 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 {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: AppBase, width: number, height: number);
renderTarget: any;
mapping: Map<any, any>;
deviceValid: boolean;
renderer: import("../../index.js").ForwardRenderer;
device: import("../../index.js").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.
*
* Note: This function is not supported on WebGPU. Use {@link Picker#getSelectionAsync} instead.
* Note: This function is blocks the main thread while reading pixels from GPU memory. It's
* recommended to use {@link Picker#getSelectionAsync} instead.
*
* @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 {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): MeshInstance[];
/**
* Return the list of mesh instances selected by the specified rectangle in the previously
* prepared pick buffer. The rectangle uses top-left coordinate system.
*
* This method is asynchronous and does not block the execution.
*
* @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 {Promise<MeshInstance[]>} - Promise that resolves with an array of mesh instances
* that are in the selection.
* @example
* // Get the mesh instances at the rectangle with start at (10,20) and size of (5,5)
* picker.getSelectionAsync(10, 20, 5, 5).then((meshInstances) => {
* console.log(meshInstances);
* });
*/
getSelectionAsync(x: number, y: number, width?: number, height?: number): Promise<MeshInstance[]>;
sanitizeRect(x: any, y: any, width: any, height: any): Vec4;
decodePixels(pixels: any, mapping: any): any[];
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 {CameraComponent} camera - The camera component used to render the scene.
* @param {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: CameraComponent, scene: 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 { RenderPassPicker } from './render-pass-picker.js';
import type { MeshInstance } from '../../scene/mesh-instance.js';
import { Vec4 } from '../../core/math/vec4.js';
import type { CameraComponent } from '../components/camera/component.js';
import type { Scene } from '../../scene/scene.js';
import { Layer } from '../../scene/layer.js';
import type { AppBase } from '../app-base.js';