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

Overview

@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 component or useInteraction hook. They allow adding handlers to your objects. All interactions are use rays that are shot from the controllers.

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>
)

Wrap any object with a RayGrab component to make it grabbable

<RayGrab>
  <Box />
</RayGrab>

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.

useXRFrame

Accepts a callback which will be invoked in the animation loop of an active XR session. (MDN)

useXRFrame((time, xrFrame) => {
  // do something on each frame of an active XR session
})

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
})

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 />

Custom hands model

While a default model is provided, you might want to use a different model that fit your design. It can work with any glTF model as long as they're ready for WebXR handtracking. If you don't specify a model for one hand it'll use the default one.

<Hands modelLeft={'/model_left.gltf'} modelRight={'/model_right.glb'} />

Player

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

const { player } = useXR()

useEffect(() => {
  player.position.x += 5
}, [])
Comments
  • added customizeable XRButton that can be used for AR/VR/Inline

    added customizeable XRButton that can be used for AR/VR/Inline

    Removes the default VRButton/ARButton in exchange for a XRButton that can be placed in the dom and completely customized as it's only a HTML

    opened by cc-bbohlender 18
  • Issue in NextJS 12

    Issue in NextJS 12

    Hi

    this code in index.js

    import { useRef, useState } from 'react'
    import { Canvas, useFrame } from '@react-three/fiber'
    import { VRCanvas } from '@react-three/xr'
    
    function Box(props) {
      // This reference gives us direct access to the THREE.Mesh object
      const ref = useRef()
      // Hold state for hovered and clicked events
      const [hovered, hover] = useState(false)
      const [clicked, click] = useState(false)
      // Subscribe this component to the render-loop, rotate the mesh every frame
      useFrame((state, delta) => (ref.current.rotation.x += 0.01))
      // Return the view, these are regular Threejs elements expressed in JSX
      return (
        <mesh
          {...props}
          ref={ref}
          scale={clicked ? 1.5 : 1}
          onClick={(event) => click(!clicked)}
          onPointerOver={(event) => hover(true)}
          onPointerOut={(event) => hover(false)}>
          <boxGeometry args={[1, 1, 1]} />
          <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
        </mesh>
      )
    }
    
    export default ()=>{
    
      return (
        <VRCanvas>
          <ambientLight />
          <pointLight position={[10, 10, 10]} />
          <Box position={[-1.2, 0, 0]} />
          <Box position={[1.2, 0, 0]} />
        </VRCanvas>
      )
    
    }
    

    produces this console error:

    Uncaught     at C:\Users\61420\curious_toy\website\node_modules\ (webxr-input-profiles\motion-controllers\dist\motion-controllers.module.js:397)
        at wrapSafe (internal/modules/cjs/loader.js:988:16)
        at Module._compile (internal/modules/cjs/loader.js:1036:27)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
        at Module.load (internal/modules/cjs/loader.js:937:32)
        at Function.Module._load (internal/modules/cjs/loader.js:778:12)
        at Module.require (internal/modules/cjs/loader.js:961:19)
        at require (internal/modules/cjs/helpers.js:92:18)
        at Object.<anonymous> (file://C:\Users\61420\curious_toy\website\node_modules\@react-three\xr\dist\index.cjs.js:10:25)
        at Module._compile (internal/modules/cjs/loader.js:1072:14)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    
    bug 
    opened by curious-toy 11
  • Example that shows how to switch from vanilla r3f Canvas to VRCanvas

    Example that shows how to switch from vanilla r3f Canvas to VRCanvas

    Example request:

    How can you let someone switch from an r3f Canvas to a VRCanvas? It would be nice for there to be an example with the "switch to vr" button that does the change

    documentation 
    opened by oveddan 7
  • Refresh Rate is Low (Quest 2)

    Refresh Rate is Low (Quest 2)

    hi,

    When trying either the demo with the blue-box you can point at or the demo the stack of cubes, I had a choppy frame-rate. I'm on a Quest 2. I ran the demos in both the view where you can see the code also but also the dedicate preview window.

    ps. I did not try the other demos, but I assume it'd be the same issue.

    bug needs reproduction 
    opened by Francois-Laberge-Bose 7
  • feat: create AR/VR buttons in react, bypass context for session init

    feat: create AR/VR buttons in react, bypass context for session init

    Continues #76

    Refactors the internal XRButton and XRCanvas to exist in React and init session state outside of XR context, so buttons can exist outside of the canvas. This is fully backwards compatible with previous versions that utilize three's VRButton & ARButton.

    type XRButtonStatus = 'unsupported' | 'exited' | 'entered'
    interface XRButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
      /** The type of `XRSession` to create */
      mode: 'AR' | 'VR' | 'inline'
      /**
       * `XRSession` configuration options.
       * @see https://immersive-web.github.io/webxr/#feature-dependencies
       */
      sessionInit?: XRSessionInit
      /** Whether this button should only enter an `XRSession` */
      enterOnly?: boolean
      /** Whether this button should only exit an `XRSession` */
      exitOnly?: boolean
      /** React children, can also accept a callback returning an `XRButtonStatus` */
      children?: React.ReactNode | ((status: React.ReactNode) => React.ReactNode)
    }
    

    Additionally, XRButton and XRCanvas are now exported to enable more composition options. For example, this would be equivalent to VRCanvas:

    <XRButton mode="VR" sessionInit={sessionInit} />
    <XRCanvas>
      // ...
    </XRCanvas>
    

    Furthermore, session events are exposed as props, and reference space can be configured on the XRCanvas:

    interface XRManagerEvent {
      type: 'sessionstart' | 'sessionend'
      target: WebXRManager
    }
    interface XRControllerEvent {
      type: XRControllerEventType
      data?: XRInputSource
    }
    interface XRCanvasEvent {
      readonly nativeEvent: XRManagerEvent | XRControllerEvent | XRSessionEvent
      readonly session: XRSession
    }
    interface XRProps {
      /**
       * Enables foveated rendering,
       * 0 = no foveation = full resolution,
       * 1 = maximum foveation = the edges render at lower resolution
       */
      foveation?: number
      /** Type of WebXR reference space to use. */
      referenceSpace?: XRReferenceSpaceType
      /** Called as an XRSession is requested. */
      onSessionStart?: (event: XRCanvasEvent) => void
      /** Called after an XRSession is terminated. */
      onSessionEnd?: (event: XRCanvasEvent) => void
      /** Called when an XRSession is hidden or unfocused. */
      onVisibilityChange?: (event: XRCanvasEvent) => void
      /** Called when available inputsources change. */
      onInputSourcesChange?: (event: XRCanvasEvent) => void
      children: React.ReactNode
    }
    
    opened by CodyJasonBennett 6
  • Issues with NextJS 12.0.9

    Issues with NextJS 12.0.9

    Trying to import VRCanvas in NextJS 12.0.9

    How can this be fixed?

    SyntaxError: Unexpected token 'export'
    
    This error happened while generating the page. Any console logs will be displayed in the terminal window.
    Call Stack
    <unknown>
    file:///C:/Users/USER/Wicka/test/node_modules/%20(webxr-input-profiles/motion-controllers/dist/motion-controllers.module.js (397)
    wrapSafe
    internal/modules/cjs/loader.js (984:16)
    Module._compile
    internal/modules/cjs/loader.js (1032:27)
    Object.Module._extensions..js
    internal/modules/cjs/loader.js (1097:10)
    Module.load
    internal/modules/cjs/loader.js (933:32)
    Function.Module._load
    internal/modules/cjs/loader.js (774:14)
    Module.require
    internal/modules/cjs/loader.js (957:19)
    require
    internal/modules/cjs/helpers.js (88:18)
    Object.<anonymous>
    file:///C:/Users/USER/Wicka/test/node_modules/@react-three/xr/dist/index.cjs.js (10:25)
    Module._compile
    internal/modules/cjs/loader.js (1068:30)
    Object.Module._extensions..js
    internal/modules/cjs/loader.js (1097:10)
    
    import React, { useRef, useState } from 'react';
    import { Canvas, useFrame } from '@react-three/fiber';
    import { VRCanvas } from '@react-three/xr'
    
    function Box(props) {
      // This reference gives us direct access to the THREE.Mesh object
      const ref = useRef()
      // Hold state for hovered and clicked events
      const [hovered, hover] = useState(false)
      const [clicked, click] = useState(false)
      // Subscribe this component to the render-loop, rotate the mesh every frame
      useFrame((state, delta) => (ref.current.rotation.x += 0.01))
      // Return the view, these are regular Threejs elements expressed in JSX
      return (
        <mesh
          {...props}
          ref={ref}
          scale={clicked ? 1.5 : 1}
          onClick={(event) => click(!clicked)}
          onPointerOver={(event) => hover(true)}
          onPointerOut={(event) => hover(false)}>
          <boxGeometry args={[1, 1, 1]} />
          <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
        </mesh>
      )
    }
    
    
    export default function Home() {
      return (
        <Canvas>
          <ambientLight />
          <pointLight position={[10, 10, 10]} />
          <Box position={[-1.2, 0, 0]} />
          <Box position={[1.2, 0, 0]} />
        </Canvas>
      )
    }
    
    
    opened by wicka-aus 6
  • 'HTTPS' is not recognized as an internal or external command when 'yarn start' in /exemples

    'HTTPS' is not recognized as an internal or external command when 'yarn start' in /exemples

    I get this error: "'HTTPS' is not recognized as an internal or external command, operable program or batch file." when I run 'yarn start' from the 'examples' folder.

    How to reproduce:

    1. Have a Windows PC.
    2. Install node.js and yarn
    3. git clone https://github.com/react-spring/react-xr
    4. cd react-xr
    5. yarn
    6. cd examples
    7. yarn
    8. yarn start
    opened by Thebinoman 6
  • docs: prefer Matrix4#decompose in hit test example

    docs: prefer Matrix4#decompose in hit test example

    Resolves #203.

    The useHitTest example wasn't working correctly. This updated code disables the target's matrixAutoUpdate and applies the hitMatrix directly to its matrix property (as per this example: https://github.com/immersive-web/webxr-samples/blob/main/hit-test.html)

    opened by wayfarerboy 5
  • cannot open locally hosted site in XRviewer

    cannot open locally hosted site in XRviewer

    I followed the examples exactly as they are listed in the react-XR examples to clone the repo, yarn, and then start. I am using an iphone XS with the latest version of the XR viewer and iOS. however when I try to access the locally hosted instance by going to https://<computer's-ip-address.: with both my computer and iphone on the same network WebXR is not able to access the site. Is there something missing from the instructions for accessing WebXR from a localhost? do I need to do anything specific to be able top access locally hosted instance?

    opened by JakeJustLearning 5
  • Use custom hands model with the Hands component

    Use custom hands model with the Hands component

    This PR should allow user to load their own models when using the<Hands /> component.

    They can specify a model for the left or right hands individually like so :

    <Hands
          modelLeft={"https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/left-hand-black-webxr-tracking-ready/model.gltf"}
          modelRight={"https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/right-hand-black-webxr-tracking-ready/model.gltf"}
    />
    

    If no model are specified it will load the current model.

    Let me know if you want me to code it differently / rename stuff etc.

    Once it's merged, I'll try to make a simple demo of it and add it to the readme and getting started.

    ( Also, can we rename src\webxr\HandModel.js to something else ? Maybe I'm missing why it's called Oculus, because I don't see why it's specific to Oculus )

    Thank you in advance !

    opened by AlaricBaraou 5
  • Using drei HTML is not showing anything

    Using drei HTML is not showing anything

    I have tried to add html when using react-xr. I am using HTML from drei but cannot get anything to show up.

    import React from "react";
    import { VRCanvas, DefaultXRControllers } from "@react-three/xr";
    import { Html } from "drei";
    
    function App() {
      const style = {
        heigh: "100px",
        width: "100px",
        backgroundColor: "red",
      };
      return (
        <div className="App">
          <VRCanvas>
            <ambientLight intensity={0.5} />
            <pointLight position={[5, 5, 5]} />
            <mesh position={[1, 1, 1]}>
              <Html
                prepend
                center
                fullscreen
                scaleFactor={10}
                zIndexRange={[100, 0]}
              >
                <h1 style={style}>hello</h1>
                <p>world</p>
              </Html>
            </mesh>
            <DefaultXRControllers />
          </VRCanvas>
        </div>
      );
    }
    
    export default App;
    
    opened by robin22d 5
  • [Question]: How to create a scrollable list in VR

    [Question]: How to create a scrollable list in VR

    So basically what I need is a scrollable list, similar to this issue here #157. The answer in this discussion said that I have to use the Gamepad API (which makes sense). But the problem I have before even trying the Gamepad API is: How do I even make an item/object scrollable in VR? I saw a few storyboard examples on react-three/drei, but I'm not sure if they are also usable in VR.

    Is there some example where I can build a simple white "plane" with text inside, which is scrollable? Or do you have any ideas what steps I have to do to accomplish this? 🙂

    opened by JenniferFalkenstein 0
  • [Question]: Disable ray through object

    [Question]: Disable ray through object

    Hi there,

    I have a Plane and a Cube (and light). The Cube is placed behind the Plane and is wrapped within an <Interact /> Element, while the Plane doesn't do anything. Every time the Cube gets selected it changes the color of the light into another color.

    Now I noticed that even if the Plane is in front of the Cube, the ray still goes through the Plane and therefore is able to select the Cube behind, which is not what I want. The Plane should actually block the ray, so the player won't be able to click the Cube behind.

    Is there some kind of prop I have to set or is there another way to accomplish this? 😄

    opened by JenniferFalkenstein 0
  • isHandTracking remaining false in AR session

    isHandTracking remaining false in AR session

    @CodyJasonBennett, in reference to discussion #207 it appears that PR #208 did not fix the underlying issue. isHandTracking is remaining false in AR sessions. Here is a demonstration with the default pmndrs Hands example sandbox forked to call an AR session with the latest releases: https://ekc8wh.csb.app/

    It has remained consistent across all other AR code utilizing hands I've tried. Forcing the isHandTracking property has no effect.

    opened by rekliner 0
  • Possibility of Video or I-Frame embed in React XR

    Possibility of Video or I-Frame embed in React XR

    As per my understanding, Drei Html component wont render in react XR and Drei Image component wont support video. Is there is any work around for I- Frame or Video embeed in react XR.

    enhancement question 
    opened by iamkkt 5
Releases(v5.1.2)
  • v5.1.2(Dec 22, 2022)

    What's Changed

    • fix: hand mesh not visible after tracking lost/restored by @bodo22 in https://github.com/pmndrs/react-xr/pull/227

    New Contributors

    • @bodo22 made their first contribution in https://github.com/pmndrs/react-xr/pull/227

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v5.1.1...v5.1.2

    Source code(tar.gz)
    Source code(zip)
  • v5.1.1(Dec 7, 2022)

    What's Changed

    • fix(XRButton): don't overwrite styles by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/221

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v5.1.0...v5.1.1

    Source code(tar.gz)
    Source code(zip)
  • v5.1.0(Nov 26, 2022)

    What's Changed

    • chore(docs): tiny addition to doc change in #199 by @rekliner in https://github.com/pmndrs/react-xr/pull/210
    • chore: set up SSL for development environment by @donmccurdy in https://github.com/pmndrs/react-xr/pull/212
    • feat(XRButton): add onError prop for XR init by @firtoz in https://github.com/pmndrs/react-xr/pull/216

    New Contributors

    • @donmccurdy made their first contribution in https://github.com/pmndrs/react-xr/pull/212
    • @firtoz made their first contribution in https://github.com/pmndrs/react-xr/pull/216

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v5.0.5...v5.1.0

    Source code(tar.gz)
    Source code(zip)
  • v5.0.5(Nov 1, 2022)

    What's Changed

    • docs: update default reference space by @timhc22 in https://github.com/pmndrs/react-xr/pull/199
    • docs: prefer Matrix4#decompose in hit test example by @wayfarerboy in https://github.com/pmndrs/react-xr/pull/202
    • fix: remove race condition around session events, init by @rekliner in https://github.com/pmndrs/react-xr/pull/208

    New Contributors

    • @timhc22 made their first contribution in https://github.com/pmndrs/react-xr/pull/199
    • @wayfarerboy made their first contribution in https://github.com/pmndrs/react-xr/pull/202
    • @rekliner made their first contribution in https://github.com/pmndrs/react-xr/pull/208

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v5.0.4...v5.0.5

    Source code(tar.gz)
    Source code(zip)
  • v5.0.4(Oct 4, 2022)

    What's Changed

    • fix: add provided reference space type to optionalFeatures by @saitonakamura in https://github.com/pmndrs/react-xr/pull/193

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v3.6.7...v5.0.4

    Source code(tar.gz)
    Source code(zip)
  • v5.0.3(Oct 3, 2022)

    What's Changed

    • fix(XR): eagerly call sessionstart when late by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/191

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v5.0.2...v5.0.3

    Source code(tar.gz)
    Source code(zip)
  • v4.1.8(Oct 3, 2022)

    What's Changed

    • fix(XR): eagerly call sessionstart when late by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/191

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.1.7...v4.1.8

    Source code(tar.gz)
    Source code(zip)
  • v3.6.7(Oct 3, 2022)

    What's Changed

    • fix(XR): eagerly call sessionstart when late by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/191

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v3.6.6...v3.6.7

    Source code(tar.gz)
    Source code(zip)
  • v5.0.2(Sep 28, 2022)

    What's Changed

    • chore: update docs that mentions VRCanvas and ARCanvas which are no longer available by @smeng9 in https://github.com/pmndrs/react-xr/pull/184
    • fix(XR): purge session cache on exit by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/188

    New Contributors

    • @smeng9 made their first contribution in https://github.com/pmndrs/react-xr/pull/184

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v5.0.1...v5.0.2

    Source code(tar.gz)
    Source code(zip)
  • v4.1.7(Sep 28, 2022)

    What's Changed

    • [v4] fix: fixed outdated callbacks by @CodyJasonBennett in #189

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.1.5...v4.1.7

    Source code(tar.gz)
    Source code(zip)
  • v5.0.1(Sep 26, 2022)

    What's Changed

    • Fixed outdated callbacks by @saitonakamura in https://github.com/pmndrs/react-xr/pull/183

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v5.0.0...v5.0.1

    Source code(tar.gz)
    Source code(zip)
  • v5.0.0(Aug 25, 2022)

    What's Changed

    • feat!: XR component, ARButton/VRButton by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/177

    Changes

    This release modularizes some internals into standalone components.

    DefaultControllers => Controllers

    <DefaultControllers /> is renamed to <Controllers /> for consistency (see Controllers).

    XRCanvas is removed for a general XR provider

    The internal <XRCanvas /> component is removed in favor of a separate <XR /> provider (see XR).

    <XRButton mode="VR" />
    <XRCanvas>
      // ...
    </XRCanvas>
    
    // is now
    
    <XRButton mode="VR" />
    <Canvas>
      <XR>
        // ...
      </XR>
    </Canvas>
    

    ARCanvas and VRCanvas are removed for ARButton and VRButton

    <ARCanvas /> and <VRCanvas /> are removed with their preset session settings moved to <ARButton /> and <VRButton /> (see XRButton).

    <VRCanvas>
      // ...
    </VRCanvas>
    
    // is now
    
    <VRButton />
    <Canvas>
      <XR>
        // ...
      </XR>
    </Canvas>
    

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.1.4...v5.0.0

    Source code(tar.gz)
    Source code(zip)
  • v4.1.4(Aug 19, 2022)

    What's Changed

    • fix: regenerate types on build by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/175
    • fix: handle session exit from device by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/176

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.1.2...v4.1.4

    Source code(tar.gz)
    Source code(zip)
  • v4.1.2(Aug 10, 2022)

    What's Changed

    • fix: unbundle for webpack tree-shaking, publish sourcemaps by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/170

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.1.1...v4.1.2

    Source code(tar.gz)
    Source code(zip)
  • v4.1.1(Aug 9, 2022)

    What's Changed

    • fix: disable JSX transform by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/169

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.1.0...v4.1.1

    Source code(tar.gz)
    Source code(zip)
  • v4.1.0(Jul 28, 2022)

    What's Changed

    • feat: de-duplicate intersections for select/squeeze event handlers, add intersection field by @saitonakamura in https://github.com/pmndrs/react-xr/pull/165
    • feat: add onMove event to Interactive and useInteraction by @saitonakamura in https://github.com/pmndrs/react-xr/pull/166

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.0.1...v4.1.0

    Source code(tar.gz)
    Source code(zip)
  • v4.0.1(Jul 18, 2022)

    What's Changed

    • fix: wrap portals in fragment by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/162

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v4.0.0...v4.0.1

    Source code(tar.gz)
    Source code(zip)
  • v4.0.0(Jul 18, 2022)

    What's Changed

    • feat!: react 18 support by @saitonakamura in https://github.com/pmndrs/react-xr/pull/131
    • feat!: use ambient WebXR types from @types/three by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/140
    • feat!: merge contexts into Zustand store, upstream src/webxr by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/143
    • feat!: add option to hide rays on blur (show by default) by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/148
    • feat!: make XREvent and XREventHandler generic by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/146
    • feat: create AR/VR buttons in react, bypass context for session init by @CodyJasonBennett, @bbohlender in https://github.com/pmndrs/react-xr/pull/142
    • feat: add onSelectMissed and onSqueezeMissed interactions by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/150
    • refactor: break up DefaultXRControllers, manage DefaultXRControllers and Hands in R3F by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/147
    • refactor(useHitTest): subscribe to session, cleanup source init by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/149
    • refactor: declaratively create controller models by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/153
    • fix: rollup => vite, cleanup peer deps and use cjs target by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/134
    • fix: downlevel transpile, use correct node exts by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/138
    • fix(HandModel): fix circular reference on dispose by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/139
    • fix(InteractionManager): don't pass stale state on filter by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/144
    • fix: don't create matrices on useframe, re-use hitmatrix by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/145
    • chore: fix markdown demo links for github by @rvdende in https://github.com/pmndrs/react-xr/pull/137

    Changes

    This release adds support for React 18, R3F v8, and three r141.

    useXRFrame => useFrame

    useXRFrame is removed in favor of R3F's useFrame.

    -useXRFrame((time: DOMHighResTimeStamp, frame: XRFrame) => ...)
    +useFrame((state: RootState, delta: number, frame?: XRFrame) => ...)
    

    R3F will pass an XRFrame as the third argument while in a WebXR session (see R3F migration guide).

    onSelectMissed and onSelectSqueezed interaction types

    onSelectMissed and onSqueezeMissed are now supported in useInteraction, and <Interactive /> components (see interactions).

    This mirror's R3F's onPointerMissed et al handlers.

    Improved Ray visibility

    DefaultXRControllers rays are now shown by default and can be hidden on blur with the hideRaysOnBlur prop. For <Rays />, this would be hideOnBlur.

    This is more inline with menu ray representations and examples like https://threejs.org/examples/#webxr_vr_dragging.

    Streamlined event types

    XREvent is now generic, and can wrap an XRControllerEvent, XRManagerEvent, or XRSessionEvent. XREventHandler would represent an event listener.

    
    useXREvent('select', (event: XREvent<XRControllerEvent>) => ...)
    

    XRButton and XRCanvas

    The internal XRButton and XRCanvas are now exported with expanded configuration options for session init and XRManager settings (see Custom XRButton and XRCanvas).

    Expanded XRCanvas

    XRCanvas is now exported for custom canvases. It's also expanded with session configuration options and listeners.

    <XRCanvas
      /**
       * Enables foveated rendering. Default is `0`
       * 0 = no foveation, full resolution
       * 1 = maximum foveation, the edges render at lower resolution
       */
      foveation={0}
      /** Type of WebXR reference space to use. Default is `local-space` */
      referenceSpace="local-space"
      /** Called as an XRSession is requested */
      onSessionStart={(event: XREvent<XRManagerEvent>) => ...}
      /** Called after an XRSession is terminated */
      onSessionEnd={(event: XREvent<XRManagerEvent>) => ...}
      /** Called when an XRSession is hidden or unfocused. */
      onVisibilityChange={(event: XREvent<XRSessionEvent>) => ...}
      /** Called when available inputsources change */
      onInputSourcesChange={(event: XREvent<XRSessionEvent>) => ...}
    >
      {/* All your regular react-three-fiber elements go here */}
    </XRCanvas>
    

    Customizeable XRButton

    Internal XRButton and XRCanvas were refactored to exist in React and init session state outside of XR context, so buttons can exist outside of the canvas. This is fully backward compatible with previous versions that utilize three's VRButton & ARButton.

    <XRButton
      /* The type of `XRSession` to create */
      mode={'AR' | 'VR' | 'inline'}
      /**
       * `XRSession` configuration options
       * @see https://immersive-web.github.io/webxr/#feature-dependencies
       */
      sessionInit={{ optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers'] }}
      /** Whether this button should only enter an `XRSession`. Default is `false` */
      enterOnly={false}
      /** Whether this button should only exit an `XRSession`. Default is `false` */
      exitOnly={false}
    >
      {/* Can accept regular DOM children and has an optional callback with the XR button status (unsupported, exited, entered) */}
      {(status) => `WebXR ${status}`}
    </XRButton>
    

    Furthermore, XRButton can be composed with XRCanvas to smoothly integrate with your UI. For example, this would be equivalent to VRCanvas:

    <XRButton mode="VR" sessionInit={{ optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers'] }} />
    <XRCanvas>
      // ...
    </XRCanvas>
    

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v3.6.0...v4.0.0

    Source code(tar.gz)
    Source code(zip)
  • v3.6.0(Jul 18, 2022)

    What's Changed

    • feat: create AR/VR buttons in react, bypass context for session init by @CodyJasonBennett, @bbohlender in https://github.com/pmndrs/react-xr/pull/142
    • fix: rollup => vite, cleanup peer deps and use cjs target by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/134
    • fix: downlevel transpile, use correct node exts by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/138
    • fix(HandModel): fix circular reference on dispose by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/139
    • chore: fix markdown demo links for github by @rvdende in https://github.com/pmndrs/react-xr/pull/137
    • fix(InteractionManager): don't pass stale state on filter by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/144
    • fix: don't create matrices on useframe, re-use hitmatrix by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/145

    Changes

    We'll be releasing v4 shortly with react 18/R3F v8 support. Due to breaking changes in @types/three, r141 support will also follow in v4.

    This release backports some important fixes and features for stability and performance.

    XRButton and XRCanvas

    The internal XRButton and XRCanvas are now exported with expanded configuration options for session init and XRManager settings (see Custom XRButton and XRCanvas).

    Expanded XRCanvas

    XRCanvas is now exported for custom canvases. It's also expanded with session configuration options and listeners.

    <XRCanvas
      /**
       * Enables foveated rendering. Default is `0`
       * 0 = no foveation, full resolution
       * 1 = maximum foveation, the edges render at lower resolution
       */
      foveation={0}
      /** Type of WebXR reference space to use. Default is `local-space` */
      referenceSpace="local-space"
      /** Called as an XRSession is requested */
      onSessionStart={(event: XREvent<XRManagerEvent>) => ...}
      /** Called after an XRSession is terminated */
      onSessionEnd={(event: XREvent<XRManagerEvent>) => ...}
      /** Called when an XRSession is hidden or unfocused. */
      onVisibilityChange={(event: XREvent<XRSessionEvent>) => ...}
      /** Called when available inputsources change */
      onInputSourcesChange={(event: XREvent<XRSessionEvent>) => ...}
    >
      {/* All your regular react-three-fiber elements go here */}
    </XRCanvas>
    

    Customizeable XRButton

    Internal XRButton and XRCanvas were refactored to exist in React and init session state outside of XR context, so buttons can exist outside of the canvas. This is fully backward compatible with previous versions that utilize three's VRButton & ARButton.

    <XRButton
      /* The type of `XRSession` to create */
      mode={'AR' | 'VR' | 'inline'}
      /**
       * `XRSession` configuration options
       * @see https://immersive-web.github.io/webxr/#feature-dependencies
       */
      sessionInit={{ optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers'] }}
      /** Whether this button should only enter an `XRSession`. Default is `false` */
      enterOnly={false}
      /** Whether this button should only exit an `XRSession`. Default is `false` */
      exitOnly={false}
    >
      {/* Can accept regular DOM children and has an optional callback with the XR button status (unsupported, exited, entered) */}
      {(status) => `WebXR ${status}`}
    </XRButton>
    

    Furthermore, XRButton can be composed with XRCanvas to smoothly integrate with your UI. For example, this would be equivalent to VRCanvas:

    <XRButton mode="VR" sessionInit={{ optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers'] }} />
    <XRCanvas>
      // ...
    </XRCanvas>
    

    New Contributors

    • @bbohlender made their first contribution in https://github.com/pmndrs/react-xr/pull/76
    • @rvdende made their first contribution in https://github.com/pmndrs/react-xr/pull/137

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v3.5.0...v3.6.0

    Source code(tar.gz)
    Source code(zip)
  • v3.5.0(May 30, 2022)

    What's Changed

    • fix(webxr): import three-stdlib from flatbundle for cjs targets by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/119
    • fix(AR/VRCanvas): cleanup button on unmount by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/127

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v3.4.0...v3.5.0

    Source code(tar.gz)
    Source code(zip)
  • v3.4.0(Feb 11, 2022)

    What's Changed

    • fix(#93) entering vr will not overwrite the xr session feature list anymore by @Kalkut in https://github.com/pmndrs/react-xr/pull/94
    • Fix prepare and pack scripts by @saitonakamura in https://github.com/pmndrs/react-xr/pull/92
    • Used 'supports webxr' for babel preset env by @saitonakamura in https://github.com/pmndrs/react-xr/pull/95
    • Import GLTFLoader from three-stdlib by @marlon360 in https://github.com/pmndrs/react-xr/pull/102
    • Added console warning when XR context isn't initialized by @saitonakamura in https://github.com/pmndrs/react-xr/pull/82
    • Added intersection field to handlers other than hover/blue by @saitonakamura in https://github.com/pmndrs/react-xr/pull/84
    • chore(examples): CRA => Vite, update deps by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/107
    • fix(XRControllerModelFactory): vendor motion controller dep by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/111
    • feat(XRIntersectionEvent): filter event candidates via state.raycaster or stop on first hit by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/113
    • fix(useXRFrame): correctly react to session state changes by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/114
    • chore(useXRFrame): add deprecation notice for v8 by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/115
    • fix(webxr): add dispose methods, cleanup hands on src change by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/116
    • chore: setup GitHub Actions CI by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/117

    New Contributors

    • @Kalkut made their first contribution in https://github.com/pmndrs/react-xr/pull/94
    • @saitonakamura made their first contribution in https://github.com/pmndrs/react-xr/pull/92
    • @marlon360 made their first contribution in https://github.com/pmndrs/react-xr/pull/102

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v3.2.0...v3.4.0

    Source code(tar.gz)
    Source code(zip)
  • v3.3.0(Jan 31, 2022)

    What's Changed

    • fix(#93) entering vr will not overwrite the xr session feature list anymore by @Kalkut in https://github.com/pmndrs/react-xr/pull/94
    • Fix prepare and pack scripts by @saitonakamura in https://github.com/pmndrs/react-xr/pull/92
    • Used 'supports webxr' for babel preset env by @saitonakamura in https://github.com/pmndrs/react-xr/pull/95
    • Import GLTFLoader from three-stdlib by @marlon360 in https://github.com/pmndrs/react-xr/pull/102
    • Added console warning when XR context isn't initialized by @saitonakamura in https://github.com/pmndrs/react-xr/pull/82
    • Added intersection field to handlers other than hover/blue by @saitonakamura in https://github.com/pmndrs/react-xr/pull/84
    • chore(examples): CRA => Vite, update deps by @CodyJasonBennett in https://github.com/pmndrs/react-xr/pull/107

    New Contributors

    • @Kalkut made their first contribution in https://github.com/pmndrs/react-xr/pull/94
    • @saitonakamura made their first contribution in https://github.com/pmndrs/react-xr/pull/92
    • @marlon360 made their first contribution in https://github.com/pmndrs/react-xr/pull/102

    Full Changelog: https://github.com/pmndrs/react-xr/compare/v3.2.0...v3.3.0

    Source code(tar.gz)
    Source code(zip)
  • v3.1.0(May 6, 2021)

    • Fixed GLTFLoader bug #48
    • Updated Hands component with new oculus model
    • Breaking: removed profile prop from Hands component. Now will only load deafult hands
    Source code(tar.gz)
    Source code(zip)
  • v2.0.2(Mar 21, 2021)

  • v2.0.1(Mar 11, 2021)

  • v2.0.0(Jan 27, 2021)

    Breaking changes:

    • Hover, Select components are removed and replaced by Interactive component

    Added:

    • <Interactive /> component - allows attaching event handlers to the content in the scene
    • useInteraction hook - attach events to an existing object in the scene
    • const { player, isPresenting } = useXR() - added player Group and isPresenting variables
    • useHitTest - hook to perform hit tests in AR mode
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Aug 30, 2020)

    • Added useController hook
    • Reworked how controllers are loaded, now controllers are available only when inputSource is present
    • Handled 'disconnect' event for the controller
    • Added experimental Hands component
    • Added 'examples/' folder
    Source code(tar.gz)
    Source code(zip)
  • v1.0.6(May 21, 2020)

  • v1.0.5(May 17, 2020)

    • New component XRCanvas
    • XR renamed to XRContextProvider to encourage the use of XRCanvas

    Before:

    <Canvas onCreate={({ gl }) => /* ... create vr button */} vr>
      <XR> {/* content */} </XR>
    </Canvas>
    

    After:

    <XRCanvas>{/* content */}</XRCanvas>
    

    Codesandbox examples were updated to the latest version

    Source code(tar.gz)
    Source code(zip)
Owner
Poimandres
Open source developer collective
Poimandres
📋 React Hooks for forms validation (Web + React Native)

English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Русский | Deutsch | Türkçe Features Built with performance and DX in mind

React Hook Form 32.4k Dec 29, 2022
Shows how React components and Redux to build a friendly user experience with instant visual updates and scaleable code in ecommerce applications

This simple shopping cart prototype shows how React components and Redux can be used to build a friendly user experience with instant visual updates and scaleable code in ecommerce applications.

Alan Vieyra 4 Feb 1, 2022
⚛️ Hooks for building fast and extendable tables and datagrids for React

Hooks for building lightweight, fast and extendable datagrids for React Enjoy this library? Try them all! React Query, React Form, React Charts Visit

Tanner Linsley 20.3k Jan 3, 2023
⚡️ Simple, Modular & Accessible UI Components for your React Applications

Build Accessible React Apps with Speed ⚡️ Chakra UI provides a set of accessible, reusable, and composable React components that make it super easy to

Chakra UI 30.5k Jan 4, 2023
⚛️ Hooks for fetching, caching and updating asynchronous data in React

Hooks for fetching, caching and updating asynchronous data in React Enjoy this library? Try the entire TanStack! React Table, React Form, React Charts

Tanner Linsley 32.1k Jan 9, 2023
Fully typed hooks and utility functions for the React Native StyleSheet API

react-native-style-utilities Fully typed hooks and utility functions for the React Native StyleSheet API npm i react-native-style-utilities ESLint Set

Marc Rousavy 73 Dec 17, 2022
Built a covid-19 trcaker app using React.js implementing hooks and materail UI

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Aditya Dond 1 Dec 21, 2021
Add multiplayer presence (live cursors/avatars) to your react application using yjs and hooks

y-presence Easy way to add presence (live cursors/avatars) to any react application using react hooks. Installation yarn add y-presence # or npm i y-p

Nimesh Nayaju 126 Dec 29, 2022
React Hooks — 👍

Collaborative editing for your app. Support on Kickstarter! ?? react-use Collection of essential React Hooks. Port of libreact. Translations: ???? 汉语

Vadim Dalecky 34.9k Jan 3, 2023
React Hooks library for remote data fetching

Introduction swr.vercel.app SWR is a React Hooks library for remote data fetching. The name “SWR” is derived from stale-while-revalidate, a cache inva

Vercel 25.2k Jan 4, 2023
Redux-Toolkit example with React Hooks CRUD Application, Axios, Rest API, Bootstrap

Redux-Toolkit CRUD example with React Hooks, Axios & Web API Build Redux-Toolkit CRUD application with React Hooks and Rest API calls in that: Each it

null 69 Dec 27, 2022
React Hooks tutorial for beginners.

React Hooks for Beginners git clone <url> Clone into the repo code react-hooks Open the folder in VS Code npm install Install the dependencies npm sta

Mohammad Muazam 2 Oct 10, 2022
A custom ESLint rule to allow static deps in React Hooks ⚛️

eslint-plugin-react-hooks-static-deps A custom ESLint rule to allow static deps in React Hooks ⚛️ Motivation react-hooks/exhaustive-deps is a really n

Stoïk 3 Apr 5, 2022
A React utility belt for function components and higher-order components.

A Note from the Author (acdlite, Oct 25 2018): Hi! I created Recompose about three years ago. About a year after that, I joined the React team. Today,

Andrew Clark 14.8k Jan 4, 2023
Nextjs-components: A collection of React components

nextjs-components A collection of React components, transcribed from https://vercel.com/design. 1 Motivation Blog post from 01/09/2022 Todo's Unit tes

null 94 Nov 30, 2022
An intro to Three.js and React :) Workshop materials and demo from HackTheNorth 2021

?? Speedy 3D - A Quick Intro to Three.js & React This workshop was originally created for Hack The North 2021! My personal motivation was to: learn th

Anson Yu 8 Dec 17, 2021
Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional functionality.

apollo-augmented-hooks Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional

appmotion Devs 57 Nov 18, 2022
Fast, tiny and solid hooks system for Javascript and Node.js

Uncino ?? Fast, tiny and solid hooks system for Javascript and NodeJS Uncino is italian word for hook Do you know Wordpress hooks system? Uncino is a

Riccardo Tartaglia 201 Dec 7, 2022
🇨🇭 A React renderer for Three.js

react-three-fiber react-three-fiber is a React renderer for threejs. npm install three @react-three/fiber Why? Build your scene declaratively with re-

Poimandres 20.9k Jan 9, 2023