Engine API Reference - v2.24.0-beta.28
    Preparing search index...

    Class TranslateGizmo

    Handles for moving Entitys: arrows along the X, Y and Z axes, planes between them and a center sphere that moves in the view plane. Works with mouse, keyboard and touch input.

    // Create a layer for rendering all gizmos
    const gizmoLayer = Gizmo.createLayer(app);

    // Create a translate gizmo
    const gizmo = new TranslateGizmo(cameraComponent, gizmoLayer);

    // Create an entity to attach the gizmo to
    const entity = new Entity();
    entity.addComponent('render', {
    type: 'box'
    });
    app.root.addChild(entity);

    // Attach the gizmo to the entity
    gizmo.attach([entity]);

    Relevant Engine API examples:

    Hierarchy (View Summary)

    Index
    _app: AppBase

    The app.

    The camera viewing the gizmo.

    _coordSpace: GizmoSpace = 'world'

    The coordinate space.

    The graphics device.

    _fadeAngle: number = 25

    The angle in degrees between the view and a shape below which it fades out.

    _handles: EventHandle[] = []

    The app event handles.

    _layer: Layer

    The render layer.

    _mouseButtons: [boolean, boolean, boolean] = ...

    The mouse buttons that interact.

    _readout: Readout | null = null

    The readout of the drag delta.

    _renderUpdate: boolean = false

    Whether a render update is due.

    _rootStartPos: Vec3 = ...

    The gizmo position at the start of a drag.

    _rootStartRot: Quat = ...

    The gizmo rotation at the start of a drag.

    _scale: number = 1

    The gizmo scale.

    _selectedAxis: "" | GizmoAxis = ''

    The selected axis.

    _selectedIsPlane: boolean = false

    Whether the selected shape is a plane.

    _selectionStartPoint: Vec3 = ...

    The selected point at the start of a drag, in world space.

    _shapes: {
        x: ArrowShape;
        xy: PlaneShape;
        xyz: SphereShape;
        xz: PlaneShape;
        y: ArrowShape;
        yz: PlaneShape;
        z: ArrowShape;
    } = ...

    The gizmo shapes.

    _theme: GizmoTheme = ...

    Internal theme.

    dragMode: GizmoDragMode = 'selected'

    Whether to hide the shapes when dragging. Defaults to 'selected'.

    flipPlanes: boolean = true

    Flips the planes to face the camera.

    intersectShapes: Shape[] = []

    The shapes the gizmo picks.

    nodes: GraphNode[] = []

    The graph nodes attached to the gizmo.

    preventDefault: boolean = true

    Whether to call preventDefault on pointer events.

    root: Entity

    The root gizmo entity.

    snap: boolean = false

    Whether dragging snaps to the increments. Defaults to false.

    snapAngleIncrement: number = 5

    The increment angles snap to, in degrees. Defaults to 5.

    • get _requiresNodes(): boolean
      Protected

      Gets whether the gizmo shows only with attached nodes. A getter, so a subclass's value applies while the base constructor runs.

      Returns boolean

    • get enabled(): boolean

      Gets the gizmo enabled state.

      Returns boolean

    • set enabled(state: boolean): void

      Sets the gizmo enabled state.

      Parameters

      • state: boolean

      Returns void

    • get mouseButtons(): [boolean, boolean, boolean]

      The mouse buttons that interact with the gizmo, by button index: 0 left, 1 middle, 2 right.

      Returns [boolean, boolean, boolean]

    • get size(): number

      Gets the gizmo size.

      Returns number

    • set size(value: number): void

      Sets the gizmo size. Defaults to 1.

      Parameters

      • value: number

      Returns void

    • get snapIncrement(): number

      Gets the increment lengths and ScaleGizmo factors snap to.

      Returns number

    • set snapIncrement(value: number): void

      Sets the increment lengths and ScaleGizmo factors snap to. Defaults to 1.

      Parameters

      • value: number

      Returns void

    • Protected

      Hides a shape when the view looks along its direction, fading it over the fade angle.

      Parameters

      • shape: Shape

        The shape.

      • cos: number

        The absolute cosine of the angle between the view and the direction.

      Returns boolean

      Whether the visibility changed.

    • Protected

      Gets the normal of the plane through a line that best faces the camera, for dragging along the line.

      Parameters

      • dir: Vec3

        The unit direction of the line.

      • facing: Vec3

        The unit direction towards the camera.

      • out: Vec3

        Receives the unit normal.

      Returns boolean

      False when the line points at the camera.

    • Protected

      Formats a delta with an explicit sign, positive when it rounds to zero.

      Parameters

      • value: number

        The value.

      • digits: number

        The number of digits after the decimal point.

      Returns string

      The signed value.

    • Protected

      Rounds a value to a multiple of an increment while snapping.

      Parameters

      • value: number

        The value.

      • increment: number

        The increment.

      Returns number

      The value, snapped while DragGizmo#snap is on.

    • Detaches all graph nodes from the gizmo.

      Returns void

      const gizmo = new Gizmo(camera, layer);
      gizmo.attach([boxA, boxB]);
      gizmo.detach();
    • Fire an event, all additional arguments are passed on to the event listener.

      Parameters

      • name: string

        Name of event to fire.

      • Optionalarg1: any

        First argument that is passed to the event handler.

      • Optionalarg2: any

        Second argument that is passed to the event handler.

      • Optionalarg3: any

        Third argument that is passed to the event handler.

      • Optionalarg4: any

        Fourth argument that is passed to the event handler.

      • Optionalarg5: any

        Fifth argument that is passed to the event handler.

      • Optionalarg6: any

        Sixth argument that is passed to the event handler.

      • Optionalarg7: any

        Seventh argument that is passed to the event handler.

      • Optionalarg8: any

        Eighth argument that is passed to the event handler.

      Returns EventHandler

      Self for chaining.

      obj.fire('test', 'This is the message');
      
    • Test if there are any handlers bound to an event name.

      Parameters

      • name: string

        The name of the event to test.

      Returns boolean

      True if the object has handlers bound to the specified event name.

      obj.on('test', () => {}); // bind an event to 'test'
      obj.hasEvent('test'); // returns true
      obj.hasEvent('hello'); // returns false
    • Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

      Use this form to remove all listeners matching a name (and optionally callback/scope). To remove a single known subscription, prefer retaining the EventHandle returned by EventHandler#on / EventHandler#once and calling its EventHandle#off: it removes exactly that subscription and is faster (no scan of the callback list).

      Parameters

      • Optionalname: string

        Name of the event to unbind.

      • Optionalcallback: HandleEventCallback

        Function to be unbound.

      • Optionalscope: any

        Scope that was used as the this when the event is fired.

      Returns EventHandler

      Self for chaining.

      const handler = () => {};
      obj.on('test', handler);

      obj.off(); // Removes all events
      obj.off('test'); // Removes all events called 'test'
      obj.off('test', handler); // Removes all handler functions, called 'test'
      obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
    • Attach an event handler to an event.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      An event handle. For later removal, prefer retaining this handle and calling its EventHandle#off over EventHandler#off with a name/callback: it removes exactly this subscription and is faster (no scan of the callback list).

      obj.on('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      // preferred removal: retain the handle and call off() on it
      const evt = obj.on('test', (a, b) => {
      console.log(a + b);
      });
      // some time later
      evt.off();
    • Attach an event handler to an event. The handler is removed before it is called, so it runs at most once, even if it fires the same event again or throws.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      An event handle. For removal before it fires, prefer retaining this handle and calling its EventHandle#off over EventHandler#off with a name/callback: it removes exactly this subscription and is faster (no scan of the callback list).

      obj.once('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      obj.fire('test', 1, 2); // not going to get handled
    • Updates the gizmo position, rotation, and scale.

      Returns void

      const gizmo = new Gizmo(camera, layer);
      gizmo.attach([boxA, boxB]);
      gizmo.update();
    • Creates a new gizmo layer and adds it to the scene.

      Parameters

      • app: AppBase

        The app.

      • OptionallayerName: string = 'Gizmo'

        The layer name. Defaults to 'Gizmo'.

      • OptionallayerIndex: number = app.scene.layers.layerList.length

        The layer index. Defaults to the end of the layer list.

      • Optionaldepth: boolean = false

        Whether the layer keeps the scene depth and sorts transparent mesh instances manually, as overlay gizmos need so occluded parts draw faint. Otherwise it clears depth and draws on top, as transform gizmos need. Defaults to false.

      Returns Layer

      The new layer.

      const layer = Gizmo.createLayer(app, 'Overlays', undefined, true);
      
    EVENT_NODESATTACH: string = 'nodes:attach'

    Fired when graph nodes are attached.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('nodes:attach', () => {
    console.log('Graph nodes attached');
    });
    EVENT_NODESDETACH: string = 'nodes:detach'

    Fired when graph nodes are detached.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('nodes:detach', () => {
    console.log('Graph nodes detached');
    });
    EVENT_POINTERDOWN: string = 'pointer:down'

    Fired when the pointer is down on the gizmo.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('pointer:down', (x, y, meshInstance) => {
    console.log(`Pointer was down on ${meshInstance.node.name} at ${x}, ${y}`);
    });
    EVENT_POINTERMOVE: string = 'pointer:move'

    Fired when the pointer is moving over the gizmo.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('pointer:move', (x, y, meshInstance) => {
    console.log(`Pointer was moving on ${meshInstance.node.name} at ${x}, ${y}`);
    });
    EVENT_POINTERUP: string = 'pointer:up'

    Fired when the pointer is up off the gizmo.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('pointer:up', (x, y, meshInstance) => {
    console.log(`Pointer was up on ${meshInstance.node.name} at ${x}, ${y}`);
    })
    EVENT_POSITIONUPDATE: string = 'position:update'

    Fired when the gizmo's position is updated.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('position:update', (position) => {
    console.log(`The gizmo's position was updated to ${position}`);
    })
    EVENT_RENDERUPDATE: string = 'render:update'

    Fired when the gizmo render has updated.

    const gizmo = new TransformGizmo(camera, layer);
    gizmo.on('render:update', () => {
    console.log('Gizmo render has been updated');
    });
    EVENT_ROTATIONUPDATE: string = 'rotation:update'

    Fired when the gizmo's rotation is updated.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('rotation:update', (rotation) => {
    console.log(`The gizmo's rotation was updated to ${rotation}`);
    });
    EVENT_SCALEUPDATE: string = 'scale:update'

    Fired when the gizmo's scale is updated.

    const gizmo = new Gizmo(camera, layer);
    gizmo.on('scale:update', (scale) => {
    console.log(`The gizmo's scale was updated to ${scale}`);
    });
    EVENT_TRANSFORMEND: string = 'transform:end'

    Fired when the transformation has ended.

    const gizmo = new TransformGizmo(camera, layer);
    gizmo.on('transform:end', () => {
    console.log('Transformation ended');
    });
    EVENT_TRANSFORMMOVE: string = 'transform:move'

    Fired during the transformation with the dragged point and the pointer's screen position.

    const gizmo = new TransformGizmo(camera, layer);
    gizmo.on('transform:move', (point, x, y) => {
    console.log(`Transformation moved to ${point} (screen: ${x}, ${y})`);
    });
    EVENT_TRANSFORMREADOUT: string = 'transform:readout'

    Fired with the readout value at the start and each step of the transformation, even with 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.

    const gizmo = new TranslateGizmo(camera, layer);
    gizmo.readout = false;
    gizmo.on('transform:readout', (axis, isPlane, value) => {
    console.log(`Transformation ${axis}: ${value}`);
    });
    EVENT_TRANSFORMSTART: string = 'transform:start'

    Fired when the transformation has started.

    const gizmo = new TransformGizmo(camera, layer);
    gizmo.on('transform:start', () => {
    console.log('Transformation started');
    });