Mugen87 6 лет назад
Родитель
Сommit
965854c072

+ 1 - 1
examples/js/loaders/STLLoader.js

@@ -44,7 +44,7 @@
  *
  *
  *  for (var i = 0; i < nGeometryGroups; i++) {
  *  for (var i = 0; i < nGeometryGroups; i++) {
  *
  *
- *		var material = new THREE.MeshStandardMaterial({
+ *		var material = new THREE.MeshPhongMaterial({
  *			color: colorMap[i],
  *			color: colorMap[i],
  *			wireframe: false
  *			wireframe: false
  *		});
  *		});

+ 42 - 3
examples/jsm/exporters/GLTFExporter.js

@@ -919,7 +919,7 @@ GLTFExporter.prototype = {
 
 
 			}
 			}
 
 
-			if ( material.isShaderMaterial ) {
+			if ( material.isShaderMaterial && !material.isGLTFSpecularGlossinessMaterial ) {
 
 
 				console.warn( 'GLTFExporter: THREE.ShaderMaterial not supported.' );
 				console.warn( 'GLTFExporter: THREE.ShaderMaterial not supported.' );
 				return null;
 				return null;
@@ -939,6 +939,12 @@ GLTFExporter.prototype = {
 
 
 				extensionsUsed[ 'KHR_materials_unlit' ] = true;
 				extensionsUsed[ 'KHR_materials_unlit' ] = true;
 
 
+			} else if ( material.isGLTFSpecularGlossinessMaterial ) {
+
+				gltfMaterial.extensions = { KHR_materials_pbrSpecularGlossiness: {} };
+
+				extensionsUsed[ 'KHR_materials_pbrSpecularGlossiness' ] = true;
+
 			} else if ( ! material.isMeshStandardMaterial ) {
 			} else if ( ! material.isMeshStandardMaterial ) {
 
 
 				console.warn( 'GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.' );
 				console.warn( 'GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.' );
@@ -971,6 +977,23 @@ GLTFExporter.prototype = {
 
 
 			}
 			}
 
 
+			// pbrSpecularGlossiness diffuse, specular and glossiness factor
+			if ( material.isGLTFSpecularGlossinessMaterial ) {
+				
+				if ( gltfMaterial.pbrMetallicRoughness.baseColorFactor ) {
+
+					gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness.diffuseFactor = gltfMaterial.pbrMetallicRoughness.baseColorFactor;
+				  
+				}
+
+				var specularFactor = [ 1, 1, 1 ];
+				material.specular.toArray( specularFactor, 0 );
+				gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness.specularFactor = specularFactor;
+
+				gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness.glossinessFactor = material.glossiness;
+			
+			}
+
 			// pbrMetallicRoughness.metallicRoughnessTexture
 			// pbrMetallicRoughness.metallicRoughnessTexture
 			if ( material.metalnessMap || material.roughnessMap ) {
 			if ( material.metalnessMap || material.roughnessMap ) {
 
 
@@ -988,12 +1011,28 @@ GLTFExporter.prototype = {
 
 
 			}
 			}
 
 
-			// pbrMetallicRoughness.baseColorTexture
+			// pbrMetallicRoughness.baseColorTexture or pbrSpecularGlossiness diffuseTexture
 			if ( material.map ) {
 			if ( material.map ) {
 
 
 				var baseColorMapDef = { index: processTexture( material.map ) };
 				var baseColorMapDef = { index: processTexture( material.map ) };
 				applyTextureTransform( baseColorMapDef, material.map );
 				applyTextureTransform( baseColorMapDef, material.map );
+
+				if ( material.isGLTFSpecularGlossinessMaterial ) {
+
+					gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness.diffuseTexture = baseColorMapDef;
+
+				}
+
 				gltfMaterial.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
 				gltfMaterial.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
+				
+			}
+
+			// pbrSpecularGlossiness specular map
+			if ( material.isGLTFSpecularGlossinessMaterial && material.specularMap ) {
+
+				var specularMapDef = { index: processTexture( material.specularMap ) };
+				applyTextureTransform( specularMapDef, material.specularMap );
+				gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness.specularGlossinessTexture = specularMapDef;
 
 
 			}
 			}
 
 
@@ -1028,7 +1067,7 @@ GLTFExporter.prototype = {
 
 
 				var normalMapDef = { index: processTexture( material.normalMap ) };
 				var normalMapDef = { index: processTexture( material.normalMap ) };
 
 
-				if ( material.normalScale.x !== - 1 ) {
+				if ( material.normalScale && material.normalScale.x !== - 1 ) {
 
 
 					if ( material.normalScale.x !== material.normalScale.y ) {
 					if ( material.normalScale.x !== material.normalScale.y ) {
 
 

+ 1 - 1
examples/jsm/loaders/STLLoader.js

@@ -44,7 +44,7 @@
  *
  *
  *  for (var i = 0; i < nGeometryGroups; i++) {
  *  for (var i = 0; i < nGeometryGroups; i++) {
  *
  *
- *		var material = new THREE.MeshStandardMaterial({
+ *		var material = new THREE.MeshPhongMaterial({
  *			color: colorMap[i],
  *			color: colorMap[i],
  *			wireframe: false
  *			wireframe: false
  *		});
  *		});