Open takahirox opened 4 years ago
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
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?
As written in the readme
Input can be controlled with Gamepad API by hacking
navigator.getGamepads()
in JavaScript (I'm not sure if it's recommended tho).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.