Voltar ao ranking

immersive-web/webvr-polyfill

JavaScriptimmersive-web.github.io/webvr-polyfill/examples/

Use WebVR today, without requiring a special browser build.

webvrwebxrpolyfill
Crescimento de estrelas
Estrelas
1.4k
Forks
322
Crescimento semanal
Issues
30
5001k
fev. de 2015nov. de 2018set. de 2022jul. de 2026
Artefatosnpmnpm install webvr-polyfill
README

WebVR is Deprecated!

The WebVR API had been developed under WebVR Community Group, but was marked as deprecated and fully replaced by the WebXR Device API and its modules which have wider support, more features, better performance, and supports both VR and XR (collectively called as XR). The WebXR Device API and its modules are under development by the W3C Immersive Web Working Group (WG) initiated at Sep 2018, was initially shipped in browsers in 2019 and are now available on many XR devices. This document is preserved out of historial interest, but the APIs described will not be implemented in any major browser.

No further development will be held on WebVR specifications. If you have any new idea of incubation around XR, please check the proposals repository of the W3C Immersive Web Community Group (CG) for further expanding XR in the Web and file as issue on any new idea there.

WebVR Polyfill

Build Status Build Status

A JavaScript implementation of the WebVR spec. This project ensures your WebVR content works on any platform, whether or not the browser/device has native WebVR support, or when there are inconsistencies in implementation.

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

Installing

Script

Download the build at build/webvr-polyfill.js and include it as a script tag, or use a CDN. You can also use the minified file in the same location as webvr-polyfill.min.js.

  <script src='webvr-polyfill.js'></script>
  <!-- or use a link to a CDN -->
  <script src='https://cdn.jsdelivr.net/npm/webvr-polyfill@latest/build/webvr-polyfill.js'></script>

npm

If you're using a build tool like browserify or webpack, install it via npm.

$ npm install --save webvr-polyfill

Using

Instructions for using versions >=0.10.0. For <=0.9.x versions, see 0.9.40 tag.

The webvr-polyfill exposes a single constructor, WebVRPolyfill that takes an object for configuration. See full configuration options at src/config.js.

Be sure to instantiate the polyfill before calling any of your VR code! The polyfill needs to patch the API if it does not exist so your content code can assume that the WebVR API will just work.

If using script tags, a WebVRPolyfill global constructor will exist.

var polyfill = new WebVRPolyfill();

In a modular ES6 world, import and instantiate the constructor similarly.

import WebVRPolyfill from 'webvr-polyfill';
const polyfill = new WebVRPolyfill();

Here's an example of querying displays and setting up controls based on environment. Remember, you'll still need to provide controls and code to support a desktop-like experience if no native VRDisplays are found, as the CardboardVRDisplay is only on mobile. See the example.

// Polyfill always provides us with `navigator.getVRDisplays`
navigator.getVRDisplays().then(displays => {
  // If we have a native VRDisplay, or if the polyfill
  // provided us with a CardboardVRDisplay, use it
  if (displays.length) {
    vrDisplay = displays[0];
    controls = new THREE.VRControls(camera);
    vrDisplay.requestAnimationFrame(animate);
  } else {
    // If we don't have a VRDisplay, we're probably on
    // a desktop environment, so set up desktop-oriented controls
    controls = new THREE.OrbitControls(camera);
    requestAnimationFrame(animate);
  }
});

iframes

There are some concerns and caveats when embedding polyfilled WebVR content inside iframes. More information is documented in the cardboard-vr-display README.

Goals

The polyfill's goal is to provide a library so that developers can create content targeting the WebVR API without worrying about what browsers and devices their users have in a world of growing, but fragmented support.

The three main components of the polyfill are:

  • Injects a WebVR 1.1 JavaScript implementation if one does not exist
  • Patches browsers that have an incomplete or inconsistent implementation of the API
  • Provide a synthesized CardboardVRDisplay on mobile when WebVR is not supported, or if it does have native support but no native VRDisplays and PROVIDE_MOBILE_VRDISPLAY is true (default).

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.

Developing

If you're interested in developing and contributing on the polyfill itself, you'll need to have npm installed and familiarize yourself with some commands below. For full list of commands available, see package.json scripts.

$ git clone git@github.com:immersive-web/webvr-polyfill.git
$ cd webvr-polyfill/

# Install dependencies
$ npm install

# Build uncompressed JS file
$ npm run build

# Run tests
$ npm test

# Watch src/* directory and auto-rebuild on changes
$ npm watch

Testing

Right now there are some unit tests in the configuration and logic for how things get polyfilled. Be sure to run tests before submitting any PRs, and bonus points for having new tests!

$ npm test

Due to the nature of the polyfill, be also sure to test the examples with your changes where appropriate.

Releasing a new version

For maintainers only, to cut a new release for npm, use the [npm version] command. The preversion, version and postversion npm scripts will run tests, build, add built files and tag to git, push to github, and publish the new npm version.

npm version <semverstring>

License

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

Repositórios relacionados
BabylonJS/Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

TypeScriptnpmApache License 2.0webglwebgl2
babylonjs.com
25.8k3.7k
aframevr/aframe

:a: Web framework for building virtual reality experiences.

JavaScriptnpmMIT Licensevrwebvr
aframe.io
17.6k4.4k
gkjohnson/three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.

JavaScriptnpmMIT Licensegraphicsraycast
gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
3.4k331
google-ar/three.ar.js

A helper three.js library for building AR web experiences that run in WebARonARKit and WebARonARCore

JavaScriptnpmApache License 2.0webvrwebar
developers.google.com/ar/develop/web/getting-started
2.9k367
tentone/nunuStudio

Web powered cross-platform 3D, WebXR game engine.

JavaScriptnpmMIT Licensewebglgame-engine
tentone.github.io/nunuStudio/
2.2k344
BabylonJS/Spector.js

Explore and Troubleshoot your WebGL scenes with ease.

TypeScriptnpmMIT Licensewebglwebgl2
spector.babylonjs.com
1.6k188
supermedium/aframe-react

:atom: Build virtual reality experiences with A-Frame and React.

JavaScriptnpmMIT Licensereactvr
ngokevin.github.io/aframe-react-boilerplate/
1.4k149
supermedium/superframe

:package: A super collection of A-Frame components.

JavaScriptnpmMIT Licenseaframevr
supermedium.com/superframe/
1.4k426
aframevr/awesome-aframe

[DISCONTINUED] Collection of awesome resources for the A-Frame WebVR framework.

aframewebvr
aframe.io
1.3k168
De-Panther/unity-webxr-export

Develop and export WebXR experiences using Unity WebGL

JavaScriptnpmApache License 2.0webxrunity
de-panther.github.io/unity-webxr-export/
1.3k141
networked-aframe/networked-aframe

A web framework for building multi-user virtual reality experiences.

JavaScriptnpmMIT Licenseaframewebrtc
cf9dc236-8b31-41d7-a0f0-3a87c89c70ea.pub.instances.scw.cloud
1.2k301
c-frame/aframe-extras

Add-ons and helpers for A-Frame VR.

JavaScriptnpmMIT Licenseaframewebvr
c-frame.github.io/aframe-extras/examples/
1k307