|
@@ -8,10 +8,17 @@
|
|
|
*/
|
|
|
const OBJLoader2Parser = function () {
|
|
|
|
|
|
+ let scope = this;
|
|
|
this.callbacks = {
|
|
|
- onProgress: null,
|
|
|
- onAssetAvailable: null,
|
|
|
- onError: null
|
|
|
+ onProgress: function ( type, text, numericalValue ) {
|
|
|
+ scope._onProgress( type, text, numericalValue )
|
|
|
+ },
|
|
|
+ onAssetAvailable: function ( payload ) {
|
|
|
+ scope._onAssetAvailable( payload )
|
|
|
+ },
|
|
|
+ onError: function ( errorMessage ) {
|
|
|
+ scope._onError( errorMessage )
|
|
|
+ }
|
|
|
};
|
|
|
this.contentRef = null;
|
|
|
this.legacyMode = false;
|
|
@@ -72,7 +79,7 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
constructor: OBJLoader2Parser,
|
|
|
|
|
|
- resetRawMesh: function () {
|
|
|
+ _resetRawMesh: function () {
|
|
|
|
|
|
// faces are stored according combined index of group, material and smoothingGroup (0 or not)
|
|
|
this.rawMesh.subGroups = [];
|
|
@@ -81,7 +88,7 @@ OBJLoader2Parser.prototype = {
|
|
|
this.rawMesh.smoothingGroup.real = - 1;
|
|
|
|
|
|
// this default index is required as it is possible to define faces without 'g' or 'usemtl'
|
|
|
- this.pushSmoothingGroup( 1 );
|
|
|
+ this._pushSmoothingGroup( 1 );
|
|
|
|
|
|
this.rawMesh.counts.doubleIndicesCount = 0;
|
|
|
this.rawMesh.counts.faceCount = 0;
|
|
@@ -90,31 +97,59 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * Tells whether a material shall be created per smoothing group.
|
|
|
+ *
|
|
|
+ * @param {boolean} materialPerSmoothingGroup=false
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
setMaterialPerSmoothingGroup: function ( materialPerSmoothingGroup ) {
|
|
|
|
|
|
- this.materialPerSmoothingGroup = materialPerSmoothingGroup;
|
|
|
+ this.materialPerSmoothingGroup = materialPerSmoothingGroup === true;
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * Usually 'o' is meta-information and does not result in creation of new meshes, but mesh creation on occurrence of "o" can be enforced.
|
|
|
+ *
|
|
|
+ * @param {boolean} useOAsMesh=false
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
setUseOAsMesh: function ( useOAsMesh ) {
|
|
|
|
|
|
- this.useOAsMesh = useOAsMesh;
|
|
|
+ this.useOAsMesh = useOAsMesh === true;
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * Instructs loaders to create indexed {@link BufferGeometry}.
|
|
|
+ *
|
|
|
+ * @param {boolean} useIndices=false
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
setUseIndices: function ( useIndices ) {
|
|
|
|
|
|
- this.useIndices = useIndices;
|
|
|
+ this.useIndices = useIndices === true;
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * Tells whether normals should be completely disregarded and regenerated.
|
|
|
+ *
|
|
|
+ * @param {boolean} disregardNormals=false
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
setDisregardNormals: function ( disregardNormals ) {
|
|
|
|
|
|
- this.disregardNormals = disregardNormals;
|
|
|
+ this.disregardNormals = disregardNormals === true;
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- setMaterials: function ( materials ) {
|
|
|
+ _setMaterials: function ( materials ) {
|
|
|
|
|
|
if ( materials === undefined || materials === null ) return;
|
|
|
|
|
@@ -130,60 +165,129 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * Register a function that is called once an asset (mesh/material) becomes available.
|
|
|
+ *
|
|
|
+ * @param onAssetAvailable
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
setCallbackOnAssetAvailable: function ( onAssetAvailable ) {
|
|
|
|
|
|
- if ( onAssetAvailable !== null && onAssetAvailable !== undefined ) {
|
|
|
+ if ( onAssetAvailable !== null && onAssetAvailable !== undefined && onAssetAvailable instanceof Function ) {
|
|
|
|
|
|
this.callbacks.onAssetAvailable = onAssetAvailable;
|
|
|
|
|
|
}
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * Register a function that is used to report overall processing progress.
|
|
|
+ *
|
|
|
+ * @param {Function} onProgress
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
setCallbackOnProgress: function ( onProgress ) {
|
|
|
|
|
|
- if ( onProgress !== null && onProgress !== undefined ) {
|
|
|
+ if ( onProgress !== null && onProgress !== undefined && onProgress instanceof Function ) {
|
|
|
|
|
|
this.callbacks.onProgress = onProgress;
|
|
|
|
|
|
}
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * Register an error handler function that is called if errors occur. It can decide to just log or to throw an exception.
|
|
|
+ *
|
|
|
+ * @param {Function} onError
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
setCallbackOnError: function ( onError ) {
|
|
|
|
|
|
- if ( onError !== null && onError !== undefined ) {
|
|
|
+ if ( onError !== null && onError !== undefined && onError instanceof Function ) {
|
|
|
|
|
|
this.callbacks.onError = onError;
|
|
|
|
|
|
}
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- setLogging: function ( enabled, debug ) {
|
|
|
+ /**
|
|
|
+ * Announce feedback which is give to the registered callbacks.
|
|
|
+ * @private
|
|
|
+ *
|
|
|
+ * @param {string} type The type of event
|
|
|
+ * @param {string} text Textual description of the event
|
|
|
+ * @param {number} numericalValue Numerical value describing the progress
|
|
|
+ */
|
|
|
+ _onProgress: function ( type, text, numericalValue ) {
|
|
|
+
|
|
|
+ let message = text ? text : '';
|
|
|
+ let event = {
|
|
|
+ detail: {
|
|
|
+ type: type,
|
|
|
+ modelName: this.modelName,
|
|
|
+ instanceNo: this.instanceNo,
|
|
|
+ text: message,
|
|
|
+ numericalValue: numericalValue
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- this.logging.enabled = enabled === true;
|
|
|
- this.logging.debug = debug === true;
|
|
|
+ if ( this.logging.enabled && this.logging.debug ) {
|
|
|
+
|
|
|
+ console.log( message );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Announce error feedback which is given to the generic error handler to the registered callbacks.
|
|
|
+ * @private
|
|
|
+ *
|
|
|
+ * @param {String} errorMessage The event containing the error
|
|
|
+ */
|
|
|
+ _onError: function ( errorMessage ) {
|
|
|
+
|
|
|
+ if ( this.logging.enabled && this.logging.debug ) {
|
|
|
+
|
|
|
+ console.error( errorMessage );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
},
|
|
|
|
|
|
- configure: function () {
|
|
|
+ _onAssetAvailable: function ( payload ) {
|
|
|
|
|
|
- if ( this.callbacks.onAssetAvailable === null ) {
|
|
|
+ let errorMessage = 'OBJLoader2Parser does not provide implementation for onAssetAvailable. Aborting...';
|
|
|
+ this.callbacks.onError( errorMessage );
|
|
|
+ throw errorMessage;
|
|
|
|
|
|
- let errorMessage = 'Unable to run as no callback for building meshes is set.';
|
|
|
- if ( this.callbacks.onError !== null ) {
|
|
|
+ },
|
|
|
|
|
|
- this.callbacks.onError( errorMessage );
|
|
|
+ /**
|
|
|
+ * Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
|
|
|
+ *
|
|
|
+ * @param {boolean} enabled True or false.
|
|
|
+ * @param {boolean} debug True or false.
|
|
|
+ *
|
|
|
+ * @return {OBJLoader2Parser}
|
|
|
+ */
|
|
|
+ setLogging: function ( enabled, debug ) {
|
|
|
|
|
|
- } else {
|
|
|
+ this.logging.enabled = enabled === true;
|
|
|
+ this.logging.debug = debug === true;
|
|
|
+ return this;
|
|
|
|
|
|
- throw errorMessage;
|
|
|
+ },
|
|
|
|
|
|
- }
|
|
|
+ _configure: function () {
|
|
|
|
|
|
- }
|
|
|
- this.pushSmoothingGroup( 1 );
|
|
|
+ this._pushSmoothingGroup( 1 );
|
|
|
if ( this.logging.enabled ) {
|
|
|
|
|
|
let matKeys = Object.keys( this.materials );
|
|
@@ -194,21 +298,9 @@ OBJLoader2Parser.prototype = {
|
|
|
+ '\n\tuseOAsMesh: ' + this.useOAsMesh
|
|
|
+ '\n\tuseIndices: ' + this.useIndices
|
|
|
+ '\n\tdisregardNormals: ' + this.disregardNormals;
|
|
|
- if ( this.callbacks.onProgress !== null ) {
|
|
|
-
|
|
|
- printedConfig += '\n\tcallbacks.onProgress: ' + this.callbacks.onProgress.name;
|
|
|
-
|
|
|
- }
|
|
|
- if ( this.callbacks.onAssetAvailable !== null ) {
|
|
|
-
|
|
|
- printedConfig += '\n\tcallbacks.onAssetAvailable: ' + this.callbacks.onAssetAvailable.name;
|
|
|
-
|
|
|
- }
|
|
|
- if ( this.callbacks.onError !== null ) {
|
|
|
-
|
|
|
- printedConfig += '\n\tcallbacks.onError: ' + this.callbacks.onError.name;
|
|
|
-
|
|
|
- }
|
|
|
+ printedConfig += '\n\tcallbacks.onProgress: ' + this.callbacks.onProgress.name;
|
|
|
+ printedConfig += '\n\tcallbacks.onAssetAvailable: ' + this.callbacks.onAssetAvailable.name;
|
|
|
+ printedConfig += '\n\tcallbacks.onError: ' + this.callbacks.onError.name;
|
|
|
console.info( printedConfig );
|
|
|
|
|
|
}
|
|
@@ -220,10 +312,10 @@ OBJLoader2Parser.prototype = {
|
|
|
*
|
|
|
* @param {Uint8Array} arrayBuffer OBJ data as Uint8Array
|
|
|
*/
|
|
|
- parse: function ( arrayBuffer ) {
|
|
|
+ execute: function ( arrayBuffer ) {
|
|
|
|
|
|
- if ( this.logging.enabled ) console.time( 'OBJLoader.Parser.parse' );
|
|
|
- this.configure();
|
|
|
+ if ( this.logging.enabled ) console.time( 'OBJLoader2Parser.execute' );
|
|
|
+ this._configure();
|
|
|
|
|
|
let arrayBufferView = new Uint8Array( arrayBuffer );
|
|
|
this.contentRef = arrayBufferView;
|
|
@@ -254,7 +346,7 @@ OBJLoader2Parser.prototype = {
|
|
|
word = '';
|
|
|
this.globalCounts.lineByte = this.globalCounts.currentByte;
|
|
|
this.globalCounts.currentByte = i;
|
|
|
- this.processLine( buffer, bufferPointer, slashesCount );
|
|
|
+ this._processLine( buffer, bufferPointer, slashesCount );
|
|
|
bufferPointer = 0;
|
|
|
slashesCount = 0;
|
|
|
break;
|
|
@@ -270,8 +362,8 @@ OBJLoader2Parser.prototype = {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- this.finalizeParsing();
|
|
|
- if ( this.logging.enabled ) console.timeEnd( 'OBJLoader.Parser.parse' );
|
|
|
+ this._finalizeParsing();
|
|
|
+ if ( this.logging.enabled ) console.timeEnd( 'OBJLoader2Parser.execute' );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -280,10 +372,10 @@ OBJLoader2Parser.prototype = {
|
|
|
*
|
|
|
* @param {string} text OBJ data as string
|
|
|
*/
|
|
|
- parseText: function ( text ) {
|
|
|
+ executeLegacy: function ( text ) {
|
|
|
|
|
|
- if ( this.logging.enabled ) console.time( 'OBJLoader.Parser.parseText' );
|
|
|
- this.configure();
|
|
|
+ if ( this.logging.enabled ) console.time( 'OBJLoader2Parser.executeLegacy' );
|
|
|
+ this._configure();
|
|
|
this.legacyMode = true;
|
|
|
this.contentRef = text;
|
|
|
let length = text.length;
|
|
@@ -311,7 +403,7 @@ OBJLoader2Parser.prototype = {
|
|
|
word = '';
|
|
|
this.globalCounts.lineByte = this.globalCounts.currentByte;
|
|
|
this.globalCounts.currentByte = i;
|
|
|
- this.processLine( buffer, bufferPointer, slashesCount );
|
|
|
+ this._processLine( buffer, bufferPointer, slashesCount );
|
|
|
bufferPointer = 0;
|
|
|
slashesCount = 0;
|
|
|
break;
|
|
@@ -325,12 +417,12 @@ OBJLoader2Parser.prototype = {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- this.finalizeParsing();
|
|
|
- if ( this.logging.enabled ) console.timeEnd( 'OBJLoader.Parser.parseText' );
|
|
|
+ this._finalizeParsing();
|
|
|
+ if ( this.logging.enabled ) console.timeEnd( 'OBJLoader2Parser.executeLegacy' );
|
|
|
|
|
|
},
|
|
|
|
|
|
- processLine: function ( buffer, bufferPointer, slashesCount ) {
|
|
|
+ _processLine: function ( buffer, bufferPointer, slashesCount ) {
|
|
|
|
|
|
if ( bufferPointer < 1 ) return;
|
|
|
|
|
@@ -391,12 +483,12 @@ OBJLoader2Parser.prototype = {
|
|
|
// "f vertex ..."
|
|
|
if ( slashesCount === 0 ) {
|
|
|
|
|
|
- this.checkFaceType( 0 );
|
|
|
+ this._checkFaceType( 0 );
|
|
|
for ( i = 2, length = bufferLength; i < length; i ++ ) {
|
|
|
|
|
|
- this.buildFace( buffer[ 1 ] );
|
|
|
- this.buildFace( buffer[ i ] );
|
|
|
- this.buildFace( buffer[ i + 1 ] );
|
|
|
+ this._buildFace( buffer[ 1 ] );
|
|
|
+ this._buildFace( buffer[ i ] );
|
|
|
+ this._buildFace( buffer[ i + 1 ] );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -404,12 +496,12 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
} else if ( bufferLength === slashesCount * 2 ) {
|
|
|
|
|
|
- this.checkFaceType( 1 );
|
|
|
+ this._checkFaceType( 1 );
|
|
|
for ( i = 3, length = bufferLength - 2; i < length; i += 2 ) {
|
|
|
|
|
|
- this.buildFace( buffer[ 1 ], buffer[ 2 ] );
|
|
|
- this.buildFace( buffer[ i ], buffer[ i + 1 ] );
|
|
|
- this.buildFace( buffer[ i + 2 ], buffer[ i + 3 ] );
|
|
|
+ this._buildFace( buffer[ 1 ], buffer[ 2 ] );
|
|
|
+ this._buildFace( buffer[ i ], buffer[ i + 1 ] );
|
|
|
+ this._buildFace( buffer[ i + 2 ], buffer[ i + 3 ] );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -417,12 +509,12 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
} else if ( bufferLength * 2 === slashesCount * 3 ) {
|
|
|
|
|
|
- this.checkFaceType( 2 );
|
|
|
+ this._checkFaceType( 2 );
|
|
|
for ( i = 4, length = bufferLength - 3; i < length; i += 3 ) {
|
|
|
|
|
|
- this.buildFace( buffer[ 1 ], buffer[ 2 ], buffer[ 3 ] );
|
|
|
- this.buildFace( buffer[ i ], buffer[ i + 1 ], buffer[ i + 2 ] );
|
|
|
- this.buildFace( buffer[ i + 3 ], buffer[ i + 4 ], buffer[ i + 5 ] );
|
|
|
+ this._buildFace( buffer[ 1 ], buffer[ 2 ], buffer[ 3 ] );
|
|
|
+ this._buildFace( buffer[ i ], buffer[ i + 1 ], buffer[ i + 2 ] );
|
|
|
+ this._buildFace( buffer[ i + 3 ], buffer[ i + 4 ], buffer[ i + 5 ] );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -430,12 +522,12 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- this.checkFaceType( 3 );
|
|
|
+ this._checkFaceType( 3 );
|
|
|
for ( i = 3, length = bufferLength - 2; i < length; i += 2 ) {
|
|
|
|
|
|
- this.buildFace( buffer[ 1 ], undefined, buffer[ 2 ] );
|
|
|
- this.buildFace( buffer[ i ], undefined, buffer[ i + 1 ] );
|
|
|
- this.buildFace( buffer[ i + 2 ], undefined, buffer[ i + 3 ] );
|
|
|
+ this._buildFace( buffer[ 1 ], undefined, buffer[ 2 ] );
|
|
|
+ this._buildFace( buffer[ i ], undefined, buffer[ i + 1 ] );
|
|
|
+ this._buildFace( buffer[ i + 2 ], undefined, buffer[ i + 3 ] );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -447,30 +539,30 @@ OBJLoader2Parser.prototype = {
|
|
|
bufferLength = bufferPointer - 1;
|
|
|
if ( bufferLength === slashesCount * 2 ) {
|
|
|
|
|
|
- this.checkFaceType( 4 );
|
|
|
- for ( i = 1, length = bufferLength + 1; i < length; i += 2 ) this.buildFace( buffer[ i ], buffer[ i + 1 ] );
|
|
|
+ this._checkFaceType( 4 );
|
|
|
+ for ( i = 1, length = bufferLength + 1; i < length; i += 2 ) this._buildFace( buffer[ i ], buffer[ i + 1 ] );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- this.checkFaceType( ( lineDesignation === 'l' ) ? 5 : 6 );
|
|
|
- for ( i = 1, length = bufferLength + 1; i < length; i ++ ) this.buildFace( buffer[ i ] );
|
|
|
+ this._checkFaceType( ( lineDesignation === 'l' ) ? 5 : 6 );
|
|
|
+ for ( i = 1, length = bufferLength + 1; i < length; i ++ ) this._buildFace( buffer[ i ] );
|
|
|
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 's':
|
|
|
- this.pushSmoothingGroup( buffer[ 1 ] );
|
|
|
+ this._pushSmoothingGroup( buffer[ 1 ] );
|
|
|
break;
|
|
|
|
|
|
case 'g':
|
|
|
// 'g' leads to creation of mesh if valid data (faces declaration was done before), otherwise only groupName gets set
|
|
|
- this.processCompletedMesh();
|
|
|
+ this._processCompletedMesh();
|
|
|
this.rawMesh.groupName = reconstructString( this.contentRef, this.legacyMode, this.globalCounts.lineByte + 2, this.globalCounts.currentByte );
|
|
|
break;
|
|
|
|
|
|
case 'o':
|
|
|
// 'o' is meta-information and usually does not result in creation of new meshes, but can be enforced with "useOAsMesh"
|
|
|
- if ( this.useOAsMesh ) this.processCompletedMesh();
|
|
|
+ if ( this.useOAsMesh ) this._processCompletedMesh();
|
|
|
this.rawMesh.objectName = reconstructString( this.contentRef, this.legacyMode, this.globalCounts.lineByte + 2, this.globalCounts.currentByte );
|
|
|
break;
|
|
|
|
|
@@ -484,7 +576,7 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
this.rawMesh.activeMtlName = mtlName;
|
|
|
this.rawMesh.counts.mtlCount ++;
|
|
|
- this.checkSubGroup();
|
|
|
+ this._checkSubGroup();
|
|
|
|
|
|
}
|
|
|
break;
|
|
@@ -496,7 +588,7 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- pushSmoothingGroup: function ( smoothingGroup ) {
|
|
|
+ _pushSmoothingGroup: function ( smoothingGroup ) {
|
|
|
|
|
|
let smoothingGroupInt = parseInt( smoothingGroup );
|
|
|
if ( isNaN( smoothingGroupInt ) ) {
|
|
@@ -512,7 +604,7 @@ OBJLoader2Parser.prototype = {
|
|
|
if ( smoothCheck !== smoothingGroupInt ) {
|
|
|
|
|
|
this.rawMesh.counts.smoothingGroupCount ++;
|
|
|
- this.checkSubGroup();
|
|
|
+ this._checkSubGroup();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -528,19 +620,19 @@ OBJLoader2Parser.prototype = {
|
|
|
* faceType = 5: "l vertex ..."
|
|
|
* faceType = 6: "p vertex ..."
|
|
|
*/
|
|
|
- checkFaceType: function ( faceType ) {
|
|
|
+ _checkFaceType: function ( faceType ) {
|
|
|
|
|
|
if ( this.rawMesh.faceType !== faceType ) {
|
|
|
|
|
|
- this.processCompletedMesh();
|
|
|
+ this._processCompletedMesh();
|
|
|
this.rawMesh.faceType = faceType;
|
|
|
- this.checkSubGroup();
|
|
|
+ this._checkSubGroup();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
- checkSubGroup: function () {
|
|
|
+ _checkSubGroup: function () {
|
|
|
|
|
|
let index = this.rawMesh.activeMtlName + '|' + this.rawMesh.smoothingGroup.normalized;
|
|
|
this.rawMesh.subGroupInUse = this.rawMesh.subGroups[ index ];
|
|
@@ -567,7 +659,7 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- buildFace: function ( faceIndexV, faceIndexU, faceIndexN ) {
|
|
|
+ _buildFace: function ( faceIndexV, faceIndexU, faceIndexN ) {
|
|
|
|
|
|
let subGroupInUse = this.rawMesh.subGroupInUse;
|
|
|
let scope = this;
|
|
@@ -640,7 +732,7 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- createRawMeshReport: function ( inputObjectCount ) {
|
|
|
+ _createRawMeshReport: function ( inputObjectCount ) {
|
|
|
|
|
|
return 'Input Object number: ' + inputObjectCount +
|
|
|
'\n\tObject name: ' + this.rawMesh.objectName +
|
|
@@ -658,7 +750,7 @@ OBJLoader2Parser.prototype = {
|
|
|
/**
|
|
|
* Clear any empty subGroup and calculate absolute vertex, normal and uv counts
|
|
|
*/
|
|
|
- finalizeRawMesh: function () {
|
|
|
+ _finalizeRawMesh: function () {
|
|
|
|
|
|
let meshOutputGroupTemp = [];
|
|
|
let meshOutputGroup;
|
|
@@ -717,33 +809,25 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- processCompletedMesh: function () {
|
|
|
+ _processCompletedMesh: function () {
|
|
|
|
|
|
- let result = this.finalizeRawMesh();
|
|
|
+ let result = this._finalizeRawMesh();
|
|
|
let haveMesh = result !== null;
|
|
|
if ( haveMesh ) {
|
|
|
|
|
|
if ( this.colors.length > 0 && this.colors.length !== this.vertices.length ) {
|
|
|
|
|
|
- if ( this.callbacks.onError !== null ) {
|
|
|
-
|
|
|
- this.callbacks.onError( 'Vertex Colors were detected, but vertex count and color count do not match!' );
|
|
|
-
|
|
|
- }
|
|
|
+ this.callbacks.onError( '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 ) );
|
|
|
this.inputObjectCount ++;
|
|
|
|
|
|
- this.buildMesh( result );
|
|
|
+ this._buildMesh( result );
|
|
|
let progressBytesPercent = this.globalCounts.currentByte / this.globalCounts.totalBytes;
|
|
|
- if ( this.callbacks.onProgress !== null ) {
|
|
|
-
|
|
|
- this.callbacks.onProgress( 'Completed [o: ' + this.rawMesh.objectName + ' g:' + this.rawMesh.groupName + '' +
|
|
|
+ this._onProgress( 'progressParse', 'Completed [o: ' + this.rawMesh.objectName + ' g:' + this.rawMesh.groupName + '' +
|
|
|
'] Total progress: ' + ( progressBytesPercent * 100 ).toFixed( 2 ) + '%', progressBytesPercent );
|
|
|
-
|
|
|
- }
|
|
|
- this.resetRawMesh();
|
|
|
+ this._resetRawMesh();
|
|
|
|
|
|
}
|
|
|
return haveMesh;
|
|
@@ -756,7 +840,7 @@ OBJLoader2Parser.prototype = {
|
|
|
*
|
|
|
* @param result
|
|
|
*/
|
|
|
- buildMesh: function ( result ) {
|
|
|
+ _buildMesh: function ( result ) {
|
|
|
|
|
|
let meshOutputGroups = result.subGroups;
|
|
|
|
|
@@ -965,10 +1049,10 @@ OBJLoader2Parser.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- finalizeParsing: function () {
|
|
|
+ _finalizeParsing: function () {
|
|
|
|
|
|
if ( this.logging.enabled ) console.info( 'Global output object count: ' + this.outputObjectCount );
|
|
|
- if ( this.processCompletedMesh() && this.logging.enabled ) {
|
|
|
+ if ( this._processCompletedMesh() && this.logging.enabled ) {
|
|
|
|
|
|
let parserFinalReport = 'Overall counts: ' +
|
|
|
'\n\tVertices: ' + this.globalCounts.vertices +
|