Class Camera

Camera determines how is world geometry projected onto a 2D surface. You may position and orient it in space, set options like aspect ratio and field or view and it outputs view and projection matrices required for rendering.

Hierarchy (view full)

Constructors

Accessors

  • get active(): boolean
  • Activates or deactivates the component.

    Returns boolean

    The returned active state also accounts for the active state of the parent SceneObject.

  • set active(value): void
  • Parameters

    • value: boolean

    Returns void

  • get aspectRatio(): number
  • Returns the aspect ratio used by the camera.

    Returns number

  • get editorMetaData(): Settings
  • Get the editor meta data.

    Returns Settings

    The API is only valid in the editor.

  • get effectSettings(): EffectSettings
  • Settings that control (post-processing) effects for this view. The settings determine how the renderer process this view, which effects will be enabled, and what properties will those effects use.

    Returns EffectSettings

  • set effectSettings(value): void
  • Parameters

    Returns void

  • get flags(): EnumValue<CameraFlag, number>
  • Determines flags used for controlling the camera behavior.

    Returns EnumValue<CameraFlag, number>

  • set flags(value): void
  • Various flags set on the component that affect it's behavior.

    Parameters

    Returns void

  • get id(): number
  • Gets the unique camera ID. This is used internally to reference the camera from the renderer data.

    Returns number

  • get isActiveSelf(): boolean
  • Determines whether the component itself is active, without accounting for the active state of the parent scene object.

    Returns boolean

  • get isCustomProjectionMatrixEnabled(): boolean
  • Returns true if a custom projection matrix is used.

    Returns boolean

  • get isCustomViewMatrixEnabled(): boolean
  • Returns true if a custom view matrix is used.

    Returns boolean

  • get isDestroyed(): boolean
  • Determines if the object has been destroyed.

    Returns boolean

  • get isRunning(): boolean
  • Determines if the component is currently active, enabled and running.

    Returns boolean

  • get layers(): rsx.LayerMask
  • Determines layer bitfield that is used when determining which object should the camera render.

    Returns rsx.LayerMask

  • set layers(value): void
  • Parameters

    Returns void

  • get orthographicProjectionSize(): Immutable<Size2>
  • Sets the orthographic window height, for use with orthographic rendering only.

    Returns Immutable<Size2>

    Calling this method will recalculate the aspect ratio, use setOrthoWindowHeight() or setOrthoWindowWidth() alone if you wish to preserve the aspect ratio but just fit one or other dimension to a particular size.

  • set orthographicProjectionSize(value): void
  • Parameters

    Returns void

  • get priority(): number
  • Determines a priority that determines in which orders the cameras are rendered. This only applies to cameras rendering to the same render target. Higher value means the camera will be rendered sooner.

    Returns number

  • set priority(value): void
  • The signed execution priority of the component.

    Determines order of execution of this component in relation to other components, higher priorities will execute earlier. The priority value determines the order of initialize, enable and update calls. Valid priorities are in the range [-100...100], other priorities are reserved for internal use.

    The priority should not be modified after onCreate has been called.

    The default priority for user implement components is -10. BuiltInComponent have a default priority of 0. However, instances that have dependencies or are a dependency to another component might have non zero default priorities. For example, the Camera component has a default priority of 50 as other components may depend on the camera being initialized early. The RigidBody component has a default priority of 22 and Joint components have a priority of 20 as the joint depends on fully initialized rigid bodies.

    Parameters

    • value: number

    Returns void

    If two components have the same priority, the order of execution is undefined, but deterministic as the system uses identifiers such as the internal type ID and UUID to guaranteed stable ordering.

  • get uuid(): UUID
  • Returns a universally unique identifier that persists scene save/load.

    Returns UUID

  • get viewport(): Viewport
  • Returns the viewport used by the camera.

    Returns Viewport

Methods

  • Virtual

    Calculates bounds of the visible content for this component.

    Returns {
        box: AABox;
        sphere: Sphere;
    }

    An object with the bounding box and bounding sphere or null, if the component has no bounds.

  • Destroys the component, removing it from its scene object and stopping component updates.

    Parameters

    • Optionalimmediate: boolean

      If true the component will be fully destroyed immediately. This means that objects that are still referencing this component might fail. Normally destruction is delayed until the end of the frame to give other objects a chance to stop using it.

    Returns void

  • Calls a parameterless method with the specified name, on the component.

    Parameters

    • name: string

      Name of the method to call.

    Returns boolean

    true if the method was invoked.

  • Makes the camera as the main one.

    Returns void

  • Converts a point in normalized device coordinates to screen space.

    Parameters

    • ndcPoint: Immutable<Vector2>

      2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

    Returns Vector2

    2D point on the render target attached to the camera's viewport, in pixels.

  • Converts a point in normalized device coordinates to view space.

    Parameters

    • ndcPoint: Immutable<Vector2>

      2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

    • Optionaldepth: number

      Depth to place the world point at. The depth is applied to the vector going from camera origin to the point on the near plane.

    Returns Vector3

    3D point relative to the camera's coordinate system.

  • Converts a point in normalized device coordinates to world space.

    Parameters

    • ndcPoint: Immutable<Vector2>

      2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

    • Optionaldepth: number

      Depth to place the world point at. The depth is applied to the vector going from camera origin to the point on the near plane.

    Returns Vector3

    3D point in world space.

  • Notifies the renderer that the effect settings changed.

    Returns void

  • Notifies a on-demand camera that it should re-draw its contents on the next frame. Ignored for a camera that isn't on-demand.

    Returns void

  • Virtual

    Called once when the component has been created.

    Returns void

    Called regardless of the state the component is in.

  • Virtual

    Called once just before the component is destroyed.

    Returns void

    Called regardless of the state the component is in.

  • Virtual

    Called every time a component is placed into the Stopped state.

    Returns void

    This method may be called during component destruction, if the component wasn't already in ScenePlayState.Stopped state during destruction. When called during destruction, it is called before onDestroy.

  • Virtual

    Called every time a component leaves the ScenePlayState.Stopped state.

    Returns void

    This method might be called during component creation, if the requirements for leaving the stopped state are met. One such case would be a component class that has the runInEditor attribute. When called during creation it is called after onInitialize.

  • Called at fixed time intervals (e.g. 60 times per frame). Only called if the component is in ScenePlayState.Playing state.

    Returns void

    RSX uses the fixed update to perform updates to sub-systems such as physics. Only implement this method if your logic depends on fixed updates (e.g. at 30hz) for stability.

  • Virtual

    Called once when the component first leaves the ScenePlayState.Stopped state.

    Returns void

    This method might be called during component creation, if the requirements for leaving the stopped state are met. One such case would be a component class that has the runInEditor attribute. When called during creation it is called after onCreate.

  • Virtual

    Called once per frame, after all other components received their onUpdate invocation. Only called if the component is in ScenePlayState.Playing state.

    Returns void

    This method should only be implemented if your component needs logic that implements on other component or SceneObject changes performend in onUpdate. An example could be a camera controller logic that updates in response to changes to the object that is being tracked.

  • Virtual

    Called when the script domain has been refreshed or when the component is initialized. During initialization it is called after onInitialize but before onEnable.

    Returns void

    This API will not be called in a deployment build.

  • Projects a point in view space to normalized device coordinates. Similar to ViewToNDCPoint() but preserves the depth component.

    Parameters

    Returns Vector3

    3D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport. Z value range depends on active render API.

  • Triggers the rendering operation for this particular camera. The results will be written to the render target provided in target.

    Parameters

    Returns AsyncOp<Any, void>

    This is an "asynchronous method".

  • Triggers the rendering operation for this particular camera. The results will be written to RenderTarget in camera viewport settings.

    Returns AsyncOp<Any, void>

    This is an "asynchronous method".

  • Converts a point in screen space to a ray in world space.

    Parameters

    • screenPoint: Immutable<Vector2>

      2D point on the render target attached to the camera's viewport, in pixels.

    Returns Ray

    Ray in world space, originating at the selected point on the camera near plane.

  • Converts a point in screen space to normalized device coordinates.

    Parameters

    • screenPoint: Immutable<Vector2>

      2D point on the render target attached to the camera's viewport, in pixels.

    Returns Vector2

    2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

  • Converts a point in screen space to a point in view space.

    Parameters

    • screenPoint: Immutable<Vector2>

      2D point on the render target attached to the camera's viewport, in pixels.

    • Optionaldepth: number

      Depth to place the world point at, in device depth. The depth is applied to the vector going from camera origin to the point on the near plane.

    Returns Vector3

    3D point relative to the camera's coordinate system.

  • Converts a point in screen space to a point in world space.

    Parameters

    • screenPoint: Immutable<Vector2>

      2D point on the render target attached to the camera's viewport, in pixels.

    • Optionaldepth: number

      Depth to place the world point at, in world coordinates. The depth is applied to the vector going from camera origin to the point on the near plane.

    Returns Vector3

    3D point in world space.

  • Sets whether the camera should use the custom projection matrix. When this is enabled camera will no longer calculate its projection matrix based on field of view, aspect and other parameters and caller will be resonsible to keep the projection matrix up to date.

    Parameters

    Returns void

  • Sets whether the camera should use the custom view matrix. When this is enabled camera will no longer calculate its view matrix based on position/orientation and caller will be resonsible to keep the view matrix up to date.

    Parameters

    Returns void

  • Registers the coroutine for the specified component using the provided args as arguments.

    Type Parameters

    Parameters

    • coroutine: T

      The coroutine.

    • Rest...args: Parameters<T>

    Returns boolean

    true if the coroutine was registered.

    The coroutine will be called for the first time when the coroutine subsystem runs for update events. There is no guarantee with regards to the order of how coroutines are invoked. Coroutines are a great way for time-deferred or delayed system. To implement a coroutine simply add a generator method to your component and register it as coroutine:

    		public *myCoroutine(text:string)
    {
    const endTime:number = Time.realElapsed + 3;

    while(Time.realElapsed < endTime)
    {
    yield true;
    }

    Debug.log("This code will be invoked after 3 seconds with the text=" + text);
    }

    To register the function simply call

    		this.startCoroutine(this.myCoroutine, "Hello World!");
    

    The function will be invoked once the coroutine runs. The coroutine function can yield the program control flow by using the keyword yield. The coroutine will then stop execution at that point, and pick up the execution in the next update event, right after the yield keyword that caused the coroutine to pause.

    With helper functions such as waitForSeconds or waitForAsyncOp it is easy to create coroutines that pause for a set time interval.

  • Registers the coroutine for the specified component using the provided args as arguments.

    Type Parameters

    Parameters

    • coroutine: T

      The coroutine.

    • Rest...args: Parameters<T>

    Returns boolean

    true if the coroutine was registered.

    The coroutine will be called for the first time when the coroutine subsystem runs for fixedUpdate events. There is no guarantee with regards to the order of how coroutines are invoked. Coroutines are a great way for time-deferred or delayed system. To implement a coroutine simply add a generator method to your component and register it as coroutine:

    		public *myCoroutine(text:string)
    {
    const endTime:number = Time.realElapsed + 3;

    while(Time.realElapsed < endTime)
    {
    yield true;
    }

    Debug.log("This code will be invoked after 3 seconds!");
    }

    To register the function simply call

    		this.startCoroutine(this.myCoroutine, "Hello World!");
    

    The function will be invoked once the coroutine runs. The coroutine function can yield the program control flow by using the keyword yield. The coroutine will then stop execution at that point, and pick up the execution in the next fixedUpdate event, right after the yield keyword that caused the coroutine to pause.

    With helper functions such as waitForSeconds or waitForAsyncOp it is easy to create coroutines that pause for a set time interval.

  • Stops all coroutines for the specified component.

    Returns void

    This API is only available for components that are registered in a scene.

  • Stops the coroutine for the specified component.

    Parameters

    Returns boolean

    true if the coroutine was registered.

  • Un-projects a point in normalized device space to view space.

    Parameters

    • point: Immutable<Vector3>

      3D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport. Z value range depends on active render API.

    Returns Vector3

    3D point relative to the camera's coordinate system.

  • Converts a point in view space to normalized device coordinates.

    Parameters

    • viewPoint: Immutable<Vector3>

      3D point relative to the camera's coordinate system.

    Returns Vector2

    2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

  • Converts a point in view space to screen space.

    Parameters

    • viewPoint: Immutable<Vector3>

      3D point relative to the camera's coordinate system.

    Returns Vector2

    2D point on the render target attached to the camera's viewport, in pixels.

  • Converts a point in view space to world space.

    Parameters

    • viewPoint: Immutable<Vector3>

      3D point relative to the camera's coordinate system.

    Returns Vector3

    3D point in world space.

  • Converts a point in world space to normalized device coordinates.

    Parameters

    Returns Vector2

    2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

  • Converts a point in world space to screen coordinates.

    Parameters

    Returns Vector2

    2D point on the render target attached to the camera's viewport, in pixels.

  • Converts a point in world space to view space coordinates.

    Parameters

    Returns Vector3

    3D point relative to the camera's coordinate system.

  • Locates a rsx object by its sceneRuntimeID and UUID.

    Parameters

    • sceneRuntimeID: number

      The runtime ID of the SceneInstance of the object.

    • uuid: Const<UUID>

      The UUID of the object to retrieve.

    Returns SceneNode

    The object or null if no object with given sceneRuntimeID and uuid has been registered

Events

didRender: Event<[], void>

Event that triggers after the camera has rendered a frame.