geometry_earth.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - geometry - earth</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7. body {
  8. color: #808080;
  9. font-family:Monospace;
  10. font-size:13px;
  11. text-align:center;
  12. background-color: #ffffff;
  13. margin: 0px;
  14. overflow: hidden;
  15. }
  16. #info {
  17. position: absolute;
  18. top: 0px; width: 100%;
  19. padding: 5px;
  20. }
  21. a {
  22. color: #0080ff;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div id="container"></div>
  28. <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - earth demo</div>
  29. <script type="text/javascript" src="js/Stats.js"></script>
  30. <script type="text/javascript" src="../build/Three.js"></script>
  31. <script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
  32. <script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
  33. <script type="text/javascript">
  34. var container, stats;
  35. var camera, scene, renderer;
  36. var mesh;
  37. var mouseX = 0;
  38. var mouseY = 0;
  39. var windowHalfX = window.innerWidth / 2;
  40. var windowHalfY = window.innerHeight / 2;
  41. init();
  42. setInterval( loop, 1000 / 60 );
  43. function init() {
  44. container = document.getElementById( 'container' );
  45. camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
  46. camera.position.z = 500;
  47. scene = new THREE.Scene();
  48. mesh = new THREE.Mesh( new Plane( 300, 300, 3, 3 ), loadImage( 'textures/shadow.png' ) );
  49. mesh.position.y = - 250;
  50. mesh.rotation.x = - 90 * Math.PI / 180;
  51. scene.addObject(mesh);
  52. mesh = new THREE.Mesh( new Sphere( 200, 20, 20 ), loadImage( 'textures/land_ocean_ice_cloud_2048.jpg' ) );
  53. mesh.overdraw = true;
  54. scene.addObject(mesh);
  55. renderer = new THREE.CanvasRenderer();
  56. renderer.setSize( window.innerWidth, window.innerHeight );
  57. container.appendChild( renderer.domElement );
  58. stats = new Stats();
  59. stats.domElement.style.position = 'absolute';
  60. stats.domElement.style.top = '0px';
  61. container.appendChild( stats.domElement );
  62. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  63. }
  64. function loadImage( path ) {
  65. var canvas = document.createElement( 'canvas' );
  66. canvas.width = 32;
  67. canvas.height = 32;
  68. var material = new THREE.MeshBasicMaterial( { map: new THREE.Texture( canvas, THREE.UVMapping ) } );
  69. var image = new Image();
  70. image.onload = function () {
  71. material.map.image = this;
  72. };
  73. image.src = path;
  74. return material;
  75. }
  76. function onDocumentMouseMove( event ) {
  77. mouseX = ( event.clientX - windowHalfX );
  78. mouseY = ( event.clientY - windowHalfY );
  79. }
  80. function loop() {
  81. camera.position.x += ( mouseX - camera.position.x ) * 0.05;
  82. camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
  83. mesh.rotation.y -= 0.005;
  84. renderer.render( scene, camera );
  85. stats.update();
  86. }
  87. </script>
  88. </body>
  89. </html>