2
0

webgpu_loader_gltf_sheen.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - sheen</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. <style>
  9. body {
  10. background: #bbbbbb;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div id="info">
  16. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - GLTFLoader + <a href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_sheen" target="_blank" rel="noopener">KHR_materials_sheen</a><br />
  17. Sheen Chair from <a href="https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/SheenChair" target="_blank" rel="noopener">glTF-Sample-Models</a>
  18. </div>
  19. <!-- Import maps polyfill -->
  20. <!-- Remove this when import maps will be widely supported -->
  21. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  22. <script type="importmap">
  23. {
  24. "imports": {
  25. "three": "../build/three.module.js",
  26. "three/addons/": "./jsm/"
  27. }
  28. }
  29. </script>
  30. <script type="module">
  31. import * as THREE from 'three';
  32. import WebGPU from 'three/addons/capabilities/WebGPU.js';
  33. import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
  34. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  35. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  36. import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
  37. import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
  38. let camera, scene, renderer, controls;
  39. init();
  40. animate();
  41. function init() {
  42. if ( WebGPU.isAvailable() === false ) {
  43. document.body.appendChild( WebGPU.getErrorMessage() );
  44. throw new Error( 'No WebGPU support' );
  45. }
  46. const container = document.createElement( 'div' );
  47. document.body.appendChild( container );
  48. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 20 );
  49. camera.position.set( - 0.75, 0.7, 1.25 );
  50. scene = new THREE.Scene();
  51. //scene.add( new THREE.DirectionalLight( 0xffffff, 2 ) );
  52. // model
  53. new GLTFLoader()
  54. .setPath( 'models/gltf/' )
  55. .load( 'SheenChair.glb', function ( gltf ) {
  56. scene.add( gltf.scene );
  57. const object = gltf.scene.getObjectByName( 'SheenChair_fabric' );
  58. const gui = new GUI();
  59. gui.add( object.material, 'sheen', 0, 1 );
  60. gui.open();
  61. } );
  62. renderer = new WebGPURenderer( { antialias: true } );
  63. renderer.setPixelRatio( window.devicePixelRatio );
  64. renderer.setSize( window.innerWidth, window.innerHeight );
  65. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  66. renderer.toneMappingExposure = 1;
  67. renderer.useLegacyLights = false;
  68. container.appendChild( renderer.domElement );
  69. scene.background = new THREE.Color( 0xAAAAAA );
  70. new RGBELoader()
  71. .setPath( 'textures/equirectangular/' )
  72. .load( 'royal_esplanade_1k.hdr', function ( texture ) {
  73. texture.mapping = THREE.EquirectangularReflectionMapping;
  74. scene.background = texture;
  75. //scene.backgroundBlurriness = 1; // @TODO: Needs PMREM
  76. scene.environment = texture;
  77. } );
  78. controls = new OrbitControls( camera, renderer.domElement );
  79. controls.enableDamping = true;
  80. controls.minDistance = 1;
  81. controls.maxDistance = 10;
  82. controls.target.set( 0, 0.35, 0 );
  83. controls.update();
  84. window.addEventListener( 'resize', onWindowResize );
  85. }
  86. function onWindowResize() {
  87. camera.aspect = window.innerWidth / window.innerHeight;
  88. camera.updateProjectionMatrix();
  89. renderer.setSize( window.innerWidth, window.innerHeight );
  90. }
  91. //
  92. function animate() {
  93. requestAnimationFrame( animate );
  94. controls.update(); // required if damping enabled
  95. render();
  96. }
  97. function render() {
  98. renderer.render( scene, camera );
  99. }
  100. </script>
  101. </body>
  102. </html>