Skip to content

UWAL / Camera3D

Classes ​

abstract Camera3D ​

Base class for orthographic and perspective cameras.

Extends ​

  • Node

Extended by ​

Properties ​

CullTest ​
ts
CullTest: 0 | 1 | 2 = 1;

Defaults to bounding sphere.

AutoUpdateWorldMatrix ​
ts
AutoUpdateWorldMatrix: boolean = false;

Update the camera's view-projection matrix every time the world matrix is updated.

Constructors ​

Constructor ​
ts
new Camera3D(
   near?, 
   far?, 
   label?
): Camera3D;
Parameters ​
ParameterTypeDefault valueDescription
near?number1Distance to the near plane.
far?number1e3Distance to the far plane.
label?stringundefinedCamera name.
Returns ​

Camera3D

Overrides ​
ts
Node.constructor

Methods ​

UpdateWorldMatrix() ​
ts
UpdateWorldMatrix(force?): void;

Update the camera's world matrix buffer. When the AutoUpdateWorldMatrix or force is true, the camera's world and view-projection matrices are also updated.

Parameters ​
ParameterTypeDefault valueDescription
force?booleanfalseForce the camera's matrices to be updated.
Returns ​

void

Overrides ​
ts
Node.UpdateWorldMatrix

UpdateProjectionMatrix() ​
ts
UpdateProjectionMatrix(): void;

Write the computed projection matrix into the corresponding uniform buffer if present.

Returns ​

void

UpdateViewProjectionMatrix() ​
ts
UpdateViewProjectionMatrix(updateWorldMatrix?): Float32Array<ArrayBufferLike>;

Compute the view-projection matrix and write the result into the corresponding uniform buffer if present. This method also updates the camera's frustum planes used in cull testing.

Parameters ​
ParameterTypeDefault valueDescription
updateWorldMatrix?booleantrueUpdate the camera's world matrix.
Returns ​

Float32Array<ArrayBufferLike>

GetInverseViewProjectionMatrix() ​
ts
GetInverseViewProjectionMatrix(
   update?, 
   translation?, 
   dst?
): Float32Array<ArrayBufferLike>;

Compute the inverse of the camera's view-projection matrix. Optionally, reset the translation component of the matrix before inverting it.

Parameters ​
ParameterTypeDescription
update?booleanWhether to update the ViewProjectionMatrix before inverting it.
translation?Float32Array<ArrayBufferLike>If passed, set the matrix translation to this vector.
dst?Float32Array<ArrayBufferLike>Destination matrix. A new one is created if omitted.
Returns ​

Float32Array<ArrayBufferLike>

See ​

Skybox / Materials and SkyBox for reference.

LookAt() ​
ts
LookAt(target, up?): void;

Rotate the camera to point at the specified point in 3D space.

Parameters ​
ParameterTypeDescription
targetFloat32Array<ArrayBufferLike>Point in 3D space to look at.
up?Float32Array<ArrayBufferLike>Camera's up vector. Defaults to [0, 1, 0].
Returns ​

void

SetRenderPipeline() ​
ts
SetRenderPipeline(Pipeline): GPUBuffer;

Create and update an internal uniform buffer of this camera's world, projection, and view-projection matrices.

Parameters ​
ParameterTypeDescription
PipelineRenderPipelineInstancePipeline using this camera's projection.
Returns ​

GPUBuffer

Contains() ​
ts
Contains(Mesh): boolean;

Check if a mesh is contained in the camera's frustum when cull testing is performed. This method is called internally on every render when cull testing is enabled.

Parameters ​
ParameterTypeDescription
MeshMesh3D mesh to test for culling.
Returns ​

boolean

Whether the mesh is in the camera's frustum.

Destroy() ​
ts
Destroy(): void;

Destroy the internal matrices buffer.

Returns ​

void

Accessors ​

ViewProjectionMatrix ​
Get Signature ​
ts
get ViewProjectionMatrix(): Float32Array<ArrayBufferLike>;
Returns ​

Float32Array<ArrayBufferLike>

Camera's view-projection matrix.

MatrixBuffer ​
Get Signature ​
ts
get MatrixBuffer(): GPUBuffer | undefined;
Returns ​

GPUBuffer | undefined

Matrix buffer created by the SetRenderPipeline method.

Near ​
Get Signature ​
ts
get Near(): number;
Returns ​

number

Distance to the near plane of the frustum.

Set Signature ​
ts
set Near(near): void;
Parameters ​
ParameterTypeDescription
nearnumberDistance to the near plane.
Returns ​

void

Far ​
Get Signature ​
ts
get Far(): number;
Returns ​

number

Distance to the far plane of the frustum.

Set Signature ​
ts
set Far(far): void;
Parameters ​
ParameterTypeDescription
farnumberDistance to the far plane.
Returns ​

void

Released under the MIT License.