misc_controls_deviceorientation.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. </head>
  9. <body>
  10. <div id="info">
  11. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - equirectangular panorama demo with DeviceOrientation controls.<br/>
  12. photo by <a href="http://www.flickr.com/photos/jonragnarsson/2294472375/" target="_blank" rel="noopener">Jón Ragnarsson</a>.
  13. </div>
  14. <script type="module">
  15. import {
  16. BoxBufferGeometry,
  17. Mesh,
  18. MeshBasicMaterial,
  19. PerspectiveCamera,
  20. Scene,
  21. SphereBufferGeometry,
  22. TextureLoader,
  23. WebGLRenderer
  24. } from "../build/three.module.js";
  25. import { DeviceOrientationControls } from './jsm/controls/DeviceOrientationControls.js';
  26. var camera, scene, renderer, controls;
  27. init();
  28. animate();
  29. function init() {
  30. camera = new PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
  31. controls = new DeviceOrientationControls( camera );
  32. scene = new Scene();
  33. var geometry = new SphereBufferGeometry( 500, 60, 40 );
  34. // invert the geometry on the x-axis so that all of the faces point inward
  35. geometry.scale( - 1, 1, 1 );
  36. var material = new MeshBasicMaterial( {
  37. map: new TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' )
  38. } );
  39. var mesh = new Mesh( geometry, material );
  40. scene.add( mesh );
  41. var helperGeometry = new BoxBufferGeometry( 100, 100, 100, 4, 4, 4 );
  42. var helperMaterial = new MeshBasicMaterial( { color: 0xff00ff, wireframe: true } );
  43. var helper = new Mesh( helperGeometry, helperMaterial );
  44. scene.add( helper );
  45. //
  46. renderer = new WebGLRenderer( { antialias: true } );
  47. renderer.setPixelRatio( window.devicePixelRatio );
  48. renderer.setSize( window.innerWidth, window.innerHeight );
  49. document.body.appendChild( renderer.domElement );
  50. //
  51. window.addEventListener( 'resize', onWindowResize, false );
  52. }
  53. function animate() {
  54. window.requestAnimationFrame( animate );
  55. controls.update();
  56. renderer.render( scene, camera );
  57. }
  58. function onWindowResize() {
  59. camera.aspect = window.innerWidth / window.innerHeight;
  60. camera.updateProjectionMatrix();
  61. renderer.setSize( window.innerWidth, window.innerHeight );
  62. }
  63. </script>
  64. </body>
  65. </html>