Is there a way to simulate VR input devices on WebVR - A-Frame?

440 Views Asked by At

I'm currently using A-Frame to build WebXR (WebVR) applications, and it's not always that I'm able to have the controllers (Oculus Touch, Vive Controls) with me to test them out. Is there a way to "simulate" the events that the different controllers emit?

1

There are 1 best solutions below

2
On

I'm not sure about lower levels, but i have an idea on a higher one: If you have your vive controllers, and want to test out oculus touch events, you could do some mapping.

I'd do a component, intercepting the original events, and emitting new ones with the same details:

AFRAME.registerComponent("event-mapper", {
  init: function() {
    let viveEvents = ["menuup", "menudown"]
    let oculusEvents = ["gripdown", "gripup"]
    viveEvents .forEach((event, index) => {
      this.el.addEventListener(event, (e) => {
        this.el.emit(oculusEvents [index], {detail: e})
      })
    })
  }
}

If you want it to be "dynamic" you could use a real Map() instead of two arrays, but here it seems redundant.

Furthermore, by including the detail in the emitted event, all details, values, targets also get passed with the new event.


So when you want your entity to react to the mapped events, you can just do:

<a-entity event-mapper></a-entity>

Check it out in my fiddle (mapped some mouse events, onto made up ones)