webgl_loader_gltf_iridescence.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - GLTFloader + Iridescence</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. <meta property="og:title" content="three.js webgl - GLTFloader + Iridescence">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgl_loader_gltf_iridescence.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgl_loader_gltf_iridescence.jpg">
  11. <link type="text/css" rel="stylesheet" href="main.css">
  12. </head>
  13. <body>
  14. <div id="info">
  15. <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_iridescence" target="_blank" rel="noopener">KHR_materials_iridescence</a><br />
  16. Iridescence Lamp from <a href="https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/IridescenceLamp" target="_blank" rel="noopener">glTF-Sample-Models</a><br />
  17. <a href="https://hdrihaven.com/hdri/?h=venice_sunset" target="_blank" rel="noopener">Venice Sunset</a> from <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
  18. </div>
  19. <script type="importmap">
  20. {
  21. "imports": {
  22. "three": "../build/three.module.js",
  23. "three/addons/": "./jsm/"
  24. }
  25. }
  26. </script>
  27. <script type="module">
  28. import * as THREE from 'three';
  29. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  30. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  31. import { HDRLoader } from 'three/addons/loaders/HDRLoader.js';
  32. let renderer, scene, camera, controls;
  33. init().catch( function ( err ) {
  34. console.error( err );
  35. } );
  36. async function init() {
  37. renderer = new THREE.WebGLRenderer( { antialias: true } );
  38. renderer.setAnimationLoop( animate );
  39. renderer.setPixelRatio( window.devicePixelRatio );
  40. renderer.setSize( window.innerWidth, window.innerHeight );
  41. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  42. document.body.appendChild( renderer.domElement );
  43. scene = new THREE.Scene();
  44. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.05, 20 );
  45. camera.position.set( 0.35, 0.05, 0.35 );
  46. controls = new OrbitControls( camera, renderer.domElement );
  47. controls.autoRotate = true;
  48. controls.autoRotateSpeed = - 0.5;
  49. controls.target.set( 0, 0.2, 0 );
  50. controls.update();
  51. const hdrLoader = new HDRLoader()
  52. .setPath( 'textures/equirectangular/' );
  53. const gltfLoader = new GLTFLoader().setPath( 'models/gltf/' );
  54. const [ texture, gltf ] = await Promise.all( [
  55. hdrLoader.loadAsync( 'venice_sunset_1k.hdr' ),
  56. gltfLoader.loadAsync( 'IridescenceLamp.glb' ),
  57. ] );
  58. // environment
  59. texture.mapping = THREE.EquirectangularReflectionMapping;
  60. scene.background = texture;
  61. scene.environment = texture;
  62. // model
  63. scene.add( gltf.scene );
  64. window.addEventListener( 'resize', onWindowResize );
  65. }
  66. function onWindowResize() {
  67. camera.aspect = window.innerWidth / window.innerHeight;
  68. camera.updateProjectionMatrix();
  69. renderer.setSize( window.innerWidth, window.innerHeight );
  70. }
  71. function animate() {
  72. controls.update();
  73. renderer.render( scene, camera );
  74. }
  75. </script>
  76. </body>
  77. </html>
粤ICP备19079148号