The base class for all transform gizmos.

Hierarchy (view full)

Constructors

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.

_dragging: boolean = false

Internal state for if the gizmo is being dragged.

_guideColors: Record<string, Color> = ...

Internal version of the guide line color.

_layer: Layer

Internal reference to layer to render the gizmo..

_meshColors: {
    axis: Record<string, Color>;
    disabled: Color;
    hover: Record<string, Color>;
} = ...

Internal color for meshes.

_rootStartPos: Vec3 = ...

Internal gizmo starting rotation in world space.

_rootStartRot: Quat = ...

Internal gizmo starting rotation in world space.

_scale: number = 1

Internal version of the gizmo scale. Defaults to 1.

_selectedAxis: string = ''

Internal currently selected axis.

_selectedIsPlane: boolean = false

Internal state of if currently selected shape is a plane.

_selectionStartAngle: number = 0

Internal selection starting angle in world space.

_selectionStartPoint: Vec3 = ...

Internal selection starting coordinates in world space.

_shading: boolean = false

Internal state of if shading is enabled. Defaults to true.

_shapes: {} = {}

Internal object containing the gizmo shapes to render.

intersectData: IntersectData[] = []

The intersection data object.

nodes: GraphNode[] = []

The graph nodes attached to the gizmo.

root: Entity

The root gizmo entity.

snapIncrement: number = 1

Snapping increment. Defaults to 1.

Accessors

Methods

  • Protected

    Parameters

    • axis: string

      The axis to create the plane for.

    • isFacing: boolean

      Whether the axis is facing the camera.

    • isLine: boolean

      Whether the axis is a line.

    Returns Plane

    • The plane.
  • Protected

    Parameters

    • x: number

      The x coordinate.

    • y: number

      The y coordinate.

    • isFacing: boolean = false

      Whether the axis is facing the camera.

    • isLine: boolean = false

      Whether the axis is a line.

    Returns {
        angle: number;
        point: Vec3;
    }

    • The point and angle.
    • angle: number
    • point: Vec3
  • Detaches all graph nodes from the gizmo.

    Returns void

    const gizmo = new pc.Gizmo(app, 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', function () { }); // 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: object

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

    Returns EventHandler

    Self for chaining.

    const handler = function () {
    };
    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: object = ...

      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', function (a, b) {
    console.log(a + b);
    });
    obj.fire('test', 1, 2); // prints 3 to the console
    const evt = obj.on('test', function (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: object = ...

      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', function (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(app, 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(app, 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(app, 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(app, 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(app, 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(app, 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(app, 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(app, 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(app, camera, layer);
gizmo.on('scale:update', (scale) => {
console.log(`The gizmo's scale was updated to ${scale}`);
});
EVENT_TRANSFORMEND: string = 'transform:end'

Fired when when the transformation has ended.

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

Fired during the transformation.

const gizmo = new pc.TransformGizmo(app, camera, layer);
gizmo.on('transform:move', (pointDelta, angleDelta) => {
console.log('Transformation moved by ${pointDelta} (angle: ${angleDelta})');
});
EVENT_TRANSFORMSTART: string = 'transform:start'

Fired when when the transformation has started.

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