2
0
Эх сурвалжийг харах

Examples: Add webgl_loader_gltf_lights. (#25506)

* Examples: Add webgl_loader_gltf_lights.

* Added screenshot.

* Examples: Update glTF lights model.

* Examples: Update glTF lights example.

* Examples: Update screenshot.
Michael Herzog 2 жил өмнө
parent
commit
1ae6d2d57a

+ 1 - 0
examples/files.json

@@ -90,6 +90,7 @@
 		"webgl_loader_gltf_compressed",
 		"webgl_loader_gltf_instancing",
 		"webgl_loader_gltf_iridescence",
+		"webgl_loader_gltf_lights",
 		"webgl_loader_gltf_sheen",
 		"webgl_loader_gltf_transmission",
 		"webgl_loader_gltf_variants",

BIN
examples/models/gltf/LightsPunctualLamp.glb


BIN
examples/screenshots/webgl_loader_gltf_lights.jpg


+ 133 - 0
examples/webgl_loader_gltf_lights.html

@@ -0,0 +1,133 @@
+<!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>
+
+		<!-- Import maps polyfill -->
+		<!-- Remove this when import maps will be widely supported -->
+		<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
+
+		<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;
+				renderer.outputEncoding = THREE.sRGBEncoding;
+				renderer.useLegacyLights = false;
+				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>