Giter Club home page Giter Club logo

webvr-ui's Introduction

WebVR UI

A javascript library allowing easily to create the Enter VR button a WebVR site. It will automatically detect the support in the browser and show correct messages to the user. The intention for the library is to create an easy way to make a button solving as many of the common use cases of WebVR as possible, and show some best practices for how to work with WebVR.

The library also supports adding a Enter Fullscreen link that allows entering a mode where on desktop you can use the mouse to drag around, and on mobile rotate the camera based on the gyroscope without rendering in stereoscopic mode (also known as Magic Window)

Examples

Library Usage

Include WebVR UI

Get the library either by cloning, downloading or installing through npm npm install webvr-ui

Include the ES5 transpiled library in a script tag

<script src="/webvr-ui/build/webvr-ui.min.js"></script>

or include it in your ES2015 code

import * as webvrui from 'webvr-ui';

The constructor for the button needs the dom element of the WebGL canvas. To use it together with the THREE.WebGLRenderer, do something like this

var renderer = new THREE.WebGLRenderer();

var options = {}
var enterVR = new webvrui.EnterVRButton(renderer.domElement, options);
document.body.appendChild(enterVR.domElement);

A-Frame

To use the button in A-Frame, include the library as above, and add webvr-ui to the scene.

<a-scene webvr-ui>
    ...
</a-scene>

This will disable the default UI and add a Enter VR button to the document DOM. All the styling and text options bellow are also available.

Options

These are the supported options in EnterVRButton. All options are optional.

Styling

  • color: Set the text and icon color (default: rgb(80,168,252))
  • background: Set the background color, set to false for no background (default: false)
  • corners: Choose the corner radius. Can either be 'square' or 'round' or a number representing pixel radius (default: 'square')
  • disabledOpacity: The opacity of the button when disabled (default: 0.5)
  • domElement: Provide a DOM element to use instead of default build in DOM. See Custom DOM example for more details how to use.
  • injectCSS: Set to false to disable CSS injection of button style (default: true)

Text

  • textEnterVRTitle: The text in the button prompting to begin presenting (default: 'ENTER VR')
  • textExitVRTitle: The text in the button prompting to begin presenting (default: 'EXIT VR')
  • textVRNotFoundTitle: The text in the button when there is no VR headset found (default: 'VR NOT FOUND')

Function Hooks

  • beforeEnter():Promise: Function called right before entering VR. Must return a Promise. Gives the opportunity to provide custom messaging or other changes before the experience is presented.
  • beforeExit():Promise: Function called right before exiting VR. Must return a promise. Gives the opportunity to update UI or other changes before the presentation is exited.
  • onRequestStateChange(state):boolean: A function called before state is changed, use to intercept entering or exiting VR for example. Return true to continue with default behavior, or false to stop the default behavior.

Events

The following events will be broadcasted by EnterVRButton, and can be subscribed to using the function .on([event]) on the button.

  • ready Event called when VR support is first detected, the VRDisplay is provided as the first parameter.
  • enter Event called when user enters VR, the VRDisplay is provided as the first parameter.
  • exit Event called when user exits VR, the VRDisplay is provided as the first parameter.
  • error Event called when an error occurs, i.e. VR is not supported, an Error is provided as the first parameter.
  • hide Event called when button is hidden
  • show Event called when button is shown

Functions

These are some of the functions that can be called on the EnterVRButton

  • setTitle(title) Change the text in the button.
  • setTooltip(tooltip) Change the hover tooltip of the button.
  • show() / hide() Change the visibility of the button.
  • disable() / enable() Change the disabled state of the button.
  • getVRDisplay():Promise Returns a Promise returning the VRDisplay associated to the button.
  • isPresenting():boolean: Returns true if the canvas associated to the button is presenting in fullscreen or VR mode.
  • requestEnterVR():Promise: Requests to start presenting. Must be called from a user action (read more)
  • requestEnterFullscreen():Promise: Requests to enter fullscreen mode if its supported in the browser.
  • requestExit():Promise: Request exiting presentation mode.

Development

To run the example, install dependencies

npm install

and start the watcher and server (available on localhost:3000/examples/basic.html)

npm start

To build the transpiled es5 version of the library, run

npm run build

and the library will be build to build/webvr-ui.js

webvr-ui's People

Contributors

dmotz avatar halfdanj avatar hapticdata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webvr-ui's Issues

Google VR Services notification disable?

Hello,
Is there some nice way to block Google VR Service notification?
We making experimental 360 content inside A-frame for mobile devices(mostly). We don't use VR-mode because we want it can be watched with almost every devices.
When new user open html content with chrome, it ask to do user wanna download VRservices, which not needed in our case. We feel it's only confuse casual users, who don't use cardboards etc. Also if content is embed inside normal website, it's not good habit to ask user download something on first spot.
I'm not sure do I ask this from right place, but i'm little lost here.
Cheers, Ila!

iOs 11 : Safari : Broken UI

Apologies in advance for logging an issue with insufficient data. We use webvr-ui at Walkinto (https://walkinto.in). Just started hearing back from users that the VR UI is broken on iOS 11 / Safari

Apparently the Magic Window is not aligned correctly, there is some sort of zooming happening with which button to enter split screen is inaccessible. I do not have device to troubleshoot. Anyone who has, and is on iOS 11, could you please test one of this sample urls?

https://goo.gl/n2LfjE
https://goo.gl/saSfPA

support updated WebVR spec

According to this commit to the spec the plan is to remove dependence on window. Instead of window.onvrdisplaypresentchange it will be vrDisplay.onpresentchange and instead of navigator.getVRDisplays() it will be navigator.vr.getDisplays().

Oculus Gear VR browser isn't supported

Trying the WebVR-UI with AFrame 0.5, the "Enter VR" button doesn't respond as expected.

Test URL: https://treasure-scraper.glitch.me/

Expected result: When clicking on the "Enter VR" button while wearing the Gear VR headset in the WebVR Oculus browser, it should launch VR mode and the user should be surrounded by the scene

Actual result: clicking on the "Enter VR" button does nothing

Firefox fullscreen doesnt work

Clicking "Try without headset" in latest Firefox (nightly or Developer Edition) on PC doesnt work, and shows the warning

Request for fullscreen was denied because Element.requestFullscreen() was not called from inside a short running user-generated event handler.

Which is odd, since we do call it within a short running user generated event handler....

Package.json main file

@hapticdata should we instead of pointing at the src/index.js in package.json point to buid/webvrui.js? Seems like many other libraries does that (THREE & polyfill at least), allowing to use require in ES5 environment.

error when entering fullscreen

In Firefox and Chrome latest I get the following error when entering fullscreen:

TypeError: e.manager.enterFullscreen(...).then is not a function

Note that the browser still successfully enters fullscreen (which, while Chrome always worked, Firefox didn't use to work on previous versions of webvr-ui).

The error sees to come from /src/enter-vr-button.js#L240. It looks like the code is attempting to use this.manager.enterFullscreen() as though it were a promise (trying to .then() on it).

I can avoid the error for now by supplying a bogus beforeEnter() to options to have the logic take the path of /src/enter-vr-button.js#L234.

Another interesting observation related to #5:

  • When not wrapped in a promise (when it takes the path that gives us the original console error: /src/enter-vr-button.js#L239), Firefox successfully enters fullscreen.
  • When using the workaround mentioned above (dummy beforeEnter() to force the working Promise section (no console errors), Firefox throws the ol:

Request for fullscreen was denied because Element.requestFullscreen() was not called from inside a short running user-generated event handler.

warning and won't enter fullscreen.

Google Cardboard support a bit wrong

Hey there,

I've been trying to find a solution for this all over the internet, but there's not much in the way of assistance anywhere.
Basically, my embedded 'photosphere' does not load correctly on my phone. It loads, there are no errors, but entering 'Cardboard' mode, causes the image to be offset incorrectly. My image is not even a stereo one, and even Google's very own example images don't load correctly, or even work.

So, here's my examples page. http://lairdsquared.co.uk/quick-test-360-degree-renderspheres/

Here's the Google dev page, where the underwater scene also doesn't seem to work correctly on my Samsung S8.
https://developers.google.com/vr/develop/web/vrview-web
This page seems to have some different issues, I cannot even enter VR mode at all as the button disappears when I click on it.

Just to dispel any issues with Samsung S8 and Cardboard, everything works fine with Google Cardboard apps, and even loading my own image onto my phone and opening it using the Google Cardboard app, and it loads it perfectly! So, it seems there are issues with Web viewing of these types of images?

If anyone could shed any light, I'd be most welcome to know how to solve this issue.

Thanks in advance,
Tim

EDIT:

I've just tried this page too, and again it's the exact same problem!
https://googlevr.github.io/webvr-ui/examples/basic.html

Just thought i would let you know.

Update to work with three.js rev86

Actually doesn't work correctly if you use last version of threejs (r86) (and I suppose and above)
Is there any plan to update to with with the last revision of threejs which is not using VREffect and VRControls yet?

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.