immersive-web / webxr-gamepads-module

Repository for the WebXR Gamepads Module
https://immersive-web.github.io/webxr-gamepads-module
Other
30 stars 11 forks source link

Haptics #29

Open lojjic opened 4 years ago

lojjic commented 4 years ago

This is a feature request for a formalized API for haptic feedback on WebXR gamepad inputs, when available. Even very simple haptics can greatly increase immersion and usability in XR applications.

The Gamepad Extensions draft defines a simple interface for pulsing haptic actuators, and that did already have some decent browser support in WebVR. That spec contains other extensions (hand and pose) that seem obsolete, however, so it may be good to respec it in a webxr module.

Or, that may not be ideal in WebXR's more robust model -- e.g looking forward to more complex haptic hardware, haptics on gamepad-less input sources, etc. -- in which case it would need a new API.

Refs: https://twitter.com/Tojiro/status/1249787874708303873 https://github.com/immersive-web/webvr/issues/23 https://w3c.github.io/gamepad/extensions.html#gamepadhapticactuator-interface

Artyom17 commented 4 years ago

Just FYI, Oculus Browser 8.5 (ETA end of this week) will have experimental support for haptics via adding hapticActuators / pulse into the gamepad object. The sample can be seen here: https://github.com/Artyom17/webxr-samples/blob/gh-pages/controller-state.html

toji commented 4 years ago

That's great to hear, @Artyom17! I've very curious to see how that works out and what bumps (if any) you hit along the way. It'll be very informative for the rest of the group.

Artyom17 commented 4 years ago

@toji It was pretty straight forward port of whatever I had for WebVR. In JS code it looks like this:

        if ("hapticActuators" in gamepad && gamepad.hapticActuators.length > 0) {
          for (let j = 0; j < gamepad.buttons.length; ++j) {
            if (gamepad.buttons[j].pressed) {
              // Vibrate the gamepad using to the value of the button as
              // the vibration intensity, normalized to 0.0..1.0 range.
              gamepad.hapticActuators[0].pulse((j + 1.0) / (gamepad.buttons.length + 1), 1000);
              break;
            }
          }
ngokevin commented 4 years ago

@Artyom17 Is the experimental API still around?

RaananW commented 4 years ago

Working wonderfully on the quest. Integrated in Babylon.js already - https://github.com/BabylonJS/Babylon.js/blob/master/src/XR/motionController/webXRAbstractMotionController.ts#L410

De-Panther commented 4 years ago

Also works at https://github.com/De-Panther/unity-webxr-export It was the simplest WebXR related feature to add so far.

julianfrank commented 2 years ago

Working wonderfully on the quest. Integrated in Babylon.js already - https://github.com/BabylonJS/Babylon.js/blob/master/src/XR/motionController/webXRAbstractMotionController.ts#L410

Is there a sample code for this?

RaananW commented 2 years ago

Working wonderfully on the quest. Integrated in Babylon.js already - https://github.com/BabylonJS/Babylon.js/blob/master/src/XR/motionController/webXRAbstractMotionController.ts#L410

Is there a sample code for this?

Sure - https://playground.babylonjs.com/#9K3MRA#854

julianfrank commented 2 years ago

Working wonderfully on the quest. Integrated in Babylon.js already - https://github.com/BabylonJS/Babylon.js/blob/master/src/XR/motionController/webXRAbstractMotionController.ts#L410

I can second that now... works like a charm now