WebVR.js 2.2 KB

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