Browse Source

Versions are printed once
OBJLoader2Parser: Aligned V2.5.1 and this version
Moved export to the end of the file. Removed imports only used by Documentation

Kai Salmen 6 years ago
parent
commit
59d0e27bd2

+ 8 - 15
examples/jsm/loaders/OBJLoader2.js

@@ -4,21 +4,15 @@
  */
  */
 
 
 import {
 import {
-	BufferGeometry,
 	DefaultLoadingManager,
 	DefaultLoadingManager,
 	FileLoader,
 	FileLoader,
-	Group,
-	Material,
-	Object3D
+	Group
 } from "../../../build/three.module.js";
 } from "../../../build/three.module.js";
 
 
 import { Parser } from "./worker/independent/OBJLoader2Parser.js";
 import { Parser } from "./worker/independent/OBJLoader2Parser.js";
 import { MeshReceiver } from "./shared/MeshReceiver.js";
 import { MeshReceiver } from "./shared/MeshReceiver.js";
 import { MaterialHandler } from "./shared/MaterialHandler.js";
 import { MaterialHandler } from "./shared/MaterialHandler.js";
 
 
-export { OBJLoader2 };
-
-
 /**
 /**
  * Use this class to load OBJ data from files or to parse OBJ data from an arraybuffer
  * Use this class to load OBJ data from files or to parse OBJ data from an arraybuffer
  * @class
  * @class
@@ -51,16 +45,13 @@ const OBJLoader2 = function ( manager ) {
 	this.meshReceiver = new MeshReceiver( this.materialHandler );
 	this.meshReceiver = new MeshReceiver( this.materialHandler );
 };
 };
 OBJLoader2.OBJLOADER2_VERSION = '3.0.0-beta';
 OBJLoader2.OBJLOADER2_VERSION = '3.0.0-beta';
+console.info( 'Using OBJLoader2 version: ' + OBJLoader2.OBJLOADER2_VERSION );
 
 
 
 
 OBJLoader2.prototype = {
 OBJLoader2.prototype = {
 
 
 	constructor: OBJLoader2,
 	constructor: OBJLoader2,
 
 
-	printVersion: function() {
-		console.info( 'Using OBJLoader2 version: ' + OBJLoader2.OBJLOADER2_VERSION );
-	},
-
 	/**
 	/**
 	 * Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
 	 * Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
 	 *
 	 *
@@ -227,17 +218,17 @@ OBJLoader2.prototype = {
 	 * Announce error feedback which is given to the generic error handler to the registered callbacks.
 	 * Announce error feedback which is given to the generic error handler to the registered callbacks.
 	 * @private
 	 * @private
 	 *
 	 *
-	 * @param {String} message The event containing the error
+	 * @param {String} errorMessage The event containing the error
 	 */
 	 */
-	_onError: function ( message ) {
+	_onError: function ( errorMessage ) {
 		if ( this.callbacks.genericErrorHandler ) {
 		if ( this.callbacks.genericErrorHandler ) {
 
 
-			this.callbacks.genericErrorHandler( message );
+			this.callbacks.genericErrorHandler( errorMessage );
 
 
 		}
 		}
 		if ( this.logging.enabled && this.logging.debug ) {
 		if ( this.logging.enabled && this.logging.debug ) {
 
 
-			console.log( message );
+			console.log( errorMessage );
 
 
 		}
 		}
 
 
@@ -388,3 +379,5 @@ OBJLoader2.prototype = {
 		return this.baseObject3d;
 		return this.baseObject3d;
 	}
 	}
 };
 };
+
+export { OBJLoader2 };

+ 2 - 2
examples/jsm/loaders/bridge/MtlObjBridge.js

@@ -5,8 +5,6 @@
 
 
 import { MTLLoader } from "../../../jsm/loaders/MTLLoader.js";
 import { MTLLoader } from "../../../jsm/loaders/MTLLoader.js";
 
 
-export { MtlObjBridge }
-
 
 
 const MtlObjBridge = {
 const MtlObjBridge = {
 
 
@@ -39,3 +37,5 @@ const MtlObjBridge = {
 		return newMaterials;
 		return newMaterials;
 	}
 	}
 };
 };
+
+export { MtlObjBridge }

+ 2 - 3
examples/jsm/loaders/shared/MaterialHandler.js

@@ -5,15 +5,12 @@
 
 
 import {
 import {
 	LineBasicMaterial,
 	LineBasicMaterial,
-	Material,
 	MaterialLoader,
 	MaterialLoader,
 	MeshStandardMaterial,
 	MeshStandardMaterial,
 	PointsMaterial,
 	PointsMaterial,
 	VertexColors
 	VertexColors
 } from "../../../../build/three.module.js";
 } from "../../../../build/three.module.js";
 
 
-export { MaterialHandler }
-
 
 
 const MaterialHandler = function () {
 const MaterialHandler = function () {
 	this.logging = {
 	this.logging = {
@@ -206,3 +203,5 @@ MaterialHandler.prototype = {
 	}
 	}
 
 
 };
 };
+
+export { MaterialHandler }

+ 6 - 5
examples/jsm/loaders/shared/MeshReceiver.js

@@ -2,6 +2,7 @@
  * @author Kai Salmen / https://kaisalmen.de
  * @author Kai Salmen / https://kaisalmen.de
  * Development repository: https://github.com/kaisalmen/WWOBJLoader
  * Development repository: https://github.com/kaisalmen/WWOBJLoader
  */
  */
+
 import {
 import {
 	BufferAttribute,
 	BufferAttribute,
 	BufferGeometry,
 	BufferGeometry,
@@ -12,11 +13,6 @@ import {
 
 
 import { MaterialHandler } from "./MaterialHandler.js";
 import { MaterialHandler } from "./MaterialHandler.js";
 
 
-export {
-	MeshReceiver,
-	LoadedMeshUserOverride
-};
-
 
 
 /**
 /**
  *
  *
@@ -284,3 +280,8 @@ LoadedMeshUserOverride.prototype = {
 		return this.alteredMesh;
 		return this.alteredMesh;
 	}
 	}
 };
 };
+
+export {
+	MeshReceiver,
+	LoadedMeshUserOverride
+};

+ 21 - 9
examples/jsm/loaders/worker/independent/OBJLoader2Parser.js

@@ -1,11 +1,8 @@
 /**
 /**
- * @author Kai Salmen / www.kaisalmen.de
+ * @author Kai Salmen / https://kaisalmen.de
+ * Development repository: https://github.com/kaisalmen/WWOBJLoader
  */
  */
 
 
-export {
-	Parser
-};
-
 /**
 /**
  * Parse OBJ data either from ArrayBuffer or string
  * Parse OBJ data either from ArrayBuffer or string
  * @class
  * @class
@@ -107,7 +104,15 @@ Parser.prototype = {
 	},
 	},
 
 
 	setMaterials: function ( materials ) {
 	setMaterials: function ( materials ) {
-		this.materials = materials;
+		if ( materials === undefined || materials === null ) return;
+
+		for ( let materialName in materials ) {
+			if ( materials.hasOwnProperty( materialName ) ) {
+
+				this.materials[ materialName ] = materials[ materialName ];
+
+			}
+		}
 	},
 	},
 
 
 	setCallbackOnAssetAvailable: function ( onAssetAvailable ) {
 	setCallbackOnAssetAvailable: function ( onAssetAvailable ) {
@@ -140,12 +145,16 @@ Parser.prototype = {
 	},
 	},
 
 
 	configure: function () {
 	configure: function () {
-		if ( this.callbacks.onAssetAvailable !== null ) {
+		if ( this.callbacks.onAssetAvailable === null ) {
 
 
+			let errorMessage = 'Unable to run as no callback for building meshes is set.';
 			if ( this.callbacks.onError !== null ) {
 			if ( this.callbacks.onError !== null ) {
 
 
-				this.callbacks.onError( 'Unable to run as no callback for building meshes is set.' );
+				this.callbacks.onError( errorMessage );
 
 
+			} else {
+
+				throw errorMessage;
 			}
 			}
 
 
 		}
 		}
@@ -662,7 +671,8 @@ Parser.prototype = {
 			let progressBytesPercent = this.globalCounts.currentByte / this.globalCounts.totalBytes;
 			let progressBytesPercent = this.globalCounts.currentByte / this.globalCounts.totalBytes;
 			if ( this.callbacks.onProgress !== null ) {
 			if ( this.callbacks.onProgress !== null ) {
 
 
-				this.callbacks.onProgress( 'Completed [o: ' + this.rawMesh.objectName + ' g:' + this.rawMesh.groupName + '] Total progress: ' + (progressBytesPercent * 100).toFixed( 2 ) + '%', progressBytesPercent );
+				this.callbacks.onProgress( 'Completed [o: ' + this.rawMesh.objectName + ' g:' + this.rawMesh.groupName + '' +
+					'] Total progress: ' + (progressBytesPercent * 100).toFixed( 2 ) + '%', progressBytesPercent );
 
 
 			}
 			}
 			this.resetRawMesh();
 			this.resetRawMesh();
@@ -897,3 +907,5 @@ Parser.prototype = {
 		}
 		}
 	}
 	}
 };
 };
+
+export { Parser };