babylon.stlFileLoader.min.js 1.6 KB

1
  1. var BABYLON;!(function(e){var t=(function(){function t(){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.extensions=".stl"}return t.prototype.importMesh=function(t,r,n,s,i,a,o){for(var l;l=this.solidPattern.exec(n);){var u=l[1];if(u!=l[3]&&console.log("error in stl, solid name != endsolid name"),t&&u)if(t instanceof Array){if(!t.indexOf(u))continue}else if(u!==t)continue;u=u||"stlmesh";var f=new e.Mesh(u,r);this.parseSolid(f,l[2])}return!0},t.prototype.load=function(e,t,r){var n=this.importMesh(null,e,t,r,null,null,null);return n&&e.createDefaultCameraOrLight(),n},t.prototype.parseSolid=function(t,r){for(var n,s=[],i=[],a=[],o=0;n=this.facetsPattern.exec(r);){var l=n[1],u=this.normalPattern.exec(l);if(this.normalPattern.lastIndex=0,u){for(var f,c=[Number(u[1]),Number(u[5]),Number(u[3])];f=this.vertexPattern.exec(l);)i.push(Number(f[1]),Number(f[5]),Number(f[3])),s.push(c[0],c[1],c[2]);a.push(o++,o++,o++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,t.setVerticesData(e.VertexBuffer.PositionKind,i),t.setVerticesData(e.VertexBuffer.NormalKind,s),t.setIndices(a),t.computeWorldMatrix(!0)},t})();e.STLFileLoader=t,e.SceneLoader.RegisterPlugin(new t)})(BABYLON||(BABYLON={}));