meta-quest / immersive-web-emulator

Browser extension that emulates Meta Quest devices for WebXR development. Lead: Felix Zhang (fe1ix@meta.com)
https://developer.oculus.com/blog/webxr-development-immersive-web-emulator/
MIT License
297 stars 34 forks source link

gamepad axes are undefined #13

Closed andreasplesch closed 1 year ago

andreasplesch commented 1 year ago

xrFrame.session.inputSources[n].gamepad.axes[0] can be undefined even though the gamepad object exists and is not null.

This apparently happens for the Quest Pro emulator, perhaps as a result of using a polyfill.

The Mozilla extension reports a number as required by the gamepad spec.

felixtrz commented 1 year ago

According to the WebXR Gamepad API spec: https://www.w3.org/TR/webxr-gamepads-module-1/#example-mappings, gamepad.axes[0] and gamepad.axes[1] are supposed to be the x and y value of touch pad on controllers, quest devices do not have a touch pad, so the value being null or undefined is expected.

If you are looking for the joystick x and y value, they are gamepad.axes[2] and gamepad.axes[3]

felixtrz commented 1 year ago

Also, according to the spec: https://www.w3.org/TR/webxr-gamepads-module-1/#xr-standard-heading, none of the axes values are required.

Screenshot 2023-02-16 at 3 39 25 PM
felixtrz commented 1 year ago

@andreasplesch I am closing this issue now, feel free to reopen this if my comments did not fully address your concerns.

andreasplesch commented 1 year ago

Thanks. But I think you may have missed

https://www.w3.org/TR/webxr-gamepads-module-1/#xr-standard-heading

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.

So instead of null or undefined the placeholder value must be 0.

This is to make it compatible with

https://w3c.github.io/gamepad/#dom-gamepad-axes

which states:

All axis values MUST be linearly normalized to the range [-1.0 .. 1.0].

as well as https://www.w3.org/TR/gamepad/#dfn-axes

A [sequence](https://webidl.spec.whatwg.org/#idl-sequence) of [double](https://webidl.spec.whatwg.org/#idl-double) values representing the current state of axes exposed by this device

andreasplesch commented 1 year ago

Unfortunately I cannot reopen the issue. Please let me know if I should file a new issue.

felixtrz commented 1 year ago

Oops! You got me there. I will put up a fix soon!

andreasplesch commented 1 year ago

Glad to help !

felixtrz commented 1 year ago

This should now be fixed, you can get the fix now by building from source, or you can wait til next week when we push an update. Thanks again for flagging this!