question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can react-three-fiber be used with vr?

See original GitHub issue

On:

https://threejs.org/docs/index.html#manual/en/introduction/How-to-create-VR-content

they explain:

Finally, you have to adjust your animation loop since we can’t use our well known window.requestAnimationFrame() function. For VR projects we use setAnimationLoop. The minimal code looks like this:

renderer.setAnimationLoop( function () {

	renderer.render( scene, camera );

} );

It’s not clear how this can be done in react-three-fiber. Any advice?

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
setpixelcommented, May 4, 2019

@drcmda this is what we are working on built with react-three-fiber: https://youtu.be/70RNZHEc39Q

3reactions
drcmdacommented, May 2, 2019

@setpixel @Toseben i have a draft, but don’t know how to test without equipment. No idea how to run it and the web gives conflicting info. The official threejs examples don’t have that split screen, some websites use StereoEffect, no idea what to do next.

If you want to try, it looks like this currently:

import * as THREE from 'three'
import * as VR from '!exports-loader?WEBVR!three/examples/js/vr/WebVR'
import React from 'react'
import { Canvas } from 'react-three-fiber'

function App() {
  return (
    <Canvas vr onCreated={({ gl }) => document.body.appendChild(VR.createButton(gl))}>
      ..
    </Canvas>
  )
}

The exports loader thing is b/c webvr.js isn’t a module, but it could also be copied and exported properly. Other than that, supplying the “vr” attrib is enough to switch gl into vr mode and it’s using setAnimation instead of raf.

It’s out as 2.1.0-beta.0

Here’s a live demo: https://codesandbox.io/s/72225y7jmx

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can react-three-fiber be used with vr? · Issue #80
requestAnimationFrame() function. For VR projects we use setAnimationLoop. The minimal code looks like this: renderer.setAnimationLoop( function ...
Read more >
Enabling VR | React Three Fiber
Enabling VR. Supplying the vr flag enables Three's VR mode and switches the render-loop to gl.setAnimationLoop as described in Three's docs.
Read more >
Write your first VR web application using React and WebXR
With react-three-fiber we can use THREE.js primitives like ambientLight the same way we can use DOM primitives like div or image .
Read more >
react-three/xr examples
Learn how to use @react-three/xr by viewing and forking example apps that make use of @react-three/xr on CodeSandbox. ; particles ; neefrehman/generative ;...
Read more >
Tutorial: Use react-three-fiber to render 3D in-browser visuals
What if I told you… that you too can learn to code in 3D objects in React that can wow customers? Learn the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found