A NeedleXRController wraps a connected XRInputDevice that is either a physical controller or a hand
You can access specific buttons using getButton and getStick
To get spatial data in rig space (position, rotation) use the gripPosition, gripQuaternion, rayPosition and rayQuaternion properties
To get spatial data in world space use the gripWorldPosition, gripWorldQuaternion, rayWorldPosition and rayWorldQuaternion properties
Inputs will also be emitted as pointer events on this.context.input - so you can receive controller inputs on objects using the appropriate input events on your components (e.g. onPointerDown, onPointerUp etc) - use the pointerType property to check if the event is from a controller or not

Implements

  • IPointerHitEventReceiver

Constructors

Properties

emitEvents: boolean = true

When enabled the controller will create input events in the Needle Engine input system (e.g. when a button is pressed or the controller is moved)
You can disable this if you don't want inputs to go through the input system but be aware that this will result in onPointerDown component callbacks to not be invoked anymore for this XRController

emitPointerDownEvent: boolean = true

When enabled the controller will automatically emit pointer down events to the Needle Engine Input System.

Default

true
emitPointerMoveEvent: boolean = true

When enabled the controller will automatically emit pointer move events to the Needle Engine Input System.

Default

true
emitPointerUpEvent: boolean = true

When enabled the controller will automatically emit pointer up events to the Needle Engine Input System.

Default

true
index: number = 0

the input source index

inputSource: XRInputSource
model: any = null

Assigned the model that you use for rendering. This can be used as a hint for other components

pointerMoveAngleThreshold: number = 0.05

The angle threshold for pointer move events. This value is in radians.

Default

0.05
pointerMoveDistanceThreshold: number = 0.03

The distance threshold for pointer move events. This value is in units in rig space

Default

0.03

the Needle XR Session

Accessors

  • get connected(): boolean
  • Is the controller still connected?

    Returns boolean

  • get gamepad(): any
  • the input source gamepad giving raw access to the gamepad values
    You should usually use the getButton and getStick methods instead to get access to named buttons and sticks

    Returns any

  • get gripMatrix(): any
  • Returns any

  • get gripQuaternion(): any
  • Grip rotation in rig space

    Returns any

  • get gripSpace(): any
  • shorthand for inputSource.gripSpace

    Returns any

  • get gripWorldPosition(): Vector3
  • Controller grip position in worldspace

    Returns Vector3

  • get gripWorldQuaternion(): any
  • Controller grip rotation in wordspace

    Returns any

  • get handWristDotUp(): number
  • The dot product of the hand palm with the up vector. This is a number between -1 and 1, where 1 means the palm is directly up and -1 means the palm is directly down (upside down). This value is undefined if there's no hand

    Returns number

  • get hasHitTestSource(): any
  • Returns any

  • get hasSelectEvent(): boolean
  • Returns boolean

  • get isHand(): boolean
  • Returns boolean

    true if this is a hand (otherwise this is a controller)

  • get isHandUpsideDown(): boolean
  • Returns boolean

    true if the hand is upside down

  • get isLeft(): boolean
  • is left side. shorthand for side === 'left'

    Returns boolean

  • get isRight(): boolean
  • is right side. shorthand for side === 'right'

    Returns boolean

  • get isTeleportGesture(): boolean
  • Returns boolean

    true if the hand is upside down and we got a pinch down event this frame.

  • get isTracking(): boolean
  • Returns boolean

  • get layout(): InputDeviceLayout
  • The device input layout

    Returns InputDeviceLayout

  • get object(): IGameObject
  • The controller object space.
    You can use it to attach objects to the controller.
    Children will be automatically detached and put into the scene when the controller disconnects

    Returns IGameObject

  • get profiles(): any
  • The input source profiles

    Returns any

  • get ray(): Ray
  • The controller ray in worldspace

    Returns Ray

  • get rayQuaternion(): any
  • Ray rotation in rig space

    Returns any

  • get rayWorldPosition(): Vector3
  • Controller ray position in worldspace (this value is calculated once per frame by default - call updateRayWorldPosition to force an update)

    Returns Vector3

  • get rayWorldQuaternion(): any
  • Controller ray rotation in wordspace (this value is calculated once per frame by default - call updateRayWorldQuaternion to force an update)

    Returns any

  • get side(): any
  • If the controller if held in the left or right hand (or if it's a left or right hand)

    Returns any

  • get targetRayMode(): any
  • shorthand for inputSource.targetRayMode

    Returns any

  • get targetRaySpace(): any
  • shorthand for inputSource.targetRaySpace

    Returns any

Methods

  • Make sure to cancel the hittest source once it's not needed anymore

    Returns void

  • Get a gesture state

    Parameters

    • key: "pinch"

    Returns NeedleGamepadButton

  • Get the hand joint pose from the current XRFrame. Results are cached for a frame to avoid calling getJointPose multiple times

    Parameters

    Returns any

  • Perform a hit test against the XR planes or meshes. shorthand for xr.getHitTest(controller)

    Returns NeedleXRHitTestResult

    the hit test result (with position and rotation in worldspace) or null if no hit was found

  • returns the URL of the default controller model

    Returns Promise<string>

  • Get the pointer id for a specific button of this input device.
    This is useful if you want to check if a button (e.g. trigger) is currently being in use which can be queried on the inputsystem.

    Parameters

    • button: number

    Returns number

    the pointer id for the button or undefined if the button is not supported

    Example

    const pointerId = controller.getPointerId("primary");
    if (pointerId !== undefined) {
    const isUsed = this.context.input.getPointerUsed(pointerId);
    console.log(controller.side, "used?", isUsed);
    }
  • Parameters

    • button: NeedleXRControllerButtonName

    Returns number

  • Called when the input source disconnects

    Returns void

  • Parameters

    • _evt: any

    Returns void

  • Returns void

  • Parameters

    Returns void

  • Recalculates the ray world position

    Returns void

  • Recalculates the ray world quaternion

    Returns void

Generated using TypeDoc