1 |
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-loaders",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-loaders"]=t(require("babylonjs")):e.LOADERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,function(e){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=14)}({0:function(t,r){t.exports=e},14:function(e,t,r){"use strict";r.r(t),function(e){var o=r(8);r.d(t,"MTLFileLoader",function(){return o.MTLFileLoader}),r.d(t,"OBJFileLoader",function(){return o.OBJFileLoader});var n=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==n)for(var s in o)n.BABYLON[s]=o[s]}.call(this,r(4))},4:function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},8:function(e,t,r){"use strict";r.r(t);var o=r(0),n=function(){function e(){this.materials=[]}return e.prototype.parseMTL=function(t,r,n,s){if(!(r instanceof ArrayBuffer)){for(var i,a=r.split("\n"),l=/\s+/,u=null,p=0;p<a.length;p++){var c=a[p].trim();if(0!==c.length&&"#"!==c.charAt(0)){var f=c.indexOf(" "),h=f>=0?c.substring(0,f):c;h=h.toLowerCase();var d=f>=0?c.substring(f+1).trim():"";"newmtl"===h?(u&&this.materials.push(u),t._blockEntityCollection=s,u=new o.StandardMaterial(d,t),t._blockEntityCollection=!1):"kd"===h&&u?(i=d.split(l,3).map(parseFloat),u.diffuseColor=o.Color3.FromArray(i)):"ka"===h&&u?(i=d.split(l,3).map(parseFloat),u.ambientColor=o.Color3.FromArray(i)):"ks"===h&&u?(i=d.split(l,3).map(parseFloat),u.specularColor=o.Color3.FromArray(i)):"ke"===h&&u?(i=d.split(l,3).map(parseFloat),u.emissiveColor=o.Color3.FromArray(i)):"ns"===h&&u?u.specularPower=parseFloat(d):"d"===h&&u?u.alpha=parseFloat(d):"map_ka"===h&&u?u.ambientTexture=e._getTexture(n,d,t):"map_kd"===h&&u?u.diffuseTexture=e._getTexture(n,d,t):"map_ks"===h&&u?u.specularTexture=e._getTexture(n,d,t):"map_ns"===h||("map_bump"===h&&u?u.bumpTexture=e._getTexture(n,d,t):"map_d"===h&&u&&(u.opacityTexture=e._getTexture(n,d,t)))}}u&&this.materials.push(u)}},e._getTexture=function(t,r,n){if(!r)return null;var s=t;if("file:"===t){var i=r.lastIndexOf("\\");-1===i&&(i=r.lastIndexOf("/")),s+=i>-1?r.substr(i+1):r}else s+=r;return new o.Texture(s,n,!1,e.INVERT_TEXTURE_Y)},e.INVERT_TEXTURE_Y=!0,e}(),s=function(){function e(t){this.name="obj",this.extensions=".obj",this.obj=/^o/,this.group=/^g/,this.mtllib=/^mtllib /,this.usemtl=/^usemtl /,this.smooth=/^s /,this.vertexPattern=/v( +[\d|\.|\+|\-|e|E]+){3,7}/,this.normalPattern=/vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.uvPattern=/vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.facePattern1=/f\s+(([\d]{1,}[\s]?){3,})+/,this.facePattern2=/f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern3=/f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern4=/f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/,this.facePattern5=/f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/,this._forAssetContainer=!1,this._meshLoadOptions=t||e.currentMeshLoadOptions}return Object.defineProperty(e,"INVERT_TEXTURE_Y",{get:function(){return n.INVERT_TEXTURE_Y},set:function(e){n.INVERT_TEXTURE_Y=e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"currentMeshLoadOptions",{get:function(){return{ComputeNormals:e.COMPUTE_NORMALS,ImportVertexColors:e.IMPORT_VERTEX_COLORS,InvertY:e.INVERT_Y,InvertTextureY:e.INVERT_TEXTURE_Y,UVScaling:e.UV_SCALING,MaterialLoadingFailsSilently:e.MATERIAL_LOADING_FAILS_SILENTLY,OptimizeWithUV:e.OPTIMIZE_WITH_UV,SkipMaterials:e.SKIP_MATERIALS}},enumerable:!0,configurable:!0}),e.prototype._loadMTL=function(e,t,r,n){var s=o.Tools.BaseUrl+t+e;o.Tools.LoadFile(s,r,void 0,void 0,!1,function(e,t){n(s,t)})},e.prototype.createPlugin=function(){return new e(e.currentMeshLoadOptions)},e.prototype.canDirectLoad=function(e){return!1},e.prototype.importMeshAsync=function(e,t,r,o,n,s){return this._parseSolid(e,t,r,o).then(function(e){return{meshes:e,particleSystems:[],skeletons:[],animationGroups:[]}})},e.prototype.loadAsync=function(e,t,r,o,n){return this.importMeshAsync(null,e,t,r,o).then(function(){})},e.prototype.loadAssetContainerAsync=function(e,t,r,n,s){var i=this;return this._forAssetContainer=!0,this.importMeshAsync(null,e,t,r).then(function(t){var r=new o.AssetContainer(e);return t.meshes.forEach(function(e){return r.meshes.push(e)}),t.meshes.forEach(function(e){var t=e.material;t&&(-1==r.materials.indexOf(t)&&(r.materials.push(t),t.getActiveTextures().forEach(function(e){-1==r.textures.indexOf(e)&&r.textures.push(e)})))}),i._forAssetContainer=!1,r}).catch(function(e){throw i._forAssetContainer=!1,e})},e.prototype._parseSolid=function(t,r,s,i){for(var a,l=this,u=[],p=[],c=[],f=[],h=[],d=[],m=[],v=[],_=[],x=[],g=[],y=0,L=!1,T=[],O=[],I=[],b=[],E=[],A="",C="",V=new n,M=1,P=!0,F=new o.Color4(.5,.5,.5,1),S=function(e,t,r,o,n,s,i){var a;-1===(a=l._meshLoadOptions.OptimizeWithUV?function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});var r=e[t[0]].normals.indexOf(t[1]);return 1!=r&&t[2]===e[t[0]].uv[r]?e[t[0]].idx[r]:-1}(g,[e,r,t]):function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[]});var r=e[t[0]].normals.indexOf(t[1]);return-1===r?-1:e[t[0]].idx[r]}(g,[e,r]))?(d.push(m.length),m.push(o),v.push(n),x.push(s),void 0!==i&&_.push(i),g[e].normals.push(r),g[e].idx.push(y++),l._meshLoadOptions.OptimizeWithUV&&g[e].uv.push(t)):d.push(a)},w=function(){for(var e=0;e<m.length;e++)T.push(m[e].x,m[e].y,m[e].z),I.push(x[e].x,x[e].y,x[e].z),b.push(v[e].x,v[e].y);!0===l._meshLoadOptions.ImportVertexColors&&O.push(_[e].r,_[e].g,_[e].b,_[e].a),m=[],x=[],v=[],_=[],g=[],y=0},R=function(e,t){for(var r=t;r<e.length-1;r++)E.push(e[0],e[r],e[r+1])},N=function(e,t){R(e,t);for(var r=0;r<E.length;r++){var n=parseInt(E[r])-1;S(n,0,0,u[n],o.Vector2.Zero(),o.Vector3.Up(),!0===l._meshLoadOptions.ImportVertexColors?f[n]:void 0)}E=[]},j=function(e,t){R(e,t);for(var r=0;r<E.length;r++){var n=E[r].split("/"),s=parseInt(n[0])-1,i=parseInt(n[1])-1;S(s,i,0,u[s],c[i],o.Vector3.Up(),!0===l._meshLoadOptions.ImportVertexColors?f[s]:void 0)}E=[]},U=function(e,t){R(e,t);for(var r=0;r<E.length;r++){var o=E[r].split("/"),n=parseInt(o[0])-1,s=parseInt(o[1])-1,i=parseInt(o[2])-1;S(n,s,i,u[n],c[s],p[i])}E=[]},Y=function(e,t){R(e,t);for(var r=0;r<E.length;r++){var n=E[r].split("//"),s=parseInt(n[0])-1,i=parseInt(n[1])-1;S(s,1,i,u[s],o.Vector2.Zero(),p[i],!0===l._meshLoadOptions.ImportVertexColors?f[s]:void 0)}E=[]},k=function(e,t){R(e,t);for(var r=0;r<E.length;r++){var o=E[r].split("/"),n=u.length+parseInt(o[0]),s=c.length+parseInt(o[1]),i=p.length+parseInt(o[2]);S(n,s,i,u[n],c[s],p[i],!0===l._meshLoadOptions.ImportVertexColors?f[n]:void 0)}E=[]},B=function(){h.length>0&&(a=h[h.length-1],w(),d.reverse(),a.indices=d.slice(),a.positions=T.slice(),a.normals=I.slice(),a.uvs=b.slice(),!0===l._meshLoadOptions.ImportVertexColors&&(a.colors=O.slice()),d=[],T=[],O=[],I=[],b=[])},G=s.split("\n"),X=0;X<G.length;X++){var W,D=G[X].trim().replace(/\s\s/g," ");if(0!==D.length&&"#"!==D.charAt(0))if(this.vertexPattern.test(D))W=D.match(/[^ ]+/g),u.push(new o.Vector3(parseFloat(W[1]),parseFloat(W[2]),parseFloat(W[3]))),!0===this._meshLoadOptions.ImportVertexColors&&(W.length>=7?f.push(new o.Color4(parseFloat(W[4]),parseFloat(W[5]),parseFloat(W[6]),7===W.length||void 0===W[7]?1:parseFloat(W[7]))):f.push(F));else if(null!==(W=this.normalPattern.exec(D)))p.push(new o.Vector3(parseFloat(W[1]),parseFloat(W[2]),parseFloat(W[3])));else if(null!==(W=this.uvPattern.exec(D)))c.push(new o.Vector2(parseFloat(W[1])*e.UV_SCALING.x,parseFloat(W[2])*e.UV_SCALING.y));else if(null!==(W=this.facePattern3.exec(D)))U(W[1].trim().split(" "),1);else if(null!==(W=this.facePattern4.exec(D)))Y(W[1].trim().split(" "),1);else if(null!==(W=this.facePattern5.exec(D)))k(W[1].trim().split(" "),1);else if(null!==(W=this.facePattern2.exec(D)))j(W[1].trim().split(" "),1);else if(null!==(W=this.facePattern1.exec(D)))N(W[1].trim().split(" "),1);else if(this.group.test(D)||this.obj.test(D)){var z={name:D.substring(2).trim(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,colors:void 0,materialName:""};B(),h.push(z),L=!0,P=!0,M=1}else if(this.usemtl.test(D)){if(A=D.substring(7).trim(),!P||!L){B();z={name:"mesh_mm"+M.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,colors:void 0,materialName:A};M++,h.push(z),L=!0}L&&P&&(h[h.length-1].materialName=A,P=!1)}else this.mtllib.test(D)?C=D.substring(7).trim():this.smooth.test(D)||console.log("Unhandled expression at line : "+D)}L&&(a=h[h.length-1],d.reverse(),w(),a.indices=d,a.positions=T,a.normals=I,a.uvs=b,!0===this._meshLoadOptions.ImportVertexColors&&(a.colors=O)),L||(d.reverse(),w(),h.push({name:o.Geometry.RandomId(),indices:d,positions:T,colors:O,normals:I,uvs:b,materialName:A}));for(var Z=[],J=new Array,q=0;q<h.length;q++){if(t&&h[q].name)if(t instanceof Array){if(-1===t.indexOf(h[q].name))continue}else if(h[q].name!==t)continue;a=h[q],r._blockEntityCollection=this._forAssetContainer;var H=new o.Mesh(h[q].name,r);r._blockEntityCollection=!1,J.push(h[q].materialName);var K=new o.VertexData;if(K.uvs=a.uvs,K.indices=a.indices,K.positions=a.positions,!0===this._meshLoadOptions.ComputeNormals){var Q=new Array;o.VertexData.ComputeNormals(a.positions,a.indices,Q),K.normals=Q}else K.normals=a.normals;!0===this._meshLoadOptions.ImportVertexColors&&(K.colors=a.colors),K.applyToMesh(H),this._meshLoadOptions.InvertY&&(H.scaling.y*=-1),Z.push(H)}var $=[];return""!==C&&!1===this._meshLoadOptions.SkipMaterials&&$.push(new Promise(function(e,t){l._loadMTL(C,i,function(n){try{V.parseMTL(r,n,i,l._forAssetContainer);for(var s=0;s<V.materials.length;s++){for(var a,u=0,p=[];(a=J.indexOf(V.materials[s].name,u))>-1;)p.push(a),u=a+1;if(-1===a&&0===p.length)V.materials[s].dispose();else for(var c=0;c<p.length;c++)Z[p[c]].material=V.materials[s]}e()}catch(r){o.Tools.Warn("Error processing MTL file: '"+C+"'"),l._meshLoadOptions.MaterialLoadingFailsSilently?e():t(r)}},function(r,n){o.Tools.Warn("Error downloading MTL file: '"+C+"'"),l._meshLoadOptions.MaterialLoadingFailsSilently?e():t(n)})})),Promise.all($).then(function(){return Z})},e.OPTIMIZE_WITH_UV=!0,e.INVERT_Y=!1,e.IMPORT_VERTEX_COLORS=!1,e.COMPUTE_NORMALS=!1,e.UV_SCALING=new o.Vector2(1,1),e.SKIP_MATERIALS=!1,e.MATERIAL_LOADING_FAILS_SILENTLY=!0,e}();o.SceneLoader&&o.SceneLoader.RegisterPlugin(new s),r.d(t,"MTLFileLoader",function(){return n}),r.d(t,"OBJFileLoader",function(){return s})}})});
|