Skip to content

joshbower/webvr-boilerplate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebVR Boilerplate

A starting point for web-based VR experiences that work well in both Google Cardboard and Oculus Rift. Also provides a good fallback for experiencing the same content without requiring a VR device.

Uses the webvr-polyfill project to provide VR support even if no VR device is available. This gives good fallbacks for Cardboard, mobile devices and desktop devices.

What's inside...

THREE.js three.min.js

  • WebGL helper library that greatly simplifies 3D graphics.

VRControls VRControls.js

  • THREE.js controls which take advantage of the WebVR API.
  • Usually attached to the THREE.Camera to look around the scene.

VREffect VREffect.js

  • THREE.js effect which renders a scene with two cameras in it.
  • Puts the two images side-by-side.

WebVR polyfill webvr-polyfill.js

  • For Cardboard rendering.
  • On mobile, supports rotation via DeviceOrientation.
  • On desktop, supports looking with the mouse or with arrow keys.

WebVR manager webvr-manager.js (lives in this repository)

  • Feature detects for WebVR (or the polyfill).
  • If WebVR is available, places a generic button in the top right corner, which, when clicked, takes you to VR mode.
  • Other means of getting into VR mode: double click anywhere, double tap anywhere.
  • Sets good defaults for VR mode: full screen, orientation lock, wake lock.

Instructions

  1. Include webvr-polyfill.js in your project.
  2. Include webvr-manager.js and instantiate a WebVRManager object, passing in your VREffect instance (from the THREE.js effect library) as first argument.

For example,

var effect = new THREE.VREffect(renderer);
var mgr = new WebVRManager(effect);

For more information, see index.html, which should be well commented and self-explanatory.

Related projects

Useful resources

About

A starting point for web-based VR experiences that work in both Cardboard and Oculus.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.1%
  • Shell 0.9%