Przeglądaj źródła

GLTFLoader: Fix regression unecessarily choosing MeshPhysicalMaterial.

Don McCurdy 5 lat temu
rodzic
commit
434c71ed43

+ 12 - 2
examples/js/loaders/GLTFLoader.js

@@ -488,7 +488,12 @@ THREE.GLTFLoader = ( function () {
 
 
 	}
 	}
 
 
-	GLTFMaterialsClearcoatExtension.prototype.getMaterialType = function ( /* materialIndex */ ) {
+	GLTFMaterialsClearcoatExtension.prototype.getMaterialType = function ( materialIndex ) {
+
+		var parser = this.parser;
+		var materialDef = parser.json.materials[ materialIndex ];
+
+		if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
 
 
 		return THREE.MeshPhysicalMaterial;
 		return THREE.MeshPhysicalMaterial;
 
 
@@ -564,7 +569,12 @@ THREE.GLTFLoader = ( function () {
 
 
 	}
 	}
 
 
-	GLTFMaterialsTransmissionExtension.prototype.getMaterialType = function ( /* materialIndex */ ) {
+	GLTFMaterialsTransmissionExtension.prototype.getMaterialType = function ( materialIndex ) {
+
+		var parser = this.parser;
+		var materialDef = parser.json.materials[ materialIndex ];
+
+		if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
 
 
 		return THREE.MeshPhysicalMaterial;
 		return THREE.MeshPhysicalMaterial;
 
 

+ 12 - 2
examples/jsm/loaders/GLTFLoader.js

@@ -551,7 +551,12 @@ var GLTFLoader = ( function () {
 
 
 	}
 	}
 
 
-	GLTFMaterialsClearcoatExtension.prototype.getMaterialType = function ( /* materialIndex */ ) {
+	GLTFMaterialsClearcoatExtension.prototype.getMaterialType = function ( materialIndex ) {
+
+		var parser = this.parser;
+		var materialDef = parser.json.materials[ materialIndex ];
+
+		if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
 
 
 		return MeshPhysicalMaterial;
 		return MeshPhysicalMaterial;
 
 
@@ -627,7 +632,12 @@ var GLTFLoader = ( function () {
 
 
 	}
 	}
 
 
-	GLTFMaterialsTransmissionExtension.prototype.getMaterialType = function ( /* materialIndex */ ) {
+	GLTFMaterialsTransmissionExtension.prototype.getMaterialType = function ( materialIndex ) {
+
+		var parser = this.parser;
+		var materialDef = parser.json.materials[ materialIndex ];
+
+		if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
 
 
 		return MeshPhysicalMaterial;
 		return MeshPhysicalMaterial;