GithubHelp home page GithubHelp logo

tempbottle / webvr-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from borismus/webvr-boilerplate

0.0 2.0 0.0 131.22 MB

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

Home Page: http://smus.com/responsive-vr/

License: Apache License 2.0

Shell 0.03% JavaScript 97.59% HTML 2.25% CSS 0.14%

webvr-boilerplate's Introduction

WebVR Boilerplate

A THREE.js-based starting point for VR experiences that work well in both Google Cardboard and other VR headsets. Also provides a fallback for experiencing the same content without requiring a VR device.

This project relies heavily on the webvr-polyfill to provide VR support even if the WebVR spec is not implemented.

Projects that use the boilerplate

WebVR Boilerplate Moving Music Photosphere Sechelt

Getting started

The easiest way to start is to fork this repository or copy its contents into a new directory.

Alternatively, you can start from scratch. The key parts that the boilerplate provides are:

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

For example,

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

The manager handles going in and out of VR mode. Instead of calling renderer.render() or effect.render(), you call manager.render(), which renders in monocular view by default, or side-by-side binocular view when in VR mode.

The polyfill and boilerplate are also available via npm. Easy install:

npm install webvr-boilerplate

Features and known issues

Features:

  • Enter and exit VR mode (in WebVR and WebVR polyfill compatible environments).
  • Immersive fullscreen, orientation locking and sleep prevention.
  • Distortion correction, enabled in iOS only.
  • High quality head tracking with motion prediction thanks to webvr-polyfill.

Bugs and known issues:

  • Proper distortion correction for Android. This requires knowing physical locations of lenses, which requires knowing device's DPI, which is hard in general. It's easier in iOS because there are relatively few iPhone models.
  • Wake lock for Android currently relies on a hack in which a hidden video is played on repeat in the background. This causes big WebGL performance issues, so has been disabled. This will be resolved when the official wakelock API lands: http://crbug.com/257511

Configuration

All configuration is done through the global window.WebVRConfig object. You can use the following properties:

  • FORCE_DISTORTION (Boolean): Set this to true to enable barrel distortion for cardboard devices, even if the device has unknown display properties.
  • PREVENT_DISTORTION (Boolean): Set this to true to prevent barrel distortion for cardboard devices, even if it is a known device. Do this if you encounter issues with barrel distortion on cardboard devices.
  • DISTORTION_BGCOLOR (Object): Use this to change the background color used in the barrel distortion shader pass (cardboard devices). Pass an object with x, y, z and w properties (type number, ranged 0..1).

Here is an example of WebVRConfig usage:

WebVRConfig = {
  // Forces cardboard distortion in VR mode.
  //FORCE_DISTORTION: true, // Default: false.
  // Prevents cardboard distortion in VR mode
  //PREVENT_DISTORTION: true, // Default: false.
  // Override the cardboard distortion background color.
  //DISTORTION_BGCOLOR: {x: 1, y: 0, z: 0, w: 1}, // Default: (0,0,0,1).
  // Show eye centers (for debugging).
  //SHOW_EYE_CENTERS: true, // Default: false.
};

In addition to render(), WebVRManager provides a sparse API surface:

  • isVRMode() (Boolean): True if and only if currently in VR mode.
  • getViewer() (Object): Information about the Cardboard-like viewer that is currently selected. Viewers are pre-defined in device-info.js.

As well as emitting the following events:

  • modechange: When the user changes the current mode.
  • viewerchange: When the user selects a new viewer.

Thanks

webvr-boilerplate's People

Contributors

borismus avatar brianchirls avatar brianpeiris avatar caseyyee avatar dmitriykovalev avatar jensarps avatar jzitelli avatar nh2 avatar njam avatar panuhorsmalahti avatar scottgwald avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.