three-full: Minified OBJLoader2 Async fails on building worker code

When OBJLoader2 is used async it builds the worker code by building up a string and passing it to the worker. Unfortunately some of the string is hard coded. That means that when it is minified (as all of my code is when I deploy) the strings aren’t the correct class/variable name any more.

In the following code you can see that LoaderSupport is hard-coded (eg. var LoaderSupport) but the Parser class definition has been minified, so where it should say LoaderSupport.Validator in prototype.setMaterials it says mh.Validator instead. I can’t think of a good way to handle this. Any ideas???

    var LoaderSupport = {};

    LoaderSupport.Validator = {
	    isValid: function(e){return null!==e&&void 0!==e},
	    verifyInput: function(e,t){return null===e||void 0===e?t:e},
    }

    Parser = (function () {

	function e(){this.callbackProgress=null,this.callbackMeshBuilder=null,this.contentRef=null,this.legacyMode=!1,this.materials={},this.useAsync=!1,this.materialPerSmoothingGroup=!1,this.useIndices=!1,this.disregardNormals=!1,this.vertices=[],this.colors=[],this.normals=[],this.uvs=[],this.rawMesh={objectName:"",groupName:"",activeMtlName:"",mtllibName:"",faceType:-1,subGroups:[],subGroupInUse:null,smoothingGroup:{splitMaterials:!1,normalized:-1,real:-1},counts:{doubleIndicesCount:0,faceCount:0,mtlCount:0,smoothingGroupCount:0}},this.inputObjectCount=1,this.outputObjectCount=1,this.globalCounts={vertices:0,faces:0,doubleIndicesCount:0,lineByte:0,currentByte:0,totalBytes:0},this.logging={enabled:!0,debug:!1}}

	e.prototype.resetRawMesh = function(){this.rawMesh.subGroups=[],this.rawMesh.subGroupInUse=null,this.rawMesh.smoothingGroup.normalized=-1,this.rawMesh.smoothingGroup.real=-1,this.pushSmoothingGroup(1),this.rawMesh.counts.doubleIndicesCount=0,this.rawMesh.counts.faceCount=0,this.rawMesh.counts.mtlCount=0,this.rawMesh.counts.smoothingGroupCount=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=mh.Validator.verifyInput(e,this.materials),this.materials=mh.Validator.verifyInput(this.materials,{})};

	e.prototype.setCallbackMeshBuilder = function(e){if(!mh.Validator.isValid(e))throw'Unable to run as no "MeshBuilder" callback is set.';this.callbackMeshBuilder=e};

	e.prototype.setCallbackProgress = function(e){this.callbackProgress=e};

And just for reference, here is the code that is causing the problem (the build worker code):

      var buildCode = function(funcBuildObject, funcBuildSingleton) {
            var workerCode = '';
            workerCode += '\n\n';
            workerCode += 'var LoaderSupport = {};\n\n';
            workerCode += funcBuildObject('LoaderSupport.Validator', Validator);
            workerCode += funcBuildSingleton('Parser', Parser);
            return workerCode;
      };
      this.workerSupport.validate(buildCode, 'Parser');
      this.workerSupport.setCallbacks(scopedOnMeshLoaded, scopedOnLoad);
      if (scope.terminateWorkerOnLoad) { this.workerSupport.setTerminateRequested(true); }

edit: add javascript tag to code

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 20 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I will take a look deeper on this case but… i think this is a bug for three js library not this converter.

I aware that this “bug” appear due to the es6 portage of OBJLoader2, but unfortunately i’m not able to determine what will be the minimified version of such code…

Currently the best thing to do could be a manual find an replace against var LoaderSupport with the minimified version of it.