2
0
Mr.doob 4 жил өмнө
parent
commit
5820a00a2d

+ 2 - 10
examples/js/loaders/FBXLoader.js

@@ -2119,16 +2119,8 @@
 			}
 
 			const curve = new THREE.NURBSCurve( degree, knots, controlPoints, startKnot, endKnot );
-			const vertices = curve.getPoints( controlPoints.length * 7 );
-			const positions = new Float32Array( vertices.length * 3 );
-			vertices.forEach( function ( vertex, i ) {
-
-				vertex.toArray( positions, i * 3 );
-
-			} );
-			const geometry = new THREE.BufferGeometry();
-			geometry.setAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
-			return geometry;
+			const points = curve.getPoints( controlPoints.length * 12 );
+			return new THREE.BufferGeometry().setFromPoints( points );
 
 		}
 

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

@@ -38,6 +38,11 @@
 
 				return new GLTFMaterialsIorExtension( parser );
 
+			} );
+			this.register( function ( parser ) {
+
+				return new GLTFMaterialsSpecularExtension( parser );
+
 			} );
 			this.register( function ( parser ) {
 
@@ -331,6 +336,7 @@
 		KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
 		KHR_MATERIALS_IOR: 'KHR_materials_ior',
 		KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
+		KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
 		KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
 		KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
 		KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
@@ -741,6 +747,70 @@
 
 		}
 
+	}
+	/**
+ * Materials specular Extension
+ *
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
+ */
+
+
+	class GLTFMaterialsSpecularExtension {
+
+		constructor( parser ) {
+
+			this.parser = parser;
+			this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
+
+		}
+
+		getMaterialType( materialIndex ) {
+
+			const parser = this.parser;
+			const materialDef = parser.json.materials[ materialIndex ];
+			if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
+			return THREE.MeshPhysicalMaterial;
+
+		}
+
+		extendMaterialParams( materialIndex, materialParams ) {
+
+			const parser = this.parser;
+			const materialDef = parser.json.materials[ materialIndex ];
+
+			if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
+
+				return Promise.resolve();
+
+			}
+
+			const pending = [];
+			const extension = materialDef.extensions[ this.name ];
+			materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
+
+			if ( extension.specularTexture !== undefined ) {
+
+				pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
+
+			}
+
+			const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
+			materialParams.specularTint = new THREE.Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
+
+			if ( extension.specularColorTexture !== undefined ) {
+
+				pending.push( parser.assignTexture( materialParams, 'specularTintMap', extension.specularColorTexture ).then( function ( texture ) {
+
+					texture.encoding = THREE.sRGBEncoding;
+
+				} ) );
+
+			}
+
+			return Promise.all( pending );
+
+		}
+
 	}
 	/**
  * BasisU THREE.Texture Extension
@@ -2501,7 +2571,7 @@
    * @param {Object} materialParams
    * @param {string} mapName
    * @param {Object} mapDef
-   * @return {Promise}
+   * @return {Promise<Texture>}
    */
 
 
@@ -2533,6 +2603,7 @@
 				}
 
 				materialParams[ mapName ] = texture;
+				return texture;
 
 			} );