Skip to content

CameraSyncSystem

Syncs CameraComponent authoring values to the live THREE.js camera object each frame, handling both perspective and orthographic projection modes.

Overview

CameraSyncSystem runs every frame and is responsible for:

  • Updating fov, near, far, and zoom on THREE.PerspectiveCamera from the component values.
  • Updating left, right, top, bottom, near, far, and zoom on THREE.OrthographicCamera.
  • Clamping all values to safe ranges (near ≥ 0.001, far > near, fov in [1, 179], zoom ≥ 0.001) so an invalid inspector value never breaks the camera projection matrix.
  • Normalizing orthographic bounds so that right > left and top > bottom are always satisfied.
  • Calling updateProjectionMatrix() whenever a change is detected.

Queried components

ComponentAccess
CameraComponentRead + sanitize (clamps written back to component fields)
Object3DRefRead (the live THREE.js camera object)

Behavior notes

  • Projection type — the system checks the concrete type of the object in Object3DRef (instanceof THREE.PerspectiveCamera / THREE.OrthographicCamera) and applies the matching update path. If neither type matches, the entity is skipped.
  • Aspect ratio — perspective cameras auto-update aspect from window.innerWidth / window.innerHeight each frame when a window is available.
  • Change detection — property values are compared before writing to avoid redundant updateProjectionMatrix() calls on every frame.

API reference