1. Introduction
Hardware that enables Virtual Reality (VR) and Augmented Reality (AR) applications are now broadly available to consumers, offering an immersive computing platform with both new opportunities and challenges. The ability to interact directly with immersive hardware is critical to ensuring that the web is well equipped to operate as a first-class citizen in this environment. The WebXR Gamepads module adds interfaces and behaviors to the WebXR Device API and the Gamepads API to allow for querying the state of buttons, triggers, thumbsticks, and touchpads available as input sources on many WebXR compatible devices.
This module is an addition to the WebXR Device API.
1.1. Terminology
This document uses the acronym XR throughout to refer to the spectrum of hardware, applications, and techniques used for Virtual Reality, Augmented Reality, and other related technologies. Examples include, but are not limited to:
-
Head mounted displays, whether they are opaque, transparent, or utilize video passthrough
-
Mobile devices with positional tracking
-
Fixed displays with head tracking capabilities
The important commonality between them being that they offer some degree of spatial tracking with which to simulate a view of virtual content.
Terms like "XR Device", "XR Application", etc. are generally understood to apply to any of the above. Portions of this document that only apply to a subset of these devices will indicate so as appropriate.
XR Devices often have additional controller hardware that allows users to interact with immersive experiences with button, trigger, thumbstick, or touchpad inputs. Frequently these devices are spatially tracked as well, and referred to as "motion controllers", "handheld controllers", or "tracked controllers".
2. WebXR Device API Integration
As defined in the WebXR Device API API, anXRInputSource
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.
This document outlines the behavior of an XRInputSource
when it has button, trigger, thumbstick, or touchpad data to report. This is commonly a motion controller, but may also be headset with buttons, triggers, thumbsticks, or touchpads on the XR device. As stated in the WebXR device API, input mechanisms which are not explicitly associated with the XR Device, such as traditional gamepads, MUST NOT be considered XR input sources.
2.1. XRInputSource
Button, trigger, thumbstick, and touchpad data is reported though a Gamepad
object exposed on the XRInputSource
it is associated with.
partial interface XRInputSource { [SameObject ]readonly attribute Gamepad ?gamepad ; };
The gamepad
attribute is a Gamepad
that describes the state of any buttons and axes on the XR input source. If the XR input source does not have at least one of the following properties, the gamepad
attribute MUST be null
:
-
A single button and a gripSpace
-
More than one button
-
One or more axes
2.2. XRSession
XRInputSource
s are reported in the inputSources
array as they are connected and disconnected. When the presence of a gamepad
changes for any entry in the inputSources
array, the user agent MUST invoke the WebXR Device API’s algorithm for responding to input source attribute changes.
The list of frame updates is updated to include apply gamepad frame updates.
To apply gamepad frame updates for an XRFrame
frame, the user agent MUST run the following steps:
-
For each
XRInputSource
with agamepad
gamepad associated with frame’ssession
, perform the following steps:-
Update gamepad to reflect the gamepad data at frame’s time.
-
NOTE: This means that the gamepad
object is "live", and any internal state is to be updated in-place every frame. Furthermore, it doesn’t work to save a reference to an XRInputSource
's gamepad
on one frame and compare it to the same XRInputSource
's gamepad
from a subsequent frame to test for state changes, because they will be the same object. Therefore developers that wish to compare input state from frame to frame should cache the state in question.
3. Gamepad API Integration
Gamepad
instances returned by an XRInputSource
's gamepad
attribute behave as described by the Gamepad API, with several additional behavioral restrictions.
An XRInputSource
's associated Gamepad
MAY be exposed via navigator.getGamepads()
, even if there is no active XR session by user agent choice. This allows XR devices to be used as "regular" gamepads if the user agent wishes to allow this.
Note: Hand tracking XRInputSource
s as described in [WEBXR-HAND-INPUT-1] may contain a Gamepad
if the user agent wishes to allow hand-based input sources to be used with gamepad-based content.
3.1. Navigator
The Gamepad API states a snapshot of Gamepad
data can be retrieved by calling the navigator.getGamepads()
function. However, Gamepad
instances returned by an XRInputSource
's gamepad
attribute MUST NOT be included in the array returned by navigator.getGamepads()
.
3.2. Gamepad
The following Gamepad
attributes MUST exhibit the following behavioral restrictions when the Gamepad
has been returned by an XRInputSource
's gamepad
attribute.
-
gamepad
'sindex
attribute MUST be-1
if it is not exposed vianavigator.getGamepads()
, otherwise it should be assigned as specified by selecting an unused gamepad index. -
gamepad
'sconnected
attribute MUST betrue
until theXRInputSource
is removed from the list of active XR input sources or theXRSession
is ended. -
If an axis reported by the
gamepad
'saxes
array represents an axis of a touchpad, the value MUST be0
when the associatedGamepadButton
'stouched
isfalse
.
3.3. "xr-standard" Gamepad Mapping
The "xr-standard"
mapping is defined in the Gamepad API and reserved for use by this spec. It indicates that the layout of the buttons and axes of the gamepad
corresponds as closely as possible to the tables below.
In order to report a mapping
of "xr-standard"
the device MUST report a targetRayMode
of "tracked-pointer"
and MUST have a non-null
gripSpace
. It MUST have at least one primary trigger, separate from any touchpads or thumbsticks. The primary trigger MUST trigger the primary action for the input source. The device MAY have a primary squeeze button, which, if present, MUST trigger the primary squeeze action for the input source. If a device does not meet the requirements for the "xr-standard"
mapping it may still expose a gamepad
with a mapping
of ""
(empty string). The "xr-standard"
mapping MUST only be used by Gamepad
instances reported by an XRInputSource
.
Buttons | xr-standard Mapping
| Required |
---|---|---|
buttons[0] | Primary trigger | Yes |
buttons[1] | Primary squeeze button | No |
buttons[2] | Primary touchpad | No |
buttons[3] | Primary thumbstick | No |
Axes | xr-standard Mapping
| Required |
---|---|---|
axes[0] | Primary touchpad X | No |
axes[1] | Primary touchpad Y | No |
axes[2] | Primary thumbstick X | No |
axes[3] | Primary thumbstick Y | No |
Devices that lack one of the optional inputs listed in the tables above MUST preserve their place in the buttons
or axes
array, reporting a placeholder button or placeholder axis, respectively. A placeholder button MUST report 0
for value
, false
for pressed
, and false
for touched
. A placeholder axis MUST report 0
. Placeholder buttons and axes MUST be omitted if they are the last element in the array or all following elements are also placeholder buttons or axes.
Additional buttons or axes may be exposed after these reserved indices, and SHOULD appear in order of decreasing importance. Related axes (such as both axes of a thumbstick) MUST be grouped and, if applicable, MUST appear in X, Y, Z order.
3.4. UA/Platform reserved buttons
User Agents SHOULD reserve at least one physical button, when possible, for performing unspoofable actions as part of a trusted UI. For example, the User Agent could designate the "menu" or "app" button present on many controllers as a dedicated button for exiting immersive presentation.Additionally, many XR platforms also reserve a button for platform specific actions, such as returning to a home environment.
Buttons reserved by the UA or platform MUST NOT be exposed on the Gamepad
. Additionally, User Agents SHOULD make an effort to coordinate which buttons are reserved for a given XR platform. The WebXR Input Profiles Registry is the recommended location for coordinating button reservations.
3.5. Example Mappings
"xr-standard"
mapping. Images are not intended to represent any particular device and are used for reference purposes only. 4. Security and Privacy
The WebXR Device API provides powerful new features which bring with them several unique privacy, security, and comfort risks that user agents must take steps to mitigate. This topic is covered in detail as part of the WebXR Device API. This module adds additional considerations, but does not change the fundamental WebXR security and privacy principles.
4.1. Fingerprinting
Given that the API describes hardware available to the user and its capabilities it will inevitably provide additional surface area for fingerprinting. While it’s impossible to completely avoid this, user agents should take steps to mitigate the issue. As defined in the WebXR Device API, XRInputSource
s are only reported after an XRSession
has been created, which requires additional protections when sensitive information will be exposed. In addition, this module requires XRInputSource
's gamepad
.id
to not report a string identifiers.
Changes
Changes from the First Public Working Draft 10 October 2019
-
Explicitly leave Gamepad API Integration up to the user agent (GitHub #49)
-
Added spec text specifying that reserved buttons are not exposed (GitHub #48)
-
Relaxed definitions of gamepad.index (GitHub #46, GitHub #47)
-
Defined primary trigger and linked buttons (GitHub #24)
-
Clarified operations when the gamepad state is updated (GitHub #22)
5. Acknowledgements
The following individuals have contributed to the design of the WebXR Device API specification:
-
Sebastian Sylvan (Formerly Microsoft)
And a special thanks to Vladimir Vukicevic (Unity) for kick-starting this whole adventure!