babylon.stlFileLoader.min.js 4.4 KB

1
  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(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},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 n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},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=16)}({0:function(t,r){t.exports=e},11:function(e,t,r){"use strict";r.r(t),r.d(t,"STLFileLoader",(function(){return o}));var n=r(0),o=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={".stl":{isBinary:!0}}}return e.prototype.importMesh=function(e,t,r,o,i,a,s){var u;if("string"!=typeof r){if(this._isBinary(r)){var l=new n.Mesh("stlmesh",t);return this._parseBinary(l,r),i&&i.push(l),!0}for(var f=new Uint8Array(r),c="",d=0;d<r.byteLength;d++)c+=String.fromCharCode(f[d]);r=c}for(;u=this.solidPattern.exec(r);){var p=u[1];if(p!=u[3])return n.Tools.Error("Error in STL, solid name != endsolid name"),!1;if(e&&p)if(e instanceof Array){if(!e.indexOf(p))continue}else if(p!==e)continue;p=p||"stlmesh";l=new n.Mesh(p,t);this._parseASCII(l,u[2]),i&&i.push(l)}return!0},e.prototype.load=function(e,t,r){return this.importMesh(null,e,t,r,null,null,null)},e.prototype.loadAssetContainer=function(e,t,r,o){var i=new n.AssetContainer(e);return e._blockEntityCollection=!0,this.importMesh(null,e,t,r,i.meshes,null,null),e._blockEntityCollection=!1,i},e.prototype._isBinary=function(e){var t;if(50,84+50*(t=new DataView(e)).getUint32(80,!0)===t.byteLength)return!0;for(var r=t.byteLength,n=0;n<r;n++)if(t.getUint8(n)>127)return!0;return!1},e.prototype._parseBinary=function(e,t){for(var r=new DataView(t),o=r.getUint32(80,!0),i=0,a=new Float32Array(3*o*3),s=new Float32Array(3*o*3),u=new Uint32Array(3*o),l=0,f=0;f<o;f++){for(var c=84+50*f,d=r.getFloat32(c,!0),p=r.getFloat32(c+4,!0),y=r.getFloat32(c+8,!0),h=1;h<=3;h++){var b=c+12*h;a[i]=r.getFloat32(b,!0),a[i+2]=r.getFloat32(b+4,!0),a[i+1]=r.getFloat32(b+8,!0),s[i]=d,s[i+2]=p,s[i+1]=y,i+=3}u[l]=l++,u[l]=l++,u[l]=l++}e.setVerticesData(n.VertexBuffer.PositionKind,a),e.setVerticesData(n.VertexBuffer.NormalKind,s),e.setIndices(u),e.computeWorldMatrix(!0)},e.prototype._parseASCII=function(e,t){for(var r,o=[],i=[],a=[],s=0;r=this.facetsPattern.exec(t);){var u=r[1],l=this.normalPattern.exec(u);if(this.normalPattern.lastIndex=0,l){for(var f,c=[Number(l[1]),Number(l[5]),Number(l[3])];f=this.vertexPattern.exec(u);)o.push(Number(f[1]),Number(f[5]),Number(f[3])),i.push(c[0],c[1],c[2]);a.push(s++,s++,s++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,e.setVerticesData(n.VertexBuffer.PositionKind,o),e.setVerticesData(n.VertexBuffer.NormalKind,i),e.setIndices(a),e.computeWorldMatrix(!0)},e}();n.SceneLoader&&n.SceneLoader.RegisterPlugin(new o)},16:function(e,t,r){"use strict";r.r(t),function(e){var n=r(11);r.d(t,"STLFileLoader",(function(){return n.STLFileLoader}));var o=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==o)for(var i in n)o.BABYLON[i]=n[i]}.call(this,r(5))},5: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}})}));