WebXR panels made of ordinary HTML

A form, a guest book, a diagnostics read-out and a keyboard as panels in a 3D scene. Each one is plain HTML inside the <canvas>, uploaded as a texture on every paint. On this page you use them with the mouse or a finger. In a headset there is no mouse, so controller, hand and gaze rays are turned into pointer events on the same elements.

Emulate a headset
Show the code HTML panels in WebXR
  1. A drawable canvas and ordinary HTML for each panel. One of the four panels is shown.
  2. Give each panel a plane in the scene. surfaces.add(el, mesh) puts the element's live texture on the mesh. On the page, the mouse and touch work natively.
  3. In a session there is no mouse, so turn controller rays into pointer events. surfaces.createRayPointer() gives each controller a pointer: aim it with a raycaster, then down() and up() on the trigger.
  4. Inside the library: what a ray pointer does. It finds the element under the ray and fires the events a real pointer would, plus focus by hand.
  5. Inside the library: DOM to texture.
  6. The whole library.

Drag empty space to look around. Everything on a panel takes input. Click a text field, then use the floating keyboard: its keys never take focus, so the caret stays where it was. Enter AR on an Android phone should put the panels in your room, with a tap as the trigger. That path has only been run in the emulator so far.

Postcard
Guest book
    Scroll with the wheel or a thumbstick
    Diagnosticspage
    • Checks run two seconds after a session starts.

    Live checks

    ResultExperimentDetail

    Inside a session

    These run two seconds after a session starts, and also show on the Diagnostics panel inside the headset.

    ResultExperimentDetail
    …No session yet. Enter VR or AR, or use the emulator.

    How it is put together

    const surfaces = new HTMLSurfaces(renderer, camera, { scene });
    surfaces.add(form, panelMesh);                  // texture + native hit testing on the page
    
    // In a session the page has no pointer. Rays become pointer events on the same elements.
    const pointer = surfaces.createRayPointer();
    controller.addEventListener('selectstart', () => { pointer.move(raycaster); pointer.down(); });
    controller.addEventListener('selectend',   () => { pointer.move(raycaster); pointer.up(); });

    Findings