webgl_performance.html 3.2 KB

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