6.4.3 âĸ Published 8 months ago
@pmndrs/xr v6.4.3
npm install three @pmndrs/xr
What does it look like?
A simple scene with a mesh that toggles its material color between "red" and "blue" when clicked through touching or pointing. | ![]() |
---|
import { createXRStore } from '@pmndrs/xr'
import { BoxGeometry, Mesh, MeshBasicMaterial, PerspectiveCamera, Scene, WebGLRenderer } from 'three'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
const camera = new PerspectiveCamera(70, 1, 0.01, 100)
const scene = new Scene()
const canvas = document.getElementById('root') as HTMLCanvasElement
const renderer = new WebGLRenderer({ antialias: true, canvas, alpha: true })
const boxMaterial = new MeshBasicMaterial({ color: 'red' })
const box = new Mesh(new BoxGeometry(), boxMaterial)
box.pointerEventsType = { deny: 'grab' }
let red = false
box.addEventListener('click', () => {
red = !red
boxMaterial.color.set(red ? 'red' : 'blue')
})
scene.add(box)
const store = createXRStore(canvas, scene, camera, renderer.xr)
document.getElementById('enter-ar')?.addEventListener('click', () => store.enterAR())
let prevTime: undefined | number
renderer.setAnimationLoop((time, frame) => {
const delta = prevTime == null ? 0 : time - prevTime
prevTime = time
store.update(frame, delta)
renderer.render(scene, camera)
})
function updateSize() {
renderer.setSize(window.innerWidth, window.innerHeight)
renderer.setPixelRatio(window.devicePixelRatio)
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
}
updateSize()
window.addEventListener('resize', updateSize)
How to enable XR for your threejs app?
const store = createXRStore(canvas, scene, camera, renderer.xr)
create a xr storestore.enterAR()
call enter AR when clicking on a button
Tutorials
The following tutorials contain code for react-three/fiber but all informations are also applicable for @pmndrs/xr.
- đ Interactions
- đ§ Options
- đ§ Object Detection
- â´ Origin
- đĒ Teleport
- đšī¸ Gamepad
- đŽ Custom Controller/Hands/...
- ⨠Guards
Roadmap
- đ¤ŗ XR Gestures
- â Multimodal
- âī¸ Anchors
- đē Layers
- đą Dom Overlays
- đē Tracked Body
- đ¯ Hit Test
- â pmndrs/controls
Sponsors
This project is supported by a few companies and individuals building cutting-edge 3D Web & XR experiences. Check them out!
6.4.1
8 months ago
6.4.3
8 months ago
6.4.2
8 months ago
6.3.0
8 months ago
6.4.0
8 months ago
6.2.17
8 months ago
6.2.18
8 months ago
6.2.16
8 months ago
6.2.19
8 months ago
6.2.15
8 months ago
6.2.14
8 months ago
6.2.13
9 months ago
6.2.11
9 months ago
6.2.12
9 months ago
6.2.10
9 months ago
6.2.9
9 months ago
6.2.8
10 months ago
6.2.7
10 months ago
6.2.5
10 months ago
6.2.4
10 months ago
6.2.6
10 months ago
6.2.3
10 months ago
6.2.2
10 months ago
6.2.1
10 months ago
6.2.0
10 months ago
6.1.1
11 months ago
6.1.0
11 months ago
6.0.0
11 months ago