API Reference

Class List

pc.XrInputSource

Extends: pc.EventHandler

Represents an XR input source, which is any input mechanism which allows the user to perform targeted actions in the same virtual space as the viewer. Example XR input sources include, but are not limited to, handheld controllers, optically tracked hands, and gaze-based input methods that operate on the viewer's pose.

Summary

Properties

gamepad

If input source has buttons, triggers, thumbstick or touchpad, then this object provides access to its states.

grip

If input source can be held, then it will have node with its world transformation, that can be used to position and rotate virtual joystics based on it.

handedness

Describes which hand input source is associated with.

inputSource

XRInputSource object that is associated with this input source.

position

If {pc.XrInputSource#grip} is true, then position will represent position of handheld input source in local space of XR session.

profiles

List of input profile names indicating both the prefered visual representation and behavior of the input source.

ray

Ray that is calculated based on {pc.XrInputSource#targetRayMode} that can be used for interacting with virtual objects.

rotation

If {pc.XrInputSource#grip} is true, then rotation will represent rotation of handheld input source in local space of XR session.

selecting

True if input source is in active primary action between selectstart and selectend events.

targetRayMode

Type of ray Input Device is based on.

Events

remove

Fired when {pc.XrInputSource} is removed.

select

Fired when input source has triggered primary action.

selectend

Fired when input source has ended triggerring primary action.

selectstart

Fired when input source has started to trigger primary action.

Inherited

Methods

fire

Fire an event, all additional arguments are passed on to the event listener.

hasEvent

Test if there are any handlers bound to an event name.

off

Detach an event handler from an event.

on

Attach an event handler to an event.

once

Attach an event handler to an event.

Details

Constructor

XrInputSource(manager, xrInputSource)

Represents an XR input source, which is any input mechanism which allows the user to perform targeted actions in the same virtual space as the viewer. Example XR input sources include, but are not limited to, handheld controllers, optically tracked hands, and gaze-based input methods that operate on the viewer's pose.

Parameters

managerpc.XrManager

WebXR Manager.

xrInputSourceobject

XRInputSource object that is created by WebXR API.

Properties

Gamepad, nullgamepad

If input source has buttons, triggers, thumbstick or touchpad, then this object provides access to its states.

booleangrip

If input source can be held, then it will have node with its world transformation, that can be used to position and rotate virtual joystics based on it.

stringhandedness

Describes which hand input source is associated with. Can be one of the following:

  • pc.XRHAND_NONE: None - input source is not meant to be held in hands.
  • pc.XRHAND_LEFT: Left - indicates that input source is meant to be held in left hand.
  • pc.XRHAND_RIGHT: Right - indicates that input source is meant to be held in right hand.

objectinputSource

XRInputSource object that is associated with this input source.

pc.Vec3, nullposition

If {pc.XrInputSource#grip} is true, then position will represent position of handheld input source in local space of XR session.

string[]profiles

List of input profile names indicating both the prefered visual representation and behavior of the input source.

pc.Rayray

Ray that is calculated based on {pc.XrInputSource#targetRayMode} that can be used for interacting with virtual objects. Its origin and direction are in local space of XR session.

pc.Quat, nullrotation

If {pc.XrInputSource#grip} is true, then rotation will represent rotation of handheld input source in local space of XR session.

booleanselecting

True if input source is in active primary action between selectstart and selectend events.

stringtargetRayMode

Type of ray Input Device is based on. Can be one of the following:

  • pc.XRTARGETRAY_GAZE: Gaze - indicates the target ray will originate at the viewer and follow the direction it is facing. (This is commonly referred to as a "gaze input" device in the context of head-mounted displays.)
  • pc.XRTARGETRAY_SCREEN: Screen - indicates that the input source was an interaction with the canvas element associated with an inline session’s output context, such as a mouse click or touch event.
  • pc.XRTARGETRAY_POINTER: Tracked Pointer - indicates that the target ray originates from either a handheld device or other hand-tracking mechanism and represents that the user is using their hands or the held device for pointing.

Events

remove

Fired when {pc.XrInputSource} is removed.

inputSource.on('remove', function () {
    // input source is not available anymore
});

select

Fired when input source has triggered primary action. This could be pressing a trigger button, or touching a screen.

app.xr.input.on('select', function (evt) {
    if (obj.intersectsRay(inputSource.ray)) {
        // selected an object with input source
    }
});

Parameters

evtobject

XRInputSourceEvent event data from WebXR API

selectend

Fired when input source has ended triggerring primary action.

Parameters

evtobject

XRInputSourceEvent event data from WebXR API

selectstart

Fired when input source has started to trigger primary action.

Parameters

evtobject

XRInputSourceEvent event data from WebXR API

Inherited

Methods

fire(name, [arg1], [arg2], [arg3], [arg4], [arg5], [arg6], [arg7], [arg8])

Fire an event, all additional arguments are passed on to the event listener.

obj.fire('test', 'This is the message');

Parameters

nameobject

Name of event to fire.

arg1*

First argument that is passed to the event handler.

arg2*

Second argument that is passed to the event handler.

arg3*

Third argument that is passed to the event handler.

arg4*

Fourth argument that is passed to the event handler.

arg5*

Fifth argument that is passed to the event handler.

arg6*

Sixth argument that is passed to the event handler.

arg7*

Seventh argument that is passed to the event handler.

arg8*

Eighth argument that is passed to the event handler.

Returns

pc.EventHandler

Self for chaining.

hasEvent(name)

Test if there are any handlers bound to an event name.

obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false

Parameters

namestring

The name of the event to test.

Returns

boolean

True if the object has handlers bound to the specified event name.

off([name], [callback], [scope])

Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

var handler = function () {
};
obj.on('test', handler);

obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all hander functions, called 'test' with scope this

Parameters

namestring

Name of the event to unbind.

callbackpc.callbacks.HandleEvent

Function to be unbound.

scopeobject

Scope that was used as the this when the event is fired.

Returns

pc.EventHandler

Self for chaining.

on(name, callback, [scope])

Attach an event handler to an event.

obj.on('test', function (a, b) {
    console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console

Parameters

namestring

Name of the event to bind the callback to.

callbackpc.callbacks.HandleEvent

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scopeobject

Object to use as 'this' when the event is fired, defaults to current this.

Returns

pc.EventHandler

Self for chaining.

once(name, callback, [scope])

Attach an event handler to an event. This handler will be removed after being fired once.

obj.once('test', function (a, b) {
    console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled

Parameters

namestring

Name of the event to bind the callback to.

callbackpc.callbacks.HandleEvent

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scopeobject

Object to use as 'this' when the event is fired, defaults to current this.

Returns

pc.EventHandler

Self for chaining.