Reference·JavaScript · @bimworks/viewer3dJavaScript

Camera

Class in @bimworks/viewer3d.

API catalogue · @bimworks/viewer3d · Class

TypeScript#
class Camera

Members#

Member Kind Description
constructor Method
center Method The point the camera orbits around (the pivot), in viewer coordinates
eye Method
eye Method The position of the camera, in viewer coordinates
fov Method
fov Method Set the fov (field of view). Whenever a fov of 0 is set, the camera wil switch to orthographic view. Whenever the fov is set to any positive value below 120 …
nearPlane Method
nearPlane Method Set the perspective near plane in meters, or "auto" to use automatic near-plane calculation.
projMatrix Method The current projection matrix: view space to clip space as in WebGL2, z −1 at the near plane to +1 at the far plane (not reversed, no infinite far plane), wi…
target Method
target Method The point the camera looks at, in viewer coordinates
up Method
up Method The camera's up direction
viewMatrix Method The current view matrix: render frame to view space. The camera matrices keep the WebGL2 conventions whatever the viewer renders with (Viewer3D-Next/docs/pla…
viewProjMatrix Method The current view-projection matrix, projMatrix × viewMatrix: render frame to clip space, for example to place DOM elements over the canvas. Un-projecting a c…
animateFov Method Changes the projection to fov (degrees, 0 orthographic, below 180). Viewer3D-Next changes it smoothly over animationTimeMs where the camera is, what it looks…
getMillimetresPerPixel Method The size of one viewer pixel (Viewer3d.getHeight) in mm: the same everywhere in an orthographic view; in a perspective view at the depth of point (render fra…
getViewpoint Method Get the current ViewPoint
interpolateView Method Moves the camera to a new eye and target (render frame, mm), animated over animationTimeMs. An eye below the camera's eye floor (the lowest height the eye ma…
isAtRest Method Whether the camera stands still: no animation, drag or navigation key in progress
orbitYaw Method Rotates the eye around the target, about the up direction
setViewpoint Method Set the current viewpoint, make sure to wait for this call to finish
viewFit Method Fits the camera on a box

constructor#

TypeScript#
constructor()

center#

TypeScript#
center(): vec3

The point the camera orbits around (the pivot), in viewer coordinates

eye#

TypeScript#
eye(): vec3

eye#

TypeScript#
eye(eye: vec3): void

The position of the camera, in viewer coordinates

Parameters#

Name Type Description
eye vec3

fov#

TypeScript#
fov(): number

Returns#

The current fov (field of view)

fov#

TypeScript#
fov(fov: number): void

Set the fov (field of view). Whenever a fov of 0 is set, the camera wil switch to orthographic view. Whenever the fov is set to any positive value below 120 it will switch to perspective view.

Parameters#

Name Type Description
fov number The new fov

nearPlane#

TypeScript#
nearPlane(): NearPlane

Returns#

The configured near plane in meters, or "auto" when automatic near-plane calculation is enabled.

nearPlane#

TypeScript#
nearPlane(nearPlane: NearPlane): void

Set the perspective near plane in meters, or "auto" to use automatic near-plane calculation.

Parameters#

Name Type Description
nearPlane NearPlane

projMatrix#

TypeScript#
projMatrix(): mat4

The current projection matrix: view space to clip space as in WebGL2, z −1 at the near plane to +1 at the far plane (not reversed, no infinite far plane), with the finite near and far the camera uses: the nearPlane setting or the automatic one. Perspective or orthographic (fov 0). Conventions as viewMatrix

target#

TypeScript#
target(): vec3

target#

TypeScript#
target(target: vec3): void

The point the camera looks at, in viewer coordinates

Parameters#

Name Type Description
target vec3

up#

TypeScript#
up(): vec3

up#

TypeScript#
up(up: vec3): void

The camera's up direction

Parameters#

Name Type Description
up vec3

viewMatrix#

TypeScript#
viewMatrix(): mat4

The current view matrix: render frame to view space. The camera matrices keep the WebGL2 conventions whatever the viewer renders with (Viewer3D-Next/docs/plan.md §3.13): gl-matrix mat4 values (Float64Array, 16 numbers, column-major), a right-handed view space with the camera looking down −z and y up. They are the camera's own arrays, updated when it moves: read them, copy what you keep

viewProjMatrix#

TypeScript#
viewProjMatrix(): mat4

The current view-projection matrix, projMatrix × viewMatrix: render frame to clip space, for example to place DOM elements over the canvas. Un-projecting a canvas point with its inverse at z −1 and +1 gives the point on the near and on the far plane. Conventions as viewMatrix and projMatrix

animateFov#

TypeScript#
animateFov(fov: number, animationTimeMs: number): void

Changes the projection to fov (degrees, 0 orthographic, below 180). Viewer3D-Next changes it smoothly over animationTimeMs where the camera is, what it looks at keeping its size; Viewer3D switches at once, as fov

Parameters#

Name Type Description
fov number
animationTimeMs number

Exceptions#

  • Error for a fov outside 0 to 180

getMillimetresPerPixel#

TypeScript#
getMillimetresPerPixel(point?: vec3): number

The size of one viewer pixel (Viewer3d.getHeight) in mm: the same everywhere in an orthographic view; in a perspective view at the depth of point (render frame, default the target); 0 before the viewer has a size

Parameters#

Name Type Description
point vec3

getViewpoint#

TypeScript#
getViewpoint(): ViewPoint

Get the current ViewPoint

Returns#

The current ViewPoint

interpolateView#

TypeScript#
interpolateView(newEye: vec3, newTarget: vec3, animationTimeMs: number, options?: { orthoHalfHeight?: number; pivot?: vec3; up?: vec3 }): void

Moves the camera to a new eye and target (render frame, mm), animated over animationTimeMs. An eye below the camera's eye floor (the lowest height the eye may have, if one is set) is lifted onto it with the target

Parameters#

Name Type Description
newEye vec3
newTarget vec3
animationTimeMs number
options { orthoHalfHeight?: number; pivot?: vec3; up?: vec3 } pivot: the orbit pivot at the end (render frame), the current one when absent; up: the up direction at the end, derived from the current one when absent; orthoHalfHeight: in orthographic mode, the half height of the view window at the end in mm, the current one when absent

isAtRest#

TypeScript#
isAtRest(): boolean

Whether the camera stands still: no animation, drag or navigation key in progress

orbitYaw#

TypeScript#
orbitYaw(degrees: number, options?: { animate?: boolean }): void

Rotates the eye around the target, about the up direction

Parameters#

Name Type Description
degrees number
options { animate?: boolean }

setViewpoint#

TypeScript#
setViewpoint(viewPoint: ViewPoint, animationTime: number): Promise<void>

Set the current viewpoint, make sure to wait for this call to finish

Parameters#

Name Type Description
viewPoint ViewPoint The ViewPoint to set. When no fov has been set on the ViewPoint, the fov will be unchanged
animationTime number The time to animate in ms, the default is 0 and indicates no animation at all

viewFit#

TypeScript#
viewFit(params: { aabb?: AxisAlignedBoundingBox3D; animate?: boolean; animationTimeMs?: number; box?: { max: vec3; min: vec3 }; fov?: number; margin?: number; target?: vec3; updatePivot?: boolean; viewDirection?: vec3 }): void

Fits the camera on a box

Parameters#

Name Type Description
params { aabb?: AxisAlignedBoundingBox3D; animate?: boolean; animationTimeMs?: number; box?: { max: vec3; min: vec3 }; fov?: number; margin?: number; target?: vec3; updatePivot?: boolean; viewDirection?: vec3 } aabb: the box (render frame), for example from Viewer3d.getFocusAabb, the camera's scene bounds when absent; box: the same box as a plain value {min, max} (render frame, mm), used when aabb is absent, for example a box computed from points with Viewer3d.measurementToRenderCoordinates; margin, animate, animationTimeMs, updatePivot (make the box's centre the orbit pivot; without it the next orbit that starts on nothing pivots under the cursor), viewDirection and target as in @bimworks/viewercommon!ViewFitOptions; fov: change the field of view first

Exceptions#

  • Error when box has a corner that is not three finite numbers, or a min above its max