canvas_geometry_earth.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js canvas - geometry - earth</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 type="text/css">
  8. body {
  9. color: #808080;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. background-color: #ffffff;
  14. margin: 0px;
  15. overflow: hidden;
  16. }
  17. #info {
  18. position: absolute;
  19. top: 0px; width: 100%;
  20. padding: 5px;
  21. }
  22. a {
  23. color: #0080ff;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="container"></div>
  29. <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - earth demo</div>
  30. <script type="text/javascript" src="../build/Three.js"></script>
  31. <script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
  32. <script type="text/javascript" src="js/Stats.js"></script>
  33. <script type="text/javascript">
  34. var container, stats;
  35. var camera, scene, renderer;
  36. var mesh;
  37. var mouseX = 0, mouseY = 0;
  38. var windowHalfX = window.innerWidth / 2;
  39. var windowHalfY = window.innerHeight / 2;
  40. init();
  41. animate();
  42. function init() {
  43. container = document.getElementById( 'container' );
  44. camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
  45. camera.position.z = 500;
  46. scene = new THREE.Scene();
  47. mesh = new THREE.Mesh( new THREE.PlaneGeometry( 300, 300, 3, 3 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/shadow.png' ) } ) );
  48. mesh.overdraw = true;
  49. mesh.position.y = - 250;
  50. mesh.rotation.x = - 90 * Math.PI / 180;
  51. scene.add(mesh);
  52. mesh = new THREE.Mesh( new THREE.SphereGeometry( 200, 20, 20 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/land_ocean_ice_cloud_2048.jpg' ) } ) );
  53. mesh.overdraw = true;
  54. scene.add(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 onDocumentMouseMove( event ) {
  65. mouseX = ( event.clientX - windowHalfX );
  66. mouseY = ( event.clientY - windowHalfY );
  67. }
  68. //
  69. function animate() {
  70. requestAnimationFrame( animate );
  71. render();
  72. stats.update();
  73. }
  74. function render() {
  75. camera.position.x += ( mouseX - camera.position.x ) * 0.05;
  76. camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
  77. mesh.rotation.y -= 0.005;
  78. renderer.render( scene, camera );
  79. }
  80. </script>
  81. </body>
  82. </html>