Index of every page on this site: llms.txt
All skills
Run it yourself

Use when building VR or AR experiences with Three.js using WebXR. Prevents the common mistake of using requestAnimationFrame instead of setAnimationLoop, not handling controller events, or wrong reference space. Covers WebXRManager, VRButton, ARButton, controllers, hand tracking, hit testing, teleportation. Keywords: VR, AR, XR, WebXR, VRButton, ARButton, immersive, controller, hand tracking, hit test, teleportation, headset, virtual reality, augmented reality, VR app, AR experience.

Use this Skill: https://skilld.dev/gh/impertio-studio/three.js-claude-skill-package/threejs-impl-xr

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesmethods.md

≈1.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

threejs-impl-xr — Methods Reference

WebXRManager

Accessed via renderer.xr. Manages the complete WebXR session lifecycle.

Properties

renderer.xr.enabled: boolean                // Default: false. MUST set to true for XR.
renderer.xr.isPresenting: boolean            // Read-only. True when XR session is active.
renderer.xr.cameraAutoUpdate: boolean        // Default: true. Auto-updates camera from XR device pose.

Methods

// Session management
renderer.xr.getSession(): XRSession | null
renderer.xr.setSessionInit(sessionInit: XRSessionInit): void
renderer.xr.setReferenceSpaceType(type: string): void
renderer.xr.getReferenceSpace(): XRReferenceSpace | null

// Controllers
renderer.xr.getController(index: number): THREE.Group
renderer.xr.getControllerGrip(index: number): THREE.Group
renderer.xr.getHand(index: number): THREE.Group

// Performance
renderer.xr.setFoveation(foveation: number): void      // 0.0 (none) to 1.0 (max)
renderer.xr.getFoveation(): number
renderer.xr.setFramebufferScaleFactor(scale: number): void

// Environment
renderer.xr.getEnvironmentBlendMode(): string           // 'opaque' | 'additive' | 'alpha-blend'

VRButton

import { VRButton } from 'three/addons/webxr/VRButton.js';

VRButton.createButton(renderer: THREE.WebGLRenderer): HTMLElement

Returns a DOM button element that:

  • Checks for WebXR immersive-vr support
  • Shows "ENTER VR" when supported
  • Shows "VR NOT SUPPORTED" when unavailable
  • Handles session request/end lifecycle automatically

ARButton

import { ARButton } from 'three/addons/webxr/ARButton.js';

ARButton.createButton(
  renderer: THREE.WebGLRenderer,
  sessionInit?: XRSessionInit
): HTMLElement

Returns a DOM button element that:

  • Checks for WebXR immersive-ar support
  • Accepts optional sessionInit for required/optional features
  • Handles session request/end lifecycle automatically

XRSessionInit Structure

interface XRSessionInit {
  requiredFeatures?: string[];    // Session fails if unavailable
  optionalFeatures?: string[];    // Session proceeds without these
  domOverlay?: { root: HTMLElement };
}

Common features: 'hit-test', 'hand-tracking', 'dom-overlay', 'anchors', 'plane-detection', 'depth-sensing', 'light-estimation'.


XRControllerModelFactory

import { XRControllerModelFactory } from 'three/addons/webxr/XRControllerModelFactory.js';

const factory = new XRControllerModelFactory(gltfLoader?: GLTFLoader);
factory.createControllerModel(controllerGrip: THREE.Group): THREE.Object3D
  • ALWAYS pass the grip space (getControllerGrip), NOT the target ray space
  • Automatically loads the correct 3D model for the detected controller hardware
  • Uses the WebXR Input Profiles library for model matching

XRHandModelFactory

import { XRHandModelFactory } from 'three/addons/webxr/XRHandModelFactory.js';

const factory = new XRHandModelFactory();
factory.createHandModel(
  hand: THREE.Group,
  profile?: 'mesh' | 'spheres' | 'boxes'
): THREE.Object3D
  • 'mesh' — Realistic hand mesh (default)
  • 'spheres' — Joint positions as spheres
  • 'boxes' — Joint positions as boxes

XREstimatedLight

import { XREstimatedLight } from 'three/addons/webxr/XREstimatedLight.js';

const xrLight = new XREstimatedLight(renderer: THREE.WebGLRenderer);
xrLight.environment: THREE.Texture    // Environment map for PBR materials
xrLight.lightProbe: THREE.LightProbe  // Spherical harmonics light probe
xrLight.directionalLight: THREE.DirectionalLight  // Primary directional light

Events:

  • 'estimationstart' — Light estimation data available
  • 'estimationend' — Light estimation lost

XRPlanes

import { XRPlanes } from 'three/addons/webxr/XRPlanes.js';

const planes = new XRPlanes(renderer: THREE.WebGLRenderer);
scene.add(planes);

Requires 'plane-detection' in session features. Automatically creates mesh visualizations for detected real-world planes.


renderer.setAnimationLoop

renderer.setAnimationLoop(
  callback: ((time: DOMHighResTimeStamp, frame?: XRFrame) => void) | null
): void
  • MUST use this instead of requestAnimationFrame for XR
  • The frame parameter is an XRFrame when an XR session is active, undefined otherwise
  • Pass null to stop the loop
  • Works for both XR and non-XR rendering (safe to use unconditionally)

Controller Events

All events fire on the THREE.Group returned by getController():

controller.addEventListener('select', (event: { target: THREE.Group }) => void): void
controller.addEventListener('selectstart', (event: { target: THREE.Group }) => void): void
controller.addEventListener('selectend', (event: { target: THREE.Group }) => void): void
controller.addEventListener('squeeze', (event: { target: THREE.Group }) => void): void
controller.addEventListener('squeezestart', (event: { target: THREE.Group }) => void): void
controller.addEventListener('squeezeend', (event: { target: THREE.Group }) => void): void
controller.addEventListener('connected', (event: { data: XRInputSource, target: THREE.Group }) => void): void
controller.addEventListener('disconnected', (event: { target: THREE.Group }) => void): void

XRInputSource Properties (from connected event)

event.data.handedness: 'none' | 'left' | 'right'
event.data.targetRayMode: 'gaze' | 'tracked-pointer' | 'screen'
event.data.profiles: string[]        // e.g., ['oculus-touch-v3', 'oculus-touch-v2']
event.data.gamepad: Gamepad | null   // Buttons and axes for gamepad-style input
event.data.hand: XRHand | null       // Hand joint data if hand tracking active

Hand Tracking Events

Events fire on the THREE.Group returned by getHand():

hand.addEventListener('connected', (event) => void): void
hand.addEventListener('disconnected', (event) => void): void
hand.addEventListener('pinchstart', (event) => void): void
hand.addEventListener('pinchend', (event) => void): void

WebXR Hit Test API (Browser API, used within Three.js loop)

// Request hit test source (once per session)
const viewerSpace = await session.requestReferenceSpace('viewer');
const hitTestSource = await session.requestHitTestSource({ space: viewerSpace });

// Each frame
const results: XRHitTestResult[] = frame.getHitTestResults(hitTestSource);
const pose: XRPose = results[0].getPose(referenceSpace);
// pose.transform.matrix is a Float32Array(16)

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5mo3 checks · Risk SAFE
  • Gen Agent Trust Hub5mo

    The skill provides comprehensive documentation and code templates for implementing VR and AR features using Three.js and WebXR. It follows industry best practices and contains no malicious patterns, hidden code, or dangerous command executions.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: LOW · No issues

Signed by skilld at 6c190f0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 8 months ago
compatibility
Designed for Claude Code. Requires Three.js r160+.
metadata
{
  "author": "OpenAEC-Foundation",
  "version": "1.0"
}

README badge

README badge for impertio-studio/three.js-claude-skill-package/threejs-impl-xr