export type OverlayRendererTheme = { /** * - The color where the shapes are visible. */ base: Color; /** * - The color where the scene hides the shapes. */ occluded: Color; /** * - The color of filled volumes, needed only to place them. */ fill?: Color; /** * - The color of the icon backdrops, needed only to place icons. */ backdrop?: Color; }; /** * @typedef {object} OverlayRendererTheme * @property {Color} base - The color where the shapes are visible. * @property {Color} occluded - The color where the scene hides the shapes. * @property {Color} [fill] - The color of filled volumes, needed only to place them. * @property {Color} [backdrop] - The color of the icon backdrops, needed only to place icons. */ /** * Pooled shapes drawn each frame between {@link begin} and {@link end}: lines and rings of a * constant screen thickness, handles of a constant screen size, labels and icons. Placed in world * space under a parent that must not be rotated or scaled. * * @ignore */ export class OverlayRenderer { /** * @param {Gizmo} gizmo - The gizmo owning the shapes. * @param {OverlayRendererTheme} theme - The theme, whose colors the shapes follow. * @param {Entity} [parent] - The parent of the shapes, which must not be rotated or scaled. * Defaults to the root of the gizmo. * @param {Layer|null} [layer] - The layer of the shapes, which must keep the scene depth. * Defaults to following the layer of the gizmo. */ constructor(gizmo: Gizmo, theme: OverlayRendererTheme, parent?: Entity, layer?: Layer | null); /** * The line thickness in CSS pixels. * * @type {number} */ lineThickness: number; /** * The handle size in CSS pixels. * * @type {number} */ handleSize: number; /** * The icon size in CSS pixels. * * @type {number} */ iconSize: number; /** * The rgb replacing the theme colors, or null to keep them. * * @type {Color|null} */ tint: Color | null; /** * @type {Gizmo} * @private */ private _gizmo; /** * @type {OverlayRendererTheme} * @private */ private _theme; /** * Gets the theme the shapes follow. * * @type {OverlayRendererTheme} */ get theme(): OverlayRendererTheme; /** * @type {ShapePool[]} * @private */ private _pools; /** * @type {Pool} * @private */ private _labels; /** * The world size of a pixel at unit depth, or at any depth in orthographic. * * @private */ private _pixel; /** * @private */ private _perspective; /** * The number of draw orders taken this frame. * * @private */ private _order; /** * The layer the shapes stay on, or null to follow the layer of the gizmo. * * @type {Layer|null} * @private */ private _fixedLayer; /** * The layer of the shapes. * * @type {Layer} * @private */ private _layer; /** * The icons drawn with the shapes. * * @type {OverlayIcons} */ icons: OverlayIcons; _parent: Entity; _lines: MeshLineBatch; _rings: ShapePool; _arcs: ShapePool; _arrows: ShapePool; _boxes: ShapePool; _arms: ShapePool; _handles: ShapePool; _pickDiscs: ShapePool; _spheres: ShapePool; _capsules: ShapePool; /** * The pools of each kind of cone. * * @type {{ [K in keyof CONES]: ShapePool }} */ _cones: { [K in "cone" | "cylinder" | "frustum" | "disk" | "triangle"]: ShapePool; }; /** * The pools of each icon glyph. * * @type {Record} */ _glyphs: Record; /** * Starts a frame. */ begin(): void; /** * Moves the shapes to a layer. * * @param {Layer} layer - The layer. * @private */ private _moveTo; /** * Hides the shapes not placed this frame. */ end(): void; /** * Hides every shape and label. */ clear(): void; /** * @param {Vec3} point - The world point. * @returns {number} The distance of the point in front of the camera, unclamped. * @private */ private _viewDepth; /** * @param {Vec3} point - The world point. * @returns {number} The depth of the point, as used for perspective scaling. * @private */ private _depth; /** * @param {Vec3} point - The world point. * @param {Vec3} out - The point relative to the gizmo root. * @returns {Vec3} The point relative to the gizmo root. * @private */ private _local; /** * Sets the temporary colors from the theme. * * @param {number} alpha - The alpha factor. * @param {boolean} [volume] - Whether to use the fill color. * @param {Color|null} [color] - The color replacing the rgb, before the tint. * @private */ private _colors; /** * Places the next shape of a pool after those placed before it, recoloring it only on change. * * @param {ShapePool} pool - The pool. * @returns {Shape} The shape. * @private */ private _next; /** * Places one piece of a line. * * @param {Vec3} from - The start point. * @param {Vec3} to - The end point. * @param {number} weight - The thickness as a factor of the line thickness. * @private */ private _piece; /** * Gets the size of a sphere on screen. * * @param {Vec3} center - The world center. * @param {number} radius - The radius. * @returns {number} The approximate radius on screen in CSS pixels. */ screenSize(center: Vec3, radius: number): number; /** * Gets the world size of a screen length at a point. * * @param {Vec3} point - The world point. * @param {number} count - The length in CSS pixels. * @returns {number} The world size. */ pixels(point: Vec3, count: number): number; /** * Adds a line between two world points. * * @param {Vec3} a - The start point. * @param {Vec3} b - The end point. * @param {number} [weight] - The thickness as a factor of the line thickness. * @param {number} [alpha] - The alpha factor. * @param {Color|null} [color] - The color replacing the rgb of the theme colors. */ line(a: Vec3, b: Vec3, weight?: number, alpha?: number, color?: Color | null): void; /** * Adds a dashed line between two world points, the dashes evenly spaced on screen. * * @param {Vec3} a - The start point. * @param {Vec3} b - The end point. * @param {number} [weight] - The thickness as a factor of the line thickness. * @param {number} [alpha] - The alpha factor. * @param {Color|null} [color] - The color replacing the rgb of the theme colors. */ dashed(a: Vec3, b: Vec3, weight?: number, alpha?: number, color?: Color | null): void; /** * Adds an arc. * * @param {Vec3} center - The world center. * @param {Vec3} x - The unit direction at angle 0. * @param {Vec3} y - The unit direction at a quarter turn. * @param {number} radius - The radius. * @param {number} from - The start angle in radians. * @param {number} to - The end angle in radians. * @param {number} [weight] - The thickness as a factor of the line thickness. * @param {number} [alpha] - The alpha factor. * @param {Color|null} [color] - The color replacing the rgb of the theme colors. */ arc(center: Vec3, x: Vec3, y: Vec3, radius: number, from: number, to: number, weight?: number, alpha?: number, color?: Color | null): void; /** * Gets the tube radius of a unit torus for a constant screen thickness. * * @param {Vec3} center - The world center. * @param {number} radius - The radius. * @param {number} weight - The thickness as a factor of the line thickness. * @returns {number} The tube radius. * @private */ private _tube; /** * Adds a ring in the xz plane of the rotation. * * @param {Vec3} center - The world center. * @param {Quat} rotation - The world rotation. * @param {number} radius - The radius. * @param {number} [weight] - The thickness as a factor of the line thickness. * @param {number} [alpha] - The alpha factor. */ ring(center: Vec3, rotation: Quat, radius: number, weight?: number, alpha?: number): void; /** * Adds a ring facing the normal. * * @param {Vec3} center - The world center. * @param {Vec3} normal - The ring normal. Need not be normalized. * @param {number} radius - The radius. * @param {number} [weight] - The thickness as a factor of the line thickness. * @param {number} [alpha] - The alpha factor. */ circle(center: Vec3, normal: Vec3, radius: number, weight?: number, alpha?: number): void; /** * Adds a dashed ring facing the normal. * * @param {Vec3} center - The world center. * @param {Vec3} normal - The ring normal. Need not be normalized. * @param {number} radius - The radius. * @param {number} [weight] - The thickness as a factor of the line thickness. * @param {number} [alpha] - The alpha factor. */ dashedCircle(center: Vec3, normal: Vec3, radius: number, weight?: number, alpha?: number): void; /** * Adds an arrow along the y axis of the rotation. * * @param {Vec3} position - The world position of the arrow base. * @param {Quat} rotation - The world rotation. * @param {number} scale - The scale, as for a transform gizmo. */ arrow(position: Vec3, rotation: Quat, scale: number): void; /** * Adds a pickable handle, a cube of a constant screen size. * * @param {Vec3} position - The world position. * @param {Color|null} [hover] - The color of a hovered handle, or null for the theme color. * @returns {BoxShape} The handle shape. */ handle(position: Vec3, hover?: Color | null): BoxShape; /** * Adds a corner bracket arm along a world axis, overhanging the corner so the arms meet. * * @param {Vec3} corner - The world corner. * @param {'x' | 'y' | 'z'} axis - The world axis the arm runs along. * @param {number} sign - The side of the corner along the axis, -1 or 1. * @param {number} length - The arm length from the corner. * @param {number} thickness - The thickness in CSS pixels. */ arm(corner: Vec3, axis: "x" | "y" | "z", sign: number, length: number, thickness: number): void; /** * Adds a dot of a constant screen size. * * @param {Vec3} position - The world position. * @param {number} radius - The radius in CSS pixels. */ dot(position: Vec3, radius: number): void; /** * Adds a filled box. * * @param {Vec3} center - The world center. * @param {Quat} rotation - The world rotation. * @param {Vec3} size - The size along each axis of the rotation. * @param {number} [alpha] - The alpha factor. * @param {boolean} [volume] - Whether to use the theme fill color. * @returns {Shape} The box. */ box(center: Vec3, rotation: Quat, size: Vec3, alpha?: number, volume?: boolean): Shape; /** * Adds a filled sphere. * * @param {Vec3} center - The world center. * @param {number} radius - The radius. * @param {number} [alpha] - The alpha factor. */ sphere(center: Vec3, radius: number, alpha?: number): void; /** * Adds a filled capsule along the y axis of the rotation. * * @param {Vec3} center - The world center. * @param {Quat} rotation - The world rotation. * @param {number} radius - The radius. * @param {number} height - The height, caps included. * @param {number} [alpha] - The alpha factor. */ capsule(center: Vec3, rotation: Quat, radius: number, height: number, alpha?: number): void; /** * Adds a filled unit cone along the y axis of the rotation, its base at y = -0.5. A disk and a * triangle are meant to be flattened by the size; a cylinder keeps its radius to the peak; a * frustum is a square pyramid. * * @param {keyof CONES} kind - The kind of cone. * @param {Vec3} center - The world center. * @param {Quat} rotation - The world rotation. * @param {Vec3} size - The size along each axis of the rotation; 1 gives a base radius of 0.5. * @param {number} [alpha] - The alpha factor. * @param {boolean} [volume] - Whether to use the theme fill color. * @param {number} [peak] - The peak radius of a frustum, as a fraction of its base radius. */ cone(kind: "cone" | "cylinder" | "frustum" | "disk" | "triangle", center: Vec3, rotation: Quat, size: Vec3, alpha?: number, volume?: boolean, peak?: number): void; /** * Adds a flat disc facing the y axis of the rotation, picked by the gizmo. * * @param {Vec3} center - The world center. * @param {Quat} rotation - The world rotation. * @param {number} size - The diameter. * @param {number} [alpha] - The alpha factor. * @param {Color|null} [color] - The color replacing the rgb of the theme color. * @returns {Shape} The disc. */ disc(center: Vec3, rotation: Quat, size: number, alpha?: number, color?: Color | null): Shape; /** * Adds an icon glyph on the xz plane of the rotation, its top toward -z. * * @param {OverlayIcon} kind - The icon. * @param {Vec3} center - The world center. * @param {Quat} rotation - The world rotation. * @param {number} size - The width and height. * @returns {Shape} The glyph. */ glyph(kind: OverlayIcon, center: Vec3, rotation: Quat, size: number): Shape; /** * Copies the colors of a partial theme into the theme. * * @param {Partial} [partial] - The partial theme. */ applyTheme(partial?: Partial): void; /** * Adds a text label just below a world point. * * @param {Vec3} position - The world position. * @param {string} html - The label markup. * @param {number} [below] - The extra offset below the point, in CSS pixels. */ label(position: Vec3, html: string, below?: number): void; /** * Destroys the shapes. Safe to call again. */ destroy(): void; } import { Color } from '../../../core/math/color.js'; import { OverlayIcons } from './overlay-icons.js'; import type { Entity } from '../../../framework/entity.js'; import { MeshLineBatch } from '../mesh/mesh-line-batch.js'; import { ShapePool } from './shape-pool.js'; import type { OverlayIcon } from './icon-glyphs.js'; import { Vec3 } from '../../../core/math/vec3.js'; import { Quat } from '../../../core/math/quat.js'; import { BoxShape } from '../shape/box-shape.js'; import type { Shape } from '../shape/shape.js'; import type { Gizmo } from '../gizmo.js'; import type { Layer } from '../../../scene/layer.js';