webgpu_loader_gltf_anisotropy.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - glTF + anisotropy</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 webgpu - glTF + anisotropy">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgpu_loader_gltf_anisotropy.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgpu_loader_gltf_anisotropy.jpg">
  11. <link type="text/css" rel="stylesheet" href="example.css">
  12. </head>
  13. <body>
  14. <div id="info" class="invert">
  15. <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
  16. <div class="title-wrapper">
  17. <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a><span>glTF + Anisotropy</span>
  18. </div>
  19. <small>
  20. <a href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_anisotropy" target="_blank" rel="noopener">KHR_materials_anisotropy</a>
  21. Anisotropy Barn Lamp from <a href="https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnisotropyBarnLamp" target="_blank" rel="noopener">glTF-Sample-Models</a><br />
  22. <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>
  23. </small>
  24. </div>
  25. <script type="importmap">
  26. {
  27. "imports": {
  28. "three": "../build/three.webgpu.js",
  29. "three/webgpu": "../build/three.webgpu.js",
  30. "three/tsl": "../build/three.tsl.js",
  31. "three/addons/": "./jsm/"
  32. }
  33. }
  34. </script>
  35. <script type="module">
  36. import * as THREE from 'three/webgpu';
  37. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  38. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  39. import { UltraHDRLoader } from 'three/addons/loaders/UltraHDRLoader.js';
  40. let renderer, scene, camera, controls;
  41. init();
  42. async function init() {
  43. renderer = new THREE.WebGPURenderer( { antialias: true } );
  44. renderer.setPixelRatio( window.devicePixelRatio );
  45. renderer.setSize( window.innerWidth, window.innerHeight );
  46. renderer.setAnimationLoop( animate );
  47. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  48. renderer.toneMappingExposure = 1.35;
  49. document.body.appendChild( renderer.domElement );
  50. scene = new THREE.Scene();
  51. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.01, 10 );
  52. camera.position.set( - 0.35, - 0.2, 0.35 );
  53. controls = new OrbitControls( camera, renderer.domElement );
  54. controls.target.set( 0, - 0.08, 0.11 );
  55. controls.minDistance = 0.1;
  56. controls.maxDistance = 2;
  57. controls.update();
  58. const hdrLoader = new UltraHDRLoader().setPath( 'textures/equirectangular/' );
  59. const gltfLoader = new GLTFLoader().setPath( 'models/gltf/' );
  60. const [ texture, gltf ] = await Promise.all( [
  61. hdrLoader.loadAsync( 'royal_esplanade_2k.hdr.jpg' ),
  62. gltfLoader.loadAsync( 'AnisotropyBarnLamp.glb' ),
  63. ] );
  64. // environment
  65. texture.mapping = THREE.EquirectangularReflectionMapping;
  66. scene.background = texture;
  67. scene.backgroundBlurriness = 0.5;
  68. scene.environment = texture;
  69. // model
  70. scene.add( gltf.scene );
  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. function animate() {
  79. renderer.render( scene, camera );
  80. }
  81. </script>
  82. </body>
  83. </html>
粤ICP备19079148号