1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
import{Bt as e,C as t,K as n,l as r,p as i,u as a,w as o,wt as s}from"./three.module-BFsVh7r1.js";var c=class extends n{constructor(e){super(e)}load(e,n,r,i){let a=this,o=new t(this.manager);o.setPath(this.path),o.setResponseType(`arraybuffer`),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(t){try{n(a.parse(t))}catch(t){i?i(t):console.error(t),a.manager.itemError(e)}},r,i)}parse(t){function n(e){let t=new DataView(e);if(84+t.getUint32(80,!0)*50===t.byteLength)return!0;let n=[115,111,108,105,100];for(let e=0;e<5;e++)if(c(n,t,e))return!1;return!0}function c(e,t,n){for(let r=0,i=e.length;r<i;r++)if(e[r]!==t.getUint8(n+r))return!1;return!0}function l(e){let t=new DataView(e),n=t.getUint32(80,!0),o,c,l,u=!1,d,f,p,m,h;for(let e=0;e<70;e++)t.getUint32(e,!1)==1129270351&&t.getUint8(e+4)==82&&t.getUint8(e+5)==61&&(u=!0,d=new Float32Array(n*3*3),f=t.getUint8(e+6)/255,p=t.getUint8(e+7)/255,m=t.getUint8(e+8)/255,h=t.getUint8(e+9)/255);let g=new a,_=new Float32Array(n*3*3),v=new Float32Array(n*3*3),y=new i;for(let e=0;e<n;e++){let n=84+e*50,r=t.getFloat32(n,!0),i=t.getFloat32(n+4,!0),a=t.getFloat32(n+8,!0);if(u){let e=t.getUint16(n+48,!0);e&32768?(o=f,c=p,l=m):(o=(e&31)/31,c=(e>>5&31)/31,l=(e>>10&31)/31)}for(let f=1;f<=3;f++){let p=n+f*12,m=e*3*3+(f-1)*3;_[m]=t.getFloat32(p,!0),_[m+1]=t.getFloat32(p+4,!0),_[m+2]=t.getFloat32(p+8,!0),v[m]=r,v[m+1]=i,v[m+2]=a,u&&(y.setRGB(o,c,l,s),d[m]=y.r,d[m+1]=y.g,d[m+2]=y.b)}}return g.setAttribute(`position`,new r(_,3)),g.setAttribute(`normal`,new r(v,3)),u&&(g.setAttribute(`color`,new r(d,3)),g.hasColors=!0,g.alpha=h),g}function u(t){let n=new a,r=/solid([\s\S]*?)endsolid/g,i=/facet([\s\S]*?)endfacet/g,s=/solid\s(.+)/,c=0,l=RegExp(`vertex[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),u=RegExp(`normal[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),d=[],f=[],p=[],m=new e,h,g=0,_=0,v=0;for(;(h=r.exec(t))!==null;){_=v;let e=h[0],t=(h=s.exec(e))===null?``:h[1];for(p.push(t);(h=i.exec(e))!==null;){let e=0,t=0,n=h[0];for(;(h=u.exec(n))!==null;)m.x=parseFloat(h[1]),m.y=parseFloat(h[2]),m.z=parseFloat(h[3]),t++;for(;(h=l.exec(n))!==null;)d.push(parseFloat(h[1]),parseFloat(h[2]),parseFloat(h[3])),f.push(m.x,m.y,m.z),e++,v++;t!==1&&console.error(`THREE.STLLoader: Something isn't right with the normal of face number `+c),e!==3&&console.error(`THREE.STLLoader: Something isn't right with the vertices of face number `+c),c++}let r=_,a=v-_;n.userData.groupNames=p,n.addGroup(r,a,g),g++}return n.setAttribute(`position`,new o(d,3)),n.setAttribute(`normal`,new o(f,3)),n}function d(e){return typeof e==`string`?e:new TextDecoder().decode(e)}function f(e){if(typeof e==`string`){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t.buffer||t}else return e}let p=f(t);return n(p)?l(p):u(d(t))}};export{c as STLLoader}; |