Camera component that handles rendering from a specific viewpoint in the scene. Supports both perspective and orthographic cameras with various rendering options. Internally, this component uses PerspectiveCamera and OrthographicCamera three.js objects.

Hierarchy (View Summary)

Implements

  • ICamera

Properties

ARBackgroundAlpha: number = 0

Controls the transparency level of the camera background in AR mode on supported devices. Value from 0 (fully transparent) to 1 (fully opaque).

gameObject: GameObject

Reference to the GameObject this component is attached to This is a three.js Object3D with additional GameObject functionality

guid: string = "invalid"

Unique identifier for this component instance, used for finding and tracking components

orthographic: boolean = false

Determines if the camera should use orthographic projection instead of perspective.

orthographicSize: number = 5

The size of the orthographic camera's view volume when in orthographic mode. Larger values show more of the scene.

sourceId?: string

Identifier for the source asset that created this component. For example, URL to the glTF file this component was loaded from

Accessors

  • get activeAndEnabled(): boolean

    Checks if this component is currently active (enabled and part of an active GameObject hierarchy) Components that are inactive won't receive lifecycle method calls

    Returns boolean

    True if the component is enabled and all parent GameObjects are active

  • get aspect(): number

    Gets or sets the camera's aspect ratio (width divided by height). For perspective cameras, this directly affects the camera's projection matrix. When set, automatically updates the projection matrix.

    Returns number

  • set aspect(value: number): void

    Gets or sets the camera's aspect ratio (width divided by height). For perspective cameras, this directly affects the camera's projection matrix. When set, automatically updates the projection matrix.

    Parameters

    • value: number

    Returns void

  • get backgroundBlurriness(): undefined | number

    Gets or sets the blurriness of the skybox background. Values range from 0 (sharp) to 1 (maximum blur).

    Returns undefined | number

  • set backgroundBlurriness(val: undefined | number): void

    Gets or sets the blurriness of the skybox background. Values range from 0 (sharp) to 1 (maximum blur).

    Parameters

    • val: undefined | number

    Returns void

  • get backgroundColor(): null | RGBAColor

    Gets or sets the background color of the camera when ClearFlags is set to ClearFlags.SolidColor. The alpha component controls transparency.

    Returns null | RGBAColor

  • set backgroundColor(val: null | RGBAColor): void

    Gets or sets the background color of the camera when ClearFlags is set to ClearFlags.SolidColor. The alpha component controls transparency.

    Parameters

    Returns void

  • get backgroundIntensity(): undefined | number

    Gets or sets the intensity of the skybox background. Values range from 0 (dark) to 10 (very bright).

    Returns undefined | number

  • set backgroundIntensity(val: undefined | number): void

    Gets or sets the intensity of the skybox background. Values range from 0 (dark) to 10 (very bright).

    Parameters

    • val: undefined | number

    Returns void

  • get backgroundRotation(): undefined | Euler

    Gets or sets the rotation of the skybox background. Controls the orientation of the environment map.

    Returns undefined | Euler

  • set backgroundRotation(val: undefined | Euler): void

    Gets or sets the rotation of the skybox background. Controls the orientation of the environment map.

    Parameters

    Returns void

  • get cam(): PerspectiveCamera | OrthographicCamera

    Gets the three.js camera object. Creates one if it doesn't exist yet.

    Returns PerspectiveCamera | OrthographicCamera

    The three.js camera object

    Use threeCamera instead

  • get clearFlags(): ClearFlags

    Gets or sets the camera's clear flags that determine how the background is rendered. Options include skybox, solid color, or transparent background.

    Returns ClearFlags

  • set clearFlags(val: ClearFlags): void

    Gets or sets the camera's clear flags that determine how the background is rendered. Options include skybox, solid color, or transparent background.

    Parameters

    Returns void

  • get context(): Context

    The context this component belongs to, providing access to the runtime environment including physics, timing utilities, camera, and scene

    Returns Context

  • set context(context: Context): void

    Parameters

    Returns void

  • set cullingLayer(val: number): void

    Sets only a specific layer to be active for rendering by this camera. This is equivalent to calling layers.set(val) on the three.js camera object.

    Parameters

    • val: number

      The layer index to set active

    Returns void

  • get cullingMask(): number

    Gets or sets the layers mask that determines which objects this camera will render. Uses the layers mask convention.

    Returns number

  • set cullingMask(val: number): void

    Gets or sets the layers mask that determines which objects this camera will render. Uses the layers mask convention.

    Parameters

    • val: number

    Returns void

  • get destroyed(): boolean

    Checks if this component has been destroyed

    Returns boolean

    True if the component or its GameObject has been destroyed

  • get enabled(): boolean

    Controls whether this component is enabled Disabled components don't receive lifecycle callbacks

    Returns boolean

  • set enabled(val: boolean): void

    Parameters

    • val: boolean

    Returns void

  • get environmentIntensity(): undefined | number

    Gets or sets the intensity of the environment lighting. Controls how strongly the environment map affects scene lighting.

    Returns undefined | number

  • set environmentIntensity(val: undefined | number): void

    Gets or sets the intensity of the environment lighting. Controls how strongly the environment map affects scene lighting.

    Parameters

    • val: undefined | number

    Returns void

  • get farClipPlane(): number

    Gets or sets the camera's far clipping plane distance. Objects farther than this distance won't be rendered. When set, automatically updates the projection matrix.

    Returns number

  • set farClipPlane(val: number): void

    Gets or sets the camera's far clipping plane distance. Objects farther than this distance won't be rendered. When set, automatically updates the projection matrix.

    Parameters

    • val: number

    Returns void

  • get fieldOfView(): undefined | number

    Gets or sets the camera's field of view in degrees for perspective cameras. When set, automatically updates the projection matrix.

    Returns undefined | number

  • set fieldOfView(val: undefined | number): void

    Gets or sets the camera's field of view in degrees for perspective cameras. When set, automatically updates the projection matrix.

    Parameters

    • val: undefined | number

    Returns void

  • get forward(): Vector3

    Gets the forward direction vector (0,0,-1) of this component's GameObject in world space

    Returns Vector3

  • get isCamera(): boolean

    Returns whether this component is a camera

    Returns boolean

    Always returns true

  • get layer(): number

    The layer value of the GameObject this component is attached to Used for visibility and physics filtering

    Returns number

  • get name(): string

    The name of the GameObject this component is attached to Used for debugging and finding objects

    Returns string

  • set name(str: string): void

    Parameters

    • str: string

    Returns void

  • get nearClipPlane(): number

    Gets or sets the camera's near clipping plane distance. Objects closer than this distance won't be rendered. When set, automatically updates the projection matrix.

    Returns number

  • set nearClipPlane(val: number): void

    Gets or sets the camera's near clipping plane distance. Objects closer than this distance won't be rendered. When set, automatically updates the projection matrix.

    Parameters

    • val: number

    Returns void

  • get right(): Vector3

    Gets the right direction vector (1,0,0) of this component's GameObject in world space

    Returns Vector3

  • get scene(): Scene

    Shorthand accessor for the current scene from the context

    Returns Scene

    The scene this component belongs to

  • get static(): boolean

    Indicates whether the GameObject is marked as static Static objects typically don't move and can be optimized by the engine

    Returns boolean

  • set static(value: boolean): void

    Parameters

    • value: boolean

    Returns void

  • get tag(): string

    The tag of the GameObject this component is attached to Used for categorizing objects and efficient lookup

    Returns string

  • set tag(str: string): void

    Parameters

    • str: string

    Returns void

  • get targetTexture(): null | RenderTexture

    Gets or sets the texture that the camera should render to instead of the screen. Useful for creating effects like mirrors, portals or custom post processing.

    Returns null | RenderTexture

  • set targetTexture(rt: null | RenderTexture): void

    Gets or sets the texture that the camera should render to instead of the screen. Useful for creating effects like mirrors, portals or custom post processing.

    Parameters

    Returns void

  • get threeCamera(): PerspectiveCamera | OrthographicCamera

    Gets the three.js camera object. Creates one if it doesn't exist yet.

    Returns PerspectiveCamera | OrthographicCamera

    The three.js camera object

  • get up(): Vector3

    Gets the up direction vector (0,1,0) of this component's GameObject in world space

    Returns Vector3

  • get worldEuler(): Euler

    Gets the rotation of this component's GameObject in world space as Euler angles (in radians)

    Returns Euler

  • set worldEuler(val: Euler): void

    Sets the rotation of this component's GameObject in world space using Euler angles (in radians)

    Parameters

    • val: Euler

      The world rotation Euler angles to set

    Returns void

  • get worldPosition(): Vector3

    Gets the position of this component's GameObject in world space

    Returns Vector3

  • set worldPosition(val: Vector3): void

    Sets the position of this component's GameObject in world space

    Parameters

    • val: Vector3

      The world position vector to set

    Returns void

  • get worldQuaternion(): Quaternion

    Gets the rotation of this component's GameObject in world space as a quaternion

    Returns Quaternion

  • set worldQuaternion(val: Quaternion): void

    Sets the rotation of this component's GameObject in world space using a quaternion

    Parameters

    • val: Quaternion

      The world rotation quaternion to set

    Returns void

  • get worldRotation(): Vector3

    Gets the rotation of this component's GameObject in world space as Euler angles (in degrees)

    Returns Vector3

  • set worldRotation(val: Vector3): void

    Sets the rotation of this component's GameObject in world space using Euler angles (in degrees)

    Parameters

    • val: Vector3

      The world rotation vector to set (in degrees)

    Returns void

Methods

  • Registers an event listener for the specified event type

    Type Parameters

    Parameters

    • type: string

      The event type to listen for

    • listener: (evt: T) => any

      The callback function to execute when the event occurs

    Returns void

  • Applies this camera's clear flags and related settings to the renderer. This controls how the background is rendered (skybox, solid color, transparent).

    Parameters

    • Optionalopts: { applySkybox: boolean }

      Options for applying clear flags

    Returns void

  • Applies clear flags if this is the active main camera.

    Parameters

    • Optionalopts: { applySkybox: boolean }

      Options for applying clear flags

    Returns void

  • Applies both the camera's near and far clipping planes and updates the projection matrix. This ensures rendering occurs only within the specified distance range.

    Returns void

  • Applies the skybox texture to the scene background.

    Returns void

  • Creates a three.js camera object if it doesn't exist yet and sets its properties. This is called internally when accessing the threeCamera property.

    Returns void

  • Destroys this component and removes it from its GameObject After destruction, the component will no longer receive lifecycle callbacks

    Returns void

  • Dispatches an event to all registered listeners

    Parameters

    • evt: Event

      The event object to dispatch

    Returns boolean

    Always returns false (standard implementation of EventTarget)

  • Called at the beginning of each frame before regular updates. Use for logic that needs to run before standard update callbacks.

    Returns void

  • Gets the camera's view frustum for culling and visibility checks. Creates the frustum if it doesn't exist and returns it.

    Returns Frustum

    The camera's view frustum

  • Gets this camera's projection-screen matrix.

    Parameters

    • target: Matrix4

      Matrix4 object to store the result in

    • OptionalforceUpdate: boolean

      Whether to force recalculation of the matrix

    Returns Matrix4

    The requested projection screen matrix

  • Called after all update functions have been called. Use for calculations that depend on other components being updated first.

    Returns void

  • Called after the scene has been rendered. Use for post-processing or UI updates that should happen after rendering

    Returns void

  • Called before an XR session is requested Use to modify session initialization parameters

    Parameters

    • mode: XRSessionMode

      The XR session mode being requested

    • args: XRSessionInit

      The session initialization parameters that can be modified

    Returns void

  • Called when this component's collider begins colliding with another collider.

    Parameters

    • col: Collision

      Information about the collision that occurred

    Returns any

  • Called when this component's collider stops colliding with another collider.

    Parameters

    • col: Collision

      Information about the collision that ended

    Returns any

  • Called each frame while this component's collider is colliding with another collider

    Parameters

    • col: Collision

      Information about the ongoing collision

    Returns any

  • Called when the component is destroyed. Use for cleanup operations like removing event listeners

    Returns void

  • Called when this component joins an XR session or becomes active in a running session

    Parameters

    Returns void

  • Called when this component exits an XR session or becomes inactive during a session

    Parameters

    Returns void

  • Called when the context's pause state changes.

    Parameters

    • isPaused: boolean

      Whether the context is currently paused

    • wasPaused: boolean

      The previous pause state

    Returns void

  • Called when a pointer completes a click interaction with this component's GameObject

    Parameters

    Returns any

  • Called when a pointer button is pressed while over this component's GameObject

    Parameters

    Returns any

  • Called when a pointer button is released while over this component's GameObject

    Parameters

    Returns any

  • Called when this component's trigger collider is entered by another collider

    Parameters

    • col: ICollider

      The collider that entered this trigger

    Returns any

  • Called when another collider exits this component's trigger collider

    Parameters

    • col: ICollider

      The collider that exited this trigger

    Returns any

  • Called each frame while another collider is inside this component's trigger collider

    Parameters

    • col: ICollider

      The collider that is inside this trigger

    Returns any

  • Called when a field decorated with @validate() is modified.

    Parameters

    • Optionalprop: string

      The name of the field that was changed

    Returns void

  • Removes a previously registered event listener

    Type Parameters

    Parameters

    • type: string

      The event type the listener was registered for

    • listener: (arg: T) => any

      The callback function to remove

    Returns void

  • Called when this component needs to remap guids after an instantiate operation.

    Parameters

    • guidsMap: GuidsMap

      Mapping from old guids to newly generated guids

    Returns void

  • Converts screen coordinates to a ray in world space. Useful for implementing picking or raycasting from screen to world.

    Parameters

    • x: number

      The x screen coordinate

    • y: number

      The y screen coordinate

    • Optionalray: Ray

      Optional ray object to reuse instead of creating a new one

    Returns Ray

    A ray originating from the camera position pointing through the screen point

  • Sets the position of this component's GameObject in world space using individual coordinates

    Parameters

    • x: number

      X-coordinate in world space

    • y: number

      Y-coordinate in world space

    • z: number

      Z-coordinate in world space

    Returns void

  • Sets the rotation of this component's GameObject in world space using quaternion components

    Parameters

    • x: number

      X component of the quaternion

    • y: number

      Y component of the quaternion

    • z: number

      Z component of the quaternion

    • w: number

      W component of the quaternion

    Returns void

  • Sets the rotation of this component's GameObject in world space using individual Euler angles

    Parameters

    • x: number

      X-axis rotation

    • y: number

      Y-axis rotation

    • z: number

      Z-axis rotation

    • degrees: boolean = true

      Whether the values are in degrees (true) or radians (false)

    Returns void

  • Called once at the beginning of the first frame after the component is enabled. Use for initialization that requires other components to be awake.

    Returns void

  • Starts a coroutine that can yield to wait for events. Coroutines allow for time-based sequencing of operations without blocking. Coroutines are based on generator functions, a JavaScript language feature.

    Parameters

    • routine: Generator

      Generator function to start

    • evt: FrameEvent = FrameEvent.Update

      Event to register the coroutine for (default: FrameEvent.Update)

    Returns Generator

    The generator function that can be used to stop the coroutine

    Time-based sequencing of operations

    *myCoroutine() {
    yield WaitForSeconds(1); // wait for 1 second
    yield WaitForFrames(10); // wait for 10 frames
    yield new Promise(resolve => setTimeout(resolve, 1000)); // wait for a promise to resolve
    }

    Coroutine that logs a message every 5 frames

    onEnable() {
    this.startCoroutine(this.myCoroutine());
    }
    private *myCoroutine() {
    while(this.activeAndEnabled) {
    console.log("Hello World", this.context.time.frame);
    // wait for 5 frames
    for(let i = 0; i < 5; i++) yield;
    }
    }
  • Stops a coroutine that was previously started with startCoroutine

    Parameters

    • routine: Generator

      The routine to be stopped

    • evt: FrameEvent = FrameEvent.Update

      The frame event the routine was registered with

    Returns void

  • Determines if this component supports a specific XR mode

    Parameters

    • mode: XRSessionMode

      The XR session mode to check support for

    Returns boolean

    True if the component supports the specified mode

  • Called once per frame during the main update loop. The primary location for frame-based game logic.

    Returns void

  • Forces an update of the camera's frustum. This is automatically called every frame in onBeforeRender.

    Returns void

  • Determines if the background should be transparent when in passthrough AR mode.

    Parameters

    • context: Context

      The current rendering context

    Returns boolean

    True when in XR on a pass through device where the background should be invisible