webgl_loader_gltf_transmission.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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=royal_esplanade" target="_blank" rel="noopener">Royal Esplanade</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. import { DRACOLoader } from './jsm/loaders/DRACOLoader.js';
  21. let camera, scene, renderer, controls, clock, mixer;
  22. init();
  23. animate();
  24. function init() {
  25. clock = new THREE.Clock();
  26. const container = document.createElement( 'div' );
  27. document.body.appendChild( container );
  28. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
  29. camera.position.set( 0, 0.4, 0.7 );
  30. scene = new THREE.Scene();
  31. new RGBELoader()
  32. .setPath( 'textures/equirectangular/' )
  33. .load( 'royal_esplanade_1k.hdr', function ( texture ) {
  34. texture.mapping = THREE.EquirectangularReflectionMapping;
  35. scene.background = texture;
  36. scene.environment = texture;
  37. // model
  38. new GLTFLoader()
  39. .setPath( 'models/gltf/' )
  40. .setDRACOLoader( new DRACOLoader().setDecoderPath( 'js/libs/draco/gltf/' ) )
  41. .load( 'IridescentDishWithOlives.glb', function ( gltf ) {
  42. mixer = new THREE.AnimationMixer( gltf.scene );
  43. mixer.clipAction( gltf.animations[ 0 ] ).play();
  44. scene.add( gltf.scene );
  45. } );
  46. } );
  47. renderer = new THREE.WebGLRenderer( { antialias: true } );
  48. renderer.setPixelRatio( window.devicePixelRatio );
  49. renderer.setSize( window.innerWidth, window.innerHeight );
  50. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  51. renderer.toneMappingExposure = 1;
  52. renderer.outputEncoding = THREE.sRGBEncoding;
  53. container.appendChild( renderer.domElement );
  54. controls = new OrbitControls( camera, renderer.domElement );
  55. controls.enableDamping = true;
  56. controls.minDistance = 0.5;
  57. controls.maxDistance = 1;
  58. controls.target.set( 0, 0.1, 0 );
  59. controls.update();
  60. window.addEventListener( 'resize', onWindowResize );
  61. }
  62. function onWindowResize() {
  63. camera.aspect = window.innerWidth / window.innerHeight;
  64. camera.updateProjectionMatrix();
  65. renderer.setSize( window.innerWidth, window.innerHeight );
  66. }
  67. //
  68. function animate() {
  69. requestAnimationFrame( animate );
  70. if ( mixer ) mixer.update( clock.getDelta() );
  71. controls.update(); // required if damping enabled
  72. render();
  73. }
  74. function render() {
  75. renderer.render( scene, camera );
  76. }
  77. </script>
  78. </body>
  79. </html>