Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headset control API #94

Open
takahirox opened this issue Sep 26, 2019 · 2 comments
Open

Headset control API #94

takahirox opened this issue Sep 26, 2019 · 2 comments

Comments

@takahirox
Copy link
Contributor

As written in the readme

The minimal input controls currently supported by WebXR is polyfilled here as well, using the Gamepad API.

Input can be controlled with Gamepad API by hacking navigator.getGamepads() in JavaScript (I'm not sure if it's recommended tho).

const customGamepad = {
  ...
};

const onSomething = () => {
  customGamepad.buttons[0].pressed = true;
};

navigator.getGamepads = () => {
  return [customGamepad];
};

Similarly, I'm happy if we can somehow control headset pose in JavaScript.

The background of this request is we've been developing WebXR emulator extension which emulates XR devices in JavaScript and I'm trying to integrate with webxr-polyfill. I need a way to control headset in JavaScript to accomplish the emulation.

@jsantell
Copy link
Contributor

To simulate a headset, it's possible to create your own "XRDevice" (like CardboardXRDevice and WebVRDevice) that provides its pose via the abstraction API, similar to how AR viewers can use the webxr-polyfill to connect to ARKit/ARCore (like Mozilla's webxr-viewer). The extension would have to wire up the polyfill with the device, similar to src/WebXRPolyfill.js here; some notes on extending the polyfill #56

@takahirox
Copy link
Contributor Author

takahirox commented Sep 26, 2019

Thanks for the comment. WebXRPolyfill creates device here so it seems we can extend WebXRPolyfill and override _patchNavigatorXR() to create custom device.

class MyWebXRPolyfill extends WebXRPolyfill {
  _patchNavigatorXR() {
    let devicePromise = new CustomXRDevice(this.global, this.config);

    // the following is duplicated with WebXRPolyfill._patchNavigatorXR()
    this.xr = new XR(devicePromise);
    Object.defineProperty(this.global.navigator, 'xr', {
      value: this.xr,
      configurable: true,
    });
  }
}

If we move requestXRDevice() in WebXRPolyfill class the duplicated code in MyWebXRPolyfill may be removed.

class MyWebXRPolyfill extends WebXRPolyfill {
  requestXRDevice() {
    return new CustomXRDevice(this.global, this.config);
  }
}

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants