Private
_dirtyPrivate
_dirtyPrivate
_elementPrivate
_elementPrivate
_gripPrivate
_handPrivate
_hitPrivate
_idPrivate
_linearPrivate
_localPrivate
_localPrivate
_localPrivate
_localPrivate
_managerPrivate
_positionPrivate
_rayPrivate
_rayPrivate
_rotationPrivate
_selectingPrivate
_squeezingPrivate
_velocitiesPrivate
_velocitiesPrivate
_worldPrivate
_xrIf XrInputSource#elementInput is true, this property will hold entity with Element component at which this input source is hovering, or null if not hovering over any element.
Set to true to allow input source to interact with Element components. Defaults to true.
If input source can be held, then it will have node with its world transformation, that can be used to position and rotate visual object based on it.
Describes which hand input source is associated with. Can be one of the following:
List of active XrHitTestSource instances associated with this input source.
Unique number associated with instance of input source. Same physical devices when reconnected will not share this ID.
XRInputSource object that is associated with this input source.
List of input profile names indicating both the preferred visual representation and behavior of the input source.
True if input source is in active primary action between selectstart and selectend events.
True if input source is in active squeeze action between squeezestart and squeezeend events.
Type of ray Input Device is based on. Can be one of the following:
Private
_updatePrivate
_updateFire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message');
Get the linear velocity (units per second) of the input source if it is handheld (XrInputSource#grip is true). Otherwise it will return null.
The world space linear velocity of the handheld input source.
Get the local space position of input source if it is handheld (XrInputSource#grip is true). Local space is relative to parent of the XR camera. Otherwise it will return null.
The world space position of handheld input source.
Get the local space rotation of input source if it is handheld (XrInputSource#grip is true). Local space is relative to parent of the XR camera. Otherwise it will return null.
The world space rotation of handheld input source.
Get the world space position of input source if it is handheld (XrInputSource#grip is true). Otherwise it will return null.
The world space position of handheld input source.
Get the world space rotation of input source if it is handheld (XrInputSource#grip is true). Otherwise it will return null.
The world space rotation of handheld input source.
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false
Attempts to start hit test source based on this input source.
Optional
options: { Object for passing optional arguments.
Optional callback function called once hit test source is created or failed.
Optional list of underlying entity types against which hit tests will be performed. Defaults to [ XRTRACKABLE_PLANE ]. Can be any combination of the following:
Optional ray by which hit test ray can be offset.
app.xr.input.on('add', function (inputSource) {
inputSource.hitTestStart({
callback: function (err, hitTestSource) {
if (err) return;
hitTestSource.on('result', function (position, rotation, inputSource, hitTestResult) {
// position and rotation of hit test result
// that will be created from touch on mobile devices
});
}
});
});
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.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const 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 handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
obj.on('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
const evt = obj.on('test', function (a, b) {
console.log(a + b);
});
// some time later
evt.off();
Private
onPrivate
Hit test source to be added.
Private
onPrivate
Hit test source to be removed.
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
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
Static
EVENT_Fired when new XrHitTestSource is added to the input source. The handler is passed the XrHitTestSource object that has been added.
inputSource.on('hittest:add', (hitTestSource) => {
// new hit test source is added
});
Static
EVENT_Fired when XrHitTestSource is removed to the the input source. The handler is passed the XrHitTestSource object that has been removed.
inputSource.on('remove', (hitTestSource) => {
// hit test source is removed
});
Static
EVENT_Fired when hit test source receives new results. It provides transform information that tries to match real world picked geometry. The handler is passed the XrHitTestSource object that produced the hit result, the Vec3 position, the Quat rotation and the XRHitTestResult object that is created by the WebXR API.
inputSource.on('hittest:result', (hitTestSource, position, rotation, hitTestResult) => {
target.setPosition(position);
target.setRotation(rotation);
});
Static
EVENT_Fired when XrInputSource is removed.
inputSource.once('remove', () => {
// input source is not available anymore
});
Static
EVENT_Fired when input source has triggered primary action. This could be pressing a trigger button, or touching a screen. The handler is passed an XRInputSourceEvent object from the WebXR API.
const ray = new pc.Ray();
inputSource.on('select', (evt) => {
ray.set(inputSource.getOrigin(), inputSource.getDirection());
if (obj.intersectsRay(ray)) {
// selected an object with input source
}
});
Static
EVENT_Fired when input source has ended triggering primary action. The handler is passed an XRInputSourceEvent object from the WebXR API.
inputSource.on('selectend', (evt) => {
console.log('Select ended');
});
Static
EVENT_Fired when input source has started to trigger primary action. The handler is passed an XRInputSourceEvent object from the WebXR API.
inputSource.on('selectstart', (evt) => {
console.log('Select started');
});
Static
EVENT_Fired when input source has triggered squeeze action. This is associated with "grabbing" action on the controllers. The handler is passed an XRInputSourceEvent object from the WebXR API.
inputSource.on('squeeze', (evt) => {
console.log('Squeeze');
});
Static
EVENT_Fired when input source has ended triggering squeeze action. The handler is passed an XRInputSourceEvent object from the WebXR API.
inputSource.on('squeezeend', (evt) => {
console.log('Squeeze ended');
});
Static
EVENT_Fired when input source has started to trigger squeeze action. The handler is passed an XRInputSourceEvent object from the WebXR API.
inputSource.on('squeezestart', (evt) => {
if (obj.containsPoint(inputSource.getPosition())) {
// grabbed an object
}
});
Represents 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, touch screen taps, and gaze-based input methods that operate on the viewer's pose.