Needle Engine component base class. Component's are the main building blocks of the Needle Engine.
Derive from Behaviour to implement your own using the provided lifecycle methods.
Components can be added to threejs objects using {@link addComponent} or {@link GameObject.addComponent}

The most common lifecycle methods are awake, start, onEnable, onDisable update and onDestroy.
XR specific callbacks include onEnterXR, onLeaveXR, onUpdateXR, onControllerAdded and onControllerRemoved.
To receive pointer events implement onPointerDown, onPointerUp, onPointerEnter, onPointerExit and onPointerMove.

Example

import { Behaviour } from "@engine/engine/engine";
export class MyComponent extends Behaviour {
start() {
console.log("Hello World");
}
update() {
console.log("Frame", this.context.time.frame);
}
}

Hierarchy (view full)

Implements

  • ICamera

Properties

gameObject: GameObject

the object this component is attached to. Note that this is a threejs Object3D with some additional features

guid: string = "invalid"

the unique identifier for this component

sourceId?: string

holds the source identifier this object was created with/from (e.g. if it was part of a glTF file the sourceId holds the url to the glTF)

Accessors

  • get activeAndEnabled(): boolean
  • Returns boolean

    true if the object is enabled and active in the hierarchy

  • get aspect(): number
  • The camera's aspect ratio (width divided by height) if it is a perspective camera

    Returns number

  • set aspect(value): void
  • Parameters

    • value: number

    Returns void

  • get backgroundBlurriness(): number
  • Returns number

  • set backgroundBlurriness(val): void
  • The blurriness of the background texture (when using a skybox)

    Parameters

    • val: number

    Returns void

  • get backgroundColor(): RGBAColor
  • The background color of the camera when ClearFlags are set to SolidColor

    Returns RGBAColor

  • set backgroundColor(val): void
  • Parameters

    Returns void

  • get backgroundIntensity(): number
  • Returns number

  • set backgroundIntensity(val): void
  • The intensity of the background texture (when using a skybox)

    Parameters

    • val: number

    Returns void

  • get backgroundRotation(): any
  • Returns any

  • set backgroundRotation(val): void
  • the rotation of the background texture (when using a skybox)

    Parameters

    • val: any

    Returns void

  • get cam(): any
  • Returns any

  • get clearFlags(): ClearFlags
  • The camera's clear flags - determines if the background is a skybox or a solid color or transparent

    Returns ClearFlags

  • set clearFlags(val): void
  • Parameters

    Returns void

  • get context(): Context
  • Use the context to get access to many Needle Engine features and use physics, timing, access the camera or scene

    Returns Context

  • set context(context): void
  • Parameters

    Returns void

  • set cullingLayer(val): void
  • Set only a specific layer active to be rendered by the camera.
    This is equivalent to calling layers.set(val)

    Parameters

    • val: number

    Returns void

  • get cullingMask(): number
  • Returns number

  • set cullingMask(val): void
  • The mask value of the three camera object layers If you want to just see objects on one layer (e.g. layer 2) then you can use cullingLayer = 2 on this camera component instead

    Parameters

    • val: number

    Returns void

  • get destroyed(): boolean
  • Returns boolean

    true if this component was destroyed (this.destroy()) or the whole object this component was part of

  • get enabled(): boolean
  • Returns boolean

  • set enabled(val): void
  • Parameters

    • val: boolean

    Returns void

  • get environmentIntensity(): number
  • Returns number

  • set environmentIntensity(val): void
  • The intensity of the environment map

    Parameters

    • val: number

    Returns void

  • get farClipPlane(): number
  • The camera's far clipping plane

    Returns number

  • set farClipPlane(val): void
  • Parameters

    • val: number

    Returns void

  • get fieldOfView(): number
  • The camera's field of view in degrees if it is a perspective camera

    Returns number

  • set fieldOfView(val): void
  • Parameters

    • val: number

    Returns void

  • get forward(): Vector3
  • Forward (0,0,-1) vector in world space

    Returns Vector3

  • get hideFlags(): HideFlags
  • Returns HideFlags

  • get isCamera(): boolean
  • Returns boolean

  • get layer(): number
  • Returns number

    the layer of the gameObject this component is attached to

  • get name(): string
  • Returns string

    the name of the gameObject this component is attached to

  • set name(str): void
  • Parameters

    • str: string

    Returns void

  • get nearClipPlane(): number
  • The camera's near clipping plane

    Returns number

  • set nearClipPlane(val): void
  • Parameters

    • val: number

    Returns void

  • get right(): Vector3
  • Right (1,0,0) vector in world space

    Returns Vector3

  • get scene(): Scene
  • shorthand for this.context.scene

    Returns Scene

    the scene of the context

  • get static(): boolean
  • Is the gameObject marked as static

    Returns boolean

  • set static(value): void
  • Parameters

    • value: boolean

    Returns void

  • get tag(): string
  • Returns string

    the tag of the gameObject this component is attached to

  • set tag(str): void
  • Parameters

    • str: string

    Returns void

  • get targetTexture(): RenderTexture
  • Returns RenderTexture

  • set targetTexture(rt): void
  • The texture that the camera should render to It can be used to render to a Texture instead of the screen.

    Parameters

    Returns void

  • get up(): Vector3
  • Up (0,1,0) vector in world space

    Returns Vector3

  • get worldEuler(): Euler
  • Returns Euler

  • set worldEuler(val): void
  • Parameters

    Returns void

  • get worldPosition(): Vector3
  • Returns Vector3

  • set worldPosition(val): void
  • Parameters

    Returns void

  • get worldQuaternion(): Quaternion
  • Returns Quaternion

  • set worldQuaternion(val): void
  • Parameters

    Returns void

  • get worldRotation(): Vector3
  • Returns Vector3

  • set worldRotation(val): void
  • Parameters

    Returns void

Methods

  • Parameters

    • Optional init: Partial<NoInternalNeedleEngineState<FilterStartingWith<FilterTypes<Camera, Function>, "_">>>

    Returns void

  • Type Parameters

    Parameters

    • type: string
    • listener: ((evt) => any)
        • (evt): any
        • Parameters

          • evt: T

          Returns any

    Returns void

  • Apply this camera's clear flags and related settings to the renderer

    Parameters

    • Optional opts: {
          applySkybox: boolean;
      }
      • applySkybox: boolean

    Returns void

  • Parameters

    • Optional opts: {
          applySkybox: boolean;
      }
      • applySkybox: boolean

    Returns void

  • Returns void

  • Apply the skybox to the scene

    Returns void

  • Creates a PerspectiveCamera if it does not exist yet and set the camera's properties. This is internally also called when accessing the cam property.

    Returns void

  • Destroys this component (and removes it from the object)

    Returns void

  • Parameters

    Returns boolean

  • first callback in a frame (called every frame when implemented)

    Returns void

  • Get a frustum - it will be created the first time this method is called and updated every frame in onBeforeRender when it exists.
    You can also manually update it using the updateFrustum method.

    Returns Frustum

  • Parameters

    • target: Matrix4
    • Optional forceUpdate: boolean

    Returns any

    this camera's projection screen matrix.

  • late callback in a frame (called every frame when implemented)

    Returns void

  • called after the scene was rendered

    Returns void

  • Called before the XR session is requested. Use this callback if you want to modify the session init features

    Parameters

    • mode: XRSessionMode
    • args: XRSessionInit

    Returns void

  • Called when the component gets destroyed

    Returns void

  • Callback when this component joins a xr session (or becomes active in a running XR session)

    Parameters

    Returns void

  • Callback when this component exists a xr session (or when it becomes inactive in a running XR session)

    Parameters

    Returns void

  • Called for all scripts when the context gets paused or unpaused

    Parameters

    • isPaused: boolean
    • wasPaused: boolean

    Returns void

  • Parameters

    • col: ICollider

    Returns any

  • Parameters

    • col: ICollider

    Returns any

  • Parameters

    • col: ICollider

    Returns any

  • Callback when a xr session updates (while it is still active in XR session)

    Parameters

    Returns void

  • called when you decorate fields with the @validate() decorator

    Parameters

    • Optional prop: string

      the name of the field that was changed

    Returns void

  • Callback when a controller is connected/added while in a XR session
    OR when the component joins a running XR session that has already connected controllers
    OR when the component becomes active during a running XR session that has already connected controllers

    Returns void

  • callback when a controller is removed while in a XR session
    OR when the component becomes inactive during a running XR session

    Returns void

  • Type Parameters

    Parameters

    • type: string
    • listener: ((arg) => any)
        • (arg): any
        • Parameters

          • arg: T

          Returns any

    Returns void

  • called on a component with a map of old to new guids (e.g. when instantiate generated new guids and e.g. timeline track bindings needs to remape them)

    Parameters

    • guidsMap: GuidsMap

    Returns void

  • Parameters

    • x: number
    • y: number
    • Optional ray: Ray

    Returns Ray

  • Parameters

    • x: number
    • y: number
    • z: number

    Returns void

  • Parameters

    • x: number
    • y: number
    • z: number
    • w: number

    Returns void

  • Parameters

    • x: number
    • y: number
    • z: number
    • degrees: boolean = true

    Returns void

  • called at the beginning of a frame (once per component)

    Returns void

  • starts a coroutine (javascript generator function)
    yield will wait for the next frame:

    • Use yield WaitForSeconds(1) to wait for 1 second.
    • Use yield WaitForFrames(10) to wait for 10 frames.
    • Use yield new Promise(...) to wait for a promise to resolve.

    Parameters

    • routine: Generator<unknown, any, unknown>

      generator function to start

    • evt: FrameEvent = FrameEvent.Update

      event to register the coroutine for (default: FrameEvent.Update). Note that all coroutine FrameEvent callbacks are invoked after the matching regular component callbacks. For example FrameEvent.Update will be called after regular component update() methods)

    Returns Generator<unknown, any, unknown>

    the generator function (use it to stop the coroutine with stopCoroutine)

    Example

    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;
    }
    }
  • Stop a coroutine that was previously started with startCoroutine

    Parameters

    • routine: Generator<unknown, any, unknown>

      the routine to be stopped

    • evt: FrameEvent = FrameEvent.Update

      the frame event to unregister the routine from (default: FrameEvent.Update)

    Returns void

  • Optional callback, you can implement this to only get callbacks for VR or AR sessions if necessary.

    Parameters

    • mode: XRSessionMode

    Returns boolean

    true if the mode is supported (if false the mode is not supported by this component and it will not receive XR callbacks for this mode)

  • regular callback in a frame (called every frame when implemented)

    Returns void

  • Force frustum update - note that this also happens automatically every frame in onBeforeRender

    Returns void

  • Used to determine if the background should be transparent when in pass through AR

    Parameters

    Returns any

    true when in XR on a pass through device where the background shouldbe invisible

Generated using TypeDoc