export type GizmoTheme = { /** * - The axis colors. */ shapeBase: { [K in "x" | "y" | "z" | "f" | "xyz"]: Color; }; /** * - The hover colors. */ shapeHover: { [K in "x" | "y" | "z" | "f" | "xyz"]: Color; }; /** * - The guide line colors. */ guideBase: { [K in "x" | "y" | "z"]: Color; }; /** * - The guide occlusion value. Defaults to 0.8. */ guideOcclusion: number; /** * - The disabled color. */ disabled: Color; }; /** * The base class of {@link TranslateGizmo}, {@link RotateGizmo} and {@link ScaleGizmo}. It * provides the axis, plane and center shapes, the transform events, {@link snap}, * {@link dragMode} and a color {@link theme}; subclasses decide what a drag does to the nodes. * * @category Gizmo */ export class TransformGizmo extends DragGizmo { /** * Fired when the transformation has started. * * @event * @example * const gizmo = new TransformGizmo(camera, layer); * gizmo.on('transform:start', () => { * console.log('Transformation started'); * }); */ static EVENT_TRANSFORMSTART: string; /** * Fired during the transformation with the dragged point and the pointer's screen position. * * @event * @example * const gizmo = new TransformGizmo(camera, layer); * gizmo.on('transform:move', (point, x, y) => { * console.log(`Transformation moved to ${point} (screen: ${x}, ${y})`); * }); */ static EVENT_TRANSFORMMOVE: string; /** * Fired with the readout value at the start and each step of the transformation, even with * {@link TransformGizmo#readout} off. The handler gets the axis, whether it is a plane, and the * value: a `Vec3` translation or scale factor, or an angle in degrees. Copy the reused `Vec3` * to keep it. * * @event * @example * const gizmo = new TranslateGizmo(camera, layer); * gizmo.readout = false; * gizmo.on('transform:readout', (axis, isPlane, value) => { * console.log(`Transformation ${axis}: ${value}`); * }); */ static EVENT_TRANSFORMREADOUT: string; /** * Fired when the transformation has ended. * * @event * @example * const gizmo = new TransformGizmo(camera, layer); * gizmo.on('transform:end', () => { * console.log('Transformation ended'); * }); */ static EVENT_TRANSFORMEND: string; /** * Internal theme. * * @type {GizmoTheme} * @protected */ protected _theme: GizmoTheme; /** * The gizmo position at the start of a drag. * * @protected */ protected _rootStartPos: Vec3; /** * The gizmo rotation at the start of a drag. * * @protected */ protected _rootStartRot: Quat; /** * The gizmo shapes. * * @type {{ [key in GizmoAxis]?: Shape }} * @protected */ protected _shapes: { [key in GizmoAxis]?: Shape; }; /** * The shapes by mesh instance. * * @type {Map} * @private */ private _shapeMap; /** * The guide line colors, whose rgb each guide replaces with its axis color. * * @private */ private _guideTheme; /** * The parent of the guide lines. * * @type {Entity} * @private */ private _guideRoot; /** * The guide lines. * * @type {OverlayRenderer} * @private */ private _guides; /** * The angle in degrees between the view and a shape below which it fades out. * * @protected */ protected _fadeAngle: number; /** * The hovered axes. * * @type {Set} * @private */ private _hovering; /** * The hovered axis. * * @type {GizmoAxis | ''} * @private */ private _hoverAxis; /** * Whether the hovered shape is a plane. * * @private */ private _hoverIsPlane; /** * The selected axis. * * @type {GizmoAxis | ''} * @protected */ protected _selectedAxis: GizmoAxis | ""; /** * Whether the selected shape is a plane. * * @protected */ protected _selectedIsPlane: boolean; /** * The selected point at the start of a drag, in world space. * * @protected */ protected _selectionStartPoint: Vec3; /** * The readout of the drag delta. * * @type {Readout | null} * @protected */ protected _readout: Readout | null; /** * Whether to hide the shapes when dragging. Defaults to 'selected'. * * @type {GizmoDragMode} */ dragMode: GizmoDragMode; /** * Sets whether to show the drag delta in a `div.gizmo-readout` below the gizmo. For a custom * UI, turn this off and listen to {@link TransformGizmo.EVENT_TRANSFORMREADOUT}. Defaults to * true. * * @type {boolean} */ set readout(value: boolean); /** * Gets whether to show the drag delta below the gizmo. * * @type {boolean} */ get readout(): boolean; /** * Gets the current theme for the gizmo. * * @type {GizmoTheme} */ get theme(): GizmoTheme; /** * Sets the thickness of the guide lines in CSS pixels. Defaults to 1. * * @type {number} */ set guideThickness(value: number); /** * Gets the thickness of the guide lines in CSS pixels. * * @type {number} */ get guideThickness(): number; /** * @type {Color} * @deprecated Use {@link setTheme} instead. * @ignore */ set xAxisColor(value: Color); /** * @type {Color} * @deprecated Use {@link theme} instead. * @ignore */ get xAxisColor(): Color; /** * @type {Color} * @deprecated Use {@link setTheme} instead. * @ignore */ set yAxisColor(value: Color); /** * @type {Color} * @deprecated Use {@link theme} instead. * @ignore */ get yAxisColor(): Color; /** * @type {Color} * @deprecated Use {@link setTheme} instead. * @ignore */ set zAxisColor(value: Color); /** * @type {Color} * @deprecated Use {@link theme} instead. * @ignore */ get zAxisColor(): Color; /** * @type {number} * @deprecated Use {@link setTheme} instead. * @ignore */ set colorAlpha(value: number); /** * @type {number} * @deprecated Use {@link theme} instead. * @ignore */ get colorAlpha(): number; /** * @type {boolean} * @protected */ protected get _dragging(): boolean; /** * @param {MeshInstance} [meshInstance] - The mesh instance. * @returns {GizmoAxis | ''} - The axis. * @private */ private _getAxis; /** * @param {MeshInstance} [meshInstance] - The mesh instance. * @returns {boolean} - Whether the mesh instance is a plane. * @private */ private _getIsPlane; /** * Formats an axis letter in the axis color. * * @param {GizmoAxis} axis - The axis. * @returns {string} The label markup. * @protected */ protected _readoutLabel(axis: GizmoAxis): string; /** * Formats a delta with an explicit sign, positive when it rounds to zero. * * @param {number} value - The value. * @param {number} digits - The number of digits after the decimal point. * @returns {string} The signed value. * @protected */ protected _readoutDelta(value: number, digits: number): string; /** * Formats a value for each of the axes being dragged. * * @param {Vec3} values - The value for each axis. * @param {boolean} [factor] - Whether the values are factors, not deltas. Defaults to false. * @returns {string} The readout markup. * @protected */ protected _readoutAxes(values: Vec3, factor?: boolean): string; /** * Shows the readout centered below the visible shapes. * * @param {string} html - The readout markup. * @protected */ protected _showReadout(html: string): void; /** * @param {MeshInstance} [meshInstance] - The mesh instance. * @private */ private _hover; /** * @param {string} axis - The axis to create the plane for. * @param {boolean} isFacing - Whether the axis is facing the camera. * @param {boolean} isLine - Whether the axis is a line. * @returns {Plane} - The plane. * @protected */ protected _createPlane(axis: string, isFacing: boolean, isLine: boolean): Plane; /** * @param {string} axis - The axis * @param {Vec3} dir - The direction * @returns {Vec3} - The direction * @protected */ protected _dirFromAxis(axis: string, dir: Vec3): Vec3; /** * @param {Vec3} point - The point to project. * @param {string} axis - The axis to project to. * @protected */ protected _projectToAxis(point: Vec3, axis: string): void; /** * @param {number} x - The x coordinate. * @param {number} y - The y coordinate. * @param {boolean} isFacing - Whether the axis is facing the camera. * @param {boolean} isLine - Whether the axis is a line. * @returns {Vec3} The point (space is {@link Gizmo#coordSpace}). * @protected */ protected _screenToPoint(x: number, y: number, isFacing?: boolean, isLine?: boolean): Vec3; /** * @param {Vec3} pos - The position. * @param {Quat} rot - The rotation. * @param {GizmoAxis | ''} activeAxis - The active axis. * @param {boolean} activeIsPlane - Whether the active axis is a plane. * @protected */ protected _drawGuideLines(pos: Vec3, rot: Quat, activeAxis: GizmoAxis | "", activeIsPlane: boolean): void; /** * @param {Vec3} pos - The position. * @param {Quat} rot - The rotation. * @param {'x' | 'y' | 'z'} axis - The axis. * @protected */ protected _drawSpanLine(pos: Vec3, rot: Quat, axis: "x" | "y" | "z"): void; /** * Hides a shape when the view looks along its direction, fading it over the fade angle. * * @param {Shape} shape - The shape. * @param {number} cos - The absolute cosine of the angle between the view and the direction. * @returns {boolean} Whether the visibility changed. * @protected */ protected _glance(shape: Shape, cos: number): boolean; /** * @protected */ protected _createTransform(): void; /** * Set the shape to be enabled or disabled. * * @param {GizmoAxis | 'face'} shapeAxis - The shape axis. * @param {boolean} enabled - The enabled state of shape. */ setShapeEnabled(shapeAxis: GizmoAxis | "face", enabled: boolean): void; /** * Get the enabled state of the shape. * * @param {GizmoAxis | 'face'} shapeAxis - The shape axis. * @returns {boolean} - Whether the shape is enabled. */ isShapeEnabled(shapeAxis: GizmoAxis | "face"): boolean; /** * Sets the theme or partial theme for the gizmo. * * @param {{ [K in keyof GizmoTheme]?: Partial }} partial - The partial theme to set. */ setTheme(partial: { [K in keyof GizmoTheme]?: Partial; }): void; /** * @param {GizmoAxis | 'face'} shapeAxis - The shape axis. * @param {boolean} enabled - The enabled state of shape. * @deprecated Use {@link TransformGizmo#setShapeEnabled} instead. * @ignore */ enableShape(shapeAxis: GizmoAxis | "face", enabled: boolean): void; } import { Color } from '../../../core/math/color.js'; import { DragGizmo } from '../drag-gizmo.js'; import { Vec3 } from '../../../core/math/vec3.js'; import { Quat } from '../../../core/math/quat.js'; import type { GizmoAxis } from '../constants.js'; import type { Shape } from '../shape/shape.js'; import { Readout } from '../overlay/readout.js'; import type { GizmoDragMode } from '../constants.js'; import { Plane } from '../../../core/shape/plane.js';