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.
- package/dist/apiExamples/BREP_Booleans.html +2 -2
- package/dist/apiExamples/BREP_Export.html +2 -2
- package/dist/apiExamples/BREP_Primitives.html +2 -2
- package/dist/apiExamples/BREP_Transforms.html +2 -2
- package/dist/apiExamples/Embeded_2D_Sketcher.html +2 -2
- package/dist/apiExamples/Embeded_CAD.html +2 -2
- package/dist/apiExamples/Embeded_CAD_Integration_Test.html +2 -2
- package/dist/assembly-constraint-capture.html +5 -5
- package/dist/assets/{AnnotationRegistry-DxnuBVib.js → AnnotationRegistry-61-QTIl6.js} +1 -1
- package/dist/assets/{AssemblyConstraintRegistry-DHKMQSj6.js → AssemblyConstraintRegistry-DDhkhKoR.js} +1 -1
- package/dist/assets/{FeatureRegistry-C9h4q68e.js → FeatureRegistry-CyK8O2Ca.js} +3 -3
- package/dist/assets/{PartHistory-4fqTqe8m.js → PartHistory-CYHQ9__L.js} +1 -1
- package/dist/assets/{annUtils-C1gESzsQ.js → annUtils-B86URBT5.js} +1 -1
- package/dist/assets/{apiExample_BREP_Booleans-B1xVAOyX.js → apiExample_BREP_Booleans-DdWlLKsQ.js} +1 -1
- package/dist/assets/{apiExample_BREP_Export-CHD3cpsa.js → apiExample_BREP_Export-AUY7EeHW.js} +1 -1
- package/dist/assets/{apiExample_BREP_Primitives-Cxgt1-u1.js → apiExample_BREP_Primitives-g6bMwZLj.js} +1 -1
- package/dist/assets/{apiExample_BREP_Transforms-CZ-klSeH.js → apiExample_BREP_Transforms-DH3-Y9FI.js} +1 -1
- package/dist/assets/{apiExample_Embeded_2D_Sketcher-Bpi0fqAV.js → apiExample_Embeded_2D_Sketcher-B8EeF-Gj.js} +1 -1
- package/dist/assets/{apiExample_Embeded_CAD-B_SPpcLZ.js → apiExample_Embeded_CAD-7roRFtt7.js} +1 -1
- package/dist/assets/{apiExample_Embeded_CAD_Integration_Test-DjKBLQ49.js → apiExample_Embeded_CAD_Integration_Test-Pb0iBwIv.js} +1 -1
- package/dist/assets/{assemblyConstraintDialogs-8hg4PlL4.js → assemblyConstraintDialogs-BJX50LIF.js} +1 -1
- package/dist/assets/{brep-kernel-QpBwDdca.js → brep-kernel-BaJWJnmy.js} +1 -1
- package/dist/assets/{browserTests-CfVrmhte.js → browserTests-DxakKnoa.js} +1 -1
- package/dist/assets/{dialogCapturePageFactory-C9unVBhR.js → dialogCapturePageFactory-B5p-TYIP.js} +1 -1
- package/dist/assets/{featureDialogs-Cx7p1XpK.js → featureDialogs-CnBa1DyN.js} +1 -1
- package/dist/assets/{featureDialogs-D7xm3LIj.js → featureDialogs-DbmvJ-NA.js} +1 -1
- package/dist/assets/{index.es-Due8Wdrm.js → index.es-kd2D9M8K.js} +1 -1
- package/dist/assets/{javascript-CvgRKapH.js → javascript-CAvRMK4c.js} +1 -1
- package/dist/assets/{main-cad-DtMN0iSg.js → main-cad-Dojzs8d6.js} +6 -6
- package/dist/assets/{pmiDialogs-Bxu3FGJy.js → pmiDialogs-DQBW7aoF.js} +1 -1
- package/dist/assets/{test-Ccoy9ITq.js → test-ByMinHh_.js} +3 -3
- package/dist/cad.html +7 -7
- package/dist/feature-dialog-capture.html +4 -4
- package/dist/pmi-dialog-capture.html +5 -5
- package/dist/test.html +1 -1
- package/dist/viewer.html +7 -7
- package/dist-kernel/brep-kernel.js +1 -1
- package/package.json +1 -1
- package/src/BREP/SolidMethods/manifoldOps.js +5 -0
|
@@ -4617,7 +4617,7 @@ void main() {
|
|
|
4617
4617
|
overflow-wrap: anywhere;
|
|
4618
4618
|
}
|
|
4619
4619
|
.cmw-select-wrap option { white-space: normal; }
|
|
4620
|
-
`,document.head.appendChild(e)}};h(z_,"CADmaterialWidget");let Lv=z_;function yr(){const r=document.createElement("div");return r.className="cmw-row",r}h(yr,"makeRightSpan");const k_=class k_ extends xo{constructor(e){super(e,fn.EDGE.BASE),this.faces=[],this.name=null,this.type="EDGE",this.renderOrder=2,this.closedLoop=!1,un.attach(this)}length(){const e=new H,t=new H;let n=0;const i=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null,s=h((a,c,l,u,f,d)=>{e.set(a,c,l).applyMatrix4(this.matrixWorld),t.set(u,f,d).applyMatrix4(this.matrixWorld),n+=e.distanceTo(t)},"addSeg");if(i&&i.length>=2){for(let a=0;a<i.length-1;a++){const c=i[a],l=i[a+1];s(c[0],c[1],c[2],l[0],l[1],l[2])}return n}const o=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(o&&o.itemSize===3&&o.count>=2){for(let a=0;a<o.count-1;a++)s(o.getX(a),o.getY(a),o.getZ(a),o.getX(a+1),o.getY(a+1),o.getZ(a+1));return n}return 0}points(e=!0){const t=new H,n=[],i=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null;if(i&&i.length){for(let o=0;o<i.length;o++){const a=i[o];t.set(a[0],a[1],a[2]),e&&t.applyMatrix4(this.matrixWorld),n.push({x:t.x,y:t.y,z:t.z})}return n}const s=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(s&&s.itemSize===3&&s.count>=1)for(let o=0;o<s.count;o++)t.set(s.getX(o),s.getY(o),s.getZ(o)),e&&t.applyMatrix4(this.matrixWorld),n.push({x:t.x,y:t.y,z:t.z});return n}collapseToPoint(){const e=this.parentSolid||this.parent||null,t=Array.isArray(e?._vertProperties)?e._vertProperties:null;if(!e||!t||t.length<3)return this;if(this?.userData?.auxEdge)return this;const n=QI(this,e);if(!n.length)return this;let i=0,s=0,o=0,a=0;for(const p of n){const m=p*3|0;m<0||m+2>=t.length||(i+=t[m+0],s+=t[m+1],o+=t[m+2],a++)}if(!a)return this;const c=1/a,l=i*c,u=s*c,f=o*c;for(const p of n){const m=p*3|0;m<0||m+2>=t.length||(t[m+0]=l,t[m+1]=u,t[m+2]=f)}const d=t.length/3|0;e._vertKeyToIndex=new Map;for(let p=0;p<d;p++){const m=p*3;e._vertKeyToIndex.set(`${t[m+0]},${t[m+1]},${t[m+2]}`,p)}e._dirty=!0,e._faceIndex=null;try{e._manifold&&typeof e._manifold.delete=="function"&&e._manifold.delete()}catch{}e._manifold=null;try{typeof e._manifoldize=="function"&&e._manifoldize()}catch(p){console.warn(`[Edge.collapseToPoint] Manifold rebuild failed for edge "${this.name||"UNKNOWN"}":`,p?.message||p)}try{typeof e.visualize=="function"&&e.visualize()}catch(p){console.warn(`[Edge.collapseToPoint] Solid visualize failed for edge "${this.name||"UNKNOWN"}":`,p?.message||p)}return this}setMetadata(e){return this.parentSolid&&typeof this.parentSolid.setEdgeMetadata=="function"&&this.parentSolid.setEdgeMetadata(this.name,e),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getEdgeMetadata=="function"?this.parentSolid.getEdgeMetadata(this.name):null}};h(k_,"Edge");let vo=k_;function QI(r,e){const t=Array.isArray(e?._vertProperties)?e._vertProperties:null;if(!t||t.length<3)return[];const n=(t.length/3|0)-1;let i=[];try{i=typeof e.getBoundaryEdgePolylines=="function"?e.getBoundaryEdgePolylines()||[]:[]}catch{i=[]}const s=eN(r,i);if(s&&Array.isArray(s.indices)&&s.indices.length){const o=[],a=new Set;for(const c of s.indices){const l=Number(c);!Number.isInteger(l)||l<0||l>n||a.has(l)||(a.add(l),o.push(l))}if(o.length)return o}return nN(r?.userData?.polylineLocal,t)}h(QI,"resolveEdgeVertexIndices");function eN(r,e){if(!Array.isArray(e)||e.length===0)return null;const t=typeof r?.name=="string"&&r.name?r.name:null;if(t){const l=e.find(u=>u&&u.name===t);if(l)return l}const n=r?.userData?.faceA,i=r?.userData?.faceB;let s=e;if(n&&i&&(s=e.filter(l=>{if(!l)return!1;const u=l.faceA,f=l.faceB;return u===n&&f===i||u===i&&f===n}),s.length===1))return s[0];const o=Array.isArray(r?.userData?.polylineLocal)?r.userData.polylineLocal:null;if(!o||o.length<2)return s[0]||null;let a=null,c=1/0;for(const l of s){const u=tN(o,l?.positions);u<c&&(c=u,a=l)}return a}h(eN,"findMatchingBoundaryPolyline");function tN(r,e){if(!Array.isArray(r)||r.length<2||!Array.isArray(e)||e.length<2)return 1/0;const t=r[0],n=r[r.length-1],i=e[0],s=e[e.length-1];if(!uo(t)||!uo(n)||!uo(i)||!uo(s))return 1/0;const o=pl(t,i)+pl(n,s),a=pl(t,s)+pl(n,i);return Math.min(o,a)}h(tN,"polylineEndpointScore");function nN(r,e){if(!Array.isArray(r)||r.length===0)return[];const t=e.length/3|0,n=new Map;for(let o=0;o<t;o++){const a=o*3,c=`${e[a+0]},${e[a+1]},${e[a+2]}`;n.has(c)||n.set(c,o)}const i=[],s=new Set;for(const o of r){if(!uo(o))continue;const a=`${o[0]},${o[1]},${o[2]}`;let c=n.get(a);c===void 0&&(c=iN(e,o,1e-9)),!(!Number.isInteger(c)||c<0||s.has(c))&&(s.add(c),i.push(c))}return i}h(nN,"resolveIndicesFromPolylinePoints");function iN(r,e,t=1e-9){if(!Array.isArray(r)||!uo(e)||!Number.isFinite(t)||t<=0)return-1;const n=t*t,i=r.length/3|0;let s=-1,o=n;for(let a=0;a<i;a++){const c=a*3,l=r[c+0]-e[0],u=r[c+1]-e[1],f=r[c+2]-e[2],d=l*l+u*u+f*f;d<=o&&(o=d,s=a)}return s}h(iN,"findNearestVertexIndex");function pl(r,e){const t=r[0]-e[0],n=r[1]-e[1],i=r[2]-e[2];return t*t+n*n+i*i}h(pl,"pointDistanceSq$1");function uo(r){return Array.isArray(r)&&r.length===3&&Number.isFinite(r[0])&&Number.isFinite(r[1])&&Number.isFinite(r[2])}h(uo,"isPoint3");const V_=class V_ extends yt{constructor(e=[0,0,0],t={}){super(),this.type="VERTEX",this.name=t.name||`VERTEX(${e[0]},${e[1]},${e[2]})`,this.position.set(e[0]||0,e[1]||0,e[2]||0);const n=new it;n.setAttribute("position",new $e([0,0,0],3));const i=fn?.VERTEX?.BASE||new Jn({color:"#ffb703",size:6,sizeAttenuation:!1});this._point=new Ss(n,i),this.add(this._point),un.attach(this)}};h(V_,"Vertex");let bf=V_;function dm(r,e,t,n,i,s,o,a,c){const l=n-r,u=i-e,f=s-t,d=o-r,p=a-e,m=c-t,_=u*m-f*p,y=f*d-l*m,g=l*p-u*d;return .5*Math.hypot(_,y,g)}h(dm,"computeTriangleArea");const hm=1e-9,ht=1e-12;function pm(r,e="FACE"){const n=(r==null?"":String(r)).trim();return n&&n.replace(/[:[\]]+/g,"_").replace(/\s+/g,"_").replace(/[^A-Za-z0-9_.-]/g,"_")||e}h(pm,"sanitizeToken$1");function Yt(r,e){const t=r<e?r:e,n=r<e?e:r;return`${t}|${n}`}h(Yt,"edgeKey");function si(r){r&&typeof r=="object"&&(r._cppSolidCoreSyncStamp=null)}h(si,"invalidateCppSolidCoreCache");function fo(r,e){const t=e>0?1/e:1e6;return[Math.round(r.x*t),Math.round(r.y*t),Math.round(r.z*t)].join(",")}h(fo,"pointKey$1");function Fs(r,e,t){return new H().subVectors(e,r).cross(new H().subVectors(t,r))}h(Fs,"triangleNormal");function Xm(r,e,t){return Fs(r,e,t).length()*.5}h(Xm,"triangleArea");function qm(r){const e=r?.userData?.faceName??r?.faceName??r?.name??null;return e==null?null:String(e).trim()||null}h(qm,"getFaceLabel");function rN(r){const e=Array.isArray(r)?r:r==null?[]:[r],t=[],n=new Set;for(const i of e){const s=typeof i=="string"?i:i?.userData?.faceName??i?.faceName??i?.name??null,o=String(s||"").trim();!o||n.has(o)||(n.add(o),t.push(o))}return t}h(rN,"getFaceLabelList");function sN(r,e){const t=rN(r.adjacentNormalFaceNames??r.smoothAdjacentNormalFaceNames??r.selectedFaceNames),n=String(e||"").trim(),i=t.filter(s=>s&&s!==n);return i.length?new Set(i):null}h(sN,"getAdjacentNormalFaceFilter");function oN(r){const e=r?.parentSolid||(String(r?.parent?.type||"").toUpperCase()==="SOLID"?r.parent:null);return String(e?.uuid||e?.id||e?.name||"NO_OWNER")}h(oN,"getFaceOwnerKey");function vl(r,e){return r<e?`${r}|${e}`:`${e}|${r}`}h(vl,"unorderedPointPairKey");function aN(r,e){return!r||!e||r.sourceFaceName!=null&&(e.sourceFaceName=r.sourceFaceName),e}h(aN,"copyTriangleMetadata");function cN(r,e={}){const t=Array.isArray(r)?r.filter(M=>M?.geometry):[];if(t.length<=1)return t.length?[t]:[];const n=new H;let i=1/0,s=1/0,o=1/0,a=-1/0,c=-1/0,l=-1/0;for(const M of t){try{M.updateMatrixWorld?.(!0)}catch{}const v=M.geometry?.getAttribute?.("position");if(!(!v||v.itemSize!==3))for(let b=0;b<v.count;b++)n.set(v.getX(b),v.getY(b),v.getZ(b)).applyMatrix4(M.matrixWorld),n.x<i&&(i=n.x),n.y<s&&(s=n.y),n.z<o&&(o=n.z),n.x>a&&(a=n.x),n.y>c&&(c=n.y),n.z>l&&(l=n.z)}const u=Number.isFinite(i)?Math.max(1,Math.hypot(a-i,c-s,l-o)):1,f=Math.max(Number(e.weldTolerance)||0,Math.max(1e-6,u*1e-7)),d=Number.isFinite(Number(e.minSharedNormalDot))?Math.max(-1,Math.min(1,Number(e.minSharedNormalDot))):-1,p=Number.isFinite(Number(e.minSharedEdgeNormalDot))?Math.max(-1,Math.min(1,Number(e.minSharedEdgeNormalDot))):null,m=Number.isFinite(Number(e.minPlanarRatio))?Math.max(0,Math.min(1,Number(e.minPlanarRatio))):0,_=h((M,v)=>{if(!(m>0))return 1;const b=M?.geometry?.getAttribute?.("position"),T=M?.geometry?.getIndex?.()||null;if(!b||b.itemSize!==3||b.count<3||!v||v.lengthSq()<=ht)return 0;const C=new H,I=new H,P=new H;let N=0,D=0;const L=T?T.count/3|0:b.count/3|0;for(let R=0;R<L;R++){const q=T?T.getX(R*3+0)>>>0:R*3+0,$=T?T.getX(R*3+1)>>>0:R*3+1,U=T?T.getX(R*3+2)>>>0:R*3+2;C.set(b.getX(q),b.getY(q),b.getZ(q)).applyMatrix4(M.matrixWorld),I.set(b.getX($),b.getY($),b.getZ($)).applyMatrix4(M.matrixWorld),P.set(b.getX(U),b.getY(U),b.getZ(U)).applyMatrix4(M.matrixWorld);const K=Fs(C,I,P),W=K.length();W>ht&&(N+=Math.abs(K.multiplyScalar(1/W).dot(v))*W,D+=W)}return D>ht?N/D:0},"computeFacePlanarRatio"),y=t.map(M=>{try{const v=typeof M?.getAverageNormal=="function"?M.getAverageNormal():null;if(v&&v.lengthSq?.()>ht)return v.clone().normalize()}catch{}return null}),g=t.map((M,v)=>_(M,y[v])),x=new Map;for(let M=0;M<t.length;M++){const v=t[M],b=v.geometry?.getAttribute?.("position"),T=v.geometry?.getIndex?.()||null;if(!b||b.itemSize!==3||b.count<3)continue;const C=[];for(let R=0;R<b.count;R++)C.push(new H(b.getX(R),b.getY(R),b.getZ(R)).applyMatrix4(v.matrixWorld));const I=new Array(C.length);for(let R=0;R<C.length;R++){const q=fo(C[R],f);I[R]=q}const P=new Map,N=new Map,D=T?T.count/3|0:b.count/3|0;for(let R=0;R<D;R++){const q=T?T.getX(R*3+0)>>>0:R*3+0,$=T?T.getX(R*3+1)>>>0:R*3+1,U=T?T.getX(R*3+2)>>>0:R*3+2,K=Fs(C[q],C[$],C[U]);for(const[W,ne]of[[q,$],[$,U],[U,q]]){const Q=I[W],k=I[ne];if(!Q||!k||Q===k)continue;const B=vl(Q,k);P.set(B,(P.get(B)||0)+1);let z=N.get(B);z||(z=new H,N.set(B,z)),z.add(K)}}const L=oN(v);for(const[R,q]of P.entries()){if(q!==1)continue;const $=`${L}::${R}`;let U=x.get($);U||(U=[],x.set($,U));const K=N.get(R)||null;U.push({faceIndex:M,normal:K&&K.lengthSq()>ht?K.clone().normalize():null})}}const w=new Array(t.length).fill(null).map((M,v)=>v),S=h(M=>{let v=M;for(;w[v]!==v;)v=w[v];for(;w[M]!==M;){const b=w[M];w[M]=v,M=b}return v},"find"),E=h((M,v)=>{const b=typeof M=="number"?M:M?.faceIndex>>>0,T=typeof v=="number"?v:v?.faceIndex>>>0;if(b===T||b>=t.length||T>=t.length)return;if(p!=null){const P=M?.normal||y[b],N=v?.normal||y[T];if(!P||!N||Math.abs(P.dot(N))<p)return}else{if(m>0&&(g[b]<m||g[T]<m))return;if(d>-1){const P=y[b],N=y[T];if(!P||!N||Math.abs(P.dot(N))<d)return}}if(d>-1&&p!=null){const P=y[b],N=y[T];if(!P||!N||Math.abs(P.dot(N))<d)return}const C=S(b),I=S(T);C!==I&&(w[I]=C)},"union");for(const M of x.values())if(!(!Array.isArray(M)||M.length<2))for(let v=1;v<M.length;v++)E(M[0],M[v]);const A=new Map;for(let M=0;M<t.length;M++){const v=S(M);let b=A.get(v);b||(b=[],A.set(v,b)),b.push(t[M])}return Array.from(A.values())}h(cN,"groupConnectedFacesBySharedEdges");function lN(r,e,t){const n=new H().subVectors(t,e),i=n.lengthSq();if(!(i>ht))return r.distanceToSquared(e);const s=Math.max(0,Math.min(1,new H().subVectors(r,e).dot(n)/i)),o=e.clone().add(n.multiplyScalar(s));return r.distanceToSquared(o)}h(lN,"pointToSegmentDistanceSq");function _h(r,e){if(!Array.isArray(e)||e.length<2)return 1/0;let t=1/0;for(let n=0;n+1<e.length;n++){const i=lN(r,e[n],e[n+1]);i<t&&(t=i)}return t}h(_h,"pointToPolylineDistanceSq");function uN(r,e,t,n){const i=new H().subVectors(t,e),s=new H().subVectors(n,e),o=new H().subVectors(r,e),a=i.dot(o),c=s.dot(o);if(a<=0&&c<=0)return r.distanceToSquared(e);const l=new H().subVectors(r,t),u=i.dot(l),f=s.dot(l);if(u>=0&&f<=u)return r.distanceToSquared(t);const d=a*f-u*c;if(d<=0&&a>=0&&u<=0){const E=a/(a-u);return r.distanceToSquared(e.clone().add(i.multiplyScalar(E)))}const p=new H().subVectors(r,n),m=i.dot(p),_=s.dot(p);if(_>=0&&m<=_)return r.distanceToSquared(n);const y=m*c-a*_;if(y<=0&&c>=0&&_<=0){const E=c/(c-_);return r.distanceToSquared(e.clone().add(s.multiplyScalar(E)))}const g=u*_-m*f;if(g<=0&&f-u>=0&&m-_>=0){const E=new H().subVectors(n,t),A=(f-u)/(f-u+(m-_));return r.distanceToSquared(t.clone().add(E.multiplyScalar(A)))}const x=1/(g+y+d),w=y*x,S=d*x;return r.distanceToSquared(e.clone().add(i.multiplyScalar(w)).add(s.multiplyScalar(S)))}h(uN,"pointToTriangleDistanceSq");function fN(r){const e=Array.isArray(r?.edges)?r.edges:[];if(!e.length)return[];const t=r?.parentSolid||(String(r?.parent?.type||"").toUpperCase()==="SOLID"?r.parent:null);try{t?.updateMatrixWorld?.(!0)}catch{}const n=t?.matrixWorld||new tt,i=[];for(let s=0;s<e.length;s++){const o=e[s],c=(Array.isArray(o?.userData?.polylineLocal)?o.userData.polylineLocal:[]).map(l=>Array.isArray(l)?new H(Number(l[0])||0,Number(l[1])||0,Number(l[2])||0).applyMatrix4(n):l&&Number.isFinite(Number(l.x))&&Number.isFinite(Number(l.y))&&Number.isFinite(Number(l.z))?new H(Number(l.x),Number(l.y),Number(l.z)).applyMatrix4(n):null).filter(Boolean);c.length<2||i.push({name:String(o?.name||o?.userData?.edgeName||`EDGE_${s}`).trim()||`EDGE_${s}`,key:String(o?.uuid||o?.name||`EDGE_${s}`),polyline:c})}return i}h(fN,"getSourceEdgePolylines");function dN(r,e,t,n,i){const s=fN(r);if(!s.length||!Array.isArray(e)||!Array.isArray(t))return;const o=Math.max(Number(i)*32,Number(n)*1e-5,1e-5),a=o*o;for(const c of e)for(const l of c?.edges||[]){const u=t[l.start],f=t[l.end];if(!u||!f)continue;const d=u.clone().add(f).multiplyScalar(.5);let p=null,m=1/0;for(const _ of s){const y=Math.max(_h(u,_.polyline),_h(d,_.polyline),_h(f,_.polyline));y<m&&(m=y,p=_)}p&&m<=a&&(l.sourceEdgeName=p.name,l.sourceEdgeKey=p.key)}}h(dN,"assignSourceEdgesToBoundaryLoops");function hN(r,e,t={}){if(t.disableAdjacentBoundaryNormals===!0)return{candidateEdges:0,acceptedEdges:0,contributionCount:0,contributedVertexCount:0,dotThreshold:null,weightScale:0,faceFilterCount:0,faceFilterNames:[]};const n=r?.parentSolid||(String(r?.parent?.type||"").toUpperCase()==="SOLID"?r.parent:null),i=qm(r),s=sN(t,i),o=Array.isArray(n?._triVerts)?n._triVerts:[],a=Array.isArray(n?._triIDs)?n._triIDs:[],c=Array.isArray(n?._vertProperties)?n._vertProperties:[],l=o.length/3|0,u=Math.max(-1,Math.min(1,Number.isFinite(Number(t.adjacentNormalDotThreshold))?Number(t.adjacentNormalDotThreshold):Number.isFinite(Number(t.smoothAdjacentNormalDotThreshold))?Number(t.smoothAdjacentNormalDotThreshold):.85)),f=Math.max(0,Number.isFinite(Number(t.adjacentNormalWeightScale))?Number(t.adjacentNormalWeightScale):1),d=h((W={})=>({candidateEdges:Number(W.candidateEdges||0),acceptedEdges:Number(W.acceptedEdges||0),contributionCount:Number(W.contributionCount||0),contributedVertexCount:Number(W.contributedVertexCount||0),dotThreshold:u,weightScale:f,faceFilterCount:s?.size||0,faceFilterNames:s?Array.from(s):[]}),"makeStats");if(!n||!i)return d();const p=Array.isArray(e?.boundaryDirectedEdges)?e.boundaryDirectedEdges:[],m=Array.isArray(e?.vertices)?e.vertices:[],_=Array.isArray(e?.vertexNormals)?e.vertexNormals:[];if(!p.length||!m.length||!_.length)return d();const y=Math.max(Number(e?.weldTolerance)||0,1e-8);if(f<=0)return d();const g=new Map,x=new Map;for(const W of p){const ne=W?.start>>>0,Q=W?.end>>>0,k=m[ne],B=m[Q];if(!k||!B)continue;const z=fo(k,y),X=fo(B,y);g.set(z,ne),g.set(X,Q),x.set(vl(z,X),!0)}if(!x.size)return d();const w=n?._idToFaceName instanceof Map?n._idToFaceName:new Map,S=new tt;try{n.updateMatrixWorld?.(!0),S.copy(n.matrixWorld||new tt)}catch{S.identity()}const E=new Map,A=new Map,M=new Set,b=t.equalAdjacentBoundaryNormals===!0||String(t.sharedBoundaryNormalMode||"").toLowerCase()==="equal"?new Map:null;let T=0,C=0,I=0;const P=h(W=>[Math.round(W.x*1e6),Math.round(W.y*1e6),Math.round(W.z*1e6)].join(","),"normalKey"),N=h(W=>{if(!b)return null;let ne=b.get(W);if(ne)return ne;const Q=_[W]?.clone?.()||null;return!Q||Q.lengthSq()<=ht?null:(Q.normalize(),ne={sum:Q.clone(),keys:new Set([P(Q)])},b.set(W,ne),ne)},"getEqualBoundaryNormalBucket"),D=h((W={})=>{if(b?.size)for(const[ne,Q]of b.entries())!Q?.sum||Q.sum.lengthSq()<=ht||_[ne].copy(Q.sum);return d(W)},"finalizeStats"),L=h((W,ne,Q)=>{const k=g.get(W);if(k==null)return!1;const B=_[k];if(!B||B.lengthSq()<=ht)return!1;if(b){const V=N(k);if(!V)return!1;const te=P(ne);return V.keys.has(te)?!1:(V.keys.add(te),V.sum.add(ne),M.add(k),I+=1,!0)}const z=Math.max(B.length(),hm),X=Math.min(Q,z)*f;return X>hm?(B.add(ne.clone().multiplyScalar(X)),M.add(k),I+=1,!0):!1},"addContributionForPointKey"),R=h(W=>{if(!Array.isArray(W)||W.length!==3)return;const ne=W.map(V=>fo(V,y));let Q=!1;for(const[V,te]of[[0,1],[1,2],[2,0]])if(x.has(vl(ne[V],ne[te]))){Q=!0,T+=1;break}if(!Q)return;const k=Fs(W[0],W[1],W[2]),B=k.length();if(!(B>ht))return;const z=k.multiplyScalar(1/B);let X=!1;for(let V=0;V<3;V++){const te=g.get(ne[V]);if(te==null)continue;const ce=_[te]?.clone?.()||null;if(!ce||ce.lengthSq()<=ht)continue;ce.normalize();const le=z.dot(ce);let ue=null;le>=u?ue=z:-le>=u&&(ue=z.clone().multiplyScalar(-1)),ue&&L(ne[V],ue,B)&&(X=!0)}X&&(C+=1)},"processAdjacentTriangle");try{const W=typeof n.getFaces=="function"?n.getFaces(!1)||[]:[];if(Array.isArray(W)&&W.length){for(const ne of W){const Q=String(ne?.faceName||"").trim();if(!(!Q||Q===i)&&!(s&&!s.has(Q)))for(const k of ne?.triangles||[]){const B=Array.isArray(k?.p1)?k.p1:null,z=Array.isArray(k?.p2)?k.p2:null,X=Array.isArray(k?.p3)?k.p3:null;!B||!z||!X||R([new H(B[0]||0,B[1]||0,B[2]||0).applyMatrix4(S),new H(z[0]||0,z[1]||0,z[2]||0).applyMatrix4(S),new H(X[0]||0,X[1]||0,X[2]||0).applyMatrix4(S)])}}if(T>0||l===0||a.length<l||c.length<9)return D({candidateEdges:T,acceptedEdges:C,contributionCount:I,contributedVertexCount:M.size})}}catch{}if(l===0||a.length<l||c.length<9)return D({candidateEdges:T,acceptedEdges:C,contributionCount:I,contributedVertexCount:M.size});const q=h(W=>{const ne=W>>>0;let Q=E.get(ne);if(Q)return Q;const k=ne*3;return Q=new H(Number(c[k+0])||0,Number(c[k+1])||0,Number(c[k+2])||0).applyMatrix4(S),E.set(ne,Q),Q},"getParentPoint"),$=h(W=>{const ne=W>>>0;let Q=A.get(ne);return Q||(Q=fo(q(ne),y),A.set(ne,Q),Q)},"getParentPointKey"),U=h((W,ne,Q)=>L($(W),ne,Q),"addContribution"),K=new H;for(let W=0;W<l;W++){const ne=String(w.get(a[W])||"").trim();if(ne===i||s&&!s.has(ne))continue;const Q=o[W*3+0]>>>0,k=o[W*3+1]>>>0,B=o[W*3+2]>>>0,z=[[Q,k],[k,B],[B,Q]];let X=!1;for(const[ae,he]of z){const Ne=$(ae),J=$(he);if(x.has(vl(Ne,J))){X=!0,T+=1;break}}if(!X)continue;const V=q(Q),te=q(k),ce=q(B);K.copy(Fs(V,te,ce));const le=K.length();if(!(le>ht))continue;const ue=K.multiplyScalar(1/le);let re=!1;for(const ae of[Q,k,B]){const he=g.get($(ae));if(he==null)continue;const Ne=_[he]?.clone?.()||null;if(!Ne||Ne.lengthSq()<=ht)continue;Ne.normalize();const J=ue.dot(Ne);let Be=null;J>=u?Be=ue:-J>=u&&(Be=ue.clone().multiplyScalar(-1)),Be&&U(ae,Be,le)&&(re=!0)}re&&(C+=1)}return D({candidateEdges:T,acceptedEdges:C,contributionCount:I,contributedVertexCount:M.size})}h(hN,"addSmoothAdjacentBoundaryNormals");function Mt(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=e.length/3|0;if(!t)return{boundaryEdgeCount:0,nonManifoldEdgeCount:0,triangleCount:0};const n=new Map;for(let o=0;o<t;o++){const a=e[o*3]>>>0,c=e[o*3+1]>>>0,l=e[o*3+2]>>>0;for(const[u,f]of[[a,c],[c,l],[l,a]]){const d=Yt(u,f);n.set(d,(n.get(d)||0)+1)}}let i=0,s=0;for(const o of n.values())o===1?i+=1:o!==2&&(s+=1);return{boundaryEdgeCount:i,nonManifoldEdgeCount:s,triangleCount:t}}h(Mt,"analyzeMeshTopology");function us(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=e.length/3|0;if(!t)return{sameDirectionEdgeCount:0,oppositeDirectionEdgeCount:0,ambiguousEdgeCount:0};const n=new Map,i=h((c,l)=>{const u=Yt(c,l);let f=n.get(u);f||(f=[],n.set(u,f)),f.push([c,l])},"addUse");for(let c=0;c<t;c++){const l=e[c*3]>>>0,u=e[c*3+1]>>>0,f=e[c*3+2]>>>0;i(l,u),i(u,f),i(f,l)}let s=0,o=0,a=0;for(const c of n.values()){if(c.length!==2){a+=1;continue}c[0][0]===c[1][0]&&c[0][1]===c[1][1]?s+=1:o+=1}return{sameDirectionEdgeCount:s,oppositeDirectionEdgeCount:o,ambiguousEdgeCount:a}}h(us,"analyzeTriangleOrientation");function is(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=e.length/3|0;if(!n||t.length<9)return 0;const i=new Map,s=h((f,d,p)=>{const m=Yt(f,d);let _=i.get(m);_||(_=[],i.set(m,_)),_.push({triIndex:p,a:f,b:d})},"addUse");for(let f=0;f<n;f++){const d=e[f*3+0]>>>0,p=e[f*3+1]>>>0,m=e[f*3+2]>>>0;s(d,p,f),s(p,m,f),s(m,d,f)}const o=Array.from({length:n},()=>[]);for(const f of i.values()){if(f.length!==2)continue;const d=f[0],p=f[1],m=d.a===p.a&&d.b===p.b;o[d.triIndex].push({triIndex:p.triIndex,sameDirection:m}),o[p.triIndex].push({triIndex:d.triIndex,sameDirection:m})}const a=new Int8Array(n);a.fill(-1);for(let f=0;f<n;f++){if(a[f]!==-1)continue;a[f]=0;const d=[f];for(;d.length;){const p=d.pop(),m=a[p];for(const _ of o[p]){const y=m^(_.sameDirection?1:0);a[_.triIndex]===-1&&(a[_.triIndex]=y,d.push(_.triIndex))}}}let c=0;for(let f=0;f<n;f++){if(a[f]!==1)continue;const d=f*3,p=e[d+1];e[d+1]=e[d+2],e[d+2]=p,c+=1}const l=h(f=>{const d=f*3,p=e[d+1];e[d+1]=e[d+2],e[d+2]=p},"flipTriangle"),u=h(()=>{const f=new Map,d=h((y,g,x)=>{const w=Yt(y,g);let S=f.get(w);S||(S=[],f.set(w,S)),S.push({triIndex:x,a:y,b:g})},"addLocalUse");for(let y=0;y<n;y++){const g=e[y*3+0]>>>0,x=e[y*3+1]>>>0,w=e[y*3+2]>>>0;d(g,x,y),d(x,w,y),d(w,g,y)}const p=new Uint8Array(n),m=new Uint8Array(n);let _=0;for(const y of f.values()){if(y.length!==2)continue;y[0].a===y[1].a&&y[0].b===y[1].b?(_+=1,p[y[0].triIndex]+=1,p[y[1].triIndex]+=1):(m[y[0].triIndex]+=1,m[y[1].triIndex]+=1)}return{sameCount:_,sameByTri:p,oppositeByTri:m}},"orientationStats");for(let f=0;f<16;f++){const d=u();if(d.sameCount===0)break;let p=0;for(let m=0;m<n;m++)d.sameByTri[m]<=d.oppositeByTri[m]||(l(m),c+=1,p+=1);if(!p)break}for(let f=0;f<64;f++){let d=u();if(d.sameCount===0)break;const p=[];for(let _=0;_<n;_++)d.sameByTri[_]&&p.push({triIndex:_,score:d.sameByTri[_]*2-d.oppositeByTri[_]});p.sort((_,y)=>y.score-_.score||_.triIndex-y.triIndex);let m=!1;for(const _ of p){if(d=u(),d.sameCount===0||!d.sameByTri[_.triIndex])break;const y=d.sameCount;l(_.triIndex),u().sameCount<y?(c+=1,m=!0):l(_.triIndex)}if(!m)break}return c>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)),c}h(is,"orientSolidTrianglesByAdjacency");function rs(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=e.length/3|0;if(!n||t.length<9)return 0;const i=new Map,s=h((u,f,d)=>{const p=Yt(u,f);let m=i.get(p);m||(m=[],i.set(p,m)),m.push(d)},"addUse");for(let u=0;u<n;u++){const f=e[u*3+0]>>>0,d=e[u*3+1]>>>0,p=e[u*3+2]>>>0;s(f,d,u),s(d,p,u),s(p,f,u)}const o=Array.from({length:n},()=>[]);for(const u of i.values())u.length===2&&(o[u[0]].push(u[1]),o[u[1]].push(u[0]));const a=h(u=>{const f=e[u*3+0]>>>0,d=e[u*3+1]>>>0,p=e[u*3+2]>>>0,m=t[f*3+0],_=t[f*3+1],y=t[f*3+2],g=t[d*3+0],x=t[d*3+1],w=t[d*3+2],S=t[p*3+0],E=t[p*3+1],A=t[p*3+2];return(m*(x*A-w*E)-_*(g*A-w*S)+y*(g*E-x*S))/6},"signedVolume"),c=new Uint8Array(n);let l=0;for(let u=0;u<n;u++){if(c[u])continue;const f=[],d=[u];c[u]=1;let p=0;for(;d.length;){const m=d.pop();f.push(m),p+=a(m);for(const _ of o[m])c[_]||(c[_]=1,d.push(_))}if(p<-ht)for(const m of f){const _=m*3,y=e[_+1];e[_+1]=e[_+2],e[_+2]=y,l+=1}}return l>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)),l}h(rs,"orientSolidComponentsBySignedVolume");function Yn(r,e){const t=Math.max(Number(e)||0,0),n=Array.isArray(r?._vertProperties)?r._vertProperties:[],i=Array.isArray(r?._triVerts)?r._triVerts:[],s=Array.isArray(r?._triIDs)?r._triIDs:[],o=n.length/3|0,a=i.length/3|0;if(!(t>0)||!o||!a||s.length<a)return{weldedVertexCount:0,removedTriangleCount:0};const c=1/t,l=h(x=>[Math.round((Number(n[x*3+0])||0)*c),Math.round((Number(n[x*3+1])||0)*c),Math.round((Number(n[x*3+2])||0)*c)].join(","),"keyForIndex"),u=new Int32Array(o);u.fill(-1);const f=new Map,d=[];let p=0;for(let x=0;x<o;x++){const w=l(x);let S=f.get(w);S==null?(S=d.length/3|0,f.set(w,S),d.push(n[x*3+0],n[x*3+1],n[x*3+2])):p+=1,u[x]=S}if(!p)return{weldedVertexCount:0,removedTriangleCount:0};const m=h((x,w,S)=>{const E=d[x*3+0],A=d[x*3+1],M=d[x*3+2],v=d[w*3+0],b=d[w*3+1],T=d[w*3+2],C=d[S*3+0],I=d[S*3+1],P=d[S*3+2],N=v-E,D=b-A,L=T-M,R=C-E,q=I-A,$=P-M;return .5*Math.hypot(D*$-L*q,L*R-N*$,N*q-D*R)},"areaByIndex"),_=[],y=[];let g=0;for(let x=0;x<a;x++){const w=u[i[x*3+0]>>>0],S=u[i[x*3+1]>>>0],E=u[i[x*3+2]>>>0];if(w<0||S<0||E<0||w===S||S===E||E===w||!(m(w,S,E)>ht)){g+=1;continue}_.push(w,S,E),y.push(s[x])}r._vertProperties=d,r._triVerts=_,r._triIDs=y,r._vertKeyToIndex=new Map;for(let x=0;x<d.length;x+=3)r._vertKeyToIndex.set(`${d[x]},${d[x+1]},${d[x+2]}`,x/3|0);return r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r),{weldedVertexCount:p,removedTriangleCount:g}}h(Yn,"weldSolidVerticesByPosition");function pS(r,e={}){if(!r?.geometry)throw new Error("Face.thicken() requires a face with geometry.");try{r.updateMatrixWorld?.(!0)}catch{}const t=r.geometry,n=t.getAttribute?.("position"),i=t.getIndex?.()||null;if(!n||n.itemSize!==3||n.count<3)throw new Error("Face.thicken() requires a triangulated face geometry.");const s=[],o=new H;let a=1/0,c=1/0,l=1/0,u=-1/0,f=-1/0,d=-1/0;for(let k=0;k<n.count;k++)o.set(n.getX(k),n.getY(k),n.getZ(k)).applyMatrix4(r.matrixWorld),s.push(o.clone()),o.x<a&&(a=o.x),o.y<c&&(c=o.y),o.z<l&&(l=o.z),o.x>u&&(u=o.x),o.y>f&&(f=o.y),o.z>d&&(d=o.z);const p=Math.max(1,Math.hypot(u-a,f-c,d-l)),m=Math.max(Number(e.weldTolerance)||0,Math.max(1e-6,p*1e-7)),_=new Map,y=[],g=new Array(s.length);for(let k=0;k<s.length;k++){const B=s[k],z=fo(B,m);let X=_.get(z);X==null?(X=y.length,_.set(z,X),y.push({point:B.clone(),count:1,key:z})):(y[X].point.add(B),y[X].count+=1),g[k]=X}let x=y.map(k=>k.point.multiplyScalar(1/k.count)),w=y.map(k=>k.key);const S=Array.isArray(e.triangleSourceFaceNames)?e.triangleSourceFaceNames:null,E=String(e.sourceFaceName||qm(r)||"").trim();let A=[];const M=i?i.count/3|0:n.count/3|0;for(let k=0;k<M;k++){const B=i?i.getX(k*3+0)>>>0:k*3+0,z=i?i.getX(k*3+1)>>>0:k*3+1,X=i?i.getX(k*3+2)>>>0:k*3+2,V=g[B]>>>0,te=g[z]>>>0,ce=g[X]>>>0;if(V===te||te===ce||ce===V||!(Xm(x[V],x[te],x[ce])>ht))continue;const ue=[V,te,ce],re=String(S?.[k]||E||"").trim();re&&(ue.sourceFaceName=re),A.push(ue)}if(!A.length)throw new Error("Face.thicken() could not resolve any non-degenerate source triangles.");const v=new Map,b=new Array(A.length).fill(null).map(()=>[]),T=h((k,B,z)=>{for(const[X,V]of[[k[0],k[1]],[k[1],k[2]],[k[2],k[0]]]){if(X===B&&V===z)return 1;if(X===z&&V===B)return-1}return 0},"edgeOrientation");for(let k=0;k<A.length;k++){const B=A[k];for(const[z,X]of[[B[0],B[1]],[B[1],B[2]],[B[2],B[0]]]){const V=Yt(z,X);let te=v.get(V);te||(te=[],v.set(V,te)),te.push({triIndex:k,u:z,v:X})}}for(const[k,B]of v.entries()){if(!Array.isArray(B)||B.length<2)continue;const[z,X]=k.split("|"),V=Number(z)>>>0,te=Number(X)>>>0;for(let ce=0;ce<B.length;ce++)for(let le=ce+1;le<B.length;le++)b[B[ce].triIndex].push({neighbor:B[le].triIndex,u:V,v:te}),b[B[le].triIndex].push({neighbor:B[ce].triIndex,u:V,v:te})}const C=new Array(A.length).fill(!1),I=h(k=>aN(k,[k[0],k[2],k[1]]),"flipTriangle");for(let k=0;k<A.length;k++){if(C[k])continue;const B=[k];for(C[k]=!0;B.length;){const z=B.pop(),X=A[z];for(const V of b[z]){const te=V.neighbor;if(te!=null&&!C[te]){const ce=A[te],le=T(X,V.u,V.v),ue=T(ce,V.u,V.v);le!==0&&le===ue&&(A[te]=I(ce)),C[te]=!0,B.push(te)}}}}const P=new Array(A.length),N=new Array(x.length).fill(null).map(()=>new H),D=new H;for(let k=0;k<A.length;k++){const[B,z,X]=A[k],V=Fs(x[B],x[z],x[X]),te=V.length();if(!(te>ht))continue;const ce=V.clone().multiplyScalar(1/te);P[k]=ce,N[B].add(ce.clone().multiplyScalar(te)),N[z].add(ce.clone().multiplyScalar(te)),N[X].add(ce.clone().multiplyScalar(te)),D.add(ce.clone().multiplyScalar(te))}D.lengthSq()<=ht?D.set(0,0,1):D.normalize();const L=[];for(const[k,B]of v.entries()){if(B.length!==1)continue;const z=B[0];L.push({key:k,start:z.u,end:z.v})}const R=new Map;for(const k of L){let B=R.get(k.start);B||(B=[],R.set(k.start,B)),B.push(k)}const q=new Set(L.map(k=>`${k.start}>${k.end}`)),$=[],U=h((k,B)=>{const z=`${w[k.start]}|${w[k.end]}`,X=`${w[B.start]}|${w[B.end]}`;return z.localeCompare(X)},"compareEdges");for(;q.size;){const k=Array.from(q.values()).sort((ae,he)=>ae.localeCompare(he))[0],[B,z]=k.split(">"),X=Number(B)>>>0,V=Number(z)>>>0,te=[],ce=[X];let le=X,ue=X,re=V;for(;q.has(`${ue}>${re}`)&&(q.delete(`${ue}>${re}`),te.push({start:ue,end:re,key:Yt(ue,re)}),ce.push(re),ue=re,ue!==le);){const ae=(R.get(ue)||[]).filter(he=>q.has(`${he.start}>${he.end}`)).sort(U);if(!ae.length)break;re=ae[0].end}te.length&&$.push({vertices:ce,edges:te})}const K=h(k=>{const B=Array.isArray(k?.vertices)?k.vertices.slice(0,-1):[];if(!B.length)return"";let z=null;for(let X=0;X<B.length;X++){const V=[];for(let ce=0;ce<B.length;ce++)V.push(w[B[(X+ce)%B.length]]||`${B[(X+ce)%B.length]}`);const te=V.join(">");(z==null||te<z)&&(z=te)}return z||""},"normalizeLoopSignature"),W=$.map(k=>({...k,signature:K(k)})).sort((k,B)=>k.signature.localeCompare(B.signature));dN(r,W,x,p,m);const ne=new Map;for(let k=0;k<W.length;k++){const B=W[k];for(const z of B.edges)ne.set(z.key,k)}const Q=hN(r,{vertices:x,vertexNormals:N,boundaryDirectedEdges:L,weldTolerance:m},e);for(let k=0;k<N.length;k++)N[k].lengthSq()<=ht&&N[k].copy(D),N[k].lengthSq()<=ht?N[k].set(0,0,1):N[k].normalize();return{vertices:x,triangles:A,triangleNormals:P,vertexNormals:N,averageNormal:D,loops:W,boundaryEdgeToLoop:ne,boundaryDirectedEdges:L,adjacentNormalStats:Q,scale:p,weldTolerance:m}}h(pS,"extractFaceSurface");function pN(r,e={}){const t=Array.isArray(r)?r.filter(d=>d?.geometry):[];if(!t.length)throw new Error("Face.thicken() requires at least one face with geometry.");const n=[],i=[],s=[],o=[],a=new H;let c=null,l=!1;for(const d of t){try{d.updateMatrixWorld?.(!0)}catch{}const p=qm(d)||`FACE_${t.indexOf(d)+1}`,m=d?.parentSolid||(String(d?.parent?.type||"").toUpperCase()==="SOLID"?d.parent:null);if(!c&&m?c=m:c&&m&&m!==c&&(l=!0),Array.isArray(d?.edges))for(const S of d.edges)S&&!o.includes(S)&&o.push(S);const _=d.geometry,y=_.getAttribute?.("position"),g=_.getIndex?.()||null;if(!y||y.itemSize!==3||y.count<3)throw new Error("Face.thicken() requires triangulated face geometries.");const x=n.length/3|0;for(let S=0;S<y.count;S++)a.set(y.getX(S),y.getY(S),y.getZ(S)).applyMatrix4(d.matrixWorld||new tt),n.push(a.x,a.y,a.z);const w=g?g.count/3|0:y.count/3|0;for(let S=0;S<w;S++){const E=g?g.getX(S*3+0)>>>0:S*3+0,A=g?g.getX(S*3+1)>>>0:S*3+1,M=g?g.getX(S*3+2)>>>0:S*3+2;i.push(x+E,x+A,x+M),s.push(p)}}if(i.length<3)throw new Error("Face.thicken() could not resolve any source triangles.");const u=new it;u.setAttribute("position",new bt(new Float32Array(n),3)),u.setIndex(i);const f={geometry:u,matrixWorld:new tt,name:String(e.sourceFaceName||"THICKEN_PATCH"),edges:o,parentSolid:l?null:c,userData:{faceName:String(e.sourceFaceName||"THICKEN_PATCH")},updateMatrixWorld(){}};return pS(f,{...e,triangleSourceFaceNames:s,disableAdjacentBoundaryNormals:e.disableAdjacentBoundaryNormals??!(e.equalAdjacentBoundaryNormals===!0||String(e.sharedBoundaryNormalMode||"").toLowerCase()==="equal")})}h(pN,"extractFacesSurface");function mN(r,e){const t=[],n=new Set,i=h((m,_)=>{const y=String(m?.label||"").trim();if(!y||n.has(y))return;n.add(y);const g=String(m?.sourceFaceName||r.sourceFaceName||"").trim()||r.sourceFaceName;t.push({label:y,kind:_,metadata:{type:_==="start"?"start_cap":"end_cap",sourceFaceName:g,distance:e}})},"addCapGroup"),s=Array.isArray(r.startCaps)&&r.startCaps.length?r.startCaps:[{label:r.start,sourceFaceName:r.sourceFaceName}],o=Array.isArray(r.endCaps)&&r.endCaps.length?r.endCaps:[{label:r.end,sourceFaceName:r.sourceFaceName}];for(const m of s)i(m,"start");for(const m of o)i(m,"end");const a=[],c=new Map;for(const m of r.sidewalls||[]){const _=String(m?.label||"").trim();if(!_)continue;let y=c.get(_);y||(y={label:_,kind:"sidewall",metadata:{type:"sidewall",sourceFaceName:r.sourceFaceName,loopIndex:m.loopIndex,edgeIndex:m.edgeIndex,edgeKey:m.key,sourceEdgeName:m.sourceEdgeName||null,sourceEdgeKey:m.sourceEdgeKey||null,distance:e,segmentCount:0,edgeKeys:[]}},c.set(_,y),a.push(y)),y.metadata.segmentCount+=1,m.key!=null&&y.metadata.edgeKeys.push(m.key)}const l=[...t,...a],u=new Map,f=new Map,d=[];let p=1;try{typeof Ds?.reserveIDs=="function"&&(p=Number(Ds.reserveIDs(l.length))||1)}catch{p=1}for(const m of l){const _=p>>>0;p+=1,u.set(m.label,_),f.set(_,m.label),d.push([m.label,JSON.stringify(m.metadata||{})])}return{labels:r,groups:l,faceNameToID:u,idToFaceName:f,faceMetadataJson:d,edgeKeyToLabel:new Map(r.sidewalls.map(m=>[m.key,m.label]))}}h(mN,"buildThickenClassificationState");function mS(r,e,t){const n=Array.from(r?.triVerts??[],l=>Number(l)>>>0),i=n.length/3|0;if(!i)return null;const s=Array.from(e?.triIDs??r?.faceID??[],l=>Number(l)>>>0),o=Number(e?.faceNameToID?.values?.()?.next?.()?.value)>>>0,a=s.length===i?s:new Array(i).fill(o||1),c=new nr;c._numProp=Number(r?.numProp??3)||3,c._vertProperties=Array.from(r?.vertProperties??[],l=>Number(l)||0),c._triVerts=n,c._triIDs=a,c._faceNameToID=e?.faceNameToID instanceof Map?new Map(e.faceNameToID):new Map,c._idToFaceName=e?.idToFaceName instanceof Map?new Map(e.idToFaceName):new Map,c._faceMetadata=new Map;for(const[l,u]of e?.faceMetadataJson||[])if(l)try{c._faceMetadata.set(String(l),JSON.parse(u||"{}")||{})}catch{c._faceMetadata.set(String(l),{})}c._vertKeyToIndex=new Map;for(let l=0;l<c._vertProperties.length;l+=3)c._vertKeyToIndex.set(`${c._vertProperties[l]},${c._vertProperties[l+1]},${c._vertProperties[l+2]}`,l/3|0);try{c.name=t||c.name}catch{}return c._dirty=!0,c._manifold=null,c._faceIndex=null,c}h(mS,"buildSolidFromTriangleMesh");function gS(r,e,t="raw_face_ids"){return{triIDs:Array.from(e||[],n=>Number(n)>>>0),faceNameToID:r?.faceNameToID instanceof Map?r.faceNameToID:new Map,idToFaceName:r?.idToFaceName instanceof Map?r.idToFaceName:new Map,faceMetadataJson:Array.from(r?.faceMetadataJson||[]),groups:Array.isArray(r?.groups)?r.groups:[],method:t}}h(gS,"buildRawClassification");function gN(r,e,t){const n=r?.labels||{},i=String(e?.sourceFaceName||"").trim(),s=i?n.capLabelsBySourceFaceName?.get?.(i):null,o=t==="start"?s?.start||n.start:s?.end||n.end;return String(o||"").trim()}h(gN,"resolveCapLabelForTriangle");function Ho(r,e,t){const n=gN(r,e,t);return Number(r?.faceNameToID?.get?.(n))>>>0}h(Ho,"resolveCapFaceIDForTriangle");function yN(r,e,t){const n=Array.isArray(r?.vertices)?r.vertices.length:0;if(!n)return null;const i=new Float32Array(n*2*3);for(let u=0;u<n;u++){const f=r.vertices[u],d=f.clone().add(r.vertexNormals[u].clone().multiplyScalar(e));i[u*3+0]=f.x,i[u*3+1]=f.y,i[u*3+2]=f.z;const p=n+u;i[p*3+0]=d.x,i[p*3+1]=d.y,i[p*3+2]=d.z}const s=Number(t?.faceNameToID?.get?.(t?.labels?.start))>>>0,o=Number(t?.faceNameToID?.get?.(t?.labels?.end))>>>0,a=[],c=[],l=h((u,f,d,p)=>{if(u===f||f===d||d===u)return;const m=new H(i[u*3+0],i[u*3+1],i[u*3+2]),_=new H(i[f*3+0],i[f*3+1],i[f*3+2]),y=new H(i[d*3+0],i[d*3+1],i[d*3+2]);Xm(m,_,y)>ht&&(a.push(u>>>0,f>>>0,d>>>0),c.push(Number(p)>>>0))},"addTriangle");for(const u of r.triangles||[]){const[f,d,p]=u,m=Ho(t,u,"start")||s,_=Ho(t,u,"end")||o;e>=0?(l(f,p,d,m),l(n+f,n+d,n+p,_)):(l(f,d,p,m),l(n+f,n+p,n+d,_))}for(let u=0;u<(r.loops?.length||0);u++){const f=r.loops[u];for(const d of f?.edges||[]){const p=d.start>>>0,m=d.end>>>0,_=n+p,y=n+m,g=t?.edgeKeyToLabel?.get?.(d.key),x=Number(t?.faceNameToID?.get?.(g))>>>0;e>=0?(l(p,m,y,x),l(p,y,_,x)):(l(_,y,m,x),l(_,m,p,x))}}return{numProp:3,vertProperties:i,triVerts:Uint32Array.from(a),faceID:Uint32Array.from(c)}}h(yN,"buildStitchedThickenMesh");function _N(r,e,t,n){const i=yN(r,e,t);if(!i)return null;const s=gS(t,i.faceID,"stitched_shell");return mS(i,s,n)}h(_N,"buildStitchedShellSolid");function xN(r,e,t){const n=Array.isArray(r?.vertices)?r.vertices:[],i=Array.isArray(r?.triangles)?r.triangles:[];if(!n.length||!i.length)return null;const s=Number(t?.faceNameToID?.get?.(t?.labels?.start))>>>0,o=Number(t?.faceNameToID?.get?.(t?.labels?.end))>>>0,a=Number(t?.faceNameToID?.values?.()?.next?.()?.value)>>>0,c=[],l=[],u=[],f=h(m=>{const _=u.length/3|0;return u.push(m.x,m.y,m.z),_},"addVertex"),d=h((m,_,y,g)=>{if(!m||!_||!y||!(Xm(m,_,y)>ht))return;const x=f(m),w=f(_),S=f(y);c.push(x,w,S),l.push(Number(g)>>>0)},"addTriangleByPoints"),p=h((m,_)=>{const y=Yt(m,_),g=t?.edgeKeyToLabel?.get?.(y);return Number(t?.faceNameToID?.get?.(g))>>>0||a||s||o||1},"resolveSideFaceID");for(const m of i){const _=m?.[0]>>>0,y=m?.[1]>>>0,g=m?.[2]>>>0,x=n[_],w=n[y],S=n[g];if(!x||!w||!S)continue;const E=Ho(t,m,"start")||s,A=Ho(t,m,"end")||o,M=Fs(x,w,S),v=M.length();if(!(v>ht))continue;M.multiplyScalar(e/v);const b=x.clone().add(M),T=w.clone().add(M),C=S.clone().add(M);e>=0?(d(x,S,w,E),d(b,T,C,A),d(x,w,T,p(_,y)),d(x,T,b,p(_,y)),d(w,S,C,p(y,g)),d(w,C,T,p(y,g)),d(S,x,b,p(g,_)),d(S,b,C,p(g,_))):(d(x,w,S,E),d(b,C,T,A),d(b,T,w,p(_,y)),d(b,w,x,p(_,y)),d(T,C,S,p(y,g)),d(T,S,w,p(y,g)),d(C,b,x,p(g,_)),d(C,x,S,p(g,_)))}return c.length?{numProp:3,vertProperties:Float32Array.from(u),triVerts:Uint32Array.from(c),faceID:Uint32Array.from(l)}:null}h(xN,"buildTrianglePrismUnionThickenMesh");function vN(r,e,t,n){const i=xN(r,e,t);if(!i)return null;const s=gS(t,i.faceID,"triangle_prism_union");return mS(i,s,n)}h(vN,"buildTrianglePrismUnionShellSolid");function bN(r,e={}){const t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=Array.isArray(r?._triVerts)?r._triVerts:[],i=Array.isArray(r?._triIDs)?r._triIDs:[],s=n.length/3|0;if(!s||t.length<9||i.length<s)return 0;let o=1/0,a=1/0,c=1/0,l=-1/0,u=-1/0,f=-1/0;for(let R=0;R<t.length;R+=3){const q=t[R+0],$=t[R+1],U=t[R+2];q<o&&(o=q),q>l&&(l=q),$<a&&(a=$),$>u&&(u=$),U<c&&(c=U),U>f&&(f=U)}const d=Math.hypot(l-o,u-a,f-c)||1,p=Math.max(d*(Number(e.offsetScale)||1e-5),1e-9),m=Math.max(p*.1,d*1e-10,1e-10),_=Math.max(12,Math.min(256,Number.isFinite(Number(e.gridSize))?Number(e.gridSize)|0:Math.ceil(Math.sqrt(s)))),y=new Array(s);for(let R=0;R<s;R++){const q=n[R*3+0]>>>0,$=n[R*3+1]>>>0,U=n[R*3+2]>>>0,K=[t[q*3+0],t[q*3+1],t[q*3+2]],W=[t[$*3+0],t[$*3+1],t[$*3+2]],ne=[t[U*3+0],t[U*3+1],t[U*3+2]],Q=W[0]-K[0],k=W[1]-K[1],B=W[2]-K[2],z=ne[0]-K[0],X=ne[1]-K[1],V=ne[2]-K[2];let te=k*V-B*X,ce=B*z-Q*V,le=Q*X-k*z;const ue=Math.hypot(te,ce,le);ue>ht?(te/=ue,ce/=ue,le/=ue):(te=0,ce=0,le=0),y[R]={a:K,b:W,c:ne,normal:[te,ce,le],centroid:[(K[0]+W[0]+ne[0])/3,(K[1]+W[1]+ne[1])/3,(K[2]+W[2]+ne[2])/3],min:[Math.min(K[0],W[0],ne[0]),Math.min(K[1],W[1],ne[1]),Math.min(K[2],W[2],ne[2])],max:[Math.max(K[0],W[0],ne[0]),Math.max(K[1],W[1],ne[1]),Math.max(K[2],W[2],ne[2])]}}const g=[{primary:0,u:1,v:2,min:[o,a,c],max:[l,u,f]},{primary:1,u:2,v:0,min:[o,a,c],max:[l,u,f]},{primary:2,u:0,v:1,min:[o,a,c],max:[l,u,f]}],x=h(R=>{const q=R.min[R.u],$=R.min[R.v],U=Math.max(R.max[R.u]-q,p),K=Math.max(R.max[R.v]-$,p),W=new Map,ne=h((k,B,z)=>Math.max(0,Math.min(_-1,Math.floor((k-B)/z*_))),"cellCoord"),Q=h((k,B,z)=>{const X=`${k}|${B}`;let V=W.get(X);V||(V=[],W.set(X,V)),V.push(z)},"addCell");for(let k=0;k<s;k++){const B=y[k],z=ne(B.min[R.u]-p,q,U),X=ne(B.max[R.u]+p,q,U),V=ne(B.min[R.v]-p,$,K),te=ne(B.max[R.v]+p,$,K);for(let ce=z;ce<=X;ce++)for(let le=V;le<=te;le++)Q(ce,le,k)}return{axis:R,uMin:q,vMin:$,uSpan:U,vSpan:K,cells:W,cellCoord:ne}},"buildIndex"),S=(String(e.axes||"").toLowerCase()==="majority"?g:[g[0]]).map(x),E=h((R,q)=>{const $=R.cellCoord(q[R.axis.u],R.uMin,R.uSpan),U=R.cellCoord(q[R.axis.v],R.vMin,R.vSpan);return R.cells.get(`${$}|${U}`)||[]},"pointInIndexCell"),A=h((R,q,$)=>{const U=q.primary,K=q.u,W=q.v,ne=$.a[U]-R[U],Q=$.a[K]-R[K],k=$.a[W]-R[W],B=$.b[U]-R[U],z=$.b[K]-R[K],X=$.b[W]-R[W],V=$.c[U]-R[U],te=$.c[K]-R[K],ce=$.c[W]-R[W],le=B-ne,ue=z-Q,re=X-k,ae=V-ne,he=te-Q,Ne=ce-k,J=re*he-ue*Ne;if(Math.abs(J)<=m)return null;const Be=1/J,ge=-ne,Ae=-Q,Ee=-k,G=0,F=-Ne,oe=he,O=(ge*G+Ae*F+Ee*oe)*Be;if(O<-1e-10||O>1+1e-10)return null;const j=Ae*re-Ee*ue,ee=Ee*le-ge*re,pe=ge*ue-Ae*le,fe=j*Be;if(fe<-1e-10||O+fe>1+1e-10)return null;const de=(ae*j+he*ee+Ne*pe)*Be;return de>m?de:null},"rayTriangleHit"),M=h((R,q)=>{const $=[];for(const W of E(q,R)){const ne=y[W];if(R[q.axis.primary]>ne.max[q.axis.primary]+p||R[q.axis.u]<ne.min[q.axis.u]-p||R[q.axis.u]>ne.max[q.axis.u]+p||R[q.axis.v]<ne.min[q.axis.v]-p||R[q.axis.v]>ne.max[q.axis.v]+p)continue;const Q=A(R,q.axis,ne);Q!=null&&$.push(Q)}if(!$.length)return!1;$.sort((W,ne)=>W-ne);let U=0,K=-1/0;for(const W of $)Math.abs(W-K)<=Math.max(m*4,1e-8)||(U+=1,K=W);return U%2===1},"inside"),v=new Uint8Array(s);v.fill(1);let b=0;for(let R=0;R<s;R++){const q=y[R],$=q.normal;if(Math.hypot($[0],$[1],$[2])<=ht)continue;const U=[q.centroid[0]+$[0]*p,q.centroid[1]+$[1]*p,q.centroid[2]+$[2]*p],K=[q.centroid[0]-$[0]*p,q.centroid[1]-$[1]*p,q.centroid[2]-$[2]*p];let W=0;for(const ne of S)M(U,ne)!==M(K,ne)&&(W+=1);W>=Math.ceil(S.length/2)||(v[R]=0,b+=1)}if(!b)return 0;const T=t.length/3|0,C=new Uint8Array(T),I=[],P=[];for(let R=0;R<s;R++){if(!v[R])continue;const q=n[R*3+0]>>>0,$=n[R*3+1]>>>0,U=n[R*3+2]>>>0;I.push(q,$,U),P.push(i[R]),C[q]=1,C[$]=1,C[U]=1}const N=new Int32Array(T);N.fill(-1);const D=[];let L=0;for(let R=0;R<T;R++)C[R]&&(N[R]=L++,D.push(t[R*3+0],t[R*3+1],t[R*3+2]));for(let R=0;R<I.length;R++)I[R]=N[I[R]>>>0];r._vertProperties=D,r._triVerts=I,r._triIDs=P,r._vertKeyToIndex=new Map;for(let R=0;R<D.length;R+=3)r._vertKeyToIndex.set(`${D[R]},${D[R+1]},${D[R+2]}`,R/3|0);r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r);try{r.fixTriangleWindingsByAdjacency?.()}catch{}return b}h(bN,"cullInternalTrianglesByIndexedRaycast");function xr(r,e){const t=Array.isArray(r?._triVerts)?r._triVerts:[],n=Array.isArray(r?._vertProperties)?r._vertProperties:[],i=t.length/3|0;if(!i||n.length<9)return 0;const s=new Map,o=h((M,v)=>{const b=Yt(M,v);let T=s.get(b);T||(T={count:0,directed:[]},s.set(b,T)),T.count+=1,T.directed.push([M,v])},"addUse");for(let M=0;M<i;M++){const v=t[M*3+0]>>>0,b=t[M*3+1]>>>0,T=t[M*3+2]>>>0;o(v,b),o(b,T),o(T,v)}const a=new Map,c=new Map,l=new Map,u=[],f=h((M,v)=>{let b=c.get(M);b||(b=[],c.set(M,b)),b.push(v)},"addUndirectedNeighbor");for(const M of s.values()){if(M.count!==1||!M.directed.length)continue;const[v,b]=M.directed[0],T={a:v,b,key:`${v}>${b}`};u.push(T),l.set(Yt(v,b),[v,b]),f(v,b),f(b,v);let C=a.get(v);C||(C=[],a.set(v,C)),C.push(T)}if(!u.length)return 0;for(const M of a.values())M.sort((v,b)=>v.b-b.b);const d=new Set,p=[];for(const M of u){if(d.has(M.key))continue;const v=[M.a];let b=M,T=0;for(;b&&!d.has(b.key)&&T++<u.length+1&&(d.add(b.key),v.push(b.b),b.b!==v[0]);)b=(a.get(b.b)||[]).find(I=>!d.has(I.key))||null;v.length>=4&&v[0]===v[v.length-1]&&p.push(v.slice(0,-1))}const m=h(M=>{if(!Array.isArray(M)||!M.length)return"";const v=[],b=h(T=>{for(let C=0;C<T.length;C++){const I=[];for(let P=0;P<T.length;P++)I.push(T[(C+P)%T.length]);v.push(I.join("|"))}},"addVariants");return b(M),M.length>1&&b(M.slice().reverse()),v.sort()[0]||""},"loopSignature"),_=h((M,v)=>{const b=Array.from(v.keys());if(b.length<3||M.length<3)return[];const T=h(ge=>[Number(n[ge*3+0])||0,Number(n[ge*3+1])||0,Number(n[ge*3+2])||0],"pointFor"),C=h((ge,Ae)=>[ge[0]-Ae[0],ge[1]-Ae[1],ge[2]-Ae[2]],"sub"),I=h((ge,Ae)=>ge[0]*Ae[0]+ge[1]*Ae[1]+ge[2]*Ae[2],"dot"),P=h((ge,Ae)=>[ge[1]*Ae[2]-ge[2]*Ae[1],ge[2]*Ae[0]-ge[0]*Ae[2],ge[0]*Ae[1]-ge[1]*Ae[0]],"cross"),N=h(ge=>Math.hypot(ge[0],ge[1],ge[2]),"length"),D=h((ge,Ae)=>[ge[0]*Ae,ge[1]*Ae,ge[2]*Ae],"scaleVec"),L=[0,0,0],R=new Map;for(const ge of b){const Ae=T(ge);R.set(ge,Ae),L[0]+=Ae[0],L[1]+=Ae[1],L[2]+=Ae[2]}L[0]/=b.length,L[1]/=b.length,L[2]/=b.length;let q=null,$=-1/0;for(const ge of R.values()){const Ae=C(ge,L),Ee=N(Ae);Ee>$&&($=Ee,q=Ae)}if(!q||!($>ht))return[];q=D(q,1/$);let U=null,K=-1/0;for(const ge of R.values()){const Ae=P(q,C(ge,L)),Ee=N(Ae);Ee>K&&(K=Ee,U=Ae)}if(!U||!(K>ht))return[];U=D(U,1/K);const W=P(U,q),ne=N(W);if(!(ne>ht))return[];const Q=D(W,1/ne),k=new Map;for(const[ge,Ae]of R.entries()){const Ee=C(Ae,L);k.set(ge,[I(Ee,q),I(Ee,Q)])}const B=new Map;for(const[ge,Ae]of v.entries()){const Ee=k.get(ge);B.set(ge,Ae.slice().sort((G,F)=>{const oe=k.get(G),O=k.get(F);return Math.atan2(oe[1]-Ee[1],oe[0]-Ee[0])-Math.atan2(O[1]-Ee[1],O[0]-Ee[0])}))}const z=h(ge=>{let Ae=0;for(let Ee=0;Ee<ge.length;Ee++){const G=k.get(ge[Ee]),F=k.get(ge[(Ee+1)%ge.length]);Ae+=G[0]*F[1]-F[0]*G[1]}return Ae*.5},"area2D"),X=new Set,V=h((ge,Ae)=>`${ge}>${Ae}`,"directedKey"),te=[];for(const[ge,Ae]of M)for(const Ee of[[ge,Ae],[Ae,ge]]){let G=Ee[0],F=Ee[1];const oe=V(G,F);if(X.has(oe))continue;const O=[];let j=!1,ee=0;const pe=Math.max(12,M.length*4);for(;!X.has(V(G,F))&&ee++<pe;){X.add(V(G,F)),O.push(G);const de=B.get(F)||[],Re=de.indexOf(G);if(Re<0||de.length===0)break;const se=de[(Re-1+de.length)%de.length];if(G=F,F=se,V(G,F)===oe){j=!0;break}}if(!j||O.length<3)continue;const fe=z(O);Math.abs(fe)<=ht||te.push({loop:O,area:fe})}const ce=te.filter(ge=>ge.area>ht),ue=(ce.length?ce:te.filter(ge=>ge.area<-ht)).map(ge=>ge.area>0?ge.loop:ge.loop.slice().reverse());if(ue.length||M.length>64)return ue;const re=new Set,ae=[],he=b.slice().sort((ge,Ae)=>ge-Ae),Ne=h(ge=>{if(!ge.length)return"";const Ae=[],Ee=h(G=>{for(let F=0;F<G.length;F++){const oe=[];for(let O=0;O<G.length;O++)oe.push(G[(F+O)%G.length]);Ae.push(oe.join("|"))}},"add");return Ee(ge),Ee(ge.slice().reverse()),Ae.sort()[0]||""},"canonicalCycleKey");for(const ge of he){const Ae=[{current:ge,path:[ge],visited:new Set([ge])}];let Ee=0;for(;Ae.length&&Ee++<5e3&&ae.length<M.length*2;){const G=Ae.pop();if(G.path.length>M.length)continue;const F=(v.get(G.current)||[]).slice().sort((oe,O)=>oe-O);for(const oe of F){if(oe===ge&&G.path.length>=3){const j=Ne(G.path);j&&!re.has(j)&&(re.add(j),ae.push(G.path.slice()));continue}if(oe<ge||G.visited.has(oe))continue;const O=new Set(G.visited);O.add(oe),Ae.push({current:oe,path:G.path.concat(oe),visited:O})}}}ae.sort((ge,Ae)=>ge.length-Ae.length);const J=new Set,Be=[];for(const ge of ae){const Ae=[];let Ee=!1;for(let G=0;G<ge.length;G++){const F=Yt(ge[G],ge[(G+1)%ge.length]);Ae.push(F),J.has(F)&&(Ee=!0)}if(!Ee){for(const G of Ae)J.add(G);Be.push(ge)}}return Be.slice(0,M.length)},"traceBoundaryGraphLoops"),y=new Set(p.map(m)),g=new Set,x=[];for(const M of u){const v=Yt(M.a,M.b);if(g.has(v))continue;const b=[],T=[[M.a,M.b]];for(g.add(v);T.length;){const[ne,Q]=T.pop();b.push([ne,Q]);for(const k of[ne,Q])for(const B of c.get(k)||[]){const z=Yt(k,B);g.has(z)||(g.add(z),T.push([k,B]))}}if(b.length<3)continue;const C=new Map,I=h((ne,Q)=>{let k=C.get(ne);k||(k=[],C.set(ne,k)),k.includes(Q)||k.push(Q)},"addComponentNeighbor");for(const[ne,Q]of b)I(ne,Q),I(Q,ne);if(!Array.from(C.values()).every(ne=>ne.length===2)){let ne=!1;for(const Q of _(b,C)){const k=m(Q);!k||y.has(k)||(y.add(k),p.push(Q),ne=!0)}ne||x.push(b);continue}const P=Math.min(...Array.from(C.keys())),N=(C.get(P)||[]).slice().sort((ne,Q)=>ne-Q);if(N.length!==2){x.push(b);continue}const D=[P];let L=-1,R=P,q=N[0],$=!1,U=0;for(;U++<b.length+2;){if(D.push(q),L=R,R=q,R===P){$=!0;break}const ne=(C.get(R)||[]).filter(Q=>Q!==L);if(ne.length!==1)break;q=ne[0]}if(!$||D.length<4){x.push(b);continue}const K=D.slice(0,-1);if(K.length!==b.length){x.push(b);continue}const W=m(K);!W||y.has(W)||(y.add(W),p.push(K))}if(x.length=0,!p.length&&!x.length)return 0;const w=h(M=>{if(!Array.isArray(M)||M.length<3)return[];const v=M.map(Q=>[Number(n[Q*3+0])||0,Number(n[Q*3+1])||0,Number(n[Q*3+2])||0]),b=[0,0,0];for(const Q of v)b[0]+=Q[0],b[1]+=Q[1],b[2]+=Q[2];b[0]/=v.length,b[1]/=v.length,b[2]/=v.length;let T=[0,0,0];for(let Q=0;Q<v.length;Q++){const k=v[Q],B=v[(Q+1)%v.length];T[0]+=(k[1]-B[1])*(k[2]+B[2]),T[1]+=(k[2]-B[2])*(k[0]+B[0]),T[2]+=(k[0]-B[0])*(k[1]+B[1])}let C=Math.hypot(T[0],T[1],T[2]);if(!(C>ht)){let Q=0;for(let k=0;k<v.length;k++){const B=v[k],z=v[(k+1)%v.length],X=v[(k+2)%v.length],V=[z[0]-B[0],z[1]-B[1],z[2]-B[2]],te=[X[0]-B[0],X[1]-B[1],X[2]-B[2]],ce=[V[1]*te[2]-V[2]*te[1],V[2]*te[0]-V[0]*te[2],V[0]*te[1]-V[1]*te[0]],le=Math.hypot(ce[0],ce[1],ce[2]);le>Q&&(Q=le,T=ce)}C=Q}if(!(C>ht))return[];T=T.map(Q=>Q/C);let I=null,P=0;for(const Q of v){const k=[Q[0]-b[0],Q[1]-b[1],Q[2]-b[2]],B=Math.hypot(k[0],k[1],k[2]);B>P&&(P=B,I=k)}if(!I||!(P>ht))return[];I=I.map(Q=>Q/P);const N=[T[1]*I[2]-T[2]*I[1],T[2]*I[0]-T[0]*I[2],T[0]*I[1]-T[1]*I[0]],D=Math.hypot(N[0],N[1],N[2]);if(!(D>ht))return[];N[0]/=D,N[1]/=D,N[2]/=D;const L=v.map(Q=>{const k=[Q[0]-b[0],Q[1]-b[1],Q[2]-b[2]];return[k[0]*I[0]+k[1]*I[1]+k[2]*I[2],k[0]*N[0]+k[1]*N[1]+k[2]*N[2]]}),R=h(Q=>{let k=0;for(let B=0;B<Q.length;B++){const z=L[Q[B]],X=L[Q[(B+1)%Q.length]];k+=z[0]*X[1]-X[0]*z[1]}return k*.5},"area2D"),q=h((Q,k,B)=>{const z=L[Q],X=L[k],V=L[B];return(X[0]-z[0])*(V[1]-X[1])-(X[1]-z[1])*(V[0]-X[0])},"cross2D"),$=h((Q,k,B,z)=>{const X=L[Q],V=L[k],te=L[B],ce=L[z],le=Math.abs((te[0]-V[0])*(ce[1]-V[1])-(te[1]-V[1])*(ce[0]-V[0]));if(!(le>ht))return!1;const ue=Math.abs((V[0]-X[0])*(te[1]-X[1])-(V[1]-X[1])*(te[0]-X[0])),re=Math.abs((te[0]-X[0])*(ce[1]-X[1])-(te[1]-X[1])*(ce[0]-X[0])),ae=Math.abs((ce[0]-X[0])*(V[1]-X[1])-(ce[1]-X[1])*(V[0]-X[0]));return Math.abs(ue+re+ae-le)<=Math.max(ht,le*1e-8)},"pointInTri"),U=Array.from({length:M.length},(Q,k)=>k);R(U)<0&&U.reverse();const K=[];let W=0;for(;U.length>3&&W++<M.length*M.length*4;){let Q=!1;for(let k=0;k<U.length;k++){const B=U[(k-1+U.length)%U.length],z=U[k],X=U[(k+1)%U.length];if(q(B,z,X)<=ht)continue;let V=!1;for(const te of U)if(!(te===B||te===z||te===X)&&$(te,B,z,X)){V=!0;break}if(!V){K.push([M[B],M[z],M[X]]),U.splice(k,1),Q=!0;break}}if(!Q)break}if(U.length===3&&K.push([M[U[0]],M[U[1]],M[U[2]]]),K.length)return K;const ne=[];for(let Q=1;Q+1<M.length;Q++)ne.push([M[0],M[Q],M[Q+1]]);return ne},"triangulateLoop"),S=h(M=>{const v=r._vertProperties.length/3|0;return r._vertProperties.push(M[0],M[1],M[2]),r._vertKeyToIndex?.set?.(`${M[0]},${M[1]},${M[2]}`,v),v},"addVertex");let E=0;const A=Number(e)>>>0;for(const M of p){if(M.length<3)continue;let v=0;for(let T=0;T<M.length;T++){const C=M[T],I=M[(T+1)%M.length],P=l.get(Yt(C,I));P&&P[0]===C&&P[1]===I&&(v+=1)}const b=v>=M.length/2;for(const T of w(M)){const C=T[0]>>>0,I=T[1]>>>0,P=T[2]>>>0;C===I||I===P||P===C||(b?r._triVerts.push(P,I,C):r._triVerts.push(C,I,P),r._triIDs.push(A),E+=1)}}for(const M of x){const v=Array.from(new Set(M.flatMap(([C,I])=>[C,I])));if(v.length<3)continue;const b=[0,0,0];for(const C of v)b[0]+=n[C*3+0],b[1]+=n[C*3+1],b[2]+=n[C*3+2];b[0]/=v.length,b[1]/=v.length,b[2]/=v.length;const T=S(b);for(const[C,I]of M){const P=l.get(Yt(C,I))||[C,I],N=P[0]>>>0,D=P[1]>>>0;N===D||N===T||D===T||(r._triVerts.push(D,N,T),r._triIDs.push(A),E+=1)}}return E>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)),E}h(xr,"fillBoundaryLoopsWithTriangles");function yS(r,e,t){const n=`${e}_INTERSECTION_CAP`;let i=r?._faceNameToID instanceof Map?r._faceNameToID.get(n):null;return!i&&typeof r?._getOrCreateID=="function"&&(i=r._getOrCreateID(n)),i&&r?._faceMetadata instanceof Map&&r._faceMetadata.set(n,{type:"intersection_cap",sourceFaceName:e,distance:t}),i||null}h(yS,"getOrCreateIntersectionCapFaceID");function SN(r,e,t,n,i){const s=Array.isArray(r?._triVerts)?r._triVerts:[],o=Array.isArray(r?._vertProperties)?r._vertProperties:[],a=Array.isArray(r?._triIDs)?r._triIDs:[],c=Array.isArray(e?.vertices)?e.vertices:[],l=Array.isArray(e?.vertexNormals)?e.vertexNormals:[],u=Array.isArray(e?.triangles)?e.triangles:[],f=s.length/3|0;if(!f||a.length<f||!c.length||!u.length)return 0;const d=Number(n?.faceNameToID?.get?.(n?.labels?.start))>>>0,p=Number(n?.faceNameToID?.get?.(n?.labels?.end))>>>0;if(!d||!p)return 0;const m=c.map((b,T)=>{const C=l[T];return b&&C?b.clone().add(C.clone().multiplyScalar(t)):null}),_=new Map,y=new Map,g=h((b,T,C)=>{const I=Number(T)>>>0;if(!I||!Array.isArray(C))return;let P=b.get(I);P||(P=[],b.set(I,P)),P.push(C)},"addRef");for(const b of u){const T=b?.[0]>>>0,C=b?.[1]>>>0,I=b?.[2]>>>0;if(!c[T]||!c[C]||!c[I])continue;const P=Ho(n,b,"start")||d,N=Ho(n,b,"end")||p;g(_,P,[c[T],c[C],c[I]]),m[T]&&m[C]&&m[I]&&g(y,N,[m[T],m[C],m[I]])}if(!_.size||!y.size)return 0;const x=Math.max(Number(i)||0,1e-7),w=x*x,S=new H,E=h((b,T)=>{let C=1/0;for(const[I,P,N]of T){const D=uN(b,I,P,N);if(D<C&&(C=D,C<=w))break}return C},"pointDistanceToSurfaceSq"),A=h((b,T)=>{let C=0;for(let I=0;I<3;I++){const N=(s[b*3+I]>>>0)*3;S.set(Number(o[N+0])||0,Number(o[N+1])||0,Number(o[N+2])||0);const D=E(S,T);if(D>C&&(C=D),C>w)break}return C},"triangleMaxDistanceSq"),M=h((b,T)=>{let C=0,I=1/0;for(const[P,N]of T.entries()){const D=A(b,N);if(D<I&&(I=D,C=Number(P)>>>0,I<=w))break}return{faceID:C,distanceSq:I}},"bestFaceIDForTriangle");let v=0;for(let b=0;b<f;b++){const T=M(b,_),C=T.distanceSq<=w?{faceID:0,distanceSq:1/0}:M(b,y),I=T.distanceSq<=w?T.faceID:C.distanceSq<=w?C.faceID:0;I&&a[b]!==I&&(a[b]=I,v+=1)}return v>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null),v}h(SN,"reclassifyThickenCapTrianglesByGeometry");function MN(r,e,t){const n=yS(r,e,t);return n?xr(r,n):0}h(MN,"fillIntersectionCapBoundaryLoops");function ha(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=Array.isArray(r?._triIDs)?r._triIDs:[],i=e.length/3|0;if(!i||n.length<i)return 0;const s=new Map,o=h((y,g,x)=>{const w=Yt(y,g);let S=s.get(w);S||(S=[],s.set(w,S)),S.push(x)},"addUse");for(let y=0;y<i;y++){const g=e[y*3+0]>>>0,x=e[y*3+1]>>>0,w=e[y*3+2]>>>0;o(g,x,y),o(x,w,y),o(w,g,y)}const a=new Uint8Array(i);for(const y of s.values())if(!(y.length<=2))for(const g of y)a[g]=1;let c=0;for(let y=0;y<i;y++)a[y]&&(c+=1);if(!c)return 0;const l=t.length/3|0,u=new Uint8Array(l),f=[],d=[];for(let y=0;y<i;y++){if(a[y])continue;const g=e[y*3+0]>>>0,x=e[y*3+1]>>>0,w=e[y*3+2]>>>0;f.push(g,x,w),d.push(n[y]),u[g]=1,u[x]=1,u[w]=1}const p=new Int32Array(l);p.fill(-1);const m=[];let _=0;for(let y=0;y<l;y++)u[y]&&(p[y]=_++,m.push(t[y*3+0],t[y*3+1],t[y*3+2]));for(let y=0;y<f.length;y++)f[y]=p[f[y]>>>0];r._vertProperties=m,r._triVerts=f,r._triIDs=d,r._vertKeyToIndex=new Map;for(let y=0;y<m.length;y+=3)r._vertKeyToIndex.set(`${m[y]},${m[y+1]},${m[y+2]}`,y/3|0);return r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r),c}h(ha,"cullTrianglesTouchingNonManifoldEdges");function bl(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=Array.isArray(r?._triIDs)?r._triIDs:[],i=e.length/3|0;if(!i||n.length<i)return 0;const s=new Map,o=h((g,x,w)=>{const S=Yt(g,x);let E=s.get(S);E||(E=[],s.set(S,E)),E.push({triIndex:w,a:g,b:x})},"addUse");for(let g=0;g<i;g++){const x=e[g*3+0]>>>0,w=e[g*3+1]>>>0,S=e[g*3+2]>>>0;o(x,w,g),o(w,S,g),o(S,x,g)}const a=new Uint16Array(i);for(const g of s.values())g.length===2&&g[0].a===g[1].a&&g[0].b===g[1].b&&(a[g[0].triIndex]+=1,a[g[1].triIndex]+=1);let c=-1,l=0;for(let g=0;g<i;g++){const x=a[g]||0;if(!x)continue;const S=(r._idToFaceName instanceof Map?String(r._idToFaceName.get(n[g])||""):"").includes("INTERSECTION_CAP")?100:0,E=x+S;E>l&&(l=E,c=g)}if(c<0)return 0;const u=t.length/3|0,f=new Uint8Array(u),d=[],p=[];for(let g=0;g<i;g++){if(g===c)continue;const x=e[g*3+0]>>>0,w=e[g*3+1]>>>0,S=e[g*3+2]>>>0;d.push(x,w,S),p.push(n[g]),f[x]=1,f[w]=1,f[S]=1}const m=new Int32Array(u);m.fill(-1);const _=[];let y=0;for(let g=0;g<u;g++)f[g]&&(m[g]=y++,_.push(t[g*3+0],t[g*3+1],t[g*3+2]));for(let g=0;g<d.length;g++)d[g]=m[d[g]>>>0];r._vertProperties=_,r._triVerts=d,r._triIDs=p,r._vertKeyToIndex=new Map;for(let g=0;g<_.length;g+=3)r._vertKeyToIndex.set(`${_[g]},${_[g+1]},${_[g+2]}`,g/3|0);return r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r),1}h(bl,"cullTrianglesTouchingSameDirectionEdges");function wN(r,e={}){const t=String(e.sourceFaceName||"").trim()||"FACE",n=Number(e.distance)||0,i=Math.max(Number(e.manifoldWeldEpsilon)||0,0),s=Math.max(0,Number.isFinite(Number(e.nonManifoldCullMaxTriangles))?Number(e.nonManifoldCullMaxTriangles):1e4),o=Math.max(1,Math.min(512,Number.isFinite(Number(e.maxPasses))?Number(e.maxPasses)|0:256)),a={orientedTriangleCount:0,orientationCulledTriangleCount:0,orientationCapTriangleCount:0,nonManifoldCulledTriangleCount:0,boundaryCapTriangleCount:0,weldedVertexCount:0,degenerateTriangleCount:0},c=h(()=>{try{return typeof r?._isCoherentlyOrientedManifold=="function"?r._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}},"isCoherent"),l=h(()=>{const f=Yn(r,i);a.weldedVertexCount+=f.weldedVertexCount||0,a.degenerateTriangleCount+=f.removedTriangleCount||0},"weld");for(let f=0;f<o;f++){let d=Mt(r),p=!1;if(d.nonManifoldEdgeCount>0&&(d.triangleCount||0)<=s){const y=ha(r);y>0&&(a.nonManifoldCulledTriangleCount+=y,p=!0,l(),d=Mt(r))}if(d.boundaryEdgeCount>0){const y=MN(r,t,n);if(y>0){a.boundaryCapTriangleCount+=y,a.orientationCapTriangleCount+=y,p=!0;try{r.fixTriangleWindingsByAdjacency?.()}catch{}l(),d=Mt(r)}}if(d.boundaryEdgeCount||d.nonManifoldEdgeCount){if(!p)return{ok:!1,topology:d,orientation:us(r),stats:a};continue}const m=is(r)+rs(r);if(m>0){a.orientedTriangleCount+=m;try{r.fixTriangleWindingsByAdjacency?.()}catch{}}if(c())return{ok:!0,topology:Mt(r),orientation:us(r),stats:a};const _=bl(r);if(!(_>0))return{ok:!1,topology:d,orientation:us(r),stats:a};if(a.orientationCulledTriangleCount+=_,p=!0,l(),!p)break}const u=Mt(r);return{ok:u.boundaryEdgeCount===0&&u.nonManifoldEdgeCount===0&&c(),topology:u,orientation:us(r),stats:a}}h(wN,"repairSolidOrientationByCullAndCap");function Ov(r,e={}){if(!r||typeof r.clone!="function")return null;let t=null;try{t=r.clone();try{t.name=r.name}catch{}const n=wN(t,e),i=n?.topology||Mt(t),s=(()=>{try{return typeof t._isCoherentlyOrientedManifold=="function"?t._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}})();if(n?.ok===!0&&i.boundaryEdgeCount===0&&i.nonManifoldEdgeCount===0&&s)return{solid:t,topology:i,stats:n.stats||{}}}catch{}try{t?.free?.()}catch{}return null}h(Ov,"tryRepairCoherentOrientationCandidate");function AN(r){let e=0;const t=h(n=>{const i=Array.isArray(r?._triVerts)?r._triVerts:[],s=Array.isArray(r?._vertProperties)?r._vertProperties:[],o=Array.isArray(r?._triIDs)?r._triIDs:[],a=i.length/3|0,c=s.length/3|0,l=new Uint8Array(c),u=[],f=[];for(let _=0;_<a;_++){if(n[_])continue;const y=i[_*3+0]>>>0,g=i[_*3+1]>>>0,x=i[_*3+2]>>>0;u.push(y,g,x),f.push(o[_]),l[y]=1,l[g]=1,l[x]=1}const d=new Int32Array(c);d.fill(-1);const p=[];let m=0;for(let _=0;_<c;_++)l[_]&&(d[_]=m++,p.push(s[_*3+0],s[_*3+1],s[_*3+2]));for(let _=0;_<u.length;_++)u[_]=d[u[_]>>>0];r._vertProperties=p,r._triVerts=u,r._triIDs=f,r._vertKeyToIndex=new Map;for(let _=0;_<p.length;_+=3)r._vertKeyToIndex.set(`${p[_]},${p[_+1]},${p[_+2]}`,_/3|0);r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)},"rebuildWithout");for(let n=0;n<256;n++){const i=Array.isArray(r?._triVerts)?r._triVerts:[],s=Array.isArray(r?._triIDs)?r._triIDs:[],o=i.length/3|0;if(!o||s.length<o)break;const a=new Map,c=[];for(let d=0;d<o;d++){const p=i[d*3+0]>>>0,m=i[d*3+1]>>>0,_=i[d*3+2]>>>0,y=[Yt(p,m),Yt(m,_),Yt(_,p)];c.push(y);for(const g of y)a.set(g,(a.get(g)||0)+1)}let l=0;for(const d of a.values())d>2&&(l+=1);if(!l)break;let u=null;for(let d=0;d<o;d++){const p=c[d];if(p.some(x=>(a.get(x)||0)<=1))continue;let m=0;for(const x of p)m+=Math.max(0,(a.get(x)||0)-2);if(!(m>0))continue;const y=(r._idToFaceName instanceof Map?String(r._idToFaceName.get(s[d])||""):"").includes("INTERSECTION_CAP")?1e3:0,g={triIndex:d,score:m+y};(!u||g.score>u.score)&&(u=g)}if(!u)break;const f=new Uint8Array(o);f[u.triIndex]=1,t(f),e+=1}return e}h(AN,"pruneOverusedTriangles");function EN(r,e={}){if(!r)return null;const t=Math.max(1,Math.min(8,Number.isFinite(Number(e.triangleCullPasses))?Number(e.triangleCullPasses)|0:1)),n={snapTolerance:e.splitSnapTolerance??e.snapTolerance,diagnostics:e.splitDiagnostics===!0||e.diagnostics===!0};(!Number.isFinite(Number(n.snapTolerance))||Number(n.snapTolerance)<=0)&&delete n.snapTolerance;let i=0,s=0,o=0,a=0,c=0;const l=Math.max(Number(e.weldTolerance??e.manifoldWeldTolerance)||0,0);for(let f=0;f<t;f++){c=f+1;const d=Number(e.precomputedTriangleSplitProbeCount),p=e.skipTriangleSplit===!0?f===0?Number.isFinite(d)&&d>=0?d:Number(r.splitSelfIntersectingTriangles?.({...n,probeOnly:!0,maxIntersections:1})||0):0:Number(r.splitSelfIntersectingTriangles?.(n)||0);p>0&&e.skipTriangleSplit!==!0&&si(r),i+=p;const m=Number(r.removeDegenerateTriangles?.()||0);m>0&&si(r),o+=m;const _=Yn(r,l);a+=_.weldedVertexCount||0,o+=_.removedTriangleCount||0;const y=(r?._triVerts?.length||0)/3|0,g=Math.max(0,Number.isFinite(Number(e.windingCullMaxTriangles))?Number(e.windingCullMaxTriangles):1e4),x=y>0&&y<=g?"winding":"raycast",w=String(e.internalCullMethod||x).toLowerCase(),S=e.skipInternalCull===!0?0:Number(w==="winding"?r.removeInternalTrianglesByWinding?.(e.windingOptions||{})||0:bN(r,e.raycastCullOptions||{})||0);S>0&&si(r),s+=S;const E=Number(r.removeDegenerateTriangles?.()||0);E>0&&si(r),o+=E;const A=Yn(r,l);if(a+=A.weldedVertexCount||0,o+=A.removedTriangleCount||0,p===0&&S===0)break}try{r.fixTriangleWindingsByAdjacency?.()}catch{}const u=Mt(r);return{splitCount:i,culledTriangleCount:s,degenerateTriangleCount:o,weldedVertexCount:a,passCount:c,topology:u}}h(EN,"triangleSplitCullSolid");function TN(r,e,t,n){let i=null;try{i=typeof e?.getMetadata=="function"&&e.getMetadata()||null}catch{i=null}if(!(!i||typeof r?.setFaceMetadata!="function"))try{r.setFaceMetadata(t.start,{...i,type:"start_cap",sourceFaceName:n,sourceFeatureId:e?.owningFeatureID??e?.parentSolid?.owningFeatureID??i?.sourceFeatureId??null}),r.setFaceMetadata(t.end,{...i,type:"end_cap",sourceFaceName:n,sourceFeatureId:e?.owningFeatureID??e?.parentSolid?.owningFeatureID??i?.sourceFeatureId??null})}catch{}}h(TN,"applySourceFaceMetadataToThickenResult");function CN(r,e){const t=Number(e);if(!(t<0))return!1;const n=Array.isArray(r?.vertices)?r.vertices:[],i=Array.isArray(r?.vertexNormals)?r.vertexNormals:[];if(n.length<3||i.length<n.length)return!1;const s=new H,o=new H;let a=0;for(let u=0;u<n.length;u++){const f=n[u],d=i[u];!f||!d||!(d.lengthSq?.()>ht)||(o.add(f),s.add(d),a+=1)}if(a<3||(o.multiplyScalar(1/a),s.length()/a>.35))return!1;let l=1/0;for(let u=0;u<n.length;u++){const f=n[u],d=i[u];if(!f||!d||!(d.lengthSq?.()>ht))continue;const p=f.clone().sub(o).dot(d);p>ht&&p<l&&(l=p)}return Number.isFinite(l)?Math.abs(t)>=l*.95:!1}h(CN,"shouldSkipArrangementSplitForSelfOverlappingSurface");function IN(r,e,t,n={},i=null){if(!(Number(t)>0))return{skip:!1,reason:"",splitProbeCount:0};if(!r||typeof r.splitSelfIntersectingTriangles!="function")return{skip:!1,reason:"",splitProbeCount:0};const o=Array.isArray(e?.loops)?e.loops:[];if(!o.length)return{skip:!1,reason:"",splitProbeCount:0};const a=i||Mt(r);if(a.boundaryEdgeCount||a.nonManifoldEdgeCount)return{skip:!1,reason:"",splitProbeCount:0};try{if(typeof r._isCoherentlyOrientedManifold=="function"&&r._isCoherentlyOrientedManifold()!==!0)return{skip:!1,reason:"",splitProbeCount:0}}catch{return{skip:!1,reason:"",splitProbeCount:0}}const c=Math.max(Array.isArray(e?.boundaryDirectedEdges)?e.boundaryDirectedEdges.length:0,o.reduce((m,_)=>m+(Array.isArray(_?.edges)?_.edges.length:0),0)),l=Math.max(16,Math.min(512,c*2||64)),u={probeOnly:!0,maxIntersections:l+1},f=n.splitSnapTolerance??n.snapTolerance;Number.isFinite(Number(f))&&Number(f)>0&&(u.snapTolerance=Number(f));let d=null,p=0;try{d=typeof r.clone=="function"?r.clone():null,p=Number(d?d.splitSelfIntersectingTriangles(u)||0:r.splitSelfIntersectingTriangles({...u,maxIntersections:1})||0)}finally{try{d?.free?.()}catch{}}return p>l?{skip:!1,reason:"",splitProbeCount:p}:{skip:!0,reason:p>0?"preserve_exact_closed_shell":"closed_shell_without_intersections",splitProbeCount:p}}h(IN,"shouldPreserveExactClosedOffsetShell");function os(r,e,t,n={}){const i=Number(t);if(!Number.isFinite(i)||Math.abs(i)<=hm)throw new Error("Face.thicken() requires a non-zero finite distance.");if(!r||!Array.isArray(r.triangles)||!r.triangles.length)throw new Error("Face.thicken() requires a non-empty source triangle surface.");const s=pm(n.featureId||n.name||e?.name||"THICKEN","THICKEN"),o=String(n.sourceFaceName||e?.userData?.faceName||e?.name||s).trim()||s,a=Array.isArray(n.sourceFaceNames)?n.sourceFaceNames.map(A=>String(A||"").trim()).filter(Boolean):[o],c=a.length?a:[o],l=new Map;for(const A of c){const M=String(A||"").trim();!M||l.has(M)||l.set(M,{start:`${M}_START`,end:`${M}_END`})}const u=l.get(o)||l.values().next().value||{start:`${o}_START`,end:`${o}_END`},f=Array.isArray(r.loops)?r.loops:[],d={sourceFaceName:o,start:u.start,end:u.end,startCaps:Array.from(l.entries(),([A,M])=>({label:M.start,sourceFaceName:A})),endCaps:Array.from(l.entries(),([A,M])=>({label:M.end,sourceFaceName:A})),capLabelsBySourceFaceName:l,sidewalls:f.flatMap((A,M)=>(Array.isArray(A?.edges)?A.edges:[]).map((v,b)=>{const T=String(v?.sourceEdgeName||"").trim(),C=T?pm(T,`EDGE_${M}_${b}`).replace(/_+$/g,""):null;return{key:v.key,loopIndex:M,edgeIndex:b,sourceEdgeName:T||null,sourceEdgeKey:v?.sourceEdgeKey||null,label:C?`${C}_SW`:M===0?`${o}_E${b}_SW`:`${o}_L${M}_E${b}_SW`}}))},p=mN(d,i),m=String(n.name||s).trim()||s,_=Math.max(Number(n.manifoldWeldTolerance)||0,Math.max(r.weldTolerance||0,r.scale*1e-7,1e-6)),y=Math.max(0,Number.isFinite(Number(n.orientationRepairDistanceLimit))?Number(n.orientationRepairDistanceLimit):2),g=Math.abs(i)<=y,x=n.trianglePrismUnion===!0,w=n.repairBoundaryCaps!==!1,S=Array.isArray(r.triangles)?r.triangles.length:0;let E=null;try{const A=h(()=>{if(n.__skipInternalCullRetry===!0||n.skipInternalCull===!0||!g)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,skipInternalCull:!0,__skipInternalCullRetry:!0})}catch{return null}},"retryWithoutInternalCull"),M=h(()=>{if(n.__relaxedWeldRetry===!0||!g)return null;const le=Math.min(1e-4,Math.max(r.scale*1e-5,1e-8)),ue=Math.max(_*16,r.scale*1e-6,le);if(Number(n.manifoldWeldTolerance)>=ue*.95)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,skipInternalCull:!0,manifoldWeldTolerance:ue,__relaxedWeldRetry:!0})}catch{return null}},"retryWithRelaxedWeld"),v=h(()=>{if(n.__raycastMajorityRetry===!0)return null;try{E?.free?.()}catch{}return E=null,os(r,e,i,{...n,internalCullMethod:"raycast",raycastCullOptions:{...n.raycastCullOptions||{},axes:"majority"},__raycastMajorityRetry:!0})},"retryWithRaycastMajority"),b=h(()=>{if(n.__skipTriangleSplitRetry===!0||n.skipTriangleSplit===!0)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,skipTriangleSplit:!0,__skipTriangleSplitRetry:!0})}catch{return null}},"retryWithoutTriangleSplit"),T=h((le="destructive_repair")=>{if(n.__trianglePrismUnionRetry===!0||x)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,trianglePrismUnion:!0,repairBoundaryCaps:!1,nonManifoldCullMaxTriangles:0,__trianglePrismUnionRetry:!0,__trianglePrismUnionReason:le})}catch{return null}},"retryWithTrianglePrismUnion"),C=h(()=>yS(E,o,i),"getBoundaryRepairFaceID");if(E=x?vN(r,i,p,m):_N(r,i,p,m),!E)throw new Error("Face.thicken() failed to build the stitched triangle shell.");let I=Mt(E);const P=n.skipTriangleSplit!==!0&&n.skipTriangleSplit!==!1&&!x?IN(E,r,i,n,I):{skip:!1,reason:"",splitProbeCount:0},N=n.skipTriangleSplit!==!1&&CN(r,i),D=n.skipTriangleSplit===!0||P.skip===!0||N,L=n.skipTriangleSplit===!0?"option":P.reason||(N?"self_overlap_surface":""),R=EN(E,{...n,skipTriangleSplit:D,precomputedTriangleSplitProbeCount:P.skip===!0?P.splitProbeCount:void 0,weldTolerance:_});I=R?.topology||Mt(E);let q=0,$=0;const U=Math.max(0,Number.isFinite(Number(n.nonManifoldCullMaxTriangles))?Number(n.nonManifoldCullMaxTriangles):1e4);for(let le=0;le<8&&(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U);le++){const ue=ha(E);if(!(ue>0))break;$+=ue;const re=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E)}if(I.nonManifoldEdgeCount===0&&I.boundaryEdgeCount>0)try{E.removeDegenerateTriangles?.(),I=Mt(E)}catch{}if(w&&I.boundaryEdgeCount>0){const le=C();if(le&&(q=xr(E,le),q>0)){try{E.fixTriangleWindingsByAdjacency?.()}catch{}const ue=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(ue.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(ue.removedTriangleCount||0),I=Mt(E)}}for(let le=0;le<16;le++){let ue=!1;if(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const re=ha(E);if(re>0){$+=re;const ae=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(ae.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(ae.removedTriangleCount||0),I=Mt(E),ue=!0}}if(w&&I.boundaryEdgeCount>0){const re=C();if(re){const ae=xr(E,re);if(ae>0){q+=ae;try{E.fixTriangleWindingsByAdjacency?.()}catch{}const he=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(he.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(he.removedTriangleCount||0),I=Mt(E),ue=!0}}}if(!ue)break}let K=I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0?is(E):0;I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0&&(K+=rs(E));let W=0,ne=0,Q=!1;if(K>0)try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0&&g&&typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0)for(let le=0;le<8;le++){const ue=bl(E);if(!(ue>0))break;if(W+=ue,I=Mt(E),w&&I.boundaryEdgeCount>0){const ae=C();if(ae){const he=xr(E,ae);he>0&&(ne+=he,q+=he)}}const re=Yn(E,_);if(R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E),I.boundaryEdgeCount||I.nonManifoldEdgeCount)break;K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(E._isCoherentlyOrientedManifold()===!0)break}for(let le=0;le<8;le++){let ue=!1;if(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const re=ha(E);re>0&&($+=re,ue=!0)}if(I=Mt(E),w&&I.boundaryEdgeCount>0){const re=C();if(re){const ae=xr(E,re);ae>0&&(q+=ae,ue=!0)}}if(ue){const re=Yn(E,_);if(R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E),I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0){K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}}}if(!ue)break}if(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const le=AN(E);if(le>0){if($+=le,I=Mt(E),w&&I.boundaryEdgeCount>0){const ue=C();if(ue){const re=xr(E,ue);re>0&&(q+=re,I=Mt(E))}}if(I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0){K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}}}}if(n.__raycastMajorityRetry!==!0&&g)for(let le=0;le<128;le++){if(I=Mt(E),I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const ae=ha(E);if(ae>0){$+=ae;const he=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(he.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(he.removedTriangleCount||0),I=Mt(E)}}if(w&&I.boundaryEdgeCount>0){const ae=C();if(ae){const he=xr(E,ae);if(he>0){q+=he;const Ne=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(Ne.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(Ne.removedTriangleCount||0),I=Mt(E)}}}if(I.boundaryEdgeCount||I.nonManifoldEdgeCount)break;K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(typeof E._isCoherentlyOrientedManifold!="function"||E._isCoherentlyOrientedManifold()===!0)break;const ue=bl(E);if(!(ue>0))break;W+=ue;const re=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0)}if(I=Mt(E),I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0&&g&&typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0){const le=Ov(E,{sourceFaceName:o,distance:i,manifoldWeldEpsilon:_,nonManifoldCullMaxTriangles:U,maxPasses:n.orientationRepairMaxPasses});if(le?.solid){const ue=E;E=le.solid;try{ue?.free?.()}catch{}I=le.topology||Mt(E);const re=le.stats||{};K+=re.orientedTriangleCount||0,W+=re.orientationCulledTriangleCount||0,ne+=re.orientationCapTriangleCount||0,q+=re.boundaryCapTriangleCount||0,$+=re.nonManifoldCulledTriangleCount||0,R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.degenerateTriangleCount||0),Q=!0}}const k=!x&&q>Math.max(1e4,S*100),B=!x&&$>Math.max(1e4,S*100);if(k||B){const le=T(k?"excessive_boundary_caps":"excessive_nonmanifold_cull");if(le)return le;throw new Error(`Face.thicken() triangle split/cull required excessive topology repair (boundaryCaps=${q}, nonManifoldCull=${$}, sourceTriangles=${S}).`)}if(I.boundaryEdgeCount||I.nonManifoldEdgeCount){const le=T("invalid_stitched_topology");if(le)return le;const ue=b();if(ue)return ue;const re=A();if(re)return re;const ae=M();if(ae)return ae;const he=v();if(he)return he;throw new Error(`Face.thicken() triangle split/cull produced invalid topology: boundaries=${I.boundaryEdgeCount}, nonManifold=${I.nonManifoldEdgeCount}, triangles=${I.triangleCount||0}.`)}let z=typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0,X=z?us(E):null;if(z&&I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0){const le=Ov(E,{sourceFaceName:o,distance:i,manifoldWeldEpsilon:_,nonManifoldCullMaxTriangles:U,maxPasses:n.orientationRepairMaxPasses});if(le?.solid){const ue=E;E=le.solid;try{ue?.free?.()}catch{}I=le.topology||Mt(E);const re=le.stats||{};K+=re.orientedTriangleCount||0,W+=re.orientationCulledTriangleCount||0,ne+=re.orientationCapTriangleCount||0,q+=re.boundaryCapTriangleCount||0,$+=re.nonManifoldCulledTriangleCount||0,R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.degenerateTriangleCount||0),Q=!0,z=typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0,X=z?us(E):null}}if(z&&I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0)for(let le=0;le<32;le++){const ue=bl(E);if(!(ue>0))break;if(W+=ue,I=Mt(E),w&&I.boundaryEdgeCount>0){const ae=C();if(ae){const he=xr(E,ae);he>0&&(ne+=he,q+=he)}}const re=Yn(E,_);if(R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E),I.boundaryEdgeCount||I.nonManifoldEdgeCount)break;K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(z=typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0,X=z?us(E):null,!z)break}if(z&&n.__raycastMajorityRetry!==!0&&g){const le=A();if(le)return le;const ue=M();if(ue)return ue;const re=v();if(re)return re;throw new Error(`Face.thicken() triangle split/cull produced a non-coherently-oriented manifold result: sameDirection=${X.sameDirectionEdgeCount}, ambiguous=${X.ambiguousEdgeCount}.`)}const V=Math.max(_*64,Math.abs(i)*1e-5,r.scale*1e-5,1e-6),te=SN(E,r,i,p,V);TN(E,e,d,o),E.__thickenMethod="triangle_split_cull",E.__thickenClassificationMethod="raw_face_ids",E.__thickenDiagnostics={boundaryLoopCount:f.length,sourceTriangleCount:Array.isArray(r.triangles)?r.triangles.length:0,sourceFaceCount:a.length,sourceFaceNames:a,resultTriangleCount:(E._triVerts?.length||0)/3|0,sourceFaceName:o,distance:i,classificationMethod:"raw_face_ids",buildMethod:E.__thickenMethod,constructionMethod:x?"triangle_prism_union":"stitched_shell",trianglePrismUnionRetry:n.__trianglePrismUnionRetry===!0,trianglePrismUnionReason:n.__trianglePrismUnionReason||"",repairBoundaryCapsEnabled:w,weldEpsilon:_,triangleSplitCount:R?.splitCount||0,triangleSplitSkipped:D,triangleSplitSkipReason:L,triangleSplitProbeCount:P.splitProbeCount||0,culledTriangleCount:R?.culledTriangleCount||0,internalTriangleCullSkipped:n.skipInternalCull===!0,internalTriangleCullRetry:n.__skipInternalCullRetry===!0,relaxedWeldRetry:n.__relaxedWeldRetry===!0,degenerateTriangleCount:R?.degenerateTriangleCount||0,weldedVertexCount:R?.weldedVertexCount||0,orientedTriangleCount:K,orientationCulledTriangleCount:W,orientationCapTriangleCount:ne,orientationCandidateRepairAccepted:Q,orientationRepairDistanceLimit:y,orientationWarning:z,orientationSameDirectionEdgeCount:X?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:X?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:te,nonManifoldCulledTriangleCount:$,boundaryCapTriangleCount:q,splitCullPasses:R?.passCount||0,adjacentBoundaryNormalContributionCount:r.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:r.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalCandidateEdgeCount:r.adjacentNormalStats?.candidateEdges||0,adjacentBoundaryNormalAcceptedEdgeCount:r.adjacentNormalStats?.acceptedEdges||0,adjacentBoundaryNormalDotThreshold:r.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalWeightScale:r.adjacentNormalStats?.weightScale??null,adjacentBoundaryNormalFaceFilterCount:r.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:r.adjacentNormalStats?.faceFilterNames||[]},E.userData={...E.userData||{},thicken:{sourceFaceName:o,sourceFaceNames:a,sourceFaceCount:a.length,distance:i,boundaryLoopCount:f.length,sourceTriangleCount:Array.isArray(r.triangles)?r.triangles.length:0,resultTriangleCount:(E._triVerts?.length||0)/3|0,classificationMethod:"raw_face_ids",buildMethod:E.__thickenMethod,weldEpsilon:_,triangleSplitCount:R?.splitCount||0,triangleSplitSkipped:D,triangleSplitSkipReason:L,triangleSplitProbeCount:P.splitProbeCount||0,culledTriangleCount:R?.culledTriangleCount||0,internalTriangleCullSkipped:n.skipInternalCull===!0,internalTriangleCullRetry:n.__skipInternalCullRetry===!0,relaxedWeldRetry:n.__relaxedWeldRetry===!0,degenerateTriangleCount:R?.degenerateTriangleCount||0,weldedVertexCount:R?.weldedVertexCount||0,orientedTriangleCount:K,orientationCulledTriangleCount:W,orientationCapTriangleCount:ne,orientationCandidateRepairAccepted:Q,orientationRepairDistanceLimit:y,orientationWarning:z,orientationSameDirectionEdgeCount:X?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:X?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:te,nonManifoldCulledTriangleCount:$,boundaryCapTriangleCount:q,splitCullPasses:R?.passCount||0,adjacentBoundaryNormalContributionCount:r.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:r.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalDotThreshold:r.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalFaceFilterCount:r.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:r.adjacentNormalStats?.faceFilterNames||[]}};const ce=E;return E=null,ce}finally{try{E?.free?.()}catch{}}}h(os,"thickenSurfaceToSolid");function NN(r,e,t={}){const n=pS(r,t),i=String(t.sourceFaceName||r?.userData?.faceName||r?.name||"").trim();return os(n,r,e,{...t,sourceFaceNames:Array.isArray(t.sourceFaceNames)?t.sourceFaceNames:i?[i]:void 0,sourceFaceName:i})}h(NN,"thickenFaceToSolid");function RN(r,e,t={}){const n=Array.isArray(r)?r.filter(c=>c?.geometry):[];if(!n.length)throw new Error("Face.thicken() requires at least one face with geometry.");const i=n.map((c,l)=>String(c?.userData?.faceName||c?.name||`FACE_${l+1}`).trim()||`FACE_${l+1}`),s=pm(t.featureId||t.name||i[0]||"THICKEN","THICKEN"),o=String(t.sourceFaceName||`${s}_PATCH`).trim()||`${s}_PATCH`,a=pN(n,t);return os(a,n[0],e,{...t,sourceFaceName:o,sourceFaceNames:i})}h(RN,"thickenFacesToSolid");const H_=class H_ extends At{constructor(e){super(e,fn.FACE.BASE),this.edges=[],this.name=null,this.type="FACE",this.renderOrder=1,this.parentSolid=null,un.attach(this)}getAverageNormal(){const e=this.geometry;if(!e)return new H(0,1,0);const t=e.getAttribute("position");if(!t||t.itemSize!==3||t.count<3)return new H(0,1,0);const n=e.getIndex(),i=new H,s=new H,o=new H,a=new H,c=new H,l=new H,u=h((f,d)=>(f.set(t.getX(d),t.getY(d),t.getZ(d)).applyMatrix4(this.matrixWorld),f),"toWorld");if(n){const f=n.count/3|0;for(let d=0;d<f;d++){const p=n.getX(3*d+0)>>>0,m=n.getX(3*d+1)>>>0,_=n.getX(3*d+2)>>>0;u(i,p),u(s,m),u(o,_),a.subVectors(s,i),c.subVectors(o,i),l.add(c.cross(a))}}else{const f=t.count/3|0;for(let d=0;d<f;d++){const p=3*d+0,m=3*d+1,_=3*d+2;u(i,p),u(s,m),u(o,_),a.subVectors(s,i),c.subVectors(o,i),l.add(c.cross(a))}}return l.lengthSq()===0?new H(0,1,0):l.normalize()}surfaceArea(){const e=this.geometry;if(!e)return 0;const t=e.getAttribute&&e.getAttribute("position");if(!t||t.itemSize!==3)return 0;const n=e.getIndex&&e.getIndex(),i=new H,s=new H,o=new H;let a=0;const c=h((l,u)=>l.set(t.getX(u),t.getY(u),t.getZ(u)).applyMatrix4(this.matrixWorld),"toWorld");if(n){const l=n.count/3|0;for(let u=0;u<l;u++){const f=n.getX(3*u+0)>>>0,d=n.getX(3*u+1)>>>0,p=n.getX(3*u+2)>>>0;c(i,f),c(s,d),c(o,p),a+=dm(i.x,i.y,i.z,s.x,s.y,s.z,o.x,o.y,o.z)}}else{const l=t.count/3|0;for(let u=0;u<l;u++){const f=3*u+0,d=3*u+1,p=3*u+2;c(i,f),c(s,d),c(o,p),a+=dm(i.x,i.y,i.z,s.x,s.y,s.z,o.x,o.y,o.z)}}return a}async points(e=!0){const t=new H,n=[],i=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(i&&i.itemSize===3&&i.count>=2)for(let s=0;s<i.count;s++)t.set(i.getX(s),i.getY(s),i.getZ(s)),e&&t.applyMatrix4(this.matrixWorld),n.push({x:t.x,y:t.y,z:t.z});return n}setMetadata(e){return this.parentSolid&&typeof this.parentSolid.setFaceMetadata=="function"&&this.parentSolid.setFaceMetadata(this.name,e),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getFaceMetadata=="function"?this.parentSolid.getFaceMetadata(this.name):null}renameFace(e){this.parentSolid.renameFace(this.name,e)}thicken(e,t={}){return NN(this,e,t)}getNeighbors(){const e=this,t=e?.name||e?.userData?.faceName||null;if(!t)return[];const n=e.parentSolid||e.userData?.parentSolid||null,i=new Set,s=h(o=>{o&&o!==e&&i.add(o)},"addFace");if(Array.isArray(e.edges)){for(const o of e.edges)if(!(!o||!Array.isArray(o.faces)))for(const a of o.faces)s(a)}if(i.size===0&&n&&typeof n.getBoundaryEdgePolylines=="function"){const o=new Map;if(Array.isArray(n.children)){for(const a of n.children)if(a&&a.type==="FACE"){const c=a.name||a.userData?.faceName||null;c&&o.set(c,a)}}try{const a=n.getBoundaryEdgePolylines()||[];for(const c of a){const l=c?.faceA,u=c?.faceB;l===t&&u?s(o.get(u)):u===t&&l&&s(o.get(l))}}catch{}}return Array.from(i)}};h(H_,"Face");let Sf=H_;const Uv=!1,Mf=h(r=>{if(!r)return{};try{const e=JSON.parse(r);return e&&typeof e=="object"?e:{}}catch{return{}}},"parseMetadataJson"),yi=h((r=[])=>Array.from(r||[],e=>[e?.[0],e?.[1]]),"cloneSnapshotEntries"),ml=h((r,e=t=>t)=>r instanceof Map?Array.from(r.entries(),([t,n])=>[t,e(n)]):[],"toPlainEntryArray"),Bv=h(r=>JSON.stringify(r&&typeof r=="object"?r:{}),"serializeMetadata"),PN=h((r=[],e=3)=>{const t=new Map,n=Math.max(3,Number(e)||3);for(let i=0;i+2<r.length;i+=n){const s=r[i+0],o=r[i+1],a=r[i+2];t.set(`${s},${o},${a}`,i/n|0)}return t},"rebuildVertexKeyMap"),Sd=h(r=>({numProp:Number(r?._numProp??3),vertPropertiesRef:r?._vertProperties||null,vertPropertiesLength:Array.isArray(r?._vertProperties)?r._vertProperties.length:0,triVertsRef:r?._triVerts||null,triVertsLength:Array.isArray(r?._triVerts)?r._triVerts.length:0,triIDsRef:r?._triIDs||null,triIDsLength:Array.isArray(r?._triIDs)?r._triIDs.length:0,faceNameToIDRef:r?._faceNameToID||null,faceNameToIDSize:r?._faceNameToID instanceof Map?r._faceNameToID.size:0,idToFaceNameRef:r?._idToFaceName||null,idToFaceNameSize:r?._idToFaceName instanceof Map?r._idToFaceName.size:0,faceMetadataRef:r?._faceMetadata||null,faceMetadataSize:r?._faceMetadata instanceof Map?r._faceMetadata.size:0,edgeMetadataRef:r?._edgeMetadata||null,edgeMetadataSize:r?._edgeMetadata instanceof Map?r._edgeMetadata.size:0,auxEdgesRef:r?._auxEdges||null,auxEdgesLength:Array.isArray(r?._auxEdges)?r._auxEdges.length:0,faceMetadataVersion:Number(r?._faceMetadataVersion||0),edgeMetadataVersion:Number(r?._edgeMetadataVersion||0),dirty:!!r?._dirty}),"captureSolidCppSyncStamp"),DN=h((r,e)=>!!r&&!!e&&r.numProp===e.numProp&&r.vertPropertiesRef===e.vertPropertiesRef&&r.vertPropertiesLength===e.vertPropertiesLength&&r.triVertsRef===e.triVertsRef&&r.triVertsLength===e.triVertsLength&&r.triIDsRef===e.triIDsRef&&r.triIDsLength===e.triIDsLength&&r.faceNameToIDRef===e.faceNameToIDRef&&r.faceNameToIDSize===e.faceNameToIDSize&&r.idToFaceNameRef===e.idToFaceNameRef&&r.idToFaceNameSize===e.idToFaceNameSize&&r.faceMetadataRef===e.faceMetadataRef&&r.faceMetadataSize===e.faceMetadataSize&&r.edgeMetadataRef===e.edgeMetadataRef&&r.edgeMetadataSize===e.edgeMetadataSize&&r.auxEdgesRef===e.auxEdgesRef&&r.auxEdgesLength===e.auxEdgesLength&&r.faceMetadataVersion===e.faceMetadataVersion&&r.edgeMetadataVersion===e.edgeMetadataVersion&&r.dirty===e.dirty,"solidCppSyncStampEquals"),Xt=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.setAuthoringState=="function"&&typeof r.bakeTransform=="function"&&typeof r.getAuthoringState=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),FN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.weldVerticesByEpsilon=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),LN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.pushFace=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),Ym=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.prepareManifoldMesh=="function"&&typeof r.isCoherentlyOrientedManifold=="function"&&typeof r.fixTriangleWindingsByAdjacency=="function"&&typeof r.invertNormals=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),ON=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.normalizeFaceTracking=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),Md=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.getFace=="function"&&typeof r.getFaces=="function"&&typeof r.getFaceNormal=="function"&&typeof r.getBoundaryEdgePolylines=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),UN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.computeFilletCenterline=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),BN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.addAuxEdge=="function"&&typeof r.getAuxEdges=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),zN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.transformMetadata=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),kN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.cleanupTinyFaceIslands=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),VN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.removeSmallIslands=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),HN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.mergeTinyFaces=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),WN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.removeInternalTriangles=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),GN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.removeDisconnectedIslandsByVolume=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),Rt=h((r,e)=>{if(!r)throw new Error(`${e} requires the custom local manifold build with BrepSolidCore support.`)},"requireCppSolidCoreCapability"),Yo=h(r=>({numProp:Number(r?._numProp??3),vertProperties:Array.from(r?._vertProperties??[]),triVerts:Array.from(r?._triVerts??[]),triIDs:Array.from(r?._triIDs??[]),faceNameToID:ml(r?._faceNameToID),idToFaceName:ml(r?._idToFaceName),faceMetadataJson:ml(r?._faceMetadata,Bv),edgeMetadataJson:ml(r?._edgeMetadata,Bv),auxEdges:bo(r?._auxEdges)}),"buildSolidAuthoringStateSnapshot"),gl=h(r=>new Map(yi(r)),"cloneSnapshotMapEntries"),$N=h((r="INSET")=>String(r||"INSET").toUpperCase()==="OUTSET"?"OUTSET":"INSET","normalizeFilletSideMode"),_S=h(r=>{if(Array.isArray(r)&&r.length>=3){const e=Number(r[0]),t=Number(r[1]),n=Number(r[2]);return Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(n)?[e,t,n]:null}if(r&&typeof r=="object"){const e=Number(r.x),t=Number(r.y),n=Number(r.z);if(Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(n))return[e,t,n]}return null},"point3ArrayFromAny"),Cr=h(r=>{const e=_S(r);return e?{x:e[0],y:e[1],z:e[2]}:null},"point3ObjectFromAny"),bo=h(r=>{const e=Array.isArray(r)?r:[],t=[];for(const n of e){const i=Array.isArray(n?.points)?n.points.map(l=>_S(l)).filter(Boolean):[];if(i.length<2)continue;const s={name:String(n?.name||"EDGE"),points:i,closedLoop:!!n?.closedLoop,polylineWorld:!!n?.polylineWorld,centerline:!!n?.centerline},o=String(n?.materialKey||"").trim();o&&(s.materialKey=o);const a=String(n?.faceA||"").trim(),c=String(n?.faceB||"").trim();a&&(s.faceA=a),c&&(s.faceB=c),t.push(s)}return t},"sanitizeAuxEdges"),XN=h((r,e=1e-9)=>{const t=Array.isArray(r)?r:[];if(t.length===0)return[];const n=Number.isFinite(e)?Math.max(1e-12,Math.abs(e)):1e-9,i=n*n,s=[];for(let d=0;d<t.length;d++){const p=t[d];if(!Array.isArray(p)||p.length<3)continue;const m=Number(p[0]),_=Number(p[1]),y=Number(p[2]);!Number.isFinite(m)||!Number.isFinite(_)||!Number.isFinite(y)||s.push([m,_,y])}if(s.length===0)return[];const o=[];for(let d=0;d<s.length;d++){const p=s[d];if(o.length>0){const m=o[o.length-1],_=p[0]-m[0],y=p[1]-m[1],g=p[2]-m[2];if(_*_+y*y+g*g<=i)continue}o.push(p)}if(o.length<3)return o;let a=0,c=0;for(let d=1;d<o.length;d++){const p=o[d-1],m=o[d],_=Math.hypot(m[0]-p[0],m[1]-p[1],m[2]-p[2]);!Number.isFinite(_)||_<=0||(a+=_,_>c&&(c=_))}const l=Math.max(n,a*1e-7,c*1e-6),u=l*l;if(u<=i)return o;const f=[];for(let d=0;d<o.length;d++){const p=o[d];if(f.length===0){f.push(p);continue}const m=f[f.length-1],_=p[0]-m[0],y=p[1]-m[1],g=p[2]-m[2];_*_+y*y+g*g<=u||f.push(p)}return f.length>=2?f:o},"sanitizeFilletInputPolyline"),qN=h((r=[])=>{const e=new Map;for(const[t,n]of yi(r))e.set(n,t);return e},"invertFaceNameToIDEntries"),YN=h(r=>{const e=Array.from(r?.triIDs??[]),t=new Set(e),n=Array.from(t).sort((o,a)=>Number(o)-Number(a));let i=new Map(yi(r?.idToFaceName));if(i.size===0&&(i=qN(r?.faceNameToID)),n.every(o=>i.has(o))||n.length===0)return i;if(i.size===n.length){const o=Array.from(i.entries()).sort((c,l)=>Number(c[0])-Number(l[0])).map(c=>String(c?.[1]||"")),a=new Map;for(let c=0;c<n.length;c++)a.set(n[c],o[c]||`FACE_${n[c]}`);return a}for(const o of n)i.has(o)||i.set(o,`FACE_${o}`);return i},"buildResolvedSnapshotIDToFaceName"),KN=h(r=>{const e=YN(r),t=new Map,n=new Map,i=new Map,s=h((a,c="")=>{const l=Number(a);if(i.has(l))return i.get(l);const u=Ds.reserveIDs(1);i.set(l,u);const f=String(e.get(a)??c??"").trim()||`FACE_${u}`;return n.set(u,f),t.set(f,u),u},"ensureReservedID");for(const[a,c]of e.entries())s(a,c);return{triIDs:Array.from(r?.triIDs??[],a=>s(a,e.get(a))),faceNameToID:t,idToFaceName:n}},"remapSnapshotFaceIDsToReservedRange"),Wi=h((r,e,t={})=>{const n=Math.max(3,Number(e?.numProp??3)),i=Array.from(e?.vertProperties??[]);let s=null;if(t?.remapFaceIDs)if(ON){const o=new nt.BrepSolidCore;try{o.setAuthoringState(e),o.normalizeFaceTracking();const a=o.getAuthoringState();s={triIDs:Array.from(a?.triIDs??[]),faceNameToID:new Map(yi(a?.faceNameToID)),idToFaceName:new Map(yi(a?.idToFaceName))}}finally{typeof o.delete=="function"&&o.delete()}}else s=KN(e);r._numProp=n,r._vertProperties=i,r._triVerts=Array.from(e?.triVerts??[]),r._triIDs=s?s.triIDs:Array.from(e?.triIDs??[]),r._faceNameToID=s?s.faceNameToID:new Map(yi(e?.faceNameToID)),r._idToFaceName=s?s.idToFaceName:new Map(yi(e?.idToFaceName)),r._faceMetadata=new Map(Array.from(e?.faceMetadataJson??[],o=>[o?.[0],Mf(o?.[1])])),r._edgeMetadata=new Map(Array.from(e?.edgeMetadataJson??[],o=>[o?.[0],Mf(o?.[1])])),r._auxEdges=bo(e?.auxEdges),r._vertKeyToIndex=PN(i,n),r._faceMetadataVersion=Number(r?._faceMetadataVersion||0)+1,r._edgeMetadataVersion=Number(r?._edgeMetadataVersion||0)+1,r._cppSolidCoreSyncStamp=null},"applySolidAuthoringStateSnapshot"),zr=h((r,e)=>(e.setAuthoringState(Yo(r)),r._cppSolidCoreSyncStamp=Sd(r),e),"syncSolidAuthoringStateToCpp"),Sn=h((r,e)=>{const t=e.getAuthoringState();return Wi(r,t),r._cppSolidCoreSyncStamp=Sd(r),t},"syncSolidAuthoringStateFromCpp"),ZN=h((r,e)=>(r._auxEdges=e.getAuxEdges(),r._cppSolidCoreSyncStamp=Sd(r),r._auxEdges),"syncSolidAuxEdgesFromCpp"),Wo=h(r=>{if(Xt)try{return Mn(r).getAuthoringState()}catch{}const e=Yo(r);return{numProp:Number(e?.numProp??3),vertProperties:Array.from(e?.vertProperties??[]),triVerts:Array.from(e?.triVerts??[]),triIDs:Array.from(e?.triIDs??[]),faceNameToID:gl(e?.faceNameToID),idToFaceName:gl(e?.idToFaceName),faceMetadataJson:gl(e?.faceMetadataJson),edgeMetadataJson:gl(e?.edgeMetadataJson),auxEdges:bo(e?.auxEdges),vertexCount:Math.floor((Array.isArray(e?.vertProperties)?e.vertProperties.length:0)/Math.max(3,Number(e?.numProp??3))),triangleCount:Math.floor((Array.isArray(e?.triVerts)?e.triVerts.length:0)/3)}},"getSolidAuthoringStateSnapshot"),Mn=h(r=>{Rt(Xt,"BrepSolidCore"),r._cppSolidCore=r._cppSolidCore||new Gi;const e=Sd(r);return DN(e,r._cppSolidCoreSyncStamp)||zr(r,r._cppSolidCore),r._cppSolidCore},"getSyncedCppSolidCore"),V2=h((r,e=1,t="INSET")=>{const n={points:[],tangentA:[],tangentB:[],edge:[],closedLoop:!1};try{if(Rt(Xt&&UN,"Solid.computeFilletCenterline()"),!r||!Number.isFinite(e)||e<=0)return n;const i=r.parentSolid||r.parent||null;if(!i)return n;const s=r?.faces?.[0]?.name||r?.userData?.faceA||null,o=r?.faces?.[1]?.name||r?.userData?.faceB||null,a=Array.isArray(r?.userData?.segmentFacePairs)?r.userData.segmentFacePairs:null,c=Array.isArray(a)&&a.length>0;if(!c&&(!s||!o))return n;const l=Math.max(1e-12,Math.abs(Number(e)||0)*1e-9,1e-9),u=XN(r?.userData?.polylineLocal,l);if(!Array.isArray(u)||u.length<2)return n;let f=!!(r?.closedLoop||r?.userData?.closedLoop);if(!f&&u.length>2){const m=u[0],_=u[u.length-1],y=m[0]-_[0],g=m[1]-_[1],x=m[2]-_[2];y*y+g*g+x*x<=l*l&&(f=!0)}const d={polyline:u,radius:Number(e),sideMode:$N(t),closedLoop:!!f};s&&(d.faceAName=s),o&&(d.faceBName=o),c&&(d.segmentFacePairs=a);const p=Mn(i).computeFilletCenterline(d);return!p||typeof p!="object"||(n.nativeKernel=p.nativeKernel===!0,n.closedLoop=!!p.closedLoop,n.points=Array.isArray(p.points)?p.points.map(Cr).filter(Boolean):[],n.tangentA=Array.isArray(p.tangentA)?p.tangentA.map(Cr).filter(Boolean):[],n.tangentB=Array.isArray(p.tangentB)?p.tangentB.map(Cr).filter(Boolean):[],n.edge=Array.isArray(p.edge)?p.edge.map(Cr).filter(Boolean):[],p.radiusClamp&&(n.radiusClamp=p.radiusClamp),p.nativeFinalized===!0&&(n.nativeFinalized=!0)),n}catch(i){return console.warn("[computeFilletCenterlineForEdge] failed:",i?.message||i),n}},"computeFilletCenterlineForEdge"),W_=class W_{constructor(e=null){if(e){this._native=e;return}if(typeof nt?.BrepSolidCore!="function")throw new Error("BrepSolidCore is only available in the custom local manifold build.");this._native=new nt.BrepSolidCore}clear(){return this._native.clear(),this}setAuthoringState(e){return this._native.setAuthoringState(e),this}addTriangle(e,t,n,i){return this._native.addTriangle(e,t,n,i),this}setFaceMetadata(e,t={}){return this._native.setFaceMetadataJson(e,JSON.stringify(t||{})),this}getFaceMetadata(e){return Mf(this._native.getFaceMetadataJson(e))}renameFace(e,t){return!!this._native.renameFace(e,t)}cleanupTinyFaceIslands(e){return Number(this._native.cleanupTinyFaceIslands(e))}removeSmallIslands(e,t=!0,n=!0){return Number(this._native.removeSmallIslands(Math.max(0,Number(e)|0),!!t,!!n))}mergeTinyFaces(e){return Number(this._native.mergeTinyFaces(e))}removeInternalTriangles(){return Number(this._native.removeInternalTriangles())}removeDisconnectedIslandsByVolume(e){return Number(this._native.removeDisconnectedIslandsByVolume(e))}normalizeFaceTracking(){return this._native.normalizeFaceTracking(),this}setEdgeMetadata(e,t={}){return this._native.setEdgeMetadataJson(e,JSON.stringify(t||{})),this}getEdgeMetadata(e){return Mf(this._native.getEdgeMetadataJson(e))}getFaceNames(){return Array.from(this._native.getFaceNames()||[])}getFace(e){return Array.from(this._native.getFace(e)||[],t=>({faceName:String(t?.faceName||e||""),indices:Array.from(t?.indices||[]),p1:Array.from(t?.p1||[]),p2:Array.from(t?.p2||[]),p3:Array.from(t?.p3||[])}))}getFaceNormal(e){const t=this._native.getFaceNormal(e)||{};return{faceFound:!!t?.faceFound,validNormal:!!t?.validNormal,normal:Array.from(t?.normal||[]),planarRatio:Number(t?.planarRatio??0),affectedVertexCount:Number(t?.affectedVertexCount??0)}}getFaces(e=!1){return Array.from(this._native.getFaces(!!e)||[],t=>({faceName:String(t?.faceName||""),triangles:Array.from(t?.triangles||[],n=>({faceName:String(n?.faceName||t?.faceName||""),indices:Array.from(n?.indices||[]),p1:Array.from(n?.p1||[]),p2:Array.from(n?.p2||[]),p3:Array.from(n?.p3||[])}))}))}getBoundaryEdgePolylines(){return Array.from(this._native.getBoundaryEdgePolylines()||[],e=>({name:String(e?.name||""),faceA:String(e?.faceA||""),faceB:String(e?.faceB||""),indices:Array.from(e?.indices||[]),positions:Array.from(e?.positions||[],t=>Array.from(t||[])),closedLoop:!!e?.closedLoop}))}addAuxEdge(e,t,n={}){return this._native.addAuxEdge(String(e||"EDGE"),t||[],n||{}),this}setAuxEdges(e=[]){return this._native.setAuxEdges(bo(e)),this}getAuxEdges(){return bo(this._native.getAuxEdges()||[])}computeFilletCenterline(e={}){const t=this._native.computeFilletCenterline(e||{});return{points:Array.from(t?.points||[],n=>Cr(n)).filter(Boolean),tangentA:Array.from(t?.tangentA||[],n=>Cr(n)).filter(Boolean),tangentB:Array.from(t?.tangentB||[],n=>Cr(n)).filter(Boolean),edge:Array.from(t?.edge||[],n=>Cr(n)).filter(Boolean),closedLoop:!!t?.closedLoop,radiusClamp:t?.radiusClamp||null,nativeKernel:t?.nativeKernel===!0,nativeFinalized:t?.nativeFinalized===!0}}getAuthoringState(){const e=this._native.getAuthoringState();return{numProp:Number(e?.numProp??3),vertProperties:Array.from(e?.vertProperties??[]),triVerts:Array.from(e?.triVerts??[]),triIDs:Array.from(e?.triIDs??[]),faceNameToID:new Map(yi(e?.faceNameToID)),idToFaceName:new Map(yi(e?.idToFaceName)),faceMetadataJson:new Map(yi(e?.faceMetadataJson)),edgeMetadataJson:new Map(yi(e?.edgeMetadataJson)),auxEdges:bo(e?.auxEdges),vertexCount:Number(e?.vertexCount??0),triangleCount:Number(e?.triangleCount??0)}}bakeTransform(e){const t=e&&typeof e=="object"&&"elements"in e?Array.from(e.elements||[]):Array.from(e||[]);return this._native.bakeTransform(t),this}transformMetadata(e){const t=e&&typeof e=="object"&&"elements"in e?Array.from(e.elements||[]):Array.from(e||[]);return this._native.transformMetadata(t),this}weldVerticesByEpsilon(e){return this._native.weldVerticesByEpsilon(e),this}pushFace(e,t){return this._native.pushFace(e,t)}isCoherentlyOrientedManifold(){return!!this._native.isCoherentlyOrientedManifold()}fixTriangleWindingsByAdjacency(){return!!this._native.fixTriangleWindingsByAdjacency()}invertNormals(){return this._native.invertNormals(),this}prepareManifoldMesh(){const e=this._native.prepareManifoldMesh();return{numProp:Number(e?.numProp??3),vertProperties:Array.from(e?.vertProperties??[]),triVerts:Array.from(e?.triVerts??[]),faceID:Array.from(e?.faceID??[]),mergeFromVert:Array.from(e?.mergeFromVert??[]),mergeToVert:Array.from(e?.mergeToVert??[]),vertexCount:Number(e?.vertexCount??0),triangleCount:Number(e?.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}}};h(W_,"CppSolidCore");let Gi=W_;function JN(){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=[]}h(JN,"constructorImpl");function jN(){const r=this.constructor,e=new r;return Wi(e,Wo(this)),e._dirty=!0,e._manifold=null,e._faceIndex=null,e._visualizeCache=null,e._minGapIndex=null,e._cppSolidCore=null,e._cppSolidCoreSyncStamp=null,e.type="SOLID",e.renderOrder=this.renderOrder,e}h(jN,"clone");function QN(){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}h(QN,"free");function eR([r,e,t]){return`${r},${e},${t}`}h(eR,"_key");function tR(r){if(!Array.isArray(r)||r.length<3)throw console.error("Invalid point passed to _getPointIndex:",r),new Error("Point must be an array with at least 3 elements");const e=r[0],t=r[1],n=r[2];if(!isFinite(e)||!isFinite(t)||!isFinite(n))throw console.error("Non-finite coordinates in _getPointIndex:",{x:e,y:t,z:n}),new Error(`Invalid point coordinates: (${e}, ${t}, ${n}) - must be finite numbers`);if((this._vertKeyToIndex?.size||0)===0&&Array.isArray(this._vertProperties)&&this._vertProperties.length>0){this._vertKeyToIndex=new Map;for(let a=0;a<this._vertProperties.length;a+=3){const c=this._vertProperties[a+0],l=this._vertProperties[a+1],u=this._vertProperties[a+2];this._vertKeyToIndex.set(`${c},${l},${u}`,a/3|0)}}const i=this._key(r),s=this._vertKeyToIndex.get(i);if(s!==void 0)return s;const o=this._vertProperties.length/3;return this._vertProperties.push(e,t,n),this._vertKeyToIndex.set(i,o),o}h(tR,"_getPointIndex");function nR(r){if(!this._faceNameToID.has(r)){const e=Ds.reserveIDs(1);this._faceNameToID.set(r,e),this._idToFaceName.set(e,r)}return this._faceNameToID.get(r)}h(nR,"_getOrCreateID");function iR(r,e,t,n){const i=this._getOrCreateID(r),s=this._getPointIndex(e),o=this._getPointIndex(t),a=this._getPointIndex(n);return this._triVerts.push(s,o,a),this._triIDs.push(i),this._dirty=!0,this._faceIndex=null,this}h(iR,"addTriangle");function rR(r,e,t={}){try{const n=h(u=>{if(Array.isArray(u)&&u.length===3)return[u[0],u[1],u[2]];if(u&&typeof u=="object"){const f=+u.x,d=+u.y,p=+u.z;if(Number.isFinite(f)&&Number.isFinite(d)&&Number.isFinite(p))return[f,d,p]}return null},"toArr"),i=Array.isArray(e)?e.map(n).filter(Boolean):[];if(i.length<2)return this;const s=r||"EDGE",o=Object.prototype.hasOwnProperty.call(t||{},"centerline"),a=typeof s=="string"&&/centerline/i.test(s),c=o?!!t.centerline:a;Rt(Xt&&BN,"Solid.addAuxEdge()");const l=Mn(this);l.addAuxEdge(s,i,{closedLoop:!!t.closedLoop,polylineWorld:!!t.polylineWorld,materialKey:t.materialKey||"OVERLAY",centerline:c,faceA:t.faceA||"",faceB:t.faceB||""}),ZN(this,l)}catch{}return this}h(rR,"addAuxEdge");function sR(r,e,t="CENTERLINE",n={}){const i=Array.isArray(r)?r:[r?.x||0,r?.y||0,r?.z||0],s=Array.isArray(e)?e:[e?.x||0,e?.y||0,e?.z||0],o={...n||{}};return Object.prototype.hasOwnProperty.call(o,"centerline")||(o.centerline=!0),this.addAuxEdge(t,[i,s],o)}h(sR,"addCenterline");function oR(r,e){if(!e||typeof e!="object")return this;Rt(Xt,"Solid.setFaceMetadata");const t=Mn(this),n=t.getFaceMetadata(r),i=n&&typeof n=="object"?n:{};return t.setFaceMetadata(r,{...i,...e}),Sn(this,t),this}h(oR,"setFaceMetadata");function aR(r){if(Rt(Xt,"Solid.getFaceMetadata"),this._faceMetadata instanceof Map)return this._faceMetadata.get(r)||{};try{return this._cppSolidCore?.getFaceMetadata(r)||{}}catch{return{}}}h(aR,"getFaceMetadata");function cR(){if(Rt(Xt,"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[]}}h(cR,"getFaceNames");function lR(){const r=this._idToFaceName instanceof Map?this._idToFaceName:new Map,e=this._faceNameToID instanceof Map?this._faceNameToID:new Map;if(r.size===0&&e.size===0)return this;const t=new Map,n=new Map,i=new Map;for(const[s,o]of r.entries())t.has(o)?n.set(s,t.get(o)):(t.set(o,s),i.set(s,o));for(const[s,o]of e.entries())t.has(s)||(t.set(s,o),i.set(o,s));return n.size===0?(this._idToFaceName=i,this._faceNameToID=new Map(Array.from(i.entries(),([s,o])=>[o,s])),this):(this._triIDs=Array.isArray(this._triIDs)?this._triIDs.map(s=>n.get(s)??s):[],this._idToFaceName=i,this._faceNameToID=new Map(Array.from(i.entries(),([s,o])=>[o,s])),this._dirty=!0,this._manifold=null,this._faceIndex=null,this._visualizeCache=null,this._cppSolidCoreSyncStamp=null,this)}h(lR,"deduplicateFaceNames");function uR(r,e){if(!r||!e||r===e)return this;Rt(Xt,"Solid.renameFace");const t=Mn(this),n=this._faceMetadata instanceof Map&&this._faceMetadata.has(r),i=n?t.getFaceMetadata(r)||{}:null,s=this._faceMetadata instanceof Map&&this._faceMetadata.has(e)?t.getFaceMetadata(e)||{}:null;return t.renameFace(r,e)?(Sn(this,t),n&&(t.setFaceMetadata(e,{...s&&typeof s=="object"?s:{},...i&&typeof i=="object"?i:{}}),Sn(this,t)),this._dirty=!0,this._faceIndex=null,this):this}h(uR,"renameFace");function fR(r,e){if(!e||typeof e!="object")return this;Rt(Xt,"Solid.setEdgeMetadata");const t=Mn(this),n=t.getEdgeMetadata(r),i=n&&typeof n=="object"?n:{};return t.setEdgeMetadata(r,{...i,...e}),Sn(this,t),this}h(fR,"setEdgeMetadata");function dR(r){if(Rt(Xt,"Solid.getEdgeMetadata"),this._edgeMetadata instanceof Map)return this._edgeMetadata.get(r)||null;try{return this._cppSolidCore?.getEdgeMetadata(r)||null}catch{return null}}h(dR,"getEdgeMetadata");function xS(r,e=Wn){const t=Array.isArray(r?.position)?r.position:[0,0,0],n=Array.isArray(r?.rotationEuler)?r.rotationEuler:[0,0,0],i=Array.isArray(r?.scale)?r.scale:[1,1,1],s=new e.Vector3(Number(t[0]||0),Number(t[1]||0),Number(t[2]||0)),o=new e.Euler(e.MathUtils.degToRad(Number(n[0]||0)),e.MathUtils.degToRad(Number(n[1]||0)),e.MathUtils.degToRad(Number(n[2]||0)),"XYZ"),a=new e.Quaternion().setFromEuler(o),c=new e.Vector3(Number(i[0]||1),Number(i[1]||1),Number(i[2]||1));return new e.Matrix4().compose(s,a,c)}h(xS,"composeTrsMatrixDeg");function vS(r,e,t=Wn){const n=new t.Vector3(Number(r?.position?.[0]||0),Number(r?.position?.[1]||0),Number(r?.position?.[2]||0)),i=new t.Quaternion().fromArray(Array.isArray(r?.quaternion)&&r.quaternion.length>=4?r.quaternion:[0,0,0,1]),s=new t.Vector3(Number(r?.scale?.[0]||1),Number(r?.scale?.[1]||1),Number(r?.scale?.[2]||1)),o=new t.Matrix4().compose(n,i,s),a=xS(e,t);return o.multiply(a)}h(vS,"combineBaseWithDeltaDeg");function hR(r){try{if(!r||typeof r.elements>"u")return this;if(!Array.isArray(this._vertProperties)||this._vertProperties.length===0)return this;const e=r&&r.isMatrix4?r:new tt().fromArray(r.elements||r);Rt(Xt,"Solid.bakeTransform()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),this._cppSolidCore.bakeTransform(e),Sn(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}h(hR,"bakeTransform");function pR(r){try{const e=xS(r,Wn);return this.bakeTransform(e)}catch{return this}}h(pR,"bakeTRS");function mR(r,e){const t=this.constructor,n=r instanceof H?r.clone():new H(r[0],r[1],r[2]),i=e instanceof H?e.clone().normalize():new H(e[0],e[1],e[2]).normalize(),s=Wo(this),o=this.getMesh();try{const a=o.vertProperties,c=o.triVerts,l=o.faceID&&o.faceID.length?Array.from(o.faceID):[],u=new t;u._numProp=o.numProp||3;const f=new Array(a.length),d=new H;for(let p=0;p<a.length;p+=3){d.set(a[p+0],a[p+1],a[p+2]);const _=2*d.clone().sub(n).dot(i),y=d.sub(i.clone().multiplyScalar(_));f[p+0]=y.x,f[p+1]=y.y,f[p+2]=y.z}u._vertProperties=f,u._triVerts=Array.from(c),u._triIDs=l.length?l:new Array(c.length/3|0).fill(0);try{u._idToFaceName=new Map(s?.idToFaceName||[]),u._faceNameToID=new Map(s?.faceNameToID||[]),u._faceMetadata=new Map(Array.from(s?.faceMetadataJson||[],([p,m])=>[p,JSON.parse(m||"{}")])),u._edgeMetadata=new Map(Array.from(s?.edgeMetadataJson||[],([p,m])=>[p,JSON.parse(m||"{}")]))}catch{}try{const p=Array.isArray(this._auxEdges)?this._auxEdges:[],m=new H,_=new H,y=new H;u._auxEdges=p.map(g=>{const x=[];if(Array.isArray(g?.points))for(const w of g.points)!Array.isArray(w)||w.length!==3||(m.set(w[0],w[1],w[2]),_.subVectors(m,n),y.copy(i).multiplyScalar(2*_.dot(i)),m.sub(y),x.push([m.x,m.y,m.z]));return{name:g?.name,closedLoop:!!g?.closedLoop,polylineWorld:!!g?.polylineWorld,materialKey:g?.materialKey,centerline:!!g?.centerline,points:x}}).filter(g=>Array.isArray(g.points)&&g.points.length)}catch{u._auxEdges=[]}u._vertKeyToIndex=new Map;for(let p=0;p<u._vertProperties.length;p+=3){const m=u._vertProperties[p],_=u._vertProperties[p+1],y=u._vertProperties[p+2];u._vertKeyToIndex.set(`${m},${_},${y}`,p/3|0)}u._dirty=!0,u._faceIndex=null,u._manifold=null;try{Rt(Xt&&zN,"Solid.mirrorAcrossPlane()");const p=i.x,m=i.y,_=i.z,y=n.dot(i),g=new tt().set(1-2*p*p,-2*p*m,-2*p*_,2*y*p,-2*m*p,1-2*m*m,-2*m*_,2*y*m,-2*_*p,-2*_*m,1-2*_*_,2*y*_,0,0,0,1);u._cppSolidCore=u._cppSolidCore||new Gi,zr(u,u._cppSolidCore),u._cppSolidCore.transformMetadata(g),Sn(u,u._cppSolidCore),u._cppSolidCore.dispose(),u._cppSolidCore=null,u._cppSolidCoreSyncStamp=null}catch{}return u}finally{try{o&&typeof o.delete=="function"&&o.delete()}catch{}}}h(mR,"mirrorAcrossPlane");function gR(r,e=.001,t={}){const n=Number(e);if(!r||!Number.isFinite(n)||n===0)return this;const i=t?.warnMissing!==!1,s=t?.warnInvalidNormal!==!1;try{this._manifoldize()}catch{}if(this._faceNameToID.get(r)===void 0)return i&&console.warn(`pushFace: Face "${r}" not found`),this;Rt(Xt&&LN,"Solid.pushFace()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore);const a=this._cppSolidCore.pushFace(r,n)||{};if(!a.faceFound)return i&&console.warn(`pushFace: Face "${r}" not found`),this;if(!a.moved)return a.invalidNormal&&s&&console.warn(`pushFace: Invalid normal for face "${r}"`),this;Sn(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}h(gR,"pushFace");function yR(){const r=h(()=>typeof performance<"u"&&performance?.now?performance.now():Date.now(),"nowMs"),e=r();try{this._freeTimer&&clearTimeout(this._freeTimer)}catch{}try{this._freeTimer=setTimeout(()=>{try{this.free()}catch{}},60*1e3)}catch{}if(!this._dirty&&this._manifold){const i=r();return this._manifold}let t=!1;const n=h((i=!0)=>{if(t)return;t=!0;const s=r(),o=(this?._triVerts?.length||0)/3|0,a=(this?._vertProperties?.length||0)/3|0},"__logDone");try{Rt(Xt&&Ym,"Solid._manifoldize()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore);const i=this._cppSolidCore.prepareManifoldMesh();Sn(this,this._cppSolidCore);const s=new UI({numProp:Number(i?.numProp??this._numProp??3),vertProperties:new Float32Array(i?.vertProperties??[]),triVerts:new Uint32Array(i?.triVerts??[]),faceID:new Uint32Array(i?.faceID??[]),mergeFromVert:new Uint32Array(i?.mergeFromVert??[]),mergeToVert:new Uint32Array(i?.mergeToVert??[])});try{this._manifold=new Ds(s)}catch(o){try{if(this&&Object.prototype.hasOwnProperty.call(this,"edgeToFillet")){const a=(this._triVerts?.length||0)/3|0,c=(this._vertProperties?.length||0)/3|0,l=[];try{if(this.edgeToFillet&&Array.isArray(this.edgeToFillet.faces))for(const f of this.edgeToFillet.faces)f&&f.name&&l.push(f.name)}catch{}const u={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:l},counts:{vertices:c,triangles:a,faceLabels:this._faceNameToID&&typeof this._faceNameToID.size=="number"?this._faceNameToID.size:void 0}};try{console.error(JSON.stringify(u))}catch{console.error("[FilletSolidManifoldFailure]",u.message)}}}catch{}throw n(!1),o}finally{try{s&&typeof s.delete=="function"&&s.delete()}catch{}}return this._dirty=!1,this._faceIndex=null,n(!0),this._manifold}finally{const i=!!(this&&this._manifold)&&this._dirty===!1;n(i)}}h(yR,"_manifoldize");function _R(r=0){return this._epsilon=Number(r)||0,this._epsilon>0&&this._weldVerticesByEpsilon(this._epsilon),this}h(_R,"setEpsilon");function xR(r,e={}){Rt(Xt&&FN,"Solid._weldVerticesByEpsilon()");const t=e?.rebuildManifold!==!1;this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),this._cppSolidCore.weldVerticesByEpsilon(r),Sn(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,t&&this._manifoldize(),this}h(xR,"_weldVerticesByEpsilon");function vR(){if(Rt(Xt&&Ym,"Solid.fixTriangleWindingsByAdjacency()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),!this._cppSolidCore.fixTriangleWindingsByAdjacency())return this;Sn(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}h(vR,"fixTriangleWindingsByAdjacency");function bR(){return Rt(Xt&&Ym,"Solid._isCoherentlyOrientedManifold()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),this._cppSolidCore.isCoherentlyOrientedManifold()}h(bR,"_isCoherentlyOrientedManifold");function SR({maxTriangles:r=30,removeInternal:e=!0,removeExternal:t=!0}={}){Rt(Xt&&VN,"Solid.removeSmallIslands()");const n=Mn(this),i=n.removeSmallIslands(r,e,t);if(i>0){Sn(this,n),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return i}h(SR,"removeSmallIslands");function MR({normalDotThreshold:r=-.95}={}){const e=this._triVerts,t=this._vertProperties,n=this._triIDs;if(!e||!t||!n)return 0;const i=e.length/3|0;if(i===0||n.length!==i)return 0;const s=t.length/3|0;if(s===0)return 0;const o=BigInt(Math.max(1,s)),a=h((v,b)=>{const T=BigInt(v),C=BigInt(b);return T<C?T*o+C:C*o+T},"eKey"),c=new Map,l=h((v,b,T,C)=>{let I=c.get(v);I||(I=[0,0,0],c.set(v,I)),I[0]+=b,I[1]+=T,I[2]+=C},"addNormal"),u=new Map;for(let v=0;v<i;v++){const b=n[v];if(b==null)continue;const T=v*3,C=e[T+0]>>>0,I=e[T+1]>>>0,P=e[T+2]>>>0,N=t[C*3+0],D=t[C*3+1],L=t[C*3+2],R=t[I*3+0],q=t[I*3+1],$=t[I*3+2],U=t[P*3+0],K=t[P*3+1],W=t[P*3+2],ne=R-N,Q=q-D,k=$-L,B=U-N,z=K-D,X=W-L,V=Q*X-k*z,te=k*B-ne*X,ce=ne*z-Q*B;l(b,V,te,ce);const le=[[C,I],[I,P],[P,C]];for(let ue=0;ue<3;ue++){let re=le[ue][0],ae=le[ue][1];if(re===ae)continue;const he=a(re,ae);let Ne=u.get(he);if(!Ne){if(re>ae){const J=re;re=ae,ae=J}Ne={faces:new Set,a:re,b:ae},u.set(he,Ne)}Ne.faces.add(b)}}const f=new Map,d=new Map,p=h((v,b)=>{let T=d.get(v);T||(T=new Set,d.set(v,T)),T.add(b)},"addPair");for(const v of u.values()){if(v.faces.size!==2)continue;const b=Array.from(v.faces),T=b[0],C=b[1];if(T===C)continue;const I=T<C?`${T}|${C}`:`${C}|${T}`;let P=f.get(I);P||(P={ids:T<C?[T,C]:[C,T],edges:[]},f.set(I,P)),P.edges.push([v.a,v.b]),p(T,I),p(C,I)}const m=h(v=>{if(!v||v.length===0)return!1;const b=new Map,T=new Set;for(const[P,N]of v)T.add(P),T.add(N),b.has(P)||b.set(P,new Set),b.has(N)||b.set(N,new Set),b.get(P).add(N),b.get(N).add(P);let C=0;const I=new Set;for(const P of T){if(I.has(P))continue;if(C++,C>1)return!1;const N=[P];for(I.add(P);N.length;){const D=N.pop(),L=b.get(D);if(L)for(const R of L)I.has(R)||(I.add(R),N.push(R))}}return C===1},"isSingleEdgeChain"),_=new Set;for(const[v,b]of d.entries()){if(b.size!==1)continue;const T=b.values().next().value,C=f.get(T);if(!C||!C.edges.length||!m(C.edges))continue;const I=C.ids[0]===v?C.ids[1]:C.ids[0],P=c.get(v),N=c.get(I);if(!P||!N)continue;const D=Math.hypot(P[0],P[1],P[2]),L=Math.hypot(N[0],N[1],N[2]);if(!(D>1e-12)||!(L>1e-12))continue;(P[0]*N[0]+P[1]*N[1]+P[2]*N[2])/(D*L)<=r&&_.add(v)}if(!_.size)return 0;const y=new Uint8Array(i);let g=0;for(let v=0;v<i;v++){if(_.has(n[v])){g++;continue}y[v]=1}if(g===0)return 0;const x=new Uint8Array(s),w=[],S=[];for(let v=0;v<i;v++){if(!y[v])continue;const b=v*3,T=e[b+0]>>>0,C=e[b+1]>>>0,I=e[b+2]>>>0;w.push(T,C,I),S.push(n[v]),x[T]=1,x[C]=1,x[I]=1}const E=new Int32Array(s);for(let v=0;v<s;v++)E[v]=-1;const A=[];let M=0;for(let v=0;v<s;v++)x[v]&&(E[v]=M++,A.push(t[v*3+0],t[v*3+1],t[v*3+2]));for(let v=0;v<w.length;v++)w[v]=E[w[v]];this._vertProperties=A,this._triVerts=w,this._triIDs=S,this._vertKeyToIndex=new Map;for(let v=0;v<this._vertProperties.length;v+=3){const b=this._vertProperties[v],T=this._vertProperties[v+1],C=this._vertProperties[v+2];this._vertKeyToIndex.set(`${b},${T},${C}`,v/3|0)}return this._dirty=!0,this._faceIndex=null,this._manifold=null,g}h(MR,"removeOppositeSingleEdgeFaces");function wR(r,e=1){const t=Number(r);if(!Number.isFinite(t)||t<=0)return 0;const n=this._vertProperties;if(!n||n.length<9||this._triVerts.length<3)return 0;const i=h((a,c,l)=>{const u=n[a*3+0],f=n[a*3+1],d=n[a*3+2],p=n[c*3+0],m=n[c*3+1],_=n[c*3+2],y=n[l*3+0],g=n[l*3+1],x=n[l*3+2],w=p-u,S=m-f,E=_-d,A=y-u,M=g-f,v=x-d,b=S*v-E*M,T=E*A-w*v,C=w*M-S*A;return .5*Math.hypot(b,T,C)},"triArea");let s=0;const o=Math.max(1,e|0);for(let a=0;a<o;a++){const c=this._triVerts,l=this._triIDs,u=c.length/3|0;if(u<2)break;const f=new Array(u),d=new Float64Array(u);for(let A=0;A<u;A++){const M=A*3,v=c[M+0]>>>0,b=c[M+1]>>>0,T=c[M+2]>>>0;f[A]=[v,b,T],d[A]=i(v,b,T)}const p=n.length/3|0,m=BigInt(p),_=h((A,M)=>{const v=BigInt(A),b=BigInt(M);return v<b?v*m+b:b*m+v},"eKey"),y=new Map;for(let A=0;A<u;A++){const[M,v,b]=f[A],T=l[A],C=[[M,v],[v,b],[b,M]];for(let I=0;I<3;I++){const P=C[I][0],N=C[I][1],D=_(P,N);let L=y.get(D);L||(L=[],y.set(D,L)),L.push({tri:A,id:T,a:P,b:N})}}const g=[];for(const[A,M]of y.entries()){if(M.length!==2)continue;const v=M[0],b=M[1];if(v.id===b.id)continue;const T=d[v.tri],C=d[b.tri],I=Math.min(T,C);I<t&&g.push({key:A,a:v,b,minAB:I})}g.sort((A,M)=>A.minAB-M.minAB);const x=new Uint8Array(u);let w=0;const S=h((A,M,v)=>{const b=_(A,M),T=y.get(b);if(T){for(let C=0;C<T.length;C++){const I=T[C];if(I.tri===v&&I.a===A&&I.b===M){T.splice(C,1);break}}T.length===0&&y.delete(b)}},"removeUse"),E=h((A,M,v,b)=>{const T=_(A,M);let C=y.get(T);C||(C=[],y.set(T,C)),C.push({tri:v,id:b,a:A,b:M})},"addUse");for(const{a:A,b:M}of g){const v=A.tri,b=M.tri;if(x[v]||x[b])continue;const T=A.a,C=A.b;if(!(M.a===C&&M.b===T))continue;const I=f[v],P=f[b];let N=-1,D=-1;for(let Q=0;Q<3;Q++){const k=I[Q];if(k!==T&&k!==C){N=k;break}}for(let Q=0;Q<3;Q++){const k=P[Q];if(k!==T&&k!==C){D=k;break}}if(N<0||D<0||N===D)continue;const L=_(N,D),R=y.get(L);if(R&&R.length)continue;const q=d[v],$=d[b],U=Math.min(q,$);if(U>=t)continue;const K=i(N,D,T),W=i(D,N,C);!(Number.isFinite(K)&&Number.isFinite(W))||K<=0||W<=0||Math.min(K,W)<U||(f[v]=[N,D,T],f[b]=[D,N,C],d[v]=K,d[b]=W,S(T,C,v),S(C,T,b),S(C,T,v),S(T,C,b),E(N,D,v,l[v]),E(D,N,v,l[v]),E(D,N,b,l[b]),E(N,D,b,l[b]),x[v]=1,x[b]=1,w++)}if(!w)break;s+=w;for(let A=0;A<u;A++){const M=f[A],v=A*3;c[v+0]=M[0],c[v+1]=M[1],c[v+2]=M[2]}this._dirty=!0,this._faceIndex=null}return s>0&&this.fixTriangleWindingsByAdjacency(),s}h(wR,"removeTinyBoundaryTriangles");function AR({maxEdgeLength:r,maxIterations:e=10}={}){const t=Number(r);if(!Number.isFinite(t)||t<=0)return this;const n=t*t,i=h(()=>{const o=this._vertProperties,a=this._triVerts,c=this._triIDs,l=a.length/3|0,u=o.length/3|0,f=BigInt(Math.max(1,u)),d=h((E,A)=>{const M=BigInt(E),v=BigInt(A);return M<v?M*f+v:v*f+M},"ukey"),p=h((E,A)=>{const M=o[E*3+0],v=o[E*3+1],b=o[E*3+2],T=o[A*3+0],C=o[A*3+1],I=o[A*3+2],P=M-T,N=v-C,D=b-I;return P*P+N*N+D*D},"len2"),m=new Set;for(let E=0;E<l;E++){const A=E*3,M=a[A+0]>>>0,v=a[A+1]>>>0,b=a[A+2]>>>0;p(M,v)>n&&m.add(d(M,v)),p(v,b)>n&&m.add(d(v,b)),p(b,M)>n&&m.add(d(b,M))}if(m.size===0)return!1;const _=o.slice(),y=new Map,g=h((E,A)=>{const M=d(E,A);let v=y.get(M);if(v!==void 0)return v;const b=o[E*3+0],T=o[E*3+1],C=o[E*3+2],I=o[A*3+0],P=o[A*3+1],N=o[A*3+2],D=.5*(b+I),L=.5*(T+P),R=.5*(C+N);return v=_.length/3|0,_.push(D,L,R),y.set(M,v),v},"midpointIndex"),x=[],w=[],S=h((E,A,M,v)=>{x.push(E,A,M),w.push(v)},"emit");for(let E=0;E<l;E++){const A=E*3,M=a[A+0]>>>0,v=a[A+1]>>>0,b=a[A+2]>>>0,T=c[E],C=d(M,v),I=d(v,b),P=d(b,M),N=m.has(C),D=m.has(I),L=m.has(P),R=(N?1:0)+(D?1:0)+(L?1:0);if(R===0){S(M,v,b,T);continue}if(R===1){if(N){const K=g(M,v);S(M,K,b,T),S(K,v,b,T)}else if(D){const K=g(v,b);S(v,K,M,T),S(K,b,M,T)}else{const K=g(b,M);S(b,K,v,T),S(K,M,v,T)}continue}if(R===2){if(N&&D){const K=g(M,v),W=g(v,b);S(M,K,b,T),S(v,W,K,T),S(K,W,b,T)}else if(D&&L){const K=g(v,b),W=g(b,M);S(v,K,M,T),S(b,W,K,T),S(K,W,M,T)}else{const K=g(b,M),W=g(M,v);S(b,K,v,T),S(M,W,K,T),S(K,W,v,T)}continue}const q=g(M,v),$=g(v,b),U=g(b,M);S(M,q,U,T),S(v,$,q,T),S(b,U,$,T),S(q,$,U,T)}this._vertProperties=_,this._triVerts=x,this._triIDs=w,this._vertKeyToIndex=new Map;for(let E=0;E<this._vertProperties.length;E+=3){const A=this._vertProperties[E],M=this._vertProperties[E+1],v=this._vertProperties[E+2];this._vertKeyToIndex.set(`${A},${M},${v}`,E/3|0)}return this._dirty=!0,this._faceIndex=null,!0},"pass");let s=!1;for(let o=0;o<e&&i();o++)s=!0;return s&&this.fixTriangleWindingsByAdjacency(),this}h(AR,"remesh");function ER(r){const e=Number(r);if(!Number.isFinite(e)||e<=0)return 0;const t=this._vertProperties,n=this._triVerts,i=n.length/3|0,s=t.length/3|0;if(i===0||s===0)return 0;const o=e*e,a=new Int32Array(s);for(let k=0;k<s;k++)a[k]=k;const c=h(k=>{for(;a[k]!==k;)a[k]=a[a[k]],k=a[k];return k},"find"),l=h((k,B)=>{let z=c(k),X=c(B);if(z===X)return!1;if(X<z){const V=z;z=X,X=V}return a[X]=z,!0},"unite"),u=h((k,B)=>{const z=t[k*3+0],X=t[k*3+1],V=t[k*3+2],te=t[B*3+0],ce=t[B*3+1],le=t[B*3+2],ue=z-te,re=X-ce,ae=V-le;return ue*ue+re*re+ae*ae},"len2");let f=0;for(let k=0;k<i;k++){const B=k*3,z=n[B+0]>>>0,X=n[B+1]>>>0,V=n[B+2]>>>0,te=u(z,X),ce=u(X,V),le=u(V,z);let ue=te,re=z,ae=X;ce<ue&&(ue=ce,re=X,ae=V),le<ue&&(ue=le,re=V,ae=z),ue<o&&l(re,ae)&&f++}if(f===0)return 0;for(let k=0;k<s;k++){const B=c(k);B!==k&&(t[k*3+0]=t[B*3+0],t[k*3+1]=t[B*3+1],t[k*3+2]=t[B*3+2])}this._vertKeyToIndex=new Map;for(let k=0;k<s;k++){const B=t[k*3+0],z=t[k*3+1],X=t[k*3+2];this._vertKeyToIndex.set(`${B},${z},${X}`,k)}this._dirty=!0,this._faceIndex=null;let d=1/0,p=1/0,m=1/0,_=-1/0,y=-1/0,g=-1/0;for(let k=0;k<s;k++){const B=t[k*3+0],z=t[k*3+1],X=t[k*3+2];B<d&&(d=B),B>_&&(_=B),z<p&&(p=z),z>y&&(y=z),X<m&&(m=X),X>g&&(g=X)}if(!Number.isFinite(d)||!Number.isFinite(_))return f;const x=Math.max(1e-9,_-d),w=Math.max(1e-9,y-p),S=Math.max(1e-9,g-m),E=Math.max(x,w,S,e),A=Math.max(e*10,E*.1+1e-6),M=x+2*A,v=w+2*A,b=S+2*A,T=d-A,C=p-A,I=m-A,P=this.constructor,N=new P,D=[T,C,I],L=[T+M,C,I],R=[T,C+v,I],q=[T+M,C+v,I],$=[T,C,I+b],U=[T+M,C,I+b],K=[T,C+v,I+b],W=[T+M,C+v,I+b];N.addTriangle("__BIGBOX_NX",D,$,K),N.addTriangle("__BIGBOX_NX",D,K,R),N.addTriangle("__BIGBOX_PX",L,q,W),N.addTriangle("__BIGBOX_PX",L,W,U),N.addTriangle("__BIGBOX_NY",D,L,U),N.addTriangle("__BIGBOX_NY",D,U,$),N.addTriangle("__BIGBOX_PY",R,K,W),N.addTriangle("__BIGBOX_PY",R,W,q),N.addTriangle("__BIGBOX_NZ",D,R,q),N.addTriangle("__BIGBOX_NZ",D,q,L),N.addTriangle("__BIGBOX_PZ",$,U,W),N.addTriangle("__BIGBOX_PZ",$,W,K);const ne=this.intersect(N),Q=ne.getMesh();try{this._numProp=Q.numProp||3,this._vertProperties=Array.from(Q.vertProperties||[]),this._triVerts=Array.from(Q.triVerts||[]);const k=this._triVerts.length/3|0;if(Q.faceID&&Q.faceID.length===k)this._triIDs=Array.from(Q.faceID);else{const B=this.constructor;this._triIDs=B._expandTriIDsFromMesh(Q)}this._vertKeyToIndex=new Map;for(let B=0;B<this._vertProperties.length;B+=3){const z=this._vertProperties[B],X=this._vertProperties[B+1],V=this._vertProperties[B+2];this._vertKeyToIndex.set(`${z},${X},${V}`,B/3|0)}try{this._idToFaceName=new Map(ne._idToFaceName)}catch{throw new Error("Failed to adopt face label mapping from boolean result")}try{this._faceNameToID=new Map([...this._idToFaceName.entries()].map(([B,z])=>[z,B]))}catch{}this._dirty=!1,this._faceIndex=null,this._manifold=null}finally{try{Q&&typeof Q.delete=="function"&&Q.delete()}catch{}}return f}h(ER,"collapseTinyTriangles");function TR(r=!1){const e=r&&typeof r=="object"?r:{},t=r===!0||e.diagnostics===!0,n=e.detectOnly===!0||e.probeOnly===!0,i=Math.max(0,Number(e.maxIntersections)||0),s=Array.from(this._vertProperties||[]),o=Array.from(this._triVerts||[]),a=Array.from(this._triIDs||[]),c=o.length/3|0;if(c<2||s.length<9)return 0;const l={add(O,j){return[O[0]+j[0],O[1]+j[1],O[2]+j[2]]},sub(O,j){return[O[0]-j[0],O[1]-j[1],O[2]-j[2]]},mul(O,j){return[O[0]*j,O[1]*j,O[2]*j]},dot(O,j){return O[0]*j[0]+O[1]*j[1]+O[2]*j[2]},cross(O,j){return[O[1]*j[2]-O[2]*j[1],O[2]*j[0]-O[0]*j[2],O[0]*j[1]-O[1]*j[0]]},len(O){return Math.hypot(O[0],O[1],O[2])},dist(O,j){return Math.hypot(O[0]-j[0],O[1]-j[1],O[2]-j[2])},norm(O){const j=Math.hypot(O[0],O[1],O[2]);return j>0?[O[0]/j,O[1]/j,O[2]/j]:[0,0,0]}},u={sub(O,j){return[O[0]-j[0],O[1]-j[1]]},cross(O,j){return O[0]*j[1]-O[1]*j[0]},dot(O,j){return O[0]*j[0]+O[1]*j[1]},dist(O,j){return Math.hypot(O[0]-j[0],O[1]-j[1])}};let f=1/0,d=1/0,p=1/0,m=-1/0,_=-1/0,y=-1/0;for(let O=0;O<s.length;O+=3){const j=s[O+0],ee=s[O+1],pe=s[O+2];j<f&&(f=j),j>m&&(m=j),ee<d&&(d=ee),ee>_&&(_=ee),pe<p&&(p=pe),pe>y&&(y=pe)}const g=Math.max(1,Math.hypot(m-f,_-d,y-p)),x=Math.max(1e-9,Number(e.snapTolerance)||g*1e-9),w=Math.max(x*8,g*1e-10),S=Math.max(1e-18,g*g*1e-18),E=h(O=>[Math.round(O[0]/x),Math.round(O[1]/x),Math.round(O[2]/x)].join(","),"qPoint"),A=h(O=>[s[O*3+0],s[O*3+1],s[O*3+2]],"sourcePoint"),M=h((O,j,ee)=>l.len(l.cross(l.sub(j,O),l.sub(ee,O)))*.5,"triangleArea3"),v=h((O,j,ee)=>{const pe=l.cross(l.sub(j,O),l.sub(ee,O)),fe=l.len(pe);if(!(fe>1e-18))return null;const de=l.mul(pe,1/fe);return{n:de,d:-l.dot(de,O)}},"planeOf"),b=h((O,j)=>l.dot(O.n,j)+O.d,"signedDistance"),T=h((O,j,ee)=>{const pe=l.norm(l.cross(l.sub(j,O),l.sub(ee,O)));if(l.len(pe)<=0)return null;let fe=l.sub(j,O);if(l.len(fe)<=x&&(fe=l.sub(ee,O)),fe=l.norm(fe),l.len(fe)<=0)return null;const de=l.norm(l.cross(pe,fe));if(l.len(de)<=0)return null;const Re=O;return{origin:Re,u:fe,v:de,n:pe,project(se){const me=l.sub(se,Re);return[l.dot(me,fe),l.dot(me,de)]},unproject(se){return l.add(Re,l.add(l.mul(fe,se[0]),l.mul(de,se[1])))}}},"makeBasis"),C=h((O,j,ee,pe,fe=1e-12)=>{const de=u.sub(ee,j),Re=u.sub(pe,ee),se=u.sub(j,pe),me=u.sub(O,j),xe=u.sub(O,ee),Ce=u.sub(O,pe),be=u.cross(de,me),Pe=u.cross(Re,xe),ie=u.cross(se,Ce);return be>=-fe&&Pe>=-fe&&ie>=-fe||be<=fe&&Pe<=fe&&ie<=fe},"pointInTri2D"),I=h((O,j,ee,pe,fe=1e-12)=>{const de=u.sub(j,O),Re=u.sub(pe,ee),se=u.cross(de,Re),me=u.sub(ee,O),xe=[];if(Math.abs(se)>fe){const ze=u.cross(me,Re)/se,Qe=u.cross(me,de)/se;return ze>=-fe&&ze<=1+fe&&Qe>=-fe&&Qe<=1+fe&&xe.push([O[0]+de[0]*ze,O[1]+de[1]*ze]),xe}if(Math.abs(u.cross(me,de))>fe)return xe;const Ce=Math.abs(de[0])>=Math.abs(de[1])?0:1,be=O[Ce],Pe=j[Ce],ie=ee[Ce],Se=pe[Ce],Ie=Math.min(be,Pe),Ue=Math.max(be,Pe),De=Math.min(ie,Se),_e=Math.max(ie,Se),Te=Math.max(Ie,De),Oe=Math.min(Ue,_e);if(Oe<Te-fe)return xe;const Fe=h(ze=>{const Qe=Pe-be,st=Math.abs(Qe)>fe?(ze-be)/Qe:0;return[O[0]+de[0]*st,O[1]+de[1]*st]},"pointAt");return xe.push(Fe(Te)),Oe>Te+fe&&xe.push(Fe(Oe)),xe},"segmentIntersection2D"),P=h((O,j,ee,pe=1e-10)=>{const fe=u.sub(ee,j),de=u.sub(O,j),Re=u.dot(fe,fe);if(!(Re>pe*pe)||Math.abs(u.cross(fe,de))>pe*Math.sqrt(Re))return!1;const me=u.dot(de,fe)/Re;return me>=-pe&&me<=1+pe},"pointOnSegment2D"),N=h((O,j,ee,pe=x)=>{const fe=l.sub(ee,j),de=l.sub(O,j),Re=l.len(fe);if(!(Re>pe))return l.dist(O,j)<=pe;if(l.len(l.cross(fe,de))>pe*Re)return!1;const me=l.dot(de,fe)/(Re*Re);return me>=-pe&&me<=1+pe},"pointOnSegment3D"),D=h(O=>{const j=[],ee=new Set,pe=h(se=>`${Math.round(se[0]/x)},${Math.round(se[1]/x)}`,"q2");for(const se of O){const me=pe(se);ee.has(me)||(ee.add(me),j.push(se))}if(j.sort((se,me)=>se[0]-me[0]||se[1]-me[1]),j.length<=2)return j;const fe=h((se,me,xe)=>u.cross(u.sub(me,se),u.sub(xe,se)),"cross"),de=[];for(const se of j){for(;de.length>=2&&fe(de[de.length-2],de[de.length-1],se)<=x;)de.pop();de.push(se)}const Re=[];for(let se=j.length-1;se>=0;se--){const me=j[se];for(;Re.length>=2&&fe(Re[Re.length-2],Re[Re.length-1],me)<=x;)Re.pop();Re.push(me)}return de.pop(),Re.pop(),de.concat(Re)},"convexHull2D"),L=h((O,j=ee=>ee)=>{let ee=0;for(let pe=0;pe<O.length;pe++){const fe=j(O[pe]),de=j(O[(pe+1)%O.length]);ee+=fe[0]*de[1]-de[0]*fe[1]}return ee*.5},"polygonArea2D"),R=h((O,j)=>{const ee=[],pe=h(se=>{for(const me of ee)if(l.dist(se,me)<=x)return;ee.push(se)},"add"),fe=O.map(se=>b(j,se));for(let se=0;se<3;se++){const me=(se+1)%3,xe=O[se],Ce=O[me],be=fe[se],Pe=fe[me];if(Math.abs(be)<=w&&pe(xe),Math.abs(be)<=w&&Math.abs(Pe)<=w){pe(Ce);continue}if(be<-w&&Pe>w||be>w&&Pe<-w){const ie=be/(be-Pe);pe([xe[0]+(Ce[0]-xe[0])*ie,xe[1]+(Ce[1]-xe[1])*ie,xe[2]+(Ce[2]-xe[2])*ie])}}if(ee.length<=2)return ee;let de=[ee[0],ee[1]],Re=-1/0;for(let se=0;se<ee.length;se++)for(let me=se+1;me<ee.length;me++){const xe=l.dist(ee[se],ee[me]);xe>Re&&(de=[ee[se],ee[me]],Re=xe)}return de},"trianglePlaneSegment"),q=h((O,j,ee)=>{const pe=O.map(me=>ee.project(me)),fe=j.map(me=>ee.project(me)),de=[],Re=h(me=>{for(const xe of de)if(u.dist(me,xe)<=x)return;de.push(me)},"add2");for(const me of pe)C(me,fe[0],fe[1],fe[2],x)&&Re(me);for(const me of fe)C(me,pe[0],pe[1],pe[2],x)&&Re(me);for(let me=0;me<3;me++){const xe=pe[me],Ce=pe[(me+1)%3];for(let be=0;be<3;be++){const Pe=fe[be],ie=fe[(be+1)%3];for(const Se of I(xe,Ce,Pe,ie,x))Re(Se)}}if(de.length<2)return null;const se=D(de);if(se.length>=3&&Math.abs(L(se))>S){const me=[];for(let xe=0;xe<se.length;xe++)me.push([ee.unproject(se[xe]),ee.unproject(se[(xe+1)%se.length])]);return{type:"segments",segments:me}}return se.length>=2&&u.dist(se[0],se[se.length-1])>x?{type:"segments",segments:[[ee.unproject(se[0]),ee.unproject(se[se.length-1])]]}:null},"coplanarTriangleOverlap"),$=h((O,j)=>{const ee=v(O[0],O[1],O[2]),pe=v(j[0],j[1],j[2]);if(!ee||!pe)return null;const fe=j.map(Fe=>b(ee,Fe)),de=O.map(Fe=>b(pe,Fe)),Re=h(Fe=>Fe.every(ze=>ze>w),"allPositive"),se=h(Fe=>Fe.every(ze=>ze<-w),"allNegative");if(Re(fe)||se(fe)||Re(de)||se(de))return null;const me=l.cross(ee.n,pe.n),xe=l.len(me);if(xe<=1e-8&&fe.every(Fe=>Math.abs(Fe)<=w)&&de.every(Fe=>Math.abs(Fe)<=w)){const Fe=T(O[0],O[1],O[2]);return Fe?q(O,j,Fe):null}if(!(xe>1e-14))return null;const be=R(O,pe),Pe=R(j,ee);if(be.length<2||Pe.length<2){if(be.length===1&&Pe.length===2&&N(be[0],Pe[0],Pe[1]))return{type:"point",point:be[0]};if(Pe.length===1&&be.length===2&&N(Pe[0],be[0],be[1]))return{type:"point",point:Pe[0]};const Fe=be.concat(Pe),ze=[];for(const Qe of Fe)ze.some(st=>l.dist(st,Qe)<=x)||ze.push(Qe);return ze.length===1?{type:"point",point:ze[0]}:null}const ie=l.mul(me,1/xe),Se=be[0],Ie=be.map(Fe=>l.dot(l.sub(Fe,Se),ie)).sort((Fe,ze)=>Fe-ze),Ue=Pe.map(Fe=>l.dot(l.sub(Fe,Se),ie)).sort((Fe,ze)=>Fe-ze),De=Math.max(Ie[0],Ue[0]),_e=Math.min(Ie[1],Ue[1]);if(_e<De-x)return null;const Te=l.add(Se,l.mul(ie,De)),Oe=l.add(Se,l.mul(ie,_e));return l.dist(Te,Oe)>x?{type:"segments",segments:[[Te,Oe]]}:{type:"point",point:Te}},"triangleIntersection"),U=new Array(c);for(let O=0;O<c;O++){const j=O*3,ee=o[j+0]>>>0,pe=o[j+1]>>>0,fe=o[j+2]>>>0,de=[A(ee),A(pe),A(fe)],Re=[Math.min(de[0][0],de[1][0],de[2][0]),Math.min(de[0][1],de[1][1],de[2][1]),Math.min(de[0][2],de[1][2],de[2][2])],se=[Math.max(de[0][0],de[1][0],de[2][0]),Math.max(de[0][1],de[1][1],de[2][1]),Math.max(de[0][2],de[1][2],de[2][2])];U[O]={indices:[ee,pe,fe],id:a[O]??0,points:de,min:Re,max:se,segments:[],pointsOnly:[],segmentKeys:new Set,pointKeys:new Set}}const K=h((O,j)=>{const ee=E(j);O.pointKeys.has(ee)||(O.pointKeys.add(ee),O.pointsOnly.push(j))},"addPointOnly"),W=h((O,j,ee)=>{if(l.dist(j,ee)<=x){K(O,j);return}const pe=E(j),fe=E(ee),de=pe<fe?`${pe}|${fe}`:`${fe}|${pe}`;O.segmentKeys.has(de)||(O.segmentKeys.add(de),O.segments.push([j,ee]))},"addSegment"),ne=h((O,j)=>{const ee=[],pe=h(fe=>{ee.some(de=>l.dist(de,fe)<=x)||ee.push(fe)},"add");for(const fe of O.points)for(const de of j.points)l.dist(fe,de)<=x&&pe(fe);return ee},"sharedCoordinatePoints"),Q=h((O,j,ee,pe)=>{const fe=ne(O,j);if(fe.length!==2)return!1;const de=l.dist(ee,fe[0])<=x&&l.dist(pe,fe[1])<=x,Re=l.dist(ee,fe[1])<=x&&l.dist(pe,fe[0])<=x;return de||Re},"isOnlySharedEdge"),k=h((O,j,ee)=>{const pe=ne(O,j);return pe.length>0&&pe.some(fe=>l.dist(fe,ee)<=x)},"isOnlySharedPoint"),B=h((O,j)=>!(O.max[0]<j.min[0]-w||j.max[0]<O.min[0]-w||O.max[1]<j.min[1]-w||j.max[1]<O.min[1]-w||O.max[2]<j.min[2]-w||j.max[2]<O.min[2]-w),"overlapAABB"),z=Array.from({length:c},(O,j)=>j).sort((O,j)=>U[O].min[0]-U[j].min[0]);let X=0,V=0,te=0;for(let O=0;O<z.length;O++){const j=z[O],ee=U[j];if(!(M(ee.points[0],ee.points[1],ee.points[2])<=S))for(let pe=O+1;pe<z.length;pe++){const fe=z[pe],de=U[fe];if(de.min[0]>ee.max[0]+w)break;if(!B(ee,de)||M(de.points[0],de.points[1],de.points[2])<=S)continue;te++;const Re=$(ee.points,de.points);if(!Re)continue;const se=ne(ee,de);if(se.length>0){const xe=h(Ce=>se.some(be=>l.dist(Ce,be)<=x),"touchesCommonPoint");if(Re.type==="point"&&xe(Re.point))continue;if(Re.type==="segments"){const Ce=Re.segments||[];if(Ce.length&&Ce.every(([be,Pe])=>xe(be)||xe(Pe)))continue}}if(Re.type==="point"){if(k(ee,de,Re.point))continue;if(K(ee,Re.point),K(de,Re.point),V++,n&&i>0&&X+V>=i)return X+V;continue}let me=!1;for(const[xe,Ce]of Re.segments||[])Q(ee,de,xe,Ce)||(W(ee,xe,Ce),W(de,xe,Ce),me=!0);if(me&&(X++,n&&i>0&&X+V>=i))return X+V}}const ce=X+V;if(ce===0)return t&&console.log("[splitSelfIntersectingTriangles] no splittable intersections",{triCount:c,testedPairs:te}),0;const le=new Set,ue=[],re=h(O=>{const j=E(O);le.has(j)||(le.add(j),ue.push(O))},"addEdgeSplitPoint");for(const O of U){for(const[j,ee]of O.segments)re(j),re(ee);for(const j of O.pointsOnly)re(j)}if(ue.length&&ue.length<=1024)for(const O of U)for(const j of ue){if(O.points.some(pe=>l.dist(pe,j)<=x))continue;let ee=!1;for(let pe=0;pe<3;pe++){const fe=O.points[pe],de=O.points[(pe+1)%3];if(N(j,fe,de,x)){ee=!0;break}}ee&&K(O,j)}this._vertProperties=s.slice(),this._vertKeyToIndex=new Map;const ae=new Map;for(let O=0;O<this._vertProperties.length;O+=3){const j=O/3|0,ee=[this._vertProperties[O+0],this._vertProperties[O+1],this._vertProperties[O+2]];this._vertKeyToIndex.set(`${ee[0]},${ee[1]},${ee[2]}`,j),ae.has(E(ee))||ae.set(E(ee),j)}const he=h(O=>{const j=E(O),ee=ae.get(j);if(ee!==void 0)return ee;const pe=this._vertProperties.length/3|0;return this._vertProperties.push(O[0],O[1],O[2]),ae.set(j,pe),this._vertKeyToIndex.set(`${O[0]},${O[1]},${O[2]}`,pe),pe},"getOrCreateVertex"),Ne=h(O=>{const j=T(O.points[0],O.points[1],O.points[2]);if(!j)return null;const ee=[],pe=new Map,fe=new Map,de=[],Re=Math.max(u.dist(j.project(O.points[0]),j.project(O.points[1])),u.dist(j.project(O.points[1]),j.project(O.points[2])),u.dist(j.project(O.points[2]),j.project(O.points[0])),1),se=Math.max(x,Re*1e-10),me=Math.max(1e-18,Re*Re*1e-16),xe=h(ie=>`${Math.round(ie[0]/se)},${Math.round(ie[1]/se)}`,"localKey"),Ce=h(ie=>{const Se=he(ie),Ie=pe.get(Se);if(Ie!==void 0)return Ie;const Ue=j.project(ie),De=xe(Ue),_e=fe.get(De);if(_e!==void 0)return pe.set(Se,_e),_e;const Te=ee.length;return ee.push({global:Se,p3:ie,p2:Ue}),pe.set(Se,Te),fe.set(De,Te),Te},"addLocalPoint"),be=h((ie,Se)=>{const Ie=Ce(ie),Ue=Ce(Se);Ie!==Ue&&de.push([Ie,Ue])},"addLocalSegment"),Pe=O.points.map(Ce);be(O.points[0],O.points[1]),be(O.points[1],O.points[2]),be(O.points[2],O.points[0]);for(const[ie,Se]of O.segments)be(ie,Se);for(const ie of O.pointsOnly){const Se=Ce(ie);for(const Ie of Pe)Se!==Ie&&de.push([Se,Ie])}return{basis:j,localPoints:ee,localSegments:de,original:Pe,eps2:se,area2:me}},"makeLocalRetriangulator"),J=h((O,j,ee,pe,fe)=>{const de=u.sub(j,O),Re=u.sub(ee,O),se=u.sub(pe,O),me=u.sub(pe,ee),xe=u.sub(O,ee),Ce=u.sub(j,ee),be=u.cross(de,Re),Pe=u.cross(de,se),ie=u.cross(me,xe),Se=u.cross(me,Ce);return be*Pe<-fe*fe&&ie*Se<-fe*fe},"segmentProperlyCrosses"),Be=h(O=>{if(!O.segments.length&&!O.pointsOnly.length)return[[O.indices[0],O.indices[1],O.indices[2]]];const j=Ne(O);if(!j)return[[O.indices[0],O.indices[1],O.indices[2]]];const{localPoints:ee,localSegments:pe,original:fe,eps2:de,area2:Re}=j,se=l.norm(l.cross(l.sub(O.points[1],O.points[0]),l.sub(O.points[2],O.points[0]))),me=h(()=>{const Te=pe.length;for(let Oe=0;Oe<Te;Oe++){const[Fe,ze]=pe[Oe],Qe=ee[Fe].p2,st=ee[ze].p2;for(let qe=Oe+1;qe<Te;qe++){const[at,_t]=pe[qe],Ot=ee[at].p2,sn=ee[_t].p2;for(const kt of I(Qe,st,Ot,sn,de)){const ti=j.basis.unproject(kt),wn=(()=>{const Gn=he(ti),Si=ee.findIndex(Mi=>Mi.global===Gn);if(Si>=0)return Si;const ar=ee.length;return ee.push({global:Gn,p3:ti,p2:kt}),ar})()}}}},"addSegmentIntersections");h(()=>{const Te=new Int32Array(ee.length);for(let qe=0;qe<Te.length;qe++)Te[qe]=qe;const Oe=h(qe=>{let at=qe;for(;Te[at]!==at;)at=Te[at];for(;Te[qe]!==qe;){const _t=Te[qe];Te[qe]=at,qe=_t}return at},"find"),Fe=h((qe,at)=>{const _t=Oe(qe),Ot=Oe(at);_t!==Ot&&(Te[Ot]=_t)},"unite");for(const[qe,at]of pe)Fe(qe,at);const ze=Oe(fe[0]),Qe=new Map;for(let qe=0;qe<ee.length;qe++){const at=Oe(qe);let _t=Qe.get(at);_t||(_t=[],Qe.set(at,_t)),_t.push(qe)}const st=h(()=>pe.map(([qe,at])=>[ee[qe].p2,ee[at].p2]),"existingSegments");for(const[qe,at]of Qe.entries()){if(qe===ze||at.some(sn=>fe.includes(sn)))continue;let _t=null;const Ot=st();for(const sn of at){const kt=ee[sn].p2;for(const ti of fe){const wn=ee[ti].p2;let Gn=!0;for(const[ar,Mi]of Ot)if(!(u.dist(kt,ar)<=de||u.dist(kt,Mi)<=de||u.dist(wn,ar)<=de||u.dist(wn,Mi)<=de)&&J(kt,wn,ar,Mi,de)){Gn=!1;break}if(!Gn)continue;const Si=u.dist(kt,wn);(!_t||Si<_t.dist)&&(_t={member:sn,target:ti,dist:Si})}}_t&&pe.push([_t.member,_t.target])}},"connectInteriorComponents")(),me();const Ce=new Set,be=h((Te,Oe)=>{if(Te===Oe||u.dist(ee[Te].p2,ee[Oe].p2)<=de)return;const Fe=Te<Oe?`${Te}|${Oe}`:`${Oe}|${Te}`;Ce.has(Fe)||Ce.add(Fe)},"addEdge");for(const[Te,Oe]of pe){const Fe=ee[Te].p2,ze=ee[Oe].p2,Qe=u.sub(ze,Fe),st=u.dot(Qe,Qe);if(!(st>de*de))continue;const qe=[];for(let at=0;at<ee.length;at++){const _t=ee[at].p2;if(!P(_t,Fe,ze,de))continue;const Ot=u.dot(u.sub(_t,Fe),Qe)/st;qe.push({index:at,t:Ot})}qe.sort((at,_t)=>at.t-_t.t);for(let at=0;at+1<qe.length;at++)be(qe[at].index,qe[at+1].index)}const Pe=new Map;for(const Te of Ce){const[Oe,Fe]=Te.split("|"),ze=Number(Oe),Qe=Number(Fe);Pe.has(ze)||Pe.set(ze,new Set),Pe.has(Qe)||Pe.set(Qe,new Set),Pe.get(ze).add(Qe),Pe.get(Qe).add(ze)}for(const[Te,Oe]of Pe.entries()){const Fe=ee[Te].p2;Pe.set(Te,Array.from(Oe).sort((ze,Qe)=>{const st=ee[ze].p2,qe=ee[Qe].p2;return Math.atan2(st[1]-Fe[1],st[0]-Fe[0])-Math.atan2(qe[1]-Fe[1],qe[0]-Fe[0])}))}const ie=new Set,Se=h((Te,Oe)=>`${Te}>${Oe}`,"directedKey"),Ie=[];for(const Te of Ce){const[Oe,Fe]=Te.split("|");for(const ze of[[Number(Oe),Number(Fe)],[Number(Fe),Number(Oe)]]){let[Qe,st]=ze;if(ie.has(Se(Qe,st)))continue;const qe=[],at=Math.max(12,Ce.size*4);let _t=0;for(;!ie.has(Se(Qe,st))&&_t++<at;){ie.add(Se(Qe,st)),qe.push(Qe);const Ot=Pe.get(st)||[],sn=Ot.indexOf(Qe);if(sn<0||Ot.length===0)break;const kt=Ot[(sn-1+Ot.length)%Ot.length];if(Qe=st,st=kt,Qe===ze[0]&&st===ze[1])break}qe.length>=3&&L(qe,sn=>ee[sn].p2)>Re&&Ie.push(qe)}}const Ue=h((Te,Oe,Fe,ze)=>{const Qe=Math.abs(u.cross(u.sub(Fe,Oe),u.sub(ze,Oe)));if(!(Qe>Re))return!1;const st=Math.abs(u.cross(u.sub(Oe,Te),u.sub(Fe,Te))),qe=Math.abs(u.cross(u.sub(Fe,Te),u.sub(ze,Te))),at=Math.abs(u.cross(u.sub(ze,Te),u.sub(Oe,Te)));return Math.abs(st+qe+at-Qe)>Math.max(Re,Qe*1e-8)?!1:st>Re&&qe>Re&&at>Re},"pointStrictlyInTri2D"),De=h(Te=>{const Oe=[],Fe=Te.slice();L(Fe,st=>ee[st].p2)<0&&Fe.reverse();let Qe=0;for(;Fe.length>3&&Qe++<Te.length*Te.length*4;){let st=!1;for(let qe=0;qe<Fe.length;qe++){const at=Fe[(qe-1+Fe.length)%Fe.length],_t=Fe[qe],Ot=Fe[(qe+1)%Fe.length],sn=ee[at].p2,kt=ee[_t].p2,ti=ee[Ot].p2;if(u.cross(u.sub(kt,sn),u.sub(ti,kt))<=Re)continue;let wn=!1;for(const Gn of Fe)if(!(Gn===at||Gn===_t||Gn===Ot)&&Ue(ee[Gn].p2,sn,kt,ti)){wn=!0;break}if(!wn){Oe.push([at,_t,Ot]),Fe.splice(qe,1),st=!0;break}}if(!st){for(let qe=1;qe+1<Fe.length;qe++)Oe.push([Fe[0],Fe[qe],Fe[qe+1]]);Fe.length=0}}return Fe.length===3&&Oe.push([Fe[0],Fe[1],Fe[2]]),Oe},"triangulateLoop"),_e=[];for(const Te of Ie)for(const Oe of De(Te)){const Fe=ee[Oe[0]],ze=ee[Oe[1]],Qe=ee[Oe[2]];if(M(Fe.p3,ze.p3,Qe.p3)<=S)continue;const st=l.cross(l.sub(ze.p3,Fe.p3),l.sub(Qe.p3,Fe.p3));l.dot(st,se)<0?_e.push([Fe.global,Qe.global,ze.global]):_e.push([Fe.global,ze.global,Qe.global])}return _e.length?_e:[[O.indices[0],O.indices[1],O.indices[2]]]},"retriangulateRecord"),ge=[],Ae=[];let Ee=0;for(let O=0;O<c;O++){const j=U[O],ee=Be(j);(j.segments.length||j.pointsOnly.length)&&Ee++;for(const pe of ee)ge.push(pe[0],pe[1],pe[2]),Ae.push(j.id)}this._triVerts=ge,this._triIDs=Ae,this._dirty=!0,this._faceIndex=null,this._manifold=null;try{this.removeDegenerateTriangles()}catch{}const F=h(()=>{const O=this._triVerts||[],j=this._vertProperties||[],ee=this._triIDs||[],pe=O.length/3|0,fe=new Set,de=[],Re=[];let se=0;for(let me=0;me<pe;me++){const xe=me*3,Ce=[O[xe+0]>>>0,O[xe+1]>>>0,O[xe+2]>>>0],be=Ce.map(Pe=>E([j[Pe*3+0],j[Pe*3+1],j[Pe*3+2]])).sort().join("|");if(fe.has(be)){se++;continue}fe.add(be),de.push(Ce[0],Ce[1],Ce[2]),Re.push(ee[me])}return se?(this._triVerts=de,this._triIDs=Re,this._dirty=!0,this._faceIndex=null,this._manifold=null,se):0},"removeDuplicateTriangles")();return h(()=>{const O=this._triVerts||[],j=this._vertProperties||[],ee=j.length/3|0,pe=new Uint8Array(ee);for(const se of O)pe[se>>>0]=1;const fe=new Int32Array(ee);for(let se=0;se<ee;se++)fe[se]=-1;const de=[];let Re=0;for(let se=0;se<ee;se++)pe[se]&&(fe[se]=Re++,de.push(j[se*3+0],j[se*3+1],j[se*3+2]));for(let se=0;se<O.length;se++)O[se]=fe[O[se]>>>0];this._vertProperties=de,this._vertKeyToIndex=new Map;for(let se=0;se<de.length;se+=3)this._vertKeyToIndex.set(`${de[se]},${de[se+1]},${de[se+2]}`,se/3|0)},"compactVertices")(),t&&console.log("[splitSelfIntersectingTriangles] complete",{initialTriangles:c,finalTriangles:this._triVerts.length/3|0,testedPairs:te,pairIntersections:X,pointIntersections:V,touchedTriangles:Ee,duplicateRemovals:F}),ce}h(TR,"splitSelfIntersectingTriangles");function CR(){if(!this._triVerts||!this._vertProperties)return 0;try{this._manifoldize()}catch{console.log("[removeDegenerateTriangles] manifoldization failed, proceeding with best effort cleanup")}const r={sub:h((o,a)=>[o[0]-a[0],o[1]-a[1],o[2]-a[2]],"sub"),len:h(o=>Math.sqrt(o[0]*o[0]+o[1]*o[1]+o[2]*o[2]),"len"),cross:h((o,a)=>[o[1]*a[2]-o[2]*a[1],o[2]*a[0]-o[0]*a[2],o[0]*a[1]-o[1]*a[0]],"cross")},e=this._triVerts.length/3,t=[],n=[];let i=0;const s=h(o=>{const a=o*3,c=this._triVerts[a]*3,l=this._triVerts[a+1]*3,u=this._triVerts[a+2]*3,f=[this._vertProperties[c],this._vertProperties[c+1],this._vertProperties[c+2]],d=[this._vertProperties[l],this._vertProperties[l+1],this._vertProperties[l+2]],p=[this._vertProperties[u],this._vertProperties[u+1],this._vertProperties[u+2]],m=1e-10,_=r.len(r.sub(f,d)),y=r.len(r.sub(d,p)),g=r.len(r.sub(p,f));if(_<m||y<m||g<m)return!0;const x=r.cross(r.sub(d,f),r.sub(p,f));return .5*r.len(x)<1e-12},"isDegenerate");for(let o=0;o<e;o++)if(s(o))i++;else{const a=o*3;t.push(this._triVerts[a]),t.push(this._triVerts[a+1]),t.push(this._triVerts[a+2]),n.push(this._triIDs[o])}return this._triVerts=t,this._triIDs=n,i>0&&(this._dirty=!0,this._faceIndex=null,this._manifold=null),i}h(CR,"removeDegenerateTriangles");function IR(){if((this._triVerts.length/3|0)===0)return 0;Rt(Xt&&WN,"Solid.removeInternalTriangles()");const e=Mn(this),t=e.removeInternalTriangles();Sn(this,e),this._dirty=!1,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,t>0?t:0}h(IR,"removeInternalTriangles");function NR(){const r=this._vertProperties,e=this._triVerts,t=this._triIDs,n=e.length/3|0;if(n===0)return 0;const i=new Array(n);for(let b=0;b<n;b++){const T=b*3,C=e[T+0]>>>0,I=e[T+1]>>>0,P=e[T+2]>>>0;i[b]=[[r[C*3+0],r[C*3+1],r[C*3+2]],[r[I*3+0],r[I*3+1],r[I*3+2]],[r[P*3+0],r[P*3+1],r[P*3+2]]]}let s=1/0,o=1/0,a=1/0,c=-1/0,l=-1/0,u=-1/0;for(let b=0;b<r.length;b+=3){const T=r[b],C=r[b+1],I=r[b+2];T<s&&(s=T),T>c&&(c=T),C<o&&(o=C),C>l&&(l=C),I<a&&(a=I),I>u&&(u=I)}const d=1e-6*(Math.hypot(c-s,l-o,u-a)||1),p=h((b,T,C)=>{const P=C[0][0],N=C[0][1],D=C[0][2],L=C[1][0],R=C[1][1],q=C[1][2],$=C[2][0],U=C[2][1],K=C[2][2],W=L-P,ne=R-N,Q=q-D,k=$-P,B=U-N,z=K-D,X=T[1]*z-T[2]*B,V=T[2]*k-T[0]*z,te=T[0]*B-T[1]*k,ce=W*X+ne*V+Q*te;if(Math.abs(ce)<1e-12)return null;const le=1/ce,ue=b[0]-P,re=b[1]-N,ae=b[2]-D,he=(ue*X+re*V+ae*te)*le;if(he<-1e-12||he>1+1e-12)return null;const Ne=re*Q-ae*ne,J=ae*W-ue*Q,Be=ue*ne-re*W,ge=(T[0]*Ne+T[1]*J+T[2]*Be)*le;if(ge<-1e-12||he+ge>1+1e-12)return null;const Ae=(k*Ne+B*J+z*Be)*le;return Ae>1e-10?Ae:null},"rayTri"),m=h(b=>{const T=[[1,0,0],[0,1,0],[0,0,1]];let C=0;for(let I=0;I<T.length;I++){const P=T[I],N=[b[0]+(I+1)*d,b[1]+(I+2)*d,b[2]+(I+3)*d];let D=0;for(let L=0;L<i.length;L++)p(N,P,i[L])!==null&&D++;D%2===1&&C++}return C>=2},"pointInside"),_=h(b=>{const[T,C,I]=i[b],P=(T[0]+C[0]+I[0])/3+d,N=(T[1]+C[1]+I[1])/3+d,D=(T[2]+C[2]+I[2])/3+d;return[P,N,D]},"triProbe"),y=new Uint8Array(n);for(let b=0;b<n;b++)y[b]=1;let g=0;for(let b=0;b<n;b++){const T=_(b);m(T)&&(y[b]=0,g++)}if(g===0)return 0;const x=r.length/3|0,w=new Uint8Array(x),S=[],E=[];for(let b=0;b<n;b++){if(!y[b])continue;const T=b*3,C=e[T+0]>>>0,I=e[T+1]>>>0,P=e[T+2]>>>0;S.push(C,I,P),E.push(t[b]),w[C]=1,w[I]=1,w[P]=1}const A=new Int32Array(x);for(let b=0;b<x;b++)A[b]=-1;const M=[];let v=0;for(let b=0;b<x;b++)w[b]&&(A[b]=v++,M.push(r[b*3+0],r[b*3+1],r[b*3+2]));for(let b=0;b<S.length;b++)S[b]=A[S[b]];this._vertProperties=M,this._triVerts=S,this._triIDs=E,this._vertKeyToIndex=new Map;for(let b=0;b<this._vertProperties.length;b+=3){const T=this._vertProperties[b],C=this._vertProperties[b+1],I=this._vertProperties[b+2];this._vertKeyToIndex.set(`${T},${C},${I}`,b/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),g}h(NR,"removeInternalTrianglesByRaycast");function RR({offsetScale:r=1e-5,crossingTolerance:e=.05}={}){const t=this._vertProperties,n=this._triVerts,i=this._triIDs,s=n.length/3|0;if(s===0)return 0;let o=1/0,a=1/0,c=1/0,l=-1/0,u=-1/0,f=-1/0;for(let P=0;P<t.length;P+=3){const N=t[P],D=t[P+1],L=t[P+2];N<o&&(o=N),N>l&&(l=N),D<a&&(a=D),D>u&&(u=D),L<c&&(c=L),L>f&&(f=L)}const d=Math.hypot(l-o,u-a,f-c)||1,p=r*d,m=new Array(s),_=new Array(s),y=new Array(s);for(let P=0;P<s;P++){const N=P*3,D=n[N+0]>>>0,L=n[N+1]>>>0,R=n[N+2]>>>0,q=t[D*3+0],$=t[D*3+1],U=t[D*3+2],K=t[L*3+0],W=t[L*3+1],ne=t[L*3+2],Q=t[R*3+0],k=t[R*3+1],B=t[R*3+2];m[P]=[[q,$,U],[K,W,ne],[Q,k,B]],_[P]=[(q+K+Q)/3,($+W+k)/3,(U+ne+B)/3];const z=K-q,X=W-$,V=ne-U,te=Q-q,ce=k-$,le=B-U;let ue=X*le-V*ce,re=V*te-z*le,ae=z*ce-X*te;const he=Math.hypot(ue,re,ae);he<1e-18?y[P]=[0,0,0]:y[P]=[ue/he,re/he,ae/he]}const g=h((P,N,D,L)=>{const R=N[0]-P[0],q=N[1]-P[1],$=N[2]-P[2],U=D[0]-P[0],K=D[1]-P[1],W=D[2]-P[2],ne=L[0]-P[0],Q=L[1]-P[1],k=L[2]-P[2],B=Math.hypot(R,q,$),z=Math.hypot(U,K,W),X=Math.hypot(ne,Q,k);if(B<1e-18||z<1e-18||X<1e-18)return 0;const V=R*U+q*K+$*W,te=U*ne+K*Q+W*k,ce=ne*R+Q*q+k*$,le=q*W-$*K,ue=$*U-R*W,re=R*K-q*U,ae=le*ne+ue*Q+re*k,he=B*z*X+V*X+te*B+ce*z;return 2*Math.atan2(ae,he)},"solidAngle"),x=h(P=>{let N=0;for(let D=0;D<s;D++){const[L,R,q]=m[D];N+=g(P,L,R,q)}return N/(4*Math.PI)},"winding"),w=new Uint8Array(s);for(let P=0;P<s;P++)w[P]=1;let S=0;const E=Math.max(0,Math.min(.49,e));for(let P=0;P<s;P++){const N=y[P];if(!N||N[0]===0&&N[1]===0&&N[2]===0)continue;const D=_[P],L=[D[0]+N[0]*p,D[1]+N[1]*p,D[2]+N[2]*p],R=[D[0]-N[0]*p,D[1]-N[1]*p,D[2]-N[2]*p],q=x(L),$=x(R),U=Math.abs(q)-.5,K=Math.abs($)-.5;U<-E&&K>E||U>E&&K<-E||U*K<-E*E||(w[P]=0,S++)}if(S===0)return 0;const A=t.length/3|0,M=new Uint8Array(A),v=[],b=[];for(let P=0;P<s;P++){if(!w[P])continue;const N=P*3,D=n[N+0]>>>0,L=n[N+1]>>>0,R=n[N+2]>>>0;v.push(D,L,R),b.push(i[P]),M[D]=1,M[L]=1,M[R]=1}const T=new Int32Array(A);for(let P=0;P<A;P++)T[P]=-1;const C=[];let I=0;for(let P=0;P<A;P++)M[P]&&(T[P]=I++,C.push(t[P*3+0],t[P*3+1],t[P*3+2]));for(let P=0;P<v.length;P++)v[P]=T[v[P]];this._vertProperties=C,this._triVerts=v,this._triIDs=b,this._vertKeyToIndex=new Map;for(let P=0;P<this._vertProperties.length;P+=3){const N=this._vertProperties[P],D=this._vertProperties[P+1],L=this._vertProperties[P+2];this._vertKeyToIndex.set(`${N},${D},${L}`,P/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),S}h(RR,"removeInternalTrianglesByWinding");function PR(r){const e=Number(r);if(!Number.isFinite(e)||e<=0)return 0;Rt(Xt&&kN,"Solid.cleanupTinyFaceIslands()");const t=Mn(this),n=t.cleanupTinyFaceIslands(e);if(n>0){Sn(this,t),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return n}h(PR,"cleanupTinyFaceIslands");function DR(r=.001){if(!Number.isFinite(r)||r<=0)return this;Rt(Xt&&HN,"Solid.mergeTinyFaces()");const e=Mn(this);if(e.mergeTinyFaces(r)>0){Sn(this,e),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}h(DR,"mergeTinyFaces");function FR(){return this._manifoldize().getMesh()}h(FR,"getMesh");function LR(){if(this._faceIndex)return;const r=this.getMesh(),{triVerts:e,faceID:t}=r,n=e.length/3|0,i=new Map;if(t&&t.length===n)for(let s=0;s<n;s++){const o=t[s];let a=i.get(o);a||(a=[],i.set(o,a)),a.push(s)}this._faceIndex=i;try{r&&typeof r.delete=="function"&&r.delete()}catch{}}h(LR,"_ensureFaceIndex");function OR(r){return Rt(Md,"Solid.getFace"),Mn(this).getFace(r)}h(OR,"getFace");function UR(r){return Rt(Md,"Solid.getFaceNormal"),Mn(this).getFaceNormal(r)}h(UR,"getFaceNormal");function BR(r=!1){return Rt(Md,"Solid.getFaces"),Mn(this).getFaces(r)}h(BR,"getFaces");function zR(){return Rt(Md,"Solid.getBoundaryEdgePolylines"),Mn(this).getBoundaryEdgePolylines()}h(zR,"getBoundaryEdgePolylines");const Go=.01,kR=.0015,bS=1e-4;function VR(){return typeof nt?.buildBooleanCombinedAuthoringState=="function"}h(VR,"hasNativeBooleanCombinedBuilder");function SS(){return typeof nt?.buildBooleanUnionManyAuthoringState=="function"}h(SS,"hasNativeBooleanUnionManyBuilder");function HR(r){if(!VR())throw new Error(`${r} requires the custom local manifold build with native boolean result reconstruction support.`)}h(HR,"requireNativeBooleanCombinedBuilder");function WR(r){if(!SS())throw new Error(`${r} requires the custom local manifold build with native batch union result reconstruction support.`)}h(WR,"requireNativeBooleanUnionManyBuilder");function _c(r){const e=r&&r.constructor;return e&&e.BaseSolid?e.BaseSolid:e}h(_c,"baseSolidCtor$1");function GR(r){const e=r&&r._vertProperties;if(!Array.isArray(e)||e.length<3)return 1;let t=1/0,n=1/0,i=1/0,s=-1/0,o=-1/0,a=-1/0;for(let c=0;c<e.length;c+=3){const l=e[c],u=e[c+1],f=e[c+2];l<t&&(t=l),l>s&&(s=l),u<n&&(n=u),u>o&&(o=u),f<i&&(i=f),f>a&&(a=f)}return Math.max(Math.hypot(s-t,o-n,a-i),1)}h(GR,"booleanApproxScale");function xh(r,e=12){return[Number(r?.[0]||0).toFixed(e),Number(r?.[1]||0).toFixed(e),Number(r?.[2]||0).toFixed(e)].join(",")}h(xh,"pointKey");function MS(r,e){if(!r||typeof r.getFace!="function"||!e)return[];const t=r.getFace(e)||[],n=new Map,i=h((a,c)=>{if(!Array.isArray(a)||!Array.isArray(c))return;const l=xh(a),u=xh(c),f=l<u?`${l}|${u}`:`${u}|${l}`,d=n.get(f);d?d.count+=1:n.set(f,{count:1,points:[[Number(a[0])||0,Number(a[1])||0,Number(a[2])||0],[Number(c[0])||0,Number(c[1])||0,Number(c[2])||0]]})},"addEdge");for(const a of t){const c=Array.isArray(a?.p1)?a.p1:null,l=Array.isArray(a?.p2)?a.p2:null,u=Array.isArray(a?.p3)?a.p3:null;!c||!l||!u||(i(c,l),i(l,u),i(u,c))}const s=[],o=new Set;for(const a of n.values())if(a.count===1)for(const c of a.points){const l=xh(c);o.has(l)||(o.add(l),s.push(c))}return s}h(MS,"faceBoundaryPoints");function $R(r,e,t){if(!r||typeof r.minGapToPoint!="function")return!1;for(const n of e){const i=r.minGapToPoint(n,t,{nearestOnly:!0});if(Array.isArray(i)&&i.some(s=>Number(s?.distance)<=t))return!0}return!1}h($R,"hasNearTargetEdgePoint");function XR(r,e,t,n,i=8){const s=MS(e,t);if(!s.length||typeof r?.minGapToPoint!="function")return-1/0;const o=Math.max(1,Math.ceil(s.length/i)),a=Math.max(GR(r)*2,bS*10);let c=0,l=0;for(let u=0;u<s.length;u+=o){l+=1;const f=r.minGapToPoint(s[u],a,{nearestOnly:!0});(Array.isArray(f)&&f.length>0?f[0].inside===!0:!1)===n&&(c+=1)}return l>0?c/l:-1/0}h(XR,"scoreFaceSide");function wS(r,e,t){const n=String(r||"").toUpperCase();if(n!=="UNION"&&n!=="SUBTRACT"||!e||!t||typeof e.minGapToPoint!="function"||typeof t.getFaceNames!="function"||typeof t.pushFace!="function")return t;const i=n==="UNION",s=bS,o=s*2,a=[];for(const u of t.getFaceNames()||[]){const f=String(u||"").trim();if(!f)continue;const d=MS(t,f);d.length&&$R(e,d,s)&&a.push(f)}if(!a.length||typeof t.clone!="function")return t;const c=t.clone();let l=!1;for(const u of a){let f=null;for(const d of[1,-1]){const p=typeof c.clone=="function"?c.clone():null;if(p)try{p.pushFace(u,d*o,{warnMissing:!1,warnInvalidNormal:!1});const m=XR(e,p,u,i);(!f||m>f.score)&&(f={sign:d,score:m})}catch{}}if(!(!f||!(f.score>-1/0)))try{c.pushFace(u,f.sign*o,{warnMissing:!1,warnInvalidNormal:!1}),l=!0}catch{}}return l?c:t}h(wS,"conditionEdgePointProximity");function Km(r,e,t){const n=new r;Wi(n,e),n._dirty=!0,n._manifold=null,n._faceIndex=null;try{n.name=t||e?.name||n?.name}catch{}return n}h(Km,"solidFromNativeBooleanSnapshot");function wf(r){return r instanceof Map?Array.from(r.entries(),([e,t])=>[String(e||""),String(t||"")]).filter(e=>e[0]):Array.isArray(r)?Array.from(r,([e,t])=>[String(e||""),String(t||"")]).filter(e=>e[0]):[]}h(wf,"toMetadataJsonEntries");function zv(r){return r instanceof Map?Array.from(r.entries()):Array.isArray(r)?Array.from(r):[]}h(zv,"toSnapshotEntries");function mm(r){return{numProp:Number(r?.numProp??3),vertProperties:Array.from(r?.vertProperties??[]),triVerts:Array.from(r?.triVerts??[]),triIDs:Array.from(r?.triIDs??[]),faceNameToID:zv(r?.faceNameToID),idToFaceName:zv(r?.idToFaceName),faceMetadataJson:wf(r?.faceMetadataJson),edgeMetadataJson:wf(r?.edgeMetadataJson),auxEdges:Array.isArray(r?.auxEdges)?r.auxEdges:[],vertexCount:Number(r?.vertexCount??0),triangleCount:Number(r?.triangleCount??0)}}h(mm,"toNativeBooleanSnapshot");function qR(r,e,t={}){Rt(typeof nt?.buildSolidAuthoringStateFromMesh=="function","Solid.simplify");const n=new Map(e instanceof Map?e:[]),i=new Map;for(const[s,o]of n.entries())i.has(o)||i.set(o,s);return nt.buildSolidAuthoringStateFromMesh({numProp:Number(r?.numProp??3),vertProperties:Array.from(r?.vertProperties??[]),triVerts:Array.from(r?.triVerts??[]),faceID:Array.from(r?.faceID??[]),faceNameToID:Array.from(i.entries()),idToFaceName:Array.from(n.entries()),faceMetadataJson:wf(t?.faceMetadataJson),edgeMetadataJson:wf(t?.edgeMetadataJson),auxEdges:Array.isArray(t?.auxEdges)?t.auxEdges:[],name:t?.name||""})}h(qR,"buildNativeSnapshotFromMesh");function So(r,e){const t=Number(r?.numProp??3)||3,n=(e>>>0)*t,i=r?.vertProperties??[];return[Number(i[n+0])||0,Number(i[n+1])||0,Number(i[n+2])||0]}h(So,"_vec3FromMesh");function AS(r,e,t){const n=e[0]-r[0],i=e[1]-r[1],s=e[2]-r[2],o=t[0]-r[0],a=t[1]-r[1],c=t[2]-r[2];let l=i*c-s*a,u=s*o-n*c,f=n*a-i*o;const d=Math.hypot(l,u,f);return d>0?(l/=d,u/=d,f/=d,{normal:[l,u,f],area2:d}):{normal:[0,0,0],area2:0}}h(AS,"_triangleNormalAndArea");function vh(r,e,t){const n=t[0]-e[0],i=t[1]-e[1],s=t[2]-e[2],o=r[0]-e[0],a=r[1]-e[1],c=r[2]-e[2],l=n*n+i*i+s*s,u=l>0?Math.max(0,Math.min(1,(o*n+a*i+c*s)/l)):0,f=o-n*u,d=a-i*u,p=c-s*u;return f*f+d*d+p*p}h(vh,"_pointSegmentDistanceSq");function YR(r,e,t,n){const i=t[0]-e[0],s=t[1]-e[1],o=t[2]-e[2],a=n[0]-e[0],c=n[1]-e[1],l=n[2]-e[2],u=r[0]-e[0],f=r[1]-e[1],d=r[2]-e[2],p=i*i+s*s+o*o,m=i*a+s*c+o*l,_=a*a+c*c+l*l,y=u*i+f*s+d*o,g=u*a+f*c+d*l,x=p*_-m*m;if(Math.abs(x)>1e-18){const w=(_*y-m*g)/x,S=(p*g-m*y)/x;if(1-w-S>=0&&w>=0&&S>=0){const A=e[0]+i*w+a*S,M=e[1]+s*w+c*S,v=e[2]+o*w+l*S,b=r[0]-A,T=r[1]-M,C=r[2]-v;return b*b+T*T+C*C}}return Math.min(vh(r,e,t),vh(r,t,n),vh(r,n,e))}h(YR,"_pointTriangleDistanceSq");function KR(r){const e={numProp:Number(r?._numProp??3)||3,vertProperties:r?._vertProperties??[],triVerts:r?._triVerts??[],faceID:r?._triIDs??[]},t=Math.min(e.triVerts.length/3|0,e.faceID.length|0),n=[];for(let i=0;i<t;i++){const s=i*3,o=So(e,e.triVerts[s+0]),a=So(e,e.triVerts[s+1]),c=So(e,e.triVerts[s+2]),{normal:l,area2:u}=AS(o,a,c);u>0&&n.push({a:o,b:a,c,id:e.faceID[i]>>>0,normal:l,centroid:[(o[0]+a[0]+c[0])/3,(o[1]+a[1]+c[1])/3,(o[2]+a[2]+c[2])/3]})}return n}h(KR,"_buildTaggedSourceTrianglesFromSolid");function ZR(r){if(!Array.isArray(r)||r.length<512)return{all:r,candidatesForPoint:h(()=>r,"candidatesForPoint")};const e=[1/0,1/0,1/0],t=[-1/0,-1/0,-1/0];for(const l of r){const u=l.centroid;for(let f=0;f<3;f++)u[f]<e[f]&&(e[f]=u[f]),u[f]>t[f]&&(t[f]=u[f])}const n=[Math.max(1e-9,t[0]-e[0]),Math.max(1e-9,t[1]-e[1]),Math.max(1e-9,t[2]-e[2])],i=Math.max(4,Math.min(64,Math.ceil(Math.cbrt(r.length)))),s=[n[0]/i,n[1]/i,n[2]/i],o=new Map,a=h((l,u)=>Math.max(0,Math.min(i-1,Math.floor((l[u]-e[u])/s[u]))),"cellCoord"),c=h((l,u,f)=>`${l},${u},${f}`,"cellKey");for(const l of r){const u=a(l.centroid,0),f=a(l.centroid,1),d=a(l.centroid,2),p=c(u,f,d);let m=o.get(p);m||(m=[],o.set(p,m)),m.push(l)}return{all:r,candidatesForPoint(l){const u=a(l,0),f=a(l,1),d=a(l,2),p=[];for(let m=0;m<=3&&p.length<32;m++)for(let _=Math.max(0,u-m);_<=Math.min(i-1,u+m);_++)for(let y=Math.max(0,f-m);y<=Math.min(i-1,f+m);y++)for(let g=Math.max(0,d-m);g<=Math.min(i-1,d+m);g++){const x=o.get(c(_,y,g));x&&p.push(...x)}return p.length?p:r}}}h(ZR,"_buildRetagCandidateIndex");function JR(r,e){const t=KR(e),n=r?.triVerts?.length/3|0;if(!n||t.length===0)return r;const i=ZR(t),s=new Uint32Array(n);for(let o=0;o<n;o++){const a=o*3,c=So(r,r.triVerts[a+0]),l=So(r,r.triVerts[a+1]),u=So(r,r.triVerts[a+2]),f=[(c[0]+l[0]+u[0])/3,(c[1]+l[1]+u[1])/3,(c[2]+l[2]+u[2])/3],{normal:d,area2:p}=AS(c,l,u);let m=t[0].id,_=1/0;for(const y of i.candidatesForPoint(f)){const g=YR(f,y.a,y.b,y.c),x=p>0?Math.max(-1,Math.min(1,d[0]*y.normal[0]+d[1]*y.normal[1]+d[2]*y.normal[2])):1,w=g+(1-x)*1e-6;w<_&&(_=w,m=y.id)}s[o]=m>>>0}return r.faceID=s,r}h(JR,"retagSimplifiedMeshFromSourceSolid");function Zm(r,e,t,n){HR(`Solid.${String(t||"boolean").toLowerCase()}`);const i=Wo(r),s=Wo(e),o=nt.buildBooleanCombinedAuthoringState({leftSnapshot:mm(i),rightSnapshot:mm(s),operation:t,featureID:String(r?.owningFeatureID||r?.name||t||"BOOLEAN"),name:String(r?.name||`${t}_RESULT`),cleanupTinyFaceIslandsArea:Go,disconnectedIslandMinVolume:Go});return Km(n,o,r?.name||`${t}_RESULT`)}h(Zm,"buildNativeBooleanResult");function Jm(r){const e=r?.message||r?.toString?.()||String(r||"");return String(e||"unknown error").slice(0,240)}h(Jm,"describeBooleanError");function bh(r,e){if(!r||typeof r!="object")return r;try{r.__unionManyDiagnostics={...e}}catch{}try{r.userData={...r.userData||{},unionMany:{...e}}}catch{}return r}h(bh,"attachUnionManyDiagnostics");function Sh(r,e={},t=[]){if(!r||typeof r!="object")return r;const n=String(e?.name||"").trim();if(n)try{r.name=n}catch{}try{r.owningFeatureID=e?.owningFeatureID||e?.featureID||e?.featureId||t.find(i=>i?.owningFeatureID)?.owningFeatureID||r?.owningFeatureID||null}catch{}return r}h(Sh,"applyUnionManyNameAndOwner");function ES(r,e,t={}){return r.union(e,{overlapConditioningEnabled:t?.overlapConditioningEnabled})}h(ES,"unionManyPair");function TS(r,e){try{r.unionManyDiagnostics={...e}}catch{}throw r}h(TS,"throwUnionManyError");function jR(r,e,t){if(!r.length)return null;let n=r[0];for(let i=1;i<r.length;i+=1){const s=r[i];t.unionAttemptCount+=1;try{n={solid:ES(n.solid,s.solid,e),count:n.count+s.count}}catch(o){t.unionFailureCount+=1,t.skippedSolidCount+=s.count,t.firstUnionError||(t.firstUnionError=Jm(o)),e?.skipFailed||TS(o,t)}}return n}h(jR,"unionManyNodesSequential");function QR(r,e,t){let n=r.slice();for(;n.length>1;){const i=[];for(let s=0;s<n.length;s+=2){const o=n[s],a=n[s+1];if(!a){i.push(o);continue}t.unionAttemptCount+=1;try{i.push({solid:ES(o.solid,a.solid,e),count:o.count+a.count})}catch(c){t.unionFailureCount+=1,t.skippedSolidCount+=a.count,t.firstUnionError||(t.firstUnionError=Jm(c)),e?.skipFailed||TS(c,t),i.push(o)}}n=i}return n[0]||null}h(QR,"unionManyNodesBalanced");function eP(r,e=null,t={}){const n=Array.isArray(r)?r.filter(Boolean):[];if(!n.length)return null;WR("Solid.unionMany");const i=e||_c(n[0]),s=n.map(u=>mm(Wo(u))),o=String(t?.featureID||n[0]?.owningFeatureID||n[0]?.name||"UNION"),a=String(t?.name||n[0]?.name||`${o}_UNION`),c=nt.buildBooleanUnionManyAuthoringState({snapshots:s,featureID:o,name:a,cleanupTinyFaceIslandsArea:Number(t?.cleanupTinyFaceIslandsArea??Go),disconnectedIslandMinVolume:Number(t?.disconnectedIslandMinVolume??Go)}),l=Km(i,c,a);try{l.owningFeatureID=t?.owningFeatureID||n.find(u=>u?.owningFeatureID)?.owningFeatureID||l?.owningFeatureID||null}catch{}return wd(l)}h(eP,"buildNativeUnionManyResult");function hc(r,e={}){const t=Array.isArray(r)?r:[r],i=(this&&typeof this=="object"&&typeof this.union=="function"?[this,...t]:t).filter(Boolean),s={unionStrategy:"none",nativeBatchUnionAvailable:SS(),nativeBatchUnionStatus:i.length>1?"not_run":"not_applicable",nativeBatchUnionError:null,unionAttemptCount:0,unionFailureCount:0,skippedSolidCount:0,contributedSolidCount:i.length,firstUnionError:null};if(!i.length)return null;if(i.length===1){s.unionStrategy="single";const d=Sh(i[0],e,i);return bh(d,s)}const o=String(e?.unionStrategy||"native_batch").trim().toLowerCase(),a=e?.nativeBatchUnion!==!1&&o!=="balanced"&&o!=="sequential",c=typeof this=="function"?this.BaseSolid||this:_c(i[0]);if(a&&s.nativeBatchUnionAvailable)try{const d=eP(i,c,{...e,featureID:e?.featureID||e?.featureId,owningFeatureID:e?.owningFeatureID||e?.featureID||e?.featureId});return s.unionStrategy="native_batch",s.nativeBatchUnionStatus="passed",s.contributedSolidCount=i.length,Sh(d,e,i),bh(d,s)}catch(d){s.nativeBatchUnionStatus="failed",s.nativeBatchUnionError=Jm(d)}else s.nativeBatchUnionAvailable?s.nativeBatchUnionStatus="disabled":s.nativeBatchUnionStatus="unavailable";const l=i.map(d=>({solid:d,count:1})),u=o==="sequential"?jR(l,e,s):QR(l,e,s);s.unionStrategy=o==="sequential"?s.nativeBatchUnionStatus==="failed"?"sequential_fallback":"sequential":s.nativeBatchUnionStatus==="failed"?"balanced_fallback":"balanced",s.contributedSolidCount=Number(u?.count||0);const f=Sh(u?.solid||null,e,i);return bh(f,s)}h(hc,"unionMany");function tP(r,e=Go){const t=Number(e);if(!Number.isFinite(t)||t<=0||!r||typeof r!="object")return 0;Rt(GN,"Solid._dropDisconnectedIslandsByVolume");const n=Mn(r),i=n.removeDisconnectedIslandsByVolume(t);if(i>0){Sn(r,n),r._dirty=!0,r._faceIndex=null;try{r._manifold&&typeof r._manifold.delete=="function"&&r._manifold.delete()}catch{}r._manifold=null}return i}h(tP,"_dropDisconnectedIslandsByVolume");function nP(r){const e=Number(kR);return!r||typeof r.setEpsilon!="function"||!Number.isFinite(e)||e<=0||r.setEpsilon(e),r}h(nP,"_applyFixedBooleanResultWeld");function wd(r){try{tP(r,Go)}catch{}return nP(r)}h(wd,"_cleanupBooleanResult");function iP(r,e={}){const t=_c(this),n=e?.overlapConditioningEnabled===!1?this:wS("UNION",r,this),i=Zm(n,r,"UNION",t);try{i.owningFeatureID=this?.owningFeatureID||r?.owningFeatureID||i?.owningFeatureID||null}catch{}return wd(i)}h(iP,"union");function rP(r,e={}){const t=_c(this),n=e?.overlapConditioningEnabled===!1?r:wS("SUBTRACT",this,r),i=Zm(this,n,"SUBTRACT",t);try{i.owningFeatureID=this?.owningFeatureID||r?.owningFeatureID||i?.owningFeatureID||null}catch{}return wd(i)}h(rP,"subtract");function sP(r){const e=_c(this),t=Zm(this,r,"INTERSECT",e);try{t.owningFeatureID=this?.owningFeatureID||r?.owningFeatureID||t?.owningFeatureID||null}catch{}return wd(t)}h(sP,"intersect");function oP(r=void 0,e=!1){e&&typeof e=="object"&&(e=!1);const t=this.constructor,n=this._manifoldize(),i=Wo(this),s=r===void 0?n.simplify():n.simplify(r);let o=null;const a=s.getMesh();try{JR(a,this),o=qR(a,this._idToFaceName,{faceMetadataJson:i?.faceMetadataJson,edgeMetadataJson:i?.edgeMetadataJson,auxEdges:i?.auxEdges,name:this?.name||""})}finally{try{a&&typeof a.delete=="function"&&a.delete()}catch{}}Wi(this,o);try{this._manifold&&this._manifold!==s&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}if(this._manifold=s,this._dirty=!1,this._faceIndex=null,e)return this;this._manifold=null,this._dirty=!0,this._faceIndex=null;const c=Km(t,o,this?.name||"");return this._manifoldize(),c}h(oP,"simplify");function aP(r){return r.faceID&&r.faceID.length?Array.from(r.faceID):new Array(r.triVerts.length/3|0).fill(0)}h(aP,"_expandTriIDsFromMesh");function gm(r){return String(r??"").replace(/'/g,"''")}h(gm,"_escapeStepString");function _i(r,e="NAME"){const t=String(r??"").trim();return gm(t||e)}h(_i,"_safeStepName");function _n(r,e){if(!Number.isFinite(r))return"0";let t=Number(r).toFixed(e);return t.includes(".")&&(t=t.replace(/\.?0+$/,"")),t==="-0"&&(t="0"),t}h(_n,"_fmtNumber");function cP(r,e=6){if(!Number.isFinite(r)||r===0)return"0.";const t=Number(r).toExponential(e),[n,i]=t.split("e"),s=Number(i);return`${n.toUpperCase()}E${s>=0?"+":""}${s}`}h(cP,"_fmtExp");function lP(r,e=1e-12){if(!r||r.length!==16)return!0;const t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let n=0;n<16;n++)if(Math.abs((r[n]??t[n])-t[n])>e)return!1;return!0}h(lP,"_isIdentityMatrixElements");function kv(r,e,t,n){if(!r||r.length!==16)return[e,t,n];const i=r[0]*e+r[4]*t+r[8]*n+r[12],s=r[1]*e+r[5]*t+r[9]*n+r[13],o=r[2]*e+r[6]*t+r[10]*n+r[14],a=r[3]*e+r[7]*t+r[11]*n+r[15];return a&&Math.abs(a-1)>1e-12?[i/a,s/a,o/a]:[i,s,o]}h(kv,"_applyMatrix4");function Aa(r,e=[0,0,1]){const t=r[0],n=r[1],i=r[2],s=Math.hypot(t,n,i);return!s||!Number.isFinite(s)?e.slice():[t/s,n/s,i/s]}h(Aa,"_normalize");function jm(r,e){return[r[1]*e[2]-r[2]*e[1],r[2]*e[0]-r[0]*e[2],r[0]*e[1]-r[1]*e[0]]}h(jm,"_cross");function fs(r,e){return r[0]*e[0]+r[1]*e[1]+r[2]*e[2]}h(fs,"_dot");function Vv(r,e){return[r[0]-e[0],r[1]-e[1],r[2]-e[2]]}h(Vv,"_sub");function Mh(r){const t=Math.abs(r[2])<.9?[0,0,1]:[0,1,0],n=jm(t,r);return Aa(n,[1,0,0])}h(Mh,"_orthogonalRefDir");function wh(r,e=40){if(!r||r.length===0)return"()";if(r.length<=e)return`(${r.map(n=>`#${n}`).join(",")})`;const t=[];for(let n=0;n<r.length;n+=e){const i=r.slice(n,n+e).map(s=>`#${s}`).join(",");t.push(i)}return`(
|
|
4620
|
+
`,document.head.appendChild(e)}};h(z_,"CADmaterialWidget");let Lv=z_;function yr(){const r=document.createElement("div");return r.className="cmw-row",r}h(yr,"makeRightSpan");const k_=class k_ extends xo{constructor(e){super(e,fn.EDGE.BASE),this.faces=[],this.name=null,this.type="EDGE",this.renderOrder=2,this.closedLoop=!1,un.attach(this)}length(){const e=new H,t=new H;let n=0;const i=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null,s=h((a,c,l,u,f,d)=>{e.set(a,c,l).applyMatrix4(this.matrixWorld),t.set(u,f,d).applyMatrix4(this.matrixWorld),n+=e.distanceTo(t)},"addSeg");if(i&&i.length>=2){for(let a=0;a<i.length-1;a++){const c=i[a],l=i[a+1];s(c[0],c[1],c[2],l[0],l[1],l[2])}return n}const o=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(o&&o.itemSize===3&&o.count>=2){for(let a=0;a<o.count-1;a++)s(o.getX(a),o.getY(a),o.getZ(a),o.getX(a+1),o.getY(a+1),o.getZ(a+1));return n}return 0}points(e=!0){const t=new H,n=[],i=this.userData&&Array.isArray(this.userData.polylineLocal)?this.userData.polylineLocal:null;if(i&&i.length){for(let o=0;o<i.length;o++){const a=i[o];t.set(a[0],a[1],a[2]),e&&t.applyMatrix4(this.matrixWorld),n.push({x:t.x,y:t.y,z:t.z})}return n}const s=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(s&&s.itemSize===3&&s.count>=1)for(let o=0;o<s.count;o++)t.set(s.getX(o),s.getY(o),s.getZ(o)),e&&t.applyMatrix4(this.matrixWorld),n.push({x:t.x,y:t.y,z:t.z});return n}collapseToPoint(){const e=this.parentSolid||this.parent||null,t=Array.isArray(e?._vertProperties)?e._vertProperties:null;if(!e||!t||t.length<3)return this;if(this?.userData?.auxEdge)return this;const n=QI(this,e);if(!n.length)return this;let i=0,s=0,o=0,a=0;for(const p of n){const m=p*3|0;m<0||m+2>=t.length||(i+=t[m+0],s+=t[m+1],o+=t[m+2],a++)}if(!a)return this;const c=1/a,l=i*c,u=s*c,f=o*c;for(const p of n){const m=p*3|0;m<0||m+2>=t.length||(t[m+0]=l,t[m+1]=u,t[m+2]=f)}const d=t.length/3|0;e._vertKeyToIndex=new Map;for(let p=0;p<d;p++){const m=p*3;e._vertKeyToIndex.set(`${t[m+0]},${t[m+1]},${t[m+2]}`,p)}e._dirty=!0,e._faceIndex=null;try{e._manifold&&typeof e._manifold.delete=="function"&&e._manifold.delete()}catch{}e._manifold=null;try{typeof e._manifoldize=="function"&&e._manifoldize()}catch(p){console.warn(`[Edge.collapseToPoint] Manifold rebuild failed for edge "${this.name||"UNKNOWN"}":`,p?.message||p)}try{typeof e.visualize=="function"&&e.visualize()}catch(p){console.warn(`[Edge.collapseToPoint] Solid visualize failed for edge "${this.name||"UNKNOWN"}":`,p?.message||p)}return this}setMetadata(e){return this.parentSolid&&typeof this.parentSolid.setEdgeMetadata=="function"&&this.parentSolid.setEdgeMetadata(this.name,e),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getEdgeMetadata=="function"?this.parentSolid.getEdgeMetadata(this.name):null}};h(k_,"Edge");let vo=k_;function QI(r,e){const t=Array.isArray(e?._vertProperties)?e._vertProperties:null;if(!t||t.length<3)return[];const n=(t.length/3|0)-1;let i=[];try{i=typeof e.getBoundaryEdgePolylines=="function"?e.getBoundaryEdgePolylines()||[]:[]}catch{i=[]}const s=eN(r,i);if(s&&Array.isArray(s.indices)&&s.indices.length){const o=[],a=new Set;for(const c of s.indices){const l=Number(c);!Number.isInteger(l)||l<0||l>n||a.has(l)||(a.add(l),o.push(l))}if(o.length)return o}return nN(r?.userData?.polylineLocal,t)}h(QI,"resolveEdgeVertexIndices");function eN(r,e){if(!Array.isArray(e)||e.length===0)return null;const t=typeof r?.name=="string"&&r.name?r.name:null;if(t){const l=e.find(u=>u&&u.name===t);if(l)return l}const n=r?.userData?.faceA,i=r?.userData?.faceB;let s=e;if(n&&i&&(s=e.filter(l=>{if(!l)return!1;const u=l.faceA,f=l.faceB;return u===n&&f===i||u===i&&f===n}),s.length===1))return s[0];const o=Array.isArray(r?.userData?.polylineLocal)?r.userData.polylineLocal:null;if(!o||o.length<2)return s[0]||null;let a=null,c=1/0;for(const l of s){const u=tN(o,l?.positions);u<c&&(c=u,a=l)}return a}h(eN,"findMatchingBoundaryPolyline");function tN(r,e){if(!Array.isArray(r)||r.length<2||!Array.isArray(e)||e.length<2)return 1/0;const t=r[0],n=r[r.length-1],i=e[0],s=e[e.length-1];if(!uo(t)||!uo(n)||!uo(i)||!uo(s))return 1/0;const o=pl(t,i)+pl(n,s),a=pl(t,s)+pl(n,i);return Math.min(o,a)}h(tN,"polylineEndpointScore");function nN(r,e){if(!Array.isArray(r)||r.length===0)return[];const t=e.length/3|0,n=new Map;for(let o=0;o<t;o++){const a=o*3,c=`${e[a+0]},${e[a+1]},${e[a+2]}`;n.has(c)||n.set(c,o)}const i=[],s=new Set;for(const o of r){if(!uo(o))continue;const a=`${o[0]},${o[1]},${o[2]}`;let c=n.get(a);c===void 0&&(c=iN(e,o,1e-9)),!(!Number.isInteger(c)||c<0||s.has(c))&&(s.add(c),i.push(c))}return i}h(nN,"resolveIndicesFromPolylinePoints");function iN(r,e,t=1e-9){if(!Array.isArray(r)||!uo(e)||!Number.isFinite(t)||t<=0)return-1;const n=t*t,i=r.length/3|0;let s=-1,o=n;for(let a=0;a<i;a++){const c=a*3,l=r[c+0]-e[0],u=r[c+1]-e[1],f=r[c+2]-e[2],d=l*l+u*u+f*f;d<=o&&(o=d,s=a)}return s}h(iN,"findNearestVertexIndex");function pl(r,e){const t=r[0]-e[0],n=r[1]-e[1],i=r[2]-e[2];return t*t+n*n+i*i}h(pl,"pointDistanceSq$1");function uo(r){return Array.isArray(r)&&r.length===3&&Number.isFinite(r[0])&&Number.isFinite(r[1])&&Number.isFinite(r[2])}h(uo,"isPoint3");const V_=class V_ extends yt{constructor(e=[0,0,0],t={}){super(),this.type="VERTEX",this.name=t.name||`VERTEX(${e[0]},${e[1]},${e[2]})`,this.position.set(e[0]||0,e[1]||0,e[2]||0);const n=new it;n.setAttribute("position",new $e([0,0,0],3));const i=fn?.VERTEX?.BASE||new Jn({color:"#ffb703",size:6,sizeAttenuation:!1});this._point=new Ss(n,i),this.add(this._point),un.attach(this)}};h(V_,"Vertex");let bf=V_;function dm(r,e,t,n,i,s,o,a,c){const l=n-r,u=i-e,f=s-t,d=o-r,p=a-e,m=c-t,_=u*m-f*p,y=f*d-l*m,g=l*p-u*d;return .5*Math.hypot(_,y,g)}h(dm,"computeTriangleArea");const hm=1e-9,ht=1e-12;function pm(r,e="FACE"){const n=(r==null?"":String(r)).trim();return n&&n.replace(/[:[\]]+/g,"_").replace(/\s+/g,"_").replace(/[^A-Za-z0-9_.-]/g,"_")||e}h(pm,"sanitizeToken$1");function Yt(r,e){const t=r<e?r:e,n=r<e?e:r;return`${t}|${n}`}h(Yt,"edgeKey");function si(r){r&&typeof r=="object"&&(r._cppSolidCoreSyncStamp=null)}h(si,"invalidateCppSolidCoreCache");function fo(r,e){const t=e>0?1/e:1e6;return[Math.round(r.x*t),Math.round(r.y*t),Math.round(r.z*t)].join(",")}h(fo,"pointKey$1");function Fs(r,e,t){return new H().subVectors(e,r).cross(new H().subVectors(t,r))}h(Fs,"triangleNormal");function Xm(r,e,t){return Fs(r,e,t).length()*.5}h(Xm,"triangleArea");function qm(r){const e=r?.userData?.faceName??r?.faceName??r?.name??null;return e==null?null:String(e).trim()||null}h(qm,"getFaceLabel");function rN(r){const e=Array.isArray(r)?r:r==null?[]:[r],t=[],n=new Set;for(const i of e){const s=typeof i=="string"?i:i?.userData?.faceName??i?.faceName??i?.name??null,o=String(s||"").trim();!o||n.has(o)||(n.add(o),t.push(o))}return t}h(rN,"getFaceLabelList");function sN(r,e){const t=rN(r.adjacentNormalFaceNames??r.smoothAdjacentNormalFaceNames??r.selectedFaceNames),n=String(e||"").trim(),i=t.filter(s=>s&&s!==n);return i.length?new Set(i):null}h(sN,"getAdjacentNormalFaceFilter");function oN(r){const e=r?.parentSolid||(String(r?.parent?.type||"").toUpperCase()==="SOLID"?r.parent:null);return String(e?.uuid||e?.id||e?.name||"NO_OWNER")}h(oN,"getFaceOwnerKey");function vl(r,e){return r<e?`${r}|${e}`:`${e}|${r}`}h(vl,"unorderedPointPairKey");function aN(r,e){return!r||!e||r.sourceFaceName!=null&&(e.sourceFaceName=r.sourceFaceName),e}h(aN,"copyTriangleMetadata");function cN(r,e={}){const t=Array.isArray(r)?r.filter(M=>M?.geometry):[];if(t.length<=1)return t.length?[t]:[];const n=new H;let i=1/0,s=1/0,o=1/0,a=-1/0,c=-1/0,l=-1/0;for(const M of t){try{M.updateMatrixWorld?.(!0)}catch{}const v=M.geometry?.getAttribute?.("position");if(!(!v||v.itemSize!==3))for(let b=0;b<v.count;b++)n.set(v.getX(b),v.getY(b),v.getZ(b)).applyMatrix4(M.matrixWorld),n.x<i&&(i=n.x),n.y<s&&(s=n.y),n.z<o&&(o=n.z),n.x>a&&(a=n.x),n.y>c&&(c=n.y),n.z>l&&(l=n.z)}const u=Number.isFinite(i)?Math.max(1,Math.hypot(a-i,c-s,l-o)):1,f=Math.max(Number(e.weldTolerance)||0,Math.max(1e-6,u*1e-7)),d=Number.isFinite(Number(e.minSharedNormalDot))?Math.max(-1,Math.min(1,Number(e.minSharedNormalDot))):-1,p=Number.isFinite(Number(e.minSharedEdgeNormalDot))?Math.max(-1,Math.min(1,Number(e.minSharedEdgeNormalDot))):null,m=Number.isFinite(Number(e.minPlanarRatio))?Math.max(0,Math.min(1,Number(e.minPlanarRatio))):0,_=h((M,v)=>{if(!(m>0))return 1;const b=M?.geometry?.getAttribute?.("position"),T=M?.geometry?.getIndex?.()||null;if(!b||b.itemSize!==3||b.count<3||!v||v.lengthSq()<=ht)return 0;const C=new H,I=new H,P=new H;let N=0,D=0;const L=T?T.count/3|0:b.count/3|0;for(let R=0;R<L;R++){const q=T?T.getX(R*3+0)>>>0:R*3+0,$=T?T.getX(R*3+1)>>>0:R*3+1,U=T?T.getX(R*3+2)>>>0:R*3+2;C.set(b.getX(q),b.getY(q),b.getZ(q)).applyMatrix4(M.matrixWorld),I.set(b.getX($),b.getY($),b.getZ($)).applyMatrix4(M.matrixWorld),P.set(b.getX(U),b.getY(U),b.getZ(U)).applyMatrix4(M.matrixWorld);const K=Fs(C,I,P),W=K.length();W>ht&&(N+=Math.abs(K.multiplyScalar(1/W).dot(v))*W,D+=W)}return D>ht?N/D:0},"computeFacePlanarRatio"),y=t.map(M=>{try{const v=typeof M?.getAverageNormal=="function"?M.getAverageNormal():null;if(v&&v.lengthSq?.()>ht)return v.clone().normalize()}catch{}return null}),g=t.map((M,v)=>_(M,y[v])),x=new Map;for(let M=0;M<t.length;M++){const v=t[M],b=v.geometry?.getAttribute?.("position"),T=v.geometry?.getIndex?.()||null;if(!b||b.itemSize!==3||b.count<3)continue;const C=[];for(let R=0;R<b.count;R++)C.push(new H(b.getX(R),b.getY(R),b.getZ(R)).applyMatrix4(v.matrixWorld));const I=new Array(C.length);for(let R=0;R<C.length;R++){const q=fo(C[R],f);I[R]=q}const P=new Map,N=new Map,D=T?T.count/3|0:b.count/3|0;for(let R=0;R<D;R++){const q=T?T.getX(R*3+0)>>>0:R*3+0,$=T?T.getX(R*3+1)>>>0:R*3+1,U=T?T.getX(R*3+2)>>>0:R*3+2,K=Fs(C[q],C[$],C[U]);for(const[W,ne]of[[q,$],[$,U],[U,q]]){const Q=I[W],k=I[ne];if(!Q||!k||Q===k)continue;const B=vl(Q,k);P.set(B,(P.get(B)||0)+1);let z=N.get(B);z||(z=new H,N.set(B,z)),z.add(K)}}const L=oN(v);for(const[R,q]of P.entries()){if(q!==1)continue;const $=`${L}::${R}`;let U=x.get($);U||(U=[],x.set($,U));const K=N.get(R)||null;U.push({faceIndex:M,normal:K&&K.lengthSq()>ht?K.clone().normalize():null})}}const w=new Array(t.length).fill(null).map((M,v)=>v),S=h(M=>{let v=M;for(;w[v]!==v;)v=w[v];for(;w[M]!==M;){const b=w[M];w[M]=v,M=b}return v},"find"),E=h((M,v)=>{const b=typeof M=="number"?M:M?.faceIndex>>>0,T=typeof v=="number"?v:v?.faceIndex>>>0;if(b===T||b>=t.length||T>=t.length)return;if(p!=null){const P=M?.normal||y[b],N=v?.normal||y[T];if(!P||!N||Math.abs(P.dot(N))<p)return}else{if(m>0&&(g[b]<m||g[T]<m))return;if(d>-1){const P=y[b],N=y[T];if(!P||!N||Math.abs(P.dot(N))<d)return}}if(d>-1&&p!=null){const P=y[b],N=y[T];if(!P||!N||Math.abs(P.dot(N))<d)return}const C=S(b),I=S(T);C!==I&&(w[I]=C)},"union");for(const M of x.values())if(!(!Array.isArray(M)||M.length<2))for(let v=1;v<M.length;v++)E(M[0],M[v]);const A=new Map;for(let M=0;M<t.length;M++){const v=S(M);let b=A.get(v);b||(b=[],A.set(v,b)),b.push(t[M])}return Array.from(A.values())}h(cN,"groupConnectedFacesBySharedEdges");function lN(r,e,t){const n=new H().subVectors(t,e),i=n.lengthSq();if(!(i>ht))return r.distanceToSquared(e);const s=Math.max(0,Math.min(1,new H().subVectors(r,e).dot(n)/i)),o=e.clone().add(n.multiplyScalar(s));return r.distanceToSquared(o)}h(lN,"pointToSegmentDistanceSq");function _h(r,e){if(!Array.isArray(e)||e.length<2)return 1/0;let t=1/0;for(let n=0;n+1<e.length;n++){const i=lN(r,e[n],e[n+1]);i<t&&(t=i)}return t}h(_h,"pointToPolylineDistanceSq");function uN(r,e,t,n){const i=new H().subVectors(t,e),s=new H().subVectors(n,e),o=new H().subVectors(r,e),a=i.dot(o),c=s.dot(o);if(a<=0&&c<=0)return r.distanceToSquared(e);const l=new H().subVectors(r,t),u=i.dot(l),f=s.dot(l);if(u>=0&&f<=u)return r.distanceToSquared(t);const d=a*f-u*c;if(d<=0&&a>=0&&u<=0){const E=a/(a-u);return r.distanceToSquared(e.clone().add(i.multiplyScalar(E)))}const p=new H().subVectors(r,n),m=i.dot(p),_=s.dot(p);if(_>=0&&m<=_)return r.distanceToSquared(n);const y=m*c-a*_;if(y<=0&&c>=0&&_<=0){const E=c/(c-_);return r.distanceToSquared(e.clone().add(s.multiplyScalar(E)))}const g=u*_-m*f;if(g<=0&&f-u>=0&&m-_>=0){const E=new H().subVectors(n,t),A=(f-u)/(f-u+(m-_));return r.distanceToSquared(t.clone().add(E.multiplyScalar(A)))}const x=1/(g+y+d),w=y*x,S=d*x;return r.distanceToSquared(e.clone().add(i.multiplyScalar(w)).add(s.multiplyScalar(S)))}h(uN,"pointToTriangleDistanceSq");function fN(r){const e=Array.isArray(r?.edges)?r.edges:[];if(!e.length)return[];const t=r?.parentSolid||(String(r?.parent?.type||"").toUpperCase()==="SOLID"?r.parent:null);try{t?.updateMatrixWorld?.(!0)}catch{}const n=t?.matrixWorld||new tt,i=[];for(let s=0;s<e.length;s++){const o=e[s],c=(Array.isArray(o?.userData?.polylineLocal)?o.userData.polylineLocal:[]).map(l=>Array.isArray(l)?new H(Number(l[0])||0,Number(l[1])||0,Number(l[2])||0).applyMatrix4(n):l&&Number.isFinite(Number(l.x))&&Number.isFinite(Number(l.y))&&Number.isFinite(Number(l.z))?new H(Number(l.x),Number(l.y),Number(l.z)).applyMatrix4(n):null).filter(Boolean);c.length<2||i.push({name:String(o?.name||o?.userData?.edgeName||`EDGE_${s}`).trim()||`EDGE_${s}`,key:String(o?.uuid||o?.name||`EDGE_${s}`),polyline:c})}return i}h(fN,"getSourceEdgePolylines");function dN(r,e,t,n,i){const s=fN(r);if(!s.length||!Array.isArray(e)||!Array.isArray(t))return;const o=Math.max(Number(i)*32,Number(n)*1e-5,1e-5),a=o*o;for(const c of e)for(const l of c?.edges||[]){const u=t[l.start],f=t[l.end];if(!u||!f)continue;const d=u.clone().add(f).multiplyScalar(.5);let p=null,m=1/0;for(const _ of s){const y=Math.max(_h(u,_.polyline),_h(d,_.polyline),_h(f,_.polyline));y<m&&(m=y,p=_)}p&&m<=a&&(l.sourceEdgeName=p.name,l.sourceEdgeKey=p.key)}}h(dN,"assignSourceEdgesToBoundaryLoops");function hN(r,e,t={}){if(t.disableAdjacentBoundaryNormals===!0)return{candidateEdges:0,acceptedEdges:0,contributionCount:0,contributedVertexCount:0,dotThreshold:null,weightScale:0,faceFilterCount:0,faceFilterNames:[]};const n=r?.parentSolid||(String(r?.parent?.type||"").toUpperCase()==="SOLID"?r.parent:null),i=qm(r),s=sN(t,i),o=Array.isArray(n?._triVerts)?n._triVerts:[],a=Array.isArray(n?._triIDs)?n._triIDs:[],c=Array.isArray(n?._vertProperties)?n._vertProperties:[],l=o.length/3|0,u=Math.max(-1,Math.min(1,Number.isFinite(Number(t.adjacentNormalDotThreshold))?Number(t.adjacentNormalDotThreshold):Number.isFinite(Number(t.smoothAdjacentNormalDotThreshold))?Number(t.smoothAdjacentNormalDotThreshold):.85)),f=Math.max(0,Number.isFinite(Number(t.adjacentNormalWeightScale))?Number(t.adjacentNormalWeightScale):1),d=h((W={})=>({candidateEdges:Number(W.candidateEdges||0),acceptedEdges:Number(W.acceptedEdges||0),contributionCount:Number(W.contributionCount||0),contributedVertexCount:Number(W.contributedVertexCount||0),dotThreshold:u,weightScale:f,faceFilterCount:s?.size||0,faceFilterNames:s?Array.from(s):[]}),"makeStats");if(!n||!i)return d();const p=Array.isArray(e?.boundaryDirectedEdges)?e.boundaryDirectedEdges:[],m=Array.isArray(e?.vertices)?e.vertices:[],_=Array.isArray(e?.vertexNormals)?e.vertexNormals:[];if(!p.length||!m.length||!_.length)return d();const y=Math.max(Number(e?.weldTolerance)||0,1e-8);if(f<=0)return d();const g=new Map,x=new Map;for(const W of p){const ne=W?.start>>>0,Q=W?.end>>>0,k=m[ne],B=m[Q];if(!k||!B)continue;const z=fo(k,y),X=fo(B,y);g.set(z,ne),g.set(X,Q),x.set(vl(z,X),!0)}if(!x.size)return d();const w=n?._idToFaceName instanceof Map?n._idToFaceName:new Map,S=new tt;try{n.updateMatrixWorld?.(!0),S.copy(n.matrixWorld||new tt)}catch{S.identity()}const E=new Map,A=new Map,M=new Set,b=t.equalAdjacentBoundaryNormals===!0||String(t.sharedBoundaryNormalMode||"").toLowerCase()==="equal"?new Map:null;let T=0,C=0,I=0;const P=h(W=>[Math.round(W.x*1e6),Math.round(W.y*1e6),Math.round(W.z*1e6)].join(","),"normalKey"),N=h(W=>{if(!b)return null;let ne=b.get(W);if(ne)return ne;const Q=_[W]?.clone?.()||null;return!Q||Q.lengthSq()<=ht?null:(Q.normalize(),ne={sum:Q.clone(),keys:new Set([P(Q)])},b.set(W,ne),ne)},"getEqualBoundaryNormalBucket"),D=h((W={})=>{if(b?.size)for(const[ne,Q]of b.entries())!Q?.sum||Q.sum.lengthSq()<=ht||_[ne].copy(Q.sum);return d(W)},"finalizeStats"),L=h((W,ne,Q)=>{const k=g.get(W);if(k==null)return!1;const B=_[k];if(!B||B.lengthSq()<=ht)return!1;if(b){const V=N(k);if(!V)return!1;const te=P(ne);return V.keys.has(te)?!1:(V.keys.add(te),V.sum.add(ne),M.add(k),I+=1,!0)}const z=Math.max(B.length(),hm),X=Math.min(Q,z)*f;return X>hm?(B.add(ne.clone().multiplyScalar(X)),M.add(k),I+=1,!0):!1},"addContributionForPointKey"),R=h(W=>{if(!Array.isArray(W)||W.length!==3)return;const ne=W.map(V=>fo(V,y));let Q=!1;for(const[V,te]of[[0,1],[1,2],[2,0]])if(x.has(vl(ne[V],ne[te]))){Q=!0,T+=1;break}if(!Q)return;const k=Fs(W[0],W[1],W[2]),B=k.length();if(!(B>ht))return;const z=k.multiplyScalar(1/B);let X=!1;for(let V=0;V<3;V++){const te=g.get(ne[V]);if(te==null)continue;const ce=_[te]?.clone?.()||null;if(!ce||ce.lengthSq()<=ht)continue;ce.normalize();const le=z.dot(ce);let ue=null;le>=u?ue=z:-le>=u&&(ue=z.clone().multiplyScalar(-1)),ue&&L(ne[V],ue,B)&&(X=!0)}X&&(C+=1)},"processAdjacentTriangle");try{const W=typeof n.getFaces=="function"?n.getFaces(!1)||[]:[];if(Array.isArray(W)&&W.length){for(const ne of W){const Q=String(ne?.faceName||"").trim();if(!(!Q||Q===i)&&!(s&&!s.has(Q)))for(const k of ne?.triangles||[]){const B=Array.isArray(k?.p1)?k.p1:null,z=Array.isArray(k?.p2)?k.p2:null,X=Array.isArray(k?.p3)?k.p3:null;!B||!z||!X||R([new H(B[0]||0,B[1]||0,B[2]||0).applyMatrix4(S),new H(z[0]||0,z[1]||0,z[2]||0).applyMatrix4(S),new H(X[0]||0,X[1]||0,X[2]||0).applyMatrix4(S)])}}if(T>0||l===0||a.length<l||c.length<9)return D({candidateEdges:T,acceptedEdges:C,contributionCount:I,contributedVertexCount:M.size})}}catch{}if(l===0||a.length<l||c.length<9)return D({candidateEdges:T,acceptedEdges:C,contributionCount:I,contributedVertexCount:M.size});const q=h(W=>{const ne=W>>>0;let Q=E.get(ne);if(Q)return Q;const k=ne*3;return Q=new H(Number(c[k+0])||0,Number(c[k+1])||0,Number(c[k+2])||0).applyMatrix4(S),E.set(ne,Q),Q},"getParentPoint"),$=h(W=>{const ne=W>>>0;let Q=A.get(ne);return Q||(Q=fo(q(ne),y),A.set(ne,Q),Q)},"getParentPointKey"),U=h((W,ne,Q)=>L($(W),ne,Q),"addContribution"),K=new H;for(let W=0;W<l;W++){const ne=String(w.get(a[W])||"").trim();if(ne===i||s&&!s.has(ne))continue;const Q=o[W*3+0]>>>0,k=o[W*3+1]>>>0,B=o[W*3+2]>>>0,z=[[Q,k],[k,B],[B,Q]];let X=!1;for(const[ae,he]of z){const Ne=$(ae),J=$(he);if(x.has(vl(Ne,J))){X=!0,T+=1;break}}if(!X)continue;const V=q(Q),te=q(k),ce=q(B);K.copy(Fs(V,te,ce));const le=K.length();if(!(le>ht))continue;const ue=K.multiplyScalar(1/le);let re=!1;for(const ae of[Q,k,B]){const he=g.get($(ae));if(he==null)continue;const Ne=_[he]?.clone?.()||null;if(!Ne||Ne.lengthSq()<=ht)continue;Ne.normalize();const J=ue.dot(Ne);let Be=null;J>=u?Be=ue:-J>=u&&(Be=ue.clone().multiplyScalar(-1)),Be&&U(ae,Be,le)&&(re=!0)}re&&(C+=1)}return D({candidateEdges:T,acceptedEdges:C,contributionCount:I,contributedVertexCount:M.size})}h(hN,"addSmoothAdjacentBoundaryNormals");function Mt(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=e.length/3|0;if(!t)return{boundaryEdgeCount:0,nonManifoldEdgeCount:0,triangleCount:0};const n=new Map;for(let o=0;o<t;o++){const a=e[o*3]>>>0,c=e[o*3+1]>>>0,l=e[o*3+2]>>>0;for(const[u,f]of[[a,c],[c,l],[l,a]]){const d=Yt(u,f);n.set(d,(n.get(d)||0)+1)}}let i=0,s=0;for(const o of n.values())o===1?i+=1:o!==2&&(s+=1);return{boundaryEdgeCount:i,nonManifoldEdgeCount:s,triangleCount:t}}h(Mt,"analyzeMeshTopology");function us(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=e.length/3|0;if(!t)return{sameDirectionEdgeCount:0,oppositeDirectionEdgeCount:0,ambiguousEdgeCount:0};const n=new Map,i=h((c,l)=>{const u=Yt(c,l);let f=n.get(u);f||(f=[],n.set(u,f)),f.push([c,l])},"addUse");for(let c=0;c<t;c++){const l=e[c*3]>>>0,u=e[c*3+1]>>>0,f=e[c*3+2]>>>0;i(l,u),i(u,f),i(f,l)}let s=0,o=0,a=0;for(const c of n.values()){if(c.length!==2){a+=1;continue}c[0][0]===c[1][0]&&c[0][1]===c[1][1]?s+=1:o+=1}return{sameDirectionEdgeCount:s,oppositeDirectionEdgeCount:o,ambiguousEdgeCount:a}}h(us,"analyzeTriangleOrientation");function is(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=e.length/3|0;if(!n||t.length<9)return 0;const i=new Map,s=h((f,d,p)=>{const m=Yt(f,d);let _=i.get(m);_||(_=[],i.set(m,_)),_.push({triIndex:p,a:f,b:d})},"addUse");for(let f=0;f<n;f++){const d=e[f*3+0]>>>0,p=e[f*3+1]>>>0,m=e[f*3+2]>>>0;s(d,p,f),s(p,m,f),s(m,d,f)}const o=Array.from({length:n},()=>[]);for(const f of i.values()){if(f.length!==2)continue;const d=f[0],p=f[1],m=d.a===p.a&&d.b===p.b;o[d.triIndex].push({triIndex:p.triIndex,sameDirection:m}),o[p.triIndex].push({triIndex:d.triIndex,sameDirection:m})}const a=new Int8Array(n);a.fill(-1);for(let f=0;f<n;f++){if(a[f]!==-1)continue;a[f]=0;const d=[f];for(;d.length;){const p=d.pop(),m=a[p];for(const _ of o[p]){const y=m^(_.sameDirection?1:0);a[_.triIndex]===-1&&(a[_.triIndex]=y,d.push(_.triIndex))}}}let c=0;for(let f=0;f<n;f++){if(a[f]!==1)continue;const d=f*3,p=e[d+1];e[d+1]=e[d+2],e[d+2]=p,c+=1}const l=h(f=>{const d=f*3,p=e[d+1];e[d+1]=e[d+2],e[d+2]=p},"flipTriangle"),u=h(()=>{const f=new Map,d=h((y,g,x)=>{const w=Yt(y,g);let S=f.get(w);S||(S=[],f.set(w,S)),S.push({triIndex:x,a:y,b:g})},"addLocalUse");for(let y=0;y<n;y++){const g=e[y*3+0]>>>0,x=e[y*3+1]>>>0,w=e[y*3+2]>>>0;d(g,x,y),d(x,w,y),d(w,g,y)}const p=new Uint8Array(n),m=new Uint8Array(n);let _=0;for(const y of f.values()){if(y.length!==2)continue;y[0].a===y[1].a&&y[0].b===y[1].b?(_+=1,p[y[0].triIndex]+=1,p[y[1].triIndex]+=1):(m[y[0].triIndex]+=1,m[y[1].triIndex]+=1)}return{sameCount:_,sameByTri:p,oppositeByTri:m}},"orientationStats");for(let f=0;f<16;f++){const d=u();if(d.sameCount===0)break;let p=0;for(let m=0;m<n;m++)d.sameByTri[m]<=d.oppositeByTri[m]||(l(m),c+=1,p+=1);if(!p)break}for(let f=0;f<64;f++){let d=u();if(d.sameCount===0)break;const p=[];for(let _=0;_<n;_++)d.sameByTri[_]&&p.push({triIndex:_,score:d.sameByTri[_]*2-d.oppositeByTri[_]});p.sort((_,y)=>y.score-_.score||_.triIndex-y.triIndex);let m=!1;for(const _ of p){if(d=u(),d.sameCount===0||!d.sameByTri[_.triIndex])break;const y=d.sameCount;l(_.triIndex),u().sameCount<y?(c+=1,m=!0):l(_.triIndex)}if(!m)break}return c>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)),c}h(is,"orientSolidTrianglesByAdjacency");function rs(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=e.length/3|0;if(!n||t.length<9)return 0;const i=new Map,s=h((u,f,d)=>{const p=Yt(u,f);let m=i.get(p);m||(m=[],i.set(p,m)),m.push(d)},"addUse");for(let u=0;u<n;u++){const f=e[u*3+0]>>>0,d=e[u*3+1]>>>0,p=e[u*3+2]>>>0;s(f,d,u),s(d,p,u),s(p,f,u)}const o=Array.from({length:n},()=>[]);for(const u of i.values())u.length===2&&(o[u[0]].push(u[1]),o[u[1]].push(u[0]));const a=h(u=>{const f=e[u*3+0]>>>0,d=e[u*3+1]>>>0,p=e[u*3+2]>>>0,m=t[f*3+0],_=t[f*3+1],y=t[f*3+2],g=t[d*3+0],x=t[d*3+1],w=t[d*3+2],S=t[p*3+0],E=t[p*3+1],A=t[p*3+2];return(m*(x*A-w*E)-_*(g*A-w*S)+y*(g*E-x*S))/6},"signedVolume"),c=new Uint8Array(n);let l=0;for(let u=0;u<n;u++){if(c[u])continue;const f=[],d=[u];c[u]=1;let p=0;for(;d.length;){const m=d.pop();f.push(m),p+=a(m);for(const _ of o[m])c[_]||(c[_]=1,d.push(_))}if(p<-ht)for(const m of f){const _=m*3,y=e[_+1];e[_+1]=e[_+2],e[_+2]=y,l+=1}}return l>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)),l}h(rs,"orientSolidComponentsBySignedVolume");function Yn(r,e){const t=Math.max(Number(e)||0,0),n=Array.isArray(r?._vertProperties)?r._vertProperties:[],i=Array.isArray(r?._triVerts)?r._triVerts:[],s=Array.isArray(r?._triIDs)?r._triIDs:[],o=n.length/3|0,a=i.length/3|0;if(!(t>0)||!o||!a||s.length<a)return{weldedVertexCount:0,removedTriangleCount:0};const c=1/t,l=h(x=>[Math.round((Number(n[x*3+0])||0)*c),Math.round((Number(n[x*3+1])||0)*c),Math.round((Number(n[x*3+2])||0)*c)].join(","),"keyForIndex"),u=new Int32Array(o);u.fill(-1);const f=new Map,d=[];let p=0;for(let x=0;x<o;x++){const w=l(x);let S=f.get(w);S==null?(S=d.length/3|0,f.set(w,S),d.push(n[x*3+0],n[x*3+1],n[x*3+2])):p+=1,u[x]=S}if(!p)return{weldedVertexCount:0,removedTriangleCount:0};const m=h((x,w,S)=>{const E=d[x*3+0],A=d[x*3+1],M=d[x*3+2],v=d[w*3+0],b=d[w*3+1],T=d[w*3+2],C=d[S*3+0],I=d[S*3+1],P=d[S*3+2],N=v-E,D=b-A,L=T-M,R=C-E,q=I-A,$=P-M;return .5*Math.hypot(D*$-L*q,L*R-N*$,N*q-D*R)},"areaByIndex"),_=[],y=[];let g=0;for(let x=0;x<a;x++){const w=u[i[x*3+0]>>>0],S=u[i[x*3+1]>>>0],E=u[i[x*3+2]>>>0];if(w<0||S<0||E<0||w===S||S===E||E===w||!(m(w,S,E)>ht)){g+=1;continue}_.push(w,S,E),y.push(s[x])}r._vertProperties=d,r._triVerts=_,r._triIDs=y,r._vertKeyToIndex=new Map;for(let x=0;x<d.length;x+=3)r._vertKeyToIndex.set(`${d[x]},${d[x+1]},${d[x+2]}`,x/3|0);return r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r),{weldedVertexCount:p,removedTriangleCount:g}}h(Yn,"weldSolidVerticesByPosition");function pS(r,e={}){if(!r?.geometry)throw new Error("Face.thicken() requires a face with geometry.");try{r.updateMatrixWorld?.(!0)}catch{}const t=r.geometry,n=t.getAttribute?.("position"),i=t.getIndex?.()||null;if(!n||n.itemSize!==3||n.count<3)throw new Error("Face.thicken() requires a triangulated face geometry.");const s=[],o=new H;let a=1/0,c=1/0,l=1/0,u=-1/0,f=-1/0,d=-1/0;for(let k=0;k<n.count;k++)o.set(n.getX(k),n.getY(k),n.getZ(k)).applyMatrix4(r.matrixWorld),s.push(o.clone()),o.x<a&&(a=o.x),o.y<c&&(c=o.y),o.z<l&&(l=o.z),o.x>u&&(u=o.x),o.y>f&&(f=o.y),o.z>d&&(d=o.z);const p=Math.max(1,Math.hypot(u-a,f-c,d-l)),m=Math.max(Number(e.weldTolerance)||0,Math.max(1e-6,p*1e-7)),_=new Map,y=[],g=new Array(s.length);for(let k=0;k<s.length;k++){const B=s[k],z=fo(B,m);let X=_.get(z);X==null?(X=y.length,_.set(z,X),y.push({point:B.clone(),count:1,key:z})):(y[X].point.add(B),y[X].count+=1),g[k]=X}let x=y.map(k=>k.point.multiplyScalar(1/k.count)),w=y.map(k=>k.key);const S=Array.isArray(e.triangleSourceFaceNames)?e.triangleSourceFaceNames:null,E=String(e.sourceFaceName||qm(r)||"").trim();let A=[];const M=i?i.count/3|0:n.count/3|0;for(let k=0;k<M;k++){const B=i?i.getX(k*3+0)>>>0:k*3+0,z=i?i.getX(k*3+1)>>>0:k*3+1,X=i?i.getX(k*3+2)>>>0:k*3+2,V=g[B]>>>0,te=g[z]>>>0,ce=g[X]>>>0;if(V===te||te===ce||ce===V||!(Xm(x[V],x[te],x[ce])>ht))continue;const ue=[V,te,ce],re=String(S?.[k]||E||"").trim();re&&(ue.sourceFaceName=re),A.push(ue)}if(!A.length)throw new Error("Face.thicken() could not resolve any non-degenerate source triangles.");const v=new Map,b=new Array(A.length).fill(null).map(()=>[]),T=h((k,B,z)=>{for(const[X,V]of[[k[0],k[1]],[k[1],k[2]],[k[2],k[0]]]){if(X===B&&V===z)return 1;if(X===z&&V===B)return-1}return 0},"edgeOrientation");for(let k=0;k<A.length;k++){const B=A[k];for(const[z,X]of[[B[0],B[1]],[B[1],B[2]],[B[2],B[0]]]){const V=Yt(z,X);let te=v.get(V);te||(te=[],v.set(V,te)),te.push({triIndex:k,u:z,v:X})}}for(const[k,B]of v.entries()){if(!Array.isArray(B)||B.length<2)continue;const[z,X]=k.split("|"),V=Number(z)>>>0,te=Number(X)>>>0;for(let ce=0;ce<B.length;ce++)for(let le=ce+1;le<B.length;le++)b[B[ce].triIndex].push({neighbor:B[le].triIndex,u:V,v:te}),b[B[le].triIndex].push({neighbor:B[ce].triIndex,u:V,v:te})}const C=new Array(A.length).fill(!1),I=h(k=>aN(k,[k[0],k[2],k[1]]),"flipTriangle");for(let k=0;k<A.length;k++){if(C[k])continue;const B=[k];for(C[k]=!0;B.length;){const z=B.pop(),X=A[z];for(const V of b[z]){const te=V.neighbor;if(te!=null&&!C[te]){const ce=A[te],le=T(X,V.u,V.v),ue=T(ce,V.u,V.v);le!==0&&le===ue&&(A[te]=I(ce)),C[te]=!0,B.push(te)}}}}const P=new Array(A.length),N=new Array(x.length).fill(null).map(()=>new H),D=new H;for(let k=0;k<A.length;k++){const[B,z,X]=A[k],V=Fs(x[B],x[z],x[X]),te=V.length();if(!(te>ht))continue;const ce=V.clone().multiplyScalar(1/te);P[k]=ce,N[B].add(ce.clone().multiplyScalar(te)),N[z].add(ce.clone().multiplyScalar(te)),N[X].add(ce.clone().multiplyScalar(te)),D.add(ce.clone().multiplyScalar(te))}D.lengthSq()<=ht?D.set(0,0,1):D.normalize();const L=[];for(const[k,B]of v.entries()){if(B.length!==1)continue;const z=B[0];L.push({key:k,start:z.u,end:z.v})}const R=new Map;for(const k of L){let B=R.get(k.start);B||(B=[],R.set(k.start,B)),B.push(k)}const q=new Set(L.map(k=>`${k.start}>${k.end}`)),$=[],U=h((k,B)=>{const z=`${w[k.start]}|${w[k.end]}`,X=`${w[B.start]}|${w[B.end]}`;return z.localeCompare(X)},"compareEdges");for(;q.size;){const k=Array.from(q.values()).sort((ae,he)=>ae.localeCompare(he))[0],[B,z]=k.split(">"),X=Number(B)>>>0,V=Number(z)>>>0,te=[],ce=[X];let le=X,ue=X,re=V;for(;q.has(`${ue}>${re}`)&&(q.delete(`${ue}>${re}`),te.push({start:ue,end:re,key:Yt(ue,re)}),ce.push(re),ue=re,ue!==le);){const ae=(R.get(ue)||[]).filter(he=>q.has(`${he.start}>${he.end}`)).sort(U);if(!ae.length)break;re=ae[0].end}te.length&&$.push({vertices:ce,edges:te})}const K=h(k=>{const B=Array.isArray(k?.vertices)?k.vertices.slice(0,-1):[];if(!B.length)return"";let z=null;for(let X=0;X<B.length;X++){const V=[];for(let ce=0;ce<B.length;ce++)V.push(w[B[(X+ce)%B.length]]||`${B[(X+ce)%B.length]}`);const te=V.join(">");(z==null||te<z)&&(z=te)}return z||""},"normalizeLoopSignature"),W=$.map(k=>({...k,signature:K(k)})).sort((k,B)=>k.signature.localeCompare(B.signature));dN(r,W,x,p,m);const ne=new Map;for(let k=0;k<W.length;k++){const B=W[k];for(const z of B.edges)ne.set(z.key,k)}const Q=hN(r,{vertices:x,vertexNormals:N,boundaryDirectedEdges:L,weldTolerance:m},e);for(let k=0;k<N.length;k++)N[k].lengthSq()<=ht&&N[k].copy(D),N[k].lengthSq()<=ht?N[k].set(0,0,1):N[k].normalize();return{vertices:x,triangles:A,triangleNormals:P,vertexNormals:N,averageNormal:D,loops:W,boundaryEdgeToLoop:ne,boundaryDirectedEdges:L,adjacentNormalStats:Q,scale:p,weldTolerance:m}}h(pS,"extractFaceSurface");function pN(r,e={}){const t=Array.isArray(r)?r.filter(d=>d?.geometry):[];if(!t.length)throw new Error("Face.thicken() requires at least one face with geometry.");const n=[],i=[],s=[],o=[],a=new H;let c=null,l=!1;for(const d of t){try{d.updateMatrixWorld?.(!0)}catch{}const p=qm(d)||`FACE_${t.indexOf(d)+1}`,m=d?.parentSolid||(String(d?.parent?.type||"").toUpperCase()==="SOLID"?d.parent:null);if(!c&&m?c=m:c&&m&&m!==c&&(l=!0),Array.isArray(d?.edges))for(const S of d.edges)S&&!o.includes(S)&&o.push(S);const _=d.geometry,y=_.getAttribute?.("position"),g=_.getIndex?.()||null;if(!y||y.itemSize!==3||y.count<3)throw new Error("Face.thicken() requires triangulated face geometries.");const x=n.length/3|0;for(let S=0;S<y.count;S++)a.set(y.getX(S),y.getY(S),y.getZ(S)).applyMatrix4(d.matrixWorld||new tt),n.push(a.x,a.y,a.z);const w=g?g.count/3|0:y.count/3|0;for(let S=0;S<w;S++){const E=g?g.getX(S*3+0)>>>0:S*3+0,A=g?g.getX(S*3+1)>>>0:S*3+1,M=g?g.getX(S*3+2)>>>0:S*3+2;i.push(x+E,x+A,x+M),s.push(p)}}if(i.length<3)throw new Error("Face.thicken() could not resolve any source triangles.");const u=new it;u.setAttribute("position",new bt(new Float32Array(n),3)),u.setIndex(i);const f={geometry:u,matrixWorld:new tt,name:String(e.sourceFaceName||"THICKEN_PATCH"),edges:o,parentSolid:l?null:c,userData:{faceName:String(e.sourceFaceName||"THICKEN_PATCH")},updateMatrixWorld(){}};return pS(f,{...e,triangleSourceFaceNames:s,disableAdjacentBoundaryNormals:e.disableAdjacentBoundaryNormals??!(e.equalAdjacentBoundaryNormals===!0||String(e.sharedBoundaryNormalMode||"").toLowerCase()==="equal")})}h(pN,"extractFacesSurface");function mN(r,e){const t=[],n=new Set,i=h((m,_)=>{const y=String(m?.label||"").trim();if(!y||n.has(y))return;n.add(y);const g=String(m?.sourceFaceName||r.sourceFaceName||"").trim()||r.sourceFaceName;t.push({label:y,kind:_,metadata:{type:_==="start"?"start_cap":"end_cap",sourceFaceName:g,distance:e}})},"addCapGroup"),s=Array.isArray(r.startCaps)&&r.startCaps.length?r.startCaps:[{label:r.start,sourceFaceName:r.sourceFaceName}],o=Array.isArray(r.endCaps)&&r.endCaps.length?r.endCaps:[{label:r.end,sourceFaceName:r.sourceFaceName}];for(const m of s)i(m,"start");for(const m of o)i(m,"end");const a=[],c=new Map;for(const m of r.sidewalls||[]){const _=String(m?.label||"").trim();if(!_)continue;let y=c.get(_);y||(y={label:_,kind:"sidewall",metadata:{type:"sidewall",sourceFaceName:r.sourceFaceName,loopIndex:m.loopIndex,edgeIndex:m.edgeIndex,edgeKey:m.key,sourceEdgeName:m.sourceEdgeName||null,sourceEdgeKey:m.sourceEdgeKey||null,distance:e,segmentCount:0,edgeKeys:[]}},c.set(_,y),a.push(y)),y.metadata.segmentCount+=1,m.key!=null&&y.metadata.edgeKeys.push(m.key)}const l=[...t,...a],u=new Map,f=new Map,d=[];let p=1;try{typeof Ds?.reserveIDs=="function"&&(p=Number(Ds.reserveIDs(l.length))||1)}catch{p=1}for(const m of l){const _=p>>>0;p+=1,u.set(m.label,_),f.set(_,m.label),d.push([m.label,JSON.stringify(m.metadata||{})])}return{labels:r,groups:l,faceNameToID:u,idToFaceName:f,faceMetadataJson:d,edgeKeyToLabel:new Map(r.sidewalls.map(m=>[m.key,m.label]))}}h(mN,"buildThickenClassificationState");function mS(r,e,t){const n=Array.from(r?.triVerts??[],l=>Number(l)>>>0),i=n.length/3|0;if(!i)return null;const s=Array.from(e?.triIDs??r?.faceID??[],l=>Number(l)>>>0),o=Number(e?.faceNameToID?.values?.()?.next?.()?.value)>>>0,a=s.length===i?s:new Array(i).fill(o||1),c=new nr;c._numProp=Number(r?.numProp??3)||3,c._vertProperties=Array.from(r?.vertProperties??[],l=>Number(l)||0),c._triVerts=n,c._triIDs=a,c._faceNameToID=e?.faceNameToID instanceof Map?new Map(e.faceNameToID):new Map,c._idToFaceName=e?.idToFaceName instanceof Map?new Map(e.idToFaceName):new Map,c._faceMetadata=new Map;for(const[l,u]of e?.faceMetadataJson||[])if(l)try{c._faceMetadata.set(String(l),JSON.parse(u||"{}")||{})}catch{c._faceMetadata.set(String(l),{})}c._vertKeyToIndex=new Map;for(let l=0;l<c._vertProperties.length;l+=3)c._vertKeyToIndex.set(`${c._vertProperties[l]},${c._vertProperties[l+1]},${c._vertProperties[l+2]}`,l/3|0);try{c.name=t||c.name}catch{}return c._dirty=!0,c._manifold=null,c._faceIndex=null,c}h(mS,"buildSolidFromTriangleMesh");function gS(r,e,t="raw_face_ids"){return{triIDs:Array.from(e||[],n=>Number(n)>>>0),faceNameToID:r?.faceNameToID instanceof Map?r.faceNameToID:new Map,idToFaceName:r?.idToFaceName instanceof Map?r.idToFaceName:new Map,faceMetadataJson:Array.from(r?.faceMetadataJson||[]),groups:Array.isArray(r?.groups)?r.groups:[],method:t}}h(gS,"buildRawClassification");function gN(r,e,t){const n=r?.labels||{},i=String(e?.sourceFaceName||"").trim(),s=i?n.capLabelsBySourceFaceName?.get?.(i):null,o=t==="start"?s?.start||n.start:s?.end||n.end;return String(o||"").trim()}h(gN,"resolveCapLabelForTriangle");function Ho(r,e,t){const n=gN(r,e,t);return Number(r?.faceNameToID?.get?.(n))>>>0}h(Ho,"resolveCapFaceIDForTriangle");function yN(r,e,t){const n=Array.isArray(r?.vertices)?r.vertices.length:0;if(!n)return null;const i=new Float32Array(n*2*3);for(let u=0;u<n;u++){const f=r.vertices[u],d=f.clone().add(r.vertexNormals[u].clone().multiplyScalar(e));i[u*3+0]=f.x,i[u*3+1]=f.y,i[u*3+2]=f.z;const p=n+u;i[p*3+0]=d.x,i[p*3+1]=d.y,i[p*3+2]=d.z}const s=Number(t?.faceNameToID?.get?.(t?.labels?.start))>>>0,o=Number(t?.faceNameToID?.get?.(t?.labels?.end))>>>0,a=[],c=[],l=h((u,f,d,p)=>{if(u===f||f===d||d===u)return;const m=new H(i[u*3+0],i[u*3+1],i[u*3+2]),_=new H(i[f*3+0],i[f*3+1],i[f*3+2]),y=new H(i[d*3+0],i[d*3+1],i[d*3+2]);Xm(m,_,y)>ht&&(a.push(u>>>0,f>>>0,d>>>0),c.push(Number(p)>>>0))},"addTriangle");for(const u of r.triangles||[]){const[f,d,p]=u,m=Ho(t,u,"start")||s,_=Ho(t,u,"end")||o;e>=0?(l(f,p,d,m),l(n+f,n+d,n+p,_)):(l(f,d,p,m),l(n+f,n+p,n+d,_))}for(let u=0;u<(r.loops?.length||0);u++){const f=r.loops[u];for(const d of f?.edges||[]){const p=d.start>>>0,m=d.end>>>0,_=n+p,y=n+m,g=t?.edgeKeyToLabel?.get?.(d.key),x=Number(t?.faceNameToID?.get?.(g))>>>0;e>=0?(l(p,m,y,x),l(p,y,_,x)):(l(_,y,m,x),l(_,m,p,x))}}return{numProp:3,vertProperties:i,triVerts:Uint32Array.from(a),faceID:Uint32Array.from(c)}}h(yN,"buildStitchedThickenMesh");function _N(r,e,t,n){const i=yN(r,e,t);if(!i)return null;const s=gS(t,i.faceID,"stitched_shell");return mS(i,s,n)}h(_N,"buildStitchedShellSolid");function xN(r,e,t){const n=Array.isArray(r?.vertices)?r.vertices:[],i=Array.isArray(r?.triangles)?r.triangles:[];if(!n.length||!i.length)return null;const s=Number(t?.faceNameToID?.get?.(t?.labels?.start))>>>0,o=Number(t?.faceNameToID?.get?.(t?.labels?.end))>>>0,a=Number(t?.faceNameToID?.values?.()?.next?.()?.value)>>>0,c=[],l=[],u=[],f=h(m=>{const _=u.length/3|0;return u.push(m.x,m.y,m.z),_},"addVertex"),d=h((m,_,y,g)=>{if(!m||!_||!y||!(Xm(m,_,y)>ht))return;const x=f(m),w=f(_),S=f(y);c.push(x,w,S),l.push(Number(g)>>>0)},"addTriangleByPoints"),p=h((m,_)=>{const y=Yt(m,_),g=t?.edgeKeyToLabel?.get?.(y);return Number(t?.faceNameToID?.get?.(g))>>>0||a||s||o||1},"resolveSideFaceID");for(const m of i){const _=m?.[0]>>>0,y=m?.[1]>>>0,g=m?.[2]>>>0,x=n[_],w=n[y],S=n[g];if(!x||!w||!S)continue;const E=Ho(t,m,"start")||s,A=Ho(t,m,"end")||o,M=Fs(x,w,S),v=M.length();if(!(v>ht))continue;M.multiplyScalar(e/v);const b=x.clone().add(M),T=w.clone().add(M),C=S.clone().add(M);e>=0?(d(x,S,w,E),d(b,T,C,A),d(x,w,T,p(_,y)),d(x,T,b,p(_,y)),d(w,S,C,p(y,g)),d(w,C,T,p(y,g)),d(S,x,b,p(g,_)),d(S,b,C,p(g,_))):(d(x,w,S,E),d(b,C,T,A),d(b,T,w,p(_,y)),d(b,w,x,p(_,y)),d(T,C,S,p(y,g)),d(T,S,w,p(y,g)),d(C,b,x,p(g,_)),d(C,x,S,p(g,_)))}return c.length?{numProp:3,vertProperties:Float32Array.from(u),triVerts:Uint32Array.from(c),faceID:Uint32Array.from(l)}:null}h(xN,"buildTrianglePrismUnionThickenMesh");function vN(r,e,t,n){const i=xN(r,e,t);if(!i)return null;const s=gS(t,i.faceID,"triangle_prism_union");return mS(i,s,n)}h(vN,"buildTrianglePrismUnionShellSolid");function bN(r,e={}){const t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=Array.isArray(r?._triVerts)?r._triVerts:[],i=Array.isArray(r?._triIDs)?r._triIDs:[],s=n.length/3|0;if(!s||t.length<9||i.length<s)return 0;let o=1/0,a=1/0,c=1/0,l=-1/0,u=-1/0,f=-1/0;for(let R=0;R<t.length;R+=3){const q=t[R+0],$=t[R+1],U=t[R+2];q<o&&(o=q),q>l&&(l=q),$<a&&(a=$),$>u&&(u=$),U<c&&(c=U),U>f&&(f=U)}const d=Math.hypot(l-o,u-a,f-c)||1,p=Math.max(d*(Number(e.offsetScale)||1e-5),1e-9),m=Math.max(p*.1,d*1e-10,1e-10),_=Math.max(12,Math.min(256,Number.isFinite(Number(e.gridSize))?Number(e.gridSize)|0:Math.ceil(Math.sqrt(s)))),y=new Array(s);for(let R=0;R<s;R++){const q=n[R*3+0]>>>0,$=n[R*3+1]>>>0,U=n[R*3+2]>>>0,K=[t[q*3+0],t[q*3+1],t[q*3+2]],W=[t[$*3+0],t[$*3+1],t[$*3+2]],ne=[t[U*3+0],t[U*3+1],t[U*3+2]],Q=W[0]-K[0],k=W[1]-K[1],B=W[2]-K[2],z=ne[0]-K[0],X=ne[1]-K[1],V=ne[2]-K[2];let te=k*V-B*X,ce=B*z-Q*V,le=Q*X-k*z;const ue=Math.hypot(te,ce,le);ue>ht?(te/=ue,ce/=ue,le/=ue):(te=0,ce=0,le=0),y[R]={a:K,b:W,c:ne,normal:[te,ce,le],centroid:[(K[0]+W[0]+ne[0])/3,(K[1]+W[1]+ne[1])/3,(K[2]+W[2]+ne[2])/3],min:[Math.min(K[0],W[0],ne[0]),Math.min(K[1],W[1],ne[1]),Math.min(K[2],W[2],ne[2])],max:[Math.max(K[0],W[0],ne[0]),Math.max(K[1],W[1],ne[1]),Math.max(K[2],W[2],ne[2])]}}const g=[{primary:0,u:1,v:2,min:[o,a,c],max:[l,u,f]},{primary:1,u:2,v:0,min:[o,a,c],max:[l,u,f]},{primary:2,u:0,v:1,min:[o,a,c],max:[l,u,f]}],x=h(R=>{const q=R.min[R.u],$=R.min[R.v],U=Math.max(R.max[R.u]-q,p),K=Math.max(R.max[R.v]-$,p),W=new Map,ne=h((k,B,z)=>Math.max(0,Math.min(_-1,Math.floor((k-B)/z*_))),"cellCoord"),Q=h((k,B,z)=>{const X=`${k}|${B}`;let V=W.get(X);V||(V=[],W.set(X,V)),V.push(z)},"addCell");for(let k=0;k<s;k++){const B=y[k],z=ne(B.min[R.u]-p,q,U),X=ne(B.max[R.u]+p,q,U),V=ne(B.min[R.v]-p,$,K),te=ne(B.max[R.v]+p,$,K);for(let ce=z;ce<=X;ce++)for(let le=V;le<=te;le++)Q(ce,le,k)}return{axis:R,uMin:q,vMin:$,uSpan:U,vSpan:K,cells:W,cellCoord:ne}},"buildIndex"),S=(String(e.axes||"").toLowerCase()==="majority"?g:[g[0]]).map(x),E=h((R,q)=>{const $=R.cellCoord(q[R.axis.u],R.uMin,R.uSpan),U=R.cellCoord(q[R.axis.v],R.vMin,R.vSpan);return R.cells.get(`${$}|${U}`)||[]},"pointInIndexCell"),A=h((R,q,$)=>{const U=q.primary,K=q.u,W=q.v,ne=$.a[U]-R[U],Q=$.a[K]-R[K],k=$.a[W]-R[W],B=$.b[U]-R[U],z=$.b[K]-R[K],X=$.b[W]-R[W],V=$.c[U]-R[U],te=$.c[K]-R[K],ce=$.c[W]-R[W],le=B-ne,ue=z-Q,re=X-k,ae=V-ne,he=te-Q,Ne=ce-k,J=re*he-ue*Ne;if(Math.abs(J)<=m)return null;const Be=1/J,ge=-ne,Ae=-Q,Ee=-k,G=0,F=-Ne,oe=he,O=(ge*G+Ae*F+Ee*oe)*Be;if(O<-1e-10||O>1+1e-10)return null;const j=Ae*re-Ee*ue,ee=Ee*le-ge*re,pe=ge*ue-Ae*le,fe=j*Be;if(fe<-1e-10||O+fe>1+1e-10)return null;const de=(ae*j+he*ee+Ne*pe)*Be;return de>m?de:null},"rayTriangleHit"),M=h((R,q)=>{const $=[];for(const W of E(q,R)){const ne=y[W];if(R[q.axis.primary]>ne.max[q.axis.primary]+p||R[q.axis.u]<ne.min[q.axis.u]-p||R[q.axis.u]>ne.max[q.axis.u]+p||R[q.axis.v]<ne.min[q.axis.v]-p||R[q.axis.v]>ne.max[q.axis.v]+p)continue;const Q=A(R,q.axis,ne);Q!=null&&$.push(Q)}if(!$.length)return!1;$.sort((W,ne)=>W-ne);let U=0,K=-1/0;for(const W of $)Math.abs(W-K)<=Math.max(m*4,1e-8)||(U+=1,K=W);return U%2===1},"inside"),v=new Uint8Array(s);v.fill(1);let b=0;for(let R=0;R<s;R++){const q=y[R],$=q.normal;if(Math.hypot($[0],$[1],$[2])<=ht)continue;const U=[q.centroid[0]+$[0]*p,q.centroid[1]+$[1]*p,q.centroid[2]+$[2]*p],K=[q.centroid[0]-$[0]*p,q.centroid[1]-$[1]*p,q.centroid[2]-$[2]*p];let W=0;for(const ne of S)M(U,ne)!==M(K,ne)&&(W+=1);W>=Math.ceil(S.length/2)||(v[R]=0,b+=1)}if(!b)return 0;const T=t.length/3|0,C=new Uint8Array(T),I=[],P=[];for(let R=0;R<s;R++){if(!v[R])continue;const q=n[R*3+0]>>>0,$=n[R*3+1]>>>0,U=n[R*3+2]>>>0;I.push(q,$,U),P.push(i[R]),C[q]=1,C[$]=1,C[U]=1}const N=new Int32Array(T);N.fill(-1);const D=[];let L=0;for(let R=0;R<T;R++)C[R]&&(N[R]=L++,D.push(t[R*3+0],t[R*3+1],t[R*3+2]));for(let R=0;R<I.length;R++)I[R]=N[I[R]>>>0];r._vertProperties=D,r._triVerts=I,r._triIDs=P,r._vertKeyToIndex=new Map;for(let R=0;R<D.length;R+=3)r._vertKeyToIndex.set(`${D[R]},${D[R+1]},${D[R+2]}`,R/3|0);r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r);try{r.fixTriangleWindingsByAdjacency?.()}catch{}return b}h(bN,"cullInternalTrianglesByIndexedRaycast");function xr(r,e){const t=Array.isArray(r?._triVerts)?r._triVerts:[],n=Array.isArray(r?._vertProperties)?r._vertProperties:[],i=t.length/3|0;if(!i||n.length<9)return 0;const s=new Map,o=h((M,v)=>{const b=Yt(M,v);let T=s.get(b);T||(T={count:0,directed:[]},s.set(b,T)),T.count+=1,T.directed.push([M,v])},"addUse");for(let M=0;M<i;M++){const v=t[M*3+0]>>>0,b=t[M*3+1]>>>0,T=t[M*3+2]>>>0;o(v,b),o(b,T),o(T,v)}const a=new Map,c=new Map,l=new Map,u=[],f=h((M,v)=>{let b=c.get(M);b||(b=[],c.set(M,b)),b.push(v)},"addUndirectedNeighbor");for(const M of s.values()){if(M.count!==1||!M.directed.length)continue;const[v,b]=M.directed[0],T={a:v,b,key:`${v}>${b}`};u.push(T),l.set(Yt(v,b),[v,b]),f(v,b),f(b,v);let C=a.get(v);C||(C=[],a.set(v,C)),C.push(T)}if(!u.length)return 0;for(const M of a.values())M.sort((v,b)=>v.b-b.b);const d=new Set,p=[];for(const M of u){if(d.has(M.key))continue;const v=[M.a];let b=M,T=0;for(;b&&!d.has(b.key)&&T++<u.length+1&&(d.add(b.key),v.push(b.b),b.b!==v[0]);)b=(a.get(b.b)||[]).find(I=>!d.has(I.key))||null;v.length>=4&&v[0]===v[v.length-1]&&p.push(v.slice(0,-1))}const m=h(M=>{if(!Array.isArray(M)||!M.length)return"";const v=[],b=h(T=>{for(let C=0;C<T.length;C++){const I=[];for(let P=0;P<T.length;P++)I.push(T[(C+P)%T.length]);v.push(I.join("|"))}},"addVariants");return b(M),M.length>1&&b(M.slice().reverse()),v.sort()[0]||""},"loopSignature"),_=h((M,v)=>{const b=Array.from(v.keys());if(b.length<3||M.length<3)return[];const T=h(ge=>[Number(n[ge*3+0])||0,Number(n[ge*3+1])||0,Number(n[ge*3+2])||0],"pointFor"),C=h((ge,Ae)=>[ge[0]-Ae[0],ge[1]-Ae[1],ge[2]-Ae[2]],"sub"),I=h((ge,Ae)=>ge[0]*Ae[0]+ge[1]*Ae[1]+ge[2]*Ae[2],"dot"),P=h((ge,Ae)=>[ge[1]*Ae[2]-ge[2]*Ae[1],ge[2]*Ae[0]-ge[0]*Ae[2],ge[0]*Ae[1]-ge[1]*Ae[0]],"cross"),N=h(ge=>Math.hypot(ge[0],ge[1],ge[2]),"length"),D=h((ge,Ae)=>[ge[0]*Ae,ge[1]*Ae,ge[2]*Ae],"scaleVec"),L=[0,0,0],R=new Map;for(const ge of b){const Ae=T(ge);R.set(ge,Ae),L[0]+=Ae[0],L[1]+=Ae[1],L[2]+=Ae[2]}L[0]/=b.length,L[1]/=b.length,L[2]/=b.length;let q=null,$=-1/0;for(const ge of R.values()){const Ae=C(ge,L),Ee=N(Ae);Ee>$&&($=Ee,q=Ae)}if(!q||!($>ht))return[];q=D(q,1/$);let U=null,K=-1/0;for(const ge of R.values()){const Ae=P(q,C(ge,L)),Ee=N(Ae);Ee>K&&(K=Ee,U=Ae)}if(!U||!(K>ht))return[];U=D(U,1/K);const W=P(U,q),ne=N(W);if(!(ne>ht))return[];const Q=D(W,1/ne),k=new Map;for(const[ge,Ae]of R.entries()){const Ee=C(Ae,L);k.set(ge,[I(Ee,q),I(Ee,Q)])}const B=new Map;for(const[ge,Ae]of v.entries()){const Ee=k.get(ge);B.set(ge,Ae.slice().sort((G,F)=>{const oe=k.get(G),O=k.get(F);return Math.atan2(oe[1]-Ee[1],oe[0]-Ee[0])-Math.atan2(O[1]-Ee[1],O[0]-Ee[0])}))}const z=h(ge=>{let Ae=0;for(let Ee=0;Ee<ge.length;Ee++){const G=k.get(ge[Ee]),F=k.get(ge[(Ee+1)%ge.length]);Ae+=G[0]*F[1]-F[0]*G[1]}return Ae*.5},"area2D"),X=new Set,V=h((ge,Ae)=>`${ge}>${Ae}`,"directedKey"),te=[];for(const[ge,Ae]of M)for(const Ee of[[ge,Ae],[Ae,ge]]){let G=Ee[0],F=Ee[1];const oe=V(G,F);if(X.has(oe))continue;const O=[];let j=!1,ee=0;const pe=Math.max(12,M.length*4);for(;!X.has(V(G,F))&&ee++<pe;){X.add(V(G,F)),O.push(G);const de=B.get(F)||[],Re=de.indexOf(G);if(Re<0||de.length===0)break;const se=de[(Re-1+de.length)%de.length];if(G=F,F=se,V(G,F)===oe){j=!0;break}}if(!j||O.length<3)continue;const fe=z(O);Math.abs(fe)<=ht||te.push({loop:O,area:fe})}const ce=te.filter(ge=>ge.area>ht),ue=(ce.length?ce:te.filter(ge=>ge.area<-ht)).map(ge=>ge.area>0?ge.loop:ge.loop.slice().reverse());if(ue.length||M.length>64)return ue;const re=new Set,ae=[],he=b.slice().sort((ge,Ae)=>ge-Ae),Ne=h(ge=>{if(!ge.length)return"";const Ae=[],Ee=h(G=>{for(let F=0;F<G.length;F++){const oe=[];for(let O=0;O<G.length;O++)oe.push(G[(F+O)%G.length]);Ae.push(oe.join("|"))}},"add");return Ee(ge),Ee(ge.slice().reverse()),Ae.sort()[0]||""},"canonicalCycleKey");for(const ge of he){const Ae=[{current:ge,path:[ge],visited:new Set([ge])}];let Ee=0;for(;Ae.length&&Ee++<5e3&&ae.length<M.length*2;){const G=Ae.pop();if(G.path.length>M.length)continue;const F=(v.get(G.current)||[]).slice().sort((oe,O)=>oe-O);for(const oe of F){if(oe===ge&&G.path.length>=3){const j=Ne(G.path);j&&!re.has(j)&&(re.add(j),ae.push(G.path.slice()));continue}if(oe<ge||G.visited.has(oe))continue;const O=new Set(G.visited);O.add(oe),Ae.push({current:oe,path:G.path.concat(oe),visited:O})}}}ae.sort((ge,Ae)=>ge.length-Ae.length);const J=new Set,Be=[];for(const ge of ae){const Ae=[];let Ee=!1;for(let G=0;G<ge.length;G++){const F=Yt(ge[G],ge[(G+1)%ge.length]);Ae.push(F),J.has(F)&&(Ee=!0)}if(!Ee){for(const G of Ae)J.add(G);Be.push(ge)}}return Be.slice(0,M.length)},"traceBoundaryGraphLoops"),y=new Set(p.map(m)),g=new Set,x=[];for(const M of u){const v=Yt(M.a,M.b);if(g.has(v))continue;const b=[],T=[[M.a,M.b]];for(g.add(v);T.length;){const[ne,Q]=T.pop();b.push([ne,Q]);for(const k of[ne,Q])for(const B of c.get(k)||[]){const z=Yt(k,B);g.has(z)||(g.add(z),T.push([k,B]))}}if(b.length<3)continue;const C=new Map,I=h((ne,Q)=>{let k=C.get(ne);k||(k=[],C.set(ne,k)),k.includes(Q)||k.push(Q)},"addComponentNeighbor");for(const[ne,Q]of b)I(ne,Q),I(Q,ne);if(!Array.from(C.values()).every(ne=>ne.length===2)){let ne=!1;for(const Q of _(b,C)){const k=m(Q);!k||y.has(k)||(y.add(k),p.push(Q),ne=!0)}ne||x.push(b);continue}const P=Math.min(...Array.from(C.keys())),N=(C.get(P)||[]).slice().sort((ne,Q)=>ne-Q);if(N.length!==2){x.push(b);continue}const D=[P];let L=-1,R=P,q=N[0],$=!1,U=0;for(;U++<b.length+2;){if(D.push(q),L=R,R=q,R===P){$=!0;break}const ne=(C.get(R)||[]).filter(Q=>Q!==L);if(ne.length!==1)break;q=ne[0]}if(!$||D.length<4){x.push(b);continue}const K=D.slice(0,-1);if(K.length!==b.length){x.push(b);continue}const W=m(K);!W||y.has(W)||(y.add(W),p.push(K))}if(x.length=0,!p.length&&!x.length)return 0;const w=h(M=>{if(!Array.isArray(M)||M.length<3)return[];const v=M.map(Q=>[Number(n[Q*3+0])||0,Number(n[Q*3+1])||0,Number(n[Q*3+2])||0]),b=[0,0,0];for(const Q of v)b[0]+=Q[0],b[1]+=Q[1],b[2]+=Q[2];b[0]/=v.length,b[1]/=v.length,b[2]/=v.length;let T=[0,0,0];for(let Q=0;Q<v.length;Q++){const k=v[Q],B=v[(Q+1)%v.length];T[0]+=(k[1]-B[1])*(k[2]+B[2]),T[1]+=(k[2]-B[2])*(k[0]+B[0]),T[2]+=(k[0]-B[0])*(k[1]+B[1])}let C=Math.hypot(T[0],T[1],T[2]);if(!(C>ht)){let Q=0;for(let k=0;k<v.length;k++){const B=v[k],z=v[(k+1)%v.length],X=v[(k+2)%v.length],V=[z[0]-B[0],z[1]-B[1],z[2]-B[2]],te=[X[0]-B[0],X[1]-B[1],X[2]-B[2]],ce=[V[1]*te[2]-V[2]*te[1],V[2]*te[0]-V[0]*te[2],V[0]*te[1]-V[1]*te[0]],le=Math.hypot(ce[0],ce[1],ce[2]);le>Q&&(Q=le,T=ce)}C=Q}if(!(C>ht))return[];T=T.map(Q=>Q/C);let I=null,P=0;for(const Q of v){const k=[Q[0]-b[0],Q[1]-b[1],Q[2]-b[2]],B=Math.hypot(k[0],k[1],k[2]);B>P&&(P=B,I=k)}if(!I||!(P>ht))return[];I=I.map(Q=>Q/P);const N=[T[1]*I[2]-T[2]*I[1],T[2]*I[0]-T[0]*I[2],T[0]*I[1]-T[1]*I[0]],D=Math.hypot(N[0],N[1],N[2]);if(!(D>ht))return[];N[0]/=D,N[1]/=D,N[2]/=D;const L=v.map(Q=>{const k=[Q[0]-b[0],Q[1]-b[1],Q[2]-b[2]];return[k[0]*I[0]+k[1]*I[1]+k[2]*I[2],k[0]*N[0]+k[1]*N[1]+k[2]*N[2]]}),R=h(Q=>{let k=0;for(let B=0;B<Q.length;B++){const z=L[Q[B]],X=L[Q[(B+1)%Q.length]];k+=z[0]*X[1]-X[0]*z[1]}return k*.5},"area2D"),q=h((Q,k,B)=>{const z=L[Q],X=L[k],V=L[B];return(X[0]-z[0])*(V[1]-X[1])-(X[1]-z[1])*(V[0]-X[0])},"cross2D"),$=h((Q,k,B,z)=>{const X=L[Q],V=L[k],te=L[B],ce=L[z],le=Math.abs((te[0]-V[0])*(ce[1]-V[1])-(te[1]-V[1])*(ce[0]-V[0]));if(!(le>ht))return!1;const ue=Math.abs((V[0]-X[0])*(te[1]-X[1])-(V[1]-X[1])*(te[0]-X[0])),re=Math.abs((te[0]-X[0])*(ce[1]-X[1])-(te[1]-X[1])*(ce[0]-X[0])),ae=Math.abs((ce[0]-X[0])*(V[1]-X[1])-(ce[1]-X[1])*(V[0]-X[0]));return Math.abs(ue+re+ae-le)<=Math.max(ht,le*1e-8)},"pointInTri"),U=Array.from({length:M.length},(Q,k)=>k);R(U)<0&&U.reverse();const K=[];let W=0;for(;U.length>3&&W++<M.length*M.length*4;){let Q=!1;for(let k=0;k<U.length;k++){const B=U[(k-1+U.length)%U.length],z=U[k],X=U[(k+1)%U.length];if(q(B,z,X)<=ht)continue;let V=!1;for(const te of U)if(!(te===B||te===z||te===X)&&$(te,B,z,X)){V=!0;break}if(!V){K.push([M[B],M[z],M[X]]),U.splice(k,1),Q=!0;break}}if(!Q)break}if(U.length===3&&K.push([M[U[0]],M[U[1]],M[U[2]]]),K.length)return K;const ne=[];for(let Q=1;Q+1<M.length;Q++)ne.push([M[0],M[Q],M[Q+1]]);return ne},"triangulateLoop"),S=h(M=>{const v=r._vertProperties.length/3|0;return r._vertProperties.push(M[0],M[1],M[2]),r._vertKeyToIndex?.set?.(`${M[0]},${M[1]},${M[2]}`,v),v},"addVertex");let E=0;const A=Number(e)>>>0;for(const M of p){if(M.length<3)continue;let v=0;for(let T=0;T<M.length;T++){const C=M[T],I=M[(T+1)%M.length],P=l.get(Yt(C,I));P&&P[0]===C&&P[1]===I&&(v+=1)}const b=v>=M.length/2;for(const T of w(M)){const C=T[0]>>>0,I=T[1]>>>0,P=T[2]>>>0;C===I||I===P||P===C||(b?r._triVerts.push(P,I,C):r._triVerts.push(C,I,P),r._triIDs.push(A),E+=1)}}for(const M of x){const v=Array.from(new Set(M.flatMap(([C,I])=>[C,I])));if(v.length<3)continue;const b=[0,0,0];for(const C of v)b[0]+=n[C*3+0],b[1]+=n[C*3+1],b[2]+=n[C*3+2];b[0]/=v.length,b[1]/=v.length,b[2]/=v.length;const T=S(b);for(const[C,I]of M){const P=l.get(Yt(C,I))||[C,I],N=P[0]>>>0,D=P[1]>>>0;N===D||N===T||D===T||(r._triVerts.push(D,N,T),r._triIDs.push(A),E+=1)}}return E>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)),E}h(xr,"fillBoundaryLoopsWithTriangles");function yS(r,e,t){const n=`${e}_INTERSECTION_CAP`;let i=r?._faceNameToID instanceof Map?r._faceNameToID.get(n):null;return!i&&typeof r?._getOrCreateID=="function"&&(i=r._getOrCreateID(n)),i&&r?._faceMetadata instanceof Map&&r._faceMetadata.set(n,{type:"intersection_cap",sourceFaceName:e,distance:t}),i||null}h(yS,"getOrCreateIntersectionCapFaceID");function SN(r,e,t,n,i){const s=Array.isArray(r?._triVerts)?r._triVerts:[],o=Array.isArray(r?._vertProperties)?r._vertProperties:[],a=Array.isArray(r?._triIDs)?r._triIDs:[],c=Array.isArray(e?.vertices)?e.vertices:[],l=Array.isArray(e?.vertexNormals)?e.vertexNormals:[],u=Array.isArray(e?.triangles)?e.triangles:[],f=s.length/3|0;if(!f||a.length<f||!c.length||!u.length)return 0;const d=Number(n?.faceNameToID?.get?.(n?.labels?.start))>>>0,p=Number(n?.faceNameToID?.get?.(n?.labels?.end))>>>0;if(!d||!p)return 0;const m=c.map((b,T)=>{const C=l[T];return b&&C?b.clone().add(C.clone().multiplyScalar(t)):null}),_=new Map,y=new Map,g=h((b,T,C)=>{const I=Number(T)>>>0;if(!I||!Array.isArray(C))return;let P=b.get(I);P||(P=[],b.set(I,P)),P.push(C)},"addRef");for(const b of u){const T=b?.[0]>>>0,C=b?.[1]>>>0,I=b?.[2]>>>0;if(!c[T]||!c[C]||!c[I])continue;const P=Ho(n,b,"start")||d,N=Ho(n,b,"end")||p;g(_,P,[c[T],c[C],c[I]]),m[T]&&m[C]&&m[I]&&g(y,N,[m[T],m[C],m[I]])}if(!_.size||!y.size)return 0;const x=Math.max(Number(i)||0,1e-7),w=x*x,S=new H,E=h((b,T)=>{let C=1/0;for(const[I,P,N]of T){const D=uN(b,I,P,N);if(D<C&&(C=D,C<=w))break}return C},"pointDistanceToSurfaceSq"),A=h((b,T)=>{let C=0;for(let I=0;I<3;I++){const N=(s[b*3+I]>>>0)*3;S.set(Number(o[N+0])||0,Number(o[N+1])||0,Number(o[N+2])||0);const D=E(S,T);if(D>C&&(C=D),C>w)break}return C},"triangleMaxDistanceSq"),M=h((b,T)=>{let C=0,I=1/0;for(const[P,N]of T.entries()){const D=A(b,N);if(D<I&&(I=D,C=Number(P)>>>0,I<=w))break}return{faceID:C,distanceSq:I}},"bestFaceIDForTriangle");let v=0;for(let b=0;b<f;b++){const T=M(b,_),C=T.distanceSq<=w?{faceID:0,distanceSq:1/0}:M(b,y),I=T.distanceSq<=w?T.faceID:C.distanceSq<=w?C.faceID:0;I&&a[b]!==I&&(a[b]=I,v+=1)}return v>0&&(r._dirty=!0,r._faceIndex=null,r._manifold=null),v}h(SN,"reclassifyThickenCapTrianglesByGeometry");function MN(r,e,t){const n=yS(r,e,t);return n?xr(r,n):0}h(MN,"fillIntersectionCapBoundaryLoops");function ha(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=Array.isArray(r?._triIDs)?r._triIDs:[],i=e.length/3|0;if(!i||n.length<i)return 0;const s=new Map,o=h((y,g,x)=>{const w=Yt(y,g);let S=s.get(w);S||(S=[],s.set(w,S)),S.push(x)},"addUse");for(let y=0;y<i;y++){const g=e[y*3+0]>>>0,x=e[y*3+1]>>>0,w=e[y*3+2]>>>0;o(g,x,y),o(x,w,y),o(w,g,y)}const a=new Uint8Array(i);for(const y of s.values())if(!(y.length<=2))for(const g of y)a[g]=1;let c=0;for(let y=0;y<i;y++)a[y]&&(c+=1);if(!c)return 0;const l=t.length/3|0,u=new Uint8Array(l),f=[],d=[];for(let y=0;y<i;y++){if(a[y])continue;const g=e[y*3+0]>>>0,x=e[y*3+1]>>>0,w=e[y*3+2]>>>0;f.push(g,x,w),d.push(n[y]),u[g]=1,u[x]=1,u[w]=1}const p=new Int32Array(l);p.fill(-1);const m=[];let _=0;for(let y=0;y<l;y++)u[y]&&(p[y]=_++,m.push(t[y*3+0],t[y*3+1],t[y*3+2]));for(let y=0;y<f.length;y++)f[y]=p[f[y]>>>0];r._vertProperties=m,r._triVerts=f,r._triIDs=d,r._vertKeyToIndex=new Map;for(let y=0;y<m.length;y+=3)r._vertKeyToIndex.set(`${m[y]},${m[y+1]},${m[y+2]}`,y/3|0);return r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r),c}h(ha,"cullTrianglesTouchingNonManifoldEdges");function bl(r){const e=Array.isArray(r?._triVerts)?r._triVerts:[],t=Array.isArray(r?._vertProperties)?r._vertProperties:[],n=Array.isArray(r?._triIDs)?r._triIDs:[],i=e.length/3|0;if(!i||n.length<i)return 0;const s=new Map,o=h((g,x,w)=>{const S=Yt(g,x);let E=s.get(S);E||(E=[],s.set(S,E)),E.push({triIndex:w,a:g,b:x})},"addUse");for(let g=0;g<i;g++){const x=e[g*3+0]>>>0,w=e[g*3+1]>>>0,S=e[g*3+2]>>>0;o(x,w,g),o(w,S,g),o(S,x,g)}const a=new Uint16Array(i);for(const g of s.values())g.length===2&&g[0].a===g[1].a&&g[0].b===g[1].b&&(a[g[0].triIndex]+=1,a[g[1].triIndex]+=1);let c=-1,l=0;for(let g=0;g<i;g++){const x=a[g]||0;if(!x)continue;const S=(r._idToFaceName instanceof Map?String(r._idToFaceName.get(n[g])||""):"").includes("INTERSECTION_CAP")?100:0,E=x+S;E>l&&(l=E,c=g)}if(c<0)return 0;const u=t.length/3|0,f=new Uint8Array(u),d=[],p=[];for(let g=0;g<i;g++){if(g===c)continue;const x=e[g*3+0]>>>0,w=e[g*3+1]>>>0,S=e[g*3+2]>>>0;d.push(x,w,S),p.push(n[g]),f[x]=1,f[w]=1,f[S]=1}const m=new Int32Array(u);m.fill(-1);const _=[];let y=0;for(let g=0;g<u;g++)f[g]&&(m[g]=y++,_.push(t[g*3+0],t[g*3+1],t[g*3+2]));for(let g=0;g<d.length;g++)d[g]=m[d[g]>>>0];r._vertProperties=_,r._triVerts=d,r._triIDs=p,r._vertKeyToIndex=new Map;for(let g=0;g<_.length;g+=3)r._vertKeyToIndex.set(`${_[g]},${_[g+1]},${_[g+2]}`,g/3|0);return r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r),1}h(bl,"cullTrianglesTouchingSameDirectionEdges");function wN(r,e={}){const t=String(e.sourceFaceName||"").trim()||"FACE",n=Number(e.distance)||0,i=Math.max(Number(e.manifoldWeldEpsilon)||0,0),s=Math.max(0,Number.isFinite(Number(e.nonManifoldCullMaxTriangles))?Number(e.nonManifoldCullMaxTriangles):1e4),o=Math.max(1,Math.min(512,Number.isFinite(Number(e.maxPasses))?Number(e.maxPasses)|0:256)),a={orientedTriangleCount:0,orientationCulledTriangleCount:0,orientationCapTriangleCount:0,nonManifoldCulledTriangleCount:0,boundaryCapTriangleCount:0,weldedVertexCount:0,degenerateTriangleCount:0},c=h(()=>{try{return typeof r?._isCoherentlyOrientedManifold=="function"?r._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}},"isCoherent"),l=h(()=>{const f=Yn(r,i);a.weldedVertexCount+=f.weldedVertexCount||0,a.degenerateTriangleCount+=f.removedTriangleCount||0},"weld");for(let f=0;f<o;f++){let d=Mt(r),p=!1;if(d.nonManifoldEdgeCount>0&&(d.triangleCount||0)<=s){const y=ha(r);y>0&&(a.nonManifoldCulledTriangleCount+=y,p=!0,l(),d=Mt(r))}if(d.boundaryEdgeCount>0){const y=MN(r,t,n);if(y>0){a.boundaryCapTriangleCount+=y,a.orientationCapTriangleCount+=y,p=!0;try{r.fixTriangleWindingsByAdjacency?.()}catch{}l(),d=Mt(r)}}if(d.boundaryEdgeCount||d.nonManifoldEdgeCount){if(!p)return{ok:!1,topology:d,orientation:us(r),stats:a};continue}const m=is(r)+rs(r);if(m>0){a.orientedTriangleCount+=m;try{r.fixTriangleWindingsByAdjacency?.()}catch{}}if(c())return{ok:!0,topology:Mt(r),orientation:us(r),stats:a};const _=bl(r);if(!(_>0))return{ok:!1,topology:d,orientation:us(r),stats:a};if(a.orientationCulledTriangleCount+=_,p=!0,l(),!p)break}const u=Mt(r);return{ok:u.boundaryEdgeCount===0&&u.nonManifoldEdgeCount===0&&c(),topology:u,orientation:us(r),stats:a}}h(wN,"repairSolidOrientationByCullAndCap");function Ov(r,e={}){if(!r||typeof r.clone!="function")return null;let t=null;try{t=r.clone();try{t.name=r.name}catch{}const n=wN(t,e),i=n?.topology||Mt(t),s=(()=>{try{return typeof t._isCoherentlyOrientedManifold=="function"?t._isCoherentlyOrientedManifold()===!0:!0}catch{return!1}})();if(n?.ok===!0&&i.boundaryEdgeCount===0&&i.nonManifoldEdgeCount===0&&s)return{solid:t,topology:i,stats:n.stats||{}}}catch{}try{t?.free?.()}catch{}return null}h(Ov,"tryRepairCoherentOrientationCandidate");function AN(r){let e=0;const t=h(n=>{const i=Array.isArray(r?._triVerts)?r._triVerts:[],s=Array.isArray(r?._vertProperties)?r._vertProperties:[],o=Array.isArray(r?._triIDs)?r._triIDs:[],a=i.length/3|0,c=s.length/3|0,l=new Uint8Array(c),u=[],f=[];for(let _=0;_<a;_++){if(n[_])continue;const y=i[_*3+0]>>>0,g=i[_*3+1]>>>0,x=i[_*3+2]>>>0;u.push(y,g,x),f.push(o[_]),l[y]=1,l[g]=1,l[x]=1}const d=new Int32Array(c);d.fill(-1);const p=[];let m=0;for(let _=0;_<c;_++)l[_]&&(d[_]=m++,p.push(s[_*3+0],s[_*3+1],s[_*3+2]));for(let _=0;_<u.length;_++)u[_]=d[u[_]>>>0];r._vertProperties=p,r._triVerts=u,r._triIDs=f,r._vertKeyToIndex=new Map;for(let _=0;_<p.length;_+=3)r._vertKeyToIndex.set(`${p[_]},${p[_+1]},${p[_+2]}`,_/3|0);r._dirty=!0,r._faceIndex=null,r._manifold=null,si(r)},"rebuildWithout");for(let n=0;n<256;n++){const i=Array.isArray(r?._triVerts)?r._triVerts:[],s=Array.isArray(r?._triIDs)?r._triIDs:[],o=i.length/3|0;if(!o||s.length<o)break;const a=new Map,c=[];for(let d=0;d<o;d++){const p=i[d*3+0]>>>0,m=i[d*3+1]>>>0,_=i[d*3+2]>>>0,y=[Yt(p,m),Yt(m,_),Yt(_,p)];c.push(y);for(const g of y)a.set(g,(a.get(g)||0)+1)}let l=0;for(const d of a.values())d>2&&(l+=1);if(!l)break;let u=null;for(let d=0;d<o;d++){const p=c[d];if(p.some(x=>(a.get(x)||0)<=1))continue;let m=0;for(const x of p)m+=Math.max(0,(a.get(x)||0)-2);if(!(m>0))continue;const y=(r._idToFaceName instanceof Map?String(r._idToFaceName.get(s[d])||""):"").includes("INTERSECTION_CAP")?1e3:0,g={triIndex:d,score:m+y};(!u||g.score>u.score)&&(u=g)}if(!u)break;const f=new Uint8Array(o);f[u.triIndex]=1,t(f),e+=1}return e}h(AN,"pruneOverusedTriangles");function EN(r,e={}){if(!r)return null;const t=Math.max(1,Math.min(8,Number.isFinite(Number(e.triangleCullPasses))?Number(e.triangleCullPasses)|0:1)),n={snapTolerance:e.splitSnapTolerance??e.snapTolerance,diagnostics:e.splitDiagnostics===!0||e.diagnostics===!0};(!Number.isFinite(Number(n.snapTolerance))||Number(n.snapTolerance)<=0)&&delete n.snapTolerance;let i=0,s=0,o=0,a=0,c=0;const l=Math.max(Number(e.weldTolerance??e.manifoldWeldTolerance)||0,0);for(let f=0;f<t;f++){c=f+1;const d=Number(e.precomputedTriangleSplitProbeCount),p=e.skipTriangleSplit===!0?f===0?Number.isFinite(d)&&d>=0?d:Number(r.splitSelfIntersectingTriangles?.({...n,probeOnly:!0,maxIntersections:1})||0):0:Number(r.splitSelfIntersectingTriangles?.(n)||0);p>0&&e.skipTriangleSplit!==!0&&si(r),i+=p;const m=Number(r.removeDegenerateTriangles?.()||0);m>0&&si(r),o+=m;const _=Yn(r,l);a+=_.weldedVertexCount||0,o+=_.removedTriangleCount||0;const y=(r?._triVerts?.length||0)/3|0,g=Math.max(0,Number.isFinite(Number(e.windingCullMaxTriangles))?Number(e.windingCullMaxTriangles):1e4),x=y>0&&y<=g?"winding":"raycast",w=String(e.internalCullMethod||x).toLowerCase(),S=e.skipInternalCull===!0?0:Number(w==="winding"?r.removeInternalTrianglesByWinding?.(e.windingOptions||{})||0:bN(r,e.raycastCullOptions||{})||0);S>0&&si(r),s+=S;const E=Number(r.removeDegenerateTriangles?.()||0);E>0&&si(r),o+=E;const A=Yn(r,l);if(a+=A.weldedVertexCount||0,o+=A.removedTriangleCount||0,p===0&&S===0)break}try{r.fixTriangleWindingsByAdjacency?.()}catch{}const u=Mt(r);return{splitCount:i,culledTriangleCount:s,degenerateTriangleCount:o,weldedVertexCount:a,passCount:c,topology:u}}h(EN,"triangleSplitCullSolid");function TN(r,e,t,n){let i=null;try{i=typeof e?.getMetadata=="function"&&e.getMetadata()||null}catch{i=null}if(!(!i||typeof r?.setFaceMetadata!="function"))try{r.setFaceMetadata(t.start,{...i,type:"start_cap",sourceFaceName:n,sourceFeatureId:e?.owningFeatureID??e?.parentSolid?.owningFeatureID??i?.sourceFeatureId??null}),r.setFaceMetadata(t.end,{...i,type:"end_cap",sourceFaceName:n,sourceFeatureId:e?.owningFeatureID??e?.parentSolid?.owningFeatureID??i?.sourceFeatureId??null})}catch{}}h(TN,"applySourceFaceMetadataToThickenResult");function CN(r,e){const t=Number(e);if(!(t<0))return!1;const n=Array.isArray(r?.vertices)?r.vertices:[],i=Array.isArray(r?.vertexNormals)?r.vertexNormals:[];if(n.length<3||i.length<n.length)return!1;const s=new H,o=new H;let a=0;for(let u=0;u<n.length;u++){const f=n[u],d=i[u];!f||!d||!(d.lengthSq?.()>ht)||(o.add(f),s.add(d),a+=1)}if(a<3||(o.multiplyScalar(1/a),s.length()/a>.35))return!1;let l=1/0;for(let u=0;u<n.length;u++){const f=n[u],d=i[u];if(!f||!d||!(d.lengthSq?.()>ht))continue;const p=f.clone().sub(o).dot(d);p>ht&&p<l&&(l=p)}return Number.isFinite(l)?Math.abs(t)>=l*.95:!1}h(CN,"shouldSkipArrangementSplitForSelfOverlappingSurface");function IN(r,e,t,n={},i=null){if(!(Number(t)>0))return{skip:!1,reason:"",splitProbeCount:0};if(!r||typeof r.splitSelfIntersectingTriangles!="function")return{skip:!1,reason:"",splitProbeCount:0};const o=Array.isArray(e?.loops)?e.loops:[];if(!o.length)return{skip:!1,reason:"",splitProbeCount:0};const a=i||Mt(r);if(a.boundaryEdgeCount||a.nonManifoldEdgeCount)return{skip:!1,reason:"",splitProbeCount:0};try{if(typeof r._isCoherentlyOrientedManifold=="function"&&r._isCoherentlyOrientedManifold()!==!0)return{skip:!1,reason:"",splitProbeCount:0}}catch{return{skip:!1,reason:"",splitProbeCount:0}}const c=Math.max(Array.isArray(e?.boundaryDirectedEdges)?e.boundaryDirectedEdges.length:0,o.reduce((m,_)=>m+(Array.isArray(_?.edges)?_.edges.length:0),0)),l=Math.max(16,Math.min(512,c*2||64)),u={probeOnly:!0,maxIntersections:l+1},f=n.splitSnapTolerance??n.snapTolerance;Number.isFinite(Number(f))&&Number(f)>0&&(u.snapTolerance=Number(f));let d=null,p=0;try{d=typeof r.clone=="function"?r.clone():null,p=Number(d?d.splitSelfIntersectingTriangles(u)||0:r.splitSelfIntersectingTriangles({...u,maxIntersections:1})||0)}finally{try{d?.free?.()}catch{}}return p>l?{skip:!1,reason:"",splitProbeCount:p}:{skip:!0,reason:p>0?"preserve_exact_closed_shell":"closed_shell_without_intersections",splitProbeCount:p}}h(IN,"shouldPreserveExactClosedOffsetShell");function os(r,e,t,n={}){const i=Number(t);if(!Number.isFinite(i)||Math.abs(i)<=hm)throw new Error("Face.thicken() requires a non-zero finite distance.");if(!r||!Array.isArray(r.triangles)||!r.triangles.length)throw new Error("Face.thicken() requires a non-empty source triangle surface.");const s=pm(n.featureId||n.name||e?.name||"THICKEN","THICKEN"),o=String(n.sourceFaceName||e?.userData?.faceName||e?.name||s).trim()||s,a=Array.isArray(n.sourceFaceNames)?n.sourceFaceNames.map(A=>String(A||"").trim()).filter(Boolean):[o],c=a.length?a:[o],l=new Map;for(const A of c){const M=String(A||"").trim();!M||l.has(M)||l.set(M,{start:`${M}_START`,end:`${M}_END`})}const u=l.get(o)||l.values().next().value||{start:`${o}_START`,end:`${o}_END`},f=Array.isArray(r.loops)?r.loops:[],d={sourceFaceName:o,start:u.start,end:u.end,startCaps:Array.from(l.entries(),([A,M])=>({label:M.start,sourceFaceName:A})),endCaps:Array.from(l.entries(),([A,M])=>({label:M.end,sourceFaceName:A})),capLabelsBySourceFaceName:l,sidewalls:f.flatMap((A,M)=>(Array.isArray(A?.edges)?A.edges:[]).map((v,b)=>{const T=String(v?.sourceEdgeName||"").trim(),C=T?pm(T,`EDGE_${M}_${b}`).replace(/_+$/g,""):null;return{key:v.key,loopIndex:M,edgeIndex:b,sourceEdgeName:T||null,sourceEdgeKey:v?.sourceEdgeKey||null,label:C?`${C}_SW`:M===0?`${o}_E${b}_SW`:`${o}_L${M}_E${b}_SW`}}))},p=mN(d,i),m=String(n.name||s).trim()||s,_=Math.max(Number(n.manifoldWeldTolerance)||0,Math.max(r.weldTolerance||0,r.scale*1e-7,1e-6)),y=Math.max(0,Number.isFinite(Number(n.orientationRepairDistanceLimit))?Number(n.orientationRepairDistanceLimit):2),g=Math.abs(i)<=y,x=n.trianglePrismUnion===!0,w=n.repairBoundaryCaps!==!1,S=Array.isArray(r.triangles)?r.triangles.length:0;let E=null;try{const A=h(()=>{if(n.__skipInternalCullRetry===!0||n.skipInternalCull===!0||!g)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,skipInternalCull:!0,__skipInternalCullRetry:!0})}catch{return null}},"retryWithoutInternalCull"),M=h(()=>{if(n.__relaxedWeldRetry===!0||!g)return null;const le=Math.min(1e-4,Math.max(r.scale*1e-5,1e-8)),ue=Math.max(_*16,r.scale*1e-6,le);if(Number(n.manifoldWeldTolerance)>=ue*.95)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,skipInternalCull:!0,manifoldWeldTolerance:ue,__relaxedWeldRetry:!0})}catch{return null}},"retryWithRelaxedWeld"),v=h(()=>{if(n.__raycastMajorityRetry===!0)return null;try{E?.free?.()}catch{}return E=null,os(r,e,i,{...n,internalCullMethod:"raycast",raycastCullOptions:{...n.raycastCullOptions||{},axes:"majority"},__raycastMajorityRetry:!0})},"retryWithRaycastMajority"),b=h(()=>{if(n.__skipTriangleSplitRetry===!0||n.skipTriangleSplit===!0)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,skipTriangleSplit:!0,__skipTriangleSplitRetry:!0})}catch{return null}},"retryWithoutTriangleSplit"),T=h((le="destructive_repair")=>{if(n.__trianglePrismUnionRetry===!0||x)return null;try{E?.free?.()}catch{}E=null;try{return os(r,e,i,{...n,trianglePrismUnion:!0,repairBoundaryCaps:!1,nonManifoldCullMaxTriangles:0,__trianglePrismUnionRetry:!0,__trianglePrismUnionReason:le})}catch{return null}},"retryWithTrianglePrismUnion"),C=h(()=>yS(E,o,i),"getBoundaryRepairFaceID");if(E=x?vN(r,i,p,m):_N(r,i,p,m),!E)throw new Error("Face.thicken() failed to build the stitched triangle shell.");let I=Mt(E);const P=n.skipTriangleSplit!==!0&&n.skipTriangleSplit!==!1&&!x?IN(E,r,i,n,I):{skip:!1,reason:"",splitProbeCount:0},N=n.skipTriangleSplit!==!1&&CN(r,i),D=n.skipTriangleSplit===!0||P.skip===!0||N,L=n.skipTriangleSplit===!0?"option":P.reason||(N?"self_overlap_surface":""),R=EN(E,{...n,skipTriangleSplit:D,precomputedTriangleSplitProbeCount:P.skip===!0?P.splitProbeCount:void 0,weldTolerance:_});I=R?.topology||Mt(E);let q=0,$=0;const U=Math.max(0,Number.isFinite(Number(n.nonManifoldCullMaxTriangles))?Number(n.nonManifoldCullMaxTriangles):1e4);for(let le=0;le<8&&(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U);le++){const ue=ha(E);if(!(ue>0))break;$+=ue;const re=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E)}if(I.nonManifoldEdgeCount===0&&I.boundaryEdgeCount>0)try{E.removeDegenerateTriangles?.(),I=Mt(E)}catch{}if(w&&I.boundaryEdgeCount>0){const le=C();if(le&&(q=xr(E,le),q>0)){try{E.fixTriangleWindingsByAdjacency?.()}catch{}const ue=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(ue.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(ue.removedTriangleCount||0),I=Mt(E)}}for(let le=0;le<16;le++){let ue=!1;if(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const re=ha(E);if(re>0){$+=re;const ae=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(ae.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(ae.removedTriangleCount||0),I=Mt(E),ue=!0}}if(w&&I.boundaryEdgeCount>0){const re=C();if(re){const ae=xr(E,re);if(ae>0){q+=ae;try{E.fixTriangleWindingsByAdjacency?.()}catch{}const he=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(he.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(he.removedTriangleCount||0),I=Mt(E),ue=!0}}}if(!ue)break}let K=I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0?is(E):0;I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0&&(K+=rs(E));let W=0,ne=0,Q=!1;if(K>0)try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0&&g&&typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0)for(let le=0;le<8;le++){const ue=bl(E);if(!(ue>0))break;if(W+=ue,I=Mt(E),w&&I.boundaryEdgeCount>0){const ae=C();if(ae){const he=xr(E,ae);he>0&&(ne+=he,q+=he)}}const re=Yn(E,_);if(R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E),I.boundaryEdgeCount||I.nonManifoldEdgeCount)break;K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(E._isCoherentlyOrientedManifold()===!0)break}for(let le=0;le<8;le++){let ue=!1;if(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const re=ha(E);re>0&&($+=re,ue=!0)}if(I=Mt(E),w&&I.boundaryEdgeCount>0){const re=C();if(re){const ae=xr(E,re);ae>0&&(q+=ae,ue=!0)}}if(ue){const re=Yn(E,_);if(R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E),I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0){K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}}}if(!ue)break}if(I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const le=AN(E);if(le>0){if($+=le,I=Mt(E),w&&I.boundaryEdgeCount>0){const ue=C();if(ue){const re=xr(E,ue);re>0&&(q+=re,I=Mt(E))}}if(I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0){K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}}}}if(n.__raycastMajorityRetry!==!0&&g)for(let le=0;le<128;le++){if(I=Mt(E),I.nonManifoldEdgeCount>0&&(I.triangleCount||0)<=U){const ae=ha(E);if(ae>0){$+=ae;const he=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(he.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(he.removedTriangleCount||0),I=Mt(E)}}if(w&&I.boundaryEdgeCount>0){const ae=C();if(ae){const he=xr(E,ae);if(he>0){q+=he;const Ne=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(Ne.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(Ne.removedTriangleCount||0),I=Mt(E)}}}if(I.boundaryEdgeCount||I.nonManifoldEdgeCount)break;K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(typeof E._isCoherentlyOrientedManifold!="function"||E._isCoherentlyOrientedManifold()===!0)break;const ue=bl(E);if(!(ue>0))break;W+=ue;const re=Yn(E,_);R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0)}if(I=Mt(E),I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0&&g&&typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0){const le=Ov(E,{sourceFaceName:o,distance:i,manifoldWeldEpsilon:_,nonManifoldCullMaxTriangles:U,maxPasses:n.orientationRepairMaxPasses});if(le?.solid){const ue=E;E=le.solid;try{ue?.free?.()}catch{}I=le.topology||Mt(E);const re=le.stats||{};K+=re.orientedTriangleCount||0,W+=re.orientationCulledTriangleCount||0,ne+=re.orientationCapTriangleCount||0,q+=re.boundaryCapTriangleCount||0,$+=re.nonManifoldCulledTriangleCount||0,R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.degenerateTriangleCount||0),Q=!0}}const k=!x&&q>Math.max(1e4,S*100),B=!x&&$>Math.max(1e4,S*100);if(k||B){const le=T(k?"excessive_boundary_caps":"excessive_nonmanifold_cull");if(le)return le;throw new Error(`Face.thicken() triangle split/cull required excessive topology repair (boundaryCaps=${q}, nonManifoldCull=${$}, sourceTriangles=${S}).`)}if(I.boundaryEdgeCount||I.nonManifoldEdgeCount){const le=T("invalid_stitched_topology");if(le)return le;const ue=b();if(ue)return ue;const re=A();if(re)return re;const ae=M();if(ae)return ae;const he=v();if(he)return he;throw new Error(`Face.thicken() triangle split/cull produced invalid topology: boundaries=${I.boundaryEdgeCount}, nonManifold=${I.nonManifoldEdgeCount}, triangles=${I.triangleCount||0}.`)}let z=typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0,X=z?us(E):null;if(z&&I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0){const le=Ov(E,{sourceFaceName:o,distance:i,manifoldWeldEpsilon:_,nonManifoldCullMaxTriangles:U,maxPasses:n.orientationRepairMaxPasses});if(le?.solid){const ue=E;E=le.solid;try{ue?.free?.()}catch{}I=le.topology||Mt(E);const re=le.stats||{};K+=re.orientedTriangleCount||0,W+=re.orientationCulledTriangleCount||0,ne+=re.orientationCapTriangleCount||0,q+=re.boundaryCapTriangleCount||0,$+=re.nonManifoldCulledTriangleCount||0,R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.degenerateTriangleCount||0),Q=!0,z=typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0,X=z?us(E):null}}if(z&&I.boundaryEdgeCount===0&&I.nonManifoldEdgeCount===0)for(let le=0;le<32;le++){const ue=bl(E);if(!(ue>0))break;if(W+=ue,I=Mt(E),w&&I.boundaryEdgeCount>0){const ae=C();if(ae){const he=xr(E,ae);he>0&&(ne+=he,q+=he)}}const re=Yn(E,_);if(R.weldedVertexCount=(R.weldedVertexCount||0)+(re.weldedVertexCount||0),R.degenerateTriangleCount=(R.degenerateTriangleCount||0)+(re.removedTriangleCount||0),I=Mt(E),I.boundaryEdgeCount||I.nonManifoldEdgeCount)break;K+=is(E),K+=rs(E);try{E.fixTriangleWindingsByAdjacency?.()}catch{}if(z=typeof E._isCoherentlyOrientedManifold=="function"&&E._isCoherentlyOrientedManifold()!==!0,X=z?us(E):null,!z)break}if(z&&n.__raycastMajorityRetry!==!0&&g){const le=A();if(le)return le;const ue=M();if(ue)return ue;const re=v();if(re)return re;throw new Error(`Face.thicken() triangle split/cull produced a non-coherently-oriented manifold result: sameDirection=${X.sameDirectionEdgeCount}, ambiguous=${X.ambiguousEdgeCount}.`)}const V=Math.max(_*64,Math.abs(i)*1e-5,r.scale*1e-5,1e-6),te=SN(E,r,i,p,V);TN(E,e,d,o),E.__thickenMethod="triangle_split_cull",E.__thickenClassificationMethod="raw_face_ids",E.__thickenDiagnostics={boundaryLoopCount:f.length,sourceTriangleCount:Array.isArray(r.triangles)?r.triangles.length:0,sourceFaceCount:a.length,sourceFaceNames:a,resultTriangleCount:(E._triVerts?.length||0)/3|0,sourceFaceName:o,distance:i,classificationMethod:"raw_face_ids",buildMethod:E.__thickenMethod,constructionMethod:x?"triangle_prism_union":"stitched_shell",trianglePrismUnionRetry:n.__trianglePrismUnionRetry===!0,trianglePrismUnionReason:n.__trianglePrismUnionReason||"",repairBoundaryCapsEnabled:w,weldEpsilon:_,triangleSplitCount:R?.splitCount||0,triangleSplitSkipped:D,triangleSplitSkipReason:L,triangleSplitProbeCount:P.splitProbeCount||0,culledTriangleCount:R?.culledTriangleCount||0,internalTriangleCullSkipped:n.skipInternalCull===!0,internalTriangleCullRetry:n.__skipInternalCullRetry===!0,relaxedWeldRetry:n.__relaxedWeldRetry===!0,degenerateTriangleCount:R?.degenerateTriangleCount||0,weldedVertexCount:R?.weldedVertexCount||0,orientedTriangleCount:K,orientationCulledTriangleCount:W,orientationCapTriangleCount:ne,orientationCandidateRepairAccepted:Q,orientationRepairDistanceLimit:y,orientationWarning:z,orientationSameDirectionEdgeCount:X?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:X?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:te,nonManifoldCulledTriangleCount:$,boundaryCapTriangleCount:q,splitCullPasses:R?.passCount||0,adjacentBoundaryNormalContributionCount:r.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:r.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalCandidateEdgeCount:r.adjacentNormalStats?.candidateEdges||0,adjacentBoundaryNormalAcceptedEdgeCount:r.adjacentNormalStats?.acceptedEdges||0,adjacentBoundaryNormalDotThreshold:r.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalWeightScale:r.adjacentNormalStats?.weightScale??null,adjacentBoundaryNormalFaceFilterCount:r.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:r.adjacentNormalStats?.faceFilterNames||[]},E.userData={...E.userData||{},thicken:{sourceFaceName:o,sourceFaceNames:a,sourceFaceCount:a.length,distance:i,boundaryLoopCount:f.length,sourceTriangleCount:Array.isArray(r.triangles)?r.triangles.length:0,resultTriangleCount:(E._triVerts?.length||0)/3|0,classificationMethod:"raw_face_ids",buildMethod:E.__thickenMethod,weldEpsilon:_,triangleSplitCount:R?.splitCount||0,triangleSplitSkipped:D,triangleSplitSkipReason:L,triangleSplitProbeCount:P.splitProbeCount||0,culledTriangleCount:R?.culledTriangleCount||0,internalTriangleCullSkipped:n.skipInternalCull===!0,internalTriangleCullRetry:n.__skipInternalCullRetry===!0,relaxedWeldRetry:n.__relaxedWeldRetry===!0,degenerateTriangleCount:R?.degenerateTriangleCount||0,weldedVertexCount:R?.weldedVertexCount||0,orientedTriangleCount:K,orientationCulledTriangleCount:W,orientationCapTriangleCount:ne,orientationCandidateRepairAccepted:Q,orientationRepairDistanceLimit:y,orientationWarning:z,orientationSameDirectionEdgeCount:X?.sameDirectionEdgeCount||0,orientationAmbiguousEdgeCount:X?.ambiguousEdgeCount||0,capReclassifiedTriangleCount:te,nonManifoldCulledTriangleCount:$,boundaryCapTriangleCount:q,splitCullPasses:R?.passCount||0,adjacentBoundaryNormalContributionCount:r.adjacentNormalStats?.contributionCount||0,adjacentBoundaryNormalVertexCount:r.adjacentNormalStats?.contributedVertexCount||0,adjacentBoundaryNormalDotThreshold:r.adjacentNormalStats?.dotThreshold??null,adjacentBoundaryNormalFaceFilterCount:r.adjacentNormalStats?.faceFilterCount||0,adjacentBoundaryNormalFaceFilterNames:r.adjacentNormalStats?.faceFilterNames||[]}};const ce=E;return E=null,ce}finally{try{E?.free?.()}catch{}}}h(os,"thickenSurfaceToSolid");function NN(r,e,t={}){const n=pS(r,t),i=String(t.sourceFaceName||r?.userData?.faceName||r?.name||"").trim();return os(n,r,e,{...t,sourceFaceNames:Array.isArray(t.sourceFaceNames)?t.sourceFaceNames:i?[i]:void 0,sourceFaceName:i})}h(NN,"thickenFaceToSolid");function RN(r,e,t={}){const n=Array.isArray(r)?r.filter(c=>c?.geometry):[];if(!n.length)throw new Error("Face.thicken() requires at least one face with geometry.");const i=n.map((c,l)=>String(c?.userData?.faceName||c?.name||`FACE_${l+1}`).trim()||`FACE_${l+1}`),s=pm(t.featureId||t.name||i[0]||"THICKEN","THICKEN"),o=String(t.sourceFaceName||`${s}_PATCH`).trim()||`${s}_PATCH`,a=pN(n,t);return os(a,n[0],e,{...t,sourceFaceName:o,sourceFaceNames:i})}h(RN,"thickenFacesToSolid");const H_=class H_ extends At{constructor(e){super(e,fn.FACE.BASE),this.edges=[],this.name=null,this.type="FACE",this.renderOrder=1,this.parentSolid=null,un.attach(this)}getAverageNormal(){const e=this.geometry;if(!e)return new H(0,1,0);const t=e.getAttribute("position");if(!t||t.itemSize!==3||t.count<3)return new H(0,1,0);const n=e.getIndex(),i=new H,s=new H,o=new H,a=new H,c=new H,l=new H,u=h((f,d)=>(f.set(t.getX(d),t.getY(d),t.getZ(d)).applyMatrix4(this.matrixWorld),f),"toWorld");if(n){const f=n.count/3|0;for(let d=0;d<f;d++){const p=n.getX(3*d+0)>>>0,m=n.getX(3*d+1)>>>0,_=n.getX(3*d+2)>>>0;u(i,p),u(s,m),u(o,_),a.subVectors(s,i),c.subVectors(o,i),l.add(c.cross(a))}}else{const f=t.count/3|0;for(let d=0;d<f;d++){const p=3*d+0,m=3*d+1,_=3*d+2;u(i,p),u(s,m),u(o,_),a.subVectors(s,i),c.subVectors(o,i),l.add(c.cross(a))}}return l.lengthSq()===0?new H(0,1,0):l.normalize()}surfaceArea(){const e=this.geometry;if(!e)return 0;const t=e.getAttribute&&e.getAttribute("position");if(!t||t.itemSize!==3)return 0;const n=e.getIndex&&e.getIndex(),i=new H,s=new H,o=new H;let a=0;const c=h((l,u)=>l.set(t.getX(u),t.getY(u),t.getZ(u)).applyMatrix4(this.matrixWorld),"toWorld");if(n){const l=n.count/3|0;for(let u=0;u<l;u++){const f=n.getX(3*u+0)>>>0,d=n.getX(3*u+1)>>>0,p=n.getX(3*u+2)>>>0;c(i,f),c(s,d),c(o,p),a+=dm(i.x,i.y,i.z,s.x,s.y,s.z,o.x,o.y,o.z)}}else{const l=t.count/3|0;for(let u=0;u<l;u++){const f=3*u+0,d=3*u+1,p=3*u+2;c(i,f),c(s,d),c(o,p),a+=dm(i.x,i.y,i.z,s.x,s.y,s.z,o.x,o.y,o.z)}}return a}async points(e=!0){const t=new H,n=[],i=this.geometry&&this.geometry.getAttribute&&this.geometry.getAttribute("position");if(i&&i.itemSize===3&&i.count>=2)for(let s=0;s<i.count;s++)t.set(i.getX(s),i.getY(s),i.getZ(s)),e&&t.applyMatrix4(this.matrixWorld),n.push({x:t.x,y:t.y,z:t.z});return n}setMetadata(e){return this.parentSolid&&typeof this.parentSolid.setFaceMetadata=="function"&&this.parentSolid.setFaceMetadata(this.name,e),this}getMetadata(){return this.parentSolid&&typeof this.parentSolid.getFaceMetadata=="function"?this.parentSolid.getFaceMetadata(this.name):null}renameFace(e){this.parentSolid.renameFace(this.name,e)}thicken(e,t={}){return NN(this,e,t)}getNeighbors(){const e=this,t=e?.name||e?.userData?.faceName||null;if(!t)return[];const n=e.parentSolid||e.userData?.parentSolid||null,i=new Set,s=h(o=>{o&&o!==e&&i.add(o)},"addFace");if(Array.isArray(e.edges)){for(const o of e.edges)if(!(!o||!Array.isArray(o.faces)))for(const a of o.faces)s(a)}if(i.size===0&&n&&typeof n.getBoundaryEdgePolylines=="function"){const o=new Map;if(Array.isArray(n.children)){for(const a of n.children)if(a&&a.type==="FACE"){const c=a.name||a.userData?.faceName||null;c&&o.set(c,a)}}try{const a=n.getBoundaryEdgePolylines()||[];for(const c of a){const l=c?.faceA,u=c?.faceB;l===t&&u?s(o.get(u)):u===t&&l&&s(o.get(l))}}catch{}}return Array.from(i)}};h(H_,"Face");let Sf=H_;const Uv=!1,Mf=h(r=>{if(!r)return{};try{const e=JSON.parse(r);return e&&typeof e=="object"?e:{}}catch{return{}}},"parseMetadataJson"),yi=h((r=[])=>Array.from(r||[],e=>[e?.[0],e?.[1]]),"cloneSnapshotEntries"),ml=h((r,e=t=>t)=>r instanceof Map?Array.from(r.entries(),([t,n])=>[t,e(n)]):[],"toPlainEntryArray"),Bv=h(r=>JSON.stringify(r&&typeof r=="object"?r:{}),"serializeMetadata"),PN=h((r=[],e=3)=>{const t=new Map,n=Math.max(3,Number(e)||3);for(let i=0;i+2<r.length;i+=n){const s=r[i+0],o=r[i+1],a=r[i+2];t.set(`${s},${o},${a}`,i/n|0)}return t},"rebuildVertexKeyMap"),Sd=h(r=>({numProp:Number(r?._numProp??3),vertPropertiesRef:r?._vertProperties||null,vertPropertiesLength:Array.isArray(r?._vertProperties)?r._vertProperties.length:0,triVertsRef:r?._triVerts||null,triVertsLength:Array.isArray(r?._triVerts)?r._triVerts.length:0,triIDsRef:r?._triIDs||null,triIDsLength:Array.isArray(r?._triIDs)?r._triIDs.length:0,faceNameToIDRef:r?._faceNameToID||null,faceNameToIDSize:r?._faceNameToID instanceof Map?r._faceNameToID.size:0,idToFaceNameRef:r?._idToFaceName||null,idToFaceNameSize:r?._idToFaceName instanceof Map?r._idToFaceName.size:0,faceMetadataRef:r?._faceMetadata||null,faceMetadataSize:r?._faceMetadata instanceof Map?r._faceMetadata.size:0,edgeMetadataRef:r?._edgeMetadata||null,edgeMetadataSize:r?._edgeMetadata instanceof Map?r._edgeMetadata.size:0,auxEdgesRef:r?._auxEdges||null,auxEdgesLength:Array.isArray(r?._auxEdges)?r._auxEdges.length:0,faceMetadataVersion:Number(r?._faceMetadataVersion||0),edgeMetadataVersion:Number(r?._edgeMetadataVersion||0),dirty:!!r?._dirty}),"captureSolidCppSyncStamp"),DN=h((r,e)=>!!r&&!!e&&r.numProp===e.numProp&&r.vertPropertiesRef===e.vertPropertiesRef&&r.vertPropertiesLength===e.vertPropertiesLength&&r.triVertsRef===e.triVertsRef&&r.triVertsLength===e.triVertsLength&&r.triIDsRef===e.triIDsRef&&r.triIDsLength===e.triIDsLength&&r.faceNameToIDRef===e.faceNameToIDRef&&r.faceNameToIDSize===e.faceNameToIDSize&&r.idToFaceNameRef===e.idToFaceNameRef&&r.idToFaceNameSize===e.idToFaceNameSize&&r.faceMetadataRef===e.faceMetadataRef&&r.faceMetadataSize===e.faceMetadataSize&&r.edgeMetadataRef===e.edgeMetadataRef&&r.edgeMetadataSize===e.edgeMetadataSize&&r.auxEdgesRef===e.auxEdgesRef&&r.auxEdgesLength===e.auxEdgesLength&&r.faceMetadataVersion===e.faceMetadataVersion&&r.edgeMetadataVersion===e.edgeMetadataVersion&&r.dirty===e.dirty,"solidCppSyncStampEquals"),Xt=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.setAuthoringState=="function"&&typeof r.bakeTransform=="function"&&typeof r.getAuthoringState=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),FN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.weldVerticesByEpsilon=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),LN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.pushFace=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),Ym=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.prepareManifoldMesh=="function"&&typeof r.isCoherentlyOrientedManifold=="function"&&typeof r.fixTriangleWindingsByAdjacency=="function"&&typeof r.invertNormals=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),ON=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.normalizeFaceTracking=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),Md=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.getFace=="function"&&typeof r.getFaces=="function"&&typeof r.getFaceNormal=="function"&&typeof r.getBoundaryEdgePolylines=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),UN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.computeFilletCenterline=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),BN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.addAuxEdge=="function"&&typeof r.getAuxEdges=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),zN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.transformMetadata=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),kN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.cleanupTinyFaceIslands=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),VN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.removeSmallIslands=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),HN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.mergeTinyFaces=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),WN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.removeInternalTriangles=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),GN=(()=>{try{if(typeof nt?.BrepSolidCore!="function")return!1;const r=new nt.BrepSolidCore;try{return typeof r.removeDisconnectedIslandsByVolume=="function"}finally{typeof r.delete=="function"&&r.delete()}}catch{return!1}})(),Rt=h((r,e)=>{if(!r)throw new Error(`${e} requires the custom local manifold build with BrepSolidCore support.`)},"requireCppSolidCoreCapability"),Yo=h(r=>({numProp:Number(r?._numProp??3),vertProperties:Array.from(r?._vertProperties??[]),triVerts:Array.from(r?._triVerts??[]),triIDs:Array.from(r?._triIDs??[]),faceNameToID:ml(r?._faceNameToID),idToFaceName:ml(r?._idToFaceName),faceMetadataJson:ml(r?._faceMetadata,Bv),edgeMetadataJson:ml(r?._edgeMetadata,Bv),auxEdges:bo(r?._auxEdges)}),"buildSolidAuthoringStateSnapshot"),gl=h(r=>new Map(yi(r)),"cloneSnapshotMapEntries"),$N=h((r="INSET")=>String(r||"INSET").toUpperCase()==="OUTSET"?"OUTSET":"INSET","normalizeFilletSideMode"),_S=h(r=>{if(Array.isArray(r)&&r.length>=3){const e=Number(r[0]),t=Number(r[1]),n=Number(r[2]);return Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(n)?[e,t,n]:null}if(r&&typeof r=="object"){const e=Number(r.x),t=Number(r.y),n=Number(r.z);if(Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(n))return[e,t,n]}return null},"point3ArrayFromAny"),Cr=h(r=>{const e=_S(r);return e?{x:e[0],y:e[1],z:e[2]}:null},"point3ObjectFromAny"),bo=h(r=>{const e=Array.isArray(r)?r:[],t=[];for(const n of e){const i=Array.isArray(n?.points)?n.points.map(l=>_S(l)).filter(Boolean):[];if(i.length<2)continue;const s={name:String(n?.name||"EDGE"),points:i,closedLoop:!!n?.closedLoop,polylineWorld:!!n?.polylineWorld,centerline:!!n?.centerline},o=String(n?.materialKey||"").trim();o&&(s.materialKey=o);const a=String(n?.faceA||"").trim(),c=String(n?.faceB||"").trim();a&&(s.faceA=a),c&&(s.faceB=c),t.push(s)}return t},"sanitizeAuxEdges"),XN=h((r,e=1e-9)=>{const t=Array.isArray(r)?r:[];if(t.length===0)return[];const n=Number.isFinite(e)?Math.max(1e-12,Math.abs(e)):1e-9,i=n*n,s=[];for(let d=0;d<t.length;d++){const p=t[d];if(!Array.isArray(p)||p.length<3)continue;const m=Number(p[0]),_=Number(p[1]),y=Number(p[2]);!Number.isFinite(m)||!Number.isFinite(_)||!Number.isFinite(y)||s.push([m,_,y])}if(s.length===0)return[];const o=[];for(let d=0;d<s.length;d++){const p=s[d];if(o.length>0){const m=o[o.length-1],_=p[0]-m[0],y=p[1]-m[1],g=p[2]-m[2];if(_*_+y*y+g*g<=i)continue}o.push(p)}if(o.length<3)return o;let a=0,c=0;for(let d=1;d<o.length;d++){const p=o[d-1],m=o[d],_=Math.hypot(m[0]-p[0],m[1]-p[1],m[2]-p[2]);!Number.isFinite(_)||_<=0||(a+=_,_>c&&(c=_))}const l=Math.max(n,a*1e-7,c*1e-6),u=l*l;if(u<=i)return o;const f=[];for(let d=0;d<o.length;d++){const p=o[d];if(f.length===0){f.push(p);continue}const m=f[f.length-1],_=p[0]-m[0],y=p[1]-m[1],g=p[2]-m[2];_*_+y*y+g*g<=u||f.push(p)}return f.length>=2?f:o},"sanitizeFilletInputPolyline"),qN=h((r=[])=>{const e=new Map;for(const[t,n]of yi(r))e.set(n,t);return e},"invertFaceNameToIDEntries"),YN=h(r=>{const e=Array.from(r?.triIDs??[]),t=new Set(e),n=Array.from(t).sort((o,a)=>Number(o)-Number(a));let i=new Map(yi(r?.idToFaceName));if(i.size===0&&(i=qN(r?.faceNameToID)),n.every(o=>i.has(o))||n.length===0)return i;if(i.size===n.length){const o=Array.from(i.entries()).sort((c,l)=>Number(c[0])-Number(l[0])).map(c=>String(c?.[1]||"")),a=new Map;for(let c=0;c<n.length;c++)a.set(n[c],o[c]||`FACE_${n[c]}`);return a}for(const o of n)i.has(o)||i.set(o,`FACE_${o}`);return i},"buildResolvedSnapshotIDToFaceName"),KN=h(r=>{const e=YN(r),t=new Map,n=new Map,i=new Map,s=h((a,c="")=>{const l=Number(a);if(i.has(l))return i.get(l);const u=Ds.reserveIDs(1);i.set(l,u);const f=String(e.get(a)??c??"").trim()||`FACE_${u}`;return n.set(u,f),t.set(f,u),u},"ensureReservedID");for(const[a,c]of e.entries())s(a,c);return{triIDs:Array.from(r?.triIDs??[],a=>s(a,e.get(a))),faceNameToID:t,idToFaceName:n}},"remapSnapshotFaceIDsToReservedRange"),Wi=h((r,e,t={})=>{const n=Math.max(3,Number(e?.numProp??3)),i=Array.from(e?.vertProperties??[]);let s=null;if(t?.remapFaceIDs)if(ON){const o=new nt.BrepSolidCore;try{o.setAuthoringState(e),o.normalizeFaceTracking();const a=o.getAuthoringState();s={triIDs:Array.from(a?.triIDs??[]),faceNameToID:new Map(yi(a?.faceNameToID)),idToFaceName:new Map(yi(a?.idToFaceName))}}finally{typeof o.delete=="function"&&o.delete()}}else s=KN(e);r._numProp=n,r._vertProperties=i,r._triVerts=Array.from(e?.triVerts??[]),r._triIDs=s?s.triIDs:Array.from(e?.triIDs??[]),r._faceNameToID=s?s.faceNameToID:new Map(yi(e?.faceNameToID)),r._idToFaceName=s?s.idToFaceName:new Map(yi(e?.idToFaceName)),r._faceMetadata=new Map(Array.from(e?.faceMetadataJson??[],o=>[o?.[0],Mf(o?.[1])])),r._edgeMetadata=new Map(Array.from(e?.edgeMetadataJson??[],o=>[o?.[0],Mf(o?.[1])])),r._auxEdges=bo(e?.auxEdges),r._vertKeyToIndex=PN(i,n),r._faceMetadataVersion=Number(r?._faceMetadataVersion||0)+1,r._edgeMetadataVersion=Number(r?._edgeMetadataVersion||0)+1,r._cppSolidCoreSyncStamp=null},"applySolidAuthoringStateSnapshot"),zr=h((r,e)=>(e.setAuthoringState(Yo(r)),r._cppSolidCoreSyncStamp=Sd(r),e),"syncSolidAuthoringStateToCpp"),Sn=h((r,e)=>{const t=e.getAuthoringState();return Wi(r,t),r._cppSolidCoreSyncStamp=Sd(r),t},"syncSolidAuthoringStateFromCpp"),ZN=h((r,e)=>(r._auxEdges=e.getAuxEdges(),r._cppSolidCoreSyncStamp=Sd(r),r._auxEdges),"syncSolidAuxEdgesFromCpp"),Wo=h(r=>{if(Xt)try{return Mn(r).getAuthoringState()}catch{}const e=Yo(r);return{numProp:Number(e?.numProp??3),vertProperties:Array.from(e?.vertProperties??[]),triVerts:Array.from(e?.triVerts??[]),triIDs:Array.from(e?.triIDs??[]),faceNameToID:gl(e?.faceNameToID),idToFaceName:gl(e?.idToFaceName),faceMetadataJson:gl(e?.faceMetadataJson),edgeMetadataJson:gl(e?.edgeMetadataJson),auxEdges:bo(e?.auxEdges),vertexCount:Math.floor((Array.isArray(e?.vertProperties)?e.vertProperties.length:0)/Math.max(3,Number(e?.numProp??3))),triangleCount:Math.floor((Array.isArray(e?.triVerts)?e.triVerts.length:0)/3)}},"getSolidAuthoringStateSnapshot"),Mn=h(r=>{Rt(Xt,"BrepSolidCore"),r._cppSolidCore=r._cppSolidCore||new Gi;const e=Sd(r);return DN(e,r._cppSolidCoreSyncStamp)||zr(r,r._cppSolidCore),r._cppSolidCore},"getSyncedCppSolidCore"),V2=h((r,e=1,t="INSET")=>{const n={points:[],tangentA:[],tangentB:[],edge:[],closedLoop:!1};try{if(Rt(Xt&&UN,"Solid.computeFilletCenterline()"),!r||!Number.isFinite(e)||e<=0)return n;const i=r.parentSolid||r.parent||null;if(!i)return n;const s=r?.faces?.[0]?.name||r?.userData?.faceA||null,o=r?.faces?.[1]?.name||r?.userData?.faceB||null,a=Array.isArray(r?.userData?.segmentFacePairs)?r.userData.segmentFacePairs:null,c=Array.isArray(a)&&a.length>0;if(!c&&(!s||!o))return n;const l=Math.max(1e-12,Math.abs(Number(e)||0)*1e-9,1e-9),u=XN(r?.userData?.polylineLocal,l);if(!Array.isArray(u)||u.length<2)return n;let f=!!(r?.closedLoop||r?.userData?.closedLoop);if(!f&&u.length>2){const m=u[0],_=u[u.length-1],y=m[0]-_[0],g=m[1]-_[1],x=m[2]-_[2];y*y+g*g+x*x<=l*l&&(f=!0)}const d={polyline:u,radius:Number(e),sideMode:$N(t),closedLoop:!!f};s&&(d.faceAName=s),o&&(d.faceBName=o),c&&(d.segmentFacePairs=a);const p=Mn(i).computeFilletCenterline(d);return!p||typeof p!="object"||(n.nativeKernel=p.nativeKernel===!0,n.closedLoop=!!p.closedLoop,n.points=Array.isArray(p.points)?p.points.map(Cr).filter(Boolean):[],n.tangentA=Array.isArray(p.tangentA)?p.tangentA.map(Cr).filter(Boolean):[],n.tangentB=Array.isArray(p.tangentB)?p.tangentB.map(Cr).filter(Boolean):[],n.edge=Array.isArray(p.edge)?p.edge.map(Cr).filter(Boolean):[],p.radiusClamp&&(n.radiusClamp=p.radiusClamp),p.nativeFinalized===!0&&(n.nativeFinalized=!0)),n}catch(i){return console.warn("[computeFilletCenterlineForEdge] failed:",i?.message||i),n}},"computeFilletCenterlineForEdge"),W_=class W_{constructor(e=null){if(e){this._native=e;return}if(typeof nt?.BrepSolidCore!="function")throw new Error("BrepSolidCore is only available in the custom local manifold build.");this._native=new nt.BrepSolidCore}clear(){return this._native.clear(),this}setAuthoringState(e){return this._native.setAuthoringState(e),this}addTriangle(e,t,n,i){return this._native.addTriangle(e,t,n,i),this}setFaceMetadata(e,t={}){return this._native.setFaceMetadataJson(e,JSON.stringify(t||{})),this}getFaceMetadata(e){return Mf(this._native.getFaceMetadataJson(e))}renameFace(e,t){return!!this._native.renameFace(e,t)}cleanupTinyFaceIslands(e){return Number(this._native.cleanupTinyFaceIslands(e))}removeSmallIslands(e,t=!0,n=!0){return Number(this._native.removeSmallIslands(Math.max(0,Number(e)|0),!!t,!!n))}mergeTinyFaces(e){return Number(this._native.mergeTinyFaces(e))}removeInternalTriangles(){return Number(this._native.removeInternalTriangles())}removeDisconnectedIslandsByVolume(e){return Number(this._native.removeDisconnectedIslandsByVolume(e))}normalizeFaceTracking(){return this._native.normalizeFaceTracking(),this}setEdgeMetadata(e,t={}){return this._native.setEdgeMetadataJson(e,JSON.stringify(t||{})),this}getEdgeMetadata(e){return Mf(this._native.getEdgeMetadataJson(e))}getFaceNames(){return Array.from(this._native.getFaceNames()||[])}getFace(e){return Array.from(this._native.getFace(e)||[],t=>({faceName:String(t?.faceName||e||""),indices:Array.from(t?.indices||[]),p1:Array.from(t?.p1||[]),p2:Array.from(t?.p2||[]),p3:Array.from(t?.p3||[])}))}getFaceNormal(e){const t=this._native.getFaceNormal(e)||{};return{faceFound:!!t?.faceFound,validNormal:!!t?.validNormal,normal:Array.from(t?.normal||[]),planarRatio:Number(t?.planarRatio??0),affectedVertexCount:Number(t?.affectedVertexCount??0)}}getFaces(e=!1){return Array.from(this._native.getFaces(!!e)||[],t=>({faceName:String(t?.faceName||""),triangles:Array.from(t?.triangles||[],n=>({faceName:String(n?.faceName||t?.faceName||""),indices:Array.from(n?.indices||[]),p1:Array.from(n?.p1||[]),p2:Array.from(n?.p2||[]),p3:Array.from(n?.p3||[])}))}))}getBoundaryEdgePolylines(){return Array.from(this._native.getBoundaryEdgePolylines()||[],e=>({name:String(e?.name||""),faceA:String(e?.faceA||""),faceB:String(e?.faceB||""),indices:Array.from(e?.indices||[]),positions:Array.from(e?.positions||[],t=>Array.from(t||[])),closedLoop:!!e?.closedLoop}))}addAuxEdge(e,t,n={}){return this._native.addAuxEdge(String(e||"EDGE"),t||[],n||{}),this}setAuxEdges(e=[]){return this._native.setAuxEdges(bo(e)),this}getAuxEdges(){return bo(this._native.getAuxEdges()||[])}computeFilletCenterline(e={}){const t=this._native.computeFilletCenterline(e||{});return{points:Array.from(t?.points||[],n=>Cr(n)).filter(Boolean),tangentA:Array.from(t?.tangentA||[],n=>Cr(n)).filter(Boolean),tangentB:Array.from(t?.tangentB||[],n=>Cr(n)).filter(Boolean),edge:Array.from(t?.edge||[],n=>Cr(n)).filter(Boolean),closedLoop:!!t?.closedLoop,radiusClamp:t?.radiusClamp||null,nativeKernel:t?.nativeKernel===!0,nativeFinalized:t?.nativeFinalized===!0}}getAuthoringState(){const e=this._native.getAuthoringState();return{numProp:Number(e?.numProp??3),vertProperties:Array.from(e?.vertProperties??[]),triVerts:Array.from(e?.triVerts??[]),triIDs:Array.from(e?.triIDs??[]),faceNameToID:new Map(yi(e?.faceNameToID)),idToFaceName:new Map(yi(e?.idToFaceName)),faceMetadataJson:new Map(yi(e?.faceMetadataJson)),edgeMetadataJson:new Map(yi(e?.edgeMetadataJson)),auxEdges:bo(e?.auxEdges),vertexCount:Number(e?.vertexCount??0),triangleCount:Number(e?.triangleCount??0)}}bakeTransform(e){const t=e&&typeof e=="object"&&"elements"in e?Array.from(e.elements||[]):Array.from(e||[]);return this._native.bakeTransform(t),this}transformMetadata(e){const t=e&&typeof e=="object"&&"elements"in e?Array.from(e.elements||[]):Array.from(e||[]);return this._native.transformMetadata(t),this}weldVerticesByEpsilon(e){return this._native.weldVerticesByEpsilon(e),this}pushFace(e,t){return this._native.pushFace(e,t)}isCoherentlyOrientedManifold(){return!!this._native.isCoherentlyOrientedManifold()}fixTriangleWindingsByAdjacency(){return!!this._native.fixTriangleWindingsByAdjacency()}invertNormals(){return this._native.invertNormals(),this}prepareManifoldMesh(){const e=this._native.prepareManifoldMesh();return{numProp:Number(e?.numProp??3),vertProperties:Array.from(e?.vertProperties??[]),triVerts:Array.from(e?.triVerts??[]),faceID:Array.from(e?.faceID??[]),mergeFromVert:Array.from(e?.mergeFromVert??[]),mergeToVert:Array.from(e?.mergeToVert??[]),vertexCount:Number(e?.vertexCount??0),triangleCount:Number(e?.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}}};h(W_,"CppSolidCore");let Gi=W_;function JN(){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=[]}h(JN,"constructorImpl");function jN(){const r=this.constructor,e=new r;return Wi(e,Wo(this)),e._dirty=!0,e._manifold=null,e._faceIndex=null,e._visualizeCache=null,e._minGapIndex=null,e._cppSolidCore=null,e._cppSolidCoreSyncStamp=null,e.type="SOLID",e.renderOrder=this.renderOrder,e}h(jN,"clone");function QN(){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}h(QN,"free");function eR([r,e,t]){return`${r},${e},${t}`}h(eR,"_key");function tR(r){if(!Array.isArray(r)||r.length<3)throw console.error("Invalid point passed to _getPointIndex:",r),new Error("Point must be an array with at least 3 elements");const e=r[0],t=r[1],n=r[2];if(!isFinite(e)||!isFinite(t)||!isFinite(n))throw console.error("Non-finite coordinates in _getPointIndex:",{x:e,y:t,z:n}),new Error(`Invalid point coordinates: (${e}, ${t}, ${n}) - must be finite numbers`);if((this._vertKeyToIndex?.size||0)===0&&Array.isArray(this._vertProperties)&&this._vertProperties.length>0){this._vertKeyToIndex=new Map;for(let a=0;a<this._vertProperties.length;a+=3){const c=this._vertProperties[a+0],l=this._vertProperties[a+1],u=this._vertProperties[a+2];this._vertKeyToIndex.set(`${c},${l},${u}`,a/3|0)}}const i=this._key(r),s=this._vertKeyToIndex.get(i);if(s!==void 0)return s;const o=this._vertProperties.length/3;return this._vertProperties.push(e,t,n),this._vertKeyToIndex.set(i,o),o}h(tR,"_getPointIndex");function nR(r){if(!this._faceNameToID.has(r)){const e=Ds.reserveIDs(1);this._faceNameToID.set(r,e),this._idToFaceName.set(e,r)}return this._faceNameToID.get(r)}h(nR,"_getOrCreateID");function iR(r,e,t,n){const i=this._getOrCreateID(r),s=this._getPointIndex(e),o=this._getPointIndex(t),a=this._getPointIndex(n);return this._triVerts.push(s,o,a),this._triIDs.push(i),this._dirty=!0,this._faceIndex=null,this}h(iR,"addTriangle");function rR(r,e,t={}){try{const n=h(u=>{if(Array.isArray(u)&&u.length===3)return[u[0],u[1],u[2]];if(u&&typeof u=="object"){const f=+u.x,d=+u.y,p=+u.z;if(Number.isFinite(f)&&Number.isFinite(d)&&Number.isFinite(p))return[f,d,p]}return null},"toArr"),i=Array.isArray(e)?e.map(n).filter(Boolean):[];if(i.length<2)return this;const s=r||"EDGE",o=Object.prototype.hasOwnProperty.call(t||{},"centerline"),a=typeof s=="string"&&/centerline/i.test(s),c=o?!!t.centerline:a;Rt(Xt&&BN,"Solid.addAuxEdge()");const l=Mn(this);l.addAuxEdge(s,i,{closedLoop:!!t.closedLoop,polylineWorld:!!t.polylineWorld,materialKey:t.materialKey||"OVERLAY",centerline:c,faceA:t.faceA||"",faceB:t.faceB||""}),ZN(this,l)}catch{}return this}h(rR,"addAuxEdge");function sR(r,e,t="CENTERLINE",n={}){const i=Array.isArray(r)?r:[r?.x||0,r?.y||0,r?.z||0],s=Array.isArray(e)?e:[e?.x||0,e?.y||0,e?.z||0],o={...n||{}};return Object.prototype.hasOwnProperty.call(o,"centerline")||(o.centerline=!0),this.addAuxEdge(t,[i,s],o)}h(sR,"addCenterline");function oR(r,e){if(!e||typeof e!="object")return this;Rt(Xt,"Solid.setFaceMetadata");const t=Mn(this),n=t.getFaceMetadata(r),i=n&&typeof n=="object"?n:{};return t.setFaceMetadata(r,{...i,...e}),Sn(this,t),this}h(oR,"setFaceMetadata");function aR(r){if(Rt(Xt,"Solid.getFaceMetadata"),this._faceMetadata instanceof Map)return this._faceMetadata.get(r)||{};try{return this._cppSolidCore?.getFaceMetadata(r)||{}}catch{return{}}}h(aR,"getFaceMetadata");function cR(){if(Rt(Xt,"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[]}}h(cR,"getFaceNames");function lR(){const r=this._idToFaceName instanceof Map?this._idToFaceName:new Map,e=this._faceNameToID instanceof Map?this._faceNameToID:new Map;if(r.size===0&&e.size===0)return this;const t=new Map,n=new Map,i=new Map;for(const[s,o]of r.entries())t.has(o)?n.set(s,t.get(o)):(t.set(o,s),i.set(s,o));for(const[s,o]of e.entries())t.has(s)||(t.set(s,o),i.set(o,s));return n.size===0?(this._idToFaceName=i,this._faceNameToID=new Map(Array.from(i.entries(),([s,o])=>[o,s])),this):(this._triIDs=Array.isArray(this._triIDs)?this._triIDs.map(s=>n.get(s)??s):[],this._idToFaceName=i,this._faceNameToID=new Map(Array.from(i.entries(),([s,o])=>[o,s])),this._dirty=!0,this._manifold=null,this._faceIndex=null,this._visualizeCache=null,this._cppSolidCoreSyncStamp=null,this)}h(lR,"deduplicateFaceNames");function uR(r,e){if(!r||!e||r===e)return this;Rt(Xt,"Solid.renameFace");const t=Mn(this),n=this._faceMetadata instanceof Map&&this._faceMetadata.has(r),i=n?t.getFaceMetadata(r)||{}:null,s=this._faceMetadata instanceof Map&&this._faceMetadata.has(e)?t.getFaceMetadata(e)||{}:null;return t.renameFace(r,e)?(Sn(this,t),n&&(t.setFaceMetadata(e,{...s&&typeof s=="object"?s:{},...i&&typeof i=="object"?i:{}}),Sn(this,t)),this._dirty=!0,this._faceIndex=null,this):this}h(uR,"renameFace");function fR(r,e){if(!e||typeof e!="object")return this;Rt(Xt,"Solid.setEdgeMetadata");const t=Mn(this),n=t.getEdgeMetadata(r),i=n&&typeof n=="object"?n:{};return t.setEdgeMetadata(r,{...i,...e}),Sn(this,t),this}h(fR,"setEdgeMetadata");function dR(r){if(Rt(Xt,"Solid.getEdgeMetadata"),this._edgeMetadata instanceof Map)return this._edgeMetadata.get(r)||null;try{return this._cppSolidCore?.getEdgeMetadata(r)||null}catch{return null}}h(dR,"getEdgeMetadata");function xS(r,e=Wn){const t=Array.isArray(r?.position)?r.position:[0,0,0],n=Array.isArray(r?.rotationEuler)?r.rotationEuler:[0,0,0],i=Array.isArray(r?.scale)?r.scale:[1,1,1],s=new e.Vector3(Number(t[0]||0),Number(t[1]||0),Number(t[2]||0)),o=new e.Euler(e.MathUtils.degToRad(Number(n[0]||0)),e.MathUtils.degToRad(Number(n[1]||0)),e.MathUtils.degToRad(Number(n[2]||0)),"XYZ"),a=new e.Quaternion().setFromEuler(o),c=new e.Vector3(Number(i[0]||1),Number(i[1]||1),Number(i[2]||1));return new e.Matrix4().compose(s,a,c)}h(xS,"composeTrsMatrixDeg");function vS(r,e,t=Wn){const n=new t.Vector3(Number(r?.position?.[0]||0),Number(r?.position?.[1]||0),Number(r?.position?.[2]||0)),i=new t.Quaternion().fromArray(Array.isArray(r?.quaternion)&&r.quaternion.length>=4?r.quaternion:[0,0,0,1]),s=new t.Vector3(Number(r?.scale?.[0]||1),Number(r?.scale?.[1]||1),Number(r?.scale?.[2]||1)),o=new t.Matrix4().compose(n,i,s),a=xS(e,t);return o.multiply(a)}h(vS,"combineBaseWithDeltaDeg");function hR(r){try{if(!r||typeof r.elements>"u")return this;if(!Array.isArray(this._vertProperties)||this._vertProperties.length===0)return this;const e=r&&r.isMatrix4?r:new tt().fromArray(r.elements||r);Rt(Xt,"Solid.bakeTransform()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),this._cppSolidCore.bakeTransform(e),Sn(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}h(hR,"bakeTransform");function pR(r){try{const e=xS(r,Wn);return this.bakeTransform(e)}catch{return this}}h(pR,"bakeTRS");function mR(r,e){const t=this.constructor,n=r instanceof H?r.clone():new H(r[0],r[1],r[2]),i=e instanceof H?e.clone().normalize():new H(e[0],e[1],e[2]).normalize(),s=Wo(this),o=this.getMesh();try{const a=o.vertProperties,c=o.triVerts,l=o.faceID&&o.faceID.length?Array.from(o.faceID):[],u=new t;u._numProp=o.numProp||3;const f=new Array(a.length),d=new H;for(let p=0;p<a.length;p+=3){d.set(a[p+0],a[p+1],a[p+2]);const _=2*d.clone().sub(n).dot(i),y=d.sub(i.clone().multiplyScalar(_));f[p+0]=y.x,f[p+1]=y.y,f[p+2]=y.z}u._vertProperties=f,u._triVerts=Array.from(c),u._triIDs=l.length?l:new Array(c.length/3|0).fill(0);try{u._idToFaceName=new Map(s?.idToFaceName||[]),u._faceNameToID=new Map(s?.faceNameToID||[]),u._faceMetadata=new Map(Array.from(s?.faceMetadataJson||[],([p,m])=>[p,JSON.parse(m||"{}")])),u._edgeMetadata=new Map(Array.from(s?.edgeMetadataJson||[],([p,m])=>[p,JSON.parse(m||"{}")]))}catch{}try{const p=Array.isArray(this._auxEdges)?this._auxEdges:[],m=new H,_=new H,y=new H;u._auxEdges=p.map(g=>{const x=[];if(Array.isArray(g?.points))for(const w of g.points)!Array.isArray(w)||w.length!==3||(m.set(w[0],w[1],w[2]),_.subVectors(m,n),y.copy(i).multiplyScalar(2*_.dot(i)),m.sub(y),x.push([m.x,m.y,m.z]));return{name:g?.name,closedLoop:!!g?.closedLoop,polylineWorld:!!g?.polylineWorld,materialKey:g?.materialKey,centerline:!!g?.centerline,points:x}}).filter(g=>Array.isArray(g.points)&&g.points.length)}catch{u._auxEdges=[]}u._vertKeyToIndex=new Map;for(let p=0;p<u._vertProperties.length;p+=3){const m=u._vertProperties[p],_=u._vertProperties[p+1],y=u._vertProperties[p+2];u._vertKeyToIndex.set(`${m},${_},${y}`,p/3|0)}u._dirty=!0,u._faceIndex=null,u._manifold=null;try{Rt(Xt&&zN,"Solid.mirrorAcrossPlane()");const p=i.x,m=i.y,_=i.z,y=n.dot(i),g=new tt().set(1-2*p*p,-2*p*m,-2*p*_,2*y*p,-2*m*p,1-2*m*m,-2*m*_,2*y*m,-2*_*p,-2*_*m,1-2*_*_,2*y*_,0,0,0,1);u._cppSolidCore=u._cppSolidCore||new Gi,zr(u,u._cppSolidCore),u._cppSolidCore.transformMetadata(g),Sn(u,u._cppSolidCore),u._cppSolidCore.dispose(),u._cppSolidCore=null,u._cppSolidCoreSyncStamp=null}catch{}return u}finally{try{o&&typeof o.delete=="function"&&o.delete()}catch{}}}h(mR,"mirrorAcrossPlane");function gR(r,e=.001,t={}){const n=Number(e);if(!r||!Number.isFinite(n)||n===0)return this;const i=t?.warnMissing!==!1,s=t?.warnInvalidNormal!==!1;try{this._manifoldize()}catch{}if(this._faceNameToID.get(r)===void 0)return i&&console.warn(`pushFace: Face "${r}" not found`),this;Rt(Xt&&LN,"Solid.pushFace()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore);const a=this._cppSolidCore.pushFace(r,n)||{};if(!a.faceFound)return i&&console.warn(`pushFace: Face "${r}" not found`),this;if(!a.moved)return a.invalidNormal&&s&&console.warn(`pushFace: Invalid normal for face "${r}"`),this;Sn(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}h(gR,"pushFace");function yR(){const r=h(()=>typeof performance<"u"&&performance?.now?performance.now():Date.now(),"nowMs"),e=r();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){const i=r();return this._manifold}let t=!1;const n=h((i=!0)=>{if(t)return;t=!0;const s=r(),o=(this?._triVerts?.length||0)/3|0,a=(this?._vertProperties?.length||0)/3|0},"__logDone");try{Rt(Xt&&Ym,"Solid._manifoldize()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore);const i=this._cppSolidCore.prepareManifoldMesh();Sn(this,this._cppSolidCore);const s=new UI({numProp:Number(i?.numProp??this._numProp??3),vertProperties:new Float32Array(i?.vertProperties??[]),triVerts:new Uint32Array(i?.triVerts??[]),faceID:new Uint32Array(i?.faceID??[]),mergeFromVert:new Uint32Array(i?.mergeFromVert??[]),mergeToVert:new Uint32Array(i?.mergeToVert??[])});try{this._manifold=new Ds(s)}catch(o){try{if(this&&Object.prototype.hasOwnProperty.call(this,"edgeToFillet")){const a=(this._triVerts?.length||0)/3|0,c=(this._vertProperties?.length||0)/3|0,l=[];try{if(this.edgeToFillet&&Array.isArray(this.edgeToFillet.faces))for(const f of this.edgeToFillet.faces)f&&f.name&&l.push(f.name)}catch{}const u={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:l},counts:{vertices:c,triangles:a,faceLabels:this._faceNameToID&&typeof this._faceNameToID.size=="number"?this._faceNameToID.size:void 0}};try{console.error(JSON.stringify(u))}catch{console.error("[FilletSolidManifoldFailure]",u.message)}}}catch{}throw n(!1),o}finally{try{s&&typeof s.delete=="function"&&s.delete()}catch{}}return this._dirty=!1,this._faceIndex=null,n(!0),this._manifold}finally{const i=!!(this&&this._manifold)&&this._dirty===!1;n(i)}}h(yR,"_manifoldize");function _R(r=0){return this._epsilon=Number(r)||0,this._epsilon>0&&this._weldVerticesByEpsilon(this._epsilon),this}h(_R,"setEpsilon");function xR(r,e={}){Rt(Xt&&FN,"Solid._weldVerticesByEpsilon()");const t=e?.rebuildManifold!==!1;this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),this._cppSolidCore.weldVerticesByEpsilon(r),Sn(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,t&&this._manifoldize(),this}h(xR,"_weldVerticesByEpsilon");function vR(){if(Rt(Xt&&Ym,"Solid.fixTriangleWindingsByAdjacency()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),!this._cppSolidCore.fixTriangleWindingsByAdjacency())return this;Sn(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}h(vR,"fixTriangleWindingsByAdjacency");function bR(){return Rt(Xt&&Ym,"Solid._isCoherentlyOrientedManifold()"),this._cppSolidCore=this._cppSolidCore||new Gi,zr(this,this._cppSolidCore),this._cppSolidCore.isCoherentlyOrientedManifold()}h(bR,"_isCoherentlyOrientedManifold");function SR({maxTriangles:r=30,removeInternal:e=!0,removeExternal:t=!0}={}){Rt(Xt&&VN,"Solid.removeSmallIslands()");const n=Mn(this),i=n.removeSmallIslands(r,e,t);if(i>0){Sn(this,n),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return i}h(SR,"removeSmallIslands");function MR({normalDotThreshold:r=-.95}={}){const e=this._triVerts,t=this._vertProperties,n=this._triIDs;if(!e||!t||!n)return 0;const i=e.length/3|0;if(i===0||n.length!==i)return 0;const s=t.length/3|0;if(s===0)return 0;const o=BigInt(Math.max(1,s)),a=h((v,b)=>{const T=BigInt(v),C=BigInt(b);return T<C?T*o+C:C*o+T},"eKey"),c=new Map,l=h((v,b,T,C)=>{let I=c.get(v);I||(I=[0,0,0],c.set(v,I)),I[0]+=b,I[1]+=T,I[2]+=C},"addNormal"),u=new Map;for(let v=0;v<i;v++){const b=n[v];if(b==null)continue;const T=v*3,C=e[T+0]>>>0,I=e[T+1]>>>0,P=e[T+2]>>>0,N=t[C*3+0],D=t[C*3+1],L=t[C*3+2],R=t[I*3+0],q=t[I*3+1],$=t[I*3+2],U=t[P*3+0],K=t[P*3+1],W=t[P*3+2],ne=R-N,Q=q-D,k=$-L,B=U-N,z=K-D,X=W-L,V=Q*X-k*z,te=k*B-ne*X,ce=ne*z-Q*B;l(b,V,te,ce);const le=[[C,I],[I,P],[P,C]];for(let ue=0;ue<3;ue++){let re=le[ue][0],ae=le[ue][1];if(re===ae)continue;const he=a(re,ae);let Ne=u.get(he);if(!Ne){if(re>ae){const J=re;re=ae,ae=J}Ne={faces:new Set,a:re,b:ae},u.set(he,Ne)}Ne.faces.add(b)}}const f=new Map,d=new Map,p=h((v,b)=>{let T=d.get(v);T||(T=new Set,d.set(v,T)),T.add(b)},"addPair");for(const v of u.values()){if(v.faces.size!==2)continue;const b=Array.from(v.faces),T=b[0],C=b[1];if(T===C)continue;const I=T<C?`${T}|${C}`:`${C}|${T}`;let P=f.get(I);P||(P={ids:T<C?[T,C]:[C,T],edges:[]},f.set(I,P)),P.edges.push([v.a,v.b]),p(T,I),p(C,I)}const m=h(v=>{if(!v||v.length===0)return!1;const b=new Map,T=new Set;for(const[P,N]of v)T.add(P),T.add(N),b.has(P)||b.set(P,new Set),b.has(N)||b.set(N,new Set),b.get(P).add(N),b.get(N).add(P);let C=0;const I=new Set;for(const P of T){if(I.has(P))continue;if(C++,C>1)return!1;const N=[P];for(I.add(P);N.length;){const D=N.pop(),L=b.get(D);if(L)for(const R of L)I.has(R)||(I.add(R),N.push(R))}}return C===1},"isSingleEdgeChain"),_=new Set;for(const[v,b]of d.entries()){if(b.size!==1)continue;const T=b.values().next().value,C=f.get(T);if(!C||!C.edges.length||!m(C.edges))continue;const I=C.ids[0]===v?C.ids[1]:C.ids[0],P=c.get(v),N=c.get(I);if(!P||!N)continue;const D=Math.hypot(P[0],P[1],P[2]),L=Math.hypot(N[0],N[1],N[2]);if(!(D>1e-12)||!(L>1e-12))continue;(P[0]*N[0]+P[1]*N[1]+P[2]*N[2])/(D*L)<=r&&_.add(v)}if(!_.size)return 0;const y=new Uint8Array(i);let g=0;for(let v=0;v<i;v++){if(_.has(n[v])){g++;continue}y[v]=1}if(g===0)return 0;const x=new Uint8Array(s),w=[],S=[];for(let v=0;v<i;v++){if(!y[v])continue;const b=v*3,T=e[b+0]>>>0,C=e[b+1]>>>0,I=e[b+2]>>>0;w.push(T,C,I),S.push(n[v]),x[T]=1,x[C]=1,x[I]=1}const E=new Int32Array(s);for(let v=0;v<s;v++)E[v]=-1;const A=[];let M=0;for(let v=0;v<s;v++)x[v]&&(E[v]=M++,A.push(t[v*3+0],t[v*3+1],t[v*3+2]));for(let v=0;v<w.length;v++)w[v]=E[w[v]];this._vertProperties=A,this._triVerts=w,this._triIDs=S,this._vertKeyToIndex=new Map;for(let v=0;v<this._vertProperties.length;v+=3){const b=this._vertProperties[v],T=this._vertProperties[v+1],C=this._vertProperties[v+2];this._vertKeyToIndex.set(`${b},${T},${C}`,v/3|0)}return this._dirty=!0,this._faceIndex=null,this._manifold=null,g}h(MR,"removeOppositeSingleEdgeFaces");function wR(r,e=1){const t=Number(r);if(!Number.isFinite(t)||t<=0)return 0;const n=this._vertProperties;if(!n||n.length<9||this._triVerts.length<3)return 0;const i=h((a,c,l)=>{const u=n[a*3+0],f=n[a*3+1],d=n[a*3+2],p=n[c*3+0],m=n[c*3+1],_=n[c*3+2],y=n[l*3+0],g=n[l*3+1],x=n[l*3+2],w=p-u,S=m-f,E=_-d,A=y-u,M=g-f,v=x-d,b=S*v-E*M,T=E*A-w*v,C=w*M-S*A;return .5*Math.hypot(b,T,C)},"triArea");let s=0;const o=Math.max(1,e|0);for(let a=0;a<o;a++){const c=this._triVerts,l=this._triIDs,u=c.length/3|0;if(u<2)break;const f=new Array(u),d=new Float64Array(u);for(let A=0;A<u;A++){const M=A*3,v=c[M+0]>>>0,b=c[M+1]>>>0,T=c[M+2]>>>0;f[A]=[v,b,T],d[A]=i(v,b,T)}const p=n.length/3|0,m=BigInt(p),_=h((A,M)=>{const v=BigInt(A),b=BigInt(M);return v<b?v*m+b:b*m+v},"eKey"),y=new Map;for(let A=0;A<u;A++){const[M,v,b]=f[A],T=l[A],C=[[M,v],[v,b],[b,M]];for(let I=0;I<3;I++){const P=C[I][0],N=C[I][1],D=_(P,N);let L=y.get(D);L||(L=[],y.set(D,L)),L.push({tri:A,id:T,a:P,b:N})}}const g=[];for(const[A,M]of y.entries()){if(M.length!==2)continue;const v=M[0],b=M[1];if(v.id===b.id)continue;const T=d[v.tri],C=d[b.tri],I=Math.min(T,C);I<t&&g.push({key:A,a:v,b,minAB:I})}g.sort((A,M)=>A.minAB-M.minAB);const x=new Uint8Array(u);let w=0;const S=h((A,M,v)=>{const b=_(A,M),T=y.get(b);if(T){for(let C=0;C<T.length;C++){const I=T[C];if(I.tri===v&&I.a===A&&I.b===M){T.splice(C,1);break}}T.length===0&&y.delete(b)}},"removeUse"),E=h((A,M,v,b)=>{const T=_(A,M);let C=y.get(T);C||(C=[],y.set(T,C)),C.push({tri:v,id:b,a:A,b:M})},"addUse");for(const{a:A,b:M}of g){const v=A.tri,b=M.tri;if(x[v]||x[b])continue;const T=A.a,C=A.b;if(!(M.a===C&&M.b===T))continue;const I=f[v],P=f[b];let N=-1,D=-1;for(let Q=0;Q<3;Q++){const k=I[Q];if(k!==T&&k!==C){N=k;break}}for(let Q=0;Q<3;Q++){const k=P[Q];if(k!==T&&k!==C){D=k;break}}if(N<0||D<0||N===D)continue;const L=_(N,D),R=y.get(L);if(R&&R.length)continue;const q=d[v],$=d[b],U=Math.min(q,$);if(U>=t)continue;const K=i(N,D,T),W=i(D,N,C);!(Number.isFinite(K)&&Number.isFinite(W))||K<=0||W<=0||Math.min(K,W)<U||(f[v]=[N,D,T],f[b]=[D,N,C],d[v]=K,d[b]=W,S(T,C,v),S(C,T,b),S(C,T,v),S(T,C,b),E(N,D,v,l[v]),E(D,N,v,l[v]),E(D,N,b,l[b]),E(N,D,b,l[b]),x[v]=1,x[b]=1,w++)}if(!w)break;s+=w;for(let A=0;A<u;A++){const M=f[A],v=A*3;c[v+0]=M[0],c[v+1]=M[1],c[v+2]=M[2]}this._dirty=!0,this._faceIndex=null}return s>0&&this.fixTriangleWindingsByAdjacency(),s}h(wR,"removeTinyBoundaryTriangles");function AR({maxEdgeLength:r,maxIterations:e=10}={}){const t=Number(r);if(!Number.isFinite(t)||t<=0)return this;const n=t*t,i=h(()=>{const o=this._vertProperties,a=this._triVerts,c=this._triIDs,l=a.length/3|0,u=o.length/3|0,f=BigInt(Math.max(1,u)),d=h((E,A)=>{const M=BigInt(E),v=BigInt(A);return M<v?M*f+v:v*f+M},"ukey"),p=h((E,A)=>{const M=o[E*3+0],v=o[E*3+1],b=o[E*3+2],T=o[A*3+0],C=o[A*3+1],I=o[A*3+2],P=M-T,N=v-C,D=b-I;return P*P+N*N+D*D},"len2"),m=new Set;for(let E=0;E<l;E++){const A=E*3,M=a[A+0]>>>0,v=a[A+1]>>>0,b=a[A+2]>>>0;p(M,v)>n&&m.add(d(M,v)),p(v,b)>n&&m.add(d(v,b)),p(b,M)>n&&m.add(d(b,M))}if(m.size===0)return!1;const _=o.slice(),y=new Map,g=h((E,A)=>{const M=d(E,A);let v=y.get(M);if(v!==void 0)return v;const b=o[E*3+0],T=o[E*3+1],C=o[E*3+2],I=o[A*3+0],P=o[A*3+1],N=o[A*3+2],D=.5*(b+I),L=.5*(T+P),R=.5*(C+N);return v=_.length/3|0,_.push(D,L,R),y.set(M,v),v},"midpointIndex"),x=[],w=[],S=h((E,A,M,v)=>{x.push(E,A,M),w.push(v)},"emit");for(let E=0;E<l;E++){const A=E*3,M=a[A+0]>>>0,v=a[A+1]>>>0,b=a[A+2]>>>0,T=c[E],C=d(M,v),I=d(v,b),P=d(b,M),N=m.has(C),D=m.has(I),L=m.has(P),R=(N?1:0)+(D?1:0)+(L?1:0);if(R===0){S(M,v,b,T);continue}if(R===1){if(N){const K=g(M,v);S(M,K,b,T),S(K,v,b,T)}else if(D){const K=g(v,b);S(v,K,M,T),S(K,b,M,T)}else{const K=g(b,M);S(b,K,v,T),S(K,M,v,T)}continue}if(R===2){if(N&&D){const K=g(M,v),W=g(v,b);S(M,K,b,T),S(v,W,K,T),S(K,W,b,T)}else if(D&&L){const K=g(v,b),W=g(b,M);S(v,K,M,T),S(b,W,K,T),S(K,W,M,T)}else{const K=g(b,M),W=g(M,v);S(b,K,v,T),S(M,W,K,T),S(K,W,v,T)}continue}const q=g(M,v),$=g(v,b),U=g(b,M);S(M,q,U,T),S(v,$,q,T),S(b,U,$,T),S(q,$,U,T)}this._vertProperties=_,this._triVerts=x,this._triIDs=w,this._vertKeyToIndex=new Map;for(let E=0;E<this._vertProperties.length;E+=3){const A=this._vertProperties[E],M=this._vertProperties[E+1],v=this._vertProperties[E+2];this._vertKeyToIndex.set(`${A},${M},${v}`,E/3|0)}return this._dirty=!0,this._faceIndex=null,!0},"pass");let s=!1;for(let o=0;o<e&&i();o++)s=!0;return s&&this.fixTriangleWindingsByAdjacency(),this}h(AR,"remesh");function ER(r){const e=Number(r);if(!Number.isFinite(e)||e<=0)return 0;const t=this._vertProperties,n=this._triVerts,i=n.length/3|0,s=t.length/3|0;if(i===0||s===0)return 0;const o=e*e,a=new Int32Array(s);for(let k=0;k<s;k++)a[k]=k;const c=h(k=>{for(;a[k]!==k;)a[k]=a[a[k]],k=a[k];return k},"find"),l=h((k,B)=>{let z=c(k),X=c(B);if(z===X)return!1;if(X<z){const V=z;z=X,X=V}return a[X]=z,!0},"unite"),u=h((k,B)=>{const z=t[k*3+0],X=t[k*3+1],V=t[k*3+2],te=t[B*3+0],ce=t[B*3+1],le=t[B*3+2],ue=z-te,re=X-ce,ae=V-le;return ue*ue+re*re+ae*ae},"len2");let f=0;for(let k=0;k<i;k++){const B=k*3,z=n[B+0]>>>0,X=n[B+1]>>>0,V=n[B+2]>>>0,te=u(z,X),ce=u(X,V),le=u(V,z);let ue=te,re=z,ae=X;ce<ue&&(ue=ce,re=X,ae=V),le<ue&&(ue=le,re=V,ae=z),ue<o&&l(re,ae)&&f++}if(f===0)return 0;for(let k=0;k<s;k++){const B=c(k);B!==k&&(t[k*3+0]=t[B*3+0],t[k*3+1]=t[B*3+1],t[k*3+2]=t[B*3+2])}this._vertKeyToIndex=new Map;for(let k=0;k<s;k++){const B=t[k*3+0],z=t[k*3+1],X=t[k*3+2];this._vertKeyToIndex.set(`${B},${z},${X}`,k)}this._dirty=!0,this._faceIndex=null;let d=1/0,p=1/0,m=1/0,_=-1/0,y=-1/0,g=-1/0;for(let k=0;k<s;k++){const B=t[k*3+0],z=t[k*3+1],X=t[k*3+2];B<d&&(d=B),B>_&&(_=B),z<p&&(p=z),z>y&&(y=z),X<m&&(m=X),X>g&&(g=X)}if(!Number.isFinite(d)||!Number.isFinite(_))return f;const x=Math.max(1e-9,_-d),w=Math.max(1e-9,y-p),S=Math.max(1e-9,g-m),E=Math.max(x,w,S,e),A=Math.max(e*10,E*.1+1e-6),M=x+2*A,v=w+2*A,b=S+2*A,T=d-A,C=p-A,I=m-A,P=this.constructor,N=new P,D=[T,C,I],L=[T+M,C,I],R=[T,C+v,I],q=[T+M,C+v,I],$=[T,C,I+b],U=[T+M,C,I+b],K=[T,C+v,I+b],W=[T+M,C+v,I+b];N.addTriangle("__BIGBOX_NX",D,$,K),N.addTriangle("__BIGBOX_NX",D,K,R),N.addTriangle("__BIGBOX_PX",L,q,W),N.addTriangle("__BIGBOX_PX",L,W,U),N.addTriangle("__BIGBOX_NY",D,L,U),N.addTriangle("__BIGBOX_NY",D,U,$),N.addTriangle("__BIGBOX_PY",R,K,W),N.addTriangle("__BIGBOX_PY",R,W,q),N.addTriangle("__BIGBOX_NZ",D,R,q),N.addTriangle("__BIGBOX_NZ",D,q,L),N.addTriangle("__BIGBOX_PZ",$,U,W),N.addTriangle("__BIGBOX_PZ",$,W,K);const ne=this.intersect(N),Q=ne.getMesh();try{this._numProp=Q.numProp||3,this._vertProperties=Array.from(Q.vertProperties||[]),this._triVerts=Array.from(Q.triVerts||[]);const k=this._triVerts.length/3|0;if(Q.faceID&&Q.faceID.length===k)this._triIDs=Array.from(Q.faceID);else{const B=this.constructor;this._triIDs=B._expandTriIDsFromMesh(Q)}this._vertKeyToIndex=new Map;for(let B=0;B<this._vertProperties.length;B+=3){const z=this._vertProperties[B],X=this._vertProperties[B+1],V=this._vertProperties[B+2];this._vertKeyToIndex.set(`${z},${X},${V}`,B/3|0)}try{this._idToFaceName=new Map(ne._idToFaceName)}catch{throw new Error("Failed to adopt face label mapping from boolean result")}try{this._faceNameToID=new Map([...this._idToFaceName.entries()].map(([B,z])=>[z,B]))}catch{}this._dirty=!1,this._faceIndex=null,this._manifold=null}finally{try{Q&&typeof Q.delete=="function"&&Q.delete()}catch{}}return f}h(ER,"collapseTinyTriangles");function TR(r=!1){const e=r&&typeof r=="object"?r:{},t=r===!0||e.diagnostics===!0,n=e.detectOnly===!0||e.probeOnly===!0,i=Math.max(0,Number(e.maxIntersections)||0),s=Array.from(this._vertProperties||[]),o=Array.from(this._triVerts||[]),a=Array.from(this._triIDs||[]),c=o.length/3|0;if(c<2||s.length<9)return 0;const l={add(O,j){return[O[0]+j[0],O[1]+j[1],O[2]+j[2]]},sub(O,j){return[O[0]-j[0],O[1]-j[1],O[2]-j[2]]},mul(O,j){return[O[0]*j,O[1]*j,O[2]*j]},dot(O,j){return O[0]*j[0]+O[1]*j[1]+O[2]*j[2]},cross(O,j){return[O[1]*j[2]-O[2]*j[1],O[2]*j[0]-O[0]*j[2],O[0]*j[1]-O[1]*j[0]]},len(O){return Math.hypot(O[0],O[1],O[2])},dist(O,j){return Math.hypot(O[0]-j[0],O[1]-j[1],O[2]-j[2])},norm(O){const j=Math.hypot(O[0],O[1],O[2]);return j>0?[O[0]/j,O[1]/j,O[2]/j]:[0,0,0]}},u={sub(O,j){return[O[0]-j[0],O[1]-j[1]]},cross(O,j){return O[0]*j[1]-O[1]*j[0]},dot(O,j){return O[0]*j[0]+O[1]*j[1]},dist(O,j){return Math.hypot(O[0]-j[0],O[1]-j[1])}};let f=1/0,d=1/0,p=1/0,m=-1/0,_=-1/0,y=-1/0;for(let O=0;O<s.length;O+=3){const j=s[O+0],ee=s[O+1],pe=s[O+2];j<f&&(f=j),j>m&&(m=j),ee<d&&(d=ee),ee>_&&(_=ee),pe<p&&(p=pe),pe>y&&(y=pe)}const g=Math.max(1,Math.hypot(m-f,_-d,y-p)),x=Math.max(1e-9,Number(e.snapTolerance)||g*1e-9),w=Math.max(x*8,g*1e-10),S=Math.max(1e-18,g*g*1e-18),E=h(O=>[Math.round(O[0]/x),Math.round(O[1]/x),Math.round(O[2]/x)].join(","),"qPoint"),A=h(O=>[s[O*3+0],s[O*3+1],s[O*3+2]],"sourcePoint"),M=h((O,j,ee)=>l.len(l.cross(l.sub(j,O),l.sub(ee,O)))*.5,"triangleArea3"),v=h((O,j,ee)=>{const pe=l.cross(l.sub(j,O),l.sub(ee,O)),fe=l.len(pe);if(!(fe>1e-18))return null;const de=l.mul(pe,1/fe);return{n:de,d:-l.dot(de,O)}},"planeOf"),b=h((O,j)=>l.dot(O.n,j)+O.d,"signedDistance"),T=h((O,j,ee)=>{const pe=l.norm(l.cross(l.sub(j,O),l.sub(ee,O)));if(l.len(pe)<=0)return null;let fe=l.sub(j,O);if(l.len(fe)<=x&&(fe=l.sub(ee,O)),fe=l.norm(fe),l.len(fe)<=0)return null;const de=l.norm(l.cross(pe,fe));if(l.len(de)<=0)return null;const Re=O;return{origin:Re,u:fe,v:de,n:pe,project(se){const me=l.sub(se,Re);return[l.dot(me,fe),l.dot(me,de)]},unproject(se){return l.add(Re,l.add(l.mul(fe,se[0]),l.mul(de,se[1])))}}},"makeBasis"),C=h((O,j,ee,pe,fe=1e-12)=>{const de=u.sub(ee,j),Re=u.sub(pe,ee),se=u.sub(j,pe),me=u.sub(O,j),xe=u.sub(O,ee),Ce=u.sub(O,pe),be=u.cross(de,me),Pe=u.cross(Re,xe),ie=u.cross(se,Ce);return be>=-fe&&Pe>=-fe&&ie>=-fe||be<=fe&&Pe<=fe&&ie<=fe},"pointInTri2D"),I=h((O,j,ee,pe,fe=1e-12)=>{const de=u.sub(j,O),Re=u.sub(pe,ee),se=u.cross(de,Re),me=u.sub(ee,O),xe=[];if(Math.abs(se)>fe){const ze=u.cross(me,Re)/se,Qe=u.cross(me,de)/se;return ze>=-fe&&ze<=1+fe&&Qe>=-fe&&Qe<=1+fe&&xe.push([O[0]+de[0]*ze,O[1]+de[1]*ze]),xe}if(Math.abs(u.cross(me,de))>fe)return xe;const Ce=Math.abs(de[0])>=Math.abs(de[1])?0:1,be=O[Ce],Pe=j[Ce],ie=ee[Ce],Se=pe[Ce],Ie=Math.min(be,Pe),Ue=Math.max(be,Pe),De=Math.min(ie,Se),_e=Math.max(ie,Se),Te=Math.max(Ie,De),Oe=Math.min(Ue,_e);if(Oe<Te-fe)return xe;const Fe=h(ze=>{const Qe=Pe-be,st=Math.abs(Qe)>fe?(ze-be)/Qe:0;return[O[0]+de[0]*st,O[1]+de[1]*st]},"pointAt");return xe.push(Fe(Te)),Oe>Te+fe&&xe.push(Fe(Oe)),xe},"segmentIntersection2D"),P=h((O,j,ee,pe=1e-10)=>{const fe=u.sub(ee,j),de=u.sub(O,j),Re=u.dot(fe,fe);if(!(Re>pe*pe)||Math.abs(u.cross(fe,de))>pe*Math.sqrt(Re))return!1;const me=u.dot(de,fe)/Re;return me>=-pe&&me<=1+pe},"pointOnSegment2D"),N=h((O,j,ee,pe=x)=>{const fe=l.sub(ee,j),de=l.sub(O,j),Re=l.len(fe);if(!(Re>pe))return l.dist(O,j)<=pe;if(l.len(l.cross(fe,de))>pe*Re)return!1;const me=l.dot(de,fe)/(Re*Re);return me>=-pe&&me<=1+pe},"pointOnSegment3D"),D=h(O=>{const j=[],ee=new Set,pe=h(se=>`${Math.round(se[0]/x)},${Math.round(se[1]/x)}`,"q2");for(const se of O){const me=pe(se);ee.has(me)||(ee.add(me),j.push(se))}if(j.sort((se,me)=>se[0]-me[0]||se[1]-me[1]),j.length<=2)return j;const fe=h((se,me,xe)=>u.cross(u.sub(me,se),u.sub(xe,se)),"cross"),de=[];for(const se of j){for(;de.length>=2&&fe(de[de.length-2],de[de.length-1],se)<=x;)de.pop();de.push(se)}const Re=[];for(let se=j.length-1;se>=0;se--){const me=j[se];for(;Re.length>=2&&fe(Re[Re.length-2],Re[Re.length-1],me)<=x;)Re.pop();Re.push(me)}return de.pop(),Re.pop(),de.concat(Re)},"convexHull2D"),L=h((O,j=ee=>ee)=>{let ee=0;for(let pe=0;pe<O.length;pe++){const fe=j(O[pe]),de=j(O[(pe+1)%O.length]);ee+=fe[0]*de[1]-de[0]*fe[1]}return ee*.5},"polygonArea2D"),R=h((O,j)=>{const ee=[],pe=h(se=>{for(const me of ee)if(l.dist(se,me)<=x)return;ee.push(se)},"add"),fe=O.map(se=>b(j,se));for(let se=0;se<3;se++){const me=(se+1)%3,xe=O[se],Ce=O[me],be=fe[se],Pe=fe[me];if(Math.abs(be)<=w&&pe(xe),Math.abs(be)<=w&&Math.abs(Pe)<=w){pe(Ce);continue}if(be<-w&&Pe>w||be>w&&Pe<-w){const ie=be/(be-Pe);pe([xe[0]+(Ce[0]-xe[0])*ie,xe[1]+(Ce[1]-xe[1])*ie,xe[2]+(Ce[2]-xe[2])*ie])}}if(ee.length<=2)return ee;let de=[ee[0],ee[1]],Re=-1/0;for(let se=0;se<ee.length;se++)for(let me=se+1;me<ee.length;me++){const xe=l.dist(ee[se],ee[me]);xe>Re&&(de=[ee[se],ee[me]],Re=xe)}return de},"trianglePlaneSegment"),q=h((O,j,ee)=>{const pe=O.map(me=>ee.project(me)),fe=j.map(me=>ee.project(me)),de=[],Re=h(me=>{for(const xe of de)if(u.dist(me,xe)<=x)return;de.push(me)},"add2");for(const me of pe)C(me,fe[0],fe[1],fe[2],x)&&Re(me);for(const me of fe)C(me,pe[0],pe[1],pe[2],x)&&Re(me);for(let me=0;me<3;me++){const xe=pe[me],Ce=pe[(me+1)%3];for(let be=0;be<3;be++){const Pe=fe[be],ie=fe[(be+1)%3];for(const Se of I(xe,Ce,Pe,ie,x))Re(Se)}}if(de.length<2)return null;const se=D(de);if(se.length>=3&&Math.abs(L(se))>S){const me=[];for(let xe=0;xe<se.length;xe++)me.push([ee.unproject(se[xe]),ee.unproject(se[(xe+1)%se.length])]);return{type:"segments",segments:me}}return se.length>=2&&u.dist(se[0],se[se.length-1])>x?{type:"segments",segments:[[ee.unproject(se[0]),ee.unproject(se[se.length-1])]]}:null},"coplanarTriangleOverlap"),$=h((O,j)=>{const ee=v(O[0],O[1],O[2]),pe=v(j[0],j[1],j[2]);if(!ee||!pe)return null;const fe=j.map(Fe=>b(ee,Fe)),de=O.map(Fe=>b(pe,Fe)),Re=h(Fe=>Fe.every(ze=>ze>w),"allPositive"),se=h(Fe=>Fe.every(ze=>ze<-w),"allNegative");if(Re(fe)||se(fe)||Re(de)||se(de))return null;const me=l.cross(ee.n,pe.n),xe=l.len(me);if(xe<=1e-8&&fe.every(Fe=>Math.abs(Fe)<=w)&&de.every(Fe=>Math.abs(Fe)<=w)){const Fe=T(O[0],O[1],O[2]);return Fe?q(O,j,Fe):null}if(!(xe>1e-14))return null;const be=R(O,pe),Pe=R(j,ee);if(be.length<2||Pe.length<2){if(be.length===1&&Pe.length===2&&N(be[0],Pe[0],Pe[1]))return{type:"point",point:be[0]};if(Pe.length===1&&be.length===2&&N(Pe[0],be[0],be[1]))return{type:"point",point:Pe[0]};const Fe=be.concat(Pe),ze=[];for(const Qe of Fe)ze.some(st=>l.dist(st,Qe)<=x)||ze.push(Qe);return ze.length===1?{type:"point",point:ze[0]}:null}const ie=l.mul(me,1/xe),Se=be[0],Ie=be.map(Fe=>l.dot(l.sub(Fe,Se),ie)).sort((Fe,ze)=>Fe-ze),Ue=Pe.map(Fe=>l.dot(l.sub(Fe,Se),ie)).sort((Fe,ze)=>Fe-ze),De=Math.max(Ie[0],Ue[0]),_e=Math.min(Ie[1],Ue[1]);if(_e<De-x)return null;const Te=l.add(Se,l.mul(ie,De)),Oe=l.add(Se,l.mul(ie,_e));return l.dist(Te,Oe)>x?{type:"segments",segments:[[Te,Oe]]}:{type:"point",point:Te}},"triangleIntersection"),U=new Array(c);for(let O=0;O<c;O++){const j=O*3,ee=o[j+0]>>>0,pe=o[j+1]>>>0,fe=o[j+2]>>>0,de=[A(ee),A(pe),A(fe)],Re=[Math.min(de[0][0],de[1][0],de[2][0]),Math.min(de[0][1],de[1][1],de[2][1]),Math.min(de[0][2],de[1][2],de[2][2])],se=[Math.max(de[0][0],de[1][0],de[2][0]),Math.max(de[0][1],de[1][1],de[2][1]),Math.max(de[0][2],de[1][2],de[2][2])];U[O]={indices:[ee,pe,fe],id:a[O]??0,points:de,min:Re,max:se,segments:[],pointsOnly:[],segmentKeys:new Set,pointKeys:new Set}}const K=h((O,j)=>{const ee=E(j);O.pointKeys.has(ee)||(O.pointKeys.add(ee),O.pointsOnly.push(j))},"addPointOnly"),W=h((O,j,ee)=>{if(l.dist(j,ee)<=x){K(O,j);return}const pe=E(j),fe=E(ee),de=pe<fe?`${pe}|${fe}`:`${fe}|${pe}`;O.segmentKeys.has(de)||(O.segmentKeys.add(de),O.segments.push([j,ee]))},"addSegment"),ne=h((O,j)=>{const ee=[],pe=h(fe=>{ee.some(de=>l.dist(de,fe)<=x)||ee.push(fe)},"add");for(const fe of O.points)for(const de of j.points)l.dist(fe,de)<=x&&pe(fe);return ee},"sharedCoordinatePoints"),Q=h((O,j,ee,pe)=>{const fe=ne(O,j);if(fe.length!==2)return!1;const de=l.dist(ee,fe[0])<=x&&l.dist(pe,fe[1])<=x,Re=l.dist(ee,fe[1])<=x&&l.dist(pe,fe[0])<=x;return de||Re},"isOnlySharedEdge"),k=h((O,j,ee)=>{const pe=ne(O,j);return pe.length>0&&pe.some(fe=>l.dist(fe,ee)<=x)},"isOnlySharedPoint"),B=h((O,j)=>!(O.max[0]<j.min[0]-w||j.max[0]<O.min[0]-w||O.max[1]<j.min[1]-w||j.max[1]<O.min[1]-w||O.max[2]<j.min[2]-w||j.max[2]<O.min[2]-w),"overlapAABB"),z=Array.from({length:c},(O,j)=>j).sort((O,j)=>U[O].min[0]-U[j].min[0]);let X=0,V=0,te=0;for(let O=0;O<z.length;O++){const j=z[O],ee=U[j];if(!(M(ee.points[0],ee.points[1],ee.points[2])<=S))for(let pe=O+1;pe<z.length;pe++){const fe=z[pe],de=U[fe];if(de.min[0]>ee.max[0]+w)break;if(!B(ee,de)||M(de.points[0],de.points[1],de.points[2])<=S)continue;te++;const Re=$(ee.points,de.points);if(!Re)continue;const se=ne(ee,de);if(se.length>0){const xe=h(Ce=>se.some(be=>l.dist(Ce,be)<=x),"touchesCommonPoint");if(Re.type==="point"&&xe(Re.point))continue;if(Re.type==="segments"){const Ce=Re.segments||[];if(Ce.length&&Ce.every(([be,Pe])=>xe(be)||xe(Pe)))continue}}if(Re.type==="point"){if(k(ee,de,Re.point))continue;if(K(ee,Re.point),K(de,Re.point),V++,n&&i>0&&X+V>=i)return X+V;continue}let me=!1;for(const[xe,Ce]of Re.segments||[])Q(ee,de,xe,Ce)||(W(ee,xe,Ce),W(de,xe,Ce),me=!0);if(me&&(X++,n&&i>0&&X+V>=i))return X+V}}const ce=X+V;if(ce===0)return t&&console.log("[splitSelfIntersectingTriangles] no splittable intersections",{triCount:c,testedPairs:te}),0;const le=new Set,ue=[],re=h(O=>{const j=E(O);le.has(j)||(le.add(j),ue.push(O))},"addEdgeSplitPoint");for(const O of U){for(const[j,ee]of O.segments)re(j),re(ee);for(const j of O.pointsOnly)re(j)}if(ue.length&&ue.length<=1024)for(const O of U)for(const j of ue){if(O.points.some(pe=>l.dist(pe,j)<=x))continue;let ee=!1;for(let pe=0;pe<3;pe++){const fe=O.points[pe],de=O.points[(pe+1)%3];if(N(j,fe,de,x)){ee=!0;break}}ee&&K(O,j)}this._vertProperties=s.slice(),this._vertKeyToIndex=new Map;const ae=new Map;for(let O=0;O<this._vertProperties.length;O+=3){const j=O/3|0,ee=[this._vertProperties[O+0],this._vertProperties[O+1],this._vertProperties[O+2]];this._vertKeyToIndex.set(`${ee[0]},${ee[1]},${ee[2]}`,j),ae.has(E(ee))||ae.set(E(ee),j)}const he=h(O=>{const j=E(O),ee=ae.get(j);if(ee!==void 0)return ee;const pe=this._vertProperties.length/3|0;return this._vertProperties.push(O[0],O[1],O[2]),ae.set(j,pe),this._vertKeyToIndex.set(`${O[0]},${O[1]},${O[2]}`,pe),pe},"getOrCreateVertex"),Ne=h(O=>{const j=T(O.points[0],O.points[1],O.points[2]);if(!j)return null;const ee=[],pe=new Map,fe=new Map,de=[],Re=Math.max(u.dist(j.project(O.points[0]),j.project(O.points[1])),u.dist(j.project(O.points[1]),j.project(O.points[2])),u.dist(j.project(O.points[2]),j.project(O.points[0])),1),se=Math.max(x,Re*1e-10),me=Math.max(1e-18,Re*Re*1e-16),xe=h(ie=>`${Math.round(ie[0]/se)},${Math.round(ie[1]/se)}`,"localKey"),Ce=h(ie=>{const Se=he(ie),Ie=pe.get(Se);if(Ie!==void 0)return Ie;const Ue=j.project(ie),De=xe(Ue),_e=fe.get(De);if(_e!==void 0)return pe.set(Se,_e),_e;const Te=ee.length;return ee.push({global:Se,p3:ie,p2:Ue}),pe.set(Se,Te),fe.set(De,Te),Te},"addLocalPoint"),be=h((ie,Se)=>{const Ie=Ce(ie),Ue=Ce(Se);Ie!==Ue&&de.push([Ie,Ue])},"addLocalSegment"),Pe=O.points.map(Ce);be(O.points[0],O.points[1]),be(O.points[1],O.points[2]),be(O.points[2],O.points[0]);for(const[ie,Se]of O.segments)be(ie,Se);for(const ie of O.pointsOnly){const Se=Ce(ie);for(const Ie of Pe)Se!==Ie&&de.push([Se,Ie])}return{basis:j,localPoints:ee,localSegments:de,original:Pe,eps2:se,area2:me}},"makeLocalRetriangulator"),J=h((O,j,ee,pe,fe)=>{const de=u.sub(j,O),Re=u.sub(ee,O),se=u.sub(pe,O),me=u.sub(pe,ee),xe=u.sub(O,ee),Ce=u.sub(j,ee),be=u.cross(de,Re),Pe=u.cross(de,se),ie=u.cross(me,xe),Se=u.cross(me,Ce);return be*Pe<-fe*fe&&ie*Se<-fe*fe},"segmentProperlyCrosses"),Be=h(O=>{if(!O.segments.length&&!O.pointsOnly.length)return[[O.indices[0],O.indices[1],O.indices[2]]];const j=Ne(O);if(!j)return[[O.indices[0],O.indices[1],O.indices[2]]];const{localPoints:ee,localSegments:pe,original:fe,eps2:de,area2:Re}=j,se=l.norm(l.cross(l.sub(O.points[1],O.points[0]),l.sub(O.points[2],O.points[0]))),me=h(()=>{const Te=pe.length;for(let Oe=0;Oe<Te;Oe++){const[Fe,ze]=pe[Oe],Qe=ee[Fe].p2,st=ee[ze].p2;for(let qe=Oe+1;qe<Te;qe++){const[at,_t]=pe[qe],Ot=ee[at].p2,sn=ee[_t].p2;for(const kt of I(Qe,st,Ot,sn,de)){const ti=j.basis.unproject(kt),wn=(()=>{const Gn=he(ti),Si=ee.findIndex(Mi=>Mi.global===Gn);if(Si>=0)return Si;const ar=ee.length;return ee.push({global:Gn,p3:ti,p2:kt}),ar})()}}}},"addSegmentIntersections");h(()=>{const Te=new Int32Array(ee.length);for(let qe=0;qe<Te.length;qe++)Te[qe]=qe;const Oe=h(qe=>{let at=qe;for(;Te[at]!==at;)at=Te[at];for(;Te[qe]!==qe;){const _t=Te[qe];Te[qe]=at,qe=_t}return at},"find"),Fe=h((qe,at)=>{const _t=Oe(qe),Ot=Oe(at);_t!==Ot&&(Te[Ot]=_t)},"unite");for(const[qe,at]of pe)Fe(qe,at);const ze=Oe(fe[0]),Qe=new Map;for(let qe=0;qe<ee.length;qe++){const at=Oe(qe);let _t=Qe.get(at);_t||(_t=[],Qe.set(at,_t)),_t.push(qe)}const st=h(()=>pe.map(([qe,at])=>[ee[qe].p2,ee[at].p2]),"existingSegments");for(const[qe,at]of Qe.entries()){if(qe===ze||at.some(sn=>fe.includes(sn)))continue;let _t=null;const Ot=st();for(const sn of at){const kt=ee[sn].p2;for(const ti of fe){const wn=ee[ti].p2;let Gn=!0;for(const[ar,Mi]of Ot)if(!(u.dist(kt,ar)<=de||u.dist(kt,Mi)<=de||u.dist(wn,ar)<=de||u.dist(wn,Mi)<=de)&&J(kt,wn,ar,Mi,de)){Gn=!1;break}if(!Gn)continue;const Si=u.dist(kt,wn);(!_t||Si<_t.dist)&&(_t={member:sn,target:ti,dist:Si})}}_t&&pe.push([_t.member,_t.target])}},"connectInteriorComponents")(),me();const Ce=new Set,be=h((Te,Oe)=>{if(Te===Oe||u.dist(ee[Te].p2,ee[Oe].p2)<=de)return;const Fe=Te<Oe?`${Te}|${Oe}`:`${Oe}|${Te}`;Ce.has(Fe)||Ce.add(Fe)},"addEdge");for(const[Te,Oe]of pe){const Fe=ee[Te].p2,ze=ee[Oe].p2,Qe=u.sub(ze,Fe),st=u.dot(Qe,Qe);if(!(st>de*de))continue;const qe=[];for(let at=0;at<ee.length;at++){const _t=ee[at].p2;if(!P(_t,Fe,ze,de))continue;const Ot=u.dot(u.sub(_t,Fe),Qe)/st;qe.push({index:at,t:Ot})}qe.sort((at,_t)=>at.t-_t.t);for(let at=0;at+1<qe.length;at++)be(qe[at].index,qe[at+1].index)}const Pe=new Map;for(const Te of Ce){const[Oe,Fe]=Te.split("|"),ze=Number(Oe),Qe=Number(Fe);Pe.has(ze)||Pe.set(ze,new Set),Pe.has(Qe)||Pe.set(Qe,new Set),Pe.get(ze).add(Qe),Pe.get(Qe).add(ze)}for(const[Te,Oe]of Pe.entries()){const Fe=ee[Te].p2;Pe.set(Te,Array.from(Oe).sort((ze,Qe)=>{const st=ee[ze].p2,qe=ee[Qe].p2;return Math.atan2(st[1]-Fe[1],st[0]-Fe[0])-Math.atan2(qe[1]-Fe[1],qe[0]-Fe[0])}))}const ie=new Set,Se=h((Te,Oe)=>`${Te}>${Oe}`,"directedKey"),Ie=[];for(const Te of Ce){const[Oe,Fe]=Te.split("|");for(const ze of[[Number(Oe),Number(Fe)],[Number(Fe),Number(Oe)]]){let[Qe,st]=ze;if(ie.has(Se(Qe,st)))continue;const qe=[],at=Math.max(12,Ce.size*4);let _t=0;for(;!ie.has(Se(Qe,st))&&_t++<at;){ie.add(Se(Qe,st)),qe.push(Qe);const Ot=Pe.get(st)||[],sn=Ot.indexOf(Qe);if(sn<0||Ot.length===0)break;const kt=Ot[(sn-1+Ot.length)%Ot.length];if(Qe=st,st=kt,Qe===ze[0]&&st===ze[1])break}qe.length>=3&&L(qe,sn=>ee[sn].p2)>Re&&Ie.push(qe)}}const Ue=h((Te,Oe,Fe,ze)=>{const Qe=Math.abs(u.cross(u.sub(Fe,Oe),u.sub(ze,Oe)));if(!(Qe>Re))return!1;const st=Math.abs(u.cross(u.sub(Oe,Te),u.sub(Fe,Te))),qe=Math.abs(u.cross(u.sub(Fe,Te),u.sub(ze,Te))),at=Math.abs(u.cross(u.sub(ze,Te),u.sub(Oe,Te)));return Math.abs(st+qe+at-Qe)>Math.max(Re,Qe*1e-8)?!1:st>Re&&qe>Re&&at>Re},"pointStrictlyInTri2D"),De=h(Te=>{const Oe=[],Fe=Te.slice();L(Fe,st=>ee[st].p2)<0&&Fe.reverse();let Qe=0;for(;Fe.length>3&&Qe++<Te.length*Te.length*4;){let st=!1;for(let qe=0;qe<Fe.length;qe++){const at=Fe[(qe-1+Fe.length)%Fe.length],_t=Fe[qe],Ot=Fe[(qe+1)%Fe.length],sn=ee[at].p2,kt=ee[_t].p2,ti=ee[Ot].p2;if(u.cross(u.sub(kt,sn),u.sub(ti,kt))<=Re)continue;let wn=!1;for(const Gn of Fe)if(!(Gn===at||Gn===_t||Gn===Ot)&&Ue(ee[Gn].p2,sn,kt,ti)){wn=!0;break}if(!wn){Oe.push([at,_t,Ot]),Fe.splice(qe,1),st=!0;break}}if(!st){for(let qe=1;qe+1<Fe.length;qe++)Oe.push([Fe[0],Fe[qe],Fe[qe+1]]);Fe.length=0}}return Fe.length===3&&Oe.push([Fe[0],Fe[1],Fe[2]]),Oe},"triangulateLoop"),_e=[];for(const Te of Ie)for(const Oe of De(Te)){const Fe=ee[Oe[0]],ze=ee[Oe[1]],Qe=ee[Oe[2]];if(M(Fe.p3,ze.p3,Qe.p3)<=S)continue;const st=l.cross(l.sub(ze.p3,Fe.p3),l.sub(Qe.p3,Fe.p3));l.dot(st,se)<0?_e.push([Fe.global,Qe.global,ze.global]):_e.push([Fe.global,ze.global,Qe.global])}return _e.length?_e:[[O.indices[0],O.indices[1],O.indices[2]]]},"retriangulateRecord"),ge=[],Ae=[];let Ee=0;for(let O=0;O<c;O++){const j=U[O],ee=Be(j);(j.segments.length||j.pointsOnly.length)&&Ee++;for(const pe of ee)ge.push(pe[0],pe[1],pe[2]),Ae.push(j.id)}this._triVerts=ge,this._triIDs=Ae,this._dirty=!0,this._faceIndex=null,this._manifold=null;try{this.removeDegenerateTriangles()}catch{}const F=h(()=>{const O=this._triVerts||[],j=this._vertProperties||[],ee=this._triIDs||[],pe=O.length/3|0,fe=new Set,de=[],Re=[];let se=0;for(let me=0;me<pe;me++){const xe=me*3,Ce=[O[xe+0]>>>0,O[xe+1]>>>0,O[xe+2]>>>0],be=Ce.map(Pe=>E([j[Pe*3+0],j[Pe*3+1],j[Pe*3+2]])).sort().join("|");if(fe.has(be)){se++;continue}fe.add(be),de.push(Ce[0],Ce[1],Ce[2]),Re.push(ee[me])}return se?(this._triVerts=de,this._triIDs=Re,this._dirty=!0,this._faceIndex=null,this._manifold=null,se):0},"removeDuplicateTriangles")();return h(()=>{const O=this._triVerts||[],j=this._vertProperties||[],ee=j.length/3|0,pe=new Uint8Array(ee);for(const se of O)pe[se>>>0]=1;const fe=new Int32Array(ee);for(let se=0;se<ee;se++)fe[se]=-1;const de=[];let Re=0;for(let se=0;se<ee;se++)pe[se]&&(fe[se]=Re++,de.push(j[se*3+0],j[se*3+1],j[se*3+2]));for(let se=0;se<O.length;se++)O[se]=fe[O[se]>>>0];this._vertProperties=de,this._vertKeyToIndex=new Map;for(let se=0;se<de.length;se+=3)this._vertKeyToIndex.set(`${de[se]},${de[se+1]},${de[se+2]}`,se/3|0)},"compactVertices")(),t&&console.log("[splitSelfIntersectingTriangles] complete",{initialTriangles:c,finalTriangles:this._triVerts.length/3|0,testedPairs:te,pairIntersections:X,pointIntersections:V,touchedTriangles:Ee,duplicateRemovals:F}),ce}h(TR,"splitSelfIntersectingTriangles");function CR(){if(!this._triVerts||!this._vertProperties)return 0;try{this._manifoldize()}catch{console.log("[removeDegenerateTriangles] manifoldization failed, proceeding with best effort cleanup")}const r={sub:h((o,a)=>[o[0]-a[0],o[1]-a[1],o[2]-a[2]],"sub"),len:h(o=>Math.sqrt(o[0]*o[0]+o[1]*o[1]+o[2]*o[2]),"len"),cross:h((o,a)=>[o[1]*a[2]-o[2]*a[1],o[2]*a[0]-o[0]*a[2],o[0]*a[1]-o[1]*a[0]],"cross")},e=this._triVerts.length/3,t=[],n=[];let i=0;const s=h(o=>{const a=o*3,c=this._triVerts[a]*3,l=this._triVerts[a+1]*3,u=this._triVerts[a+2]*3,f=[this._vertProperties[c],this._vertProperties[c+1],this._vertProperties[c+2]],d=[this._vertProperties[l],this._vertProperties[l+1],this._vertProperties[l+2]],p=[this._vertProperties[u],this._vertProperties[u+1],this._vertProperties[u+2]],m=1e-10,_=r.len(r.sub(f,d)),y=r.len(r.sub(d,p)),g=r.len(r.sub(p,f));if(_<m||y<m||g<m)return!0;const x=r.cross(r.sub(d,f),r.sub(p,f));return .5*r.len(x)<1e-12},"isDegenerate");for(let o=0;o<e;o++)if(s(o))i++;else{const a=o*3;t.push(this._triVerts[a]),t.push(this._triVerts[a+1]),t.push(this._triVerts[a+2]),n.push(this._triIDs[o])}return this._triVerts=t,this._triIDs=n,i>0&&(this._dirty=!0,this._faceIndex=null,this._manifold=null),i}h(CR,"removeDegenerateTriangles");function IR(){if((this._triVerts.length/3|0)===0)return 0;Rt(Xt&&WN,"Solid.removeInternalTriangles()");const e=Mn(this),t=e.removeInternalTriangles();Sn(this,e),this._dirty=!1,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}return this._manifold=null,t>0?t:0}h(IR,"removeInternalTriangles");function NR(){const r=this._vertProperties,e=this._triVerts,t=this._triIDs,n=e.length/3|0;if(n===0)return 0;const i=new Array(n);for(let b=0;b<n;b++){const T=b*3,C=e[T+0]>>>0,I=e[T+1]>>>0,P=e[T+2]>>>0;i[b]=[[r[C*3+0],r[C*3+1],r[C*3+2]],[r[I*3+0],r[I*3+1],r[I*3+2]],[r[P*3+0],r[P*3+1],r[P*3+2]]]}let s=1/0,o=1/0,a=1/0,c=-1/0,l=-1/0,u=-1/0;for(let b=0;b<r.length;b+=3){const T=r[b],C=r[b+1],I=r[b+2];T<s&&(s=T),T>c&&(c=T),C<o&&(o=C),C>l&&(l=C),I<a&&(a=I),I>u&&(u=I)}const d=1e-6*(Math.hypot(c-s,l-o,u-a)||1),p=h((b,T,C)=>{const P=C[0][0],N=C[0][1],D=C[0][2],L=C[1][0],R=C[1][1],q=C[1][2],$=C[2][0],U=C[2][1],K=C[2][2],W=L-P,ne=R-N,Q=q-D,k=$-P,B=U-N,z=K-D,X=T[1]*z-T[2]*B,V=T[2]*k-T[0]*z,te=T[0]*B-T[1]*k,ce=W*X+ne*V+Q*te;if(Math.abs(ce)<1e-12)return null;const le=1/ce,ue=b[0]-P,re=b[1]-N,ae=b[2]-D,he=(ue*X+re*V+ae*te)*le;if(he<-1e-12||he>1+1e-12)return null;const Ne=re*Q-ae*ne,J=ae*W-ue*Q,Be=ue*ne-re*W,ge=(T[0]*Ne+T[1]*J+T[2]*Be)*le;if(ge<-1e-12||he+ge>1+1e-12)return null;const Ae=(k*Ne+B*J+z*Be)*le;return Ae>1e-10?Ae:null},"rayTri"),m=h(b=>{const T=[[1,0,0],[0,1,0],[0,0,1]];let C=0;for(let I=0;I<T.length;I++){const P=T[I],N=[b[0]+(I+1)*d,b[1]+(I+2)*d,b[2]+(I+3)*d];let D=0;for(let L=0;L<i.length;L++)p(N,P,i[L])!==null&&D++;D%2===1&&C++}return C>=2},"pointInside"),_=h(b=>{const[T,C,I]=i[b],P=(T[0]+C[0]+I[0])/3+d,N=(T[1]+C[1]+I[1])/3+d,D=(T[2]+C[2]+I[2])/3+d;return[P,N,D]},"triProbe"),y=new Uint8Array(n);for(let b=0;b<n;b++)y[b]=1;let g=0;for(let b=0;b<n;b++){const T=_(b);m(T)&&(y[b]=0,g++)}if(g===0)return 0;const x=r.length/3|0,w=new Uint8Array(x),S=[],E=[];for(let b=0;b<n;b++){if(!y[b])continue;const T=b*3,C=e[T+0]>>>0,I=e[T+1]>>>0,P=e[T+2]>>>0;S.push(C,I,P),E.push(t[b]),w[C]=1,w[I]=1,w[P]=1}const A=new Int32Array(x);for(let b=0;b<x;b++)A[b]=-1;const M=[];let v=0;for(let b=0;b<x;b++)w[b]&&(A[b]=v++,M.push(r[b*3+0],r[b*3+1],r[b*3+2]));for(let b=0;b<S.length;b++)S[b]=A[S[b]];this._vertProperties=M,this._triVerts=S,this._triIDs=E,this._vertKeyToIndex=new Map;for(let b=0;b<this._vertProperties.length;b+=3){const T=this._vertProperties[b],C=this._vertProperties[b+1],I=this._vertProperties[b+2];this._vertKeyToIndex.set(`${T},${C},${I}`,b/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),g}h(NR,"removeInternalTrianglesByRaycast");function RR({offsetScale:r=1e-5,crossingTolerance:e=.05}={}){const t=this._vertProperties,n=this._triVerts,i=this._triIDs,s=n.length/3|0;if(s===0)return 0;let o=1/0,a=1/0,c=1/0,l=-1/0,u=-1/0,f=-1/0;for(let P=0;P<t.length;P+=3){const N=t[P],D=t[P+1],L=t[P+2];N<o&&(o=N),N>l&&(l=N),D<a&&(a=D),D>u&&(u=D),L<c&&(c=L),L>f&&(f=L)}const d=Math.hypot(l-o,u-a,f-c)||1,p=r*d,m=new Array(s),_=new Array(s),y=new Array(s);for(let P=0;P<s;P++){const N=P*3,D=n[N+0]>>>0,L=n[N+1]>>>0,R=n[N+2]>>>0,q=t[D*3+0],$=t[D*3+1],U=t[D*3+2],K=t[L*3+0],W=t[L*3+1],ne=t[L*3+2],Q=t[R*3+0],k=t[R*3+1],B=t[R*3+2];m[P]=[[q,$,U],[K,W,ne],[Q,k,B]],_[P]=[(q+K+Q)/3,($+W+k)/3,(U+ne+B)/3];const z=K-q,X=W-$,V=ne-U,te=Q-q,ce=k-$,le=B-U;let ue=X*le-V*ce,re=V*te-z*le,ae=z*ce-X*te;const he=Math.hypot(ue,re,ae);he<1e-18?y[P]=[0,0,0]:y[P]=[ue/he,re/he,ae/he]}const g=h((P,N,D,L)=>{const R=N[0]-P[0],q=N[1]-P[1],$=N[2]-P[2],U=D[0]-P[0],K=D[1]-P[1],W=D[2]-P[2],ne=L[0]-P[0],Q=L[1]-P[1],k=L[2]-P[2],B=Math.hypot(R,q,$),z=Math.hypot(U,K,W),X=Math.hypot(ne,Q,k);if(B<1e-18||z<1e-18||X<1e-18)return 0;const V=R*U+q*K+$*W,te=U*ne+K*Q+W*k,ce=ne*R+Q*q+k*$,le=q*W-$*K,ue=$*U-R*W,re=R*K-q*U,ae=le*ne+ue*Q+re*k,he=B*z*X+V*X+te*B+ce*z;return 2*Math.atan2(ae,he)},"solidAngle"),x=h(P=>{let N=0;for(let D=0;D<s;D++){const[L,R,q]=m[D];N+=g(P,L,R,q)}return N/(4*Math.PI)},"winding"),w=new Uint8Array(s);for(let P=0;P<s;P++)w[P]=1;let S=0;const E=Math.max(0,Math.min(.49,e));for(let P=0;P<s;P++){const N=y[P];if(!N||N[0]===0&&N[1]===0&&N[2]===0)continue;const D=_[P],L=[D[0]+N[0]*p,D[1]+N[1]*p,D[2]+N[2]*p],R=[D[0]-N[0]*p,D[1]-N[1]*p,D[2]-N[2]*p],q=x(L),$=x(R),U=Math.abs(q)-.5,K=Math.abs($)-.5;U<-E&&K>E||U>E&&K<-E||U*K<-E*E||(w[P]=0,S++)}if(S===0)return 0;const A=t.length/3|0,M=new Uint8Array(A),v=[],b=[];for(let P=0;P<s;P++){if(!w[P])continue;const N=P*3,D=n[N+0]>>>0,L=n[N+1]>>>0,R=n[N+2]>>>0;v.push(D,L,R),b.push(i[P]),M[D]=1,M[L]=1,M[R]=1}const T=new Int32Array(A);for(let P=0;P<A;P++)T[P]=-1;const C=[];let I=0;for(let P=0;P<A;P++)M[P]&&(T[P]=I++,C.push(t[P*3+0],t[P*3+1],t[P*3+2]));for(let P=0;P<v.length;P++)v[P]=T[v[P]];this._vertProperties=C,this._triVerts=v,this._triIDs=b,this._vertKeyToIndex=new Map;for(let P=0;P<this._vertProperties.length;P+=3){const N=this._vertProperties[P],D=this._vertProperties[P+1],L=this._vertProperties[P+2];this._vertKeyToIndex.set(`${N},${D},${L}`,P/3|0)}return this._dirty=!0,this._faceIndex=null,this.fixTriangleWindingsByAdjacency(),S}h(RR,"removeInternalTrianglesByWinding");function PR(r){const e=Number(r);if(!Number.isFinite(e)||e<=0)return 0;Rt(Xt&&kN,"Solid.cleanupTinyFaceIslands()");const t=Mn(this),n=t.cleanupTinyFaceIslands(e);if(n>0){Sn(this,t),this._dirty=!0,this._faceIndex=null;try{this._manifold&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}this._manifold=null}return n}h(PR,"cleanupTinyFaceIslands");function DR(r=.001){if(!Number.isFinite(r)||r<=0)return this;Rt(Xt&&HN,"Solid.mergeTinyFaces()");const e=Mn(this);if(e.mergeTinyFaces(r)>0){Sn(this,e),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}h(DR,"mergeTinyFaces");function FR(){return this._manifoldize().getMesh()}h(FR,"getMesh");function LR(){if(this._faceIndex)return;const r=this.getMesh(),{triVerts:e,faceID:t}=r,n=e.length/3|0,i=new Map;if(t&&t.length===n)for(let s=0;s<n;s++){const o=t[s];let a=i.get(o);a||(a=[],i.set(o,a)),a.push(s)}this._faceIndex=i;try{r&&typeof r.delete=="function"&&r.delete()}catch{}}h(LR,"_ensureFaceIndex");function OR(r){return Rt(Md,"Solid.getFace"),Mn(this).getFace(r)}h(OR,"getFace");function UR(r){return Rt(Md,"Solid.getFaceNormal"),Mn(this).getFaceNormal(r)}h(UR,"getFaceNormal");function BR(r=!1){return Rt(Md,"Solid.getFaces"),Mn(this).getFaces(r)}h(BR,"getFaces");function zR(){return Rt(Md,"Solid.getBoundaryEdgePolylines"),Mn(this).getBoundaryEdgePolylines()}h(zR,"getBoundaryEdgePolylines");const Go=.01,kR=.0015,bS=1e-4;function VR(){return typeof nt?.buildBooleanCombinedAuthoringState=="function"}h(VR,"hasNativeBooleanCombinedBuilder");function SS(){return typeof nt?.buildBooleanUnionManyAuthoringState=="function"}h(SS,"hasNativeBooleanUnionManyBuilder");function HR(r){if(!VR())throw new Error(`${r} requires the custom local manifold build with native boolean result reconstruction support.`)}h(HR,"requireNativeBooleanCombinedBuilder");function WR(r){if(!SS())throw new Error(`${r} requires the custom local manifold build with native batch union result reconstruction support.`)}h(WR,"requireNativeBooleanUnionManyBuilder");function _c(r){const e=r&&r.constructor;return e&&e.BaseSolid?e.BaseSolid:e}h(_c,"baseSolidCtor$1");function GR(r){const e=r&&r._vertProperties;if(!Array.isArray(e)||e.length<3)return 1;let t=1/0,n=1/0,i=1/0,s=-1/0,o=-1/0,a=-1/0;for(let c=0;c<e.length;c+=3){const l=e[c],u=e[c+1],f=e[c+2];l<t&&(t=l),l>s&&(s=l),u<n&&(n=u),u>o&&(o=u),f<i&&(i=f),f>a&&(a=f)}return Math.max(Math.hypot(s-t,o-n,a-i),1)}h(GR,"booleanApproxScale");function xh(r,e=12){return[Number(r?.[0]||0).toFixed(e),Number(r?.[1]||0).toFixed(e),Number(r?.[2]||0).toFixed(e)].join(",")}h(xh,"pointKey");function MS(r,e){if(!r||typeof r.getFace!="function"||!e)return[];const t=r.getFace(e)||[],n=new Map,i=h((a,c)=>{if(!Array.isArray(a)||!Array.isArray(c))return;const l=xh(a),u=xh(c),f=l<u?`${l}|${u}`:`${u}|${l}`,d=n.get(f);d?d.count+=1:n.set(f,{count:1,points:[[Number(a[0])||0,Number(a[1])||0,Number(a[2])||0],[Number(c[0])||0,Number(c[1])||0,Number(c[2])||0]]})},"addEdge");for(const a of t){const c=Array.isArray(a?.p1)?a.p1:null,l=Array.isArray(a?.p2)?a.p2:null,u=Array.isArray(a?.p3)?a.p3:null;!c||!l||!u||(i(c,l),i(l,u),i(u,c))}const s=[],o=new Set;for(const a of n.values())if(a.count===1)for(const c of a.points){const l=xh(c);o.has(l)||(o.add(l),s.push(c))}return s}h(MS,"faceBoundaryPoints");function $R(r,e,t){if(!r||typeof r.minGapToPoint!="function")return!1;for(const n of e){const i=r.minGapToPoint(n,t,{nearestOnly:!0});if(Array.isArray(i)&&i.some(s=>Number(s?.distance)<=t))return!0}return!1}h($R,"hasNearTargetEdgePoint");function XR(r,e,t,n,i=8){const s=MS(e,t);if(!s.length||typeof r?.minGapToPoint!="function")return-1/0;const o=Math.max(1,Math.ceil(s.length/i)),a=Math.max(GR(r)*2,bS*10);let c=0,l=0;for(let u=0;u<s.length;u+=o){l+=1;const f=r.minGapToPoint(s[u],a,{nearestOnly:!0});(Array.isArray(f)&&f.length>0?f[0].inside===!0:!1)===n&&(c+=1)}return l>0?c/l:-1/0}h(XR,"scoreFaceSide");function wS(r,e,t){const n=String(r||"").toUpperCase();if(n!=="UNION"&&n!=="SUBTRACT"||!e||!t||typeof e.minGapToPoint!="function"||typeof t.getFaceNames!="function"||typeof t.pushFace!="function")return t;const i=n==="UNION",s=bS,o=s*2,a=[];for(const u of t.getFaceNames()||[]){const f=String(u||"").trim();if(!f)continue;const d=MS(t,f);d.length&&$R(e,d,s)&&a.push(f)}if(!a.length||typeof t.clone!="function")return t;const c=t.clone();let l=!1;for(const u of a){let f=null;for(const d of[1,-1]){const p=typeof c.clone=="function"?c.clone():null;if(p)try{p.pushFace(u,d*o,{warnMissing:!1,warnInvalidNormal:!1});const m=XR(e,p,u,i);(!f||m>f.score)&&(f={sign:d,score:m})}catch{}}if(!(!f||!(f.score>-1/0)))try{c.pushFace(u,f.sign*o,{warnMissing:!1,warnInvalidNormal:!1}),l=!0}catch{}}return l?c:t}h(wS,"conditionEdgePointProximity");function Km(r,e,t){const n=new r;Wi(n,e),n._dirty=!0,n._manifold=null,n._faceIndex=null;try{n.name=t||e?.name||n?.name}catch{}return n}h(Km,"solidFromNativeBooleanSnapshot");function wf(r){return r instanceof Map?Array.from(r.entries(),([e,t])=>[String(e||""),String(t||"")]).filter(e=>e[0]):Array.isArray(r)?Array.from(r,([e,t])=>[String(e||""),String(t||"")]).filter(e=>e[0]):[]}h(wf,"toMetadataJsonEntries");function zv(r){return r instanceof Map?Array.from(r.entries()):Array.isArray(r)?Array.from(r):[]}h(zv,"toSnapshotEntries");function mm(r){return{numProp:Number(r?.numProp??3),vertProperties:Array.from(r?.vertProperties??[]),triVerts:Array.from(r?.triVerts??[]),triIDs:Array.from(r?.triIDs??[]),faceNameToID:zv(r?.faceNameToID),idToFaceName:zv(r?.idToFaceName),faceMetadataJson:wf(r?.faceMetadataJson),edgeMetadataJson:wf(r?.edgeMetadataJson),auxEdges:Array.isArray(r?.auxEdges)?r.auxEdges:[],vertexCount:Number(r?.vertexCount??0),triangleCount:Number(r?.triangleCount??0)}}h(mm,"toNativeBooleanSnapshot");function qR(r,e,t={}){Rt(typeof nt?.buildSolidAuthoringStateFromMesh=="function","Solid.simplify");const n=new Map(e instanceof Map?e:[]),i=new Map;for(const[s,o]of n.entries())i.has(o)||i.set(o,s);return nt.buildSolidAuthoringStateFromMesh({numProp:Number(r?.numProp??3),vertProperties:Array.from(r?.vertProperties??[]),triVerts:Array.from(r?.triVerts??[]),faceID:Array.from(r?.faceID??[]),faceNameToID:Array.from(i.entries()),idToFaceName:Array.from(n.entries()),faceMetadataJson:wf(t?.faceMetadataJson),edgeMetadataJson:wf(t?.edgeMetadataJson),auxEdges:Array.isArray(t?.auxEdges)?t.auxEdges:[],name:t?.name||""})}h(qR,"buildNativeSnapshotFromMesh");function So(r,e){const t=Number(r?.numProp??3)||3,n=(e>>>0)*t,i=r?.vertProperties??[];return[Number(i[n+0])||0,Number(i[n+1])||0,Number(i[n+2])||0]}h(So,"_vec3FromMesh");function AS(r,e,t){const n=e[0]-r[0],i=e[1]-r[1],s=e[2]-r[2],o=t[0]-r[0],a=t[1]-r[1],c=t[2]-r[2];let l=i*c-s*a,u=s*o-n*c,f=n*a-i*o;const d=Math.hypot(l,u,f);return d>0?(l/=d,u/=d,f/=d,{normal:[l,u,f],area2:d}):{normal:[0,0,0],area2:0}}h(AS,"_triangleNormalAndArea");function vh(r,e,t){const n=t[0]-e[0],i=t[1]-e[1],s=t[2]-e[2],o=r[0]-e[0],a=r[1]-e[1],c=r[2]-e[2],l=n*n+i*i+s*s,u=l>0?Math.max(0,Math.min(1,(o*n+a*i+c*s)/l)):0,f=o-n*u,d=a-i*u,p=c-s*u;return f*f+d*d+p*p}h(vh,"_pointSegmentDistanceSq");function YR(r,e,t,n){const i=t[0]-e[0],s=t[1]-e[1],o=t[2]-e[2],a=n[0]-e[0],c=n[1]-e[1],l=n[2]-e[2],u=r[0]-e[0],f=r[1]-e[1],d=r[2]-e[2],p=i*i+s*s+o*o,m=i*a+s*c+o*l,_=a*a+c*c+l*l,y=u*i+f*s+d*o,g=u*a+f*c+d*l,x=p*_-m*m;if(Math.abs(x)>1e-18){const w=(_*y-m*g)/x,S=(p*g-m*y)/x;if(1-w-S>=0&&w>=0&&S>=0){const A=e[0]+i*w+a*S,M=e[1]+s*w+c*S,v=e[2]+o*w+l*S,b=r[0]-A,T=r[1]-M,C=r[2]-v;return b*b+T*T+C*C}}return Math.min(vh(r,e,t),vh(r,t,n),vh(r,n,e))}h(YR,"_pointTriangleDistanceSq");function KR(r){const e={numProp:Number(r?._numProp??3)||3,vertProperties:r?._vertProperties??[],triVerts:r?._triVerts??[],faceID:r?._triIDs??[]},t=Math.min(e.triVerts.length/3|0,e.faceID.length|0),n=[];for(let i=0;i<t;i++){const s=i*3,o=So(e,e.triVerts[s+0]),a=So(e,e.triVerts[s+1]),c=So(e,e.triVerts[s+2]),{normal:l,area2:u}=AS(o,a,c);u>0&&n.push({a:o,b:a,c,id:e.faceID[i]>>>0,normal:l,centroid:[(o[0]+a[0]+c[0])/3,(o[1]+a[1]+c[1])/3,(o[2]+a[2]+c[2])/3]})}return n}h(KR,"_buildTaggedSourceTrianglesFromSolid");function ZR(r){if(!Array.isArray(r)||r.length<512)return{all:r,candidatesForPoint:h(()=>r,"candidatesForPoint")};const e=[1/0,1/0,1/0],t=[-1/0,-1/0,-1/0];for(const l of r){const u=l.centroid;for(let f=0;f<3;f++)u[f]<e[f]&&(e[f]=u[f]),u[f]>t[f]&&(t[f]=u[f])}const n=[Math.max(1e-9,t[0]-e[0]),Math.max(1e-9,t[1]-e[1]),Math.max(1e-9,t[2]-e[2])],i=Math.max(4,Math.min(64,Math.ceil(Math.cbrt(r.length)))),s=[n[0]/i,n[1]/i,n[2]/i],o=new Map,a=h((l,u)=>Math.max(0,Math.min(i-1,Math.floor((l[u]-e[u])/s[u]))),"cellCoord"),c=h((l,u,f)=>`${l},${u},${f}`,"cellKey");for(const l of r){const u=a(l.centroid,0),f=a(l.centroid,1),d=a(l.centroid,2),p=c(u,f,d);let m=o.get(p);m||(m=[],o.set(p,m)),m.push(l)}return{all:r,candidatesForPoint(l){const u=a(l,0),f=a(l,1),d=a(l,2),p=[];for(let m=0;m<=3&&p.length<32;m++)for(let _=Math.max(0,u-m);_<=Math.min(i-1,u+m);_++)for(let y=Math.max(0,f-m);y<=Math.min(i-1,f+m);y++)for(let g=Math.max(0,d-m);g<=Math.min(i-1,d+m);g++){const x=o.get(c(_,y,g));x&&p.push(...x)}return p.length?p:r}}}h(ZR,"_buildRetagCandidateIndex");function JR(r,e){const t=KR(e),n=r?.triVerts?.length/3|0;if(!n||t.length===0)return r;const i=ZR(t),s=new Uint32Array(n);for(let o=0;o<n;o++){const a=o*3,c=So(r,r.triVerts[a+0]),l=So(r,r.triVerts[a+1]),u=So(r,r.triVerts[a+2]),f=[(c[0]+l[0]+u[0])/3,(c[1]+l[1]+u[1])/3,(c[2]+l[2]+u[2])/3],{normal:d,area2:p}=AS(c,l,u);let m=t[0].id,_=1/0;for(const y of i.candidatesForPoint(f)){const g=YR(f,y.a,y.b,y.c),x=p>0?Math.max(-1,Math.min(1,d[0]*y.normal[0]+d[1]*y.normal[1]+d[2]*y.normal[2])):1,w=g+(1-x)*1e-6;w<_&&(_=w,m=y.id)}s[o]=m>>>0}return r.faceID=s,r}h(JR,"retagSimplifiedMeshFromSourceSolid");function Zm(r,e,t,n){HR(`Solid.${String(t||"boolean").toLowerCase()}`);const i=Wo(r),s=Wo(e),o=nt.buildBooleanCombinedAuthoringState({leftSnapshot:mm(i),rightSnapshot:mm(s),operation:t,featureID:String(r?.owningFeatureID||r?.name||t||"BOOLEAN"),name:String(r?.name||`${t}_RESULT`),cleanupTinyFaceIslandsArea:Go,disconnectedIslandMinVolume:Go});return Km(n,o,r?.name||`${t}_RESULT`)}h(Zm,"buildNativeBooleanResult");function Jm(r){const e=r?.message||r?.toString?.()||String(r||"");return String(e||"unknown error").slice(0,240)}h(Jm,"describeBooleanError");function bh(r,e){if(!r||typeof r!="object")return r;try{r.__unionManyDiagnostics={...e}}catch{}try{r.userData={...r.userData||{},unionMany:{...e}}}catch{}return r}h(bh,"attachUnionManyDiagnostics");function Sh(r,e={},t=[]){if(!r||typeof r!="object")return r;const n=String(e?.name||"").trim();if(n)try{r.name=n}catch{}try{r.owningFeatureID=e?.owningFeatureID||e?.featureID||e?.featureId||t.find(i=>i?.owningFeatureID)?.owningFeatureID||r?.owningFeatureID||null}catch{}return r}h(Sh,"applyUnionManyNameAndOwner");function ES(r,e,t={}){return r.union(e,{overlapConditioningEnabled:t?.overlapConditioningEnabled})}h(ES,"unionManyPair");function TS(r,e){try{r.unionManyDiagnostics={...e}}catch{}throw r}h(TS,"throwUnionManyError");function jR(r,e,t){if(!r.length)return null;let n=r[0];for(let i=1;i<r.length;i+=1){const s=r[i];t.unionAttemptCount+=1;try{n={solid:ES(n.solid,s.solid,e),count:n.count+s.count}}catch(o){t.unionFailureCount+=1,t.skippedSolidCount+=s.count,t.firstUnionError||(t.firstUnionError=Jm(o)),e?.skipFailed||TS(o,t)}}return n}h(jR,"unionManyNodesSequential");function QR(r,e,t){let n=r.slice();for(;n.length>1;){const i=[];for(let s=0;s<n.length;s+=2){const o=n[s],a=n[s+1];if(!a){i.push(o);continue}t.unionAttemptCount+=1;try{i.push({solid:ES(o.solid,a.solid,e),count:o.count+a.count})}catch(c){t.unionFailureCount+=1,t.skippedSolidCount+=a.count,t.firstUnionError||(t.firstUnionError=Jm(c)),e?.skipFailed||TS(c,t),i.push(o)}}n=i}return n[0]||null}h(QR,"unionManyNodesBalanced");function eP(r,e=null,t={}){const n=Array.isArray(r)?r.filter(Boolean):[];if(!n.length)return null;WR("Solid.unionMany");const i=e||_c(n[0]),s=n.map(u=>mm(Wo(u))),o=String(t?.featureID||n[0]?.owningFeatureID||n[0]?.name||"UNION"),a=String(t?.name||n[0]?.name||`${o}_UNION`),c=nt.buildBooleanUnionManyAuthoringState({snapshots:s,featureID:o,name:a,cleanupTinyFaceIslandsArea:Number(t?.cleanupTinyFaceIslandsArea??Go),disconnectedIslandMinVolume:Number(t?.disconnectedIslandMinVolume??Go)}),l=Km(i,c,a);try{l.owningFeatureID=t?.owningFeatureID||n.find(u=>u?.owningFeatureID)?.owningFeatureID||l?.owningFeatureID||null}catch{}return wd(l)}h(eP,"buildNativeUnionManyResult");function hc(r,e={}){const t=Array.isArray(r)?r:[r],i=(this&&typeof this=="object"&&typeof this.union=="function"?[this,...t]:t).filter(Boolean),s={unionStrategy:"none",nativeBatchUnionAvailable:SS(),nativeBatchUnionStatus:i.length>1?"not_run":"not_applicable",nativeBatchUnionError:null,unionAttemptCount:0,unionFailureCount:0,skippedSolidCount:0,contributedSolidCount:i.length,firstUnionError:null};if(!i.length)return null;if(i.length===1){s.unionStrategy="single";const d=Sh(i[0],e,i);return bh(d,s)}const o=String(e?.unionStrategy||"native_batch").trim().toLowerCase(),a=e?.nativeBatchUnion!==!1&&o!=="balanced"&&o!=="sequential",c=typeof this=="function"?this.BaseSolid||this:_c(i[0]);if(a&&s.nativeBatchUnionAvailable)try{const d=eP(i,c,{...e,featureID:e?.featureID||e?.featureId,owningFeatureID:e?.owningFeatureID||e?.featureID||e?.featureId});return s.unionStrategy="native_batch",s.nativeBatchUnionStatus="passed",s.contributedSolidCount=i.length,Sh(d,e,i),bh(d,s)}catch(d){s.nativeBatchUnionStatus="failed",s.nativeBatchUnionError=Jm(d)}else s.nativeBatchUnionAvailable?s.nativeBatchUnionStatus="disabled":s.nativeBatchUnionStatus="unavailable";const l=i.map(d=>({solid:d,count:1})),u=o==="sequential"?jR(l,e,s):QR(l,e,s);s.unionStrategy=o==="sequential"?s.nativeBatchUnionStatus==="failed"?"sequential_fallback":"sequential":s.nativeBatchUnionStatus==="failed"?"balanced_fallback":"balanced",s.contributedSolidCount=Number(u?.count||0);const f=Sh(u?.solid||null,e,i);return bh(f,s)}h(hc,"unionMany");function tP(r,e=Go){const t=Number(e);if(!Number.isFinite(t)||t<=0||!r||typeof r!="object")return 0;Rt(GN,"Solid._dropDisconnectedIslandsByVolume");const n=Mn(r),i=n.removeDisconnectedIslandsByVolume(t);if(i>0){Sn(r,n),r._dirty=!0,r._faceIndex=null;try{r._manifold&&typeof r._manifold.delete=="function"&&r._manifold.delete()}catch{}r._manifold=null}return i}h(tP,"_dropDisconnectedIslandsByVolume");function nP(r){const e=Number(kR);return!r||typeof r.setEpsilon!="function"||!Number.isFinite(e)||e<=0||r.setEpsilon(e),r}h(nP,"_applyFixedBooleanResultWeld");function wd(r){try{tP(r,Go)}catch{}return nP(r)}h(wd,"_cleanupBooleanResult");function iP(r,e={}){const t=_c(this),n=e?.overlapConditioningEnabled===!1?this:wS("UNION",r,this),i=Zm(n,r,"UNION",t);try{i.owningFeatureID=this?.owningFeatureID||r?.owningFeatureID||i?.owningFeatureID||null}catch{}return wd(i)}h(iP,"union");function rP(r,e={}){const t=_c(this),n=e?.overlapConditioningEnabled===!1?r:wS("SUBTRACT",this,r),i=Zm(this,n,"SUBTRACT",t);try{i.owningFeatureID=this?.owningFeatureID||r?.owningFeatureID||i?.owningFeatureID||null}catch{}return wd(i)}h(rP,"subtract");function sP(r){const e=_c(this),t=Zm(this,r,"INTERSECT",e);try{t.owningFeatureID=this?.owningFeatureID||r?.owningFeatureID||t?.owningFeatureID||null}catch{}return wd(t)}h(sP,"intersect");function oP(r=void 0,e=!1){e&&typeof e=="object"&&(e=!1);const t=this.constructor,n=this._manifoldize(),i=Wo(this),s=r===void 0?n.simplify():n.simplify(r);let o=null;const a=s.getMesh();try{JR(a,this),o=qR(a,this._idToFaceName,{faceMetadataJson:i?.faceMetadataJson,edgeMetadataJson:i?.edgeMetadataJson,auxEdges:i?.auxEdges,name:this?.name||""})}finally{try{a&&typeof a.delete=="function"&&a.delete()}catch{}}Wi(this,o);try{this._manifold&&this._manifold!==s&&typeof this._manifold.delete=="function"&&this._manifold.delete()}catch{}if(this._manifold=s,this._dirty=!1,this._faceIndex=null,e)return this;this._manifold=null,this._dirty=!0,this._faceIndex=null;const c=Km(t,o,this?.name||"");return this._manifoldize(),c}h(oP,"simplify");function aP(r){return r.faceID&&r.faceID.length?Array.from(r.faceID):new Array(r.triVerts.length/3|0).fill(0)}h(aP,"_expandTriIDsFromMesh");function gm(r){return String(r??"").replace(/'/g,"''")}h(gm,"_escapeStepString");function _i(r,e="NAME"){const t=String(r??"").trim();return gm(t||e)}h(_i,"_safeStepName");function _n(r,e){if(!Number.isFinite(r))return"0";let t=Number(r).toFixed(e);return t.includes(".")&&(t=t.replace(/\.?0+$/,"")),t==="-0"&&(t="0"),t}h(_n,"_fmtNumber");function cP(r,e=6){if(!Number.isFinite(r)||r===0)return"0.";const t=Number(r).toExponential(e),[n,i]=t.split("e"),s=Number(i);return`${n.toUpperCase()}E${s>=0?"+":""}${s}`}h(cP,"_fmtExp");function lP(r,e=1e-12){if(!r||r.length!==16)return!0;const t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let n=0;n<16;n++)if(Math.abs((r[n]??t[n])-t[n])>e)return!1;return!0}h(lP,"_isIdentityMatrixElements");function kv(r,e,t,n){if(!r||r.length!==16)return[e,t,n];const i=r[0]*e+r[4]*t+r[8]*n+r[12],s=r[1]*e+r[5]*t+r[9]*n+r[13],o=r[2]*e+r[6]*t+r[10]*n+r[14],a=r[3]*e+r[7]*t+r[11]*n+r[15];return a&&Math.abs(a-1)>1e-12?[i/a,s/a,o/a]:[i,s,o]}h(kv,"_applyMatrix4");function Aa(r,e=[0,0,1]){const t=r[0],n=r[1],i=r[2],s=Math.hypot(t,n,i);return!s||!Number.isFinite(s)?e.slice():[t/s,n/s,i/s]}h(Aa,"_normalize");function jm(r,e){return[r[1]*e[2]-r[2]*e[1],r[2]*e[0]-r[0]*e[2],r[0]*e[1]-r[1]*e[0]]}h(jm,"_cross");function fs(r,e){return r[0]*e[0]+r[1]*e[1]+r[2]*e[2]}h(fs,"_dot");function Vv(r,e){return[r[0]-e[0],r[1]-e[1],r[2]-e[2]]}h(Vv,"_sub");function Mh(r){const t=Math.abs(r[2])<.9?[0,0,1]:[0,1,0],n=jm(t,r);return Aa(n,[1,0,0])}h(Mh,"_orthogonalRefDir");function wh(r,e=40){if(!r||r.length===0)return"()";if(r.length<=e)return`(${r.map(n=>`#${n}`).join(",")})`;const t=[];for(let n=0;n<r.length;n+=e){const i=r.slice(n,n+e).map(s=>`#${s}`).join(",");t.push(i)}return`(
|
|
4621
4621
|
${t.join(`,
|
|
4622
4622
|
`)}
|
|
4623
4623
|
)`}h(wh,"_formatEntityList");function yl(r,e){return!Number.isFinite(r)||!Number.isFinite(e)||e<=0?0:Math.round(r/e)}h(yl,"_quantize");function Hv(r,e,t,n){const i=yl(r[0],t),s=yl(r[1],t),o=yl(r[2],t),a=yl(e,n);return`${i},${s},${o},${a}`}h(Hv,"_planeKey");function pc(r,e){return r<e?`${r}_${e}`:`${e}_${r}`}h(pc,"_edgeKey");function uP(r,e){const t=new Map;for(const i of r){const s=e[i];if(!s)continue;const o=[[s.i0,s.i1],[s.i1,s.i2],[s.i2,s.i0]];for(const[a,c]of o){const l=pc(a,c),u=t.get(l);u?u.count+=1:t.set(l,{count:1,from:a,to:c})}}const n=[];for(const i of t.values())i.count===1&&n.push({from:i.from,to:i.to});return n}h(uP,"_collectBoundaryEdges");function fP(r){const e=new Map;for(const s of r){const o=e.get(s.from)||[];o.push(s),e.set(s.from,o)}const t=new Set,n=[],i=h(s=>`${s.from},${s.to}`,"edgeId");for(const s of r){const o=i(s);if(t.has(o))continue;const a=[s.from];let c=s;t.add(o);let l=0;for(;l++<r.length+5;){if(a.push(c.to),c.to===a[0]){a.pop(),a.length>=3&&n.push(a);break}const u=e.get(c.to)||[];let f=null;for(const d of u){const p=i(d);if(!t.has(p)){f=d;break}}if(!f)return{loops:[],ok:!1};c=f,t.add(i(c))}}return{loops:n,ok:n.length>0}}h(fP,"_buildLoopsFromEdges");function dP(r,e){const{vertProperties:t,triVerts:n,faceID:i}=r||{};if(!t||!n||!i)return[];const s=n.length/3|0,o=t.length/3|0;if(s===0||o===0)return[];const a=BigInt(o),c=h((d,p)=>{const m=BigInt(d),_=BigInt(p);return m<_?m*a+_:_*a+m},"ukey"),l=new Map;for(let d=0;d<s;d++){const p=i?i[d]:void 0,m=d*3,_=n[m+0],y=n[m+1],g=n[m+2],x=[[_,y],[y,g],[g,_]];for(let w=0;w<3;w++){const S=x[w][0],E=x[w][1],A=c(S,E);let M=l.get(A);M||(M=[],l.set(A,M)),M.push({id:p,a:S,b:E,tri:d})}}const u=new Map;for(const[,d]of l.entries()){if(d.length!==2)continue;const p=d[0],m=d[1];if(p.id===m.id)continue;const _=e?.get(p.id)||`FACE_${p.id}`,y=e?.get(m.id)||`FACE_${m.id}`,g=_<y?[_,y]:[y,_],x=JSON.stringify(g);let w=u.get(x);w||(w=[],u.set(x,w));const S=Math.min(p.a,p.b),E=Math.max(p.a,p.b);w.push([S,E])}const f=[];for(const[d,p]of u.entries()){const m=new Map,_=new Set,y=h((A,M)=>A<M?`${A},${M}`:`${M},${A}`,"ek");for(const[A,M]of p)m.has(A)||m.set(A,new Set),m.has(M)||m.set(M,new Set),m.get(A).add(M),m.get(M).add(A);const[g,x]=JSON.parse(d);let w=0;const S=h(A=>{const M=[];let v=-1,b=A;for(M.push(b);;){const T=m.get(b)||new Set;let C;for(const I of T){const P=y(b,I);if(!_.has(P)&&I!==v){C=I,_.add(P);break}}if(C===void 0)break;v=b,b=C,M.push(b)}return M},"visitChainFrom");for(const[A,M]of m.entries())if((M.size|0)===1){const v=[...M][0],b=y(A,v);if(_.has(b))continue;const T=S(A);f.push({name:`${g}|${x}[${w++}]`,faceA:g,faceB:x,indices:T,closedLoop:!1})}const E=h((A,M)=>{const v=[A,M];let b=A,T=M;for(_.add(y(A,M));;){const N=m.get(T)||new Set;let D;for(const L of N){if(L===b)continue;const R=y(T,L);if(!_.has(R)){D=L;break}}if(D===void 0)break;_.add(y(T,D)),v.push(D),b=T,T=D}const C=v[0],I=v[v.length-1];return(m.get(I)||new Set).has(C)&&(_.add(y(I,C)),v.push(C)),v},"buildLoopFromEdge");for(const[A,M]of m.entries())for(const v of M){const b=y(A,v);if(_.has(b))continue;const T=E(A,v),C=T.length>=3&&T[0]===T[T.length-1];f.push({name:`${g}|${x}[${w++}]`,faceA:g,faceB:x,indices:T,closedLoop:C})}}return f}h(dP,"_buildBoundaryEdgePolylines");function hP(r,e,t,n){let i=0;const s=r.length;for(let o=0;o<s;o++){const a=e[r[o]]?.pos,c=e[r[(o+1)%s]]?.pos;if(!a||!c)continue;const l=fs(a,t),u=fs(a,n),f=fs(c,t),d=fs(c,n);i+=l*d-f*u}return i*.5}h(hP,"_loopArea");function CS(r,e){let t=Aa(e,Mh(r));Math.abs(fs(t,r))>.99&&(t=Mh(r)),t=Aa(t);const n=Aa(jm(r,t),Mh(r));return{u:t,v:n}}h(CS,"_planeBasis");function Ah(r,e){const t=new Map;for(const s of r){const o=e[s];if(!o)continue;const a=[[o.i0,o.i1],[o.i1,o.i2],[o.i2,o.i0]];for(const[c,l]of a){const u=pc(c,l),f=t.get(u)||[];f.push(s),t.set(u,f)}}const n=new Set,i=[];for(const s of r){if(n.has(s))continue;const o=[s],a=[];for(n.add(s);o.length;){const c=o.pop();a.push(c);const l=e[c];if(!l)continue;const u=[[l.i0,l.i1],[l.i1,l.i2],[l.i2,l.i0]];for(const[f,d]of u){const p=pc(f,d),m=t.get(p)||[];if(!(m.length<2))for(const _ of m)n.has(_)||(n.add(_),o.push(_))}}a.length&&i.push(a)}return i}h(Ah,"_splitComponents");function pP(r,e,t,n){if(!r||r.length===0)return!1;const i=e[r[0]];if(!i)return!1;let s=i.normal,o=i.d;for(const a of r){const c=e[a];if(!c)continue;let l=c.normal,u=c.d,f=fs(l,s);if(f<0&&(l=[-l[0],-l[1],-l[2]],u=-u,f=-f),1-f>t||Math.abs(u-o)>n)return!1}return!0}h(pP,"_isCoplanarGroup");function ca(r,e,t,n,i,s=""){const o=e[r.i0],a=e[r.i1],c=e[r.i2];if(!o||!a||!c)return null;const l=r.normal,u=CS(l,r.e1),f=n(l),d=n(u.u),p=t.add(`AXIS2_PLACEMENT_3D('',#${o.pointId},#${f},#${d})`),m=t.add(`PLANE('',#${p})`),_=t.add(`POLY_LOOP('',(#${o.pointId},#${a.pointId},#${c.pointId}))`),y=t.add(`FACE_OUTER_BOUND('',#${_},.T.)`);return t.add(`ADVANCED_FACE('${_i(s,"")}',(#${y}),#${m},.T.)`)}h(ca,"_emitTriangleFace");function Eh(r,e,t,n,i,s,o="",a=null){if(!r.length)return{ok:!1};const c=e[r[0]];if(!c)return{ok:!1};const l=uP(r,e);if(l.length<3)return{ok:!1};const{loops:u,ok:f}=fP(l);if(!f||u.length===0)return{ok:!1};const d=c.normal,p=CS(d,c.e1),m=u.map(T=>hP(T,t,p.u,p.v));let _=0,y=Math.abs(m[0]||0);for(let T=1;T<m.length;T++){const C=Math.abs(m[T]||0);C>y&&(y=C,_=T)}m[_]<0&&(u[_].reverse(),m[_]=-m[_]);for(let T=0;T<u.length;T++)T!==_&&m[T]>0&&(u[T].reverse(),m[T]=-m[T]);const g=u[_][0],x=t[g];if(!x)return{ok:!1};const w=i(d),S=i(p.u),E=n.add(`AXIS2_PLACEMENT_3D('',#${x.pointId},#${w},#${S})`),A=n.add(`PLANE('',#${E})`),M=[],v=h((T,C)=>{if(!a)return null;const I=[],P=T.length;for(let D=0;D<P;D++){const L=T[D],R=T[(D+1)%P],q=pc(L,R);let $=a.edgeCurveCache.get(q);if(!$){const W=a.edgeNameByKey.get(q)||a.edgeNameAllocator.allocate(`EDGE_${a.edgeCurveCache.size}`),ne=t[L],Q=t[R];if(!ne||!Q)return null;const k=n.add(`POLYLINE('',(#${ne.pointId},#${Q.pointId}))`);$={id:n.add(`EDGE_CURVE('${_i(W)}',#${ne.vertexId},#${Q.vertexId},#${k},.T.)`),start:L,end:R},a.edgeCurveCache.set(q,$)}const U=$.start===L&&$.end===R?".T.":".F.",K=n.add(`ORIENTED_EDGE('',*,*,#${$.id},${U})`);I.push(K)}return I.length?n.add(`EDGE_LOOP('${_i(C,"")}',(${I.map(D=>`#${D}`).join(",")}))`):null},"buildEdgeLoop");for(let T=0;T<u.length;T++){const C=u[T];if(!C||C.length<3)continue;const I=C.map(N=>{const D=t[N]?.pointId;return D?`#${D}`:null});if(I.length<3||I.some(N=>!N))return{ok:!1};let P=null;if(a&&(P=v(C,`${o}_LOOP_${T}`)),P||(P=n.add(`POLY_LOOP('',(${I.join(",")}))`)),T===_){const N=n.add(`FACE_OUTER_BOUND('',#${P},.T.)`);M.push(N)}else{const N=n.add(`FACE_BOUND('',#${P},.F.)`);M.push(N)}}return M.length===0?{ok:!1}:{ok:!0,faceId:n.add(`ADVANCED_FACE('${_i(o,"")}',(${M.map(T=>`#${T}`).join(",")}),#${A},.T.)`)}}h(Eh,"_emitPlanarComponent");function Wv(r,e,t,n,i,s=""){if(!r||r.length===0)return{ok:!1};const o=new Map,a=[],c=[],l=h(m=>{let _=o.get(m);if(_!=null)return _;const y=t[m];if(!y)return null;const g=y.pos,x=a.length;return a.push([g[0],g[1],g[2]]),o.set(m,x),x},"addVertex");for(const m of r){const _=e[m];if(!_)continue;const y=l(_.i0),g=l(_.i1),x=l(_.i2);y==null||g==null||x==null||c.push([y+1,g+1,x+1])}if(a.length<3||c.length===0)return{ok:!1};const u=a.map(m=>`(${_n(m[0],i)},${_n(m[1],i)},${_n(m[2],i)})`).join(","),f=n.add(`CARTESIAN_POINT_LIST_3D('',(${u}))`),d=c.map(m=>`(${m[0]},${m[1]},${m[2]})`).join(",");return{ok:!0,faceId:n.add(`TRIANGULATED_FACE('${_i(s,"")}',#${f},(${d}),$)`)}}h(Wv,"_emitTessellatedFace");const G_=class G_{constructor(){this.nextId=1,this.lines=[]}add(e){const t=this.nextId++;return this.lines.push(`#${t}=${e};`),t}};h(G_,"StepBuilder");let ym=G_;const $_=class $_{constructor(){this.counts=new Map}allocate(e){const t=_i(e,"NAME"),n=this.counts.get(t)||0;return this.counts.set(t,n+1),n===0?t:_i(`${t}[${n}]`)}};h($_,"NameAllocator");let Af=$_;function mP(r,e){const t=String(e).toLowerCase(),n=r.add("(LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT($,.METRE.))"),i={millimeter:".MILLI.",centimeter:".CENTI.",meter:"$",micron:".MICRO."};if(Object.prototype.hasOwnProperty.call(i,t)){const s=i[t];return s==="$"?n:r.add(`(LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(${s},.METRE.))`)}if(t==="inch"||t==="foot"){const s=t==="inch"?.0254:.3048,o=t==="inch"?"INCH":"FOOT",a=r.add(`LENGTH_MEASURE_WITH_UNIT(LENGTH_MEASURE(${_n(s,8)}),#${n})`);return r.add(`(CONVERSION_BASED_UNIT('${o}',#${a}) LENGTH_UNIT() NAMED_UNIT(*))`)}return r.add("(LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.))")}h(mP,"_buildLengthUnit");function gP(r,e={}){const t=e.unit||"millimeter",n=Number.isFinite(e.precision)?e.precision:6,i=Number.isFinite(e.scale)?e.scale:1,s=e.applyWorldTransform!==!1,o=e.mergePlanarFaces!==!1,a=e.useTessellatedFaces!==!1,c=e.exportFaces!==!1,l=e.exportEdgesAsPolylines!==!1,u=gm(e.name||r?.[0]?.name||"part"),f=new ym,d=f.add("APPLICATION_CONTEXT('automotive_design')"),p=a?"ap242":"automotive_design";f.add(`APPLICATION_PROTOCOL_DEFINITION('international standard','${p}',2000,#${d})`);const m=mP(f,t),_=f.add("(PLANE_ANGLE_UNIT() NAMED_UNIT(*) SI_UNIT($,.RADIAN.))"),y=f.add("(SOLID_ANGLE_UNIT() NAMED_UNIT(*) SI_UNIT($,.STERADIAN.))"),g=Math.max(1e-9,Math.abs(i)*1e-6),x=f.add(`UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(${cP(g,6)}),#${m},'distance_accuracy_value','')`),w=f.add(`(GEOMETRIC_REPRESENTATION_CONTEXT(3) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#${x})) GLOBAL_UNIT_ASSIGNED_CONTEXT((#${m},#${_},#${y})) REPRESENTATION_CONTEXT('',''))`),S=f.add(`PRODUCT_CONTEXT('',#${d},'mechanical')`),E=f.add(`PRODUCT('${u}','${u}','',(#${S}))`),A=f.add(`PRODUCT_DEFINITION_FORMATION('','',#${E})`),M=f.add(`PRODUCT_DEFINITION_CONTEXT('part definition',#${d},'design')`),v=f.add(`PRODUCT_DEFINITION('design','',#${A},#${M})`),b=f.add(`PRODUCT_DEFINITION_SHAPE('','',#${v})`),T=[],C=[],I=[],P=new Map,N=h(Q=>{const k=Aa(Q),B=`${_n(k[0],9)},${_n(k[1],9)},${_n(k[2],9)}`;let z=P.get(B);return z||(z=f.add(`DIRECTION('',(${_n(k[0],n)},${_n(k[1],n)},${_n(k[2],n)}))`),P.set(B,z),z)},"getDirectionId");for(let Q=0;Q<(r||[]).length;Q++){const k=r[Q];if(!k||typeof k.getMesh!="function")continue;let B=null;try{if(B=k.getMesh(),!B||!B.vertProperties||!B.triVerts){I.push(String(k?.name||`solid_${Q+1}`));continue}let z=null;if(s){try{typeof k.updateWorldMatrix=="function"?k.updateWorldMatrix(!0,!1):typeof k.updateMatrixWorld=="function"&&k.updateMatrixWorld(!0)}catch{}const se=k?.matrixWorld;se?.elements&&se.elements.length===16&&!lP(se.elements)&&(z=se.elements)}const X=B.vertProperties,V=B.triVerts,te=X.length/3|0,ce=V.length/3|0,le=new Array(te),ue=[1/0,1/0,1/0],re=[-1/0,-1/0,-1/0];for(let se=0;se<te;se++){const me=X[se*3+0],xe=X[se*3+1],Ce=X[se*3+2],[be,Pe,ie]=z?kv(z,me,xe,Ce):[me,xe,Ce],Se=be*i,Ie=Pe*i,Ue=ie*i;ue[0]=Math.min(ue[0],Se),ue[1]=Math.min(ue[1],Ie),ue[2]=Math.min(ue[2],Ue),re[0]=Math.max(re[0],Se),re[1]=Math.max(re[1],Ie),re[2]=Math.max(re[2],Ue);const De=f.add(`CARTESIAN_POINT('',(${_n(Se,n)},${_n(Ie,n)},${_n(Ue,n)}))`),_e=f.add(`VERTEX_POINT('',#${De})`);le[se]={pointId:De,vertexId:_e,pos:[Se,Ie,Ue]}}const ae=[],he=1e-16,Ne=re[0]-ue[0],J=re[1]-ue[1],Be=re[2]-ue[2],ge=Math.hypot(Ne,J,Be)||1,Ae=Number.isFinite(e.planarNormalTolerance)?e.planarNormalTolerance:2e-4,Ee=Number.isFinite(e.planarDistanceTolerance)?e.planarDistanceTolerance:Math.max(2e-5,ge*2e-5),G=new Array(ce),F=B.faceID&&B.faceID.length===ce?B.faceID:null,oe=k&&k._idToFaceName instanceof Map?k._idToFaceName:null,O=F?new Map:null,j=F?null:new Map,ee=new Af,pe=new Af,fe=new Map,de=new Map;for(let se=0;se<ce;se++){const me=V[se*3+0]>>>0,xe=V[se*3+1]>>>0,Ce=V[se*3+2]>>>0,be=le[me],Pe=le[xe],ie=le[Ce];if(!be||!Pe||!ie)continue;const Se=be.pos,Ie=Pe.pos,Ue=ie.pos,De=Vv(Ie,Se),_e=Vv(Ue,Se),Te=jm(De,_e),Oe=Math.hypot(Te[0],Te[1],Te[2]);if(!Oe||Oe<he)continue;const Fe=[Te[0]/Oe,Te[1]/Oe,Te[2]/Oe],ze=fs(Fe,Se),Qe={i0:me,i1:xe,i2:Ce,normal:Fe,d:ze,e1:De};if(G[se]=Qe,F){const st=F[se]>>>0,qe=O.get(st)||[];qe.push(se),O.set(st,qe)}else{const st=o?Hv(Fe,ze,Ae,Ee):`tri_${se}`,qe=j.get(st)||[];qe.push(se),j.set(st,qe)}}const Re=l||c;if(O){if(o&&Re){const se=new Map;for(let xe=0;xe<ce;xe++){const Ce=G[xe];if(!Ce)continue;const be=F[xe]>>>0,Pe=[[Ce.i0,Ce.i1],[Ce.i1,Ce.i2],[Ce.i2,Ce.i0]];for(const[ie,Se]of Pe){const Ie=pc(ie,Se);let Ue=se.get(Ie);Ue||(Ue={faces:new Set},se.set(Ie,Ue)),Ue.faces.add(be)}}const me=new Map;for(const[xe,Ce]of se.entries()){const be=[...Ce.faces];if(be.length===0)continue;let Pe=null;if(be.length===1)Pe=`${oe?.get(be[0])||`FACE_${be[0]}`}|BOUNDARY`;else{const Se=oe?.get(be[0])||`FACE_${be[0]}`,Ie=oe?.get(be[1])||`FACE_${be[1]}`,Ue=Se<Ie?[Se,Ie]:[Ie,Se];Pe=`${Ue[0]}|${Ue[1]}`}const ie=me.get(Pe)||[];ie.push(xe),me.set(Pe,ie)}for(const[xe,Ce]of me.entries()){if(Ce.sort(),Ce.length===1){de.set(Ce[0],_i(xe));continue}for(let be=0;be<Ce.length;be++)de.set(Ce[be],_i(`${xe}[${be}]`))}}for(const[se,me]of O.entries()){const xe=oe?.get(se)||`FACE_${se}`,Ce=Ah(me,G);if(a&&c){const be=pP(me,G,Ae,Ee);if(be&&o){for(const Pe of Ce){const ie=ee.allocate(xe),Ie=Eh(Pe,G,le,f,N,n,ie,o&&l?{edgeNameByKey:de,edgeCurveCache:fe,edgeNameAllocator:pe}:null);if(Ie.ok&&Ie.faceId){ae.push(Ie.faceId);continue}const Ue=Wv(Pe,G,le,f,n,ie);if(Ue.ok&&Ue.faceId){ae.push(Ue.faceId);continue}for(const De of Pe){const _e=G[De];if(!_e)continue;const Te=ee.allocate(xe),Oe=ca(_e,le,f,N,n,Te);Oe&&ae.push(Oe)}}continue}if(!be){for(const Pe of Ce){const ie=ee.allocate(xe),Se=Wv(Pe,G,le,f,n,ie);if(Se.ok&&Se.faceId)ae.push(Se.faceId);else for(const Ie of Pe){const Ue=G[Ie];if(!Ue)continue;const De=ee.allocate(xe),_e=ca(Ue,le,f,N,n,De);_e&&ae.push(_e)}}continue}}if(o&&c){const be=new Map;for(const Pe of me){const ie=G[Pe];if(!ie)continue;const Se=Hv(ie.normal,ie.d,Ae,Ee),Ie=be.get(Se)||[];Ie.push(Pe),be.set(Se,Ie)}for(const Pe of be.values()){const ie=Ah(Pe,G);for(const Se of ie){const Ie=ee.allocate(xe),De=Eh(Se,G,le,f,N,n,Ie,l?{edgeNameByKey:de,edgeCurveCache:fe,edgeNameAllocator:pe}:null);if(De.ok&&De.faceId)ae.push(De.faceId);else for(const _e of Se){const Te=G[_e];if(!Te)continue;const Oe=ee.allocate(xe),Fe=ca(Te,le,f,N,n,Oe);Fe&&ae.push(Fe)}}}}else if(c)for(const be of me){const Pe=G[be];if(!Pe)continue;const ie=ee.allocate(xe),Se=ca(Pe,le,f,N,n,ie);Se&&ae.push(Se)}}}else if(j){let se=0;for(const me of j.values()){const xe=o?Ah(me,G):[me],Ce=`FACE_${++se}`;for(const be of xe){if(o&&c){const Pe=ee.allocate(Ce),Se=Eh(be,G,le,f,N,n,Pe,o&&l?{edgeNameByKey:de,edgeCurveCache:fe,edgeNameAllocator:pe}:null);if(Se.ok&&Se.faceId){ae.push(Se.faceId);continue}}if(c)for(const Pe of be){const ie=G[Pe];if(!ie)continue;const Se=ee.allocate(Ce),Ie=ca(ie,le,f,N,n,Se);Ie&&ae.push(Ie)}}}}if(c){if(ae.length===0){I.push(String(k?.name||`solid_${Q+1}`));continue}const se=f.add(`CLOSED_SHELL('',${wh(ae)})`),me=f.add(`FACETED_BREP('',#${se})`);T.push(me)}if(l){const se=dP(B,oe);for(const xe of se){const Ce=Array.isArray(xe.indices)?xe.indices:[];if(Ce.length<2)continue;const be=[];let Pe=!1;for(const Ue of Ce){const De=le[Ue]?.pointId;if(!De){Pe=!0;break}be.push(`#${De}`)}if(Pe||be.length<2)continue;const ie=xe.name||`${xe.faceA}|${xe.faceB}`,Se=pe.allocate(ie),Ie=f.add(`POLYLINE('${_i(Se)}',(${be.join(",")}))`);C.push(Ie)}const me=Array.isArray(k?._auxEdges)?k._auxEdges:[];for(const xe of me){if(!xe)continue;const Ce=xe?.name||"CENTERLINE";if(!(!!xe?.centerline||typeof Ce=="string"&&/centerline/i.test(Ce)))continue;const Pe=Array.isArray(xe?.points)?xe.points:[];if(Pe.length<2)continue;const ie=[];for(const _e of Pe){if(!Array.isArray(_e)||_e.length<3)continue;let Te=_e[0],Oe=_e[1],Fe=_e[2];if(!(!Number.isFinite(Te)||!Number.isFinite(Oe)||!Number.isFinite(Fe))){if(s&&z&&!xe?.polylineWorld){const ze=kv(z,Te,Oe,Fe);Te=ze[0],Oe=ze[1],Fe=ze[2]}ie.push([Te*i,Oe*i,Fe*i])}}if(ie.length<2)continue;if(xe?.closedLoop&&ie.length>=2){const _e=ie[0],Te=ie[ie.length-1];(_e[0]!==Te[0]||_e[1]!==Te[1]||_e[2]!==Te[2])&&ie.push([_e[0],_e[1],_e[2]])}const Se=[];let Ie=!1;for(const _e of ie){if(!_e||_e.length<3){Ie=!0;break}const Te=f.add(`CARTESIAN_POINT('',(${_n(_e[0],n)},${_n(_e[1],n)},${_n(_e[2],n)}))`);Se.push(`#${Te}`)}if(Ie||Se.length<2)continue;const Ue=pe.allocate(Ce),De=f.add(`POLYLINE('${_i(Ue)}',(${Se.join(",")}))`);C.push(De)}}}catch{I.push(String(k?.name||`solid_${Q+1}`))}finally{try{B&&typeof B.delete=="function"&&B.delete()}catch{}}}const D=[];if(c&&T.length&&D.push(...T),l&&C.length){const Q=f.add(`GEOMETRIC_CURVE_SET('EDGES',${wh(C)})`);D.push(Q)}if(D.length===0)return{data:"",exported:0,skipped:r?.map(Q=>Q?.name||"solid")||[]};const L=a?"tessellated":"",R=l?"SHAPE_REPRESENTATION":"ADVANCED_BREP_SHAPE_REPRESENTATION",q=f.add(`${R}('${L}',${wh(D)},#${w})`);f.add(`SHAPE_DEFINITION_REPRESENTATION(#${b},#${q})`);const U=new Date().toISOString().replace(/\.\d+Z$/,""),K=["ISO-10303-21;","HEADER;","FILE_DESCRIPTION(('BREP STEP export'),'2;1');",`FILE_NAME('${u}','${gm(U)}',('BREP'),('BREP'),'Codex','BREP','');`,`FILE_SCHEMA(('${a?"AP242_MANAGED_MODEL_BASED_3D_ENGINEERING":"AUTOMOTIVE_DESIGN"}'));`,"ENDSEC;","DATA;"],W=["ENDSEC;","END-ISO-10303-21;"];return{data:`${K.join(`
|