All Projects β†’ pmndrs β†’ React Xr

pmndrs / React Xr

Licence: mit
🀳 VR/AR with react-three-fiber

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Xr

Webxr Emulator Extension
WebXR emulator extension
Stars: ✭ 231 (-61.31%)
Mutual labels:  vr, webxr
aframe-react
React library for A-frame
Stars: ✭ 58 (-90.28%)
Mutual labels:  vr, webxr
Webxr Polyfill
Use the WebXR Device API today, providing fallbacks to native WebVR 1.1 and Cardboard
Stars: ✭ 251 (-57.96%)
Mutual labels:  vr, webxr
Remixvr
RemixVR is a tool for collaboratively building customisable VR experiences.
Stars: ✭ 129 (-78.39%)
Mutual labels:  vr, webxr
Vr Dos
πŸ’Ύ Virtual Reality DOS πŸ’Ύ
Stars: ✭ 416 (-30.32%)
Mutual labels:  vr, webxr
Webar Article
WebAR-Article is a responsive and information rich website that is progressively enhanced with Augmented Reality content exposed through experimental web technologies.
Stars: ✭ 225 (-62.31%)
Mutual labels:  vr, webxr
Ideaspace
😎 Create interactive 3D and VR web experiences for desktop, mobile & VR devices
Stars: ✭ 344 (-42.38%)
Mutual labels:  vr, webxr
Lovr
Lua Virtual Reality Engine
Stars: ✭ 743 (+24.46%)
Mutual labels:  vr, webxr
webvrrocks
Your guide to Virtual Reality in the browser.
Stars: ✭ 116 (-80.57%)
Mutual labels:  vr, webxr
spacesvr
A standardized reality for the future of the 3D Web.
Stars: ✭ 135 (-77.39%)
Mutual labels:  vr, webxr
Emukit
WebXR immersive console emulator w/ Retroach, Javascript, and WASM
Stars: ✭ 123 (-79.4%)
Mutual labels:  vr, webxr
app
Web metaverse client
Stars: ✭ 115 (-80.74%)
Mutual labels:  vr, webxr
Webxr Handtracking
πŸ‘ WebXR hand tracking examples
Stars: ✭ 116 (-80.57%)
Mutual labels:  vr, webxr
Webxr Polyfill
A polyfill and example code for building augmented reality (AR) and virtual reality (VR) applications using WebXR.
Stars: ✭ 227 (-61.98%)
Mutual labels:  vr, webxr
Webxr Physics
Adds physics to WebXR
Stars: ✭ 18 (-96.98%)
Mutual labels:  vr, webxr
awesome-webxr
All things WebXR.
Stars: ✭ 117 (-80.4%)
Mutual labels:  vr, webxr
VRStreaming
Unity Render Streaming SDK to stream VR from CloudXR to WebXR over WebRTC
Stars: ✭ 112 (-81.24%)
Mutual labels:  vr, webxr
emscripten-webxr
WebXR library for use with Emscripten.
Stars: ✭ 21 (-96.48%)
Mutual labels:  vr, webxr
Jeelizar
JavaScript object detection lightweight library for augmented reality (WebXR demos included). It uses convolutional neural networks running on the GPU with WebGL.
Stars: ✭ 296 (-50.42%)
Mutual labels:  vr, webxr
Troika
A JavaScript framework for interactive 3D and 2D visualizations
Stars: ✭ 342 (-42.71%)
Mutual labels:  webxr

@react-three/xr

Version Downloads Discord Shield

React components and hooks for creating VR/AR applications with react-three-fiber

npm install @react-three/xr

These demos are real, you can click them! They contain the full code, too.

Getting started

Add VRCanvas or ARCanvas component (or replace your existing react-three-fiber Canvas component)

import { VRCanvas } from '@react-three/xr'

function App() {
  return (
    <VRCanvas>
      {/* All your regular react-three-fiber elements go here */}
    </VRCanvas>

Adding controllers to the scene

To get started with default controller models add DefaultXRControllers component. It will fetch appropriate input profile models. You can learn more here.

import { VRCanvas, DefaultXRControllers } from '@react-three/xr'

<VRCanvas>
  <DefaultXRControllers />

You can access controllers' state (position, orientation, etc.) by using useXR() hook

const { controllers } = useXR()

Interactions

To interact with objects using controllers you can use <Interactive> component or useInteraction hook. They allow adding handlers to your objects. All interactions are use rays that are shot from the controllers.

<Interactive>

Use this component to wrap your objects and pass handlers as props. Supports select, hover, blur and squeeze events.

const [isHovered, setIsHovered] = useState(false)

return (
  <Interactive onSelect={() => console.log('clicked!')} onHover={() => setIsHovered(true)} onBlur={() => setIsHovered(false)}>
    <Box />
  </Interactive>
)

useInteraction

Attach handler to an existing object in a scene

const ref = useResource()

useInteraction(ref, 'onSelect', () => console.log('selected!'))

return <Box ref={ref} />

Events

To handle controller events that are not bound to any object in the scene you can use useXREvent() hook

Every controller emits following events: select, selectstart, selectend, squeeze, squeezestart, squeezeend.

useXREvent('squeeze', (e) => console.log('squeeze event has been triggered'))

it supports optional third parameter with options

useXREvent('squeeze', () => console.log('Left controller squeeze'), { handedness: 'left' })

VRCanvas, ARCanvas componentss

Extended react-three-fiber Canvas that includes:

  • Button to start VR session
  • Color management
  • VR Mode
  • react-xr context

For VR apps use VRCanvas and for AR apps use ARCanvas

import { VRCanvas } from '@react-three/xr'

<VRCanvas>
  {/* All your regular react-three-fiber elements go here */}

useXR

Hook that can only be used by components inside XRCanvas component.

const { controllers, player, isPresenting } = useXR()

Controllers is an array of XRController objects

interface XRController {
  grip: Group
  controller: Group
  inputSource: XRInputSource
  // ...
  // more in XRController.ts
}

grip and controller are ThreeJS groups that have the position and orientation of xr controllers. grip has an orientation that should be used to render virtual objects such that they appear to be held in the user’s hand and controller has an orientation of the preferred pointing ray.

inputSource is the WebXR input source (MDN). Note that it will not be available before controller is connected.

useController

Use this hook to get an instance of the controller

const leftController = useController('left')

useHitTest

codesandbox

Use this hook to perform a hit test for an AR environment

To enable hit testing in your AR app add sessionInit prop to ARCanvas like this

<ARCanvas sessionInit={{ requiredFeatures: ['hit-test'] }}>

And then in your component handle hit with useHitTest hook

useHitTest((hitMatrix, hit) => {
  // use hitMatrix to position any object on the real life surface
})

<Hands>

Add hands model for hand-tracking. Works out of the box on Oculus Browser v13, and can be enabled on versions as low as v10.2 with #webxr-hands experimental flag enabled.

<VRCanvas>
  <Hands />

Player

player group contains camera and controllers that you can use to move player around

const { player } = useXR()

useEffect(() => {
  player.position.x += 5
}, [])
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].