filens-preview 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -16
- package/dist/all-in-one/THIRD-PARTY-NOTICES.txt +1902 -63
- package/dist/all-in-one/archive/7zz.wasm +0 -0
- package/dist/all-in-one/assets/archive-worker-Cy3bEdVg.js +2 -0
- package/dist/all-in-one/filens.js +5063 -108925
- package/dist/all-in-one/index.html +12 -3
- package/dist/index.d.ts +7 -0
- package/dist/split/THIRD-PARTY-NOTICES.txt +1902 -63
- package/dist/split/archive/7zz.wasm +0 -0
- package/dist/split/assets/archive-worker-Cy3bEdVg.js +2 -0
- package/dist/split/assets/{iwork-worker-DiTOJG8f.js → iwork-worker-B9KPoDW3.js} +17 -17
- package/dist/split/chunks/archive-DMapcEqq.js +1 -0
- package/dist/split/chunks/browser-video-session-CGI8FpX_.js +1 -0
- package/dist/split/chunks/cad-BvXJNqHR.js +7 -0
- package/dist/split/chunks/core-BLayEJn5.js +17 -0
- package/dist/split/chunks/diagram-DlpgioZ9.js +1 -0
- package/dist/split/chunks/docx-Sii3GNtE.js +1 -0
- package/dist/split/chunks/ebook-CLCQfska.js +5 -0
- package/dist/split/chunks/index-BPK_cNTp.js +1 -0
- package/dist/split/chunks/index-DI_GyFX1.js +1 -0
- package/dist/split/chunks/iwork-Datv3D5d.js +4 -0
- package/dist/split/chunks/media-runtime-tb-Q4Sah.js +1 -0
- package/dist/split/chunks/mindmap-B_GYpiFO.js +1 -0
- package/dist/split/chunks/model3d-BsIQNF2D.js +55 -0
- package/dist/split/chunks/mp4box.all-Bw_Tlr0T-D0URDfA1.js +1 -0
- package/dist/split/chunks/panorama-CIdiLIwD.js +973 -0
- package/dist/split/chunks/pdf-Dzzffz3p.js +12 -0
- package/dist/split/chunks/vendor-CBCxJuSg.js +4115 -0
- package/dist/split/chunks/xlsx-D2NFYc3n.js +3 -0
- package/dist/split/converter-image.wasm +0 -0
- package/dist/split/filens.js +2 -4781
- package/dist/split/index.html +12 -3
- package/package.json +2 -2
- package/dist/split/chunks/archive-_cUUL2-3.js +0 -731
- package/dist/split/chunks/cad-Cyh8aipO.js +0 -2405
- package/dist/split/chunks/core-gp02JQ3r.js +0 -14182
- package/dist/split/chunks/diagram-rxvArV-1.js +0 -654
- package/dist/split/chunks/docx-ecvZsSWm.js +0 -299
- package/dist/split/chunks/ebook-5FyKWZ8s.js +0 -623
- package/dist/split/chunks/iwork-DlaehzuR.js +0 -772
- package/dist/split/chunks/media-runtime-DwW7eq4g.js +0 -48
- package/dist/split/chunks/mindmap-D9lNNDoa.js +0 -560
- package/dist/split/chunks/model3d-BtFT01ZH.js +0 -5093
- package/dist/split/chunks/panorama-Ci6DK6sa.js +0 -5960
- package/dist/split/chunks/pdf-CecYOWld.js +0 -17898
- package/dist/split/chunks/vendor-DvWhw-zP.js +0 -54471
- package/dist/split/chunks/xlsx-VJTu9XNS.js +0 -818
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var Gn=Object.defineProperty;var Un=(n,e,t)=>e in n?Gn(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var M=(n,e,t)=>Un(n,typeof e!="symbol"?e+"":e,t);import{c as _n,o as Vn}from"./core-BLayEJn5.js";import{L as Ne,M as V,b as ne,F as et,S as $n,C as de,V as E,d as ee,e as en,R as tn,B as Y,g as ie,h as Q,j as $,k as Wn,l as at,P as we,m as yt,E as vt,A as xt,D as Oe,n as te,o as Mt,O as Kn,p as Z,q as _e,r as Pe,t as me,v as Yn,w as Ve,x as Te,y as Ee,z as St,H as fe,I as Xn,K as Zn,N as nn,Q as qn,T as Jn,W as Qn,X as er,Y as tr,Z as nr,_ as rr,$ as sr,a0 as ir,a1 as ar,a2 as or,a3 as lr,a4 as cr,a5 as ur,a6 as dr,a7 as hr,a8 as mr,J as fr,a9 as pr,aa as gr,ab as wr}from"./vendor-CBCxJuSg.js";import{c as br}from"./panorama-CIdiLIwD.js";const Ct=0,Pt=1,Lt=2,Et=3,Ft=4,At=5,$e=0,yr=1,vr=2,xr=3,Mr=4,Sr=5,Dt=6,ae="16",ve="24",ke=$n,He=new E,je=new E;class Cr extends Q{constructor(e,t){super(e,t),this.isConditionalLine=true}}function Pr(n){for(let e=0,t=n.length;e<t;e++){const r=n[e],s=r.vertices,i=s[0],a=s[1],o=s[2];He.subVectors(a,i),je.subVectors(o,a),r.faceNormal=new E().crossVectors(He,je).normalize()}}const Nt=new tn;function Lr(n,e,t=false){const r=100.00000001000001;function s(f){const m=~~(f.x*r),g=~~(f.y*r),w=~~(f.z*r);return`${m},${g},${w}`}function i(f,m){return`${s(f)}_${s(m)}`}function a(f,m,g){g.direction.subVectors(m,f).normalize();const w=f.dot(g.direction);return g.origin.copy(f).addScaledVector(g.direction,-w),g}function o(f){return i(f.origin,f.direction)}const u=new Set,l=new Map,c=new Map,d=[];for(let f=0,m=e.length;f<m;f++){const w=e[f].vertices,p=w[0],b=w[1];if(u.add(i(p,b)),u.add(i(b,p)),t){const y=a(p,b,new tn),C=o(y);if(!l.has(C)){a(b,p,y);const k=o(y),D={ray:y,distances:[]};l.set(C,D),l.set(k,D)}const P=l.get(C);let S=P.ray.direction.dot(p),L=P.ray.direction.dot(b);S>L&&([S,L]=[L,S]),P.distances.push(S,L)}}for(let f=0,m=n.length;f<m;f++){const g=n[f],w=g.vertices,p=w.length;for(let b=0;b<p;b++){const y=b,C=(b+1)%p,P=w[y],S=w[C],L=i(P,S);if(u.has(L))continue;if(t){a(P,S,Nt);const D=o(Nt);if(l.has(D)){const N=l.get(D),{ray:v,distances:O}=N;let A=v.direction.dot(P),x=v.direction.dot(S);A>x&&([A,x]=[x,A]);let z=false;for(let H=0,U=O.length;H<U;H+=2)if(A>=O[H]&&x<=O[H+1]){z=true;break}if(z)continue}}const k={index:y,tri:g};c.set(L,k)}}const h=c.values();for(;;){const f=h.next().value;if(f===void 0)break;const m=[f];for(;m.length>0;){const g=m.pop().tri,w=g.vertices,p=g.normals,b=g.faceNormal,y=w.length;for(let C=0;C<y;C++){const P=C,S=(C+1)%y,L=w[P],k=w[S],D=i(L,k);c.delete(D);const N=i(k,L),v=c.get(N);if(v){const O=v.tri,A=v.index,x=O.normals,z=x.length,H=O.faceNormal;if(Math.abs(O.faceNormal.dot(g.faceNormal))<.25)continue;c.has(N)&&(m.push(v),c.delete(N));const U=(A+1)%z;p[P]&&x[U]&&p[P]!==x[U]&&(x[U].norm.add(p[P].norm),p[P].norm=x[U].norm);let I=p[P]||x[U];I===null&&(I={norm:new E},d.push(I.norm)),p[P]===null&&(p[P]=I,I.norm.add(b)),x[U]===null&&(x[U]=I,I.norm.add(H)),p[S]&&x[A]&&p[S]!==x[A]&&(x[A].norm.add(p[S].norm),p[S].norm=x[A].norm);let B=p[S]||x[A];B===null&&(B={norm:new E},d.push(B.norm)),p[S]===null&&(p[S]=B,B.norm.add(b)),x[A]===null&&(x[A]=B,B.norm.add(H))}}}}for(let f=0,m=d.length;f<m;f++)d[f].normalize()}function Ot(n){return n==="Part"||n==="Unofficial_Part"}function Er(n){return/primitive/i.test(n)||n==="Subpart"}class Se{constructor(e,t){this.line=e,this.lineLength=e.length,this.currentCharIndex=0,this.currentChar=" ",this.lineNumber=t}seekNonSpace(){for(;this.currentCharIndex<this.lineLength;){if(this.currentChar=this.line.charAt(this.currentCharIndex),this.currentChar!==" "&&this.currentChar!==" ")return;this.currentCharIndex++}}getToken(){const e=this.currentCharIndex++;for(;this.currentCharIndex<this.lineLength&&(this.currentChar=this.line.charAt(this.currentCharIndex),!(this.currentChar===" "||this.currentChar===" "));)this.currentCharIndex++;const t=this.currentCharIndex;return this.seekNonSpace(),this.line.substring(e,t)}getVector(){return new E(parseFloat(this.getToken()),parseFloat(this.getToken()),parseFloat(this.getToken()))}getRemainingString(){return this.line.substring(this.currentCharIndex,this.lineLength)}isAtTheEnd(){return this.currentCharIndex>=this.lineLength}setToEnd(){this.currentCharIndex=this.lineLength}getLineNumberString(){return this.lineNumber>=0?" at line "+this.lineNumber:""}}class Fr{constructor(e){this.loader=e,this._cache={}}cloneResult(e){const t={};return t.faces=e.faces.map(r=>({colorCode:r.colorCode,material:r.material,vertices:r.vertices.map(s=>s.clone()),normals:r.normals.map(()=>null),faceNormal:null})),t.conditionalSegments=e.conditionalSegments.map(r=>({colorCode:r.colorCode,material:r.material,vertices:r.vertices.map(s=>s.clone()),controlPoints:r.controlPoints.map(s=>s.clone())})),t.lineSegments=e.lineSegments.map(r=>({colorCode:r.colorCode,material:r.material,vertices:r.vertices.map(s=>s.clone())})),t.type=e.type,t.category=e.category,t.keywords=e.keywords,t.author=e.author,t.subobjects=e.subobjects,t.fileName=e.fileName,t.totalFaces=e.totalFaces,t.startingBuildingStep=e.startingBuildingStep,t.materials=e.materials,t.group=null,t}async fetchData(e){let t=false,r=$e;for(;r!==Dt;){let s=e;switch(r){case xr:r=r+1;break;case $e:s="parts/"+s,r=r+1;break;case yr:s="p/"+s,r=r+1;break;case vr:s="models/"+s,r=r+1;break;case Mr:s=e.substring(0,e.lastIndexOf("/")+1)+s,r=r+1;break;case Sr:t?r=Dt:(e=e.toLowerCase(),s=e,t=true,r=$e);break}const i=this.loader,a=new et(i.manager);a.setPath(i.partsLibraryPath),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials);try{return await a.loadAsync(s)}catch{continue}}throw new Error('LDrawLoader: Subobject "'+e+'" could not be loaded.')}parse(e,t=null){const r=this.loader,s=[],i=[],a=[],o=[],u={},l=D=>u[D]||null;let c="Model",d=null,h=null,f=null,m=0;e.indexOf(`\r
|
|
2
|
+
`)!==-1&&(e=e.replace(/\r\n/g,`
|
|
3
|
+
`));const g=e.split(`
|
|
4
|
+
`),w=g.length;let p=false,b=null,y=null,C=false,P=true,S=false,L=true,k=false;for(let D=0;D<w;D++){const N=g[D];if(N.length===0)continue;if(p){N.startsWith("0 FILE ")?(this.setData(b,y),b=N.substring(7),y=""):y+=N+`
|
|
5
|
+
`;continue}const v=new Se(N,D+1);if(v.seekNonSpace(),v.isAtTheEnd())continue;const O=v.getToken();let A,x,z,H,U,I,B,se,De,pt,gt;switch(O){case"0":const wt=v.getToken();if(wt)switch(wt){case"!LDRAW_ORG":c=v.getToken();break;case"!COLOUR":A=r.parseColorMetaDirective(v),A?u[A.userData.code]=A:console.warn("LDrawLoader: Error parsing material"+v.getLineNumberString());break;case"!CATEGORY":d=v.getToken();break;case"!KEYWORDS":const bt=v.getRemainingString().split(",");bt.length>0&&(h||(h=[]),bt.forEach(function(ce){h.push(ce.trim())}));break;case"FILE":D>0&&(p=true,b=v.getRemainingString(),y="",C=false,P=true);break;case"BFC":for(;!v.isAtTheEnd();){const ce=v.getToken();switch(ce){case"CERTIFY":case"NOCERTIFY":C=ce==="CERTIFY",P=true;break;case"CW":case"CCW":P=ce==="CCW";break;case"INVERTNEXT":S=true;break;case"CLIP":case"NOCLIP":L=ce==="CLIP";break;default:console.warn('THREE.LDrawLoader: BFC directive "'+ce+'" is unknown.');break}}break;case"STEP":k=true;break;case"Author:":f=v.getToken();break}break;case"1":x=v.getToken(),A=l(x);const Fn=parseFloat(v.getToken()),An=parseFloat(v.getToken()),Dn=parseFloat(v.getToken()),Nn=parseFloat(v.getToken()),On=parseFloat(v.getToken()),kn=parseFloat(v.getToken()),Rn=parseFloat(v.getToken()),Tn=parseFloat(v.getToken()),In=parseFloat(v.getToken()),Bn=parseFloat(v.getToken()),zn=parseFloat(v.getToken()),Hn=parseFloat(v.getToken()),jn=new en().set(Nn,On,kn,Fn,Rn,Tn,In,An,Bn,zn,Hn,Dn,0,0,0,1);let J=v.getRemainingString().trim().replace(/\\/g,"/");r.fileMap[J]?J=r.fileMap[J]:J.startsWith("s/")?J="parts/"+J:J.startsWith("48/")&&(J="p/"+J),o.push({material:A,colorCode:x,matrix:jn,fileName:J,inverted:S,startingBuildingStep:k}),k=false,S=false;break;case"2":x=v.getToken(),A=l(x),I=v.getVector(),B=v.getVector(),z={material:A,colorCode:x,vertices:[I,B]},i.push(z);break;case"5":x=v.getToken(),A=l(x),I=v.getVector(),B=v.getVector(),pt=v.getVector(),gt=v.getVector(),z={material:A,colorCode:x,vertices:[I,B],controlPoints:[pt,gt]},a.push(z);break;case"3":x=v.getToken(),A=l(x),H=P,U=!C||!L,H===true?(I=v.getVector(),B=v.getVector(),se=v.getVector()):(se=v.getVector(),B=v.getVector(),I=v.getVector()),s.push({material:A,colorCode:x,faceNormal:null,vertices:[I,B,se],normals:[null,null,null]}),m++,U===true&&(s.push({material:A,colorCode:x,faceNormal:null,vertices:[se,B,I],normals:[null,null,null]}),m++);break;case"4":x=v.getToken(),A=l(x),H=P,U=!C||!L,H===true?(I=v.getVector(),B=v.getVector(),se=v.getVector(),De=v.getVector()):(De=v.getVector(),se=v.getVector(),B=v.getVector(),I=v.getVector()),s.push({material:A,colorCode:x,faceNormal:null,vertices:[I,B,se,De],normals:[null,null,null,null]}),m+=2,U===true&&(s.push({material:A,colorCode:x,faceNormal:null,vertices:[De,se,B,I],normals:[null,null,null,null]}),m+=2);break;default:throw new Error('LDrawLoader: Unknown line type "'+O+'"'+v.getLineNumberString()+".")}}return p&&this.setData(b,y),{faces:s,conditionalSegments:a,lineSegments:i,type:c,category:d,keywords:h,author:f,subobjects:o,totalFaces:m,startingBuildingStep:k,materials:u,fileName:t,group:null}}getData(e,t=true){const r=e.toLowerCase(),s=this._cache[r];return s===null||s instanceof Promise?null:t?this.cloneResult(s):s}async ensureDataLoaded(e){const t=e.toLowerCase();t in this._cache||(this._cache[t]=this.fetchData(e).then(r=>{const s=this.parse(r,e);return this._cache[t]=s,s})),await this._cache[t]}setData(e,t){const r=e.toLowerCase();this._cache[r]=this.parse(t,e)}}function We(n,e,t,r){return(!r&&n===ae||r&&n===ve)&&(n=e),t[n]||null}class Ar{constructor(e){this.loader=e,this.parseCache=new Fr(e),this._cache={}}async processIntoMesh(e){const t=this.loader,r=this.parseCache,s=new Set,i=async(o,u=null)=>{const l=o.subobjects,c=[];for(let f=0,m=l.length;f<m;f++){const g=l[f],w=r.ensureDataLoaded(g.fileName).then(()=>{const p=r.getData(g.fileName,false);return Er(p.type)?i(r.getData(g.fileName),g):this.loadModel(g.fileName).catch(b=>(console.warn(b),null))});c.push(w)}const d=new ee;d.userData.category=o.category,d.userData.keywords=o.keywords,d.userData.author=o.author,d.userData.type=o.type,d.userData.fileName=o.fileName,o.group=d;const h=await Promise.all(c);for(let f=0,m=h.length;f<m;f++){const g=o.subobjects[f],w=h[f];if(w===null)continue;if(w.isGroup){const O=w;g.matrix.decompose(O.position,O.quaternion,O.scale),O.userData.startingBuildingStep=g.startingBuildingStep,O.name=g.fileName,t.applyMaterialsToMesh(O,g.colorCode,o.materials),O.userData.colorCode=g.colorCode,d.add(O);continue}w.group.children.length&&d.add(w.group);const p=o.lineSegments,b=o.conditionalSegments,y=o.faces,C=w.lineSegments,P=w.conditionalSegments,S=w.faces,L=g.matrix,k=g.inverted,D=L.determinant()<0,N=g.colorCode,v=N===ae?ve:N;for(let O=0,A=C.length;O<A;O++){const x=C[O],z=x.vertices;z[0].applyMatrix4(L),z[1].applyMatrix4(L),x.colorCode=x.colorCode===ve?v:x.colorCode,x.material=x.material||We(x.colorCode,x.colorCode,o.materials,true),p.push(x)}for(let O=0,A=P.length;O<A;O++){const x=P[O],z=x.vertices,H=x.controlPoints;z[0].applyMatrix4(L),z[1].applyMatrix4(L),H[0].applyMatrix4(L),H[1].applyMatrix4(L),x.colorCode=x.colorCode===ve?v:x.colorCode,x.material=x.material||We(x.colorCode,x.colorCode,o.materials,true),b.push(x)}for(let O=0,A=S.length;O<A;O++){const x=S[O],z=x.vertices;for(let H=0,U=z.length;H<U;H++)z[H].applyMatrix4(L);x.colorCode=x.colorCode===ae?N:x.colorCode,x.material=x.material||We(x.colorCode,N,o.materials,false),s.add(x.colorCode),D!==k&&z.reverse(),y.push(x)}o.totalFaces+=w.totalFaces}return u&&(t.applyMaterialsToMesh(d,u.colorCode,o.materials),d.userData.colorCode=u.colorCode),o};for(let o=0,u=e.faces;o<u;o++)s.add(e.faces[o].colorCode);if(await i(e),t.smoothNormals){const o=s.size>1;Pr(e.faces),Lr(e.faces,e.lineSegments,o)}const a=e.group;return e.faces.length>0&&a.add(Ke(this.loader,e.faces,3,false,e.totalFaces)),e.lineSegments.length>0&&a.add(Ke(this.loader,e.lineSegments,2)),e.conditionalSegments.length>0&&a.add(Ke(this.loader,e.conditionalSegments,2,true)),a}hasCachedModel(e){return e!==null&&e.toLowerCase()in this._cache}async getCachedModel(e){if(e!==null&&this.hasCachedModel(e)){const t=e.toLowerCase();return(await this._cache[t]).clone()}else return null}async loadModel(e){const t=this.parseCache,r=e.toLowerCase();if(this.hasCachedModel(e))return this.getCachedModel(e);{await t.ensureDataLoaded(e);const s=t.getData(e),i=this.processIntoMesh(s);return this.hasCachedModel(e)?this.getCachedModel(e):(Ot(s.type)&&(this._cache[r]=i),(await i).clone())}}async parseModel(e){const r=this.parseCache.parse(e);return Ot(r.type)&&this.hasCachedModel(r.fileName)?this.getCachedModel(r.fileName):this.processIntoMesh(r)}}function Dr(n,e){return n.colorCode===e.colorCode?0:n.colorCode<e.colorCode?-1:1}function Ke(n,e,t,r=false,s=null){e.sort(Dr),s===null&&(s=e.length);const i=new Float32Array(t*s*3),a=t===3?new Float32Array(t*s*3):null,o=[],u=new Array(6),l=new Y;let c=null,d=0,h=0,f=0;for(let g=0,w=e.length;g<w;g++){const p=e[g];let b=p.vertices;b.length===4&&(u[0]=b[0],u[1]=b[1],u[2]=b[2],u[3]=b[0],u[4]=b[2],u[5]=b[3],b=u);for(let y=0,C=b.length;y<C;y++){const P=b[y],S=f+y*3;i[S+0]=P.x,i[S+1]=P.y,i[S+2]=P.z}if(t===3){if(!p.faceNormal){const C=b[0],P=b[1],S=b[2];He.subVectors(P,C),je.subVectors(S,P),p.faceNormal=new E().crossVectors(He,je).normalize()}let y=p.normals;y.length===4&&(u[0]=y[0],u[1]=y[1],u[2]=y[2],u[3]=y[0],u[4]=y[2],u[5]=y[3],y=u);for(let C=0,P=y.length;C<P;C++){let S=p.faceNormal;y[C]&&(S=y[C].norm);const L=f+C*3;a[L+0]=S.x,a[L+1]=S.y,a[L+2]=S.z}}if(c!==p.colorCode){c!==null&&l.addGroup(d,h,o.length-1);const y=p.material;if(y!==null){if(t===3)o.push(y);else if(t===2)if(r){const C=n.edgeMaterialCache.get(y);o.push(n.conditionalEdgeMaterialCache.get(C))}else o.push(n.edgeMaterialCache.get(y))}else o.push(p.colorCode);c=p.colorCode,d=f/3,h=b.length}else h+=b.length;f+=3*b.length}h>0&&l.addGroup(d,1/0,o.length-1),l.setAttribute("position",new ie(i,3)),a!==null&&l.setAttribute("normal",new ie(a,3));let m=null;if(t===2?r?m=new Cr(l,o.length===1?o[0]:o):m=new Q(l,o.length===1?o[0]:o):t===3&&(m=new $(l,o.length===1?o[0]:o)),r){m.isConditionalLine=true;const g=new Float32Array(e.length*3*2),w=new Float32Array(e.length*3*2),p=new Float32Array(e.length*3*2);for(let b=0,y=e.length;b<y;b++){const C=e[b],P=C.vertices,S=C.controlPoints,L=S[0],k=S[1],D=P[0],N=P[1],v=b*3*2;g[v+0]=L.x,g[v+1]=L.y,g[v+2]=L.z,g[v+3]=L.x,g[v+4]=L.y,g[v+5]=L.z,w[v+0]=k.x,w[v+1]=k.y,w[v+2]=k.z,w[v+3]=k.x,w[v+4]=k.y,w[v+5]=k.z,p[v+0]=N.x-D.x,p[v+1]=N.y-D.y,p[v+2]=N.z-D.z,p[v+3]=N.x-D.x,p[v+4]=N.y-D.y,p[v+5]=N.z-D.z}l.setAttribute("control0",new ie(g,3,false)),l.setAttribute("control1",new ie(w,3,false)),l.setAttribute("direction",new ie(p,3,false))}return m}class Nr extends Ne{constructor(e){super(e),this.materials=[],this.materialLibrary={},this.edgeMaterialCache=new WeakMap,this.conditionalEdgeMaterialCache=new WeakMap,this.partsCache=new Ar(this),this.fileMap={},this.smoothNormals=true,this.partsLibraryPath="",this.ConditionalLineMaterial=null,this.missingColorMaterial=new V({name:Ne.DEFAULT_MATERIAL_NAME,color:16711935,roughness:.3,metalness:0}),this.missingEdgeColorMaterial=new ne({name:Ne.DEFAULT_MATERIAL_NAME,color:16711935}),this.missingConditionalEdgeColorMaterial=null,this.edgeMaterialCache.set(this.missingColorMaterial,this.missingEdgeColorMaterial),this.conditionalEdgeMaterialCache.set(this.missingEdgeColorMaterial,this.missingConditionalEdgeColorMaterial)}setPartsLibraryPath(e){return this.partsLibraryPath=e,this}setConditionalLineMaterial(e){return this.ConditionalLineMaterial=e,this.missingConditionalEdgeColorMaterial=new this.ConditionalLineMaterial({name:Ne.DEFAULT_MATERIAL_NAME,fog:true,color:16711935}),this}async preloadMaterials(e){const t=new et(this.manager);t.setPath(this.path),t.setRequestHeader(this.requestHeader),t.setWithCredentials(this.withCredentials);const r=await t.loadAsync(e),s=/^0 !COLOUR/,i=r.split(/[\n\r]/g),a=[];for(let o=0,u=i.length;o<u;o++){const l=i[o];if(s.test(l)){const c=l.replace(s,""),d=this.parseColorMetaDirective(new Se(c));a.push(d)}}this.setMaterials(a)}load(e,t,r,s){const i=new et(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,a=>{this.setMaterials([]),this.partsCache.parseModel(a).then(o=>{this.applyMaterialsToMesh(o,ae,this.materialLibrary,true),this.computeBuildingSteps(o),o.userData.fileName=e,t(o)}).catch(s)},r,s)}parse(e,t,r){this.partsCache.parseModel(e).then(s=>{this.applyMaterialsToMesh(s,ae,this.materialLibrary,true),this.computeBuildingSteps(s),s.userData.fileName="",t(s)}).catch(r)}setMaterials(e){this.materialLibrary={},this.materials=[];for(let t=0,r=e.length;t<r;t++)this.addMaterial(e[t]);return this.addMaterial(this.parseColorMetaDirective(new Se("Main_Colour CODE 16 VALUE #FF8080 EDGE #333333"))),this.addMaterial(this.parseColorMetaDirective(new Se("Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333"))),this}setFileMap(e){return this.fileMap=e,this}addMaterial(e){const t=this.materialLibrary;return t[e.userData.code]||(this.materials.push(e),t[e.userData.code]=e),this}getMaterial(e){if(e.startsWith("0x2")){const t=e.substring(3);return this.parseColorMetaDirective(new Se("Direct_Color_"+t+" CODE -1 VALUE #"+t+" EDGE #"+t))}return this.materialLibrary[e]||null}applyMaterialsToMesh(e,t,r,s=false){const i=this,a=t===ae;e.traverse(u=>{if(u.isMesh||u.isLineSegments)if(Array.isArray(u.material))for(let l=0,c=u.material.length;l<c;l++)u.material[l].isMaterial||(u.material[l]=o(u,u.material[l]));else u.material.isMaterial||(u.material=o(u,u.material))});function o(u,l){if(a&&!(l in r)&&!s)return l;const c=u.isLineSegments||u.isConditionalLine;(!c&&l===ae||c&&l===ve)&&(l=t);let h=null;if(l in r)h=r[l];else if(s)h=i.getMaterial(l),h===null&&(console.warn(`LDrawLoader: Material properties for code ${l} not available.`),h=i.missingColorMaterial);else return l;return u.isLineSegments&&(h=i.edgeMaterialCache.get(h),u.isConditionalLine&&(h=i.conditionalEdgeMaterialCache.get(h))),h}}getMainMaterial(){return this.getMaterial(ae)}getMainEdgeMaterial(){const e=this.getMaterial(ve);return e?this.edgeMaterialCache.get(e):null}parseColorMetaDirective(e){let t=null,r="#FF00FF",s="#FF00FF",i=1,a=false,o=0,u=Ct,l=null;const c=e.getToken();if(!c)throw new Error('LDrawLoader: Material name was expected after "!COLOUR tag'+e.getLineNumberString()+".");let d=null;for(;d=e.getToken(),!!d;)if(!f(d))switch(d.toUpperCase()){case"CODE":t=e.getToken();break;case"VALUE":if(r=e.getToken(),r.startsWith("0x"))r="#"+r.substring(2);else if(!r.startsWith("#"))throw new Error("LDrawLoader: Invalid color while parsing material"+e.getLineNumberString()+".");break;case"EDGE":if(s=e.getToken(),s.startsWith("0x"))s="#"+s.substring(2);else if(!s.startsWith("#")){if(l=this.getMaterial(s),!l)throw new Error("LDrawLoader: Invalid edge color while parsing material"+e.getLineNumberString()+".");l=this.edgeMaterialCache.get(l)}break;case"ALPHA":if(i=parseInt(e.getToken()),isNaN(i))throw new Error("LDrawLoader: Invalid alpha value in material definition"+e.getLineNumberString()+".");i=Math.max(0,Math.min(1,i/255)),i<1&&(a=true);break;case"LUMINANCE":if(!f(e.getToken()))throw new Error("LDrawLoader: Invalid luminance value in material definition"+e.getLineNumberString()+".");break;case"CHROME":u=Pt;break;case"PEARLESCENT":u=Lt;break;case"RUBBER":u=Et;break;case"MATTE_METALLIC":u=Ft;break;case"METAL":u=At;break;case"MATERIAL":e.setToEnd();break;default:throw new Error('LDrawLoader: Unknown token "'+d+'" while parsing material'+e.getLineNumberString()+".")}let h=null;switch(u){case Ct:h=new V({roughness:.3,metalness:0});break;case Lt:h=new V({roughness:.3,metalness:.25});break;case Pt:h=new V({roughness:0,metalness:1});break;case Et:h=new V({roughness:.9,metalness:0});break;case Ft:h=new V({roughness:.8,metalness:.4});break;case At:h=new V({roughness:.2,metalness:.85});break}if(h.color.setStyle(r,ke),h.transparent=a,h.premultipliedAlpha=true,h.opacity=i,h.depthWrite=!a,h.polygonOffset=true,h.polygonOffsetFactor=1,o!==0&&h.emissive.setStyle(r,ke).multiplyScalar(o),!l){if(l=new ne({color:new de().setStyle(s,ke),transparent:a,opacity:i,depthWrite:!a}),l.color,l.userData.code=t,l.name=c+" - Edge",this.ConditionalLineMaterial===null)throw new Error("THREE.LDrawLoader: ConditionalLineMaterial type must be specified via .setConditionalLineMaterial().");const m=new this.ConditionalLineMaterial({fog:true,transparent:a,depthWrite:!a,color:new de().setStyle(s,ke),opacity:i});m.userData.code=t,m.name=c+" - Conditional Edge",this.conditionalEdgeMaterialCache.set(l,m)}return h.userData.code=t,h.name=c,this.edgeMaterialCache.set(h,l),this.addMaterial(h),h;function f(m){let g;return m.startsWith("LUMINANCE")?g=parseInt(m.substring(9)):g=parseInt(m),isNaN(g)?false:(o=Math.max(0,Math.min(1,g/255)),true)}}computeBuildingSteps(e){let t=0;e.traverse(r=>{r.isGroup&&(r.userData.startingBuildingStep&&t++,r.userData.buildingStep=t)}),e.userData.numBuildingSteps=t+1}}const ot=new Set(["step","stp","stl","obj","ply","gltf","glb","3mf","amf","dae","fbx","3ds","usdz","gcode","gco","nc","wrl","vrml","pcd","xyz","vtk","vox","ldr","mpd","kmz","md2","lwo","bvh","pdb","nrrd","nhdr"]),kt=250,tt=12e3,Or=24,Rt=33;let Me=null;const kr=[{extensions:["step","stp","stl","obj","ply","gltf","glb","3mf","amf","dae","fbx","3ds","usdz","gcode","gco","nc","wrl","vrml","pcd","xyz","vtk","vox","ldr","mpd","kmz","md2","lwo","bvh","pdb","nrrd","nhdr"],family:"model3d",driverId:"model3d",targetFormat:"model3d",contentTypes:["model/stl","model/step","application/step","application/x-step","model/x.stl-ascii","model/x.stl-binary","application/vnd.ms-pki.stl","model/obj","model/ply","application/ply","model/gltf+json","model/gltf-binary","model/3mf","model/amf","application/x-amf","model/vnd.collada+xml","application/vnd.collada+xml","model/fbx","model/3ds","model/vnd.usdz+zip","model/usd","text/x-gcode","model/vrml","x-world/x-vrml","application/vnd.pointcloud","model/vtk","application/vnd.vtk","model/vox","application/x-magica-voxel","model/vnd.ldraw","text/vnd.ldraw","application/x-ldraw","application/vnd.google-earth.kmz","application/vnd.google-earth.kmz+xml","model/md2","application/x-md2","model/lwo","application/x-lwo","application/x-lightwave-object","application/bvh","application/x-bvh","chemical/x-pdb","chemical/pdb","application/nrrd","application/x-nrrd","application/vnd.ms-package.3dmanufacturing-3dmodel+xml"]}];class Rr{constructor(e,t={}){M(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});M(this,"root");M(this,"stage");M(this,"hint");M(this,"renderer",null);M(this,"scene",null);M(this,"camera",null);M(this,"modelGroup",null);M(this,"geometry",null);M(this,"edgeGeometry",null);M(this,"material",null);M(this,"edgeMaterial",null);M(this,"resizeObserver",null);M(this,"animationFrame",0);M(this,"yaw",-35);M(this,"pitch",24);M(this,"distance",140);M(this,"modelRadius",60);M(this,"baseDistance",140);M(this,"baseModelRadius",60);M(this,"baseModelGroupPosition",new E);M(this,"explodeTargets",[]);M(this,"maxExplodeOffset",0);M(this,"materialRuntimeState",new WeakMap);M(this,"sectionSourceGeometry",null);M(this,"raycaster",new Wn);M(this,"pointerNdc",new at);M(this,"measurementLineGeometry",null);M(this,"measurementLineMaterial",null);M(this,"measurementLine",null);M(this,"measurementPointsGeometry",null);M(this,"measurementPointsMaterial",null);M(this,"measurementPoints",null);M(this,"sectionHelperGroup",null);M(this,"sectionPlaneHelper",null);M(this,"sectionPlaneHelperGeometry",null);M(this,"sectionPlaneHelperMaterial",null);M(this,"sectionPlaneOutlineGeometry",null);M(this,"sectionPlaneOutlineMaterial",null);M(this,"sectionPlaneOutline",null);M(this,"sectionPlaneFillGeometry",null);M(this,"sectionPlaneFillMaterial",null);M(this,"sectionPlaneFill",null);M(this,"sectionBoxFillGeometry",null);M(this,"sectionBoxFillMaterial",null);M(this,"sectionBoxFill",null);M(this,"sectionBoxHelperGeometry",null);M(this,"sectionBoxHelperMaterial",null);M(this,"sectionBoxHelper",null);M(this,"sectionPlanes",[new we(new E(1,0,0),0),new we(new E(-1,0,0),0),new we(new E(0,1,0),0),new we(new E(0,-1,0),0),new we(new E(0,0,1),0),new we(new E(0,0,-1),0)]);M(this,"sectionHelperCache",new Map);M(this,"appliedSectionClippingKey",null);M(this,"appliedSectionHelperKey",null);M(this,"lastSectionHelperUpdateAt",Number.NEGATIVE_INFINITY);M(this,"sectionBounds",Ge());M(this,"measurementHoverClientX",null);M(this,"measurementHoverClientY",null);M(this,"projectionMode","perspective");M(this,"viewPreset","isometric");M(this,"displayMode","solid-edge");M(this,"snapshotBackground","scene");M(this,"state");M(this,"loadController",null);M(this,"interactionController",null);M(this,"resize",()=>{if(!this.renderer||!this.camera)return;const e2=this.stage.getBoundingClientRect(),t2=Math.max(1,Math.floor(e2.width||this.stage.clientWidth||1)),r2=Math.max(1,Math.floor(e2.height||this.stage.clientHeight||1));if(this.camera instanceof Mt)this.camera.aspect=t2/r2,this.camera.updateProjectionMatrix();else{const s=t2/r2,i=Math.max(this.modelRadius,1)*1.35/this.state.scale,a=i*s;this.camera.left=-a,this.camera.right=a,this.camera.top=i,this.camera.bottom=-i,this.camera.updateProjectionMatrix()}this.renderer.setSize(t2,r2,false)});this.host=e,this.options=t;const r=this.options.initialScale??1;this.root=document.createElement("div"),this.root.className="model3dv-preview",this.stage=document.createElement("div"),this.stage.className="model3dv-stage",this.hint=document.createElement("div"),this.hint.className="model3dv-hint",this.hint.textContent="Drag to orbit \xB7 Pinch or scroll to zoom",this.root.replaceChildren(this.stage,this.hint),this.host.replaceChildren(this.root),this.state={loading:false,error:null,family:"model3d",warnings:[],capabilities:{zoom:true,fit:true,pan:true,orbit:true,fullscreen:true,download:true,modelTree:true,metadata:true,measure:false,section:false,explode:false,materialFilter:false},scale:Number.isFinite(r)?_(r,.2,4):1,explode:0,displayMode:this.displayMode,snapshotBackground:this.snapshotBackground,measurement:{active:false,status:"idle",snapMode:"surface",axisLock:"free"},section:ue(),camera:{position:[0,0,this.distance],target:[0,0,0],projection:this.projectionMode,viewPreset:this.viewPreset}}}async load(e,t){var a,o,u,l;this.stopLoad();const r=new AbortController;this.loadController=r;const s=r.signal,i=()=>r.abort();s.addEventListener("abort",()=>{var c;(c=t.signal)==null||c.removeEventListener("abort",i),this.loadController===r&&(this.loadController=null,this.disposeScene(),this.state.loading=false,this.emit("statechange",this.state))},{once:true}),(a=t.signal)==null||a.addEventListener("abort",i,{once:true}),this.state={...this.state,loading:true,error:null,title:t.descriptor.name,warnings:[],explode:0,modelTree:void 0,selectedNodeId:void 0,isolatedMaterialKey:void 0,displayMode:this.displayMode,snapshotBackground:this.snapshotBackground,measurement:{active:false,status:"idle",snapMode:"surface",axisLock:"free"},section:ue(),metadata:void 0},this.projectionMode="perspective",this.viewPreset="isometric",this.yaw=-35,this.pitch=24,this.emit("loading",this.state),this.emit("statechange",this.state);try{(o=t.signal)!=null&&o.aborted&&r.abort(),F(s);const c=Sn(((u=t.route)==null?void 0:u.sourceFormat)??t.descriptor.extension);if(!ot.has(c))throw new Error(`3D preview currently supports browser-WASM STEP/STP plus browser-native STL, OBJ, PLY, glTF, GLB, 3MF, AMF, DAE, FBX, 3DS, USDA-backed USDZ, G-code, VRML, PCD, XYZ, VTK, VOX, LDraw, KMZ, MD2, LWO, BVH, PDB, NRRD, and NHDR files, got ${c||"unknown"}.`);const d=await ut(e,s);if(F(s),c==="step"||c==="stp"){const m=await os(d,{signal:s});this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:m.userData.previewWarnings??[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="glb"||c==="gltf"){const m=c==="gltf"?await gs(d,{resourcePath:Cn(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s}):{object:await Gr(d,{signal:s}),warnings:[]};this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="obj"){const m=new TextDecoder().decode(d);let g=[],w;if(this.options.resourceResolver&&rn(m).length){const p=await Br(m,{resourceBasePath:t.descriptor.name,resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});g=p.warnings,w=T(p.object,c),this.createObjectScene(p.object,s)}else{const p=Ir(m);w=jt(p,c),this.createScene(p,s)}this.state={...this.state,loading:false,error:null,warnings:g,metadata:w,camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="amf"){const m=Ur(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="dae"){const m=_r(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourcePath:Vi(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="fbx"){const m=ss(d,{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="3ds"){const m=is(d,{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="usdz"){const m=await as(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="gcode"||c==="gco"||c==="nc"){const m=ls(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="wrl"||c==="vrml"){const m=cs(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="pcd"){const m=us(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="xyz"){const m=ds(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="vtk"){const m=hs(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="vox"){const m=fs(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="ldr"||c==="mpd"){const m=await ps(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="kmz"){const m=await Vr(d,{signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="md2"){const m=Jr(d);this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="lwo"){const m=Qr(d,{resourceBasePath:t.descriptor.name,resourcePath:Ce(e),modelName:$i(t.descriptor.name),resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s});this.createObjectScene(m.object,s),this.state={...this.state,loading:false,error:null,warnings:m.warnings,metadata:T(m.object,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="bvh"){const m=es(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="pdb"){const m=ts(new TextDecoder().decode(d));this.createObjectScene(m,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(m,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}if(c==="nrrd"||c==="nhdr"){const m=c==="nhdr"?await rs(new TextDecoder().decode(d),{resourceBasePath:t.descriptor.name,resourceResolver:this.options.resourceResolver,sourceFormat:c,signal:s}):d;F(s);const g=ns(m);this.createObjectScene(g,s),this.state={...this.state,loading:false,error:null,warnings:[],metadata:T(g,c),camera:this.currentCameraState()},this.emit("rendered",this.state),this.emit("statechange",this.state);return}const h=c==="3mf"?await jr(d,{signal:s}):{geometry:c==="ply"?Hr(d):Tr(d),warnings:[]},f=h.geometry;this.createScene(f,s),this.state={...this.state,loading:false,error:null,warnings:h.warnings,metadata:jt(h.geometry,c),camera:this.currentCameraState()},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(c){if(s.aborted){(l=t.signal)!=null&&l.aborted&&F(s);return}this.stopLoad();const d=c instanceof Error?c:new Error(String(c));throw this.state.loading=false,this.state.error=d.message,this.emit("error",d),this.emit("statechange",this.state),d}}destroy(){this.stopLoad(),this.state.loading=false,this.stage.replaceChildren(),this.root.replaceChildren(),this.root.parentElement===this.host&&this.host.replaceChildren();for(const e of Object.values(this.listeners))e.clear()}stopLoad(){const e=this.loadController;this.loadController=null,e==null||e.abort(),this.disposeScene()}getState(){return{...this.state,warnings:[...this.state.warnings],modelTree:this.state.modelTree?fn(this.state.modelTree):void 0,layers:[...this.state.layers??[]],activeLayerIds:[...this.state.activeLayerIds??[]],metadata:this.state.metadata?{...this.state.metadata,materialNames:[...this.state.metadata.materialNames??[]],materialDetails:yn(this.state.metadata.materialDetails),bounds:this.state.metadata.bounds?{...this.state.metadata.bounds,min:[...this.state.metadata.bounds.min],max:[...this.state.metadata.bounds.max],size:[...this.state.metadata.bounds.size]}:void 0}:void 0,isolatedMaterialKey:this.state.isolatedMaterialKey,displayMode:this.state.displayMode,snapshotBackground:this.state.snapshotBackground,measurement:_t(this.state.measurement),section:ii(this.state.section),camera:this.state.camera?{...this.state.camera}:void 0}}on(e,t){return this.listeners[e].add(t),()=>{this.listeners[e].delete(t)}}setScale(e){if(!Number.isFinite(e))return;const t=Math.max(.2,Math.min(e,4));this.state.scale!==t&&(this.state.scale=t,this.distance=Math.max(this.modelRadius*1.25,this.modelRadius*2.6/this.state.scale),this.updateCamera(),this.emit("statechange",this.state))}fit(){this.setScale(1)}pan(e,t){!Number.isFinite(e)||!Number.isFinite(t)||(this.yaw+=e*.35,this.pitch=_(this.pitch+t*.25,-80,80),this.viewPreset="free",this.updateCamera(),this.emit("statechange",this.state))}selectNode(e){this.state.selectedNodeId!==e&&(this.state.selectedNodeId=e,this.applyAppearanceState(),this.focusNode(e),this.emit("statechange",this.state))}setNodeVisibility(e,t){this.toggleNodeVisibility(e,t)}toggleNodeVisibility(e,t){var i;if(!this.modelGroup||!((i=this.state.modelTree)!=null&&i.length))return;const r=this.findNodeObject(e);if(!r)return;const s=typeof t=="boolean"?t:!(r.userData.previewOriginalVisible??r.visible);if(!!(r.userData.previewOriginalVisible??r.visible)!==s){if(this.applyNodeVisibility(r,s),this.state.modelTree=pn(this.state.modelTree,e,s),this.state.selectedNodeId){const a=wn(this.state.modelTree,this.state.selectedNodeId);a!=null&&a.visible?this.applyAppearanceState():(this.state.selectedNodeId=void 0,this.applyAppearanceState(),this.focusNode(void 0))}else this.applyAppearanceState();this.clearSectionHelperCache(),this.emit("statechange",this.state)}}setExplode(e){if(!Number.isFinite(e))return;if(!this.explodeTargets.length){this.state.explode=0;return}const t=_(e,0,1);(this.state.explode??0)!==t&&(this.state.explode=t,this.applyExplode(this.state.explode),this.focusNode(this.state.selectedNodeId),this.emit("statechange",this.state))}setActiveMaterial(e){const t=e||void 0;this.state.isolatedMaterialKey!==t&&(this.state.isolatedMaterialKey=t,this.applyAppearanceState(),this.clearSectionHelperCache(),this.focusNode(this.state.selectedNodeId),this.emit("statechange",this.state))}setMeasurementActive(e){const t=_t(this.state.measurement)??{active:false,status:"idle",snapMode:"surface",axisLock:"free"},r={...t,active:e,status:e?t.start?t.end?"complete":"pick-end":"pick-start":t.start&&t.end?"complete":t.start?"pick-end":"idle"};e||(r.previewPoint=void 0,r.previewDelta=void 0,r.previewDistance=void 0),!Vt(this.state.measurement,r)&&(this.state.measurement=r,this.updateMeasurementHelpers(),this.emit("statechange",this.state))}clearMeasurement(){var t,r;const e={active:false,status:"idle",snapMode:((t=this.state.measurement)==null?void 0:t.snapMode)??"surface",axisLock:((r=this.state.measurement)==null?void 0:r.axisLock)??"free",previewPoint:void 0,previewDelta:void 0,previewDistance:void 0};Vt(this.state.measurement,e)||(this.state.measurement=e,this.updateMeasurementHelpers(),this.emit("statechange",this.state))}ensureSectionState(){const e=this.state.section;return e?Je(e,this.sectionBounds):ue(this.sectionBounds)}setMeasurementSnapMode(e){const t=this.state.measurement??{active:false,status:"idle",snapMode:"surface",axisLock:"free"};(t.snapMode??"surface")!==e&&(t.snapMode=e,this.state.measurement=t,this.refreshMeasurementHover(),this.updateMeasurementHelpers(),this.emit("statechange",this.state))}setMeasurementAxisLock(e){const t=this.state.measurement??{active:false,status:"idle",snapMode:"surface",axisLock:"free"};(t.axisLock??"free")!==e&&(t.axisLock=e,this.state.measurement=t,this.refreshMeasurementHover(),this.updateMeasurementHelpers(),this.emit("statechange",this.state))}setSectionActive(e){const t=this.ensureSectionState();t.active!==e&&(t.active=e,this.state.section=t,this.updateSectionPlanes(),this.emit("statechange",this.state))}setSectionMode(e){const t=this.ensureSectionState();(t.mode??"single")!==e&&(t.mode=e,this.state.section=Je(t,this.sectionBounds),this.updateSectionPlanes(),this.emit("statechange",this.state))}setSectionAxis(e){const t=this.ensureSectionState();if(t.axis===e)return;const[r,s]=this.sectionBounds[e];t.axis=e,t.min=R(r),t.max=R(s),t.offset=_(t.offset,t.min,t.max),this.state.section=t,this.updateSectionPlanes(),this.emit("statechange",this.state)}setSectionOffset(e){if(!Number.isFinite(e))return;const t=this.ensureSectionState(),r=R(_(e,t.min,t.max));t.offset!==r&&(t.offset=r,this.state.section=t,this.updateSectionPlanes(),this.emit("statechange",this.state))}setSectionRange(e,t,r){var c;if(!Number.isFinite(t)||!Number.isFinite(r))return;const s=this.ensureSectionState(),i=this.sectionBounds[e],a=_(Math.min(t,r),i[0],i[1]),o=_(Math.max(t,r),i[0],i[1]),u=[R(a),R(o)],l=(c=s.range)==null?void 0:c[e];l&&l[0]===u[0]&&l[1]===u[1]||(s.range={...s.range??xe(this.sectionBounds),[e]:u},this.state.section=Je(s,this.sectionBounds),this.updateSectionPlanes(),this.emit("statechange",this.state))}clearSection(){const e=ue(this.sectionBounds);ai(this.state.section,e)||(this.state.section=e,this.updateSectionPlanes(),this.emit("statechange",this.state))}setCameraProjection(e){this.projectionMode!==e&&(this.projectionMode=e,this.replaceCamera(),this.updateCamera(),this.emit("statechange",this.state))}setCameraViewPreset(e){if(this.viewPreset===e)return;this.viewPreset=e;const t=Js(e);t&&(this.yaw=t.yaw,this.pitch=t.pitch),this.updateCamera(),this.emit("statechange",this.state)}setDisplayMode(e){this.displayMode!==e&&(this.displayMode=e,this.state.displayMode=e,this.applyAppearanceState(),this.emit("statechange",this.state))}setSnapshotBackground(e){this.snapshotBackground!==e&&(this.snapshotBackground=e,this.state.snapshotBackground=e,this.emit("statechange",this.state))}downloadSnapshot(e,t){if(typeof document>"u")return;const r=this.renderer,s=r==null?void 0:r.domElement,i=this.scene,a=this.camera;if(!s||!r||!i||!a)return;const o=this.applySceneBackground(t??this.snapshotBackground);r.render(i,a);const u=s.toDataURL("image/png");o(),r.render(i,a);const l=document.createElement("a");l.href=u,l.download=Qs(e??this.state.title),l.rel="noopener",l.click()}async fullscreen(){var e,t;await((t=(e=this.root).requestFullscreen)==null?void 0:t.call(e))}createScene(e,t){F(t);const r=Qt({antialias:true,alpha:false,preserveDrawingBuffer:true});this.renderer=r,r.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),r.setClearColor(1120295,1),r.localClippingEnabled=true,r.clippingPlanes=[],r.domElement.className="model3dv-canvas",this.stage.replaceChildren(r.domElement);const s=new yt;s.background=new de(1120295);const i=this.createCamera(),a=new ee;this.modelGroup=a,this.scene=s,this.camera=i;const o=new Y;this.geometry=o,o.setAttribute("position",new ie(e.positions,3)),o.setAttribute("normal",new ie(e.normals,3)),e.colors&&o.setAttribute("color",new ie(e.colors,3)),o.computeBoundingSphere();const u=zi(e.bounds),l=Hi(e.bounds);this.modelRadius=Math.max(l.x,l.y,l.z,1)*.72,this.baseModelRadius=this.modelRadius,this.distance=this.modelRadius*2.6,this.baseDistance=this.distance,a.position.set(-u.x,-u.y,-u.z),this.baseModelGroupPosition.copy(a.position);const c=new V({color:e.colors?16777215:8246268,roughness:.55,metalness:.08,vertexColors:!!e.colors});this.material=c;const d=new $(o,c);a.add(d);const h=new vt(o,35),f=new ne({color:14412542,transparent:true,opacity:.22});this.edgeGeometry=h,this.edgeMaterial=f;const m=new Q(h,f),g=m;g.userData.previewEdgeHelper=true,g.userData.previewEdgeSourceId=d.id,g.userData.previewOriginalVisible=true,a.add(m),s.add(new xt(16777215,.48));const w=new Oe(16777215,1.4);w.position.set(1,1.6,1.3),s.add(w);const p=new Oe(9684477,.8);p.position.set(-1.5,.8,-1),s.add(p),s.add(a),this.renderer=r,this.scene=s,this.camera=i,this.modelGroup=a,this.geometry=o,this.edgeGeometry=h,this.material=c,this.edgeMaterial=f,this.clearSectionHelperCache(),this.sectionSourceGeometry={positions:ki(e.positions,tt)},this.explodeTargets=[],this.maxExplodeOffset=0,this.sectionBounds=ji(e.bounds,u),this.state.modelTree=void 0,this.state.selectedNodeId=void 0,this.state.isolatedMaterialKey=void 0,this.state.explode=0,this.state.displayMode=this.displayMode,this.state.snapshotBackground=this.snapshotBackground,this.state.measurement={active:false,status:"idle",snapMode:"surface",axisLock:"free"},this.state.section=ue(this.sectionBounds),this.state.capabilities.measure=true,this.state.capabilities.section=true,this.state.capabilities.explode=false,this.state.capabilities.materialFilter=false,this.state.capabilities.displayMode=true,this.captureMaterialRuntimeState(a),this.applyAppearanceState(),this.setupMeasurementHelpers(a),this.bindInteractions(r.domElement),this.observeResize(),this.resize(),this.updateSectionPlanes(),this.updateCamera(),this.startAnimation()}createObjectScene(e,t){t.aborted&&(he(e),F(t));const r=Qt({antialias:true,alpha:false,preserveDrawingBuffer:true});this.renderer=r,r.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),r.setClearColor(1120295,1),r.localClippingEnabled=true,r.clippingPlanes=[],r.domElement.className="model3dv-canvas",this.stage.replaceChildren(r.domElement);const s=new yt;s.background=new de(1120295);const i=this.createCamera(),a=new ee;this.modelGroup=a,this.scene=s,this.camera=i,a.add(e),s.add(new xt(16777215,.62));const o=new Oe(16777215,1.45);o.position.set(1,1.6,1.3),s.add(o);const u=new Oe(9684477,.7);u.position.set(-1.5,.8,-1),s.add(u),s.add(a);const l=new te().setFromObject(e),c=l.getCenter(new E),d=l.getSize(new E);this.modelRadius=Math.max(d.x,d.y,d.z,1)*.72,this.baseModelRadius=this.modelRadius,this.distance=this.modelRadius*2.6,this.baseDistance=this.distance,e.position.sub(c),this.sectionBounds=Gi(e),this.baseModelGroupPosition.copy(a.position),this.explodeTargets=ei(e,this.baseModelRadius),this.maxExplodeOffset=this.explodeTargets.reduce((h,f)=>Math.max(h,f.distance),0),this.state.modelTree=Ks(e),this.state.selectedNodeId=void 0,this.state.isolatedMaterialKey=void 0,this.state.explode=0,this.state.displayMode=this.displayMode,this.state.snapshotBackground=this.snapshotBackground,this.state.measurement={active:false,status:"idle",snapMode:"surface",axisLock:"free"},this.state.section=ue(this.sectionBounds),this.state.capabilities.measure=true,this.state.capabilities.section=true,this.state.capabilities.explode=this.explodeTargets.length>1,this.state.capabilities.materialFilter=Ys(e),this.state.capabilities.displayMode=true,this.attachEdgeHelpers(e),this.captureMaterialRuntimeState(e),this.applyExplode(0),this.applyAppearanceState(),this.setupMeasurementHelpers(a),this.renderer=r,this.scene=s,this.camera=i,this.modelGroup=a,this.clearSectionHelperCache(),this.sectionSourceGeometry={positions:new Float32Array,objects:Di(e,tt)},this.bindInteractions(r.domElement),this.observeResize(),this.resize(),this.updateSectionPlanes(),this.updateCamera(),this.startAnimation()}bindInteractions(e){var u;(u=this.interactionController)==null||u.abort(),this.interactionController=new AbortController;const t=this.interactionController.signal,r=new Map;let s=null;const i=()=>{const[l,c]=r.values();return l&&c?Math.hypot(c.x-l.x,c.y-l.y):0},a=l=>{e.hasPointerCapture(l)&&e.releasePointerCapture(l)};e.style.touchAction="none",t.addEventListener("abort",()=>{for(const l of r.keys())a(l);r.clear(),s=null},{once:true}),e.addEventListener("pointerdown",l=>{const c={x:l.clientX,y:l.clientY};r.set(l.pointerId,c),s=r.size===1?{...c}:null,e.setPointerCapture(l.pointerId)},{signal:t}),e.addEventListener("pointermove",l=>{var m;const c=r.get(l.pointerId);if(!c){(((m=this.state.measurement)==null?void 0:m.active)??false)&&r.size===0&&(this.measurementHoverClientX=l.clientX,this.measurementHoverClientY=l.clientY,this.updateMeasurementHover(l.clientX,l.clientY));return}s&&Math.hypot(l.clientX-s.x,l.clientY-s.y)>4&&(s=null);const d=i(),h=l.clientX-c.x,f=l.clientY-c.y;if(c.x=l.clientX,c.y=l.clientY,r.size===1)(h!==0||f!==0)&&this.pan(h,f);else{const g=i();d>0&&g>0&&this.setScale(this.state.scale*g/d)}},{signal:t}),e.addEventListener("pointerup",l=>{var d;if(!r.delete(l.pointerId))return;const c=s&&Math.hypot(l.clientX-s.x,l.clientY-s.y)<=4;s=null,a(l.pointerId),(((d=this.state.measurement)==null?void 0:d.active)??false)&&c&&this.pickMeasurementPoint(l.clientX,l.clientY)},{signal:t});const o=l=>{r.delete(l.pointerId)&&(s=null,a(l.pointerId))};e.addEventListener("pointercancel",o,{signal:t}),e.addEventListener("lostpointercapture",o,{signal:t}),e.addEventListener("pointerleave",()=>{this.measurementHoverClientX=null,this.measurementHoverClientY=null,this.clearMeasurementHover()},{signal:t}),e.addEventListener("wheel",l=>{l.preventDefault(),this.setScale(this.state.scale+(l.deltaY>0?-.08:.08))},{passive:false,signal:t})}observeResize(){var e;if((e=this.resizeObserver)==null||e.disconnect(),typeof ResizeObserver<"u"){this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.stage);return}window.addEventListener("resize",this.resize)}startAnimation(){const e=()=>{this.animationFrame=requestAnimationFrame(e),this.renderFrame()};e()}renderFrame(){!this.renderer||!this.scene||!this.camera||!this.modelGroup||(this.updateSectionPlanes(),this.renderer.render(this.scene,this.camera))}createCamera(){return this.projectionMode==="orthographic"?new Kn(-100,100,100,-100,.1,1e5):new Mt(45,1,.1,1e5)}replaceCamera(){var t;const e=((t=this.camera)==null?void 0:t.position.clone())??new E(0,0,this.distance);this.camera=this.createCamera(),this.camera.position.copy(e),this.resize()}updateCamera(){if(!this.camera)return;const e=Jt(this.yaw),t=Jt(this.pitch);this.camera.position.set(this.distance*Math.cos(t)*Math.sin(e),this.distance*Math.sin(t),this.distance*Math.cos(t)*Math.cos(e)),this.camera.lookAt(0,0,0),this.resize(),this.state.camera=this.currentCameraState()}currentCameraState(){var t;const e=((t=this.camera)==null?void 0:t.position)??new E(0,0,this.distance);return{position:[e.x,e.y,e.z],target:[0,0,0],projection:this.projectionMode,viewPreset:this.viewPreset}}applyExplode(e){this.explodeTargets.length&&this.clearSectionHelperCache();for(const t of this.explodeTargets)t.object.position.copy(t.basePosition).addScaledVector(t.direction,t.distance*e)}setupMeasurementHelpers(e){const t=new Y;t.setAttribute("position",new Z([0,0,0,0,0,0],3));const r=new ne({color:16096779,transparent:true,opacity:.95}),s=new _e(t,r);s.visible=false,s.userData.previewMeasurementHelper=true;const i=new Y;i.setAttribute("position",new Z([0,0,0,0,0,0],3));const a=new Pe({color:16498468,size:Math.max(this.baseModelRadius*.045,.8),sizeAttenuation:true}),o=new me(i,a);o.visible=false,o.userData.previewMeasurementHelper=true,e.add(s),e.add(o),this.measurementLineGeometry=t,this.measurementLineMaterial=r,this.measurementLine=s,this.measurementPointsGeometry=i,this.measurementPointsMaterial=a,this.measurementPoints=o,this.updateMeasurementHelpers()}pickMeasurementPoint(e,t){this.measurementHoverClientX=e,this.measurementHoverClientY=t;const r=this.resolveMeasurementPoint(e,t);r&&this.applyMeasurementPoint(r)}updateMeasurementHover(e,t){const r=this.state.measurement;if(!(r!=null&&r.active))return;const s=this.resolveMeasurementPoint(e,t);if(!s){this.clearMeasurementHover();return}this.applyMeasurementPreviewPoint(s)}applyMeasurementPreviewPoint(e){const t=this.state.measurement;if(t!=null&&t.active){if(t.start){const r=new E(...t.start),s=Gt(e,r,t.axisLock??"free"),i=s.clone().sub(r),a=ye(s),o=ye(i),u=R(i.length());if(oe(t.previewPoint,a)&&oe(t.previewDelta,o)&&t.previewDistance===u&&t.status==="pick-end")return;t.previewPoint=a,t.previewDelta=o,t.previewDistance=u,t.status="pick-end"}else{const r=ye(e);if(oe(t.previewPoint,r)&&t.previewDelta==null&&t.previewDistance==null&&t.status==="pick-start")return;t.previewPoint=r,t.previewDelta=void 0,t.previewDistance=void 0,t.status="pick-start"}this.updateMeasurementHelpers(),this.emit("statechange",this.state)}}refreshMeasurementHover(){this.measurementHoverClientX==null||this.measurementHoverClientY==null||this.updateMeasurementHover(this.measurementHoverClientX,this.measurementHoverClientY)}clearMeasurementHover(){const e=this.state.measurement;if(!e)return;const t=e.active?e.start?"pick-end":"pick-start":e.status;e.previewPoint==null&&e.previewDelta==null&&e.previewDistance==null&&e.status===t||(e.previewPoint=void 0,e.previewDelta=void 0,e.previewDistance=void 0,e.active&&(e.status=t),this.updateMeasurementHelpers(),this.emit("statechange",this.state))}resolveMeasurementPoint(e,t){var c;if(!this.renderer||!this.camera||!this.modelGroup)return;const r=this.renderer.domElement.getBoundingClientRect(),s=r.width||1,i=r.height||1;this.pointerNdc.set((e-r.left)/s*2-1,-((t-r.top)/i*2-1)),this.raycaster.setFromCamera(this.pointerNdc,this.camera);const o=this.raycaster.intersectObject(this.modelGroup,true).find(d=>{const h=d.object;return!h.userData.previewMeasurementHelper&&h.visible});if(!o)return;const l=(((c=this.state.measurement)==null?void 0:c.snapMode)??"surface")==="vertex"?Zs(o)??o.point:o.point;return this.modelGroup.worldToLocal(l.clone())}applyMeasurementPoint(e){const t=this.state.measurement??{active:false,status:"idle",snapMode:"surface",axisLock:"free"},r=t.start?new E(...t.start):void 0;if(!r||t.end)t.start=ye(e),t.end=void 0,t.delta=void 0,t.distance=void 0,t.previewPoint=void 0,t.previewDelta=void 0,t.previewDistance=void 0,t.status="pick-end";else{const s=Gt(e,r,t.axisLock??"free"),i=s.clone().sub(r);t.end=ye(s),t.delta=ye(i),t.distance=R(i.length()),t.previewPoint=void 0,t.previewDelta=void 0,t.previewDistance=void 0,t.status="complete",t.active=false}this.state.measurement=t,this.updateMeasurementHelpers(),this.emit("statechange",this.state)}updateMeasurementHelpers(){var r,s,i,a;const e=(r=this.state.measurement)!=null&&r.start?new E(...this.state.measurement.start):void 0,t=(s=this.state.measurement)!=null&&s.end?new E(...this.state.measurement.end):(i=this.state.measurement)!=null&&i.previewPoint?new E(...this.state.measurement.previewPoint):void 0;if(this.measurementLineGeometry&&this.measurementLine){const o=this.measurementLineGeometry.getAttribute("position");e&&t?(o.setXYZ(0,e.x,e.y,e.z),o.setXYZ(1,t.x,t.y,t.z),o.needsUpdate=true,this.measurementLineGeometry.computeBoundingSphere(),this.measurementLine.visible=true):this.measurementLine.visible=false}if(this.measurementPointsGeometry&&this.measurementPoints){const o=this.measurementPointsGeometry.getAttribute("position"),u=e??((a=this.state.measurement)!=null&&a.previewPoint?new E(...this.state.measurement.previewPoint):void 0);if(u){o.setXYZ(0,u.x,u.y,u.z);const l=t??u;o.setXYZ(1,l.x,l.y,l.z),o.needsUpdate=true,this.measurementPointsGeometry.computeBoundingSphere(),this.measurementPoints.visible=true}else this.measurementPoints.visible=false}}updateSectionPlanes(){var s,i;if(!this.renderer||!this.modelGroup)return;const e=this.state.section;if(!(e!=null&&e.active)){this.appliedSectionClippingKey!=="inactive"&&(this.renderer.clippingPlanes=[],this.appliedSectionClippingKey="inactive"),this.appliedSectionHelperKey!=="inactive"&&(this.updateSectionHelpers(void 0),this.appliedSectionHelperKey="inactive");return}this.modelGroup.updateMatrixWorld(true);const t=ui(e,this.modelGroup);if(t!==this.appliedSectionClippingKey){const a=e.mode==="box"?this.resolveBoxSectionPlanes(e):this.resolveSingleSectionPlanes(e);this.renderer.clippingPlanes=a,this.appliedSectionClippingKey=t}const r=ci(e);if(e.mode==="box"){r!==this.appliedSectionHelperKey&&this.appliedSectionHelperKey!==null&&this.appliedSectionHelperKey!=="inactive"&&this.appliedSectionHelperKey.startsWith("box:")&&((s=this.sectionBoxFill)==null?void 0:s.visible)&&((i=this.sectionBoxHelper)==null?void 0:i.visible)&&Re()-this.lastSectionHelperUpdateAt<Rt?this.markBoxSectionHelperPending():r!==this.appliedSectionHelperKey&&(this.updateSectionHelpers(e),this.appliedSectionHelperKey=r,this.lastSectionHelperUpdateAt=Re());return}this.prepareSingleSectionHelper(e),r!==this.appliedSectionHelperKey&&(this.shouldRefreshSingleSectionHelper(e)?(this.updateSectionPlaneDetail(e),this.appliedSectionHelperKey=r,this.lastSectionHelperUpdateAt=Re()):this.markSingleSectionHelperPending())}markBoxSectionHelperPending(){!this.sectionPlaneHelper||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.sectionBoxFill||!this.sectionBoxHelper||(this.sectionPlaneHelper.visible=false,this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false,this.sectionBoxFill.visible=false,this.sectionBoxHelper.visible=false)}shouldRefreshSingleSectionHelper(e){return this.appliedSectionHelperKey===null||this.appliedSectionHelperKey==="inactive"||this.sectionHelperCache.has(Ue(e))?true:Re()-this.lastSectionHelperUpdateAt>=Rt}prepareSingleSectionHelper(e){this.ensureSectionHelpers(),!(!this.sectionPlaneHelper||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.sectionBoxFill||!this.sectionBoxHelper)&&(this.updateSectionPlaneMesh(e),this.sectionBoxFill.visible=false,this.sectionBoxHelper.visible=false,this.sectionPlaneHelper.visible=true,this.sectionPlaneOutline.visible=true)}markSingleSectionHelperPending(){!this.sectionPlaneOutline||!this.sectionPlaneFill||(this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false)}resolveSingleSectionPlanes(e){const t=Ut(e.axis),r=this.sectionPlanes[0];return r.set(t,-e.offset),r.applyMatrix4(this.modelGroup.matrixWorld),[r]}resolveBoxSectionPlanes(e){const t=e.range??xe(this.sectionBounds),r=[],s=[{axis:"x",positive:this.sectionPlanes[0],negative:this.sectionPlanes[1]},{axis:"y",positive:this.sectionPlanes[2],negative:this.sectionPlanes[3]},{axis:"z",positive:this.sectionPlanes[4],negative:this.sectionPlanes[5]}];for(const{axis:i,positive:a,negative:o}of s){const u=this.sectionBounds[i],[l,c]=t[i];l>u[0]+5e-4&&(a.set(Ut(i),-l),a.applyMatrix4(this.modelGroup.matrixWorld),r.push(a)),c<u[1]-5e-4&&(o.set(qs(i),c),o.applyMatrix4(this.modelGroup.matrixWorld),r.push(o))}return r}ensureSectionHelpers(){if(!this.modelGroup||this.sectionHelperGroup)return;const e=new ee;e.userData.previewMeasurementHelper=true;const t=new Yn(1,1),r=new Ve({color:3718648,transparent:true,opacity:.14,side:Te,depthWrite:false}),s=new $(t,r);s.visible=false,s.renderOrder=3,s.userData.previewMeasurementHelper=true,e.add(s);const i=new Y;i.setAttribute("position",new Z(new Array(24).fill(0),3));const a=new ne({color:8246268,transparent:true,opacity:.95,depthWrite:false}),o=new Q(i,a);o.visible=false,o.renderOrder=4,o.userData.previewMeasurementHelper=true,e.add(o);const u=new Y,l=new Ve({color:3718648,transparent:true,opacity:.22,side:Te,depthWrite:false}),c=new $(u,l);c.visible=false,c.renderOrder=3.5,c.userData.previewMeasurementHelper=true,e.add(c);const d=new Y,h=new Ve({color:3718648,transparent:true,opacity:.1,side:Te,depthWrite:false}),f=new $(d,h);f.visible=false,f.renderOrder=2.8,f.userData.previewMeasurementHelper=true,e.add(f);const m=new Y;m.setAttribute("position",new Z(new Array(72).fill(0),3));const g=new ne({color:3718648,transparent:true,opacity:.7,depthWrite:false}),w=new Q(m,g);w.visible=false,w.renderOrder=3,w.userData.previewMeasurementHelper=true,e.add(w),this.modelGroup.add(e),this.sectionHelperGroup=e,this.sectionPlaneHelperGeometry=t,this.sectionPlaneHelperMaterial=r,this.sectionPlaneHelper=s,this.sectionPlaneOutlineGeometry=i,this.sectionPlaneOutlineMaterial=a,this.sectionPlaneOutline=o,this.sectionPlaneFillGeometry=u,this.sectionPlaneFillMaterial=l,this.sectionPlaneFill=c,this.sectionBoxFillGeometry=d,this.sectionBoxFillMaterial=h,this.sectionBoxFill=f,this.sectionBoxHelperGeometry=m,this.sectionBoxHelperMaterial=g,this.sectionBoxHelper=w}updateSectionHelpers(e){if(this.ensureSectionHelpers(),!(!this.sectionPlaneHelper||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.sectionBoxFill||!this.sectionBoxHelper||!this.modelGroup)){if(!(e!=null&&e.active)){this.sectionPlaneHelper.visible=false,this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false,this.sectionBoxFill.visible=false,this.sectionBoxHelper.visible=false;return}if(e.mode==="box"){this.sectionPlaneHelper.visible=false,this.sectionPlaneOutline.visible=false,this.sectionPlaneFill.visible=false,this.updateSectionBoxHelper(e),this.updateSectionBoxFill(e),this.sectionBoxHelper.visible=true;return}}}updateSectionPlaneMesh(e){if(!this.sectionPlaneHelper)return;const t=di(e,this.sectionBounds),r=Math.max(t.width,.001)*1.02,s=Math.max(t.height,.001)*1.02;switch(this.sectionPlaneHelper.position.set(0,0,0),this.sectionPlaneHelper.rotation.set(0,0,0),e.axis){case"x":this.sectionPlaneHelper.position.x=e.offset,this.sectionPlaneHelper.rotation.y=Math.PI/2;break;case"y":this.sectionPlaneHelper.position.y=e.offset,this.sectionPlaneHelper.rotation.x=Math.PI/2;break;case"z":default:this.sectionPlaneHelper.position.z=e.offset;break}this.sectionPlaneHelper.scale.set(r,s,1)}updateSectionPlaneDetail(e){if(!this.sectionPlaneOutlineGeometry||!this.sectionPlaneOutline||!this.sectionPlaneFill||!this.modelGroup)return;const t=this.resolveSectionHelperCacheEntry(e),r=t!=null&&t.outlinePoints.length?t.outlinePoints:hi(e,this.sectionBounds),s=this.sectionPlaneOutlineGeometry.getAttribute("position"),i=r.length/3;if(s.count!==i)this.sectionPlaneOutlineGeometry.setAttribute("position",new Z(r,3)),this.sectionPlaneOutlineGeometry.computeBoundingSphere();else{for(let o=0;o<r.length;o+=3)s.setXYZ(o/3,r[o],r[o+1],r[o+2]);s.needsUpdate=true,this.sectionPlaneOutlineGeometry.computeBoundingSphere()}this.sectionPlaneOutline.visible=true;const a=t!=null&&t.fillData?yi(t.fillData):void 0;if(!a){this.sectionPlaneFill.visible=false;return}this.replaceSectionPlaneFillGeometry(a),this.sectionPlaneFill.visible=true}resolveSectionHelperCacheEntry(e){const t=Ue(e),r=this.sectionHelperCache.get(t);if(r)return this.sectionHelperCache.delete(t),this.sectionHelperCache.set(t,r),r;const s=Ai(e,this.sectionSourceGeometry,this.modelGroup);if(!s.length)return;const i=fi(e.axis,s),a={outlinePoints:i.loops.length||i.chains.length?[...i.loops.flatMap(o=>Be(o)),...i.chains.flatMap(o=>mi(o))]:s,fillData:i.loops.length?bi(e.axis,i.loops):void 0};for(this.sectionHelperCache.set(t,a);this.sectionHelperCache.size>Or;){const o=this.sectionHelperCache.keys().next().value;if(typeof o!="string")break;this.sectionHelperCache.delete(o)}return a}clearSectionHelperCache(){this.sectionHelperCache.clear(),this.appliedSectionHelperKey=null,this.appliedSectionClippingKey=null,this.lastSectionHelperUpdateAt=Number.NEGATIVE_INFINITY}replaceSectionPlaneFillGeometry(e){if(!this.sectionPlaneFill){e.dispose();return}const t=this.sectionPlaneFillGeometry;this.sectionPlaneFill.geometry=e,this.sectionPlaneFillGeometry=e,t==null||t.dispose()}replaceSectionBoxFillGeometry(e){if(!this.sectionBoxFill){e.dispose();return}const t=this.sectionBoxFillGeometry;this.sectionBoxFill.geometry=e,this.sectionBoxFillGeometry=e,t==null||t.dispose()}updateSectionBoxFill(e){if(!this.sectionBoxFill)return;const t=vi(e,this.sectionBounds);if(!t){this.sectionBoxFill.visible=false;return}this.replaceSectionBoxFillGeometry(t),this.sectionBoxFill.visible=true}updateSectionBoxHelper(e){if(!this.sectionBoxHelperGeometry)return;const t=e.range??xe(this.sectionBounds),[r,s]=t.x,[i,a]=t.y,[o,u]=t.z,l=[[r,i,o],[s,i,o],[s,a,o],[r,a,o],[r,i,u],[s,i,u],[s,a,u],[r,a,u]],c=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],d=[];for(const[f,m]of c)d.push(...l[f],...l[m]);const h=this.sectionBoxHelperGeometry.getAttribute("position");for(let f=0;f<d.length;f+=3)h.setXYZ(f/3,d[f],d[f+1],d[f+2]);h.needsUpdate=true,this.sectionBoxHelperGeometry.computeBoundingSphere()}findNodeObject(e){var r;let t;return(r=this.modelGroup)==null||r.traverse(s=>{const i=s;i.userData.previewNodeId===e&&(t=i)}),t}applyNodeVisibility(e,t){e.traverse(r=>{const s=r;s.userData.previewOriginalVisible=t,r.visible=t})}focusNode(e){if(!this.modelGroup)return;if(!e){if(this.state.isolatedMaterialKey){const o=Xs(this.modelGroup);if(!o.isEmpty()){const u=o.getCenter(new E),l=o.getSize(new E);this.modelRadius=Math.max(l.x,l.y,l.z,1)*.72,this.distance=Math.max(this.modelRadius*2.6,this.baseDistance*.24),this.modelGroup.position.copy(this.baseModelGroupPosition).sub(u),this.updateCamera();return}}const a=this.state.explode??0;this.modelRadius=this.baseModelRadius+this.maxExplodeOffset*a,this.distance=Math.max(this.modelRadius*1.25,this.modelRadius*2.6/this.state.scale),this.modelGroup.position.copy(this.baseModelGroupPosition),this.updateCamera();return}let t;if(this.modelGroup.traverse(a=>{a.userData.previewNodeId===e&&(t=a)}),!t)return;const r=new te().setFromObject(t);if(r.isEmpty())return;const s=r.getCenter(new E),i=r.getSize(new E);this.modelRadius=Math.max(i.x,i.y,i.z,1)*.72,this.distance=Math.max(this.modelRadius*2.6,this.baseDistance*.24),this.modelGroup.position.copy(this.baseModelGroupPosition).sub(s),this.updateCamera()}applyAppearanceState(){var e;(e=this.modelGroup)==null||e.traverse(t=>{const r=t;if(typeof r.userData.previewOriginalVisible!="boolean"&&(r.userData.previewOriginalVisible=t.visible),r.userData.previewMeasurementHelper)return;if(r.userData.previewEdgeHelper){const a=this.findObjectById(r.userData.previewEdgeSourceId),o=a?!!a.userData.previewOriginalVisible&&this.matchesActiveMaterialFilter(a):true;t.visible=r.userData.previewOriginalVisible&&o&&this.displayMode!=="shaded",this.applySelectionMaterialState(t,{emphasized:false,dimmed:!!(this.state.selectedNodeId&&a&&a.userData.previewNodeId!==this.state.selectedNodeId)});return}const s=!!(this.state.selectedNodeId&&r.userData.previewNodeId===this.state.selectedNodeId),i=!!(this.state.selectedNodeId&&r.userData.previewNodeId&&r.userData.previewNodeId!==this.state.selectedNodeId);t.visible=r.userData.previewOriginalVisible&&this.matchesActiveMaterialFilter(t),this.applySelectionMaterialState(t,{emphasized:s&&t.visible,dimmed:i&&t.visible})})}matchesActiveMaterialFilter(e){const t=this.state.isolatedMaterialKey;if(!t)return true;const r=ht(e);return r.length?r.includes(t):true}captureMaterialRuntimeState(e){e.traverse(t=>{const r=t,s=Array.isArray(r.material)?r.material:r.material?[r.material]:[];for(const i of s)this.materialRuntimeState.has(i)||this.materialRuntimeState.set(i,{opacity:i.opacity,transparent:i.transparent,wireframe:"wireframe"in i?!!i.wireframe:void 0,depthWrite:i.depthWrite,...i instanceof V?{emissiveHex:i.emissive.getHex(),emissiveIntensity:i.emissiveIntensity}:{}})})}applySelectionMaterialState(e,t){const r=e,s=Array.isArray(r.material)?r.material:r.material?[r.material]:[];for(const i of s){const a=this.materialRuntimeState.get(i)??{opacity:i.opacity,transparent:i.transparent,wireframe:"wireframe"in i?!!i.wireframe:void 0,depthWrite:i.depthWrite},o=this.displayMode==="xray"?Math.min(a.opacity,.26):a.opacity,u=a.transparent||o<1,l=this.displayMode==="xray"?false:a.depthWrite??true;if(i instanceof V){i.wireframe=this.displayMode==="wireframe",i.emissive.setHex(t.emphasized?1920728:a.emissiveHex??0),i.emissiveIntensity=t.emphasized?Math.max(a.emissiveIntensity??0,.42):a.emissiveIntensity??0,i.opacity=t.dimmed?Math.min(o,.28):o,i.transparent=u||i.opacity<1,i.depthWrite=l,i.needsUpdate=true;continue}(i instanceof ne||i instanceof Pe)&&(i.opacity=t.dimmed?Math.min(o,.24):o,i.transparent=u||i.opacity<1,i.depthWrite=l,i.needsUpdate=true)}}attachEdgeHelpers(e){e.traverse(t=>{if(!(t instanceof $||t instanceof Ee))return;const r=t.geometry;if(!r||!r.getAttribute("position"))return;const s=new vt(r,35),i=new ne({color:14412542,transparent:true,opacity:.22,depthWrite:false}),a=new Q(s,i);a.renderOrder=2,a.userData.previewEdgeHelper=true,a.userData.previewEdgeSourceId=t.id,a.userData.previewOriginalVisible=t.visible,t.add(a)})}findObjectById(e){if(!this.modelGroup||typeof e!="number")return;let t;return this.modelGroup.traverse(r=>{!t&&r.id===e&&(t=r)}),t}applySceneBackground(e){const t=this.renderer,r=this.scene;if(!t||!r)return()=>{};const s=r.background;switch(e){case"white":r.background=new de(16777215),t.setClearColor(16777215,1);break;case"transparent":r.background=null,t.setClearColor(0,0);break;default:r.background=new de(1120295),t.setClearColor(1120295,1);break}return()=>{r.background=s,t.setClearColor(1120295,1)}}disposeScene(){var e,t,r,s,i;this.animationFrame&&(cancelAnimationFrame(this.animationFrame),this.animationFrame=0),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,window.removeEventListener("resize",this.resize),(t=this.interactionController)==null||t.abort(),this.interactionController=null,he(this.modelGroup,[this.geometry,this.edgeGeometry,this.measurementLineGeometry,this.measurementPointsGeometry,this.sectionPlaneHelperGeometry,this.sectionPlaneOutlineGeometry,this.sectionPlaneFillGeometry,this.sectionBoxFillGeometry,this.sectionBoxHelperGeometry],[this.material,this.edgeMaterial,this.measurementLineMaterial,this.measurementPointsMaterial,this.sectionPlaneHelperMaterial,this.sectionPlaneOutlineMaterial,this.sectionPlaneFillMaterial,this.sectionBoxFillMaterial,this.sectionBoxHelperMaterial]),this.renderer&&(this.renderer.clippingPlanes=[],this.renderer.localClippingEnabled=false),(r=this.renderer)==null||r.dispose(),this.stage.replaceChildren(),this.renderer=null,this.scene=null,this.camera=null,this.modelGroup=null,this.geometry=null,this.edgeGeometry=null,this.material=null,this.edgeMaterial=null,this.measurementLineGeometry=null,this.measurementLineMaterial=null,this.measurementLine=null,this.measurementPointsGeometry=null,this.measurementPointsMaterial=null,this.measurementPoints=null,this.sectionHelperGroup=null,this.sectionPlaneHelper=null,this.sectionPlaneHelperGeometry=null,this.sectionPlaneHelperMaterial=null,this.sectionPlaneOutlineGeometry=null,this.sectionPlaneOutlineMaterial=null,this.sectionPlaneOutline=null,this.sectionPlaneFillGeometry=null,this.sectionPlaneFillMaterial=null,this.sectionPlaneFill=null,this.sectionBoxFillGeometry=null,this.sectionBoxFillMaterial=null,this.sectionBoxFill=null,this.sectionBoxHelperGeometry=null,this.sectionBoxHelperMaterial=null,this.sectionBoxHelper=null,this.measurementHoverClientX=null,this.measurementHoverClientY=null,this.clearSectionHelperCache(),this.sectionBounds=Ge(),this.explodeTargets=[],this.maxExplodeOffset=0,this.materialRuntimeState=new WeakMap,this.state.modelTree=void 0,this.state.selectedNodeId=void 0,this.state.isolatedMaterialKey=void 0,this.state.measurement={active:false,status:"idle",snapMode:((s=this.state.measurement)==null?void 0:s.snapMode)??"surface",axisLock:((i=this.state.measurement)==null?void 0:i.axisLock)??"free"},this.state.section=ue(),this.state.capabilities.measure=false,this.state.capabilities.section=false,this.state.capabilities.explode=false,this.state.capabilities.materialFilter=false}emit(e,t){for(const r of this.listeners[e])r(t)}}function F(n){if(n!=null&&n.aborted)throw new DOMException("3D preview aborted.","AbortError")}function j(n,e,t){return e?new Promise((r,s)=>{let i=false;const a=()=>{i||(i=true,e.removeEventListener("abort",a),s(new DOMException("3D preview aborted.","AbortError")))};e.addEventListener("abort",a,{once:true}),e.aborted&&a(),n.then(o=>{if(i){t==null||t(o);return}i=true,e.removeEventListener("abort",a),r(o)},o=>{i||(i=true,e.removeEventListener("abort",a),s(o))}).catch(()=>{})}):n}function he(n,e=[],t=[]){const r=new Set(e.filter(l=>!!l)),s=new Set(t.filter(l=>!!l)),i=new Set,a=new Set,o=new Set;for(const l of Array.isArray(n)?n:n?[n]:[])l.traverse(c=>{const d=c;d.geometry&&r.add(d.geometry);for(const h of Array.isArray(d.material)?d.material:d.material?[d.material]:[])s.add(h);if(d.skeleton&&a.add(d.skeleton),Array.isArray(c.userData.previewObjectUrls)){for(const h of c.userData.previewObjectUrls)typeof h=="string"&&h.startsWith("blob:")&&o.add(h);delete c.userData.previewObjectUrls}});const u=l=>{l&&typeof l=="object"&&l.isTexture?i.add(l):Array.isArray(l)&&l.forEach(u)};for(const l of s){Object.values(l).forEach(u);const c=l.uniforms;if(c)for(const d of Object.values(c))u(d.value)}for(const l of a)l.boneTexture&&i.delete(l.boneTexture),l.dispose();for(const l of r)l.dispose();for(const l of s)l.dispose();for(const l of i)l.dispose();for(const l of o)URL.revokeObjectURL(l)}function ta(){return{id:"model3d",family:"model3d",supports:n=>ot.has(Sn(n)),createSession:(n,e)=>new Rr(n,e)}}function na(n=_n()){return[...kr,...n.filter(e=>!e.extensions.some(t=>ot.has(t)))]}function Tr(n){const e=new Uint8Array(n);return Bi(e)?Ts(e):Rs(new TextDecoder().decode(e))}function Ir(n){const e=[],t=[],r=[],s=[],i=[],a=[];for(const o of n.split(/\r?\n/)){const u=o.trim();if(!u||u.startsWith("#"))continue;const l=u.split(/\s+/);if(l[0]==="v"){e.push([G(l[1]),G(l[2]),G(l[3])]),t.push(js(l));continue}if(l[0]==="vn"){r.push(ln([G(l[1]),G(l[2]),G(l[3])]));continue}if(l[0]!=="f"||l.length<4)continue;const c=l.slice(1).map(d=>zs(d,e.length,r.length)).filter(Boolean);if(!(c.length<3))for(let d=1;d<c.length-1;d+=1)Hs(c[0],c[d],c[d+1],e,t,r,s,i,a)}if(!s.length)throw new Error("No OBJ triangles found.");return Fe(s,i,a.length===s.length?a:void 0)}async function Br(n,e={}){F(e.signal);const t=rn(n);if(!t.length||!e.resourceResolver)return{object:new St().parse(n),warnings:[]};const r=[],s=[],i=[];let a=null,o;try{for(const l of t){const c=Ae(await ct(e.resourceResolver,{source:K(X(e.resourceBasePath??""),l),fallbackSource:l,relation:"material",sourceFormat:e.sourceFormat??"obj"},e.signal));if(F(e.signal),s.push(...c.warnings),!c.source){s.push(`OBJ material library "${l}" could not be resolved; materials were skipped.`);continue}const d=await Pn(c.source,e.signal);F(e.signal);const h=await ys(d,l,e,i);s.push(...h.warnings),r.push(h.text)}F(e.signal);const u=new St;if(r.length){const l=new fe,c=new Promise(d=>{l.onLoad=d});l.onError=()=>{s.push("An OBJ texture failed to load; the preview may be incomplete.")},l.itemStart("filens:obj-parse");try{o=new Xn(l).parse(r.join(`
|
|
6
|
+
`),""),u.setMaterials(o),a=u.parse(n)}finally{l.itemEnd("filens:obj-parse")}await j(c,e.signal),F(e.signal),zr(a,Object.values(o.materials))}else a=u.parse(n);return{object:a,warnings:s}}catch(u){throw he(a,[],Object.values((o==null?void 0:o.materials)??{})),u}finally{for(const u of i)URL.revokeObjectURL(u)}}function zr(n,e){const t=new Set,r=new Set;n.traverse(s=>{const i=s.material;for(const a of Array.isArray(i)?i:i?[i]:[])t.add(a)});for(const s of t)for(const i of Object.values(s))i!=null&&i.isTexture&&r.add(i);for(const s of e)if(!t.has(s)){for(const i of Object.values(s))i!=null&&i.isTexture&&!r.has(i)&&(r.add(i),i.dispose());s.dispose()}}function rn(n){const e=[];for(const t of n.split(/\r?\n/)){const r=t.trim();if(!r||r.startsWith("#"))continue;const s=/^mtllib\s+(.+)$/i.exec(r);if(s!=null&&s[1])for(const i of s[1].trim().split(/\s+/))i&&e.push(i)}return[...new Set(e)]}function Hr(n){const e=new Uint8Array(n),t=Gs(e);if(t.format==="ascii")return Us(new TextDecoder().decode(e.slice(t.dataOffset)),t);if(t.format==="binary_little_endian")return _s(e,t);throw new Error(`Unsupported PLY format "${t.format}".`)}async function jr(n,e={}){F(e.signal);const t=await j(fr.loadAsync(n),e.signal);F(e.signal);const r=t.file("3D/3dmodel.model")??t.file(/(^|\/)3dmodel\.model$/i)[0];if(!r)throw new Error("3MF package is missing 3D/3dmodel.model.");const s=[r,...Object.values(t.files).filter(p=>!p.dir&&/\.model$/i.test(p.name)&&p.name!==r.name)],i=[];for(const p of s){const b=await j(p.async("text"),e.signal);F(e.signal);const y=new DOMParser().parseFromString(b,"application/xml");if(y.getElementsByTagName("parsererror")[0]){if(p===r)throw new Error("3MF model XML is invalid.");continue}i.push(y)}const a=new Map,o=new Set;for(const p of i){for(const[b,y]of Is(p))a.has(b)||a.set(b,y);for(const b of Bs(p))o.add(b)}const u=new Set,l=new Map,c=new Map;for(const p of i)for(const b of W(p,"object")){const y=b.getAttribute("id");if(!y)continue;const C=W(b,"mesh")[0],P=c.has(y);if(C){const S=W(C,"vertex").map(N=>[G(N.getAttribute("x")??void 0),G(N.getAttribute("y")??void 0),G(N.getAttribute("z")??void 0)]),L=[],k=[],D=Bt(b.getAttribute("pid"),b.getAttribute("pindex"),a);It(b.getAttribute("pid"),a,u);for(const N of W(C,"triangle")){const v=["v1","v2","v3"].map(x=>Number(N.getAttribute(x))).filter(x=>Number.isInteger(x)&&x>=0&&x<S.length);if(v.length!==3)continue;const O=N.getAttribute("pid")??b.getAttribute("pid");It(O,a,u);const A=["p1","p2","p3"].map(x=>Bt(O,N.getAttribute(x)??N.getAttribute("pindex")??b.getAttribute("pindex"),a)??D??[.49,.83,.99]);L.push(S[v[0]],S[v[1]],S[v[2]]),k.push(...A)}L.length&&!P&&c.set(y,{positions:L,colors:k})}(!l.has(y)||!P&&c.has(y))&&l.set(y,b)}for(const p of l.keys())an(p,l,c,new Set);const d=i[0],h=[],f=[],m=[],g=W(d,"item"),w=g.length?g:[...c.keys()].map(p=>({objectId:p}));for(const p of w){const b=p instanceof Element?p.getAttribute("objectid"):p.objectId,y=b?c.get(b):void 0;if(!(y!=null&&y.positions.length))continue;const C=p instanceof Element?on(p.getAttribute("transform")):rt;for(let P=0;P<y.positions.length;P+=3){const S=Ie(y.positions[P],C),L=Ie(y.positions[P+1],C),k=Ie(y.positions[P+2],C),D=dt(S,L,k),N=[y.colors[P]??[.49,.83,.99],y.colors[P+1]??[.49,.83,.99],y.colors[P+2]??[.49,.83,.99]];for(const v of[S,L,k])h.push(...v),f.push(...D);for(const v of N)m.push(...v)}}if(!h.length)throw new Error("No 3MF mesh triangles found.");for(const p of Array.from(u).map(b=>`3MF material resource "${b}" is not a supported color palette; fallback vertex colors were used.`))o.add(p);return{geometry:Fe(h,f,m),warnings:[...o]}}async function Gr(n,e={}){return sn(n,"",e.signal)}async function sn(n,e,t){F(t);const r=new wr,s=a=>{var o;return he((o=a.scenes)!=null&&o.length?a.scenes:[a.scene])},i=await j(r.parseAsync(n,e),t,s);return t!=null&&t.aborted&&(s(i),F(t)),i.scene}function Ur(n){return new Zn().parse(n)}function _r(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>Fs(a,e,r,t));const i=new nn(s).parse(n,e.resourcePath??"").scene;return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}async function Vr(n,e={}){var h,f;F(e.signal);const t=await j(Vn(new Uint8Array(n)),e.signal);F(e.signal);const r=Kr([...t.values()].filter(m=>!m.directory).map(m=>m.name)),s=Yr(r),i=s?await j(t.get(s).text(),e.signal):void 0;F(e.signal);const a=[],o=Xr(r,s,i,a),u=await j(t.get(o).text(),e.signal);F(e.signal);const l=new DOMParser().parseFromString(u,"application/xml");if(l.getElementsByTagName("parsererror").length)throw new Error("KMZ Collada XML is invalid.");const c=new Map;for(const m of Array.from(l.getElementsByTagName("*"))){if(m.localName!=="image")continue;const g=(f=(h=Array.from(m.children).find(p=>p.localName==="init_from"))==null?void 0:h.textContent)==null?void 0:f.trim();if(!g)continue;const w=lt(r,g,o);w&&!c.has(w)&&(c.set(w,await j(t.get(w).bytes(),e.signal)),F(e.signal))}const d=$r(u,o,r,m=>c.get(m),a,e.signal);try{return await j(d.ready,e.signal),F(e.signal),{object:d.object,warnings:a}}catch(m){throw d.release(),he(d.object),m}finally{d.release()}}function $r(n,e,t,r,s,i){F(i);const a=new fe,o=[],u=new Map;let l;const c=()=>{for(const h of o.splice(0))URL.revokeObjectURL(h);(l==null?void 0:l.userData.previewObjectUrls)===o&&delete l.userData.previewObjectUrls},d=new Promise(h=>{a.onLoad=()=>{c(),h()}});a.onError=()=>{s.push("A KMZ texture failed to load; the preview may be incomplete.")},a.setURLModifier(h=>{F(i);const f=lt(t,h,e),m=u.get(f??h);if(m)return m;const g=f?r(f):void 0;if(g){const w=new Uint8Array(g.byteLength);w.set(g);const p=URL.createObjectURL(new Blob([w.buffer],{type:qr(f)}));return u.set(f,p),o.push(p),p}return/^[a-z][a-z\d+.-]*:/i.test(h)&&!/^file:/i.test(h)?h:(s.push(`KMZ texture "${h}" could not be resolved; dependent appearance may be missing.`),'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="1" height="1"%3E%3Cpath fill="white" d="M0 0h1v1H0z"/%3E%3C/svg%3E')}),a.itemStart("filens:kmz-parse");try{l=new nn(a).parse(n,"").scene,o.length&&(l.userData.previewObjectUrls=o),Wr(l)||s.push("KMZ Collada model contains no renderable geometry.")}catch(h){throw c(),h}finally{a.itemEnd("filens:kmz-parse")}return{object:l,ready:d,release:c}}function Wr(n){let e=false;return n.traverse(t=>{var r,s;(s=(r=t.geometry)==null?void 0:r.getAttribute("position"))!=null&&s.count&&(e=true)}),e}function nt(n){const e=[];for(const t of n.replace(/\\/g,"/").split("/"))!t||t==="."||(t===".."?e.pop():e.push(t));return e.join("/")}function Kr(n){return new Map(n.map(e=>[nt(e),e]))}function lt(n,e,t=""){let r=e.trim().replace(/\\/g,"/").split(/[?#]/,1)[0]??"";if(/^[a-z][a-z\d+.-]*:/i.test(r))return;try{r=decodeURIComponent(r)}catch{}const s=t.slice(0,t.lastIndexOf("/")+1),i=[...new Set([...r.startsWith("/")?[]:[nt(s+r)],nt(r)])];for(const u of i){const l=n.get(u);if(l)return l}for(const u of i){const l=[...n].filter(([c])=>c.toLowerCase()===u.toLowerCase());if(l.length===1)return l[0][1]}const a=i[i.length-1].toLowerCase(),o=[...n].filter(([u])=>u.toLowerCase().endsWith("/"+a));return o.length===1?o[0][1]:void 0}function Yr(n){return n.get("doc.kml")??[...n.values()].find(e=>/^doc\.kml$/i.test(e))??[...n.values()].find(e=>/(^|\/)doc\.kml$/i.test(e))??[...n.values()].find(e=>/\.kml$/i.test(e))}function Xr(n,e,t,r){const s=t?Zr(t):void 0,i=s?lt(n,s,e):void 0,a=[...n.values()].find(u=>/\.dae$/i.test(u));s&&!i&&a&&r.push(`KMZ model "${s}" could not be resolved; using "${a}".`);const o=i??a;if(!o)throw new Error("KMZ archive does not contain a Collada (.dae) model.");return o}function Zr(n){var t,r,s;const e=new DOMParser().parseFromString(n,"application/xml");if(!e.getElementsByTagName("parsererror").length)for(const i of Array.from(e.getElementsByTagName("*"))){if(((t=i.localName)==null?void 0:t.toLowerCase())!=="model")continue;const a=Array.from(i.children).find(u=>u.localName.toLowerCase()==="link"),o=a&&((s=(r=Array.from(a.children).find(u=>u.localName.toLowerCase()==="href"))==null?void 0:r.textContent)==null?void 0:s.trim());if(o&&/\.dae(?:[?#].*)?$/i.test(o))return o}}function qr(n){var t;switch((t=n.split(".").pop())==null?void 0:t.toLowerCase()){case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";case"bmp":return"image/bmp";case"tga":return"image/x-tga";case"dds":return"image/vnd-ms.dds";default:return"application/octet-stream"}}function Jr(n){const e=new lr().parse(n);if(!e)throw new Error("Invalid MD2 model data.");return e.hasAttribute("normal")||e.computeVertexNormals(),new $(e,new V({color:8246268,roughness:.58,metalness:.04}))}function Qr(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(u=>Ls(u,e,r,t));const a=new cr(s).parse(n,e.resourcePath??"",e.modelName??"model"),o=new ee;for(const u of a.meshes??[])o.add(u);if(!o.children.length){for(const u of t)URL.revokeObjectURL(u);throw new Error("No LWO meshes found.")}return t.length&&(o.userData.previewObjectUrls=t),{object:o,warnings:r}}function es(n){const t=new ur().parse(n).skeleton.bones[0];if(!t)throw new Error("No BVH skeleton bones found.");const r=new ee;r.add(t);const s=new dr(t),i=s.material;for(const a of Array.isArray(i)?i:[i])a.color.set(8246268);return r.add(s),r}function ts(n){var r,s;const e=new hr().parse(n),t=new ee;if((r=e.geometryAtoms.getAttribute("position"))!=null&&r.count&&t.add(new me(e.geometryAtoms,new Pe({size:.6,color:16777215,vertexColors:true}))),(s=e.geometryBonds.getAttribute("position"))!=null&&s.count&&t.add(new Q(e.geometryBonds,new ne({color:14412542,transparent:true,opacity:.72}))),!t.children.length)throw new Error("No PDB atoms found.");return t}function ns(n){const e=Ps(n),t=new mr().parse(e.buffer),r=t.xLength*t.yLength*t.zLength;if(!Number.isSafeInteger(r)||r<1||t.data.length!==r)throw new Error("NRRD voxel data length does not match its dimensions.");if((e.encoding==="raw"||e.encoding==="gz"||e.encoding==="gzip")&&e.endian){const m=new Uint8Array(new Uint16Array([1]).buffer)[0]===1?"little":"big";if(e.endian!==m){const g=new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.byteLength),w=t.data.BYTES_PER_ELEMENT;for(let p=0;p<g.length;p+=w)for(let b=p,y=p+w-1;b<y;b++,y--){const C=g[b];g[b]=g[y],g[y]=C}}}const[s,i]=t.computeMinMax(),a=i-s,o=s<=0&&i>0?0:a>0?s+a*.5:s,l=Math.max(1,Math.ceil(r/6e4)),c=t.spacing.length>=3?t.spacing:[1,1,1],d=[],h=[];for(let m=0;m<r;m+=l){const g=Number(t.data[m]);if(!Number.isFinite(g)||g<o)continue;const w=m%t.xLength,p=Math.floor(m/t.xLength),b=p%t.yLength,y=Math.floor(p/t.yLength);d.push(w*c[0],b*c[1],y*c[2]);const C=a>0?_((g-s)/a,0,1):1;h.push(.22+C*.64,.3+C*.55,.4+C*.52)}if(!d.length)throw new Error("No NRRD voxels passed the preview threshold.");const f=new Y;return f.setAttribute("position",new Z(d,3)),f.setAttribute("color",new Z(h,3)),new me(f,new Pe({size:Math.max(Math.min(...c.filter(m=>m>0)),1)*.75,vertexColors:true}))}async function rs(n,e={}){F(e.signal);const t=Ss(n);if(!t)return new TextEncoder().encode(n).buffer;const r=e.resourceResolver;if(!r)throw new Error(`NHDR references external data file "${t}" but no resourceResolver was provided.`);const s=X(e.resourceBasePath??""),i=Ae(await ct(r,{source:K(s,t),fallbackSource:t,relation:"volume",sourceFormat:e.sourceFormat??"nhdr"},e.signal));if(!i.source)throw new Error(`NHDR external data file "${t}" could not be resolved.`);const a=await ut(i.source,e.signal);return F(e.signal),Cs(n,a)}function ss(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>As(a,e,r,t));const i=new qn(s).parse(n,e.resourcePath??"");return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}function is(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>Ds(a,e,r,t));const i=new Jn(s).parse(n,e.resourcePath??"");return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}async function as(n){return new Qn().parse(n)}async function os(n,e={}){var a;if(F(e.signal),!Me){const o=Promise.resolve().then(()=>Zi).then(({createRustStepImporter:u})=>u());Me=o,o.catch(()=>{Me===o&&(Me=null)})}const t=await j(Me,e.signal);F(e.signal);const r=t.ReadStepFile(new Uint8Array(n),{linearUnit:"millimeter"},e.signal),s=await j(Promise.resolve(r),e.signal);if(F(e.signal),!s.success||!s.root||!((a=s.meshes)!=null&&a.length))throw new Error("Rust STEP could not read this STEP file.");const i=new ee;i.userData.stepEngine="rust",i.userData.previewWarnings=s.warnings??[];for(const o of s.root.meshes){const u=s.meshes[o];if(!u)continue;const l=new Y;l.setAttribute("position",new Z(u.attributes.position.array,3)),u.attributes.normal?l.setAttribute("normal",new Z(u.attributes.normal.array,3)):l.computeVertexNormals(),u.index&&l.setIndex(u.index.array),i.add(new $(l,new V({color:new de(.72,.76,.82),side:Te})))}return i}function ls(n){return new er().parse(n)}function cs(n,e={}){const t=[],r=[],s=new fe;e.resourceResolver&&s.setURLModifier(a=>Es(a,e,r,t));const i=new tr(s).parse(n,e.resourcePath??"");return t.length&&(i.userData.previewObjectUrls=t),{object:i,warnings:r}}function us(n){return new nr().parse(n)}function ds(n){const e=new rr().parse(n),t=e.hasAttribute("color");return new me(e,new Pe({size:.08,color:t?16777215:8246268,vertexColors:t}))}function hs(n){const e=new sr().parse(ms(n),"");return e.hasAttribute("normal")||e.computeVertexNormals(),new $(e,new V({color:e.hasAttribute("color")?16777215:8246268,roughness:.58,metalness:.04,vertexColors:e.hasAttribute("color")}))}function ms(n){const e=typeof n=="string"?new TextEncoder().encode(n):new Uint8Array(n);if(e.byteLength>=kt)return typeof n=="string"?e.buffer:n;const t=new Uint8Array(kt);return t.fill(32),t.set(e),t[t.length-1]=10,t.buffer}function fs(n){const e=new ir().parse(n),t=new ee;for(const r of e??[])r&&t.add(new ar(r));return t}async function ps(n,e={}){var r;F(e.signal);const t=[];try{const s=await xs(n,e,t);F(e.signal);const i=new Nr;i.setConditionalLineMaterial(or),i.setMaterials([]);const a=new Promise((u,l)=>{i.parse(s,c=>u(c),c=>l(c))}),o=await j(a,e.signal,he);return(r=e.signal)!=null&&r.aborted&&(he(o),F(e.signal)),{object:o,warnings:t}}catch(s){throw t.length&&!(s&&typeof s=="object"&&"name"in s&&s.name==="AbortError")?new Error(`${s instanceof Error?s.message:String(s)} Warnings: ${t.join(" ")}`):s}}async function gs(n,e={}){F(e.signal);const t=[];try{const r=typeof n=="string"?n:new TextDecoder().decode(n),s=Ui(r),i=ws(s),a=i.length&&e.resourceResolver?await bs(s,i,e,t):{json:s,warnings:[],unresolvedResources:i},o=a.unresolvedResources;if(o.length&&!e.resourcePath)throw new Error(`glTF references external resources that are not bundled with this preview: ${o.join(", ")}.`);return F(e.signal),{object:await sn(JSON.stringify(a.json),e.resourcePath??"",e.signal),warnings:a.warnings}}finally{for(const r of t)URL.revokeObjectURL(r)}}function ws(n){if(!n||typeof n!="object")return[];const e=n,t=[...(e.buffers??[]).map(r=>r.uri),...(e.images??[]).filter(r=>r.bufferView==null).map(r=>r.uri)];return[...new Set(t.filter(r=>typeof r=="string"&&r.trim().length>0).map(r=>r.trim()).filter(r=>!_i(r)))]}async function bs(n,e,t,r){var u;const s=Ns(n),i=[],a=new Map,o=[];for(const l of e){F(t.signal);const c=await j(Promise.resolve((u=t.resourceResolver)==null?void 0:u.call(t,{family:"model3d",sourceFormat:t.sourceFormat??"gltf",source:l,relation:ks(s,l),name:l.split(/[\\/]/).pop()??l})),t.signal);F(t.signal);const d=pe(c,Ln(l),r);i.push(...d.warnings),d.source?a.set(l,d.source):o.push(l)}return Os(s,a),{json:s,warnings:i,unresolvedResources:o}}async function ys(n,e,t,r){var o;const s=X(K(X(t.resourceBasePath??""),e)),i=[],a=[];for(const u of n.split(/\r?\n/)){const l=Ms(u);if(!l||!t.resourceResolver){i.push(u);continue}if((o=t.signal)!=null&&o.aborted)throw new DOMException("3D preview aborted.","AbortError");const c=await ct(t.resourceResolver,{source:K(s,l.path),fallbackSource:l.path,relation:"texture",sourceFormat:t.sourceFormat??"obj"},t.signal);F(t.signal);const d=pe(c,q(l.path),r);if(a.push(...d.warnings),!d.source){a.push(`OBJ texture "${l.path}" could not be resolved; the material map was left unchanged.`),i.push(u);continue}i.push(`${l.prefix}${d.source}`)}return{text:i.join(`
|
|
7
|
+
`),warnings:a}}async function ct(n,e,t){F(t);const r=await j(Promise.resolve(n({family:"model3d",sourceFormat:e.sourceFormat,source:e.source,relation:e.relation,name:e.source.split(/[\\/]/).pop()??e.source})),t);return F(t),Ae(r).source||e.fallbackSource===e.source?r:j(Promise.resolve(n({family:"model3d",sourceFormat:e.sourceFormat,source:e.fallbackSource,relation:e.relation,name:e.fallbackSource.split(/[\\/]/).pop()??e.fallbackSource})),t)}function vs(n,e){const t=[];let r=e,s=[],i=false,a=false;for(const o of n.replace(/^\uFEFF/,"").replace(/\r\n?/g,`
|
|
8
|
+
`).split(`
|
|
9
|
+
`)){const u=/^\s*0\s+FILE\s+(.+?)\s*$/i.exec(o);u?(i&&(t.push({name:r,text:s.join(`
|
|
10
|
+
`)+`
|
|
11
|
+
`}),s=[]),r=u[1],i=true,a=false):/^\s*0\s+NOFILE\s*$/i.test(o)?a=true:a||s.push(o)}return t.push({name:r,text:s.join(`
|
|
12
|
+
`)+`
|
|
13
|
+
`}),t}async function xs(n,e,t){const r=X(e.resourceBasePath??""),s=new Map,i=new Map,a=new Map,o=f=>r&&f.startsWith(`${r}/`)?f.slice(r.length+1):f,u=(f,m,g,w)=>{const p=vs(f,g??"__filens_main__.ldr"),b=new Map;let y;for(let C=0;C<p.length;C++){const P=p[C],S=Ye(P.name),L=C===0&&w?o(w):Ye(g?o(K(m,S)):S),k=L.toLowerCase();let D=s.get(k);D||(D={name:L,text:P.text,directory:C===0&&g?m:X(K(m,S)),definitions:b},s.set(k,D)),b.set(S.toLowerCase(),D),C===0&&(y=D,g&&b.set(g.toLowerCase(),D))}return y},l=u(n,r),c=new Set,d=new Set,h=async f=>{if(F(e.signal),c.has(f))throw new Error(`Cyclic LDraw part reference: "${f.name}".`);if(d.has(f))return;c.add(f);const m=f.text.split(`
|
|
14
|
+
`);for(let g=0;g<m.length;g++){const w=/^(\s*1\s+(?:\S+\s+){13})(.+?)\s*$/.exec(m[g]);if(!w)continue;const p=Ye(w[2]),b=p.toLowerCase();let y=f.definitions.get(b)??l.definitions.get(b);if(!y&&e.resourceResolver){const C=/^(?:parts\/s|p\/48)\//i.test(p),P=[...new Set([K(C?r:f.directory,p),K(r,p),p])],S=P[0].toLowerCase();y=a.get(S);for(const L of P){if(y||(y=i.get(L.toLowerCase()),y))break;const k=Ae(await j(Promise.resolve(e.resourceResolver({family:"model3d",sourceFormat:e.sourceFormat??"ldr",source:L,relation:"part",name:L.split("/").pop()??L})),e.signal));if(F(e.signal),t.push(...k.warnings),!k.source)continue;const D=await Pn(k.source,e.signal);F(e.signal),y=u(D,X(L),p,L),i.set(L.toLowerCase(),y);break}y||(t.push(`LDraw part "${w[2]}" could not be resolved; dependent geometry may be missing.`),y=u(`0 !LDRAW_ORG Subpart
|
|
15
|
+
`,f.directory,p,P[0])),a.set(S,y)}y&&(m[g]=`${w[1]}${y.name}`,await h(y))}f.text=m.join(`
|
|
16
|
+
`),c.delete(f),d.add(f)};return await h(l),F(e.signal),[...new Set(s.values())].map(f=>`0 FILE ${f.name}
|
|
17
|
+
${f.text}`).join(`
|
|
18
|
+
`)}function Ms(n){const e=/^(\s*(?:map_\S+|bump|norm|disp)\s+)(.+?)\s*$/i.exec(n);if(!(e!=null&&e[1])||!e[2])return;let t=e[1],r=e[2];const s={"-bm":1,"-mm":2,"-s":3,"-o":3};for(;;){const i=/^(\S+)\s+/.exec(r),a=i&&s[i[1]];if(!a)break;const o=new RegExp(`^\\S+(?:\\s+\\S+){${a}}\\s+`).exec(r);if(!o)break;t+=o[0],r=r.slice(o[0].length)}return r?{prefix:t,path:r}:void 0}function Ss(n){for(const e of n.split(/\r?\n/)){const t=e.trim();if(!t||t.startsWith("#"))continue;const r=/^data\s*file\s*:\s*(.+)$/i.exec(t)??/^datafile\s*:\s*(.+)$/i.exec(t);if(!(r!=null&&r[1]))continue;const s=r[1].trim();if(!s||/[\s%]/.test(s))throw new Error(`NHDR data file reference "${s}" is not supported for direct preview yet.`);return s}}function Cs(n,e){const t=n.split(/\r?\n/),r=[];let s=false,i=false;for(const c of t){if(!c.trim())break;if(/^\s*data\s*file\s*:/i.test(c)||/^\s*datafile\s*:/i.test(c)){s=true;continue}/^\s*encoding\s*:/i.test(c)&&(i=true),r.push(c)}if(!s)return new TextEncoder().encode(n).buffer;i||r.push("encoding: raw");const a=r.join(`
|
|
19
|
+
`).replace(/\s+$/,""),o=new TextEncoder().encode(`${a}
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
`),u=new Uint8Array(e),l=new Uint8Array(o.byteLength+u.byteLength);return l.set(o,0),l.set(u,o.byteLength),l.buffer}function Ps(n){const e=new Uint8Array(n);let t=0;for(let r=0;r<e.length;r++){if(e[r]!==10)continue;if((e[r-1]===13?r-1:r)!==t){t=r+1;continue}const i=new TextDecoder().decode(e.subarray(0,t)),a=new Map(i.split(/\r?\n/).flatMap(d=>{const h=/^([^:#]+):\s*(.*)$/.exec(d);return h?[[h[1].trim().toLowerCase(),h[2].trim().toLowerCase()]]:[]}));for(const d of["line skip","byte skip"])if(a.has(d)&&a.get(d)!=="0")throw new Error(`NRRD ${d} is not supported for preview.`);if(a.get("dimension")!=="3")throw new Error("NRRD preview requires three scalar dimensions.");const o=a.get("encoding");if(!["raw","gz","gzip","ascii","text","txt","hex"].includes(o??""))throw new Error(`NRRD encoding "${o??""}" is not supported for preview.`);const u=a.get("endian");if(u&&u!=="little"&&u!=="big")throw new Error(`Unsupported NRRD endian "${u}".`);if(!i.includes("\r")&&/\n#[^\n]*\n$/.test(i))return{buffer:n,encoding:o,endian:u};const l=new TextEncoder().encode(`${i.replace(/\r\n/g,`
|
|
23
|
+
`).trimEnd()}
|
|
24
|
+
#
|
|
25
|
+
|
|
26
|
+
`),c=new Uint8Array(l.length+e.length-r-1);return c.set(l),c.set(e.subarray(r+1),l.length),{buffer:c.buffer,encoding:o,endian:u}}return{buffer:n}}function Ls(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"lwo",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`LWO texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`LWO texture "${a}" could not be resolved; default loader lookup was used.`),n}function Es(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"vrml",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`VRML texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`VRML texture "${a}" could not be resolved; default loader lookup was used.`),n}function Fs(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"dae",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`Collada texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`Collada texture "${a}" could not be resolved; default loader lookup was used.`),n}function As(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"fbx",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`FBX texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`FBX texture "${a}" could not be resolved; default loader lookup was used.`),n}function Ds(n,e,t,r){var u;const s=e.resourceResolver;if(!s)return n;if((u=e.signal)!=null&&u.aborted)throw new DOMException("3D preview aborted.","AbortError");const i=X(e.resourceBasePath??""),a=n.replace(/\\/g,"/"),o=[K(i,a),a,a.split("/").pop()??a];for(const l of o){const c=s({family:"model3d",sourceFormat:e.sourceFormat??"3ds",source:l,relation:"texture",name:l.split(/[\\/]/).pop()??l});if(c&&!(c instanceof Promise)){const d=pe(c,q(l));if(t.push(...d.warnings),d.source){const h=ge(d.source,q(l));return h?(h.startsWith("blob:")&&r.push(h),h):(t.push(`3DS texture "${a}" resolved to an unsupported source type; default loader lookup was used.`),n)}}}return t.push(`3DS texture "${a}" could not be resolved; default loader lookup was used.`),n}function Ye(n){const e=n.replace(/\\/g,"/").replace(/^\.\//,"");return/^s\//i.test(e)?`parts/${e}`:/^48\//i.test(e)?`p/${e}`:e}function Ns(n){return JSON.parse(JSON.stringify(n))}function Os(n,e){if(!n||typeof n!="object")return;const t=n;for(const r of t.buffers??[]){const s=typeof r.uri=="string"?e.get(r.uri.trim()):void 0;s!==void 0&&(r.uri=s)}for(const r of t.images??[]){const s=typeof r.uri=="string"?e.get(r.uri.trim()):void 0;r.bufferView==null&&s!==void 0&&(r.uri=s)}}function ks(n,e){if(!n||typeof n!="object")return"resource";const t=n;return(t.buffers??[]).some(r=>r.uri===e)?"buffer":(t.images??[]).some(r=>r.bufferView==null&&r.uri===e)?"image":"resource"}async function ut(n,e){if(F(e),typeof n=="string"){const t=s=>{var i;(i=s.body)==null||i.cancel().catch(()=>{})},r=await j(fetch(n,{signal:e}),e,t);try{if(F(e),!r.ok)throw new Error(`Failed to load 3D source: ${r.status} ${r.statusText}`.trim());return await j(r.arrayBuffer(),e)}catch(s){throw t(r),s}}if(n instanceof Blob)return j(n.arrayBuffer(),e);if(ArrayBuffer.isView(n)){const t=new Uint8Array(n.byteLength);return t.set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength)),t.buffer}if(n instanceof ArrayBuffer)return n.slice(0);throw new Error("Unsupported 3D source type.")}function Rs(n){const e=[],t=[];let r=[0,0,1];const s=[];for(const i of n.split(/\r?\n/)){const a=i.trim().split(/\s+/);if(a[0]==="facet"&&a[1]==="normal"){r=[G(a[2]),G(a[3]),G(a[4])];continue}if(a[0]==="vertex"&&(s.push([G(a[1]),G(a[2]),G(a[3])]),s.length===3))for(const o of s.splice(0,3))e.push(...o),t.push(...r)}if(!e.length)throw new Error("No STL triangles found.");return Fe(e,t)}function Ts(n){if(n.byteLength<84)throw new Error("Binary STL is too small.");const e=new DataView(n.buffer,n.byteOffset,n.byteLength),t=e.getUint32(80,true);if(84+t*50>n.byteLength)throw new Error("Binary STL triangle data is truncated.");if(!t)throw new Error("No STL triangles found.");const s=new Float32Array(t*9),i=new Float32Array(t*9);let a=84;for(let o=0;o<t;o+=1){const u=e.getFloat32(a,true),l=e.getFloat32(a+4,true),c=e.getFloat32(a+8,true);a+=12;for(let d=0;d<3;d+=1){const h=o*9+d*3;s[h]=e.getFloat32(a,true),s[h+1]=e.getFloat32(a+4,true),s[h+2]=e.getFloat32(a+8,true),i[h]=u,i[h+1]=l,i[h+2]=c,a+=12}a+=2}return{positions:s,normals:i,triangleCount:t,bounds:hn(s)}}const rt=[1,0,0,0,1,0,0,0,1,0,0,0];function W(n,e){return Array.from(n.querySelectorAll("*")).filter(t=>t.localName===e)}function Tt(n,e){return Array.from(n.children).filter(t=>t.localName===e)}function an(n,e,t,r){const s=t.get(n);if(s)return s;if(r.has(n))return;const i=e.get(n);if(!i)return;r.add(n);const a=Tt(i,"components")[0];if(!a){r.delete(n);return}const o=[],u=[];for(const c of Tt(a,"component")){const d=c.getAttribute("objectid"),h=d?an(d,e,t,r):void 0;if(!(h!=null&&h.positions.length))continue;const f=on(c.getAttribute("transform"));for(let m=0;m<h.positions.length;m+=1)o.push(Ie(h.positions[m],f)),u.push(h.colors[m]??[.49,.83,.99])}if(r.delete(n),!o.length)return;const l={positions:o,colors:u};return t.set(n,l),l}function Is(n){const e=new Map;for(const t of W(n,"basematerials")){const r=t.getAttribute("id");r&&e.set(r,W(t,"base").map(s=>zt(s.getAttribute("displaycolor"))))}for(const t of W(n,"colorgroup")){const r=t.getAttribute("id");r&&e.set(r,W(t,"color").map(s=>zt(s.getAttribute("color"))))}return e}function Bs(n){return[...W(n,"texture2d").map(t=>["texture2d",t.getAttribute("id")]),...W(n,"texture2dgroup").map(t=>["texture2dgroup",t.getAttribute("id")]),...W(n,"compositematerials").map(t=>["composite materials",t.getAttribute("id")]),...W(n,"multiproperties").map(t=>["multi properties",t.getAttribute("id")])].filter(([,t])=>!!t).map(([t,r])=>`3MF ${t} resource "${r}" is not rendered directly yet; base-material colors remain supported.`)}function It(n,e,t){n&&!e.has(n)&&t.add(n)}function Bt(n,e,t){if(!n)return;const r=t.get(n);if(!(r!=null&&r.length))return;const s=Number(e??0);return Number.isInteger(s)&&s>=0&&s<r.length?r[s]:r[0]}function zt(n){const e=String(n??"").trim(),t=/^#?([0-9a-f]{6})(?:[0-9a-f]{2})?$/i.exec(e);if(!(t!=null&&t[1]))return[.49,.83,.99];const r=t[1];return[Number.parseInt(r.slice(0,2),16)/255,Number.parseInt(r.slice(2,4),16)/255,Number.parseInt(r.slice(4,6),16)/255]}function on(n){if(!n)return rt;const e=n.trim().split(/\s+/).map(Number);return e.length!==12||e.some(t=>!Number.isFinite(t))?rt:e}function Ie(n,e){return[n[0]*e[0]+n[1]*e[1]+n[2]*e[2]+e[9],n[0]*e[3]+n[1]*e[4]+n[2]*e[5]+e[10],n[0]*e[6]+n[1]*e[7]+n[2]*e[8]+e[11]]}function zs(n,e,t){const[r,,s]=n.split("/"),i=Ht(Number(r),e);if(i==null)return;const a=s?Ht(Number(s),t):void 0;return{vertexIndex:i,normalIndex:a}}function Hs(n,e,t,r,s,i,a,o,u){const l=[n,e,t],c=dt(r[n.vertexIndex],r[e.vertexIndex],r[t.vertexIndex]);for(const d of l){a.push(...r[d.vertexIndex]),o.push(...d.normalIndex!=null?i[d.normalIndex]??c:c);const h=s[d.vertexIndex];h&&u.push(...h)}}function js(n){if(n.length<7)return;const e=[Number(n[4]),Number(n[5]),Number(n[6])];if(!e.some(t=>!Number.isFinite(t)))return e.map(t=>_(t>1?t/255:t,0,1))}function Ht(n,e){if(!Number.isInteger(n)||n===0||e<=0)return;const t=n>0?n-1:e+n;return t>=0&&t<e?t:void 0}function dt(n,e,t){const r=e[0]-n[0],s=e[1]-n[1],i=e[2]-n[2],a=t[0]-n[0],o=t[1]-n[1],u=t[2]-n[2];return ln([s*u-i*o,i*a-r*u,r*o-s*a])}function ln(n){const e=Math.hypot(n[0],n[1],n[2]);return e?[n[0]/e,n[1]/e,n[2]/e]:[0,0,1]}function Gs(n){const e=$s(n);if(!e)throw new Error("PLY header is missing end_header.");const r=new TextDecoder().decode(n.slice(0,e.headerEnd)).replace(/\r/g,"").split(`
|
|
27
|
+
`).map(c=>c.trim()).filter(Boolean);if(r[0]!=="ply")throw new Error("Invalid PLY header.");let s="",i=0,a=0,o;const u=[];let l;for(const c of r.slice(1)){const d=c.split(/\s+/);if(d[0]==="format"){s=d[1]??"";continue}if(d[0]==="element"){o=d[1]==="vertex"||d[1]==="face"?d[1]:void 0,d[1]==="vertex"&&(i=Number(d[2])||0),d[1]==="face"&&(a=Number(d[2])||0);continue}if(d[0]==="property"){if(o==="vertex"&&d.length>=3&&d[1]!=="list"){u.push({type:d[1],name:d[2]});continue}o==="face"&&d[1]==="list"&&d.length>=5&&!l&&(l={countType:d[2],itemType:d[3],name:d[4]})}}if(!s||!i||!a||!u.length||!l)throw new Error("PLY header does not define supported vertex and face data.");return{format:s,dataOffset:e.dataOffset,vertexCount:i,faceCount:a,vertexProperties:u,faceListProperty:l}}function Us(n,e){const t=n.replace(/\r/g,"").split(`
|
|
28
|
+
`).map(f=>f.trim()).filter(Boolean),r=[],s=[];let i=0;const a=e.vertexProperties.findIndex(f=>f.name==="x"),o=e.vertexProperties.findIndex(f=>f.name==="y"),u=e.vertexProperties.findIndex(f=>f.name==="z"),l=un(e.vertexProperties);if(a<0||o<0||u<0)throw new Error("PLY vertex properties must include x, y, and z.");for(;i<e.vertexCount&&i<t.length;i+=1){const f=t[i].split(/\s+/);r.push([G(f[a]),G(f[o]),G(f[u])]),s.push(dn(f.map(Number),e.vertexProperties,l))}const c=[],d=[],h=[];for(let f=0;f<e.faceCount&&i<t.length;f+=1,i+=1){const m=t[i].split(/\s+/).map(Number),g=m[0]??0,w=m.slice(1,1+g).filter(p=>Number.isInteger(p));cn(w,r,s,c,d,h)}if(!c.length)throw new Error("No PLY triangles found.");return Fe(c,d,h.length===c.length?h:void 0)}function _s(n,e){const t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=[],s=[];let i=e.dataOffset;const a=e.vertexProperties.findIndex(f=>f.name==="x"),o=e.vertexProperties.findIndex(f=>f.name==="y"),u=e.vertexProperties.findIndex(f=>f.name==="z"),l=un(e.vertexProperties);if(a<0||o<0||u<0)throw new Error("PLY vertex properties must include x, y, and z.");for(let f=0;f<e.vertexCount;f+=1){const m=[];for(const g of e.vertexProperties){const w=Ze(t,i,g.type,true);m.push(w.value),i=w.nextOffset}r.push([m[a]??0,m[o]??0,m[u]??0]),s.push(dn(m,e.vertexProperties,l))}const c=[],d=[],h=[];for(let f=0;f<e.faceCount;f+=1){const m=Ze(t,i,e.faceListProperty.countType,true);i=m.nextOffset;const g=[];for(let w=0;w<m.value;w+=1){const p=Ze(t,i,e.faceListProperty.itemType,true);g.push(p.value),i=p.nextOffset}cn(g,r,s,c,d,h)}if(!c.length)throw new Error("No PLY triangles found.");return Fe(c,d,h.length===c.length?h:void 0)}function cn(n,e,t,r,s,i){const a=n.filter(o=>Number.isInteger(o)&&o>=0&&o<e.length);if(!(a.length<3))for(let o=1;o<a.length-1;o+=1){const u=e[a[0]],l=e[a[o]],c=e[a[o+1]],d=dt(u,l,c),h=[a[0],a[o],a[o+1]];for(const f of[u,l,c])r.push(...f),s.push(...d);for(const f of h){const m=t[f];m&&i.push(...m)}}}function un(n){const e=Xe(n,["red","diffuse_red","r"]),t=Xe(n,["green","diffuse_green","g"]),r=Xe(n,["blue","diffuse_blue","b"]);return e>=0&&t>=0&&r>=0?[e,t,r]:void 0}function Xe(n,e){return n.findIndex(t=>e.includes(t.name.toLowerCase()))}function dn(n,e,t){if(!t)return;const r=t.map(s=>n[s]??Number.NaN);if(!r.some(s=>!Number.isFinite(s)))return r.map((s,i)=>Vs(s,e[t[i]].type))}function Vs(n,e){return _(e==="float"||e==="float32"||e==="double"||e==="float64"?n>1?n/255:n:n/255,0,1)}function $s(n){const e=[new TextEncoder().encode(`end_header
|
|
29
|
+
`),new TextEncoder().encode(`end_header\r
|
|
30
|
+
`)];for(let t=0;t<n.length;t+=1)for(const r of e)if(Ws(n,r,t))return{headerEnd:t+10,dataOffset:t+r.length}}function Ws(n,e,t){if(t+e.length>n.length)return false;for(let r=0;r<e.length;r+=1)if(n[t+r]!==e[r])return false;return true}function Ze(n,e,t,r){switch(t){case"char":case"int8":return{value:n.getInt8(e),nextOffset:e+1};case"uchar":case"uint8":return{value:n.getUint8(e),nextOffset:e+1};case"short":case"int16":return{value:n.getInt16(e,r),nextOffset:e+2};case"ushort":case"uint16":return{value:n.getUint16(e,r),nextOffset:e+2};case"int":case"int32":return{value:n.getInt32(e,r),nextOffset:e+4};case"uint":case"uint32":return{value:n.getUint32(e,r),nextOffset:e+4};case"float":case"float32":return{value:n.getFloat32(e,r),nextOffset:e+4};case"double":case"float64":return{value:n.getFloat64(e,r),nextOffset:e+8};default:throw new Error(`Unsupported PLY scalar type "${t}".`)}}function Fe(n,e,t){const r=hn(n);return{positions:new Float32Array(n),normals:new Float32Array(e),...t!=null&&t.length?{colors:new Float32Array(t)}:{},triangleCount:n.length/9,bounds:r}}function hn(n){let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(let o=0;o<n.length;o+=3){const u=n[o],l=n[o+1],c=n[o+2];e=Math.min(e,u),t=Math.min(t,l),r=Math.min(r,c),s=Math.max(s,u),i=Math.max(i,l),a=Math.max(a,c)}return{min:[e,t,r],max:[s,i,a]}}function jt(n,e){var t;return{format:e,triangleCount:n.triangleCount,vertexCount:n.positions.length/3,hasVertexColors:!!((t=n.colors)!=null&&t.length),bounds:{min:[...n.bounds.min],max:[...n.bounds.max],size:[n.bounds.max[0]-n.bounds.min[0],n.bounds.max[1]-n.bounds.min[1],n.bounds.max[2]-n.bounds.min[2]]}}}function Ks(n){return n.children.map((e,t)=>mn(e,`node-${t+1}`))}function mn(n,e){const t=n;return t.userData.previewNodeId=e,t.userData.previewOriginalVisible=n.visible,t.userData.previewMaterialKeys=ht(n),{id:e,label:ni(n,e),kind:ri(n),visible:n.visible,metadata:si(n),children:n.children.map((r,s)=>mn(r,`${e}.${s+1}`))}}function ht(n){const e=n;if(e.userData.previewEdgeHelper||e.userData.previewMeasurementHelper)return[];const t=n;return(Array.isArray(t.material)?t.material:t.material?[t.material]:[]).map(s=>Mn(s))}function Ys(n){let e=false;return n.traverse(t=>{const r=t;r.userData.previewEdgeHelper||r.userData.previewMeasurementHelper||!e&&ht(t).length&&(e=true)}),e}function Xs(n){const e=new te,t=new te;let r=false;return n.traverse(s=>{const i=s;if(!(!s.visible||!i.geometry)&&(t.setFromObject(s),!t.isEmpty())){if(!r){e.copy(t),r=true;return}e.union(t)}}),e}function Zs(n){const e=n.object.geometry;if(!e||!n.face)return;const t=e.getAttribute("position");if(!t||t.itemSize<3)return;const r=[qe(n.object,t,e.index,n.face.a),qe(n.object,t,e.index,n.face.b),qe(n.object,t,e.index,n.face.c)].filter(a=>!!a);if(!r.length)return;let s=r[0],i=s.distanceToSquared(n.point);for(let a=1;a<r.length;a+=1){const o=r[a],u=o.distanceToSquared(n.point);u<i&&(s=o,i=u)}return s}function qe(n,e,t,r){const s=t?t.getX(r):r;if(!Number.isFinite(s))return;const i=new E(e.getX(s),e.getY(s),e.getZ(s));return n.localToWorld(i)}function Gt(n,e,t){switch(t){case"x":return new E(n.x,e.y,e.z);case"y":return new E(e.x,n.y,e.z);case"z":return new E(e.x,e.y,n.z);default:return n}}function Ut(n){switch(n){case"y":return new E(0,1,0);case"z":return new E(0,0,1);default:return new E(1,0,0)}}function qs(n){switch(n){case"y":return new E(0,-1,0);case"z":return new E(0,0,-1);default:return new E(-1,0,0)}}function Js(n){switch(n){case"front":return{yaw:0,pitch:0};case"back":return{yaw:180,pitch:0};case"left":return{yaw:-90,pitch:0};case"right":return{yaw:90,pitch:0};case"top":return{yaw:0,pitch:90};case"bottom":return{yaw:0,pitch:-90};case"isometric":return{yaw:-35,pitch:24};default:return}}function Qs(n){return`${String(n??"model-preview").replace(/\.[^.]+$/,"").replace(/[<>:"/\\|?*\u0000-\u001F]+/g,"-").trim()||"model-preview"}.png`}function fn(n){return n.map(e=>({...e,metadata:e.metadata?{...e.metadata,materialNames:[...e.metadata.materialNames??[]],materialDetails:yn(e.metadata.materialDetails),bounds:e.metadata.bounds?{...e.metadata.bounds,min:[...e.metadata.bounds.min],max:[...e.metadata.bounds.max],size:[...e.metadata.bounds.size]}:void 0}:void 0,children:fn(e.children)}))}function pn(n,e,t){return n.map(r=>r.id===e?gn(r,t):{...r,children:pn(r.children,e,t)})}function gn(n,e){return{...n,visible:e,children:n.children.map(t=>gn(t,e))}}function wn(n,e){for(const t of n){if(t.id===e)return t;const r=wn(t.children,e);if(r)return r}}function ei(n,e){const t=ti(n),r=t.children.filter(a=>!new te().setFromObject(a).isEmpty());if(r.length<2)return[];const i=new te().setFromObject(t).getCenter(new E);return r.map((a,o)=>{const u=new te().setFromObject(a),l=u.getCenter(new E),c=u.getSize(new E),d=l.sub(i);if(d.lengthSq()<=1e-6){const h=o/r.length*Math.PI*2;d.set(Math.cos(h),0,Math.sin(h))}else d.normalize();return{object:a,basePosition:a.position.clone(),direction:d,distance:Math.max(c.length()*.45,e*.22)}})}function ti(n){let e=n;for(;e.children.length===1;){const t=e.children[0];if(!t||t.children.length<2)break;e=t}return e}function ni(n,e){var r;const t=(r=n.name)==null?void 0:r.trim();return t||(n.type&&n.type!=="Object3D"?n.type:e)}function ri(n){return n instanceof $||n instanceof Ee?"mesh":n instanceof me?"points":n instanceof _e||n instanceof Q||n.type==="LineLoop"?"lines":n.type==="Bone"?"bone":n.type.endsWith("Light")?"light":n.type.endsWith("Camera")?"camera":n instanceof ee?"group":"object"}function T(n,e){var g;let t=0,r=0,s=0,i=0,a=0,o=0,u=false,l=Array.isArray(n.animations)?((g=n.animations)==null?void 0:g.length)??0:0;const c=new Set,d=new Set,h=new Map;n.traverse(w=>{var P;const p=w;if(p.userData.previewEdgeHelper||p.userData.previewMeasurementHelper)return;t+=1,"animations"in w&&Array.isArray(w.animations)&&(l+=((P=w.animations)==null?void 0:P.length)??0);const b=w,y=b.geometry;if(y){const S=y.getAttribute("position");S&&(a+=S.count),y.getAttribute("color")&&(u=true),o+=mt(y)}w instanceof $||w instanceof Ee?r+=1:w instanceof me?i+=1:(w instanceof _e||w instanceof Q||w.type==="LineLoop")&&(s+=1);const C=Array.isArray(b.material)?b.material:b.material?[b.material]:[];for(const S of C)d.add(S),S.name&&c.add(S.name),h.set(S.id,bn(S))});const f=new te().setFromObject(n),m=f.isEmpty()?void 0:(()=>{const w=f.min,p=f.max,b=f.getSize(new E);return{min:[w.x,w.y,w.z],max:[p.x,p.y,p.z],size:[b.x,b.y,b.z]}})();return{format:e,objectCount:t,meshCount:r,lineCount:s,pointCount:i,materialCount:d.size,materialNames:[...c].sort((w,p)=>w.localeCompare(p)),materialDetails:[...h.values()].sort(xn),animationCount:l,bounds:m,triangleCount:o,vertexCount:a,hasVertexColors:u}}function si(n){let e=0,t=0,r=0,s=0,i=0,a=false;const o=new Set,u=new Set,l=new Map;n.traverse(h=>{const f=h;if(f.userData.previewEdgeHelper||f.userData.previewMeasurementHelper)return;const m=h,g=m.geometry;if(g){const p=g.getAttribute("position");p&&(s+=p.count),g.getAttribute("color")&&(a=true),i+=mt(g)}h instanceof $||h instanceof Ee?e+=1:h instanceof me?r+=1:(h instanceof _e||h instanceof Q||h.type==="LineLoop")&&(t+=1);const w=Array.isArray(m.material)?m.material:m.material?[m.material]:[];for(const p of w)u.add(p),p.name&&o.add(p.name),l.set(p.id,bn(p))});const c=new te().setFromObject(n),d=c.isEmpty()?void 0:(()=>{const h=c.min,f=c.max,m=c.getSize(new E);return{min:[h.x,h.y,h.z],max:[f.x,f.y,f.z],size:[m.x,m.y,m.z]}})();return{meshCount:e,lineCount:t,pointCount:r,materialCount:u.size,materialNames:[...o].sort((h,f)=>h.localeCompare(f)),materialDetails:[...l.values()].sort(xn),triangleCount:i,vertexCount:s,hasVertexColors:a,bounds:d}}function mt(n){const e=n.getAttribute("position");return e?n.index?Math.floor(n.index.count/3):Math.floor(e.count/3):0}function bn(n){const e=n,t=[e.map?"base":void 0,e.alphaMap?"alpha":void 0,e.aoMap?"ao":void 0,e.bumpMap?"bump":void 0,e.displacementMap?"displacement":void 0,e.emissiveMap?"emissive":void 0,e.envMap?"environment":void 0,e.lightMap?"light":void 0,e.metalnessMap?"metalness":void 0,e.normalMap?"normal":void 0,e.roughnessMap?"roughness":void 0,e.specularMap?"specular":void 0].filter(r=>!!r);return{key:Mn(n),...n.name?{name:n.name}:{},type:n.type||n.constructor.name||"Material",...e.color?{color:qt(e.color)}:{},...e.emissive?{emissiveColor:qt(e.emissive)}:{},...Number.isFinite(n.opacity)?{opacity:R(n.opacity)}:{},...Number.isFinite(n.alphaTest)?{alphaTest:R(n.alphaTest)}:{},transparent:n.transparent,...typeof e.wireframe=="boolean"?{wireframe:e.wireframe}:{},...typeof e.vertexColors=="boolean"?{vertexColors:e.vertexColors}:{},...typeof e.vertexColors=="number"?{vertexColors:e.vertexColors>0}:{},...typeof e.flatShading=="boolean"?{flatShading:e.flatShading}:{},...typeof e.depthWrite=="boolean"?{depthWrite:e.depthWrite}:{},...typeof e.depthTest=="boolean"?{depthTest:e.depthTest}:{},...n.side===1?{side:"back"}:n.side===2?{side:"double"}:{side:"front"},...Number.isFinite(e.roughness)?{roughness:R(e.roughness)}:{},...Number.isFinite(e.metalness)?{metalness:R(e.metalness)}:{},...Number.isFinite(e.shininess)?{shininess:R(e.shininess)}:{},...Number.isFinite(e.size)?{size:R(e.size)}:{},...t.length?{mapKinds:t}:{}}}function yn(n){return n==null?void 0:n.map(e=>({...e,mapKinds:e.mapKinds?[...e.mapKinds]:void 0}))}function _t(n){return n?{...n,snapMode:n.snapMode??"surface",axisLock:n.axisLock??"free",start:n.start?[...n.start]:void 0,end:n.end?[...n.end]:void 0,delta:n.delta?[...n.delta]:void 0,previewPoint:n.previewPoint?[...n.previewPoint]:void 0,previewDelta:n.previewDelta?[...n.previewDelta]:void 0,previewDistance:n.previewDistance}:void 0}function Vt(n,e){return!n||!e?n===e:n.active===e.active&&n.status===e.status&&(n.snapMode??"surface")===(e.snapMode??"surface")&&(n.axisLock??"free")===(e.axisLock??"free")&&oe(n.start,e.start)&&oe(n.end,e.end)&&oe(n.delta,e.delta)&&oe(n.previewPoint,e.previewPoint)&&oe(n.previewDelta,e.previewDelta)&&n.distance===e.distance&&n.previewDistance===e.previewDistance}function oe(n,e){return!n||!e?n===e:n[0]===e[0]&&n[1]===e[1]&&n[2]===e[2]}function ue(n){const e="x",[t,r]=(n==null?void 0:n[e])??[-1,1];return{active:false,mode:"single",axis:e,offset:_(0,t,r),min:R(t),max:R(r),bounds:Le(n??Ge()),range:xe(n??Ge())}}function ii(n){return n?{...n,mode:n.mode??"single",offset:R(n.offset),min:R(n.min),max:R(n.max),bounds:n.bounds?Le(n.bounds):void 0,range:n.range?Le(n.range):void 0}:void 0}function Je(n,e){const t=n.axis??"x",[r,s]=e[t];return{active:n.active,mode:n.mode??"single",axis:t,offset:R(_(n.offset,r,s)),min:R(r),max:R(s),bounds:Le(e),range:li(n.range,e)}}function ai(n,e){return!n||!e?n===e:n.active===e.active&&(n.mode??"single")===(e.mode??"single")&&n.axis===e.axis&&n.offset===e.offset&&n.min===e.min&&n.max===e.max&&oi(n.range,e.range)}function oi(n,e){return!n||!e?n===e:n.x[0]===e.x[0]&&n.x[1]===e.x[1]&&n.y[0]===e.y[0]&&n.y[1]===e.y[1]&&n.z[0]===e.z[0]&&n.z[1]===e.z[1]}function li(n,e){const t=xe(e);return{x:Qe(n==null?void 0:n.x,e.x,t.x),y:Qe(n==null?void 0:n.y,e.y,t.y),z:Qe(n==null?void 0:n.z,e.z,t.z)}}function Qe(n,e,t){if(!n)return[...t];const r=_(Math.min(n[0],n[1]),e[0],e[1]),s=_(Math.max(n[0],n[1]),e[0],e[1]);return[R(r),R(s)]}function Ge(){return{x:[-1,1],y:[-1,1],z:[-1,1]}}function Le(n){return{x:[...n.x],y:[...n.y],z:[...n.z]}}function xe(n){return Le(n)}function Ue(n){return`${n.axis}:${n.offset.toFixed(5)}`}function ci(n){if(n.mode==="box"){const e=n.range;return e?`box:${e.x[0].toFixed(5)}:${e.x[1].toFixed(5)}:${e.y[0].toFixed(5)}:${e.y[1].toFixed(5)}:${e.z[0].toFixed(5)}:${e.z[1].toFixed(5)}`:"box"}return`single:${Ue(n)}`}function ui(n,e){const t=`${e.position.x.toFixed(5)}:${e.position.y.toFixed(5)}:${e.position.z.toFixed(5)}`;if(n.mode==="box"){const r=n.range;return r?`box:${t}:${r.x[0].toFixed(5)}:${r.x[1].toFixed(5)}:${r.y[0].toFixed(5)}:${r.y[1].toFixed(5)}:${r.z[0].toFixed(5)}:${r.z[1].toFixed(5)}`:`box:${t}`}return`single:${t}:${Ue(n)}`}function di(n,e){switch(n.axis){case"x":return{width:Math.max(e.z[1]-e.z[0],0),height:Math.max(e.y[1]-e.y[0],0)};case"y":return{width:Math.max(e.x[1]-e.x[0],0),height:Math.max(e.z[1]-e.z[0],0)};case"z":default:return{width:Math.max(e.x[1]-e.x[0],0),height:Math.max(e.y[1]-e.y[0],0)}}}function hi(n,e){switch(n.axis){case"x":return Be([[n.offset,e.y[0],e.z[0]],[n.offset,e.y[1],e.z[0]],[n.offset,e.y[1],e.z[1]],[n.offset,e.y[0],e.z[1]]]);case"y":return Be([[e.x[0],n.offset,e.z[0]],[e.x[1],n.offset,e.z[0]],[e.x[1],n.offset,e.z[1]],[e.x[0],n.offset,e.z[1]]]);case"z":default:return Be([[e.x[0],e.y[0],n.offset],[e.x[1],e.y[0],n.offset],[e.x[1],e.y[1],n.offset],[e.x[0],e.y[1],n.offset]])}}function Be(n){const e=[];for(let t=0;t<n.length;t+=1){const r=n[t],s=n[(t+1)%n.length];e.push(...r,...s)}return e}function mi(n){const e=[];for(let t=0;t<n.length-1;t+=1)e.push(...n[t],...n[t+1]);return e}function fi(n,e,t=1e-4){const r=[],s=[],i=new Map,a=new Set,o=(c,d,h)=>{const[f,m]=re(n,[c,d,h]),g=`${Math.round(f/t)}:${Math.round(m/t)}`,w=i.get(g);if(typeof w=="number"){const b=r[w];return b.x+=c,b.y+=d,b.z+=h,b.count+=1,w}const p=r.length;return r.push({x:c,y:d,z:h,count:1,edges:[]}),i.set(g,p),p};for(let c=0;c<e.length;c+=6){const d=o(e[c],e[c+1],e[c+2]),h=o(e[c+3],e[c+4],e[c+5]);if(d===h)continue;const f=d<h?`${d}:${h}`:`${h}:${d}`;if(a.has(f))continue;a.add(f);const m=s.length;s.push({a:d,b:h,visited:false}),r[d].edges.push(m),r[h].edges.push(m)}const u=[],l=[];for(let c=0;c<r.length;c+=1)if(r[c].edges.length!==2)for(;;){const d=r[c].edges.find(f=>!s[f].visited);if(typeof d!="number")break;const h=$t(n,r,s,c,d);Wt(n,r,h,u,l,t)}for(let c=0;c<r.length;c+=1)for(;;){const d=r[c].edges.find(f=>!s[f].visited);if(typeof d!="number")break;const h=$t(n,r,s,c,d);Wt(n,r,h,u,l,t)}return{loops:Mi(n,u,t).filter(c=>c.length>=3),chains:Si(n,l,t).filter(c=>c.length>=2)}}function pi(n,e,t,r,s,i){const a=e[r].edges.filter(f=>!t[f].visited&&f!==i);if(!a.length)return;if(typeof s!="number")return a[0];const o=ze(e[r]),u=ze(e[s]),l=st(n,u,o),c=Math.hypot(l.x,l.y);if(c<=1e-10)return a[0];let d=a[0],h=Number.NEGATIVE_INFINITY;for(const f of a){const m=t[f],g=m.a===r?m.b:m.a,w=ze(e[g]),p=st(n,o,w),b=Math.hypot(p.x,p.y);if(b<=1e-10)continue;const y=(l.x*p.x+l.y*p.y)/(c*b);y>h&&(h=y,d=f)}return d}function $t(n,e,t,r,s){const i=t[s];i.visited=true;const a=i.a===r?i.b:i.a,o=[r,a];let u=r,l=a,c=s;for(;l!==r;){const d=pi(n,e,t,l,u,c);if(typeof d!="number")break;const h=t[d];h.visited=true;const f=h.a===l?h.b:h.a;o.push(f),u=l,c=d,l=f}return o}function Wt(n,e,t,r,s,i=1e-4){if(t.length<2)return;const a=t.length>=4&&t[0]===t[t.length-1],o=t.slice(0,a?-1:t.length).map(l=>ze(e[l])),u=gi(n,o,a,i);if(a){const l=Math.abs(ft(u.map(c=>{const[d,h]=re(n,c);return new at(d,h)})));u.length>=3&&l>i*i&&r.push(u);return}u.length>=2&&wi(n,u)>i&&s.push(u)}function gi(n,e,t,r=1e-5){if(e.length<=(t?3:2))return e;const s=[];for(let i=0;i<e.length;i+=1){if(!t&&(i===0||i===e.length-1)){s.push(e[i]);continue}const a=e[(i-1+e.length)%e.length],o=e[i],u=e[(i+1)%e.length],[l,c]=re(n,a),[d,h]=re(n,o),[f,m]=re(n,u),g=(d-l)*(m-c)-(h-c)*(f-l);Math.abs(g)>r&&s.push(o)}return s.length>=(t?3:2)?s:e}function wi(n,e){let t=0;for(let r=0;r<e.length-1;r+=1){const s=st(n,e[r],e[r+1]);t+=Math.hypot(s.x,s.y)}return t}function ze(n){return[n.x/n.count,n.y/n.count,n.z/n.count]}function st(n,e,t){const[r,s]=re(n,e),[i,a]=re(n,t);return{x:i-r,y:a-s}}function bi(n,e){if(!e.length)return;const t=xi(n,e),r=[],s=[];let i=0;for(let a=0;a<t.length;a+=1){const o=t[a];if(o.depth%2!==0)continue;const u=Yt(o.loop,o.points2d,"ccw"),l=o.children.map(h=>t[h]).filter(h=>h.depth===o.depth+1).map(h=>Yt(h.loop,h.points2d,"cw")),c=gr.triangulateShape(u.points2d,l.map(h=>h.points2d));if(!c.length)continue;const d=[u,...l];r.push(...d.flatMap(h=>h.loop.flat())),s.push(...c.flat().map(h=>h+i)),i+=d.reduce((h,f)=>h+f.loop.length,0)}if(!(!r.length||!s.length))return{positions:r,indices:s}}function yi(n){const e=new Y;return e.setAttribute("position",new Z(n.positions,3)),e.setIndex(n.indices),e.computeVertexNormals(),e.computeBoundingSphere(),e}function vi(n,e,t=5e-4){const r=n.range??xe(e),[s,i]=r.x,[a,o]=r.y,[u,l]=r.z,c=[];if(s>e.x[0]+t&&be(c,[[s,a,u],[s,o,u],[s,o,l],[s,a,l]]),i<e.x[1]-t&&be(c,[[i,a,u],[i,a,l],[i,o,l],[i,o,u]]),a>e.y[0]+t&&be(c,[[s,a,u],[s,a,l],[i,a,l],[i,a,u]]),o<e.y[1]-t&&be(c,[[s,o,u],[i,o,u],[i,o,l],[s,o,l]]),u>e.z[0]+t&&be(c,[[s,a,u],[i,a,u],[i,o,u],[s,o,u]]),l<e.z[1]-t&&be(c,[[s,a,l],[s,o,l],[i,o,l],[i,a,l]]),!c.length)return;const d=new Y;return d.setAttribute("position",new Z(c,3)),d.computeVertexNormals(),d.computeBoundingSphere(),d}function be(n,e){n.push(...e[0],...e[1],...e[2],...e[0],...e[2],...e[3])}function re(n,e){switch(n){case"x":return[e[1],e[2]];case"y":return[e[0],e[2]];case"z":default:return[e[0],e[1]]}}function xi(n,e){const t=e.filter(r=>r.length>=3).map(r=>{const s=r.map(a=>{const[o,u]=re(n,a);return new at(o,u)}),i=ft(s);return{loop:r,points2d:s,signedArea:i,absoluteArea:Math.abs(i),children:[],depth:0}}).sort((r,s)=>s.absoluteArea-r.absoluteArea);for(let r=0;r<t.length;r+=1){const s=t[r];let i=-1,a=Number.POSITIVE_INFINITY;for(let o=0;o<r;o+=1){const u=t[o];u.absoluteArea>=s.absoluteArea&&Ei(s.points2d[0],u.points2d)&&u.absoluteArea<a&&(a=u.absoluteArea,i=o)}i>=0&&(t[i].children.push(r),s.depth=t[i].depth+1)}return t}function Mi(n,e,t=1e-4){const r=new Set,s=[];for(const i of e){const a=Ci(n,i,t);!a||r.has(a)||(r.add(a),s.push(i))}return s}function Si(n,e,t=1e-4){const r=new Set,s=[];for(const i of e){const a=Pi(n,i,t);!a||r.has(a)||(r.add(a),s.push(i))}return s}function Ci(n,e,t=1e-4){if(e.length<3)return;const r=e.map(o=>it(n,o,t)),s=[...r].reverse(),i=Kt(r),a=Kt(s);return i<a?i:a}function Pi(n,e,t=1e-4){if(e.length<2)return;const r=e.map(i=>it(n,i,t)).join("|"),s=[...e].reverse().map(i=>it(n,i,t)).join("|");return r<s?r:s}function it(n,e,t=1e-4){const[r,s]=re(n,e);return`${Math.round(r/t)}:${Math.round(s/t)}`}function Kt(n){if(!n.length)return"";let e=0;for(let r=1;r<n.length;r+=1)Li(n,r,e)<0&&(e=r);const t=[];for(let r=0;r<n.length;r+=1)t.push(n[(e+r)%n.length]);return t.join("|")}function Li(n,e,t){for(let r=0;r<n.length;r+=1){const s=n[(e+r)%n.length],i=n[(t+r)%n.length],a=s.localeCompare(i);if(a!==0)return a}return 0}function Yt(n,e,t){const r=ft(e);return(t==="ccw"?r<0:r>0)?{loop:[...n].reverse(),points2d:[...e].reverse().map(i=>i.clone())}:{loop:[...n],points2d:e.map(i=>i.clone())}}function Ei(n,e,t=1e-7){let r=false;for(let s=0,i=e.length-1;s<e.length;i=s,s+=1){const a=e[s],o=e[i];if(Fi(n,o,a,t))return true;a.y>n.y!=o.y>n.y&&n.x<(o.x-a.x)*(n.y-a.y)/(o.y-a.y||t)+a.x&&(r=!r)}return r}function Fi(n,e,t,r=1e-7){const s=(n.y-e.y)*(t.x-e.x)-(n.x-e.x)*(t.y-e.y);if(Math.abs(s)>r)return false;const i=(n.x-e.x)*(t.x-e.x)+(n.y-e.y)*(t.y-e.y);if(i<-r)return false;const a=(t.x-e.x)**2+(t.y-e.y)**2;return i<=a+r}function ft(n){let e=0;for(let t=0;t<n.length;t+=1){const r=n[t],s=n[(t+1)%n.length];e+=r.x*s.y-s.x*r.y}return e/2}function Xt(n,e){const t=[];for(let r=0;r<e.length;r+=9){const s=new E(e[r],e[r+1],e[r+2]),i=new E(e[r+3],e[r+4],e[r+5]),a=new E(e[r+6],e[r+7],e[r+8]),o=Ti(n.axis,n.offset,s,i,a);o.length===2&&t.push(o[0].x,o[0].y,o[0].z,o[1].x,o[1].y,o[1].z)}return t}function Ai(n,e,t){var r;if(!e)return[];if((r=e.objects)!=null&&r.length&&t){const s=[];for(const i of e.objects){if(!i.object.visible)continue;const a=Ri(i.positions,i.object,t);s.push(...Xt(n,a))}return s}return e.positions.length?Xt(n,e.positions):[]}function Di(n,e=tt){const t=[];if(n.traverse(i=>{if(!(i instanceof $||i instanceof Ee))return;const a=i.geometry,o=a==null?void 0:a.getAttribute("position");if(!a||!o||o.itemSize<3)return;const u=mt(a);u&&t.push({object:i,geometry:a,position:o,triangleCount:u})}),!t.length)return[];const r=Oi(t.map(i=>i.triangleCount),e),s=[];for(let i=0;i<t.length;i+=1){const a=t[i],o=Ni(a.geometry,a.position,r[i]);o.length&&s.push({object:a.object,positions:o})}return s}function Ni(n,e,t){const r=n.index?Math.floor(n.index.count/3):Math.floor(e.count/3);if(!r)return new Float32Array;const s=vn(r,t),i=new Float32Array(s.length*9);let a=0;if(n.index){for(const o of s)for(let u=0;u<3;u+=1){const l=n.index.getX(o*3+u);i[a]=e.getX(l),i[a+1]=e.getY(l),i[a+2]=e.getZ(l),a+=3}return i}for(const o of s){const u=o*3;for(let l=0;l<3;l+=1){const c=u+l;i[a]=e.getX(c),i[a+1]=e.getY(c),i[a+2]=e.getZ(c),a+=3}}return i}function Oi(n,e){if(!n.length||e<=0)return n.map(()=>0);const t=n.reduce((a,o)=>a+o,0);if(t<=e)return[...n];const r=n.map(a=>Math.floor(a/t*e));let s=r.reduce((a,o)=>a+o,0);const i=n.map((a,o)=>({index:o,remainder:a/t*e-r[o],available:a-r[o]})).sort((a,o)=>o.remainder-a.remainder||o.available-a.available);for(const a of i){if(s>=e)break;a.available<=0||(r[a.index]=r[a.index]+1,s+=1)}return r}function ki(n,e){const t=Math.floor(n.length/9);if(!t||t<=e)return n;const r=vn(t,e),s=new Float32Array(r.length*9);let i=0;for(const a of r){const o=a*9;s.set(n.subarray(o,o+9),i),i+=9}return s}function vn(n,e){if(!n)return[];if(typeof e!="number"||e<=0||n<=e)return Array.from({length:n},(s,i)=>i);const t=[],r=n-1;for(let s=0;s<e;s+=1){const i=Math.min(r,Math.floor((s+.5)*n/e));t.push(i)}return t}function Ri(n,e,t){e.updateMatrixWorld(true),t.updateMatrixWorld(true);const r=new en().copy(t.matrixWorld).invert().multiply(e.matrixWorld),s=new Float32Array(n.length),i=new E;for(let a=0;a<n.length;a+=3)i.set(n[a],n[a+1],n[a+2]).applyMatrix4(r),s[a]=i.x,s[a+1]=i.y,s[a+2]=i.z;return s}function Ti(n,e,t,r,s){const i=[t,r,s],a=[],o=[[i[0],i[1]],[i[1],i[2]],[i[2],i[0]]];for(const[u,l]of o){const c=Ii(n,e,u,l);c&&!a.some(d=>d.distanceToSquared(c)<1e-10)&&a.push(c)}return a}function Ii(n,e,t,r){const s=Zt(t,n)-e,i=Zt(r,n)-e;if(Math.abs(s)<=1e-7&&Math.abs(i)<=1e-7||s>0&&i>0||s<0&&i<0)return;const a=i-s;if(Math.abs(a)<=1e-7)return;const o=-s/a;if(!(o<-1e-7||o>1+1e-7))return t.clone().lerp(r,_(o,0,1))}function Zt(n,e){switch(e){case"y":return n.y;case"z":return n.z;default:return n.x}}function Re(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function xn(n,e){const t=`${n.name??""}\0${n.type}\0${n.key}`,r=`${e.name??""}\0${e.type}\0${e.key}`;return t.localeCompare(r)}function Mn(n){return`${n.type||n.constructor.name||"Material"}:${n.name||"unnamed"}:${n.id}`}function qt(n){return`#${n.getHexString().toUpperCase()}`}function R(n){return Math.round(n*1e3)/1e3}function ye(n){return[R(n.x),R(n.y),R(n.z)]}function Bi(n){return n.byteLength<84?false:84+new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(80,true)*50===n.byteLength}function zi(n){return new E((n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2)}function Hi(n){return new E(n.max[0]-n.min[0],n.max[1]-n.min[1],n.max[2]-n.min[2])}function ji(n,e){return{x:[n.min[0]-e.x,n.max[0]-e.x],y:[n.min[1]-e.y,n.max[1]-e.y],z:[n.min[2]-e.z,n.max[2]-e.z]}}function Gi(n){const e=new te().setFromObject(n);return e.isEmpty()?{x:[-1,1],y:[-1,1],z:[-1,1]}:{x:[e.min.x,e.max.x],y:[e.min.y,e.max.y],z:[e.min.z,e.max.z]}}function G(n){const e=Number(n);return Number.isFinite(e)?e:0}function Jt(n){return n*Math.PI/180}function _(n,e,t){return Math.max(e,Math.min(t,n))}function Qt(n){var e,t;try{const r=new pr(n);if(!((e=r.getContext)==null?void 0:e.call(r)))throw(t=r.dispose)==null||t.call(r),new Error("WebGL unavailable");return r}catch{const r=document.createElement("canvas");return r.width=1,r.height=1,{domElement:r,setPixelRatio:()=>{},setClearColor:()=>{},setSize:(s,i)=>{const a=Math.max(1,Math.floor(s)),o=Math.max(1,Math.floor(i));r.width=a,r.height=o},render:()=>{},dispose:()=>{}}}}function Sn(n){return String(n??"").trim().replace(/^\./,"").toLowerCase()}function Ui(n){try{return JSON.parse(n)}catch{throw new Error("glTF JSON is invalid.")}}function _i(n){const e=n.trim().toLowerCase();return e.startsWith("data:")||e.startsWith("blob:")}function Cn(n){var t;if(typeof n!="string")return;const e=n.trim();if(!(!e||e.toLowerCase().startsWith("data:")||e.toLowerCase().startsWith("blob:")))try{const r=new URL(e,((t=globalThis.location)==null?void 0:t.href)??"http://localhost/");return new URL(".",r).href}catch{return}}function Ce(n){return Cn(n)??""}function Vi(n){return Ce(n)}function $i(n){return(String(n??"model").split(/[\\/]/).pop()??"model").replace(/\.[^.]+$/,"")||"model"}function pe(n,e,t){const r=Ae(n);return{source:ge(r.source,e,t),warnings:r.warnings}}function Ae(n){if(!n)return{warnings:[]};const e=t=>typeof t=="string"||t instanceof Blob||ArrayBuffer.isView(t)||t instanceof ArrayBuffer;return e(n)?{source:n,warnings:[]}:{source:e(n.source)?n.source:void 0,warnings:n.warnings??[]}}function ge(n,e,t){if(n){if(typeof n=="string")return n;if(n instanceof Blob){const r=URL.createObjectURL(n);return t==null||t.push(r),r}if(ArrayBuffer.isView(n)||n instanceof ArrayBuffer){const r=ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n);if(!t)return Wi(r,e);const s=r.buffer instanceof ArrayBuffer?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r);return ge(new Blob([s],{type:e}),e,t)}}}async function Pn(n,e){return new TextDecoder().decode(await ut(n,e))}function Ln(n){var t;const e=((t=n.split("?")[0])==null?void 0:t.toLowerCase())??n.toLowerCase();return e.endsWith(".png")?"image/png":e.endsWith(".jpg")||e.endsWith(".jpeg")?"image/jpeg":e.endsWith(".webp")?"image/webp":e.endsWith(".ktx2")?"image/ktx2":"application/octet-stream"}function q(n){var t;return(((t=n.split("?")[0])==null?void 0:t.toLowerCase())??n.toLowerCase()).endsWith(".mtl")?"text/plain":Ln(n)}function X(n){const e=n.replace(/\\/g,"/").split(/[?#]/)[0]??"",t=e.lastIndexOf("/");return t>=0?e.slice(0,t):""}function K(n,e){if(!n||/^[a-z]+:\/\//i.test(e)||/^[a-z]:[\\/]/i.test(e)||e.startsWith("/"))return e.replace(/\\/g,"/");const t=[];for(const r of`${n}/${e}`.replace(/\\/g,"/").split("/"))if(!(!r||r===".")){if(r===".."){t.pop();continue}t.push(r)}return t.join("/")}function Wi(n,e){let t="";for(const r of n)t+=String.fromCharCode(r);return`data:${e};base64,${btoa(t)}`}const Ki=new URL("../filens-step.wasm",import.meta.url).href;class le extends Error{constructor(e,t){super(t),this.code=e,this.name="StepReadError"}}function En(n={}){const e=br({wasm:n.wasm??Ki,fetch:n.fetch});return{async read(t,{tolerance:r=.1,signal:s}={}){if(s!=null&&s.aborted)throw Object.assign(new Error("STEP loading was aborted."),{name:"AbortError"});if(!Number.isFinite(r)||r<=0)throw new RangeError("STEP tolerance must be positive and finite (millimetres).");const i=typeof t=="string"?new TextEncoder().encode(t):ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t);if(i.byteLength>64<<20)throw new RangeError("STEP input exceeds 64 MiB.");const a=await e({args:["filens-step","/work/input.step","/work/mesh.bin",String(r),"--reviewed","--binary"],files:{"/work/input.step":i},readFiles:["/work/mesh.bin"],signal:s,captureStdio:true}),o=(a.stdout??"").trim().split(`
|
|
31
|
+
`);let u;try{u=JSON.parse(o[o.length-1])}catch{throw new le("invalid_step","Rust STEP could not read this file.")}if(a.exitCode||u.error)throw new le("invalid_step",u.error||"Rust STEP could not read this file.");if(!u.success)throw new le("empty_geometry","STEP contains no displayable geometry; external assemblies require their referenced part files.");if(u.missingFaces>0)throw new le("incomplete_mesh",`STEP tessellation left ${u.missingFaces} faces without geometry.`);const l=a.files["/work/mesh.bin"];if(!l)throw new le("invalid_mesh","Rust STEP did not produce a mesh.");const{positions:c,normals:d}=Yi(l),h=["STEP preview omits source colors, names and the assembly tree."];return u.shellFallback&&h.push("Shells were imported without a resolved assembly hierarchy; instance placement may be incomplete."),{positions:c,normals:d,triangleCount:c.length/9,metadata:u,warnings:h}}}}function Yi(n){if(n.byteLength<16||new TextDecoder().decode(n.subarray(0,8))!=="FLNSMESH")throw new le("invalid_mesh","Invalid STEP mesh header.");const e=new DataView(n.buffer,n.byteOffset,n.byteLength),t=e.getUint32(12,true),r=t*3;if(e.getUint32(8,true)!==1||!t||t%3||n.byteLength!==16+r*8)throw new le("invalid_mesh","Invalid STEP mesh version or triangle count.");const s=new Float32Array(r),i=new Float32Array(r);for(let a=0;a<r;a++){const o=e.getFloat32(16+a*4,true),u=e.getFloat32(16+(r+a)*4,true);if(!Number.isFinite(o)||!Number.isFinite(u))throw new le("invalid_mesh","Nonfinite STEP coordinate or normal.");s[a]=o,i[a]=u}return{positions:s,normals:i}}En();async function Xi(){const n=En();return{async ReadStepFile(e,t,r){const s=await n.read(e,{signal:r});return{success:true,root:{meshes:[0]},warnings:s.warnings,meshes:[{attributes:{position:{array:s.positions},normal:{array:s.normals}}}]}}}}const Zi=Object.freeze(Object.defineProperty({__proto__:null,createRustStepImporter:Xi},Symbol.toStringTag,{value:"Module"}));export{na as a,ta as c};
|
|
32
|
+
/*!
|
|
33
|
+
* @license
|
|
34
|
+
* The MIT License
|
|
35
|
+
*
|
|
36
|
+
* Copyright © 2010-2025 three.js authors
|
|
37
|
+
*
|
|
38
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
39
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
40
|
+
* in the Software without restriction, including without limitation the rights
|
|
41
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
42
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
43
|
+
* furnished to do so, subject to the following conditions:
|
|
44
|
+
*
|
|
45
|
+
* The above copyright notice and this permission notice shall be included in
|
|
46
|
+
* all copies or substantial portions of the Software.
|
|
47
|
+
*
|
|
48
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
49
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
50
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
51
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
52
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
53
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
54
|
+
* THE SOFTWARE.
|
|
55
|
+
*/
|