webgpu_performance.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - 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> - WebGPU 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.webgpu.js",
  20. "three/webgpu": "../build/three.webgpu.js",
  21. "three/addons/": "./jsm/"
  22. }
  23. }
  24. </script>
  25. <script type="module">
  26. import * as THREE from 'three';
  27. import Stats from 'three/addons/libs/stats.module.js';
  28. import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
  29. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  30. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  31. import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
  32. import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
  33. let camera, scene, renderer, stats;
  34. let model;
  35. const options = { static: true };
  36. init();
  37. function setStatic( object, value ) {
  38. object.traverse( child => {
  39. if ( child.isMesh ) {
  40. child.static = value;
  41. }
  42. } );
  43. }
  44. function init() {
  45. const container = document.createElement( 'div' );
  46. document.body.appendChild( container );
  47. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 100 );
  48. camera.position.set( 60, 60, 60 );
  49. scene = new THREE.Scene();
  50. renderer = new THREE.WebGPURenderer( { antialias: true, forceWebGL: false } );
  51. renderer.setPixelRatio( window.devicePixelRatio );
  52. renderer.setSize( window.innerWidth, window.innerHeight );
  53. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  54. renderer.toneMappingExposure = 1;
  55. renderer.setAnimationLoop( render );
  56. container.appendChild( renderer.domElement );
  57. //
  58. stats = new Stats();
  59. document.body.appendChild( stats.dom );
  60. new RGBELoader()
  61. .setPath( 'textures/equirectangular/' )
  62. .load( 'royal_esplanade_1k.hdr', function ( texture ) {
  63. texture.mapping = THREE.EquirectangularReflectionMapping;
  64. scene.environment = texture;
  65. // model
  66. const dracoLoader = new DRACOLoader();
  67. dracoLoader.setDecoderPath( 'jsm/libs/draco/gltf/' );
  68. const loader = new GLTFLoader().setPath( 'models/gltf/' );
  69. loader.setDRACOLoader( dracoLoader );
  70. loader.load( 'dungeon_warkarma.glb', async function ( gltf ) {
  71. model = gltf.scene;
  72. // wait until the model can be added to the scene without blocking due to shader compilation
  73. await renderer.compileAsync( model, camera, scene );
  74. scene.add( model );
  75. //
  76. setStatic( model, options.static );
  77. } );
  78. } );
  79. const controls = new OrbitControls( camera, renderer.domElement );
  80. controls.minDistance = 2;
  81. controls.maxDistance = 60;
  82. controls.target.set( 0, 0, - 0.2 );
  83. controls.update();
  84. // gui
  85. const gui = new GUI();
  86. gui.add( options, 'static' ).onChange( () => {
  87. setStatic( model, options.static );
  88. } );
  89. window.addEventListener( 'resize', onWindowResize );
  90. }
  91. function onWindowResize() {
  92. camera.aspect = window.innerWidth / window.innerHeight;
  93. camera.updateProjectionMatrix();
  94. renderer.setSize( window.innerWidth, window.innerHeight );
  95. }
  96. //
  97. function render() {
  98. renderer.renderAsync( scene, camera );
  99. stats.update();
  100. }
  101. </script>
  102. </body>
  103. </html>
粤ICP备19079148号