Code Monkey home page Code Monkey logo

webvr-polyfill's Introduction

WebVR Polyfill

A JavaScript implementation of the WebVR spec. This project lets you use WebVR today, without requiring a special browser build. It also lets you view the same content without requiring a virtual reality viewer.

Take a look at basic WebVR samples that use this polyfill.

Implementation

The polyfill decides which VRDisplays to provide, depending on the configuration of your browser. Mobile devices provide the CardboardVRDisplay. Desktop devices use the MouseKeyboardVRDisplay.

CardboardVRDisplay uses DeviceMotionEvents to implement a complementary filter which does sensor fusion and pose prediction to provide orientation tracking. It can also render in stereo mode, and includes mesh-based lens distortion. This display also includes user interface elements in VR mode to make the VR experience more intuitive, including:

  • A gear icon to select your VR viewer.
  • A back button to exit VR mode.
  • An interstitial which only appears in portrait orientation, requesting you switch into landscape orientation (if orientation lock is not available).

MouseKeyboardVRDisplay uses mouse events to allow you to do the equivalent of mouselook. It also uses keyboard arrows keys to look around the scene with the keyboard.

Configuration

The polyfill can be configured and debugged with various options. The following are supported:

WebVRConfig = {
  // Flag to disabled the UI in VR Mode.
  CARDBOARD_UI_DISABLED: false, // Default: false

  // Forces availability of VR mode, even for non-mobile devices.
  FORCE_ENABLE_VR: true, // Default: false.

  // Complementary filter coefficient. 0 for accelerometer, 1 for gyro.
  K_FILTER: 0.98, // Default: 0.98.

  // Flag to disable the instructions to rotate your device.
  ROTATE_INSTRUCTIONS_DISABLED: false, // Default: false.

  // How far into the future to predict during fast motion (in seconds).
  PREDICTION_TIME_S: 0.040, // Default: 0.040.

  // Flag to disable touch panner. In case you have your own touch controls.
  TOUCH_PANNER_DISABLED: false, // Default: true.

  // Enable yaw panning only, disabling roll and pitch. This can be useful
  // for panoramas with nothing interesting above or below.
  YAW_ONLY: true, // Default: false.

  // To disable keyboard and mouse controls, if you want to use your own
  // implementation.
  MOUSE_KEYBOARD_CONTROLS_DISABLED: true, // Default: false.

  // Prevent the polyfill from initializing immediately. Requires the app
  // to call InitializeWebVRPolyfill() before it can be used.
  DEFER_INITIALIZATION: true, // Default: false.

  // Enable the deprecated version of the API (navigator.getVRDevices).
  ENABLE_DEPRECATED_API: true, // Default: false.

  // Scales the recommended buffer size reported by WebVR, which can improve
  // performance.
  BUFFER_SCALE: 0.5, // Default: 0.5.

  // Allow VRDisplay.submitFrame to change gl bindings, which is more
  // efficient if the application code will re-bind its resources on the
  // next frame anyway. This has been seen to cause rendering glitches with
  // THREE.js.
  // Dirty bindings include: gl.FRAMEBUFFER_BINDING, gl.CURRENT_PROGRAM,
  // gl.ARRAY_BUFFER_BINDING, gl.ELEMENT_ARRAY_BUFFER_BINDING,
  // and gl.TEXTURE_BINDING_2D for texture unit 0.
  DIRTY_SUBMIT_FRAME_BINDINGS: true // Default: false.
}

Performance

Performance is critical for VR. If you find your application is too sluggish, consider tweaking some of the above parameters. In particular, keeping BUFFER_SCALE at 0.5 (the default) will likely help a lot.

Development

If you'd like to contribute to the webvr-poyfill library, check out the repository and install Node and the dependencies:

git clone https://github.com/borismus/webvr-polyfill
cd webvr-polyfill
npm install

License

This program is free software for both commercial and non-commercial use, distributed under the Apache 2.0 License.

webvr-polyfill's People

Contributors

autonome avatar borismus avatar brianchirls avatar caseyyee avatar cvan avatar daredevildave avatar deathcap avatar dmarcos avatar jeromeetienne avatar jzitelli avatar ngokevin avatar santanm avatar stuartpb avatar toji 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.