Ver Fonte

GLTFExporter: guard against missing image data in textures (#25021)

* GLTFExporter: guard against missing image data in textures

* simplify null check
hybridherbst há 2 anos atrás
pai
commit
d93c3052fd
1 ficheiros alterados com 8 adições e 6 exclusões
  1. 8 6
      examples/jsm/exporters/GLTFExporter.js

+ 8 - 6
examples/jsm/exporters/GLTFExporter.js

@@ -1297,9 +1297,11 @@ class GLTFWriter {
 		}
 
 		// pbrMetallicRoughness.metallicRoughnessTexture
-		if ( material.metalnessMap || material.roughnessMap ) {
+		const metalnessMap = material.metalnessMap?.image ? material.metalnessMap : undefined;
+		const roughnessMap = material.roughnessMap?.image ? material.roughnessMap : undefined;
+		if ( metalnessMap || roughnessMap ) {
 
-			const metalRoughTexture = this.buildMetalRoughTexture( material.metalnessMap, material.roughnessMap );
+			const metalRoughTexture = this.buildMetalRoughTexture( metalnessMap, roughnessMap );
 
 			const metalRoughMapDef = { index: this.processTexture( metalRoughTexture ) };
 			this.applyTextureTransform( metalRoughMapDef, metalRoughTexture );
@@ -1308,7 +1310,7 @@ class GLTFWriter {
 		}
 
 		// pbrMetallicRoughness.baseColorTexture or pbrSpecularGlossiness diffuseTexture
-		if ( material.map ) {
+		if ( material.map?.image ) {
 
 			const baseColorMapDef = { index: this.processTexture( material.map ) };
 			this.applyTextureTransform( baseColorMapDef, material.map );
@@ -1337,7 +1339,7 @@ class GLTFWriter {
 			}
 
 			// emissiveTexture
-			if ( material.emissiveMap ) {
+			if ( material.emissiveMap?.image ) {
 
 				const emissiveMapDef = { index: this.processTexture( material.emissiveMap ) };
 				this.applyTextureTransform( emissiveMapDef, material.emissiveMap );
@@ -1348,7 +1350,7 @@ class GLTFWriter {
 		}
 
 		// normalTexture
-		if ( material.normalMap ) {
+		if ( material.normalMap?.image ) {
 
 			const normalMapDef = { index: this.processTexture( material.normalMap ) };
 
@@ -1366,7 +1368,7 @@ class GLTFWriter {
 		}
 
 		// occlusionTexture
-		if ( material.aoMap ) {
+		if ( material.aoMap?.image ) {
 
 			const occlusionMapDef = {
 				index: this.processTexture( material.aoMap ),