-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjLoader2 async worker code breaks under uglify #31
Comments
To reiterate... I'm not posting this as a bug report per se. I just wanted to illustrate a failure i encountered and it seems like there is some tantalizing room for robustifying the code a bit! But i need your help to make sense of it a little better. |
Minification with Gulp used to work fine after release of V2.x.x. I fixed previous bugs and thought I did not break it again. I will investigate. |
i have to admit i do not currently use a gulp workflow. i run uglify directly, here is my command
where
|
I use gulp-uglify 3.0.0 which uses UglifyJS2 3.1.5. The only option I set is: When I set toplevel to true as you do on cmd-line it does not work. Constructors are broken. Do you require mangle? |
As I've explained, I do not require minifying/uglifying js, so as a corollary, mangling (yes, it is a word!) is not required by me. I'm kind of curious though because it feels like it would be easy to fix it to work with mangling! Feel free to just put this issue on the back burner. I'm totally not blocked by it because I have changed my deployment to not minify any of my three.js dependencies anymore. Thanks. |
The build object/singleton build function has problems creating a valid constructor from the existing mangled code. I will see whether I can make it work by adding some additional hints/arguments to the utility function. There was a similar issue in the past. I want to make this work. Let's see... |
I'm encountering an error which seems likely to be caused by minification as well:
Comparing the output with @unphased , it seems like the Edit: After looking through the blob, it seems like |
@poacher2k on branch |
@kaisalmen: seems like I'm still getting the same error. This is the blob, error on :270
|
I'm beginning to realize this might be caused by webpack and not the loader itself. |
For example the Parser Blob code generated by THREE.LoaderSupport.ObjParser.Parser = (function () {
function e(){this.callbackProgress=null,this.callbackBuilder=null,this.materials={},this.rawMesh=null,this.useAsync=!1,this.materialPerSmoothingGroup=!1,this.useIndices=!1,this.disregardNormals=!1,this.inputObjectCount=1,this.outputObjectCount=1,this.counts={vertices:0,faces:0,doubleIndicesCount:0},this.logger=new THREE.LoaderSupport.ConsoleLogger,this.totalBytes=0}
e.prototype.setUseAsync = function (e){this.useAsync=e};
e.prototype.setMaterialPerSmoothingGroup = function (e){this.materialPerSmoothingGroup=e};
e.prototype.setUseIndices = function (e){this.useIndices=e};
e.prototype.setDisregardNormals = function (e){this.disregardNormals=e};
e.prototype.setMaterials = function (e){this.materials=THREE.LoaderSupport.Validator.verifyInput(e,this.materials),this.materials=THREE.LoaderSupport.Validator.verifyInput(this.materials,{})};
e.prototype.setCallbackBuilder = function (e){if(this.callbackBuilder=e,!THREE.LoaderSupport.Validator.isValid(this.callbackBuilder))throw'Unable to run as no "builder" callback is set.'};
e.prototype.setCallbackProgress = function (e){this.callbackProgress=e};
e.prototype.setLogConfig = function (e,t){this.logger.setEnabled(e),this.logger.setDebug(t)};
e.prototype.configure = function (){if(this.rawMesh=new THREE.LoaderSupport.ObjParser.RawMesh(this.materialPerSmoothingGroup,this.useIndices,this.disregardNormals),this.logger.isEnabled()){var e=Object.keys(this.materials),t="OBJLoader2.Parser configuration:"+(e.length>0?"\n\tmaterialNames:\n\t\t- "+e.join("\n\t\t- "):"\n\tmaterialNames: None")+"\n\tuseAsync: "+this.useAsync+"\n\tmaterialPerSmoothingGroup: "+this.materialPerSmoothingGroup+"\n\tuseIndices: "+this.useIndices+"\n\tdisregardNormals: "+this.disregardNormals+"\n\tcallbackBuilderName: "+this.callbackBuilder.name+"\n\tcallbackProgressName: "+this.callbackProgress.name;this.logger.logInfo(t)}};
e.prototype.parse = function (e){this.logger.logTimeStart("OBJLoader2.Parser.parse"),this.configure();var t=new Uint8Array(e),r=t.byteLength;this.totalBytes=r;for(var o,s=new Array(128),a=0,i=new Array(16),n=0,l="",u=0;u<r;u++)switch(o=t[u]){case THREE.LoaderSupport.ObjParser.Consts.CODE_SPACE:l.length>0&&(s[a++]=l),i[n++]=0,l="";break;case THREE.LoaderSupport.ObjParser.Consts.CODE_SLASH:l.length>0&&(s[a++]=l),i[n++]=1,l="";break;case THREE.LoaderSupport.ObjParser.Consts.CODE_LF:l.length>0&&(s[a++]=l),l="",this.processLine(s,a,i,n,u),a=0,n=0;break;case THREE.LoaderSupport.ObjParser.Consts.CODE_CR:break;default:l+=String.fromCharCode(o)}this.finalize(u),this.logger.logTimeEnd("OBJLoader2.Parser.parse")};
e.prototype.parseText = function (e){this.logger.logTimeStart("OBJLoader2.Parser.parseText"),this.configure();var t=e.length;this.totalBytes=t;for(var r,o=new Array(128),s=0,a=new Array(16),i=0,n="",l=0;l<t;l++)switch(r=e[l]){case THREE.LoaderSupport.ObjParser.Consts.STRING_SPACE:n.length>0&&(o[s++]=n),a[i++]=0,n="";break;case THREE.LoaderSupport.ObjParser.Consts.STRING_SLASH:n.length>0&&(o[s++]=n),a[i++]=1,n="";break;case THREE.LoaderSupport.ObjParser.Consts.STRING_LF:n.length>0&&(o[s++]=n),n="",this.processLine(o,s,a,i,l),s=0,i=0;break;case THREE.LoaderSupport.ObjParser.Consts.STRING_CR:break;default:n+=r}this.finalize(l),this.logger.logTimeEnd("OBJLoader2.Parser.parseText")};
e.prototype.processLine = function (e,t,r,o,s){if(!(t<1)){var a=function(e,t){for(var r=0,o=0;o<t;o++)r+=e[o];return r},i=function(e,t,r){var o="";if(2===t)o=e[1];else{for(var s=t-1,a=1;a<s;a++)o+=e[a]+(0===r[a]?" ":"/");o+=e[s]}return o},n=function(e,t){for(var r=0;r<t;r++)e[r]=""};switch(e[0]){case THREE.LoaderSupport.ObjParser.Consts.LINE_V:this.rawMesh.pushVertex(e,t>4);break;case THREE.LoaderSupport.ObjParser.Consts.LINE_VT:this.rawMesh.pushUv(e);break;case THREE.LoaderSupport.ObjParser.Consts.LINE_VN:this.rawMesh.pushNormal(e);break;case THREE.LoaderSupport.ObjParser.Consts.LINE_F:this.rawMesh.processFaces(e,t,a(r,o));break;case THREE.LoaderSupport.ObjParser.Consts.LINE_L:this.rawMesh.processLines(e,t,a(r,o));break;case THREE.LoaderSupport.ObjParser.Consts.LINE_S:this.rawMesh.pushSmoothingGroup(e[1]),n(e,t);break;case THREE.LoaderSupport.ObjParser.Consts.LINE_G:this.processCompletedMesh(s),this.rawMesh.pushGroup(i(e,t,r)),n(e,t);break;case THREE.LoaderSupport.ObjParser.Consts.LINE_O:this.rawMesh.pushObject(i(e,t,r)),n(e,t);break;case THREE.LoaderSupport.ObjParser.Consts.LINE_MTLLIB:this.rawMesh.pushMtllib(i(e,t,r)),n(e,t);break;case THREE.LoaderSupport.ObjParser.Consts.LINE_USEMTL:this.rawMesh.pushUsemtl(i(e,t,r)),n(e,t)}}};
e.prototype.createRawMeshReport = function (e,t){var r=e.createReport(t);return"Input Object number: "+t+"\n\tObject name: "+r.objectName+"\n\tGroup name: "+r.groupName+"\n\tMtllib name: "+r.mtllibName+"\n\tVertex count: "+r.vertexCount+"\n\tNormal count: "+r.normalCount+"\n\tUV count: "+r.uvCount+"\n\tSmoothingGroup count: "+r.smoothingGroupCount+"\n\tMaterial count: "+r.mtlCount+"\n\tReal RawMeshSubGroup count: "+r.subGroups};
e.prototype.processCompletedMesh = function (e){var t=this.rawMesh.finalize();if(THREE.LoaderSupport.Validator.isValid(t)){if(this.rawMesh.colors.length>0&&this.rawMesh.colors.length!==this.rawMesh.vertices.length)throw"Vertex Colors were detected, but vertex count and color count do not match!";this.logger.isDebug()&&this.logger.logDebug(this.createRawMeshReport(this.rawMesh,this.inputObjectCount)),this.inputObjectCount++,this.buildMesh(t,e);var r=e/this.totalBytes;return this.callbackProgress("Completed [o: "+this.rawMesh.objectName+" g:"+this.rawMesh.groupName+"] Total progress: "+(100*r).toFixed(2)+"%",r),this.rawMesh.reset(this.rawMesh.smoothingGroup.splitMaterials),!0}return!1};
e.prototype.finalize = function (e){if(this.logger.logInfo("Global output object count: "+this.outputObjectCount),this.processCompletedMesh(e)&&this.logger.isEnabled()){var t="Overall counts: \n\tVertices: "+this.counts.vertices+"\n\tFaces: "+this.counts.faces+"\n\tMultiple definitions: "+this.counts.doubleIndicesCount;this.logger.logInfo(t)}};
e.prototype.buildMesh = function (e,t){var r=e.subGroups,o=new Float32Array(e.absoluteVertexCount);this.counts.vertices+=e.absoluteVertexCount/3,this.counts.faces+=e.faceCount,this.counts.doubleIndicesCount+=e.doubleIndicesCount;var s,a,i,n,l,u,p,h=e.absoluteIndexCount>0?new Uint32Array(e.absoluteIndexCount):null,d=e.absoluteColorCount>0?new Float32Array(e.absoluteColorCount):null,c=e.absoluteNormalCount>0?new Float32Array(e.absoluteNormalCount):null,g=e.absoluteUvCount>0?new Float32Array(e.absoluteUvCount):null,m=THREE.LoaderSupport.Validator.isValid(d),b=[],f=r.length>1,E=0,L=[],v=[],S=0,C=0,T=0,R=0,N=0,y=0,P=0;for(var M in r)if(r.hasOwnProperty(M)){if(s=r[M],p=s.materialName,u=p+(m?"_vertexColor":"")+(0===s.smoothingGroup?"_flat":""),n=this.materials[p],l=this.materials[u],!THREE.LoaderSupport.Validator.isValid(n)&&!THREE.LoaderSupport.Validator.isValid(l)){var I=m?"vertexColorMaterial":"defaultMaterial";n=this.materials[I],this.logger.logWarn('object_group "'+s.objectName+"_"+s.groupName+'" was defined with unresolvable material "'+p+'"! Assigning "'+I+'".'),(p=I)===u&&(l=n,u=I)}if(!THREE.LoaderSupport.Validator.isValid(l)){var O={materialNameOrg:p,materialName:u,materialProperties:{vertexColors:m?2:0,flatShading:0===s.smoothingGroup}},H={cmd:"materialData",materials:{materialCloneInstructions:O}};this.callbackBuilder(H),this.useAsync&&(this.materials[u]=O)}if(f?((a=L[u])||(a=E,L[u]=E,b.push(u),E++),i={start:y,count:P=this.useIndices?s.indices.length:s.vertices.length/3,index:a},v.push(i),y+=P):b.push(u),o.set(s.vertices,S),S+=s.vertices.length,h&&(h.set(s.indices,C),C+=s.indices.length),d&&(d.set(s.colors,T),T+=s.colors.length),c&&(c.set(s.normals,R),R+=s.normals.length),g&&(g.set(s.uvs,N),N+=s.uvs.length),this.logger.isDebug()){var w=THREE.LoaderSupport.Validator.isValid(a)?"\n\t\tmaterialIndex: "+a:"",G="Output Object no.: "+this.outputObjectCount+"\n\t\tgroupName: "+s.groupName+w+"\n\t\tmaterialName: "+s.materialName+"\n\t\tsmoothingGroup: "+s.smoothingGroup+"\n\t\tobjectName: "+s.objectName+"\n\t\t#vertices: "+s.vertices.length/3+"\n\t\t#indices: "+s.indices.length+"\n\t\t#colors: "+s.colors.length/3+"\n\t\t#uvs: "+s.uvs.length/2+"\n\t\t#normals: "+s.normals.length/3;this.logger.logDebug(G)}}this.outputObjectCount++,this.callbackBuilder({cmd:"meshData",progress:{numericalValue:t/this.totalBytes},params:{meshName:e.name},materials:{multiMaterial:f,materialNames:b,materialGroups:v},buffers:{vertices:o,indices:h,colors:d,normals:c,uvs:g}},[o.buffer],THREE.LoaderSupport.Validator.isValid(h)?[h.buffer]:null,THREE.LoaderSupport.Validator.isValid(d)?[d.buffer]:null,THREE.LoaderSupport.Validator.isValid(c)?[c.buffer]:null,THREE.LoaderSupport.Validator.isValid(g)?[g.buffer]:null)};
return e;
})(); gulp now uses uglifyjs2 as follows: It looks like webpack does not properly minify/uglify things... Did you also try the gulp build as described in the README? |
Verified this was caused by webpack (I'm using Worked around it by adding I did indeed build it according to the README. Thank you for trying to help @kaisalmen ! |
I tweaked the package naming a bit and removed unneeded local vars, but I think that's it. I did not see any problems with the new approach (all versions source, bundles (minified & not) work fine). I merged it back to master already. Any feedback is welcome. @unphased Local vars/objects defined inside |
I forgot to update |
Ok, |
Hi guys. The issue is still present in parser code generated in
I am using following versions including the latest version of OBJLoader2 and LoaderSupport: package.json
Per documentation I can see that it is possible to override default behaviour using UglifyJsPlugin configuration:
Could you please provide me with valid UglifyJsPlugin configuration that should solve this issue? Thanks! |
Hi @4zuko, this is the only thing gulp passes to uglify-js: uglify( { mangle: { toplevel: true } } ) I just check that it still works and it does. module: {
...
plugins: [new webpack.optimize.UglifyJsPlugin( { mangle: { toplevel: true } } )],
...
} Thanks |
The code that gets generated for the blob for the worker ends up mangled. Here is an excerpt
ConsolConsoleLoggerLogger = (function () {
})();
/**
*/
LoadLoaderBaserBase = (function () {
})();
Consts = {
CODE_LF: 10,
CODE_CR: 13,
CODE_SPACE: 32,
CODE_SLASH: 47,
STRING_LF: "\n",
STRING_CR: "\r",
STRING_SPACE: " ",
STRING_SLASH: "/",
LINE_F: "f",
LINE_G: "g",
LINE_L: "l",
LINE_O: "o",
LINE_S: "s",
LINE_V: "v",
LINE_VT: "vt",
LINE_VN: "vn",
LINE_MTLLIB: "mtllib",
LINE_USEMTL: "usemtl",
}
ParsParserr = (function () {
})();
RawMRawMeshsh = (function () {
})();
RawMRawMeshSubGroupshSubGroup = (function () {
})();
e = (function () {
})();
new e();
Validator = {
isValid: function ( input ) {
return ( input !== null && input !== undefined );
},
verifyInput: function ( input, defaultValue ) {
return ( input === null || input === undefined ) ? defaultValue : input;
},
}
ConsoleLogger = (function () {
})();
/**
*/
LoaderBase = (function () {
})();
Consts = {
CODE_LF: 10,
CODE_CR: 13,
CODE_SPACE: 32,
CODE_SLASH: 47,
STRING_LF: "\n",
STRING_CR: "\r",
STRING_SPACE: " ",
STRING_SLASH: "/",
LINE_F: "f",
LINE_G: "g",
LINE_L: "l",
LINE_O: "o",
LINE_S: "s",
LINE_V: "v",
LINE_VT: "vt",
LINE_VN: "vn",
LINE_MTLLIB: "mtllib",
LINE_USEMTL: "usemtl",
}
Parser = (function () {
})();
RawMesh = (function () {
})();
RawMeshSubGroup = (function () {
})();
WorkerRunnerRefImpl = (function () {
})();
new WorkerRunnerRefImpl();
The text was updated successfully, but these errors were encountered: