XR

Input Manager

The input manager is part of the XRManager instance and can be accessed via xrManager.inputManager. It manages all input devices, including but not limited to:

  • Controllers
  • Head-mounted displays (HMDs)
  • Hands
  • ...

Methods

MethodDescription
getTrackedDeviceRetrieve a device by type using XRTrackedInputDevice to specify the target device.
addTrackedDeviceChangedListenerAdd a listener for device changes. The callback will be triggered when devices are added or removed, with the added/removed device lists as parameters.
removeTrackedDeviceChangedListenerRemove a device change listener.

Currently supported input devices include:

EnumerationDescription
XRTrackedInputDevice.CameraTypically the camera on AR devices
XRTrackedInputDevice.LeftCameraTypically the left eye of VR HMDs
XRTrackedInputDevice.RightCameraTypically the right eye of VR HMDs
XRTrackedInputDevice.ControlTypically the remote control for AR devices
XRTrackedInputDevice.LeftControllerTypically the left controller for VR devices
XRTrackedInputDevice.RightControllerTypically the right controller for VR devices

Usage

Use the following code to listen for device update events:

const { inputManager } = xrManager.inputManager;  
inputManager.addTrackedDeviceChangedListener((added: readonly XRInput[], removed: readonly XRInput[]) => {  
  // Add your logic to handle newly added or removed devices here  
});  

Use the following code to retrieve the pose of the left controller:

const controller = inputManager.getTrackedDevice<XRController>(XRTrackedInputDevice.LeftController);  
// Controller pose  
controller.gripPose.position;  
controller.gripPose.rotation;  
controller.gripPose.matrix;  
// Check if the Select button is pressed  
controller.isButtonDown(XRInputButton.Select);  
// Check if the Select button is released  
controller.isButtonUp(XRInputButton.Select);  
// Check if the Select button is held down  
controller.isButtonHeldDown(XRInputButton.Select);  

XRInputButton.Select corresponds to the native WebXR event XRInputSourceEventType.selectXXX. XRInputButton.Squeeze corresponds to the native WebXR event XRInputSourceEventType.squeezeXXX.

Was this page helpful?

On this page