소스 검색

#11200

Code related changes:
- Validator and its functions replace all Boolean calls. It is included in THREE.OBJLoader2.
- Versions are now defined inside OBJLoader2 and WWOBJLoader2.
- Static OBJLoader2._getValidator and OBJLoader2_buildWebWorkerCode are reached via prototype of OBJLoader2. Instance of OBJLoader2 is no longer created.

Bugfix in webgl_loader_obj2_ww_parallels:
- Fixed "Run Queue" started new run before first was completed.
- Replaced Boolean with Validator
Kai Salmen 8 년 전
부모
커밋
459baa02d7
4개의 변경된 파일154개의 추가작업 그리고 87개의 파일을 삭제
  1. 46 15
      examples/js/loaders/OBJLoader2.js
  2. 87 68
      examples/js/loaders/WWOBJLoader2.js
  3. 4 2
      examples/webgl_loader_obj2_ww.html
  4. 17 2
      examples/webgl_loader_obj2_ww_parallels.html

+ 46 - 15
examples/js/loaders/OBJLoader2.js

@@ -6,7 +6,6 @@
 'use strict';
 
 if ( THREE.OBJLoader2 === undefined ) { THREE.OBJLoader2 = {} }
-THREE.OBJLoader2.version = '1.2.1';
 
 /**
  * Use this class to load OBJ data from files or to parse OBJ data from arraybuffer or text
@@ -16,8 +15,11 @@ THREE.OBJLoader2.version = '1.2.1';
  */
 THREE.OBJLoader2 = (function () {
 
+	var OBJLOADER2_VERSION = '1.2.1';
+
 	function OBJLoader2( manager ) {
-		this.manager = ! Boolean( manager ) ? THREE.DefaultLoadingManager : manager;
+		console.log( "Using THREE.OBJLoader2 version: " + OBJLOADER2_VERSION );
+		this.manager = Validator.verifyInput( manager, THREE.DefaultLoadingManager );
 
 		this.path = '';
 		this.fileLoader = new THREE.FileLoader( this.manager );
@@ -35,7 +37,7 @@ THREE.OBJLoader2 = (function () {
 	 * @param {string} path The basepath
 	 */
 	OBJLoader2.prototype.setPath = function ( path ) {
-		this.path = Boolean( path ) ? path : this.path;
+		this.path = Validator.verifyInput( path, this.path );
 	};
 
 	/**
@@ -83,13 +85,13 @@ THREE.OBJLoader2 = (function () {
 	OBJLoader2.prototype.load = function ( url, onLoad, onProgress, onError, useArrayBuffer ) {
 		this._validate();
 		this.fileLoader.setPath( this.path );
-		this.fileLoader.setResponseType( ( useArrayBuffer || useArrayBuffer === null || useArrayBuffer === undefined ) ? 'arraybuffer' : 'text' );
+		this.fileLoader.setResponseType( useArrayBuffer !== false ? 'arraybuffer' : 'text' );
 
 		var scope = this;
 		scope.fileLoader.load( url, function ( content ) {
 
 			// only use parseText if useArrayBuffer is explicitly set to false
-			onLoad( ( useArrayBuffer || useArrayBuffer === null || useArrayBuffer === undefined ) ? scope.parse( content ) : scope.parseText( content ) );
+			onLoad( useArrayBuffer !== false ? scope.parse( content ) : scope.parseText( content ) );
 
 		}, onProgress, onError );
 	};
@@ -147,7 +149,7 @@ THREE.OBJLoader2 = (function () {
 	OBJLoader2.prototype._validate = function () {
 		if ( this.validated ) return;
 
-		this.fileLoader = Boolean( this.fileLoader ) ? this.fileLoader : new THREE.FileLoader( this.manager );
+		this.fileLoader = Validator.verifyInput( this.fileLoader, new THREE.FileLoader( this.manager ) );
 		this.parser.validate();
 		this.meshCreator.validate();
 
@@ -206,6 +208,32 @@ THREE.OBJLoader2 = (function () {
 		QUAD_INDICES_3: [ 1, 4, 7, 7, 10, 1 ]
 	};
 
+	var Validator = {
+		/**
+		 * If given input is null or undefined, false is returned otherwise true.
+		 *
+		 * @param input Anything
+		 * @returns {boolean}
+		 */
+		isValid: function( input ) {
+			return ( input !== null && input !== undefined );
+		},
+		/**
+		 * If given input is null or undefined, the defaultValue is returned otherwise the given input.
+		 *
+		 * @param input Anything
+		 * @param defaultValue Anything
+		 * @returns {*}
+		 */
+		verifyInput: function( input, defaultValue ) {
+			return ( input === null || input === undefined ) ? defaultValue : input;
+		}
+	};
+
+	OBJLoader2.prototype._getValidator = function () {
+		return Validator;
+	};
+
 	/**
 	 * Parse OBJ data either from ArrayBuffer or string
 	 * @class
@@ -220,7 +248,7 @@ THREE.OBJLoader2 = (function () {
 		}
 
 		Parser.prototype.setDebug = function ( debug ) {
-			this.debug = Boolean( debug ) ? debug : this.debug;
+			if ( debug === true || debug === false ) this.debug = debug;
 		};
 
 		Parser.prototype.validate = function () {
@@ -486,9 +514,9 @@ THREE.OBJLoader2 = (function () {
 			this.uvs = [];
 
 			// faces are stored according combined index of group, material and smoothingGroup (0 or not)
-			this.mtllibName = Boolean( mtllibName ) ? mtllibName : 'none';
-			this.objectName = Boolean( objectName ) ? objectName : 'none';
-			this.groupName = Boolean( groupName ) ? groupName : 'none';
+			this.mtllibName = Validator.verifyInput( mtllibName, 'none' );
+			this.objectName = Validator.verifyInput( objectName, 'none' );
+			this.groupName = Validator.verifyInput( groupName, 'none' );
 			this.activeMtlName = 'none';
 			this.activeSmoothingGroup = 1;
 
@@ -562,7 +590,7 @@ THREE.OBJLoader2 = (function () {
 		};
 
 		RawObject.prototype.pushUsemtl = function ( mtlName ) {
-			if ( this.activeMtlName === mtlName || mtlName === null || mtlName === undefined ) return;
+			if ( this.activeMtlName === mtlName || ! Validator.isValid( mtlName ) ) return;
 			this.activeMtlName = mtlName;
 			this.mtlCount++;
 
@@ -581,7 +609,7 @@ THREE.OBJLoader2 = (function () {
 		RawObject.prototype.verifyIndex = function () {
 			var index = this.buildIndex( this.activeMtlName, ( this.activeSmoothingGroup === 0 ) ? 0 : 1 );
 			this.rawObjectDescriptionInUse = this.rawObjectDescriptions[ index ];
-			if ( ! Boolean( this.rawObjectDescriptionInUse ) ) {
+			if ( ! Validator.isValid( this.rawObjectDescriptionInUse ) ) {
 
 				this.rawObjectDescriptionInUse = new RawObjectDescription( this.objectName, this.groupName, this.activeMtlName, this.activeSmoothingGroup );
 				this.rawObjectDescriptions[ index ] = this.rawObjectDescriptionInUse;
@@ -809,15 +837,17 @@ THREE.OBJLoader2 = (function () {
 		}
 
 		MeshCreator.prototype.setSceneGraphBaseNode = function ( sceneGraphBaseNode ) {
-			this.sceneGraphBaseNode = Boolean( sceneGraphBaseNode ) ? sceneGraphBaseNode : ( Boolean( this.sceneGraphBaseNode ) ? this.sceneGraphBaseNode : new THREE.Group() );
+			this.sceneGraphBaseNode = Validator.verifyInput( sceneGraphBaseNode, this.sceneGraphBaseNode );
+			this.sceneGraphBaseNode = Validator.verifyInput( this.sceneGraphBaseNode, new THREE.Group() );
 		};
 
 		MeshCreator.prototype.setMaterials = function ( materials ) {
-			this.materials = Boolean( materials ) ? materials : ( Boolean( this.materials ) ? this.materials : { materials: [] } );
+			this.materials = Validator.verifyInput( materials, this.materials );
+			this.materials = Validator.verifyInput( this.materials, { materials: [] } );
 		};
 
 		MeshCreator.prototype.setDebug = function ( debug ) {
-			this.debug = Boolean( debug ) ? debug : this.debug;
+			if ( debug === true || debug === false ) this.debug = debug;
 		};
 
 		MeshCreator.prototype.validate = function () {
@@ -986,6 +1016,7 @@ THREE.OBJLoader2 = (function () {
 	OBJLoader2.prototype._buildWebWorkerCode = function ( funcBuildObject, funcBuildSingelton ) {
 		var workerCode = '';
 		workerCode += funcBuildObject( 'Consts', Consts );
+		workerCode += funcBuildObject( 'Validator', Validator );
 		workerCode += funcBuildSingelton( 'Parser', 'Parser', Parser );
 		workerCode += funcBuildSingelton( 'RawObject', 'RawObject', RawObject );
 		workerCode += funcBuildSingelton( 'RawObjectDescription', 'RawObjectDescription', RawObjectDescription );

+ 87 - 68
examples/js/loaders/WWOBJLoader2.js

@@ -1,12 +1,11 @@
-/**
-  * @author Kai Salmen / https://kaisalmen.de
-  * Development repository: https://github.com/kaisalmen/WWOBJLoader
-  */
-
-'use strict';
-
+/**
+  * @author Kai Salmen / https://kaisalmen.de
+  * Development repository: https://github.com/kaisalmen/WWOBJLoader
+  */
+
+'use strict';
+
 if ( THREE.OBJLoader2 === undefined ) { THREE.OBJLoader2 = {} }
-THREE.OBJLoader2.version = '1.2.1';
 
 /**
  * OBJ data will be loaded by dynamically created web worker.
@@ -16,11 +15,17 @@ THREE.OBJLoader2.version = '1.2.1';
  */
 THREE.OBJLoader2.WWOBJLoader2 = (function () {
 
+	var WWOBJLOADER2_VERSION = '1.2.1';
+
+	var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 	function WWOBJLoader2() {
 		this._init();
 	}
 
 	WWOBJLoader2.prototype._init = function () {
+		console.log( "Using THREE.OBJLoader2.WWOBJLoader2 version: " + WWOBJLOADER2_VERSION );
+		
 		// check worker support first
 		if ( window.Worker === undefined ) throw "This browser does not support web workers!";
 		if ( window.Blob === undefined  ) throw "This browser does not support Blob!";
@@ -86,7 +91,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	 * @param {callback} callbackProgress Callback function for described functionality
 	 */
 	WWOBJLoader2.prototype.registerCallbackProgress = function ( callbackProgress ) {
-		if ( Boolean( callbackProgress ) ) this.callbacks.progress.push( callbackProgress );
+		if ( Validator.isValid( callbackProgress ) ) this.callbacks.progress.push( callbackProgress );
 	};
 
 	/**
@@ -96,7 +101,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	 * @param {callback} callbackCompletedLoading Callback function for described functionality
 	 */
 	WWOBJLoader2.prototype.registerCallbackCompletedLoading = function ( callbackCompletedLoading ) {
-		if ( Boolean( callbackCompletedLoading ) ) this.callbacks.completedLoading.push( callbackCompletedLoading );
+		if ( Validator.isValid( callbackCompletedLoading ) ) this.callbacks.completedLoading.push( callbackCompletedLoading );
 	};
 
 	/**
@@ -106,7 +111,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	 * @param {callback} callbackMaterialsLoaded Callback function for described functionality
 	 */
 	WWOBJLoader2.prototype.registerCallbackMaterialsLoaded = function ( callbackMaterialsLoaded ) {
-		if ( Boolean( callbackMaterialsLoaded ) ) this.callbacks.materialsLoaded.push( callbackMaterialsLoaded );
+		if ( Validator.isValid( callbackMaterialsLoaded ) ) this.callbacks.materialsLoaded.push( callbackMaterialsLoaded );
 	};
 
 	/**
@@ -117,7 +122,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	 * @param {callback} callbackMeshLoaded Callback function for described functionality
 	 */
 	WWOBJLoader2.prototype.registerCallbackMeshLoaded = function ( callbackMeshLoaded ) {
-		if ( Boolean( callbackMeshLoaded ) ) this.callbacks.meshLoaded.push( callbackMeshLoaded );
+		if ( Validator.isValid( callbackMeshLoaded ) ) this.callbacks.meshLoaded.push( callbackMeshLoaded );
 	};
 
 	/**
@@ -127,7 +132,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	 * @param {callback} callbackErrorWhileLoading Callback function for described functionality
 	 */
 	WWOBJLoader2.prototype.registerCallbackErrorWhileLoading = function ( callbackErrorWhileLoading ) {
-		if ( Boolean( callbackErrorWhileLoading ) ) this.callbacks.errorWhileLoading.push( callbackErrorWhileLoading );
+		if ( Validator.isValid( callbackErrorWhileLoading ) ) this.callbacks.errorWhileLoading.push( callbackErrorWhileLoading );
 	};
 
 	/**
@@ -151,12 +156,12 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	 * @param {boolean} requestTerminate True or false
 	 */
 	WWOBJLoader2.prototype.setRequestTerminate = function ( requestTerminate ) {
-		this.requestTerminate = Boolean( requestTerminate );
+		this.requestTerminate = requestTerminate === true;
 	};
 
 	WWOBJLoader2.prototype._validate = function () {
 		if ( this.validated ) return;
-		if ( ! Boolean( this.worker ) ) {
+		if ( ! Validator.isValid( this.worker ) ) {
 
 			this._buildWebWorkerCode();
 			var blob = new Blob( [ this.workerCode ], { type: 'text/plain' } );
@@ -178,9 +183,9 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 		this.running = true;
 		this.requestTerminate = false;
 
-		this.fileLoader = Boolean( this.fileLoader ) ? this.fileLoader : new THREE.FileLoader( this.manager );
-		this.mtlLoader = Boolean( this.mtlLoader ) ? this.mtlLoader : new THREE.MTLLoader();
-		if ( Boolean( this.crossOrigin ) ) this.mtlLoader.setCrossOrigin( this.crossOrigin );
+		this.fileLoader = Validator.verifyInput( this.fileLoader, new THREE.FileLoader( this.manager ) );
+		this.mtlLoader = Validator.verifyInput( this.mtlLoader, new THREE.MTLLoader() );
+		if ( Validator.isValid( this.crossOrigin ) ) this.mtlLoader.setCrossOrigin( this.crossOrigin );
 
 		this.dataAvailable = false;
 		this.fileObj = null;
@@ -258,7 +263,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 		var processLoadedMaterials = function ( materialCreator ) {
 			var materialCreatorMaterials = [];
 			var materialNames = [];
-			if ( Boolean( materialCreator ) ) {
+			if ( Validator.isValid( materialCreator ) ) {
 
 				materialCreator.preload();
 				materialCreatorMaterials = materialCreator.materials;
@@ -285,7 +290,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 
 				callbackMaterialsLoaded = scope.callbacks.materialsLoaded[ index ];
 				materialsFromCallback = callbackMaterialsLoaded( scope.materials );
-				if ( Boolean( materialsFromCallback ) ) scope.materials = materialsFromCallback;
+				if ( Validator.isValid( materialsFromCallback ) ) scope.materials = materialsFromCallback;
 
 			}
 			if ( scope.dataAvailable && scope.objAsArrayBuffer ) {
@@ -344,11 +349,11 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 		this.mtlLoader.setPath( this.pathTexture );
 		if ( this.dataAvailable ) {
 
-			processLoadedMaterials( Boolean( this.mtlAsString ) ? this.mtlLoader.parse( this.mtlAsString ) : null );
+			processLoadedMaterials( Validator.isValid( this.mtlAsString ) ? this.mtlLoader.parse( this.mtlAsString ) : null );
 
 		} else {
 
-			if ( Boolean( this.fileMtl ) ) {
+			if ( Validator.isValid( this.fileMtl ) ) {
 
 				var onError = function ( event ) {
 					output = 'Error occurred while downloading "' + scope.fileMtl + '"';
@@ -379,7 +384,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 
 				var bufferGeometry = new THREE.BufferGeometry();
 				bufferGeometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( payload.vertices ), 3 ) );
-				if ( payload.normals !== null ) {
+				if ( Validator.isValid( payload.normals ) ) {
 
 					bufferGeometry.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( payload.normals ), 3 ) );
 
@@ -388,7 +393,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 					bufferGeometry.computeVertexNormals();
 
 				}
-				if ( payload.uvs !== null ) {
+				if ( Validator.isValid( payload.uvs ) ) {
 
 					bufferGeometry.addAttribute( 'uv', new THREE.BufferAttribute( new Float32Array( payload.uvs ), 2 ) );
 
@@ -454,7 +459,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 					callbackMeshLoaded = this.callbacks.meshLoaded[ index ];
 					callbackMeshLoadedResult = callbackMeshLoaded( meshName, bufferGeometry, material );
 
-					if ( Boolean( callbackMeshLoadedResult ) ) {
+					if ( Validator.isValid( callbackMeshLoadedResult ) ) {
 
 						if ( callbackMeshLoadedResult.disregardMesh ) {
 
@@ -506,7 +511,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 				}
 
 				console.timeEnd( 'WWOBJLoader2' );
-				if ( Boolean( payload.msg ) ) {
+				if ( Validator.isValid( payload.msg ) ) {
 
 					this._announceProgress( payload.msg );
 
@@ -531,7 +536,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	};
 
 	WWOBJLoader2.prototype._terminate = function () {
-		if ( Boolean( this.worker ) ) {
+		if ( Validator.isValid( this.worker ) ) {
 
 			if ( this.running ) throw 'Unable to gracefully terminate worker as it is currently running!';
 
@@ -579,8 +584,8 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	};
 
 	WWOBJLoader2.prototype._announceProgress = function ( baseText, text ) {
-		var output = ( Boolean( baseText ) ) ? baseText: "";
-		output = ( Boolean( text ) ) ? output + " " + text : output;
+		var output = Validator.isValid( baseText ) ? baseText: "";
+		output = Validator.isValid( text ) ? output + " " + text : output;
 
 		var callbackProgress;
 		for ( var index in this.callbacks.progress ) {
@@ -594,8 +599,8 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 	};
 
 	WWOBJLoader2.prototype._buildWebWorkerCode = function ( existingWorkerCode ) {
-		if ( Boolean( existingWorkerCode ) ) this.workerCode = existingWorkerCode;
-		if ( ! Boolean( this.workerCode ) ) {
+		if ( Validator.isValid( existingWorkerCode ) ) this.workerCode = existingWorkerCode;
+		if ( ! Validator.isValid( this.workerCode ) ) {
 
 			console.time( 'buildWebWorkerCode' );
 			var wwDef = (function () {
@@ -690,11 +695,12 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 				}
 
 				WWMeshCreator.prototype.setMaterials = function ( materials ) {
-					this.materials = Boolean( materials ) ? materials : ( Boolean( this.materials ) ? this.materials : { materials: [] } );
+					this.materials = Validator.verifyInput( materials, this.materials );
+					this.materials = Validator.verifyInput( this.materials, { materials: [] } );
 				};
 
 				WWMeshCreator.prototype.setDebug = function ( debug ) {
-					this.debug = Boolean( debug ) ? debug : this.debug;
+					if ( debug === true || debug === false ) this.debug = debug;
 				};
 
 				WWMeshCreator.prototype.validate = function () {
@@ -923,8 +929,7 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
 			this.workerCode += '  */\n\n';
 
 			// parser re-construction
-			var objLoaderHelper = new THREE.OBJLoader2();
-			this.workerCode += objLoaderHelper._buildWebWorkerCode( buildObject, buildSingelton );
+			this.workerCode += THREE.OBJLoader2.prototype._buildWebWorkerCode( buildObject, buildSingelton );
 
 			// web worker construction
 			this.workerCode += buildSingelton( 'WWOBJLoader', 'WWOBJLoader', wwDef );
@@ -955,6 +960,9 @@ THREE.OBJLoader2.WWOBJLoader2 = (function () {
  * @constructor
  */
 THREE.OBJLoader2.WWOBJLoader2.PrepDataArrayBuffer = function ( modelName, objAsArrayBuffer, pathTexture, mtlAsString ) {
+
+	var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 	return {
 
 		/**
@@ -964,7 +972,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataArrayBuffer = function ( modelName, objAsA
 		 * @param {THREE.Object3D} sceneGraphBaseNode Scene graph object
 		 */
 		setSceneGraphBaseNode: function ( sceneGraphBaseNode ) {
-			this.sceneGraphBaseNode = Boolean( sceneGraphBaseNode ) ? sceneGraphBaseNode : null;
+			this.sceneGraphBaseNode = Validator.verifyInput( sceneGraphBaseNode, null );
 		},
 
 		/**
@@ -974,7 +982,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataArrayBuffer = function ( modelName, objAsA
 		 * @param {boolean} streamMeshes=true Default is true
 		 */
 		setStreamMeshes: function ( streamMeshes ) {
-			this.streamMeshes = ( streamMeshes === null || streamMeshes === undefined ) ? true : streamMeshes;
+			this.streamMeshes = streamMeshes !== false;
 		},
 
 		/**
@@ -984,7 +992,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataArrayBuffer = function ( modelName, objAsA
 		 * @param {boolean} requestTerminate=false Default is false
 		 */
 		setRequestTerminate: function ( requestTerminate ) {
-			this.requestTerminate = Boolean( requestTerminate );
+			this.requestTerminate = requestTerminate === true;
 		},
 
 		/**
@@ -996,11 +1004,11 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataArrayBuffer = function ( modelName, objAsA
 		getCallbacks: function () {
 			return this.callbacks;
 		},
-		modelName: Boolean( modelName ) ? modelName : 'none',
+		modelName: Validator.verifyInput( modelName, 'none' ),
 		dataAvailable: true,
-		objAsArrayBuffer: Boolean( objAsArrayBuffer ) ? objAsArrayBuffer : null,
-		pathTexture: Boolean( pathTexture ) ? pathTexture : null,
-		mtlAsString: Boolean( mtlAsString ) ? mtlAsString : null,
+		objAsArrayBuffer: Validator.verifyInput( objAsArrayBuffer, null ),
+		pathTexture: Validator.verifyInput( pathTexture, null ),
+		mtlAsString: Validator.verifyInput( mtlAsString, null ),
 		sceneGraphBaseNode: null,
 		streamMeshes: true,
 		requestTerminate: false,
@@ -1021,6 +1029,9 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataArrayBuffer = function ( modelName, objAsA
  * @constructor
  */
 THREE.OBJLoader2.WWOBJLoader2.PrepDataFile = function ( modelName, pathObj, fileObj, pathTexture, fileMtl ) {
+
+	var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 	return {
 
 		/**
@@ -1030,7 +1041,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataFile = function ( modelName, pathObj, file
 		 * @param {THREE.Object3D} sceneGraphBaseNode Scene graph object
 		 */
 		setSceneGraphBaseNode: function ( sceneGraphBaseNode ) {
-			this.sceneGraphBaseNode = Boolean( sceneGraphBaseNode ) ? sceneGraphBaseNode : null;
+			this.sceneGraphBaseNode = Validator.verifyInput( sceneGraphBaseNode, null );
 		},
 
 		/**
@@ -1040,7 +1051,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataFile = function ( modelName, pathObj, file
 		 * @param {boolean} streamMeshes=true Default is true
 		 */
 		setStreamMeshes: function ( streamMeshes ) {
-			this.streamMeshes = ( streamMeshes === null || streamMeshes === undefined ) ? true : streamMeshes;
+			this.streamMeshes = streamMeshes !== false;
 		},
 
 		/**
@@ -1050,7 +1061,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataFile = function ( modelName, pathObj, file
 		 * @param {boolean} requestTerminate=false Default is false
 		 */
 		setRequestTerminate: function ( requestTerminate ) {
-			this.requestTerminate = Boolean( requestTerminate );
+			this.requestTerminate = requestTerminate === true;
 		},
 
 		/**
@@ -1062,12 +1073,12 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataFile = function ( modelName, pathObj, file
 		getCallbacks: function () {
 			return this.callbacks;
 		},
-		modelName: Boolean( modelName ) ? modelName : 'none',
+		modelName: Validator.verifyInput( modelName, 'none' ),
 		dataAvailable: false,
-		pathObj: Boolean( pathObj ) ? pathObj : null,
-		fileObj: Boolean( fileObj ) ? fileObj : null,
-		pathTexture: Boolean( pathTexture ) ? pathTexture : null,
-		fileMtl: Boolean( fileMtl ) ? fileMtl : null,
+		pathObj: Validator.verifyInput( pathObj, null ),
+		fileObj: Validator.verifyInput( fileObj, null ),
+		pathTexture: Validator.verifyInput( pathTexture, null ),
+		fileMtl: Validator.verifyInput( fileMtl, null ),
 		sceneGraphBaseNode: null,
 		streamMeshes: true,
 		requestTerminate: false,
@@ -1082,6 +1093,9 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataFile = function ( modelName, pathObj, file
  * @constructor
  */
 THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks = function () {
+
+	var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 	return {
 		/**
 		 * Register callback function that is invoked by internal function "_announceProgress" to print feedback.
@@ -1090,7 +1104,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks = function () {
 		 * @param {callback} callbackProgress Callback function for described functionality
 		 */
 		registerCallbackProgress: function ( callbackProgress ) {
-			if ( Boolean( callbackProgress ) ) this.progress = callbackProgress;
+			if ( Validator.isValid( callbackProgress ) ) this.progress = callbackProgress;
 		},
 
 		/**
@@ -1100,7 +1114,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks = function () {
 		 * @param {callback} callbackCompletedLoading Callback function for described functionality
 		 */
 		registerCallbackCompletedLoading: function ( callbackCompletedLoading ) {
-			if ( Boolean( callbackCompletedLoading ) ) this.completedLoading = callbackCompletedLoading;
+			if ( Validator.isValid( callbackCompletedLoading ) ) this.completedLoading = callbackCompletedLoading;
 		},
 
 		/**
@@ -1110,7 +1124,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks = function () {
 		 * @param {callback} callbackMaterialsLoaded Callback function for described functionality
 		 */
 		registerCallbackMaterialsLoaded: function ( callbackMaterialsLoaded ) {
-			if ( Boolean( callbackMaterialsLoaded ) ) this.materialsLoaded = callbackMaterialsLoaded;
+			if ( Validator.isValid( callbackMaterialsLoaded ) ) this.materialsLoaded = callbackMaterialsLoaded;
 		},
 
 		/**
@@ -1121,7 +1135,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks = function () {
 		 * @param {callback} callbackMeshLoaded Callback function for described functionality
 		 */
 		registerCallbackMeshLoaded: function ( callbackMeshLoaded ) {
-			if ( Boolean( callbackMeshLoaded ) ) this.meshLoaded = callbackMeshLoaded;
+			if ( Validator.isValid( callbackMeshLoaded ) ) this.meshLoaded = callbackMeshLoaded;
 		},
 
 		/**
@@ -1131,7 +1145,7 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks = function () {
 		 * @param {callback} callbackErrorWhileLoading Callback function for described functionality
 		 */
 		registerCallbackErrorWhileLoading: function ( callbackErrorWhileLoading ) {
-			if ( Boolean( callbackErrorWhileLoading ) ) this.errorWhileLoading = callbackErrorWhileLoading;
+			if ( Validator.isValid( callbackErrorWhileLoading ) ) this.errorWhileLoading = callbackErrorWhileLoading;
 		},
 
 		progress: null,
@@ -1154,15 +1168,18 @@ THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks = function () {
  * @constructor
  */
 THREE.OBJLoader2.WWOBJLoader2.LoadedMeshUserOverride = function ( disregardMesh, bufferGeometry, material ) {
+
+	var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 	return {
-		disregardMesh: Boolean( disregardMesh ),
-		replaceBufferGeometry: Boolean( bufferGeometry ),
-		bufferGeometry: Boolean( bufferGeometry ) ? bufferGeometry : null,
-		replaceMaterial: Boolean( material ),
-		material: Boolean( material ) ? material : null
+		disregardMesh: disregardMesh === true,
+		replaceBufferGeometry: Validator.isValid( bufferGeometry ),
+		bufferGeometry: Validator.verifyInput( bufferGeometry, null ),
+		replaceMaterial: Validator.isValid( material ),
+		material: Validator.verifyInput( material, null )
 	};
 };
-
+
 /**
  * Orchestrate loading of multiple OBJ files/data from an instruction queue with a configurable amount of workers (1-16).
  * Workflow:
@@ -1175,6 +1192,8 @@ THREE.OBJLoader2.WWOBJLoader2.LoadedMeshUserOverride = function ( disregardMesh,
  */
 THREE.OBJLoader2.WWOBJLoader2Director = (function () {
 
+	var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 	var MAX_WEB_WORKER = 16;
 	var MAX_QUEUE_SIZE = 1024;
 
@@ -1232,7 +1251,7 @@ THREE.OBJLoader2.WWOBJLoader2Director = (function () {
 	 * @param {number} maxWebWorkers Set the maximum amount of workers (1-16)
 	 */
 	WWOBJLoader2Director.prototype.prepareWorkers = function ( globalCallbacks, maxQueueSize, maxWebWorkers ) {
-		if ( Boolean( globalCallbacks ) ) this.workerDescription.globalCallbacks = globalCallbacks;
+		if ( Validator.isValid( globalCallbacks ) ) this.workerDescription.globalCallbacks = globalCallbacks;
 		this.maxQueueSize = Math.min( maxQueueSize, MAX_QUEUE_SIZE );
 		this.maxWebWorkers = Math.min( maxWebWorkers, MAX_WEB_WORKER );
 		this.objectsCompleted = 0;
@@ -1301,18 +1320,18 @@ THREE.OBJLoader2.WWOBJLoader2Director = (function () {
 			if ( workerCallbacks.hasOwnProperty( key ) && globalCallbacks.hasOwnProperty( key ) ) {
 
 				selectedGlobalCallback = globalCallbacks[ key ];
-				if ( Boolean( selectedGlobalCallback ) ) workerCallbacks[ key ].push( selectedGlobalCallback );
+				if ( Validator.isValid( selectedGlobalCallback ) ) workerCallbacks[ key ].push( selectedGlobalCallback );
 
 			}
 
 		}
 		// register per object callbacks
 		var runCallbacks = runParams.callbacks;
-		if ( Boolean( runCallbacks ) ) {
+		if ( Validator.isValid( runCallbacks ) ) {
 
 			for ( key in runCallbacks ) {
 
-				if ( workerCallbacks.hasOwnProperty( key ) && runCallbacks.hasOwnProperty( key ) && Boolean( runCallbacks[ key ] ) ) {
+				if ( workerCallbacks.hasOwnProperty( key ) && runCallbacks.hasOwnProperty( key ) && Validator.isValid( runCallbacks[ key ] ) ) {
 
 					workerCallbacks[ key ].push( runCallbacks[ key ] );
 
@@ -1329,7 +1348,7 @@ THREE.OBJLoader2.WWOBJLoader2Director = (function () {
 
 				var worker = scope.workerDescription.webWorkers[ instanceNo ];
 				var runParams = scope.instructionQueue[ 0 ];
-				if ( Boolean( runParams ) ) {
+				if ( Validator.isValid( runParams ) ) {
 
 					console.log( '\nAssigning next item from queue to worker (queue length: ' + scope.instructionQueue.length + ')\n\n' );
 					scope._kickWebWorkerRun( worker, runParams );
@@ -1348,10 +1367,10 @@ THREE.OBJLoader2.WWOBJLoader2Director = (function () {
 	WWOBJLoader2Director.prototype._buildWebWorker = function () {
 		var webWorker = Object.create( this.workerDescription.prototypeDef );
 		webWorker._init();
-		if ( Boolean( this.crossOrigin ) ) webWorker.setCrossOrigin( this.crossOrigin );
+		if ( Validator.isValid( this.crossOrigin ) ) webWorker.setCrossOrigin( this.crossOrigin );
 
 		// Ensure code string is built once and then it is just passed on to every new instance
-		if ( Boolean( this.workerDescription.codeBuffer ) ) {
+		if ( Validator.isValid( this.workerDescription.codeBuffer ) ) {
 
 			webWorker._buildWebWorkerCode( this.workerDescription.codeBuffer );
 

+ 4 - 2
examples/webgl_loader_obj2_ww.html

@@ -90,6 +90,8 @@
 
 			var WWOBJLoader2Example = (function () {
 
+				var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 				function WWOBJLoader2Example( elementToBindTo ) {
 					this.renderer = null;
 					this.canvas = elementToBindTo;
@@ -181,7 +183,7 @@
 						console.log( 'Progress: ' + content );
 					};
 					var materialsLoaded = function ( materials ) {
-						var count = Boolean( materials ) ? materials.length : 0;
+						var count = Validator.isValid( materials ) ? materials.length : 0;
 						console.log( 'Loaded #' + count + ' materials.' );
 					};
 					var meshLoaded = function ( name, bufferGeometry, material ) {
@@ -222,7 +224,7 @@
 
 					}
 
-					if ( ! Boolean( fileObj ) ) {
+					if ( ! Validator.isValid( fileObj ) ) {
 						alert( 'Unable to load OBJ file from given files.' );
 					}
 

+ 17 - 2
examples/webgl_loader_obj2_ww_parallels.html

@@ -92,6 +92,8 @@
 
 			var WWParallels = (function () {
 
+				var Validator = THREE.OBJLoader2.prototype._getValidator();
+
 				function WWParallels( elementToBindTo ) {
 					this.renderer = null;
 					this.canvas = elementToBindTo;
@@ -117,6 +119,8 @@
 
 					this.allAssets = [];
 					this.feedbackArray = null;
+
+					this.running = false;
 				}
 
 				WWParallels.prototype.initGL = function () {
@@ -192,6 +196,15 @@
 				};
 
 				WWParallels.prototype.enqueueAllAssests = function ( maxQueueSize, maxWebWorkers, streamMeshes ) {
+					if ( this.running ) {
+
+						return;
+
+					} else {
+
+						this.running = true;
+
+					}
 					var scope = this;
 					scope.wwDirector.objectsCompleted = 0;
 					scope.feedbackArray = new Array( maxWebWorkers );
@@ -209,12 +222,14 @@
 						console.log( msg );
 						scope.feedbackArray[ instanceNo ] = msg;
 						scope.reportProgress( scope.feedbackArray.join( '\<br\>' ) );
+
+						if ( scope.wwDirector.objectsCompleted + 1 === maxQueueSize ) scope.running = false;
 					};
 
 					var callbackMeshLoaded = function ( name, bufferGeometry, material ) {
 						var materialOverride;
 
-						if ( Boolean( material ) && material.name === 'defaultMaterial' || name === 'Mesh_Mesh_head_geo.001' ) {
+						if ( Validator.isValid( material ) && material.name === 'defaultMaterial' || name === 'Mesh_Mesh_head_geo.001' ) {
 
 							materialOverride = material;
 							materialOverride.color = new THREE.Color( Math.random(), Math.random(), Math.random() );
@@ -294,7 +309,7 @@
 							distributionBase + distributionMax * Math.random(),
 							distributionBase + distributionMax * Math.random()
 						);
-						if ( Boolean( model.scale ) ) pivot.scale.set( model.scale, model.scale, model.scale );
+						if ( Validator.isValid( model.scale ) ) pivot.scale.set( model.scale, model.scale, model.scale );
 
 						this.scene.add( pivot );