webgl_performance_static.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - performance [static]</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/libs/stats.min.js"></script>
  20. <script>
  21. var container, stats;
  22. var camera, scene, renderer;
  23. var mouseX = 0, mouseY = 0;
  24. var windowHalfX = window.innerWidth / 2;
  25. var windowHalfY = window.innerHeight / 2;
  26. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  27. init();
  28. animate();
  29. function init() {
  30. container = document.createElement( 'div' );
  31. document.body.appendChild( container );
  32. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
  33. camera.position.z = 3200;
  34. scene = new THREE.Scene();
  35. scene.background = new THREE.Color( 0xffffff );
  36. var material = new THREE.MeshNormalMaterial();
  37. var loader = new THREE.BufferGeometryLoader();
  38. loader.load( 'models/json/suzanne_buffergeometry.json', function ( geometry ) {
  39. geometry.computeVertexNormals();
  40. for ( var i = 0; i < 7700; i ++ ) {
  41. var mesh = new THREE.Mesh( geometry, material );
  42. mesh.position.x = Math.random() * 10000 - 5000;
  43. mesh.position.y = Math.random() * 10000 - 5000;
  44. mesh.position.z = Math.random() * 10000 - 5000;
  45. mesh.rotation.x = Math.random() * 2 * Math.PI;
  46. mesh.rotation.y = Math.random() * 2 * Math.PI;
  47. mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
  48. mesh.matrixAutoUpdate = false;
  49. mesh.updateMatrix();
  50. scene.add( mesh );
  51. }
  52. } );
  53. renderer = new THREE.WebGLRenderer();
  54. renderer.setPixelRatio( window.devicePixelRatio );
  55. renderer.setSize( window.innerWidth, window.innerHeight );
  56. //renderer.sortObjects = false;
  57. container.appendChild( renderer.domElement );
  58. stats = new Stats();
  59. container.appendChild( stats.dom );
  60. //
  61. window.addEventListener( 'resize', onWindowResize, false );
  62. }
  63. function onWindowResize() {
  64. windowHalfX = window.innerWidth / 2;
  65. windowHalfY = window.innerHeight / 2;
  66. camera.aspect = window.innerWidth / window.innerHeight;
  67. camera.updateProjectionMatrix();
  68. renderer.setSize( window.innerWidth, window.innerHeight );
  69. }
  70. function onDocumentMouseMove( event ) {
  71. mouseX = ( event.clientX - windowHalfX ) * 10;
  72. mouseY = ( event.clientY - windowHalfY ) * 10;
  73. }
  74. //
  75. function animate() {
  76. requestAnimationFrame( animate );
  77. render();
  78. stats.update();
  79. }
  80. function render() {
  81. camera.position.x += ( mouseX - camera.position.x ) * .05;
  82. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  83. camera.lookAt( scene.position );
  84. renderer.render( scene, camera );
  85. }
  86. </script>
  87. </body>
  88. </html>