misc_controls_deviceorientation.html 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 * as THREE from '../build/three.module.js';
  16. import { DeviceOrientationControls } from './jsm/controls/DeviceOrientationControls.js';
  17. var camera, scene, renderer, controls;
  18. init();
  19. animate();
  20. function init() {
  21. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
  22. controls = new DeviceOrientationControls( camera );
  23. scene = new THREE.Scene();
  24. var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
  25. // invert the geometry on the x-axis so that all of the faces point inward
  26. geometry.scale( - 1, 1, 1 );
  27. var material = new THREE.MeshBasicMaterial( {
  28. map: new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' )
  29. } );
  30. var mesh = new THREE.Mesh( geometry, material );
  31. scene.add( mesh );
  32. var helperGeometry = new THREE.BoxBufferGeometry( 100, 100, 100, 4, 4, 4 );
  33. var helperMaterial = new THREE.MeshBasicMaterial( { color: 0xff00ff, wireframe: true } );
  34. var helper = new THREE.Mesh( helperGeometry, helperMaterial );
  35. scene.add( helper );
  36. //
  37. renderer = new THREE.WebGLRenderer( { antialias: true } );
  38. renderer.setPixelRatio( window.devicePixelRatio );
  39. renderer.setSize( window.innerWidth, window.innerHeight );
  40. document.body.appendChild( renderer.domElement );
  41. //
  42. window.addEventListener( 'resize', onWindowResize, false );
  43. }
  44. function animate() {
  45. window.requestAnimationFrame( animate );
  46. controls.update();
  47. renderer.render( scene, camera );
  48. }
  49. function onWindowResize() {
  50. camera.aspect = window.innerWidth / window.innerHeight;
  51. camera.updateProjectionMatrix();
  52. renderer.setSize( window.innerWidth, window.innerHeight );
  53. }
  54. </script>
  55. </body>
  56. </html>