@react-three/xr
Version:
VR/AR for react-three-fiber
103 lines (80 loc) âĸ 4.18 kB
Markdown
<p align="center">
<img src="./docs/getting-started/logo.svg" width="100" />
</p>
<h1 align="center">xr</h1>
<h3 align="center">Turn any R3F app into an interactive immersive experience.</h3>
<br/>
<p align="center">
<a href="https://npmjs.com/package/@react-three/xr" target="_blank">
<img src="https://img.shields.io/npm/v/@react-three/xr?style=flat&colorA=000000&colorB=000000" alt="NPM" />
</a>
<a href="https://npmjs.com/package/@react-three/xr" target="_blank">
<img src="https://img.shields.io/npm/dt/@react-three/xr.svg?style=flat&colorA=000000&colorB=000000" alt="NPM" />
</a>
<a href="https://twitter.com/pmndrs" target="_blank">
<img src="https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000" alt="Twitter" />
</a>
<a href="https://discord.gg/ZZjjNvJ" target="_blank">
<img src="https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000" alt="Discord" />
</a>
</p>
```bash
npm install three @react-three/fiber @react-three/xr@latest
```
| A simple scene with a mesh that toggles its material color between `"red"` and `"blue"` when clicked through touching or pointing. |  |
| ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
```tsx
import { Canvas } from '@react-three/fiber'
import { XR, createXRStore } from '@react-three/xr'
import { useState } from 'react'
const store = createXRStore()
export function App() {
const [red, setRed] = useState(false)
return (
<>
<button onClick={() => store.enterAR()}>Enter AR</button>
<Canvas>
<XR store={store}>
<mesh pointerEventsType={{ deny: 'grab' }} onClick={() => setRed(!red)} position={[0, 1, -1]}>
<boxGeometry />
<meshBasicMaterial color={red ? 'red' : 'blue'} />
</mesh>
</XR>
</Canvas>
</>
)
}
```
1. `const store = createXRStore()` create a xr store
2. `store.enterAR()` call enter AR when clicking on a button
3. `<XR>...</XR>` wrap your content with the XR component
... or read this guide for [converting a react-three/fiber app to XR](https://docs.pmnd.rs/xr/getting-started/convert-to-xr).
- đž [Store](https://docs.pmnd.rs/xr/tutorials/store)
- đ [Interactions](https://docs.pmnd.rs/xr/tutorials/interactions)
- đ [Handles](https://docs.pmnd.rs/xr/handles/introduction)
- đ§ [Options](https://docs.pmnd.rs/xr/tutorials/options)
- đ§ [Object Detection](https://docs.pmnd.rs/xr/tutorials/object-detection)
- â´ [Origin](https://docs.pmnd.rs/xr/tutorials/origin)
- đĒ [Teleport](https://docs.pmnd.rs/xr/tutorials/teleport)
- đšī¸ [Gamepad](https://docs.pmnd.rs/xr/tutorials/gamepad)
- â [Secondary Input Sources](https://docs.pmnd.rs/xr/tutorials/secondary-input-sources)
- đē [Layers](https://docs.pmnd.rs/xr/tutorials/layers)
- đŽ [Custom Controller/Hands/...](https://docs.pmnd.rs/xr/tutorials/custom-inputs)
- âī¸ [Anchors](https://docs.pmnd.rs/xr/tutorials/anchors)
- đą [Dom Overlays](https://docs.pmnd.rs/xr/tutorials/dom-overlay)
- đ¯ [Hit Test](https://docs.pmnd.rs/xr/tutorials/hit-test)
- ⨠[Guards](https://docs.pmnd.rs/xr/tutorials/guards)
- đĨ [**WebXR First Steps React** by Meta Quest](https://github.com/meta-quest/webxr-first-steps-react)
- đ¤ŗ XR Gestures
- đē Tracked Body
- from [@react-three/xr v5](https://docs.pmnd.rs/xr/migration/from-react-three-xr-5)
- from [natuerlich](https://docs.pmnd.rs/xr/migration/from-natuerlich)
This project is supported by a few companies and individuals building cutting-edge 3D Web & XR experiences. Check them out!
