Skip to content

Commit cf15b51

Browse files
committed
OBJLoader2 V2.3.0:
#28 Parser Validation. Parser now is one single class: THREE.LoaderSupport.Parser.Obj. This way existing constructor and usage of OBJLoader2 is kept. Simplified code, fixed bugs missing 'g' statements) and introduced obj_obj2 verification examples with gulpfile to re-create verify.obj. #31 Worker code still works when mangling is used during minification. Needed to remove Consts. #32 THREE.LoaderSupport.ConsoleLogger: Allow to pass additional arguments to error, warn, info and debug Fixed CRLF issues. Now all files has unix line-endings
1 parent a885290 commit cf15b51

File tree

12 files changed

+3251
-2680
lines changed

12 files changed

+3251
-2680
lines changed

docs/examples/loaders/LoaderSupport.html

Lines changed: 675 additions & 671 deletions
Large diffs are not rendered by default.

examples/files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ var files = {
107107
"webgl_loader_nodes",
108108
"webgl_loader_obj",
109109
"webgl_loader_obj_mtl",
110+
"webgl_loader_obj_obj2_verify",
110111
"webgl_loader_obj2",
111112
"webgl_loader_obj2_meshspray",
112113
"webgl_loader_obj2_options",

examples/js/loaders/LoaderSupport.js

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,39 +93,52 @@ THREE.LoaderSupport.ConsoleLogger = (function () {
9393
* @memberOf THREE.LoaderSupport.ConsoleLogger
9494
*
9595
* @param {string} message Message to log
96+
* @param {string[]} additional Array of strings containing additional content to be logged
97+
*
9698
*/
97-
ConsoleLogger.prototype.logDebug = function ( message ) {
98-
if ( this.enabled && this.debug ) console.info( message );
99+
ConsoleLogger.prototype.logDebug = function ( message, additional ) {
100+
if ( this.enabled && this.debug ) {
101+
102+
this._createStatement( message, 'Additional content:', additional, function ( output ) { console.debug( output ) } );
103+
104+
}
99105
};
100106

101107
/**
102108
* Log an info message if enabled.
103109
* @memberOf THREE.LoaderSupport.ConsoleLogger
104110
*
105111
* @param {string} message Message to log
112+
* @param {string[]} additional Array of strings containing additional content to be logged
106113
*/
107-
ConsoleLogger.prototype.logInfo = function ( message ) {
108-
if ( this.enabled ) console.info( message );
114+
ConsoleLogger.prototype.logInfo = function ( message, additional ) {
115+
if ( this.enabled ) {
116+
117+
this._createStatement( message, 'Additional content:', additional, function ( output ) { console.info( output ) } );
118+
119+
}
109120
};
110121

111122
/**
112123
* Log a warn message (always).
113124
* @memberOf THREE.LoaderSupport.ConsoleLogger
114125
*
115126
* @param {string} message Message to log
127+
* @param {string[]} additional Array of strings containing additional content to be logged
116128
*/
117-
ConsoleLogger.prototype.logWarn = function ( message ) {
118-
console.warn( message );
129+
ConsoleLogger.prototype.logWarn = function ( message, additional ) {
130+
this._createStatement( message, 'Additional content:', additional, function ( output ) { console.warn( output ) } );
119131
};
120132

121133
/**
122134
* Log an error message (always).
123135
* @memberOf THREE.LoaderSupport.ConsoleLogger
124136
*
125137
* @param {string} message Message to log
138+
* @param {string[]} additional Array of strings containing additional content to be logged
126139
*/
127-
ConsoleLogger.prototype.logError = function ( message ) {
128-
console.error( message );
140+
ConsoleLogger.prototype.logError = function ( message, additional ) {
141+
this._createStatement( message, 'Additional content:', additional, function ( output ) { console.error( output ) } );
129142
};
130143

131144
/**
@@ -148,6 +161,16 @@ THREE.LoaderSupport.ConsoleLogger = (function () {
148161
if ( this.enabled ) console.timeEnd( id );
149162
};
150163

164+
ConsoleLogger.prototype._createStatement = function ( message, addHeader, additional, logFunction ) {
165+
var output = message;
166+
if ( Array.isArray( additional ) ) {
167+
168+
output += '\n' + addHeader + '\n' + additional.join( '\n' );
169+
170+
}
171+
logFunction( output );
172+
};
173+
151174
return ConsoleLogger;
152175
})();
153176

@@ -428,6 +451,10 @@ THREE.LoaderSupport.PrepData = (function () {
428451
return PrepData;
429452
})();
430453

454+
THREE.LoaderSupport.Parser = {
455+
Obj: null
456+
};
457+
431458
/**
432459
* Builds one or many THREE.Mesh from one raw set of Arraybuffers, materialGroup descriptions and further parameters.
433460
* Supports vertex, vertexColor, normal, uv and index buffers.
@@ -989,7 +1016,7 @@ THREE.LoaderSupport.WorkerRunnerRefImpl = (function () {
9891016
*/
9901017
THREE.LoaderSupport.WorkerSupport = (function () {
9911018

992-
var WORKER_SUPPORT_VERSION = '2.0.1';
1019+
var WORKER_SUPPORT_VERSION = '2.1.2';
9931020

9941021
var Validator = THREE.LoaderSupport.Validator;
9951022

@@ -1159,11 +1186,12 @@ THREE.LoaderSupport.WorkerSupport = (function () {
11591186
* @memberOf THREE.LoaderSupport.WorkerSupport
11601187
*
11611188
* @param {Function} functionCodeBuilder Function that is invoked with funcBuildObject and funcBuildSingelton that allows stringification of objects and singletons.
1189+
* @param {String} parserName Name of the Parser object
11621190
* @param {String[]} libLocations URL of libraries that shall be added to worker code relative to libPath
11631191
* @param {String} libPath Base path used for loading libraries
11641192
* @param {THREE.LoaderSupport.WorkerRunnerRefImpl} runnerImpl The default worker parser wrapper implementation (communication and execution). An extended class could be passed here.
11651193
*/
1166-
WorkerSupport.prototype.validate = function ( functionCodeBuilder, libLocations, libPath, runnerImpl ) {
1194+
WorkerSupport.prototype.validate = function ( functionCodeBuilder, parserName, libLocations, libPath, runnerImpl ) {
11671195
if ( Validator.isValid( this.loaderWorker.worker ) ) return;
11681196

11691197
this.logger.logInfo( 'WorkerSupport: Building worker code...' );
@@ -1181,7 +1209,8 @@ THREE.LoaderSupport.WorkerSupport = (function () {
11811209
}
11821210

11831211
var userWorkerCode = functionCodeBuilder( buildObject, buildSingelton );
1184-
userWorkerCode += buildSingelton( runnerImpl.name, runnerImpl.name, runnerImpl );
1212+
userWorkerCode += 'var Parser = '+ parserName + ';\n\n';
1213+
userWorkerCode += buildSingelton( runnerImpl.name, runnerImpl );
11851214
userWorkerCode += 'new ' + runnerImpl.name + '();\n\n';
11861215

11871216
var scope = this;
@@ -1282,10 +1311,9 @@ THREE.LoaderSupport.WorkerSupport = (function () {
12821311
return objectString;
12831312
};
12841313

1285-
var buildSingelton = function ( fullName, internalName, object ) {
1314+
var buildSingelton = function ( fullName, object ) {
12861315
var objectString = fullName + ' = (function () {\n\n';
12871316
objectString += '\t' + object.prototype.constructor.toString() + '\n\n';
1288-
objectString = objectString.replace( object.name, internalName );
12891317

12901318
var funcString;
12911319
var objectPart;
@@ -1295,12 +1323,12 @@ THREE.LoaderSupport.WorkerSupport = (function () {
12951323
if ( typeof objectPart === 'function' ) {
12961324

12971325
funcString = objectPart.toString();
1298-
objectString += '\t' + internalName + '.prototype.' + name + ' = ' + funcString + ';\n\n';
1326+
objectString += '\t' + object.name + '.prototype.' + name + ' = ' + funcString + ';\n\n';
12991327

13001328
}
13011329

13021330
}
1303-
objectString += '\treturn ' + internalName + ';\n';
1331+
objectString += '\treturn ' + object.name + ';\n';
13041332
objectString += '})();\n\n';
13051333

13061334
return objectString;

0 commit comments

Comments
 (0)