webgl_loader_gltf_transmission.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - GLTFloader + 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><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. <!-- Import maps polyfill -->
  16. <!-- Remove this when import maps will be widely supported -->
  17. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  18. <script type="importmap">
  19. {
  20. "imports": {
  21. "three": "../build/three.module.js",
  22. "three/addons/": "./jsm/"
  23. }
  24. }
  25. </script>
  26. <script type="module">
  27. import * as THREE from 'three';
  28. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  29. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  30. import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
  31. import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
  32. let camera, scene, renderer, controls, clock, mixer;
  33. init();
  34. animate();
  35. function init() {
  36. clock = new THREE.Clock();
  37. const container = document.createElement( 'div' );
  38. document.body.appendChild( container );
  39. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
  40. camera.position.set( 0, 0.4, 0.7 );
  41. scene = new THREE.Scene();
  42. new RGBELoader()
  43. .setPath( 'textures/equirectangular/' )
  44. .load( 'royal_esplanade_1k.hdr', function ( texture ) {
  45. texture.mapping = THREE.EquirectangularReflectionMapping;
  46. scene.background = texture;
  47. scene.environment = texture;
  48. // model
  49. new GLTFLoader()
  50. .setPath( 'models/gltf/' )
  51. .setDRACOLoader( new DRACOLoader().setDecoderPath( 'jsm/libs/draco/gltf/' ) )
  52. .load( 'IridescentDishWithOlives.glb', function ( gltf ) {
  53. mixer = new THREE.AnimationMixer( gltf.scene );
  54. mixer.clipAction( gltf.animations[ 0 ] ).play();
  55. scene.add( gltf.scene );
  56. } );
  57. } );
  58. renderer = new THREE.WebGLRenderer( { antialias: true } );
  59. renderer.setPixelRatio( window.devicePixelRatio );
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  62. renderer.toneMappingExposure = 1;
  63. container.appendChild( renderer.domElement );
  64. controls = new OrbitControls( camera, renderer.domElement );
  65. controls.enableDamping = true;
  66. controls.minDistance = 0.5;
  67. controls.maxDistance = 1;
  68. controls.target.set( 0, 0.1, 0 );
  69. controls.update();
  70. window.addEventListener( 'resize', onWindowResize );
  71. }
  72. function onWindowResize() {
  73. camera.aspect = window.innerWidth / window.innerHeight;
  74. camera.updateProjectionMatrix();
  75. renderer.setSize( window.innerWidth, window.innerHeight );
  76. }
  77. //
  78. function animate() {
  79. requestAnimationFrame( animate );
  80. if ( mixer ) mixer.update( clock.getDelta() );
  81. controls.update(); // required if damping enabled
  82. render();
  83. }
  84. function render() {
  85. renderer.render( scene, camera );
  86. }
  87. </script>
  88. </body>
  89. </html>