WebXR runs three.js scenes in headsets (immersive VR) and on phones (immersive AR with hit testing). Support is uneven, so decide the target first:
- Android Chrome: immersive AR with hit test, anchors, DOM overlay, light estimation.
- Meta Quest browser: immersive VR and passthrough AR, controllers and hands.
- Apple Vision Pro Safari: immersive VR with hand and gaze input.
- iPhone Safari: no immersive WebXR. For "view this product in my room" on iOS, use
web3d-model-viewer(Quick Look), which also covers Android with less code.
Process
- Model scale is meters in XR, always: a 180-unit centimeter model fills the room. Inspect and fix scale first
(
threejs-model-inspect). - Read the recipe for the stack:
references/vanilla.md(three'sXRButton/ARButton,renderer.xr) orreferences/r3f.md(@react-three/xr6:createXRStore,<XR>, hit-test hooks). - Render with
renderer.setAnimationLooponly;requestAnimationFramestops inside an XR session. In R3F this is automatic. - Request only the session features you use (
hit-test,anchors,dom-overlay,hand-tracking,light-estimation); missing optional features must degrade, not crash. - Light AR content from the real room when possible (
XREstimatedLightin vanilla), or at least with an environment map, so placed models do not look pasted on. - Hold 72-90 fps on the headset: halve draw calls and texture sizes compared with desktop, avoid post-processing, and keep the pixel ratio at the device default (the XR framebuffer sets it).
- Test on the real device. Desktop browsers can emulate sessions (the Immersive Web Emulator extension), which is fine for logic, not for comfort or performance.
Anti-patterns
- Moving the camera in XR; the headset owns it. Move a parent of the content (or the XR origin) instead.
- Showing an "Enter AR" button without checking
navigator.xr.isSessionSupported("immersive-ar"). - Placing models without hit testing, so they float or sink in the room.
- Large text in 3D canvases for UI; use DOM overlay on phones and readable, world-anchored panels in headsets.
Done when
- The session starts from a user gesture on the target devices, and unsupported devices see a fallback.
- Placed or VR content is at real-world scale and lit to match.
- Frame rate holds on the target headset for a full minute of movement.
Next: web3d-model-viewer when the requirement is only product AR.