Browse Source

Updated examples builds.

Mr.doob 3 years ago
parent
commit
d1b2086c1e

+ 1 - 1
examples/js/animation/MMDPhysics.js

@@ -821,7 +821,7 @@
 						return new Ammo.btCapsuleShape( p.width, p.height );
 
 					default:
-						throw 'unknown shape type ' + p.shapeType;
+						throw new Error( 'unknown shape type ' + p.shapeType );
 
 				}
 

+ 1 - 1
examples/js/exporters/MMDExporter.js

@@ -161,7 +161,7 @@
 
 			if ( value === undefined ) {
 
-				throw 'cannot convert charcode 0x' + code.toString( 16 );
+				throw new Error( 'cannot convert charcode 0x' + code.toString( 16 ) );
 
 			} else if ( value > 0xff ) {
 

+ 1 - 0
examples/js/loaders/BasisTextureLoader.js

@@ -28,6 +28,7 @@
 			this.workerNextTaskID = 1;
 			this.workerSourceURL = '';
 			this.workerConfig = null;
+			console.warn( 'THREE.BasisTextureLoader: This loader is deprecated, and will be removed in a future release. ' + 'Instead, use Basis Universal compression in KTX2 (.ktx2) files with THREE.KTX2Loader.' );
 
 		}
 

+ 25 - 19
examples/js/loaders/EXRLoader.js

@@ -210,7 +210,7 @@
 
 						if ( p.value - inOffset.value > ni ) {
 
-							throw 'Something wrong with hufUnpackEncTable';
+							throw new Error( 'Something wrong with hufUnpackEncTable' );
 
 						}
 
@@ -221,7 +221,7 @@
 
 						if ( im + zerun > iM + 1 ) {
 
-							throw 'Something wrong with hufUnpackEncTable';
+							throw new Error( 'Something wrong with hufUnpackEncTable' );
 
 						}
 
@@ -235,7 +235,7 @@
 
 						if ( im + zerun > iM + 1 ) {
 
-							throw 'Something wrong with hufUnpackEncTable';
+							throw new Error( 'Something wrong with hufUnpackEncTable' );
 
 						}
 
@@ -272,7 +272,7 @@
 
 					if ( c >> l ) {
 
-						throw 'Invalid table entry';
+						throw new Error( 'Invalid table entry' );
 
 					}
 
@@ -282,7 +282,7 @@
 
 						if ( pl.len ) {
 
-							throw 'Invalid table entry';
+							throw new Error( 'Invalid table entry' );
 
 						}
 
@@ -317,7 +317,7 @@
 
 							if ( pl.len || pl.p ) {
 
-								throw 'Invalid table entry';
+								throw new Error( 'Invalid table entry' );
 
 							}
 
@@ -576,7 +576,7 @@
 
 							if ( ! pl.p ) {
 
-								throw 'hufDecode issues';
+								throw new Error( 'hufDecode issues' );
 
 							}
 
@@ -612,7 +612,7 @@
 
 							if ( j == pl.lit ) {
 
-								throw 'hufDecode issues';
+								throw new Error( 'hufDecode issues' );
 
 							}
 
@@ -639,7 +639,7 @@
 
 					} else {
 
-						throw 'hufDecode issues';
+						throw new Error( 'hufDecode issues' );
 
 					}
 
@@ -663,7 +663,7 @@
 
 				if ( im < 0 || im >= HUF_ENCSIZE || iM < 0 || iM >= HUF_ENCSIZE ) {
 
-					throw 'Something wrong with HUF_ENCSIZE';
+					throw new Error( 'Something wrong with HUF_ENCSIZE' );
 
 				}
 
@@ -675,7 +675,7 @@
 
 				if ( nBits > 8 * ( nCompressed - ( inOffset.value - initialInOffset ) ) ) {
 
-					throw 'Something wrong with hufUncompress';
+					throw new Error( 'Something wrong with hufUncompress' );
 
 				}
 
@@ -1198,7 +1198,7 @@
 
 				if ( maxNonZero >= BITMAP_SIZE ) {
 
-					throw 'Something is wrong with PIZ_COMPRESSION BITMAP_SIZE';
+					throw new Error( 'Something is wrong with PIZ_COMPRESSION BITMAP_SIZE' );
 
 				}
 
@@ -1346,7 +1346,7 @@
 					totalDcUncompressedCount: parseInt64( inDataView, inOffset ),
 					acCompression: parseInt64( inDataView, inOffset )
 				};
-				if ( dwaHeader.version < 2 ) throw 'EXRLoader.parse: ' + EXRHeader.compression + ' version ' + dwaHeader.version + ' is unsupported'; // Read channel ruleset information
+				if ( dwaHeader.version < 2 ) throw new Error( 'EXRLoader.parse: ' + EXRHeader.compression + ' version ' + dwaHeader.version + ' is unsupported' ); // Read channel ruleset information
 
 				var channelRules = new Array();
 				var ruleSize = parseUint16( inDataView, inOffset ) - INT16_SIZE;
@@ -1523,7 +1523,7 @@
 						case LOSSY_DCT: // skip
 
 						default:
-							throw 'EXRLoader.parse: unsupported channel compression';
+							throw new Error( 'EXRLoader.parse: unsupported channel compression' );
 
 					}
 
@@ -1818,8 +1818,14 @@
 			function parseHeader( dataView, buffer, offset ) {
 
 				const EXRHeader = {};
-				if ( dataView.getUint32( 0, true ) != 20000630 ) // magic
-					throw 'THREE.EXRLoader: provided file doesn\'t appear to be in OpenEXR format.';
+
+				if ( dataView.getUint32( 0, true ) != 20000630 ) {
+
+					// magic
+					throw new Error( 'THREE.EXRLoader: provided file doesn\'t appear to be in OpenEXR format.' );
+
+				}
+
 				EXRHeader.version = dataView.getUint8( 4, true );
 				const spec = dataView.getUint8( 5, true ); // fullMask
 
@@ -1865,7 +1871,7 @@
 				if ( spec != 0 ) {
 
 					console.error( 'EXRHeader:', EXRHeader );
-					throw 'THREE.EXRLoader: provided file is currently unsupported.';
+					throw new Error( 'THREE.EXRLoader: provided file is currently unsupported.' );
 
 				}
 
@@ -1936,7 +1942,7 @@
 						break;
 
 					default:
-						throw 'EXRLoader.parse: ' + EXRHeader.compression + ' is unsupported';
+						throw new Error( 'EXRLoader.parse: ' + EXRHeader.compression + ' is unsupported' );
 
 				}
 
@@ -1977,7 +1983,7 @@
 
 				} else {
 
-					throw 'EXRLoader.parse: unsupported pixelType ' + EXRDecoder.type + ' for ' + EXRHeader.compression + '.';
+					throw new Error( 'EXRLoader.parse: unsupported pixelType ' + EXRDecoder.type + ' for ' + EXRHeader.compression + '.' );
 
 				}
 

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

@@ -1329,7 +1329,7 @@
 
 			const specularMapParsFragmentChunk = [ '#ifdef USE_SPECULARMAP', '	uniform sampler2D specularMap;', '#endif' ].join( '\n' );
 			const glossinessMapParsFragmentChunk = [ '#ifdef USE_GLOSSINESSMAP', '	uniform sampler2D glossinessMap;', '#endif' ].join( '\n' );
-			const specularMapFragmentChunk = [ 'vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', '	vec4 texelSpecular = texture2D( specularMap, vUv );', '	texelSpecular = sRGBToLinear( texelSpecular );', '	// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', '	specularFactor *= texelSpecular.rgb;', '#endif' ].join( '\n' );
+			const specularMapFragmentChunk = [ 'vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', '	vec4 texelSpecular = texture2D( specularMap, vUv );', '	// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', '	specularFactor *= texelSpecular.rgb;', '#endif' ].join( '\n' );
 			const glossinessMapFragmentChunk = [ 'float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', '	vec4 texelGlossiness = texture2D( glossinessMap, vUv );', '	// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', '	glossinessFactor *= texelGlossiness.a;', '#endif' ].join( '\n' );
 			const lightPhysicalFragmentChunk = [ 'PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;' ].join( '\n' );
 			const uniforms = {

+ 69 - 56
examples/js/loaders/LDrawLoader.js

@@ -142,6 +142,26 @@
 
 	}
 
+	function generateFaceNormals( faces ) {
+
+		for ( let i = 0, l = faces.length; i < l; i ++ ) {
+
+			const face = faces[ i ];
+			const vertices = face.vertices;
+			const v0 = vertices[ 0 ];
+			const v1 = vertices[ 1 ];
+			const v2 = vertices[ 2 ];
+
+			_tempVec0.subVectors( v1, v0 );
+
+			_tempVec1.subVectors( v2, v1 );
+
+			face.faceNormal = new THREE.Vector3().crossVectors( _tempVec0, _tempVec1 ).normalize();
+
+		}
+
+	}
+
 	function smoothNormals( faces, lineSegments ) {
 
 		function hashVertex( v ) {
@@ -635,10 +655,25 @@
 				positions[ index + 1 ] = v.y;
 				positions[ index + 2 ] = v.z;
 
-			}
+			} // create the normals array if this is a set of faces
+
 
 			if ( elementSize === 3 ) {
 
+				if ( ! elem.faceNormal ) {
+
+					const v0 = vertices[ 0 ];
+					const v1 = vertices[ 1 ];
+					const v2 = vertices[ 2 ];
+
+					_tempVec0.subVectors( v1, v0 );
+
+					_tempVec1.subVectors( v2, v1 );
+
+					elem.faceNormal = new THREE.Vector3().crossVectors( _tempVec0, _tempVec1 ).normalize();
+
+				}
+
 				let elemNormals = elem.normals;
 
 				if ( elemNormals.length === 4 ) {
@@ -655,6 +690,7 @@
 
 				for ( let j = 0, l = elemNormals.length; j < l; j ++ ) {
 
+					// use face normal if a vertex normal is not provided
 					let n = elem.faceNormal;
 
 					if ( elemNormals[ j ] ) {
@@ -781,7 +817,7 @@
 
 			this.cache = new LDrawFileCache( this ); // This object is a map from file names to paths. It agilizes the paths search. If it is not set then files will be searched by trial and error.
 
-			this.fileMap = null;
+			this.fileMap = {};
 			this.rootParseScope = this.newParseScopeLevel(); // Add default main triangle and line edge materials (used in pieces that can be coloured with a main color)
 
 			this.setMaterials( [ this.parseColourMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ), this.parseColourMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) ] ); // If this flag is set to true, each subobject will be a Object.
@@ -833,12 +869,6 @@
 
 		load( url, onLoad, onProgress, onError ) {
 
-			if ( ! this.fileMap ) {
-
-				this.fileMap = {};
-
-			}
-
 			const fileLoader = new THREE.FileLoader( this.manager );
 			fileLoader.setPath( this.path );
 			fileLoader.setRequestHeader( this.requestHeader );
@@ -997,7 +1027,7 @@
 
 			if ( ! name ) {
 
-				throw 'LDrawLoader: Material name was expected after "!COLOUR tag' + lineParser.getLineNumberString() + '.';
+				throw new Error( 'LDrawLoader: Material name was expected after "!COLOUR tag' + lineParser.getLineNumberString() + '.' );
 
 			} // Parse tag tokens and their parameters
 
@@ -1029,7 +1059,7 @@
 
 						} else if ( ! colour.startsWith( '#' ) ) {
 
-							throw 'LDrawLoader: Invalid colour while parsing material' + lineParser.getLineNumberString() + '.';
+							throw new Error( 'LDrawLoader: Invalid colour while parsing material' + lineParser.getLineNumberString() + '.' );
 
 						}
 
@@ -1049,7 +1079,7 @@
 
 							if ( ! edgeMaterial ) {
 
-								throw 'LDrawLoader: Invalid edge colour while parsing material' + lineParser.getLineNumberString() + '.';
+								throw new Error( 'LDrawLoader: Invalid edge colour while parsing material' + lineParser.getLineNumberString() + '.' );
 
 							} // Get the edge material for this triangle material
 
@@ -1065,7 +1095,7 @@
 
 						if ( isNaN( alpha ) ) {
 
-							throw 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + '.';
+							throw new Error( 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + '.' );
 
 						}
 
@@ -1084,7 +1114,7 @@
 
 						if ( isNaN( luminance ) ) {
 
-							throw 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + '.';
+							throw new Error( 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + '.' );
 
 						}
 
@@ -1117,8 +1147,7 @@
 						break;
 
 					default:
-						throw 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + '.';
-						break;
+						throw new Error( 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + '.' );
 
 				}
 
@@ -1264,9 +1293,8 @@
 			let bfcCull = true;
 			let type = '';
 			let startingConstructionStep = false;
-			const scope = this;
 
-			function parseColourCode( lineParser, forEdge ) {
+			const parseColourCode = ( lineParser, forEdge ) => {
 
 				// Parses next colour code and returns a THREE.Material
 				let colourCode = lineParser.getToken();
@@ -1283,23 +1311,23 @@
 
 				}
 
-				const material = scope.getMaterial( colourCode, currentParseScope );
+				const material = this.getMaterial( colourCode, currentParseScope );
 
 				if ( ! material ) {
 
-					throw 'LDrawLoader: Unknown colour code "' + colourCode + '" is used' + lineParser.getLineNumberString() + ' but it was not defined previously.';
+					throw new Error( 'LDrawLoader: Unknown colour code "' + colourCode + '" is used' + lineParser.getLineNumberString() + ' but it was not defined previously.' );
 
 				}
 
 				return material;
 
-			}
+			};
 
-			function parseVector( lp ) {
+			const parseVector = lp => {
 
 				const v = new THREE.Vector3( parseFloat( lp.getToken() ), parseFloat( lp.getToken() ), parseFloat( lp.getToken() ) );
 
-				if ( ! scope.separateObjects ) {
+				if ( ! this.separateObjects ) {
 
 					v.applyMatrix4( currentParseScope.currentMatrix );
 
@@ -1307,7 +1335,7 @@
 
 				return v;
 
-			} // Parse all line commands
+			}; // Parse all line commands
 
 
 			for ( let lineIndex = 0; lineIndex < numLines; lineIndex ++ ) {
@@ -1352,7 +1380,7 @@
 				let inverted;
 				let ccw;
 				let doubleSided;
-				let v0, v1, v2, v3, c0, c1, faceNormal;
+				let v0, v1, v2, v3, c0, c1;
 
 				switch ( lineType ) {
 
@@ -1370,7 +1398,7 @@
 									currentParseScope.type = type; // If the scale of the object is negated then the triangle winding order
 									// needs to be flipped.
 
-									if ( currentParseScope.matrix.determinant() < 0 && ( scope.separateObjects && isPrimitiveType( type ) || ! scope.separateObjects ) ) {
+									if ( currentParseScope.matrix.determinant() < 0 && ( this.separateObjects && isPrimitiveType( type ) || ! this.separateObjects ) ) {
 
 										currentParseScope.inverted = ! currentParseScope.inverted;
 
@@ -1505,10 +1533,10 @@
 						const matrix = new THREE.Matrix4().set( m0, m1, m2, posX, m3, m4, m5, posY, m6, m7, m8, posZ, 0, 0, 0, 1 );
 						let fileName = lp.getRemainingString().trim().replace( /\\/g, '/' );
 
-						if ( scope.fileMap[ fileName ] ) {
+						if ( this.fileMap[ fileName ] ) {
 
 							// Found the subobject path in the preloaded file path map
-							fileName = scope.fileMap[ fileName ];
+							fileName = this.fileMap[ fileName ];
 
 						} else {
 
@@ -1587,15 +1615,10 @@
 
 						}
 
-						_tempVec0.subVectors( v1, v0 );
-
-						_tempVec1.subVectors( v2, v1 );
-
-						faceNormal = new THREE.Vector3().crossVectors( _tempVec0, _tempVec1 ).normalize();
 						faces.push( {
 							material: material,
 							colourCode: material.userData.code,
-							faceNormal: faceNormal,
+							faceNormal: null,
 							vertices: [ v0, v1, v2 ],
 							normals: [ null, null, null ]
 						} );
@@ -1606,7 +1629,7 @@
 							faces.push( {
 								material: material,
 								colourCode: material.userData.code,
-								faceNormal: faceNormal,
+								faceNormal: null,
 								vertices: [ v2, v1, v0 ],
 								normals: [ null, null, null ]
 							} );
@@ -1637,19 +1660,14 @@
 							v1 = parseVector( lp );
 							v0 = parseVector( lp );
 
-						}
-
-						_tempVec0.subVectors( v1, v0 );
-
-						_tempVec1.subVectors( v2, v1 );
-
-						faceNormal = new THREE.Vector3().crossVectors( _tempVec0, _tempVec1 ).normalize(); // specifically place the triangle diagonal in the v0 and v1 slots so we can
+						} // specifically place the triangle diagonal in the v0 and v1 slots so we can
 						// account for the doubling of vertices later when smoothing normals.
 
+
 						faces.push( {
 							material: material,
 							colourCode: material.userData.code,
-							faceNormal: faceNormal,
+							faceNormal: null,
 							vertices: [ v0, v1, v2, v3 ],
 							normals: [ null, null, null, null ]
 						} );
@@ -1660,7 +1678,7 @@
 							faces.push( {
 								material: material,
 								colourCode: material.userData.code,
-								faceNormal: faceNormal,
+								faceNormal: null,
 								vertices: [ v3, v2, v1, v0 ],
 								normals: [ null, null, null, null ]
 							} );
@@ -1671,8 +1689,7 @@
 						break;
 
 					default:
-						throw 'LDrawLoader: Unknown line type "' + lineType + '"' + lp.getLineNumberString() + '.';
-						break;
+						throw new Error( 'LDrawLoader: Unknown line type "' + lineType + '"' + lp.getLineNumberString() + '.' );
 
 				}
 
@@ -1691,7 +1708,7 @@
 			currentParseScope.subobjectIndex = 0;
 			const isRoot = ! parentParseScope.isFromParse;
 
-			if ( isRoot || scope.separateObjects && ! isPrimitiveType( type ) ) {
+			if ( isRoot || this.separateObjects && ! isPrimitiveType( type ) ) {
 
 				currentParseScope.groupObject = new THREE.Group();
 				currentParseScope.groupObject.userData.startingConstructionStep = currentParseScope.startingConstructionStep;
@@ -1736,10 +1753,11 @@
 			// is added directly into the parent model (meaning it will never get smoothed by
 			// being added to a part)
 
-			const doSmooth = isPartType( subobjectParseScope.type ) || ! isPartType( subobjectParseScope.type ) && ! isModelType( subobjectParseScope.type ) && isModelType( subobjectParseScope.parentScope.type );
+			const doSmooth = isPartType( subobjectParseScope.type ) || isPrimitiveType( subobjectParseScope.type ) && isModelType( subobjectParseScope.parentScope.type );
 
 			if ( this.smoothNormals && doSmooth ) {
 
+				generateFaceNormals( subobjectParseScope.faces );
 				smoothNormals( subobjectParseScope.faces, subobjectParseScope.lineSegments );
 
 			}
@@ -1833,16 +1851,10 @@
 
 						for ( let i = 0, l = vertices.length; i < l; i ++ ) {
 
-							vertices[ i ] = vertices[ i ].clone().applyMatrix4( subobjectParseScope.matrix );
+							vertices[ i ].applyMatrix4( subobjectParseScope.matrix );
 
 						}
 
-						_tempVec0.subVectors( vertices[ 1 ], vertices[ 0 ] );
-
-						_tempVec1.subVectors( vertices[ 2 ], vertices[ 1 ] );
-
-						tri.faceNormal.crossVectors( _tempVec0, _tempVec1 ).normalize();
-
 					}
 
 					parentFaces.push( tri );
@@ -1911,9 +1923,10 @@
 
 					return scope.processObject( text, subobject, url, parseScope );
 
-				} ).catch( function () {
+				} ).catch( function ( err ) {
 
-					console.warn( 'LDrawLoader: Subobject "' + subobject.fileName + '" could not be found.' );
+					console.warn( 'LDrawLoader: Subobject "' + subobject.fileName + '" could not be loaded.' );
+					console.warn( err );
 					return null;
 
 				} );

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

@@ -393,7 +393,7 @@
 
 		var mgck = [ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a ];
 
-		for ( var i = 0; i < 8; i ++ ) if ( data[ i ] != mgck[ i ] ) throw 'The input is not a PNG file!';
+		for ( var i = 0; i < 8; i ++ ) if ( data[ i ] != mgck[ i ] ) throw new Error( 'The input is not a PNG file!' );
 
 		while ( offset < data.length ) {
 

+ 2 - 2
examples/js/misc/Volume.js

@@ -104,7 +104,7 @@
 				case 'unsigned long long int':
 				case 'uint64':
 				case 'uint64_t':
-					throw 'Error in Volume constructor : this type is not supported in JavaScript';
+					throw new Error( 'Error in Volume constructor : this type is not supported in JavaScript' );
 					break;
 
 				case 'Float32':
@@ -126,7 +126,7 @@
 
 			if ( this.data.length !== this.xLength * this.yLength * this.zLength ) {
 
-				throw 'Error in Volume constructor, lengths are not matching arrayBuffer size';
+				throw new Error( 'Error in Volume constructor, lengths are not matching arrayBuffer size' );
 
 			}
 

+ 1 - 1
examples/js/modifiers/EdgeSplitModifier.js

@@ -168,7 +168,7 @@
 
 				if ( THREE.BufferGeometryUtils === undefined ) {
 
-					throw 'THREE.EdgeSplitModifier relies on THREE.BufferGeometryUtils';
+					throw new Error( 'THREE.EdgeSplitModifier relies on THREE.BufferGeometryUtils' );
 
 				}
 

+ 1 - 1
examples/js/modifiers/SimplifyModifier.js

@@ -17,7 +17,7 @@
 
 			if ( THREE.BufferGeometryUtils === undefined ) {
 
-				throw 'THREE.SimplifyModifier relies on THREE.BufferGeometryUtils';
+				throw new Error( 'THREE.SimplifyModifier relies on THREE.BufferGeometryUtils' );
 
 			}
 

+ 0 - 2
examples/js/utils/RoughnessMipmapper.js

@@ -166,8 +166,6 @@
 
 			#define ENVMAP_TYPE_CUBE_UV
 
-			vec4 envMapTexelToLinear( vec4 a ) { return a; }
-
 			#include <cube_uv_reflection_fragment>
 
 			float roughnessToVariance( float roughness ) {