|
@@ -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 );
|
|
|
|