Camera
Class in @bimworks/viewer3d.
API catalogue · @bimworks/viewer3d · Class
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#
constructor()center#
The point the camera orbits around (the pivot), in viewer coordinates
eye#
eye#
The position of the camera, in viewer coordinates
Parameters#
| Name | Type | Description |
|---|---|---|
eye |
vec3 |
fov#
fov(): numberReturns#
The current fov (field of view)
fov#
fov(fov: number): voidSet 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#
Returns#
The configured near plane in meters, or "auto" when automatic near-plane calculation is enabled.
nearPlane#
Set the perspective near plane in meters, or "auto" to use automatic near-plane calculation.
Parameters#
| Name | Type | Description |
|---|---|---|
nearPlane |
NearPlane |
projMatrix#
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#
target#
The point the camera looks at, in viewer coordinates
Parameters#
| Name | Type | Description |
|---|---|---|
target |
vec3 |
up#
up#
The camera's up direction
Parameters#
| Name | Type | Description |
|---|---|---|
up |
vec3 |
viewMatrix#
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#
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#
animateFov(fov: number, animationTimeMs: number): voidChanges 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#
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#
Get the current ViewPoint
Returns#
The current ViewPoint
interpolateView#
interpolateView(newEye: vec3, newTarget: vec3, animationTimeMs: number, options?: { orthoHalfHeight?: number; pivot?: vec3; up?: vec3 }): voidMoves 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#
isAtRest(): booleanWhether the camera stands still: no animation, drag or navigation key in progress
orbitYaw#
orbitYaw(degrees: number, options?: { animate?: boolean }): voidRotates the eye around the target, about the up direction
Parameters#
| Name | Type | Description |
|---|---|---|
degrees |
number |
|
options |
{ animate?: boolean } |
setViewpoint#
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#
viewFit(params: { aabb?: AxisAlignedBoundingBox3D; animate?: boolean; animationTimeMs?: number; box?: { max: vec3; min: vec3 }; fov?: number; margin?: number; target?: vec3; updatePivot?: boolean; viewDirection?: vec3 }): voidFits 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