webgl_loader_gltf_transmission.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - glTF 2.0 - transmission</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> - GLTFLoader + <a href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission" target="_blank" rel="noopener">KHR_materials_transmission</a> extension<br />
  12. Iridescent Dish With Olives by <a href="https://github.com/echadwick-wayfair" target="_blank" rel="noopener">Eric Chadwick</a><br />
  13. <a href="https://hdrihaven.com/hdri/?h=quarry_01" target="_blank" rel="noopener">Quarry</a> by <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
  14. </div>
  15. <script type="module">
  16. import * as THREE from '../build/three.module.js';
  17. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  18. import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
  19. import { RGBELoader } from './jsm/loaders/RGBELoader.js';
  20. let camera, scene, renderer, clock, mixer;
  21. init();
  22. animate();
  23. function init() {
  24. clock = new THREE.Clock();
  25. const container = document.createElement( 'div' );
  26. document.body.appendChild( container );
  27. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
  28. camera.position.set( 0, 0.5, 0.7 );
  29. scene = new THREE.Scene();
  30. new RGBELoader()
  31. .setDataType( THREE.FloatType )
  32. .setPath( 'textures/equirectangular/' )
  33. .load( 'quarry_01_1k.hdr', function ( texture ) {
  34. texture.mapping = THREE.EquirectangularReflectionMapping;
  35. scene.background = texture;
  36. scene.environment = texture;
  37. // model
  38. const loader = new GLTFLoader().setPath( 'models/gltf/' );
  39. loader.load( 'IridescentDishWithOlives.glb', function ( gltf ) {
  40. mixer = new THREE.AnimationMixer( gltf.scene );
  41. mixer.clipAction( gltf.animations[ 0 ] ).play();
  42. scene.add( gltf.scene );
  43. } );
  44. } );
  45. renderer = new THREE.WebGLRenderer( { antialias: true } );
  46. renderer.setPixelRatio( window.devicePixelRatio );
  47. renderer.setSize( window.innerWidth, window.innerHeight );
  48. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  49. renderer.toneMappingExposure = 1;
  50. renderer.outputEncoding = THREE.sRGBEncoding;
  51. container.appendChild( renderer.domElement );
  52. const controls = new OrbitControls( camera, renderer.domElement );
  53. controls.minDistance = 0.5;
  54. controls.maxDistance = 10;
  55. controls.update();
  56. window.addEventListener( 'resize', onWindowResize );
  57. }
  58. function onWindowResize() {
  59. camera.aspect = window.innerWidth / window.innerHeight;
  60. camera.updateProjectionMatrix();
  61. renderer.setSize( window.innerWidth, window.innerHeight );
  62. }
  63. //
  64. function animate() {
  65. requestAnimationFrame( animate );
  66. if ( mixer ) mixer.update( clock.getDelta() );
  67. render();
  68. }
  69. function render() {
  70. renderer.render( scene, camera );
  71. }
  72. </script>
  73. </body>
  74. </html>