MozillaReality / WebXR-emulator-extension

WebXR emulator extension
Mozilla Public License 2.0
454 stars 55 forks source link

Expose the emulator to make it usable as an API, straight from the browser page #296

Open Utopiah opened 1 year ago

Utopiah commented 1 year ago

Some existing issues, e.g https://github.com/MozillaReality/WebXR-emulator-extension/issues/284 , already ask how some things can be done programmatically, e.g manipulating controllers.

I'm wondering if it could make sense and be easy enough to make the entire emulator, or at least key functions, e.g enter VR, update poses of head and controllers/hands, move fingers on hands, etc via JavaScript directly.

I'm working on a WebXR project focusing on hand tracking and a key aspect is moving objects around. If I could use something like WebXREmulator.hands[0].position.set(-0.1+Math.random()/100,1.6+Math.random()/100,-0.1+Math.random()/100) (randomness is just to fuzz things a bit, could be as sin() also to make it change overtime) then emulate a pinch, etc I could run series of tests right from the console. That would probably accelerate development time quite a bit.

Ledzz commented 1 year ago

@Utopiah you can dispatch custom events right now, like this:

window.dispatchEvent(
    new CustomEvent("webxr-input-pose", {
      detail: {
        position: [0, 0, 0],
        quaternion: [0, 0, 0, 0],
        objectName: 'rightController',
      },
    })
  );

But there's no docs and the API is unstable I guess as it is not exposed.

Utopiah commented 1 year ago

Thanks for the recommendation. I just tried to paste that in the console and nothing moved, neither in the emulator nor the WebXR experience. Did I miss a step?

Ledzz commented 1 year ago

@Utopiah exactly this command should move right controller to (0, 0, 0) point. Sadly, it moves it only in you app, but not in the emulator. I've just tried it, and it worked. Also try to replace quaternion to (0, 0, 0, 1)?