UNPKG

babylonjs-loaders

Version:

Babylon.js Loaders module =====================

2 lines 4.43 kB
!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,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.d(o,{default:()=>p});var i={};n.r(i),n.d(i,{STLFileLoader:()=>f});var s={};n.r(s),n.d(s,{STLFileLoader:()=>f});var a=n(597),l={".stl":{isBinary:!0}},f=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=l}return e.prototype.importMesh=function(e,t,r,n,o){var i;if("string"!=typeof r){if(this._isBinary(r)){var s=new a.Mesh("stlmesh",t);return this._parseBinary(s,r),o&&o.push(s),!0}r=(new TextDecoder).decode(new Uint8Array(r))}for(;i=this.solidPattern.exec(r);){var l=i[1],f=i[3];if(f&&l!=f)return a.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",s=new a.Mesh(l,t),this._parseASCII(s,i[2]),o&&o.push(s)}return!0},e.prototype.load=function(e,t,r){return this.importMesh(null,e,t,r,null)},e.prototype.loadAssetContainer=function(e,t,r){var n=new a.AssetContainer(e);return e._blockEntityCollection=!0,this.importMesh(null,e,t,r,n.meshes),e._blockEntityCollection=!1,n},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(t,r){for(var n=new DataView(r),o=n.getUint32(80,!0),i=0,s=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 p=84+50*d,c=n.getFloat32(p,!0),y=n.getFloat32(p+4,!0),h=n.getFloat32(p+8,!0),b=1;b<=3;b++){var m=p+12*b;s[i]=n.getFloat32(m,!0),l[i]=c,e.DO_NOT_ALTER_FILE_COORDINATES?(s[i+1]=n.getFloat32(m+4,!0),s[i+2]=n.getFloat32(m+8,!0),l[i+1]=y,l[i+2]=h):(s[i+2]=n.getFloat32(m+4,!0),s[i+1]=n.getFloat32(m+8,!0),l[i+2]=y,l[i+1]=h),i+=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++)}t.setVerticesData(a.VertexBuffer.PositionKind,s),t.setVerticesData(a.VertexBuffer.NormalKind,l),t.setIndices(f),t.computeWorldMatrix(!0)},e.prototype._parseASCII=function(t,r){for(var n,o=[],i=[],s=[],l=0;n=this.facetsPattern.exec(r);){var f=n[1],u=this.normalPattern.exec(f);if(this.normalPattern.lastIndex=0,u){for(var d=[Number(u[1]),Number(u[5]),Number(u[3])],p=void 0;p=this.vertexPattern.exec(f);)e.DO_NOT_ALTER_FILE_COORDINATES?(o.push(Number(p[1]),Number(p[3]),Number(p[5])),i.push(d[0],d[2],d[1])):(o.push(Number(p[1]),Number(p[5]),Number(p[3])),i.push(d[0],d[1],d[2]));e.DO_NOT_ALTER_FILE_COORDINATES?(s.push(l,l+2,l+1),l+=3):s.push(l++,l++,l++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,t.setVerticesData(a.VertexBuffer.PositionKind,o),t.setVerticesData(a.VertexBuffer.NormalKind,i),t.setIndices(s),t.computeWorldMatrix(!0)},e.DO_NOT_ALTER_FILE_COORDINATES=!1,e}();(0,a.RegisterSceneLoaderPlugin)(new f);var u=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==u)for(var d in i)u.BABYLON[d]||(u.BABYLON[d]=i[d]);const p=s;return o.default})())); //# sourceMappingURL=babylon.stlFileLoader.min.js.map