import{t as e}from"../webview.js";var t=class{parse(t,n={}){n=Object.assign({binary:!1},n);let r=n.binary,i=[],a=0;t.traverse(function(e){if(e.isMesh){let t=e.geometry,n=t.index,r=t.getAttribute(`position`);a+=n===null?r.count/3:n.count/3,i.push({object3d:e,geometry:t})}});let o,s=80;if(r===!0){let e=a*2+a*3*4*4+80+4,t=new ArrayBuffer(e);o=new DataView(t),o.setUint32(s,a,!0),s+=4}else o=``,o+=`solid exported
`;let c=new e,l=new e,u=new e,d=new e,f=new e,p=new e;for(let e=0,t=i.length;e<t;e++){let t=i[e].object3d,n=i[e].geometry,r=n.index,a=n.getAttribute(`position`);if(r!==null)for(let e=0;e<r.count;e+=3)m(r.getX(e+0),r.getX(e+1),r.getX(e+2),a,t);else for(let e=0;e<a.count;e+=3)m(e+0,e+1,e+2,a,t)}return r===!1&&(o+=`endsolid exported
`),o;function m(e,t,n,i,a){c.fromBufferAttribute(i,e),l.fromBufferAttribute(i,t),u.fromBufferAttribute(i,n),a.isSkinnedMesh===!0&&(a.applyBoneTransform(e,c),a.applyBoneTransform(t,l),a.applyBoneTransform(n,u)),c.applyMatrix4(a.matrixWorld),l.applyMatrix4(a.matrixWorld),u.applyMatrix4(a.matrixWorld),h(c,l,u),g(c),g(l),g(u),r===!0?(o.setUint16(s,0,!0),s+=2):(o+=`		endloop
`,o+=`	endfacet
`)}function h(e,t,n){d.subVectors(n,t),f.subVectors(e,t),d.cross(f).normalize(),p.copy(d).normalize(),r===!0?(o.setFloat32(s,p.x,!0),s+=4,o.setFloat32(s,p.y,!0),s+=4,o.setFloat32(s,p.z,!0),s+=4):(o+=`	facet normal `+p.x+` `+p.y+` `+p.z+`
`,o+=`		outer loop
`)}function g(e){r===!0?(o.setFloat32(s,e.x,!0),s+=4,o.setFloat32(s,e.y,!0),s+=4,o.setFloat32(s,e.z,!0),s+=4):o+=`			vertex `+e.x+` `+e.y+` `+e.z+`
`}}};export{t as STLExporter};