Ver Fonte

Updated examples builds.

Mr.doob há 4 anos atrás
pai
commit
9d77e99f37
2 ficheiros alterados com 95 adições e 1 exclusões
  1. 94 0
      examples/js/exporters/GLTFExporter.js
  2. 1 1
      examples/js/loaders/GLTFLoader.js

+ 94 - 0
examples/js/exporters/GLTFExporter.js

@@ -20,6 +20,16 @@
 				return new GLTFMaterialsPBRSpecularGlossiness( writer );
 
 			} );
+			this.register( function ( writer ) {
+
+				return new GLTFMaterialsTransmissionExtension( writer );
+
+			} );
+			this.register( function ( writer ) {
+
+				return new GLTFMaterialsVolumeExtension( writer );
+
+			} );
 
 		}
 
@@ -2056,6 +2066,90 @@
 
 		}
 
+	}
+	/**
+ * Transmission Materials Extension
+ *
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
+ */
+
+
+	class GLTFMaterialsTransmissionExtension {
+
+		constructor( writer ) {
+
+			this.writer = writer;
+			this.name = 'KHR_materials_transmission';
+
+		}
+
+		writeMaterial( material, materialDef ) {
+
+			if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
+			const writer = this.writer;
+			const extensionsUsed = writer.extensionsUsed;
+			const extensionDef = {};
+			extensionDef.transmissionFactor = material.transmission;
+
+			if ( material.transmissionMap ) {
+
+				const transmissionMapDef = {
+					index: writer.processTexture( material.transmissionMap )
+				};
+				writer.applyTextureTransform( transmissionMapDef, material.transmissionMap );
+				extensionDef.transmissionTexture = transmissionMapDef;
+
+			}
+
+			materialDef.extensions = materialDef.extensions || {};
+			materialDef.extensions[ this.name ] = extensionDef;
+			extensionsUsed[ this.name ] = true;
+
+		}
+
+	}
+	/**
+ * Materials Volume Extension
+ *
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
+ */
+
+
+	class GLTFMaterialsVolumeExtension {
+
+		constructor( writer ) {
+
+			this.writer = writer;
+			this.name = 'KHR_materials_volume';
+
+		}
+
+		writeMaterial( material, materialDef ) {
+
+			if ( ! material.isMeshPhysicalMaterial || material.thickness === 0 ) return;
+			const writer = this.writer;
+			const extensionsUsed = writer.extensionsUsed;
+			const extensionDef = {};
+			extensionDef.thicknessFactor = material.thickness;
+
+			if ( material.thicknessMap ) {
+
+				const thicknessMapDef = {
+					index: writer.processTexture( material.thicknessMap )
+				};
+				writer.applyTextureTransform( thicknessMapDef, material.thicknessMap );
+				extensionDef.thicknessTexture = thicknessMapDef;
+
+			}
+
+			extensionDef.attenuationDistance = material.attenuationDistance;
+			extensionDef.attenuationColor = material.attenuationTint.toArray();
+			materialDef.extensions = materialDef.extensions || {};
+			materialDef.extensions[ this.name ] = extensionDef;
+			extensionsUsed[ this.name ] = true;
+
+		}
+
 	}
 	/**
  * Static utility functions

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

@@ -699,7 +699,7 @@
 
 			materialParams.attenuationDistance = extension.attenuationDistance || 0;
 			const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
-			materialParams.attenuationColor = new THREE.Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
+			materialParams.attenuationTint = new THREE.Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
 			return Promise.all( pending );
 
 		}