Engine API Reference - v2.20.0-beta.0
    Preparing search index...

    Class RotateGizmo

    The RotateGizmo provides interactive 3D manipulation handles for rotating/reorienting Entitys in a Scene. It creates a visual widget with a draggable ring for each axis of rotation, plus a fourth ring for rotation in the camera's view plane, allowing precise control over object orientation through direct manipulation. The gizmo's visual appearance can be customized away from the defaults as required.

    Note that the gizmo can be driven by both mouse+keyboard and touch input.

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

    // Create a rotate gizmo
    const gizmo = new pc.RotateGizmo(cameraComponent, gizmoLayer);

    // Create an entity to attach the gizmo to
    const entity = new pc.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

    Constructors

    Properties

    _app: AppBase

    Internal reference to the app containing the gizmo.

    Internal reference to camera component to view the gizmo.

    _coordSpace: GizmoSpace = 'world'

    Internal version of coordinate space. Defaults to 'world'.

    Internal reference to the graphics device of the app.

    _handles: EventHandle[] = []

    Internal list of app event handles for the gizmo.

    _layer: Layer

    Internal reference to layer to render the gizmo..

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

    Internal array of mouse buttons that can interact with the gizmo.

    _renderUpdate: boolean = false

    Internal flag to track if a render update is required.

    _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: "" | GizmoAxis = ''

    Internal currently selected axis.

    _selectedIsPlane: boolean = false

    Internal state of if currently selected shape is a plane.

    _selectionStartPoint: Vec3 = ...

    Internal selection starting coordinates in world space.

    _shapes: {
        f: ArcShape;
        x: ArcShape;
        xyz: SphereShape;
        y: ArcShape;
        z: ArcShape;
    } = ...

    Internal object containing the gizmo shapes to render.

    _theme: GizmoTheme = ...

    Internal theme.

    dragMode: GizmoDragMode = 'selected'

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

    intersectShapes: Shape[] = []

    The intersection shapes for the gizmo.

    nodes: GraphNode[] = []

    The graph nodes attached to the gizmo.

    preventDefault: boolean = true

    Flag to indicate whether to call preventDefault on pointer events.

    root: Entity

    The root gizmo entity.

    rotationMode: "absolute" | "orbit" = 'absolute'

    The rotation mode of the gizmo. This can be either:

    • 'absolute': The rotation is calculated based on the mouse displacement relative to the initial click point.
    • 'orbit': The rotation is calculated based on the gizmos position around the center of rotation.
    snap: boolean = false

    Whether snapping is enabled. Defaults to false.

    snapIncrement: number = 5

    Accessors

    • get _dragging(): boolean
      Protected

      Returns boolean

    • get angleGuideThickness(): number

      Gets the angle guide line thickness.

      Returns number

    • set angleGuideThickness(value: number): void

      Sets the angle guide line thickness.

      Parameters

      • value: number

      Returns void

    • get camera(): CameraComponent

      Gets the camera component to view the gizmo.

      Returns CameraComponent

    • set camera(camera: CameraComponent): void

      Sets the camera component to view the gizmo.

      Parameters

      Returns void

    • get cameraDir(): Vec3
      Protected

      Returns Vec3

    • get centerRadius(): number

      Gets the center radius.

      Returns number

    • set centerRadius(value: number): void

      Sets the center radius.

      Parameters

      • value: number

      Returns void

    • get coordSpace(): GizmoSpace

      Gets the gizmo coordinate space.

      Returns GizmoSpace

    • set coordSpace(value: GizmoSpace): void

      Sets the gizmo coordinate space. Defaults to 'world'

      Parameters

      Returns void

    • 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 faceRingRadius(): number

      Gets the face ring radius.

      Returns number

    • set faceRingRadius(value: number): void

      Sets the face ring radius.

      Parameters

      • value: number

      Returns void

    • get faceTubeRadius(): number

      Gets the face tube radius.

      Returns number

    • set faceTubeRadius(value: number): void

      Sets the face tube radius.

      Parameters

      • value: number

      Returns void

    • get facingDir(): Vec3
      Protected

      Returns Vec3

    • get layer(): Layer

      Gets the gizmo render layer.

      Returns Layer

    • set layer(layer: Layer): void

      Sets the gizmo render layer.

      Parameters

      • layer: Layer

        The layer to render the gizmo.

      Returns void

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

      Array of mouse buttons that can interact with the gizmo. The button indices are defined as:

      • 0: Left button
      • 1: Middle button
      • 2: Right button

      The full list of button indices can be found here: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button

      Returns [boolean, boolean, boolean]

    • get ringTolerance(): number

      Gets the ring tolerance.

      Returns number

    • set ringTolerance(value: number): void

      Sets the ring tolerance.

      Parameters

      • value: number

      Returns void

    • 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 theme(): GizmoTheme

      Gets the current theme for the gizmo.

      Returns GizmoTheme

    • get xyzRingRadius(): number

      Gets the XYZ ring radius.

      Returns number

    • set xyzRingRadius(value: number): void

      Sets the XYZ ring radius.

      Parameters

      • value: number

      Returns void

    • get xyzTubeRadius(): number

      Gets the XYZ tube radius.

      Returns number

    • set xyzTubeRadius(value: number): void

      Sets the XYZ tube radius.

      Parameters

      • value: number

      Returns void

    Methods

    • Protected

      Parameters

      • point: Vec3

        The point.

      • x: number

        The x coordinate.

      • y: number

        The y coordinate.

      Returns number

      The angle.

    • 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

      • mouseWPos: Vec3

        The mouse world position.

      Returns Ray

      • The ray.
    • Protected

      Parameters

      • axis: string

        The axis

      • dir: Vec3

        The direction

      Returns Vec3

      • The direction
    • Parameters

      • pos: Vec3

        The position.

      • rot: Quat

        The rotation.

      • activeAxis: GizmoAxis

        The active axis.

      • activeIsPlane: boolean

        Whether the active axis is a plane.

      Returns void

    • Protected

      Parameters

      • pos: Vec3

        The position.

      • rot: Quat

        The rotation.

      • axis: "x" | "y" | "z"

        The axis.

      Returns void

    • Protected

      Parameters

      • point: Vec3

        The point to project.

      • axis: string

        The axis to project to.

      Returns void

    • 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 from the gizmo.

      Returns void

      const gizmo = new pc.Gizmo(camera, layer);
      gizmo.attach([boxA, boxB]);
      gizmo.detach();
    • Set the shape to be enabled or disabled.

      Parameters

      • shapeAxis: "face" | GizmoAxis

        The shape axis.

      • enabled: boolean

        The enabled state of shape.

      Returns void

    • 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
    • Get the enabled state of the shape.

      Parameters

      • shapeAxis: "face" | GizmoAxis

        The shape axis. Can be:

      Returns boolean

      • Then enabled state of the shape
    • 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
    • Updates the gizmo position, rotation, and scale.

      Returns void

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

      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 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}`);
    });
    EVENT_TRANSFORMEND: string = 'transform:end'

    Fired when the transformation has ended.

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

    Fired during the transformation.

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

    Fired when the transformation has started.

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