!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";var r={".stl":{isBinary:!0}},n=function(){function e(){this.solidPattern=/solid (\S*)([\S\s]*?)endsolid[ ]*(\S*)/g,this.facetsPattern=/facet([\s\S]*?)endfacet/g,this.normalPattern=/normal[\s]+([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g,this.vertexPattern=/vertex[\s]+([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g,this.name="stl",this.extensions=r}return e.prototype.importMesh=function(e,r,n,i,o){var s;if("string"!=typeof n){if(this._isBinary(n)){var a=new t.Mesh("stlmesh",r);return this._parseBinary(a,n),o&&o.push(a),!0}n=(new TextDecoder).decode(new Uint8Array(n))}for(;s=this.solidPattern.exec(n);){var l=s[1],f=s[3];if(f&&l!=f)return t.Tools.Error("Error in STL, solid name != endsolid name"),!1;if(e&&l)if(e instanceof Array){if(!e.indexOf(l))continue}else if(l!==e)continue;l=l||"stlmesh",a=new t.Mesh(l,r),this._parseASCII(a,s[2]),o&&o.push(a)}return!0},e.prototype.load=function(e,t,r){return this.importMesh(null,e,t,r,null)},e.prototype.loadAssetContainer=function(e,r,n){var i=new t.AssetContainer(e);return e._blockEntityCollection=!0,this.importMesh(null,e,r,n,i.meshes),e._blockEntityCollection=!1,i},e.prototype._isBinary=function(e){var t=new DataView(e);if(t.byteLength<=80)return!1;if(84+50*t.getUint32(80,!0)===t.byteLength)return!0;for(var r=[115,111,108,105,100],n=0;n<5;n++)if(t.getUint8(n)!==r[n])return!0;return!1},e.prototype._parseBinary=function(r,n){for(var i=new DataView(n),o=i.getUint32(80,!0),s=0,a=new Float32Array(3*o*3),l=new Float32Array(3*o*3),f=new Uint32Array(3*o),u=0,d=0;d<o;d++){for(var c=84+50*d,p=i.getFloat32(c,!0),h=i.getFloat32(c+4,!0),_=i.getFloat32(c+8,!0),y=1;y<=3;y++){var m=c+12*y;a[s]=i.getFloat32(m,!0),l[s]=p,e.DO_NOT_ALTER_FILE_COORDINATES?(a[s+1]=i.getFloat32(m+4,!0),a[s+2]=i.getFloat32(m+8,!0),l[s+1]=h,l[s+2]=_):(a[s+2]=i.getFloat32(m+4,!0),a[s+1]=i.getFloat32(m+8,!0),l[s+2]=h,l[s+1]=_),s+=3}e.DO_NOT_ALTER_FILE_COORDINATES?(f[u]=u,f[u+1]=u+2,f[u+2]=u+1,u+=3):(f[u]=u++,f[u]=u++,f[u]=u++)}r.setVerticesData(t.VertexBuffer.PositionKind,a),r.setVerticesData(t.VertexBuffer.NormalKind,l),r.setIndices(f),r.computeWorldMatrix(!0)},e.prototype._parseASCII=function(r,n){for(var i,o=[],s=[],a=[],l=0;i=this.facetsPattern.exec(n);){var f=i[1],u=this.normalPattern.exec(f);if(this.normalPattern.lastIndex=0,u){for(var d=[Number(u[1]),Number(u[5]),Number(u[3])],c=void 0;c=this.vertexPattern.exec(f);)e.DO_NOT_ALTER_FILE_COORDINATES?(o.push(Number(c[1]),Number(c[3]),Number(c[5])),s.push(d[0],d[2],d[1])):(o.push(Number(c[1]),Number(c[5]),Number(c[3])),s.push(d[0],d[1],d[2]));e.DO_NOT_ALTER_FILE_COORDINATES?(a.push(l,l+2,l+1),l+=3):a.push(l++,l++,l++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,r.setVerticesData(t.VertexBuffer.PositionKind,o),r.setVerticesData(t.VertexBuffer.NormalKind,s),r.setIndices(a),r.computeWorldMatrix(!0)},e.DO_NOT_ALTER_FILE_COORDINATES=!1,e}();t.RegisterSceneLoaderPlugin(new n);var i={__proto__:null,STLFileLoader:n},o="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==o)for(var s in i)o.BABYLON[s]||(o.BABYLON[s]=i[s]);e.STLFileLoader=n});
//# sourceMappingURL=babylon.stlFileLoader.min.js.map
