123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - GLTFloader + Punctual Lights</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - GLTFLoader + <a href="https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_lights_punctual" target="_blank" rel="noopener">KHR_lights_punctual</a><br />
- Lamp by
- <a href="https://www.artstation.com/teresagviegas" target="_blank" rel="noopener">Teresa González Viegas</a>
- </div>
- <script type="importmap">
- {
- "imports": {
- "three": "../build/three.module.js",
- "three/addons/": "./jsm/"
- }
- }
- </script>
- <script type="module">
- import * as THREE from 'three';
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
- import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
- import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
- let camera, scene, renderer;
- const params = {
- punctualLightsEnabled: true
- };
- init().then( render );
- async function init() {
- const container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
- camera.position.set( - 2, 1.5, 3 );
- scene = new THREE.Scene();
- const rgbeLoader = new RGBELoader();
- const envMap = await rgbeLoader.loadAsync( 'textures/equirectangular/moonless_golf_1k.hdr ' );
- envMap.mapping = THREE.EquirectangularReflectionMapping;
- scene.background = envMap;
- scene.environment = envMap;
- const loader = new GLTFLoader();
- const gltf = await loader.loadAsync( 'models/gltf/LightsPunctualLamp.glb' );
- scene.add( gltf.scene );
- const gui = new GUI();
- gui.add( params, 'punctualLightsEnabled' ).onChange( toggleLights );
- gui.open();
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.toneMapping = THREE.ACESFilmicToneMapping;
- renderer.toneMappingExposure = 1;
- container.appendChild( renderer.domElement );
- const controls = new OrbitControls( camera, renderer.domElement );
- controls.addEventListener( 'change', render ); // use if there is no animation loop
- controls.minDistance = 2;
- controls.maxDistance = 10;
- controls.target.set( 0, 1, 0 );
- controls.update();
- window.addEventListener( 'resize', onWindowResize );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- render();
- }
- function toggleLights( visible ) {
- scene.traverse( function ( object ) {
- if ( object.isLight ) {
- object.visible = visible;
- }
- } );
- render();
- }
- //
- function render() {
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|