misc_controls_deviceorientation.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - controls - deviceorientation</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. <style>
  9. #overlay {
  10. position: absolute;
  11. z-index: 1;
  12. top: 0;
  13. left: 0;
  14. width: 100%;
  15. height:100%;
  16. display: flex;
  17. align-items: center;
  18. justify-content: center;
  19. opacity: 1;
  20. background-color: #000000;
  21. color: #ffffff;
  22. }
  23. #overlay > div {
  24. text-align: center;
  25. }
  26. #overlay > div > button {
  27. height: 20px;
  28. background: transparent;
  29. color: #ffffff;
  30. outline: 1px solid #ffffff;
  31. border: 0px;
  32. cursor: pointer;
  33. }
  34. #overlay > div > p {
  35. color: #777777;
  36. font-size: 12px;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div id="overlay">
  42. <div>
  43. <button id="startButton">Start Demo</button>
  44. <p>Using device orientation might require a user interaction.</p>
  45. </div>
  46. </div>
  47. <div id="info">
  48. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - equirectangular panorama demo with DeviceOrientation controls.<br/>
  49. photo by <a href="http://www.flickr.com/photos/jonragnarsson/2294472375/" target="_blank" rel="noopener">Jón Ragnarsson</a>.
  50. </div>
  51. <script type="module">
  52. import * as THREE from '../build/three.module.js';
  53. import { DeviceOrientationControls } from './jsm/controls/DeviceOrientationControls.js';
  54. var camera, scene, renderer, controls;
  55. var startButton = document.getElementById( 'startButton' );
  56. startButton.addEventListener( 'click', function () {
  57. init();
  58. animate();
  59. }, false );
  60. function init() {
  61. var overlay = document.getElementById( 'overlay' );
  62. overlay.remove();
  63. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
  64. controls = new DeviceOrientationControls( camera );
  65. scene = new THREE.Scene();
  66. var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
  67. // invert the geometry on the x-axis so that all of the faces point inward
  68. geometry.scale( - 1, 1, 1 );
  69. var material = new THREE.MeshBasicMaterial( {
  70. map: new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' )
  71. } );
  72. var mesh = new THREE.Mesh( geometry, material );
  73. scene.add( mesh );
  74. var helperGeometry = new THREE.BoxBufferGeometry( 100, 100, 100, 4, 4, 4 );
  75. var helperMaterial = new THREE.MeshBasicMaterial( { color: 0xff00ff, wireframe: true } );
  76. var helper = new THREE.Mesh( helperGeometry, helperMaterial );
  77. scene.add( helper );
  78. //
  79. renderer = new THREE.WebGLRenderer( { antialias: true } );
  80. renderer.setPixelRatio( window.devicePixelRatio );
  81. renderer.setSize( window.innerWidth, window.innerHeight );
  82. document.body.appendChild( renderer.domElement );
  83. //
  84. window.addEventListener( 'resize', onWindowResize, false );
  85. }
  86. function animate() {
  87. window.requestAnimationFrame( animate );
  88. controls.update();
  89. renderer.render( scene, camera );
  90. }
  91. function onWindowResize() {
  92. camera.aspect = window.innerWidth / window.innerHeight;
  93. camera.updateProjectionMatrix();
  94. renderer.setSize( window.innerWidth, window.innerHeight );
  95. }
  96. </script>
  97. </body>
  98. </html>