brep-io-kernel 1.0.251 → 1.0.252

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.
Files changed (39) hide show
  1. package/dist/apiExamples/BREP_Booleans.html +2 -2
  2. package/dist/apiExamples/BREP_Export.html +2 -2
  3. package/dist/apiExamples/BREP_Primitives.html +2 -2
  4. package/dist/apiExamples/BREP_Transforms.html +2 -2
  5. package/dist/apiExamples/Embeded_2D_Sketcher.html +2 -2
  6. package/dist/apiExamples/Embeded_CAD.html +2 -2
  7. package/dist/apiExamples/Embeded_CAD_Integration_Test.html +2 -2
  8. package/dist/assembly-constraint-capture.html +5 -5
  9. package/dist/assets/{AnnotationRegistry-DxnuBVib.js → AnnotationRegistry-61-QTIl6.js} +1 -1
  10. package/dist/assets/{AssemblyConstraintRegistry-DHKMQSj6.js → AssemblyConstraintRegistry-DDhkhKoR.js} +1 -1
  11. package/dist/assets/{FeatureRegistry-C9h4q68e.js → FeatureRegistry-CyK8O2Ca.js} +3 -3
  12. package/dist/assets/{PartHistory-4fqTqe8m.js → PartHistory-CYHQ9__L.js} +1 -1
  13. package/dist/assets/{annUtils-C1gESzsQ.js → annUtils-B86URBT5.js} +1 -1
  14. package/dist/assets/{apiExample_BREP_Booleans-B1xVAOyX.js → apiExample_BREP_Booleans-DdWlLKsQ.js} +1 -1
  15. package/dist/assets/{apiExample_BREP_Export-CHD3cpsa.js → apiExample_BREP_Export-AUY7EeHW.js} +1 -1
  16. package/dist/assets/{apiExample_BREP_Primitives-Cxgt1-u1.js → apiExample_BREP_Primitives-g6bMwZLj.js} +1 -1
  17. package/dist/assets/{apiExample_BREP_Transforms-CZ-klSeH.js → apiExample_BREP_Transforms-DH3-Y9FI.js} +1 -1
  18. package/dist/assets/{apiExample_Embeded_2D_Sketcher-Bpi0fqAV.js → apiExample_Embeded_2D_Sketcher-B8EeF-Gj.js} +1 -1
  19. package/dist/assets/{apiExample_Embeded_CAD-B_SPpcLZ.js → apiExample_Embeded_CAD-7roRFtt7.js} +1 -1
  20. package/dist/assets/{apiExample_Embeded_CAD_Integration_Test-DjKBLQ49.js → apiExample_Embeded_CAD_Integration_Test-Pb0iBwIv.js} +1 -1
  21. package/dist/assets/{assemblyConstraintDialogs-8hg4PlL4.js → assemblyConstraintDialogs-BJX50LIF.js} +1 -1
  22. package/dist/assets/{brep-kernel-QpBwDdca.js → brep-kernel-BaJWJnmy.js} +1 -1
  23. package/dist/assets/{browserTests-CfVrmhte.js → browserTests-DxakKnoa.js} +1 -1
  24. package/dist/assets/{dialogCapturePageFactory-C9unVBhR.js → dialogCapturePageFactory-B5p-TYIP.js} +1 -1
  25. package/dist/assets/{featureDialogs-Cx7p1XpK.js → featureDialogs-CnBa1DyN.js} +1 -1
  26. package/dist/assets/{featureDialogs-D7xm3LIj.js → featureDialogs-DbmvJ-NA.js} +1 -1
  27. package/dist/assets/{index.es-Due8Wdrm.js → index.es-kd2D9M8K.js} +1 -1
  28. package/dist/assets/{javascript-CvgRKapH.js → javascript-CAvRMK4c.js} +1 -1
  29. package/dist/assets/{main-cad-DtMN0iSg.js → main-cad-Dojzs8d6.js} +6 -6
  30. package/dist/assets/{pmiDialogs-Bxu3FGJy.js → pmiDialogs-DQBW7aoF.js} +1 -1
  31. package/dist/assets/{test-Ccoy9ITq.js → test-ByMinHh_.js} +3 -3
  32. package/dist/cad.html +7 -7
  33. package/dist/feature-dialog-capture.html +4 -4
  34. package/dist/pmi-dialog-capture.html +5 -5
  35. package/dist/test.html +1 -1
  36. package/dist/viewer.html +7 -7
  37. package/dist-kernel/brep-kernel.js +1 -1
  38. package/package.json +1 -1
  39. package/src/BREP/SolidMethods/manifoldOps.js +5 -0
@@ -4808,7 +4808,7 @@ void main() {
4808
4808
  overflow-wrap: anywhere;
4809
4809
  }
4810
4810
  .cmw-select-wrap option { white-space: normal; }
4811
- `,document.head.appendChild(A)}},c(aW,"ohe2"),aW);r(QEt,"CADmaterialWidget");let h8e=QEt;function mf(){const i=document.createElement("div");return i.className="cmw-row",i}c(mf,"hN");r(mf,"makeRightSpan");var QW;const EEt=(QW=class extends hO{constructor(A){super(A,Do.EDGE.BASE),this.faces=[],this.name=null,this.type="EDGE",this.renderOrder=2,this.closedLoop=!1,Ps.attach(this)}length(){const A=new W,e=new W;let t=0;const g=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null,o=r((I,n,B,C,a,Q)=>{A.set(I,n,B).applyMatrix4(this.matrixWorld),e.set(C,a,Q).applyMatrix4(this.matrixWorld),t+=A.distanceTo(e)},"addSeg");if(g&&g.length>=2){for(let I=0;I<g.length-1;I++){const n=g[I],B=g[I+1];o(n[0],n[1],n[2],B[0],B[1],B[2])}return t}const s=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(s&&s.itemSize===3&&s.count>=2){for(let I=0;I<s.count-1;I++)o(s.getX(I),s.getY(I),s.getZ(I),s.getX(I+1),s.getY(I+1),s.getZ(I+1));return t}return 0}points(A=!0){const e=new W,t=[],g=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null;if(g&&g.length){for(let s=0;s<g.length;s++){const I=g[s];e.set(I[0],I[1],I[2]),A&&e.applyMatrix4(this.matrixWorld),t.push({x:e.x,y:e.y,z:e.z})}return t}const o=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(o&&o.itemSize===3&&o.count>=1)for(let s=0;s<o.count;s++)e.set(o.getX(s),o.getY(s),o.getZ(s)),A&&e.applyMatrix4(this.matrixWorld),t.push({x:e.x,y:e.y,z:e.z});return t}collapseToPoint(){const A=this.parentSolid||this.parent||null,e=Array.isArray(A?._vertProperties)?A._vertProperties:null;if(!A||!e||e.length<3)return this;if(this?.userData?.auxEdge)return this;const t=cEt(this,A);if(!t.length)return this;let g=0,o=0,s=0,I=0;for(const E of t){const l=E*3|0;l<0||l+2>=e.length||(g+=e[l+0],o+=e[l+1],s+=e[l+2],I++)}if(!I)return this;const n=1/I,B=g*n,C=o*n,a=s*n;for(const E of t){const l=E*3|0;l<0||l+2>=e.length||(e[l+0]=B,e[l+1]=C,e[l+2]=a)}const Q=e.length/3|0;A._vertKeyToIndex=new Map;for(let E=0;E<Q;E++){const l=E*3;A._vertKeyToIndex.set(`${e[l+0]},${e[l+1]},${e[l+2]}`,E)}A._dirty=!0,A._faceIndex=null;try{A._manifold&&typeof A._manifold.delete=="function"&&A._manifold.delete()}catch{}A._manifold=null;try{typeof A._manifoldize=="function"&&A._manifoldize()}catch(E){console.warn(`[Edge.collapseToPoint] Manifold rebuild failed for edge "${this.name||"UNKNOWN"}":`,E?.message||E)}try{typeof A.visualize=="function"&&A.visualize()}catch(E){console.warn(`[Edge.collapseToPoint] Solid visualize failed for edge "${this.name||"UNKNOWN"}":`,E?.message||E)}return this}setMetadata(A){return this.parentSolid&&typeof this.parentSolid.setEdgeMetadata=="function"&&this.parentSolid.setEdgeMetadata(this.name,A),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getEdgeMetadata=="function"?this.parentSolid.getEdgeMetadata(this.name):null}},c(QW,"nhe2"),QW);r(EEt,"Edge");let gYA=EEt;function cEt(i,A){const e=Array.isArray(A?._vertProperties)?A._vertProperties:null;if(!e||e.length<3)return[];const t=(e.length/3|0)-1;let g=[];try{g=typeof A.getBoundaryEdgePolylines=="function"?A.getBoundaryEdgePolylines()||[]:[]}catch{g=[]}const o=lEt(i,g);if(o&&Array.isArray(o.indices)&&o.indices.length){const s=[],I=new Set;for(const n of o.indices){const B=Number(n);!Number.isInteger(B)||B<0||B>t||I.has(B)||(I.add(B),s.push(B))}if(s.length)return s}return wEt(i?.userData?.polylineLocal,e)}c(cEt,"tKt");r(cEt,"resolveEdgeVertexIndices");function lEt(i,A){if(!Array.isArray(A)||A.length===0)return null;const e=typeof i?.name=="string"&&i.name?i.name:null;if(e){const B=A.find(C=>C&&C.name===e);if(B)return B}const t=i?.userData?.faceA,g=i?.userData?.faceB;let o=A;if(t&&g&&(o=A.filter(B=>{if(!B)return!1;const C=B.faceA,a=B.faceB;return C===t&&a===g||C===g&&a===t}),o.length===1))return o[0];const s=Array.isArray(i?.userData?.polylineLocal)?i.userData.polylineLocal:null;if(!s||s.length<2)return o[0]||null;let I=null,n=1/0;for(const B of o){const C=hEt(s,B?.positions);C<n&&(n=C,I=B)}return I}c(lEt,"iKt");r(lEt,"findMatchingBoundaryPolyline$1");function hEt(i,A){if(!Array.isArray(i)||i.length<2||!Array.isArray(A)||A.length<2)return 1/0;const e=i[0],t=i[i.length-1],g=A[0],o=A[A.length-1];if(!Gb(e)||!Gb(t)||!Gb(g)||!Gb(o))return 1/0;const s=HNA(e,g)+HNA(t,o),I=HNA(e,o)+HNA(t,g);return Math.min(s,I)}c(hEt,"gKt");r(hEt,"polylineEndpointScore$2");function wEt(i,A){if(!Array.isArray(i)||i.length===0)return[];const e=A.length/3|0,t=new Map;for(let s=0;s<e;s++){const I=s*3,n=`${A[I+0]},${A[I+1]},${A[I+2]}`;t.has(n)||t.set(n,s)}const g=[],o=new Set;for(const s of i){if(!Gb(s))continue;const I=`${s[0]},${s[1]},${s[2]}`;let n=t.get(I);n===void 0&&(n=dEt(A,s,1e-9)),!(!Number.isInteger(n)||n<0||o.has(n))&&(o.add(n),g.push(n))}return g}c(wEt,"sKt");r(wEt,"resolveIndicesFromPolylinePoints$1");function dEt(i,A,e=1e-9){if(!Array.isArray(i)||!Gb(A)||!Number.isFinite(e)||e<=0)return-1;const t=e*e,g=i.length/3|0;let o=-1,s=t;for(let I=0;I<g;I++){const n=I*3,B=i[n+0]-A[0],C=i[n+1]-A[1],a=i[n+2]-A[2],Q=B*B+C*C+a*a;Q<=s&&(s=Q,o=I)}return o}c(dEt,"oKt");r(dEt,"findNearestVertexIndex$1");function HNA(i,A){const e=i[0]-A[0],t=i[1]-A[1],g=i[2]-A[2];return e*e+t*t+g*g}c(HNA,"ugA");r(HNA,"pointDistanceSq$4");function Gb(i){return Array.isArray(i)&&i.length===3&&Number.isFinite(i[0])&&Number.isFinite(i[1])&&Number.isFinite(i[2])}c(Gb,"b1");r(Gb,"isPoint3$3");var EW;const DEt=(EW=class extends Xg{constructor(A=[0,0,0],e={}){super(),this.type="VERTEX",this.name=e.name||`VERTEX(${A[0]},${A[1]},${A[2]})`,this.position.set(A[0]||0,A[1]||0,A[2]||0);const t=new Kt;t.setAttribute("position",new bt([0,0,0],3));const g=Do?.VERTEX?.BASE||new iM({color:"#ffb703",size:6,sizeAttenuation:!1});this._point=new NUA(t,g),this.add(this._point),Ps.attach(this)}},c(EW,"Ihe2"),EW);r(DEt,"Vertex");let jRe=DEt;function IzA(i,A,e,t,g,o,s,I,n){const B=t-i,C=g-A,a=o-e,Q=s-i,E=I-A,l=n-e,h=C*l-a*E,w=a*Q-B*l,d=B*E-C*Q;return .5*Math.hypot(h,w,d)}c(IzA,"KKA");r(IzA,"computeTriangleArea");const dae=1e-9,Lo=1e-12;function nzA(i,A="FACE"){const e=(i==null?"":String(i)).trim();return e&&e.replace(/[:[\]]+/g,"_").replace(/\s+/g,"_").replace(/[^A-Za-z0-9_.-]/g,"_")||A}c(nzA,"JKA");r(nzA,"sanitizeToken$2");function hr(i,A){const e=i<A?i:A,t=i<A?A:i;return`${e}|${t}`}c(hr,"eC");r(hr,"edgeKey$2");function hw(i){i&&typeof i=="object"&&(i._cppSolidCoreSyncStamp=null)}c(hw,"fw");r(hw,"invalidateCppSolidCoreCache");function Rb(i,A){const e=A>0?1/A:1e6;return[Math.round(i.x*e),Math.round(i.y*e),Math.round(i.z*e)].join(",")}c(Rb,"x1");r(Rb,"pointKey$2");function QU(i,A,e){return new W().subVectors(A,i).cross(new W().subVectors(e,i))}c(QU,"sK");r(QU,"triangleNormal");function S5A(i,A,e){return QU(i,A,e).length()*.5}c(S5A,"jne");r(S5A,"triangleArea$1");function G5A(i){const A=i?.userData?.faceName??i?.faceName??i?.name??null;return A==null?null:String(A).trim()||null}c(G5A,"Vne");r(G5A,"getFaceLabel");function uEt(i){const A=Array.isArray(i)?i:i==null?[]:[i],e=[],t=new Set;for(const g of A){const o=typeof g=="string"?g:g?.userData?.faceName??g?.faceName??g?.name??null,s=String(o||"").trim();!s||t.has(s)||(t.add(s),e.push(s))}return e}c(uEt,"nKt");r(uEt,"getFaceLabelList");function MEt(i,A){const e=uEt(i.adjacentNormalFaceNames??i.smoothAdjacentNormalFaceNames??i.selectedFaceNames),t=String(A||"").trim(),g=e.filter(o=>o&&o!==t);return g.length?new Set(g):null}c(MEt,"IKt");r(MEt,"getAdjacentNormalFaceFilter");function yEt(i){const A=i?.parentSolid||(String(i?.parent?.type||"").toUpperCase()==="SOLID"?i.parent:null);return String(A?.uuid||A?.id||A?.name||"NO_OWNER")}c(yEt,"rKt");r(yEt,"getFaceOwnerKey");function oYA(i,A){return i<A?`${i}|${A}`:`${A}|${i}`}c(oYA,"qnA");r(oYA,"unorderedPointPairKey");function pEt(i,A){return!i||!A||i.sourceFaceName!=null&&(A.sourceFaceName=i.sourceFaceName),A}c(pEt,"BKt");r(pEt,"copyTriangleMetadata");function TUA(i,A={}){const e=Array.isArray(i)?i.filter(f=>f?.geometry):[];if(e.length<=1)return e.length?[e]:[];const t=new W;let g=1/0,o=1/0,s=1/0,I=-1/0,n=-1/0,B=-1/0;for(const f of e){try{f.updateMatrixWorld?.(!0)}catch{}const F=f.geometry?.getAttribute?.("position");if(!(!F||F.itemSize!==3))for(let m=0;m<F.count;m++)t.set(F.getX(m),F.getY(m),F.getZ(m)).applyMatrix4(f.matrixWorld),t.x<g&&(g=t.x),t.y<o&&(o=t.y),t.z<s&&(s=t.z),t.x>I&&(I=t.x),t.y>n&&(n=t.y),t.z>B&&(B=t.z)}const C=Number.isFinite(g)?Math.max(1,Math.hypot(I-g,n-o,B-s)):1,a=Math.max(Number(A.weldTolerance)||0,Math.max(1e-6,C*1e-7)),Q=Number.isFinite(Number(A.minSharedNormalDot))?Math.max(-1,Math.min(1,Number(A.minSharedNormalDot))):-1,E=Number.isFinite(Number(A.minSharedEdgeNormalDot))?Math.max(-1,Math.min(1,Number(A.minSharedEdgeNormalDot))):null,l=Number.isFinite(Number(A.minPlanarRatio))?Math.max(0,Math.min(1,Number(A.minPlanarRatio))):0,h=r((f,F)=>{if(!(l>0))return 1;const m=f?.geometry?.getAttribute?.("position"),G=f?.geometry?.getIndex?.()||null;if(!m||m.itemSize!==3||m.count<3||!F||F.lengthSq()<=Lo)return 0;const N=new W,S=new W,Y=new W;let R=0,k=0;const b=G?G.count/3|0:m.count/3|0;for(let L=0;L<b;L++){const x=G?G.getX(L*3+0)>>>0:L*3+0,J=G?G.getX(L*3+1)>>>0:L*3+1,$=G?G.getX(L*3+2)>>>0:L*3+2;N.set(m.getX(x),m.getY(x),m.getZ(x)).applyMatrix4(f.matrixWorld),S.set(m.getX(J),m.getY(J),m.getZ(J)).applyMatrix4(f.matrixWorld),Y.set(m.getX($),m.getY($),m.getZ($)).applyMatrix4(f.matrixWorld);const T=QU(N,S,Y),H=T.length();H>Lo&&(R+=Math.abs(T.multiplyScalar(1/H).dot(F))*H,k+=H)}return k>Lo?R/k:0},"computeFacePlanarRatio"),w=e.map(f=>{try{const F=typeof f?.getAverageNormal=="function"?f.getAverageNormal():null;if(F&&F.lengthSq?.()>Lo)return F.clone().normalize()}catch{}return null}),d=e.map((f,F)=>h(f,w[F])),D=new Map;for(let f=0;f<e.length;f++){const F=e[f],m=F.geometry?.getAttribute?.("position"),G=F.geometry?.getIndex?.()||null;if(!m||m.itemSize!==3||m.count<3)continue;const N=[];for(let L=0;L<m.count;L++)N.push(new W(m.getX(L),m.getY(L),m.getZ(L)).applyMatrix4(F.matrixWorld));const S=new Array(N.length);for(let L=0;L<N.length;L++){const x=Rb(N[L],a);S[L]=x}const Y=new Map,R=new Map,k=G?G.count/3|0:m.count/3|0;for(let L=0;L<k;L++){const x=G?G.getX(L*3+0)>>>0:L*3+0,J=G?G.getX(L*3+1)>>>0:L*3+1,$=G?G.getX(L*3+2)>>>0:L*3+2,T=QU(N[x],N[J],N[$]);for(const[H,X]of[[x,J],[J,$],[$,x]]){const oA=S[H],_=S[X];if(!oA||!_||oA===_)continue;const V=oYA(oA,_);Y.set(V,(Y.get(V)||0)+1);let O=R.get(V);O||(O=new W,R.set(V,O)),O.add(T)}}const b=yEt(F);for(const[L,x]of Y.entries()){if(x!==1)continue;const J=`${b}::${L}`;let $=D.get(J);$||($=[],D.set(J,$));const T=R.get(L)||null;$.push({faceIndex:f,normal:T&&T.lengthSq()>Lo?T.clone().normalize():null})}}const u=new Array(e.length).fill(null).map((f,F)=>F),M=r(f=>{let F=f;for(;u[F]!==F;)F=u[F];for(;u[f]!==f;){const m=u[f];u[f]=F,f=m}return F},"find"),y=r((f,F)=>{const m=typeof f=="number"?f:f?.faceIndex>>>0,G=typeof F=="number"?F:F?.faceIndex>>>0;if(m===G||m>=e.length||G>=e.length)return;if(E!=null){const Y=f?.normal||w[m],R=F?.normal||w[G];if(!Y||!R||Math.abs(Y.dot(R))<E)return}else{if(l>0&&(d[m]<l||d[G]<l))return;if(Q>-1){const Y=w[m],R=w[G];if(!Y||!R||Math.abs(Y.dot(R))<Q)return}}if(Q>-1&&E!=null){const Y=w[m],R=w[G];if(!Y||!R||Math.abs(Y.dot(R))<Q)return}const N=M(m),S=M(G);N!==S&&(u[S]=N)},"union");for(const f of D.values())if(!(!Array.isArray(f)||f.length<2))for(let F=1;F<f.length;F++)y(f[0],f[F]);const p=new Map;for(let f=0;f<e.length;f++){const F=M(f);let m=p.get(F);m||(m=[],p.set(F,m)),m.push(e[f])}return Array.from(p.values())}c(TUA,"oaA");r(TUA,"groupConnectedFacesBySharedEdges");function fEt(i,A,e){const t=new W().subVectors(e,A),g=t.lengthSq();if(!(g>Lo))return i.distanceToSquared(A);const o=Math.max(0,Math.min(1,new W().subVectors(i,A).dot(t)/g)),s=A.clone().add(t.multiplyScalar(o));return i.distanceToSquared(s)}c(fEt,"CKt");r(fEt,"pointToSegmentDistanceSq");function yTA(i,A){if(!Array.isArray(A)||A.length<2)return 1/0;let e=1/0;for(let t=0;t+1<A.length;t++){const g=fEt(i,A[t],A[t+1]);g<e&&(e=g)}return e}c(yTA,"NNA");r(yTA,"pointToPolylineDistanceSq");function FEt(i,A,e,t){const g=new W().subVectors(e,A),o=new W().subVectors(t,A),s=new W().subVectors(i,A),I=g.dot(s),n=o.dot(s);if(I<=0&&n<=0)return i.distanceToSquared(A);const B=new W().subVectors(i,e),C=g.dot(B),a=o.dot(B);if(C>=0&&a<=C)return i.distanceToSquared(e);const Q=I*a-C*n;if(Q<=0&&I>=0&&C<=0){const y=I/(I-C);return i.distanceToSquared(A.clone().add(g.multiplyScalar(y)))}const E=new W().subVectors(i,t),l=g.dot(E),h=o.dot(E);if(h>=0&&l<=h)return i.distanceToSquared(t);const w=l*n-I*h;if(w<=0&&n>=0&&h<=0){const y=n/(n-h);return i.distanceToSquared(A.clone().add(o.multiplyScalar(y)))}const d=C*h-l*a;if(d<=0&&a-C>=0&&l-h>=0){const y=new W().subVectors(t,e),p=(a-C)/(a-C+(l-h));return i.distanceToSquared(e.clone().add(y.multiplyScalar(p)))}const D=1/(d+w+Q),u=w*D,M=Q*D;return i.distanceToSquared(A.clone().add(g.multiplyScalar(u)).add(o.multiplyScalar(M)))}c(FEt,"aKt");r(FEt,"pointToTriangleDistanceSq");function mEt(i){const A=Array.isArray(i?.edges)?i.edges:[];if(!A.length)return[];const e=i?.parentSolid||(String(i?.parent?.type||"").toUpperCase()==="SOLID"?i.parent:null);try{e?.updateMatrixWorld?.(!0)}catch{}const t=e?.matrixWorld||new Bt,g=[];for(let o=0;o<A.length;o++){const s=A[o],I=(Array.isArray(s?.userData?.polylineLocal)?s.userData.polylineLocal:[]).map(n=>Array.isArray(n)?new W(Number(n[0])||0,Number(n[1])||0,Number(n[2])||0).applyMatrix4(t):n&&Number.isFinite(Number(n.x))&&Number.isFinite(Number(n.y))&&Number.isFinite(Number(n.z))?new W(Number(n.x),Number(n.y),Number(n.z)).applyMatrix4(t):null).filter(Boolean);I.length<2||g.push({name:String(s?.name||s?.userData?.edgeName||`EDGE_${o}`).trim()||`EDGE_${o}`,key:String(s?.uuid||s?.name||`EDGE_${o}`),polyline:I})}return g}c(mEt,"QKt");r(mEt,"getSourceEdgePolylines");function NEt(i,A,e,t,g){const o=mEt(i);if(!o.length||!Array.isArray(A)||!Array.isArray(e))return;const s=Math.max(Number(g)*32,Number(t)*1e-5,1e-5),I=s*s;for(const n of A)for(const B of n?.edges||[]){const C=e[B.start],a=e[B.end];if(!C||!a)continue;const Q=C.clone().add(a).multiplyScalar(.5);let E=null,l=1/0;for(const h of o){const w=Math.max(yTA(C,h.polyline),yTA(Q,h.polyline),yTA(a,h.polyline));w<l&&(l=w,E=h)}E&&l<=I&&(B.sourceEdgeName=E.name,B.sourceEdgeKey=E.key)}}c(NEt,"EKt");r(NEt,"assignSourceEdgesToBoundaryLoops");function SEt(i,A,e={}){if(e.disableAdjacentBoundaryNormals===!0)return{candidateEdges:0,acceptedEdges:0,contributionCount:0,contributedVertexCount:0,dotThreshold:null,weightScale:0,faceFilterCount:0,faceFilterNames:[]};const t=i?.parentSolid||(String(i?.parent?.type||"").toUpperCase()==="SOLID"?i.parent:null),g=G5A(i),o=MEt(e,g),s=Array.isArray(t?._triVerts)?t._triVerts:[],I=Array.isArray(t?._triIDs)?t._triIDs:[],n=Array.isArray(t?._vertProperties)?t._vertProperties:[],B=s.length/3|0,C=Math.max(-1,Math.min(1,Number.isFinite(Number(e.adjacentNormalDotThreshold))?Number(e.adjacentNormalDotThreshold):Number.isFinite(Number(e.smoothAdjacentNormalDotThreshold))?Number(e.smoothAdjacentNormalDotThreshold):.85)),a=Math.max(0,Number.isFinite(Number(e.adjacentNormalWeightScale))?Number(e.adjacentNormalWeightScale):1),Q=r((T={})=>({candidateEdges:Number(T.candidateEdges||0),acceptedEdges:Number(T.acceptedEdges||0),contributionCount:Number(T.contributionCount||0),contributedVertexCount:Number(T.contributedVertexCount||0),dotThreshold:C,weightScale:a,faceFilterCount:o?.size||0,faceFilterNames:o?Array.from(o):[]}),"makeStats");if(!t||!g)return Q();const E=Array.isArray(A?.boundaryDirectedEdges)?A.boundaryDirectedEdges:[],l=Array.isArray(A?.vertices)?A.vertices:[],h=Array.isArray(A?.vertexNormals)?A.vertexNormals:[];if(!E.length||!l.length||!h.length)return Q();const w=Math.max(Number(A?.weldTolerance)||0,1e-8);if(a<=0)return Q();const d=new Map,D=new Map;for(const T of E){const H=T?.start>>>0,X=T?.end>>>0,oA=l[H],_=l[X];if(!oA||!_)continue;const V=Rb(oA,w),O=Rb(_,w);d.set(V,H),d.set(O,X),D.set(oYA(V,O),!0)}if(!D.size)return Q();const u=t?._idToFaceName instanceof Map?t._idToFaceName:new Map,M=new Bt;try{t.updateMatrixWorld?.(!0),M.copy(t.matrixWorld||new Bt)}catch{M.identity()}const y=new Map,p=new Map,f=new Set,F=e.equalAdjacentBoundaryNormals===!0||String(e.sharedBoundaryNormalMode||"").toLowerCase()==="equal"?new Map:null;let m=0,G=0,N=0;const S=r(T=>[Math.round(T.x*1e6),Math.round(T.y*1e6),Math.round(T.z*1e6)].join(","),"normalKey"),Y=r(T=>{if(!F)return null;let H=F.get(T);if(H)return H;const X=h[T]?.clone?.()||null;return!X||X.lengthSq()<=Lo?null:(X.normalize(),H={sum:X.clone(),keys:new Set([S(X)])},F.set(T,H),H)},"getEqualBoundaryNormalBucket"),R=r((T={})=>{if(F?.size)for(const[H,X]of F.entries())!X?.sum||X.sum.lengthSq()<=Lo||h[H].copy(X.sum);return Q(T)},"finalizeStats"),k=r((T,H,X)=>{const oA=d.get(T);if(oA==null)return!1;const _=h[oA];if(!_||_.lengthSq()<=Lo)return!1;if(F){const AA=Y(oA);if(!AA)return!1;const BA=S(H);return AA.keys.has(BA)?!1:(AA.keys.add(BA),AA.sum.add(H),f.add(oA),N+=1,!0)}const V=Math.max(_.length(),dae),O=Math.min(X,V)*a;return O>dae?(_.add(H.clone().multiplyScalar(O)),f.add(oA),N+=1,!0):!1},"addContributionForPointKey"),b=r(T=>{if(!Array.isArray(T)||T.length!==3)return;const H=T.map(AA=>Rb(AA,w));let X=!1;for(const[AA,BA]of[[0,1],[1,2],[2,0]])if(D.has(oYA(H[AA],H[BA]))){X=!0,m+=1;break}if(!X)return;const oA=QU(T[0],T[1],T[2]),_=oA.length();if(!(_>Lo))return;const V=oA.multiplyScalar(1/_);let O=!1;for(let AA=0;AA<3;AA++){const BA=d.get(H[AA]);if(BA==null)continue;const rA=h[BA]?.clone?.()||null;if(!rA||rA.lengthSq()<=Lo)continue;rA.normalize();const tA=V.dot(rA);let sA=null;tA>=C?sA=V:-tA>=C&&(sA=V.clone().multiplyScalar(-1)),sA&&k(H[AA],sA,_)&&(O=!0)}O&&(G+=1)},"processAdjacentTriangle");try{const T=typeof t.getFaces=="function"?t.getFaces(!1)||[]:[];if(Array.isArray(T)&&T.length){for(const H of T){const X=String(H?.faceName||"").trim();if(!(!X||X===g)&&!(o&&!o.has(X)))for(const oA of H?.triangles||[]){const _=Array.isArray(oA?.p1)?oA.p1:null,V=Array.isArray(oA?.p2)?oA.p2:null,O=Array.isArray(oA?.p3)?oA.p3:null;!_||!V||!O||b([new W(_[0]||0,_[1]||0,_[2]||0).applyMatrix4(M),new W(V[0]||0,V[1]||0,V[2]||0).applyMatrix4(M),new W(O[0]||0,O[1]||0,O[2]||0).applyMatrix4(M)])}}if(m>0||B===0||I.length<B||n.length<9)return R({candidateEdges:m,acceptedEdges:G,contributionCount:N,contributedVertexCount:f.size})}}catch{}if(B===0||I.length<B||n.length<9)return R({candidateEdges:m,acceptedEdges:G,contributionCount:N,contributedVertexCount:f.size});const L=r(T=>{const H=T>>>0;let X=y.get(H);if(X)return X;const oA=H*3;return X=new W(Number(n[oA+0])||0,Number(n[oA+1])||0,Number(n[oA+2])||0).applyMatrix4(M),y.set(H,X),X},"getParentPoint"),x=r(T=>{const H=T>>>0;let X=p.get(H);return X||(X=Rb(L(H),w),p.set(H,X),X)},"getParentPointKey"),J=r((T,H,X)=>k(x(T),H,X),"addContribution"),$=new W;for(let T=0;T<B;T++){const H=String(u.get(I[T])||"").trim();if(H===g||o&&!o.has(H))continue;const X=s[T*3+0]>>>0,oA=s[T*3+1]>>>0,_=s[T*3+2]>>>0,V=[[X,oA],[oA,_],[_,X]];let O=!1;for(const[K,v]of V){const iA=x(K),QA=x(v);if(D.has(oYA(iA,QA))){O=!0,m+=1;break}}if(!O)continue;const AA=L(X),BA=L(oA),rA=L(_);$.copy(QU(AA,BA,rA));const tA=$.length();if(!(tA>Lo))continue;const sA=$.multiplyScalar(1/tA);let eA=!1;for(const K of[X,oA,_]){const v=d.get(x(K));if(v==null)continue;const iA=h[v]?.clone?.()||null;if(!iA||iA.lengthSq()<=Lo)continue;iA.normalize();const QA=sA.dot(iA);let gA=null;QA>=C?gA=sA:-QA>=C&&(gA=sA.clone().multiplyScalar(-1)),gA&&J(K,gA,tA)&&(eA=!0)}eA&&(G+=1)}return R({candidateEdges:m,acceptedEdges:G,contributionCount:N,contributedVertexCount:f.size})}c(SEt,"cKt");r(SEt,"addSmoothAdjacentBoundaryNormals");function wI(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=A.length/3|0;if(!e)return{boundaryEdgeCount:0,nonManifoldEdgeCount:0,triangleCount:0};const t=new Map;for(let s=0;s<e;s++){const I=A[s*3]>>>0,n=A[s*3+1]>>>0,B=A[s*3+2]>>>0;for(const[C,a]of[[I,n],[n,B],[B,I]]){const Q=hr(C,a);t.set(Q,(t.get(Q)||0)+1)}}let g=0,o=0;for(const s of t.values())s===1?g+=1:s!==2&&(o+=1);return{boundaryEdgeCount:g,nonManifoldEdgeCount:o,triangleCount:e}}c(wI,"Un");r(wI,"analyzeMeshTopology$5");function jG(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=A.length/3|0;if(!e)return{sameDirectionEdgeCount:0,oppositeDirectionEdgeCount:0,ambiguousEdgeCount:0};const t=new Map,g=r((n,B)=>{const C=hr(n,B);let a=t.get(C);a||(a=[],t.set(C,a)),a.push([n,B])},"addUse");for(let n=0;n<e;n++){const B=A[n*3]>>>0,C=A[n*3+1]>>>0,a=A[n*3+2]>>>0;g(B,C),g(C,a),g(a,B)}let o=0,s=0,I=0;for(const n of t.values()){if(n.length!==2){I+=1;continue}n[0][0]===n[1][0]&&n[0][1]===n[1][1]?o+=1:s+=1}return{sameDirectionEdgeCount:o,oppositeDirectionEdgeCount:s,ambiguousEdgeCount:I}}c(jG,"Eb");r(jG,"analyzeTriangleOrientation");function QG(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=A.length/3|0;if(!t||e.length<9)return 0;const g=new Map,o=r((a,Q,E)=>{const l=hr(a,Q);let h=g.get(l);h||(h=[],g.set(l,h)),h.push({triIndex:E,a,b:Q})},"addUse");for(let a=0;a<t;a++){const Q=A[a*3+0]>>>0,E=A[a*3+1]>>>0,l=A[a*3+2]>>>0;o(Q,E,a),o(E,l,a),o(l,Q,a)}const s=Array.from({length:t},()=>[]);for(const a of g.values()){if(a.length!==2)continue;const Q=a[0],E=a[1],l=Q.a===E.a&&Q.b===E.b;s[Q.triIndex].push({triIndex:E.triIndex,sameDirection:l}),s[E.triIndex].push({triIndex:Q.triIndex,sameDirection:l})}const I=new Int8Array(t);I.fill(-1);for(let a=0;a<t;a++){if(I[a]!==-1)continue;I[a]=0;const Q=[a];for(;Q.length;){const E=Q.pop(),l=I[E];for(const h of s[E]){const w=l^(h.sameDirection?1:0);I[h.triIndex]===-1&&(I[h.triIndex]=w,Q.push(h.triIndex))}}}let n=0;for(let a=0;a<t;a++){if(I[a]!==1)continue;const Q=a*3,E=A[Q+1];A[Q+1]=A[Q+2],A[Q+2]=E,n+=1}const B=r(a=>{const Q=a*3,E=A[Q+1];A[Q+1]=A[Q+2],A[Q+2]=E},"flipTriangle"),C=r(()=>{const a=new Map,Q=r((w,d,D)=>{const u=hr(w,d);let M=a.get(u);M||(M=[],a.set(u,M)),M.push({triIndex:D,a:w,b:d})},"addLocalUse");for(let w=0;w<t;w++){const d=A[w*3+0]>>>0,D=A[w*3+1]>>>0,u=A[w*3+2]>>>0;Q(d,D,w),Q(D,u,w),Q(u,d,w)}const E=new Uint8Array(t),l=new Uint8Array(t);let h=0;for(const w of a.values())w.length===2&&(w[0].a===w[1].a&&w[0].b===w[1].b?(h+=1,E[w[0].triIndex]+=1,E[w[1].triIndex]+=1):(l[w[0].triIndex]+=1,l[w[1].triIndex]+=1));return{sameCount:h,sameByTri:E,oppositeByTri:l}},"orientationStats");for(let a=0;a<16;a++){const Q=C();if(Q.sameCount===0)break;let E=0;for(let l=0;l<t;l++)Q.sameByTri[l]<=Q.oppositeByTri[l]||(B(l),n+=1,E+=1);if(!E)break}for(let a=0;a<64;a++){let Q=C();if(Q.sameCount===0)break;const E=[];for(let h=0;h<t;h++)Q.sameByTri[h]&&E.push({triIndex:h,score:Q.sameByTri[h]*2-Q.oppositeByTri[h]});E.sort((h,w)=>w.score-h.score||h.triIndex-w.triIndex);let l=!1;for(const h of E){if(Q=C(),Q.sameCount===0||!Q.sameByTri[h.triIndex])break;const w=Q.sameCount;B(h.triIndex),C().sameCount<w?(n+=1,l=!0):B(h.triIndex)}if(!l)break}return n>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)),n}c(QG,"Sk");r(QG,"orientSolidTrianglesByAdjacency");function EG(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=A.length/3|0;if(!t||e.length<9)return 0;const g=new Map,o=r((C,a,Q)=>{const E=hr(C,a);let l=g.get(E);l||(l=[],g.set(E,l)),l.push(Q)},"addUse");for(let C=0;C<t;C++){const a=A[C*3+0]>>>0,Q=A[C*3+1]>>>0,E=A[C*3+2]>>>0;o(a,Q,C),o(Q,E,C),o(E,a,C)}const s=Array.from({length:t},()=>[]);for(const C of g.values())C.length===2&&(s[C[0]].push(C[1]),s[C[1]].push(C[0]));const I=r(C=>{const a=A[C*3+0]>>>0,Q=A[C*3+1]>>>0,E=A[C*3+2]>>>0,l=e[a*3+0],h=e[a*3+1],w=e[a*3+2],d=e[Q*3+0],D=e[Q*3+1],u=e[Q*3+2],M=e[E*3+0],y=e[E*3+1],p=e[E*3+2];return(l*(D*p-u*y)-h*(d*p-u*M)+w*(d*y-D*M))/6},"signedVolume"),n=new Uint8Array(t);let B=0;for(let C=0;C<t;C++){if(n[C])continue;const a=[],Q=[C];n[C]=1;let E=0;for(;Q.length;){const l=Q.pop();a.push(l),E+=I(l);for(const h of s[l])n[h]||(n[h]=1,Q.push(h))}if(E<-Lo)for(const l of a){const h=l*3,w=A[h+1];A[h+1]=A[h+2],A[h+2]=w,B+=1}}return B>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)),B}c(EG,"Gk");r(EG,"orientSolidComponentsBySignedVolume");function wl(i,A){const e=Math.max(Number(A)||0,0),t=Array.isArray(i?._vertProperties)?i._vertProperties:[],g=Array.isArray(i?._triVerts)?i._triVerts:[],o=Array.isArray(i?._triIDs)?i._triIDs:[],s=t.length/3|0,I=g.length/3|0;if(!(e>0)||!s||!I||o.length<I)return{weldedVertexCount:0,removedTriangleCount:0};const n=1/e,B=r(D=>[Math.round((Number(t[D*3+0])||0)*n),Math.round((Number(t[D*3+1])||0)*n),Math.round((Number(t[D*3+2])||0)*n)].join(","),"keyForIndex"),C=new Int32Array(s);C.fill(-1);const a=new Map,Q=[];let E=0;for(let D=0;D<s;D++){const u=B(D);let M=a.get(u);M==null?(M=Q.length/3|0,a.set(u,M),Q.push(t[D*3+0],t[D*3+1],t[D*3+2])):E+=1,C[D]=M}if(!E)return{weldedVertexCount:0,removedTriangleCount:0};const l=r((D,u,M)=>{const y=Q[D*3+0],p=Q[D*3+1],f=Q[D*3+2],F=Q[u*3+0],m=Q[u*3+1],G=Q[u*3+2],N=Q[M*3+0],S=Q[M*3+1],Y=Q[M*3+2],R=F-y,k=m-p,b=G-f,L=N-y,x=S-p,J=Y-f;return .5*Math.hypot(k*J-b*x,b*L-R*J,R*x-k*L)},"areaByIndex"),h=[],w=[];let d=0;for(let D=0;D<I;D++){const u=C[g[D*3+0]>>>0],M=C[g[D*3+1]>>>0],y=C[g[D*3+2]>>>0];if(u<0||M<0||y<0||u===M||M===y||y===u||!(l(u,M,y)>Lo)){d+=1;continue}h.push(u,M,y),w.push(o[D])}i._vertProperties=Q,i._triVerts=h,i._triIDs=w,i._vertKeyToIndex=new Map;for(let D=0;D<Q.length;D+=3)i._vertKeyToIndex.set(`${Q[D]},${Q[D+1]},${Q[D+2]}`,D/3|0);return i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i),{weldedVertexCount:E,removedTriangleCount:d}}c(wl,"ph");r(wl,"weldSolidVerticesByPosition");function zRe(i,A={}){if(!i?.geometry)throw new Error("Face.thicken() requires a face with geometry.");try{i.updateMatrixWorld?.(!0)}catch{}const e=i.geometry,t=e.getAttribute?.("position"),g=e.getIndex?.()||null;if(!t||t.itemSize!==3||t.count<3)throw new Error("Face.thicken() requires a triangulated face geometry.");const o=[],s=new W;let I=1/0,n=1/0,B=1/0,C=-1/0,a=-1/0,Q=-1/0;for(let _=0;_<t.count;_++)s.set(t.getX(_),t.getY(_),t.getZ(_)).applyMatrix4(i.matrixWorld),o.push(s.clone()),s.x<I&&(I=s.x),s.y<n&&(n=s.y),s.z<B&&(B=s.z),s.x>C&&(C=s.x),s.y>a&&(a=s.y),s.z>Q&&(Q=s.z);const E=Math.max(1,Math.hypot(C-I,a-n,Q-B)),l=Math.max(Number(A.weldTolerance)||0,Math.max(1e-6,E*1e-7)),h=new Map,w=[],d=new Array(o.length);for(let _=0;_<o.length;_++){const V=o[_],O=Rb(V,l);let AA=h.get(O);AA==null?(AA=w.length,h.set(O,AA),w.push({point:V.clone(),count:1,key:O})):(w[AA].point.add(V),w[AA].count+=1),d[_]=AA}let D=w.map(_=>_.point.multiplyScalar(1/_.count)),u=w.map(_=>_.key);const M=Array.isArray(A.triangleSourceFaceNames)?A.triangleSourceFaceNames:null,y=String(A.sourceFaceName||G5A(i)||"").trim();let p=[];const f=g?g.count/3|0:t.count/3|0;for(let _=0;_<f;_++){const V=g?g.getX(_*3+0)>>>0:_*3+0,O=g?g.getX(_*3+1)>>>0:_*3+1,AA=g?g.getX(_*3+2)>>>0:_*3+2,BA=d[V]>>>0,rA=d[O]>>>0,tA=d[AA]>>>0;if(BA===rA||rA===tA||tA===BA||!(S5A(D[BA],D[rA],D[tA])>Lo))continue;const sA=[BA,rA,tA],eA=String(M?.[_]||y||"").trim();eA&&(sA.sourceFaceName=eA),p.push(sA)}if(!p.length)throw new Error("Face.thicken() could not resolve any non-degenerate source triangles.");const F=new Map,m=new Array(p.length).fill(null).map(()=>[]),G=r((_,V,O)=>{for(const[AA,BA]of[[_[0],_[1]],[_[1],_[2]],[_[2],_[0]]]){if(AA===V&&BA===O)return 1;if(AA===O&&BA===V)return-1}return 0},"edgeOrientation");for(let _=0;_<p.length;_++){const V=p[_];for(const[O,AA]of[[V[0],V[1]],[V[1],V[2]],[V[2],V[0]]]){const BA=hr(O,AA);let rA=F.get(BA);rA||(rA=[],F.set(BA,rA)),rA.push({triIndex:_,u:O,v:AA})}}for(const[_,V]of F.entries()){if(!Array.isArray(V)||V.length<2)continue;const[O,AA]=_.split("|"),BA=Number(O)>>>0,rA=Number(AA)>>>0;for(let tA=0;tA<V.length;tA++)for(let sA=tA+1;sA<V.length;sA++)m[V[tA].triIndex].push({neighbor:V[sA].triIndex,u:BA,v:rA}),m[V[sA].triIndex].push({neighbor:V[tA].triIndex,u:BA,v:rA})}const N=new Array(p.length).fill(!1),S=r(_=>pEt(_,[_[0],_[2],_[1]]),"flipTriangle");for(let _=0;_<p.length;_++){if(N[_])continue;const V=[_];for(N[_]=!0;V.length;){const O=V.pop(),AA=p[O];for(const BA of m[O]){const rA=BA.neighbor;if(rA!=null&&!N[rA]){const tA=p[rA],sA=G(AA,BA.u,BA.v),eA=G(tA,BA.u,BA.v);sA!==0&&sA===eA&&(p[rA]=S(tA)),N[rA]=!0,V.push(rA)}}}}const Y=new Array(p.length),R=new Array(D.length).fill(null).map(()=>new W),k=new W;for(let _=0;_<p.length;_++){const[V,O,AA]=p[_],BA=QU(D[V],D[O],D[AA]),rA=BA.length();if(!(rA>Lo))continue;const tA=BA.clone().multiplyScalar(1/rA);Y[_]=tA,R[V].add(tA.clone().multiplyScalar(rA)),R[O].add(tA.clone().multiplyScalar(rA)),R[AA].add(tA.clone().multiplyScalar(rA)),k.add(tA.clone().multiplyScalar(rA))}k.lengthSq()<=Lo?k.set(0,0,1):k.normalize();const b=[];for(const[_,V]of F.entries()){if(V.length!==1)continue;const O=V[0];b.push({key:_,start:O.u,end:O.v})}const L=new Map;for(const _ of b){let V=L.get(_.start);V||(V=[],L.set(_.start,V)),V.push(_)}const x=new Set(b.map(_=>`${_.start}>${_.end}`)),J=[],$=r((_,V)=>{const O=`${u[_.start]}|${u[_.end]}`,AA=`${u[V.start]}|${u[V.end]}`;return O.localeCompare(AA)},"compareEdges");for(;x.size;){const _=Array.from(x.values()).sort((v,iA)=>v.localeCompare(iA))[0],[V,O]=_.split(">"),AA=Number(V)>>>0,BA=Number(O)>>>0,rA=[],tA=[AA];let sA=AA,eA=AA,K=BA;for(;x.has(`${eA}>${K}`)&&(x.delete(`${eA}>${K}`),rA.push({start:eA,end:K,key:hr(eA,K)}),tA.push(K),eA=K,eA!==sA);){const v=(L.get(eA)||[]).filter(iA=>x.has(`${iA.start}>${iA.end}`)).sort($);if(!v.length)break;K=v[0].end}rA.length&&J.push({vertices:tA,edges:rA})}const T=r(_=>{const V=Array.isArray(_?.vertices)?_.vertices.slice(0,-1):[];if(!V.length)return"";let O=null;for(let AA=0;AA<V.length;AA++){const BA=[];for(let tA=0;tA<V.length;tA++)BA.push(u[V[(AA+tA)%V.length]]||`${V[(AA+tA)%V.length]}`);const rA=BA.join(">");(O==null||rA<O)&&(O=rA)}return O||""},"normalizeLoopSignature"),H=J.map(_=>({..._,signature:T(_)})).sort((_,V)=>_.signature.localeCompare(V.signature));NEt(i,H,D,E,l);const X=new Map;for(let _=0;_<H.length;_++){const V=H[_];for(const O of V.edges)X.set(O.key,_)}const oA=SEt(i,{vertices:D,vertexNormals:R,boundaryDirectedEdges:b,weldTolerance:l},A);for(let _=0;_<R.length;_++)R[_].lengthSq()<=Lo&&R[_].copy(k),R[_].lengthSq()<=Lo?R[_].set(0,0,1):R[_].normalize();return{vertices:D,triangles:p,triangleNormals:Y,vertexNormals:R,averageNormal:k,loops:H,boundaryEdgeToLoop:X,boundaryDirectedEdges:b,adjacentNormalStats:oA,scale:E,weldTolerance:l}}c(zRe,"sgt");r(zRe,"extractFaceSurface");function GEt(i,A={}){const e=Array.isArray(i)?i.filter(Q=>Q?.geometry):[];if(!e.length)throw new Error("Face.thicken() requires at least one face with geometry.");const t=[],g=[],o=[],s=[],I=new W;let n=null,B=!1;for(const Q of e){try{Q.updateMatrixWorld?.(!0)}catch{}const E=G5A(Q)||`FACE_${e.indexOf(Q)+1}`,l=Q?.parentSolid||(String(Q?.parent?.type||"").toUpperCase()==="SOLID"?Q.parent:null);if(!n&&l?n=l:n&&l&&l!==n&&(B=!0),Array.isArray(Q?.edges))for(const M of Q.edges)M&&!s.includes(M)&&s.push(M);const h=Q.geometry,w=h.getAttribute?.("position"),d=h.getIndex?.()||null;if(!w||w.itemSize!==3||w.count<3)throw new Error("Face.thicken() requires triangulated face geometries.");const D=t.length/3|0;for(let M=0;M<w.count;M++)I.set(w.getX(M),w.getY(M),w.getZ(M)).applyMatrix4(Q.matrixWorld||new Bt),t.push(I.x,I.y,I.z);const u=d?d.count/3|0:w.count/3|0;for(let M=0;M<u;M++){const y=d?d.getX(M*3+0)>>>0:M*3+0,p=d?d.getX(M*3+1)>>>0:M*3+1,f=d?d.getX(M*3+2)>>>0:M*3+2;g.push(D+y,D+p,D+f),o.push(E)}}if(g.length<3)throw new Error("Face.thicken() could not resolve any source triangles.");const C=new Kt;C.setAttribute("position",new pg(new Float32Array(t),3)),C.setIndex(g);const a={geometry:C,matrixWorld:new Bt,name:String(A.sourceFaceName||"THICKEN_PATCH"),edges:s,parentSolid:B?null:n,userData:{faceName:String(A.sourceFaceName||"THICKEN_PATCH")},updateMatrixWorld(){}};return zRe(a,{...A,triangleSourceFaceNames:o,disableAdjacentBoundaryNormals:A.disableAdjacentBoundaryNormals??!(A.equalAdjacentBoundaryNormals===!0||String(A.sharedBoundaryNormalMode||"").toLowerCase()==="equal")})}c(GEt,"lKt");r(GEt,"extractFacesSurface");function REt(i,A){const e=[],t=new Set,g=r((l,h)=>{const w=String(l?.label||"").trim();if(!w||t.has(w))return;t.add(w);const d=String(l?.sourceFaceName||i.sourceFaceName||"").trim()||i.sourceFaceName;e.push({label:w,kind:h,metadata:{type:h==="start"?"start_cap":"end_cap",sourceFaceName:d,distance:A}})},"addCapGroup"),o=Array.isArray(i.startCaps)&&i.startCaps.length?i.startCaps:[{label:i.start,sourceFaceName:i.sourceFaceName}],s=Array.isArray(i.endCaps)&&i.endCaps.length?i.endCaps:[{label:i.end,sourceFaceName:i.sourceFaceName}];for(const l of o)g(l,"start");for(const l of s)g(l,"end");const I=[],n=new Map;for(const l of i.sidewalls||[]){const h=String(l?.label||"").trim();if(!h)continue;let w=n.get(h);w||(w={label:h,kind:"sidewall",metadata:{type:"sidewall",sourceFaceName:i.sourceFaceName,loopIndex:l.loopIndex,edgeIndex:l.edgeIndex,edgeKey:l.key,sourceEdgeName:l.sourceEdgeName||null,sourceEdgeKey:l.sourceEdgeKey||null,distance:A,segmentCount:0,edgeKeys:[]}},n.set(h,w),I.push(w)),w.metadata.segmentCount+=1,l.key!=null&&w.metadata.edgeKeys.push(l.key)}const B=[...e,...I],C=new Map,a=new Map,Q=[];let E=1;try{typeof gD?.reserveIDs=="function"&&(E=Number(gD.reserveIDs(B.length))||1)}catch{E=1}for(const l of B){const h=E>>>0;E+=1,C.set(l.label,h),a.set(h,l.label),Q.push([l.label,JSON.stringify(l.metadata||{})])}return{labels:i,groups:B,faceNameToID:C,idToFaceName:a,faceMetadataJson:Q,edgeKeyToLabel:new Map(i.sidewalls.map(l=>[l.key,l.label]))}}c(REt,"hKt");r(REt,"buildThickenClassificationState");function VRe(i,A,e){const t=Array.from(i?.triVerts??[],B=>Number(B)>>>0),g=t.length/3|0;if(!g)return null;const o=Array.from(A?.triIDs??i?.faceID??[],B=>Number(B)>>>0),s=Number(A?.faceNameToID?.values?.()?.next?.()?.value)>>>0,I=o.length===g?o:new Array(g).fill(s||1),n=new Qg;n._numProp=Number(i?.numProp??3)||3,n._vertProperties=Array.from(i?.vertProperties??[],B=>Number(B)||0),n._triVerts=t,n._triIDs=I,n._faceNameToID=A?.faceNameToID instanceof Map?new Map(A.faceNameToID):new Map,n._idToFaceName=A?.idToFaceName instanceof Map?new Map(A.idToFaceName):new Map,n._faceMetadata=new Map;for(const[B,C]of A?.faceMetadataJson||[])if(B)try{n._faceMetadata.set(String(B),JSON.parse(C||"{}")||{})}catch{n._faceMetadata.set(String(B),{})}n._vertKeyToIndex=new Map;for(let B=0;B<n._vertProperties.length;B+=3)n._vertKeyToIndex.set(`${n._vertProperties[B]},${n._vertProperties[B+1]},${n._vertProperties[B+2]}`,B/3|0);try{n.name=e||n.name}catch{}return n._dirty=!0,n._manifold=null,n._faceIndex=null,n}c(VRe,"ogt");r(VRe,"buildSolidFromTriangleMesh");function WRe(i,A,e="raw_face_ids"){return{triIDs:Array.from(A||[],t=>Number(t)>>>0),faceNameToID:i?.faceNameToID instanceof Map?i.faceNameToID:new Map,idToFaceName:i?.idToFaceName instanceof Map?i.idToFaceName:new Map,faceMetadataJson:Array.from(i?.faceMetadataJson||[]),groups:Array.isArray(i?.groups)?i.groups:[],method:e}}c(WRe,"ngt");r(WRe,"buildRawClassification");function YEt(i,A,e){const t=i?.labels||{},g=String(A?.sourceFaceName||"").trim(),o=g?t.capLabelsBySourceFaceName?.get?.(g):null,s=e==="start"?o?.start||t.start:o?.end||t.end;return String(s||"").trim()}c(YEt,"dKt");r(YEt,"resolveCapLabelForTriangle");function sv(i,A,e){const t=YEt(i,A,e);return Number(i?.faceNameToID?.get?.(t))>>>0}c(sv,"Aj");r(sv,"resolveCapFaceIDForTriangle");function UEt(i,A,e){const t=Array.isArray(i?.vertices)?i.vertices.length:0;if(!t)return null;const g=new Float32Array(t*2*3);for(let C=0;C<t;C++){const a=i.vertices[C],Q=a.clone().add(i.vertexNormals[C].clone().multiplyScalar(A));g[C*3+0]=a.x,g[C*3+1]=a.y,g[C*3+2]=a.z;const E=t+C;g[E*3+0]=Q.x,g[E*3+1]=Q.y,g[E*3+2]=Q.z}const o=Number(e?.faceNameToID?.get?.(e?.labels?.start))>>>0,s=Number(e?.faceNameToID?.get?.(e?.labels?.end))>>>0,I=[],n=[],B=r((C,a,Q,E)=>{if(C===a||a===Q||Q===C)return;const l=new W(g[C*3+0],g[C*3+1],g[C*3+2]),h=new W(g[a*3+0],g[a*3+1],g[a*3+2]),w=new W(g[Q*3+0],g[Q*3+1],g[Q*3+2]);S5A(l,h,w)>Lo&&(I.push(C>>>0,a>>>0,Q>>>0),n.push(Number(E)>>>0))},"addTriangle");for(const C of i.triangles||[]){const[a,Q,E]=C,l=sv(e,C,"start")||o,h=sv(e,C,"end")||s;A>=0?(B(a,E,Q,l),B(t+a,t+Q,t+E,h)):(B(a,Q,E,l),B(t+a,t+E,t+Q,h))}for(let C=0;C<(i.loops?.length||0);C++){const a=i.loops[C];for(const Q of a?.edges||[]){const E=Q.start>>>0,l=Q.end>>>0,h=t+E,w=t+l,d=e?.edgeKeyToLabel?.get?.(Q.key),D=Number(e?.faceNameToID?.get?.(d))>>>0;A>=0?(B(E,l,w,D),B(E,w,h,D)):(B(h,w,l,D),B(h,l,E,D))}}return{numProp:3,vertProperties:g,triVerts:Uint32Array.from(I),faceID:Uint32Array.from(n)}}c(UEt,"wKt");r(UEt,"buildStitchedThickenMesh");function kEt(i,A,e,t){const g=UEt(i,A,e);if(!g)return null;const o=WRe(e,g.faceID,"stitched_shell");return VRe(g,o,t)}c(kEt,"uKt");r(kEt,"buildStitchedShellSolid");function LEt(i,A,e){const t=Array.isArray(i?.vertices)?i.vertices:[],g=Array.isArray(i?.triangles)?i.triangles:[];if(!t.length||!g.length)return null;const o=Number(e?.faceNameToID?.get?.(e?.labels?.start))>>>0,s=Number(e?.faceNameToID?.get?.(e?.labels?.end))>>>0,I=Number(e?.faceNameToID?.values?.()?.next?.()?.value)>>>0,n=[],B=[],C=[],a=r(l=>{const h=C.length/3|0;return C.push(l.x,l.y,l.z),h},"addVertex"),Q=r((l,h,w,d)=>{if(!l||!h||!w||!(S5A(l,h,w)>Lo))return;const D=a(l),u=a(h),M=a(w);n.push(D,u,M),B.push(Number(d)>>>0)},"addTriangleByPoints"),E=r((l,h)=>{const w=hr(l,h),d=e?.edgeKeyToLabel?.get?.(w);return Number(e?.faceNameToID?.get?.(d))>>>0||I||o||s||1},"resolveSideFaceID");for(const l of g){const h=l?.[0]>>>0,w=l?.[1]>>>0,d=l?.[2]>>>0,D=t[h],u=t[w],M=t[d];if(!D||!u||!M)continue;const y=sv(e,l,"start")||o,p=sv(e,l,"end")||s,f=QU(D,u,M),F=f.length();if(!(F>Lo))continue;f.multiplyScalar(A/F);const m=D.clone().add(f),G=u.clone().add(f),N=M.clone().add(f);A>=0?(Q(D,M,u,y),Q(m,G,N,p),Q(D,u,G,E(h,w)),Q(D,G,m,E(h,w)),Q(u,M,N,E(w,d)),Q(u,N,G,E(w,d)),Q(M,D,m,E(d,h)),Q(M,m,N,E(d,h))):(Q(D,u,M,y),Q(m,N,G,p),Q(m,G,u,E(h,w)),Q(m,u,D,E(h,w)),Q(G,N,M,E(w,d)),Q(G,M,u,E(w,d)),Q(N,m,D,E(d,h)),Q(N,D,M,E(d,h)))}return n.length?{numProp:3,vertProperties:Float32Array.from(C),triVerts:Uint32Array.from(n),faceID:Uint32Array.from(B)}:null}c(LEt,"DKt");r(LEt,"buildTrianglePrismUnionThickenMesh");function bEt(i,A,e,t){const g=LEt(i,A,e);if(!g)return null;const o=WRe(e,g.faceID,"triangle_prism_union");return VRe(g,o,t)}c(bEt,"fKt");r(bEt,"buildTrianglePrismUnionShellSolid");function KEt(i,A={}){const e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=Array.isArray(i?._triVerts)?i._triVerts:[],g=Array.isArray(i?._triIDs)?i._triIDs:[],o=t.length/3|0;if(!o||e.length<9||g.length<o)return 0;let s=1/0,I=1/0,n=1/0,B=-1/0,C=-1/0,a=-1/0;for(let b=0;b<e.length;b+=3){const L=e[b+0],x=e[b+1],J=e[b+2];L<s&&(s=L),L>B&&(B=L),x<I&&(I=x),x>C&&(C=x),J<n&&(n=J),J>a&&(a=J)}const Q=Math.hypot(B-s,C-I,a-n)||1,E=Math.max(Q*(Number(A.offsetScale)||1e-5),1e-9),l=Math.max(E*.1,Q*1e-10,1e-10),h=Math.max(12,Math.min(256,Number.isFinite(Number(A.gridSize))?Number(A.gridSize)|0:Math.ceil(Math.sqrt(o)))),w=new Array(o);for(let b=0;b<o;b++){const L=t[b*3+0]>>>0,x=t[b*3+1]>>>0,J=t[b*3+2]>>>0,$=[e[L*3+0],e[L*3+1],e[L*3+2]],T=[e[x*3+0],e[x*3+1],e[x*3+2]],H=[e[J*3+0],e[J*3+1],e[J*3+2]],X=T[0]-$[0],oA=T[1]-$[1],_=T[2]-$[2],V=H[0]-$[0],O=H[1]-$[1],AA=H[2]-$[2];let BA=oA*AA-_*O,rA=_*V-X*AA,tA=X*O-oA*V;const sA=Math.hypot(BA,rA,tA);sA>Lo?(BA/=sA,rA/=sA,tA/=sA):(BA=0,rA=0,tA=0),w[b]={a:$,b:T,c:H,normal:[BA,rA,tA],centroid:[($[0]+T[0]+H[0])/3,($[1]+T[1]+H[1])/3,($[2]+T[2]+H[2])/3],min:[Math.min($[0],T[0],H[0]),Math.min($[1],T[1],H[1]),Math.min($[2],T[2],H[2])],max:[Math.max($[0],T[0],H[0]),Math.max($[1],T[1],H[1]),Math.max($[2],T[2],H[2])]}}const d=[{primary:0,u:1,v:2,min:[s,I,n],max:[B,C,a]},{primary:1,u:2,v:0,min:[s,I,n],max:[B,C,a]},{primary:2,u:0,v:1,min:[s,I,n],max:[B,C,a]}],D=r(b=>{const L=b.min[b.u],x=b.min[b.v],J=Math.max(b.max[b.u]-L,E),$=Math.max(b.max[b.v]-x,E),T=new Map,H=r((oA,_,V)=>Math.max(0,Math.min(h-1,Math.floor((oA-_)/V*h))),"cellCoord"),X=r((oA,_,V)=>{const O=`${oA}|${_}`;let AA=T.get(O);AA||(AA=[],T.set(O,AA)),AA.push(V)},"addCell");for(let oA=0;oA<o;oA++){const _=w[oA],V=H(_.min[b.u]-E,L,J),O=H(_.max[b.u]+E,L,J),AA=H(_.min[b.v]-E,x,$),BA=H(_.max[b.v]+E,x,$);for(let rA=V;rA<=O;rA++)for(let tA=AA;tA<=BA;tA++)X(rA,tA,oA)}return{axis:b,uMin:L,vMin:x,uSpan:J,vSpan:$,cells:T,cellCoord:H}},"buildIndex"),u=(String(A.axes||"").toLowerCase()==="majority"?d:[d[0]]).map(D),M=r((b,L)=>{const x=b.cellCoord(L[b.axis.u],b.uMin,b.uSpan),J=b.cellCoord(L[b.axis.v],b.vMin,b.vSpan);return b.cells.get(`${x}|${J}`)||[]},"pointInIndexCell"),y=r((b,L,x)=>{const J=L.primary,$=L.u,T=L.v,H=x.a[J]-b[J],X=x.a[$]-b[$],oA=x.a[T]-b[T],_=x.b[J]-b[J],V=x.b[$]-b[$],O=x.b[T]-b[T],AA=x.c[J]-b[J],BA=x.c[$]-b[$],rA=x.c[T]-b[T],tA=_-H,sA=V-X,eA=O-oA,K=AA-H,v=BA-X,iA=rA-oA,QA=eA*v-sA*iA;if(Math.abs(QA)<=l)return null;const gA=1/QA,IA=-H,lA=-X,cA=-oA,CA=0,EA=-iA,z=v,aA=(IA*CA+lA*EA+cA*z)*gA;if(aA<-1e-10||aA>1+1e-10)return null;const hA=lA*eA-cA*sA,MA=cA*tA-IA*eA,fA=IA*sA-lA*tA,SA=hA*gA;if(SA<-1e-10||aA+SA>1+1e-10)return null;const UA=(K*hA+v*MA+iA*fA)*gA;return UA>l?UA:null},"rayTriangleHit"),p=r((b,L)=>{const x=[];for(const T of M(L,b)){const H=w[T];if(b[L.axis.primary]>H.max[L.axis.primary]+E||b[L.axis.u]<H.min[L.axis.u]-E||b[L.axis.u]>H.max[L.axis.u]+E||b[L.axis.v]<H.min[L.axis.v]-E||b[L.axis.v]>H.max[L.axis.v]+E)continue;const X=y(b,L.axis,H);X!=null&&x.push(X)}if(!x.length)return!1;x.sort((T,H)=>T-H);let J=0,$=-1/0;for(const T of x)Math.abs(T-$)<=Math.max(l*4,1e-8)||(J+=1,$=T);return J%2===1},"inside"),f=new Uint8Array(o);f.fill(1);let F=0;for(let b=0;b<o;b++){const L=w[b],x=L.normal;if(Math.hypot(x[0],x[1],x[2])<=Lo)continue;const J=[L.centroid[0]+x[0]*E,L.centroid[1]+x[1]*E,L.centroid[2]+x[2]*E],$=[L.centroid[0]-x[0]*E,L.centroid[1]-x[1]*E,L.centroid[2]-x[2]*E];let T=0;for(const H of u)p(J,H)!==p($,H)&&(T+=1);T>=Math.ceil(u.length/2)||(f[b]=0,F+=1)}if(!F)return 0;const m=e.length/3|0,G=new Uint8Array(m),N=[],S=[];for(let b=0;b<o;b++){if(!f[b])continue;const L=t[b*3+0]>>>0,x=t[b*3+1]>>>0,J=t[b*3+2]>>>0;N.push(L,x,J),S.push(g[b]),G[L]=1,G[x]=1,G[J]=1}const Y=new Int32Array(m);Y.fill(-1);const R=[];let k=0;for(let b=0;b<m;b++)G[b]&&(Y[b]=k++,R.push(e[b*3+0],e[b*3+1],e[b*3+2]));for(let b=0;b<N.length;b++)N[b]=Y[N[b]>>>0];i._vertProperties=R,i._triVerts=N,i._triIDs=S,i._vertKeyToIndex=new Map;for(let b=0;b<R.length;b+=3)i._vertKeyToIndex.set(`${R[b]},${R[b+1]},${R[b+2]}`,b/3|0);i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i);try{i.fixTriangleWindingsByAdjacency?.()}catch{}return F}c(KEt,"MKt");r(KEt,"cullInternalTrianglesByIndexedRaycast");function Zf(i,A){const e=Array.isArray(i?._triVerts)?i._triVerts:[],t=Array.isArray(i?._vertProperties)?i._vertProperties:[],g=e.length/3|0;if(!g||t.length<9)return 0;const o=new Map,s=r((f,F)=>{const m=hr(f,F);let G=o.get(m);G||(G={count:0,directed:[]},o.set(m,G)),G.count+=1,G.directed.push([f,F])},"addUse");for(let f=0;f<g;f++){const F=e[f*3+0]>>>0,m=e[f*3+1]>>>0,G=e[f*3+2]>>>0;s(F,m),s(m,G),s(G,F)}const I=new Map,n=new Map,B=new Map,C=[],a=r((f,F)=>{let m=n.get(f);m||(m=[],n.set(f,m)),m.push(F)},"addUndirectedNeighbor");for(const f of o.values()){if(f.count!==1||!f.directed.length)continue;const[F,m]=f.directed[0],G={a:F,b:m,key:`${F}>${m}`};C.push(G),B.set(hr(F,m),[F,m]),a(F,m),a(m,F);let N=I.get(F);N||(N=[],I.set(F,N)),N.push(G)}if(!C.length)return 0;for(const f of I.values())f.sort((F,m)=>F.b-m.b);const Q=new Set,E=[];for(const f of C){if(Q.has(f.key))continue;const F=[f.a];let m=f,G=0;for(;m&&!Q.has(m.key)&&G++<C.length+1&&(Q.add(m.key),F.push(m.b),m.b!==F[0]);)m=(I.get(m.b)||[]).find(N=>!Q.has(N.key))||null;F.length>=4&&F[0]===F[F.length-1]&&E.push(F.slice(0,-1))}const l=r(f=>{if(!Array.isArray(f)||!f.length)return"";const F=[],m=r(G=>{for(let N=0;N<G.length;N++){const S=[];for(let Y=0;Y<G.length;Y++)S.push(G[(N+Y)%G.length]);F.push(S.join("|"))}},"addVariants");return m(f),f.length>1&&m(f.slice().reverse()),F.sort()[0]||""},"loopSignature"),h=r((f,F)=>{const m=Array.from(F.keys());if(m.length<3||f.length<3)return[];const G=r(IA=>[Number(t[IA*3+0])||0,Number(t[IA*3+1])||0,Number(t[IA*3+2])||0],"pointFor"),N=r((IA,lA)=>[IA[0]-lA[0],IA[1]-lA[1],IA[2]-lA[2]],"sub"),S=r((IA,lA)=>IA[0]*lA[0]+IA[1]*lA[1]+IA[2]*lA[2],"dot"),Y=r((IA,lA)=>[IA[1]*lA[2]-IA[2]*lA[1],IA[2]*lA[0]-IA[0]*lA[2],IA[0]*lA[1]-IA[1]*lA[0]],"cross"),R=r(IA=>Math.hypot(IA[0],IA[1],IA[2]),"length"),k=r((IA,lA)=>[IA[0]*lA,IA[1]*lA,IA[2]*lA],"scaleVec"),b=[0,0,0],L=new Map;for(const IA of m){const lA=G(IA);L.set(IA,lA),b[0]+=lA[0],b[1]+=lA[1],b[2]+=lA[2]}b[0]/=m.length,b[1]/=m.length,b[2]/=m.length;let x=null,J=-1/0;for(const IA of L.values()){const lA=N(IA,b),cA=R(lA);cA>J&&(J=cA,x=lA)}if(!x||!(J>Lo))return[];x=k(x,1/J);let $=null,T=-1/0;for(const IA of L.values()){const lA=Y(x,N(IA,b)),cA=R(lA);cA>T&&(T=cA,$=lA)}if(!$||!(T>Lo))return[];$=k($,1/T);const H=Y($,x),X=R(H);if(!(X>Lo))return[];const oA=k(H,1/X),_=new Map;for(const[IA,lA]of L.entries()){const cA=N(lA,b);_.set(IA,[S(cA,x),S(cA,oA)])}const V=new Map;for(const[IA,lA]of F.entries()){const cA=_.get(IA);V.set(IA,lA.slice().sort((CA,EA)=>{const z=_.get(CA),aA=_.get(EA);return Math.atan2(z[1]-cA[1],z[0]-cA[0])-Math.atan2(aA[1]-cA[1],aA[0]-cA[0])}))}const O=r(IA=>{let lA=0;for(let cA=0;cA<IA.length;cA++){const CA=_.get(IA[cA]),EA=_.get(IA[(cA+1)%IA.length]);lA+=CA[0]*EA[1]-EA[0]*CA[1]}return lA*.5},"area2D"),AA=new Set,BA=r((IA,lA)=>`${IA}>${lA}`,"directedKey"),rA=[];for(const[IA,lA]of f)for(const cA of[[IA,lA],[lA,IA]]){let CA=cA[0],EA=cA[1];const z=BA(CA,EA);if(AA.has(z))continue;const aA=[];let hA=!1,MA=0;const fA=Math.max(12,f.length*4);for(;!AA.has(BA(CA,EA))&&MA++<fA;){AA.add(BA(CA,EA)),aA.push(CA);const UA=V.get(EA)||[],GA=UA.indexOf(CA);if(GA<0||UA.length===0)break;const _A=UA[(GA-1+UA.length)%UA.length];if(CA=EA,EA=_A,BA(CA,EA)===z){hA=!0;break}}if(!hA||aA.length<3)continue;const SA=O(aA);Math.abs(SA)<=Lo||rA.push({loop:aA,area:SA})}const tA=rA.filter(IA=>IA.area>Lo),sA=(tA.length?tA:rA.filter(IA=>IA.area<-Lo)).map(IA=>IA.area>0?IA.loop:IA.loop.slice().reverse());if(sA.length||f.length>64)return sA;const eA=new Set,K=[],v=m.slice().sort((IA,lA)=>IA-lA),iA=r(IA=>{if(!IA.length)return"";const lA=[],cA=r(CA=>{for(let EA=0;EA<CA.length;EA++){const z=[];for(let aA=0;aA<CA.length;aA++)z.push(CA[(EA+aA)%CA.length]);lA.push(z.join("|"))}},"add");return cA(IA),cA(IA.slice().reverse()),lA.sort()[0]||""},"canonicalCycleKey");for(const IA of v){const lA=[{current:IA,path:[IA],visited:new Set([IA])}];let cA=0;for(;lA.length&&cA++<5e3&&K.length<f.length*2;){const CA=lA.pop();if(CA.path.length>f.length)continue;const EA=(F.get(CA.current)||[]).slice().sort((z,aA)=>z-aA);for(const z of EA){if(z===IA&&CA.path.length>=3){const hA=iA(CA.path);hA&&!eA.has(hA)&&(eA.add(hA),K.push(CA.path.slice()));continue}if(z<IA||CA.visited.has(z))continue;const aA=new Set(CA.visited);aA.add(z),lA.push({current:z,path:CA.path.concat(z),visited:aA})}}}K.sort((IA,lA)=>IA.length-lA.length);const QA=new Set,gA=[];for(const IA of K){const lA=[];let cA=!1;for(let CA=0;CA<IA.length;CA++){const EA=hr(IA[CA],IA[(CA+1)%IA.length]);lA.push(EA),QA.has(EA)&&(cA=!0)}if(!cA){for(const CA of lA)QA.add(CA);gA.push(IA)}}return gA.slice(0,f.length)},"traceBoundaryGraphLoops"),w=new Set(E.map(l)),d=new Set,D=[];for(const f of C){const F=hr(f.a,f.b);if(d.has(F))continue;const m=[],G=[[f.a,f.b]];for(d.add(F);G.length;){const[X,oA]=G.pop();m.push([X,oA]);for(const _ of[X,oA])for(const V of n.get(_)||[]){const O=hr(_,V);d.has(O)||(d.add(O),G.push([_,V]))}}if(m.length<3)continue;const N=new Map,S=r((X,oA)=>{let _=N.get(X);_||(_=[],N.set(X,_)),_.includes(oA)||_.push(oA)},"addComponentNeighbor");for(const[X,oA]of m)S(X,oA),S(oA,X);if(!Array.from(N.values()).every(X=>X.length===2)){let X=!1;for(const oA of h(m,N)){const _=l(oA);!_||w.has(_)||(w.add(_),E.push(oA),X=!0)}X||D.push(m);continue}const Y=Math.min(...Array.from(N.keys())),R=(N.get(Y)||[]).slice().sort((X,oA)=>X-oA);if(R.length!==2){D.push(m);continue}const k=[Y];let b=-1,L=Y,x=R[0],J=!1,$=0;for(;$++<m.length+2;){if(k.push(x),b=L,L=x,L===Y){J=!0;break}const X=(N.get(L)||[]).filter(oA=>oA!==b);if(X.length!==1)break;x=X[0]}if(!J||k.length<4){D.push(m);continue}const T=k.slice(0,-1);if(T.length!==m.length){D.push(m);continue}const H=l(T);!H||w.has(H)||(w.add(H),E.push(T))}if(D.length=0,!E.length&&!D.length)return 0;const u=r(f=>{if(!Array.isArray(f)||f.length<3)return[];const F=f.map(oA=>[Number(t[oA*3+0])||0,Number(t[oA*3+1])||0,Number(t[oA*3+2])||0]),m=[0,0,0];for(const oA of F)m[0]+=oA[0],m[1]+=oA[1],m[2]+=oA[2];m[0]/=F.length,m[1]/=F.length,m[2]/=F.length;let G=[0,0,0];for(let oA=0;oA<F.length;oA++){const _=F[oA],V=F[(oA+1)%F.length];G[0]+=(_[1]-V[1])*(_[2]+V[2]),G[1]+=(_[2]-V[2])*(_[0]+V[0]),G[2]+=(_[0]-V[0])*(_[1]+V[1])}let N=Math.hypot(G[0],G[1],G[2]);if(!(N>Lo)){let oA=0;for(let _=0;_<F.length;_++){const V=F[_],O=F[(_+1)%F.length],AA=F[(_+2)%F.length],BA=[O[0]-V[0],O[1]-V[1],O[2]-V[2]],rA=[AA[0]-V[0],AA[1]-V[1],AA[2]-V[2]],tA=[BA[1]*rA[2]-BA[2]*rA[1],BA[2]*rA[0]-BA[0]*rA[2],BA[0]*rA[1]-BA[1]*rA[0]],sA=Math.hypot(tA[0],tA[1],tA[2]);sA>oA&&(oA=sA,G=tA)}N=oA}if(!(N>Lo))return[];G=G.map(oA=>oA/N);let S=null,Y=0;for(const oA of F){const _=[oA[0]-m[0],oA[1]-m[1],oA[2]-m[2]],V=Math.hypot(_[0],_[1],_[2]);V>Y&&(Y=V,S=_)}if(!S||!(Y>Lo))return[];S=S.map(oA=>oA/Y);const R=[G[1]*S[2]-G[2]*S[1],G[2]*S[0]-G[0]*S[2],G[0]*S[1]-G[1]*S[0]],k=Math.hypot(R[0],R[1],R[2]);if(!(k>Lo))return[];R[0]/=k,R[1]/=k,R[2]/=k;const b=F.map(oA=>{const _=[oA[0]-m[0],oA[1]-m[1],oA[2]-m[2]];return[_[0]*S[0]+_[1]*S[1]+_[2]*S[2],_[0]*R[0]+_[1]*R[1]+_[2]*R[2]]}),L=r(oA=>{let _=0;for(let V=0;V<oA.length;V++){const O=b[oA[V]],AA=b[oA[(V+1)%oA.length]];_+=O[0]*AA[1]-AA[0]*O[1]}return _*.5},"area2D"),x=r((oA,_,V)=>{const O=b[oA],AA=b[_],BA=b[V];return(AA[0]-O[0])*(BA[1]-AA[1])-(AA[1]-O[1])*(BA[0]-AA[0])},"cross2D"),J=r((oA,_,V,O)=>{const AA=b[oA],BA=b[_],rA=b[V],tA=b[O],sA=Math.abs((rA[0]-BA[0])*(tA[1]-BA[1])-(rA[1]-BA[1])*(tA[0]-BA[0]));if(!(sA>Lo))return!1;const eA=Math.abs((BA[0]-AA[0])*(rA[1]-AA[1])-(BA[1]-AA[1])*(rA[0]-AA[0])),K=Math.abs((rA[0]-AA[0])*(tA[1]-AA[1])-(rA[1]-AA[1])*(tA[0]-AA[0])),v=Math.abs((tA[0]-AA[0])*(BA[1]-AA[1])-(tA[1]-AA[1])*(BA[0]-AA[0]));return Math.abs(eA+K+v-sA)<=Math.max(Lo,sA*1e-8)},"pointInTri"),$=Array.from({length:f.length},(oA,_)=>_);L($)<0&&$.reverse();const T=[];let H=0;for(;$.length>3&&H++<f.length*f.length*4;){let oA=!1;for(let _=0;_<$.length;_++){const V=$[(_-1+$.length)%$.length],O=$[_],AA=$[(_+1)%$.length];if(x(V,O,AA)<=Lo)continue;let BA=!1;for(const rA of $)if(!(rA===V||rA===O||rA===AA)&&J(rA,V,O,AA)){BA=!0;break}if(!BA){T.push([f[V],f[O],f[AA]]),$.splice(_,1),oA=!0;break}}if(!oA)break}if($.length===3&&T.push([f[$[0]],f[$[1]],f[$[2]]]),T.length)return T;const X=[];for(let oA=1;oA+1<f.length;oA++)X.push([f[0],f[oA],f[oA+1]]);return X},"triangulateLoop"),M=r(f=>{const F=i._vertProperties.length/3|0;return i._vertProperties.push(f[0],f[1],f[2]),i._vertKeyToIndex?.set?.(`${f[0]},${f[1]},${f[2]}`,F),F},"addVertex");let y=0;const p=Number(A)>>>0;for(const f of E){if(f.length<3)continue;let F=0;for(let G=0;G<f.length;G++){const N=f[G],S=f[(G+1)%f.length],Y=B.get(hr(N,S));Y&&Y[0]===N&&Y[1]===S&&(F+=1)}const m=F>=f.length/2;for(const G of u(f)){const N=G[0]>>>0,S=G[1]>>>0,Y=G[2]>>>0;N===S||S===Y||Y===N||(m?i._triVerts.push(Y,S,N):i._triVerts.push(N,S,Y),i._triIDs.push(p),y+=1)}}for(const f of D){const F=Array.from(new Set(f.flatMap(([N,S])=>[N,S])));if(F.length<3)continue;const m=[0,0,0];for(const N of F)m[0]+=t[N*3+0],m[1]+=t[N*3+1],m[2]+=t[N*3+2];m[0]/=F.length,m[1]/=F.length,m[2]/=F.length;const G=M(m);for(const[N,S]of f){const Y=B.get(hr(N,S))||[N,S],R=Y[0]>>>0,k=Y[1]>>>0;R===k||R===G||k===G||(i._triVerts.push(k,R,G),i._triIDs.push(p),y+=1)}}return y>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)),y}c(Zf,"HN");r(Zf,"fillBoundaryLoopsWithTriangles");function _Re(i,A,e){const t=`${A}_INTERSECTION_CAP`;let g=i?._faceNameToID instanceof Map?i._faceNameToID.get(t):null;return!g&&typeof i?._getOrCreateID=="function"&&(g=i._getOrCreateID(t)),g&&i?._faceMetadata instanceof Map&&i._faceMetadata.set(t,{type:"intersection_cap",sourceFaceName:A,distance:e}),g||null}c(_Re,"Igt");r(_Re,"getOrCreateIntersectionCapFaceID");function xEt(i,A,e,t,g){const o=Array.isArray(i?._triVerts)?i._triVerts:[],s=Array.isArray(i?._vertProperties)?i._vertProperties:[],I=Array.isArray(i?._triIDs)?i._triIDs:[],n=Array.isArray(A?.vertices)?A.vertices:[],B=Array.isArray(A?.vertexNormals)?A.vertexNormals:[],C=Array.isArray(A?.triangles)?A.triangles:[],a=o.length/3|0;if(!a||I.length<a||!n.length||!C.length)return 0;const Q=Number(t?.faceNameToID?.get?.(t?.labels?.start))>>>0,E=Number(t?.faceNameToID?.get?.(t?.labels?.end))>>>0;if(!Q||!E)return 0;const l=n.map((m,G)=>{const N=B[G];return m&&N?m.clone().add(N.clone().multiplyScalar(e)):null}),h=new Map,w=new Map,d=r((m,G,N)=>{const S=Number(G)>>>0;if(!S||!Array.isArray(N))return;let Y=m.get(S);Y||(Y=[],m.set(S,Y)),Y.push(N)},"addRef");for(const m of C){const G=m?.[0]>>>0,N=m?.[1]>>>0,S=m?.[2]>>>0;if(!n[G]||!n[N]||!n[S])continue;const Y=sv(t,m,"start")||Q,R=sv(t,m,"end")||E;d(h,Y,[n[G],n[N],n[S]]),l[G]&&l[N]&&l[S]&&d(w,R,[l[G],l[N],l[S]])}if(!h.size||!w.size)return 0;const D=Math.max(Number(g)||0,1e-7),u=D*D,M=new W,y=r((m,G)=>{let N=1/0;for(const[S,Y,R]of G){const k=FEt(m,S,Y,R);if(k<N&&(N=k,N<=u))break}return N},"pointDistanceToSurfaceSq"),p=r((m,G)=>{let N=0;for(let S=0;S<3;S++){const Y=(o[m*3+S]>>>0)*3;M.set(Number(s[Y+0])||0,Number(s[Y+1])||0,Number(s[Y+2])||0);const R=y(M,G);if(R>N&&(N=R),N>u)break}return N},"triangleMaxDistanceSq"),f=r((m,G)=>{let N=0,S=1/0;for(const[Y,R]of G.entries()){const k=p(m,R);if(k<S&&(S=k,N=Number(Y)>>>0,S<=u))break}return{faceID:N,distanceSq:S}},"bestFaceIDForTriangle");let F=0;for(let m=0;m<a;m++){const G=f(m,h),N=G.distanceSq<=u?{faceID:0,distanceSq:1/0}:f(m,w),S=G.distanceSq<=u?G.faceID:N.distanceSq<=u?N.faceID:0;S&&I[m]!==S&&(I[m]=S,F+=1)}return F>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null),F}c(xEt,"yKt");r(xEt,"reclassifyThickenCapTrianglesByGeometry");function JEt(i,A,e){const t=_Re(i,A,e);return t?Zf(i,t):0}c(JEt,"pKt");r(JEt,"fillIntersectionCapBoundaryLoops");function m8(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=Array.isArray(i?._triIDs)?i._triIDs:[],g=A.length/3|0;if(!g||t.length<g)return 0;const o=new Map,s=r((w,d,D)=>{const u=hr(w,d);let M=o.get(u);M||(M=[],o.set(u,M)),M.push(D)},"addUse");for(let w=0;w<g;w++){const d=A[w*3+0]>>>0,D=A[w*3+1]>>>0,u=A[w*3+2]>>>0;s(d,D,w),s(D,u,w),s(u,d,w)}const I=new Uint8Array(g);for(const w of o.values())if(!(w.length<=2))for(const d of w)I[d]=1;let n=0;for(let w=0;w<g;w++)I[w]&&(n+=1);if(!n)return 0;const B=e.length/3|0,C=new Uint8Array(B),a=[],Q=[];for(let w=0;w<g;w++){if(I[w])continue;const d=A[w*3+0]>>>0,D=A[w*3+1]>>>0,u=A[w*3+2]>>>0;a.push(d,D,u),Q.push(t[w]),C[d]=1,C[D]=1,C[u]=1}const E=new Int32Array(B);E.fill(-1);const l=[];let h=0;for(let w=0;w<B;w++)C[w]&&(E[w]=h++,l.push(e[w*3+0],e[w*3+1],e[w*3+2]));for(let w=0;w<a.length;w++)a[w]=E[a[w]>>>0];i._vertProperties=l,i._triVerts=a,i._triIDs=Q,i._vertKeyToIndex=new Map;for(let w=0;w<l.length;w+=3)i._vertKeyToIndex.set(`${l[w]},${l[w+1]},${l[w+2]}`,w/3|0);return i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i),n}c(m8,"l3");r(m8,"cullTrianglesTouchingNonManifoldEdges");function sYA(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=Array.isArray(i?._triIDs)?i._triIDs:[],g=A.length/3|0;if(!g||t.length<g)return 0;const o=new Map,s=r((d,D,u)=>{const M=hr(d,D);let y=o.get(M);y||(y=[],o.set(M,y)),y.push({triIndex:u,a:d,b:D})},"addUse");for(let d=0;d<g;d++){const D=A[d*3+0]>>>0,u=A[d*3+1]>>>0,M=A[d*3+2]>>>0;s(D,u,d),s(u,M,d),s(M,D,d)}const I=new Uint16Array(g);for(const d of o.values())d.length===2&&d[0].a===d[1].a&&d[0].b===d[1].b&&(I[d[0].triIndex]+=1,I[d[1].triIndex]+=1);let n=-1,B=0;for(let d=0;d<g;d++){const D=I[d]||0;if(!D)continue;const u=(i._idToFaceName instanceof Map?String(i._idToFaceName.get(t[d])||""):"").includes("INTERSECTION_CAP")?100:0,M=D+u;M>B&&(B=M,n=d)}if(n<0)return 0;const C=e.length/3|0,a=new Uint8Array(C),Q=[],E=[];for(let d=0;d<g;d++){if(d===n)continue;const D=A[d*3+0]>>>0,u=A[d*3+1]>>>0,M=A[d*3+2]>>>0;Q.push(D,u,M),E.push(t[d]),a[D]=1,a[u]=1,a[M]=1}const l=new Int32Array(C);l.fill(-1);const h=[];let w=0;for(let d=0;d<C;d++)a[d]&&(l[d]=w++,h.push(e[d*3+0],e[d*3+1],e[d*3+2]));for(let d=0;d<Q.length;d++)Q[d]=l[Q[d]>>>0];i._vertProperties=h,i._triVerts=Q,i._triIDs=E,i._vertKeyToIndex=new Map;for(let d=0;d<h.length;d+=3)i._vertKeyToIndex.set(`${h[d]},${h[d+1]},${h[d+2]}`,d/3|0);return i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i),1}c(sYA,"ZnA");r(sYA,"cullTrianglesTouchingSameDirectionEdges");function HEt(i,A={}){const e=String(A.sourceFaceName||"").trim()||"FACE",t=Number(A.distance)||0,g=Math.max(Number(A.manifoldWeldEpsilon)||0,0),o=Math.max(0,Number.isFinite(Number(A.nonManifoldCullMaxTriangles))?Number(A.nonManifoldCullMaxTriangles):1e4),s=Math.max(1,Math.min(512,Number.isFinite(Number(A.maxPasses))?Number(A.maxPasses)|0:256)),I={orientedTriangleCount:0,orientationCulledTriangleCount:0,orientationCapTriangleCount:0,nonManifoldCulledTriangleCount:0,boundaryCapTriangleCount:0,weldedVertexCount:0,degenerateTriangleCount:0},n=r(()=>{try{return typeof i?._isCoherentlyOrientedManifold=="function"?i._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}},"isCoherent"),B=r(()=>{const a=wl(i,g);I.weldedVertexCount+=a.weldedVertexCount||0,I.degenerateTriangleCount+=a.removedTriangleCount||0},"weld");for(let a=0;a<s;a++){let Q=wI(i),E=!1;if(Q.nonManifoldEdgeCount>0&&(Q.triangleCount||0)<=o){const w=m8(i);w>0&&(I.nonManifoldCulledTriangleCount+=w,E=!0,B(),Q=wI(i))}if(Q.boundaryEdgeCount>0){const w=JEt(i,e,t);if(w>0){I.boundaryCapTriangleCount+=w,I.orientationCapTriangleCount+=w,E=!0;try{i.fixTriangleWindingsByAdjacency?.()}catch{}B(),Q=wI(i)}}if(Q.boundaryEdgeCount||Q.nonManifoldEdgeCount){if(!E)return{ok:!1,topology:Q,orientation:jG(i),stats:I};continue}const l=QG(i)+EG(i);if(l>0){I.orientedTriangleCount+=l;try{i.fixTriangleWindingsByAdjacency?.()}catch{}}if(n())return{ok:!0,topology:wI(i),orientation:jG(i),stats:I};const h=sYA(i);if(!(h>0))return{ok:!1,topology:Q,orientation:jG(i),stats:I};if(I.orientationCulledTriangleCount+=h,E=!0,B(),!E)break}const C=wI(i);return{ok:C.boundaryEdgeCount===0&&C.nonManifoldEdgeCount===0&&n(),topology:C,orientation:jG(i),stats:I}}c(HEt,"FKt");r(HEt,"repairSolidOrientationByCullAndCap");function Dae(i,A={}){if(!i||typeof i.clone!="function")return null;let e=null;try{e=i.clone();try{e.name=i.name}catch{}const t=HEt(e,A),g=t?.topology||wI(e),o=(()=>{try{return typeof e._isCoherentlyOrientedManifold=="function"?e._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}})();if(t?.ok===!0&&g.boundaryEdgeCount===0&&g.nonManifoldEdgeCount===0&&o)return{solid:e,topology:g,stats:t.stats||{}}}catch{}try{e?.free?.()}catch{}return null}c(Dae,"LPe");r(Dae,"tryRepairCoherentOrientationCandidate");function vEt(i){let A=0;const e=r(t=>{const g=Array.isArray(i?._triVerts)?i._triVerts:[],o=Array.isArray(i?._vertProperties)?i._vertProperties:[],s=Array.isArray(i?._triIDs)?i._triIDs:[],I=g.length/3|0,n=o.length/3|0,B=new Uint8Array(n),C=[],a=[];for(let h=0;h<I;h++){if(t[h])continue;const w=g[h*3+0]>>>0,d=g[h*3+1]>>>0,D=g[h*3+2]>>>0;C.push(w,d,D),a.push(s[h]),B[w]=1,B[d]=1,B[D]=1}const Q=new Int32Array(n);Q.fill(-1);const E=[];let l=0;for(let h=0;h<n;h++)B[h]&&(Q[h]=l++,E.push(o[h*3+0],o[h*3+1],o[h*3+2]));for(let h=0;h<C.length;h++)C[h]=Q[C[h]>>>0];i._vertProperties=E,i._triVerts=C,i._triIDs=a,i._vertKeyToIndex=new Map;for(let h=0;h<E.length;h+=3)i._vertKeyToIndex.set(`${E[h]},${E[h+1]},${E[h+2]}`,h/3|0);i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)},"rebuildWithout");for(let t=0;t<256;t++){const g=Array.isArray(i?._triVerts)?i._triVerts:[],o=Array.isArray(i?._triIDs)?i._triIDs:[],s=g.length/3|0;if(!s||o.length<s)break;const I=new Map,n=[];for(let Q=0;Q<s;Q++){const E=g[Q*3+0]>>>0,l=g[Q*3+1]>>>0,h=g[Q*3+2]>>>0,w=[hr(E,l),hr(l,h),hr(h,E)];n.push(w);for(const d of w)I.set(d,(I.get(d)||0)+1)}let B=0;for(const Q of I.values())Q>2&&(B+=1);if(!B)break;let C=null;for(let Q=0;Q<s;Q++){const E=n[Q];if(E.some(d=>(I.get(d)||0)<=1))continue;let l=0;for(const d of E)l+=Math.max(0,(I.get(d)||0)-2);if(!(l>0))continue;const h=(i._idToFaceName instanceof Map?String(i._idToFaceName.get(o[Q])||""):"").includes("INTERSECTION_CAP")?1e3:0,w={triIndex:Q,score:l+h};(!C||w.score>C.score)&&(C=w)}if(!C)break;const a=new Uint8Array(s);a[C.triIndex]=1,e(a),A+=1}return A}c(vEt,"mKt");r(vEt,"pruneOverusedTriangles");function TEt(i,A={}){if(!i)return null;const e=Math.max(1,Math.min(8,Number.isFinite(Number(A.triangleCullPasses))?Number(A.triangleCullPasses)|0:1)),t={snapTolerance:A.splitSnapTolerance??A.snapTolerance,diagnostics:A.splitDiagnostics===!0||A.diagnostics===!0};(!Number.isFinite(Number(t.snapTolerance))||Number(t.snapTolerance)<=0)&&delete t.snapTolerance;let g=0,o=0,s=0,I=0,n=0;const B=Math.max(Number(A.weldTolerance??A.manifoldWeldTolerance)||0,0);for(let a=0;a<e;a++){n=a+1;const Q=Number(A.precomputedTriangleSplitProbeCount),E=A.skipTriangleSplit===!0?a===0?Number.isFinite(Q)&&Q>=0?Q:Number(i.splitSelfIntersectingTriangles?.({...t,probeOnly:!0,maxIntersections:1})||0):0:Number(i.splitSelfIntersectingTriangles?.(t)||0);E>0&&A.skipTriangleSplit!==!0&&hw(i),g+=E;const l=Number(i.removeDegenerateTriangles?.()||0);l>0&&hw(i),s+=l;const h=wl(i,B);I+=h.weldedVertexCount||0,s+=h.removedTriangleCount||0;const w=(i?._triVerts?.length||0)/3|0,d=Math.max(0,Number.isFinite(Number(A.windingCullMaxTriangles))?Number(A.windingCullMaxTriangles):1e4),D=w>0&&w<=d?"winding":"raycast",u=String(A.internalCullMethod||D).toLowerCase(),M=A.skipInternalCull===!0?0:Number(u==="winding"?i.removeInternalTrianglesByWinding?.(A.windingOptions||{})||0:KEt(i,A.raycastCullOptions||{})||0);M>0&&hw(i),o+=M;const y=Number(i.removeDegenerateTriangles?.()||0);y>0&&hw(i),s+=y;const p=wl(i,B);if(I+=p.weldedVertexCount||0,s+=p.removedTriangleCount||0,E===0&&M===0)break}try{i.fixTriangleWindingsByAdjacency?.()}catch{}const C=wI(i);return{splitCount:g,culledTriangleCount:o,degenerateTriangleCount:s,weldedVertexCount:I,passCount:n,topology:C}}c(TEt,"NKt");r(TEt,"triangleSplitCullSolid");function PEt(i,A,e,t){let g=null;try{g=typeof A?.getMetadata=="function"&&A.getMetadata()||null}catch{g=null}if(!(!g||typeof i?.setFaceMetadata!="function"))try{i.setFaceMetadata(e.start,{...g,type:"start_cap",sourceFaceName:t,sourceFeatureId:A?.owningFeatureID??A?.parentSolid?.owningFeatureID??g?.sourceFeatureId??null}),i.setFaceMetadata(e.end,{...g,type:"end_cap",sourceFaceName:t,sourceFeatureId:A?.owningFeatureID??A?.parentSolid?.owningFeatureID??g?.sourceFeatureId??null})}catch{}}c(PEt,"SKt");r(PEt,"applySourceFaceMetadataToThickenResult");function OEt(i,A){const e=Number(A);if(!(e<0))return!1;const t=Array.isArray(i?.vertices)?i.vertices:[],g=Array.isArray(i?.vertexNormals)?i.vertexNormals:[];if(t.length<3||g.length<t.length)return!1;const o=new W,s=new W;let I=0;for(let B=0;B<t.length;B++){const C=t[B],a=g[B];!C||!a||!(a.lengthSq?.()>Lo)||(s.add(C),o.add(a),I+=1)}if(I<3||(s.multiplyScalar(1/I),o.length()/I>.35))return!1;let n=1/0;for(let B=0;B<t.length;B++){const C=t[B],a=g[B];if(!C||!a||!(a.lengthSq?.()>Lo))continue;const Q=C.clone().sub(s).dot(a);Q>Lo&&Q<n&&(n=Q)}return Number.isFinite(n)?Math.abs(e)>=n*.95:!1}c(OEt,"GKt");r(OEt,"shouldSkipArrangementSplitForSelfOverlappingSurface");function jEt(i,A,e,t={},g=null){if(!(Number(e)>0))return{skip:!1,reason:"",splitProbeCount:0};if(!i||typeof i.splitSelfIntersectingTriangles!="function")return{skip:!1,reason:"",splitProbeCount:0};const o=Array.isArray(A?.loops)?A.loops:[];if(!o.length)return{skip:!1,reason:"",splitProbeCount:0};const s=g||wI(i);if(s.boundaryEdgeCount||s.nonManifoldEdgeCount)return{skip:!1,reason:"",splitProbeCount:0};try{if(typeof i._isCoherentlyOrientedManifold=="function"&&i._isCoherentlyOrientedManifold()!==!0)return{skip:!1,reason:"",splitProbeCount:0}}catch{return{skip:!1,reason:"",splitProbeCount:0}}const I=Math.max(Array.isArray(A?.boundaryDirectedEdges)?A.boundaryDirectedEdges.length:0,o.reduce((E,l)=>E+(Array.isArray(l?.edges)?l.edges.length:0),0)),n=Math.max(16,Math.min(512,I*2||64)),B={probeOnly:!0,maxIntersections:n+1},C=t.splitSnapTolerance??t.snapTolerance;Number.isFinite(Number(C))&&Number(C)>0&&(B.snapTolerance=Number(C));let a=null,Q=0;try{a=typeof i.clone=="function"?i.clone():null,Q=Number(a?a.splitSelfIntersectingTriangles(B)||0:i.splitSelfIntersectingTriangles({...B,maxIntersections:1})||0)}finally{try{a?.free?.()}catch{}}return Q>n?{skip:!1,reason:"",splitProbeCount:Q}:{skip:!0,reason:Q>0?"preserve_exact_closed_shell":"closed_shell_without_intersections",splitProbeCount:Q}}c(jEt,"RKt");r(jEt,"shouldPreserveExactClosedOffsetShell");function NG(i,A,e,t={}){const g=Number(e);if(!Number.isFinite(g)||Math.abs(g)<=dae)throw new Error("Face.thicken() requires a non-zero finite distance.");if(!i||!Array.isArray(i.triangles)||!i.triangles.length)throw new Error("Face.thicken() requires a non-empty source triangle surface.");const o=nzA(t.featureId||t.name||A?.name||"THICKEN","THICKEN"),s=String(t.sourceFaceName||A?.userData?.faceName||A?.name||o).trim()||o,I=Array.isArray(t.sourceFaceNames)?t.sourceFaceNames.map(p=>String(p||"").trim()).filter(Boolean):[s],n=I.length?I:[s],B=new Map;for(const p of n){const f=String(p||"").trim();!f||B.has(f)||B.set(f,{start:`${f}_START`,end:`${f}_END`})}const C=B.get(s)||B.values().next().value||{start:`${s}_START`,end:`${s}_END`},a=Array.isArray(i.loops)?i.loops:[],Q={sourceFaceName:s,start:C.start,end:C.end,startCaps:Array.from(B.entries(),([p,f])=>({label:f.start,sourceFaceName:p})),endCaps:Array.from(B.entries(),([p,f])=>({label:f.end,sourceFaceName:p})),capLabelsBySourceFaceName:B,sidewalls:a.flatMap((p,f)=>(Array.isArray(p?.edges)?p.edges:[]).map((F,m)=>{const G=String(F?.sourceEdgeName||"").trim(),N=G?nzA(G,`EDGE_${f}_${m}`).replace(/_+$/g,""):null;return{key:F.key,loopIndex:f,edgeIndex:m,sourceEdgeName:G||null,sourceEdgeKey:F?.sourceEdgeKey||null,label:N?`${N}_SW`:f===0?`${s}_E${m}_SW`:`${s}_L${f}_E${m}_SW`}}))},E=REt(Q,g),l=String(t.name||o).trim()||o,h=Math.max(Number(t.manifoldWeldTolerance)||0,Math.max(i.weldTolerance||0,i.scale*1e-7,1e-6)),w=Math.max(0,Number.isFinite(Number(t.orientationRepairDistanceLimit))?Number(t.orientationRepairDistanceLimit):2),d=Math.abs(g)<=w,D=t.trianglePrismUnion===!0,u=t.repairBoundaryCaps!==!1,M=Array.isArray(i.triangles)?i.triangles.length:0;let y=null;try{const p=r(()=>{if(t.__skipInternalCullRetry===!0||t.skipInternalCull===!0||!d)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,skipInternalCull:!0,__skipInternalCullRetry:!0})}catch{return null}},"retryWithoutInternalCull"),f=r(()=>{if(t.__relaxedWeldRetry===!0||!d)return null;const sA=Math.min(1e-4,Math.max(i.scale*1e-5,1e-8)),eA=Math.max(h*16,i.scale*1e-6,sA);if(Number(t.manifoldWeldTolerance)>=eA*.95)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,skipInternalCull:!0,manifoldWeldTolerance:eA,__relaxedWeldRetry:!0})}catch{return null}},"retryWithRelaxedWeld"),F=r(()=>{if(t.__raycastMajorityRetry===!0)return null;try{y?.free?.()}catch{}return y=null,NG(i,A,g,{...t,internalCullMethod:"raycast",raycastCullOptions:{...t.raycastCullOptions||{},axes:"majority"},__raycastMajorityRetry:!0})},"retryWithRaycastMajority"),m=r(()=>{if(t.__skipTriangleSplitRetry===!0||t.skipTriangleSplit===!0)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,skipTriangleSplit:!0,__skipTriangleSplitRetry:!0})}catch{return null}},"retryWithoutTriangleSplit"),G=r((sA="destructive_repair")=>{if(t.__trianglePrismUnionRetry===!0||D)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,trianglePrismUnion:!0,repairBoundaryCaps:!1,nonManifoldCullMaxTriangles:0,__trianglePrismUnionRetry:!0,__trianglePrismUnionReason:sA})}catch{return null}},"retryWithTrianglePrismUnion"),N=r(()=>_Re(y,s,g),"getBoundaryRepairFaceID");if(y=D?bEt(i,g,E,l):kEt(i,g,E,l),!y)throw new Error("Face.thicken() failed to build the stitched triangle shell.");let S=wI(y);const Y=t.skipTriangleSplit!==!0&&t.skipTriangleSplit!==!1&&!D?jEt(y,i,g,t,S):{skip:!1,reason:"",splitProbeCount:0},R=t.skipTriangleSplit!==!1&&OEt(i,g),k=t.skipTriangleSplit===!0||Y.skip===!0||R,b=t.skipTriangleSplit===!0?"option":Y.reason||(R?"self_overlap_surface":""),L=TEt(y,{...t,skipTriangleSplit:k,precomputedTriangleSplitProbeCount:Y.skip===!0?Y.splitProbeCount:void 0,weldTolerance:h});S=L?.topology||wI(y);let x=0,J=0;const $=Math.max(0,Number.isFinite(Number(t.nonManifoldCullMaxTriangles))?Number(t.nonManifoldCullMaxTriangles):1e4);for(let sA=0;sA<8&&S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$;sA++){const eA=m8(y);if(!(eA>0))break;J+=eA;const K=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y)}if(S.nonManifoldEdgeCount===0&&S.boundaryEdgeCount>0)try{y.removeDegenerateTriangles?.(),S=wI(y)}catch{}if(u&&S.boundaryEdgeCount>0){const sA=N();if(sA&&(x=Zf(y,sA),x>0)){try{y.fixTriangleWindingsByAdjacency?.()}catch{}const eA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(eA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(eA.removedTriangleCount||0),S=wI(y)}}for(let sA=0;sA<16;sA++){let eA=!1;if(S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const K=m8(y);if(K>0){J+=K;const v=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(v.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(v.removedTriangleCount||0),S=wI(y),eA=!0}}if(u&&S.boundaryEdgeCount>0){const K=N();if(K){const v=Zf(y,K);if(v>0){x+=v;try{y.fixTriangleWindingsByAdjacency?.()}catch{}const iA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(iA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(iA.removedTriangleCount||0),S=wI(y),eA=!0}}}if(!eA)break}let T=S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0?QG(y):0;S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0&&(T+=EG(y));let H=0,X=0,oA=!1;if(T>0)try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0&&d&&typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0)for(let sA=0;sA<8;sA++){const eA=sYA(y);if(!(eA>0))break;if(H+=eA,S=wI(y),u&&S.boundaryEdgeCount>0){const v=N();if(v){const iA=Zf(y,v);iA>0&&(X+=iA,x+=iA)}}const K=wl(y,h);if(L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y),S.boundaryEdgeCount||S.nonManifoldEdgeCount)break;T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(y._isCoherentlyOrientedManifold()===!0)break}for(let sA=0;sA<8;sA++){let eA=!1;if(S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const K=m8(y);K>0&&(J+=K,eA=!0)}if(S=wI(y),u&&S.boundaryEdgeCount>0){const K=N();if(K){const v=Zf(y,K);v>0&&(x+=v,eA=!0)}}if(eA){const K=wl(y,h);if(L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y),S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0){T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}}}if(!eA)break}if(S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const sA=vEt(y);if(sA>0){if(J+=sA,S=wI(y),u&&S.boundaryEdgeCount>0){const eA=N();if(eA){const K=Zf(y,eA);K>0&&(x+=K,S=wI(y))}}if(S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0){T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}}}}if(t.__raycastMajorityRetry!==!0&&d)for(let sA=0;sA<128;sA++){if(S=wI(y),S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const v=m8(y);if(v>0){J+=v;const iA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(iA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(iA.removedTriangleCount||0),S=wI(y)}}if(u&&S.boundaryEdgeCount>0){const v=N();if(v){const iA=Zf(y,v);if(iA>0){x+=iA;const QA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(QA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(QA.removedTriangleCount||0),S=wI(y)}}}if(S.boundaryEdgeCount||S.nonManifoldEdgeCount)break;T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(typeof y._isCoherentlyOrientedManifold!="function"||y._isCoherentlyOrientedManifold()===!0)break;const eA=sYA(y);if(!(eA>0))break;H+=eA;const K=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0)}if(S=wI(y),S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0&&d&&typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0){const sA=Dae(y,{sourceFaceName:s,distance:g,manifoldWeldEpsilon:h,nonManifoldCullMaxTriangles:$,maxPasses:t.orientationRepairMaxPasses});if(sA?.solid){const eA=y;y=sA.solid;try{eA?.free?.()}catch{}S=sA.topology||wI(y);const K=sA.stats||{};T+=K.orientedTriangleCount||0,H+=K.orientationCulledTriangleCount||0,X+=K.orientationCapTriangleCount||0,x+=K.boundaryCapTriangleCount||0,J+=K.nonManifoldCulledTriangleCount||0,L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.degenerateTriangleCount||0),oA=!0}}const _=!D&&x>Math.max(1e4,M*100),V=!D&&J>Math.max(1e4,M*100);if(_||V){const sA=G(_?"excessive_boundary_caps":"excessive_nonmanifold_cull");if(sA)return sA;throw new Error(`Face.thicken() triangle split/cull required excessive topology repair (boundaryCaps=${x}, nonManifoldCull=${J}, sourceTriangles=${M}).`)}if(S.boundaryEdgeCount||S.nonManifoldEdgeCount){const sA=G("invalid_stitched_topology");if(sA)return sA;const eA=m();if(eA)return eA;const K=p();if(K)return K;const v=f();if(v)return v;const iA=F();if(iA)return iA;throw new Error(`Face.thicken() triangle split/cull produced invalid topology: boundaries=${S.boundaryEdgeCount}, nonManifold=${S.nonManifoldEdgeCount}, triangles=${S.triangleCount||0}.`)}let O=typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0,AA=O?jG(y):null;if(O&&S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0){const sA=Dae(y,{sourceFaceName:s,distance:g,manifoldWeldEpsilon:h,nonManifoldCullMaxTriangles:$,maxPasses:t.orientationRepairMaxPasses});if(sA?.solid){const eA=y;y=sA.solid;try{eA?.free?.()}catch{}S=sA.topology||wI(y);const K=sA.stats||{};T+=K.orientedTriangleCount||0,H+=K.orientationCulledTriangleCount||0,X+=K.orientationCapTriangleCount||0,x+=K.boundaryCapTriangleCount||0,J+=K.nonManifoldCulledTriangleCount||0,L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.degenerateTriangleCount||0),oA=!0,O=typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0,AA=O?jG(y):null}}if(O&&S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0)for(let sA=0;sA<32;sA++){const eA=sYA(y);if(!(eA>0))break;if(H+=eA,S=wI(y),u&&S.boundaryEdgeCount>0){const v=N();if(v){const iA=Zf(y,v);iA>0&&(X+=iA,x+=iA)}}const K=wl(y,h);if(L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y),S.boundaryEdgeCount||S.nonManifoldEdgeCount)break;T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(O=typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0,AA=O?jG(y):null,!O)break}if(O&&t.__raycastMajorityRetry!==!0&&d){const sA=p();if(sA)return sA;const eA=f();if(eA)return eA;const K=F();if(K)return K;throw new Error(`Face.thicken() triangle split/cull produced a non-coherently-oriented manifold result: sameDirection=${AA.sameDirectionEdgeCount}, ambiguous=${AA.ambiguousEdgeCount}.`)}const BA=Math.max(h*64,Math.abs(g)*1e-5,i.scale*1e-5,1e-6),rA=xEt(y,i,g,E,BA);PEt(y,A,Q,s),y.__thickenMethod="triangle_split_cull",y.__thickenClassificationMethod="raw_face_ids",y.__thickenDiagnostics={boundaryLoopCount:a.length,sourceTriangleCount:Array.isArray(i.triangles)?i.triangles.length:0,sourceFaceCount:I.length,sourceFaceNames:I,resultTriangleCount:(y._triVerts?.length||0)/3|0,sourceFaceName:s,distance:g,classificationMethod:"raw_face_ids",buildMethod:y.__thickenMethod,constructionMethod:D?"triangle_prism_union":"stitched_shell",trianglePrismUnionRetry:t.__trianglePrismUnionRetry===!0,trianglePrismUnionReason:t.__trianglePrismUnionReason||"",repairBoundaryCapsEnabled:u,weldEpsilon:h,triangleSplitCount:L?.splitCount||0,triangleSplitSkipped:k,triangleSplitSkipReason:b,triangleSplitProbeCount:Y.splitProbeCount||0,culledTriangleCount:L?.culledTriangleCount||0,internalTriangleCullSkipped:t.skipInternalCull===!0,internalTriangleCullRetry:t.__skipInternalCullRetry===!0,relaxedWeldRetry:t.__relaxedWeldRetry===!0,degenerateTriangleCount:L?.degenerateTriangleCount||0,weldedVertexCount:L?.weldedVertexCount||0,orientedTriangleCount:T,orientationCulledTriangleCount:H,orientationCapTriangleCount:X,orientationCandidateRepairAccepted:oA,orientationRepairDistanceLimit:w,orientationWarning:O,orientationSameDirectionEdgeCount:AA?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:AA?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:rA,nonManifoldCulledTriangleCount:J,boundaryCapTriangleCount:x,splitCullPasses:L?.passCount||0,adjacentBoundaryNormalContributionCount:i.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:i.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalCandidateEdgeCount:i.adjacentNormalStats?.candidateEdges||0,adjacentBoundaryNormalAcceptedEdgeCount:i.adjacentNormalStats?.acceptedEdges||0,adjacentBoundaryNormalDotThreshold:i.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalWeightScale:i.adjacentNormalStats?.weightScale??null,adjacentBoundaryNormalFaceFilterCount:i.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:i.adjacentNormalStats?.faceFilterNames||[]},y.userData={...y.userData||{},thicken:{sourceFaceName:s,sourceFaceNames:I,sourceFaceCount:I.length,distance:g,boundaryLoopCount:a.length,sourceTriangleCount:Array.isArray(i.triangles)?i.triangles.length:0,resultTriangleCount:(y._triVerts?.length||0)/3|0,classificationMethod:"raw_face_ids",buildMethod:y.__thickenMethod,weldEpsilon:h,triangleSplitCount:L?.splitCount||0,triangleSplitSkipped:k,triangleSplitSkipReason:b,triangleSplitProbeCount:Y.splitProbeCount||0,culledTriangleCount:L?.culledTriangleCount||0,internalTriangleCullSkipped:t.skipInternalCull===!0,internalTriangleCullRetry:t.__skipInternalCullRetry===!0,relaxedWeldRetry:t.__relaxedWeldRetry===!0,degenerateTriangleCount:L?.degenerateTriangleCount||0,weldedVertexCount:L?.weldedVertexCount||0,orientedTriangleCount:T,orientationCulledTriangleCount:H,orientationCapTriangleCount:X,orientationCandidateRepairAccepted:oA,orientationRepairDistanceLimit:w,orientationWarning:O,orientationSameDirectionEdgeCount:AA?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:AA?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:rA,nonManifoldCulledTriangleCount:J,boundaryCapTriangleCount:x,splitCullPasses:L?.passCount||0,adjacentBoundaryNormalContributionCount:i.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:i.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalDotThreshold:i.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalFaceFilterCount:i.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:i.adjacentNormalStats?.faceFilterNames||[]}};const tA=y;return y=null,tA}finally{try{y?.free?.()}catch{}}}c(NG,"tL");r(NG,"thickenSurfaceToSolid");function zEt(i,A,e={}){const t=zRe(i,e),g=String(e.sourceFaceName||i?.userData?.faceName||i?.name||"").trim();return NG(t,i,A,{...e,sourceFaceNames:Array.isArray(e.sourceFaceNames)?e.sourceFaceNames:g?[g]:void 0,sourceFaceName:g})}c(zEt,"YKt");r(zEt,"thickenFaceToSolid");function HbA(i,A,e={}){const t=Array.isArray(i)?i.filter(n=>n?.geometry):[];if(!t.length)throw new Error("Face.thicken() requires at least one face with geometry.");const g=t.map((n,B)=>String(n?.userData?.faceName||n?.name||`FACE_${B+1}`).trim()||`FACE_${B+1}`),o=nzA(e.featureId||e.name||g[0]||"THICKEN","THICKEN"),s=String(e.sourceFaceName||`${o}_PATCH`).trim()||`${o}_PATCH`,I=GEt(t,e);return NG(I,t[0],A,{...e,sourceFaceName:s,sourceFaceNames:g})}c(HbA,"U0A");r(HbA,"thickenFacesToSolid");var cW;const VEt=(cW=class extends Ig{constructor(A){super(A,Do.FACE.BASE),this.edges=[],this.name=null,this.type="FACE",this.renderOrder=1,this.parentSolid=null,Ps.attach(this)}getAverageNormal(){const A=this.geometry;if(!A)return new W(0,1,0);const e=A.getAttribute("position");if(!e||e.itemSize!==3||e.count<3)return new W(0,1,0);const t=A.getIndex(),g=new W,o=new W,s=new W,I=new W,n=new W,B=new W,C=r((a,Q)=>(a.set(e.getX(Q),e.getY(Q),e.getZ(Q)).applyMatrix4(this.matrixWorld),a),"toWorld");if(t){const a=t.count/3|0;for(let Q=0;Q<a;Q++){const E=t.getX(3*Q+0)>>>0,l=t.getX(3*Q+1)>>>0,h=t.getX(3*Q+2)>>>0;C(g,E),C(o,l),C(s,h),I.subVectors(o,g),n.subVectors(s,g),B.add(n.cross(I))}}else{const a=e.count/3|0;for(let Q=0;Q<a;Q++){const E=3*Q+0,l=3*Q+1,h=3*Q+2;C(g,E),C(o,l),C(s,h),I.subVectors(o,g),n.subVectors(s,g),B.add(n.cross(I))}}return B.lengthSq()===0?new W(0,1,0):B.normalize()}surfaceArea(){const A=this.geometry;if(!A)return 0;const e=A.getAttribute&&A.getAttribute("position");if(!e||e.itemSize!==3)return 0;const t=A.getIndex&&A.getIndex(),g=new W,o=new W,s=new W;let I=0;const n=r((B,C)=>B.set(e.getX(C),e.getY(C),e.getZ(C)).applyMatrix4(this.matrixWorld),"toWorld");if(t){const B=t.count/3|0;for(let C=0;C<B;C++){const a=t.getX(3*C+0)>>>0,Q=t.getX(3*C+1)>>>0,E=t.getX(3*C+2)>>>0;n(g,a),n(o,Q),n(s,E),I+=IzA(g.x,g.y,g.z,o.x,o.y,o.z,s.x,s.y,s.z)}}else{const B=e.count/3|0;for(let C=0;C<B;C++){const a=3*C+0,Q=3*C+1,E=3*C+2;n(g,a),n(o,Q),n(s,E),I+=IzA(g.x,g.y,g.z,o.x,o.y,o.z,s.x,s.y,s.z)}}return I}async points(A=!0){const e=new W,t=[],g=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(g&&g.itemSize===3&&g.count>=2)for(let o=0;o<g.count;o++)e.set(g.getX(o),g.getY(o),g.getZ(o)),A&&e.applyMatrix4(this.matrixWorld),t.push({x:e.x,y:e.y,z:e.z});return t}setMetadata(A){return this.parentSolid&&typeof this.parentSolid.setFaceMetadata=="function"&&this.parentSolid.setFaceMetadata(this.name,A),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getFaceMetadata=="function"?this.parentSolid.getFaceMetadata(this.name):null}renameFace(A){this.parentSolid.renameFace(this.name,A)}thicken(A,e={}){return zEt(this,A,e)}getNeighbors(){const A=this,e=A?.name||A?.userData?.faceName||null;if(!e)return[];const t=A.parentSolid||A.userData?.parentSolid||null,g=new Set,o=r(s=>{s&&s!==A&&g.add(s)},"addFace");if(Array.isArray(A.edges)){for(const s of A.edges)if(!(!s||!Array.isArray(s.faces)))for(const I of s.faces)o(I)}if(g.size===0&&t&&typeof t.getBoundaryEdgePolylines=="function"){const s=new Map;if(Array.isArray(t.children)){for(const I of t.children)if(I&&I.type==="FACE"){const n=I.name||I.userData?.faceName||null;n&&s.set(n,I)}}try{const I=t.getBoundaryEdgePolylines()||[];for(const n of I){const B=n?.faceA,C=n?.faceB;B===e&&C?o(s.get(C)):C===e&&B&&o(s.get(B))}}catch{}}return Array.from(g)}},c(cW,"rhe2"),cW);r(VEt,"Face");let qRe=VEt;const BzA=r(i=>{if(!i)return{};try{const A=JSON.parse(i);return A&&typeof A=="object"?A:{}}catch{return{}}},"parseMetadataJson"),oM=r((i=[])=>Array.from(i||[],A=>[A?.[0],A?.[1]]),"cloneSnapshotEntries"),AHA=r((i,A=e=>e)=>i instanceof Map?Array.from(i.entries(),([e,t])=>[e,A(t)]):[],"toPlainEntryArray"),w8e=r(i=>JSON.stringify(i&&typeof i=="object"?i:{}),"serializeMetadata"),pTi=r((i=[],A=3)=>{const e=new Map,t=Math.max(3,Number(A)||3);for(let g=0;g+2<i.length;g+=t){const o=i[g+0],s=i[g+1],I=i[g+2];e.set(`${o},${s},${I}`,g/t|0)}return e},"rebuildVertexKeyMap"),R5A=r(i=>({numProp:Number(i?._numProp??3),vertPropertiesRef:i?._vertProperties||null,vertPropertiesLength:Array.isArray(i?._vertProperties)?i._vertProperties.length:0,triVertsRef:i?._triVerts||null,triVertsLength:Array.isArray(i?._triVerts)?i._triVerts.length:0,triIDsRef:i?._triIDs||null,triIDsLength:Array.isArray(i?._triIDs)?i._triIDs.length:0,faceNameToIDRef:i?._faceNameToID||null,faceNameToIDSize:i?._faceNameToID instanceof Map?i._faceNameToID.size:0,idToFaceNameRef:i?._idToFaceName||null,idToFaceNameSize:i?._idToFaceName instanceof Map?i._idToFaceName.size:0,faceMetadataRef:i?._faceMetadata||null,faceMetadataSize:i?._faceMetadata instanceof Map?i._faceMetadata.size:0,edgeMetadataRef:i?._edgeMetadata||null,edgeMetadataSize:i?._edgeMetadata instanceof Map?i._edgeMetadata.size:0,auxEdgesRef:i?._auxEdges||null,auxEdgesLength:Array.isArray(i?._auxEdges)?i._auxEdges.length:0,faceMetadataVersion:Number(i?._faceMetadataVersion||0),edgeMetadataVersion:Number(i?._edgeMetadataVersion||0),dirty:!!i?._dirty}),"captureSolidCppSyncStamp"),fTi=r((i,A)=>!!i&&!!A&&i.numProp===A.numProp&&i.vertPropertiesRef===A.vertPropertiesRef&&i.vertPropertiesLength===A.vertPropertiesLength&&i.triVertsRef===A.triVertsRef&&i.triVertsLength===A.triVertsLength&&i.triIDsRef===A.triIDsRef&&i.triIDsLength===A.triIDsLength&&i.faceNameToIDRef===A.faceNameToIDRef&&i.faceNameToIDSize===A.faceNameToIDSize&&i.idToFaceNameRef===A.idToFaceNameRef&&i.idToFaceNameSize===A.idToFaceNameSize&&i.faceMetadataRef===A.faceMetadataRef&&i.faceMetadataSize===A.faceMetadataSize&&i.edgeMetadataRef===A.edgeMetadataRef&&i.edgeMetadataSize===A.edgeMetadataSize&&i.auxEdgesRef===A.auxEdgesRef&&i.auxEdgesLength===A.auxEdgesLength&&i.faceMetadataVersion===A.faceMetadataVersion&&i.edgeMetadataVersion===A.edgeMetadataVersion&&i.dirty===A.dirty,"solidCppSyncStampEquals"),YB=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.setAuthoringState=="function"&&typeof i.bakeTransform=="function"&&typeof i.getAuthoringState=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),ZRe=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.weldVerticesByEpsilon=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),WEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.pushFace=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),Y5A=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.prepareManifoldMesh=="function"&&typeof i.isCoherentlyOrientedManifold=="function"&&typeof i.fixTriangleWindingsByAdjacency=="function"&&typeof i.invertNormals=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),FTi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.normalizeFaceTracking=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),U5A=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.getFace=="function"&&typeof i.getFaces=="function"&&typeof i.getFaceNormal=="function"&&typeof i.getBoundaryEdgePolylines=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),mTi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.computeFilletCenterline=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),NTi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.addAuxEdge=="function"&&typeof i.getAuxEdges=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),_Et=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.transformMetadata=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),qEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.cleanupTinyFaceIslands=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),ZEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.removeSmallIslands=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),XEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.mergeTinyFaces=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),$Et=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.removeInternalTriangles=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),STi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.removeDisconnectedIslandsByVolume=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),mn=r((i,A)=>{if(!i)throw new Error(`${A} requires the custom local manifold build with BrepSolidCore support.`)},"requireCppSolidCoreCapability"),lC=r(i=>({numProp:Number(i?._numProp??3),vertProperties:Array.from(i?._vertProperties??[]),triVerts:Array.from(i?._triVerts??[]),triIDs:Array.from(i?._triIDs??[]),faceNameToID:AHA(i?._faceNameToID),idToFaceName:AHA(i?._idToFaceName),faceMetadataJson:AHA(i?._faceMetadata,w8e),edgeMetadataJson:AHA(i?._edgeMetadata,w8e),auxEdges:DO(i?._auxEdges)}),"buildSolidAuthoringStateSnapshot"),eHA=r(i=>new Map(oM(i)),"cloneSnapshotMapEntries"),GTi=r((i="INSET")=>String(i||"INSET").toUpperCase()==="OUTSET"?"OUTSET":"INSET","normalizeFilletSideMode$1"),Act=r(i=>{if(Array.isArray(i)&&i.length>=3){const A=Number(i[0]),e=Number(i[1]),t=Number(i[2]);return Number.isFinite(A)&&Number.isFinite(e)&&Number.isFinite(t)?[A,e,t]:null}if(i&&typeof i=="object"){const A=Number(i.x),e=Number(i.y),t=Number(i.z);if(Number.isFinite(A)&&Number.isFinite(e)&&Number.isFinite(t))return[A,e,t]}return null},"point3ArrayFromAny$1"),zG=r(i=>{const A=Act(i);return A?{x:A[0],y:A[1],z:A[2]}:null},"point3ObjectFromAny$1"),DO=r(i=>{const A=Array.isArray(i)?i:[],e=[];for(const t of A){const g=Array.isArray(t?.points)?t.points.map(B=>Act(B)).filter(Boolean):[];if(g.length<2)continue;const o={name:String(t?.name||"EDGE"),points:g,closedLoop:!!t?.closedLoop,polylineWorld:!!t?.polylineWorld,centerline:!!t?.centerline},s=String(t?.materialKey||"").trim();s&&(o.materialKey=s);const I=String(t?.faceA||"").trim(),n=String(t?.faceB||"").trim();I&&(o.faceA=I),n&&(o.faceB=n),e.push(o)}return e},"sanitizeAuxEdges$1"),RTi=r((i,A=1e-9)=>{const e=Array.isArray(i)?i:[];if(e.length===0)return[];const t=Number.isFinite(A)?Math.max(1e-12,Math.abs(A)):1e-9,g=t*t,o=[];for(let Q=0;Q<e.length;Q++){const E=e[Q];if(!Array.isArray(E)||E.length<3)continue;const l=Number(E[0]),h=Number(E[1]),w=Number(E[2]);!Number.isFinite(l)||!Number.isFinite(h)||!Number.isFinite(w)||o.push([l,h,w])}if(o.length===0)return[];const s=[];for(let Q=0;Q<o.length;Q++){const E=o[Q];if(s.length>0){const l=s[s.length-1],h=E[0]-l[0],w=E[1]-l[1],d=E[2]-l[2];if(h*h+w*w+d*d<=g)continue}s.push(E)}if(s.length<3)return s;let I=0,n=0;for(let Q=1;Q<s.length;Q++){const E=s[Q-1],l=s[Q],h=Math.hypot(l[0]-E[0],l[1]-E[1],l[2]-E[2]);!Number.isFinite(h)||h<=0||(I+=h,h>n&&(n=h))}const B=Math.max(t,I*1e-7,n*1e-6),C=B*B;if(C<=g)return s;const a=[];for(let Q=0;Q<s.length;Q++){const E=s[Q];if(a.length===0){a.push(E);continue}const l=a[a.length-1],h=E[0]-l[0],w=E[1]-l[1],d=E[2]-l[2];h*h+w*w+d*d<=C||a.push(E)}return a.length>=2?a:s},"sanitizeFilletInputPolyline$1"),YTi=r((i=[])=>{const A=new Map;for(const[e,t]of oM(i))A.set(t,e);return A},"invertFaceNameToIDEntries"),UTi=r(i=>{const A=Array.from(i?.triIDs??[]),e=new Set(A),t=Array.from(e).sort((o,s)=>Number(o)-Number(s));let g=new Map(oM(i?.idToFaceName));if(g.size===0&&(g=YTi(i?.faceNameToID)),t.every(o=>g.has(o))||t.length===0)return g;if(g.size===t.length){const o=Array.from(g.entries()).sort((I,n)=>Number(I[0])-Number(n[0])).map(I=>String(I?.[1]||"")),s=new Map;for(let I=0;I<t.length;I++)s.set(t[I],o[I]||`FACE_${t[I]}`);return s}for(const o of t)g.has(o)||g.set(o,`FACE_${o}`);return g},"buildResolvedSnapshotIDToFaceName"),kTi=r(i=>{const A=UTi(i),e=new Map,t=new Map,g=new Map,o=r((s,I="")=>{const n=Number(s);if(g.has(n))return g.get(n);const B=gD.reserveIDs(1);g.set(n,B);const C=String(A.get(s)??I??"").trim()||`FACE_${B}`;return t.set(B,C),e.set(C,B),B},"ensureReservedID");for(const[s,I]of A.entries())o(s,I);return{triIDs:Array.from(i?.triIDs??[],s=>o(s,A.get(s))),faceNameToID:e,idToFaceName:t}},"remapSnapshotFaceIDsToReservedRange"),sB=r((i,A,e={})=>{const t=Math.max(3,Number(A?.numProp??3)),g=Array.from(A?.vertProperties??[]);let o=null;if(e?.remapFaceIDs)if(FTi){const s=new Tt.BrepSolidCore;try{s.setAuthoringState(A),s.normalizeFaceTracking();const I=s.getAuthoringState();o={triIDs:Array.from(I?.triIDs??[]),faceNameToID:new Map(oM(I?.faceNameToID)),idToFaceName:new Map(oM(I?.idToFaceName))}}finally{typeof s.delete=="function"&&s.delete()}}else o=kTi(A);i._numProp=t,i._vertProperties=g,i._triVerts=Array.from(A?.triVerts??[]),i._triIDs=o?o.triIDs:Array.from(A?.triIDs??[]),i._faceNameToID=o?o.faceNameToID:new Map(oM(A?.faceNameToID)),i._idToFaceName=o?o.idToFaceName:new Map(oM(A?.idToFaceName)),i._faceMetadata=new Map(Array.from(A?.faceMetadataJson??[],s=>[s?.[0],BzA(s?.[1])])),i._edgeMetadata=new Map(Array.from(A?.edgeMetadataJson??[],s=>[s?.[0],BzA(s?.[1])])),i._auxEdges=DO(A?.auxEdges),i._vertKeyToIndex=pTi(g,t),i._faceMetadataVersion=Number(i?._faceMetadataVersion||0)+1,i._edgeMetadataVersion=Number(i?._edgeMetadataVersion||0)+1,i._cppSolidCoreSyncStamp=null},"applySolidAuthoringStateSnapshot"),jU=r((i,A)=>(A.setAuthoringState(lC(i)),i._cppSolidCoreSyncStamp=R5A(i),A),"syncSolidAuthoringStateToCpp"),yQ=r((i,A)=>{const e=A.getAuthoringState();return sB(i,e),i._cppSolidCoreSyncStamp=R5A(i),e},"syncSolidAuthoringStateFromCpp"),LTi=r((i,A)=>(i._auxEdges=A.getAuxEdges(),i._cppSolidCoreSyncStamp=R5A(i),i._auxEdges),"syncSolidAuxEdgesFromCpp"),eN=r(i=>{if(YB)try{return Ya(i).getAuthoringState()}catch{}const A=lC(i);return{numProp:Number(A?.numProp??3),vertProperties:Array.from(A?.vertProperties??[]),triVerts:Array.from(A?.triVerts??[]),triIDs:Array.from(A?.triIDs??[]),faceNameToID:eHA(A?.faceNameToID),idToFaceName:eHA(A?.idToFaceName),faceMetadataJson:eHA(A?.faceMetadataJson),edgeMetadataJson:eHA(A?.edgeMetadataJson),auxEdges:DO(A?.auxEdges),vertexCount:Math.floor((Array.isArray(A?.vertProperties)?A.vertProperties.length:0)/Math.max(3,Number(A?.numProp??3))),triangleCount:Math.floor((Array.isArray(A?.triVerts)?A.triVerts.length:0)/3)}},"getSolidAuthoringStateSnapshot"),Ya=r(i=>{mn(YB,"BrepSolidCore"),i._cppSolidCore=i._cppSolidCore||new Ua;const A=R5A(i);return fTi(A,i._cppSolidCoreSyncStamp)||jU(i,i._cppSolidCore),i._cppSolidCore},"getSyncedCppSolidCore"),PUA=r((i,A=1,e="INSET")=>{const t={points:[],tangentA:[],tangentB:[],edge:[],closedLoop:!1};try{if(mn(YB&&mTi,"Solid.computeFilletCenterline()"),!i||!Number.isFinite(A)||A<=0)return t;const g=i.parentSolid||i.parent||null;if(!g)return t;const o=i?.faces?.[0]?.name||i?.userData?.faceA||null,s=i?.faces?.[1]?.name||i?.userData?.faceB||null,I=Array.isArray(i?.userData?.segmentFacePairs)?i.userData.segmentFacePairs:null,n=Array.isArray(I)&&I.length>0;if(!n&&(!o||!s))return t;const B=Math.max(1e-12,Math.abs(Number(A)||0)*1e-9,1e-9),C=RTi(i?.userData?.polylineLocal,B);if(!Array.isArray(C)||C.length<2)return t;let a=!!(i?.closedLoop||i?.userData?.closedLoop);if(!a&&C.length>2){const l=C[0],h=C[C.length-1],w=l[0]-h[0],d=l[1]-h[1],D=l[2]-h[2];w*w+d*d+D*D<=B*B&&(a=!0)}const Q={polyline:C,radius:Number(A),sideMode:GTi(e),closedLoop:!!a};o&&(Q.faceAName=o),s&&(Q.faceBName=s),n&&(Q.segmentFacePairs=I);const E=Ya(g).computeFilletCenterline(Q);return!E||typeof E!="object"||(t.nativeKernel=E.nativeKernel===!0,t.closedLoop=!!E.closedLoop,t.points=Array.isArray(E.points)?E.points.map(zG).filter(Boolean):[],t.tangentA=Array.isArray(E.tangentA)?E.tangentA.map(zG).filter(Boolean):[],t.tangentB=Array.isArray(E.tangentB)?E.tangentB.map(zG).filter(Boolean):[],t.edge=Array.isArray(E.edge)?E.edge.map(zG).filter(Boolean):[],E.radiusClamp&&(t.radiusClamp=E.radiusClamp),E.nativeFinalized===!0&&(t.nativeFinalized=!0)),t}catch(g){return console.warn("[computeFilletCenterlineForEdge] failed:",g?.message||g),t}},"computeFilletCenterlineForEdge");var lW;const ect=(lW=class{constructor(A=null){if(A){this._native=A;return}if(typeof Tt?.BrepSolidCore!="function")throw new Error("BrepSolidCore is only available in the custom local manifold build.");this._native=new Tt.BrepSolidCore}clear(){return this._native.clear(),this}setAuthoringState(A){return this._native.setAuthoringState(A),this}addTriangle(A,e,t,g){return this._native.addTriangle(A,e,t,g),this}setFaceMetadata(A,e={}){return this._native.setFaceMetadataJson(A,JSON.stringify(e||{})),this}getFaceMetadata(A){return BzA(this._native.getFaceMetadataJson(A))}renameFace(A,e){return!!this._native.renameFace(A,e)}cleanupTinyFaceIslands(A){return Number(this._native.cleanupTinyFaceIslands(A))}removeSmallIslands(A,e=!0,t=!0){return Number(this._native.removeSmallIslands(Math.max(0,Number(A)|0),!!e,!!t))}mergeTinyFaces(A){return Number(this._native.mergeTinyFaces(A))}removeInternalTriangles(){return Number(this._native.removeInternalTriangles())}removeDisconnectedIslandsByVolume(A){return Number(this._native.removeDisconnectedIslandsByVolume(A))}normalizeFaceTracking(){return this._native.normalizeFaceTracking(),this}setEdgeMetadata(A,e={}){return this._native.setEdgeMetadataJson(A,JSON.stringify(e||{})),this}getEdgeMetadata(A){return BzA(this._native.getEdgeMetadataJson(A))}getFaceNames(){return Array.from(this._native.getFaceNames()||[])}getFace(A){return Array.from(this._native.getFace(A)||[],e=>({faceName:String(e?.faceName||A||""),indices:Array.from(e?.indices||[]),p1:Array.from(e?.p1||[]),p2:Array.from(e?.p2||[]),p3:Array.from(e?.p3||[])}))}getFaceNormal(A){const e=this._native.getFaceNormal(A)||{};return{faceFound:!!e?.faceFound,validNormal:!!e?.validNormal,normal:Array.from(e?.normal||[]),planarRatio:Number(e?.planarRatio??0),affectedVertexCount:Number(e?.affectedVertexCount??0)}}getFaces(A=!1){return Array.from(this._native.getFaces(!!A)||[],e=>({faceName:String(e?.faceName||""),triangles:Array.from(e?.triangles||[],t=>({faceName:String(t?.faceName||e?.faceName||""),indices:Array.from(t?.indices||[]),p1:Array.from(t?.p1||[]),p2:Array.from(t?.p2||[]),p3:Array.from(t?.p3||[])}))}))}getBoundaryEdgePolylines(){return Array.from(this._native.getBoundaryEdgePolylines()||[],A=>({name:String(A?.name||""),faceA:String(A?.faceA||""),faceB:String(A?.faceB||""),indices:Array.from(A?.indices||[]),positions:Array.from(A?.positions||[],e=>Array.from(e||[])),closedLoop:!!A?.closedLoop}))}addAuxEdge(A,e,t={}){return this._native.addAuxEdge(String(A||"EDGE"),e||[],t||{}),this}setAuxEdges(A=[]){return this._native.setAuxEdges(DO(A)),this}getAuxEdges(){return DO(this._native.getAuxEdges()||[])}computeFilletCenterline(A={}){const e=this._native.computeFilletCenterline(A||{});return{points:Array.from(e?.points||[],t=>zG(t)).filter(Boolean),tangentA:Array.from(e?.tangentA||[],t=>zG(t)).filter(Boolean),tangentB:Array.from(e?.tangentB||[],t=>zG(t)).filter(Boolean),edge:Array.from(e?.edge||[],t=>zG(t)).filter(Boolean),closedLoop:!!e?.closedLoop,radiusClamp:e?.radiusClamp||null,nativeKernel:e?.nativeKernel===!0,nativeFinalized:e?.nativeFinalized===!0}}getAuthoringState(){const A=this._native.getAuthoringState();return{numProp:Number(A?.numProp??3),vertProperties:Array.from(A?.vertProperties??[]),triVerts:Array.from(A?.triVerts??[]),triIDs:Array.from(A?.triIDs??[]),faceNameToID:new Map(oM(A?.faceNameToID)),idToFaceName:new Map(oM(A?.idToFaceName)),faceMetadataJson:new Map(oM(A?.faceMetadataJson)),edgeMetadataJson:new Map(oM(A?.edgeMetadataJson)),auxEdges:DO(A?.auxEdges),vertexCount:Number(A?.vertexCount??0),triangleCount:Number(A?.triangleCount??0)}}bakeTransform(A){const e=A&&typeof A=="object"&&"elements"in A?Array.from(A.elements||[]):Array.from(A||[]);return this._native.bakeTransform(e),this}transformMetadata(A){const e=A&&typeof A=="object"&&"elements"in A?Array.from(A.elements||[]):Array.from(A||[]);return this._native.transformMetadata(e),this}weldVerticesByEpsilon(A){return this._native.weldVerticesByEpsilon(A),this}pushFace(A,e){return this._native.pushFace(A,e)}isCoherentlyOrientedManifold(){return!!this._native.isCoherentlyOrientedManifold()}fixTriangleWindingsByAdjacency(){return!!this._native.fixTriangleWindingsByAdjacency()}invertNormals(){return this._native.invertNormals(),this}prepareManifoldMesh(){const A=this._native.prepareManifoldMesh();return{numProp:Number(A?.numProp??3),vertProperties:Array.from(A?.vertProperties??[]),triVerts:Array.from(A?.triVerts??[]),faceID:Array.from(A?.faceID??[]),mergeFromVert:Array.from(A?.mergeFromVert??[]),mergeToVert:Array.from(A?.mergeToVert??[]),vertexCount:Number(A?.vertexCount??0),triangleCount:Number(A?.triangleCount??0)}}vertexCount(){return Number(this._native.vertexCount())}triangleCount(){return Number(this._native.triangleCount())}dispose(){try{this._native&&typeof this._native.delete=="function"&&this._native.delete()}finally{this._native=null}}},c(lW,"Bhe2"),lW);r(ect,"CppSolidCore");let Ua=ect;function tct(){this._numProp=3,this._vertProperties=[],this._triVerts=[],this._triIDs=[],this._vertKeyToIndex=new Map,this._faceNameToID=new Map,this._idToFaceName=new Map,this._faceMetadata=new Map,this._edgeMetadata=new Map,this._faceMetadataVersion=0,this._edgeMetadataVersion=0,this._dirty=!0,this._manifold=null,this._faceIndex=null,this._visualizeCache=null,this._minGapIndex=null,this._epsilon=0,this._freeTimer=null,this._cppSolidCore=null,this._cppSolidCoreSyncStamp=null,this.type="SOLID",this.renderOrder=1,this._auxEdges=[]}c(tct,"zKt");r(tct,"constructorImpl");function ict(){const i=this.constructor,A=new i;return sB(A,eN(this)),A._dirty=!0,A._manifold=null,A._faceIndex=null,A._visualizeCache=null,A._minGapIndex=null,A._cppSolidCore=null,A._cppSolidCoreSyncStamp=null,A.type="SOLID",A.renderOrder=this.renderOrder,A}c(ict,"jKt");r(ict,"clone$7");function gct(){try{try{this._freeTimer&&clearTimeout(this._freeTimer)}catch{}if(this._freeTimer=null,this._manifold){try{typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}if(this._cppSolidCore){try{typeof this._cppSolidCore.dispose=="function"&&this._cppSolidCore.dispose()}catch{}this._cppSolidCore=null}this._cppSolidCoreSyncStamp=null,this._dirty=!0,this._faceIndex=null}catch{}return this}c(gct,"VKt");r(gct,"free");function oct([i,A,e]){return`${i},${A},${e}`}c(oct,"WKt");r(oct,"_key");function sct(i){if(!Array.isArray(i)||i.length<3)throw console.error("Invalid point passed to _getPointIndex:",i),new Error("Point must be an array with at least 3 elements");const A=i[0],e=i[1],t=i[2];if(!isFinite(A)||!isFinite(e)||!isFinite(t))throw console.error("Non-finite coordinates in _getPointIndex:",{x:A,y:e,z:t}),new Error(`Invalid point coordinates: (${A}, ${e}, ${t}) - must be finite numbers`);if((this._vertKeyToIndex?.size||0)===0&&Array.isArray(this._vertProperties)&&this._vertProperties.length>0){this._vertKeyToIndex=new Map;for(let I=0;I<this._vertProperties.length;I+=3){const n=this._vertProperties[I+0],B=this._vertProperties[I+1],C=this._vertProperties[I+2];this._vertKeyToIndex.set(`${n},${B},${C}`,I/3|0)}}const g=this._key(i),o=this._vertKeyToIndex.get(g);if(o!==void 0)return o;const s=this._vertProperties.length/3;return this._vertProperties.push(A,e,t),this._vertKeyToIndex.set(g,s),s}c(sct,"_Kt");r(sct,"_getPointIndex");function Ict(i){if(!this._faceNameToID.has(i)){const A=gD.reserveIDs(1);this._faceNameToID.set(i,A),this._idToFaceName.set(A,i)}return this._faceNameToID.get(i)}c(Ict,"qKt");r(Ict,"_getOrCreateID");function nct(i,A,e,t){const g=this._getOrCreateID(i),o=this._getPointIndex(A),s=this._getPointIndex(e),I=this._getPointIndex(t);return this._triVerts.push(o,s,I),this._triIDs.push(g),this._dirty=!0,this._faceIndex=null,this}c(nct,"ZKt");r(nct,"addTriangle");function Bct(i,A,e={}){try{const t=r(C=>{if(Array.isArray(C)&&C.length===3)return[C[0],C[1],C[2]];if(C&&typeof C=="object"){const a=+C.x,Q=+C.y,E=+C.z;if(Number.isFinite(a)&&Number.isFinite(Q)&&Number.isFinite(E))return[a,Q,E]}return null},"toArr"),g=Array.isArray(A)?A.map(t).filter(Boolean):[];if(g.length<2)return this;const o=i||"EDGE",s=Object.prototype.hasOwnProperty.call(e||{},"centerline"),I=typeof o=="string"&&/centerline/i.test(o),n=s?!!e.centerline:I;mn(YB&&NTi,"Solid.addAuxEdge()");const B=Ya(this);B.addAuxEdge(o,g,{closedLoop:!!e.closedLoop,polylineWorld:!!e.polylineWorld,materialKey:e.materialKey||"OVERLAY",centerline:n,faceA:e.faceA||"",faceB:e.faceB||""}),LTi(this,B)}catch{}return this}c(Bct,"XKt");r(Bct,"addAuxEdge");function rct(i,A,e="CENTERLINE",t={}){const g=Array.isArray(i)?i:[i?.x||0,i?.y||0,i?.z||0],o=Array.isArray(A)?A:[A?.x||0,A?.y||0,A?.z||0],s={...t||{}};return Object.prototype.hasOwnProperty.call(s,"centerline")||(s.centerline=!0),this.addAuxEdge(e,[g,o],s)}c(rct,"$Kt");r(rct,"addCenterline");function Cct(i,A){if(!A||typeof A!="object")return this;mn(YB,"Solid.setFaceMetadata");const e=Ya(this),t=e.getFaceMetadata(i),g=t&&typeof t=="object"?t:{};return e.setFaceMetadata(i,{...g,...A}),yQ(this,e),this}c(Cct,"AHt");r(Cct,"setFaceMetadata");function act(i){if(mn(YB,"Solid.getFaceMetadata"),this._faceMetadata instanceof Map)return this._faceMetadata.get(i)||{};try{return this._cppSolidCore?.getFaceMetadata(i)||{}}catch{return{}}}c(act,"eHt");r(act,"getFaceMetadata");function Qct(){if(mn(YB,"Solid.getFaceNames"),this._faceNameToID instanceof Map&&this._faceNameToID.size>0)return Array.from(this._faceNameToID.keys());if(this._idToFaceName instanceof Map&&this._idToFaceName.size>0)return Array.from(this._idToFaceName.values());try{return this._cppSolidCore?.getFaceNames()||[]}catch{return[]}}c(Qct,"tHt");r(Qct,"getFaceNames");function Ect(){const i=this._idToFaceName instanceof Map?this._idToFaceName:new Map,A=this._faceNameToID instanceof Map?this._faceNameToID:new Map;if(i.size===0&&A.size===0)return this;const e=new Map,t=new Map,g=new Map;for(const[o,s]of i.entries())e.has(s)?t.set(o,e.get(s)):(e.set(s,o),g.set(o,s));for(const[o,s]of A.entries())e.has(o)||(e.set(o,s),g.set(s,o));return t.size===0?(this._idToFaceName=g,this._faceNameToID=new Map(Array.from(g.entries(),([o,s])=>[s,o])),this):(this._triIDs=Array.isArray(this._triIDs)?this._triIDs.map(o=>t.get(o)??o):[],this._idToFaceName=g,this._faceNameToID=new Map(Array.from(g.entries(),([o,s])=>[s,o])),this._dirty=!0,this._manifold=null,this._faceIndex=null,this._visualizeCache=null,this._cppSolidCoreSyncStamp=null,this)}c(Ect,"iHt");r(Ect,"deduplicateFaceNames");function cct(i,A){if(!i||!A||i===A)return this;mn(YB,"Solid.renameFace");const e=Ya(this),t=this._faceMetadata instanceof Map&&this._faceMetadata.has(i),g=t?e.getFaceMetadata(i)||{}:null,o=this._faceMetadata instanceof Map&&this._faceMetadata.has(A)?e.getFaceMetadata(A)||{}:null;return e.renameFace(i,A)?(yQ(this,e),t&&(e.setFaceMetadata(A,{...o&&typeof o=="object"?o:{},...g&&typeof g=="object"?g:{}}),yQ(this,e)),this._dirty=!0,this._faceIndex=null,this):this}c(cct,"gHt");r(cct,"renameFace");function lct(i,A){if(!A||typeof A!="object")return this;mn(YB,"Solid.setEdgeMetadata");const e=Ya(this),t=e.getEdgeMetadata(i),g=t&&typeof t=="object"?t:{};return e.setEdgeMetadata(i,{...g,...A}),yQ(this,e),this}c(lct,"sHt");r(lct,"setEdgeMetadata");function hct(i){if(mn(YB,"Solid.getEdgeMetadata"),this._edgeMetadata instanceof Map)return this._edgeMetadata.get(i)||null;try{return this._cppSolidCore?.getEdgeMetadata(i)||null}catch{return null}}c(hct,"oHt");r(hct,"getEdgeMetadata");function XRe(i,A=PC){const e=Array.isArray(i?.position)?i.position:[0,0,0],t=Array.isArray(i?.rotationEuler)?i.rotationEuler:[0,0,0],g=Array.isArray(i?.scale)?i.scale:[1,1,1],o=new A.Vector3(Number(e[0]||0),Number(e[1]||0),Number(e[2]||0)),s=new A.Euler(A.MathUtils.degToRad(Number(t[0]||0)),A.MathUtils.degToRad(Number(t[1]||0)),A.MathUtils.degToRad(Number(t[2]||0)),"XYZ"),I=new A.Quaternion().setFromEuler(s),n=new A.Vector3(Number(g[0]||1),Number(g[1]||1),Number(g[2]||1));return new A.Matrix4().compose(o,I,n)}c(XRe,"lgt");r(XRe,"composeTrsMatrixDeg");function k5A(i,A,e=PC){const t=new e.Vector3(Number(i?.position?.[0]||0),Number(i?.position?.[1]||0),Number(i?.position?.[2]||0)),g=new e.Quaternion().fromArray(Array.isArray(i?.quaternion)&&i.quaternion.length>=4?i.quaternion:[0,0,0,1]),o=new e.Vector3(Number(i?.scale?.[0]||1),Number(i?.scale?.[1]||1),Number(i?.scale?.[2]||1)),s=new e.Matrix4().compose(t,g,o),I=XRe(A,e);return s.multiply(I)}c(k5A,"_ne");r(k5A,"combineBaseWithDeltaDeg");function wct(i){try{if(!i||typeof i.elements>"u")return this;if(!Array.isArray(this._vertProperties)||this._vertProperties.length===0)return this;const A=i&&i.isMatrix4?i:new Bt().fromArray(i.elements||i);mn(YB,"Solid.bakeTransform()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),this._cppSolidCore.bakeTransform(A),yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}catch{}return this}c(wct,"nHt");r(wct,"bakeTransform");function dct(i){try{const A=XRe(i,PC);return this.bakeTransform(A)}catch{return this}}c(dct,"IHt");r(dct,"bakeTRS");function Dct(i,A){const e=this.constructor,t=i instanceof W?i.clone():new W(i[0],i[1],i[2]),g=A instanceof W?A.clone().normalize():new W(A[0],A[1],A[2]).normalize(),o=eN(this),s=this.getMesh();try{const I=s.vertProperties,n=s.triVerts,B=s.faceID&&s.faceID.length?Array.from(s.faceID):[],C=new e;C._numProp=s.numProp||3;const a=new Array(I.length),Q=new W;for(let E=0;E<I.length;E+=3){Q.set(I[E+0],I[E+1],I[E+2]);const l=2*Q.clone().sub(t).dot(g),h=Q.sub(g.clone().multiplyScalar(l));a[E+0]=h.x,a[E+1]=h.y,a[E+2]=h.z}C._vertProperties=a,C._triVerts=Array.from(n),C._triIDs=B.length?B:new Array(n.length/3|0).fill(0);try{C._idToFaceName=new Map(o?.idToFaceName||[]),C._faceNameToID=new Map(o?.faceNameToID||[]),C._faceMetadata=new Map(Array.from(o?.faceMetadataJson||[],([E,l])=>[E,JSON.parse(l||"{}")])),C._edgeMetadata=new Map(Array.from(o?.edgeMetadataJson||[],([E,l])=>[E,JSON.parse(l||"{}")]))}catch{}try{const E=Array.isArray(this._auxEdges)?this._auxEdges:[],l=new W,h=new W,w=new W;C._auxEdges=E.map(d=>{const D=[];if(Array.isArray(d?.points))for(const u of d.points)!Array.isArray(u)||u.length!==3||(l.set(u[0],u[1],u[2]),h.subVectors(l,t),w.copy(g).multiplyScalar(2*h.dot(g)),l.sub(w),D.push([l.x,l.y,l.z]));return{name:d?.name,closedLoop:!!d?.closedLoop,polylineWorld:!!d?.polylineWorld,materialKey:d?.materialKey,centerline:!!d?.centerline,points:D}}).filter(d=>Array.isArray(d.points)&&d.points.length)}catch{C._auxEdges=[]}C._vertKeyToIndex=new Map;for(let E=0;E<C._vertProperties.length;E+=3){const l=C._vertProperties[E],h=C._vertProperties[E+1],w=C._vertProperties[E+2];C._vertKeyToIndex.set(`${l},${h},${w}`,E/3|0)}C._dirty=!0,C._faceIndex=null,C._manifold=null;try{mn(YB&&_Et,"Solid.mirrorAcrossPlane()");const E=g.x,l=g.y,h=g.z,w=t.dot(g),d=new Bt().set(1-2*E*E,-2*E*l,-2*E*h,2*w*E,-2*l*E,1-2*l*l,-2*l*h,2*w*l,-2*h*E,-2*h*l,1-2*h*h,2*w*h,0,0,0,1);C._cppSolidCore=C._cppSolidCore||new Ua,jU(C,C._cppSolidCore),C._cppSolidCore.transformMetadata(d),yQ(C,C._cppSolidCore),C._cppSolidCore.dispose(),C._cppSolidCore=null,C._cppSolidCoreSyncStamp=null}catch{}return C}finally{try{s&&typeof s.delete=="function"&&s.delete()}catch{}}}c(Dct,"rHt");r(Dct,"mirrorAcrossPlane");function uct(i,A=.001,e={}){const t=Number(A);if(!i||!Number.isFinite(t)||t===0)return this;const g=e?.warnMissing!==!1,o=e?.warnInvalidNormal!==!1;try{this._manifoldize()}catch{}if(this._faceNameToID.get(i)===void 0)return g&&console.warn(`pushFace: Face "${i}" not found`),this;mn(YB&&WEt,"Solid.pushFace()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore);const s=this._cppSolidCore.pushFace(i,t)||{};if(!s.faceFound)return g&&console.warn(`pushFace: Face "${i}" not found`),this;if(!s.moved)return s.invalidNormal&&o&&console.warn(`pushFace: Invalid normal for face "${i}"`),this;yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,this}c(uct,"BHt");r(uct,"pushFace");function Mct(){const i=r(()=>typeof performance<"u"&&performance?.now?performance.now():Date.now(),"nowMs");i();try{this._freeTimer&&clearTimeout(this._freeTimer)}catch{}try{this._freeTimer=setTimeout(()=>{try{this.free()}catch{}},60*1e3)}catch{}if(!this._dirty&&this._manifold)return i(),this._manifold;let A=!1;const e=r((t=!0)=>{A||(A=!0,i(),(this?._triVerts?.length||0)/3|0,(this?._vertProperties?.length||0)/3|0)},"__logDone");try{mn(YB&&Y5A,"Solid._manifoldize()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore);const t=this._cppSolidCore.prepareManifoldMesh();yQ(this,this._cppSolidCore);const g=new X$e({numProp:Number(t?.numProp??this._numProp??3),vertProperties:new Float32Array(t?.vertProperties??[]),triVerts:new Uint32Array(t?.triVerts??[]),faceID:new Uint32Array(t?.faceID??[]),mergeFromVert:new Uint32Array(t?.mergeFromVert??[]),mergeToVert:new Uint32Array(t?.mergeToVert??[])});try{this._manifold=new gD(g)}catch(o){try{if(this&&Object.prototype.hasOwnProperty.call(this,"edgeToFillet")){const s=(this._triVerts?.length||0)/3|0,I=(this._vertProperties?.length||0)/3|0,n=[];try{if(this.edgeToFillet&&Array.isArray(this.edgeToFillet.faces))for(const C of this.edgeToFillet.faces)C&&C.name&&n.push(C.name)}catch{}const B={type:"FilletSolidManifoldFailure",message:o&&(o.message||String(o))||"unknown",params:{radius:this.radius,arcSegments:this.arcSegments,sampleCount:this.sampleCount,sideMode:this.sideMode,inflate:this.inflate,sideStripSubdiv:this.sideStripSubdiv,seamInsetScale:this.seamInsetScale,projectStripsOpenEdges:this.projectStripsOpenEdges,forceSeamInset:this.forceSeamInset},edge:{name:this.edgeToFillet?.name||null,closedLoop:!!(this.edgeToFillet?.closedLoop||this.edgeToFillet?.userData?.closedLoop),faces:n},counts:{vertices:I,triangles:s,faceLabels:this._faceNameToID&&typeof this._faceNameToID.size=="number"?this._faceNameToID.size:void 0}};try{console.error(JSON.stringify(B))}catch{console.error("[FilletSolidManifoldFailure]",B.message)}}}catch{}throw e(!1),o}finally{try{g&&typeof g.delete=="function"&&g.delete()}catch{}}return this._dirty=!1,this._faceIndex=null,e(!0),this._manifold}finally{const t=!!(this&&this._manifold)&&this._dirty===!1;e(t)}}c(Mct,"CHt");r(Mct,"_manifoldize");function yct(i=0){return this._epsilon=Number(i)||0,this._epsilon>0&&this._weldVerticesByEpsilon(this._epsilon),this}c(yct,"aHt");r(yct,"setEpsilon");function pct(i,A={}){mn(YB&&ZRe,"Solid._weldVerticesByEpsilon()");const e=A?.rebuildManifold!==!1;this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),this._cppSolidCore.weldVerticesByEpsilon(i),yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,e&&this._manifoldize(),this}c(pct,"QHt");r(pct,"_weldVerticesByEpsilon");function fct(){if(mn(YB&&Y5A,"Solid.fixTriangleWindingsByAdjacency()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),!this._cppSolidCore.fixTriangleWindingsByAdjacency())return this;yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,this}c(fct,"EHt");r(fct,"fixTriangleWindingsByAdjacency");function Fct(){return mn(YB&&Y5A,"Solid._isCoherentlyOrientedManifold()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),this._cppSolidCore.isCoherentlyOrientedManifold()}c(Fct,"cHt");r(Fct,"_isCoherentlyOrientedManifold");function mct({maxTriangles:i=30,removeInternal:A=!0,removeExternal:e=!0}={}){mn(YB&&ZEt,"Solid.removeSmallIslands()");const t=Ya(this),g=t.removeSmallIslands(i,A,e);if(g>0){yQ(this,t),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return g}c(mct,"lHt");r(mct,"removeSmallIslands");function Nct({normalDotThreshold:i=-.95}={}){const A=this._triVerts,e=this._vertProperties,t=this._triIDs;if(!A||!e||!t)return 0;const g=A.length/3|0;if(g===0||t.length!==g)return 0;const o=e.length/3|0;if(o===0)return 0;const s=BigInt(Math.max(1,o)),I=r((F,m)=>{const G=BigInt(F),N=BigInt(m);return G<N?G*s+N:N*s+G},"eKey"),n=new Map,B=r((F,m,G,N)=>{let S=n.get(F);S||(S=[0,0,0],n.set(F,S)),S[0]+=m,S[1]+=G,S[2]+=N},"addNormal"),C=new Map;for(let F=0;F<g;F++){const m=t[F];if(m==null)continue;const G=F*3,N=A[G+0]>>>0,S=A[G+1]>>>0,Y=A[G+2]>>>0,R=e[N*3+0],k=e[N*3+1],b=e[N*3+2],L=e[S*3+0],x=e[S*3+1],J=e[S*3+2],$=e[Y*3+0],T=e[Y*3+1],H=e[Y*3+2],X=L-R,oA=x-k,_=J-b,V=$-R,O=T-k,AA=H-b,BA=oA*AA-_*O,rA=_*V-X*AA,tA=X*O-oA*V;B(m,BA,rA,tA);const sA=[[N,S],[S,Y],[Y,N]];for(let eA=0;eA<3;eA++){let K=sA[eA][0],v=sA[eA][1];if(K===v)continue;const iA=I(K,v);let QA=C.get(iA);if(!QA){if(K>v){const gA=K;K=v,v=gA}QA={faces:new Set,a:K,b:v},C.set(iA,QA)}QA.faces.add(m)}}const a=new Map,Q=new Map,E=r((F,m)=>{let G=Q.get(F);G||(G=new Set,Q.set(F,G)),G.add(m)},"addPair");for(const F of C.values()){if(F.faces.size!==2)continue;const m=Array.from(F.faces),G=m[0],N=m[1];if(G===N)continue;const S=G<N?`${G}|${N}`:`${N}|${G}`;let Y=a.get(S);Y||(Y={ids:G<N?[G,N]:[N,G],edges:[]},a.set(S,Y)),Y.edges.push([F.a,F.b]),E(G,S),E(N,S)}const l=r(F=>{if(!F||F.length===0)return!1;const m=new Map,G=new Set;for(const[Y,R]of F)G.add(Y),G.add(R),m.has(Y)||m.set(Y,new Set),m.has(R)||m.set(R,new Set),m.get(Y).add(R),m.get(R).add(Y);let N=0;const S=new Set;for(const Y of G){if(S.has(Y))continue;if(N++,N>1)return!1;const R=[Y];for(S.add(Y);R.length;){const k=R.pop(),b=m.get(k);if(b)for(const L of b)S.has(L)||(S.add(L),R.push(L))}}return N===1},"isSingleEdgeChain"),h=new Set;for(const[F,m]of Q.entries()){if(m.size!==1)continue;const G=m.values().next().value,N=a.get(G);if(!N||!N.edges.length||!l(N.edges))continue;const S=N.ids[0]===F?N.ids[1]:N.ids[0],Y=n.get(F),R=n.get(S);if(!Y||!R)continue;const k=Math.hypot(Y[0],Y[1],Y[2]),b=Math.hypot(R[0],R[1],R[2]);!(k>1e-12)||!(b>1e-12)||(Y[0]*R[0]+Y[1]*R[1]+Y[2]*R[2])/(k*b)<=i&&h.add(F)}if(!h.size)return 0;const w=new Uint8Array(g);let d=0;for(let F=0;F<g;F++){if(h.has(t[F])){d++;continue}w[F]=1}if(d===0)return 0;const D=new Uint8Array(o),u=[],M=[];for(let F=0;F<g;F++){if(!w[F])continue;const m=F*3,G=A[m+0]>>>0,N=A[m+1]>>>0,S=A[m+2]>>>0;u.push(G,N,S),M.push(t[F]),D[G]=1,D[N]=1,D[S]=1}const y=new Int32Array(o);for(let F=0;F<o;F++)y[F]=-1;const p=[];let f=0;for(let F=0;F<o;F++)D[F]&&(y[F]=f++,p.push(e[F*3+0],e[F*3+1],e[F*3+2]));for(let F=0;F<u.length;F++)u[F]=y[u[F]];this._vertProperties=p,this._triVerts=u,this._triIDs=M,this._vertKeyToIndex=new Map;for(let F=0;F<this._vertProperties.length;F+=3){const m=this._vertProperties[F],G=this._vertProperties[F+1],N=this._vertProperties[F+2];this._vertKeyToIndex.set(`${m},${G},${N}`,F/3|0)}return this._dirty=!0,this._faceIndex=null,this._manifold=null,d}c(Nct,"hHt");r(Nct,"removeOppositeSingleEdgeFaces");function Sct(i,A=1){const e=Number(i);if(!Number.isFinite(e)||e<=0)return 0;const t=this._vertProperties;if(!t||t.length<9||this._triVerts.length<3)return 0;const g=r((I,n,B)=>{const C=t[I*3+0],a=t[I*3+1],Q=t[I*3+2],E=t[n*3+0],l=t[n*3+1],h=t[n*3+2],w=t[B*3+0],d=t[B*3+1],D=t[B*3+2],u=E-C,M=l-a,y=h-Q,p=w-C,f=d-a,F=D-Q,m=M*F-y*f,G=y*p-u*F,N=u*f-M*p;return .5*Math.hypot(m,G,N)},"triArea");let o=0;const s=Math.max(1,A|0);for(let I=0;I<s;I++){const n=this._triVerts,B=this._triIDs,C=n.length/3|0;if(C<2)break;const a=new Array(C),Q=new Float64Array(C);for(let p=0;p<C;p++){const f=p*3,F=n[f+0]>>>0,m=n[f+1]>>>0,G=n[f+2]>>>0;a[p]=[F,m,G],Q[p]=g(F,m,G)}const E=t.length/3|0,l=BigInt(E),h=r((p,f)=>{const F=BigInt(p),m=BigInt(f);return F<m?F*l+m:m*l+F},"eKey"),w=new Map;for(let p=0;p<C;p++){const[f,F,m]=a[p],G=B[p],N=[[f,F],[F,m],[m,f]];for(let S=0;S<3;S++){const Y=N[S][0],R=N[S][1],k=h(Y,R);let b=w.get(k);b||(b=[],w.set(k,b)),b.push({tri:p,id:G,a:Y,b:R})}}const d=[];for(const[p,f]of w.entries()){if(f.length!==2)continue;const F=f[0],m=f[1];if(F.id===m.id)continue;const G=Q[F.tri],N=Q[m.tri],S=Math.min(G,N);S<e&&d.push({key:p,a:F,b:m,minAB:S})}d.sort((p,f)=>p.minAB-f.minAB);const D=new Uint8Array(C);let u=0;const M=r((p,f,F)=>{const m=h(p,f),G=w.get(m);if(G){for(let N=0;N<G.length;N++){const S=G[N];if(S.tri===F&&S.a===p&&S.b===f){G.splice(N,1);break}}G.length===0&&w.delete(m)}},"removeUse"),y=r((p,f,F,m)=>{const G=h(p,f);let N=w.get(G);N||(N=[],w.set(G,N)),N.push({tri:F,id:m,a:p,b:f})},"addUse");for(const{a:p,b:f}of d){const F=p.tri,m=f.tri;if(D[F]||D[m])continue;const G=p.a,N=p.b;if(!(f.a===N&&f.b===G))continue;const S=a[F],Y=a[m];let R=-1,k=-1;for(let X=0;X<3;X++){const oA=S[X];if(oA!==G&&oA!==N){R=oA;break}}for(let X=0;X<3;X++){const oA=Y[X];if(oA!==G&&oA!==N){k=oA;break}}if(R<0||k<0||R===k)continue;const b=h(R,k),L=w.get(b);if(L&&L.length)continue;const x=Q[F],J=Q[m],$=Math.min(x,J);if($>=e)continue;const T=g(R,k,G),H=g(k,R,N);!(Number.isFinite(T)&&Number.isFinite(H))||T<=0||H<=0||Math.min(T,H)<$||(a[F]=[R,k,G],a[m]=[k,R,N],Q[F]=T,Q[m]=H,M(G,N,F),M(N,G,m),M(N,G,F),M(G,N,m),y(R,k,F,B[F]),y(k,R,F,B[F]),y(k,R,m,B[m]),y(R,k,m,B[m]),D[F]=1,D[m]=1,u++)}if(!u)break;o+=u;for(let p=0;p<C;p++){const f=a[p],F=p*3;n[F+0]=f[0],n[F+1]=f[1],n[F+2]=f[2]}this._dirty=!0,this._faceIndex=null}return o>0&&this.fixTriangleWindingsByAdjacency(),o}c(Sct,"dHt");r(Sct,"removeTinyBoundaryTriangles");function Gct({maxEdgeLength:i,maxIterations:A=10}={}){const e=Number(i);if(!Number.isFinite(e)||e<=0)return this;const t=e*e,g=r(()=>{const s=this._vertProperties,I=this._triVerts,n=this._triIDs,B=I.length/3|0,C=s.length/3|0,a=BigInt(Math.max(1,C)),Q=r((y,p)=>{const f=BigInt(y),F=BigInt(p);return f<F?f*a+F:F*a+f},"ukey"),E=r((y,p)=>{const f=s[y*3+0],F=s[y*3+1],m=s[y*3+2],G=s[p*3+0],N=s[p*3+1],S=s[p*3+2],Y=f-G,R=F-N,k=m-S;return Y*Y+R*R+k*k},"len2"),l=new Set;for(let y=0;y<B;y++){const p=y*3,f=I[p+0]>>>0,F=I[p+1]>>>0,m=I[p+2]>>>0;E(f,F)>t&&l.add(Q(f,F)),E(F,m)>t&&l.add(Q(F,m)),E(m,f)>t&&l.add(Q(m,f))}if(l.size===0)return!1;const h=s.slice(),w=new Map,d=r((y,p)=>{const f=Q(y,p);let F=w.get(f);if(F!==void 0)return F;const m=s[y*3+0],G=s[y*3+1],N=s[y*3+2],S=s[p*3+0],Y=s[p*3+1],R=s[p*3+2],k=.5*(m+S),b=.5*(G+Y),L=.5*(N+R);return F=h.length/3|0,h.push(k,b,L),w.set(f,F),F},"midpointIndex"),D=[],u=[],M=r((y,p,f,F)=>{D.push(y,p,f),u.push(F)},"emit");for(let y=0;y<B;y++){const p=y*3,f=I[p+0]>>>0,F=I[p+1]>>>0,m=I[p+2]>>>0,G=n[y],N=Q(f,F),S=Q(F,m),Y=Q(m,f),R=l.has(N),k=l.has(S),b=l.has(Y),L=(R?1:0)+(k?1:0)+(b?1:0);if(L===0){M(f,F,m,G);continue}if(L===1){if(R){const T=d(f,F);M(f,T,m,G),M(T,F,m,G)}else if(k){const T=d(F,m);M(F,T,f,G),M(T,m,f,G)}else{const T=d(m,f);M(m,T,F,G),M(T,f,F,G)}continue}if(L===2){if(R&&k){const T=d(f,F),H=d(F,m);M(f,T,m,G),M(F,H,T,G),M(T,H,m,G)}else if(k&&b){const T=d(F,m),H=d(m,f);M(F,T,f,G),M(m,H,T,G),M(T,H,f,G)}else{const T=d(m,f),H=d(f,F);M(m,T,F,G),M(f,H,T,G),M(T,H,F,G)}continue}const x=d(f,F),J=d(F,m),$=d(m,f);M(f,x,$,G),M(F,J,x,G),M(m,$,J,G),M(x,J,$,G)}this._vertProperties=h,this._triVerts=D,this._triIDs=u,this._vertKeyToIndex=new Map;for(let y=0;y<this._vertProperties.length;y+=3){const p=this._vertProperties[y],f=this._vertProperties[y+1],F=this._vertProperties[y+2];this._vertKeyToIndex.set(`${p},${f},${F}`,y/3|0)}return this._dirty=!0,this._faceIndex=null,!0},"pass");let o=!1;for(let s=0;s<A&&g();s++)o=!0;return o&&this.fixTriangleWindingsByAdjacency(),this}c(Gct,"wHt");r(Gct,"remesh");function Rct(i){const A=Number(i);if(!Number.isFinite(A)||A<=0)return 0;const e=this._vertProperties,t=this._triVerts,g=t.length/3|0,o=e.length/3|0;if(g===0||o===0)return 0;const s=A*A,I=new Int32Array(o);for(let _=0;_<o;_++)I[_]=_;const n=r(_=>{for(;I[_]!==_;)I[_]=I[I[_]],_=I[_];return _},"find"),B=r((_,V)=>{let O=n(_),AA=n(V);if(O===AA)return!1;if(AA<O){const BA=O;O=AA,AA=BA}return I[AA]=O,!0},"unite"),C=r((_,V)=>{const O=e[_*3+0],AA=e[_*3+1],BA=e[_*3+2],rA=e[V*3+0],tA=e[V*3+1],sA=e[V*3+2],eA=O-rA,K=AA-tA,v=BA-sA;return eA*eA+K*K+v*v},"len2");let a=0;for(let _=0;_<g;_++){const V=_*3,O=t[V+0]>>>0,AA=t[V+1]>>>0,BA=t[V+2]>>>0,rA=C(O,AA),tA=C(AA,BA),sA=C(BA,O);let eA=rA,K=O,v=AA;tA<eA&&(eA=tA,K=AA,v=BA),sA<eA&&(eA=sA,K=BA,v=O),eA<s&&B(K,v)&&a++}if(a===0)return 0;for(let _=0;_<o;_++){const V=n(_);V!==_&&(e[_*3+0]=e[V*3+0],e[_*3+1]=e[V*3+1],e[_*3+2]=e[V*3+2])}this._vertKeyToIndex=new Map;for(let _=0;_<o;_++){const V=e[_*3+0],O=e[_*3+1],AA=e[_*3+2];this._vertKeyToIndex.set(`${V},${O},${AA}`,_)}this._dirty=!0,this._faceIndex=null;let Q=1/0,E=1/0,l=1/0,h=-1/0,w=-1/0,d=-1/0;for(let _=0;_<o;_++){const V=e[_*3+0],O=e[_*3+1],AA=e[_*3+2];V<Q&&(Q=V),V>h&&(h=V),O<E&&(E=O),O>w&&(w=O),AA<l&&(l=AA),AA>d&&(d=AA)}if(!Number.isFinite(Q)||!Number.isFinite(h))return a;const D=Math.max(1e-9,h-Q),u=Math.max(1e-9,w-E),M=Math.max(1e-9,d-l),y=Math.max(D,u,M,A),p=Math.max(A*10,y*.1+1e-6),f=D+2*p,F=u+2*p,m=M+2*p,G=Q-p,N=E-p,S=l-p,Y=this.constructor,R=new Y,k=[G,N,S],b=[G+f,N,S],L=[G,N+F,S],x=[G+f,N+F,S],J=[G,N,S+m],$=[G+f,N,S+m],T=[G,N+F,S+m],H=[G+f,N+F,S+m];R.addTriangle("__BIGBOX_NX",k,J,T),R.addTriangle("__BIGBOX_NX",k,T,L),R.addTriangle("__BIGBOX_PX",b,x,H),R.addTriangle("__BIGBOX_PX",b,H,$),R.addTriangle("__BIGBOX_NY",k,b,$),R.addTriangle("__BIGBOX_NY",k,$,J),R.addTriangle("__BIGBOX_PY",L,T,H),R.addTriangle("__BIGBOX_PY",L,H,x),R.addTriangle("__BIGBOX_NZ",k,L,x),R.addTriangle("__BIGBOX_NZ",k,x,b),R.addTriangle("__BIGBOX_PZ",J,$,H),R.addTriangle("__BIGBOX_PZ",J,H,T);const X=this.intersect(R),oA=X.getMesh();try{this._numProp=oA.numProp||3,this._vertProperties=Array.from(oA.vertProperties||[]),this._triVerts=Array.from(oA.triVerts||[]);const _=this._triVerts.length/3|0;if(oA.faceID&&oA.faceID.length===_)this._triIDs=Array.from(oA.faceID);else{const V=this.constructor;this._triIDs=V._expandTriIDsFromMesh(oA)}this._vertKeyToIndex=new Map;for(let V=0;V<this._vertProperties.length;V+=3){const O=this._vertProperties[V],AA=this._vertProperties[V+1],BA=this._vertProperties[V+2];this._vertKeyToIndex.set(`${O},${AA},${BA}`,V/3|0)}try{this._idToFaceName=new Map(X._idToFaceName)}catch{throw new Error("Failed to adopt face label mapping from boolean result")}try{this._faceNameToID=new Map([...this._idToFaceName.entries()].map(([V,O])=>[O,V]))}catch{}this._dirty=!1,this._faceIndex=null,this._manifold=null}finally{try{oA&&typeof oA.delete=="function"&&oA.delete()}catch{}}return a}c(Rct,"uHt");r(Rct,"collapseTinyTriangles");function Yct(i=!1){const A=i&&typeof i=="object"?i:{},e=i===!0||A.diagnostics===!0,t=A.detectOnly===!0||A.probeOnly===!0,g=Math.max(0,Number(A.maxIntersections)||0),o=Array.from(this._vertProperties||[]),s=Array.from(this._triVerts||[]),I=Array.from(this._triIDs||[]),n=s.length/3|0;if(n<2||o.length<9)return 0;const B={add(z,aA){return[z[0]+aA[0],z[1]+aA[1],z[2]+aA[2]]},sub(z,aA){return[z[0]-aA[0],z[1]-aA[1],z[2]-aA[2]]},mul(z,aA){return[z[0]*aA,z[1]*aA,z[2]*aA]},dot(z,aA){return z[0]*aA[0]+z[1]*aA[1]+z[2]*aA[2]},cross(z,aA){return[z[1]*aA[2]-z[2]*aA[1],z[2]*aA[0]-z[0]*aA[2],z[0]*aA[1]-z[1]*aA[0]]},len(z){return Math.hypot(z[0],z[1],z[2])},dist(z,aA){return Math.hypot(z[0]-aA[0],z[1]-aA[1],z[2]-aA[2])},norm(z){const aA=Math.hypot(z[0],z[1],z[2]);return aA>0?[z[0]/aA,z[1]/aA,z[2]/aA]:[0,0,0]}},C={sub(z,aA){return[z[0]-aA[0],z[1]-aA[1]]},cross(z,aA){return z[0]*aA[1]-z[1]*aA[0]},dot(z,aA){return z[0]*aA[0]+z[1]*aA[1]},dist(z,aA){return Math.hypot(z[0]-aA[0],z[1]-aA[1])}};let a=1/0,Q=1/0,E=1/0,l=-1/0,h=-1/0,w=-1/0;for(let z=0;z<o.length;z+=3){const aA=o[z+0],hA=o[z+1],MA=o[z+2];aA<a&&(a=aA),aA>l&&(l=aA),hA<Q&&(Q=hA),hA>h&&(h=hA),MA<E&&(E=MA),MA>w&&(w=MA)}const d=Math.max(1,Math.hypot(l-a,h-Q,w-E)),D=Math.max(1e-9,Number(A.snapTolerance)||d*1e-9),u=Math.max(D*8,d*1e-10),M=Math.max(1e-18,d*d*1e-18),y=r(z=>[Math.round(z[0]/D),Math.round(z[1]/D),Math.round(z[2]/D)].join(","),"qPoint"),p=r(z=>[o[z*3+0],o[z*3+1],o[z*3+2]],"sourcePoint"),f=r((z,aA,hA)=>B.len(B.cross(B.sub(aA,z),B.sub(hA,z)))*.5,"triangleArea3"),F=r((z,aA,hA)=>{const MA=B.cross(B.sub(aA,z),B.sub(hA,z)),fA=B.len(MA);if(!(fA>1e-18))return null;const SA=B.mul(MA,1/fA);return{n:SA,d:-B.dot(SA,z)}},"planeOf"),m=r((z,aA)=>B.dot(z.n,aA)+z.d,"signedDistance"),G=r((z,aA,hA)=>{const MA=B.norm(B.cross(B.sub(aA,z),B.sub(hA,z)));if(B.len(MA)<=0)return null;let fA=B.sub(aA,z);if(B.len(fA)<=D&&(fA=B.sub(hA,z)),fA=B.norm(fA),B.len(fA)<=0)return null;const SA=B.norm(B.cross(MA,fA));if(B.len(SA)<=0)return null;const UA=z;return{origin:UA,u:fA,v:SA,n:MA,project(GA){const _A=B.sub(GA,UA);return[B.dot(_A,fA),B.dot(_A,SA)]},unproject(GA){return B.add(UA,B.add(B.mul(fA,GA[0]),B.mul(SA,GA[1])))}}},"makeBasis"),N=r((z,aA,hA,MA,fA=1e-12)=>{const SA=C.sub(hA,aA),UA=C.sub(MA,hA),GA=C.sub(aA,MA),_A=C.sub(z,aA),YA=C.sub(z,hA),KA=C.sub(z,MA),OA=C.cross(SA,_A),te=C.cross(UA,YA),XA=C.cross(GA,KA);return OA>=-fA&&te>=-fA&&XA>=-fA||OA<=fA&&te<=fA&&XA<=fA},"pointInTri2D"),S=r((z,aA,hA,MA,fA=1e-12)=>{const SA=C.sub(aA,z),UA=C.sub(MA,hA),GA=C.cross(SA,UA),_A=C.sub(hA,z),YA=[];if(Math.abs(GA)>fA){const Oe=C.cross(_A,UA)/GA,ve=C.cross(_A,SA)/GA;return Oe>=-fA&&Oe<=1+fA&&ve>=-fA&&ve<=1+fA&&YA.push([z[0]+SA[0]*Oe,z[1]+SA[1]*Oe]),YA}if(Math.abs(C.cross(_A,SA))>fA)return YA;const KA=Math.abs(SA[0])>=Math.abs(SA[1])?0:1,OA=z[KA],te=aA[KA],XA=hA[KA],Ge=MA[KA],zA=Math.min(OA,te),ae=Math.max(OA,te),de=Math.min(XA,Ge),we=Math.max(XA,Ge),Qe=Math.max(zA,de),oe=Math.min(ae,we);if(oe<Qe-fA)return YA;const ke=r(Oe=>{const ve=te-OA,gt=Math.abs(ve)>fA?(Oe-OA)/ve:0;return[z[0]+SA[0]*gt,z[1]+SA[1]*gt]},"pointAt");return YA.push(ke(Qe)),oe>Qe+fA&&YA.push(ke(oe)),YA},"segmentIntersection2D"),Y=r((z,aA,hA,MA=1e-10)=>{const fA=C.sub(hA,aA),SA=C.sub(z,aA),UA=C.dot(fA,fA);if(!(UA>MA*MA)||Math.abs(C.cross(fA,SA))>MA*Math.sqrt(UA))return!1;const GA=C.dot(SA,fA)/UA;return GA>=-MA&&GA<=1+MA},"pointOnSegment2D"),R=r((z,aA,hA,MA=D)=>{const fA=B.sub(hA,aA),SA=B.sub(z,aA),UA=B.len(fA);if(!(UA>MA))return B.dist(z,aA)<=MA;if(B.len(B.cross(fA,SA))>MA*UA)return!1;const GA=B.dot(SA,fA)/(UA*UA);return GA>=-MA&&GA<=1+MA},"pointOnSegment3D"),k=r(z=>{const aA=[],hA=new Set,MA=r(GA=>`${Math.round(GA[0]/D)},${Math.round(GA[1]/D)}`,"q2");for(const GA of z){const _A=MA(GA);hA.has(_A)||(hA.add(_A),aA.push(GA))}if(aA.sort((GA,_A)=>GA[0]-_A[0]||GA[1]-_A[1]),aA.length<=2)return aA;const fA=r((GA,_A,YA)=>C.cross(C.sub(_A,GA),C.sub(YA,GA)),"cross"),SA=[];for(const GA of aA){for(;SA.length>=2&&fA(SA[SA.length-2],SA[SA.length-1],GA)<=D;)SA.pop();SA.push(GA)}const UA=[];for(let GA=aA.length-1;GA>=0;GA--){const _A=aA[GA];for(;UA.length>=2&&fA(UA[UA.length-2],UA[UA.length-1],_A)<=D;)UA.pop();UA.push(_A)}return SA.pop(),UA.pop(),SA.concat(UA)},"convexHull2D"),b=r((z,aA=hA=>hA)=>{let hA=0;for(let MA=0;MA<z.length;MA++){const fA=aA(z[MA]),SA=aA(z[(MA+1)%z.length]);hA+=fA[0]*SA[1]-SA[0]*fA[1]}return hA*.5},"polygonArea2D"),L=r((z,aA)=>{const hA=[],MA=r(GA=>{for(const _A of hA)if(B.dist(GA,_A)<=D)return;hA.push(GA)},"add"),fA=z.map(GA=>m(aA,GA));for(let GA=0;GA<3;GA++){const _A=(GA+1)%3,YA=z[GA],KA=z[_A],OA=fA[GA],te=fA[_A];if(Math.abs(OA)<=u&&MA(YA),Math.abs(OA)<=u&&Math.abs(te)<=u){MA(KA);continue}if(OA<-u&&te>u||OA>u&&te<-u){const XA=OA/(OA-te);MA([YA[0]+(KA[0]-YA[0])*XA,YA[1]+(KA[1]-YA[1])*XA,YA[2]+(KA[2]-YA[2])*XA])}}if(hA.length<=2)return hA;let SA=[hA[0],hA[1]],UA=-1/0;for(let GA=0;GA<hA.length;GA++)for(let _A=GA+1;_A<hA.length;_A++){const YA=B.dist(hA[GA],hA[_A]);YA>UA&&(SA=[hA[GA],hA[_A]],UA=YA)}return SA},"trianglePlaneSegment"),x=r((z,aA,hA)=>{const MA=z.map(_A=>hA.project(_A)),fA=aA.map(_A=>hA.project(_A)),SA=[],UA=r(_A=>{for(const YA of SA)if(C.dist(_A,YA)<=D)return;SA.push(_A)},"add2");for(const _A of MA)N(_A,fA[0],fA[1],fA[2],D)&&UA(_A);for(const _A of fA)N(_A,MA[0],MA[1],MA[2],D)&&UA(_A);for(let _A=0;_A<3;_A++){const YA=MA[_A],KA=MA[(_A+1)%3];for(let OA=0;OA<3;OA++){const te=fA[OA],XA=fA[(OA+1)%3];for(const Ge of S(YA,KA,te,XA,D))UA(Ge)}}if(SA.length<2)return null;const GA=k(SA);if(GA.length>=3&&Math.abs(b(GA))>M){const _A=[];for(let YA=0;YA<GA.length;YA++)_A.push([hA.unproject(GA[YA]),hA.unproject(GA[(YA+1)%GA.length])]);return{type:"segments",segments:_A}}return GA.length>=2&&C.dist(GA[0],GA[GA.length-1])>D?{type:"segments",segments:[[hA.unproject(GA[0]),hA.unproject(GA[GA.length-1])]]}:null},"coplanarTriangleOverlap"),J=r((z,aA)=>{const hA=F(z[0],z[1],z[2]),MA=F(aA[0],aA[1],aA[2]);if(!hA||!MA)return null;const fA=aA.map(oe=>m(hA,oe)),SA=z.map(oe=>m(MA,oe)),UA=r(oe=>oe.every(ke=>ke>u),"allPositive"),GA=r(oe=>oe.every(ke=>ke<-u),"allNegative");if(UA(fA)||GA(fA)||UA(SA)||GA(SA))return null;const _A=B.cross(hA.n,MA.n),YA=B.len(_A);if(YA<=1e-8&&fA.every(oe=>Math.abs(oe)<=u)&&SA.every(oe=>Math.abs(oe)<=u)){const oe=G(z[0],z[1],z[2]);return oe?x(z,aA,oe):null}if(!(YA>1e-14))return null;const KA=L(z,MA),OA=L(aA,hA);if(KA.length<2||OA.length<2){if(KA.length===1&&OA.length===2&&R(KA[0],OA[0],OA[1]))return{type:"point",point:KA[0]};if(OA.length===1&&KA.length===2&&R(OA[0],KA[0],KA[1]))return{type:"point",point:OA[0]};const oe=KA.concat(OA),ke=[];for(const Oe of oe)ke.some(ve=>B.dist(ve,Oe)<=D)||ke.push(Oe);return ke.length===1?{type:"point",point:ke[0]}:null}const te=B.mul(_A,1/YA),XA=KA[0],Ge=KA.map(oe=>B.dot(B.sub(oe,XA),te)).sort((oe,ke)=>oe-ke),zA=OA.map(oe=>B.dot(B.sub(oe,XA),te)).sort((oe,ke)=>oe-ke),ae=Math.max(Ge[0],zA[0]),de=Math.min(Ge[1],zA[1]);if(de<ae-D)return null;const we=B.add(XA,B.mul(te,ae)),Qe=B.add(XA,B.mul(te,de));return B.dist(we,Qe)>D?{type:"segments",segments:[[we,Qe]]}:{type:"point",point:we}},"triangleIntersection"),$=new Array(n);for(let z=0;z<n;z++){const aA=z*3,hA=s[aA+0]>>>0,MA=s[aA+1]>>>0,fA=s[aA+2]>>>0,SA=[p(hA),p(MA),p(fA)],UA=[Math.min(SA[0][0],SA[1][0],SA[2][0]),Math.min(SA[0][1],SA[1][1],SA[2][1]),Math.min(SA[0][2],SA[1][2],SA[2][2])],GA=[Math.max(SA[0][0],SA[1][0],SA[2][0]),Math.max(SA[0][1],SA[1][1],SA[2][1]),Math.max(SA[0][2],SA[1][2],SA[2][2])];$[z]={indices:[hA,MA,fA],id:I[z]??0,points:SA,min:UA,max:GA,segments:[],pointsOnly:[],segmentKeys:new Set,pointKeys:new Set}}const T=r((z,aA)=>{const hA=y(aA);z.pointKeys.has(hA)||(z.pointKeys.add(hA),z.pointsOnly.push(aA))},"addPointOnly"),H=r((z,aA,hA)=>{if(B.dist(aA,hA)<=D){T(z,aA);return}const MA=y(aA),fA=y(hA),SA=MA<fA?`${MA}|${fA}`:`${fA}|${MA}`;z.segmentKeys.has(SA)||(z.segmentKeys.add(SA),z.segments.push([aA,hA]))},"addSegment"),X=r((z,aA)=>{const hA=[],MA=r(fA=>{hA.some(SA=>B.dist(SA,fA)<=D)||hA.push(fA)},"add");for(const fA of z.points)for(const SA of aA.points)B.dist(fA,SA)<=D&&MA(fA);return hA},"sharedCoordinatePoints"),oA=r((z,aA,hA,MA)=>{const fA=X(z,aA);if(fA.length!==2)return!1;const SA=B.dist(hA,fA[0])<=D&&B.dist(MA,fA[1])<=D,UA=B.dist(hA,fA[1])<=D&&B.dist(MA,fA[0])<=D;return SA||UA},"isOnlySharedEdge"),_=r((z,aA,hA)=>{const MA=X(z,aA);return MA.length>0&&MA.some(fA=>B.dist(fA,hA)<=D)},"isOnlySharedPoint"),V=r((z,aA)=>!(z.max[0]<aA.min[0]-u||aA.max[0]<z.min[0]-u||z.max[1]<aA.min[1]-u||aA.max[1]<z.min[1]-u||z.max[2]<aA.min[2]-u||aA.max[2]<z.min[2]-u),"overlapAABB"),O=Array.from({length:n},(z,aA)=>aA).sort((z,aA)=>$[z].min[0]-$[aA].min[0]);let AA=0,BA=0,rA=0;for(let z=0;z<O.length;z++){const aA=O[z],hA=$[aA];if(!(f(hA.points[0],hA.points[1],hA.points[2])<=M))for(let MA=z+1;MA<O.length;MA++){const fA=O[MA],SA=$[fA];if(SA.min[0]>hA.max[0]+u)break;if(!V(hA,SA)||f(SA.points[0],SA.points[1],SA.points[2])<=M)continue;rA++;const UA=J(hA.points,SA.points);if(!UA)continue;const GA=X(hA,SA);if(GA.length>0){const YA=r(KA=>GA.some(OA=>B.dist(KA,OA)<=D),"touchesCommonPoint");if(UA.type==="point"&&YA(UA.point))continue;if(UA.type==="segments"){const KA=UA.segments||[];if(KA.length&&KA.every(([OA,te])=>YA(OA)||YA(te)))continue}}if(UA.type==="point"){if(_(hA,SA,UA.point))continue;if(T(hA,UA.point),T(SA,UA.point),BA++,t&&g>0&&AA+BA>=g)return AA+BA;continue}let _A=!1;for(const[YA,KA]of UA.segments||[])oA(hA,SA,YA,KA)||(H(hA,YA,KA),H(SA,YA,KA),_A=!0);if(_A&&(AA++,t&&g>0&&AA+BA>=g))return AA+BA}}const tA=AA+BA;if(tA===0)return e&&console.log("[splitSelfIntersectingTriangles] no splittable intersections",{triCount:n,testedPairs:rA}),0;const sA=new Set,eA=[],K=r(z=>{const aA=y(z);sA.has(aA)||(sA.add(aA),eA.push(z))},"addEdgeSplitPoint");for(const z of $){for(const[aA,hA]of z.segments)K(aA),K(hA);for(const aA of z.pointsOnly)K(aA)}if(eA.length&&eA.length<=1024)for(const z of $)for(const aA of eA){if(z.points.some(MA=>B.dist(MA,aA)<=D))continue;let hA=!1;for(let MA=0;MA<3;MA++){const fA=z.points[MA],SA=z.points[(MA+1)%3];if(R(aA,fA,SA,D)){hA=!0;break}}hA&&T(z,aA)}this._vertProperties=o.slice(),this._vertKeyToIndex=new Map;const v=new Map;for(let z=0;z<this._vertProperties.length;z+=3){const aA=z/3|0,hA=[this._vertProperties[z+0],this._vertProperties[z+1],this._vertProperties[z+2]];this._vertKeyToIndex.set(`${hA[0]},${hA[1]},${hA[2]}`,aA),v.has(y(hA))||v.set(y(hA),aA)}const iA=r(z=>{const aA=y(z),hA=v.get(aA);if(hA!==void 0)return hA;const MA=this._vertProperties.length/3|0;return this._vertProperties.push(z[0],z[1],z[2]),v.set(aA,MA),this._vertKeyToIndex.set(`${z[0]},${z[1]},${z[2]}`,MA),MA},"getOrCreateVertex"),QA=r(z=>{const aA=G(z.points[0],z.points[1],z.points[2]);if(!aA)return null;const hA=[],MA=new Map,fA=new Map,SA=[],UA=Math.max(C.dist(aA.project(z.points[0]),aA.project(z.points[1])),C.dist(aA.project(z.points[1]),aA.project(z.points[2])),C.dist(aA.project(z.points[2]),aA.project(z.points[0])),1),GA=Math.max(D,UA*1e-10),_A=Math.max(1e-18,UA*UA*1e-16),YA=r(XA=>`${Math.round(XA[0]/GA)},${Math.round(XA[1]/GA)}`,"localKey"),KA=r(XA=>{const Ge=iA(XA),zA=MA.get(Ge);if(zA!==void 0)return zA;const ae=aA.project(XA),de=YA(ae),we=fA.get(de);if(we!==void 0)return MA.set(Ge,we),we;const Qe=hA.length;return hA.push({global:Ge,p3:XA,p2:ae}),MA.set(Ge,Qe),fA.set(de,Qe),Qe},"addLocalPoint"),OA=r((XA,Ge)=>{const zA=KA(XA),ae=KA(Ge);zA!==ae&&SA.push([zA,ae])},"addLocalSegment"),te=z.points.map(KA);OA(z.points[0],z.points[1]),OA(z.points[1],z.points[2]),OA(z.points[2],z.points[0]);for(const[XA,Ge]of z.segments)OA(XA,Ge);for(const XA of z.pointsOnly){const Ge=KA(XA);for(const zA of te)Ge!==zA&&SA.push([Ge,zA])}return{basis:aA,localPoints:hA,localSegments:SA,original:te,eps2:GA,area2:_A}},"makeLocalRetriangulator"),gA=r((z,aA,hA,MA,fA)=>{const SA=C.sub(aA,z),UA=C.sub(hA,z),GA=C.sub(MA,z),_A=C.sub(MA,hA),YA=C.sub(z,hA),KA=C.sub(aA,hA),OA=C.cross(SA,UA),te=C.cross(SA,GA),XA=C.cross(_A,YA),Ge=C.cross(_A,KA);return OA*te<-fA*fA&&XA*Ge<-fA*fA},"segmentProperlyCrosses"),IA=r(z=>{if(!z.segments.length&&!z.pointsOnly.length)return[[z.indices[0],z.indices[1],z.indices[2]]];const aA=QA(z);if(!aA)return[[z.indices[0],z.indices[1],z.indices[2]]];const{localPoints:hA,localSegments:MA,original:fA,eps2:SA,area2:UA}=aA,GA=B.norm(B.cross(B.sub(z.points[1],z.points[0]),B.sub(z.points[2],z.points[0]))),_A=r(()=>{const we=MA.length;for(let Qe=0;Qe<we;Qe++){const[oe,ke]=MA[Qe],Oe=hA[oe].p2,ve=hA[ke].p2;for(let gt=Qe+1;gt<we;gt++){const[$e,vt]=MA[gt],ng=hA[$e].p2,Rg=hA[vt].p2;for(const ug of S(Oe,ve,ng,Rg,SA)){const ki=aA.basis.unproject(ug);(()=>{const Bg=iA(ki),eo=hA.findIndex(cs=>cs.global===Bg);if(eo>=0)return eo;const fs=hA.length;return hA.push({global:Bg,p3:ki,p2:ug}),fs})()}}}},"addSegmentIntersections");r(()=>{const we=new Int32Array(hA.length);for(let gt=0;gt<we.length;gt++)we[gt]=gt;const Qe=r(gt=>{let $e=gt;for(;we[$e]!==$e;)$e=we[$e];for(;we[gt]!==gt;){const vt=we[gt];we[gt]=$e,gt=vt}return $e},"find"),oe=r((gt,$e)=>{const vt=Qe(gt),ng=Qe($e);vt!==ng&&(we[ng]=vt)},"unite");for(const[gt,$e]of MA)oe(gt,$e);const ke=Qe(fA[0]),Oe=new Map;for(let gt=0;gt<hA.length;gt++){const $e=Qe(gt);let vt=Oe.get($e);vt||(vt=[],Oe.set($e,vt)),vt.push(gt)}const ve=r(()=>MA.map(([gt,$e])=>[hA[gt].p2,hA[$e].p2]),"existingSegments");for(const[gt,$e]of Oe.entries()){if(gt===ke||$e.some(Rg=>fA.includes(Rg)))continue;let vt=null;const ng=ve();for(const Rg of $e){const ug=hA[Rg].p2;for(const ki of fA){const Bg=hA[ki].p2;let eo=!0;for(const[cs,Eo]of ng)if(!(C.dist(ug,cs)<=SA||C.dist(ug,Eo)<=SA||C.dist(Bg,cs)<=SA||C.dist(Bg,Eo)<=SA)&&gA(ug,Bg,cs,Eo,SA)){eo=!1;break}if(!eo)continue;const fs=C.dist(ug,Bg);(!vt||fs<vt.dist)&&(vt={member:Rg,target:ki,dist:fs})}}vt&&MA.push([vt.member,vt.target])}},"connectInteriorComponents")(),_A();const YA=new Set,KA=r((we,Qe)=>{if(we===Qe||C.dist(hA[we].p2,hA[Qe].p2)<=SA)return;const oe=we<Qe?`${we}|${Qe}`:`${Qe}|${we}`;YA.has(oe)||YA.add(oe)},"addEdge");for(const[we,Qe]of MA){const oe=hA[we].p2,ke=hA[Qe].p2,Oe=C.sub(ke,oe),ve=C.dot(Oe,Oe);if(!(ve>SA*SA))continue;const gt=[];for(let $e=0;$e<hA.length;$e++){const vt=hA[$e].p2;if(!Y(vt,oe,ke,SA))continue;const ng=C.dot(C.sub(vt,oe),Oe)/ve;gt.push({index:$e,t:ng})}gt.sort(($e,vt)=>$e.t-vt.t);for(let $e=0;$e+1<gt.length;$e++)KA(gt[$e].index,gt[$e+1].index)}const OA=new Map;for(const we of YA){const[Qe,oe]=we.split("|"),ke=Number(Qe),Oe=Number(oe);OA.has(ke)||OA.set(ke,new Set),OA.has(Oe)||OA.set(Oe,new Set),OA.get(ke).add(Oe),OA.get(Oe).add(ke)}for(const[we,Qe]of OA.entries()){const oe=hA[we].p2;OA.set(we,Array.from(Qe).sort((ke,Oe)=>{const ve=hA[ke].p2,gt=hA[Oe].p2;return Math.atan2(ve[1]-oe[1],ve[0]-oe[0])-Math.atan2(gt[1]-oe[1],gt[0]-oe[0])}))}const te=new Set,XA=r((we,Qe)=>`${we}>${Qe}`,"directedKey"),Ge=[];for(const we of YA){const[Qe,oe]=we.split("|");for(const ke of[[Number(Qe),Number(oe)],[Number(oe),Number(Qe)]]){let[Oe,ve]=ke;if(te.has(XA(Oe,ve)))continue;const gt=[],$e=Math.max(12,YA.size*4);let vt=0;for(;!te.has(XA(Oe,ve))&&vt++<$e;){te.add(XA(Oe,ve)),gt.push(Oe);const ng=OA.get(ve)||[],Rg=ng.indexOf(Oe);if(Rg<0||ng.length===0)break;const ug=ng[(Rg-1+ng.length)%ng.length];if(Oe=ve,ve=ug,Oe===ke[0]&&ve===ke[1])break}gt.length>=3&&b(gt,ng=>hA[ng].p2)>UA&&Ge.push(gt)}}const zA=r((we,Qe,oe,ke)=>{const Oe=Math.abs(C.cross(C.sub(oe,Qe),C.sub(ke,Qe)));if(!(Oe>UA))return!1;const ve=Math.abs(C.cross(C.sub(Qe,we),C.sub(oe,we))),gt=Math.abs(C.cross(C.sub(oe,we),C.sub(ke,we))),$e=Math.abs(C.cross(C.sub(ke,we),C.sub(Qe,we)));return Math.abs(ve+gt+$e-Oe)>Math.max(UA,Oe*1e-8)?!1:ve>UA&&gt>UA&&$e>UA},"pointStrictlyInTri2D"),ae=r(we=>{const Qe=[],oe=we.slice();b(oe,Oe=>hA[Oe].p2)<0&&oe.reverse();let ke=0;for(;oe.length>3&&ke++<we.length*we.length*4;){let Oe=!1;for(let ve=0;ve<oe.length;ve++){const gt=oe[(ve-1+oe.length)%oe.length],$e=oe[ve],vt=oe[(ve+1)%oe.length],ng=hA[gt].p2,Rg=hA[$e].p2,ug=hA[vt].p2;if(C.cross(C.sub(Rg,ng),C.sub(ug,Rg))<=UA)continue;let ki=!1;for(const Bg of oe)if(!(Bg===gt||Bg===$e||Bg===vt)&&zA(hA[Bg].p2,ng,Rg,ug)){ki=!0;break}if(!ki){Qe.push([gt,$e,vt]),oe.splice(ve,1),Oe=!0;break}}if(!Oe){for(let ve=1;ve+1<oe.length;ve++)Qe.push([oe[0],oe[ve],oe[ve+1]]);oe.length=0}}return oe.length===3&&Qe.push([oe[0],oe[1],oe[2]]),Qe},"triangulateLoop"),de=[];for(const we of Ge)for(const Qe of ae(we)){const oe=hA[Qe[0]],ke=hA[Qe[1]],Oe=hA[Qe[2]];if(f(oe.p3,ke.p3,Oe.p3)<=M)continue;const ve=B.cross(B.sub(ke.p3,oe.p3),B.sub(Oe.p3,oe.p3));B.dot(ve,GA)<0?de.push([oe.global,Oe.global,ke.global]):de.push([oe.global,ke.global,Oe.global])}return de.length?de:[[z.indices[0],z.indices[1],z.indices[2]]]},"retriangulateRecord"),lA=[],cA=[];let CA=0;for(let z=0;z<n;z++){const aA=$[z],hA=IA(aA);(aA.segments.length||aA.pointsOnly.length)&&CA++;for(const MA of hA)lA.push(MA[0],MA[1],MA[2]),cA.push(aA.id)}this._triVerts=lA,this._triIDs=cA,this._dirty=!0,this._faceIndex=null,this._manifold=null;try{this.removeDegenerateTriangles()}catch{}const EA=r(()=>{const z=this._triVerts||[],aA=this._vertProperties||[],hA=this._triIDs||[],MA=z.length/3|0,fA=new Set,SA=[],UA=[];let GA=0;for(let _A=0;_A<MA;_A++){const YA=_A*3,KA=[z[YA+0]>>>0,z[YA+1]>>>0,z[YA+2]>>>0],OA=KA.map(te=>y([aA[te*3+0],aA[te*3+1],aA[te*3+2]])).sort().join("|");if(fA.has(OA)){GA++;continue}fA.add(OA),SA.push(KA[0],KA[1],KA[2]),UA.push(hA[_A])}return GA?(this._triVerts=SA,this._triIDs=UA,this._dirty=!0,this._faceIndex=null,this._manifold=null,GA):0},"removeDuplicateTriangles")();return r(()=>{const z=this._triVerts||[],aA=this._vertProperties||[],hA=aA.length/3|0,MA=new Uint8Array(hA);for(const GA of z)MA[GA>>>0]=1;const fA=new Int32Array(hA);for(let GA=0;GA<hA;GA++)fA[GA]=-1;const SA=[];let UA=0;for(let GA=0;GA<hA;GA++)MA[GA]&&(fA[GA]=UA++,SA.push(aA[GA*3+0],aA[GA*3+1],aA[GA*3+2]));for(let GA=0;GA<z.length;GA++)z[GA]=fA[z[GA]>>>0];this._vertProperties=SA,this._vertKeyToIndex=new Map;for(let GA=0;GA<SA.length;GA+=3)this._vertKeyToIndex.set(`${SA[GA]},${SA[GA+1]},${SA[GA+2]}`,GA/3|0)},"compactVertices")(),e&&console.log("[splitSelfIntersectingTriangles] complete",{initialTriangles:n,finalTriangles:this._triVerts.length/3|0,testedPairs:rA,pairIntersections:AA,pointIntersections:BA,touchedTriangles:CA,duplicateRemovals:EA}),tA}c(Yct,"DHt");r(Yct,"splitSelfIntersectingTriangles");function Uct(){if(!this._triVerts||!this._vertProperties)return 0;try{this._manifoldize()}catch{console.log("[removeDegenerateTriangles] manifoldization failed, proceeding with best effort cleanup")}const i={sub:r((s,I)=>[s[0]-I[0],s[1]-I[1],s[2]-I[2]],"sub"),len:r(s=>Math.sqrt(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]),"len"),cross:r((s,I)=>[s[1]*I[2]-s[2]*I[1],s[2]*I[0]-s[0]*I[2],s[0]*I[1]-s[1]*I[0]],"cross")},A=this._triVerts.length/3,e=[],t=[];let g=0;const o=r(s=>{const I=s*3,n=this._triVerts[I]*3,B=this._triVerts[I+1]*3,C=this._triVerts[I+2]*3,a=[this._vertProperties[n],this._vertProperties[n+1],this._vertProperties[n+2]],Q=[this._vertProperties[B],this._vertProperties[B+1],this._vertProperties[B+2]],E=[this._vertProperties[C],this._vertProperties[C+1],this._vertProperties[C+2]],l=1e-10,h=i.len(i.sub(a,Q)),w=i.len(i.sub(Q,E)),d=i.len(i.sub(E,a));if(h<l||w<l||d<l)return!0;const D=i.cross(i.sub(Q,a),i.sub(E,a));return .5*i.len(D)<1e-12},"isDegenerate");for(let s=0;s<A;s++)if(o(s))g++;else{const I=s*3;e.push(this._triVerts[I]),e.push(this._triVerts[I+1]),e.push(this._triVerts[I+2]),t.push(this._triIDs[s])}return this._triVerts=e,this._triIDs=t,g>0&&(this._dirty=!0,this._faceIndex=null,this._manifold=null),g}c(Uct,"fHt");r(Uct,"removeDegenerateTriangles");function kct(){if((this._triVerts.length/3|0)===0)return 0;mn(YB&&$Et,"Solid.removeInternalTriangles()");const i=Ya(this),A=i.removeInternalTriangles();yQ(this,i),this._dirty=!1,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,A>0?A:0}c(kct,"MHt");r(kct,"removeInternalTriangles");function Lct(){const i=this._vertProperties,A=this._triVerts,e=this._triIDs,t=A.length/3|0;if(t===0)return 0;const g=new Array(t);for(let F=0;F<t;F++){const m=F*3,G=A[m+0]>>>0,N=A[m+1]>>>0,S=A[m+2]>>>0;g[F]=[[i[G*3+0],i[G*3+1],i[G*3+2]],[i[N*3+0],i[N*3+1],i[N*3+2]],[i[S*3+0],i[S*3+1],i[S*3+2]]]}let o=1/0,s=1/0,I=1/0,n=-1/0,B=-1/0,C=-1/0;for(let F=0;F<i.length;F+=3){const m=i[F],G=i[F+1],N=i[F+2];m<o&&(o=m),m>n&&(n=m),G<s&&(s=G),G>B&&(B=G),N<I&&(I=N),N>C&&(C=N)}const a=1e-6*(Math.hypot(n-o,B-s,C-I)||1),Q=r((F,m,G)=>{const N=G[0][0],S=G[0][1],Y=G[0][2],R=G[1][0],k=G[1][1],b=G[1][2],L=G[2][0],x=G[2][1],J=G[2][2],$=R-N,T=k-S,H=b-Y,X=L-N,oA=x-S,_=J-Y,V=m[1]*_-m[2]*oA,O=m[2]*X-m[0]*_,AA=m[0]*oA-m[1]*X,BA=$*V+T*O+H*AA;if(Math.abs(BA)<1e-12)return null;const rA=1/BA,tA=F[0]-N,sA=F[1]-S,eA=F[2]-Y,K=(tA*V+sA*O+eA*AA)*rA;if(K<-1e-12||K>1+1e-12)return null;const v=sA*H-eA*T,iA=eA*$-tA*H,QA=tA*T-sA*$,gA=(m[0]*v+m[1]*iA+m[2]*QA)*rA;if(gA<-1e-12||K+gA>1+1e-12)return null;const IA=(X*v+oA*iA+_*QA)*rA;return IA>1e-10?IA:null},"rayTri"),E=r(F=>{const m=[[1,0,0],[0,1,0],[0,0,1]];let G=0;for(let N=0;N<m.length;N++){const S=m[N],Y=[F[0]+(N+1)*a,F[1]+(N+2)*a,F[2]+(N+3)*a];let R=0;for(let k=0;k<g.length;k++)Q(Y,S,g[k])!==null&&R++;R%2===1&&G++}return G>=2},"pointInside"),l=r(F=>{const[m,G,N]=g[F],S=(m[0]+G[0]+N[0])/3+a,Y=(m[1]+G[1]+N[1])/3+a,R=(m[2]+G[2]+N[2])/3+a;return[S,Y,R]},"triProbe"),h=new Uint8Array(t);for(let F=0;F<t;F++)h[F]=1;let w=0;for(let F=0;F<t;F++){const m=l(F);E(m)&&(h[F]=0,w++)}if(w===0)return 0;const d=i.length/3|0,D=new Uint8Array(d),u=[],M=[];for(let F=0;F<t;F++){if(!h[F])continue;const m=F*3,G=A[m+0]>>>0,N=A[m+1]>>>0,S=A[m+2]>>>0;u.push(G,N,S),M.push(e[F]),D[G]=1,D[N]=1,D[S]=1}const y=new Int32Array(d);for(let F=0;F<d;F++)y[F]=-1;const p=[];let f=0;for(let F=0;F<d;F++)D[F]&&(y[F]=f++,p.push(i[F*3+0],i[F*3+1],i[F*3+2]));for(let F=0;F<u.length;F++)u[F]=y[u[F]];this._vertProperties=p,this._triVerts=u,this._triIDs=M,this._vertKeyToIndex=new Map;for(let F=0;F<this._vertProperties.length;F+=3){const m=this._vertProperties[F],G=this._vertProperties[F+1],N=this._vertProperties[F+2];this._vertKeyToIndex.set(`${m},${G},${N}`,F/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),w}c(Lct,"yHt");r(Lct,"removeInternalTrianglesByRaycast");function bct({offsetScale:i=1e-5,crossingTolerance:A=.05}={}){const e=this._vertProperties,t=this._triVerts,g=this._triIDs,o=t.length/3|0;if(o===0)return 0;let s=1/0,I=1/0,n=1/0,B=-1/0,C=-1/0,a=-1/0;for(let Y=0;Y<e.length;Y+=3){const R=e[Y],k=e[Y+1],b=e[Y+2];R<s&&(s=R),R>B&&(B=R),k<I&&(I=k),k>C&&(C=k),b<n&&(n=b),b>a&&(a=b)}const Q=Math.hypot(B-s,C-I,a-n)||1,E=i*Q,l=new Array(o),h=new Array(o),w=new Array(o);for(let Y=0;Y<o;Y++){const R=Y*3,k=t[R+0]>>>0,b=t[R+1]>>>0,L=t[R+2]>>>0,x=e[k*3+0],J=e[k*3+1],$=e[k*3+2],T=e[b*3+0],H=e[b*3+1],X=e[b*3+2],oA=e[L*3+0],_=e[L*3+1],V=e[L*3+2];l[Y]=[[x,J,$],[T,H,X],[oA,_,V]],h[Y]=[(x+T+oA)/3,(J+H+_)/3,($+X+V)/3];const O=T-x,AA=H-J,BA=X-$,rA=oA-x,tA=_-J,sA=V-$;let eA=AA*sA-BA*tA,K=BA*rA-O*sA,v=O*tA-AA*rA;const iA=Math.hypot(eA,K,v);iA<1e-18?w[Y]=[0,0,0]:w[Y]=[eA/iA,K/iA,v/iA]}const d=r((Y,R,k,b)=>{const L=R[0]-Y[0],x=R[1]-Y[1],J=R[2]-Y[2],$=k[0]-Y[0],T=k[1]-Y[1],H=k[2]-Y[2],X=b[0]-Y[0],oA=b[1]-Y[1],_=b[2]-Y[2],V=Math.hypot(L,x,J),O=Math.hypot($,T,H),AA=Math.hypot(X,oA,_);if(V<1e-18||O<1e-18||AA<1e-18)return 0;const BA=L*$+x*T+J*H,rA=$*X+T*oA+H*_,tA=X*L+oA*x+_*J,sA=x*H-J*T,eA=J*$-L*H,K=L*T-x*$,v=sA*X+eA*oA+K*_,iA=V*O*AA+BA*AA+rA*V+tA*O;return 2*Math.atan2(v,iA)},"solidAngle"),D=r(Y=>{let R=0;for(let k=0;k<o;k++){const[b,L,x]=l[k];R+=d(Y,b,L,x)}return R/(4*Math.PI)},"winding"),u=new Uint8Array(o);for(let Y=0;Y<o;Y++)u[Y]=1;let M=0;const y=Math.max(0,Math.min(.49,A));for(let Y=0;Y<o;Y++){const R=w[Y];if(!R||R[0]===0&&R[1]===0&&R[2]===0)continue;const k=h[Y],b=[k[0]+R[0]*E,k[1]+R[1]*E,k[2]+R[2]*E],L=[k[0]-R[0]*E,k[1]-R[1]*E,k[2]-R[2]*E],x=D(b),J=D(L),$=Math.abs(x)-.5,T=Math.abs(J)-.5;$<-y&&T>y||$>y&&T<-y||$*T<-y*y||(u[Y]=0,M++)}if(M===0)return 0;const p=e.length/3|0,f=new Uint8Array(p),F=[],m=[];for(let Y=0;Y<o;Y++){if(!u[Y])continue;const R=Y*3,k=t[R+0]>>>0,b=t[R+1]>>>0,L=t[R+2]>>>0;F.push(k,b,L),m.push(g[Y]),f[k]=1,f[b]=1,f[L]=1}const G=new Int32Array(p);for(let Y=0;Y<p;Y++)G[Y]=-1;const N=[];let S=0;for(let Y=0;Y<p;Y++)f[Y]&&(G[Y]=S++,N.push(e[Y*3+0],e[Y*3+1],e[Y*3+2]));for(let Y=0;Y<F.length;Y++)F[Y]=G[F[Y]];this._vertProperties=N,this._triVerts=F,this._triIDs=m,this._vertKeyToIndex=new Map;for(let Y=0;Y<this._vertProperties.length;Y+=3){const R=this._vertProperties[Y],k=this._vertProperties[Y+1],b=this._vertProperties[Y+2];this._vertKeyToIndex.set(`${R},${k},${b}`,Y/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),M}c(bct,"pHt");r(bct,"removeInternalTrianglesByWinding");function Kct(i){const A=Number(i);if(!Number.isFinite(A)||A<=0)return 0;mn(YB&&qEt,"Solid.cleanupTinyFaceIslands()");const e=Ya(this),t=e.cleanupTinyFaceIslands(A);if(t>0){yQ(this,e),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return t}c(Kct,"FHt");r(Kct,"cleanupTinyFaceIslands");function xct(i=.001){if(!Number.isFinite(i)||i<=0)return this;mn(YB&&XEt,"Solid.mergeTinyFaces()");const A=Ya(this);if(A.mergeTinyFaces(i)>0){yQ(this,A),this._faceIndex=null,this._dirty=!0;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null;try{typeof this._manifoldize=="function"&&(this._manifoldize(),typeof this._ensureFaceIndex=="function"&&this._ensureFaceIndex())}catch{}}return this}c(xct,"mHt");r(xct,"mergeTinyFaces");function Jct(){return this._manifoldize().getMesh()}c(Jct,"NHt");r(Jct,"getMesh");function Hct(){if(this._faceIndex)return;const i=this.getMesh(),{triVerts:A,faceID:e}=i,t=A.length/3|0,g=new Map;if(e&&e.length===t)for(let o=0;o<t;o++){const s=e[o];let I=g.get(s);I||(I=[],g.set(s,I)),I.push(o)}this._faceIndex=g;try{i&&typeof i.delete=="function"&&i.delete()}catch{}}c(Hct,"SHt");r(Hct,"_ensureFaceIndex");function vct(i){return mn(U5A,"Solid.getFace"),Ya(this).getFace(i)}c(vct,"GHt");r(vct,"getFace");function Tct(i){return mn(U5A,"Solid.getFaceNormal"),Ya(this).getFaceNormal(i)}c(Tct,"RHt");r(Tct,"getFaceNormal");function Pct(i=!1){return mn(U5A,"Solid.getFaces"),Ya(this).getFaces(i)}c(Pct,"YHt");r(Pct,"getFaces");function Oct(){return mn(U5A,"Solid.getBoundaryEdgePolylines"),Ya(this).getBoundaryEdgePolylines()}c(Oct,"UHt");r(Oct,"getBoundaryEdgePolylines");const lpA=.01,bTi=.0015,jct=1e-4;function zct(){return typeof Tt?.buildBooleanCombinedAuthoringState=="function"}c(zct,"LHt");r(zct,"hasNativeBooleanCombinedBuilder");function $Re(){return typeof Tt?.buildBooleanUnionManyAuthoringState=="function"}c($Re,"dgt");r($Re,"hasNativeBooleanUnionManyBuilder");function Vct(i){if(!zct())throw new Error(`${i} requires the custom local manifold build with native boolean result reconstruction support.`)}c(Vct,"bHt");r(Vct,"requireNativeBooleanCombinedBuilder");function Wct(i){if(!$Re())throw new Error(`${i} requires the custom local manifold build with native batch union result reconstruction support.`)}c(Wct,"xHt");r(Wct,"requireNativeBooleanUnionManyBuilder");function v0A(i){const A=i&&i.constructor;return A&&A.BaseSolid?A.BaseSolid:A}c(v0A,"etA");r(v0A,"baseSolidCtor$1");function _ct(i){const A=i&&i._vertProperties;if(!Array.isArray(A)||A.length<3)return 1;let e=1/0,t=1/0,g=1/0,o=-1/0,s=-1/0,I=-1/0;for(let n=0;n<A.length;n+=3){const B=A[n],C=A[n+1],a=A[n+2];B<e&&(e=B),B>o&&(o=B),C<t&&(t=C),C>s&&(s=C),a<g&&(g=a),a>I&&(I=a)}return Math.max(Math.hypot(o-e,s-t,I-g),1)}c(_ct,"KHt");r(_ct,"booleanApproxScale");function pTA(i,A=12){return[Number(i?.[0]||0).toFixed(A),Number(i?.[1]||0).toFixed(A),Number(i?.[2]||0).toFixed(A)].join(",")}c(pTA,"SNA");r(pTA,"pointKey$1");function AYe(i,A){if(!i||typeof i.getFace!="function"||!A)return[];const e=i.getFace(A)||[],t=new Map,g=r((I,n)=>{if(!Array.isArray(I)||!Array.isArray(n))return;const B=pTA(I),C=pTA(n),a=B<C?`${B}|${C}`:`${C}|${B}`,Q=t.get(a);Q?Q.count+=1:t.set(a,{count:1,points:[[Number(I[0])||0,Number(I[1])||0,Number(I[2])||0],[Number(n[0])||0,Number(n[1])||0,Number(n[2])||0]]})},"addEdge");for(const I of e){const n=Array.isArray(I?.p1)?I.p1:null,B=Array.isArray(I?.p2)?I.p2:null,C=Array.isArray(I?.p3)?I.p3:null;!n||!B||!C||(g(n,B),g(B,C),g(C,n))}const o=[],s=new Set;for(const I of t.values())if(I.count===1)for(const n of I.points){const B=pTA(n);s.has(B)||(s.add(B),o.push(n))}return o}c(AYe,"wgt");r(AYe,"faceBoundaryPoints");function qct(i,A,e){if(!i||typeof i.minGapToPoint!="function")return!1;for(const t of A){const g=i.minGapToPoint(t,e,{nearestOnly:!0});if(Array.isArray(g)&&g.some(o=>Number(o?.distance)<=e))return!0}return!1}c(qct,"HHt");r(qct,"hasNearTargetEdgePoint");function Zct(i,A,e,t,g=8){const o=AYe(A,e);if(!o.length||typeof i?.minGapToPoint!="function")return-1/0;const s=Math.max(1,Math.ceil(o.length/g)),I=Math.max(_ct(i)*2,jct*10);let n=0,B=0;for(let C=0;C<o.length;C+=s){B+=1;const a=i.minGapToPoint(o[C],I,{nearestOnly:!0});(Array.isArray(a)&&a.length>0?a[0].inside===!0:!1)===t&&(n+=1)}return B>0?n/B:-1/0}c(Zct,"JHt");r(Zct,"scoreFaceSide");function eYe(i,A,e){const t=String(i||"").toUpperCase();if(t!=="UNION"&&t!=="SUBTRACT"||!A||!e||typeof A.minGapToPoint!="function"||typeof e.getFaceNames!="function"||typeof e.pushFace!="function")return e;const g=t==="UNION",o=jct,s=o*2,I=[];for(const C of e.getFaceNames()||[]){const a=String(C||"").trim();if(!a)continue;const Q=AYe(e,a);Q.length&&qct(A,Q,o)&&I.push(a)}if(!I.length||typeof e.clone!="function")return e;const n=e.clone();let B=!1;for(const C of I){let a=null;for(const Q of[1,-1]){const E=typeof n.clone=="function"?n.clone():null;if(E)try{E.pushFace(C,Q*s,{warnMissing:!1,warnInvalidNormal:!1});const l=Zct(A,E,C,g);(!a||l>a.score)&&(a={sign:Q,score:l})}catch{}}if(!(!a||!(a.score>-1/0)))try{n.pushFace(C,a.sign*s,{warnMissing:!1,warnInvalidNormal:!1}),B=!0}catch{}}return B?n:e}c(eYe,"ugt");r(eYe,"conditionEdgePointProximity");function L5A(i,A,e){const t=new i;sB(t,A),t._dirty=!0,t._manifold=null,t._faceIndex=null;try{t.name=e||A?.name||t?.name}catch{}return t}c(L5A,"qne");r(L5A,"solidFromNativeBooleanSnapshot");function OUA(i){return i instanceof Map?Array.from(i.entries(),([A,e])=>[String(A||""),String(e||"")]).filter(A=>A[0]):Array.isArray(i)?Array.from(i,([A,e])=>[String(A||""),String(e||"")]).filter(A=>A[0]):[]}c(OUA,"IaA");r(OUA,"toMetadataJsonEntries");function uae(i){return i instanceof Map?Array.from(i.entries()):Array.isArray(i)?Array.from(i):[]}c(uae,"KPe");r(uae,"toSnapshotEntries");function rzA(i){return{numProp:Number(i?.numProp??3),vertProperties:Array.from(i?.vertProperties??[]),triVerts:Array.from(i?.triVerts??[]),triIDs:Array.from(i?.triIDs??[]),faceNameToID:uae(i?.faceNameToID),idToFaceName:uae(i?.idToFaceName),faceMetadataJson:OUA(i?.faceMetadataJson),edgeMetadataJson:OUA(i?.edgeMetadataJson),auxEdges:Array.isArray(i?.auxEdges)?i.auxEdges:[],vertexCount:Number(i?.vertexCount??0),triangleCount:Number(i?.triangleCount??0)}}c(rzA,"vKA");r(rzA,"toNativeBooleanSnapshot");function Xct(i,A,e={}){mn(typeof Tt?.buildSolidAuthoringStateFromMesh=="function","Solid.simplify");const t=new Map(A instanceof Map?A:[]),g=new Map;for(const[o,s]of t.entries())g.has(s)||g.set(s,o);return Tt.buildSolidAuthoringStateFromMesh({numProp:Number(i?.numProp??3),vertProperties:Array.from(i?.vertProperties??[]),triVerts:Array.from(i?.triVerts??[]),faceID:Array.from(i?.faceID??[]),faceNameToID:Array.from(g.entries()),idToFaceName:Array.from(t.entries()),faceMetadataJson:OUA(e?.faceMetadataJson),edgeMetadataJson:OUA(e?.edgeMetadataJson),auxEdges:Array.isArray(e?.auxEdges)?e.auxEdges:[],name:e?.name||""})}c(Xct,"vHt");r(Xct,"buildNativeSnapshotFromMesh");function DK(i,A){const e=Number(i?.numProp??3)||3,t=(A>>>0)*e,g=i?.vertProperties??[];return[Number(g[t+0])||0,Number(g[t+1])||0,Number(g[t+2])||0]}c(DK,"ET");r(DK,"_vec3FromMesh");function tYe(i,A,e){const t=A[0]-i[0],g=A[1]-i[1],o=A[2]-i[2],s=e[0]-i[0],I=e[1]-i[1],n=e[2]-i[2];let B=g*n-o*I,C=o*s-t*n,a=t*I-g*s;const Q=Math.hypot(B,C,a);return Q>0?(B/=Q,C/=Q,a/=Q,{normal:[B,C,a],area2:Q}):{normal:[0,0,0],area2:0}}c(tYe,"Dgt");r(tYe,"_triangleNormalAndArea");function fTA(i,A,e){const t=e[0]-A[0],g=e[1]-A[1],o=e[2]-A[2],s=i[0]-A[0],I=i[1]-A[1],n=i[2]-A[2],B=t*t+g*g+o*o,C=B>0?Math.max(0,Math.min(1,(s*t+I*g+n*o)/B)):0,a=s-t*C,Q=I-g*C,E=n-o*C;return a*a+Q*Q+E*E}c(fTA,"GNA");r(fTA,"_pointSegmentDistanceSq");function $ct(i,A,e,t){const g=e[0]-A[0],o=e[1]-A[1],s=e[2]-A[2],I=t[0]-A[0],n=t[1]-A[1],B=t[2]-A[2],C=i[0]-A[0],a=i[1]-A[1],Q=i[2]-A[2],E=g*g+o*o+s*s,l=g*I+o*n+s*B,h=I*I+n*n+B*B,w=C*g+a*o+Q*s,d=C*I+a*n+Q*B,D=E*h-l*l;if(Math.abs(D)>1e-18){const u=(h*w-l*d)/D,M=(E*d-l*w)/D;if(1-u-M>=0&&u>=0&&M>=0){const y=A[0]+g*u+I*M,p=A[1]+o*u+n*M,f=A[2]+s*u+B*M,F=i[0]-y,m=i[1]-p,G=i[2]-f;return F*F+m*m+G*G}}return Math.min(fTA(i,A,e),fTA(i,e,t),fTA(i,t,A))}c($ct,"THt");r($ct,"_pointTriangleDistanceSq");function Alt(i){const A={numProp:Number(i?._numProp??3)||3,vertProperties:i?._vertProperties??[],triVerts:i?._triVerts??[],faceID:i?._triIDs??[]},e=Math.min(A.triVerts.length/3|0,A.faceID.length|0),t=[];for(let g=0;g<e;g++){const o=g*3,s=DK(A,A.triVerts[o+0]),I=DK(A,A.triVerts[o+1]),n=DK(A,A.triVerts[o+2]),{normal:B,area2:C}=tYe(s,I,n);C>0&&t.push({a:s,b:I,c:n,id:A.faceID[g]>>>0,normal:B,centroid:[(s[0]+I[0]+n[0])/3,(s[1]+I[1]+n[1])/3,(s[2]+I[2]+n[2])/3]})}return t}c(Alt,"PHt");r(Alt,"_buildTaggedSourceTrianglesFromSolid");function elt(i){if(!Array.isArray(i)||i.length<512)return{all:i,candidatesForPoint:r(()=>i,"candidatesForPoint")};const A=[1/0,1/0,1/0],e=[-1/0,-1/0,-1/0];for(const B of i){const C=B.centroid;for(let a=0;a<3;a++)C[a]<A[a]&&(A[a]=C[a]),C[a]>e[a]&&(e[a]=C[a])}const t=[Math.max(1e-9,e[0]-A[0]),Math.max(1e-9,e[1]-A[1]),Math.max(1e-9,e[2]-A[2])],g=Math.max(4,Math.min(64,Math.ceil(Math.cbrt(i.length)))),o=[t[0]/g,t[1]/g,t[2]/g],s=new Map,I=r((B,C)=>Math.max(0,Math.min(g-1,Math.floor((B[C]-A[C])/o[C]))),"cellCoord"),n=r((B,C,a)=>`${B},${C},${a}`,"cellKey");for(const B of i){const C=I(B.centroid,0),a=I(B.centroid,1),Q=I(B.centroid,2),E=n(C,a,Q);let l=s.get(E);l||(l=[],s.set(E,l)),l.push(B)}return{all:i,candidatesForPoint(B){const C=I(B,0),a=I(B,1),Q=I(B,2),E=[];for(let l=0;l<=3&&E.length<32;l++)for(let h=Math.max(0,C-l);h<=Math.min(g-1,C+l);h++)for(let w=Math.max(0,a-l);w<=Math.min(g-1,a+l);w++)for(let d=Math.max(0,Q-l);d<=Math.min(g-1,Q+l);d++){const D=s.get(n(h,w,d));D&&E.push(...D)}return E.length?E:i}}}c(elt,"OHt");r(elt,"_buildRetagCandidateIndex");function tlt(i,A){const e=Alt(A),t=i?.triVerts?.length/3|0;if(!t||e.length===0)return i;const g=elt(e),o=new Uint32Array(t);for(let s=0;s<t;s++){const I=s*3,n=DK(i,i.triVerts[I+0]),B=DK(i,i.triVerts[I+1]),C=DK(i,i.triVerts[I+2]),a=[(n[0]+B[0]+C[0])/3,(n[1]+B[1]+C[1])/3,(n[2]+B[2]+C[2])/3],{normal:Q,area2:E}=tYe(n,B,C);let l=e[0].id,h=1/0;for(const w of g.candidatesForPoint(a)){const d=$ct(a,w.a,w.b,w.c),D=E>0?Math.max(-1,Math.min(1,Q[0]*w.normal[0]+Q[1]*w.normal[1]+Q[2]*w.normal[2])):1,u=d+(1-D)*1e-6;u<h&&(h=u,l=w.id)}o[s]=l>>>0}return i.faceID=o,i}c(tlt,"zHt");r(tlt,"retagSimplifiedMeshFromSourceSolid");function b5A(i,A,e,t){Vct(`Solid.${String(e||"boolean").toLowerCase()}`);const g=eN(i),o=eN(A),s=Tt.buildBooleanCombinedAuthoringState({leftSnapshot:rzA(g),rightSnapshot:rzA(o),operation:e,featureID:String(i?.owningFeatureID||i?.name||e||"BOOLEAN"),name:String(i?.name||`${e}_RESULT`),cleanupTinyFaceIslandsArea:lpA,disconnectedIslandMinVolume:lpA});return L5A(t,s,i?.name||`${e}_RESULT`)}c(b5A,"Zne");r(b5A,"buildNativeBooleanResult");function K5A(i){const A=i?.message||i?.toString?.()||String(i||"");return String(A||"unknown error").slice(0,240)}c(K5A,"Xne");r(K5A,"describeBooleanError");function FTA(i,A){if(!i||typeof i!="object")return i;try{i.__unionManyDiagnostics={...A}}catch{}try{i.userData={...i.userData||{},unionMany:{...A}}}catch{}return i}c(FTA,"RNA");r(FTA,"attachUnionManyDiagnostics");function mTA(i,A={},e=[]){if(!i||typeof i!="object")return i;const t=String(A?.name||"").trim();if(t)try{i.name=t}catch{}try{i.owningFeatureID=A?.owningFeatureID||A?.featureID||A?.featureId||e.find(g=>g?.owningFeatureID)?.owningFeatureID||i?.owningFeatureID||null}catch{}return i}c(mTA,"YNA");r(mTA,"applyUnionManyNameAndOwner");function iYe(i,A,e={}){return i.union(A,{overlapConditioningEnabled:e?.overlapConditioningEnabled})}c(iYe,"fgt");r(iYe,"unionManyPair");function gYe(i,A){try{i.unionManyDiagnostics={...A}}catch{}throw i}c(gYe,"Mgt");r(gYe,"throwUnionManyError");function ilt(i,A,e){if(!i.length)return null;let t=i[0];for(let g=1;g<i.length;g+=1){const o=i[g];e.unionAttemptCount+=1;try{t={solid:iYe(t.solid,o.solid,A),count:t.count+o.count}}catch(s){e.unionFailureCount+=1,e.skippedSolidCount+=o.count,e.firstUnionError||(e.firstUnionError=K5A(s)),A?.skipFailed||gYe(s,e)}}return t}c(ilt,"jHt");r(ilt,"unionManyNodesSequential");function glt(i,A,e){let t=i.slice();for(;t.length>1;){const g=[];for(let o=0;o<t.length;o+=2){const s=t[o],I=t[o+1];if(!I){g.push(s);continue}e.unionAttemptCount+=1;try{g.push({solid:iYe(s.solid,I.solid,A),count:s.count+I.count})}catch(n){e.unionFailureCount+=1,e.skippedSolidCount+=I.count,e.firstUnionError||(e.firstUnionError=K5A(n)),A?.skipFailed||gYe(n,e),g.push(s)}}t=g}return t[0]||null}c(glt,"VHt");r(glt,"unionManyNodesBalanced");function olt(i,A=null,e={}){const t=Array.isArray(i)?i.filter(Boolean):[];if(!t.length)return null;Wct("Solid.unionMany");const g=A||v0A(t[0]),o=t.map(C=>rzA(eN(C))),s=String(e?.featureID||t[0]?.owningFeatureID||t[0]?.name||"UNION"),I=String(e?.name||t[0]?.name||`${s}_UNION`),n=Tt.buildBooleanUnionManyAuthoringState({snapshots:o,featureID:s,name:I,cleanupTinyFaceIslandsArea:Number(e?.cleanupTinyFaceIslandsArea??lpA),disconnectedIslandMinVolume:Number(e?.disconnectedIslandMinVolume??lpA)}),B=L5A(g,n,I);try{B.owningFeatureID=e?.owningFeatureID||t.find(C=>C?.owningFeatureID)?.owningFeatureID||B?.owningFeatureID||null}catch{}return vbA(B)}c(olt,"WHt");r(olt,"buildNativeUnionManyResult");function hpA(i,A={}){const e=Array.isArray(i)?i:[i],t=(this&&typeof this=="object"&&typeof this.union=="function"?[this,...e]:e).filter(Boolean),g={unionStrategy:"none",nativeBatchUnionAvailable:$Re(),nativeBatchUnionStatus:t.length>1?"not_run":"not_applicable",nativeBatchUnionError:null,unionAttemptCount:0,unionFailureCount:0,skippedSolidCount:0,contributedSolidCount:t.length,firstUnionError:null};if(!t.length)return null;if(t.length===1){g.unionStrategy="single";const a=mTA(t[0],A,t);return FTA(a,g)}const o=String(A?.unionStrategy||"native_batch").trim().toLowerCase(),s=A?.nativeBatchUnion!==!1&&o!=="balanced"&&o!=="sequential",I=typeof this=="function"?this.BaseSolid||this:v0A(t[0]);if(s&&g.nativeBatchUnionAvailable)try{const a=olt(t,I,{...A,featureID:A?.featureID||A?.featureId,owningFeatureID:A?.owningFeatureID||A?.featureID||A?.featureId});return g.unionStrategy="native_batch",g.nativeBatchUnionStatus="passed",g.contributedSolidCount=t.length,mTA(a,A,t),FTA(a,g)}catch(a){g.nativeBatchUnionStatus="failed",g.nativeBatchUnionError=K5A(a)}else g.nativeBatchUnionAvailable?g.nativeBatchUnionStatus="disabled":g.nativeBatchUnionStatus="unavailable";const n=t.map(a=>({solid:a,count:1})),B=o==="sequential"?ilt(n,A,g):glt(n,A,g);g.unionStrategy=o==="sequential"?g.nativeBatchUnionStatus==="failed"?"sequential_fallback":"sequential":g.nativeBatchUnionStatus==="failed"?"balanced_fallback":"balanced",g.contributedSolidCount=Number(B?.count||0);const C=mTA(B?.solid||null,A,t);return FTA(C,g)}c(hpA,"I6");r(hpA,"unionMany");function slt(i,A=lpA){const e=Number(A);if(!Number.isFinite(e)||e<=0||!i||typeof i!="object")return 0;mn(STi,"Solid._dropDisconnectedIslandsByVolume");const t=Ya(i),g=t.removeDisconnectedIslandsByVolume(e);if(g>0){yQ(i,t),i._dirty=!0,i._faceIndex=null;try{i._manifold&&typeof i._manifold.delete=="function"&&i._manifold.delete()}catch{}i._manifold=null}return g}c(slt,"_Ht");r(slt,"_dropDisconnectedIslandsByVolume");function Ilt(i){const A=Number(bTi);return!i||typeof i.setEpsilon!="function"||!Number.isFinite(A)||A<=0||i.setEpsilon(A),i}c(Ilt,"qHt");r(Ilt,"_applyFixedBooleanResultWeld");function vbA(i){try{slt(i,lpA)}catch{}return Ilt(i)}c(vbA,"x0A");r(vbA,"_cleanupBooleanResult");function nlt(i,A={}){const e=v0A(this),t=A?.overlapConditioningEnabled===!1?this:eYe("UNION",i,this),g=b5A(t,i,"UNION",e);try{g.owningFeatureID=this?.owningFeatureID||i?.owningFeatureID||g?.owningFeatureID||null}catch{}return vbA(g)}c(nlt,"ZHt");r(nlt,"union");function Blt(i,A={}){const e=v0A(this),t=A?.overlapConditioningEnabled===!1?i:eYe("SUBTRACT",this,i),g=b5A(this,t,"SUBTRACT",e);try{g.owningFeatureID=this?.owningFeatureID||i?.owningFeatureID||g?.owningFeatureID||null}catch{}return vbA(g)}c(Blt,"XHt");r(Blt,"subtract");function rlt(i){const A=v0A(this),e=b5A(this,i,"INTERSECT",A);try{e.owningFeatureID=this?.owningFeatureID||i?.owningFeatureID||e?.owningFeatureID||null}catch{}return vbA(e)}c(rlt,"$Ht");r(rlt,"intersect$1");function Clt(i=void 0,A=!1){A&&typeof A=="object"&&(A=!1);const e=this.constructor,t=this._manifoldize(),g=eN(this),o=i===void 0?t.simplify():t.simplify(i);let s=null;const I=o.getMesh();try{tlt(I,this),s=Xct(I,this._idToFaceName,{faceMetadataJson:g?.faceMetadataJson,edgeMetadataJson:g?.edgeMetadataJson,auxEdges:g?.auxEdges,name:this?.name||""})}finally{try{I&&typeof I.delete=="function"&&I.delete()}catch{}}sB(this,s);try{this._manifold&&this._manifold!==o&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}if(this._manifold=o,this._dirty=!1,this._faceIndex=null,A)return this;this._manifold=null,this._dirty=!0,this._faceIndex=null;const n=L5A(e,s,this?.name||"");return this._manifoldize(),n}c(Clt,"AJt");r(Clt,"simplify");function alt(i){return i.faceID&&i.faceID.length?Array.from(i.faceID):new Array(i.triVerts.length/3|0).fill(0)}c(alt,"eJt");r(alt,"_expandTriIDsFromMesh");function CzA(i){return String(i??"").replace(/'/g,"''")}c(CzA,"TKA");r(CzA,"_escapeStepString");function xd(i,A="NAME"){const e=String(i??"").trim();return CzA(e||A)}c(xd,"DD");r(xd,"_safeStepName");function IQ(i,A){if(!Number.isFinite(i))return"0";let e=Number(i).toFixed(A);return e.includes(".")&&(e=e.replace(/\.?0+$/,"")),e==="-0"&&(e="0"),e}c(IQ,"bQ");r(IQ,"_fmtNumber");function Qlt(i,A=6){if(!Number.isFinite(i)||i===0)return"0.";const e=Number(i).toExponential(A),[t,g]=e.split("e"),o=Number(g);return`${t.toUpperCase()}E${o>=0?"+":""}${o}`}c(Qlt,"tJt");r(Qlt,"_fmtExp");function Elt(i,A=1e-12){if(!i||i.length!==16)return!0;const e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let t=0;t<16;t++)if(Math.abs((i[t]??e[t])-e[t])>A)return!1;return!0}c(Elt,"iJt");r(Elt,"_isIdentityMatrixElements$1");function Mae(i,A,e,t){if(!i||i.length!==16)return[A,e,t];const g=i[0]*A+i[4]*e+i[8]*t+i[12],o=i[1]*A+i[5]*e+i[9]*t+i[13],s=i[2]*A+i[6]*e+i[10]*t+i[14],I=i[3]*A+i[7]*e+i[11]*t+i[15];return I&&Math.abs(I-1)>1e-12?[g/I,o/I,s/I]:[g,o,s]}c(Mae,"HPe");r(Mae,"_applyMatrix4");function uO(i,A=[0,0,1]){const e=i[0],t=i[1],g=i[2],o=Math.hypot(e,t,g);return!o||!Number.isFinite(o)?A.slice():[e/o,t/o,g/o]}c(uO,"Zq");r(uO,"_normalize$1");function x5A(i,A){return[i[1]*A[2]-i[2]*A[1],i[2]*A[0]-i[0]*A[2],i[0]*A[1]-i[1]*A[0]]}c(x5A,"$ne");r(x5A,"_cross");function VG(i,A){return i[0]*A[0]+i[1]*A[1]+i[2]*A[2]}c(VG,"cb");r(VG,"_dot");function yae(i,A){return[i[0]-A[0],i[1]-A[1],i[2]-A[2]]}c(yae,"JPe");r(yae,"_sub");function NTA(i){const A=Math.abs(i[2])<.9?[0,0,1]:[0,1,0],e=x5A(A,i);return uO(e,[1,0,0])}c(NTA,"UNA");r(NTA,"_orthogonalRefDir");function STA(i,A=40){if(!i||i.length===0)return"()";if(i.length<=A)return`(${i.map(t=>`#${t}`).join(",")})`;const e=[];for(let t=0;t<i.length;t+=A){const g=i.slice(t,t+A).map(o=>`#${o}`).join(",");e.push(g)}return`(
4811
+ `,document.head.appendChild(A)}},c(aW,"ohe2"),aW);r(QEt,"CADmaterialWidget");let h8e=QEt;function mf(){const i=document.createElement("div");return i.className="cmw-row",i}c(mf,"hN");r(mf,"makeRightSpan");var QW;const EEt=(QW=class extends hO{constructor(A){super(A,Do.EDGE.BASE),this.faces=[],this.name=null,this.type="EDGE",this.renderOrder=2,this.closedLoop=!1,Ps.attach(this)}length(){const A=new W,e=new W;let t=0;const g=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null,o=r((I,n,B,C,a,Q)=>{A.set(I,n,B).applyMatrix4(this.matrixWorld),e.set(C,a,Q).applyMatrix4(this.matrixWorld),t+=A.distanceTo(e)},"addSeg");if(g&&g.length>=2){for(let I=0;I<g.length-1;I++){const n=g[I],B=g[I+1];o(n[0],n[1],n[2],B[0],B[1],B[2])}return t}const s=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(s&&s.itemSize===3&&s.count>=2){for(let I=0;I<s.count-1;I++)o(s.getX(I),s.getY(I),s.getZ(I),s.getX(I+1),s.getY(I+1),s.getZ(I+1));return t}return 0}points(A=!0){const e=new W,t=[],g=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null;if(g&&g.length){for(let s=0;s<g.length;s++){const I=g[s];e.set(I[0],I[1],I[2]),A&&e.applyMatrix4(this.matrixWorld),t.push({x:e.x,y:e.y,z:e.z})}return t}const o=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(o&&o.itemSize===3&&o.count>=1)for(let s=0;s<o.count;s++)e.set(o.getX(s),o.getY(s),o.getZ(s)),A&&e.applyMatrix4(this.matrixWorld),t.push({x:e.x,y:e.y,z:e.z});return t}collapseToPoint(){const A=this.parentSolid||this.parent||null,e=Array.isArray(A?._vertProperties)?A._vertProperties:null;if(!A||!e||e.length<3)return this;if(this?.userData?.auxEdge)return this;const t=cEt(this,A);if(!t.length)return this;let g=0,o=0,s=0,I=0;for(const E of t){const l=E*3|0;l<0||l+2>=e.length||(g+=e[l+0],o+=e[l+1],s+=e[l+2],I++)}if(!I)return this;const n=1/I,B=g*n,C=o*n,a=s*n;for(const E of t){const l=E*3|0;l<0||l+2>=e.length||(e[l+0]=B,e[l+1]=C,e[l+2]=a)}const Q=e.length/3|0;A._vertKeyToIndex=new Map;for(let E=0;E<Q;E++){const l=E*3;A._vertKeyToIndex.set(`${e[l+0]},${e[l+1]},${e[l+2]}`,E)}A._dirty=!0,A._faceIndex=null;try{A._manifold&&typeof A._manifold.delete=="function"&&A._manifold.delete()}catch{}A._manifold=null;try{typeof A._manifoldize=="function"&&A._manifoldize()}catch(E){console.warn(`[Edge.collapseToPoint] Manifold rebuild failed for edge "${this.name||"UNKNOWN"}":`,E?.message||E)}try{typeof A.visualize=="function"&&A.visualize()}catch(E){console.warn(`[Edge.collapseToPoint] Solid visualize failed for edge "${this.name||"UNKNOWN"}":`,E?.message||E)}return this}setMetadata(A){return this.parentSolid&&typeof this.parentSolid.setEdgeMetadata=="function"&&this.parentSolid.setEdgeMetadata(this.name,A),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getEdgeMetadata=="function"?this.parentSolid.getEdgeMetadata(this.name):null}},c(QW,"nhe2"),QW);r(EEt,"Edge");let gYA=EEt;function cEt(i,A){const e=Array.isArray(A?._vertProperties)?A._vertProperties:null;if(!e||e.length<3)return[];const t=(e.length/3|0)-1;let g=[];try{g=typeof A.getBoundaryEdgePolylines=="function"?A.getBoundaryEdgePolylines()||[]:[]}catch{g=[]}const o=lEt(i,g);if(o&&Array.isArray(o.indices)&&o.indices.length){const s=[],I=new Set;for(const n of o.indices){const B=Number(n);!Number.isInteger(B)||B<0||B>t||I.has(B)||(I.add(B),s.push(B))}if(s.length)return s}return wEt(i?.userData?.polylineLocal,e)}c(cEt,"tKt");r(cEt,"resolveEdgeVertexIndices");function lEt(i,A){if(!Array.isArray(A)||A.length===0)return null;const e=typeof i?.name=="string"&&i.name?i.name:null;if(e){const B=A.find(C=>C&&C.name===e);if(B)return B}const t=i?.userData?.faceA,g=i?.userData?.faceB;let o=A;if(t&&g&&(o=A.filter(B=>{if(!B)return!1;const C=B.faceA,a=B.faceB;return C===t&&a===g||C===g&&a===t}),o.length===1))return o[0];const s=Array.isArray(i?.userData?.polylineLocal)?i.userData.polylineLocal:null;if(!s||s.length<2)return o[0]||null;let I=null,n=1/0;for(const B of o){const C=hEt(s,B?.positions);C<n&&(n=C,I=B)}return I}c(lEt,"iKt");r(lEt,"findMatchingBoundaryPolyline$1");function hEt(i,A){if(!Array.isArray(i)||i.length<2||!Array.isArray(A)||A.length<2)return 1/0;const e=i[0],t=i[i.length-1],g=A[0],o=A[A.length-1];if(!Gb(e)||!Gb(t)||!Gb(g)||!Gb(o))return 1/0;const s=HNA(e,g)+HNA(t,o),I=HNA(e,o)+HNA(t,g);return Math.min(s,I)}c(hEt,"gKt");r(hEt,"polylineEndpointScore$2");function wEt(i,A){if(!Array.isArray(i)||i.length===0)return[];const e=A.length/3|0,t=new Map;for(let s=0;s<e;s++){const I=s*3,n=`${A[I+0]},${A[I+1]},${A[I+2]}`;t.has(n)||t.set(n,s)}const g=[],o=new Set;for(const s of i){if(!Gb(s))continue;const I=`${s[0]},${s[1]},${s[2]}`;let n=t.get(I);n===void 0&&(n=dEt(A,s,1e-9)),!(!Number.isInteger(n)||n<0||o.has(n))&&(o.add(n),g.push(n))}return g}c(wEt,"sKt");r(wEt,"resolveIndicesFromPolylinePoints$1");function dEt(i,A,e=1e-9){if(!Array.isArray(i)||!Gb(A)||!Number.isFinite(e)||e<=0)return-1;const t=e*e,g=i.length/3|0;let o=-1,s=t;for(let I=0;I<g;I++){const n=I*3,B=i[n+0]-A[0],C=i[n+1]-A[1],a=i[n+2]-A[2],Q=B*B+C*C+a*a;Q<=s&&(s=Q,o=I)}return o}c(dEt,"oKt");r(dEt,"findNearestVertexIndex$1");function HNA(i,A){const e=i[0]-A[0],t=i[1]-A[1],g=i[2]-A[2];return e*e+t*t+g*g}c(HNA,"ugA");r(HNA,"pointDistanceSq$4");function Gb(i){return Array.isArray(i)&&i.length===3&&Number.isFinite(i[0])&&Number.isFinite(i[1])&&Number.isFinite(i[2])}c(Gb,"b1");r(Gb,"isPoint3$3");var EW;const DEt=(EW=class extends Xg{constructor(A=[0,0,0],e={}){super(),this.type="VERTEX",this.name=e.name||`VERTEX(${A[0]},${A[1]},${A[2]})`,this.position.set(A[0]||0,A[1]||0,A[2]||0);const t=new Kt;t.setAttribute("position",new bt([0,0,0],3));const g=Do?.VERTEX?.BASE||new iM({color:"#ffb703",size:6,sizeAttenuation:!1});this._point=new NUA(t,g),this.add(this._point),Ps.attach(this)}},c(EW,"Ihe2"),EW);r(DEt,"Vertex");let jRe=DEt;function IzA(i,A,e,t,g,o,s,I,n){const B=t-i,C=g-A,a=o-e,Q=s-i,E=I-A,l=n-e,h=C*l-a*E,w=a*Q-B*l,d=B*E-C*Q;return .5*Math.hypot(h,w,d)}c(IzA,"KKA");r(IzA,"computeTriangleArea");const dae=1e-9,Lo=1e-12;function nzA(i,A="FACE"){const e=(i==null?"":String(i)).trim();return e&&e.replace(/[:[\]]+/g,"_").replace(/\s+/g,"_").replace(/[^A-Za-z0-9_.-]/g,"_")||A}c(nzA,"JKA");r(nzA,"sanitizeToken$2");function hr(i,A){const e=i<A?i:A,t=i<A?A:i;return`${e}|${t}`}c(hr,"eC");r(hr,"edgeKey$2");function hw(i){i&&typeof i=="object"&&(i._cppSolidCoreSyncStamp=null)}c(hw,"fw");r(hw,"invalidateCppSolidCoreCache");function Rb(i,A){const e=A>0?1/A:1e6;return[Math.round(i.x*e),Math.round(i.y*e),Math.round(i.z*e)].join(",")}c(Rb,"x1");r(Rb,"pointKey$2");function QU(i,A,e){return new W().subVectors(A,i).cross(new W().subVectors(e,i))}c(QU,"sK");r(QU,"triangleNormal");function S5A(i,A,e){return QU(i,A,e).length()*.5}c(S5A,"jne");r(S5A,"triangleArea$1");function G5A(i){const A=i?.userData?.faceName??i?.faceName??i?.name??null;return A==null?null:String(A).trim()||null}c(G5A,"Vne");r(G5A,"getFaceLabel");function uEt(i){const A=Array.isArray(i)?i:i==null?[]:[i],e=[],t=new Set;for(const g of A){const o=typeof g=="string"?g:g?.userData?.faceName??g?.faceName??g?.name??null,s=String(o||"").trim();!s||t.has(s)||(t.add(s),e.push(s))}return e}c(uEt,"nKt");r(uEt,"getFaceLabelList");function MEt(i,A){const e=uEt(i.adjacentNormalFaceNames??i.smoothAdjacentNormalFaceNames??i.selectedFaceNames),t=String(A||"").trim(),g=e.filter(o=>o&&o!==t);return g.length?new Set(g):null}c(MEt,"IKt");r(MEt,"getAdjacentNormalFaceFilter");function yEt(i){const A=i?.parentSolid||(String(i?.parent?.type||"").toUpperCase()==="SOLID"?i.parent:null);return String(A?.uuid||A?.id||A?.name||"NO_OWNER")}c(yEt,"rKt");r(yEt,"getFaceOwnerKey");function oYA(i,A){return i<A?`${i}|${A}`:`${A}|${i}`}c(oYA,"qnA");r(oYA,"unorderedPointPairKey");function pEt(i,A){return!i||!A||i.sourceFaceName!=null&&(A.sourceFaceName=i.sourceFaceName),A}c(pEt,"BKt");r(pEt,"copyTriangleMetadata");function TUA(i,A={}){const e=Array.isArray(i)?i.filter(f=>f?.geometry):[];if(e.length<=1)return e.length?[e]:[];const t=new W;let g=1/0,o=1/0,s=1/0,I=-1/0,n=-1/0,B=-1/0;for(const f of e){try{f.updateMatrixWorld?.(!0)}catch{}const F=f.geometry?.getAttribute?.("position");if(!(!F||F.itemSize!==3))for(let m=0;m<F.count;m++)t.set(F.getX(m),F.getY(m),F.getZ(m)).applyMatrix4(f.matrixWorld),t.x<g&&(g=t.x),t.y<o&&(o=t.y),t.z<s&&(s=t.z),t.x>I&&(I=t.x),t.y>n&&(n=t.y),t.z>B&&(B=t.z)}const C=Number.isFinite(g)?Math.max(1,Math.hypot(I-g,n-o,B-s)):1,a=Math.max(Number(A.weldTolerance)||0,Math.max(1e-6,C*1e-7)),Q=Number.isFinite(Number(A.minSharedNormalDot))?Math.max(-1,Math.min(1,Number(A.minSharedNormalDot))):-1,E=Number.isFinite(Number(A.minSharedEdgeNormalDot))?Math.max(-1,Math.min(1,Number(A.minSharedEdgeNormalDot))):null,l=Number.isFinite(Number(A.minPlanarRatio))?Math.max(0,Math.min(1,Number(A.minPlanarRatio))):0,h=r((f,F)=>{if(!(l>0))return 1;const m=f?.geometry?.getAttribute?.("position"),G=f?.geometry?.getIndex?.()||null;if(!m||m.itemSize!==3||m.count<3||!F||F.lengthSq()<=Lo)return 0;const N=new W,S=new W,Y=new W;let R=0,k=0;const b=G?G.count/3|0:m.count/3|0;for(let L=0;L<b;L++){const x=G?G.getX(L*3+0)>>>0:L*3+0,J=G?G.getX(L*3+1)>>>0:L*3+1,$=G?G.getX(L*3+2)>>>0:L*3+2;N.set(m.getX(x),m.getY(x),m.getZ(x)).applyMatrix4(f.matrixWorld),S.set(m.getX(J),m.getY(J),m.getZ(J)).applyMatrix4(f.matrixWorld),Y.set(m.getX($),m.getY($),m.getZ($)).applyMatrix4(f.matrixWorld);const T=QU(N,S,Y),H=T.length();H>Lo&&(R+=Math.abs(T.multiplyScalar(1/H).dot(F))*H,k+=H)}return k>Lo?R/k:0},"computeFacePlanarRatio"),w=e.map(f=>{try{const F=typeof f?.getAverageNormal=="function"?f.getAverageNormal():null;if(F&&F.lengthSq?.()>Lo)return F.clone().normalize()}catch{}return null}),d=e.map((f,F)=>h(f,w[F])),D=new Map;for(let f=0;f<e.length;f++){const F=e[f],m=F.geometry?.getAttribute?.("position"),G=F.geometry?.getIndex?.()||null;if(!m||m.itemSize!==3||m.count<3)continue;const N=[];for(let L=0;L<m.count;L++)N.push(new W(m.getX(L),m.getY(L),m.getZ(L)).applyMatrix4(F.matrixWorld));const S=new Array(N.length);for(let L=0;L<N.length;L++){const x=Rb(N[L],a);S[L]=x}const Y=new Map,R=new Map,k=G?G.count/3|0:m.count/3|0;for(let L=0;L<k;L++){const x=G?G.getX(L*3+0)>>>0:L*3+0,J=G?G.getX(L*3+1)>>>0:L*3+1,$=G?G.getX(L*3+2)>>>0:L*3+2,T=QU(N[x],N[J],N[$]);for(const[H,X]of[[x,J],[J,$],[$,x]]){const oA=S[H],_=S[X];if(!oA||!_||oA===_)continue;const V=oYA(oA,_);Y.set(V,(Y.get(V)||0)+1);let O=R.get(V);O||(O=new W,R.set(V,O)),O.add(T)}}const b=yEt(F);for(const[L,x]of Y.entries()){if(x!==1)continue;const J=`${b}::${L}`;let $=D.get(J);$||($=[],D.set(J,$));const T=R.get(L)||null;$.push({faceIndex:f,normal:T&&T.lengthSq()>Lo?T.clone().normalize():null})}}const u=new Array(e.length).fill(null).map((f,F)=>F),M=r(f=>{let F=f;for(;u[F]!==F;)F=u[F];for(;u[f]!==f;){const m=u[f];u[f]=F,f=m}return F},"find"),y=r((f,F)=>{const m=typeof f=="number"?f:f?.faceIndex>>>0,G=typeof F=="number"?F:F?.faceIndex>>>0;if(m===G||m>=e.length||G>=e.length)return;if(E!=null){const Y=f?.normal||w[m],R=F?.normal||w[G];if(!Y||!R||Math.abs(Y.dot(R))<E)return}else{if(l>0&&(d[m]<l||d[G]<l))return;if(Q>-1){const Y=w[m],R=w[G];if(!Y||!R||Math.abs(Y.dot(R))<Q)return}}if(Q>-1&&E!=null){const Y=w[m],R=w[G];if(!Y||!R||Math.abs(Y.dot(R))<Q)return}const N=M(m),S=M(G);N!==S&&(u[S]=N)},"union");for(const f of D.values())if(!(!Array.isArray(f)||f.length<2))for(let F=1;F<f.length;F++)y(f[0],f[F]);const p=new Map;for(let f=0;f<e.length;f++){const F=M(f);let m=p.get(F);m||(m=[],p.set(F,m)),m.push(e[f])}return Array.from(p.values())}c(TUA,"oaA");r(TUA,"groupConnectedFacesBySharedEdges");function fEt(i,A,e){const t=new W().subVectors(e,A),g=t.lengthSq();if(!(g>Lo))return i.distanceToSquared(A);const o=Math.max(0,Math.min(1,new W().subVectors(i,A).dot(t)/g)),s=A.clone().add(t.multiplyScalar(o));return i.distanceToSquared(s)}c(fEt,"CKt");r(fEt,"pointToSegmentDistanceSq");function yTA(i,A){if(!Array.isArray(A)||A.length<2)return 1/0;let e=1/0;for(let t=0;t+1<A.length;t++){const g=fEt(i,A[t],A[t+1]);g<e&&(e=g)}return e}c(yTA,"NNA");r(yTA,"pointToPolylineDistanceSq");function FEt(i,A,e,t){const g=new W().subVectors(e,A),o=new W().subVectors(t,A),s=new W().subVectors(i,A),I=g.dot(s),n=o.dot(s);if(I<=0&&n<=0)return i.distanceToSquared(A);const B=new W().subVectors(i,e),C=g.dot(B),a=o.dot(B);if(C>=0&&a<=C)return i.distanceToSquared(e);const Q=I*a-C*n;if(Q<=0&&I>=0&&C<=0){const y=I/(I-C);return i.distanceToSquared(A.clone().add(g.multiplyScalar(y)))}const E=new W().subVectors(i,t),l=g.dot(E),h=o.dot(E);if(h>=0&&l<=h)return i.distanceToSquared(t);const w=l*n-I*h;if(w<=0&&n>=0&&h<=0){const y=n/(n-h);return i.distanceToSquared(A.clone().add(o.multiplyScalar(y)))}const d=C*h-l*a;if(d<=0&&a-C>=0&&l-h>=0){const y=new W().subVectors(t,e),p=(a-C)/(a-C+(l-h));return i.distanceToSquared(e.clone().add(y.multiplyScalar(p)))}const D=1/(d+w+Q),u=w*D,M=Q*D;return i.distanceToSquared(A.clone().add(g.multiplyScalar(u)).add(o.multiplyScalar(M)))}c(FEt,"aKt");r(FEt,"pointToTriangleDistanceSq");function mEt(i){const A=Array.isArray(i?.edges)?i.edges:[];if(!A.length)return[];const e=i?.parentSolid||(String(i?.parent?.type||"").toUpperCase()==="SOLID"?i.parent:null);try{e?.updateMatrixWorld?.(!0)}catch{}const t=e?.matrixWorld||new Bt,g=[];for(let o=0;o<A.length;o++){const s=A[o],I=(Array.isArray(s?.userData?.polylineLocal)?s.userData.polylineLocal:[]).map(n=>Array.isArray(n)?new W(Number(n[0])||0,Number(n[1])||0,Number(n[2])||0).applyMatrix4(t):n&&Number.isFinite(Number(n.x))&&Number.isFinite(Number(n.y))&&Number.isFinite(Number(n.z))?new W(Number(n.x),Number(n.y),Number(n.z)).applyMatrix4(t):null).filter(Boolean);I.length<2||g.push({name:String(s?.name||s?.userData?.edgeName||`EDGE_${o}`).trim()||`EDGE_${o}`,key:String(s?.uuid||s?.name||`EDGE_${o}`),polyline:I})}return g}c(mEt,"QKt");r(mEt,"getSourceEdgePolylines");function NEt(i,A,e,t,g){const o=mEt(i);if(!o.length||!Array.isArray(A)||!Array.isArray(e))return;const s=Math.max(Number(g)*32,Number(t)*1e-5,1e-5),I=s*s;for(const n of A)for(const B of n?.edges||[]){const C=e[B.start],a=e[B.end];if(!C||!a)continue;const Q=C.clone().add(a).multiplyScalar(.5);let E=null,l=1/0;for(const h of o){const w=Math.max(yTA(C,h.polyline),yTA(Q,h.polyline),yTA(a,h.polyline));w<l&&(l=w,E=h)}E&&l<=I&&(B.sourceEdgeName=E.name,B.sourceEdgeKey=E.key)}}c(NEt,"EKt");r(NEt,"assignSourceEdgesToBoundaryLoops");function SEt(i,A,e={}){if(e.disableAdjacentBoundaryNormals===!0)return{candidateEdges:0,acceptedEdges:0,contributionCount:0,contributedVertexCount:0,dotThreshold:null,weightScale:0,faceFilterCount:0,faceFilterNames:[]};const t=i?.parentSolid||(String(i?.parent?.type||"").toUpperCase()==="SOLID"?i.parent:null),g=G5A(i),o=MEt(e,g),s=Array.isArray(t?._triVerts)?t._triVerts:[],I=Array.isArray(t?._triIDs)?t._triIDs:[],n=Array.isArray(t?._vertProperties)?t._vertProperties:[],B=s.length/3|0,C=Math.max(-1,Math.min(1,Number.isFinite(Number(e.adjacentNormalDotThreshold))?Number(e.adjacentNormalDotThreshold):Number.isFinite(Number(e.smoothAdjacentNormalDotThreshold))?Number(e.smoothAdjacentNormalDotThreshold):.85)),a=Math.max(0,Number.isFinite(Number(e.adjacentNormalWeightScale))?Number(e.adjacentNormalWeightScale):1),Q=r((T={})=>({candidateEdges:Number(T.candidateEdges||0),acceptedEdges:Number(T.acceptedEdges||0),contributionCount:Number(T.contributionCount||0),contributedVertexCount:Number(T.contributedVertexCount||0),dotThreshold:C,weightScale:a,faceFilterCount:o?.size||0,faceFilterNames:o?Array.from(o):[]}),"makeStats");if(!t||!g)return Q();const E=Array.isArray(A?.boundaryDirectedEdges)?A.boundaryDirectedEdges:[],l=Array.isArray(A?.vertices)?A.vertices:[],h=Array.isArray(A?.vertexNormals)?A.vertexNormals:[];if(!E.length||!l.length||!h.length)return Q();const w=Math.max(Number(A?.weldTolerance)||0,1e-8);if(a<=0)return Q();const d=new Map,D=new Map;for(const T of E){const H=T?.start>>>0,X=T?.end>>>0,oA=l[H],_=l[X];if(!oA||!_)continue;const V=Rb(oA,w),O=Rb(_,w);d.set(V,H),d.set(O,X),D.set(oYA(V,O),!0)}if(!D.size)return Q();const u=t?._idToFaceName instanceof Map?t._idToFaceName:new Map,M=new Bt;try{t.updateMatrixWorld?.(!0),M.copy(t.matrixWorld||new Bt)}catch{M.identity()}const y=new Map,p=new Map,f=new Set,F=e.equalAdjacentBoundaryNormals===!0||String(e.sharedBoundaryNormalMode||"").toLowerCase()==="equal"?new Map:null;let m=0,G=0,N=0;const S=r(T=>[Math.round(T.x*1e6),Math.round(T.y*1e6),Math.round(T.z*1e6)].join(","),"normalKey"),Y=r(T=>{if(!F)return null;let H=F.get(T);if(H)return H;const X=h[T]?.clone?.()||null;return!X||X.lengthSq()<=Lo?null:(X.normalize(),H={sum:X.clone(),keys:new Set([S(X)])},F.set(T,H),H)},"getEqualBoundaryNormalBucket"),R=r((T={})=>{if(F?.size)for(const[H,X]of F.entries())!X?.sum||X.sum.lengthSq()<=Lo||h[H].copy(X.sum);return Q(T)},"finalizeStats"),k=r((T,H,X)=>{const oA=d.get(T);if(oA==null)return!1;const _=h[oA];if(!_||_.lengthSq()<=Lo)return!1;if(F){const AA=Y(oA);if(!AA)return!1;const BA=S(H);return AA.keys.has(BA)?!1:(AA.keys.add(BA),AA.sum.add(H),f.add(oA),N+=1,!0)}const V=Math.max(_.length(),dae),O=Math.min(X,V)*a;return O>dae?(_.add(H.clone().multiplyScalar(O)),f.add(oA),N+=1,!0):!1},"addContributionForPointKey"),b=r(T=>{if(!Array.isArray(T)||T.length!==3)return;const H=T.map(AA=>Rb(AA,w));let X=!1;for(const[AA,BA]of[[0,1],[1,2],[2,0]])if(D.has(oYA(H[AA],H[BA]))){X=!0,m+=1;break}if(!X)return;const oA=QU(T[0],T[1],T[2]),_=oA.length();if(!(_>Lo))return;const V=oA.multiplyScalar(1/_);let O=!1;for(let AA=0;AA<3;AA++){const BA=d.get(H[AA]);if(BA==null)continue;const rA=h[BA]?.clone?.()||null;if(!rA||rA.lengthSq()<=Lo)continue;rA.normalize();const tA=V.dot(rA);let sA=null;tA>=C?sA=V:-tA>=C&&(sA=V.clone().multiplyScalar(-1)),sA&&k(H[AA],sA,_)&&(O=!0)}O&&(G+=1)},"processAdjacentTriangle");try{const T=typeof t.getFaces=="function"?t.getFaces(!1)||[]:[];if(Array.isArray(T)&&T.length){for(const H of T){const X=String(H?.faceName||"").trim();if(!(!X||X===g)&&!(o&&!o.has(X)))for(const oA of H?.triangles||[]){const _=Array.isArray(oA?.p1)?oA.p1:null,V=Array.isArray(oA?.p2)?oA.p2:null,O=Array.isArray(oA?.p3)?oA.p3:null;!_||!V||!O||b([new W(_[0]||0,_[1]||0,_[2]||0).applyMatrix4(M),new W(V[0]||0,V[1]||0,V[2]||0).applyMatrix4(M),new W(O[0]||0,O[1]||0,O[2]||0).applyMatrix4(M)])}}if(m>0||B===0||I.length<B||n.length<9)return R({candidateEdges:m,acceptedEdges:G,contributionCount:N,contributedVertexCount:f.size})}}catch{}if(B===0||I.length<B||n.length<9)return R({candidateEdges:m,acceptedEdges:G,contributionCount:N,contributedVertexCount:f.size});const L=r(T=>{const H=T>>>0;let X=y.get(H);if(X)return X;const oA=H*3;return X=new W(Number(n[oA+0])||0,Number(n[oA+1])||0,Number(n[oA+2])||0).applyMatrix4(M),y.set(H,X),X},"getParentPoint"),x=r(T=>{const H=T>>>0;let X=p.get(H);return X||(X=Rb(L(H),w),p.set(H,X),X)},"getParentPointKey"),J=r((T,H,X)=>k(x(T),H,X),"addContribution"),$=new W;for(let T=0;T<B;T++){const H=String(u.get(I[T])||"").trim();if(H===g||o&&!o.has(H))continue;const X=s[T*3+0]>>>0,oA=s[T*3+1]>>>0,_=s[T*3+2]>>>0,V=[[X,oA],[oA,_],[_,X]];let O=!1;for(const[K,v]of V){const iA=x(K),QA=x(v);if(D.has(oYA(iA,QA))){O=!0,m+=1;break}}if(!O)continue;const AA=L(X),BA=L(oA),rA=L(_);$.copy(QU(AA,BA,rA));const tA=$.length();if(!(tA>Lo))continue;const sA=$.multiplyScalar(1/tA);let eA=!1;for(const K of[X,oA,_]){const v=d.get(x(K));if(v==null)continue;const iA=h[v]?.clone?.()||null;if(!iA||iA.lengthSq()<=Lo)continue;iA.normalize();const QA=sA.dot(iA);let gA=null;QA>=C?gA=sA:-QA>=C&&(gA=sA.clone().multiplyScalar(-1)),gA&&J(K,gA,tA)&&(eA=!0)}eA&&(G+=1)}return R({candidateEdges:m,acceptedEdges:G,contributionCount:N,contributedVertexCount:f.size})}c(SEt,"cKt");r(SEt,"addSmoothAdjacentBoundaryNormals");function wI(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=A.length/3|0;if(!e)return{boundaryEdgeCount:0,nonManifoldEdgeCount:0,triangleCount:0};const t=new Map;for(let s=0;s<e;s++){const I=A[s*3]>>>0,n=A[s*3+1]>>>0,B=A[s*3+2]>>>0;for(const[C,a]of[[I,n],[n,B],[B,I]]){const Q=hr(C,a);t.set(Q,(t.get(Q)||0)+1)}}let g=0,o=0;for(const s of t.values())s===1?g+=1:s!==2&&(o+=1);return{boundaryEdgeCount:g,nonManifoldEdgeCount:o,triangleCount:e}}c(wI,"Un");r(wI,"analyzeMeshTopology$5");function jG(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=A.length/3|0;if(!e)return{sameDirectionEdgeCount:0,oppositeDirectionEdgeCount:0,ambiguousEdgeCount:0};const t=new Map,g=r((n,B)=>{const C=hr(n,B);let a=t.get(C);a||(a=[],t.set(C,a)),a.push([n,B])},"addUse");for(let n=0;n<e;n++){const B=A[n*3]>>>0,C=A[n*3+1]>>>0,a=A[n*3+2]>>>0;g(B,C),g(C,a),g(a,B)}let o=0,s=0,I=0;for(const n of t.values()){if(n.length!==2){I+=1;continue}n[0][0]===n[1][0]&&n[0][1]===n[1][1]?o+=1:s+=1}return{sameDirectionEdgeCount:o,oppositeDirectionEdgeCount:s,ambiguousEdgeCount:I}}c(jG,"Eb");r(jG,"analyzeTriangleOrientation");function QG(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=A.length/3|0;if(!t||e.length<9)return 0;const g=new Map,o=r((a,Q,E)=>{const l=hr(a,Q);let h=g.get(l);h||(h=[],g.set(l,h)),h.push({triIndex:E,a,b:Q})},"addUse");for(let a=0;a<t;a++){const Q=A[a*3+0]>>>0,E=A[a*3+1]>>>0,l=A[a*3+2]>>>0;o(Q,E,a),o(E,l,a),o(l,Q,a)}const s=Array.from({length:t},()=>[]);for(const a of g.values()){if(a.length!==2)continue;const Q=a[0],E=a[1],l=Q.a===E.a&&Q.b===E.b;s[Q.triIndex].push({triIndex:E.triIndex,sameDirection:l}),s[E.triIndex].push({triIndex:Q.triIndex,sameDirection:l})}const I=new Int8Array(t);I.fill(-1);for(let a=0;a<t;a++){if(I[a]!==-1)continue;I[a]=0;const Q=[a];for(;Q.length;){const E=Q.pop(),l=I[E];for(const h of s[E]){const w=l^(h.sameDirection?1:0);I[h.triIndex]===-1&&(I[h.triIndex]=w,Q.push(h.triIndex))}}}let n=0;for(let a=0;a<t;a++){if(I[a]!==1)continue;const Q=a*3,E=A[Q+1];A[Q+1]=A[Q+2],A[Q+2]=E,n+=1}const B=r(a=>{const Q=a*3,E=A[Q+1];A[Q+1]=A[Q+2],A[Q+2]=E},"flipTriangle"),C=r(()=>{const a=new Map,Q=r((w,d,D)=>{const u=hr(w,d);let M=a.get(u);M||(M=[],a.set(u,M)),M.push({triIndex:D,a:w,b:d})},"addLocalUse");for(let w=0;w<t;w++){const d=A[w*3+0]>>>0,D=A[w*3+1]>>>0,u=A[w*3+2]>>>0;Q(d,D,w),Q(D,u,w),Q(u,d,w)}const E=new Uint8Array(t),l=new Uint8Array(t);let h=0;for(const w of a.values())w.length===2&&(w[0].a===w[1].a&&w[0].b===w[1].b?(h+=1,E[w[0].triIndex]+=1,E[w[1].triIndex]+=1):(l[w[0].triIndex]+=1,l[w[1].triIndex]+=1));return{sameCount:h,sameByTri:E,oppositeByTri:l}},"orientationStats");for(let a=0;a<16;a++){const Q=C();if(Q.sameCount===0)break;let E=0;for(let l=0;l<t;l++)Q.sameByTri[l]<=Q.oppositeByTri[l]||(B(l),n+=1,E+=1);if(!E)break}for(let a=0;a<64;a++){let Q=C();if(Q.sameCount===0)break;const E=[];for(let h=0;h<t;h++)Q.sameByTri[h]&&E.push({triIndex:h,score:Q.sameByTri[h]*2-Q.oppositeByTri[h]});E.sort((h,w)=>w.score-h.score||h.triIndex-w.triIndex);let l=!1;for(const h of E){if(Q=C(),Q.sameCount===0||!Q.sameByTri[h.triIndex])break;const w=Q.sameCount;B(h.triIndex),C().sameCount<w?(n+=1,l=!0):B(h.triIndex)}if(!l)break}return n>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)),n}c(QG,"Sk");r(QG,"orientSolidTrianglesByAdjacency");function EG(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=A.length/3|0;if(!t||e.length<9)return 0;const g=new Map,o=r((C,a,Q)=>{const E=hr(C,a);let l=g.get(E);l||(l=[],g.set(E,l)),l.push(Q)},"addUse");for(let C=0;C<t;C++){const a=A[C*3+0]>>>0,Q=A[C*3+1]>>>0,E=A[C*3+2]>>>0;o(a,Q,C),o(Q,E,C),o(E,a,C)}const s=Array.from({length:t},()=>[]);for(const C of g.values())C.length===2&&(s[C[0]].push(C[1]),s[C[1]].push(C[0]));const I=r(C=>{const a=A[C*3+0]>>>0,Q=A[C*3+1]>>>0,E=A[C*3+2]>>>0,l=e[a*3+0],h=e[a*3+1],w=e[a*3+2],d=e[Q*3+0],D=e[Q*3+1],u=e[Q*3+2],M=e[E*3+0],y=e[E*3+1],p=e[E*3+2];return(l*(D*p-u*y)-h*(d*p-u*M)+w*(d*y-D*M))/6},"signedVolume"),n=new Uint8Array(t);let B=0;for(let C=0;C<t;C++){if(n[C])continue;const a=[],Q=[C];n[C]=1;let E=0;for(;Q.length;){const l=Q.pop();a.push(l),E+=I(l);for(const h of s[l])n[h]||(n[h]=1,Q.push(h))}if(E<-Lo)for(const l of a){const h=l*3,w=A[h+1];A[h+1]=A[h+2],A[h+2]=w,B+=1}}return B>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)),B}c(EG,"Gk");r(EG,"orientSolidComponentsBySignedVolume");function wl(i,A){const e=Math.max(Number(A)||0,0),t=Array.isArray(i?._vertProperties)?i._vertProperties:[],g=Array.isArray(i?._triVerts)?i._triVerts:[],o=Array.isArray(i?._triIDs)?i._triIDs:[],s=t.length/3|0,I=g.length/3|0;if(!(e>0)||!s||!I||o.length<I)return{weldedVertexCount:0,removedTriangleCount:0};const n=1/e,B=r(D=>[Math.round((Number(t[D*3+0])||0)*n),Math.round((Number(t[D*3+1])||0)*n),Math.round((Number(t[D*3+2])||0)*n)].join(","),"keyForIndex"),C=new Int32Array(s);C.fill(-1);const a=new Map,Q=[];let E=0;for(let D=0;D<s;D++){const u=B(D);let M=a.get(u);M==null?(M=Q.length/3|0,a.set(u,M),Q.push(t[D*3+0],t[D*3+1],t[D*3+2])):E+=1,C[D]=M}if(!E)return{weldedVertexCount:0,removedTriangleCount:0};const l=r((D,u,M)=>{const y=Q[D*3+0],p=Q[D*3+1],f=Q[D*3+2],F=Q[u*3+0],m=Q[u*3+1],G=Q[u*3+2],N=Q[M*3+0],S=Q[M*3+1],Y=Q[M*3+2],R=F-y,k=m-p,b=G-f,L=N-y,x=S-p,J=Y-f;return .5*Math.hypot(k*J-b*x,b*L-R*J,R*x-k*L)},"areaByIndex"),h=[],w=[];let d=0;for(let D=0;D<I;D++){const u=C[g[D*3+0]>>>0],M=C[g[D*3+1]>>>0],y=C[g[D*3+2]>>>0];if(u<0||M<0||y<0||u===M||M===y||y===u||!(l(u,M,y)>Lo)){d+=1;continue}h.push(u,M,y),w.push(o[D])}i._vertProperties=Q,i._triVerts=h,i._triIDs=w,i._vertKeyToIndex=new Map;for(let D=0;D<Q.length;D+=3)i._vertKeyToIndex.set(`${Q[D]},${Q[D+1]},${Q[D+2]}`,D/3|0);return i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i),{weldedVertexCount:E,removedTriangleCount:d}}c(wl,"ph");r(wl,"weldSolidVerticesByPosition");function zRe(i,A={}){if(!i?.geometry)throw new Error("Face.thicken() requires a face with geometry.");try{i.updateMatrixWorld?.(!0)}catch{}const e=i.geometry,t=e.getAttribute?.("position"),g=e.getIndex?.()||null;if(!t||t.itemSize!==3||t.count<3)throw new Error("Face.thicken() requires a triangulated face geometry.");const o=[],s=new W;let I=1/0,n=1/0,B=1/0,C=-1/0,a=-1/0,Q=-1/0;for(let _=0;_<t.count;_++)s.set(t.getX(_),t.getY(_),t.getZ(_)).applyMatrix4(i.matrixWorld),o.push(s.clone()),s.x<I&&(I=s.x),s.y<n&&(n=s.y),s.z<B&&(B=s.z),s.x>C&&(C=s.x),s.y>a&&(a=s.y),s.z>Q&&(Q=s.z);const E=Math.max(1,Math.hypot(C-I,a-n,Q-B)),l=Math.max(Number(A.weldTolerance)||0,Math.max(1e-6,E*1e-7)),h=new Map,w=[],d=new Array(o.length);for(let _=0;_<o.length;_++){const V=o[_],O=Rb(V,l);let AA=h.get(O);AA==null?(AA=w.length,h.set(O,AA),w.push({point:V.clone(),count:1,key:O})):(w[AA].point.add(V),w[AA].count+=1),d[_]=AA}let D=w.map(_=>_.point.multiplyScalar(1/_.count)),u=w.map(_=>_.key);const M=Array.isArray(A.triangleSourceFaceNames)?A.triangleSourceFaceNames:null,y=String(A.sourceFaceName||G5A(i)||"").trim();let p=[];const f=g?g.count/3|0:t.count/3|0;for(let _=0;_<f;_++){const V=g?g.getX(_*3+0)>>>0:_*3+0,O=g?g.getX(_*3+1)>>>0:_*3+1,AA=g?g.getX(_*3+2)>>>0:_*3+2,BA=d[V]>>>0,rA=d[O]>>>0,tA=d[AA]>>>0;if(BA===rA||rA===tA||tA===BA||!(S5A(D[BA],D[rA],D[tA])>Lo))continue;const sA=[BA,rA,tA],eA=String(M?.[_]||y||"").trim();eA&&(sA.sourceFaceName=eA),p.push(sA)}if(!p.length)throw new Error("Face.thicken() could not resolve any non-degenerate source triangles.");const F=new Map,m=new Array(p.length).fill(null).map(()=>[]),G=r((_,V,O)=>{for(const[AA,BA]of[[_[0],_[1]],[_[1],_[2]],[_[2],_[0]]]){if(AA===V&&BA===O)return 1;if(AA===O&&BA===V)return-1}return 0},"edgeOrientation");for(let _=0;_<p.length;_++){const V=p[_];for(const[O,AA]of[[V[0],V[1]],[V[1],V[2]],[V[2],V[0]]]){const BA=hr(O,AA);let rA=F.get(BA);rA||(rA=[],F.set(BA,rA)),rA.push({triIndex:_,u:O,v:AA})}}for(const[_,V]of F.entries()){if(!Array.isArray(V)||V.length<2)continue;const[O,AA]=_.split("|"),BA=Number(O)>>>0,rA=Number(AA)>>>0;for(let tA=0;tA<V.length;tA++)for(let sA=tA+1;sA<V.length;sA++)m[V[tA].triIndex].push({neighbor:V[sA].triIndex,u:BA,v:rA}),m[V[sA].triIndex].push({neighbor:V[tA].triIndex,u:BA,v:rA})}const N=new Array(p.length).fill(!1),S=r(_=>pEt(_,[_[0],_[2],_[1]]),"flipTriangle");for(let _=0;_<p.length;_++){if(N[_])continue;const V=[_];for(N[_]=!0;V.length;){const O=V.pop(),AA=p[O];for(const BA of m[O]){const rA=BA.neighbor;if(rA!=null&&!N[rA]){const tA=p[rA],sA=G(AA,BA.u,BA.v),eA=G(tA,BA.u,BA.v);sA!==0&&sA===eA&&(p[rA]=S(tA)),N[rA]=!0,V.push(rA)}}}}const Y=new Array(p.length),R=new Array(D.length).fill(null).map(()=>new W),k=new W;for(let _=0;_<p.length;_++){const[V,O,AA]=p[_],BA=QU(D[V],D[O],D[AA]),rA=BA.length();if(!(rA>Lo))continue;const tA=BA.clone().multiplyScalar(1/rA);Y[_]=tA,R[V].add(tA.clone().multiplyScalar(rA)),R[O].add(tA.clone().multiplyScalar(rA)),R[AA].add(tA.clone().multiplyScalar(rA)),k.add(tA.clone().multiplyScalar(rA))}k.lengthSq()<=Lo?k.set(0,0,1):k.normalize();const b=[];for(const[_,V]of F.entries()){if(V.length!==1)continue;const O=V[0];b.push({key:_,start:O.u,end:O.v})}const L=new Map;for(const _ of b){let V=L.get(_.start);V||(V=[],L.set(_.start,V)),V.push(_)}const x=new Set(b.map(_=>`${_.start}>${_.end}`)),J=[],$=r((_,V)=>{const O=`${u[_.start]}|${u[_.end]}`,AA=`${u[V.start]}|${u[V.end]}`;return O.localeCompare(AA)},"compareEdges");for(;x.size;){const _=Array.from(x.values()).sort((v,iA)=>v.localeCompare(iA))[0],[V,O]=_.split(">"),AA=Number(V)>>>0,BA=Number(O)>>>0,rA=[],tA=[AA];let sA=AA,eA=AA,K=BA;for(;x.has(`${eA}>${K}`)&&(x.delete(`${eA}>${K}`),rA.push({start:eA,end:K,key:hr(eA,K)}),tA.push(K),eA=K,eA!==sA);){const v=(L.get(eA)||[]).filter(iA=>x.has(`${iA.start}>${iA.end}`)).sort($);if(!v.length)break;K=v[0].end}rA.length&&J.push({vertices:tA,edges:rA})}const T=r(_=>{const V=Array.isArray(_?.vertices)?_.vertices.slice(0,-1):[];if(!V.length)return"";let O=null;for(let AA=0;AA<V.length;AA++){const BA=[];for(let tA=0;tA<V.length;tA++)BA.push(u[V[(AA+tA)%V.length]]||`${V[(AA+tA)%V.length]}`);const rA=BA.join(">");(O==null||rA<O)&&(O=rA)}return O||""},"normalizeLoopSignature"),H=J.map(_=>({..._,signature:T(_)})).sort((_,V)=>_.signature.localeCompare(V.signature));NEt(i,H,D,E,l);const X=new Map;for(let _=0;_<H.length;_++){const V=H[_];for(const O of V.edges)X.set(O.key,_)}const oA=SEt(i,{vertices:D,vertexNormals:R,boundaryDirectedEdges:b,weldTolerance:l},A);for(let _=0;_<R.length;_++)R[_].lengthSq()<=Lo&&R[_].copy(k),R[_].lengthSq()<=Lo?R[_].set(0,0,1):R[_].normalize();return{vertices:D,triangles:p,triangleNormals:Y,vertexNormals:R,averageNormal:k,loops:H,boundaryEdgeToLoop:X,boundaryDirectedEdges:b,adjacentNormalStats:oA,scale:E,weldTolerance:l}}c(zRe,"sgt");r(zRe,"extractFaceSurface");function GEt(i,A={}){const e=Array.isArray(i)?i.filter(Q=>Q?.geometry):[];if(!e.length)throw new Error("Face.thicken() requires at least one face with geometry.");const t=[],g=[],o=[],s=[],I=new W;let n=null,B=!1;for(const Q of e){try{Q.updateMatrixWorld?.(!0)}catch{}const E=G5A(Q)||`FACE_${e.indexOf(Q)+1}`,l=Q?.parentSolid||(String(Q?.parent?.type||"").toUpperCase()==="SOLID"?Q.parent:null);if(!n&&l?n=l:n&&l&&l!==n&&(B=!0),Array.isArray(Q?.edges))for(const M of Q.edges)M&&!s.includes(M)&&s.push(M);const h=Q.geometry,w=h.getAttribute?.("position"),d=h.getIndex?.()||null;if(!w||w.itemSize!==3||w.count<3)throw new Error("Face.thicken() requires triangulated face geometries.");const D=t.length/3|0;for(let M=0;M<w.count;M++)I.set(w.getX(M),w.getY(M),w.getZ(M)).applyMatrix4(Q.matrixWorld||new Bt),t.push(I.x,I.y,I.z);const u=d?d.count/3|0:w.count/3|0;for(let M=0;M<u;M++){const y=d?d.getX(M*3+0)>>>0:M*3+0,p=d?d.getX(M*3+1)>>>0:M*3+1,f=d?d.getX(M*3+2)>>>0:M*3+2;g.push(D+y,D+p,D+f),o.push(E)}}if(g.length<3)throw new Error("Face.thicken() could not resolve any source triangles.");const C=new Kt;C.setAttribute("position",new pg(new Float32Array(t),3)),C.setIndex(g);const a={geometry:C,matrixWorld:new Bt,name:String(A.sourceFaceName||"THICKEN_PATCH"),edges:s,parentSolid:B?null:n,userData:{faceName:String(A.sourceFaceName||"THICKEN_PATCH")},updateMatrixWorld(){}};return zRe(a,{...A,triangleSourceFaceNames:o,disableAdjacentBoundaryNormals:A.disableAdjacentBoundaryNormals??!(A.equalAdjacentBoundaryNormals===!0||String(A.sharedBoundaryNormalMode||"").toLowerCase()==="equal")})}c(GEt,"lKt");r(GEt,"extractFacesSurface");function REt(i,A){const e=[],t=new Set,g=r((l,h)=>{const w=String(l?.label||"").trim();if(!w||t.has(w))return;t.add(w);const d=String(l?.sourceFaceName||i.sourceFaceName||"").trim()||i.sourceFaceName;e.push({label:w,kind:h,metadata:{type:h==="start"?"start_cap":"end_cap",sourceFaceName:d,distance:A}})},"addCapGroup"),o=Array.isArray(i.startCaps)&&i.startCaps.length?i.startCaps:[{label:i.start,sourceFaceName:i.sourceFaceName}],s=Array.isArray(i.endCaps)&&i.endCaps.length?i.endCaps:[{label:i.end,sourceFaceName:i.sourceFaceName}];for(const l of o)g(l,"start");for(const l of s)g(l,"end");const I=[],n=new Map;for(const l of i.sidewalls||[]){const h=String(l?.label||"").trim();if(!h)continue;let w=n.get(h);w||(w={label:h,kind:"sidewall",metadata:{type:"sidewall",sourceFaceName:i.sourceFaceName,loopIndex:l.loopIndex,edgeIndex:l.edgeIndex,edgeKey:l.key,sourceEdgeName:l.sourceEdgeName||null,sourceEdgeKey:l.sourceEdgeKey||null,distance:A,segmentCount:0,edgeKeys:[]}},n.set(h,w),I.push(w)),w.metadata.segmentCount+=1,l.key!=null&&w.metadata.edgeKeys.push(l.key)}const B=[...e,...I],C=new Map,a=new Map,Q=[];let E=1;try{typeof gD?.reserveIDs=="function"&&(E=Number(gD.reserveIDs(B.length))||1)}catch{E=1}for(const l of B){const h=E>>>0;E+=1,C.set(l.label,h),a.set(h,l.label),Q.push([l.label,JSON.stringify(l.metadata||{})])}return{labels:i,groups:B,faceNameToID:C,idToFaceName:a,faceMetadataJson:Q,edgeKeyToLabel:new Map(i.sidewalls.map(l=>[l.key,l.label]))}}c(REt,"hKt");r(REt,"buildThickenClassificationState");function VRe(i,A,e){const t=Array.from(i?.triVerts??[],B=>Number(B)>>>0),g=t.length/3|0;if(!g)return null;const o=Array.from(A?.triIDs??i?.faceID??[],B=>Number(B)>>>0),s=Number(A?.faceNameToID?.values?.()?.next?.()?.value)>>>0,I=o.length===g?o:new Array(g).fill(s||1),n=new Qg;n._numProp=Number(i?.numProp??3)||3,n._vertProperties=Array.from(i?.vertProperties??[],B=>Number(B)||0),n._triVerts=t,n._triIDs=I,n._faceNameToID=A?.faceNameToID instanceof Map?new Map(A.faceNameToID):new Map,n._idToFaceName=A?.idToFaceName instanceof Map?new Map(A.idToFaceName):new Map,n._faceMetadata=new Map;for(const[B,C]of A?.faceMetadataJson||[])if(B)try{n._faceMetadata.set(String(B),JSON.parse(C||"{}")||{})}catch{n._faceMetadata.set(String(B),{})}n._vertKeyToIndex=new Map;for(let B=0;B<n._vertProperties.length;B+=3)n._vertKeyToIndex.set(`${n._vertProperties[B]},${n._vertProperties[B+1]},${n._vertProperties[B+2]}`,B/3|0);try{n.name=e||n.name}catch{}return n._dirty=!0,n._manifold=null,n._faceIndex=null,n}c(VRe,"ogt");r(VRe,"buildSolidFromTriangleMesh");function WRe(i,A,e="raw_face_ids"){return{triIDs:Array.from(A||[],t=>Number(t)>>>0),faceNameToID:i?.faceNameToID instanceof Map?i.faceNameToID:new Map,idToFaceName:i?.idToFaceName instanceof Map?i.idToFaceName:new Map,faceMetadataJson:Array.from(i?.faceMetadataJson||[]),groups:Array.isArray(i?.groups)?i.groups:[],method:e}}c(WRe,"ngt");r(WRe,"buildRawClassification");function YEt(i,A,e){const t=i?.labels||{},g=String(A?.sourceFaceName||"").trim(),o=g?t.capLabelsBySourceFaceName?.get?.(g):null,s=e==="start"?o?.start||t.start:o?.end||t.end;return String(s||"").trim()}c(YEt,"dKt");r(YEt,"resolveCapLabelForTriangle");function sv(i,A,e){const t=YEt(i,A,e);return Number(i?.faceNameToID?.get?.(t))>>>0}c(sv,"Aj");r(sv,"resolveCapFaceIDForTriangle");function UEt(i,A,e){const t=Array.isArray(i?.vertices)?i.vertices.length:0;if(!t)return null;const g=new Float32Array(t*2*3);for(let C=0;C<t;C++){const a=i.vertices[C],Q=a.clone().add(i.vertexNormals[C].clone().multiplyScalar(A));g[C*3+0]=a.x,g[C*3+1]=a.y,g[C*3+2]=a.z;const E=t+C;g[E*3+0]=Q.x,g[E*3+1]=Q.y,g[E*3+2]=Q.z}const o=Number(e?.faceNameToID?.get?.(e?.labels?.start))>>>0,s=Number(e?.faceNameToID?.get?.(e?.labels?.end))>>>0,I=[],n=[],B=r((C,a,Q,E)=>{if(C===a||a===Q||Q===C)return;const l=new W(g[C*3+0],g[C*3+1],g[C*3+2]),h=new W(g[a*3+0],g[a*3+1],g[a*3+2]),w=new W(g[Q*3+0],g[Q*3+1],g[Q*3+2]);S5A(l,h,w)>Lo&&(I.push(C>>>0,a>>>0,Q>>>0),n.push(Number(E)>>>0))},"addTriangle");for(const C of i.triangles||[]){const[a,Q,E]=C,l=sv(e,C,"start")||o,h=sv(e,C,"end")||s;A>=0?(B(a,E,Q,l),B(t+a,t+Q,t+E,h)):(B(a,Q,E,l),B(t+a,t+E,t+Q,h))}for(let C=0;C<(i.loops?.length||0);C++){const a=i.loops[C];for(const Q of a?.edges||[]){const E=Q.start>>>0,l=Q.end>>>0,h=t+E,w=t+l,d=e?.edgeKeyToLabel?.get?.(Q.key),D=Number(e?.faceNameToID?.get?.(d))>>>0;A>=0?(B(E,l,w,D),B(E,w,h,D)):(B(h,w,l,D),B(h,l,E,D))}}return{numProp:3,vertProperties:g,triVerts:Uint32Array.from(I),faceID:Uint32Array.from(n)}}c(UEt,"wKt");r(UEt,"buildStitchedThickenMesh");function kEt(i,A,e,t){const g=UEt(i,A,e);if(!g)return null;const o=WRe(e,g.faceID,"stitched_shell");return VRe(g,o,t)}c(kEt,"uKt");r(kEt,"buildStitchedShellSolid");function LEt(i,A,e){const t=Array.isArray(i?.vertices)?i.vertices:[],g=Array.isArray(i?.triangles)?i.triangles:[];if(!t.length||!g.length)return null;const o=Number(e?.faceNameToID?.get?.(e?.labels?.start))>>>0,s=Number(e?.faceNameToID?.get?.(e?.labels?.end))>>>0,I=Number(e?.faceNameToID?.values?.()?.next?.()?.value)>>>0,n=[],B=[],C=[],a=r(l=>{const h=C.length/3|0;return C.push(l.x,l.y,l.z),h},"addVertex"),Q=r((l,h,w,d)=>{if(!l||!h||!w||!(S5A(l,h,w)>Lo))return;const D=a(l),u=a(h),M=a(w);n.push(D,u,M),B.push(Number(d)>>>0)},"addTriangleByPoints"),E=r((l,h)=>{const w=hr(l,h),d=e?.edgeKeyToLabel?.get?.(w);return Number(e?.faceNameToID?.get?.(d))>>>0||I||o||s||1},"resolveSideFaceID");for(const l of g){const h=l?.[0]>>>0,w=l?.[1]>>>0,d=l?.[2]>>>0,D=t[h],u=t[w],M=t[d];if(!D||!u||!M)continue;const y=sv(e,l,"start")||o,p=sv(e,l,"end")||s,f=QU(D,u,M),F=f.length();if(!(F>Lo))continue;f.multiplyScalar(A/F);const m=D.clone().add(f),G=u.clone().add(f),N=M.clone().add(f);A>=0?(Q(D,M,u,y),Q(m,G,N,p),Q(D,u,G,E(h,w)),Q(D,G,m,E(h,w)),Q(u,M,N,E(w,d)),Q(u,N,G,E(w,d)),Q(M,D,m,E(d,h)),Q(M,m,N,E(d,h))):(Q(D,u,M,y),Q(m,N,G,p),Q(m,G,u,E(h,w)),Q(m,u,D,E(h,w)),Q(G,N,M,E(w,d)),Q(G,M,u,E(w,d)),Q(N,m,D,E(d,h)),Q(N,D,M,E(d,h)))}return n.length?{numProp:3,vertProperties:Float32Array.from(C),triVerts:Uint32Array.from(n),faceID:Uint32Array.from(B)}:null}c(LEt,"DKt");r(LEt,"buildTrianglePrismUnionThickenMesh");function bEt(i,A,e,t){const g=LEt(i,A,e);if(!g)return null;const o=WRe(e,g.faceID,"triangle_prism_union");return VRe(g,o,t)}c(bEt,"fKt");r(bEt,"buildTrianglePrismUnionShellSolid");function KEt(i,A={}){const e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=Array.isArray(i?._triVerts)?i._triVerts:[],g=Array.isArray(i?._triIDs)?i._triIDs:[],o=t.length/3|0;if(!o||e.length<9||g.length<o)return 0;let s=1/0,I=1/0,n=1/0,B=-1/0,C=-1/0,a=-1/0;for(let b=0;b<e.length;b+=3){const L=e[b+0],x=e[b+1],J=e[b+2];L<s&&(s=L),L>B&&(B=L),x<I&&(I=x),x>C&&(C=x),J<n&&(n=J),J>a&&(a=J)}const Q=Math.hypot(B-s,C-I,a-n)||1,E=Math.max(Q*(Number(A.offsetScale)||1e-5),1e-9),l=Math.max(E*.1,Q*1e-10,1e-10),h=Math.max(12,Math.min(256,Number.isFinite(Number(A.gridSize))?Number(A.gridSize)|0:Math.ceil(Math.sqrt(o)))),w=new Array(o);for(let b=0;b<o;b++){const L=t[b*3+0]>>>0,x=t[b*3+1]>>>0,J=t[b*3+2]>>>0,$=[e[L*3+0],e[L*3+1],e[L*3+2]],T=[e[x*3+0],e[x*3+1],e[x*3+2]],H=[e[J*3+0],e[J*3+1],e[J*3+2]],X=T[0]-$[0],oA=T[1]-$[1],_=T[2]-$[2],V=H[0]-$[0],O=H[1]-$[1],AA=H[2]-$[2];let BA=oA*AA-_*O,rA=_*V-X*AA,tA=X*O-oA*V;const sA=Math.hypot(BA,rA,tA);sA>Lo?(BA/=sA,rA/=sA,tA/=sA):(BA=0,rA=0,tA=0),w[b]={a:$,b:T,c:H,normal:[BA,rA,tA],centroid:[($[0]+T[0]+H[0])/3,($[1]+T[1]+H[1])/3,($[2]+T[2]+H[2])/3],min:[Math.min($[0],T[0],H[0]),Math.min($[1],T[1],H[1]),Math.min($[2],T[2],H[2])],max:[Math.max($[0],T[0],H[0]),Math.max($[1],T[1],H[1]),Math.max($[2],T[2],H[2])]}}const d=[{primary:0,u:1,v:2,min:[s,I,n],max:[B,C,a]},{primary:1,u:2,v:0,min:[s,I,n],max:[B,C,a]},{primary:2,u:0,v:1,min:[s,I,n],max:[B,C,a]}],D=r(b=>{const L=b.min[b.u],x=b.min[b.v],J=Math.max(b.max[b.u]-L,E),$=Math.max(b.max[b.v]-x,E),T=new Map,H=r((oA,_,V)=>Math.max(0,Math.min(h-1,Math.floor((oA-_)/V*h))),"cellCoord"),X=r((oA,_,V)=>{const O=`${oA}|${_}`;let AA=T.get(O);AA||(AA=[],T.set(O,AA)),AA.push(V)},"addCell");for(let oA=0;oA<o;oA++){const _=w[oA],V=H(_.min[b.u]-E,L,J),O=H(_.max[b.u]+E,L,J),AA=H(_.min[b.v]-E,x,$),BA=H(_.max[b.v]+E,x,$);for(let rA=V;rA<=O;rA++)for(let tA=AA;tA<=BA;tA++)X(rA,tA,oA)}return{axis:b,uMin:L,vMin:x,uSpan:J,vSpan:$,cells:T,cellCoord:H}},"buildIndex"),u=(String(A.axes||"").toLowerCase()==="majority"?d:[d[0]]).map(D),M=r((b,L)=>{const x=b.cellCoord(L[b.axis.u],b.uMin,b.uSpan),J=b.cellCoord(L[b.axis.v],b.vMin,b.vSpan);return b.cells.get(`${x}|${J}`)||[]},"pointInIndexCell"),y=r((b,L,x)=>{const J=L.primary,$=L.u,T=L.v,H=x.a[J]-b[J],X=x.a[$]-b[$],oA=x.a[T]-b[T],_=x.b[J]-b[J],V=x.b[$]-b[$],O=x.b[T]-b[T],AA=x.c[J]-b[J],BA=x.c[$]-b[$],rA=x.c[T]-b[T],tA=_-H,sA=V-X,eA=O-oA,K=AA-H,v=BA-X,iA=rA-oA,QA=eA*v-sA*iA;if(Math.abs(QA)<=l)return null;const gA=1/QA,IA=-H,lA=-X,cA=-oA,CA=0,EA=-iA,z=v,aA=(IA*CA+lA*EA+cA*z)*gA;if(aA<-1e-10||aA>1+1e-10)return null;const hA=lA*eA-cA*sA,MA=cA*tA-IA*eA,fA=IA*sA-lA*tA,SA=hA*gA;if(SA<-1e-10||aA+SA>1+1e-10)return null;const UA=(K*hA+v*MA+iA*fA)*gA;return UA>l?UA:null},"rayTriangleHit"),p=r((b,L)=>{const x=[];for(const T of M(L,b)){const H=w[T];if(b[L.axis.primary]>H.max[L.axis.primary]+E||b[L.axis.u]<H.min[L.axis.u]-E||b[L.axis.u]>H.max[L.axis.u]+E||b[L.axis.v]<H.min[L.axis.v]-E||b[L.axis.v]>H.max[L.axis.v]+E)continue;const X=y(b,L.axis,H);X!=null&&x.push(X)}if(!x.length)return!1;x.sort((T,H)=>T-H);let J=0,$=-1/0;for(const T of x)Math.abs(T-$)<=Math.max(l*4,1e-8)||(J+=1,$=T);return J%2===1},"inside"),f=new Uint8Array(o);f.fill(1);let F=0;for(let b=0;b<o;b++){const L=w[b],x=L.normal;if(Math.hypot(x[0],x[1],x[2])<=Lo)continue;const J=[L.centroid[0]+x[0]*E,L.centroid[1]+x[1]*E,L.centroid[2]+x[2]*E],$=[L.centroid[0]-x[0]*E,L.centroid[1]-x[1]*E,L.centroid[2]-x[2]*E];let T=0;for(const H of u)p(J,H)!==p($,H)&&(T+=1);T>=Math.ceil(u.length/2)||(f[b]=0,F+=1)}if(!F)return 0;const m=e.length/3|0,G=new Uint8Array(m),N=[],S=[];for(let b=0;b<o;b++){if(!f[b])continue;const L=t[b*3+0]>>>0,x=t[b*3+1]>>>0,J=t[b*3+2]>>>0;N.push(L,x,J),S.push(g[b]),G[L]=1,G[x]=1,G[J]=1}const Y=new Int32Array(m);Y.fill(-1);const R=[];let k=0;for(let b=0;b<m;b++)G[b]&&(Y[b]=k++,R.push(e[b*3+0],e[b*3+1],e[b*3+2]));for(let b=0;b<N.length;b++)N[b]=Y[N[b]>>>0];i._vertProperties=R,i._triVerts=N,i._triIDs=S,i._vertKeyToIndex=new Map;for(let b=0;b<R.length;b+=3)i._vertKeyToIndex.set(`${R[b]},${R[b+1]},${R[b+2]}`,b/3|0);i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i);try{i.fixTriangleWindingsByAdjacency?.()}catch{}return F}c(KEt,"MKt");r(KEt,"cullInternalTrianglesByIndexedRaycast");function Zf(i,A){const e=Array.isArray(i?._triVerts)?i._triVerts:[],t=Array.isArray(i?._vertProperties)?i._vertProperties:[],g=e.length/3|0;if(!g||t.length<9)return 0;const o=new Map,s=r((f,F)=>{const m=hr(f,F);let G=o.get(m);G||(G={count:0,directed:[]},o.set(m,G)),G.count+=1,G.directed.push([f,F])},"addUse");for(let f=0;f<g;f++){const F=e[f*3+0]>>>0,m=e[f*3+1]>>>0,G=e[f*3+2]>>>0;s(F,m),s(m,G),s(G,F)}const I=new Map,n=new Map,B=new Map,C=[],a=r((f,F)=>{let m=n.get(f);m||(m=[],n.set(f,m)),m.push(F)},"addUndirectedNeighbor");for(const f of o.values()){if(f.count!==1||!f.directed.length)continue;const[F,m]=f.directed[0],G={a:F,b:m,key:`${F}>${m}`};C.push(G),B.set(hr(F,m),[F,m]),a(F,m),a(m,F);let N=I.get(F);N||(N=[],I.set(F,N)),N.push(G)}if(!C.length)return 0;for(const f of I.values())f.sort((F,m)=>F.b-m.b);const Q=new Set,E=[];for(const f of C){if(Q.has(f.key))continue;const F=[f.a];let m=f,G=0;for(;m&&!Q.has(m.key)&&G++<C.length+1&&(Q.add(m.key),F.push(m.b),m.b!==F[0]);)m=(I.get(m.b)||[]).find(N=>!Q.has(N.key))||null;F.length>=4&&F[0]===F[F.length-1]&&E.push(F.slice(0,-1))}const l=r(f=>{if(!Array.isArray(f)||!f.length)return"";const F=[],m=r(G=>{for(let N=0;N<G.length;N++){const S=[];for(let Y=0;Y<G.length;Y++)S.push(G[(N+Y)%G.length]);F.push(S.join("|"))}},"addVariants");return m(f),f.length>1&&m(f.slice().reverse()),F.sort()[0]||""},"loopSignature"),h=r((f,F)=>{const m=Array.from(F.keys());if(m.length<3||f.length<3)return[];const G=r(IA=>[Number(t[IA*3+0])||0,Number(t[IA*3+1])||0,Number(t[IA*3+2])||0],"pointFor"),N=r((IA,lA)=>[IA[0]-lA[0],IA[1]-lA[1],IA[2]-lA[2]],"sub"),S=r((IA,lA)=>IA[0]*lA[0]+IA[1]*lA[1]+IA[2]*lA[2],"dot"),Y=r((IA,lA)=>[IA[1]*lA[2]-IA[2]*lA[1],IA[2]*lA[0]-IA[0]*lA[2],IA[0]*lA[1]-IA[1]*lA[0]],"cross"),R=r(IA=>Math.hypot(IA[0],IA[1],IA[2]),"length"),k=r((IA,lA)=>[IA[0]*lA,IA[1]*lA,IA[2]*lA],"scaleVec"),b=[0,0,0],L=new Map;for(const IA of m){const lA=G(IA);L.set(IA,lA),b[0]+=lA[0],b[1]+=lA[1],b[2]+=lA[2]}b[0]/=m.length,b[1]/=m.length,b[2]/=m.length;let x=null,J=-1/0;for(const IA of L.values()){const lA=N(IA,b),cA=R(lA);cA>J&&(J=cA,x=lA)}if(!x||!(J>Lo))return[];x=k(x,1/J);let $=null,T=-1/0;for(const IA of L.values()){const lA=Y(x,N(IA,b)),cA=R(lA);cA>T&&(T=cA,$=lA)}if(!$||!(T>Lo))return[];$=k($,1/T);const H=Y($,x),X=R(H);if(!(X>Lo))return[];const oA=k(H,1/X),_=new Map;for(const[IA,lA]of L.entries()){const cA=N(lA,b);_.set(IA,[S(cA,x),S(cA,oA)])}const V=new Map;for(const[IA,lA]of F.entries()){const cA=_.get(IA);V.set(IA,lA.slice().sort((CA,EA)=>{const z=_.get(CA),aA=_.get(EA);return Math.atan2(z[1]-cA[1],z[0]-cA[0])-Math.atan2(aA[1]-cA[1],aA[0]-cA[0])}))}const O=r(IA=>{let lA=0;for(let cA=0;cA<IA.length;cA++){const CA=_.get(IA[cA]),EA=_.get(IA[(cA+1)%IA.length]);lA+=CA[0]*EA[1]-EA[0]*CA[1]}return lA*.5},"area2D"),AA=new Set,BA=r((IA,lA)=>`${IA}>${lA}`,"directedKey"),rA=[];for(const[IA,lA]of f)for(const cA of[[IA,lA],[lA,IA]]){let CA=cA[0],EA=cA[1];const z=BA(CA,EA);if(AA.has(z))continue;const aA=[];let hA=!1,MA=0;const fA=Math.max(12,f.length*4);for(;!AA.has(BA(CA,EA))&&MA++<fA;){AA.add(BA(CA,EA)),aA.push(CA);const UA=V.get(EA)||[],GA=UA.indexOf(CA);if(GA<0||UA.length===0)break;const _A=UA[(GA-1+UA.length)%UA.length];if(CA=EA,EA=_A,BA(CA,EA)===z){hA=!0;break}}if(!hA||aA.length<3)continue;const SA=O(aA);Math.abs(SA)<=Lo||rA.push({loop:aA,area:SA})}const tA=rA.filter(IA=>IA.area>Lo),sA=(tA.length?tA:rA.filter(IA=>IA.area<-Lo)).map(IA=>IA.area>0?IA.loop:IA.loop.slice().reverse());if(sA.length||f.length>64)return sA;const eA=new Set,K=[],v=m.slice().sort((IA,lA)=>IA-lA),iA=r(IA=>{if(!IA.length)return"";const lA=[],cA=r(CA=>{for(let EA=0;EA<CA.length;EA++){const z=[];for(let aA=0;aA<CA.length;aA++)z.push(CA[(EA+aA)%CA.length]);lA.push(z.join("|"))}},"add");return cA(IA),cA(IA.slice().reverse()),lA.sort()[0]||""},"canonicalCycleKey");for(const IA of v){const lA=[{current:IA,path:[IA],visited:new Set([IA])}];let cA=0;for(;lA.length&&cA++<5e3&&K.length<f.length*2;){const CA=lA.pop();if(CA.path.length>f.length)continue;const EA=(F.get(CA.current)||[]).slice().sort((z,aA)=>z-aA);for(const z of EA){if(z===IA&&CA.path.length>=3){const hA=iA(CA.path);hA&&!eA.has(hA)&&(eA.add(hA),K.push(CA.path.slice()));continue}if(z<IA||CA.visited.has(z))continue;const aA=new Set(CA.visited);aA.add(z),lA.push({current:z,path:CA.path.concat(z),visited:aA})}}}K.sort((IA,lA)=>IA.length-lA.length);const QA=new Set,gA=[];for(const IA of K){const lA=[];let cA=!1;for(let CA=0;CA<IA.length;CA++){const EA=hr(IA[CA],IA[(CA+1)%IA.length]);lA.push(EA),QA.has(EA)&&(cA=!0)}if(!cA){for(const CA of lA)QA.add(CA);gA.push(IA)}}return gA.slice(0,f.length)},"traceBoundaryGraphLoops"),w=new Set(E.map(l)),d=new Set,D=[];for(const f of C){const F=hr(f.a,f.b);if(d.has(F))continue;const m=[],G=[[f.a,f.b]];for(d.add(F);G.length;){const[X,oA]=G.pop();m.push([X,oA]);for(const _ of[X,oA])for(const V of n.get(_)||[]){const O=hr(_,V);d.has(O)||(d.add(O),G.push([_,V]))}}if(m.length<3)continue;const N=new Map,S=r((X,oA)=>{let _=N.get(X);_||(_=[],N.set(X,_)),_.includes(oA)||_.push(oA)},"addComponentNeighbor");for(const[X,oA]of m)S(X,oA),S(oA,X);if(!Array.from(N.values()).every(X=>X.length===2)){let X=!1;for(const oA of h(m,N)){const _=l(oA);!_||w.has(_)||(w.add(_),E.push(oA),X=!0)}X||D.push(m);continue}const Y=Math.min(...Array.from(N.keys())),R=(N.get(Y)||[]).slice().sort((X,oA)=>X-oA);if(R.length!==2){D.push(m);continue}const k=[Y];let b=-1,L=Y,x=R[0],J=!1,$=0;for(;$++<m.length+2;){if(k.push(x),b=L,L=x,L===Y){J=!0;break}const X=(N.get(L)||[]).filter(oA=>oA!==b);if(X.length!==1)break;x=X[0]}if(!J||k.length<4){D.push(m);continue}const T=k.slice(0,-1);if(T.length!==m.length){D.push(m);continue}const H=l(T);!H||w.has(H)||(w.add(H),E.push(T))}if(D.length=0,!E.length&&!D.length)return 0;const u=r(f=>{if(!Array.isArray(f)||f.length<3)return[];const F=f.map(oA=>[Number(t[oA*3+0])||0,Number(t[oA*3+1])||0,Number(t[oA*3+2])||0]),m=[0,0,0];for(const oA of F)m[0]+=oA[0],m[1]+=oA[1],m[2]+=oA[2];m[0]/=F.length,m[1]/=F.length,m[2]/=F.length;let G=[0,0,0];for(let oA=0;oA<F.length;oA++){const _=F[oA],V=F[(oA+1)%F.length];G[0]+=(_[1]-V[1])*(_[2]+V[2]),G[1]+=(_[2]-V[2])*(_[0]+V[0]),G[2]+=(_[0]-V[0])*(_[1]+V[1])}let N=Math.hypot(G[0],G[1],G[2]);if(!(N>Lo)){let oA=0;for(let _=0;_<F.length;_++){const V=F[_],O=F[(_+1)%F.length],AA=F[(_+2)%F.length],BA=[O[0]-V[0],O[1]-V[1],O[2]-V[2]],rA=[AA[0]-V[0],AA[1]-V[1],AA[2]-V[2]],tA=[BA[1]*rA[2]-BA[2]*rA[1],BA[2]*rA[0]-BA[0]*rA[2],BA[0]*rA[1]-BA[1]*rA[0]],sA=Math.hypot(tA[0],tA[1],tA[2]);sA>oA&&(oA=sA,G=tA)}N=oA}if(!(N>Lo))return[];G=G.map(oA=>oA/N);let S=null,Y=0;for(const oA of F){const _=[oA[0]-m[0],oA[1]-m[1],oA[2]-m[2]],V=Math.hypot(_[0],_[1],_[2]);V>Y&&(Y=V,S=_)}if(!S||!(Y>Lo))return[];S=S.map(oA=>oA/Y);const R=[G[1]*S[2]-G[2]*S[1],G[2]*S[0]-G[0]*S[2],G[0]*S[1]-G[1]*S[0]],k=Math.hypot(R[0],R[1],R[2]);if(!(k>Lo))return[];R[0]/=k,R[1]/=k,R[2]/=k;const b=F.map(oA=>{const _=[oA[0]-m[0],oA[1]-m[1],oA[2]-m[2]];return[_[0]*S[0]+_[1]*S[1]+_[2]*S[2],_[0]*R[0]+_[1]*R[1]+_[2]*R[2]]}),L=r(oA=>{let _=0;for(let V=0;V<oA.length;V++){const O=b[oA[V]],AA=b[oA[(V+1)%oA.length]];_+=O[0]*AA[1]-AA[0]*O[1]}return _*.5},"area2D"),x=r((oA,_,V)=>{const O=b[oA],AA=b[_],BA=b[V];return(AA[0]-O[0])*(BA[1]-AA[1])-(AA[1]-O[1])*(BA[0]-AA[0])},"cross2D"),J=r((oA,_,V,O)=>{const AA=b[oA],BA=b[_],rA=b[V],tA=b[O],sA=Math.abs((rA[0]-BA[0])*(tA[1]-BA[1])-(rA[1]-BA[1])*(tA[0]-BA[0]));if(!(sA>Lo))return!1;const eA=Math.abs((BA[0]-AA[0])*(rA[1]-AA[1])-(BA[1]-AA[1])*(rA[0]-AA[0])),K=Math.abs((rA[0]-AA[0])*(tA[1]-AA[1])-(rA[1]-AA[1])*(tA[0]-AA[0])),v=Math.abs((tA[0]-AA[0])*(BA[1]-AA[1])-(tA[1]-AA[1])*(BA[0]-AA[0]));return Math.abs(eA+K+v-sA)<=Math.max(Lo,sA*1e-8)},"pointInTri"),$=Array.from({length:f.length},(oA,_)=>_);L($)<0&&$.reverse();const T=[];let H=0;for(;$.length>3&&H++<f.length*f.length*4;){let oA=!1;for(let _=0;_<$.length;_++){const V=$[(_-1+$.length)%$.length],O=$[_],AA=$[(_+1)%$.length];if(x(V,O,AA)<=Lo)continue;let BA=!1;for(const rA of $)if(!(rA===V||rA===O||rA===AA)&&J(rA,V,O,AA)){BA=!0;break}if(!BA){T.push([f[V],f[O],f[AA]]),$.splice(_,1),oA=!0;break}}if(!oA)break}if($.length===3&&T.push([f[$[0]],f[$[1]],f[$[2]]]),T.length)return T;const X=[];for(let oA=1;oA+1<f.length;oA++)X.push([f[0],f[oA],f[oA+1]]);return X},"triangulateLoop"),M=r(f=>{const F=i._vertProperties.length/3|0;return i._vertProperties.push(f[0],f[1],f[2]),i._vertKeyToIndex?.set?.(`${f[0]},${f[1]},${f[2]}`,F),F},"addVertex");let y=0;const p=Number(A)>>>0;for(const f of E){if(f.length<3)continue;let F=0;for(let G=0;G<f.length;G++){const N=f[G],S=f[(G+1)%f.length],Y=B.get(hr(N,S));Y&&Y[0]===N&&Y[1]===S&&(F+=1)}const m=F>=f.length/2;for(const G of u(f)){const N=G[0]>>>0,S=G[1]>>>0,Y=G[2]>>>0;N===S||S===Y||Y===N||(m?i._triVerts.push(Y,S,N):i._triVerts.push(N,S,Y),i._triIDs.push(p),y+=1)}}for(const f of D){const F=Array.from(new Set(f.flatMap(([N,S])=>[N,S])));if(F.length<3)continue;const m=[0,0,0];for(const N of F)m[0]+=t[N*3+0],m[1]+=t[N*3+1],m[2]+=t[N*3+2];m[0]/=F.length,m[1]/=F.length,m[2]/=F.length;const G=M(m);for(const[N,S]of f){const Y=B.get(hr(N,S))||[N,S],R=Y[0]>>>0,k=Y[1]>>>0;R===k||R===G||k===G||(i._triVerts.push(k,R,G),i._triIDs.push(p),y+=1)}}return y>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)),y}c(Zf,"HN");r(Zf,"fillBoundaryLoopsWithTriangles");function _Re(i,A,e){const t=`${A}_INTERSECTION_CAP`;let g=i?._faceNameToID instanceof Map?i._faceNameToID.get(t):null;return!g&&typeof i?._getOrCreateID=="function"&&(g=i._getOrCreateID(t)),g&&i?._faceMetadata instanceof Map&&i._faceMetadata.set(t,{type:"intersection_cap",sourceFaceName:A,distance:e}),g||null}c(_Re,"Igt");r(_Re,"getOrCreateIntersectionCapFaceID");function xEt(i,A,e,t,g){const o=Array.isArray(i?._triVerts)?i._triVerts:[],s=Array.isArray(i?._vertProperties)?i._vertProperties:[],I=Array.isArray(i?._triIDs)?i._triIDs:[],n=Array.isArray(A?.vertices)?A.vertices:[],B=Array.isArray(A?.vertexNormals)?A.vertexNormals:[],C=Array.isArray(A?.triangles)?A.triangles:[],a=o.length/3|0;if(!a||I.length<a||!n.length||!C.length)return 0;const Q=Number(t?.faceNameToID?.get?.(t?.labels?.start))>>>0,E=Number(t?.faceNameToID?.get?.(t?.labels?.end))>>>0;if(!Q||!E)return 0;const l=n.map((m,G)=>{const N=B[G];return m&&N?m.clone().add(N.clone().multiplyScalar(e)):null}),h=new Map,w=new Map,d=r((m,G,N)=>{const S=Number(G)>>>0;if(!S||!Array.isArray(N))return;let Y=m.get(S);Y||(Y=[],m.set(S,Y)),Y.push(N)},"addRef");for(const m of C){const G=m?.[0]>>>0,N=m?.[1]>>>0,S=m?.[2]>>>0;if(!n[G]||!n[N]||!n[S])continue;const Y=sv(t,m,"start")||Q,R=sv(t,m,"end")||E;d(h,Y,[n[G],n[N],n[S]]),l[G]&&l[N]&&l[S]&&d(w,R,[l[G],l[N],l[S]])}if(!h.size||!w.size)return 0;const D=Math.max(Number(g)||0,1e-7),u=D*D,M=new W,y=r((m,G)=>{let N=1/0;for(const[S,Y,R]of G){const k=FEt(m,S,Y,R);if(k<N&&(N=k,N<=u))break}return N},"pointDistanceToSurfaceSq"),p=r((m,G)=>{let N=0;for(let S=0;S<3;S++){const Y=(o[m*3+S]>>>0)*3;M.set(Number(s[Y+0])||0,Number(s[Y+1])||0,Number(s[Y+2])||0);const R=y(M,G);if(R>N&&(N=R),N>u)break}return N},"triangleMaxDistanceSq"),f=r((m,G)=>{let N=0,S=1/0;for(const[Y,R]of G.entries()){const k=p(m,R);if(k<S&&(S=k,N=Number(Y)>>>0,S<=u))break}return{faceID:N,distanceSq:S}},"bestFaceIDForTriangle");let F=0;for(let m=0;m<a;m++){const G=f(m,h),N=G.distanceSq<=u?{faceID:0,distanceSq:1/0}:f(m,w),S=G.distanceSq<=u?G.faceID:N.distanceSq<=u?N.faceID:0;S&&I[m]!==S&&(I[m]=S,F+=1)}return F>0&&(i._dirty=!0,i._faceIndex=null,i._manifold=null),F}c(xEt,"yKt");r(xEt,"reclassifyThickenCapTrianglesByGeometry");function JEt(i,A,e){const t=_Re(i,A,e);return t?Zf(i,t):0}c(JEt,"pKt");r(JEt,"fillIntersectionCapBoundaryLoops");function m8(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=Array.isArray(i?._triIDs)?i._triIDs:[],g=A.length/3|0;if(!g||t.length<g)return 0;const o=new Map,s=r((w,d,D)=>{const u=hr(w,d);let M=o.get(u);M||(M=[],o.set(u,M)),M.push(D)},"addUse");for(let w=0;w<g;w++){const d=A[w*3+0]>>>0,D=A[w*3+1]>>>0,u=A[w*3+2]>>>0;s(d,D,w),s(D,u,w),s(u,d,w)}const I=new Uint8Array(g);for(const w of o.values())if(!(w.length<=2))for(const d of w)I[d]=1;let n=0;for(let w=0;w<g;w++)I[w]&&(n+=1);if(!n)return 0;const B=e.length/3|0,C=new Uint8Array(B),a=[],Q=[];for(let w=0;w<g;w++){if(I[w])continue;const d=A[w*3+0]>>>0,D=A[w*3+1]>>>0,u=A[w*3+2]>>>0;a.push(d,D,u),Q.push(t[w]),C[d]=1,C[D]=1,C[u]=1}const E=new Int32Array(B);E.fill(-1);const l=[];let h=0;for(let w=0;w<B;w++)C[w]&&(E[w]=h++,l.push(e[w*3+0],e[w*3+1],e[w*3+2]));for(let w=0;w<a.length;w++)a[w]=E[a[w]>>>0];i._vertProperties=l,i._triVerts=a,i._triIDs=Q,i._vertKeyToIndex=new Map;for(let w=0;w<l.length;w+=3)i._vertKeyToIndex.set(`${l[w]},${l[w+1]},${l[w+2]}`,w/3|0);return i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i),n}c(m8,"l3");r(m8,"cullTrianglesTouchingNonManifoldEdges");function sYA(i){const A=Array.isArray(i?._triVerts)?i._triVerts:[],e=Array.isArray(i?._vertProperties)?i._vertProperties:[],t=Array.isArray(i?._triIDs)?i._triIDs:[],g=A.length/3|0;if(!g||t.length<g)return 0;const o=new Map,s=r((d,D,u)=>{const M=hr(d,D);let y=o.get(M);y||(y=[],o.set(M,y)),y.push({triIndex:u,a:d,b:D})},"addUse");for(let d=0;d<g;d++){const D=A[d*3+0]>>>0,u=A[d*3+1]>>>0,M=A[d*3+2]>>>0;s(D,u,d),s(u,M,d),s(M,D,d)}const I=new Uint16Array(g);for(const d of o.values())d.length===2&&d[0].a===d[1].a&&d[0].b===d[1].b&&(I[d[0].triIndex]+=1,I[d[1].triIndex]+=1);let n=-1,B=0;for(let d=0;d<g;d++){const D=I[d]||0;if(!D)continue;const u=(i._idToFaceName instanceof Map?String(i._idToFaceName.get(t[d])||""):"").includes("INTERSECTION_CAP")?100:0,M=D+u;M>B&&(B=M,n=d)}if(n<0)return 0;const C=e.length/3|0,a=new Uint8Array(C),Q=[],E=[];for(let d=0;d<g;d++){if(d===n)continue;const D=A[d*3+0]>>>0,u=A[d*3+1]>>>0,M=A[d*3+2]>>>0;Q.push(D,u,M),E.push(t[d]),a[D]=1,a[u]=1,a[M]=1}const l=new Int32Array(C);l.fill(-1);const h=[];let w=0;for(let d=0;d<C;d++)a[d]&&(l[d]=w++,h.push(e[d*3+0],e[d*3+1],e[d*3+2]));for(let d=0;d<Q.length;d++)Q[d]=l[Q[d]>>>0];i._vertProperties=h,i._triVerts=Q,i._triIDs=E,i._vertKeyToIndex=new Map;for(let d=0;d<h.length;d+=3)i._vertKeyToIndex.set(`${h[d]},${h[d+1]},${h[d+2]}`,d/3|0);return i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i),1}c(sYA,"ZnA");r(sYA,"cullTrianglesTouchingSameDirectionEdges");function HEt(i,A={}){const e=String(A.sourceFaceName||"").trim()||"FACE",t=Number(A.distance)||0,g=Math.max(Number(A.manifoldWeldEpsilon)||0,0),o=Math.max(0,Number.isFinite(Number(A.nonManifoldCullMaxTriangles))?Number(A.nonManifoldCullMaxTriangles):1e4),s=Math.max(1,Math.min(512,Number.isFinite(Number(A.maxPasses))?Number(A.maxPasses)|0:256)),I={orientedTriangleCount:0,orientationCulledTriangleCount:0,orientationCapTriangleCount:0,nonManifoldCulledTriangleCount:0,boundaryCapTriangleCount:0,weldedVertexCount:0,degenerateTriangleCount:0},n=r(()=>{try{return typeof i?._isCoherentlyOrientedManifold=="function"?i._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}},"isCoherent"),B=r(()=>{const a=wl(i,g);I.weldedVertexCount+=a.weldedVertexCount||0,I.degenerateTriangleCount+=a.removedTriangleCount||0},"weld");for(let a=0;a<s;a++){let Q=wI(i),E=!1;if(Q.nonManifoldEdgeCount>0&&(Q.triangleCount||0)<=o){const w=m8(i);w>0&&(I.nonManifoldCulledTriangleCount+=w,E=!0,B(),Q=wI(i))}if(Q.boundaryEdgeCount>0){const w=JEt(i,e,t);if(w>0){I.boundaryCapTriangleCount+=w,I.orientationCapTriangleCount+=w,E=!0;try{i.fixTriangleWindingsByAdjacency?.()}catch{}B(),Q=wI(i)}}if(Q.boundaryEdgeCount||Q.nonManifoldEdgeCount){if(!E)return{ok:!1,topology:Q,orientation:jG(i),stats:I};continue}const l=QG(i)+EG(i);if(l>0){I.orientedTriangleCount+=l;try{i.fixTriangleWindingsByAdjacency?.()}catch{}}if(n())return{ok:!0,topology:wI(i),orientation:jG(i),stats:I};const h=sYA(i);if(!(h>0))return{ok:!1,topology:Q,orientation:jG(i),stats:I};if(I.orientationCulledTriangleCount+=h,E=!0,B(),!E)break}const C=wI(i);return{ok:C.boundaryEdgeCount===0&&C.nonManifoldEdgeCount===0&&n(),topology:C,orientation:jG(i),stats:I}}c(HEt,"FKt");r(HEt,"repairSolidOrientationByCullAndCap");function Dae(i,A={}){if(!i||typeof i.clone!="function")return null;let e=null;try{e=i.clone();try{e.name=i.name}catch{}const t=HEt(e,A),g=t?.topology||wI(e),o=(()=>{try{return typeof e._isCoherentlyOrientedManifold=="function"?e._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}})();if(t?.ok===!0&&g.boundaryEdgeCount===0&&g.nonManifoldEdgeCount===0&&o)return{solid:e,topology:g,stats:t.stats||{}}}catch{}try{e?.free?.()}catch{}return null}c(Dae,"LPe");r(Dae,"tryRepairCoherentOrientationCandidate");function vEt(i){let A=0;const e=r(t=>{const g=Array.isArray(i?._triVerts)?i._triVerts:[],o=Array.isArray(i?._vertProperties)?i._vertProperties:[],s=Array.isArray(i?._triIDs)?i._triIDs:[],I=g.length/3|0,n=o.length/3|0,B=new Uint8Array(n),C=[],a=[];for(let h=0;h<I;h++){if(t[h])continue;const w=g[h*3+0]>>>0,d=g[h*3+1]>>>0,D=g[h*3+2]>>>0;C.push(w,d,D),a.push(s[h]),B[w]=1,B[d]=1,B[D]=1}const Q=new Int32Array(n);Q.fill(-1);const E=[];let l=0;for(let h=0;h<n;h++)B[h]&&(Q[h]=l++,E.push(o[h*3+0],o[h*3+1],o[h*3+2]));for(let h=0;h<C.length;h++)C[h]=Q[C[h]>>>0];i._vertProperties=E,i._triVerts=C,i._triIDs=a,i._vertKeyToIndex=new Map;for(let h=0;h<E.length;h+=3)i._vertKeyToIndex.set(`${E[h]},${E[h+1]},${E[h+2]}`,h/3|0);i._dirty=!0,i._faceIndex=null,i._manifold=null,hw(i)},"rebuildWithout");for(let t=0;t<256;t++){const g=Array.isArray(i?._triVerts)?i._triVerts:[],o=Array.isArray(i?._triIDs)?i._triIDs:[],s=g.length/3|0;if(!s||o.length<s)break;const I=new Map,n=[];for(let Q=0;Q<s;Q++){const E=g[Q*3+0]>>>0,l=g[Q*3+1]>>>0,h=g[Q*3+2]>>>0,w=[hr(E,l),hr(l,h),hr(h,E)];n.push(w);for(const d of w)I.set(d,(I.get(d)||0)+1)}let B=0;for(const Q of I.values())Q>2&&(B+=1);if(!B)break;let C=null;for(let Q=0;Q<s;Q++){const E=n[Q];if(E.some(d=>(I.get(d)||0)<=1))continue;let l=0;for(const d of E)l+=Math.max(0,(I.get(d)||0)-2);if(!(l>0))continue;const h=(i._idToFaceName instanceof Map?String(i._idToFaceName.get(o[Q])||""):"").includes("INTERSECTION_CAP")?1e3:0,w={triIndex:Q,score:l+h};(!C||w.score>C.score)&&(C=w)}if(!C)break;const a=new Uint8Array(s);a[C.triIndex]=1,e(a),A+=1}return A}c(vEt,"mKt");r(vEt,"pruneOverusedTriangles");function TEt(i,A={}){if(!i)return null;const e=Math.max(1,Math.min(8,Number.isFinite(Number(A.triangleCullPasses))?Number(A.triangleCullPasses)|0:1)),t={snapTolerance:A.splitSnapTolerance??A.snapTolerance,diagnostics:A.splitDiagnostics===!0||A.diagnostics===!0};(!Number.isFinite(Number(t.snapTolerance))||Number(t.snapTolerance)<=0)&&delete t.snapTolerance;let g=0,o=0,s=0,I=0,n=0;const B=Math.max(Number(A.weldTolerance??A.manifoldWeldTolerance)||0,0);for(let a=0;a<e;a++){n=a+1;const Q=Number(A.precomputedTriangleSplitProbeCount),E=A.skipTriangleSplit===!0?a===0?Number.isFinite(Q)&&Q>=0?Q:Number(i.splitSelfIntersectingTriangles?.({...t,probeOnly:!0,maxIntersections:1})||0):0:Number(i.splitSelfIntersectingTriangles?.(t)||0);E>0&&A.skipTriangleSplit!==!0&&hw(i),g+=E;const l=Number(i.removeDegenerateTriangles?.()||0);l>0&&hw(i),s+=l;const h=wl(i,B);I+=h.weldedVertexCount||0,s+=h.removedTriangleCount||0;const w=(i?._triVerts?.length||0)/3|0,d=Math.max(0,Number.isFinite(Number(A.windingCullMaxTriangles))?Number(A.windingCullMaxTriangles):1e4),D=w>0&&w<=d?"winding":"raycast",u=String(A.internalCullMethod||D).toLowerCase(),M=A.skipInternalCull===!0?0:Number(u==="winding"?i.removeInternalTrianglesByWinding?.(A.windingOptions||{})||0:KEt(i,A.raycastCullOptions||{})||0);M>0&&hw(i),o+=M;const y=Number(i.removeDegenerateTriangles?.()||0);y>0&&hw(i),s+=y;const p=wl(i,B);if(I+=p.weldedVertexCount||0,s+=p.removedTriangleCount||0,E===0&&M===0)break}try{i.fixTriangleWindingsByAdjacency?.()}catch{}const C=wI(i);return{splitCount:g,culledTriangleCount:o,degenerateTriangleCount:s,weldedVertexCount:I,passCount:n,topology:C}}c(TEt,"NKt");r(TEt,"triangleSplitCullSolid");function PEt(i,A,e,t){let g=null;try{g=typeof A?.getMetadata=="function"&&A.getMetadata()||null}catch{g=null}if(!(!g||typeof i?.setFaceMetadata!="function"))try{i.setFaceMetadata(e.start,{...g,type:"start_cap",sourceFaceName:t,sourceFeatureId:A?.owningFeatureID??A?.parentSolid?.owningFeatureID??g?.sourceFeatureId??null}),i.setFaceMetadata(e.end,{...g,type:"end_cap",sourceFaceName:t,sourceFeatureId:A?.owningFeatureID??A?.parentSolid?.owningFeatureID??g?.sourceFeatureId??null})}catch{}}c(PEt,"SKt");r(PEt,"applySourceFaceMetadataToThickenResult");function OEt(i,A){const e=Number(A);if(!(e<0))return!1;const t=Array.isArray(i?.vertices)?i.vertices:[],g=Array.isArray(i?.vertexNormals)?i.vertexNormals:[];if(t.length<3||g.length<t.length)return!1;const o=new W,s=new W;let I=0;for(let B=0;B<t.length;B++){const C=t[B],a=g[B];!C||!a||!(a.lengthSq?.()>Lo)||(s.add(C),o.add(a),I+=1)}if(I<3||(s.multiplyScalar(1/I),o.length()/I>.35))return!1;let n=1/0;for(let B=0;B<t.length;B++){const C=t[B],a=g[B];if(!C||!a||!(a.lengthSq?.()>Lo))continue;const Q=C.clone().sub(s).dot(a);Q>Lo&&Q<n&&(n=Q)}return Number.isFinite(n)?Math.abs(e)>=n*.95:!1}c(OEt,"GKt");r(OEt,"shouldSkipArrangementSplitForSelfOverlappingSurface");function jEt(i,A,e,t={},g=null){if(!(Number(e)>0))return{skip:!1,reason:"",splitProbeCount:0};if(!i||typeof i.splitSelfIntersectingTriangles!="function")return{skip:!1,reason:"",splitProbeCount:0};const o=Array.isArray(A?.loops)?A.loops:[];if(!o.length)return{skip:!1,reason:"",splitProbeCount:0};const s=g||wI(i);if(s.boundaryEdgeCount||s.nonManifoldEdgeCount)return{skip:!1,reason:"",splitProbeCount:0};try{if(typeof i._isCoherentlyOrientedManifold=="function"&&i._isCoherentlyOrientedManifold()!==!0)return{skip:!1,reason:"",splitProbeCount:0}}catch{return{skip:!1,reason:"",splitProbeCount:0}}const I=Math.max(Array.isArray(A?.boundaryDirectedEdges)?A.boundaryDirectedEdges.length:0,o.reduce((E,l)=>E+(Array.isArray(l?.edges)?l.edges.length:0),0)),n=Math.max(16,Math.min(512,I*2||64)),B={probeOnly:!0,maxIntersections:n+1},C=t.splitSnapTolerance??t.snapTolerance;Number.isFinite(Number(C))&&Number(C)>0&&(B.snapTolerance=Number(C));let a=null,Q=0;try{a=typeof i.clone=="function"?i.clone():null,Q=Number(a?a.splitSelfIntersectingTriangles(B)||0:i.splitSelfIntersectingTriangles({...B,maxIntersections:1})||0)}finally{try{a?.free?.()}catch{}}return Q>n?{skip:!1,reason:"",splitProbeCount:Q}:{skip:!0,reason:Q>0?"preserve_exact_closed_shell":"closed_shell_without_intersections",splitProbeCount:Q}}c(jEt,"RKt");r(jEt,"shouldPreserveExactClosedOffsetShell");function NG(i,A,e,t={}){const g=Number(e);if(!Number.isFinite(g)||Math.abs(g)<=dae)throw new Error("Face.thicken() requires a non-zero finite distance.");if(!i||!Array.isArray(i.triangles)||!i.triangles.length)throw new Error("Face.thicken() requires a non-empty source triangle surface.");const o=nzA(t.featureId||t.name||A?.name||"THICKEN","THICKEN"),s=String(t.sourceFaceName||A?.userData?.faceName||A?.name||o).trim()||o,I=Array.isArray(t.sourceFaceNames)?t.sourceFaceNames.map(p=>String(p||"").trim()).filter(Boolean):[s],n=I.length?I:[s],B=new Map;for(const p of n){const f=String(p||"").trim();!f||B.has(f)||B.set(f,{start:`${f}_START`,end:`${f}_END`})}const C=B.get(s)||B.values().next().value||{start:`${s}_START`,end:`${s}_END`},a=Array.isArray(i.loops)?i.loops:[],Q={sourceFaceName:s,start:C.start,end:C.end,startCaps:Array.from(B.entries(),([p,f])=>({label:f.start,sourceFaceName:p})),endCaps:Array.from(B.entries(),([p,f])=>({label:f.end,sourceFaceName:p})),capLabelsBySourceFaceName:B,sidewalls:a.flatMap((p,f)=>(Array.isArray(p?.edges)?p.edges:[]).map((F,m)=>{const G=String(F?.sourceEdgeName||"").trim(),N=G?nzA(G,`EDGE_${f}_${m}`).replace(/_+$/g,""):null;return{key:F.key,loopIndex:f,edgeIndex:m,sourceEdgeName:G||null,sourceEdgeKey:F?.sourceEdgeKey||null,label:N?`${N}_SW`:f===0?`${s}_E${m}_SW`:`${s}_L${f}_E${m}_SW`}}))},E=REt(Q,g),l=String(t.name||o).trim()||o,h=Math.max(Number(t.manifoldWeldTolerance)||0,Math.max(i.weldTolerance||0,i.scale*1e-7,1e-6)),w=Math.max(0,Number.isFinite(Number(t.orientationRepairDistanceLimit))?Number(t.orientationRepairDistanceLimit):2),d=Math.abs(g)<=w,D=t.trianglePrismUnion===!0,u=t.repairBoundaryCaps!==!1,M=Array.isArray(i.triangles)?i.triangles.length:0;let y=null;try{const p=r(()=>{if(t.__skipInternalCullRetry===!0||t.skipInternalCull===!0||!d)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,skipInternalCull:!0,__skipInternalCullRetry:!0})}catch{return null}},"retryWithoutInternalCull"),f=r(()=>{if(t.__relaxedWeldRetry===!0||!d)return null;const sA=Math.min(1e-4,Math.max(i.scale*1e-5,1e-8)),eA=Math.max(h*16,i.scale*1e-6,sA);if(Number(t.manifoldWeldTolerance)>=eA*.95)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,skipInternalCull:!0,manifoldWeldTolerance:eA,__relaxedWeldRetry:!0})}catch{return null}},"retryWithRelaxedWeld"),F=r(()=>{if(t.__raycastMajorityRetry===!0)return null;try{y?.free?.()}catch{}return y=null,NG(i,A,g,{...t,internalCullMethod:"raycast",raycastCullOptions:{...t.raycastCullOptions||{},axes:"majority"},__raycastMajorityRetry:!0})},"retryWithRaycastMajority"),m=r(()=>{if(t.__skipTriangleSplitRetry===!0||t.skipTriangleSplit===!0)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,skipTriangleSplit:!0,__skipTriangleSplitRetry:!0})}catch{return null}},"retryWithoutTriangleSplit"),G=r((sA="destructive_repair")=>{if(t.__trianglePrismUnionRetry===!0||D)return null;try{y?.free?.()}catch{}y=null;try{return NG(i,A,g,{...t,trianglePrismUnion:!0,repairBoundaryCaps:!1,nonManifoldCullMaxTriangles:0,__trianglePrismUnionRetry:!0,__trianglePrismUnionReason:sA})}catch{return null}},"retryWithTrianglePrismUnion"),N=r(()=>_Re(y,s,g),"getBoundaryRepairFaceID");if(y=D?bEt(i,g,E,l):kEt(i,g,E,l),!y)throw new Error("Face.thicken() failed to build the stitched triangle shell.");let S=wI(y);const Y=t.skipTriangleSplit!==!0&&t.skipTriangleSplit!==!1&&!D?jEt(y,i,g,t,S):{skip:!1,reason:"",splitProbeCount:0},R=t.skipTriangleSplit!==!1&&OEt(i,g),k=t.skipTriangleSplit===!0||Y.skip===!0||R,b=t.skipTriangleSplit===!0?"option":Y.reason||(R?"self_overlap_surface":""),L=TEt(y,{...t,skipTriangleSplit:k,precomputedTriangleSplitProbeCount:Y.skip===!0?Y.splitProbeCount:void 0,weldTolerance:h});S=L?.topology||wI(y);let x=0,J=0;const $=Math.max(0,Number.isFinite(Number(t.nonManifoldCullMaxTriangles))?Number(t.nonManifoldCullMaxTriangles):1e4);for(let sA=0;sA<8&&S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$;sA++){const eA=m8(y);if(!(eA>0))break;J+=eA;const K=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y)}if(S.nonManifoldEdgeCount===0&&S.boundaryEdgeCount>0)try{y.removeDegenerateTriangles?.(),S=wI(y)}catch{}if(u&&S.boundaryEdgeCount>0){const sA=N();if(sA&&(x=Zf(y,sA),x>0)){try{y.fixTriangleWindingsByAdjacency?.()}catch{}const eA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(eA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(eA.removedTriangleCount||0),S=wI(y)}}for(let sA=0;sA<16;sA++){let eA=!1;if(S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const K=m8(y);if(K>0){J+=K;const v=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(v.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(v.removedTriangleCount||0),S=wI(y),eA=!0}}if(u&&S.boundaryEdgeCount>0){const K=N();if(K){const v=Zf(y,K);if(v>0){x+=v;try{y.fixTriangleWindingsByAdjacency?.()}catch{}const iA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(iA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(iA.removedTriangleCount||0),S=wI(y),eA=!0}}}if(!eA)break}let T=S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0?QG(y):0;S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0&&(T+=EG(y));let H=0,X=0,oA=!1;if(T>0)try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0&&d&&typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0)for(let sA=0;sA<8;sA++){const eA=sYA(y);if(!(eA>0))break;if(H+=eA,S=wI(y),u&&S.boundaryEdgeCount>0){const v=N();if(v){const iA=Zf(y,v);iA>0&&(X+=iA,x+=iA)}}const K=wl(y,h);if(L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y),S.boundaryEdgeCount||S.nonManifoldEdgeCount)break;T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(y._isCoherentlyOrientedManifold()===!0)break}for(let sA=0;sA<8;sA++){let eA=!1;if(S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const K=m8(y);K>0&&(J+=K,eA=!0)}if(S=wI(y),u&&S.boundaryEdgeCount>0){const K=N();if(K){const v=Zf(y,K);v>0&&(x+=v,eA=!0)}}if(eA){const K=wl(y,h);if(L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y),S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0){T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}}}if(!eA)break}if(S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const sA=vEt(y);if(sA>0){if(J+=sA,S=wI(y),u&&S.boundaryEdgeCount>0){const eA=N();if(eA){const K=Zf(y,eA);K>0&&(x+=K,S=wI(y))}}if(S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0){T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}}}}if(t.__raycastMajorityRetry!==!0&&d)for(let sA=0;sA<128;sA++){if(S=wI(y),S.nonManifoldEdgeCount>0&&(S.triangleCount||0)<=$){const v=m8(y);if(v>0){J+=v;const iA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(iA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(iA.removedTriangleCount||0),S=wI(y)}}if(u&&S.boundaryEdgeCount>0){const v=N();if(v){const iA=Zf(y,v);if(iA>0){x+=iA;const QA=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(QA.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(QA.removedTriangleCount||0),S=wI(y)}}}if(S.boundaryEdgeCount||S.nonManifoldEdgeCount)break;T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(typeof y._isCoherentlyOrientedManifold!="function"||y._isCoherentlyOrientedManifold()===!0)break;const eA=sYA(y);if(!(eA>0))break;H+=eA;const K=wl(y,h);L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0)}if(S=wI(y),S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0&&d&&typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0){const sA=Dae(y,{sourceFaceName:s,distance:g,manifoldWeldEpsilon:h,nonManifoldCullMaxTriangles:$,maxPasses:t.orientationRepairMaxPasses});if(sA?.solid){const eA=y;y=sA.solid;try{eA?.free?.()}catch{}S=sA.topology||wI(y);const K=sA.stats||{};T+=K.orientedTriangleCount||0,H+=K.orientationCulledTriangleCount||0,X+=K.orientationCapTriangleCount||0,x+=K.boundaryCapTriangleCount||0,J+=K.nonManifoldCulledTriangleCount||0,L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.degenerateTriangleCount||0),oA=!0}}const _=!D&&x>Math.max(1e4,M*100),V=!D&&J>Math.max(1e4,M*100);if(_||V){const sA=G(_?"excessive_boundary_caps":"excessive_nonmanifold_cull");if(sA)return sA;throw new Error(`Face.thicken() triangle split/cull required excessive topology repair (boundaryCaps=${x}, nonManifoldCull=${J}, sourceTriangles=${M}).`)}if(S.boundaryEdgeCount||S.nonManifoldEdgeCount){const sA=G("invalid_stitched_topology");if(sA)return sA;const eA=m();if(eA)return eA;const K=p();if(K)return K;const v=f();if(v)return v;const iA=F();if(iA)return iA;throw new Error(`Face.thicken() triangle split/cull produced invalid topology: boundaries=${S.boundaryEdgeCount}, nonManifold=${S.nonManifoldEdgeCount}, triangles=${S.triangleCount||0}.`)}let O=typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0,AA=O?jG(y):null;if(O&&S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0){const sA=Dae(y,{sourceFaceName:s,distance:g,manifoldWeldEpsilon:h,nonManifoldCullMaxTriangles:$,maxPasses:t.orientationRepairMaxPasses});if(sA?.solid){const eA=y;y=sA.solid;try{eA?.free?.()}catch{}S=sA.topology||wI(y);const K=sA.stats||{};T+=K.orientedTriangleCount||0,H+=K.orientationCulledTriangleCount||0,X+=K.orientationCapTriangleCount||0,x+=K.boundaryCapTriangleCount||0,J+=K.nonManifoldCulledTriangleCount||0,L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.degenerateTriangleCount||0),oA=!0,O=typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0,AA=O?jG(y):null}}if(O&&S.boundaryEdgeCount===0&&S.nonManifoldEdgeCount===0)for(let sA=0;sA<32;sA++){const eA=sYA(y);if(!(eA>0))break;if(H+=eA,S=wI(y),u&&S.boundaryEdgeCount>0){const v=N();if(v){const iA=Zf(y,v);iA>0&&(X+=iA,x+=iA)}}const K=wl(y,h);if(L.weldedVertexCount=(L.weldedVertexCount||0)+(K.weldedVertexCount||0),L.degenerateTriangleCount=(L.degenerateTriangleCount||0)+(K.removedTriangleCount||0),S=wI(y),S.boundaryEdgeCount||S.nonManifoldEdgeCount)break;T+=QG(y),T+=EG(y);try{y.fixTriangleWindingsByAdjacency?.()}catch{}if(O=typeof y._isCoherentlyOrientedManifold=="function"&&y._isCoherentlyOrientedManifold()!==!0,AA=O?jG(y):null,!O)break}if(O&&t.__raycastMajorityRetry!==!0&&d){const sA=p();if(sA)return sA;const eA=f();if(eA)return eA;const K=F();if(K)return K;throw new Error(`Face.thicken() triangle split/cull produced a non-coherently-oriented manifold result: sameDirection=${AA.sameDirectionEdgeCount}, ambiguous=${AA.ambiguousEdgeCount}.`)}const BA=Math.max(h*64,Math.abs(g)*1e-5,i.scale*1e-5,1e-6),rA=xEt(y,i,g,E,BA);PEt(y,A,Q,s),y.__thickenMethod="triangle_split_cull",y.__thickenClassificationMethod="raw_face_ids",y.__thickenDiagnostics={boundaryLoopCount:a.length,sourceTriangleCount:Array.isArray(i.triangles)?i.triangles.length:0,sourceFaceCount:I.length,sourceFaceNames:I,resultTriangleCount:(y._triVerts?.length||0)/3|0,sourceFaceName:s,distance:g,classificationMethod:"raw_face_ids",buildMethod:y.__thickenMethod,constructionMethod:D?"triangle_prism_union":"stitched_shell",trianglePrismUnionRetry:t.__trianglePrismUnionRetry===!0,trianglePrismUnionReason:t.__trianglePrismUnionReason||"",repairBoundaryCapsEnabled:u,weldEpsilon:h,triangleSplitCount:L?.splitCount||0,triangleSplitSkipped:k,triangleSplitSkipReason:b,triangleSplitProbeCount:Y.splitProbeCount||0,culledTriangleCount:L?.culledTriangleCount||0,internalTriangleCullSkipped:t.skipInternalCull===!0,internalTriangleCullRetry:t.__skipInternalCullRetry===!0,relaxedWeldRetry:t.__relaxedWeldRetry===!0,degenerateTriangleCount:L?.degenerateTriangleCount||0,weldedVertexCount:L?.weldedVertexCount||0,orientedTriangleCount:T,orientationCulledTriangleCount:H,orientationCapTriangleCount:X,orientationCandidateRepairAccepted:oA,orientationRepairDistanceLimit:w,orientationWarning:O,orientationSameDirectionEdgeCount:AA?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:AA?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:rA,nonManifoldCulledTriangleCount:J,boundaryCapTriangleCount:x,splitCullPasses:L?.passCount||0,adjacentBoundaryNormalContributionCount:i.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:i.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalCandidateEdgeCount:i.adjacentNormalStats?.candidateEdges||0,adjacentBoundaryNormalAcceptedEdgeCount:i.adjacentNormalStats?.acceptedEdges||0,adjacentBoundaryNormalDotThreshold:i.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalWeightScale:i.adjacentNormalStats?.weightScale??null,adjacentBoundaryNormalFaceFilterCount:i.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:i.adjacentNormalStats?.faceFilterNames||[]},y.userData={...y.userData||{},thicken:{sourceFaceName:s,sourceFaceNames:I,sourceFaceCount:I.length,distance:g,boundaryLoopCount:a.length,sourceTriangleCount:Array.isArray(i.triangles)?i.triangles.length:0,resultTriangleCount:(y._triVerts?.length||0)/3|0,classificationMethod:"raw_face_ids",buildMethod:y.__thickenMethod,weldEpsilon:h,triangleSplitCount:L?.splitCount||0,triangleSplitSkipped:k,triangleSplitSkipReason:b,triangleSplitProbeCount:Y.splitProbeCount||0,culledTriangleCount:L?.culledTriangleCount||0,internalTriangleCullSkipped:t.skipInternalCull===!0,internalTriangleCullRetry:t.__skipInternalCullRetry===!0,relaxedWeldRetry:t.__relaxedWeldRetry===!0,degenerateTriangleCount:L?.degenerateTriangleCount||0,weldedVertexCount:L?.weldedVertexCount||0,orientedTriangleCount:T,orientationCulledTriangleCount:H,orientationCapTriangleCount:X,orientationCandidateRepairAccepted:oA,orientationRepairDistanceLimit:w,orientationWarning:O,orientationSameDirectionEdgeCount:AA?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:AA?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:rA,nonManifoldCulledTriangleCount:J,boundaryCapTriangleCount:x,splitCullPasses:L?.passCount||0,adjacentBoundaryNormalContributionCount:i.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:i.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalDotThreshold:i.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalFaceFilterCount:i.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:i.adjacentNormalStats?.faceFilterNames||[]}};const tA=y;return y=null,tA}finally{try{y?.free?.()}catch{}}}c(NG,"tL");r(NG,"thickenSurfaceToSolid");function zEt(i,A,e={}){const t=zRe(i,e),g=String(e.sourceFaceName||i?.userData?.faceName||i?.name||"").trim();return NG(t,i,A,{...e,sourceFaceNames:Array.isArray(e.sourceFaceNames)?e.sourceFaceNames:g?[g]:void 0,sourceFaceName:g})}c(zEt,"YKt");r(zEt,"thickenFaceToSolid");function HbA(i,A,e={}){const t=Array.isArray(i)?i.filter(n=>n?.geometry):[];if(!t.length)throw new Error("Face.thicken() requires at least one face with geometry.");const g=t.map((n,B)=>String(n?.userData?.faceName||n?.name||`FACE_${B+1}`).trim()||`FACE_${B+1}`),o=nzA(e.featureId||e.name||g[0]||"THICKEN","THICKEN"),s=String(e.sourceFaceName||`${o}_PATCH`).trim()||`${o}_PATCH`,I=GEt(t,e);return NG(I,t[0],A,{...e,sourceFaceName:s,sourceFaceNames:g})}c(HbA,"U0A");r(HbA,"thickenFacesToSolid");var cW;const VEt=(cW=class extends Ig{constructor(A){super(A,Do.FACE.BASE),this.edges=[],this.name=null,this.type="FACE",this.renderOrder=1,this.parentSolid=null,Ps.attach(this)}getAverageNormal(){const A=this.geometry;if(!A)return new W(0,1,0);const e=A.getAttribute("position");if(!e||e.itemSize!==3||e.count<3)return new W(0,1,0);const t=A.getIndex(),g=new W,o=new W,s=new W,I=new W,n=new W,B=new W,C=r((a,Q)=>(a.set(e.getX(Q),e.getY(Q),e.getZ(Q)).applyMatrix4(this.matrixWorld),a),"toWorld");if(t){const a=t.count/3|0;for(let Q=0;Q<a;Q++){const E=t.getX(3*Q+0)>>>0,l=t.getX(3*Q+1)>>>0,h=t.getX(3*Q+2)>>>0;C(g,E),C(o,l),C(s,h),I.subVectors(o,g),n.subVectors(s,g),B.add(n.cross(I))}}else{const a=e.count/3|0;for(let Q=0;Q<a;Q++){const E=3*Q+0,l=3*Q+1,h=3*Q+2;C(g,E),C(o,l),C(s,h),I.subVectors(o,g),n.subVectors(s,g),B.add(n.cross(I))}}return B.lengthSq()===0?new W(0,1,0):B.normalize()}surfaceArea(){const A=this.geometry;if(!A)return 0;const e=A.getAttribute&&A.getAttribute("position");if(!e||e.itemSize!==3)return 0;const t=A.getIndex&&A.getIndex(),g=new W,o=new W,s=new W;let I=0;const n=r((B,C)=>B.set(e.getX(C),e.getY(C),e.getZ(C)).applyMatrix4(this.matrixWorld),"toWorld");if(t){const B=t.count/3|0;for(let C=0;C<B;C++){const a=t.getX(3*C+0)>>>0,Q=t.getX(3*C+1)>>>0,E=t.getX(3*C+2)>>>0;n(g,a),n(o,Q),n(s,E),I+=IzA(g.x,g.y,g.z,o.x,o.y,o.z,s.x,s.y,s.z)}}else{const B=e.count/3|0;for(let C=0;C<B;C++){const a=3*C+0,Q=3*C+1,E=3*C+2;n(g,a),n(o,Q),n(s,E),I+=IzA(g.x,g.y,g.z,o.x,o.y,o.z,s.x,s.y,s.z)}}return I}async points(A=!0){const e=new W,t=[],g=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(g&&g.itemSize===3&&g.count>=2)for(let o=0;o<g.count;o++)e.set(g.getX(o),g.getY(o),g.getZ(o)),A&&e.applyMatrix4(this.matrixWorld),t.push({x:e.x,y:e.y,z:e.z});return t}setMetadata(A){return this.parentSolid&&typeof this.parentSolid.setFaceMetadata=="function"&&this.parentSolid.setFaceMetadata(this.name,A),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getFaceMetadata=="function"?this.parentSolid.getFaceMetadata(this.name):null}renameFace(A){this.parentSolid.renameFace(this.name,A)}thicken(A,e={}){return zEt(this,A,e)}getNeighbors(){const A=this,e=A?.name||A?.userData?.faceName||null;if(!e)return[];const t=A.parentSolid||A.userData?.parentSolid||null,g=new Set,o=r(s=>{s&&s!==A&&g.add(s)},"addFace");if(Array.isArray(A.edges)){for(const s of A.edges)if(!(!s||!Array.isArray(s.faces)))for(const I of s.faces)o(I)}if(g.size===0&&t&&typeof t.getBoundaryEdgePolylines=="function"){const s=new Map;if(Array.isArray(t.children)){for(const I of t.children)if(I&&I.type==="FACE"){const n=I.name||I.userData?.faceName||null;n&&s.set(n,I)}}try{const I=t.getBoundaryEdgePolylines()||[];for(const n of I){const B=n?.faceA,C=n?.faceB;B===e&&C?o(s.get(C)):C===e&&B&&o(s.get(B))}}catch{}}return Array.from(g)}},c(cW,"rhe2"),cW);r(VEt,"Face");let qRe=VEt;const BzA=r(i=>{if(!i)return{};try{const A=JSON.parse(i);return A&&typeof A=="object"?A:{}}catch{return{}}},"parseMetadataJson"),oM=r((i=[])=>Array.from(i||[],A=>[A?.[0],A?.[1]]),"cloneSnapshotEntries"),AHA=r((i,A=e=>e)=>i instanceof Map?Array.from(i.entries(),([e,t])=>[e,A(t)]):[],"toPlainEntryArray"),w8e=r(i=>JSON.stringify(i&&typeof i=="object"?i:{}),"serializeMetadata"),pTi=r((i=[],A=3)=>{const e=new Map,t=Math.max(3,Number(A)||3);for(let g=0;g+2<i.length;g+=t){const o=i[g+0],s=i[g+1],I=i[g+2];e.set(`${o},${s},${I}`,g/t|0)}return e},"rebuildVertexKeyMap"),R5A=r(i=>({numProp:Number(i?._numProp??3),vertPropertiesRef:i?._vertProperties||null,vertPropertiesLength:Array.isArray(i?._vertProperties)?i._vertProperties.length:0,triVertsRef:i?._triVerts||null,triVertsLength:Array.isArray(i?._triVerts)?i._triVerts.length:0,triIDsRef:i?._triIDs||null,triIDsLength:Array.isArray(i?._triIDs)?i._triIDs.length:0,faceNameToIDRef:i?._faceNameToID||null,faceNameToIDSize:i?._faceNameToID instanceof Map?i._faceNameToID.size:0,idToFaceNameRef:i?._idToFaceName||null,idToFaceNameSize:i?._idToFaceName instanceof Map?i._idToFaceName.size:0,faceMetadataRef:i?._faceMetadata||null,faceMetadataSize:i?._faceMetadata instanceof Map?i._faceMetadata.size:0,edgeMetadataRef:i?._edgeMetadata||null,edgeMetadataSize:i?._edgeMetadata instanceof Map?i._edgeMetadata.size:0,auxEdgesRef:i?._auxEdges||null,auxEdgesLength:Array.isArray(i?._auxEdges)?i._auxEdges.length:0,faceMetadataVersion:Number(i?._faceMetadataVersion||0),edgeMetadataVersion:Number(i?._edgeMetadataVersion||0),dirty:!!i?._dirty}),"captureSolidCppSyncStamp"),fTi=r((i,A)=>!!i&&!!A&&i.numProp===A.numProp&&i.vertPropertiesRef===A.vertPropertiesRef&&i.vertPropertiesLength===A.vertPropertiesLength&&i.triVertsRef===A.triVertsRef&&i.triVertsLength===A.triVertsLength&&i.triIDsRef===A.triIDsRef&&i.triIDsLength===A.triIDsLength&&i.faceNameToIDRef===A.faceNameToIDRef&&i.faceNameToIDSize===A.faceNameToIDSize&&i.idToFaceNameRef===A.idToFaceNameRef&&i.idToFaceNameSize===A.idToFaceNameSize&&i.faceMetadataRef===A.faceMetadataRef&&i.faceMetadataSize===A.faceMetadataSize&&i.edgeMetadataRef===A.edgeMetadataRef&&i.edgeMetadataSize===A.edgeMetadataSize&&i.auxEdgesRef===A.auxEdgesRef&&i.auxEdgesLength===A.auxEdgesLength&&i.faceMetadataVersion===A.faceMetadataVersion&&i.edgeMetadataVersion===A.edgeMetadataVersion&&i.dirty===A.dirty,"solidCppSyncStampEquals"),YB=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.setAuthoringState=="function"&&typeof i.bakeTransform=="function"&&typeof i.getAuthoringState=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),ZRe=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.weldVerticesByEpsilon=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),WEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.pushFace=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),Y5A=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.prepareManifoldMesh=="function"&&typeof i.isCoherentlyOrientedManifold=="function"&&typeof i.fixTriangleWindingsByAdjacency=="function"&&typeof i.invertNormals=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),FTi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.normalizeFaceTracking=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),U5A=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.getFace=="function"&&typeof i.getFaces=="function"&&typeof i.getFaceNormal=="function"&&typeof i.getBoundaryEdgePolylines=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),mTi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.computeFilletCenterline=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),NTi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.addAuxEdge=="function"&&typeof i.getAuxEdges=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),_Et=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.transformMetadata=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),qEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.cleanupTinyFaceIslands=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),ZEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.removeSmallIslands=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),XEt=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.mergeTinyFaces=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),$Et=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.removeInternalTriangles=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),STi=(()=>{try{if(typeof Tt?.BrepSolidCore!="function")return!1;const i=new Tt.BrepSolidCore;try{return typeof i.removeDisconnectedIslandsByVolume=="function"}finally{typeof i.delete=="function"&&i.delete()}}catch{return!1}})(),mn=r((i,A)=>{if(!i)throw new Error(`${A} requires the custom local manifold build with BrepSolidCore support.`)},"requireCppSolidCoreCapability"),lC=r(i=>({numProp:Number(i?._numProp??3),vertProperties:Array.from(i?._vertProperties??[]),triVerts:Array.from(i?._triVerts??[]),triIDs:Array.from(i?._triIDs??[]),faceNameToID:AHA(i?._faceNameToID),idToFaceName:AHA(i?._idToFaceName),faceMetadataJson:AHA(i?._faceMetadata,w8e),edgeMetadataJson:AHA(i?._edgeMetadata,w8e),auxEdges:DO(i?._auxEdges)}),"buildSolidAuthoringStateSnapshot"),eHA=r(i=>new Map(oM(i)),"cloneSnapshotMapEntries"),GTi=r((i="INSET")=>String(i||"INSET").toUpperCase()==="OUTSET"?"OUTSET":"INSET","normalizeFilletSideMode$1"),Act=r(i=>{if(Array.isArray(i)&&i.length>=3){const A=Number(i[0]),e=Number(i[1]),t=Number(i[2]);return Number.isFinite(A)&&Number.isFinite(e)&&Number.isFinite(t)?[A,e,t]:null}if(i&&typeof i=="object"){const A=Number(i.x),e=Number(i.y),t=Number(i.z);if(Number.isFinite(A)&&Number.isFinite(e)&&Number.isFinite(t))return[A,e,t]}return null},"point3ArrayFromAny$1"),zG=r(i=>{const A=Act(i);return A?{x:A[0],y:A[1],z:A[2]}:null},"point3ObjectFromAny$1"),DO=r(i=>{const A=Array.isArray(i)?i:[],e=[];for(const t of A){const g=Array.isArray(t?.points)?t.points.map(B=>Act(B)).filter(Boolean):[];if(g.length<2)continue;const o={name:String(t?.name||"EDGE"),points:g,closedLoop:!!t?.closedLoop,polylineWorld:!!t?.polylineWorld,centerline:!!t?.centerline},s=String(t?.materialKey||"").trim();s&&(o.materialKey=s);const I=String(t?.faceA||"").trim(),n=String(t?.faceB||"").trim();I&&(o.faceA=I),n&&(o.faceB=n),e.push(o)}return e},"sanitizeAuxEdges$1"),RTi=r((i,A=1e-9)=>{const e=Array.isArray(i)?i:[];if(e.length===0)return[];const t=Number.isFinite(A)?Math.max(1e-12,Math.abs(A)):1e-9,g=t*t,o=[];for(let Q=0;Q<e.length;Q++){const E=e[Q];if(!Array.isArray(E)||E.length<3)continue;const l=Number(E[0]),h=Number(E[1]),w=Number(E[2]);!Number.isFinite(l)||!Number.isFinite(h)||!Number.isFinite(w)||o.push([l,h,w])}if(o.length===0)return[];const s=[];for(let Q=0;Q<o.length;Q++){const E=o[Q];if(s.length>0){const l=s[s.length-1],h=E[0]-l[0],w=E[1]-l[1],d=E[2]-l[2];if(h*h+w*w+d*d<=g)continue}s.push(E)}if(s.length<3)return s;let I=0,n=0;for(let Q=1;Q<s.length;Q++){const E=s[Q-1],l=s[Q],h=Math.hypot(l[0]-E[0],l[1]-E[1],l[2]-E[2]);!Number.isFinite(h)||h<=0||(I+=h,h>n&&(n=h))}const B=Math.max(t,I*1e-7,n*1e-6),C=B*B;if(C<=g)return s;const a=[];for(let Q=0;Q<s.length;Q++){const E=s[Q];if(a.length===0){a.push(E);continue}const l=a[a.length-1],h=E[0]-l[0],w=E[1]-l[1],d=E[2]-l[2];h*h+w*w+d*d<=C||a.push(E)}return a.length>=2?a:s},"sanitizeFilletInputPolyline$1"),YTi=r((i=[])=>{const A=new Map;for(const[e,t]of oM(i))A.set(t,e);return A},"invertFaceNameToIDEntries"),UTi=r(i=>{const A=Array.from(i?.triIDs??[]),e=new Set(A),t=Array.from(e).sort((o,s)=>Number(o)-Number(s));let g=new Map(oM(i?.idToFaceName));if(g.size===0&&(g=YTi(i?.faceNameToID)),t.every(o=>g.has(o))||t.length===0)return g;if(g.size===t.length){const o=Array.from(g.entries()).sort((I,n)=>Number(I[0])-Number(n[0])).map(I=>String(I?.[1]||"")),s=new Map;for(let I=0;I<t.length;I++)s.set(t[I],o[I]||`FACE_${t[I]}`);return s}for(const o of t)g.has(o)||g.set(o,`FACE_${o}`);return g},"buildResolvedSnapshotIDToFaceName"),kTi=r(i=>{const A=UTi(i),e=new Map,t=new Map,g=new Map,o=r((s,I="")=>{const n=Number(s);if(g.has(n))return g.get(n);const B=gD.reserveIDs(1);g.set(n,B);const C=String(A.get(s)??I??"").trim()||`FACE_${B}`;return t.set(B,C),e.set(C,B),B},"ensureReservedID");for(const[s,I]of A.entries())o(s,I);return{triIDs:Array.from(i?.triIDs??[],s=>o(s,A.get(s))),faceNameToID:e,idToFaceName:t}},"remapSnapshotFaceIDsToReservedRange"),sB=r((i,A,e={})=>{const t=Math.max(3,Number(A?.numProp??3)),g=Array.from(A?.vertProperties??[]);let o=null;if(e?.remapFaceIDs)if(FTi){const s=new Tt.BrepSolidCore;try{s.setAuthoringState(A),s.normalizeFaceTracking();const I=s.getAuthoringState();o={triIDs:Array.from(I?.triIDs??[]),faceNameToID:new Map(oM(I?.faceNameToID)),idToFaceName:new Map(oM(I?.idToFaceName))}}finally{typeof s.delete=="function"&&s.delete()}}else o=kTi(A);i._numProp=t,i._vertProperties=g,i._triVerts=Array.from(A?.triVerts??[]),i._triIDs=o?o.triIDs:Array.from(A?.triIDs??[]),i._faceNameToID=o?o.faceNameToID:new Map(oM(A?.faceNameToID)),i._idToFaceName=o?o.idToFaceName:new Map(oM(A?.idToFaceName)),i._faceMetadata=new Map(Array.from(A?.faceMetadataJson??[],s=>[s?.[0],BzA(s?.[1])])),i._edgeMetadata=new Map(Array.from(A?.edgeMetadataJson??[],s=>[s?.[0],BzA(s?.[1])])),i._auxEdges=DO(A?.auxEdges),i._vertKeyToIndex=pTi(g,t),i._faceMetadataVersion=Number(i?._faceMetadataVersion||0)+1,i._edgeMetadataVersion=Number(i?._edgeMetadataVersion||0)+1,i._cppSolidCoreSyncStamp=null},"applySolidAuthoringStateSnapshot"),jU=r((i,A)=>(A.setAuthoringState(lC(i)),i._cppSolidCoreSyncStamp=R5A(i),A),"syncSolidAuthoringStateToCpp"),yQ=r((i,A)=>{const e=A.getAuthoringState();return sB(i,e),i._cppSolidCoreSyncStamp=R5A(i),e},"syncSolidAuthoringStateFromCpp"),LTi=r((i,A)=>(i._auxEdges=A.getAuxEdges(),i._cppSolidCoreSyncStamp=R5A(i),i._auxEdges),"syncSolidAuxEdgesFromCpp"),eN=r(i=>{if(YB)try{return Ya(i).getAuthoringState()}catch{}const A=lC(i);return{numProp:Number(A?.numProp??3),vertProperties:Array.from(A?.vertProperties??[]),triVerts:Array.from(A?.triVerts??[]),triIDs:Array.from(A?.triIDs??[]),faceNameToID:eHA(A?.faceNameToID),idToFaceName:eHA(A?.idToFaceName),faceMetadataJson:eHA(A?.faceMetadataJson),edgeMetadataJson:eHA(A?.edgeMetadataJson),auxEdges:DO(A?.auxEdges),vertexCount:Math.floor((Array.isArray(A?.vertProperties)?A.vertProperties.length:0)/Math.max(3,Number(A?.numProp??3))),triangleCount:Math.floor((Array.isArray(A?.triVerts)?A.triVerts.length:0)/3)}},"getSolidAuthoringStateSnapshot"),Ya=r(i=>{mn(YB,"BrepSolidCore"),i._cppSolidCore=i._cppSolidCore||new Ua;const A=R5A(i);return fTi(A,i._cppSolidCoreSyncStamp)||jU(i,i._cppSolidCore),i._cppSolidCore},"getSyncedCppSolidCore"),PUA=r((i,A=1,e="INSET")=>{const t={points:[],tangentA:[],tangentB:[],edge:[],closedLoop:!1};try{if(mn(YB&&mTi,"Solid.computeFilletCenterline()"),!i||!Number.isFinite(A)||A<=0)return t;const g=i.parentSolid||i.parent||null;if(!g)return t;const o=i?.faces?.[0]?.name||i?.userData?.faceA||null,s=i?.faces?.[1]?.name||i?.userData?.faceB||null,I=Array.isArray(i?.userData?.segmentFacePairs)?i.userData.segmentFacePairs:null,n=Array.isArray(I)&&I.length>0;if(!n&&(!o||!s))return t;const B=Math.max(1e-12,Math.abs(Number(A)||0)*1e-9,1e-9),C=RTi(i?.userData?.polylineLocal,B);if(!Array.isArray(C)||C.length<2)return t;let a=!!(i?.closedLoop||i?.userData?.closedLoop);if(!a&&C.length>2){const l=C[0],h=C[C.length-1],w=l[0]-h[0],d=l[1]-h[1],D=l[2]-h[2];w*w+d*d+D*D<=B*B&&(a=!0)}const Q={polyline:C,radius:Number(A),sideMode:GTi(e),closedLoop:!!a};o&&(Q.faceAName=o),s&&(Q.faceBName=s),n&&(Q.segmentFacePairs=I);const E=Ya(g).computeFilletCenterline(Q);return!E||typeof E!="object"||(t.nativeKernel=E.nativeKernel===!0,t.closedLoop=!!E.closedLoop,t.points=Array.isArray(E.points)?E.points.map(zG).filter(Boolean):[],t.tangentA=Array.isArray(E.tangentA)?E.tangentA.map(zG).filter(Boolean):[],t.tangentB=Array.isArray(E.tangentB)?E.tangentB.map(zG).filter(Boolean):[],t.edge=Array.isArray(E.edge)?E.edge.map(zG).filter(Boolean):[],E.radiusClamp&&(t.radiusClamp=E.radiusClamp),E.nativeFinalized===!0&&(t.nativeFinalized=!0)),t}catch(g){return console.warn("[computeFilletCenterlineForEdge] failed:",g?.message||g),t}},"computeFilletCenterlineForEdge");var lW;const ect=(lW=class{constructor(A=null){if(A){this._native=A;return}if(typeof Tt?.BrepSolidCore!="function")throw new Error("BrepSolidCore is only available in the custom local manifold build.");this._native=new Tt.BrepSolidCore}clear(){return this._native.clear(),this}setAuthoringState(A){return this._native.setAuthoringState(A),this}addTriangle(A,e,t,g){return this._native.addTriangle(A,e,t,g),this}setFaceMetadata(A,e={}){return this._native.setFaceMetadataJson(A,JSON.stringify(e||{})),this}getFaceMetadata(A){return BzA(this._native.getFaceMetadataJson(A))}renameFace(A,e){return!!this._native.renameFace(A,e)}cleanupTinyFaceIslands(A){return Number(this._native.cleanupTinyFaceIslands(A))}removeSmallIslands(A,e=!0,t=!0){return Number(this._native.removeSmallIslands(Math.max(0,Number(A)|0),!!e,!!t))}mergeTinyFaces(A){return Number(this._native.mergeTinyFaces(A))}removeInternalTriangles(){return Number(this._native.removeInternalTriangles())}removeDisconnectedIslandsByVolume(A){return Number(this._native.removeDisconnectedIslandsByVolume(A))}normalizeFaceTracking(){return this._native.normalizeFaceTracking(),this}setEdgeMetadata(A,e={}){return this._native.setEdgeMetadataJson(A,JSON.stringify(e||{})),this}getEdgeMetadata(A){return BzA(this._native.getEdgeMetadataJson(A))}getFaceNames(){return Array.from(this._native.getFaceNames()||[])}getFace(A){return Array.from(this._native.getFace(A)||[],e=>({faceName:String(e?.faceName||A||""),indices:Array.from(e?.indices||[]),p1:Array.from(e?.p1||[]),p2:Array.from(e?.p2||[]),p3:Array.from(e?.p3||[])}))}getFaceNormal(A){const e=this._native.getFaceNormal(A)||{};return{faceFound:!!e?.faceFound,validNormal:!!e?.validNormal,normal:Array.from(e?.normal||[]),planarRatio:Number(e?.planarRatio??0),affectedVertexCount:Number(e?.affectedVertexCount??0)}}getFaces(A=!1){return Array.from(this._native.getFaces(!!A)||[],e=>({faceName:String(e?.faceName||""),triangles:Array.from(e?.triangles||[],t=>({faceName:String(t?.faceName||e?.faceName||""),indices:Array.from(t?.indices||[]),p1:Array.from(t?.p1||[]),p2:Array.from(t?.p2||[]),p3:Array.from(t?.p3||[])}))}))}getBoundaryEdgePolylines(){return Array.from(this._native.getBoundaryEdgePolylines()||[],A=>({name:String(A?.name||""),faceA:String(A?.faceA||""),faceB:String(A?.faceB||""),indices:Array.from(A?.indices||[]),positions:Array.from(A?.positions||[],e=>Array.from(e||[])),closedLoop:!!A?.closedLoop}))}addAuxEdge(A,e,t={}){return this._native.addAuxEdge(String(A||"EDGE"),e||[],t||{}),this}setAuxEdges(A=[]){return this._native.setAuxEdges(DO(A)),this}getAuxEdges(){return DO(this._native.getAuxEdges()||[])}computeFilletCenterline(A={}){const e=this._native.computeFilletCenterline(A||{});return{points:Array.from(e?.points||[],t=>zG(t)).filter(Boolean),tangentA:Array.from(e?.tangentA||[],t=>zG(t)).filter(Boolean),tangentB:Array.from(e?.tangentB||[],t=>zG(t)).filter(Boolean),edge:Array.from(e?.edge||[],t=>zG(t)).filter(Boolean),closedLoop:!!e?.closedLoop,radiusClamp:e?.radiusClamp||null,nativeKernel:e?.nativeKernel===!0,nativeFinalized:e?.nativeFinalized===!0}}getAuthoringState(){const A=this._native.getAuthoringState();return{numProp:Number(A?.numProp??3),vertProperties:Array.from(A?.vertProperties??[]),triVerts:Array.from(A?.triVerts??[]),triIDs:Array.from(A?.triIDs??[]),faceNameToID:new Map(oM(A?.faceNameToID)),idToFaceName:new Map(oM(A?.idToFaceName)),faceMetadataJson:new Map(oM(A?.faceMetadataJson)),edgeMetadataJson:new Map(oM(A?.edgeMetadataJson)),auxEdges:DO(A?.auxEdges),vertexCount:Number(A?.vertexCount??0),triangleCount:Number(A?.triangleCount??0)}}bakeTransform(A){const e=A&&typeof A=="object"&&"elements"in A?Array.from(A.elements||[]):Array.from(A||[]);return this._native.bakeTransform(e),this}transformMetadata(A){const e=A&&typeof A=="object"&&"elements"in A?Array.from(A.elements||[]):Array.from(A||[]);return this._native.transformMetadata(e),this}weldVerticesByEpsilon(A){return this._native.weldVerticesByEpsilon(A),this}pushFace(A,e){return this._native.pushFace(A,e)}isCoherentlyOrientedManifold(){return!!this._native.isCoherentlyOrientedManifold()}fixTriangleWindingsByAdjacency(){return!!this._native.fixTriangleWindingsByAdjacency()}invertNormals(){return this._native.invertNormals(),this}prepareManifoldMesh(){const A=this._native.prepareManifoldMesh();return{numProp:Number(A?.numProp??3),vertProperties:Array.from(A?.vertProperties??[]),triVerts:Array.from(A?.triVerts??[]),faceID:Array.from(A?.faceID??[]),mergeFromVert:Array.from(A?.mergeFromVert??[]),mergeToVert:Array.from(A?.mergeToVert??[]),vertexCount:Number(A?.vertexCount??0),triangleCount:Number(A?.triangleCount??0)}}vertexCount(){return Number(this._native.vertexCount())}triangleCount(){return Number(this._native.triangleCount())}dispose(){try{this._native&&typeof this._native.delete=="function"&&this._native.delete()}finally{this._native=null}}},c(lW,"Bhe2"),lW);r(ect,"CppSolidCore");let Ua=ect;function tct(){this._numProp=3,this._vertProperties=[],this._triVerts=[],this._triIDs=[],this._vertKeyToIndex=new Map,this._faceNameToID=new Map,this._idToFaceName=new Map,this._faceMetadata=new Map,this._edgeMetadata=new Map,this._faceMetadataVersion=0,this._edgeMetadataVersion=0,this._dirty=!0,this._manifold=null,this._faceIndex=null,this._visualizeCache=null,this._minGapIndex=null,this._epsilon=0,this._freeTimer=null,this._cppSolidCore=null,this._cppSolidCoreSyncStamp=null,this.type="SOLID",this.renderOrder=1,this._auxEdges=[]}c(tct,"zKt");r(tct,"constructorImpl");function ict(){const i=this.constructor,A=new i;return sB(A,eN(this)),A._dirty=!0,A._manifold=null,A._faceIndex=null,A._visualizeCache=null,A._minGapIndex=null,A._cppSolidCore=null,A._cppSolidCoreSyncStamp=null,A.type="SOLID",A.renderOrder=this.renderOrder,A}c(ict,"jKt");r(ict,"clone$7");function gct(){try{try{this._freeTimer&&clearTimeout(this._freeTimer)}catch{}if(this._freeTimer=null,this._manifold){try{typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}if(this._cppSolidCore){try{typeof this._cppSolidCore.dispose=="function"&&this._cppSolidCore.dispose()}catch{}this._cppSolidCore=null}this._cppSolidCoreSyncStamp=null,this._dirty=!0,this._faceIndex=null}catch{}return this}c(gct,"VKt");r(gct,"free");function oct([i,A,e]){return`${i},${A},${e}`}c(oct,"WKt");r(oct,"_key");function sct(i){if(!Array.isArray(i)||i.length<3)throw console.error("Invalid point passed to _getPointIndex:",i),new Error("Point must be an array with at least 3 elements");const A=i[0],e=i[1],t=i[2];if(!isFinite(A)||!isFinite(e)||!isFinite(t))throw console.error("Non-finite coordinates in _getPointIndex:",{x:A,y:e,z:t}),new Error(`Invalid point coordinates: (${A}, ${e}, ${t}) - must be finite numbers`);if((this._vertKeyToIndex?.size||0)===0&&Array.isArray(this._vertProperties)&&this._vertProperties.length>0){this._vertKeyToIndex=new Map;for(let I=0;I<this._vertProperties.length;I+=3){const n=this._vertProperties[I+0],B=this._vertProperties[I+1],C=this._vertProperties[I+2];this._vertKeyToIndex.set(`${n},${B},${C}`,I/3|0)}}const g=this._key(i),o=this._vertKeyToIndex.get(g);if(o!==void 0)return o;const s=this._vertProperties.length/3;return this._vertProperties.push(A,e,t),this._vertKeyToIndex.set(g,s),s}c(sct,"_Kt");r(sct,"_getPointIndex");function Ict(i){if(!this._faceNameToID.has(i)){const A=gD.reserveIDs(1);this._faceNameToID.set(i,A),this._idToFaceName.set(A,i)}return this._faceNameToID.get(i)}c(Ict,"qKt");r(Ict,"_getOrCreateID");function nct(i,A,e,t){const g=this._getOrCreateID(i),o=this._getPointIndex(A),s=this._getPointIndex(e),I=this._getPointIndex(t);return this._triVerts.push(o,s,I),this._triIDs.push(g),this._dirty=!0,this._faceIndex=null,this}c(nct,"ZKt");r(nct,"addTriangle");function Bct(i,A,e={}){try{const t=r(C=>{if(Array.isArray(C)&&C.length===3)return[C[0],C[1],C[2]];if(C&&typeof C=="object"){const a=+C.x,Q=+C.y,E=+C.z;if(Number.isFinite(a)&&Number.isFinite(Q)&&Number.isFinite(E))return[a,Q,E]}return null},"toArr"),g=Array.isArray(A)?A.map(t).filter(Boolean):[];if(g.length<2)return this;const o=i||"EDGE",s=Object.prototype.hasOwnProperty.call(e||{},"centerline"),I=typeof o=="string"&&/centerline/i.test(o),n=s?!!e.centerline:I;mn(YB&&NTi,"Solid.addAuxEdge()");const B=Ya(this);B.addAuxEdge(o,g,{closedLoop:!!e.closedLoop,polylineWorld:!!e.polylineWorld,materialKey:e.materialKey||"OVERLAY",centerline:n,faceA:e.faceA||"",faceB:e.faceB||""}),LTi(this,B)}catch{}return this}c(Bct,"XKt");r(Bct,"addAuxEdge");function rct(i,A,e="CENTERLINE",t={}){const g=Array.isArray(i)?i:[i?.x||0,i?.y||0,i?.z||0],o=Array.isArray(A)?A:[A?.x||0,A?.y||0,A?.z||0],s={...t||{}};return Object.prototype.hasOwnProperty.call(s,"centerline")||(s.centerline=!0),this.addAuxEdge(e,[g,o],s)}c(rct,"$Kt");r(rct,"addCenterline");function Cct(i,A){if(!A||typeof A!="object")return this;mn(YB,"Solid.setFaceMetadata");const e=Ya(this),t=e.getFaceMetadata(i),g=t&&typeof t=="object"?t:{};return e.setFaceMetadata(i,{...g,...A}),yQ(this,e),this}c(Cct,"AHt");r(Cct,"setFaceMetadata");function act(i){if(mn(YB,"Solid.getFaceMetadata"),this._faceMetadata instanceof Map)return this._faceMetadata.get(i)||{};try{return this._cppSolidCore?.getFaceMetadata(i)||{}}catch{return{}}}c(act,"eHt");r(act,"getFaceMetadata");function Qct(){if(mn(YB,"Solid.getFaceNames"),this._faceNameToID instanceof Map&&this._faceNameToID.size>0)return Array.from(this._faceNameToID.keys());if(this._idToFaceName instanceof Map&&this._idToFaceName.size>0)return Array.from(this._idToFaceName.values());try{return this._cppSolidCore?.getFaceNames()||[]}catch{return[]}}c(Qct,"tHt");r(Qct,"getFaceNames");function Ect(){const i=this._idToFaceName instanceof Map?this._idToFaceName:new Map,A=this._faceNameToID instanceof Map?this._faceNameToID:new Map;if(i.size===0&&A.size===0)return this;const e=new Map,t=new Map,g=new Map;for(const[o,s]of i.entries())e.has(s)?t.set(o,e.get(s)):(e.set(s,o),g.set(o,s));for(const[o,s]of A.entries())e.has(o)||(e.set(o,s),g.set(s,o));return t.size===0?(this._idToFaceName=g,this._faceNameToID=new Map(Array.from(g.entries(),([o,s])=>[s,o])),this):(this._triIDs=Array.isArray(this._triIDs)?this._triIDs.map(o=>t.get(o)??o):[],this._idToFaceName=g,this._faceNameToID=new Map(Array.from(g.entries(),([o,s])=>[s,o])),this._dirty=!0,this._manifold=null,this._faceIndex=null,this._visualizeCache=null,this._cppSolidCoreSyncStamp=null,this)}c(Ect,"iHt");r(Ect,"deduplicateFaceNames");function cct(i,A){if(!i||!A||i===A)return this;mn(YB,"Solid.renameFace");const e=Ya(this),t=this._faceMetadata instanceof Map&&this._faceMetadata.has(i),g=t?e.getFaceMetadata(i)||{}:null,o=this._faceMetadata instanceof Map&&this._faceMetadata.has(A)?e.getFaceMetadata(A)||{}:null;return e.renameFace(i,A)?(yQ(this,e),t&&(e.setFaceMetadata(A,{...o&&typeof o=="object"?o:{},...g&&typeof g=="object"?g:{}}),yQ(this,e)),this._dirty=!0,this._faceIndex=null,this):this}c(cct,"gHt");r(cct,"renameFace");function lct(i,A){if(!A||typeof A!="object")return this;mn(YB,"Solid.setEdgeMetadata");const e=Ya(this),t=e.getEdgeMetadata(i),g=t&&typeof t=="object"?t:{};return e.setEdgeMetadata(i,{...g,...A}),yQ(this,e),this}c(lct,"sHt");r(lct,"setEdgeMetadata");function hct(i){if(mn(YB,"Solid.getEdgeMetadata"),this._edgeMetadata instanceof Map)return this._edgeMetadata.get(i)||null;try{return this._cppSolidCore?.getEdgeMetadata(i)||null}catch{return null}}c(hct,"oHt");r(hct,"getEdgeMetadata");function XRe(i,A=PC){const e=Array.isArray(i?.position)?i.position:[0,0,0],t=Array.isArray(i?.rotationEuler)?i.rotationEuler:[0,0,0],g=Array.isArray(i?.scale)?i.scale:[1,1,1],o=new A.Vector3(Number(e[0]||0),Number(e[1]||0),Number(e[2]||0)),s=new A.Euler(A.MathUtils.degToRad(Number(t[0]||0)),A.MathUtils.degToRad(Number(t[1]||0)),A.MathUtils.degToRad(Number(t[2]||0)),"XYZ"),I=new A.Quaternion().setFromEuler(s),n=new A.Vector3(Number(g[0]||1),Number(g[1]||1),Number(g[2]||1));return new A.Matrix4().compose(o,I,n)}c(XRe,"lgt");r(XRe,"composeTrsMatrixDeg");function k5A(i,A,e=PC){const t=new e.Vector3(Number(i?.position?.[0]||0),Number(i?.position?.[1]||0),Number(i?.position?.[2]||0)),g=new e.Quaternion().fromArray(Array.isArray(i?.quaternion)&&i.quaternion.length>=4?i.quaternion:[0,0,0,1]),o=new e.Vector3(Number(i?.scale?.[0]||1),Number(i?.scale?.[1]||1),Number(i?.scale?.[2]||1)),s=new e.Matrix4().compose(t,g,o),I=XRe(A,e);return s.multiply(I)}c(k5A,"_ne");r(k5A,"combineBaseWithDeltaDeg");function wct(i){try{if(!i||typeof i.elements>"u")return this;if(!Array.isArray(this._vertProperties)||this._vertProperties.length===0)return this;const A=i&&i.isMatrix4?i:new Bt().fromArray(i.elements||i);mn(YB,"Solid.bakeTransform()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),this._cppSolidCore.bakeTransform(A),yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}catch{}return this}c(wct,"nHt");r(wct,"bakeTransform");function dct(i){try{const A=XRe(i,PC);return this.bakeTransform(A)}catch{return this}}c(dct,"IHt");r(dct,"bakeTRS");function Dct(i,A){const e=this.constructor,t=i instanceof W?i.clone():new W(i[0],i[1],i[2]),g=A instanceof W?A.clone().normalize():new W(A[0],A[1],A[2]).normalize(),o=eN(this),s=this.getMesh();try{const I=s.vertProperties,n=s.triVerts,B=s.faceID&&s.faceID.length?Array.from(s.faceID):[],C=new e;C._numProp=s.numProp||3;const a=new Array(I.length),Q=new W;for(let E=0;E<I.length;E+=3){Q.set(I[E+0],I[E+1],I[E+2]);const l=2*Q.clone().sub(t).dot(g),h=Q.sub(g.clone().multiplyScalar(l));a[E+0]=h.x,a[E+1]=h.y,a[E+2]=h.z}C._vertProperties=a,C._triVerts=Array.from(n),C._triIDs=B.length?B:new Array(n.length/3|0).fill(0);try{C._idToFaceName=new Map(o?.idToFaceName||[]),C._faceNameToID=new Map(o?.faceNameToID||[]),C._faceMetadata=new Map(Array.from(o?.faceMetadataJson||[],([E,l])=>[E,JSON.parse(l||"{}")])),C._edgeMetadata=new Map(Array.from(o?.edgeMetadataJson||[],([E,l])=>[E,JSON.parse(l||"{}")]))}catch{}try{const E=Array.isArray(this._auxEdges)?this._auxEdges:[],l=new W,h=new W,w=new W;C._auxEdges=E.map(d=>{const D=[];if(Array.isArray(d?.points))for(const u of d.points)!Array.isArray(u)||u.length!==3||(l.set(u[0],u[1],u[2]),h.subVectors(l,t),w.copy(g).multiplyScalar(2*h.dot(g)),l.sub(w),D.push([l.x,l.y,l.z]));return{name:d?.name,closedLoop:!!d?.closedLoop,polylineWorld:!!d?.polylineWorld,materialKey:d?.materialKey,centerline:!!d?.centerline,points:D}}).filter(d=>Array.isArray(d.points)&&d.points.length)}catch{C._auxEdges=[]}C._vertKeyToIndex=new Map;for(let E=0;E<C._vertProperties.length;E+=3){const l=C._vertProperties[E],h=C._vertProperties[E+1],w=C._vertProperties[E+2];C._vertKeyToIndex.set(`${l},${h},${w}`,E/3|0)}C._dirty=!0,C._faceIndex=null,C._manifold=null;try{mn(YB&&_Et,"Solid.mirrorAcrossPlane()");const E=g.x,l=g.y,h=g.z,w=t.dot(g),d=new Bt().set(1-2*E*E,-2*E*l,-2*E*h,2*w*E,-2*l*E,1-2*l*l,-2*l*h,2*w*l,-2*h*E,-2*h*l,1-2*h*h,2*w*h,0,0,0,1);C._cppSolidCore=C._cppSolidCore||new Ua,jU(C,C._cppSolidCore),C._cppSolidCore.transformMetadata(d),yQ(C,C._cppSolidCore),C._cppSolidCore.dispose(),C._cppSolidCore=null,C._cppSolidCoreSyncStamp=null}catch{}return C}finally{try{s&&typeof s.delete=="function"&&s.delete()}catch{}}}c(Dct,"rHt");r(Dct,"mirrorAcrossPlane");function uct(i,A=.001,e={}){const t=Number(A);if(!i||!Number.isFinite(t)||t===0)return this;const g=e?.warnMissing!==!1,o=e?.warnInvalidNormal!==!1;try{this._manifoldize()}catch{}if(this._faceNameToID.get(i)===void 0)return g&&console.warn(`pushFace: Face "${i}" not found`),this;mn(YB&&WEt,"Solid.pushFace()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore);const s=this._cppSolidCore.pushFace(i,t)||{};if(!s.faceFound)return g&&console.warn(`pushFace: Face "${i}" not found`),this;if(!s.moved)return s.invalidNormal&&o&&console.warn(`pushFace: Invalid normal for face "${i}"`),this;yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,this}c(uct,"BHt");r(uct,"pushFace");function Mct(){const i=r(()=>typeof performance<"u"&&performance?.now?performance.now():Date.now(),"nowMs");i();try{this._freeTimer&&clearTimeout(this._freeTimer)}catch{}try{this._freeTimer=setTimeout(()=>{try{this.free()}catch{}},60*1e3)}catch{}if(this.deduplicateFaceNames(),!this._dirty&&this._manifold)return i(),this._manifold;let A=!1;const e=r((t=!0)=>{A||(A=!0,i(),(this?._triVerts?.length||0)/3|0,(this?._vertProperties?.length||0)/3|0)},"__logDone");try{mn(YB&&Y5A,"Solid._manifoldize()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore);const t=this._cppSolidCore.prepareManifoldMesh();yQ(this,this._cppSolidCore);const g=new X$e({numProp:Number(t?.numProp??this._numProp??3),vertProperties:new Float32Array(t?.vertProperties??[]),triVerts:new Uint32Array(t?.triVerts??[]),faceID:new Uint32Array(t?.faceID??[]),mergeFromVert:new Uint32Array(t?.mergeFromVert??[]),mergeToVert:new Uint32Array(t?.mergeToVert??[])});try{this._manifold=new gD(g)}catch(o){try{if(this&&Object.prototype.hasOwnProperty.call(this,"edgeToFillet")){const s=(this._triVerts?.length||0)/3|0,I=(this._vertProperties?.length||0)/3|0,n=[];try{if(this.edgeToFillet&&Array.isArray(this.edgeToFillet.faces))for(const C of this.edgeToFillet.faces)C&&C.name&&n.push(C.name)}catch{}const B={type:"FilletSolidManifoldFailure",message:o&&(o.message||String(o))||"unknown",params:{radius:this.radius,arcSegments:this.arcSegments,sampleCount:this.sampleCount,sideMode:this.sideMode,inflate:this.inflate,sideStripSubdiv:this.sideStripSubdiv,seamInsetScale:this.seamInsetScale,projectStripsOpenEdges:this.projectStripsOpenEdges,forceSeamInset:this.forceSeamInset},edge:{name:this.edgeToFillet?.name||null,closedLoop:!!(this.edgeToFillet?.closedLoop||this.edgeToFillet?.userData?.closedLoop),faces:n},counts:{vertices:I,triangles:s,faceLabels:this._faceNameToID&&typeof this._faceNameToID.size=="number"?this._faceNameToID.size:void 0}};try{console.error(JSON.stringify(B))}catch{console.error("[FilletSolidManifoldFailure]",B.message)}}}catch{}throw e(!1),o}finally{try{g&&typeof g.delete=="function"&&g.delete()}catch{}}return this._dirty=!1,this._faceIndex=null,e(!0),this._manifold}finally{const t=!!(this&&this._manifold)&&this._dirty===!1;e(t)}}c(Mct,"CHt");r(Mct,"_manifoldize");function yct(i=0){return this._epsilon=Number(i)||0,this._epsilon>0&&this._weldVerticesByEpsilon(this._epsilon),this}c(yct,"aHt");r(yct,"setEpsilon");function pct(i,A={}){mn(YB&&ZRe,"Solid._weldVerticesByEpsilon()");const e=A?.rebuildManifold!==!1;this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),this._cppSolidCore.weldVerticesByEpsilon(i),yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,e&&this._manifoldize(),this}c(pct,"QHt");r(pct,"_weldVerticesByEpsilon");function fct(){if(mn(YB&&Y5A,"Solid.fixTriangleWindingsByAdjacency()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),!this._cppSolidCore.fixTriangleWindingsByAdjacency())return this;yQ(this,this._cppSolidCore),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,this}c(fct,"EHt");r(fct,"fixTriangleWindingsByAdjacency");function Fct(){return mn(YB&&Y5A,"Solid._isCoherentlyOrientedManifold()"),this._cppSolidCore=this._cppSolidCore||new Ua,jU(this,this._cppSolidCore),this._cppSolidCore.isCoherentlyOrientedManifold()}c(Fct,"cHt");r(Fct,"_isCoherentlyOrientedManifold");function mct({maxTriangles:i=30,removeInternal:A=!0,removeExternal:e=!0}={}){mn(YB&&ZEt,"Solid.removeSmallIslands()");const t=Ya(this),g=t.removeSmallIslands(i,A,e);if(g>0){yQ(this,t),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return g}c(mct,"lHt");r(mct,"removeSmallIslands");function Nct({normalDotThreshold:i=-.95}={}){const A=this._triVerts,e=this._vertProperties,t=this._triIDs;if(!A||!e||!t)return 0;const g=A.length/3|0;if(g===0||t.length!==g)return 0;const o=e.length/3|0;if(o===0)return 0;const s=BigInt(Math.max(1,o)),I=r((F,m)=>{const G=BigInt(F),N=BigInt(m);return G<N?G*s+N:N*s+G},"eKey"),n=new Map,B=r((F,m,G,N)=>{let S=n.get(F);S||(S=[0,0,0],n.set(F,S)),S[0]+=m,S[1]+=G,S[2]+=N},"addNormal"),C=new Map;for(let F=0;F<g;F++){const m=t[F];if(m==null)continue;const G=F*3,N=A[G+0]>>>0,S=A[G+1]>>>0,Y=A[G+2]>>>0,R=e[N*3+0],k=e[N*3+1],b=e[N*3+2],L=e[S*3+0],x=e[S*3+1],J=e[S*3+2],$=e[Y*3+0],T=e[Y*3+1],H=e[Y*3+2],X=L-R,oA=x-k,_=J-b,V=$-R,O=T-k,AA=H-b,BA=oA*AA-_*O,rA=_*V-X*AA,tA=X*O-oA*V;B(m,BA,rA,tA);const sA=[[N,S],[S,Y],[Y,N]];for(let eA=0;eA<3;eA++){let K=sA[eA][0],v=sA[eA][1];if(K===v)continue;const iA=I(K,v);let QA=C.get(iA);if(!QA){if(K>v){const gA=K;K=v,v=gA}QA={faces:new Set,a:K,b:v},C.set(iA,QA)}QA.faces.add(m)}}const a=new Map,Q=new Map,E=r((F,m)=>{let G=Q.get(F);G||(G=new Set,Q.set(F,G)),G.add(m)},"addPair");for(const F of C.values()){if(F.faces.size!==2)continue;const m=Array.from(F.faces),G=m[0],N=m[1];if(G===N)continue;const S=G<N?`${G}|${N}`:`${N}|${G}`;let Y=a.get(S);Y||(Y={ids:G<N?[G,N]:[N,G],edges:[]},a.set(S,Y)),Y.edges.push([F.a,F.b]),E(G,S),E(N,S)}const l=r(F=>{if(!F||F.length===0)return!1;const m=new Map,G=new Set;for(const[Y,R]of F)G.add(Y),G.add(R),m.has(Y)||m.set(Y,new Set),m.has(R)||m.set(R,new Set),m.get(Y).add(R),m.get(R).add(Y);let N=0;const S=new Set;for(const Y of G){if(S.has(Y))continue;if(N++,N>1)return!1;const R=[Y];for(S.add(Y);R.length;){const k=R.pop(),b=m.get(k);if(b)for(const L of b)S.has(L)||(S.add(L),R.push(L))}}return N===1},"isSingleEdgeChain"),h=new Set;for(const[F,m]of Q.entries()){if(m.size!==1)continue;const G=m.values().next().value,N=a.get(G);if(!N||!N.edges.length||!l(N.edges))continue;const S=N.ids[0]===F?N.ids[1]:N.ids[0],Y=n.get(F),R=n.get(S);if(!Y||!R)continue;const k=Math.hypot(Y[0],Y[1],Y[2]),b=Math.hypot(R[0],R[1],R[2]);!(k>1e-12)||!(b>1e-12)||(Y[0]*R[0]+Y[1]*R[1]+Y[2]*R[2])/(k*b)<=i&&h.add(F)}if(!h.size)return 0;const w=new Uint8Array(g);let d=0;for(let F=0;F<g;F++){if(h.has(t[F])){d++;continue}w[F]=1}if(d===0)return 0;const D=new Uint8Array(o),u=[],M=[];for(let F=0;F<g;F++){if(!w[F])continue;const m=F*3,G=A[m+0]>>>0,N=A[m+1]>>>0,S=A[m+2]>>>0;u.push(G,N,S),M.push(t[F]),D[G]=1,D[N]=1,D[S]=1}const y=new Int32Array(o);for(let F=0;F<o;F++)y[F]=-1;const p=[];let f=0;for(let F=0;F<o;F++)D[F]&&(y[F]=f++,p.push(e[F*3+0],e[F*3+1],e[F*3+2]));for(let F=0;F<u.length;F++)u[F]=y[u[F]];this._vertProperties=p,this._triVerts=u,this._triIDs=M,this._vertKeyToIndex=new Map;for(let F=0;F<this._vertProperties.length;F+=3){const m=this._vertProperties[F],G=this._vertProperties[F+1],N=this._vertProperties[F+2];this._vertKeyToIndex.set(`${m},${G},${N}`,F/3|0)}return this._dirty=!0,this._faceIndex=null,this._manifold=null,d}c(Nct,"hHt");r(Nct,"removeOppositeSingleEdgeFaces");function Sct(i,A=1){const e=Number(i);if(!Number.isFinite(e)||e<=0)return 0;const t=this._vertProperties;if(!t||t.length<9||this._triVerts.length<3)return 0;const g=r((I,n,B)=>{const C=t[I*3+0],a=t[I*3+1],Q=t[I*3+2],E=t[n*3+0],l=t[n*3+1],h=t[n*3+2],w=t[B*3+0],d=t[B*3+1],D=t[B*3+2],u=E-C,M=l-a,y=h-Q,p=w-C,f=d-a,F=D-Q,m=M*F-y*f,G=y*p-u*F,N=u*f-M*p;return .5*Math.hypot(m,G,N)},"triArea");let o=0;const s=Math.max(1,A|0);for(let I=0;I<s;I++){const n=this._triVerts,B=this._triIDs,C=n.length/3|0;if(C<2)break;const a=new Array(C),Q=new Float64Array(C);for(let p=0;p<C;p++){const f=p*3,F=n[f+0]>>>0,m=n[f+1]>>>0,G=n[f+2]>>>0;a[p]=[F,m,G],Q[p]=g(F,m,G)}const E=t.length/3|0,l=BigInt(E),h=r((p,f)=>{const F=BigInt(p),m=BigInt(f);return F<m?F*l+m:m*l+F},"eKey"),w=new Map;for(let p=0;p<C;p++){const[f,F,m]=a[p],G=B[p],N=[[f,F],[F,m],[m,f]];for(let S=0;S<3;S++){const Y=N[S][0],R=N[S][1],k=h(Y,R);let b=w.get(k);b||(b=[],w.set(k,b)),b.push({tri:p,id:G,a:Y,b:R})}}const d=[];for(const[p,f]of w.entries()){if(f.length!==2)continue;const F=f[0],m=f[1];if(F.id===m.id)continue;const G=Q[F.tri],N=Q[m.tri],S=Math.min(G,N);S<e&&d.push({key:p,a:F,b:m,minAB:S})}d.sort((p,f)=>p.minAB-f.minAB);const D=new Uint8Array(C);let u=0;const M=r((p,f,F)=>{const m=h(p,f),G=w.get(m);if(G){for(let N=0;N<G.length;N++){const S=G[N];if(S.tri===F&&S.a===p&&S.b===f){G.splice(N,1);break}}G.length===0&&w.delete(m)}},"removeUse"),y=r((p,f,F,m)=>{const G=h(p,f);let N=w.get(G);N||(N=[],w.set(G,N)),N.push({tri:F,id:m,a:p,b:f})},"addUse");for(const{a:p,b:f}of d){const F=p.tri,m=f.tri;if(D[F]||D[m])continue;const G=p.a,N=p.b;if(!(f.a===N&&f.b===G))continue;const S=a[F],Y=a[m];let R=-1,k=-1;for(let X=0;X<3;X++){const oA=S[X];if(oA!==G&&oA!==N){R=oA;break}}for(let X=0;X<3;X++){const oA=Y[X];if(oA!==G&&oA!==N){k=oA;break}}if(R<0||k<0||R===k)continue;const b=h(R,k),L=w.get(b);if(L&&L.length)continue;const x=Q[F],J=Q[m],$=Math.min(x,J);if($>=e)continue;const T=g(R,k,G),H=g(k,R,N);!(Number.isFinite(T)&&Number.isFinite(H))||T<=0||H<=0||Math.min(T,H)<$||(a[F]=[R,k,G],a[m]=[k,R,N],Q[F]=T,Q[m]=H,M(G,N,F),M(N,G,m),M(N,G,F),M(G,N,m),y(R,k,F,B[F]),y(k,R,F,B[F]),y(k,R,m,B[m]),y(R,k,m,B[m]),D[F]=1,D[m]=1,u++)}if(!u)break;o+=u;for(let p=0;p<C;p++){const f=a[p],F=p*3;n[F+0]=f[0],n[F+1]=f[1],n[F+2]=f[2]}this._dirty=!0,this._faceIndex=null}return o>0&&this.fixTriangleWindingsByAdjacency(),o}c(Sct,"dHt");r(Sct,"removeTinyBoundaryTriangles");function Gct({maxEdgeLength:i,maxIterations:A=10}={}){const e=Number(i);if(!Number.isFinite(e)||e<=0)return this;const t=e*e,g=r(()=>{const s=this._vertProperties,I=this._triVerts,n=this._triIDs,B=I.length/3|0,C=s.length/3|0,a=BigInt(Math.max(1,C)),Q=r((y,p)=>{const f=BigInt(y),F=BigInt(p);return f<F?f*a+F:F*a+f},"ukey"),E=r((y,p)=>{const f=s[y*3+0],F=s[y*3+1],m=s[y*3+2],G=s[p*3+0],N=s[p*3+1],S=s[p*3+2],Y=f-G,R=F-N,k=m-S;return Y*Y+R*R+k*k},"len2"),l=new Set;for(let y=0;y<B;y++){const p=y*3,f=I[p+0]>>>0,F=I[p+1]>>>0,m=I[p+2]>>>0;E(f,F)>t&&l.add(Q(f,F)),E(F,m)>t&&l.add(Q(F,m)),E(m,f)>t&&l.add(Q(m,f))}if(l.size===0)return!1;const h=s.slice(),w=new Map,d=r((y,p)=>{const f=Q(y,p);let F=w.get(f);if(F!==void 0)return F;const m=s[y*3+0],G=s[y*3+1],N=s[y*3+2],S=s[p*3+0],Y=s[p*3+1],R=s[p*3+2],k=.5*(m+S),b=.5*(G+Y),L=.5*(N+R);return F=h.length/3|0,h.push(k,b,L),w.set(f,F),F},"midpointIndex"),D=[],u=[],M=r((y,p,f,F)=>{D.push(y,p,f),u.push(F)},"emit");for(let y=0;y<B;y++){const p=y*3,f=I[p+0]>>>0,F=I[p+1]>>>0,m=I[p+2]>>>0,G=n[y],N=Q(f,F),S=Q(F,m),Y=Q(m,f),R=l.has(N),k=l.has(S),b=l.has(Y),L=(R?1:0)+(k?1:0)+(b?1:0);if(L===0){M(f,F,m,G);continue}if(L===1){if(R){const T=d(f,F);M(f,T,m,G),M(T,F,m,G)}else if(k){const T=d(F,m);M(F,T,f,G),M(T,m,f,G)}else{const T=d(m,f);M(m,T,F,G),M(T,f,F,G)}continue}if(L===2){if(R&&k){const T=d(f,F),H=d(F,m);M(f,T,m,G),M(F,H,T,G),M(T,H,m,G)}else if(k&&b){const T=d(F,m),H=d(m,f);M(F,T,f,G),M(m,H,T,G),M(T,H,f,G)}else{const T=d(m,f),H=d(f,F);M(m,T,F,G),M(f,H,T,G),M(T,H,F,G)}continue}const x=d(f,F),J=d(F,m),$=d(m,f);M(f,x,$,G),M(F,J,x,G),M(m,$,J,G),M(x,J,$,G)}this._vertProperties=h,this._triVerts=D,this._triIDs=u,this._vertKeyToIndex=new Map;for(let y=0;y<this._vertProperties.length;y+=3){const p=this._vertProperties[y],f=this._vertProperties[y+1],F=this._vertProperties[y+2];this._vertKeyToIndex.set(`${p},${f},${F}`,y/3|0)}return this._dirty=!0,this._faceIndex=null,!0},"pass");let o=!1;for(let s=0;s<A&&g();s++)o=!0;return o&&this.fixTriangleWindingsByAdjacency(),this}c(Gct,"wHt");r(Gct,"remesh");function Rct(i){const A=Number(i);if(!Number.isFinite(A)||A<=0)return 0;const e=this._vertProperties,t=this._triVerts,g=t.length/3|0,o=e.length/3|0;if(g===0||o===0)return 0;const s=A*A,I=new Int32Array(o);for(let _=0;_<o;_++)I[_]=_;const n=r(_=>{for(;I[_]!==_;)I[_]=I[I[_]],_=I[_];return _},"find"),B=r((_,V)=>{let O=n(_),AA=n(V);if(O===AA)return!1;if(AA<O){const BA=O;O=AA,AA=BA}return I[AA]=O,!0},"unite"),C=r((_,V)=>{const O=e[_*3+0],AA=e[_*3+1],BA=e[_*3+2],rA=e[V*3+0],tA=e[V*3+1],sA=e[V*3+2],eA=O-rA,K=AA-tA,v=BA-sA;return eA*eA+K*K+v*v},"len2");let a=0;for(let _=0;_<g;_++){const V=_*3,O=t[V+0]>>>0,AA=t[V+1]>>>0,BA=t[V+2]>>>0,rA=C(O,AA),tA=C(AA,BA),sA=C(BA,O);let eA=rA,K=O,v=AA;tA<eA&&(eA=tA,K=AA,v=BA),sA<eA&&(eA=sA,K=BA,v=O),eA<s&&B(K,v)&&a++}if(a===0)return 0;for(let _=0;_<o;_++){const V=n(_);V!==_&&(e[_*3+0]=e[V*3+0],e[_*3+1]=e[V*3+1],e[_*3+2]=e[V*3+2])}this._vertKeyToIndex=new Map;for(let _=0;_<o;_++){const V=e[_*3+0],O=e[_*3+1],AA=e[_*3+2];this._vertKeyToIndex.set(`${V},${O},${AA}`,_)}this._dirty=!0,this._faceIndex=null;let Q=1/0,E=1/0,l=1/0,h=-1/0,w=-1/0,d=-1/0;for(let _=0;_<o;_++){const V=e[_*3+0],O=e[_*3+1],AA=e[_*3+2];V<Q&&(Q=V),V>h&&(h=V),O<E&&(E=O),O>w&&(w=O),AA<l&&(l=AA),AA>d&&(d=AA)}if(!Number.isFinite(Q)||!Number.isFinite(h))return a;const D=Math.max(1e-9,h-Q),u=Math.max(1e-9,w-E),M=Math.max(1e-9,d-l),y=Math.max(D,u,M,A),p=Math.max(A*10,y*.1+1e-6),f=D+2*p,F=u+2*p,m=M+2*p,G=Q-p,N=E-p,S=l-p,Y=this.constructor,R=new Y,k=[G,N,S],b=[G+f,N,S],L=[G,N+F,S],x=[G+f,N+F,S],J=[G,N,S+m],$=[G+f,N,S+m],T=[G,N+F,S+m],H=[G+f,N+F,S+m];R.addTriangle("__BIGBOX_NX",k,J,T),R.addTriangle("__BIGBOX_NX",k,T,L),R.addTriangle("__BIGBOX_PX",b,x,H),R.addTriangle("__BIGBOX_PX",b,H,$),R.addTriangle("__BIGBOX_NY",k,b,$),R.addTriangle("__BIGBOX_NY",k,$,J),R.addTriangle("__BIGBOX_PY",L,T,H),R.addTriangle("__BIGBOX_PY",L,H,x),R.addTriangle("__BIGBOX_NZ",k,L,x),R.addTriangle("__BIGBOX_NZ",k,x,b),R.addTriangle("__BIGBOX_PZ",J,$,H),R.addTriangle("__BIGBOX_PZ",J,H,T);const X=this.intersect(R),oA=X.getMesh();try{this._numProp=oA.numProp||3,this._vertProperties=Array.from(oA.vertProperties||[]),this._triVerts=Array.from(oA.triVerts||[]);const _=this._triVerts.length/3|0;if(oA.faceID&&oA.faceID.length===_)this._triIDs=Array.from(oA.faceID);else{const V=this.constructor;this._triIDs=V._expandTriIDsFromMesh(oA)}this._vertKeyToIndex=new Map;for(let V=0;V<this._vertProperties.length;V+=3){const O=this._vertProperties[V],AA=this._vertProperties[V+1],BA=this._vertProperties[V+2];this._vertKeyToIndex.set(`${O},${AA},${BA}`,V/3|0)}try{this._idToFaceName=new Map(X._idToFaceName)}catch{throw new Error("Failed to adopt face label mapping from boolean result")}try{this._faceNameToID=new Map([...this._idToFaceName.entries()].map(([V,O])=>[O,V]))}catch{}this._dirty=!1,this._faceIndex=null,this._manifold=null}finally{try{oA&&typeof oA.delete=="function"&&oA.delete()}catch{}}return a}c(Rct,"uHt");r(Rct,"collapseTinyTriangles");function Yct(i=!1){const A=i&&typeof i=="object"?i:{},e=i===!0||A.diagnostics===!0,t=A.detectOnly===!0||A.probeOnly===!0,g=Math.max(0,Number(A.maxIntersections)||0),o=Array.from(this._vertProperties||[]),s=Array.from(this._triVerts||[]),I=Array.from(this._triIDs||[]),n=s.length/3|0;if(n<2||o.length<9)return 0;const B={add(z,aA){return[z[0]+aA[0],z[1]+aA[1],z[2]+aA[2]]},sub(z,aA){return[z[0]-aA[0],z[1]-aA[1],z[2]-aA[2]]},mul(z,aA){return[z[0]*aA,z[1]*aA,z[2]*aA]},dot(z,aA){return z[0]*aA[0]+z[1]*aA[1]+z[2]*aA[2]},cross(z,aA){return[z[1]*aA[2]-z[2]*aA[1],z[2]*aA[0]-z[0]*aA[2],z[0]*aA[1]-z[1]*aA[0]]},len(z){return Math.hypot(z[0],z[1],z[2])},dist(z,aA){return Math.hypot(z[0]-aA[0],z[1]-aA[1],z[2]-aA[2])},norm(z){const aA=Math.hypot(z[0],z[1],z[2]);return aA>0?[z[0]/aA,z[1]/aA,z[2]/aA]:[0,0,0]}},C={sub(z,aA){return[z[0]-aA[0],z[1]-aA[1]]},cross(z,aA){return z[0]*aA[1]-z[1]*aA[0]},dot(z,aA){return z[0]*aA[0]+z[1]*aA[1]},dist(z,aA){return Math.hypot(z[0]-aA[0],z[1]-aA[1])}};let a=1/0,Q=1/0,E=1/0,l=-1/0,h=-1/0,w=-1/0;for(let z=0;z<o.length;z+=3){const aA=o[z+0],hA=o[z+1],MA=o[z+2];aA<a&&(a=aA),aA>l&&(l=aA),hA<Q&&(Q=hA),hA>h&&(h=hA),MA<E&&(E=MA),MA>w&&(w=MA)}const d=Math.max(1,Math.hypot(l-a,h-Q,w-E)),D=Math.max(1e-9,Number(A.snapTolerance)||d*1e-9),u=Math.max(D*8,d*1e-10),M=Math.max(1e-18,d*d*1e-18),y=r(z=>[Math.round(z[0]/D),Math.round(z[1]/D),Math.round(z[2]/D)].join(","),"qPoint"),p=r(z=>[o[z*3+0],o[z*3+1],o[z*3+2]],"sourcePoint"),f=r((z,aA,hA)=>B.len(B.cross(B.sub(aA,z),B.sub(hA,z)))*.5,"triangleArea3"),F=r((z,aA,hA)=>{const MA=B.cross(B.sub(aA,z),B.sub(hA,z)),fA=B.len(MA);if(!(fA>1e-18))return null;const SA=B.mul(MA,1/fA);return{n:SA,d:-B.dot(SA,z)}},"planeOf"),m=r((z,aA)=>B.dot(z.n,aA)+z.d,"signedDistance"),G=r((z,aA,hA)=>{const MA=B.norm(B.cross(B.sub(aA,z),B.sub(hA,z)));if(B.len(MA)<=0)return null;let fA=B.sub(aA,z);if(B.len(fA)<=D&&(fA=B.sub(hA,z)),fA=B.norm(fA),B.len(fA)<=0)return null;const SA=B.norm(B.cross(MA,fA));if(B.len(SA)<=0)return null;const UA=z;return{origin:UA,u:fA,v:SA,n:MA,project(GA){const _A=B.sub(GA,UA);return[B.dot(_A,fA),B.dot(_A,SA)]},unproject(GA){return B.add(UA,B.add(B.mul(fA,GA[0]),B.mul(SA,GA[1])))}}},"makeBasis"),N=r((z,aA,hA,MA,fA=1e-12)=>{const SA=C.sub(hA,aA),UA=C.sub(MA,hA),GA=C.sub(aA,MA),_A=C.sub(z,aA),YA=C.sub(z,hA),KA=C.sub(z,MA),OA=C.cross(SA,_A),te=C.cross(UA,YA),XA=C.cross(GA,KA);return OA>=-fA&&te>=-fA&&XA>=-fA||OA<=fA&&te<=fA&&XA<=fA},"pointInTri2D"),S=r((z,aA,hA,MA,fA=1e-12)=>{const SA=C.sub(aA,z),UA=C.sub(MA,hA),GA=C.cross(SA,UA),_A=C.sub(hA,z),YA=[];if(Math.abs(GA)>fA){const Oe=C.cross(_A,UA)/GA,ve=C.cross(_A,SA)/GA;return Oe>=-fA&&Oe<=1+fA&&ve>=-fA&&ve<=1+fA&&YA.push([z[0]+SA[0]*Oe,z[1]+SA[1]*Oe]),YA}if(Math.abs(C.cross(_A,SA))>fA)return YA;const KA=Math.abs(SA[0])>=Math.abs(SA[1])?0:1,OA=z[KA],te=aA[KA],XA=hA[KA],Ge=MA[KA],zA=Math.min(OA,te),ae=Math.max(OA,te),de=Math.min(XA,Ge),we=Math.max(XA,Ge),Qe=Math.max(zA,de),oe=Math.min(ae,we);if(oe<Qe-fA)return YA;const ke=r(Oe=>{const ve=te-OA,gt=Math.abs(ve)>fA?(Oe-OA)/ve:0;return[z[0]+SA[0]*gt,z[1]+SA[1]*gt]},"pointAt");return YA.push(ke(Qe)),oe>Qe+fA&&YA.push(ke(oe)),YA},"segmentIntersection2D"),Y=r((z,aA,hA,MA=1e-10)=>{const fA=C.sub(hA,aA),SA=C.sub(z,aA),UA=C.dot(fA,fA);if(!(UA>MA*MA)||Math.abs(C.cross(fA,SA))>MA*Math.sqrt(UA))return!1;const GA=C.dot(SA,fA)/UA;return GA>=-MA&&GA<=1+MA},"pointOnSegment2D"),R=r((z,aA,hA,MA=D)=>{const fA=B.sub(hA,aA),SA=B.sub(z,aA),UA=B.len(fA);if(!(UA>MA))return B.dist(z,aA)<=MA;if(B.len(B.cross(fA,SA))>MA*UA)return!1;const GA=B.dot(SA,fA)/(UA*UA);return GA>=-MA&&GA<=1+MA},"pointOnSegment3D"),k=r(z=>{const aA=[],hA=new Set,MA=r(GA=>`${Math.round(GA[0]/D)},${Math.round(GA[1]/D)}`,"q2");for(const GA of z){const _A=MA(GA);hA.has(_A)||(hA.add(_A),aA.push(GA))}if(aA.sort((GA,_A)=>GA[0]-_A[0]||GA[1]-_A[1]),aA.length<=2)return aA;const fA=r((GA,_A,YA)=>C.cross(C.sub(_A,GA),C.sub(YA,GA)),"cross"),SA=[];for(const GA of aA){for(;SA.length>=2&&fA(SA[SA.length-2],SA[SA.length-1],GA)<=D;)SA.pop();SA.push(GA)}const UA=[];for(let GA=aA.length-1;GA>=0;GA--){const _A=aA[GA];for(;UA.length>=2&&fA(UA[UA.length-2],UA[UA.length-1],_A)<=D;)UA.pop();UA.push(_A)}return SA.pop(),UA.pop(),SA.concat(UA)},"convexHull2D"),b=r((z,aA=hA=>hA)=>{let hA=0;for(let MA=0;MA<z.length;MA++){const fA=aA(z[MA]),SA=aA(z[(MA+1)%z.length]);hA+=fA[0]*SA[1]-SA[0]*fA[1]}return hA*.5},"polygonArea2D"),L=r((z,aA)=>{const hA=[],MA=r(GA=>{for(const _A of hA)if(B.dist(GA,_A)<=D)return;hA.push(GA)},"add"),fA=z.map(GA=>m(aA,GA));for(let GA=0;GA<3;GA++){const _A=(GA+1)%3,YA=z[GA],KA=z[_A],OA=fA[GA],te=fA[_A];if(Math.abs(OA)<=u&&MA(YA),Math.abs(OA)<=u&&Math.abs(te)<=u){MA(KA);continue}if(OA<-u&&te>u||OA>u&&te<-u){const XA=OA/(OA-te);MA([YA[0]+(KA[0]-YA[0])*XA,YA[1]+(KA[1]-YA[1])*XA,YA[2]+(KA[2]-YA[2])*XA])}}if(hA.length<=2)return hA;let SA=[hA[0],hA[1]],UA=-1/0;for(let GA=0;GA<hA.length;GA++)for(let _A=GA+1;_A<hA.length;_A++){const YA=B.dist(hA[GA],hA[_A]);YA>UA&&(SA=[hA[GA],hA[_A]],UA=YA)}return SA},"trianglePlaneSegment"),x=r((z,aA,hA)=>{const MA=z.map(_A=>hA.project(_A)),fA=aA.map(_A=>hA.project(_A)),SA=[],UA=r(_A=>{for(const YA of SA)if(C.dist(_A,YA)<=D)return;SA.push(_A)},"add2");for(const _A of MA)N(_A,fA[0],fA[1],fA[2],D)&&UA(_A);for(const _A of fA)N(_A,MA[0],MA[1],MA[2],D)&&UA(_A);for(let _A=0;_A<3;_A++){const YA=MA[_A],KA=MA[(_A+1)%3];for(let OA=0;OA<3;OA++){const te=fA[OA],XA=fA[(OA+1)%3];for(const Ge of S(YA,KA,te,XA,D))UA(Ge)}}if(SA.length<2)return null;const GA=k(SA);if(GA.length>=3&&Math.abs(b(GA))>M){const _A=[];for(let YA=0;YA<GA.length;YA++)_A.push([hA.unproject(GA[YA]),hA.unproject(GA[(YA+1)%GA.length])]);return{type:"segments",segments:_A}}return GA.length>=2&&C.dist(GA[0],GA[GA.length-1])>D?{type:"segments",segments:[[hA.unproject(GA[0]),hA.unproject(GA[GA.length-1])]]}:null},"coplanarTriangleOverlap"),J=r((z,aA)=>{const hA=F(z[0],z[1],z[2]),MA=F(aA[0],aA[1],aA[2]);if(!hA||!MA)return null;const fA=aA.map(oe=>m(hA,oe)),SA=z.map(oe=>m(MA,oe)),UA=r(oe=>oe.every(ke=>ke>u),"allPositive"),GA=r(oe=>oe.every(ke=>ke<-u),"allNegative");if(UA(fA)||GA(fA)||UA(SA)||GA(SA))return null;const _A=B.cross(hA.n,MA.n),YA=B.len(_A);if(YA<=1e-8&&fA.every(oe=>Math.abs(oe)<=u)&&SA.every(oe=>Math.abs(oe)<=u)){const oe=G(z[0],z[1],z[2]);return oe?x(z,aA,oe):null}if(!(YA>1e-14))return null;const KA=L(z,MA),OA=L(aA,hA);if(KA.length<2||OA.length<2){if(KA.length===1&&OA.length===2&&R(KA[0],OA[0],OA[1]))return{type:"point",point:KA[0]};if(OA.length===1&&KA.length===2&&R(OA[0],KA[0],KA[1]))return{type:"point",point:OA[0]};const oe=KA.concat(OA),ke=[];for(const Oe of oe)ke.some(ve=>B.dist(ve,Oe)<=D)||ke.push(Oe);return ke.length===1?{type:"point",point:ke[0]}:null}const te=B.mul(_A,1/YA),XA=KA[0],Ge=KA.map(oe=>B.dot(B.sub(oe,XA),te)).sort((oe,ke)=>oe-ke),zA=OA.map(oe=>B.dot(B.sub(oe,XA),te)).sort((oe,ke)=>oe-ke),ae=Math.max(Ge[0],zA[0]),de=Math.min(Ge[1],zA[1]);if(de<ae-D)return null;const we=B.add(XA,B.mul(te,ae)),Qe=B.add(XA,B.mul(te,de));return B.dist(we,Qe)>D?{type:"segments",segments:[[we,Qe]]}:{type:"point",point:we}},"triangleIntersection"),$=new Array(n);for(let z=0;z<n;z++){const aA=z*3,hA=s[aA+0]>>>0,MA=s[aA+1]>>>0,fA=s[aA+2]>>>0,SA=[p(hA),p(MA),p(fA)],UA=[Math.min(SA[0][0],SA[1][0],SA[2][0]),Math.min(SA[0][1],SA[1][1],SA[2][1]),Math.min(SA[0][2],SA[1][2],SA[2][2])],GA=[Math.max(SA[0][0],SA[1][0],SA[2][0]),Math.max(SA[0][1],SA[1][1],SA[2][1]),Math.max(SA[0][2],SA[1][2],SA[2][2])];$[z]={indices:[hA,MA,fA],id:I[z]??0,points:SA,min:UA,max:GA,segments:[],pointsOnly:[],segmentKeys:new Set,pointKeys:new Set}}const T=r((z,aA)=>{const hA=y(aA);z.pointKeys.has(hA)||(z.pointKeys.add(hA),z.pointsOnly.push(aA))},"addPointOnly"),H=r((z,aA,hA)=>{if(B.dist(aA,hA)<=D){T(z,aA);return}const MA=y(aA),fA=y(hA),SA=MA<fA?`${MA}|${fA}`:`${fA}|${MA}`;z.segmentKeys.has(SA)||(z.segmentKeys.add(SA),z.segments.push([aA,hA]))},"addSegment"),X=r((z,aA)=>{const hA=[],MA=r(fA=>{hA.some(SA=>B.dist(SA,fA)<=D)||hA.push(fA)},"add");for(const fA of z.points)for(const SA of aA.points)B.dist(fA,SA)<=D&&MA(fA);return hA},"sharedCoordinatePoints"),oA=r((z,aA,hA,MA)=>{const fA=X(z,aA);if(fA.length!==2)return!1;const SA=B.dist(hA,fA[0])<=D&&B.dist(MA,fA[1])<=D,UA=B.dist(hA,fA[1])<=D&&B.dist(MA,fA[0])<=D;return SA||UA},"isOnlySharedEdge"),_=r((z,aA,hA)=>{const MA=X(z,aA);return MA.length>0&&MA.some(fA=>B.dist(fA,hA)<=D)},"isOnlySharedPoint"),V=r((z,aA)=>!(z.max[0]<aA.min[0]-u||aA.max[0]<z.min[0]-u||z.max[1]<aA.min[1]-u||aA.max[1]<z.min[1]-u||z.max[2]<aA.min[2]-u||aA.max[2]<z.min[2]-u),"overlapAABB"),O=Array.from({length:n},(z,aA)=>aA).sort((z,aA)=>$[z].min[0]-$[aA].min[0]);let AA=0,BA=0,rA=0;for(let z=0;z<O.length;z++){const aA=O[z],hA=$[aA];if(!(f(hA.points[0],hA.points[1],hA.points[2])<=M))for(let MA=z+1;MA<O.length;MA++){const fA=O[MA],SA=$[fA];if(SA.min[0]>hA.max[0]+u)break;if(!V(hA,SA)||f(SA.points[0],SA.points[1],SA.points[2])<=M)continue;rA++;const UA=J(hA.points,SA.points);if(!UA)continue;const GA=X(hA,SA);if(GA.length>0){const YA=r(KA=>GA.some(OA=>B.dist(KA,OA)<=D),"touchesCommonPoint");if(UA.type==="point"&&YA(UA.point))continue;if(UA.type==="segments"){const KA=UA.segments||[];if(KA.length&&KA.every(([OA,te])=>YA(OA)||YA(te)))continue}}if(UA.type==="point"){if(_(hA,SA,UA.point))continue;if(T(hA,UA.point),T(SA,UA.point),BA++,t&&g>0&&AA+BA>=g)return AA+BA;continue}let _A=!1;for(const[YA,KA]of UA.segments||[])oA(hA,SA,YA,KA)||(H(hA,YA,KA),H(SA,YA,KA),_A=!0);if(_A&&(AA++,t&&g>0&&AA+BA>=g))return AA+BA}}const tA=AA+BA;if(tA===0)return e&&console.log("[splitSelfIntersectingTriangles] no splittable intersections",{triCount:n,testedPairs:rA}),0;const sA=new Set,eA=[],K=r(z=>{const aA=y(z);sA.has(aA)||(sA.add(aA),eA.push(z))},"addEdgeSplitPoint");for(const z of $){for(const[aA,hA]of z.segments)K(aA),K(hA);for(const aA of z.pointsOnly)K(aA)}if(eA.length&&eA.length<=1024)for(const z of $)for(const aA of eA){if(z.points.some(MA=>B.dist(MA,aA)<=D))continue;let hA=!1;for(let MA=0;MA<3;MA++){const fA=z.points[MA],SA=z.points[(MA+1)%3];if(R(aA,fA,SA,D)){hA=!0;break}}hA&&T(z,aA)}this._vertProperties=o.slice(),this._vertKeyToIndex=new Map;const v=new Map;for(let z=0;z<this._vertProperties.length;z+=3){const aA=z/3|0,hA=[this._vertProperties[z+0],this._vertProperties[z+1],this._vertProperties[z+2]];this._vertKeyToIndex.set(`${hA[0]},${hA[1]},${hA[2]}`,aA),v.has(y(hA))||v.set(y(hA),aA)}const iA=r(z=>{const aA=y(z),hA=v.get(aA);if(hA!==void 0)return hA;const MA=this._vertProperties.length/3|0;return this._vertProperties.push(z[0],z[1],z[2]),v.set(aA,MA),this._vertKeyToIndex.set(`${z[0]},${z[1]},${z[2]}`,MA),MA},"getOrCreateVertex"),QA=r(z=>{const aA=G(z.points[0],z.points[1],z.points[2]);if(!aA)return null;const hA=[],MA=new Map,fA=new Map,SA=[],UA=Math.max(C.dist(aA.project(z.points[0]),aA.project(z.points[1])),C.dist(aA.project(z.points[1]),aA.project(z.points[2])),C.dist(aA.project(z.points[2]),aA.project(z.points[0])),1),GA=Math.max(D,UA*1e-10),_A=Math.max(1e-18,UA*UA*1e-16),YA=r(XA=>`${Math.round(XA[0]/GA)},${Math.round(XA[1]/GA)}`,"localKey"),KA=r(XA=>{const Ge=iA(XA),zA=MA.get(Ge);if(zA!==void 0)return zA;const ae=aA.project(XA),de=YA(ae),we=fA.get(de);if(we!==void 0)return MA.set(Ge,we),we;const Qe=hA.length;return hA.push({global:Ge,p3:XA,p2:ae}),MA.set(Ge,Qe),fA.set(de,Qe),Qe},"addLocalPoint"),OA=r((XA,Ge)=>{const zA=KA(XA),ae=KA(Ge);zA!==ae&&SA.push([zA,ae])},"addLocalSegment"),te=z.points.map(KA);OA(z.points[0],z.points[1]),OA(z.points[1],z.points[2]),OA(z.points[2],z.points[0]);for(const[XA,Ge]of z.segments)OA(XA,Ge);for(const XA of z.pointsOnly){const Ge=KA(XA);for(const zA of te)Ge!==zA&&SA.push([Ge,zA])}return{basis:aA,localPoints:hA,localSegments:SA,original:te,eps2:GA,area2:_A}},"makeLocalRetriangulator"),gA=r((z,aA,hA,MA,fA)=>{const SA=C.sub(aA,z),UA=C.sub(hA,z),GA=C.sub(MA,z),_A=C.sub(MA,hA),YA=C.sub(z,hA),KA=C.sub(aA,hA),OA=C.cross(SA,UA),te=C.cross(SA,GA),XA=C.cross(_A,YA),Ge=C.cross(_A,KA);return OA*te<-fA*fA&&XA*Ge<-fA*fA},"segmentProperlyCrosses"),IA=r(z=>{if(!z.segments.length&&!z.pointsOnly.length)return[[z.indices[0],z.indices[1],z.indices[2]]];const aA=QA(z);if(!aA)return[[z.indices[0],z.indices[1],z.indices[2]]];const{localPoints:hA,localSegments:MA,original:fA,eps2:SA,area2:UA}=aA,GA=B.norm(B.cross(B.sub(z.points[1],z.points[0]),B.sub(z.points[2],z.points[0]))),_A=r(()=>{const we=MA.length;for(let Qe=0;Qe<we;Qe++){const[oe,ke]=MA[Qe],Oe=hA[oe].p2,ve=hA[ke].p2;for(let gt=Qe+1;gt<we;gt++){const[$e,vt]=MA[gt],ng=hA[$e].p2,Rg=hA[vt].p2;for(const ug of S(Oe,ve,ng,Rg,SA)){const ki=aA.basis.unproject(ug);(()=>{const Bg=iA(ki),eo=hA.findIndex(cs=>cs.global===Bg);if(eo>=0)return eo;const fs=hA.length;return hA.push({global:Bg,p3:ki,p2:ug}),fs})()}}}},"addSegmentIntersections");r(()=>{const we=new Int32Array(hA.length);for(let gt=0;gt<we.length;gt++)we[gt]=gt;const Qe=r(gt=>{let $e=gt;for(;we[$e]!==$e;)$e=we[$e];for(;we[gt]!==gt;){const vt=we[gt];we[gt]=$e,gt=vt}return $e},"find"),oe=r((gt,$e)=>{const vt=Qe(gt),ng=Qe($e);vt!==ng&&(we[ng]=vt)},"unite");for(const[gt,$e]of MA)oe(gt,$e);const ke=Qe(fA[0]),Oe=new Map;for(let gt=0;gt<hA.length;gt++){const $e=Qe(gt);let vt=Oe.get($e);vt||(vt=[],Oe.set($e,vt)),vt.push(gt)}const ve=r(()=>MA.map(([gt,$e])=>[hA[gt].p2,hA[$e].p2]),"existingSegments");for(const[gt,$e]of Oe.entries()){if(gt===ke||$e.some(Rg=>fA.includes(Rg)))continue;let vt=null;const ng=ve();for(const Rg of $e){const ug=hA[Rg].p2;for(const ki of fA){const Bg=hA[ki].p2;let eo=!0;for(const[cs,Eo]of ng)if(!(C.dist(ug,cs)<=SA||C.dist(ug,Eo)<=SA||C.dist(Bg,cs)<=SA||C.dist(Bg,Eo)<=SA)&&gA(ug,Bg,cs,Eo,SA)){eo=!1;break}if(!eo)continue;const fs=C.dist(ug,Bg);(!vt||fs<vt.dist)&&(vt={member:Rg,target:ki,dist:fs})}}vt&&MA.push([vt.member,vt.target])}},"connectInteriorComponents")(),_A();const YA=new Set,KA=r((we,Qe)=>{if(we===Qe||C.dist(hA[we].p2,hA[Qe].p2)<=SA)return;const oe=we<Qe?`${we}|${Qe}`:`${Qe}|${we}`;YA.has(oe)||YA.add(oe)},"addEdge");for(const[we,Qe]of MA){const oe=hA[we].p2,ke=hA[Qe].p2,Oe=C.sub(ke,oe),ve=C.dot(Oe,Oe);if(!(ve>SA*SA))continue;const gt=[];for(let $e=0;$e<hA.length;$e++){const vt=hA[$e].p2;if(!Y(vt,oe,ke,SA))continue;const ng=C.dot(C.sub(vt,oe),Oe)/ve;gt.push({index:$e,t:ng})}gt.sort(($e,vt)=>$e.t-vt.t);for(let $e=0;$e+1<gt.length;$e++)KA(gt[$e].index,gt[$e+1].index)}const OA=new Map;for(const we of YA){const[Qe,oe]=we.split("|"),ke=Number(Qe),Oe=Number(oe);OA.has(ke)||OA.set(ke,new Set),OA.has(Oe)||OA.set(Oe,new Set),OA.get(ke).add(Oe),OA.get(Oe).add(ke)}for(const[we,Qe]of OA.entries()){const oe=hA[we].p2;OA.set(we,Array.from(Qe).sort((ke,Oe)=>{const ve=hA[ke].p2,gt=hA[Oe].p2;return Math.atan2(ve[1]-oe[1],ve[0]-oe[0])-Math.atan2(gt[1]-oe[1],gt[0]-oe[0])}))}const te=new Set,XA=r((we,Qe)=>`${we}>${Qe}`,"directedKey"),Ge=[];for(const we of YA){const[Qe,oe]=we.split("|");for(const ke of[[Number(Qe),Number(oe)],[Number(oe),Number(Qe)]]){let[Oe,ve]=ke;if(te.has(XA(Oe,ve)))continue;const gt=[],$e=Math.max(12,YA.size*4);let vt=0;for(;!te.has(XA(Oe,ve))&&vt++<$e;){te.add(XA(Oe,ve)),gt.push(Oe);const ng=OA.get(ve)||[],Rg=ng.indexOf(Oe);if(Rg<0||ng.length===0)break;const ug=ng[(Rg-1+ng.length)%ng.length];if(Oe=ve,ve=ug,Oe===ke[0]&&ve===ke[1])break}gt.length>=3&&b(gt,ng=>hA[ng].p2)>UA&&Ge.push(gt)}}const zA=r((we,Qe,oe,ke)=>{const Oe=Math.abs(C.cross(C.sub(oe,Qe),C.sub(ke,Qe)));if(!(Oe>UA))return!1;const ve=Math.abs(C.cross(C.sub(Qe,we),C.sub(oe,we))),gt=Math.abs(C.cross(C.sub(oe,we),C.sub(ke,we))),$e=Math.abs(C.cross(C.sub(ke,we),C.sub(Qe,we)));return Math.abs(ve+gt+$e-Oe)>Math.max(UA,Oe*1e-8)?!1:ve>UA&&gt>UA&&$e>UA},"pointStrictlyInTri2D"),ae=r(we=>{const Qe=[],oe=we.slice();b(oe,Oe=>hA[Oe].p2)<0&&oe.reverse();let ke=0;for(;oe.length>3&&ke++<we.length*we.length*4;){let Oe=!1;for(let ve=0;ve<oe.length;ve++){const gt=oe[(ve-1+oe.length)%oe.length],$e=oe[ve],vt=oe[(ve+1)%oe.length],ng=hA[gt].p2,Rg=hA[$e].p2,ug=hA[vt].p2;if(C.cross(C.sub(Rg,ng),C.sub(ug,Rg))<=UA)continue;let ki=!1;for(const Bg of oe)if(!(Bg===gt||Bg===$e||Bg===vt)&&zA(hA[Bg].p2,ng,Rg,ug)){ki=!0;break}if(!ki){Qe.push([gt,$e,vt]),oe.splice(ve,1),Oe=!0;break}}if(!Oe){for(let ve=1;ve+1<oe.length;ve++)Qe.push([oe[0],oe[ve],oe[ve+1]]);oe.length=0}}return oe.length===3&&Qe.push([oe[0],oe[1],oe[2]]),Qe},"triangulateLoop"),de=[];for(const we of Ge)for(const Qe of ae(we)){const oe=hA[Qe[0]],ke=hA[Qe[1]],Oe=hA[Qe[2]];if(f(oe.p3,ke.p3,Oe.p3)<=M)continue;const ve=B.cross(B.sub(ke.p3,oe.p3),B.sub(Oe.p3,oe.p3));B.dot(ve,GA)<0?de.push([oe.global,Oe.global,ke.global]):de.push([oe.global,ke.global,Oe.global])}return de.length?de:[[z.indices[0],z.indices[1],z.indices[2]]]},"retriangulateRecord"),lA=[],cA=[];let CA=0;for(let z=0;z<n;z++){const aA=$[z],hA=IA(aA);(aA.segments.length||aA.pointsOnly.length)&&CA++;for(const MA of hA)lA.push(MA[0],MA[1],MA[2]),cA.push(aA.id)}this._triVerts=lA,this._triIDs=cA,this._dirty=!0,this._faceIndex=null,this._manifold=null;try{this.removeDegenerateTriangles()}catch{}const EA=r(()=>{const z=this._triVerts||[],aA=this._vertProperties||[],hA=this._triIDs||[],MA=z.length/3|0,fA=new Set,SA=[],UA=[];let GA=0;for(let _A=0;_A<MA;_A++){const YA=_A*3,KA=[z[YA+0]>>>0,z[YA+1]>>>0,z[YA+2]>>>0],OA=KA.map(te=>y([aA[te*3+0],aA[te*3+1],aA[te*3+2]])).sort().join("|");if(fA.has(OA)){GA++;continue}fA.add(OA),SA.push(KA[0],KA[1],KA[2]),UA.push(hA[_A])}return GA?(this._triVerts=SA,this._triIDs=UA,this._dirty=!0,this._faceIndex=null,this._manifold=null,GA):0},"removeDuplicateTriangles")();return r(()=>{const z=this._triVerts||[],aA=this._vertProperties||[],hA=aA.length/3|0,MA=new Uint8Array(hA);for(const GA of z)MA[GA>>>0]=1;const fA=new Int32Array(hA);for(let GA=0;GA<hA;GA++)fA[GA]=-1;const SA=[];let UA=0;for(let GA=0;GA<hA;GA++)MA[GA]&&(fA[GA]=UA++,SA.push(aA[GA*3+0],aA[GA*3+1],aA[GA*3+2]));for(let GA=0;GA<z.length;GA++)z[GA]=fA[z[GA]>>>0];this._vertProperties=SA,this._vertKeyToIndex=new Map;for(let GA=0;GA<SA.length;GA+=3)this._vertKeyToIndex.set(`${SA[GA]},${SA[GA+1]},${SA[GA+2]}`,GA/3|0)},"compactVertices")(),e&&console.log("[splitSelfIntersectingTriangles] complete",{initialTriangles:n,finalTriangles:this._triVerts.length/3|0,testedPairs:rA,pairIntersections:AA,pointIntersections:BA,touchedTriangles:CA,duplicateRemovals:EA}),tA}c(Yct,"DHt");r(Yct,"splitSelfIntersectingTriangles");function Uct(){if(!this._triVerts||!this._vertProperties)return 0;try{this._manifoldize()}catch{console.log("[removeDegenerateTriangles] manifoldization failed, proceeding with best effort cleanup")}const i={sub:r((s,I)=>[s[0]-I[0],s[1]-I[1],s[2]-I[2]],"sub"),len:r(s=>Math.sqrt(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]),"len"),cross:r((s,I)=>[s[1]*I[2]-s[2]*I[1],s[2]*I[0]-s[0]*I[2],s[0]*I[1]-s[1]*I[0]],"cross")},A=this._triVerts.length/3,e=[],t=[];let g=0;const o=r(s=>{const I=s*3,n=this._triVerts[I]*3,B=this._triVerts[I+1]*3,C=this._triVerts[I+2]*3,a=[this._vertProperties[n],this._vertProperties[n+1],this._vertProperties[n+2]],Q=[this._vertProperties[B],this._vertProperties[B+1],this._vertProperties[B+2]],E=[this._vertProperties[C],this._vertProperties[C+1],this._vertProperties[C+2]],l=1e-10,h=i.len(i.sub(a,Q)),w=i.len(i.sub(Q,E)),d=i.len(i.sub(E,a));if(h<l||w<l||d<l)return!0;const D=i.cross(i.sub(Q,a),i.sub(E,a));return .5*i.len(D)<1e-12},"isDegenerate");for(let s=0;s<A;s++)if(o(s))g++;else{const I=s*3;e.push(this._triVerts[I]),e.push(this._triVerts[I+1]),e.push(this._triVerts[I+2]),t.push(this._triIDs[s])}return this._triVerts=e,this._triIDs=t,g>0&&(this._dirty=!0,this._faceIndex=null,this._manifold=null),g}c(Uct,"fHt");r(Uct,"removeDegenerateTriangles");function kct(){if((this._triVerts.length/3|0)===0)return 0;mn(YB&&$Et,"Solid.removeInternalTriangles()");const i=Ya(this),A=i.removeInternalTriangles();yQ(this,i),this._dirty=!1,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,A>0?A:0}c(kct,"MHt");r(kct,"removeInternalTriangles");function Lct(){const i=this._vertProperties,A=this._triVerts,e=this._triIDs,t=A.length/3|0;if(t===0)return 0;const g=new Array(t);for(let F=0;F<t;F++){const m=F*3,G=A[m+0]>>>0,N=A[m+1]>>>0,S=A[m+2]>>>0;g[F]=[[i[G*3+0],i[G*3+1],i[G*3+2]],[i[N*3+0],i[N*3+1],i[N*3+2]],[i[S*3+0],i[S*3+1],i[S*3+2]]]}let o=1/0,s=1/0,I=1/0,n=-1/0,B=-1/0,C=-1/0;for(let F=0;F<i.length;F+=3){const m=i[F],G=i[F+1],N=i[F+2];m<o&&(o=m),m>n&&(n=m),G<s&&(s=G),G>B&&(B=G),N<I&&(I=N),N>C&&(C=N)}const a=1e-6*(Math.hypot(n-o,B-s,C-I)||1),Q=r((F,m,G)=>{const N=G[0][0],S=G[0][1],Y=G[0][2],R=G[1][0],k=G[1][1],b=G[1][2],L=G[2][0],x=G[2][1],J=G[2][2],$=R-N,T=k-S,H=b-Y,X=L-N,oA=x-S,_=J-Y,V=m[1]*_-m[2]*oA,O=m[2]*X-m[0]*_,AA=m[0]*oA-m[1]*X,BA=$*V+T*O+H*AA;if(Math.abs(BA)<1e-12)return null;const rA=1/BA,tA=F[0]-N,sA=F[1]-S,eA=F[2]-Y,K=(tA*V+sA*O+eA*AA)*rA;if(K<-1e-12||K>1+1e-12)return null;const v=sA*H-eA*T,iA=eA*$-tA*H,QA=tA*T-sA*$,gA=(m[0]*v+m[1]*iA+m[2]*QA)*rA;if(gA<-1e-12||K+gA>1+1e-12)return null;const IA=(X*v+oA*iA+_*QA)*rA;return IA>1e-10?IA:null},"rayTri"),E=r(F=>{const m=[[1,0,0],[0,1,0],[0,0,1]];let G=0;for(let N=0;N<m.length;N++){const S=m[N],Y=[F[0]+(N+1)*a,F[1]+(N+2)*a,F[2]+(N+3)*a];let R=0;for(let k=0;k<g.length;k++)Q(Y,S,g[k])!==null&&R++;R%2===1&&G++}return G>=2},"pointInside"),l=r(F=>{const[m,G,N]=g[F],S=(m[0]+G[0]+N[0])/3+a,Y=(m[1]+G[1]+N[1])/3+a,R=(m[2]+G[2]+N[2])/3+a;return[S,Y,R]},"triProbe"),h=new Uint8Array(t);for(let F=0;F<t;F++)h[F]=1;let w=0;for(let F=0;F<t;F++){const m=l(F);E(m)&&(h[F]=0,w++)}if(w===0)return 0;const d=i.length/3|0,D=new Uint8Array(d),u=[],M=[];for(let F=0;F<t;F++){if(!h[F])continue;const m=F*3,G=A[m+0]>>>0,N=A[m+1]>>>0,S=A[m+2]>>>0;u.push(G,N,S),M.push(e[F]),D[G]=1,D[N]=1,D[S]=1}const y=new Int32Array(d);for(let F=0;F<d;F++)y[F]=-1;const p=[];let f=0;for(let F=0;F<d;F++)D[F]&&(y[F]=f++,p.push(i[F*3+0],i[F*3+1],i[F*3+2]));for(let F=0;F<u.length;F++)u[F]=y[u[F]];this._vertProperties=p,this._triVerts=u,this._triIDs=M,this._vertKeyToIndex=new Map;for(let F=0;F<this._vertProperties.length;F+=3){const m=this._vertProperties[F],G=this._vertProperties[F+1],N=this._vertProperties[F+2];this._vertKeyToIndex.set(`${m},${G},${N}`,F/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),w}c(Lct,"yHt");r(Lct,"removeInternalTrianglesByRaycast");function bct({offsetScale:i=1e-5,crossingTolerance:A=.05}={}){const e=this._vertProperties,t=this._triVerts,g=this._triIDs,o=t.length/3|0;if(o===0)return 0;let s=1/0,I=1/0,n=1/0,B=-1/0,C=-1/0,a=-1/0;for(let Y=0;Y<e.length;Y+=3){const R=e[Y],k=e[Y+1],b=e[Y+2];R<s&&(s=R),R>B&&(B=R),k<I&&(I=k),k>C&&(C=k),b<n&&(n=b),b>a&&(a=b)}const Q=Math.hypot(B-s,C-I,a-n)||1,E=i*Q,l=new Array(o),h=new Array(o),w=new Array(o);for(let Y=0;Y<o;Y++){const R=Y*3,k=t[R+0]>>>0,b=t[R+1]>>>0,L=t[R+2]>>>0,x=e[k*3+0],J=e[k*3+1],$=e[k*3+2],T=e[b*3+0],H=e[b*3+1],X=e[b*3+2],oA=e[L*3+0],_=e[L*3+1],V=e[L*3+2];l[Y]=[[x,J,$],[T,H,X],[oA,_,V]],h[Y]=[(x+T+oA)/3,(J+H+_)/3,($+X+V)/3];const O=T-x,AA=H-J,BA=X-$,rA=oA-x,tA=_-J,sA=V-$;let eA=AA*sA-BA*tA,K=BA*rA-O*sA,v=O*tA-AA*rA;const iA=Math.hypot(eA,K,v);iA<1e-18?w[Y]=[0,0,0]:w[Y]=[eA/iA,K/iA,v/iA]}const d=r((Y,R,k,b)=>{const L=R[0]-Y[0],x=R[1]-Y[1],J=R[2]-Y[2],$=k[0]-Y[0],T=k[1]-Y[1],H=k[2]-Y[2],X=b[0]-Y[0],oA=b[1]-Y[1],_=b[2]-Y[2],V=Math.hypot(L,x,J),O=Math.hypot($,T,H),AA=Math.hypot(X,oA,_);if(V<1e-18||O<1e-18||AA<1e-18)return 0;const BA=L*$+x*T+J*H,rA=$*X+T*oA+H*_,tA=X*L+oA*x+_*J,sA=x*H-J*T,eA=J*$-L*H,K=L*T-x*$,v=sA*X+eA*oA+K*_,iA=V*O*AA+BA*AA+rA*V+tA*O;return 2*Math.atan2(v,iA)},"solidAngle"),D=r(Y=>{let R=0;for(let k=0;k<o;k++){const[b,L,x]=l[k];R+=d(Y,b,L,x)}return R/(4*Math.PI)},"winding"),u=new Uint8Array(o);for(let Y=0;Y<o;Y++)u[Y]=1;let M=0;const y=Math.max(0,Math.min(.49,A));for(let Y=0;Y<o;Y++){const R=w[Y];if(!R||R[0]===0&&R[1]===0&&R[2]===0)continue;const k=h[Y],b=[k[0]+R[0]*E,k[1]+R[1]*E,k[2]+R[2]*E],L=[k[0]-R[0]*E,k[1]-R[1]*E,k[2]-R[2]*E],x=D(b),J=D(L),$=Math.abs(x)-.5,T=Math.abs(J)-.5;$<-y&&T>y||$>y&&T<-y||$*T<-y*y||(u[Y]=0,M++)}if(M===0)return 0;const p=e.length/3|0,f=new Uint8Array(p),F=[],m=[];for(let Y=0;Y<o;Y++){if(!u[Y])continue;const R=Y*3,k=t[R+0]>>>0,b=t[R+1]>>>0,L=t[R+2]>>>0;F.push(k,b,L),m.push(g[Y]),f[k]=1,f[b]=1,f[L]=1}const G=new Int32Array(p);for(let Y=0;Y<p;Y++)G[Y]=-1;const N=[];let S=0;for(let Y=0;Y<p;Y++)f[Y]&&(G[Y]=S++,N.push(e[Y*3+0],e[Y*3+1],e[Y*3+2]));for(let Y=0;Y<F.length;Y++)F[Y]=G[F[Y]];this._vertProperties=N,this._triVerts=F,this._triIDs=m,this._vertKeyToIndex=new Map;for(let Y=0;Y<this._vertProperties.length;Y+=3){const R=this._vertProperties[Y],k=this._vertProperties[Y+1],b=this._vertProperties[Y+2];this._vertKeyToIndex.set(`${R},${k},${b}`,Y/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),M}c(bct,"pHt");r(bct,"removeInternalTrianglesByWinding");function Kct(i){const A=Number(i);if(!Number.isFinite(A)||A<=0)return 0;mn(YB&&qEt,"Solid.cleanupTinyFaceIslands()");const e=Ya(this),t=e.cleanupTinyFaceIslands(A);if(t>0){yQ(this,e),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return t}c(Kct,"FHt");r(Kct,"cleanupTinyFaceIslands");function xct(i=.001){if(!Number.isFinite(i)||i<=0)return this;mn(YB&&XEt,"Solid.mergeTinyFaces()");const A=Ya(this);if(A.mergeTinyFaces(i)>0){yQ(this,A),this._faceIndex=null,this._dirty=!0;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null;try{typeof this._manifoldize=="function"&&(this._manifoldize(),typeof this._ensureFaceIndex=="function"&&this._ensureFaceIndex())}catch{}}return this}c(xct,"mHt");r(xct,"mergeTinyFaces");function Jct(){return this._manifoldize().getMesh()}c(Jct,"NHt");r(Jct,"getMesh");function Hct(){if(this._faceIndex)return;const i=this.getMesh(),{triVerts:A,faceID:e}=i,t=A.length/3|0,g=new Map;if(e&&e.length===t)for(let o=0;o<t;o++){const s=e[o];let I=g.get(s);I||(I=[],g.set(s,I)),I.push(o)}this._faceIndex=g;try{i&&typeof i.delete=="function"&&i.delete()}catch{}}c(Hct,"SHt");r(Hct,"_ensureFaceIndex");function vct(i){return mn(U5A,"Solid.getFace"),Ya(this).getFace(i)}c(vct,"GHt");r(vct,"getFace");function Tct(i){return mn(U5A,"Solid.getFaceNormal"),Ya(this).getFaceNormal(i)}c(Tct,"RHt");r(Tct,"getFaceNormal");function Pct(i=!1){return mn(U5A,"Solid.getFaces"),Ya(this).getFaces(i)}c(Pct,"YHt");r(Pct,"getFaces");function Oct(){return mn(U5A,"Solid.getBoundaryEdgePolylines"),Ya(this).getBoundaryEdgePolylines()}c(Oct,"UHt");r(Oct,"getBoundaryEdgePolylines");const lpA=.01,bTi=.0015,jct=1e-4;function zct(){return typeof Tt?.buildBooleanCombinedAuthoringState=="function"}c(zct,"LHt");r(zct,"hasNativeBooleanCombinedBuilder");function $Re(){return typeof Tt?.buildBooleanUnionManyAuthoringState=="function"}c($Re,"dgt");r($Re,"hasNativeBooleanUnionManyBuilder");function Vct(i){if(!zct())throw new Error(`${i} requires the custom local manifold build with native boolean result reconstruction support.`)}c(Vct,"bHt");r(Vct,"requireNativeBooleanCombinedBuilder");function Wct(i){if(!$Re())throw new Error(`${i} requires the custom local manifold build with native batch union result reconstruction support.`)}c(Wct,"xHt");r(Wct,"requireNativeBooleanUnionManyBuilder");function v0A(i){const A=i&&i.constructor;return A&&A.BaseSolid?A.BaseSolid:A}c(v0A,"etA");r(v0A,"baseSolidCtor$1");function _ct(i){const A=i&&i._vertProperties;if(!Array.isArray(A)||A.length<3)return 1;let e=1/0,t=1/0,g=1/0,o=-1/0,s=-1/0,I=-1/0;for(let n=0;n<A.length;n+=3){const B=A[n],C=A[n+1],a=A[n+2];B<e&&(e=B),B>o&&(o=B),C<t&&(t=C),C>s&&(s=C),a<g&&(g=a),a>I&&(I=a)}return Math.max(Math.hypot(o-e,s-t,I-g),1)}c(_ct,"KHt");r(_ct,"booleanApproxScale");function pTA(i,A=12){return[Number(i?.[0]||0).toFixed(A),Number(i?.[1]||0).toFixed(A),Number(i?.[2]||0).toFixed(A)].join(",")}c(pTA,"SNA");r(pTA,"pointKey$1");function AYe(i,A){if(!i||typeof i.getFace!="function"||!A)return[];const e=i.getFace(A)||[],t=new Map,g=r((I,n)=>{if(!Array.isArray(I)||!Array.isArray(n))return;const B=pTA(I),C=pTA(n),a=B<C?`${B}|${C}`:`${C}|${B}`,Q=t.get(a);Q?Q.count+=1:t.set(a,{count:1,points:[[Number(I[0])||0,Number(I[1])||0,Number(I[2])||0],[Number(n[0])||0,Number(n[1])||0,Number(n[2])||0]]})},"addEdge");for(const I of e){const n=Array.isArray(I?.p1)?I.p1:null,B=Array.isArray(I?.p2)?I.p2:null,C=Array.isArray(I?.p3)?I.p3:null;!n||!B||!C||(g(n,B),g(B,C),g(C,n))}const o=[],s=new Set;for(const I of t.values())if(I.count===1)for(const n of I.points){const B=pTA(n);s.has(B)||(s.add(B),o.push(n))}return o}c(AYe,"wgt");r(AYe,"faceBoundaryPoints");function qct(i,A,e){if(!i||typeof i.minGapToPoint!="function")return!1;for(const t of A){const g=i.minGapToPoint(t,e,{nearestOnly:!0});if(Array.isArray(g)&&g.some(o=>Number(o?.distance)<=e))return!0}return!1}c(qct,"HHt");r(qct,"hasNearTargetEdgePoint");function Zct(i,A,e,t,g=8){const o=AYe(A,e);if(!o.length||typeof i?.minGapToPoint!="function")return-1/0;const s=Math.max(1,Math.ceil(o.length/g)),I=Math.max(_ct(i)*2,jct*10);let n=0,B=0;for(let C=0;C<o.length;C+=s){B+=1;const a=i.minGapToPoint(o[C],I,{nearestOnly:!0});(Array.isArray(a)&&a.length>0?a[0].inside===!0:!1)===t&&(n+=1)}return B>0?n/B:-1/0}c(Zct,"JHt");r(Zct,"scoreFaceSide");function eYe(i,A,e){const t=String(i||"").toUpperCase();if(t!=="UNION"&&t!=="SUBTRACT"||!A||!e||typeof A.minGapToPoint!="function"||typeof e.getFaceNames!="function"||typeof e.pushFace!="function")return e;const g=t==="UNION",o=jct,s=o*2,I=[];for(const C of e.getFaceNames()||[]){const a=String(C||"").trim();if(!a)continue;const Q=AYe(e,a);Q.length&&qct(A,Q,o)&&I.push(a)}if(!I.length||typeof e.clone!="function")return e;const n=e.clone();let B=!1;for(const C of I){let a=null;for(const Q of[1,-1]){const E=typeof n.clone=="function"?n.clone():null;if(E)try{E.pushFace(C,Q*s,{warnMissing:!1,warnInvalidNormal:!1});const l=Zct(A,E,C,g);(!a||l>a.score)&&(a={sign:Q,score:l})}catch{}}if(!(!a||!(a.score>-1/0)))try{n.pushFace(C,a.sign*s,{warnMissing:!1,warnInvalidNormal:!1}),B=!0}catch{}}return B?n:e}c(eYe,"ugt");r(eYe,"conditionEdgePointProximity");function L5A(i,A,e){const t=new i;sB(t,A),t._dirty=!0,t._manifold=null,t._faceIndex=null;try{t.name=e||A?.name||t?.name}catch{}return t}c(L5A,"qne");r(L5A,"solidFromNativeBooleanSnapshot");function OUA(i){return i instanceof Map?Array.from(i.entries(),([A,e])=>[String(A||""),String(e||"")]).filter(A=>A[0]):Array.isArray(i)?Array.from(i,([A,e])=>[String(A||""),String(e||"")]).filter(A=>A[0]):[]}c(OUA,"IaA");r(OUA,"toMetadataJsonEntries");function uae(i){return i instanceof Map?Array.from(i.entries()):Array.isArray(i)?Array.from(i):[]}c(uae,"KPe");r(uae,"toSnapshotEntries");function rzA(i){return{numProp:Number(i?.numProp??3),vertProperties:Array.from(i?.vertProperties??[]),triVerts:Array.from(i?.triVerts??[]),triIDs:Array.from(i?.triIDs??[]),faceNameToID:uae(i?.faceNameToID),idToFaceName:uae(i?.idToFaceName),faceMetadataJson:OUA(i?.faceMetadataJson),edgeMetadataJson:OUA(i?.edgeMetadataJson),auxEdges:Array.isArray(i?.auxEdges)?i.auxEdges:[],vertexCount:Number(i?.vertexCount??0),triangleCount:Number(i?.triangleCount??0)}}c(rzA,"vKA");r(rzA,"toNativeBooleanSnapshot");function Xct(i,A,e={}){mn(typeof Tt?.buildSolidAuthoringStateFromMesh=="function","Solid.simplify");const t=new Map(A instanceof Map?A:[]),g=new Map;for(const[o,s]of t.entries())g.has(s)||g.set(s,o);return Tt.buildSolidAuthoringStateFromMesh({numProp:Number(i?.numProp??3),vertProperties:Array.from(i?.vertProperties??[]),triVerts:Array.from(i?.triVerts??[]),faceID:Array.from(i?.faceID??[]),faceNameToID:Array.from(g.entries()),idToFaceName:Array.from(t.entries()),faceMetadataJson:OUA(e?.faceMetadataJson),edgeMetadataJson:OUA(e?.edgeMetadataJson),auxEdges:Array.isArray(e?.auxEdges)?e.auxEdges:[],name:e?.name||""})}c(Xct,"vHt");r(Xct,"buildNativeSnapshotFromMesh");function DK(i,A){const e=Number(i?.numProp??3)||3,t=(A>>>0)*e,g=i?.vertProperties??[];return[Number(g[t+0])||0,Number(g[t+1])||0,Number(g[t+2])||0]}c(DK,"ET");r(DK,"_vec3FromMesh");function tYe(i,A,e){const t=A[0]-i[0],g=A[1]-i[1],o=A[2]-i[2],s=e[0]-i[0],I=e[1]-i[1],n=e[2]-i[2];let B=g*n-o*I,C=o*s-t*n,a=t*I-g*s;const Q=Math.hypot(B,C,a);return Q>0?(B/=Q,C/=Q,a/=Q,{normal:[B,C,a],area2:Q}):{normal:[0,0,0],area2:0}}c(tYe,"Dgt");r(tYe,"_triangleNormalAndArea");function fTA(i,A,e){const t=e[0]-A[0],g=e[1]-A[1],o=e[2]-A[2],s=i[0]-A[0],I=i[1]-A[1],n=i[2]-A[2],B=t*t+g*g+o*o,C=B>0?Math.max(0,Math.min(1,(s*t+I*g+n*o)/B)):0,a=s-t*C,Q=I-g*C,E=n-o*C;return a*a+Q*Q+E*E}c(fTA,"GNA");r(fTA,"_pointSegmentDistanceSq");function $ct(i,A,e,t){const g=e[0]-A[0],o=e[1]-A[1],s=e[2]-A[2],I=t[0]-A[0],n=t[1]-A[1],B=t[2]-A[2],C=i[0]-A[0],a=i[1]-A[1],Q=i[2]-A[2],E=g*g+o*o+s*s,l=g*I+o*n+s*B,h=I*I+n*n+B*B,w=C*g+a*o+Q*s,d=C*I+a*n+Q*B,D=E*h-l*l;if(Math.abs(D)>1e-18){const u=(h*w-l*d)/D,M=(E*d-l*w)/D;if(1-u-M>=0&&u>=0&&M>=0){const y=A[0]+g*u+I*M,p=A[1]+o*u+n*M,f=A[2]+s*u+B*M,F=i[0]-y,m=i[1]-p,G=i[2]-f;return F*F+m*m+G*G}}return Math.min(fTA(i,A,e),fTA(i,e,t),fTA(i,t,A))}c($ct,"THt");r($ct,"_pointTriangleDistanceSq");function Alt(i){const A={numProp:Number(i?._numProp??3)||3,vertProperties:i?._vertProperties??[],triVerts:i?._triVerts??[],faceID:i?._triIDs??[]},e=Math.min(A.triVerts.length/3|0,A.faceID.length|0),t=[];for(let g=0;g<e;g++){const o=g*3,s=DK(A,A.triVerts[o+0]),I=DK(A,A.triVerts[o+1]),n=DK(A,A.triVerts[o+2]),{normal:B,area2:C}=tYe(s,I,n);C>0&&t.push({a:s,b:I,c:n,id:A.faceID[g]>>>0,normal:B,centroid:[(s[0]+I[0]+n[0])/3,(s[1]+I[1]+n[1])/3,(s[2]+I[2]+n[2])/3]})}return t}c(Alt,"PHt");r(Alt,"_buildTaggedSourceTrianglesFromSolid");function elt(i){if(!Array.isArray(i)||i.length<512)return{all:i,candidatesForPoint:r(()=>i,"candidatesForPoint")};const A=[1/0,1/0,1/0],e=[-1/0,-1/0,-1/0];for(const B of i){const C=B.centroid;for(let a=0;a<3;a++)C[a]<A[a]&&(A[a]=C[a]),C[a]>e[a]&&(e[a]=C[a])}const t=[Math.max(1e-9,e[0]-A[0]),Math.max(1e-9,e[1]-A[1]),Math.max(1e-9,e[2]-A[2])],g=Math.max(4,Math.min(64,Math.ceil(Math.cbrt(i.length)))),o=[t[0]/g,t[1]/g,t[2]/g],s=new Map,I=r((B,C)=>Math.max(0,Math.min(g-1,Math.floor((B[C]-A[C])/o[C]))),"cellCoord"),n=r((B,C,a)=>`${B},${C},${a}`,"cellKey");for(const B of i){const C=I(B.centroid,0),a=I(B.centroid,1),Q=I(B.centroid,2),E=n(C,a,Q);let l=s.get(E);l||(l=[],s.set(E,l)),l.push(B)}return{all:i,candidatesForPoint(B){const C=I(B,0),a=I(B,1),Q=I(B,2),E=[];for(let l=0;l<=3&&E.length<32;l++)for(let h=Math.max(0,C-l);h<=Math.min(g-1,C+l);h++)for(let w=Math.max(0,a-l);w<=Math.min(g-1,a+l);w++)for(let d=Math.max(0,Q-l);d<=Math.min(g-1,Q+l);d++){const D=s.get(n(h,w,d));D&&E.push(...D)}return E.length?E:i}}}c(elt,"OHt");r(elt,"_buildRetagCandidateIndex");function tlt(i,A){const e=Alt(A),t=i?.triVerts?.length/3|0;if(!t||e.length===0)return i;const g=elt(e),o=new Uint32Array(t);for(let s=0;s<t;s++){const I=s*3,n=DK(i,i.triVerts[I+0]),B=DK(i,i.triVerts[I+1]),C=DK(i,i.triVerts[I+2]),a=[(n[0]+B[0]+C[0])/3,(n[1]+B[1]+C[1])/3,(n[2]+B[2]+C[2])/3],{normal:Q,area2:E}=tYe(n,B,C);let l=e[0].id,h=1/0;for(const w of g.candidatesForPoint(a)){const d=$ct(a,w.a,w.b,w.c),D=E>0?Math.max(-1,Math.min(1,Q[0]*w.normal[0]+Q[1]*w.normal[1]+Q[2]*w.normal[2])):1,u=d+(1-D)*1e-6;u<h&&(h=u,l=w.id)}o[s]=l>>>0}return i.faceID=o,i}c(tlt,"zHt");r(tlt,"retagSimplifiedMeshFromSourceSolid");function b5A(i,A,e,t){Vct(`Solid.${String(e||"boolean").toLowerCase()}`);const g=eN(i),o=eN(A),s=Tt.buildBooleanCombinedAuthoringState({leftSnapshot:rzA(g),rightSnapshot:rzA(o),operation:e,featureID:String(i?.owningFeatureID||i?.name||e||"BOOLEAN"),name:String(i?.name||`${e}_RESULT`),cleanupTinyFaceIslandsArea:lpA,disconnectedIslandMinVolume:lpA});return L5A(t,s,i?.name||`${e}_RESULT`)}c(b5A,"Zne");r(b5A,"buildNativeBooleanResult");function K5A(i){const A=i?.message||i?.toString?.()||String(i||"");return String(A||"unknown error").slice(0,240)}c(K5A,"Xne");r(K5A,"describeBooleanError");function FTA(i,A){if(!i||typeof i!="object")return i;try{i.__unionManyDiagnostics={...A}}catch{}try{i.userData={...i.userData||{},unionMany:{...A}}}catch{}return i}c(FTA,"RNA");r(FTA,"attachUnionManyDiagnostics");function mTA(i,A={},e=[]){if(!i||typeof i!="object")return i;const t=String(A?.name||"").trim();if(t)try{i.name=t}catch{}try{i.owningFeatureID=A?.owningFeatureID||A?.featureID||A?.featureId||e.find(g=>g?.owningFeatureID)?.owningFeatureID||i?.owningFeatureID||null}catch{}return i}c(mTA,"YNA");r(mTA,"applyUnionManyNameAndOwner");function iYe(i,A,e={}){return i.union(A,{overlapConditioningEnabled:e?.overlapConditioningEnabled})}c(iYe,"fgt");r(iYe,"unionManyPair");function gYe(i,A){try{i.unionManyDiagnostics={...A}}catch{}throw i}c(gYe,"Mgt");r(gYe,"throwUnionManyError");function ilt(i,A,e){if(!i.length)return null;let t=i[0];for(let g=1;g<i.length;g+=1){const o=i[g];e.unionAttemptCount+=1;try{t={solid:iYe(t.solid,o.solid,A),count:t.count+o.count}}catch(s){e.unionFailureCount+=1,e.skippedSolidCount+=o.count,e.firstUnionError||(e.firstUnionError=K5A(s)),A?.skipFailed||gYe(s,e)}}return t}c(ilt,"jHt");r(ilt,"unionManyNodesSequential");function glt(i,A,e){let t=i.slice();for(;t.length>1;){const g=[];for(let o=0;o<t.length;o+=2){const s=t[o],I=t[o+1];if(!I){g.push(s);continue}e.unionAttemptCount+=1;try{g.push({solid:iYe(s.solid,I.solid,A),count:s.count+I.count})}catch(n){e.unionFailureCount+=1,e.skippedSolidCount+=I.count,e.firstUnionError||(e.firstUnionError=K5A(n)),A?.skipFailed||gYe(n,e),g.push(s)}}t=g}return t[0]||null}c(glt,"VHt");r(glt,"unionManyNodesBalanced");function olt(i,A=null,e={}){const t=Array.isArray(i)?i.filter(Boolean):[];if(!t.length)return null;Wct("Solid.unionMany");const g=A||v0A(t[0]),o=t.map(C=>rzA(eN(C))),s=String(e?.featureID||t[0]?.owningFeatureID||t[0]?.name||"UNION"),I=String(e?.name||t[0]?.name||`${s}_UNION`),n=Tt.buildBooleanUnionManyAuthoringState({snapshots:o,featureID:s,name:I,cleanupTinyFaceIslandsArea:Number(e?.cleanupTinyFaceIslandsArea??lpA),disconnectedIslandMinVolume:Number(e?.disconnectedIslandMinVolume??lpA)}),B=L5A(g,n,I);try{B.owningFeatureID=e?.owningFeatureID||t.find(C=>C?.owningFeatureID)?.owningFeatureID||B?.owningFeatureID||null}catch{}return vbA(B)}c(olt,"WHt");r(olt,"buildNativeUnionManyResult");function hpA(i,A={}){const e=Array.isArray(i)?i:[i],t=(this&&typeof this=="object"&&typeof this.union=="function"?[this,...e]:e).filter(Boolean),g={unionStrategy:"none",nativeBatchUnionAvailable:$Re(),nativeBatchUnionStatus:t.length>1?"not_run":"not_applicable",nativeBatchUnionError:null,unionAttemptCount:0,unionFailureCount:0,skippedSolidCount:0,contributedSolidCount:t.length,firstUnionError:null};if(!t.length)return null;if(t.length===1){g.unionStrategy="single";const a=mTA(t[0],A,t);return FTA(a,g)}const o=String(A?.unionStrategy||"native_batch").trim().toLowerCase(),s=A?.nativeBatchUnion!==!1&&o!=="balanced"&&o!=="sequential",I=typeof this=="function"?this.BaseSolid||this:v0A(t[0]);if(s&&g.nativeBatchUnionAvailable)try{const a=olt(t,I,{...A,featureID:A?.featureID||A?.featureId,owningFeatureID:A?.owningFeatureID||A?.featureID||A?.featureId});return g.unionStrategy="native_batch",g.nativeBatchUnionStatus="passed",g.contributedSolidCount=t.length,mTA(a,A,t),FTA(a,g)}catch(a){g.nativeBatchUnionStatus="failed",g.nativeBatchUnionError=K5A(a)}else g.nativeBatchUnionAvailable?g.nativeBatchUnionStatus="disabled":g.nativeBatchUnionStatus="unavailable";const n=t.map(a=>({solid:a,count:1})),B=o==="sequential"?ilt(n,A,g):glt(n,A,g);g.unionStrategy=o==="sequential"?g.nativeBatchUnionStatus==="failed"?"sequential_fallback":"sequential":g.nativeBatchUnionStatus==="failed"?"balanced_fallback":"balanced",g.contributedSolidCount=Number(B?.count||0);const C=mTA(B?.solid||null,A,t);return FTA(C,g)}c(hpA,"I6");r(hpA,"unionMany");function slt(i,A=lpA){const e=Number(A);if(!Number.isFinite(e)||e<=0||!i||typeof i!="object")return 0;mn(STi,"Solid._dropDisconnectedIslandsByVolume");const t=Ya(i),g=t.removeDisconnectedIslandsByVolume(e);if(g>0){yQ(i,t),i._dirty=!0,i._faceIndex=null;try{i._manifold&&typeof i._manifold.delete=="function"&&i._manifold.delete()}catch{}i._manifold=null}return g}c(slt,"_Ht");r(slt,"_dropDisconnectedIslandsByVolume");function Ilt(i){const A=Number(bTi);return!i||typeof i.setEpsilon!="function"||!Number.isFinite(A)||A<=0||i.setEpsilon(A),i}c(Ilt,"qHt");r(Ilt,"_applyFixedBooleanResultWeld");function vbA(i){try{slt(i,lpA)}catch{}return Ilt(i)}c(vbA,"x0A");r(vbA,"_cleanupBooleanResult");function nlt(i,A={}){const e=v0A(this),t=A?.overlapConditioningEnabled===!1?this:eYe("UNION",i,this),g=b5A(t,i,"UNION",e);try{g.owningFeatureID=this?.owningFeatureID||i?.owningFeatureID||g?.owningFeatureID||null}catch{}return vbA(g)}c(nlt,"ZHt");r(nlt,"union");function Blt(i,A={}){const e=v0A(this),t=A?.overlapConditioningEnabled===!1?i:eYe("SUBTRACT",this,i),g=b5A(this,t,"SUBTRACT",e);try{g.owningFeatureID=this?.owningFeatureID||i?.owningFeatureID||g?.owningFeatureID||null}catch{}return vbA(g)}c(Blt,"XHt");r(Blt,"subtract");function rlt(i){const A=v0A(this),e=b5A(this,i,"INTERSECT",A);try{e.owningFeatureID=this?.owningFeatureID||i?.owningFeatureID||e?.owningFeatureID||null}catch{}return vbA(e)}c(rlt,"$Ht");r(rlt,"intersect$1");function Clt(i=void 0,A=!1){A&&typeof A=="object"&&(A=!1);const e=this.constructor,t=this._manifoldize(),g=eN(this),o=i===void 0?t.simplify():t.simplify(i);let s=null;const I=o.getMesh();try{tlt(I,this),s=Xct(I,this._idToFaceName,{faceMetadataJson:g?.faceMetadataJson,edgeMetadataJson:g?.edgeMetadataJson,auxEdges:g?.auxEdges,name:this?.name||""})}finally{try{I&&typeof I.delete=="function"&&I.delete()}catch{}}sB(this,s);try{this._manifold&&this._manifold!==o&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}if(this._manifold=o,this._dirty=!1,this._faceIndex=null,A)return this;this._manifold=null,this._dirty=!0,this._faceIndex=null;const n=L5A(e,s,this?.name||"");return this._manifoldize(),n}c(Clt,"AJt");r(Clt,"simplify");function alt(i){return i.faceID&&i.faceID.length?Array.from(i.faceID):new Array(i.triVerts.length/3|0).fill(0)}c(alt,"eJt");r(alt,"_expandTriIDsFromMesh");function CzA(i){return String(i??"").replace(/'/g,"''")}c(CzA,"TKA");r(CzA,"_escapeStepString");function xd(i,A="NAME"){const e=String(i??"").trim();return CzA(e||A)}c(xd,"DD");r(xd,"_safeStepName");function IQ(i,A){if(!Number.isFinite(i))return"0";let e=Number(i).toFixed(A);return e.includes(".")&&(e=e.replace(/\.?0+$/,"")),e==="-0"&&(e="0"),e}c(IQ,"bQ");r(IQ,"_fmtNumber");function Qlt(i,A=6){if(!Number.isFinite(i)||i===0)return"0.";const e=Number(i).toExponential(A),[t,g]=e.split("e"),o=Number(g);return`${t.toUpperCase()}E${o>=0?"+":""}${o}`}c(Qlt,"tJt");r(Qlt,"_fmtExp");function Elt(i,A=1e-12){if(!i||i.length!==16)return!0;const e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let t=0;t<16;t++)if(Math.abs((i[t]??e[t])-e[t])>A)return!1;return!0}c(Elt,"iJt");r(Elt,"_isIdentityMatrixElements$1");function Mae(i,A,e,t){if(!i||i.length!==16)return[A,e,t];const g=i[0]*A+i[4]*e+i[8]*t+i[12],o=i[1]*A+i[5]*e+i[9]*t+i[13],s=i[2]*A+i[6]*e+i[10]*t+i[14],I=i[3]*A+i[7]*e+i[11]*t+i[15];return I&&Math.abs(I-1)>1e-12?[g/I,o/I,s/I]:[g,o,s]}c(Mae,"HPe");r(Mae,"_applyMatrix4");function uO(i,A=[0,0,1]){const e=i[0],t=i[1],g=i[2],o=Math.hypot(e,t,g);return!o||!Number.isFinite(o)?A.slice():[e/o,t/o,g/o]}c(uO,"Zq");r(uO,"_normalize$1");function x5A(i,A){return[i[1]*A[2]-i[2]*A[1],i[2]*A[0]-i[0]*A[2],i[0]*A[1]-i[1]*A[0]]}c(x5A,"$ne");r(x5A,"_cross");function VG(i,A){return i[0]*A[0]+i[1]*A[1]+i[2]*A[2]}c(VG,"cb");r(VG,"_dot");function yae(i,A){return[i[0]-A[0],i[1]-A[1],i[2]-A[2]]}c(yae,"JPe");r(yae,"_sub");function NTA(i){const A=Math.abs(i[2])<.9?[0,0,1]:[0,1,0],e=x5A(A,i);return uO(e,[1,0,0])}c(NTA,"UNA");r(NTA,"_orthogonalRefDir");function STA(i,A=40){if(!i||i.length===0)return"()";if(i.length<=A)return`(${i.map(t=>`#${t}`).join(",")})`;const e=[];for(let t=0;t<i.length;t+=A){const g=i.slice(t,t+A).map(o=>`#${o}`).join(",");e.push(g)}return`(
4812
4812
  ${e.join(`,
4813
4813
  `)}
4814
4814
  )`}c(STA,"kNA");r(STA,"_formatEntityList");function vNA(i,A){return!Number.isFinite(i)||!Number.isFinite(A)||A<=0?0:Math.round(i/A)}c(vNA,"MgA");r(vNA,"_quantize");function pae(i,A,e,t){const g=vNA(i[0],e),o=vNA(i[1],e),s=vNA(i[2],e),I=vNA(A,t);return`${g},${o},${s},${I}`}c(pae,"vPe");r(pae,"_planeKey");function wpA(i,A){return i<A?`${i}_${A}`:`${A}_${i}`}c(wpA,"r6");r(wpA,"_edgeKey");function clt(i,A){const e=new Map;for(const g of i){const o=A[g];if(!o)continue;const s=[[o.i0,o.i1],[o.i1,o.i2],[o.i2,o.i0]];for(const[I,n]of s){const B=wpA(I,n),C=e.get(B);C?C.count+=1:e.set(B,{count:1,from:I,to:n})}}const t=[];for(const g of e.values())g.count===1&&t.push({from:g.from,to:g.to});return t}c(clt,"gJt");r(clt,"_collectBoundaryEdges");function llt(i){const A=new Map;for(const o of i){const s=A.get(o.from)||[];s.push(o),A.set(o.from,s)}const e=new Set,t=[],g=r(o=>`${o.from},${o.to}`,"edgeId");for(const o of i){const s=g(o);if(e.has(s))continue;const I=[o.from];let n=o;e.add(s);let B=0;for(;B++<i.length+5;){if(I.push(n.to),n.to===I[0]){I.pop(),I.length>=3&&t.push(I);break}const C=A.get(n.to)||[];let a=null;for(const Q of C){const E=g(Q);if(!e.has(E)){a=Q;break}}if(!a)return{loops:[],ok:!1};n=a,e.add(g(n))}}return{loops:t,ok:t.length>0}}c(llt,"sJt");r(llt,"_buildLoopsFromEdges");function hlt(i,A){const{vertProperties:e,triVerts:t,faceID:g}=i||{};if(!e||!t||!g)return[];const o=t.length/3|0,s=e.length/3|0;if(o===0||s===0)return[];const I=BigInt(s),n=r((Q,E)=>{const l=BigInt(Q),h=BigInt(E);return l<h?l*I+h:h*I+l},"ukey"),B=new Map;for(let Q=0;Q<o;Q++){const E=g?g[Q]:void 0,l=Q*3,h=t[l+0],w=t[l+1],d=t[l+2],D=[[h,w],[w,d],[d,h]];for(let u=0;u<3;u++){const M=D[u][0],y=D[u][1],p=n(M,y);let f=B.get(p);f||(f=[],B.set(p,f)),f.push({id:E,a:M,b:y,tri:Q})}}const C=new Map;for(const[,Q]of B.entries()){if(Q.length!==2)continue;const E=Q[0],l=Q[1];if(E.id===l.id)continue;const h=A?.get(E.id)||`FACE_${E.id}`,w=A?.get(l.id)||`FACE_${l.id}`,d=h<w?[h,w]:[w,h],D=JSON.stringify(d);let u=C.get(D);u||(u=[],C.set(D,u));const M=Math.min(E.a,E.b),y=Math.max(E.a,E.b);u.push([M,y])}const a=[];for(const[Q,E]of C.entries()){const l=new Map,h=new Set,w=r((p,f)=>p<f?`${p},${f}`:`${f},${p}`,"ek");for(const[p,f]of E)l.has(p)||l.set(p,new Set),l.has(f)||l.set(f,new Set),l.get(p).add(f),l.get(f).add(p);const[d,D]=JSON.parse(Q);let u=0;const M=r(p=>{const f=[];let F=-1,m=p;for(f.push(m);;){const G=l.get(m)||new Set;let N;for(const S of G){const Y=w(m,S);if(!h.has(Y)&&S!==F){N=S,h.add(Y);break}}if(N===void 0)break;F=m,m=N,f.push(m)}return f},"visitChainFrom");for(const[p,f]of l.entries())if((f.size|0)===1){const F=[...f][0],m=w(p,F);if(h.has(m))continue;const G=M(p);a.push({name:`${d}|${D}[${u++}]`,faceA:d,faceB:D,indices:G,closedLoop:!1})}const y=r((p,f)=>{const F=[p,f];let m=p,G=f;for(h.add(w(p,f));;){const Y=l.get(G)||new Set;let R;for(const k of Y){if(k===m)continue;const b=w(G,k);if(!h.has(b)){R=k;break}}if(R===void 0)break;h.add(w(G,R)),F.push(R),m=G,G=R}const N=F[0],S=F[F.length-1];return(l.get(S)||new Set).has(N)&&(h.add(w(S,N)),F.push(N)),F},"buildLoopFromEdge");for(const[p,f]of l.entries())for(const F of f){const m=w(p,F);if(h.has(m))continue;const G=y(p,F),N=G.length>=3&&G[0]===G[G.length-1];a.push({name:`${d}|${D}[${u++}]`,faceA:d,faceB:D,indices:G,closedLoop:N})}}return a}c(hlt,"oJt");r(hlt,"_buildBoundaryEdgePolylines");function wlt(i,A,e,t){let g=0;const o=i.length;for(let s=0;s<o;s++){const I=A[i[s]]?.pos,n=A[i[(s+1)%o]]?.pos;if(!I||!n)continue;const B=VG(I,e),C=VG(I,t),a=VG(n,e),Q=VG(n,t);g+=B*Q-a*C}return g*.5}c(wlt,"nJt");r(wlt,"_loopArea");function oYe(i,A){let e=uO(A,NTA(i));Math.abs(VG(e,i))>.99&&(e=NTA(i)),e=uO(e);const t=uO(x5A(i,e),NTA(i));return{u:e,v:t}}c(oYe,"ygt");r(oYe,"_planeBasis");function GTA(i,A){const e=new Map;for(const o of i){const s=A[o];if(!s)continue;const I=[[s.i0,s.i1],[s.i1,s.i2],[s.i2,s.i0]];for(const[n,B]of I){const C=wpA(n,B),a=e.get(C)||[];a.push(o),e.set(C,a)}}const t=new Set,g=[];for(const o of i){if(t.has(o))continue;const s=[o],I=[];for(t.add(o);s.length;){const n=s.pop();I.push(n);const B=A[n];if(!B)continue;const C=[[B.i0,B.i1],[B.i1,B.i2],[B.i2,B.i0]];for(const[a,Q]of C){const E=wpA(a,Q),l=e.get(E)||[];if(!(l.length<2))for(const h of l)t.has(h)||(t.add(h),s.push(h))}}I.length&&g.push(I)}return g}c(GTA,"LNA");r(GTA,"_splitComponents");function dlt(i,A,e,t){if(!i||i.length===0)return!1;const g=A[i[0]];if(!g)return!1;let o=g.normal,s=g.d;for(const I of i){const n=A[I];if(!n)continue;let B=n.normal,C=n.d,a=VG(B,o);if(a<0&&(B=[-B[0],-B[1],-B[2]],C=-C,a=-a),1-a>e||Math.abs(C-s)>t)return!1}return!0}c(dlt,"IJt");r(dlt,"_isCoplanarGroup");function d4(i,A,e,t,g,o=""){const s=A[i.i0],I=A[i.i1],n=A[i.i2];if(!s||!I||!n)return null;const B=i.normal,C=oYe(B,i.e1),a=t(B),Q=t(C.u),E=e.add(`AXIS2_PLACEMENT_3D('',#${s.pointId},#${a},#${Q})`),l=e.add(`PLANE('',#${E})`),h=e.add(`POLY_LOOP('',(#${s.pointId},#${I.pointId},#${n.pointId}))`),w=e.add(`FACE_OUTER_BOUND('',#${h},.T.)`);return e.add(`ADVANCED_FACE('${xd(o,"")}',(#${w}),#${l},.T.)`)}c(d4,"jW");r(d4,"_emitTriangleFace");function RTA(i,A,e,t,g,o,s="",I=null){if(!i.length)return{ok:!1};const n=A[i[0]];if(!n)return{ok:!1};const B=clt(i,A);if(B.length<3)return{ok:!1};const{loops:C,ok:a}=llt(B);if(!a||C.length===0)return{ok:!1};const Q=n.normal,E=oYe(Q,n.e1),l=C.map(m=>wlt(m,e,E.u,E.v));let h=0,w=Math.abs(l[0]||0);for(let m=1;m<l.length;m++){const G=Math.abs(l[m]||0);G>w&&(w=G,h=m)}l[h]<0&&(C[h].reverse(),l[h]=-l[h]);for(let m=0;m<C.length;m++)m!==h&&l[m]>0&&(C[m].reverse(),l[m]=-l[m]);const d=C[h][0],D=e[d];if(!D)return{ok:!1};const u=g(Q),M=g(E.u),y=t.add(`AXIS2_PLACEMENT_3D('',#${D.pointId},#${u},#${M})`),p=t.add(`PLANE('',#${y})`),f=[],F=r((m,G)=>{if(!I)return null;const N=[],S=m.length;for(let Y=0;Y<S;Y++){const R=m[Y],k=m[(Y+1)%S],b=wpA(R,k);let L=I.edgeCurveCache.get(b);if(!L){const $=I.edgeNameByKey.get(b)||I.edgeNameAllocator.allocate(`EDGE_${I.edgeCurveCache.size}`),T=e[R],H=e[k];if(!T||!H)return null;const X=t.add(`POLYLINE('',(#${T.pointId},#${H.pointId}))`);L={id:t.add(`EDGE_CURVE('${xd($)}',#${T.vertexId},#${H.vertexId},#${X},.T.)`),start:R,end:k},I.edgeCurveCache.set(b,L)}const x=L.start===R&&L.end===k?".T.":".F.",J=t.add(`ORIENTED_EDGE('',*,*,#${L.id},${x})`);N.push(J)}return N.length?t.add(`EDGE_LOOP('${xd(G,"")}',(${N.map(Y=>`#${Y}`).join(",")}))`):null},"buildEdgeLoop");for(let m=0;m<C.length;m++){const G=C[m];if(!G||G.length<3)continue;const N=G.map(Y=>{const R=e[Y]?.pointId;return R?`#${R}`:null});if(N.length<3||N.some(Y=>!Y))return{ok:!1};let S=null;if(I&&(S=F(G,`${s}_LOOP_${m}`)),S||(S=t.add(`POLY_LOOP('',(${N.join(",")}))`)),m===h){const Y=t.add(`FACE_OUTER_BOUND('',#${S},.T.)`);f.push(Y)}else{const Y=t.add(`FACE_BOUND('',#${S},.F.)`);f.push(Y)}}return f.length===0?{ok:!1}:{ok:!0,faceId:t.add(`ADVANCED_FACE('${xd(s,"")}',(${f.map(m=>`#${m}`).join(",")}),#${p},.T.)`)}}c(RTA,"bNA");r(RTA,"_emitPlanarComponent");function fae(i,A,e,t,g,o=""){if(!i||i.length===0)return{ok:!1};const s=new Map,I=[],n=[],B=r(E=>{let l=s.get(E);if(l!=null)return l;const h=e[E];if(!h)return null;const w=h.pos,d=I.length;return I.push([w[0],w[1],w[2]]),s.set(E,d),d},"addVertex");for(const E of i){const l=A[E];if(!l)continue;const h=B(l.i0),w=B(l.i1),d=B(l.i2);h==null||w==null||d==null||n.push([h+1,w+1,d+1])}if(I.length<3||n.length===0)return{ok:!1};const C=I.map(E=>`(${IQ(E[0],g)},${IQ(E[1],g)},${IQ(E[2],g)})`).join(","),a=t.add(`CARTESIAN_POINT_LIST_3D('',(${C}))`),Q=n.map(E=>`(${E[0]},${E[1]},${E[2]})`).join(",");return{ok:!0,faceId:t.add(`TRIANGULATED_FACE('${xd(o,"")}',#${a},(${Q}),$)`)}}c(fae,"TPe");r(fae,"_emitTessellatedFace");var hW;const Dlt=(hW=class{constructor(){this.nextId=1,this.lines=[]}add(A){const e=this.nextId++;return this.lines.push(`#${e}=${A};`),e}},c(hW,"Che2"),hW);r(Dlt,"StepBuilder");let KTi=Dlt;var wW;const ult=(wW=class{constructor(){this.counts=new Map}allocate(A){const e=xd(A,"NAME"),t=this.counts.get(e)||0;return this.counts.set(e,t+1),t===0?e:xd(`${e}[${t}]`)}},c(wW,"ahe2"),wW);r(ult,"NameAllocator");let d8e=ult;function Mlt(i,A){const e=String(A).toLowerCase(),t=i.add("(LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT($,.METRE.))"),g={millimeter:".MILLI.",centimeter:".CENTI.",meter:"$",micron:".MICRO."};if(Object.prototype.hasOwnProperty.call(g,e)){const o=g[e];return o==="$"?t:i.add(`(LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(${o},.METRE.))`)}if(e==="inch"||e==="foot"){const o=e==="inch"?.0254:.3048,s=e==="inch"?"INCH":"FOOT",I=i.add(`LENGTH_MEASURE_WITH_UNIT(LENGTH_MEASURE(${IQ(o,8)}),#${t})`);return i.add(`(CONVERSION_BASED_UNIT('${s}',#${I}) LENGTH_UNIT() NAMED_UNIT(*))`)}return i.add("(LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.))")}c(Mlt,"rJt");r(Mlt,"_buildLengthUnit");function sYe(i,A={}){const e=A.unit||"millimeter",t=Number.isFinite(A.precision)?A.precision:6,g=Number.isFinite(A.scale)?A.scale:1,o=A.applyWorldTransform!==!1,s=A.mergePlanarFaces!==!1,I=A.useTessellatedFaces!==!1,n=A.exportFaces!==!1,B=A.exportEdgesAsPolylines!==!1,C=CzA(A.name||i?.[0]?.name||"part"),a=new KTi,Q=a.add("APPLICATION_CONTEXT('automotive_design')"),E=I?"ap242":"automotive_design";a.add(`APPLICATION_PROTOCOL_DEFINITION('international standard','${E}',2000,#${Q})`);const l=Mlt(a,e),h=a.add("(PLANE_ANGLE_UNIT() NAMED_UNIT(*) SI_UNIT($,.RADIAN.))"),w=a.add("(SOLID_ANGLE_UNIT() NAMED_UNIT(*) SI_UNIT($,.STERADIAN.))"),d=Math.max(1e-9,Math.abs(g)*1e-6),D=a.add(`UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(${Qlt(d,6)}),#${l},'distance_accuracy_value','')`),u=a.add(`(GEOMETRIC_REPRESENTATION_CONTEXT(3) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#${D})) GLOBAL_UNIT_ASSIGNED_CONTEXT((#${l},#${h},#${w})) REPRESENTATION_CONTEXT('',''))`),M=a.add(`PRODUCT_CONTEXT('',#${Q},'mechanical')`),y=a.add(`PRODUCT('${C}','${C}','',(#${M}))`),p=a.add(`PRODUCT_DEFINITION_FORMATION('','',#${y})`),f=a.add(`PRODUCT_DEFINITION_CONTEXT('part definition',#${Q},'design')`),F=a.add(`PRODUCT_DEFINITION('design','',#${p},#${f})`),m=a.add(`PRODUCT_DEFINITION_SHAPE('','',#${F})`),G=[],N=[],S=[],Y=new Map,R=r(H=>{const X=uO(H),oA=`${IQ(X[0],9)},${IQ(X[1],9)},${IQ(X[2],9)}`;let _=Y.get(oA);return _||(_=a.add(`DIRECTION('',(${IQ(X[0],t)},${IQ(X[1],t)},${IQ(X[2],t)}))`),Y.set(oA,_),_)},"getDirectionId");for(let H=0;H<(i||[]).length;H++){const X=i[H];if(!X||typeof X.getMesh!="function")continue;let oA=null;try{if(oA=X.getMesh(),!oA||!oA.vertProperties||!oA.triVerts){S.push(String(X?.name||`solid_${H+1}`));continue}let _=null;if(o){try{typeof X.updateWorldMatrix=="function"?X.updateWorldMatrix(!0,!1):typeof X.updateMatrixWorld=="function"&&X.updateMatrixWorld(!0)}catch{}const GA=X?.matrixWorld;GA?.elements&&GA.elements.length===16&&!Elt(GA.elements)&&(_=GA.elements)}const V=oA.vertProperties,O=oA.triVerts,AA=V.length/3|0,BA=O.length/3|0,rA=new Array(AA),tA=[1/0,1/0,1/0],sA=[-1/0,-1/0,-1/0];for(let GA=0;GA<AA;GA++){const _A=V[GA*3+0],YA=V[GA*3+1],KA=V[GA*3+2],[OA,te,XA]=_?Mae(_,_A,YA,KA):[_A,YA,KA],Ge=OA*g,zA=te*g,ae=XA*g;tA[0]=Math.min(tA[0],Ge),tA[1]=Math.min(tA[1],zA),tA[2]=Math.min(tA[2],ae),sA[0]=Math.max(sA[0],Ge),sA[1]=Math.max(sA[1],zA),sA[2]=Math.max(sA[2],ae);const de=a.add(`CARTESIAN_POINT('',(${IQ(Ge,t)},${IQ(zA,t)},${IQ(ae,t)}))`),we=a.add(`VERTEX_POINT('',#${de})`);rA[GA]={pointId:de,vertexId:we,pos:[Ge,zA,ae]}}const eA=[],K=1e-16,v=sA[0]-tA[0],iA=sA[1]-tA[1],QA=sA[2]-tA[2],gA=Math.hypot(v,iA,QA)||1,IA=Number.isFinite(A.planarNormalTolerance)?A.planarNormalTolerance:2e-4,lA=Number.isFinite(A.planarDistanceTolerance)?A.planarDistanceTolerance:Math.max(2e-5,gA*2e-5),cA=new Array(BA),CA=oA.faceID&&oA.faceID.length===BA?oA.faceID:null,EA=X&&X._idToFaceName instanceof Map?X._idToFaceName:null,z=CA?new Map:null,aA=CA?null:new Map,hA=new d8e,MA=new d8e,fA=new Map,SA=new Map;for(let GA=0;GA<BA;GA++){const _A=O[GA*3+0]>>>0,YA=O[GA*3+1]>>>0,KA=O[GA*3+2]>>>0,OA=rA[_A],te=rA[YA],XA=rA[KA];if(!OA||!te||!XA)continue;const Ge=OA.pos,zA=te.pos,ae=XA.pos,de=yae(zA,Ge),we=yae(ae,Ge),Qe=x5A(de,we),oe=Math.hypot(Qe[0],Qe[1],Qe[2]);if(!oe||oe<K)continue;const ke=[Qe[0]/oe,Qe[1]/oe,Qe[2]/oe],Oe=VG(ke,Ge),ve={i0:_A,i1:YA,i2:KA,normal:ke,d:Oe,e1:de};if(cA[GA]=ve,CA){const gt=CA[GA]>>>0,$e=z.get(gt)||[];$e.push(GA),z.set(gt,$e)}else{const gt=s?pae(ke,Oe,IA,lA):`tri_${GA}`,$e=aA.get(gt)||[];$e.push(GA),aA.set(gt,$e)}}const UA=B||n;if(z){if(s&&UA){const GA=new Map;for(let YA=0;YA<BA;YA++){const KA=cA[YA];if(!KA)continue;const OA=CA[YA]>>>0,te=[[KA.i0,KA.i1],[KA.i1,KA.i2],[KA.i2,KA.i0]];for(const[XA,Ge]of te){const zA=wpA(XA,Ge);let ae=GA.get(zA);ae||(ae={faces:new Set},GA.set(zA,ae)),ae.faces.add(OA)}}const _A=new Map;for(const[YA,KA]of GA.entries()){const OA=[...KA.faces];if(OA.length===0)continue;let te=null;if(OA.length===1)te=`${EA?.get(OA[0])||`FACE_${OA[0]}`}|BOUNDARY`;else{const Ge=EA?.get(OA[0])||`FACE_${OA[0]}`,zA=EA?.get(OA[1])||`FACE_${OA[1]}`,ae=Ge<zA?[Ge,zA]:[zA,Ge];te=`${ae[0]}|${ae[1]}`}const XA=_A.get(te)||[];XA.push(YA),_A.set(te,XA)}for(const[YA,KA]of _A.entries()){if(KA.sort(),KA.length===1){SA.set(KA[0],xd(YA));continue}for(let OA=0;OA<KA.length;OA++)SA.set(KA[OA],xd(`${YA}[${OA}]`))}}for(const[GA,_A]of z.entries()){const YA=EA?.get(GA)||`FACE_${GA}`,KA=GTA(_A,cA);if(I&&n){const OA=dlt(_A,cA,IA,lA);if(OA&&s){for(const te of KA){const XA=hA.allocate(YA),Ge=RTA(te,cA,rA,a,R,t,XA,s&&B?{edgeNameByKey:SA,edgeCurveCache:fA,edgeNameAllocator:MA}:null);if(Ge.ok&&Ge.faceId){eA.push(Ge.faceId);continue}const zA=fae(te,cA,rA,a,t,XA);if(zA.ok&&zA.faceId){eA.push(zA.faceId);continue}for(const ae of te){const de=cA[ae];if(!de)continue;const we=hA.allocate(YA),Qe=d4(de,rA,a,R,t,we);Qe&&eA.push(Qe)}}continue}if(!OA){for(const te of KA){const XA=hA.allocate(YA),Ge=fae(te,cA,rA,a,t,XA);if(Ge.ok&&Ge.faceId)eA.push(Ge.faceId);else for(const zA of te){const ae=cA[zA];if(!ae)continue;const de=hA.allocate(YA),we=d4(ae,rA,a,R,t,de);we&&eA.push(we)}}continue}}if(s&&n){const OA=new Map;for(const te of _A){const XA=cA[te];if(!XA)continue;const Ge=pae(XA.normal,XA.d,IA,lA),zA=OA.get(Ge)||[];zA.push(te),OA.set(Ge,zA)}for(const te of OA.values()){const XA=GTA(te,cA);for(const Ge of XA){const zA=hA.allocate(YA),ae=RTA(Ge,cA,rA,a,R,t,zA,B?{edgeNameByKey:SA,edgeCurveCache:fA,edgeNameAllocator:MA}:null);if(ae.ok&&ae.faceId)eA.push(ae.faceId);else for(const de of Ge){const we=cA[de];if(!we)continue;const Qe=hA.allocate(YA),oe=d4(we,rA,a,R,t,Qe);oe&&eA.push(oe)}}}}else if(n)for(const OA of _A){const te=cA[OA];if(!te)continue;const XA=hA.allocate(YA),Ge=d4(te,rA,a,R,t,XA);Ge&&eA.push(Ge)}}}else if(aA){let GA=0;for(const _A of aA.values()){const YA=s?GTA(_A,cA):[_A],KA=`FACE_${++GA}`;for(const OA of YA){if(s&&n){const te=hA.allocate(KA),XA=RTA(OA,cA,rA,a,R,t,te,s&&B?{edgeNameByKey:SA,edgeCurveCache:fA,edgeNameAllocator:MA}:null);if(XA.ok&&XA.faceId){eA.push(XA.faceId);continue}}if(n)for(const te of OA){const XA=cA[te];if(!XA)continue;const Ge=hA.allocate(KA),zA=d4(XA,rA,a,R,t,Ge);zA&&eA.push(zA)}}}}if(n){if(eA.length===0){S.push(String(X?.name||`solid_${H+1}`));continue}const GA=a.add(`CLOSED_SHELL('',${STA(eA)})`),_A=a.add(`FACETED_BREP('',#${GA})`);G.push(_A)}if(B){const GA=hlt(oA,EA);for(const YA of GA){const KA=Array.isArray(YA.indices)?YA.indices:[];if(KA.length<2)continue;const OA=[];let te=!1;for(const ae of KA){const de=rA[ae]?.pointId;if(!de){te=!0;break}OA.push(`#${de}`)}if(te||OA.length<2)continue;const XA=YA.name||`${YA.faceA}|${YA.faceB}`,Ge=MA.allocate(XA),zA=a.add(`POLYLINE('${xd(Ge)}',(${OA.join(",")}))`);N.push(zA)}const _A=Array.isArray(X?._auxEdges)?X._auxEdges:[];for(const YA of _A){if(!YA)continue;const KA=YA?.name||"CENTERLINE";if(!(YA?.centerline||typeof KA=="string"&&/centerline/i.test(KA)))continue;const OA=Array.isArray(YA?.points)?YA.points:[];if(OA.length<2)continue;const te=[];for(const de of OA){if(!Array.isArray(de)||de.length<3)continue;let we=de[0],Qe=de[1],oe=de[2];if(!(!Number.isFinite(we)||!Number.isFinite(Qe)||!Number.isFinite(oe))){if(o&&_&&!YA?.polylineWorld){const ke=Mae(_,we,Qe,oe);we=ke[0],Qe=ke[1],oe=ke[2]}te.push([we*g,Qe*g,oe*g])}}if(te.length<2)continue;if(YA?.closedLoop&&te.length>=2){const de=te[0],we=te[te.length-1];(de[0]!==we[0]||de[1]!==we[1]||de[2]!==we[2])&&te.push([de[0],de[1],de[2]])}const XA=[];let Ge=!1;for(const de of te){if(!de||de.length<3){Ge=!0;break}const we=a.add(`CARTESIAN_POINT('',(${IQ(de[0],t)},${IQ(de[1],t)},${IQ(de[2],t)}))`);XA.push(`#${we}`)}if(Ge||XA.length<2)continue;const zA=MA.allocate(KA),ae=a.add(`POLYLINE('${xd(zA)}',(${XA.join(",")}))`);N.push(ae)}}}catch{S.push(String(X?.name||`solid_${H+1}`))}finally{try{oA&&typeof oA.delete=="function"&&oA.delete()}catch{}}}const k=[];if(n&&G.length&&k.push(...G),B&&N.length){const H=a.add(`GEOMETRIC_CURVE_SET('EDGES',${STA(N)})`);k.push(H)}if(k.length===0)return{data:"",exported:0,skipped:i?.map(H=>H?.name||"solid")||[]};const b=I?"tessellated":"",L=B?"SHAPE_REPRESENTATION":"ADVANCED_BREP_SHAPE_REPRESENTATION",x=a.add(`${L}('${b}',${STA(k)},#${u})`);a.add(`SHAPE_DEFINITION_REPRESENTATION(#${m},#${x})`);const J=new Date().toISOString().replace(/\.\d+Z$/,""),$=["ISO-10303-21;","HEADER;","FILE_DESCRIPTION(('BREP STEP export'),'2;1');",`FILE_NAME('${C}','${CzA(J)}',('BREP'),('BREP'),'Codex','BREP','');`,`FILE_SCHEMA(('${I?"AP242_MANAGED_MODEL_BASED_3D_ENGINEERING":"AUTOMOTIVE_DESIGN"}'));`,"ENDSEC;","DATA;"],T=["ENDSEC;","END-ISO-10303-21;"];return{data:`${$.join(`