# CameraController

The default camera controller extension that comes with the viewer package. Includes toggleable perspective and orthographic camera projections.

#

Accessors

aspect controls enabled fieldOfView
options renderingCamera

#

Methods

disableRotations enableRotations on removeListener
setCameraPlanes setCameraView setOrthoCameraOn setPerspectiveCameraOn
toggleCameras

#

Typedefs

CameraEvent CameraEventPayload CameraControllerOptions CameraProjection
CanonicalView InlineView PolarView

#

Accessors

# aspect

get aspect(): number
1

Gets the current display aspect ratio

Returns: number

# controls

get controls(): SpeckleControls
1

Gets the current underlying SpeckleControls implementation.

Returns: SpeckleControls

# enabled

get enabled(): boolean
set enabled(val: boolean)
1
2

Gets or sets whether this extension is enabled.

TIP

Extensions typically need to support being turned on/off with no impact on potentially other active extensions.

Returns: boolean

# fieldOfView

get fieldOfView(): number
set fieldOfView(value: number)
1
2

Gets or sets the perspective camera's field of view.

Returns: number

# options

get options(): CameraControllerOptions
set options(value: CameraControllerOptions)
1
2

Gets or sets the current camera controller options.

Returns: CameraControllerOptions

# renderingCamera

get renderingCamera(): PerspectiveCamera | OrthographicCamera
set renderingCamera(value: PerspectiveCamera | OrthographicCamera)
1
2

Gets or sets the current rendering camera.

Returns: number

#

Methods

# disableRotations

disableRotations(): void
1

Disables all camera controls rotation capabilities.

Returns: void

# enableRotations

enableRotations(): void
1

Enables all camera controls rotation capabilities.

Returns: void

# on

on<T extends CameraEvent>(
  eventType: T,
  listener: (arg: CameraEventPayload[T]) => void
): void
1
2
3
4

Function for subscribing to camera events.

Parameters

Returns: void

# removeListener

removeListener(e: CameraEvent, handler: (data: unknown) => void)
1

Function for un-subscribing from camera events.

Parameters

  • e: CameraEvent
  • handler: The handler for the events to unsubscribe

Returns: void

# setCameraPlanes

setCameraPlanes(targetVolume: Box3, offsetScale: number = 1)
1

Function that adapts the camera's near and far clipping planes according to the current scene's volume. Parameters

Returns: void

# setCameraView

setCameraView(objectIds: string[], transition: boolean, fit?: number): void
1

Focuses the camera based on the volume defined by the received object ids list.

Parameters

  • objectIds: The object ids that make up the volume
  • transition: Whether or not to make the transition animated
  • optional fit: Linear tolerance
setCameraView(
    view: CanonicalView | SpeckleView | InlineView | PolarView,
    transition: boolean,
    fit?: number
  ): void
1
2
3
4
5

Focuses the camera based on explicit view models provided.

Parameters

  • view: Explicit view of different possible type: CanonicalView, SpeckleView, InlineView
  • transition: Whether or not to make the transition animated
  • optional fit: Linear tolerance
setCameraView(bounds: Box3, transition: boolean, fit?: number): void
1

Focuses the camera based on explicit volume provided as Box3 (opens new window).

Parameters

  • bounds: Box3 (opens new window)
  • transition: Whether or not to make the transition animated
  • optional fit: Linear tolerance

Returns: void

# setOrthoCameraOn

setOrthoCameraOn(): void
1

Enables the orthographic camera.

Returns: void

# setPerspectiveCameraOn

setPerspectiveCameraOn(): void
1

Enables the perspective camera.

Returns: void

# toggleCameras

toggleCameras(): void
1

Switches between perspective and orthographic cameras.

Returns: void

#

Typedefs

# CameraEvent

enum CameraEvent {
  Stationary = 'stationary',
  Dynamic = 'dynamic',
  FrameUpdate = 'frame-update',
  ProjectionChanged = 'projection-changed'
}
1
2
3
4
5
6

Events the camera controller puts out.

# CameraEventPayload

interface CameraEventPayload {
  [CameraEvent.Stationary]: void
  [CameraEvent.Dynamic]: void
  [CameraEvent.FrameUpdate]x: boolean
  [CameraEvent.ProjectionChanged]: CameraProjection
}
1
2
3
4
5
6

Mapping CameraEvent types to handler argument type

# CameraControllerOptions

type CameraControllerOptions = SmoothOrbitControlsOptions &
  { nearPlaneCalculation?: NearPlaneCalculation }
1
2

The camera controller options. Defaults to

export const DefaultOrbitControlsOptions: Required<CameraControllerOptions> = {
  enableOrbit: true,
  enableZoom: true,
  enablePan: true,
  orbitSensitivity: 1,
  zoomSensitivity: 1,
  panSensitivity: 1,
  inputSensitivity: 1,
  minimumRadius: 0,
  maximumRadius: Infinity,
  minimumPolarAngle: 0,
  maximumPolarAngle: Math.PI,
  minimumAzimuthalAngle: -Infinity,
  maximumAzimuthalAngle: Infinity,
  infiniteZoom: true,
  zoomToCursor: true,
  damperDecay: 30,
  nearPlaneCalculation: NearPlaneCalculation.EMPIRIC
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# CameraProjection

enum CameraProjection {
  PERSPECTIVE,
  ORTHOGRAPHIC,
}
1
2
3
4

Camera projection types.

# CanonicalView

type CanonicalView =
  | "front"
  | "back"
  | "up"
  | "top"
  | "down"
  | "bottom"
  | "right"
  | "left"
  | "3d"
  | "3D";
1
2
3
4
5
6
7
8
9
10
11

Supported cannonical views.

# InlineView

type InlineView = {
  position: Vector3;
  target: Vector3;
};
1
2
3
4

Inline, on-demand camera view.

  • position: The position of the camera
  • target: The point in space where the camera looks at Returns: void

# PolarView

type PolarView = {
  azimuth: number;
  polar: number;
  radius?: number;
  origin?: Vector3;
};
1
2
3
4
5
6

Camera view defined in polar coordinates.