import{aD as g,D as x,e as N,m as h,aE as D}from"./index-6jOCfdig.js";import{A as I}from"./assetContainer-Drc86vic.js";import"./standardMaterial-BXdzQN--.js";import"./index-Ds2meNS5.js";import"./svelte/svelte_svelte.js";import"./svelte/svelte_animate.js";import"./svelte/svelte_attachments.js";import"./svelte/svelte_easing.js";import"./svelte/svelte_internal_client.js";import"./svelte/svelte_internal_flags_async.js";import"./svelte/svelte_internal_flags_legacy.js";import"./svelte/svelte_internal_flags_tracing.js";import"./svelte/svelte_internal_server.js";import"./svelte/svelte_legacy.js";import"./svelte/svelte_motion.js";import"./svelte/svelte_reactivity.js";import"./svelte/svelte_reactivity_window.js";import"./svelte/svelte_server.js";import"./svelte/svelte_store.js";import"./svelte/svelte_transition.js";import"./svelte/svelte_events.js";class m{constructor(){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=g.name,this.extensions=g.extensions}importMesh(r,o,t,i,c){let s;if(typeof t!="string"){if(this._isBinary(t)){const e=new x("stlmesh",o);return this._parseBinary(e,t),c&&c.push(e),!0}t=new TextDecoder().decode(new Uint8Array(t))}for(;s=this.solidPattern.exec(t);){let e=s[1];const u=s[3];if(u&&e!=u)return N.Error("Error in STL, solid name != endsolid name"),!1;if(r&&e){if(r instanceof Array){if(!r.indexOf(e))continue}else if(e!==r)continue}e=e||"stlmesh";const a=new x(e,o);this._parseASCII(a,s[2]),c&&c.push(a)}return!0}load(r,o,t){return this.importMesh(null,r,o,t,null)}loadAssetContainer(r,o,t){const i=new I(r);return r._blockEntityCollection=!0,this.importMesh(null,r,o,t,i.meshes),r._blockEntityCollection=!1,i}_isBinary(r){const o=new DataView(r);if(o.byteLength<=80)return!1;const t=32/8*3+32/8*3*3+16/8,i=o.getUint32(80,!0);if(80+32/8+i*t===o.byteLength)return!0;const c=[115,111,108,105,100];for(let s=0;s<5;s++)if(o.getUint8(s)!==c[s])return!0;return!1}_parseBinary(r,o){const t=new DataView(o),i=t.getUint32(80,!0),c=84,s=50;let e=0;const u=new Float32Array(i*3*3),a=new Float32Array(i*3*3),l=new Uint32Array(i*3);let n=0;for(let d=0;d<i;d++){const p=c+d*s,A=t.getFloat32(p,!0),_=t.getFloat32(p+4,!0),O=t.getFloat32(p+8,!0);for(let E=1;E<=3;E++){const f=p+E*12;u[e]=t.getFloat32(f,!0),a[e]=A,m.DO_NOT_ALTER_FILE_COORDINATES?(u[e+1]=t.getFloat32(f+4,!0),u[e+2]=t.getFloat32(f+8,!0),a[e+1]=_,a[e+2]=O):(u[e+2]=t.getFloat32(f+4,!0),u[e+1]=t.getFloat32(f+8,!0),a[e+2]=_,a[e+1]=O),e+=3}m.DO_NOT_ALTER_FILE_COORDINATES?(l[n]=n,l[n+1]=n+2,l[n+2]=n+1,n+=3):(l[n]=n++,l[n]=n++,l[n]=n++)}r.setVerticesData(h.PositionKind,u),r.setVerticesData(h.NormalKind,a),r.setIndices(l),r.computeWorldMatrix(!0)}_parseASCII(r,o){const t=[],i=[],c=[];let s=0,e;for(;e=this.facetsPattern.exec(o);){const u=e[1],a=this.normalPattern.exec(u);if(this.normalPattern.lastIndex=0,!a)continue;const l=[Number(a[1]),Number(a[5]),Number(a[3])];let n;for(;n=this.vertexPattern.exec(u);)m.DO_NOT_ALTER_FILE_COORDINATES?(t.push(Number(n[1]),Number(n[3]),Number(n[5])),i.push(l[0],l[2],l[1])):(t.push(Number(n[1]),Number(n[5]),Number(n[3])),i.push(l[0],l[1],l[2]));m.DO_NOT_ALTER_FILE_COORDINATES?(c.push(s,s+2,s+1),s+=3):c.push(s++,s++,s++),this.vertexPattern.lastIndex=0}this.facetsPattern.lastIndex=0,r.setVerticesData(h.PositionKind,t),r.setVerticesData(h.NormalKind,i),r.setIndices(c),r.computeWorldMatrix(!0)}}m.DO_NOT_ALTER_FILE_COORDINATES=!1;D(new m);export{m as STLFileLoader};
