/*
* @author aleeper / http://adamleeper.com/ 
* @author mrdoob / http://mrdoob.com/ 
* @author gero3 / https://github.com/gero3 
*/
THREE.STLLoader=function(a){this.manager=void 0!==a?a:THREE.DefaultLoadingManager},THREE.STLLoader.prototype={constructor:THREE.STLLoader,load:function(a,b,c,d){var e=this,f=new THREE.XHRLoader(e.manager);f.setCrossOrigin(this.crossOrigin),f.setResponseType("arraybuffer"),f.load(a,function(a){b(e.parse(a))},c,d)},parse:function(a){var b=function(){var a,b,d,e;if(e=new DataView(c),b=50,d=e.getUint32(80,!0),a=84+d*b,a===e.byteLength)return!0;for(var f=e.byteLength,g=0;f>g;g++)if(e.getUint8(g,!1)>127)return!0;return!1},c=this.ensureBinary(a);return b()?this.parseBinary(c):this.parseASCII(this.ensureString(a))},parseBinary:function(a){for(var b,c,d,e,f,g,h,i,j=new DataView(a),k=j.getUint32(80,!0),l=!1,m=0;70>m;m++)1129270351==j.getUint32(m,!1)&&82==j.getUint8(m+4)&&61==j.getUint8(m+5)&&(l=!0,e=new Float32Array(3*k*3),f=j.getUint8(m+6)/255,g=j.getUint8(m+7)/255,h=j.getUint8(m+8)/255,i=j.getUint8(m+9)/255);for(var n=84,o=50,p=0,q=new THREE.BufferGeometry,r=new Float32Array(3*k*3),s=new Float32Array(3*k*3),t=0;k>t;t++){var u=n+t*o,v=j.getFloat32(u,!0),w=j.getFloat32(u+4,!0),x=j.getFloat32(u+8,!0);if(l){var y=j.getUint16(u+48,!0);0===(32768&y)?(b=(31&y)/31,c=(y>>5&31)/31,d=(y>>10&31)/31):(b=f,c=g,d=h)}for(var z=1;3>=z;z++){var A=u+12*z;r[p]=j.getFloat32(A,!0),r[p+1]=j.getFloat32(A+4,!0),r[p+2]=j.getFloat32(A+8,!0),s[p]=v,s[p+1]=w,s[p+2]=x,l&&(e[p]=b,e[p+1]=c,e[p+2]=d),p+=3}}return q.addAttribute("position",new THREE.BufferAttribute(r,3)),q.addAttribute("normal",new THREE.BufferAttribute(s,3)),l&&(q.addAttribute("color",new THREE.BufferAttribute(e,3)),q.hasColors=!0,q.alpha=i),q},parseASCII:function(a){var b,c,d,e,f,g,h,i;for(b=new THREE.Geometry,e=/facet([\s\S]*?)endfacet/g;null!==(h=e.exec(a));){for(i=h[0],f=/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;null!==(h=f.exec(i));)d=new THREE.Vector3(parseFloat(h[1]),parseFloat(h[3]),parseFloat(h[5]));for(g=/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;null!==(h=g.exec(i));)b.vertices.push(new THREE.Vector3(parseFloat(h[1]),parseFloat(h[3]),parseFloat(h[5])));c=b.vertices.length,b.faces.push(new THREE.Face3(c-3,c-2,c-1,d))}return b.computeBoundingBox(),b.computeBoundingSphere(),b},ensureString:function(a){if("string"!=typeof a){for(var b=new Uint8Array(a),c="",d=0;d<a.byteLength;d++)c+=String.fromCharCode(b[d]);return c}return a},ensureBinary:function(a){if("string"==typeof a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++)b[c]=255&a.charCodeAt(c);return b.buffer||b}return a}},"undefined"==typeof DataView&&(DataView=function(a,b,c){this.buffer=a,this.byteOffset=b||0,this.byteLength=c||a.byteLength||a.length,this._isString="string"==typeof a},DataView.prototype={_getCharCodes:function(a,b,c){b=b||0,c=c||a.length;for(var d=b+c,e=[],f=b;d>f;f++)e.push(255&a.charCodeAt(f));return e},_getBytes:function(a,b,c){var d;if(void 0===c&&(c=this._littleEndian),b=void 0===b?this.byteOffset:this.byteOffset+b,void 0===a&&(a=this.byteLength-b),"number"!=typeof b)throw new TypeError("DataView byteOffset is not a number");if(0>a||b+a>this.byteLength)throw new Error("DataView length or (byteOffset+length) value is out of bounds");return d=this.isString?this._getCharCodes(this.buffer,b,b+a):this.buffer.slice(b,b+a),!c&&a>1&&(d instanceof Array||(d=Array.prototype.slice.call(d)),d.reverse()),d},getFloat64:function(a,b){var c=this._getBytes(8,a,b),d=1-2*(c[7]>>7),e=((c[7]<<1&255)<<3|c[6]>>4)-1023,f=(15&c[6])*Math.pow(2,48)+c[5]*Math.pow(2,40)+c[4]*Math.pow(2,32)+c[3]*Math.pow(2,24)+c[2]*Math.pow(2,16)+c[1]*Math.pow(2,8)+c[0];return 1024===e?0!==f?NaN:d*(1/0):-1023===e?d*f*Math.pow(2,-1074):d*(1+f*Math.pow(2,-52))*Math.pow(2,e)},getFloat32:function(a,b){var c=this._getBytes(4,a,b),d=1-2*(c[3]>>7),e=(c[3]<<1&255|c[2]>>7)-127,f=(127&c[2])<<16|c[1]<<8|c[0];return 128===e?0!==f?NaN:d*(1/0):-127===e?d*f*Math.pow(2,-149):d*(1+f*Math.pow(2,-23))*Math.pow(2,e)},getInt32:function(a,b){var c=this._getBytes(4,a,b);return c[3]<<24|c[2]<<16|c[1]<<8|c[0]},getUint32:function(a,b){return this.getInt32(a,b)>>>0},getInt16:function(a,b){return this.getUint16(a,b)<<16>>16},getUint16:function(a,b){var c=this._getBytes(2,a,b);return c[1]<<8|c[0]},getInt8:function(a){return this.getUint8(a)<<24>>24},getUint8:function(a){return this._getBytes(1,a)[0]}});