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