API Referencevgpu/scene

Camera

Type alias for scene cameras returned by `perspectiveCamera()` and `orthographicCamera()`. Use it when storing a camera without caring which helper produced it.

Import

import type { Camera } from "vgpu/scene";

Signature

type Camera = import("vgpu/scene").SceneCamera;

Parameters

ParamTypeRequiredDefaultNotes
CameraSceneCamera✔—Alias that keeps helper and consumer types in sync.

Returns: Not a callable; this alias ensures perspectiveCamera() and orthographicCamera() share the same contract.

Throws: None.

Examples

import type { Camera } from "vgpu/scene";
import { perspectiveCamera } from "vgpu/scene";

const camera: Camera = perspectiveCamera({
  fov: 60,
  aspect: 16 / 9,
  position: [0, 2, 4],
  target: [0, 0, 0],
});

Notes

  • Prefer the Camera alias when storing values in state containers so switching between perspective and orthographic helpers stays type-safe.
  • See also: SceneCamera, perspectiveCamera, orthographicCamera.

SceneCamera

Common contract of stateful camera nodes: column-major matrices plus the camera position, exposed as stable Float32Array identities that are updated in place by set() / lookAt().

Import

import type { SceneCamera } from "vgpu/scene";

Signature

interface SceneCamera {
  readonly viewProjection: Float32Array;
  readonly viewProjectionMatrix: Float32Array;
  readonly position: Float32Array;
  readonly view: Float32Array;
  readonly projection: Float32Array;
  readonly worldPosition: Float32Array;
}

Parameters

FieldTypeRequiredDefaultNotes
viewProjectionFloat32Array✔—Column-major projection × view matrix. Bind this to your WGSL uniforms.
viewProjectionMatrixFloat32Array✔—Alias of viewProjection, kept for naming continuity.
positionFloat32Array✔—Local position (world position for unparented cameras). Mutate via set().
viewFloat32Array✔—Inverse of the camera node's world matrix.
projectionFloat32Array✔—Projection matrix derived from the camera's parameters.
worldPositionFloat32Array✔—World position used for specular highlights or parallax.

Returns: Not a callable — the interface describes what camera helpers return.

Throws: None.

Examples

import { perspectiveCamera } from "vgpu/scene";

const camera = perspectiveCamera({
  fov: 50,
  aspect: 4 / 3,
  position: [2, 2, 4],
  target: [0, 0, 0],
});

void camera.viewProjection;

Notes

  • Cameras are scene nodes: update them in place with set() / lookAt() instead of recreating them.
  • viewProjectionMatrix is a duplicate reference so existing consumer code keeps working.
  • See also: Camera, CameraVec3, perspectiveCamera, SceneNode.

CameraVec3

Input-friendly vector type accepted by camera helpers. Accepts tuple literals or typed arrays; helpers always clone into a Float32Array.

Import

import type { CameraVec3 } from "vgpu/scene";

Signature

type CameraVec3 = readonly [number, number, number] | Float32Array;

Parameters

ParamTypeRequiredDefaultNotes
tuple formreadonly [number, number, number]✔—Pass literal XYZ coordinates without allocations.
typed array formFloat32Array✔—Use when positions already live in typed arrays (e.g. math libraries).

Returns: Not a callable — this is the accepted input type for camera helpers.

Throws: None.

Examples

import type { CameraVec3 } from "vgpu/scene";

const orbitPos: CameraVec3 = new Float32Array([0, 3, 5]);

Notes

  • Helpers clone the input, so mutating the original array after the call does not affect the camera.
  • See also: perspectiveCamera, orthographicCamera.

Vec3

Type-only re-export of the Vec3 alias from wgpu-matrix. Used internally by low-level camera helpers.

Import

import type { Vec3 } from "vgpu/scene";

Signature

type Vec3 = Float32Array;

Parameters

ParamTypeRequiredDefaultNotes
Vec3Float32Array✔—Column vector used by low-level helpers; provided for users wiring math utilities.

Returns: Not a callable.

Throws: None.

Examples

import type { Vec3 } from "vgpu/scene";

const up: Vec3 = new Float32Array([0, 1, 0]);

Notes

  • Prefer CameraVec3 when calling public helpers; Vec3 is useful when interoperating with @vgpu/wgsl math utilities.
  • See also: Mat4, CameraVec3.

Mat4

Type-only re-export of the column-major 4×4 matrix type from wgpu-matrix. Helpful when authoring math utilities that feed into scene helpers.

Import

import type { Mat4 } from "vgpu/scene";

Signature

type Mat4 = Float32Array;

Parameters

ParamTypeRequiredDefaultNotes
Mat4Float32Array✔—Column-major 4×4 matrix used across scene helpers.

Returns: Not a callable.

Throws: None.

Examples

import type { Mat4 } from "vgpu/scene";

const identity: Mat4 = new Float32Array([
  1, 0, 0, 0,
  0, 1, 0, 0,
  0, 0, 1, 0,
  0, 0, 0, 1,
]);

Notes

  • Use these aliases when building custom math helpers so your APIs stay aligned with vgpu’s scene entrypoints.
  • See also: Vec3, SceneCamera.