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

Use clamped material.emissiveIntensity at GLTF export (#22007)

* Use clamped material.emissiveIntensity at GLTF export

* Revert build

* Revert build (for real)

* Third time's the charm

* Limit the emissive value after multiplying by emissiveIntensity

* Better readability (as suggested by WestLangley)
Benjamin MICHEL 4 жил өмнө
parent
commit
a5ce030b9c

+ 13 - 4
examples/js/exporters/GLTFExporter.js

@@ -1089,12 +1089,21 @@
 
 			if ( material.emissive ) {
 
-				// note: `emissive` is not scaled by `material.emissiveIntensity` for now to accommodate glTF spec. see #21849.
-				const emissive = material.emissive.toArray();
+				// note: emissive components are limited to stay within the 0 - 1 range to accommodate glTF spec. see #21849 and #22000.
+				const emissive = material.emissive.clone().multiplyScalar( material.emissiveIntensity );
+				const maxEmissiveComponent = Math.max( emissive.r, emissive.g, emissive.b );
 
-				if ( ! equalArray( emissive, [ 0, 0, 0 ] ) ) {
+				if ( maxEmissiveComponent > 1 ) {
 
-					materialDef.emissiveFactor = emissive;
+					emissive.multiplyScalar( 1 / maxEmissiveComponent );
+
+					console.warn( 'THREE.GLTFExporter: Some emissive components exceed 1; emissive has been limited' );
+
+				}
+
+				if ( maxEmissiveComponent > 0 ) {
+
+					materialDef.emissiveFactor = emissive.toArray();
 
 				} // emissiveTexture
 

+ 13 - 4
examples/jsm/exporters/GLTFExporter.js

@@ -1185,12 +1185,21 @@ class GLTFWriter {
 
 		if ( material.emissive ) {
 
-			// note: `emissive` is not scaled by `material.emissiveIntensity` for now to accommodate glTF spec. see #21849.
-			const emissive = material.emissive.toArray();
+			// note: emissive components are limited to stay within the 0 - 1 range to accommodate glTF spec. see #21849 and #22000.
+			const emissive = material.emissive.clone().multiplyScalar( material.emissiveIntensity );
+			const maxEmissiveComponent = Math.max( emissive.r, emissive.g, emissive.b );
 
-			if ( ! equalArray( emissive, [ 0, 0, 0 ] ) ) {
+			if ( maxEmissiveComponent > 1 ) {
 
-				materialDef.emissiveFactor = emissive;
+				emissive.multiplyScalar( 1 / maxEmissiveComponent );
+
+				console.warn( 'THREE.GLTFExporter: Some emissive components exceed 1; emissive has been limited' );
+
+			}
+
+			if ( maxEmissiveComponent > 0 ) {
+
+				materialDef.emissiveFactor = emissive.toArray();
 
 			}