Просмотр исходного кода

Added scene.environment to some examples.

Mr.doob 5 лет назад
Родитель
Сommit
a8c7317c0d

+ 1 - 1
examples/webgl_loader_gltf.html

@@ -51,6 +51,7 @@
 						pmremGenerator.dispose();
 
 						scene.background = envMap;
+						scene.environment = envMap;
 
 						// model
 
@@ -63,7 +64,6 @@
 
 								if ( child.isMesh ) {
 
-									child.material.envMap = envMap;
 									roughnessMipmapper.generateMipmaps( child.material );
 
 								}

+ 12 - 21
examples/webgl_materials_car.html

@@ -39,7 +39,7 @@
 			import { RGBELoader } from './jsm/loaders/RGBELoader.js';
 
 			var camera, scene, renderer;
-			var stats, carModel, materialsLib, envMap;
+			var stats, carModel, materialsLib;
 
 			var bodyMatSelect = document.getElementById( 'body-mat' );
 			var rimMatSelect = document.getElementById( 'rim-mat' );
@@ -67,10 +67,11 @@
 					.setPath( 'textures/hdr/' )
 					.load( 'quarry_01_1k.hdr', function ( texture ) {
 
-						envMap = pmremGenerator.fromEquirectangular( texture ).texture;
+						var envMap = pmremGenerator.fromEquirectangular( texture ).texture;
 						pmremGenerator.dispose();
 
 						scene.background = envMap;
+						scene.environment = envMap;
 
 						//
 
@@ -126,16 +127,6 @@
 
 					carModel = gltf.scene.children[ 0 ];
 
-					carModel.traverse( function ( child ) {
-
-						if ( child.isMesh ) {
-
-							child.material.envMap = envMap;
-
-						}
-
-					} );
-
 					// shadow
 					var texture = new THREE.TextureLoader().load( 'models/gltf/ferrari_ao.png' );
 					var shadow = new THREE.Mesh(
@@ -185,22 +176,22 @@
 					main: [
 
 						new THREE.MeshStandardMaterial( {
-							color: 0xff4400, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'orange'
+							color: 0xff4400, metalness: 1.0, roughness: 0.2, name: 'orange'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0x001166, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'blue'
+							color: 0x001166, metalness: 1.0, roughness: 0.2, name: 'blue'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0x990000, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'red'
+							color: 0x990000, metalness: 1.0, roughness: 0.2, name: 'red'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0x000000, envMap: envMap, metalness: 1.0, roughness: 0.4, name: 'black'
+							color: 0x000000, metalness: 1.0, roughness: 0.4, name: 'black'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0xffffff, envMap: envMap, metalness: 0.1, roughness: 0.2, name: 'white'
+							color: 0xffffff, metalness: 0.1, roughness: 0.2, name: 'white'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0xffffff, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'metallic'
+							color: 0xffffff, metalness: 1.0, roughness: 0.2, name: 'metallic'
 						} ),
 
 					],
@@ -208,13 +199,13 @@
 					glass: [
 
 						new THREE.MeshPhysicalMaterial( {
-							color: 0xffffff, envMap: envMap, metalness: 1, roughness: 0, transparency: 1.0, transparent: true, name: 'clear'
+							color: 0xffffff, metalness: 1, roughness: 0, transparency: 1.0, transparent: true, name: 'clear'
 						} ),
 						new THREE.MeshPhysicalMaterial( {
-							color: 0x000000, envMap: envMap, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'smoked'
+							color: 0x000000, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'smoked'
 						} ),
 						new THREE.MeshPhysicalMaterial( {
-							color: 0x001133, envMap: envMap, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'blue'
+							color: 0x001133, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'blue'
 						} ),
 
 					],

+ 189 - 193
examples/webgl_materials_physical_clearcoat.html

@@ -1,248 +1,244 @@
 <!DOCTYPE html>
 <html lang="en">
+	<head>
+		<title>three.js webgl - materials - clearcoat</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> webgl - materials - clearcoat
+		</div>
 
-<head>
-	<title>three.js webgl - materials - clearcoat</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>
+		<script type="module">
 
-<body>
-	<div id="info">
-		<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - materials - clearcoat
-	</div>
+			import * as THREE from '../build/three.module.js';
 
-	<script type="module">
+			import Stats from './jsm/libs/stats.module.js';
 
-		import * as THREE from '../build/three.module.js';
+			import { OrbitControls } from './jsm/controls/OrbitControls.js';
+			import { HDRCubeTextureLoader } from './jsm/loaders/HDRCubeTextureLoader.js';
 
-		import Stats from './jsm/libs/stats.module.js';
+			var container, stats;
 
-		import { OrbitControls } from './jsm/controls/OrbitControls.js';
-		import { RGBELoader } from './jsm/loaders/RGBELoader.js';
+			var camera, scene, renderer;
 
-		var container, stats;
+			var particleLight;
+			var group;
 
-		var camera, scene, renderer;
+			init();
+			animate();
 
-		var particleLight;
-		var group;
+			function init() {
 
-		init();
-		animate();
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
 
-		function init() {
+				camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
+				camera.position.z = 1000;
 
-			container = document.createElement( 'div' );
-			document.body.appendChild( container );
+				scene = new THREE.Scene();
 
-			camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
-			camera.position.z = 1000;
+				group = new THREE.Group();
+				scene.add( group );
 
-			scene = new THREE.Scene();
-
-			group = new THREE.Group();
-			scene.add( group );
-
-			new RGBELoader()
+				new HDRCubeTextureLoader()
 					.setDataType( THREE.UnsignedByteType )
-					.setPath( 'textures/equirectangular/' )
-					.load( 'pedestrian_overpass_1k.hdr', function ( hdrEquirect ) {
-
-						var hdrCubeRenderTarget = pmremGenerator.fromEquirectangular( hdrEquirect );
-						hdrEquirect.dispose();
-						pmremGenerator.dispose();
-
-						var geometry = new THREE.SphereBufferGeometry( 80, 64, 32 );
-
-						var textureLoader = new THREE.TextureLoader();
-
-						var diffuse = textureLoader.load( "textures/carbon/Carbon.png" );
-						diffuse.encoding = THREE.sRGBEncoding;
-						diffuse.wrapS = THREE.RepeatWrapping;
-						diffuse.wrapT = THREE.RepeatWrapping;
-						diffuse.repeat.x = 10;
-						diffuse.repeat.y = 10;
-
-						var normalMap = textureLoader.load( "textures/carbon/Carbon_Normal.png" );
-						normalMap.wrapS = THREE.RepeatWrapping;
-						normalMap.wrapT = THREE.RepeatWrapping;
-
-						var normalMap2 = textureLoader.load( "textures/water/Water_1_M_Normal.jpg" );
-
-						var normalMap3 = textureLoader.load( "textures/flakes.png" );
-						normalMap3.wrapS = THREE.RepeatWrapping;
-						normalMap3.wrapT = THREE.RepeatWrapping;
-						normalMap3.repeat.x = 10;
-						normalMap3.repeat.y = 10;
-						normalMap3.anisotropy = 16;
-
-						var normalMap4 = textureLoader.load( "textures/golfball.jpg" );
-
-						var clearcoatNormaMap = textureLoader.load( "textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png" );
-
-						// car paint
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							clearcoat: 1.0,
-							clearcoatRoughness: 0.1,
-							metalness: 0.9,
-							roughness: 0.5,
-							color: 0x0000ff,
-							envMap: hdrCubeRenderTarget.texture,
-							normalMap: normalMap3,
-							normalScale: new THREE.Vector2( 0.1, 0.1 )
-						} );
-
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = - 100;
-						mesh.position.y = 100;
-						group.add( mesh );
-
-						// fibers
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							clearcoat: 1.0,
-							clearcoatRoughness: 0.1,
-							envMap: hdrCubeRenderTarget.texture,
-							map: diffuse,
-							normalMap: normalMap
-						} );
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = 100;
-						mesh.position.y = 100;
-						group.add( mesh );
-
-						// golf
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							metalness: 0.0,
-							roughness: 0.1,
-							clearcoat: 1.0,
-							normalMap: normalMap4,
-							envMap: hdrCubeRenderTarget.texture,
-							clearcoatNormalMap: clearcoatNormaMap,
-							clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
-						} );
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = - 100;
-						mesh.position.y = - 100;
-						group.add( mesh );
-
-						// clearcoat + normalmap
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							clearcoat: 1.0,
-							metalness: 1.0,
-							color: 0xff0000,
-							envMap: hdrCubeRenderTarget.texture,
-							normalMap: normalMap2,
-							normalScale: new THREE.Vector2( 0.15, 0.15 ),
-							clearcoatNormalMap: clearcoatNormaMap,
-							clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
-						} );
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = 100;
-						mesh.position.y = - 100;
-						group.add( mesh );
-
-						//
-
-						scene.background = hdrCubeRenderTarget.texture;
-
-					}
-
+					.setPath( 'textures/cube/pisaHDR/' )
+					.load( [ 'px.hdr', 'nx.hdr', 'py.hdr', 'ny.hdr', 'pz.hdr', 'nz.hdr' ],
+						function ( hdrCubeMap ) {
+
+							var hdrCubeRenderTarget = pmremGenerator.fromCubemap( hdrCubeMap );
+							hdrCubeMap.dispose();
+							pmremGenerator.dispose();
+
+							var geometry = new THREE.SphereBufferGeometry( 80, 64, 32 );
+
+							var textureLoader = new THREE.TextureLoader();
+
+							var diffuse = textureLoader.load( "textures/carbon/Carbon.png" );
+							diffuse.encoding = THREE.sRGBEncoding;
+							diffuse.wrapS = THREE.RepeatWrapping;
+							diffuse.wrapT = THREE.RepeatWrapping;
+							diffuse.repeat.x = 10;
+							diffuse.repeat.y = 10;
+
+							var normalMap = textureLoader.load( "textures/carbon/Carbon_Normal.png" );
+							normalMap.wrapS = THREE.RepeatWrapping;
+							normalMap.wrapT = THREE.RepeatWrapping;
+
+							var normalMap2 = textureLoader.load( "textures/water/Water_1_M_Normal.jpg" );
+
+							var normalMap3 = textureLoader.load( "textures/flakes.png" );
+							normalMap3.wrapS = THREE.RepeatWrapping;
+							normalMap3.wrapT = THREE.RepeatWrapping;
+							normalMap3.repeat.x = 10;
+							normalMap3.repeat.y = 10;
+							normalMap3.anisotropy = 16;
+
+							var normalMap4 = textureLoader.load( "textures/golfball.jpg" );
+
+							var clearcoatNormaMap = textureLoader.load( "textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png" );
+
+							// car paint
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								clearcoat: 1.0,
+								clearcoatRoughness: 0.1,
+								metalness: 0.9,
+								roughness: 0.5,
+								color: 0x0000ff,
+								normalMap: normalMap3,
+								normalScale: new THREE.Vector2( 0.15, 0.15 )
+							} );
+
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = - 100;
+							mesh.position.y = 100;
+							group.add( mesh );
+
+							// fibers
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								roughness: 0.5,
+								clearcoat: 1.0,
+								clearcoatRoughness: 0.1,
+								map: diffuse,
+								normalMap: normalMap
+							} );
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = 100;
+							mesh.position.y = 100;
+							group.add( mesh );
+
+							// golf
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								metalness: 0.0,
+								roughness: 0.1,
+								clearcoat: 1.0,
+								normalMap: normalMap4,
+								clearcoatNormalMap: clearcoatNormaMap,
+								clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
+							} );
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = - 100;
+							mesh.position.y = - 100;
+							group.add( mesh );
+
+							// clearcoat + normalmap
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								clearcoat: 1.0,
+								metalness: 1.0,
+								color: 0xff0000,
+								normalMap: normalMap2,
+								normalScale: new THREE.Vector2( 0.15, 0.15 ),
+								clearcoatNormalMap: clearcoatNormaMap,
+								clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
+							} );
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = 100;
+							mesh.position.y = - 100;
+							group.add( mesh );
+
+							//
+
+							scene.background = hdrCubeRenderTarget.texture;
+							scene.environment = hdrCubeRenderTarget.texture;
+
+						}
+
+					);
+
+				// LIGHTS
+
+				particleLight = new THREE.Mesh(
+					new THREE.SphereBufferGeometry( 4, 8, 8 ),
+					new THREE.MeshBasicMaterial( { color: 0xffffff } )
 				);
+				scene.add( particleLight );
 
-			// LIGHTS
+				particleLight.add( new THREE.PointLight( 0xffffff, 1 ) );
 
-			particleLight = new THREE.Mesh(
-				new THREE.SphereBufferGeometry( 4, 8, 8 ),
-				new THREE.MeshBasicMaterial( { color: 0xffffff } )
-			);
-			scene.add( particleLight );
+				renderer = new THREE.WebGLRenderer();
+				renderer.setPixelRatio( window.devicePixelRatio );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+				container.appendChild( renderer.domElement );
 
-			particleLight.add( new THREE.PointLight( 0xffffff, 1 ) );
+				//
 
-			renderer = new THREE.WebGLRenderer();
-			renderer.setPixelRatio( window.devicePixelRatio );
-			renderer.setSize( window.innerWidth, window.innerHeight );
-			container.appendChild( renderer.domElement );
+				renderer.toneMapping = THREE.ACESFilmicToneMapping;
+				renderer.toneMappingExposure = 1;
 
-			//
+				//
 
-			renderer.toneMapping = THREE.ACESFilmicToneMapping;
-			renderer.toneMappingExposure = 1;
+				renderer.outputEncoding = THREE.sRGBEncoding;
 
-			//
+				//
 
-			renderer.outputEncoding = THREE.sRGBEncoding;
+				var pmremGenerator = new THREE.PMREMGenerator( renderer );
+				pmremGenerator.compileEquirectangularShader();
 
-			//
+				//
 
-			var pmremGenerator = new THREE.PMREMGenerator( renderer );
-			pmremGenerator.compileEquirectangularShader();
+				stats = new Stats();
+				container.appendChild( stats.dom );
 
-			//
+				// EVENTS
 
-			stats = new Stats();
-			container.appendChild( stats.dom );
+				new OrbitControls( camera, renderer.domElement );
 
-			// EVENTS
+				window.addEventListener( 'resize', onWindowResize, false );
 
-			var controls = new OrbitControls( camera, renderer.domElement );
+			}
 
-			window.addEventListener( 'resize', onWindowResize, false );
+			//
 
-		}
+			function onWindowResize() {
 
-		//
+				var width = window.innerWidth;
+				var height = window.innerHeight;
 
-		function onWindowResize() {
+				camera.aspect = width / height;
+				camera.updateProjectionMatrix();
 
-			var width = window.innerWidth;
-			var height = window.innerHeight;
+				renderer.setSize( width, height );
 
-			camera.aspect = width / height;
-			camera.updateProjectionMatrix();
+			}
 
-			renderer.setSize( width, height );
+			//
 
-		}
+			function animate() {
 
-		//
+				requestAnimationFrame( animate );
 
-		function animate() {
+				render();
 
-			requestAnimationFrame( animate );
+				stats.update();
 
-			render();
+			}
 
-			stats.update();
+			function render() {
 
-		}
+				var timer = Date.now() * 0.00025;
 
-		function render() {
+				particleLight.position.x = Math.sin( timer * 7 ) * 300;
+				particleLight.position.y = Math.cos( timer * 5 ) * 400;
+				particleLight.position.z = Math.cos( timer * 3 ) * 300;
 
-			var timer = Date.now() * 0.00025;
+				for ( var i = 0; i < group.children.length; i ++ ) {
 
-			particleLight.position.x = Math.sin( timer * 7 ) * 300;
-			particleLight.position.y = Math.cos( timer * 5 ) * 400;
-			particleLight.position.z = Math.cos( timer * 3 ) * 300;
+					var child = group.children[ i ];
+					child.rotation.y += 0.005;
 
-			for ( var i = 0; i < group.children.length; i ++ ) {
+				}
 
-				var child = group.children[ i ];
-				child.rotation.y += 0.005;
+				renderer.render( scene, camera );
 
 			}
 
-			renderer.render( scene, camera );
-
-		}
-
-
-	</script>
-</body>
+		</script>
+	</body>
 </html>

+ 2 - 3
examples/webgl_materials_standard.html

@@ -87,7 +87,7 @@
 
 						group.traverse( function ( child ) {
 
-							if ( child instanceof THREE.Mesh ) {
+							if ( child.isMesh ) {
 
 								child.material = material;
 
@@ -110,9 +110,8 @@
 						hdrEquirect.dispose();
 						pmremGenerator.dispose();
 
-						material.envMap = hdrCubeRenderTarget.texture;
-
 						scene.background = hdrCubeRenderTarget.texture;
+						scene.environment = hdrCubeRenderTarget.texture;
 
 					} );
 

+ 4 - 3
examples/webgl_tonemapping.html

@@ -136,8 +136,9 @@
 					.setPath( 'textures/equirectangular/' )
 					.load( 'pedestrian_overpass_1k.hdr', function ( hdrEquirect ) {
 
-						standardMaterial.envMap = pmremGenerator.fromEquirectangular( hdrEquirect ).texture;
-						standardMaterial.needsUpdate = true;
+						scene.environment = pmremGenerator.fromEquirectangular( hdrEquirect ).texture;
+
+						standardMaterial.needsUpdate = true; // TODO(mrdoob) Should WebGLRenderer handle this?
 
 						hdrEquirect.dispose();
 						pmremGenerator.dispose();
@@ -179,7 +180,7 @@
 				stats = new Stats();
 				container.appendChild( stats.dom );
 
-				var controls = new OrbitControls( camera, renderer.domElement );
+				new OrbitControls( camera, renderer.domElement );
 
 				window.addEventListener( 'resize', onWindowResize, false );