1 |
- var BABYLON;!(function(g){var e=(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,n,a,i,s){var o;if("string"!=typeof r){if(this.isBinary(r)){var l=new g.Mesh("stlmesh",t);return this.parseBinary(l,r),a&&a.push(l),!0}for(var u=new Uint8Array(r),f="",h=0;h<r.byteLength;h++)f+=String.fromCharCode(u[h]);r=f}for(;o=this.solidPattern.exec(r);){var c=o[1];if(c!=o[3])return g.Tools.Error("Error in STL, solid name != endsolid name"),!1;if(e&&c)if(e instanceof Array){if(!e.indexOf(c))continue}else if(c!==e)continue;c=c||"stlmesh";l=new g.Mesh(c,t);this.parseASCII(l,o[2]),a&&a.push(l)}return!0},e.prototype.load=function(e,t,r){var n=this.importMesh(null,e,t,r,null,null,null);return n&&e.createDefaultCameraOrLight(),n},e.prototype.loadAssetContainer=function(e,t,r,n){var a=new g.AssetContainer(e);return this.importMesh(null,e,t,r,a.meshes,null,null),a.removeAllFromScene(),a},e.prototype.isBinary=function(e){var t;if(84+50*(t=new DataView(e)).getUint32(80,!0)===t.byteLength)return!0;for(var r=t.byteLength,n=0;n<r;n++)if(127<t.getUint8(n))return!0;return!1},e.prototype.parseBinary=function(e,t){for(var r=new DataView(t),n=r.getUint32(80,!0),a=0,i=new Float32Array(3*n*3),s=new Float32Array(3*n*3),o=new Uint32Array(3*n),l=0,u=0;u<n;u++){for(var f=84+50*u,h=r.getFloat32(f,!0),c=r.getFloat32(f+4,!0),d=r.getFloat32(f+8,!0),m=1;m<=3;m++){var p=f+12*m;i[a]=r.getFloat32(p,!0),i[a+2]=r.getFloat32(p+4,!0),i[a+1]=r.getFloat32(p+8,!0),s[a]=h,s[a+2]=c,s[a+1]=d,a+=3}o[l]=l++,o[l]=l++,o[l]=l++}e.setVerticesData(g.VertexBuffer.PositionKind,i),e.setVerticesData(g.VertexBuffer.NormalKind,s),e.setIndices(o),e.computeWorldMatrix(!0)},e.prototype.parseASCII=function(e,t){for(var r,n=[],a=[],i=[],s=0;r=this.facetsPattern.exec(t);){var o=r[1],l=this.normalPattern.exec(o);if(this.normalPattern.lastIndex=0,l){for(var u,f=[Number(l[1]),Number(l[5]),Number(l[3])];u=this.vertexPattern.exec(o);)n.push(Number(u[1]),Number(u[5]),Number(u[3])),a.push(f[0],f[1],f[2]);i.push(s++,s++,s++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,e.setVerticesData(g.VertexBuffer.PositionKind,n),e.setVerticesData(g.VertexBuffer.NormalKind,a),e.setIndices(i),e.computeWorldMatrix(!0)},e})();g.STLFileLoader=e,g.SceneLoader&&g.SceneLoader.RegisterPlugin(new e)})(BABYLON||(BABYLON={}));
|