lines_sphere_gl.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - lines - spheres - webgl</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7. body {
  8. background-color: #000;
  9. margin: 0px;
  10. overflow: hidden;
  11. }
  12. a {
  13. color:#0078ff;
  14. }
  15. #info {
  16. position: absolute;
  17. top: 10px; width: 100%;
  18. color: #ffffff;
  19. padding: 5px;
  20. font-family: Monospace;
  21. font-size: 13px;
  22. text-align: center;
  23. z-index:100;
  24. }
  25. #oldie {
  26. font-family:monospace;
  27. font-size:13px;
  28. text-align:center;
  29. background:rgb(50,0,0);
  30. color:#fff;
  31. padding:1em;
  32. width:475px;
  33. margin:5em auto 0;
  34. display:none;
  35. }
  36. a {
  37. color: #ff0080;
  38. text-decoration: none;
  39. }
  40. a:hover {
  41. color: #0080ff;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <div id="info">
  47. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - lines WebGL demo
  48. </div>
  49. <center>
  50. <div id="oldie">
  51. Sorry, your browser doesn't support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>.<br/>
  52. <br/>
  53. Please try in
  54. <a href="http://www.chromium.org/getting-involved/dev-channel">Chrome 9+</a> /
  55. <a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 4+</a> /
  56. <a href="http://nightly.webkit.org/">Safari OSX 10.6+</a>
  57. </div>
  58. </center>
  59. <script type="text/javascript" src="../build/Three.js"></script>
  60. <script type="text/javascript" src="js/Stats.js"></script>
  61. <script type="text/javascript">
  62. if ( !is_browser_compatible() ) {
  63. document.getElementById( "oldie" ).style.display = "block";
  64. }
  65. var SCREEN_WIDTH = window.innerWidth,
  66. SCREEN_HEIGHT = window.innerHeight,
  67. r = 450,
  68. mouseX = 0, mouseY = 0,
  69. windowHalfX = window.innerWidth / 2,
  70. windowHalfY = window.innerHeight / 2,
  71. camera, scene, renderer,
  72. stats;
  73. init();
  74. setInterval( loop, 1000 / 60 );
  75. function init() {
  76. var container;
  77. container = document.createElement('div');
  78. document.body.appendChild(container);
  79. camera = new THREE.Camera( 80, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 3000 );
  80. camera.position.z = 1000;
  81. scene = new THREE.Scene();
  82. var i, line, vector1, vector2, material, p,
  83. parameters = [ [ 0.25, 0xff7700, 1, 2 ], [ 0.5, 0xff9900, 1, 1 ], [ 0.75, 0xffaa00, 0.75, 1 ], [ 1, 0xffaa00, 0.5, 1 ], [ 1.25, 0x000833, 0.8, 1 ],
  84. [ 3.0, 0xaaaaaa, 0.75, 2 ], [ 3.5, 0xffffff, 0.5, 1 ], [ 4.5, 0xffffff, 0.25, 1 ], [ 5.5, 0xffffff, 0.125, 1 ] ],
  85. geometry = new THREE.Geometry();
  86. for ( i = 0; i < 1500; ++i ) {
  87. vector1 = new THREE.Vector3( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
  88. vector1.normalize();
  89. vector1.multiplyScalar( r );
  90. vector2 = vector1.clone();
  91. vector2.multiplyScalar( Math.random() * 0.09 + 1 );
  92. geometry.vertices.push( new THREE.Vertex( vector1 ) );
  93. geometry.vertices.push( new THREE.Vertex( vector2 ) );
  94. }
  95. for( i = 0; i < parameters.length; ++i ) {
  96. p = parameters[ i ];
  97. material = new THREE.LineBasicMaterial( { color: p[ 1 ], opacity: p[ 2 ], linewidth: p[ 3 ] } );
  98. line = new THREE.Line( geometry, material, THREE.LinePieces );
  99. line.scale.x = line.scale.y = line.scale.z = p[ 0 ];
  100. line.originalScale = p[ 0 ];
  101. line.rotation.y = Math.random() * Math.PI;
  102. line.updateMatrix();
  103. scene.addObject( line );
  104. }
  105. renderer = new THREE.WebGLRenderer();
  106. renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  107. container.appendChild(renderer.domElement);
  108. /*
  109. stats = new Stats();
  110. stats.domElement.style.position = 'absolute';
  111. stats.domElement.style.top = '0px';
  112. container.appendChild(stats.domElement);
  113. */
  114. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  115. document.addEventListener( 'touchstart', onDocumentTouchStart, false );
  116. document.addEventListener( 'touchmove', onDocumentTouchMove, false );
  117. }
  118. function onDocumentMouseMove(event) {
  119. mouseX = event.clientX - windowHalfX;
  120. mouseY = event.clientY - windowHalfY;
  121. }
  122. function onDocumentTouchStart( event ) {
  123. if(event.touches.length > 1) {
  124. event.preventDefault();
  125. mouseX = event.touches[ 0 ].pageX - windowHalfX;
  126. mouseY = event.touches[ 0 ].pageY - windowHalfY;
  127. }
  128. }
  129. function onDocumentTouchMove( event ) {
  130. if(event.touches.length == 1) {
  131. event.preventDefault();
  132. mouseX = event.touches[ 0 ].pageX - windowHalfX;
  133. mouseY = event.touches[ 0 ].pageY - windowHalfY;
  134. }
  135. }
  136. //
  137. function loop() {
  138. //camera.position.x += ( mouseX - camera.position.x ) * .05;
  139. camera.position.y += ( - mouseY + 200 - camera.position.y ) * .05;
  140. camera.updateMatrix();
  141. renderer.render( scene, camera );
  142. var time = new Date().getTime() * 0.0001;
  143. for( var i = 0; i<scene.objects.length; i++ ) {
  144. scene.objects[i].rotation.y = time * ( i < 4 ? i+1 : - (i+1) );
  145. if ( i < 5 ) scene.objects[i].scale.x = scene.objects[i].scale.y = scene.objects[i].scale.z = scene.objects[i].originalScale * (i/5+1) * (1 + 0.5 * Math.sin( 7*time ) );
  146. }
  147. //stats.update();
  148. }
  149. function is_browser_compatible() {
  150. // WebGL support
  151. try { var test = new Float32Array(1); } catch(e) { return false; }
  152. return true;
  153. }
  154. </script>
  155. </body>
  156. </html>