threejs-impl-xr

Implements VR and AR experiences in Three.js using the WebXR API.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-impl-xr-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-impl-xr
Source: https://github.com/imanlangaran/mini-projects/tree/main/react/three-gsap/.claude/skills/threejs-impl-xr
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-impl-xr-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires three, and includes references (resource) components.

What problem does it solve? Building WebXR experiences in Three.js involves subtle pitfalls that break immersion or cause motion sickness, such as using requestAnimationFrame instead of setAnimationLoop, moving the camera directly instead of a rig, or choosing the wrong reference space. This Skill provides correct patterns, API references, and anti-patterns for VR/AR development. ## Core Features & Use Cases - VR/AR Session Setup: Correct configuration of WebXRManager, VRButton, ARButton, session features, and reference space types. - Controllers & Hand Tracking: Controller target ray/grip/hand spaces, select and squeeze events, controller models, and pinch gestures. - AR Hit Testing & Teleportation: Real-world surface placement with reticles, teleportation locomotion via camera rigs, and estimated environment lighting. - Use Case: You are building a Quest 3 VR showroom where users teleport around and grab products with controllers. Use this Skill to set up the session, controllers, teleportation rig, and performance optimizations like foveated rendering. ## Quick Start Use the threejs-impl-xr skill to create a VR scene with controller laser pointers and teleportation on a floor plane.

Frequently Asked Questions about threejs-impl-xr

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a VR scene in Three.js with WebXR?

Set renderer.xr.enabled = true, choose a reference space like 'local-floor', add VRButton.createButton(renderer) to the DOM, and render with renderer.setAnimationLoop. Never use requestAnimationFrame, since it stops firing when an XR session is active.

How do I handle controller input in Three.js WebXR?

Call renderer.xr.getController(index) to get the target ray space and listen for selectstart, selectend, squeezestart, and squeezeend events. You must add the returned Group to the scene, otherwise its matrixWorld never updates and raycasting fails.

Why does my Three.js scene freeze when entering VR?

The scene freezes because requestAnimationFrame stops firing once a WebXR session starts. Replace it with renderer.setAnimationLoop, which works for both XR and non-XR rendering and is synchronized to the headset refresh rate.

How do I place objects on real surfaces with AR hit testing?

Request 'hit-test' as a required feature, then call session.requestHitTestSource with a viewer reference space. Each frame, call frame.getHitTestResults and position a reticle from the returned pose matrix; place objects at the reticle on select events.

What reference space should I use for room-scale VR?

Use 'local-floor' for standing or room-scale VR so y=0 corresponds to the physical floor. The 'local' space places the origin at initial head height, which makes floor-level objects appear at eye level.

Why is my VR app dropping frames and causing motion sickness?

Common causes are heavy post-processing (each pass renders twice in stereo), no foveated rendering, and per-frame object allocations triggering garbage collection. Set renderer.xr.setFoveation(1.0), avoid SSAO and bloom, and pre-allocate vectors and matrices outside the render loop.