WebVR.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @author mrdoob / http://mrdoob.com
  3. * Based on @tojiro's vr-samples-utils.js
  4. */
  5. var WEBVR = {
  6. button: function ( effect ) {
  7. var button = document.createElement( 'button' );
  8. button.style.position = 'absolute';
  9. button.style.left = 'calc(50% - 30px)';
  10. button.style.bottom = '20px';
  11. button.style.border = '0';
  12. button.style.padding = '8px';
  13. button.style.cursor = 'pointer';
  14. button.style.backgroundColor = '#000';
  15. button.style.color = '#fff';
  16. button.style.fontFamily = 'sans-serif';
  17. button.style.fontSize = '13px';
  18. button.style.fontStyle = 'normal';
  19. button.style.zIndex = '999';
  20. button.textContent = 'ENTER VR';
  21. button.onclick = function() {
  22. effect.setFullScreen( true );
  23. };
  24. document.body.appendChild( button );
  25. },
  26. test: function () {
  27. var message;
  28. if ( navigator.getVRDisplays ) {
  29. navigator.getVRDisplays().then( function ( displays ) {
  30. if ( displays.length === 0 ) message = 'WebVR supported, but no VRDisplays found.';
  31. } );
  32. } else if ( navigator.getVRDevices ) {
  33. message = 'Your browser supports WebVR but not the latest version. See <a href="http://webvr.info">webvr.info</a> for more info.';
  34. } else {
  35. message = 'Your browser does not support WebVR. See <a href="http://webvr.info">webvr.info</a> for assistance.';
  36. }
  37. if ( message !== undefined ) {
  38. var container = document.createElement( 'div' );
  39. container.style.position = 'absolute';
  40. container.style.left = '0';
  41. container.style.top = '0';
  42. container.style.right = '0';
  43. container.style.zIndex = '999';
  44. container.align = 'center';
  45. document.body.appendChild( container );
  46. var error = document.createElement( 'div' );
  47. error.style.fontFamily = 'sans-serif';
  48. error.style.fontSize = '16px';
  49. error.style.fontStyle = 'normal';
  50. error.style.lineHeight = '26px';
  51. error.style.backgroundColor = '#fff';
  52. error.style.color = '#000';
  53. error.style.padding = '10px 20px';
  54. error.style.margin = '40px';
  55. error.style.display = 'inline-block';
  56. error.innerHTML = message;
  57. container.appendChild( error );
  58. }
  59. }
  60. };