[name]

This guide provides a brief overview of the basic components of a web-based VR application made with three.js.

Workflow

First, you have to include [link:https://github.com/mrdoob/three.js/blob/master/examples/js/vr/WebVR.js WebVR.js] into your project.

import { WEBVR } from 'three/examples/jsm/vr/WebVR.js';

*WEBVR.createButton()* does two important things: It creates a button which indicates VR compatibility. Besides, it initiates a VR session if the user activates the button. The only thing you have to do is to add the following line of code to your app.

document.body.appendChild( WEBVR.createButton( renderer ) );

Next, you have to tell your instance of *WebGLRenderer* to enable VR rendering.

renderer.vr.enabled = true;

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

renderer.setAnimationLoop( function () { renderer.render( scene, camera ); } );

Next Steps

Have a look at one of the official WebVR examples to see this workflow in action.

[example:webvr_ballshooter WebVR / ballshoter]
[example:webvr_cubes WebVR / cubes]
[example:webvr_dragging WebVR / dragging]
[example:webvr_lorenzattractor WebVR / lorenzattractor]
[example:webvr_panorama WebVR / panorama]
[example:webvr_paint WebVR / paint]
[example:webvr_rollercoaster WebVR / rollercoaster]
[example:webvr_sandbox WebVR / sandbox]
[example:webvr_sculpt WebVR / sculpt]
[example:webvr_vive_paint WebVR / vive / paint]
[example:webvr_vive_sculpt WebVR / vive / sculpt]