webgl_performance_doublesided.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - performance</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:#fff;
  10. padding:0;
  11. margin:0;
  12. font-weight: bold;
  13. overflow:hidden;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <script src="../build/Three.js"></script>
  19. <script src="js/Stats.js"></script>
  20. <script>
  21. var container, stats;
  22. var camera, scene, renderer;
  23. var mesh, zmesh, lightMesh, geometry;
  24. var mouseX = 0, mouseY = 0;
  25. var windowHalfX = window.innerWidth / 2;
  26. var windowHalfY = window.innerHeight / 2;
  27. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  28. init();
  29. animate();
  30. function init() {
  31. container = document.createElement( 'div' );
  32. document.body.appendChild( container );
  33. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 20000 );
  34. camera.position.z = 3200;
  35. scene = new THREE.Scene();
  36. scene.add( camera );
  37. var light = new THREE.PointLight( 0x0011ff, 1, 5000 );
  38. light.position.set( 4000, 0, 0 );
  39. scene.add( light );
  40. var light = new THREE.PointLight( 0xff1100, 1, 5000 );
  41. light.position.set( -4000, 0, 0 );
  42. scene.add( light );
  43. var material = new THREE.MeshPhongMaterial( { specular: 0xffffff, shading: THREE.SmoothShading, perPixel: true } );
  44. var geometry = new THREE.SphereGeometry( 1, 32, 16, 0, Math.PI );
  45. for ( var i = 0; i < 5000; i ++ ) {
  46. var mesh = new THREE.Mesh( geometry, material );
  47. mesh.position.x = Math.random() * 10000 - 5000;
  48. mesh.position.y = Math.random() * 10000 - 5000;
  49. mesh.position.z = Math.random() * 10000 - 5000;
  50. mesh.rotation.x = Math.random() * 360 * ( Math.PI / 180 );
  51. mesh.rotation.y = Math.random() * 360 * ( Math.PI / 180 );
  52. mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
  53. mesh.matrixAutoUpdate = false;
  54. mesh.updateMatrix();
  55. mesh.doubleSided = true;
  56. scene.add( mesh );
  57. }
  58. renderer = new THREE.WebGLRenderer( { clearColor: 0x050505, clearAlpha: 1, antialias: false } );
  59. renderer.setSize( window.innerWidth, window.innerHeight );
  60. renderer.sortObjects = false;
  61. renderer.gammaInput = true;
  62. renderer.gammaOutput = true;
  63. container.appendChild( renderer.domElement );
  64. stats = new Stats();
  65. stats.domElement.style.position = 'absolute';
  66. stats.domElement.style.top = '0px';
  67. stats.domElement.style.zIndex = 100;
  68. stats.domElement.children[ 0 ].children[ 0 ].style.color = "#eee";
  69. stats.domElement.children[ 0 ].style.background = "transparent";
  70. stats.domElement.children[ 0 ].children[ 1 ].style.display = "none";
  71. container.appendChild( stats.domElement );
  72. }
  73. function onDocumentMouseMove(event) {
  74. mouseX = ( event.clientX - windowHalfX ) * 10;
  75. mouseY = ( event.clientY - windowHalfY ) * 10;
  76. }
  77. //
  78. function animate() {
  79. requestAnimationFrame( animate );
  80. render();
  81. stats.update();
  82. }
  83. function render() {
  84. camera.position.x += ( mouseX - camera.position.x ) * .05;
  85. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  86. camera.lookAt( scene.position );
  87. renderer.render( scene, camera );
  88. }
  89. </script>
  90. </body>
  91. </html>
粤ICP备19079148号