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

    Class Gizmo

    The base class for all gizmos.

    A gizmo draws in its own Layer (see createLayer) for a CameraComponent, acts on the GraphNodes passed to attach, and updates itself each frame until destroy. Where gizmos overlap, a press goes to the first one created that it hits, so create the gizmos that should win, such as transform gizmos, first.

    Hierarchy (View Summary)

    Index
    • Creates a new Gizmo object.

      Parameters

      • camera: CameraComponent

        The camera component.

      • layer: Layer

        The render layer, added to the camera. Gizmos can share it; it leaves the camera with the last gizmo using it there.

      • Optionalname: string = 'gizmo'

        The name of the gizmo. Defaults to 'gizmo'.

      Returns Gizmo

      const gizmo = new Gizmo(camera, layer);
      
    _app: AppBase

    The app.

    The camera viewing the gizmo.

    _coordSpace: GizmoSpace = 'world'

    The coordinate space.

    The graphics device.

    _handles: EventHandle[] = []

    The app event handles.

    _layer: Layer

    The render layer.

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

    The mouse buttons that interact.

    _renderUpdate: boolean = false

    Whether a render update is due.

    _scale: number = 1

    The gizmo scale.

    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.

    • 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 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]

    • Protected

      Gets the scale keeping geometry at a world position a constant size on screen.

      Parameters

      • pos: Vec3

        The world position.

      Returns number

      The scale.

    • Attach an array of graph nodes to the gizmo.

      Parameters

      Returns void

      const gizmo = new Gizmo(camera, layer);
      gizmo.attach([boxA, boxB]);
    • Detaches all graph nodes and destroys the gizmo instance.

      Returns void

      const gizmo = new Gizmo(camera, layer);
      gizmo.attach([boxA, boxB]);
      gizmo.destroy();
    • 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
    • Called before the gizmo renders.

      Returns void

      const gizmo = new Gizmo(camera, layer);
      gizmo.attach([boxA, boxB]);
      gizmo.prerender();
    • 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}`);
    });