export type IconGizmoTheme = { /** * - The color where the icons are visible. */ base: Color; /** * - The color where the scene hides the icons. */ occluded: Color; /** * - The color of the disc behind each icon, which is clicked to select it. */ backdrop: Color; }; /** * @import { CameraComponent } from '../../framework/components/camera/component.js' * @import { Entity } from '../../framework/entity.js' * @import { GraphNode } from '../../scene/graph-node.js' * @import { Layer } from '../../scene/layer.js' * @import { MeshInstance } from '../../scene/mesh-instance.js' * @import { Picker } from '../../framework/graphics/picker.js' * @import { OverlayIcon } from './overlay/icon-glyphs.js' */ /** * @typedef {object} IconGizmoTheme * @property {Color} base - The color where the icons are visible. * @property {Color} occluded - The color where the scene hides the icons. * @property {Color} backdrop - The color of the disc behind each icon, which is clicked to select it. */ /** * Draws an icon at each attached entity with nothing else to see, such as a light, camera or sound. * Entities with an enabled render, model, sprite or element component show none, and a disabled * component still shows its icon. Clicking an icon * fires {@link IconGizmo.EVENT_ICONSELECT}. The icons are {@link IconGizmo#iconSize} CSS pixels * square. * * Use a layer that keeps the scene depth, so hidden icons use the `occluded` color. * * ```javascript * const layer = Gizmo.createLayer(app, 'Overlays', undefined, true); * const gizmo = new IconGizmo(cameraComponent, layer); * gizmo.attach([lightEntity, soundEntity]); * gizmo.on('icon:select', entity => select(entity)); * ``` * * Relevant Engine API examples: * * - [Icon Gizmo](https://playcanvas.github.io/#/gizmos/icon) * - [Editor](https://playcanvas.github.io/#/misc/editor) * * @category Gizmo */ export class IconGizmo extends Gizmo { /** * Fired when the icon of an entity is clicked. * * @event * @example * const gizmo = new pc.IconGizmo(camera, layer); * gizmo.on('icon:select', (entity) => { * console.log(`Clicked the icon of ${entity.name}`); * }); */ static EVENT_ICONSELECT: string; /** * Creates a new IconGizmo object. * * @param {CameraComponent} camera - The camera component. * @param {Layer} layer - The render layer. * @example * const gizmo = new IconGizmo(camera, layer); */ constructor(camera: CameraComponent, layer: Layer); /** * Whether to draw light icons in the light color. Defaults to false. * * @type {boolean} */ useLightColor: boolean; /** * The theme. * * @type {IconGizmoTheme} * @private */ private _theme; /** * The renderer drawing the icons. * * @type {OverlayRenderer} * @private */ private _renderer; /** * Gets the current theme for the gizmo. * * @type {IconGizmoTheme} */ get theme(): IconGizmoTheme; /** * Gets the entity whose icon a mesh instance draws, such as one a {@link Picker} returns, so * an app can pick icons with the rest of its scene. * * @param {MeshInstance} meshInstance - The mesh instance. * @returns {GraphNode|null} The entity, or null when the mesh instance draws no icon. */ getIconNode(meshInstance: MeshInstance): GraphNode | null; /** * Sets the icon size in CSS pixels. Defaults to 24. * * @type {number} */ set iconSize(value: number); /** * Gets the icon size in CSS pixels. * * @type {number} */ get iconSize(): number; /** * Sets the theme or partial theme for the gizmo. * * @param {Partial} partial - The partial theme to set. * @example * gizmo.setTheme({ occluded: new Color(1, 1, 1, 0.5) }); */ setTheme(partial: Partial): void; /** * Gets the icon an entity shows. * * @param {Entity} entity - The entity. * @returns {OverlayIcon|null} The icon, or null for none. * @private */ private _iconOf; } import { Color } from '../../core/math/color.js'; import { Gizmo } from './gizmo.js'; import type { MeshInstance } from '../../scene/mesh-instance.js'; import type { GraphNode } from '../../scene/graph-node.js'; import type { CameraComponent } from '../../framework/components/camera/component.js'; import type { Layer } from '../../scene/layer.js';