|
@@ -17,7 +17,7 @@ if ( THREE.LoaderSupport === undefined ) console.error( '"THREE.LoaderSupport" i
|
|
*/
|
|
*/
|
|
THREE.OBJLoader2 = (function () {
|
|
THREE.OBJLoader2 = (function () {
|
|
|
|
|
|
- var OBJLOADER2_VERSION = '2.4.1';
|
|
|
|
|
|
+ var OBJLOADER2_VERSION = '2.4.2';
|
|
var Validator = THREE.LoaderSupport.Validator;
|
|
var Validator = THREE.LoaderSupport.Validator;
|
|
|
|
|
|
function OBJLoader2( manager ) {
|
|
function OBJLoader2( manager ) {
|
|
@@ -139,6 +139,7 @@ THREE.OBJLoader2 = (function () {
|
|
|
|
|
|
OBJLoader2.prototype._setCallbacks = function ( callbacks ) {
|
|
OBJLoader2.prototype._setCallbacks = function ( callbacks ) {
|
|
if ( Validator.isValid( callbacks.onProgress ) ) this.callbacks.setCallbackOnProgress( callbacks.onProgress );
|
|
if ( Validator.isValid( callbacks.onProgress ) ) this.callbacks.setCallbackOnProgress( callbacks.onProgress );
|
|
|
|
+ if ( Validator.isValid( callbacks.onReportError ) ) this.callbacks.setCallbackOnReportError( callbacks.onReportError );
|
|
if ( Validator.isValid( callbacks.onMeshAlter ) ) this.callbacks.setCallbackOnMeshAlter( callbacks.onMeshAlter );
|
|
if ( Validator.isValid( callbacks.onMeshAlter ) ) this.callbacks.setCallbackOnMeshAlter( callbacks.onMeshAlter );
|
|
if ( Validator.isValid( callbacks.onLoad ) ) this.callbacks.setCallbackOnLoad( callbacks.onLoad );
|
|
if ( Validator.isValid( callbacks.onLoad ) ) this.callbacks.setCallbackOnLoad( callbacks.onLoad );
|
|
if ( Validator.isValid( callbacks.onLoadMaterials ) ) this.callbacks.setCallbackOnLoadMaterials( callbacks.onLoadMaterials );
|
|
if ( Validator.isValid( callbacks.onLoadMaterials ) ) this.callbacks.setCallbackOnLoadMaterials( callbacks.onLoadMaterials );
|
|
@@ -181,7 +182,19 @@ THREE.OBJLoader2 = (function () {
|
|
|
|
|
|
}
|
|
}
|
|
this.onProgress( 'error', output, -1 );
|
|
this.onProgress( 'error', output, -1 );
|
|
- throw output;
|
|
|
|
|
|
+ this._throwError( output );
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ OBJLoader2.prototype._throwError = function ( errorMessage ) {
|
|
|
|
+ if ( Validator.isValid( this.callbacks.onReportError ) ) {
|
|
|
|
+
|
|
|
|
+ this.callbacks.onReportError( errorMessage );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ throw errorMessage;
|
|
|
|
+
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -201,11 +214,15 @@ THREE.OBJLoader2 = (function () {
|
|
};
|
|
};
|
|
|
|
|
|
OBJLoader2.prototype._loadObj = function ( resource, onLoad, onProgress, onError, onMeshAlter, useAsync ) {
|
|
OBJLoader2.prototype._loadObj = function ( resource, onLoad, onProgress, onError, onMeshAlter, useAsync ) {
|
|
- if ( ! Validator.isValid( onError ) ) onError = this._onError;
|
|
|
|
|
|
+ var scope = this;
|
|
|
|
+ if ( ! Validator.isValid( onError ) ) {
|
|
|
|
+ onError = function ( event ) {
|
|
|
|
+ scope._onError( event );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
// fast-fail
|
|
// fast-fail
|
|
if ( ! Validator.isValid( resource ) ) onError( 'An invalid ResourceDescriptor was provided. Unable to continue!' );
|
|
if ( ! Validator.isValid( resource ) ) onError( 'An invalid ResourceDescriptor was provided. Unable to continue!' );
|
|
- var scope = this;
|
|
|
|
var fileLoaderOnLoad = function ( content ) {
|
|
var fileLoaderOnLoad = function ( content ) {
|
|
|
|
|
|
resource.content = content;
|
|
resource.content = content;
|
|
@@ -295,7 +312,7 @@ THREE.OBJLoader2 = (function () {
|
|
scope._loadObj( available.obj, scope.callbacks.onLoad, null, null, scope.callbacks.onMeshAlter, prepData.useAsync );
|
|
scope._loadObj( available.obj, scope.callbacks.onLoad, null, null, scope.callbacks.onMeshAlter, prepData.useAsync );
|
|
|
|
|
|
};
|
|
};
|
|
- this._loadMtl( available.mtl, onMaterialsLoaded, prepData.crossOrigin, prepData.materialOptions );
|
|
|
|
|
|
+ this._loadMtl( available.mtl, onMaterialsLoaded, null, null, prepData.crossOrigin, prepData.materialOptions );
|
|
};
|
|
};
|
|
|
|
|
|
OBJLoader2.prototype._applyPrepData = function ( prepData ) {
|
|
OBJLoader2.prototype._applyPrepData = function ( prepData ) {
|
|
@@ -368,7 +385,7 @@ THREE.OBJLoader2 = (function () {
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- throw 'Provided content was neither of type String nor Uint8Array! Aborting...';
|
|
|
|
|
|
+ this._throwError( 'Provided content was neither of type String nor Uint8Array! Aborting...' );
|
|
|
|
|
|
}
|
|
}
|
|
if ( this.logging.enabled ) console.timeEnd( 'OBJLoader2 parse: ' + this.modelName );
|
|
if ( this.logging.enabled ) console.timeEnd( 'OBJLoader2 parse: ' + this.modelName );
|
|
@@ -574,7 +591,11 @@ THREE.OBJLoader2 = (function () {
|
|
};
|
|
};
|
|
|
|
|
|
Parser.prototype.setCallbackMeshBuilder = function ( callbackMeshBuilder ) {
|
|
Parser.prototype.setCallbackMeshBuilder = function ( callbackMeshBuilder ) {
|
|
- if ( ! THREE.LoaderSupport.Validator.isValid( callbackMeshBuilder ) ) throw 'Unable to run as no "MeshBuilder" callback is set.';
|
|
|
|
|
|
+ if ( ! THREE.LoaderSupport.Validator.isValid( callbackMeshBuilder ) ) {
|
|
|
|
+
|
|
|
|
+ this._throwError( 'Unable to run as no "MeshBuilder" callback is set.' );
|
|
|
|
+
|
|
|
|
+ }
|
|
this.callbackMeshBuilder = callbackMeshBuilder;
|
|
this.callbackMeshBuilder = callbackMeshBuilder;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -1077,7 +1098,7 @@ THREE.OBJLoader2 = (function () {
|
|
|
|
|
|
if ( this.colors.length > 0 && this.colors.length !== this.vertices.length ) {
|
|
if ( this.colors.length > 0 && this.colors.length !== this.vertices.length ) {
|
|
|
|
|
|
- throw 'Vertex Colors were detected, but vertex count and color count do not match!';
|
|
|
|
|
|
+ this._throwError( 'Vertex Colors were detected, but vertex count and color count do not match!' );
|
|
|
|
|
|
}
|
|
}
|
|
if ( this.logging.enabled && this.logging.debug ) console.debug( this.createRawMeshReport( this.inputObjectCount ) );
|
|
if ( this.logging.enabled && this.logging.debug ) console.debug( this.createRawMeshReport( this.inputObjectCount ) );
|
|
@@ -1327,18 +1348,20 @@ THREE.OBJLoader2 = (function () {
|
|
*
|
|
*
|
|
* @param {string} url URL to the file
|
|
* @param {string} url URL to the file
|
|
* @param {Object} content The file content as arraybuffer or text
|
|
* @param {Object} content The file content as arraybuffer or text
|
|
- * @param {function} callbackOnLoad Callback to be called after successful load
|
|
|
|
|
|
+ * @param {function} onLoad Callback to be called after successful load
|
|
|
|
+ * @param {callback} [onProgress] A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains total and Integer bytes.
|
|
|
|
+ * @param {callback} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument.
|
|
* @param {string} [crossOrigin] CORS value
|
|
* @param {string} [crossOrigin] CORS value
|
|
* @param {Object} [materialOptions] Set material loading options for MTLLoader
|
|
* @param {Object} [materialOptions] Set material loading options for MTLLoader
|
|
*/
|
|
*/
|
|
- OBJLoader2.prototype.loadMtl = function ( url, content, callbackOnLoad, crossOrigin, materialOptions ) {
|
|
|
|
|
|
+ OBJLoader2.prototype.loadMtl = function ( url, content, onLoad, onProgress, onError, crossOrigin, materialOptions ) {
|
|
var resource = new THREE.LoaderSupport.ResourceDescriptor( url, 'MTL' );
|
|
var resource = new THREE.LoaderSupport.ResourceDescriptor( url, 'MTL' );
|
|
resource.setContent( content );
|
|
resource.setContent( content );
|
|
- this._loadMtl( resource, callbackOnLoad, crossOrigin, materialOptions );
|
|
|
|
|
|
+ this._loadMtl( resource, onLoad, onProgress, onError, crossOrigin, materialOptions );
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
- OBJLoader2.prototype._loadMtl = function ( resource, callbackOnLoad, crossOrigin, materialOptions ) {
|
|
|
|
|
|
+ OBJLoader2.prototype._loadMtl = function ( resource, onLoad, onProgress, onError, crossOrigin, materialOptions ) {
|
|
if ( THREE.MTLLoader === undefined ) console.error( '"THREE.MTLLoader" is not available. "THREE.OBJLoader2" requires it for loading MTL files.' );
|
|
if ( THREE.MTLLoader === undefined ) console.error( '"THREE.MTLLoader" is not available. "THREE.OBJLoader2" requires it for loading MTL files.' );
|
|
if ( Validator.isValid( resource ) && this.logging.enabled ) console.time( 'Loading MTL: ' + resource.name );
|
|
if ( Validator.isValid( resource ) && this.logging.enabled ) console.time( 'Loading MTL: ' + resource.name );
|
|
|
|
|
|
@@ -1361,7 +1384,7 @@ THREE.OBJLoader2 = (function () {
|
|
}
|
|
}
|
|
|
|
|
|
if ( Validator.isValid( resource ) && scope.logging.enabled ) console.timeEnd( 'Loading MTL: ' + resource.name );
|
|
if ( Validator.isValid( resource ) && scope.logging.enabled ) console.timeEnd( 'Loading MTL: ' + resource.name );
|
|
- callbackOnLoad( materials, materialCreator );
|
|
|
|
|
|
+ onLoad( materials, materialCreator );
|
|
};
|
|
};
|
|
|
|
|
|
// fast-fail
|
|
// fast-fail
|
|
@@ -1387,7 +1410,7 @@ THREE.OBJLoader2 = (function () {
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- throw 'Unable to parse mtl as it it seems to be neither a String, an Array or an ArrayBuffer!';
|
|
|
|
|
|
+ this._throwError( 'Unable to parse mtl as it it seems to be neither a String, an Array or an ArrayBuffer!' );
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -1401,7 +1424,29 @@ THREE.OBJLoader2 = (function () {
|
|
} else if ( Validator.isValid( resource.url ) ) {
|
|
} else if ( Validator.isValid( resource.url ) ) {
|
|
|
|
|
|
var fileLoader = new THREE.FileLoader( this.manager );
|
|
var fileLoader = new THREE.FileLoader( this.manager );
|
|
- fileLoader.load( resource.url, parseTextWithMtlLoader, this._onProgress, this._onError );
|
|
|
|
|
|
+ if ( ! Validator.isValid( onError ) ) {
|
|
|
|
+ onError = function ( event ) {
|
|
|
|
+ scope._onError( event );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if ( ! Validator.isValid( onProgress ) ) {
|
|
|
|
+ var numericalValueRef = 0;
|
|
|
|
+ var numericalValue = 0;
|
|
|
|
+ onProgress = function ( event ) {
|
|
|
|
+ if ( ! event.lengthComputable ) return;
|
|
|
|
+
|
|
|
|
+ numericalValue = event.loaded / event.total;
|
|
|
|
+ if ( numericalValue > numericalValueRef ) {
|
|
|
|
+
|
|
|
|
+ numericalValueRef = numericalValue;
|
|
|
|
+ var output = 'Download of "' + resource.url + '": ' + ( numericalValue * 100 ).toFixed( 2 ) + '%';
|
|
|
|
+ scope.onProgress( 'progressLoad', output, numericalValue );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fileLoader.load( resource.url, parseTextWithMtlLoader, onProgress, onError );
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|