A real form in a three.js scene

Three HTML documents on three kinds of surface: a laptop screen, a far-away billboard and a curved wall. Type, tab, select text, drag the slider, scroll the list. They're ordinary DOM elements inside the <canvas>, uploaded as textures on every paint, and the browser's hit testing follows them around the scene.

Best available WebGL WebGPU

Drag empty space to orbit, wheel or pinch to zoom. Everything on a screen takes input. Hover states, the caret and the clock repaint the texture.

Show the code HTML on three.js meshes
  1. A drawable canvas, and ordinary HTML for each screen. The canvas is the three.js canvas. The billboard's document is shown here; the form and the wall are the same idea.
  2. Make the renderer on that canvas and attach each document to a mesh. surfaces.add(element, mesh) moves the element into the canvas and gives the mesh a texture of it. { hit: 'mesh' } is for curved meshes.
  3. Call surfaces.update() before each render. It keeps hit testing in step with the camera. These lines are inside the animation callback.
  4. Inside the library: DOM to texture. On every canvas paint event, each element that changed is uploaded with gl.texElementSubImage2D(…, element) into its own sRGB texture with mipmaps.
  5. Inside the library: tell the browser where the element is on screen. For a flat mesh one perspective matrix (element pixels to canvas pixels) goes to canvas.updateElementGeometry(), and clicks, the caret and Tab then work natively.
  6. The whole library.
Postcard to the billboard
A plain <form>. Tab between fields, select text, press Enter to post.

Now showing · live DOM, 9 metres away

The DOM can go anywhere a pixel can.

from Ada

Guest book

#FromMessageWhen

Notes contenteditable

This wall is a 100° arc of a cylinder. No single matrix maps a rectangle onto it, so the element's geometry follows your pointer instead. Select this text, edit it, paste into it.
How is this hit tested?

On every pointer move the scene is raycast. The triangle and UV under the pointer give a small affine map that is exact at that spot, and updateElementGeometry() puts the element there.

Controls

A real link: all experiments ↗

Live checks

ResultExperimentDetail

How it is put together

import * as THREE from 'three';
import { HTMLSurfaces } from '/lib/html3d.js';

const renderer = new THREE.WebGLRenderer({ canvas });   // <canvas content="drawable">
const surfaces = new HTMLSurfaces(renderer, camera, { scene });

surfaces.add(form,  laptopScreen);                 // flat: one projective matrix
surfaces.add(guest, curvedWall, { hit: 'mesh' });  // curved: geometry follows the pointer

renderer.setAnimationLoop(() => { surfaces.update(); renderer.render(scene, camera); });

Findings