canvas_geometry_earth.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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>
  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 src="../build/Three.js"></script>
  31. <script src="js/Stats.js"></script>
  32. <script>
  33. var container, stats;
  34. var camera, scene, renderer;
  35. var mesh;
  36. var mouseX = 0, mouseY = 0;
  37. var windowHalfX = window.innerWidth / 2;
  38. var windowHalfY = window.innerHeight / 2;
  39. init();
  40. animate();
  41. function init() {
  42. container = document.getElementById( 'container' );
  43. scene = new THREE.Scene();
  44. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
  45. camera.position.z = 500;
  46. scene.add( camera );
  47. mesh = new THREE.Mesh( new THREE.PlaneGeometry( 300, 300, 3, 3 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/shadow.png' ), overdraw: true } ) );
  48. mesh.position.y = - 250;
  49. mesh.rotation.x = - 90 * Math.PI / 180;
  50. scene.add( mesh );
  51. mesh = new THREE.Mesh( new THREE.SphereGeometry( 200, 20, 20 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/land_ocean_ice_cloud_2048.jpg' ), overdraw: true } ) );
  52. scene.add( mesh );
  53. renderer = new THREE.CanvasRenderer();
  54. renderer.setSize( window.innerWidth, window.innerHeight );
  55. container.appendChild( renderer.domElement );
  56. stats = new Stats();
  57. stats.domElement.style.position = 'absolute';
  58. stats.domElement.style.top = '0px';
  59. container.appendChild( stats.domElement );
  60. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  61. }
  62. function onDocumentMouseMove( event ) {
  63. mouseX = ( event.clientX - windowHalfX );
  64. mouseY = ( event.clientY - windowHalfY );
  65. }
  66. //
  67. function animate() {
  68. requestAnimationFrame( animate );
  69. render();
  70. stats.update();
  71. }
  72. function render() {
  73. camera.position.x += ( mouseX - camera.position.x ) * 0.05;
  74. camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
  75. camera.lookAt( scene.position );
  76. mesh.rotation.y -= 0.005;
  77. renderer.render( scene, camera );
  78. }
  79. </script>
  80. </body>
  81. </html>