소스 검색

OBJLoader2 is now based on Loader.
Fixed typescript definition.
MaterialHandler no longer logs during init
OBJLoader2Parallel typescript: parse is implemented differently

Kai Salmen 5 년 전
부모
커밋
d6029e94c1

+ 19 - 8
examples/jsm/loaders/OBJLoader2.d.ts

@@ -1,31 +1,42 @@
 import {
-  LoadingManager,
-  Group,
-  Object3D
+	Loader,
+	LoadingManager,
+	Object3D,
 } from '../../../src/Three';
 
 import { OBJLoader2Parser } from './obj2/worker/parallel/OBJLoader2Parser';
 import { MaterialHandler } from './obj2/shared/MaterialHandler';
 import { MeshReceiver} from './obj2/shared/MeshReceiver';
 
-export class OBJLoader2 extends OBJLoader2Parser {
+export class OBJLoader2 extends Loader {
   constructor(manager?: LoadingManager);
-  manager: LoadingManager;
+  parser: OBJLoader2Parser;
   modelName: string;
   instanceNo: number;
   path: string;
   resourcePath: string;
-  baseObject3d: Group;
+  baseObject3d: Object3D;
   materialHandler: MaterialHandler;
   meshReceiver: MeshReceiver;
 
+  setLogging(enabled: boolean, debug: boolean): this;
+  setMaterialPerSmoothingGroup(materialPerSmoothingGroup: boolean): this;
+  setUseOAsMesh(useOAsMesh: boolean): this;
+  setUseIndices(useIndices: boolean): this;
+  setDisregardNormals(disregardNormals: boolean): this;
+
   setModelName(modelName: string): this;
   setPath(path: string): this;
   setResourcePath(path: string): this;
   setBaseObject3d(baseObject3d: Object3D): this;
   addMaterials(materials: object): this;
+
+  setCallbackOnAssetAvailable(onAssetAvailable: Function): this;
+  setCallbackOnProgress(onProgress: Function): this;
+  setCallbackOnError(onError: Function): this;
   setCallbackOnMeshAlter(onMeshAlter: Function): this;
   setCallbackOnLoadMaterials(onLoadMaterials: Function): this;
-  load(url: string, onLoad: (group: Group) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, onMeshAlter?: (meshData: object) => void): void;
-  parse(content: ArrayBuffer | string): void;
+
+  load(url: string, onLoad: (object3d: Object3D) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, onMeshAlter?: (meshData: object) => void): void;
+  parse(content: ArrayBuffer | string): Object3D;
 }

+ 255 - 177
examples/jsm/loaders/OBJLoader2.js

@@ -4,9 +4,10 @@
  */
 
 import {
-	DefaultLoadingManager,
+	LoadingManager,
 	FileLoader,
-	Group
+	Object3D,
+	Loader
 } from "../../../build/three.module.js";
 
 import { OBJLoader2Parser } from "./obj2/worker/parallel/OBJLoader2Parser.js";
@@ -17,269 +18,346 @@ import { MaterialHandler } from "./obj2/shared/MaterialHandler.js";
  * Use this class to load OBJ data from files or to parse OBJ data from an arraybuffer
  * @class
  *
- * @param {DefaultLoadingManager} [manager] The loadingManager for the loader to use. Default is {@link DefaultLoadingManager}
+ * @param {LoadingManager} [manager] The loadingManager for the loader to use. Default is {@link LoadingManager}
  */
 const OBJLoader2 = function ( manager ) {
+	Loader.call( this, manager );
 
-	OBJLoader2Parser.call( this );
-	this.manager = ( manager !== undefined && manager !== null ) ? manager : DefaultLoadingManager;
+	this.parser = new OBJLoader2Parser();
 
 	this.modelName = '';
 	this.instanceNo = 0;
-	this.path = undefined;
-	this.resourcePath = undefined;
-	this.baseObject3d = new Group();
+	this.baseObject3d = new Object3D();
 
 	this.materialHandler = new MaterialHandler();
 	this.meshReceiver = new MeshReceiver( this.materialHandler );
 
+	this._init();
 };
-OBJLoader2.OBJLOADER2_VERSION = '3.0.0';
+
+OBJLoader2.OBJLOADER2_VERSION = '3.0.1';
 console.info( 'Using OBJLoader2 version: ' + OBJLoader2.OBJLOADER2_VERSION );
 
-OBJLoader2.prototype = Object.create( OBJLoader2Parser.prototype );
-OBJLoader2.prototype.constructor = OBJLoader2;
 
+OBJLoader2.prototype = Object.assign( Object.create( Loader.prototype ), {
 
-/**
- * Set the name of the model.
- *
- * @param {string} modelName
- * @return {OBJLoader2}
- */
-OBJLoader2.prototype.setModelName = function ( modelName ) {
+	constructor: OBJLoader2,
 
-	this.modelName = modelName ? modelName : this.modelName;
-	return this;
+	_init: function () {
 
-};
+		// as OBJLoader2 is no longer derived from OBJLoader2Parser, we need to override the default onAssetAvailable callback
+		let scope = this;
+		let defaultOnAssetAvailable = function ( payload ) {
+			scope._onAssetAvailable( payload )
+		};
+		this.parser.setCallbackOnAssetAvailable( defaultOnAssetAvailable );
 
-/**
- * The URL of the base path.
- *
- * @param {string} path URL
- * @return {OBJLoader2}
- */
-OBJLoader2.prototype.setPath = function ( path ) {
+	},
 
-	this.path = path ? path : this.path;
-	return this;
+	/**
+	 * See {@link OBJLoader2Parser.setLogging}
+	 * @return {OBJLoader2}
+	 */
+	setLogging: function ( enabled, debug ) {
 
-};
+		this.parser.setLogging( enabled, debug );
+		return this;
 
-/**
- * Allow to specify resourcePath for dependencies of specified resource.
- *
- * @param {string} resourcePath
- * @return {OBJLoader2}
- */
-OBJLoader2.prototype.setResourcePath = function ( resourcePath ) {
+	},
 
-	this.resourcePath = resourcePath ? resourcePath : this.resourcePath;
-	return this;
+	/**
+	 * See {@link OBJLoader2Parser.setMaterialPerSmoothingGroup}
+	 * @return {OBJLoader2}
+	 */
+	setMaterialPerSmoothingGroup: function ( materialPerSmoothingGroup ) {
 
-};
+		this.parser.setMaterialPerSmoothingGroup( materialPerSmoothingGroup );
+		return this;
 
-/**
- * Set the node where the loaded objects will be attached directly.
- *
- * @param {Object3D} baseObject3d Object already attached to scenegraph where new meshes will be attached to
- * @return {OBJLoader2}
- */
-OBJLoader2.prototype.setBaseObject3d = function ( baseObject3d ) {
+	},
 
-	this.baseObject3d = ( baseObject3d === undefined || baseObject3d === null ) ? this.baseObject3d : baseObject3d;
-	return this;
+	/**
+	 * See {@link OBJLoader2Parser.setUseOAsMesh}
+	 * @return {OBJLoader2}
+	 */
+	setUseOAsMesh: function ( useOAsMesh ) {
 
-};
+		this.parser.setUseOAsMesh( useOAsMesh );
+		return this;
 
-/**
- * Add materials as associated array.
- *
- * @param {Object} materials Object with named {@link Material}
- * @return {OBJLoader2}
- */
-OBJLoader2.prototype.addMaterials = function ( materials ) {
+	},
 
-	this.materialHandler.addMaterials( materials );
-	return this;
+	/**
+	 * See {@link OBJLoader2Parser.setUseIndices}
+	 * @return {OBJLoader2}
+	 */
+	setUseIndices: function ( useIndices ) {
 
-};
+		this.parser.setUseIndices( useIndices );
+		return this;
 
-/**
- * Register a function that is called once a single mesh is available and it could be altered by the supplied function.
- *
- * @param {Function} [onMeshAlter]
- * @return {OBJLoader2}
- */
-OBJLoader2.prototype.setCallbackOnMeshAlter = function ( onMeshAlter ) {
+	},
 
-	this.meshReceiver._setCallbacks( this.callbacks.onProgress, onMeshAlter );
-	return this;
+	/**
+	 * See {@link OBJLoader2Parser.setDisregardNormals}
+	 * @return {OBJLoader2}
+	 */
+	setDisregardNormals: function ( disregardNormals ) {
 
-};
+		this.parser.setDisregardNormals( disregardNormals );
+		return this;
 
-/**
- * Register a function that is called once all materials have been loaded and they could be altered by the supplied function.
- *
- * @param {Function} [onLoadMaterials]
- * @return {OBJLoader2}
- */
-OBJLoader2.prototype.setCallbackOnLoadMaterials = function ( onLoadMaterials ) {
+	},
 
-	this.materialHandler._setCallbacks( onLoadMaterials );
-	return this;
+	/**
+	 * Set the name of the model.
+	 *
+	 * @param {string} modelName
+	 * @return {OBJLoader2}
+	 */
+	setModelName: function ( modelName ) {
 
-};
+		this.modelName = modelName ? modelName : this.modelName;
+		return this;
 
-/**
- * Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer.
- *
- * @param {string}  url A string containing the path/URL of the file to be loaded.
- * @param {function} onLoad A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument.
- * @param {function} [onFileLoadProgress] 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 {function} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument.
- * @param {function} [onMeshAlter] Called after every single mesh is made available by the parser
- */
-OBJLoader2.prototype.load = function ( url, onLoad, onFileLoadProgress, onError, onMeshAlter ) {
+	},
 
-	let scope = this;
-	if ( onLoad === null || onLoad === undefined || ! ( onLoad instanceof Function ) ) {
+	/**
+	 * Set the node where the loaded objects will be attached directly.
+	 *
+	 * @param {Object3D} baseObject3d Object already attached to scenegraph where new meshes will be attached to
+	 * @return {OBJLoader2}
+	 */
+	setBaseObject3d: function ( baseObject3d ) {
 
-		let errorMessage = 'onLoad is not a function! Aborting...';
-		scope.callbacks.onError( errorMessage );
-		throw errorMessage
+		this.baseObject3d = (baseObject3d === undefined || baseObject3d === null) ? this.baseObject3d : baseObject3d;
+		return this;
 
-	}
-	if ( onError === null || onError === undefined || ! ( onError instanceof Function ) ) {
+	},
 
-		onError = function ( event ) {
+	/**
+	 * Add materials as associated array.
+	 *
+	 * @param {Object} materials Object with named {@link Material}
+	 * @return {OBJLoader2}
+	 */
+	addMaterials: function ( materials ) {
 
-			let errorMessage = event;
-			if ( event.currentTarget && event.currentTarget.statusText !== null ) {
+		this.materialHandler.addMaterials( materials );
+		return this;
 
-				 errorMessage = 'Error occurred while downloading!\nurl: ' + event.currentTarget.responseURL + '\nstatus: ' + event.currentTarget.statusText;
+	},
 
-			}
-			scope.callbacks.onError( errorMessage );
+	/**
+	 * See {@link OBJLoader2Parser.setCallbackOnAssetAvailable}
+	 * @return {OBJLoader2}
+	 */
+	setCallbackOnAssetAvailable: function ( onAssetAvailable ) {
 
-		};
+		this.parser.setCallbackOnAssetAvailable( onAssetAvailable );
+		return this;
 
-	}
-	if ( ! url ) {
+	},
 
-		onError( 'An invalid url was provided. Unable to continue!' );
+	/**
+	 * See {@link OBJLoader2Parser.setCallbackOnProgress}
+	 * @return {OBJLoader2}
+	 */
+	setCallbackOnProgress: function ( onProgress ) {
 
-	}
-	let urlFull = new URL( url, window.location.href ).href;
-	let filename = urlFull;
-	let urlParts = urlFull.split( '/' );
-	if ( urlParts.length > 2 ) {
+		this.parser.setCallbackOnProgress( onProgress );
+		return this;
 
-		filename = urlParts[ urlParts.length - 1 ];
-		let urlPartsPath = urlParts.slice( 0, urlParts.length - 1 ).join( '/' ) + '/';
-		if ( urlPartsPath !== undefined && urlPartsPath !== null ) this.path = urlPartsPath;
+	},
 
-	}
-	if ( onFileLoadProgress === null || onFileLoadProgress === undefined || ! ( onFileLoadProgress instanceof Function ) ) {
+	/**
+	 * See {@link OBJLoader2Parser.setCallbackOnError}
+	 * @return {OBJLoader2}
+	 */
+	setCallbackOnError: function ( onError ) {
 
-		let numericalValueRef = 0;
-		let numericalValue = 0;
-		onFileLoadProgress = function ( event ) {
+		this.parser.setCallbackOnError( onError );
+		return this;
 
-			if ( ! event.lengthComputable ) return;
+	},
 
-			numericalValue = event.loaded / event.total;
-			if ( numericalValue > numericalValueRef ) {
+	/**
+	 * Register a function that is called once a single mesh is available and it could be altered by the supplied function.
+	 *
+	 * @param {Function} [onMeshAlter]
+	 * @return {OBJLoader2}
+	 */
+	setCallbackOnMeshAlter: function ( onMeshAlter ) {
+
+		this.meshReceiver._setCallbacks( this.parser.callbacks.onProgress, onMeshAlter );
+		return this;
 
-				numericalValueRef = numericalValue;
-				let output = 'Download of "' + url + '": ' + ( numericalValue * 100 ).toFixed( 2 ) + '%';
-				scope.callbacks.onProgress( 'progressLoad', output, numericalValue );
+	},
+
+	/**
+	 * Register a function that is called once all materials have been loaded and they could be altered by the supplied function.
+	 *
+	 * @param {Function} [onLoadMaterials]
+	 * @return {OBJLoader2}
+	 */
+	setCallbackOnLoadMaterials: function ( onLoadMaterials ) {
+
+		this.materialHandler._setCallbacks( onLoadMaterials );
+		return this;
+
+	},
 
-			}
+	/**
+	 * Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer.
+	 *
+	 * @param {string}  url A string containing the path/URL of the file to be loaded.
+	 * @param {function} onLoad A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument.
+	 * @param {function} [onFileLoadProgress] 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 {function} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument.
+	 * @param {function} [onMeshAlter] Called after every single mesh is made available by the parser
+	 */
+	load: function ( url, onLoad, onFileLoadProgress, onError, onMeshAlter ) {
+
+		let scope = this;
+		if ( onLoad === null || onLoad === undefined || !(onLoad instanceof Function) ) {
+
+			let errorMessage = 'onLoad is not a function! Aborting...';
+			scope.parser.callbacks.onError( errorMessage );
+			throw errorMessage
 
-		};
+		}
+		if ( onError === null || onError === undefined || !(onError instanceof Function) ) {
 
-	}
+			onError = function ( event ) {
 
-	this.setCallbackOnMeshAlter( onMeshAlter );
-	let fileLoaderOnLoad = function ( content ) {
+				let errorMessage = event;
+				if ( event.currentTarget && event.currentTarget.statusText !== null ) {
 
-		onLoad( scope.parse( content ) );
+					errorMessage = 'Error occurred while downloading!\nurl: ' + event.currentTarget.responseURL + '\nstatus: ' + event.currentTarget.statusText;
 
-	};
-	let fileLoader = new FileLoader( this.manager );
-	fileLoader.setPath( this.path || this.resourcePath );
-	fileLoader.setResponseType( 'arraybuffer' );
-	fileLoader.load( filename, fileLoaderOnLoad, onFileLoadProgress, onError );
+				}
+				scope.parser.callbacks.onError( errorMessage );
 
-};
+			};
 
-/**
- * Parses OBJ data synchronously from arraybuffer or string.
- *
- * @param {arraybuffer|string} content OBJ data as Uint8Array or String
- */
-OBJLoader2.prototype.parse = function ( content ) {
+		}
+		if ( !url ) {
 
-	// fast-fail in case of illegal data
-	if ( content === null || content === undefined ) {
+			onError( 'An invalid url was provided. Unable to continue!' );
 
-		throw 'Provided content is not a valid ArrayBuffer or String. Unable to continue parsing';
+		}
+		let urlFull = new URL( url, window.location.href ).href;
+		let filename = urlFull;
+		let urlParts = urlFull.split( '/' );
+		if ( urlParts.length > 2 ) {
 
-	}
-	if ( this.logging.enabled ) {
+			filename = urlParts[ urlParts.length - 1 ];
+			let urlPartsPath = urlParts.slice( 0, urlParts.length - 1 ).join( '/' ) + '/';
+			if ( urlPartsPath !== undefined && urlPartsPath !== null ) this.path = urlPartsPath;
 
-		console.time( 'OBJLoader parse: ' + this.modelName );
+		}
+		if ( onFileLoadProgress === null || onFileLoadProgress === undefined || !(onFileLoadProgress instanceof Function) ) {
 
-	}
+			let numericalValueRef = 0;
+			let numericalValue = 0;
+			onFileLoadProgress = function ( event ) {
 
-	// sync code works directly on the material references
-	this._setMaterials( this.materialHandler.getMaterials() );
+				if ( !event.lengthComputable ) return;
 
-	if ( content instanceof ArrayBuffer || content instanceof Uint8Array ) {
+				numericalValue = event.loaded / event.total;
+				if ( numericalValue > numericalValueRef ) {
 
-		if ( this.logging.enabled ) console.info( 'Parsing arrayBuffer...' );
-		this.execute( content );
+					numericalValueRef = numericalValue;
+					let output = 'Download of "' + url + '": ' + (numericalValue * 100).toFixed( 2 ) + '%';
+					scope.parser.callbacks.onProgress( 'progressLoad', output, numericalValue );
 
-	} else if ( typeof ( content ) === 'string' || content instanceof String ) {
+				}
 
-		if ( this.logging.enabled ) console.info( 'Parsing text...' );
-		this.executeLegacy( content );
+			};
 
-	} else {
+		}
 
-		this.callbacks.onError( 'Provided content was neither of type String nor Uint8Array! Aborting...' );
+		this.setCallbackOnMeshAlter( onMeshAlter );
+		let fileLoaderOnLoad = function ( content ) {
 
-	}
-	if ( this.logging.enabled ) {
+			onLoad( scope.parse( content ) );
+
+		};
+		let fileLoader = new FileLoader( this.manager );
+		fileLoader.setPath( this.path || this.resourcePath );
+		fileLoader.setResponseType( 'arraybuffer' );
+		fileLoader.load( filename, fileLoaderOnLoad, onFileLoadProgress, onError );
 
-		console.timeEnd( 'OBJLoader parse: ' + this.modelName );
+	},
 
-	}
-	return this.baseObject3d;
+	/**
+	 * Parses OBJ data synchronously from arraybuffer or string.
+	 *
+	 * @param {arraybuffer|string} content OBJ data as Uint8Array or String
+	 * @return {Object3D}
+	 */
+	parse: function ( content ) {
 
-};
+		// fast-fail in case of illegal data
+		if ( content === null || content === undefined ) {
+
+			throw 'Provided content is not a valid ArrayBuffer or String. Unable to continue parsing';
+
+		}
+		if ( this.parser.logging.enabled ) {
+
+			console.time( 'OBJLoader parse: ' + this.modelName );
+
+		}
+
+		// sync code works directly on the material references
+		this.parser._setMaterials( this.materialHandler.getMaterials() );
 
-OBJLoader2.prototype._onAssetAvailable = function ( payload ) {
+		if ( content instanceof ArrayBuffer || content instanceof Uint8Array ) {
 
-	if ( payload.cmd !== 'assetAvailable' ) return;
+			if ( this.parser.logging.enabled ) console.info( 'Parsing arrayBuffer...' );
+			this.parser.execute( content );
 
-	if ( payload.type === 'mesh' ) {
+		} else if ( typeof (content) === 'string' || content instanceof String ) {
 
-		let meshes = this.meshReceiver.buildMeshes( payload );
-		for ( let mesh of meshes ) {
+			if ( this.parser.logging.enabled ) console.info( 'Parsing text...' );
+			this.parser.executeLegacy( content );
 
-			this.baseObject3d.add( mesh );
+		} else {
+
+			this.parser.callbacks.onError( 'Provided content was neither of type String nor Uint8Array! Aborting...' );
 
 		}
+		if ( this.parser.logging.enabled ) {
+
+			console.timeEnd( 'OBJLoader parse: ' + this.modelName );
+
+		}
+		return this.baseObject3d;
+
+	},
 
-	} else if ( payload.type === 'material' ) {
+	_onAssetAvailable: function ( payload ) {
 
-		this.materialHandler.addPayloadMaterials( payload );
+		if ( payload.cmd !== 'assetAvailable' ) return;
+
+		if ( payload.type === 'mesh' ) {
+
+			let meshes = this.meshReceiver.buildMeshes( payload );
+			for ( let mesh of meshes ) {
+
+				this.baseObject3d.add( mesh );
+
+			}
+
+		} else if ( payload.type === 'material' ) {
+
+			this.materialHandler.addPayloadMaterials( payload );
+
+		}
 
 	}
 
-};
+} );
 
 export { OBJLoader2 };

+ 3 - 0
examples/jsm/loaders/OBJLoader2Parallel.d.ts

@@ -16,4 +16,7 @@ export class OBJLoader2Parallel extends OBJLoader2 {
   setExecuteParallel(executeParallel: boolean): this;
   getWorkerExecutionSupport(): object;
   buildWorkerCode(): object;
+
+  // @ts-ignore
+  parse(content: ArrayBuffer): void;
 }

+ 134 - 129
examples/jsm/loaders/OBJLoader2Parallel.js

@@ -31,180 +31,185 @@ const OBJLoader2Parallel = function ( manager ) {
 	OBJLoader2.call( this, manager );
 	this.preferJsmWorker = false;
 
-	this.callbacks.onParseComplete = null;
+	this.parser.callbacks.onParseComplete = null;
 	this.executeParallel = true;
 	this.workerExecutionSupport = new WorkerExecutionSupport();
 
 };
-OBJLoader2Parallel.prototype = Object.create( OBJLoader2.prototype );
-OBJLoader2Parallel.prototype.constructor = OBJLoader2Parallel;
 
-OBJLoader2Parallel.OBJLOADER2_PARALLEL_VERSION = '3.0.0';
+OBJLoader2Parallel.OBJLOADER2_PARALLEL_VERSION = '3.0.1';
 console.info( 'Using OBJLoader2Parallel version: ' + OBJLoader2Parallel.OBJLOADER2_PARALLEL_VERSION );
 
 
-OBJLoader2Parallel.prototype.setPreferJsmWorker = function ( preferJsmWorker ) {
+OBJLoader2Parallel.prototype = Object.assign( Object.create( OBJLoader2.prototype ), {
 
-	this.preferJsmWorker = preferJsmWorker === true;
-	return this;
+	constructor: OBJLoader2Parallel,
 
-};
+	setPreferJsmWorker: function ( preferJsmWorker ) {
 
-/**
- * If this call back is not set, then the completion message from worker will not be received.
- *
- * @param {function} onParseComplete
- * @return {OBJLoader2Parallel}
- */
-OBJLoader2Parallel.prototype.setCallbackOnParseComplete = function ( onParseComplete ) {
+		this.preferJsmWorker = preferJsmWorker === true;
+		return this;
 
-	if ( onParseComplete !== undefined && onParseComplete !== null ) {
+	},
 
-		this.callbacks.onParseComplete = onParseComplete;
+	/**
+	 * If this call back is not set, then the completion message from worker will not be received.
+	 *
+	 * @param {function} onParseComplete
+	 * @return {OBJLoader2Parallel}
+	 */
+	setCallbackOnParseComplete: function ( onParseComplete ) {
 
-	}
-	return this;
+		if ( onParseComplete !== undefined && onParseComplete !== null ) {
 
-};
+			this.parser.callbacks.onParseComplete = onParseComplete;
 
-/**
- * Execution of parse in parallel via Worker is default, but normal {OBJLoader2} parsing can be enforced via false here.
- *
- * @param executeParallel
- * @return {OBJLoader2Parallel}
- */
-OBJLoader2Parallel.prototype.setExecuteParallel = function ( executeParallel ) {
+		}
+		return this;
 
-	this.executeParallel = executeParallel === true;
-	return this;
+	},
 
-};
+	/**
+	 * Execution of parse in parallel via Worker is default, but normal {OBJLoader2} parsing can be enforced via false here.
+	 *
+	 * @param executeParallel
+	 * @return {OBJLoader2Parallel}
+	 */
+	setExecuteParallel: function ( executeParallel ) {
 
-/**
- * Allow to get hold of {WorkerExecutionSupport} for configuratin purposes
- *
- * @return {WorkerExecutionSupport|WorkerExecutionSupport}
- */
-OBJLoader2Parallel.prototype.getWorkerExecutionSupport = function () {
+		this.executeParallel = executeParallel === true;
+		return this;
 
-	return this.workerExecutionSupport;
+	},
 
-};
+	/**
+	 * Allow to get hold of {WorkerExecutionSupport} for configuratin purposes
+	 *
+	 * @return {WorkerExecutionSupport|WorkerExecutionSupport}
+	 */
+	getWorkerExecutionSupport: function () {
 
-/**
- * Provides instructions on what is to be contained in the worker
- *
- * @return {CodeBuilderInstructions}
- */
-OBJLoader2Parallel.prototype.buildWorkerCode = function () {
+		return this.workerExecutionSupport;
 
-	let codeBuilderInstructions = new CodeBuilderInstructions( true, true, this.preferJsmWorker );
-	if ( codeBuilderInstructions.isSupportsJsmWorker() ) {
+	},
 
-		codeBuilderInstructions.setJsmWorkerFile( '../../src/loaders/worker/parallel/jsm/OBJLoader2Worker.js' );
+	/**
+	 * Provides instructions on what is to be contained in the worker
+	 *
+	 * @return {CodeBuilderInstructions}
+	 */
+	buildWorkerCode: function () {
 
-	}
-	if ( codeBuilderInstructions.isSupportsStandardWorker() ) {
+		let codeBuilderInstructions = new CodeBuilderInstructions( true, true, this.preferJsmWorker );
+		if ( codeBuilderInstructions.isSupportsJsmWorker() ) {
 
-		let codeOBJLoader2Parser = CodeSerializer.serializeClass( 'OBJLoader2Parser', OBJLoader2Parser );
-		let codeObjectManipulator = CodeSerializer.serializeObject( 'ObjectManipulator', ObjectManipulator );
-		let codeParserPayloadHandler = CodeSerializer.serializeClass( 'DefaultWorkerPayloadHandler', DefaultWorkerPayloadHandler );
-		let codeWorkerRunner = CodeSerializer.serializeClass( 'WorkerRunner', WorkerRunner );
+			codeBuilderInstructions.setJsmWorkerFile( '../../src/loaders/worker/parallel/jsm/OBJLoader2Worker.js' );
 
-		codeBuilderInstructions.addCodeFragment( codeOBJLoader2Parser );
-		codeBuilderInstructions.addCodeFragment( codeObjectManipulator );
-		codeBuilderInstructions.addCodeFragment( codeParserPayloadHandler );
-		codeBuilderInstructions.addCodeFragment( codeWorkerRunner );
+		}
+		if ( codeBuilderInstructions.isSupportsStandardWorker() ) {
 
-		codeBuilderInstructions.addStartCode( 'new WorkerRunner( new DefaultWorkerPayloadHandler( new OBJLoader2Parser() ) );' );
+			let codeOBJLoader2Parser = CodeSerializer.serializeClass( 'OBJLoader2Parser', OBJLoader2Parser );
+			let codeObjectManipulator = CodeSerializer.serializeObject( 'ObjectManipulator', ObjectManipulator );
+			let codeParserPayloadHandler = CodeSerializer.serializeClass( 'DefaultWorkerPayloadHandler', DefaultWorkerPayloadHandler );
+			let codeWorkerRunner = CodeSerializer.serializeClass( 'WorkerRunner', WorkerRunner );
 
-	}
-	return codeBuilderInstructions;
+			codeBuilderInstructions.addCodeFragment( codeOBJLoader2Parser );
+			codeBuilderInstructions.addCodeFragment( codeObjectManipulator );
+			codeBuilderInstructions.addCodeFragment( codeParserPayloadHandler );
+			codeBuilderInstructions.addCodeFragment( codeWorkerRunner );
 
-};
+			codeBuilderInstructions.addStartCode( 'new WorkerRunner( new DefaultWorkerPayloadHandler( new OBJLoader2Parser() ) );' );
 
-/**
- * @private
- */
-OBJLoader2Parallel.prototype._configure = function () {
+		}
+		return codeBuilderInstructions;
 
-	if ( this.callbacks.onParseComplete === null ) {
+	},
 
-		throw "No callbackOnLoad was provided! Aborting!";
+	/**
+	 * @private
+	 */
+	_configure: function () {
 
-	}
-	// check if worker is already available and if so, then fast-fail
-	if ( this.workerExecutionSupport.isWorkerLoaded( this.preferJsmWorker ) ) return;
+		if ( this.parser.callbacks.onParseComplete === null ) {
 
-	this.workerExecutionSupport.buildWorker( this.buildWorkerCode() );
+			throw "No callbackOnLoad was provided! Aborting!";
 
-	let scope = this;
-	let scopedOnAssetAvailable = function ( payload ) {
+		}
+		// check if worker is already available and if so, then fast-fail
+		if ( this.workerExecutionSupport.isWorkerLoaded( this.preferJsmWorker ) ) return;
 
-		scope._onAssetAvailable( payload );
+		this.workerExecutionSupport.buildWorker( this.buildWorkerCode() );
 
-	};
+		let scope = this;
+		let scopedOnAssetAvailable = function ( payload ) {
 
-	this.workerExecutionSupport.updateCallbacks( scopedOnAssetAvailable, this.callbacks.onParseComplete );
+			scope._onAssetAvailable( payload );
 
-};
+		};
 
-/**
- * Load is intercepted from {OBJLoader2}. It replaces the regular onLoad callback as the final worker result will be
- * returned later by its own callbackOnLoad.
- *
- * @param {string}  url A string containing the path/URL of the file to be loaded.
- * @param {function} onLoad A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument.
- * @param {function} [onFileLoadProgress] 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 {function} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument.
- * @param {function} [onMeshAlter] Called after worker successfully delivered a single mesh
- */
-OBJLoader2Parallel.prototype.load = function ( content, onLoad, onFileLoadProgress, onError, onMeshAlter ) {
+		this.workerExecutionSupport.updateCallbacks( scopedOnAssetAvailable, this.parser.callbacks.onParseComplete );
 
-	this.setCallbackOnParseComplete( onLoad );
+	},
 
-	OBJLoader2.prototype.load.call( this, content, function () {}, onFileLoadProgress, onError, onMeshAlter );
+	/**
+	 * Load is intercepted from {OBJLoader2}. It replaces the regular onLoad callback as the final worker result will be
+	 * returned later by its own callbackOnLoad.
+	 *
+	 * @param {string}  url A string containing the path/URL of the file to be loaded.
+	 * @param {function} onLoad A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument.
+	 * @param {function} [onFileLoadProgress] 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 {function} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument.
+	 * @param {function} [onMeshAlter] Called after worker successfully delivered a single mesh
+	 */
+	load: function ( content, onLoad, onFileLoadProgress, onError, onMeshAlter ) {
 
-};
+		this.setCallbackOnParseComplete( onLoad );
 
-/**
- * Parses OBJ data in parallel with web worker.
- *
- * @param {arraybuffer} content OBJ data as Uint8Array or String
- */
-OBJLoader2Parallel.prototype.parse = function ( content ) {
-
-	if ( this.executeParallel ) {
-
-		this._configure();
-
-		this.workerExecutionSupport.executeParallel(
-			{
-				params: {
-					modelName: this.modelName,
-					instanceNo: this.instanceNo,
-					useIndices: this.useIndices,
-					disregardNormals: this.disregardNormals,
-					materialPerSmoothingGroup: this.materialPerSmoothingGroup,
-					useOAsMesh: this.useOAsMesh,
-				},
-				materials: this.materialHandler.getMaterialsJSON(),
-				data: {
-					input: content,
-					options: null
-				},
-				logging: {
-					enabled: this.logging.enabled,
-					debug: this.logging.debug
-				}
-			} );
-
-	} else {
-
-		this.callbacks.onParseComplete( OBJLoader2.prototype.parse.call( this, content ) );
-
-	}
+		OBJLoader2.prototype.load.call( this, content, function () {
+		}, onFileLoadProgress, onError, onMeshAlter );
 
-};
+	},
+
+	/**
+	 * Parses OBJ data in parallel with web worker.
+	 *
+	 * @param {arraybuffer} content OBJ data as Uint8Array or String
+	 */
+	parse: function ( content ) {
+
+		if ( this.executeParallel ) {
+
+			this._configure();
+
+			this.workerExecutionSupport.executeParallel(
+				{
+					params: {
+						modelName: this.modelName,
+						instanceNo: this.instanceNo,
+						useIndices: this.parser.useIndices,
+						disregardNormals: this.parser.disregardNormals,
+						materialPerSmoothingGroup: this.parser.materialPerSmoothingGroup,
+						useOAsMesh: this.parser.useOAsMesh,
+					},
+					materials: this.materialHandler.getMaterialsJSON(),
+					data: {
+						input: content,
+						options: null
+					},
+					logging: {
+						enabled: this.parser.logging.enabled,
+						debug: this.parser.logging.debug
+					}
+				} );
+
+		} else {
+
+			this.parser.callbacks.onParseComplete( OBJLoader2.prototype.parse.call( this, content ) );
+
+		}
+
+	},
+
+} );
 
 export { OBJLoader2Parallel };

+ 1 - 1
examples/jsm/loaders/obj2/shared/MaterialHandler.js

@@ -172,7 +172,7 @@ MaterialHandler.prototype = {
 				material = materials[ materialName ];
 				this.materials[ materialName ] = material;
 				newMaterials[ materialName ] = material;
-				if ( this.logging.enabled ) console.info( 'Material with name "' + materialName + '" was added.' );
+				if ( this.logging.enabled && this.logging.debug ) console.info( 'Material with name "' + materialName + '" was added.' );
 
 			}