webgl_loader_gltf_transmission.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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, 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.5, 0.7 );
  30. scene = new THREE.Scene();
  31. new RGBELoader()
  32. .setDataType( THREE.FloatType )
  33. .setPath( 'textures/equirectangular/' )
  34. .load( 'royal_esplanade_1k.hdr', function ( texture ) {
  35. texture.mapping = THREE.EquirectangularReflectionMapping;
  36. scene.background = texture;
  37. scene.environment = texture;
  38. // model
  39. const loader = new GLTFLoader()
  40. .setPath( 'models/gltf/' )
  41. .setDRACOLoader( new DRACOLoader().setDecoderPath( 'js/libs/draco/gltf/' ) );
  42. loader.load( 'IridescentDishWithOlives.glb', function ( gltf ) {
  43. mixer = new THREE.AnimationMixer( gltf.scene );
  44. mixer.clipAction( gltf.animations[ 0 ] ).play();
  45. scene.add( gltf.scene );
  46. } );
  47. } );
  48. renderer = new THREE.WebGLRenderer( { antialias: true } );
  49. renderer.setPixelRatio( window.devicePixelRatio );
  50. renderer.setSize( window.innerWidth, window.innerHeight );
  51. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  52. renderer.toneMappingExposure = 1;
  53. renderer.outputEncoding = THREE.sRGBEncoding;
  54. container.appendChild( renderer.domElement );
  55. const controls = new OrbitControls( camera, renderer.domElement );
  56. controls.minDistance = 0.5;
  57. controls.maxDistance = 10;
  58. controls.update();
  59. window.addEventListener( 'resize', onWindowResize );
  60. }
  61. function onWindowResize() {
  62. camera.aspect = window.innerWidth / window.innerHeight;
  63. camera.updateProjectionMatrix();
  64. renderer.setSize( window.innerWidth, window.innerHeight );
  65. }
  66. //
  67. function animate() {
  68. requestAnimationFrame( animate );
  69. if ( mixer ) mixer.update( clock.getDelta() );
  70. render();
  71. }
  72. function render() {
  73. renderer.render( scene, camera );
  74. }
  75. </script>
  76. </body>
  77. </html>