Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Camera Abstract

The Camera class contains properties that reflect a world space position, a view direction (lookAt), and normalized vector representing the up direction.

It also provides utility methods to update orientation of the camera and rerender the scene.

This class in intended to treated as an immutable type. Any mutations return a new instance of the class with the updated properties.

Hierarchy

  • Camera

Index

Constructors

  • new Camera(stream: StreamApi, aspect: number, data: FrameCamera, boundingBox: BoundingBox, decodeFrame: FrameDecoder, flyToOptions?: FlyToOptions): Camera

Accessors

  • get aspectRatio(): number
  • get far(): number
  • get lookAt(): Vector3
  • get near(): number
  • get position(): Vector3
  • get up(): Vector3
  • get viewVector(): Vector3

Methods

  • alignTo(position: Vector3, normal: Vector3): Camera
  • Aligns the camera to the plane defined by the provided position and normal. This will place the camera at the provided position, set the up vector to the provided normal, and place the lookAt on the defined plane. The point chosen for the lookAt will be determined using the current view vector.

    example
    const viewer = document.querySelector("vertex-viewer");

    viewer.addEventListener("tap", async (event) => {
    const scene = await viewer.scene();
    const raycaster = scene.raycaster();

    const [hit] = await raycaster.hitItems(event.detail.position);

    if (hit != null) {
    const camera = scene.camera();

    // Align to the plane represented by the hit result with an animation of 1 second
    await camera
    .alignTo(hit.hitPoint, hit.hitNormal)
    .render({ animation: { milliseconds: 1000 } });
    }
    });

    Parameters

    • position: Vector3

      The position to place the camera at.

    • normal: Vector3

      The normal of the plane to align to.

    Returns Camera

  • fitToBoundingBox(boundingBox: BoundingBox): Camera
  • Updates the position of the camera such that the given bounding box will be contained within the camera's view.

    Parameters

    • boundingBox: BoundingBox

      The bounding box to position to.

    Returns Camera

  • flyTo(paramsOrQuery: FlyToParams | ((q: FlyToExecutor) => TerminalFlyToExecutor)): Camera
  • Specifies that the next render of the camera will be repositioned to one of the options specified in options.

    example
    const viewer = document.querySelector("vertex-viewer");
    const scene = await viewer.scene();
    const camera = scene.camera();

    // Fly to and fit to a specific item by ID with an animation of 1 second
    await camera
    .flyTo({ itemId: "item-id" })
    .render({ animation: { milliseconds: 1000 } });

    // Fly to and fit to a specific item by supplied ID with an animation of 1 second
    await camera
    .flyTo({ itemSuppliedId: "item-supplied-id" })
    .render({ animation: { milliseconds: 1000 } });

    // Fly to and fit to the bounding box of the current set of selected items
    // with an animation of 1 second
    await camera
    .flyTo({
    boundingBox:
    viewer.frame.scene.sceneViewSummary.selectedVisibleSummary.boundingBox,
    })
    .render({ animation: { milliseconds: 1000 } });

    // Fly to a specific camera
    await camera
    .flyTo({
    camera: {
    position: {
    x: 1,
    y: 2,
    z: 3,
    },
    lookAt: {
    x: 0,
    y: 0,
    z: 0,
    },
    up: {
    x: 0,
    y: 1,
    z: 0,
    },
    },
    })
    .render({ animation: { milliseconds: 1000 } });

    Parameters

    • paramsOrQuery: FlyToParams | ((q: FlyToExecutor) => TerminalFlyToExecutor)

      An object or query describing how the camera should be positioned.

    Returns Camera

  • moveBy(delta: Vector3): Camera
  • render(renderOptions?: CameraRenderOptions): Promise<CameraRenderResult>
  • Queues the rendering for a new frame using this camera. The returned promise will resolve when a frame is received that contains this camera.

    Parameters

    • Optional renderOptions: CameraRenderOptions

    Returns Promise<CameraRenderResult>

  • rotateAroundAxis(angleInRadians: number, axis: Vector3): Camera
  • rotateAroundAxisAtPoint(angleInRadians: number, point: Vector3, axis: Vector3): Camera
  • Repositions the camera by rotating its current position around an axis defined at a specific world point.

    example
    const viewer = document.querySelector('vertex-viewer');

    viewer.addEventListener('tap', async (event) => {
    const scene = await viewer.scene();
    const raycaster = scene.raycaster();

    const [hit] = await raycaster.hitItems(event.detail.position);

    if (hit != null) {
    const camera = scene.camera();

    // Using the current `up` vector of the camera, rotate 45 degrees
    // about the hit position with an animation of 1 second
    await camera.rotateAroundAxisAtPoint(
    Angle.toRadians(45),
    hit.hitPoint,
    camera.up,
    ).render({ animation: { milliseconds: 1000 } });
    }
    });

    Parameters

    • angleInRadians: number

      The angle, in radians, to rotate.

    • point: Vector3

      The point in world space to place the axis at.

    • axis: Vector3

      A normalized vector to rotate around.

    Returns Camera

  • signedDistanceToBoundingBoxCenter(boundingBox?: BoundingBox): number
  • Returns the distance from the camera's position to the center of the provided bounding box (or the scene's visible bounding box if not provided).

    Parameters

    • Optional boundingBox: BoundingBox

      The bounding box to determine distance from.

    Returns number

  • update(camera: Partial<FrameCamera>): Camera
  • Updates the position, lookAt and/or up vectors of the camera. Each vector can be omitted in the payload, and the resulting camera will keep the previous position, lookAt, or up vectors.

    example
    const viewer = document.querySelector("vertex-viewer");
    const scene = await viewer.scene();
    const camera = scene.camera();

    // Update the camera to place it at the origin
    await camera
    .update({
    position: {
    x: 0,
    y: 0,
    z: 0,
    },
    })
    .render({ animation: { milliseconds: 1000 } });

    // Update the camera to look at the origin
    await camera
    .update({
    lookAt: {
    x: 0,
    y: 0,
    z: 0,
    },
    })
    .render({ animation: { milliseconds: 1000 } });

    Parameters

    • camera: Partial<FrameCamera>

      The values to update the camera to.

    Returns Camera

  • Performs a flyTo operation with the current visible bounding box of the scene.

    example
    const viewer = document.querySelector('vertex-viewer');
    const scene = await viewer.scene();
    const camera = scene.camera();

    // Fit to the visible bounding box of the scene with an animation of 1 second
    await camera.viewAll().render({ animation: { milliseconds: 1000 } });

    Returns Camera