css3d_panorama_deviceorientation.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>three.js css3d - panorama - 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. <style>
  8. body {
  9. background-color: #000000;
  10. margin: 0;
  11. cursor: move;
  12. overflow: hidden;
  13. }
  14. a {
  15. color: #ffffff;
  16. }
  17. #info {
  18. position: absolute;
  19. width: 100%;
  20. color: #ffffff;
  21. padding: 5px;
  22. font-family: Monospace;
  23. font-size: 13px;
  24. font-weight: bold;
  25. text-align: center;
  26. z-index: 1;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <script src="../build/three.js"></script>
  32. <script src="js/controls/DeviceOrientationControls.js"></script>
  33. <script src="js/renderers/CSS3DRenderer.js"></script>
  34. <div id="info"><a href="http://threejs.org" target="_blank" rel="noopener">three.js css3d</a> - panorama - decideorientation. cubemap by <a href="http://www.humus.name/index.php?page=Textures" target="_blank" rel="noopener">Humus</a>.</div>
  35. <script>
  36. var camera, scene, renderer;
  37. var controls;
  38. var geometry, material, mesh;
  39. init();
  40. animate();
  41. function init() {
  42. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000 );
  43. controls = new THREE.DeviceOrientationControls( camera );
  44. scene = new THREE.Scene();
  45. var sides = [
  46. {
  47. url: 'textures/cube/Bridge2/posx.jpg',
  48. position: [ -512, 0, 0 ],
  49. rotation: [ 0, Math.PI / 2, 0 ]
  50. },
  51. {
  52. url: 'textures/cube/Bridge2/negx.jpg',
  53. position: [ 512, 0, 0 ],
  54. rotation: [ 0, -Math.PI / 2, 0 ]
  55. },
  56. {
  57. url: 'textures/cube/Bridge2/posy.jpg',
  58. position: [ 0, 512, 0 ],
  59. rotation: [ Math.PI / 2, 0, Math.PI ]
  60. },
  61. {
  62. url: 'textures/cube/Bridge2/negy.jpg',
  63. position: [ 0, -512, 0 ],
  64. rotation: [ - Math.PI / 2, 0, Math.PI ]
  65. },
  66. {
  67. url: 'textures/cube/Bridge2/posz.jpg',
  68. position: [ 0, 0, 512 ],
  69. rotation: [ 0, Math.PI, 0 ]
  70. },
  71. {
  72. url: 'textures/cube/Bridge2/negz.jpg',
  73. position: [ 0, 0, -512 ],
  74. rotation: [ 0, 0, 0 ]
  75. }
  76. ];
  77. var cube = new THREE.Object3D();
  78. scene.add( cube );
  79. for ( var i = 0; i < sides.length; i ++ ) {
  80. var side = sides[ i ];
  81. var element = document.createElement( 'img' );
  82. element.width = 1026; // 2 pixels extra to close the gap.
  83. element.src = side.url;
  84. var object = new THREE.CSS3DObject( element );
  85. object.position.fromArray( side.position );
  86. object.rotation.fromArray( side.rotation );
  87. cube.add( object );
  88. }
  89. renderer = new THREE.CSS3DRenderer();
  90. renderer.setSize( window.innerWidth, window.innerHeight );
  91. document.body.appendChild( renderer.domElement );
  92. //
  93. window.addEventListener( 'resize', onWindowResize, false );
  94. }
  95. function onWindowResize() {
  96. camera.aspect = window.innerWidth / window.innerHeight;
  97. camera.updateProjectionMatrix();
  98. renderer.setSize( window.innerWidth, window.innerHeight );
  99. }
  100. function animate() {
  101. requestAnimationFrame( animate );
  102. controls.update();
  103. renderer.render( scene, camera );
  104. }
  105. </script>
  106. </body>
  107. </html>