Engine API Reference - v2.6.1
    Preparing search index...

    Class Gizmo

    The base class for all gizmos.

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new Gizmo object.

      Parameters

      • camera: CameraComponent

        The camera component.

      • layer: Layer

        The render layer. This can be provided by the user or will be created and added to the scene and camera if not provided. Successive gizmos will share the same layer and will be removed from the camera and scene when the last gizmo is destroyed. const gizmo = new pc.Gizmo(camera, layer);

      Returns Gizmo

    Properties

    _app: AppBase

    Internal reference to the app containing the gizmo.

    Internal reference to camera component to view the gizmo.

    _coordSpace: string = GIZMOSPACE_WORLD

    Internal version of coordinate space. Defaults to GIZMOSPACE_WORLD.

    Internal reference to the graphics device of the app.

    _layer: Layer

    Internal reference to layer to render the gizmo..

    _scale: number = 1

    Internal version of the gizmo scale. Defaults to 1.

    intersectShapes: Shape[] = []

    The intersection shapes for the gizmo.

    nodes: GraphNode[] = []

    The graph nodes attached to the gizmo.

    root: Entity

    The root gizmo entity.

    Accessors

    Methods

    • Attach an array of graph nodes to the gizmo.

      Parameters

      Returns void

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

      Returns void

      const gizmo = new pc.Gizmo(camera, layer);
      gizmo.attach([boxA, boxB]);
      gizmo.destroy();
    • Detaches all graph nodes from the gizmo.

      Returns void

      const gizmo = new pc.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.

      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

      Can be used for removing event in the future.

      obj.on('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      const evt = obj.on('test', (a, b) => {
      console.log(a + b);
      });
      // some time later
      evt.off();
    • Attach an event handler to an event. This handler will be removed after being fired once.

      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

      • can be used for removing event in the future.
      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
    • Creates a new gizmo layer and adds it to the scene.

      Parameters

      • app: AppBase

        The app.

      • OptionallayerName: string = LAYER_NAME

        The layer name. Defaults to 'Gizmo'.

      • OptionallayerIndex: number

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

      Returns Layer

      The new layer.

    Events

    EVENT_NODESATTACH: string = 'nodes:attach'

    Fired when graph nodes are attached.

    const gizmo = new pc.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 pc.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 pc.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 pc.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 pc.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 pc.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 when the gizmo render has updated.

    const gizmo = new pc.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 pc.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 pc.Gizmo(camera, layer);
    gizmo.on('scale:update', (scale) => {
    console.log(`The gizmo's scale was updated to ${scale}`);
    });