webgl_performance.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - GLTFloader</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. <meta property="og:title" content="three.js webgl - GLTFloader">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgl_performance.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgl_performance.jpg">
  11. <link type="text/css" rel="stylesheet" href="main.css">
  12. </head>
  13. <body>
  14. <div id="info">
  15. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - Performance<br />
  16. Dungeon - Low Poly Game Level Challenge by
  17. <a href="https://sketchfab.com/warkarma" target="_blank" rel="noopener">Warkarma</a><br />
  18. <a href="https://hdrihaven.com/hdri/?h=royal_esplanade" target="_blank" rel="noopener">Royal Esplanade</a> from <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
  19. </div>
  20. <script type="importmap">
  21. {
  22. "imports": {
  23. "three": "../build/three.module.js",
  24. "three/addons/": "./jsm/"
  25. }
  26. }
  27. </script>
  28. <script type="module">
  29. import * as THREE from 'three';
  30. import Stats from 'three/addons/libs/stats.module.js';
  31. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  32. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  33. import { UltraHDRLoader } from 'three/addons/loaders/UltraHDRLoader.js';
  34. let camera, scene, renderer, stats;
  35. init();
  36. function init() {
  37. const container = document.createElement( 'div' );
  38. document.body.appendChild( container );
  39. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 100 );
  40. camera.position.set( 60, 60, 60 );
  41. scene = new THREE.Scene();
  42. renderer = new THREE.WebGLRenderer( { antialias: true } );
  43. renderer.setPixelRatio( window.devicePixelRatio );
  44. renderer.setSize( window.innerWidth, window.innerHeight );
  45. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  46. renderer.toneMappingExposure = 1;
  47. renderer.setAnimationLoop( render );
  48. container.appendChild( renderer.domElement );
  49. //
  50. stats = new Stats();
  51. document.body.appendChild( stats.dom );
  52. new UltraHDRLoader()
  53. .setPath( 'textures/equirectangular/' )
  54. .load( 'royal_esplanade_2k.hdr.jpg', function ( texture ) {
  55. texture.mapping = THREE.EquirectangularReflectionMapping;
  56. scene.environment = texture;
  57. // model
  58. const loader = new GLTFLoader().setPath( 'models/gltf/' );
  59. loader.load( 'dungeon_warkarma.glb', async function ( gltf ) {
  60. const model = gltf.scene;
  61. // wait until the model can be added to the scene without blocking due to shader compilation
  62. await renderer.compileAsync( model, camera, scene );
  63. scene.add( model );
  64. } );
  65. } );
  66. const controls = new OrbitControls( camera, renderer.domElement );
  67. controls.minDistance = 2;
  68. controls.maxDistance = 60;
  69. controls.target.set( 0, 0, - 0.2 );
  70. controls.update();
  71. window.addEventListener( 'resize', onWindowResize );
  72. }
  73. function onWindowResize() {
  74. camera.aspect = window.innerWidth / window.innerHeight;
  75. camera.updateProjectionMatrix();
  76. renderer.setSize( window.innerWidth, window.innerHeight );
  77. }
  78. //
  79. function render() {
  80. renderer.render( scene, camera );
  81. stats.update();
  82. }
  83. </script>
  84. </body>
  85. </html>
粤ICP备19079148号